Search in sources :

Example 6 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project BIMserver by opensourceBIM.

the class PluginManager method loadDependencies.

private PublicFindClassClassLoader loadDependencies(Set<org.bimserver.plugins.Dependency> bimServerDependencies, Model model, PublicFindClassClassLoader previous) throws FileNotFoundException, IOException {
    List<org.apache.maven.model.Dependency> dependencies = model.getDependencies();
    Iterator<org.apache.maven.model.Dependency> it = dependencies.iterator();
    Path workspaceDir = Paths.get("..");
    bimServerDependencies.add(new org.bimserver.plugins.Dependency(workspaceDir.resolve("PluginBase/target/classes")));
    bimServerDependencies.add(new org.bimserver.plugins.Dependency(workspaceDir.resolve("Shared/target/classes")));
    while (it.hasNext()) {
        org.apache.maven.model.Dependency depend = it.next();
        try {
            if (depend.getGroupId().equals("org.opensourcebim") && (depend.getArtifactId().equals("shared") || depend.getArtifactId().equals("pluginbase"))) {
                // TODO we might want to check the version though
                continue;
            }
            if (depend.isOptional() || "test".equals(depend.getScope())) {
                continue;
            }
            Dependency dependency2 = new Dependency(new DefaultArtifact(depend.getGroupId() + ":" + depend.getArtifactId() + ":jar:" + depend.getVersion()), "compile");
            DelegatingClassLoader depDelLoader = new DelegatingClassLoader(previous);
            if (!dependency2.getArtifact().isSnapshot()) {
                if (dependency2.getArtifact().getFile() != null) {
                    bimServerDependencies.add(new org.bimserver.plugins.Dependency(dependency2.getArtifact().getFile().toPath()));
                    loadDependencies(dependency2.getArtifact().getFile().toPath(), depDelLoader);
                } else {
                    ArtifactRequest request = new ArtifactRequest();
                    request.setArtifact(dependency2.getArtifact());
                    request.setRepositories(mavenPluginRepository.getRepositories());
                    try {
                        ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
                        if (resolveArtifact.getArtifact().getFile() != null) {
                            bimServerDependencies.add(new org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
                            loadDependencies(resolveArtifact.getArtifact().getFile().toPath(), depDelLoader);
                        } else {
                        // TODO error?
                        }
                    } catch (ArtifactResolutionException e) {
                        e.printStackTrace();
                    }
                }
            } else {
                // Snapshot projects linked in Eclipse
                ArtifactRequest request = new ArtifactRequest();
                if ((!"test".equals(dependency2.getScope()) && !dependency2.getArtifact().isSnapshot())) {
                    request.setArtifact(dependency2.getArtifact());
                    request.setRepositories(mavenPluginRepository.getLocalRepositories());
                    try {
                        ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
                        if (resolveArtifact.getArtifact().getFile() != null) {
                            bimServerDependencies.add(new org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
                            loadDependencies(resolveArtifact.getArtifact().getFile().toPath(), depDelLoader);
                        } else {
                        // TODO error?
                        }
                    } catch (Exception e) {
                        LOGGER.info(dependency2.getArtifact().toString());
                        e.printStackTrace();
                    }
                // bimServerDependencies.add(new
                // org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
                }
            }
            ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
            descriptorRequest.setArtifact(dependency2.getArtifact());
            descriptorRequest.setRepositories(mavenPluginRepository.getRepositories());
            ArtifactDescriptorResult descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
            CollectRequest collectRequest = new CollectRequest();
            collectRequest.setRootArtifact(descriptorResult.getArtifact());
            collectRequest.setDependencies(descriptorResult.getDependencies());
            collectRequest.setManagedDependencies(descriptorResult.getManagedDependencies());
            collectRequest.setRepositories(descriptorResult.getRepositories());
            DependencyNode node = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest).getRoot();
            DependencyRequest dependencyRequest = new DependencyRequest();
            dependencyRequest.setRoot(node);
            CollectResult collectResult = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest);
            PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
            // collectResult.getRoot().accept(new
            // ConsoleDependencyGraphDumper());
            collectResult.getRoot().accept(nlg);
            try {
                mavenPluginRepository.getSystem().resolveDependencies(mavenPluginRepository.getSession(), dependencyRequest);
            } catch (DependencyResolutionException e) {
            // Ignore
            }
            for (DependencyNode dependencyNode : nlg.getNodes()) {
                ArtifactRequest newRequest = new ArtifactRequest(dependencyNode);
                newRequest.setRepositories(mavenPluginRepository.getRepositories());
                ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), newRequest);
                Artifact artifact = resolveArtifact.getArtifact();
                Path jarFile = Paths.get(artifact.getFile().getAbsolutePath());
                loadDependencies(jarFile, depDelLoader);
                Artifact versionArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion());
                ArtifactRequest request = new ArtifactRequest();
                request.setArtifact(versionArtifact);
                request.setRepositories(mavenPluginRepository.getRepositories());
                // try {
                // ArtifactResult resolveArtifact =
                // mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(),
                // request);
                // File depPomFile =
                // resolveArtifact.getArtifact().getFile();
                // if (depPomFile != null) {
                // MavenXpp3Reader mavenreader = new MavenXpp3Reader();
                // Model depModel = null;
                // try (FileReader reader = new FileReader(depPomFile)) {
                // try {
                // depModel = mavenreader.read(reader);
                // } catch (XmlPullParserException e) {
                // e.printStackTrace();
                // }
                // }
                // previous = loadDependencies(bimServerDependencies,
                // depModel, previous);
                // } else {
                // LOGGER.info("Artifact not found " + versionArtifact);
                // }
                // } catch (ArtifactResolutionException e1) {
                // LOGGER.error(e1.getMessage());
                // }
                // EclipsePluginClassloader depLoader = new
                // EclipsePluginClassloader(depDelLoader, projectRoot);
                bimServerDependencies.add(new org.bimserver.plugins.Dependency(jarFile));
            }
            previous = depDelLoader;
        } catch (DependencyCollectionException e) {
            e.printStackTrace();
        } catch (ArtifactDescriptorException e2) {
            e2.printStackTrace();
        } catch (ArtifactResolutionException e) {
            e.printStackTrace();
        }
    }
    return previous;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest) Path(java.nio.file.Path) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) CollectResult(org.eclipse.aether.collection.CollectResult) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DelegatingClassLoader(org.bimserver.plugins.classloaders.DelegatingClassLoader) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) ObjectIDMException(org.bimserver.plugins.objectidms.ObjectIDMException) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) PluginException(org.bimserver.shared.exceptions.PluginException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) UserException(org.bimserver.shared.exceptions.UserException) ChannelConnectionException(org.bimserver.shared.ChannelConnectionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 7 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project bnd by bndtools.

the class AetherRepository method get.

@Override
public File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) throws Exception {
    init();
    // Use the index by preference
    if (indexedRepo != null)
        return indexedRepo.get(ConversionUtils.maybeMavenCoordsToBsn(bsn), version, properties, listeners);
    File file = null;
    boolean getSource = false;
    try {
        // Setup the Aether repo session and request
        DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
        session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
        if (bsn.endsWith(".source")) {
            String originalBsn = properties.get("bsn");
            if (originalBsn != null) {
                bsn = originalBsn;
                getSource = true;
            }
        }
        String[] coords = ConversionUtils.getGroupAndArtifactForBsn(bsn);
        MavenVersion mvnVersion = new MavenVersion(version);
        String versionStr = null;
        if ("exact".equals(properties.get("strategy")) || getSource) {
            versionStr = properties.get("version");
        } else {
            versionStr = mvnVersion.toString();
        }
        Artifact artifact = null;
        if (getSource) {
            artifact = new DefaultArtifact(coords[0], coords[1], "sources", "jar", versionStr);
        } else {
            artifact = new DefaultArtifact(coords[0], coords[1], "jar", versionStr);
        }
        ArtifactRequest request = new ArtifactRequest();
        request.setArtifact(artifact);
        request.setRepositories(Collections.singletonList(remoteRepo));
        // Log the transfer
        session.setTransferListener(new AbstractTransferListener() {

            @Override
            public void transferStarted(TransferEvent event) throws TransferCancelledException {
                System.err.println(event);
            }

            @Override
            public void transferSucceeded(TransferEvent event) {
                System.err.println(event);
            }

            @Override
            public void transferFailed(TransferEvent event) {
                System.err.println(event);
            }
        });
        try {
            // Resolve the version
            ArtifactResult artifactResult = repoSystem.resolveArtifact(session, request);
            artifact = artifactResult.getArtifact();
            file = artifact.getFile();
        } catch (ArtifactResolutionException ex) {
        // could not download artifact, simply return null
        }
        return file;
    } finally {
        for (DownloadListener dl : listeners) {
            if (file != null)
                dl.success(file);
            else
                dl.failure(null, "Download failed");
        }
    }
}
Also used : AbstractTransferListener(org.eclipse.aether.transfer.AbstractTransferListener) TransferCancelledException(org.eclipse.aether.transfer.TransferCancelledException) TransferEvent(org.eclipse.aether.transfer.TransferEvent) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MavenVersion(aQute.bnd.version.MavenVersion) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 8 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project bnd by bndtools.

