Search in sources :

Example 46 with ArtifactResolutionException

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

the class UpdatePluginBundle method execute.

@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    MavenPluginLocation mavenPluginLocation = bimServer.getMavenPluginRepository().getPluginLocation(repository, groupId, artifactId);
    try {
        Path jarFile = mavenPluginLocation.getVersionJar(version);
        Path pomFile = mavenPluginLocation.getVersionPom(version);
        try {
            List<SPluginInformation> plugins = null;
            try {
                plugins = bimServer.getPluginManager().getPluginInformationFromPluginFile(new ByteArrayInputStream(mavenPluginLocation.getVersionPluginXml(version)));
            } catch (ArtifactResolutionException e) {
                plugins = bimServer.getPluginManager().getPluginInformationFromJar(jarFile);
            }
            // IfcModelInterface allOfType = getDatabaseSession().getAllOfType(StorePackage.eINSTANCE.getPluginDescriptor(), OldQuery.getDefault());
            // for (SPluginInformation sPluginInformation : plugins) {
            // update plugin information with data from potentially existing plugins
            // }
            bimServer.getPluginBundleManager().update(mavenPluginLocation.getPluginVersionIdentifier(version), mavenPluginLocation.getPluginBundle(version), mavenPluginLocation.getPluginBundleVersion(version), jarFile, pomFile, plugins);
        } catch (Exception e) {
            throw new UserException(e);
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        throw new UserException(e);
    }
    return null;
}
Also used : Path(java.nio.file.Path) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MavenPluginLocation(org.bimserver.plugins.MavenPluginLocation) ByteArrayInputStream(java.io.ByteArrayInputStream) SPluginInformation(org.bimserver.interfaces.objects.SPluginInformation) UserException(org.bimserver.shared.exceptions.UserException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException)

Example 47 with ArtifactResolutionException

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

the class PluginBundleManager method loadDependencies.

private PublicFindClassClassLoader loadDependencies(Set<org.bimserver.plugins.Dependency> bimServerDependencies, Model model, PublicFindClassClassLoader previous, boolean resolveRemoteDependencies) 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") || depend.getArtifactId().equals("ifcplugins"))) {
                // 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(resolveRemoteDependencies ? mavenPluginRepository.getRepositoriesAsList() : 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 (ArtifactResolutionException e) {
                        LOGGER.error(model.getGroupId() + "." + model.getArtifactId(), e);
                    }
                }
            } 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.getRepositoriesAsList());
            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.getRepositoriesAsList());
                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.getRepositoriesAsList());
                // 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) PluginException(org.bimserver.shared.exceptions.PluginException) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) UserException(org.bimserver.shared.exceptions.UserException) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) IOException(java.io.IOException) 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 48 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project acceptance-test-harness by jenkinsci.

the class PluginManager method installPlugins.

/**
 * Installs specified plugins.
 *
 * @deprecated Please be encouraged to use {@link WithPlugins} annotations to statically declare
 * the required plugins you need. If you really do need to install plugins in the middle
 * of a test, as opposed to be in the beginning, then this is the right method.
 * <p/>
 * The deprecation marker is to call attention to {@link WithPlugins}. This method
 * is not really deprecated.
 * @return Always false.
 */
