Java Code Examples for org.eclipse.aether.artifact.Artifact#getFile()

The following examples show how to use org.eclipse.aether.artifact.Artifact#getFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuildDependencyGraphVisitor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void visitLeave(DependencyNode node) {
    final Dependency dep = node.getDependency();
    if (dep == null) {
        return;
    }
    final Artifact artifact = dep.getArtifact();
    if (artifact.getFile() == null) {
        requests.add(new ArtifactRequest(node));
    }
    if (deploymentNode != null) {
        if (runtimeNode == null && !appDeps.contains(new AppArtifactKey(artifact.getGroupId(),
                artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension()))) {
            //we never want optional deps on the deployment CP
            if (!node.getDependency().isOptional()) {
                deploymentDepNodes.add(node);
            }
        } else if (runtimeNode == node) {
            runtimeNode = null;
            runtimeArtifact = null;
        }
        if (deploymentNode == node) {
            deploymentNode = null;
        }
    }
}
 
Example 2
Source File: EclipseAetherArtifactResolver.java    From wildfly-maven-plugin with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Path resolve(final RepositorySystemSession session, final List<RemoteRepository> repositories, final ArtifactName name) {
    final ArtifactResult result;
    try {
        final ArtifactRequest request = new ArtifactRequest();
        final Artifact defaultArtifact = new DefaultArtifact(name.getGroupId(), name.getArtifactId(), name.getClassifier(), name.getPackaging(), name.getVersion());
        request.setArtifact(defaultArtifact);
        request.setRepositories(repositories);
        result = repoSystem.resolveArtifact(session, request);
    } catch (ArtifactResolutionException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    if (!result.isResolved()) {
        throw new RuntimeException("Failed to resolve artifact " + name);
    }
    final Artifact artifact = result.getArtifact();
    final File artifactFile;
    if (artifact == null || (artifactFile = artifact.getFile()) == null) {
        throw new RuntimeException("Failed to resolve artifact " + name);
    }
    return artifactFile.toPath();
}
 
Example 3
Source File: SimpleReactorReader.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public File findArtifact(Artifact artifact) {
  MavenProject project = getProject(artifact);
  if (project != null) {
    if ("pom".equals(artifact.getExtension())) {
      return project.getFile();
    } else if ("jar".equals(artifact.getExtension()) && "".equals(artifact.getClassifier())) {
      return new File(project.getBuild().getOutputDirectory());
    }
  }
  Artifact _artifact = getArtifact(artifact);
  if (_artifact != null) {
    return _artifact.getFile();
  }
  return null;
}
 
Example 4
Source File: ValidateExtensionsJsonMojo.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void analyzeArtifact(Artifact artifact, Map<String, Artifact> extensions) throws MojoExecutionException {
    final File file = artifact.getFile();
    if (!file.exists()) {
        throw new MojoExecutionException("Failed to locate " + artifact + " at " + file);
    }

    if (!doesDescriptorExistAndCanBeRead(artifact, extensions, file, BootstrapConstants.QUARKUS_EXTENSION_FILE_NAME) &&
            !doesDescriptorExistAndCanBeRead(artifact, extensions, file,
                    BootstrapConstants.EXTENSION_PROPS_JSON_FILE_NAME)) {

        throw new MojoExecutionException("Failed to locate and read neither "
                + BootstrapConstants.QUARKUS_EXTENSION_FILE_NAME
                + " or " + BootstrapConstants.EXTENSION_PROPS_JSON_FILE_NAME
                + " for '" + artifact + "' in " + file);
    }
}
 
Example 5
Source File: SimpleModelResolver.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ModelSource resolveModel(String groupId, String artifactId, String version)
        throws UnresolvableModelException {
    Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "", "pom", version);

    try {
        ArtifactRequest request = new ArtifactRequest(pomArtifact, repositories, null);
        pomArtifact = system.resolveArtifact(session, request).getArtifact();
    } catch (org.eclipse.aether.resolution.ArtifactResolutionException ex) {
        throw new UnresolvableModelException(ex.getMessage(), groupId, artifactId, version, ex);
    } 

    File pomFile = pomArtifact.getFile();

    return new FileModelSource(pomFile);
}
 