the class DependencyResolver method discoverArtifacts.

private void discoverArtifacts(Map<File, ArtifactResult> files, List<DependencyNode> nodes, String parent, List<RemoteRepository> remoteRepositories) throws MojoExecutionException {
    for (DependencyNode node : nodes) {
        // Ensure that the file is downloaded so we can index it
        try {
            ArtifactResult resolvedArtifact = postProcessor.postProcessResult(system.resolveArtifact(session, new ArtifactRequest(node.getArtifact(), remoteRepositories, parent)));
            logger.debug("Located file: {} for artifact {}", resolvedArtifact.getArtifact().getFile(), resolvedArtifact);
            files.put(resolvedArtifact.getArtifact().getFile(), resolvedArtifact);
        } catch (ArtifactResolutionException e) {
            throw new MojoExecutionException("Failed to resolve the dependency " + node.getArtifact().toString(), e);
        }
        if (includeTransitive) {
            discoverArtifacts(files, node.getChildren(), node.getRequestContext(), remoteRepositories);
        } else {
            logger.debug("Ignoring transitive dependencies of {}", node.getDependency());
        }
    }
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DependencyNode(org.eclipse.aether.graph.DependencyNode) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 9 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project bnd by bndtools.

the class RemotePostProcessor method postProcessSnapshot.

private ArtifactResult postProcessSnapshot(ArtifactRequest request, Artifact artifact) throws MojoExecutionException {
    for (RemoteRepository repository : request.getRepositories()) {
        if (!repository.getPolicy(true).isEnabled()) {
            // Skip the repo if it isn't enabled for snapshots
            continue;
        }
        // Remove the workspace from the session so that we don't use it
        DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession(session);
        newSession.setWorkspaceReader(null);
        // Find the snapshot metadata for the module
        MetadataRequest mr = new MetadataRequest().setRepository(repository).setMetadata(new DefaultMetadata(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "maven-metadata.xml", SNAPSHOT));
        for (MetadataResult metadataResult : system.resolveMetadata(newSession, singletonList(mr))) {
            if (metadataResult.isResolved()) {
                String version;
                try {
                    Metadata read = metadataReader.read(metadataResult.getMetadata().getFile(), null);
                    Versioning versioning = read.getVersioning();
                    if (versioning == null || versioning.getSnapshotVersions() == null || versioning.getSnapshotVersions().isEmpty()) {
                        continue;
                    } else {
                        version = versioning.getSnapshotVersions().get(0).getVersion();
                    }
                } catch (Exception e) {
                    throw new MojoExecutionException("Unable to read project metadata for " + artifact, e);
                }
                Artifact fullVersionArtifact = new org.eclipse.aether.artifact.DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension(), version);
                try {
                    ArtifactResult result = system.resolveArtifact(newSession, new ArtifactRequest().setArtifact(fullVersionArtifact).addRepository(repository));
                    if (result.isResolved()) {
                        File toUse = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteArtifact(fullVersionArtifact, repository, artifact.toString()));
                        if (!toUse.exists()) {
                            logger.warn("The resolved artifact {} does not exist at {}", fullVersionArtifact, toUse);
                            continue;
                        } else {
                            logger.debug("Located snapshot file {} for artifact {}", toUse, artifact);
                        }
                        result.getArtifact().setFile(toUse);
                        return result;
                    }
                } catch (ArtifactResolutionException e) {
                    logger.debug("Unable to locate the artifact {}", fullVersionArtifact, e);
                }
            }
        }
    }
    logger.debug("Unable to resolve a remote repository containing {}", artifact);
    return null;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultMetadata(org.eclipse.aether.metadata.DefaultMetadata) DefaultMetadata(org.eclipse.aether.metadata.DefaultMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) Artifact(org.eclipse.aether.artifact.Artifact) MetadataResult(org.eclipse.aether.resolution.MetadataResult) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MetadataRequest(org.eclipse.aether.resolution.MetadataRequest) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) File(java.io.File)