@Deprecated
public boolean installPlugins(final PluginSpec... specs) throws UnableToResolveDependencies, IOException {
    final Map<String, String> candidates = getMapShortNamesVersion(specs);
    if (!updated) {
        checkForUpdates();
    }
    if (uploadPlugins) {
        LOGGER.warning("Installing plugins by direct upload. Better to use the default MockUpdateCenter.");
        // First check to see whether we need to do anything.
        // If not, do not consider transitive dependencies of the requested plugins,
        // which might force updates (and thus restarts) even though we already have
        // a sufficiently new version of the requested plugin.
        boolean someChangeRequired = false;
        for (PluginSpec spec : specs) {
            if (installationStatus(spec) != InstallationStatus.UP_TO_DATE) {
                someChangeRequired = true;
                break;
            }
        }
        if (!someChangeRequired) {
            return false;
        }
        List<PluginMetadata> pluginToBeInstalled = ucmd.get(jenkins).transitiveDependenciesOf(jenkins, Arrays.asList(specs));
        for (PluginMetadata newPlugin : pluginToBeInstalled) {
            final String name = newPlugin.getName();
            String requiredVersion = candidates.get(name);
            String availableVersion = newPlugin.getVersion();
            if (requiredVersion == null) {
                // a dependency
                requiredVersion = availableVersion;
            }
            final String currentSpec = StringUtils.isNotEmpty(requiredVersion) ? name + "@" + requiredVersion : name;
            InstallationStatus status = installationStatus(currentSpec);
            if (status != InstallationStatus.UP_TO_DATE) {
                if (new VersionNumber(requiredVersion).compareTo(new VersionNumber(availableVersion)) > 0) {
                    throw new AssumptionViolatedException(name + " has version " + availableVersion + " but " + requiredVersion + " was requested");
                }
                try {
                    newPlugin.uploadTo(jenkins, injector, availableVersion);
                } catch (ArtifactResolutionException x) {
                    throw new UnableToResolveDependencies(x);
                }
            }
        }
    } else {
        // JENKINS-50790 It seems that this page takes too much time to load when running in the new ci.jenkins.io
        try {
            driver.manage().timeouts().pageLoadTimeout(time.seconds(240), TimeUnit.MILLISECONDS);
            visit("available");
        } finally {
            driver.manage().timeouts().pageLoadTimeout(time.seconds(FallbackConfig.PAGE_LOAD_TIMEOUT), TimeUnit.MILLISECONDS);
        }
        // End JENKINS-50790
        final ArrayList<PluginSpec> update = new ArrayList<>();
        for (final PluginSpec n : specs) {
            switch(installationStatus(n)) {
                case NOT_INSTALLED:
                    tickPluginToInstall(n);
                    break;
                case OUTDATED:
                    update.add(n);
                    break;
                case UP_TO_DATE:
                    // Nothing to do
                    break;
                default:
                    assert false : "Unreachable";
            }
        }
        clickButton("Install");
        // Plugins that are already installed in older version will be updated
        System.out.println("Plugins to be updated: " + update);
        if (!update.isEmpty()) {
            // Updates tab
            visit("");
            for (PluginSpec n : update) {
                tickPluginToInstall(n);
            }
            clickButton("Download now and install after restart");
        }
    }
    // Jenkins will be restarted if necessary
    boolean hasBeenRestarted = new UpdateCenter(jenkins).waitForInstallationToComplete(specs);
    if (!hasBeenRestarted && specs.length > 0 && jenkins.getVersion().isNewerThan(new VersionNumber("2.188"))) {
        jenkins.getLogger("all").waitForLogged(Pattern.compile("Completed installation of .*"), 1000);
    }
    return false;
}
Also used : MockUpdateCenter(org.jenkinsci.test.acceptance.update_center.MockUpdateCenter) AssumptionViolatedException(org.junit.AssumptionViolatedException) ArrayList(java.util.ArrayList) VersionNumber(hudson.util.VersionNumber) PluginSpec(org.jenkinsci.test.acceptance.update_center.PluginSpec) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) UnableToResolveDependencies(org.jenkinsci.test.acceptance.update_center.UpdateCenterMetadata.UnableToResolveDependencies) PluginMetadata(org.jenkinsci.test.acceptance.update_center.PluginMetadata)

Example 49 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project acceptance-test-harness by jenkinsci.

the class ArtifactResolverUtil method resolve.

/**
 * @param artifact The artifact to be resolved
 *
 * @return artifact resolution result
 */