Example 6
Source File: AutoDiscoverDeployService.java    From vertx-deploy-tools with Apache License 2.0 6 votes vote down vote up
private List<Artifact> getDeployDependencies(Artifact artifact, List<Exclusion> exclusions, boolean testScope, Map<String, String> properties, DeployType type) {
    ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
    descriptorRequest.setRepositories(AetherUtil.newRepositories(deployConfig));
    descriptorRequest.setArtifact(artifact);
    Model model = AetherUtil.readPom(artifact);
    if (model == null) {
        throw new IllegalStateException("Unable to read POM for " + artifact.getFile());
    }
    try {
        ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor(session, descriptorRequest);

        return descriptorResult.getDependencies().stream()
                .filter(d -> type == DeployType.DEFAULT || (type == DeployType.APPLICATION && !d.getArtifact().getExtension().equals("zip")) || (type == DeployType.ARTIFACT && !d.getArtifact().getExtension().equals("jar")))
                .filter(d -> "compile".equalsIgnoreCase(d.getScope()) || ("test".equalsIgnoreCase(d.getScope()) && testScope))
                .filter(d -> !exclusions.contains(new Exclusion(d.getArtifact().getGroupId(), d.getArtifact().getArtifactId(), null, null)))
                .map(Dependency::getArtifact)
                .map(d -> this.checkWithModel(model, d, properties))
                .collect(Collectors.toList());

    } catch (ArtifactDescriptorException e) {
        LOG.error("Unable to resolve dependencies for deploy artifact '{}', unable to auto-discover ", artifact, e);
    }
    return Collections.emptyList();
}
 
Example 7
Source File: MavenModelResolver.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public ModelSource resolveModel(String groupId, String artifactId, String version)
         throws UnresolvableModelException
{
   Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "", "pom", version);
   try
   {
      final ArtifactRequest request = new ArtifactRequest(pomArtifact, repositories, null);
      pomArtifact = system.resolveArtifact(session, request).getArtifact();

   }
   catch (ArtifactResolutionException e)
   {
      throw new UnresolvableModelException("Failed to resolve POM for " + groupId + ":" + artifactId + ":"
               + version + " due to " + e.getMessage(), groupId, artifactId, version, e);
   }

   final File pomFile = pomArtifact.getFile();

   return new FileModelSource(pomFile);

}
 
Example 8
Source File: MavenDependencyMediation.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
void put(DependencyPath dependencyPath) {
  Artifact artifact = dependencyPath.getLeaf();
  File file = artifact.getFile();
  if (file == null) {
    return;
  }
  Path jarAbsolutePath = file.toPath().toAbsolutePath();
  if (!jarAbsolutePath.toString().endsWith(".jar")) {
    return;
  } 
  put(artifact);
}
 
Example 9
Source File: Publisher.java    From buck with Apache License 2.0 5 votes vote down vote up
private DeployRequest createDeployRequest(List<Artifact> toPublish) {
  DeployRequest deployRequest = new DeployRequest().setRepository(remoteRepo);
  for (Artifact artifact : toPublish) {
    File file = artifact.getFile();
    Objects.requireNonNull(file);
    Preconditions.checkArgument(file.exists(), "No such file: %s", file.getAbsolutePath());

    deployRequest.addArtifact(artifact);
  }
  return deployRequest;
}
 
Example 10
Source File: AutoDiscoverDeployService.java    From vertx-deploy-tools with Apache License 2.0 5 votes vote down vote up
private Artifact checkWithModel(Model model, Artifact artifact, Map<String, String> properties) {
    Optional<org.apache.maven.model.Dependency> result = model.getDependencies().stream()
            .filter(d -> d.getGroupId().equals(artifact.getGroupId()))
            .filter(d -> d.getArtifactId().equals(artifact.getArtifactId()))
            .filter(d -> d.getClassifier() != null && properties.containsKey(d.getClassifier().substring(2, d.getClassifier().length() - 1)))
            .findFirst();
    return result.isPresent() ?
            new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), properties.get(result.get().getClassifier().substring(2, result.get().getClassifier().length() - 1)), artifact.getExtension(), artifact.getVersion(), artifact.getProperties(), artifact.getFile())
            : artifact;
}
 
Example 11
Source File: AetherResolver.java    From onos with Apache License 2.0 5 votes vote down vote up
private boolean isOsgiReady(Artifact artifact) throws Exception {
    try (JarFile jar = new JarFile(artifact.getFile())) {
        Attributes attrs = jar.getManifest().getMainAttributes();
        return attrs.getValue("Bundle-SymbolicName") != null &&
                attrs.getValue("Bundle-Version") != null;
    } catch (IOException e) {
        // wasn't jar
        return false;
    }
}
 
Example 12
Source File: OArtifactReference.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public static OArtifactReference valueOf(Artifact artifact) {
    if (artifact == null) return null;
    String groupId = artifact.getGroupId();
    String artifactId = artifact.getArtifactId();
    String version = artifact.getVersion();
    File file = artifact.getFile();
    return new OArtifactReference(groupId, artifactId, version, file);
}
 
Example 13
Source File: MavenArchive.java    From revapi with Apache License 2.0 5 votes vote down vote up
private MavenArchive(Artifact artifact) {
    if (artifact == null) {
        throw new IllegalArgumentException("Artifact cannot be null");
    }

    file = artifact.getFile();
    if (file == null) {
        throw new IllegalArgumentException("Could not locate the file of the maven artifact: " + artifact);
    }

    this.gav = artifact.toString();
    this.version = artifact.getBaseVersion();
}
 