Example 10 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project fabric8 by jboss-fuse.

the class AetherBasedResolver method isRetryableException.

@Override
public RetryChance isRetryableException(Exception exception) {
    RetryChance retry = RetryChance.NEVER;
    RepositoryException aetherException = findAetherException(exception);
    if (aetherException instanceof ArtifactResolutionException) {
        // aggregate case - exception that contains exceptions - usually per repository
        ArtifactResolutionException resolutionException = (ArtifactResolutionException) aetherException;
        if (resolutionException.getResult() != null) {
            for (Exception ex : resolutionException.getResult().getExceptions()) {
                RetryChance singleRetry = isRetryableException(ex);
                if (retry.chance() < singleRetry.chance()) {
                    retry = singleRetry;
                }
            }
        }
    } else if (aetherException != null) {
        // single exception case
        if (aetherException instanceof ArtifactNotFoundException) {
            // very little chance we'll find the artifact next time
            retry = RetryChance.NEVER;
        } else if (aetherException instanceof MetadataNotFoundException) {
            retry = RetryChance.NEVER;
        } else if (aetherException instanceof ArtifactTransferException || aetherException instanceof MetadataTransferException) {
            // we could try again
            Throwable root = rootException(aetherException);
            if (root instanceof SocketTimeoutException) {
                // we could try again - but without assuming we'll succeed eventually
                retry = RetryChance.LOW;
            } else if (root instanceof ConnectException) {
                // "connection refused" - not retryable
                retry = RetryChance.NEVER;
            } else if (root instanceof NoRouteToHostException) {
                // not retryable
                retry = RetryChance.NEVER;
            }
        } else {
            // general aether exception - let's fallback to NEVER, as retryable cases should be
            // handled explicitly
            retry = RetryChance.NEVER;
        }
    } else {
        // we don't know about non-aether exceptions, so let's allow
        retry = RetryChance.UNKNOWN;
    }
    return retry;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MetadataNotFoundException(org.eclipse.aether.transfer.MetadataNotFoundException) ArtifactTransferException(org.eclipse.aether.transfer.ArtifactTransferException) SocketTimeoutException(java.net.SocketTimeoutException) MetadataTransferException(org.eclipse.aether.transfer.MetadataTransferException) RepositoryException(org.eclipse.aether.RepositoryException) ArtifactNotFoundException(org.eclipse.aether.transfer.ArtifactNotFoundException) NoRouteToHostException(java.net.NoRouteToHostException) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ArtifactNotFoundException(org.eclipse.aether.transfer.ArtifactNotFoundException) RepositoryException(org.eclipse.aether.RepositoryException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) MetadataTransferException(org.eclipse.aether.transfer.MetadataTransferException) NoRouteToHostException(java.net.NoRouteToHostException) ArtifactTransferException(org.eclipse.aether.transfer.ArtifactTransferException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) MalformedURLException(java.net.MalformedURLException) MetadataNotFoundException(org.eclipse.aether.transfer.MetadataNotFoundException) InvalidVersionSpecificationException(org.eclipse.aether.version.InvalidVersionSpecificationException) ConnectException(java.net.ConnectException)

Aggregations

ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)52 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)33 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)32 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)27 File (java.io.File)21 Artifact (org.eclipse.aether.artifact.Artifact)21 IOException (java.io.IOException)19 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)10 FileNotFoundException (java.io.FileNotFoundException)9 MalformedURLException (java.net.MalformedURLException)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)9 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)9 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)8 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)8 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)7 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)7 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)7 ArrayList (java.util.ArrayList)6 Model (org.apache.maven.model.Model)6 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)6