public ArtifactResult resolve(DefaultArtifact artifact) {
    Builder repoBuilder = new RemoteRepository.Builder("repo.jenkins-ci.org", "default", "https://repo.jenkins-ci.org/public/");
    DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
    File userHome = new File(System.getProperty("user.home"));
    File userSettingsFile = new File(new File(userHome, ".m2"), "settings.xml");
    request.setUserSettingsFile(userSettingsFile);
    if (userSettingsFile.exists()) {
        LOGGER.config("Found maven settings file - " + userSettingsFile.getAbsolutePath());
        SettingsBuilder settingsBuilder = new DefaultSettingsBuilderFactory().newInstance();
        try {
            Settings settings = settingsBuilder.build(request).getEffectiveSettings();
            org.apache.maven.settings.Proxy mavenActiveproxy = settings.getActiveProxy();
            if (mavenActiveproxy != null) {
                LOGGER.config("Found maven proxy settings. Will use for artifact resolution");
                repoBuilder.setProxy(asProxy(mavenActiveproxy));
            } else {
                LOGGER.config("Did not find an active proxy in maven settings xml file");
            }
        } catch (SettingsBuildingException e) {
            LOGGER.log(Level.WARNING, "Could not find or load settings.xml to attempt to user proxy settings.", e);
        }
    }
    RemoteRepository repo = repoBuilder.build();
    ArtifactResult r;
    try {
        r = repoSystem.resolveArtifact(repoSystemSession, new ArtifactRequest(artifact, Arrays.asList(repo), null));
    } catch (ArtifactResolutionException e) {
        throw new RuntimeException("Could not resolve " + artifact + " from Maven repository", e);
    }
    LOGGER.config("Found " + r);
    return r;
}
Also used : SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuilder(org.apache.maven.settings.building.SettingsBuilder) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) Builder(org.eclipse.aether.repository.RemoteRepository.Builder) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DefaultSettingsBuilderFactory(org.apache.maven.settings.building.DefaultSettingsBuilderFactory) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) SettingsBuilder(org.apache.maven.settings.building.SettingsBuilder) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) File(java.io.File) Settings(org.apache.maven.settings.Settings)

Example 50 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project acceptance-test-harness by jenkinsci.

the class TSRPluginManager method installPlugins.

/**
 * Installs specified plugins.
 *
 * deprecated Please be encouraged to use {@link WithPlugins} annotations to statically declare
 * the required plugins you need. If you really do need to install plugins in the middle
 * of a test, as opposed to be in the beginning, then this is the right method.
 * <p/>
 * The deprecation marker is to call attention to {@link WithPlugins}. This method
 * is not really deprecated.
 */
@Deprecated
public void installPlugins(final String... specs) {
    final Map<String, String> candidates = getMapShortNamesVersion(specs);
    if (uploadPlugins) {
        for (PluginMetadata newPlugin : ucmd.get().transitiveDependenciesOf(candidates.keySet())) {
            final String name = newPlugin.name;
            final String claimedVersion = candidates.get(name);
            String currentSpec;
            if (StringUtils.isNotEmpty(claimedVersion)) {
                currentSpec = name + "@" + claimedVersion;
            } else {
                currentSpec = name;
            }
            if (!isInstalled(currentSpec)) {
                // we need to override existing "old" plugins
                try {
                    newPlugin.uploadTo(jenkins, injector, null);
                } catch (IOException | ArtifactResolutionException e) {
                    throw new AssertionError("Failed to upload plugin: " + newPlugin, e);
                }
            }
        }
        // TODO: Use better detection if this is actually necessary
        try {
            waitForCond(new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    return isInstalled(specs);
                }
            }, 5);
        } catch (TimeoutException e) {
            jenkins.restart();
        }
    } else {
        if (!updated)
            checkForUpdates();
        OUTER: for (final String n : candidates.keySet()) {
            for (int attempt = 0; attempt < 2; attempt++) {
                // # of installations attempted, considering retries
                visit("available");
                check(find(by.xpath("//input[starts-with(@name,'plugin.%s.')]", n)));
                clickButton("Install");
                sleep(1000);
                try {
                    new UpdateCenter(jenkins).waitForInstallationToComplete(n);
                } catch (InstallationFailedException e) {
                    if (e.getMessage().contains("Failed to download from")) {
                        // retry
                        continue;
                    }
                }
                // installation completed
                continue OUTER;
            }
        }
    }
}
Also used : InstallationFailedException(org.jenkinsci.test.acceptance.po.UpdateCenter.InstallationFailedException) IOException(java.io.IOException) IOException(java.io.IOException) TimeoutException(org.openqa.selenium.TimeoutException) InstallationFailedException(org.jenkinsci.test.acceptance.po.UpdateCenter.InstallationFailedException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) PluginMetadata(org.jenkinsci.test.acceptance.update_center.PluginMetadata) TimeoutException(org.openqa.selenium.TimeoutException)

Aggregations

ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)55 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)24 Artifact (org.eclipse.aether.artifact.Artifact)21 IOException (java.io.IOException)20 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)11 FileNotFoundException (java.io.FileNotFoundException)9 MalformedURLException (java.net.MalformedURLException)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)9 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)9 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)9 Path (java.nio.file.Path)8 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)8 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)8 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