Example 14
Source File: ArtifactResolver.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private ResolutionResult getResolutionResult(ArtifactResult artifactResult, boolean remoteOnly) {
  ResolutionResult result = null;
  Artifact artifact = artifactResult.getArtifact();
  if (artifact != null) {
    String repositoryId = artifactResult.getRepository().getId();
    if (remoteOnly) {
      if (!Objects.equal(repositoryId, this.repoSession.getLocalRepository().getId())) {
        result = new ResolutionResult(artifact.getFile(), repositoryId);
      }
    } else {
      result = new ResolutionResult(artifact.getFile(), repositoryId);
    }
  }
  return result;
}
 
Example 15
Source File: BuildComponentM2RepositoryMojo.java    From component-runtime with Apache License 2.0 5 votes vote down vote up
protected String copyComponentDependencies(final Artifact car,
        final BiConsumer<ZipEntry, InputStream> onDependency) {
    String gav = null;
    try (final ZipInputStream read =
            new ZipInputStream(new BufferedInputStream(new FileInputStream(car.getFile())))) {
        ZipEntry entry;
        while ((entry = read.getNextEntry()) != null) {
            if (entry.isDirectory()) {
                continue;
            }

            final String path = entry.getName();
            if ("TALEND-INF/metadata.properties".equals(path)) {
                final Properties properties = new Properties();
                properties.load(read);
                gav = properties.getProperty("component_coordinates").replace("\\:", "");
                continue;
            }
            if (!path.startsWith("MAVEN-INF/repository/")) {
                continue;
            }

            onDependency.accept(entry, read);
        }
    } catch (final IOException e) {
        throw new IllegalArgumentException(e);
    }
    return gav;
}
 
Example 16
Source File: ArtifactDownload.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This method fetches the artifact from the remote server using aether library
 * 
 * @param groupId group ID of the artifact
 * @param artifactId artifact ID of the artifact
 * @param version artifact version to be downloaded
 * @param classifier classifier of the artifact
 * @param packaging packaging of the artifact
 * @param localRepository destination path
 * @return location of the downloaded artifact in the local system
 * @throws IOException
 */
public static File getArtifactByAether(String groupId, String artifactId, String version, String classifier, String packaging, File localRepository) throws IOException {
	RepositorySystem repositorySystem = newRepositorySystem();
	RepositorySystemSession session = newSession(repositorySystem, localRepository);

	Artifact artifact = new DefaultArtifact(groupId, artifactId, classifier, packaging, version);
	ArtifactRequest artifactRequest = new ArtifactRequest();
	artifactRequest.setArtifact(artifact);

	List<RemoteRepository> repositories = new ArrayList<>();
	Section ini = Utils.getConfig().get(Constants.INI_URL_HEADER);

	RemoteRepository remoteRepository = new RemoteRepository.Builder("public", "default", ini.get(Constants.INI_NEXUS_SOOT_RELEASE)).build();

	repositories.add(remoteRepository);

	artifactRequest.setRepositories(repositories);
	File result = null;

	try {
		ArtifactResult artifactResult = repositorySystem.resolveArtifact(session, artifactRequest);
		artifact = artifactResult.getArtifact();
		if (artifact != null) {
			result = artifact.getFile();
		}
	}
	catch (ArtifactResolutionException e) {
		throw new IOException("Artifact " + groupId + ":" + artifactId + ":" + version + " could not be downloaded due to " + e.getMessage());
	}

	return result;

}
 
Example 17
Source File: BootstrapAppModelResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static AppArtifact toAppArtifact(Artifact artifact) {
    final AppArtifact appArtifact = new AppArtifact(artifact.getGroupId(), artifact.getArtifactId(),
            artifact.getClassifier(), artifact.getExtension(), artifact.getVersion());
    final File file = artifact.getFile();
    if (file != null) {
        appArtifact.setPaths(PathsCollection.of(file.toPath()));
    }
    return appArtifact;
}
 
Example 18
Source File: DeploymentInjectingDependencyVisitor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private Path resolve(Artifact artifact) {
    File file = artifact.getFile();
    if (file != null) {
        return file.toPath();
    }
    try {
        return resolver.resolve(artifact).getArtifact().getFile().toPath();
    } catch (AppModelResolverException e) {
        throw new DeploymentInjectionException(e);
    }
}
 
Example 19
Source File: ArtifactHelper.java    From LicenseScout with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves an artifact and returns the local file.
 * @param repositoryParameters 
 * @param artifactItem the description of thr artifact to be resolved
 * @return a file object if a configuration file bundle was found, otherwise null
 * @throws MojoExecutionException 
 */
public static File getArtifactFile(final IRepositoryParameters repositoryParameters,
                                   final ArtifactItem artifactItem)
        throws MojoExecutionException {
    final Artifact artifact = resolve(repositoryParameters, artifactItem);
    if (artifact != null) {
        return artifact.getFile();
    }
    return null;
}
 
Example 20
Source File: PublishCommand.java    From buck with Apache License 2.0 4 votes vote down vote up
private static String artifactToString(Artifact artifact) {
  return artifact + " < " + artifact.getFile();
}