Search in sources :

Example 86 with Artifact

use of org.eclipse.aether.artifact.Artifact in project BIMserver by opensourceBIM.

the class RemotePluginRepository method main.

public static void main(String[] args) throws ArtifactResolutionException {
    System.out.println("------------------------------------------------------------");
    System.out.println(RemotePluginRepository.class.getSimpleName());
    RepositorySystem system = newRepositorySystem();
    RepositorySystemSession session = newRepositorySystemSession(system);
    Artifact artifact = new DefaultArtifact("org.eclipse.aether:aether-util:1.0.0.v20140518");
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(artifact);
    artifactRequest.setRepositories(newRepositories(system, session));
    ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
    artifact = artifactResult.getArtifact();
    System.out.println(artifact + " resolved to  " + artifact.getFile());
}
Also used : RepositorySystem(org.eclipse.aether.RepositorySystem) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 87 with Artifact

use of org.eclipse.aether.artifact.Artifact in project karaf by apache.

the class ReactorMavenResolver method resolve.

@Override
public File resolve(String url) throws IOException {
    Artifact artifact = toArtifact(url);
    File file = reactor.findArtifact(artifact);
    return file == null ? fallback.resolve(url) : file;
}
Also used : File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact)

Example 88 with Artifact

use of org.eclipse.aether.artifact.Artifact in project karaf by apache.

the class ReactorMavenResolver method resolve.

@Override
public File resolve(String url, Exception previousException) throws IOException {
    Artifact artifact = toArtifact(url);
    File file = reactor.findArtifact(artifact);
    return file == null ? fallback.resolve(url, previousException) : file;
}
Also used : File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact)

Example 89 with Artifact

use of org.eclipse.aether.artifact.Artifact in project activemq-artemis by apache.

the class ArtemisAbstractPlugin method resolveDependencies.

protected Set<File> resolveDependencies(String[] dependencyListParameter, String[] individualListParameter) throws DependencyCollectionException, MojoFailureException, MojoExecutionException {
    Set<File> filesSet = new HashSet<>();
    if (dependencyListParameter != null) {
        for (String lib : dependencyListParameter) {
            getLog().debug("********************" + lib);
            List<Artifact> artifactsList = explodeDependencies(newArtifact(lib));
            for (Artifact artifact : artifactsList) {
                File artifactFile = resolveArtifact(artifact);
                filesSet.add(artifactFile);
            }
        }
    }
    if (individualListParameter != null) {
        for (String lib : individualListParameter) {
            Artifact artifact = newArtifact(lib);
            getLog().debug("Single dpendency resolved::" + artifact);
            File artifactFile = resolveArtifact(artifact);
            filesSet.add(artifactFile);
        }
    }
    return filesSet;
}
Also used : File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) HashSet(java.util.HashSet)

Example 90 with Artifact

use of org.eclipse.aether.artifact.Artifact in project fabric8 by jboss-fuse.

the class MavenProxyServletSupport method doUpload.

protected UploadContext doUpload(InputStream is, String path) throws InvalidMavenArtifactRequest {
    if (path == null) {
        throw new InvalidMavenArtifactRequest();
    }
    int p = path.lastIndexOf('/');
    final String filename = path.substring(p + 1);
    // TODO -- user uuid?
    String uuid = UUID.randomUUID().toString();
    File tmp = new File(tmpFolder, uuid);
    // noinspection ResultOfMethodCallIgnored
    tmp.mkdir();
    final File file;
    try {
        file = readFile(is, tmp, filename);
    } catch (FileNotFoundException e) {
        throw new IllegalStateException(e);
    }
    UploadContext result = new UploadContext(file);
    // root path, try reading mvn coords
    if (p <= 0) {
        try {
            String mvnCoordsPath = readMvnCoordsPath(file);
            if (mvnCoordsPath != null) {
                return move(file, mvnCoordsPath);
            } else {
                // we need manual mvn coords input
                result.addHeader(LOCATION_HEADER, file.getPath());
                return result;
            }
        } catch (Exception e) {
            LOGGER.warn(String.format("Failed to deploy artifact : %s due to %s", filename, e.getMessage()), e);
            return UploadContext.ERROR;
        }
    }
    Matcher artifactMatcher = ARTIFACT_REQUEST_URL_REGEX.matcher(path);
    Matcher metadataMatcher = ARTIFACT_METADATA_URL_REGEX.matcher(path);
    File target = null;
    if (metadataMatcher.matches()) {
        LOGGER.info("Received upload request for maven metadata : {}", path);
        try {
            target = new File(uploadRepository, path);
            Files.copy(file, target);
            LOGGER.info("Maven metadata installed");
            result.setFile(target);
        } catch (Exception e) {
            result = UploadContext.ERROR;
            LOGGER.warn(String.format("Failed to upload metadata: %s due to %s", path, e.getMessage()), e);
        }
    // If no matching metadata found return nothing
    } else if (artifactMatcher.matches()) {
        LOGGER.info("Received upload request for maven artifact : {}", path);
        Artifact artifact = null;
        try {
            artifact = convertPathToArtifact(path);
            target = new File(uploadRepository, path);
            Files.copy(file, target);
            result.setFile(target);
            result.setGroupId(artifact.getGroupId());
            result.setArtifactId(artifact.getArtifactId());
            result.setVersion(artifact.getVersion());
            result.setType(artifact.getExtension());
            LOGGER.info("Artifact installed: {}", artifact.toString());
        } catch (Exception e) {
            result = UploadContext.ERROR;
            LOGGER.warn(String.format("Failed to upload artifact : %s due to %s", artifact, e.getMessage()), e);
        }
    }
    try {
        if (file != null) {
            // delete tmp directory and file
            Files.recursiveDelete(file.getParentFile());
        }
    } catch (Exception e) {
        LOGGER.warn(e.getMessage());
    }
    return result;
}
Also used : Matcher(java.util.regex.Matcher) FileNotFoundException(java.io.FileNotFoundException) JarFile(java.util.jar.JarFile) File(java.io.File) VersionConstraint(org.eclipse.aether.version.VersionConstraint) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact)

Aggregations

Artifact (org.eclipse.aether.artifact.Artifact)122 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)97 File (java.io.File)51 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)34 Dependency (org.eclipse.aether.graph.Dependency)32 IOException (java.io.IOException)29 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)26 ArrayList (java.util.ArrayList)23 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)22 List (java.util.List)20 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)18 CollectRequest (org.eclipse.aether.collection.CollectRequest)15 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)15 DependencyNode (org.eclipse.aether.graph.DependencyNode)14 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)14 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)13 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)13 URL (java.net.URL)12 Map (java.util.Map)12 RepositorySystem (org.eclipse.aether.RepositorySystem)11