Search in sources :

Example 1 with AbstractArtifactResolutionException

use of org.apache.maven.artifact.resolver.AbstractArtifactResolutionException in project jangaroo-tools by CoreMedia.

the class ExmlToMxmlMojo method resolveExtAsArtifact.

private Artifact resolveExtAsArtifact(String version, String packaging) throws MojoExecutionException {
    Artifact toDownload = artifactFactory.createBuildArtifact("net.jangaroo", "ext-as", version, packaging);
    try {
        getLog().info("Resolving " + toDownload + "...");
        artifactResolver.resolve(toDownload, remoteRepositories, localRepository);
        return toDownload;
    } catch (AbstractArtifactResolutionException e) {
        throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
    }
}
Also used : AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with AbstractArtifactResolutionException

use of org.apache.maven.artifact.resolver.AbstractArtifactResolutionException in project tycho by eclipse.

the class LocalDependencyResolver method addDependencies.

private void addDependencies(MavenSession session, MavenProject project, DefaultDependencyArtifacts platform) {
    TargetPlatformConfiguration configuration = (TargetPlatformConfiguration) project.getContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION);
    if (configuration != null && TargetPlatformConfiguration.POM_DEPENDENCIES_CONSIDER.equals(configuration.getPomDependencies())) {
        Map<String, MavenProject> projectIds = new HashMap<>(session.getProjects().size() * 2);
        // make a list of reactor projects
        for (MavenProject p : session.getProjects()) {
            String key = ArtifactUtils.key(p.getGroupId(), p.getArtifactId(), p.getVersion());
            projectIds.put(key, p);
        }
        // handle dependencies that are in reactor
        for (Dependency dependency : project.getDependencies()) {
            if (Artifact.SCOPE_COMPILE.equals(dependency.getScope())) {
                String key = ArtifactUtils.key(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
                if (projectIds.containsKey(key)) {
                    MavenProject dependent = projectIds.get(key);
                    ArtifactKey artifactKey = getArtifactKey(session, dependent);
                    if (artifactKey != null) {
                        platform.removeAll(artifactKey.getType(), artifactKey.getId());
                        ReactorProject projectProxy = DefaultReactorProject.adapt(dependent);
                        platform.addReactorArtifact(artifactKey, projectProxy, null, null);
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug("Add Maven project " + artifactKey);
                        }
                    }
                }
            }
        }
        // handle rest of dependencies
        ArrayList<String> scopes = new ArrayList<>();
        scopes.add(Artifact.SCOPE_COMPILE);
        Collection<Artifact> artifacts;
        try {
            artifacts = projectDependenciesResolver.resolve(project, scopes, session);
        } catch (MultipleArtifactsNotFoundException e) {
            Collection<Artifact> missing = new HashSet<>(e.getMissingArtifacts());
            for (Iterator<Artifact> it = missing.iterator(); it.hasNext(); ) {
                Artifact a = it.next();
                String key = ArtifactUtils.key(a.getGroupId(), a.getArtifactId(), a.getBaseVersion());
                if (projectIds.containsKey(key)) {
                    it.remove();
                }
            }
            if (!missing.isEmpty()) {
                throw new RuntimeException("Could not resolve project dependencies", e);
            }
            artifacts = e.getResolvedArtifacts();
            artifacts.removeAll(e.getMissingArtifacts());
        } catch (AbstractArtifactResolutionException e) {
            throw new RuntimeException("Could not resolve project dependencies", e);
        }
        for (Artifact artifact : artifacts) {
            String key = ArtifactUtils.key(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion());
            if (!projectIds.containsKey(key)) {
                File plugin = artifact.getFile();
                ArtifactKey artifactKey = getArtifactKey(session, plugin);
                if (artifactKey != null) {
                    platform.addArtifactFile(artifactKey, plugin, null);
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("Add Maven artifact " + artifactKey);
                    }
                }
            }
        }
    }
}
Also used : DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey) ArtifactKey(org.eclipse.tycho.ArtifactKey) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) HashMap(java.util.HashMap) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) ReactorProject(org.eclipse.tycho.ReactorProject) ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) MultipleArtifactsNotFoundException(org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration) Artifact(org.apache.maven.artifact.Artifact) MavenProject(org.apache.maven.project.MavenProject) Iterator(java.util.Iterator) Collection(java.util.Collection) File(java.io.File)

Example 3 with AbstractArtifactResolutionException

use of org.apache.maven.artifact.resolver.AbstractArtifactResolutionException in project hudson-2.x by hudson.

the class HudsonTestCase method recipeLoadCurrentPlugin.

/**
     * If this test harness is launched for a Hudson plugin, locate the <tt>target/test-classes/the.hpl</tt>
     * and add a recipe to install that to the new Hudson.
     *
     * <p>
     * This file is created by <tt>maven-hpi-plugin</tt> at the testCompile phase when the current
     * packaging is <tt>hpi</tt>.
     */
protected void recipeLoadCurrentPlugin() throws Exception {
    final Enumeration<URL> e = getClass().getClassLoader().getResources("the.hpl");
    // nope
    if (!e.hasMoreElements())
        return;
    final URL hpl = e.nextElement();
    recipes.add(new Runner() {

        @Override
        public void decorateHome(HudsonTestCase testCase, File home) throws Exception {
            while (e.hasMoreElements()) {
                final URL hpl = e.nextElement();
                // make the plugin itself available
                Manifest m = new Manifest(hpl.openStream());
                String shortName = m.getMainAttributes().getValue("Short-Name");
                if (shortName == null)
                    throw new Error(hpl + " doesn't have the Short-Name attribute");
                FileUtils.copyURLToFile(hpl, new File(home, "plugins/" + shortName + ".hpl"));
                // make dependency plugins available
                // TODO: probably better to read POM, but where to read from?
                // TODO: this doesn't handle transitive dependencies
                // Tom: plugins are now searched on the classpath first. They should be available on
                // the compile or test classpath. As a backup, we do a best-effort lookup in the Maven repository
                // For transitive dependencies, we could evaluate Plugin-Dependencies transitively.
                String dependencies = m.getMainAttributes().getValue("Plugin-Dependencies");
                if (dependencies != null) {
                    MavenEmbedder embedder = new MavenEmbedder(getClass().getClassLoader(), null);
                    for (String dep : dependencies.split(",")) {
                        String[] tokens = dep.split(":");
                        String artifactId = tokens[0];
                        String version = tokens[1];
                        File dependencyJar = null;
                        // need to search multiple group IDs
                        // TODO: extend manifest to include groupID:artifactID:version
                        Exception resolutionError = null;
                        for (String groupId : new String[] { "org.jvnet.hudson.plugins", "org.jvnet.hudson.main" }) {
                            // first try to find it on the classpath.
                            // this takes advantage of Maven POM located in POM
                            URL dependencyPomResource = getClass().getResource("/META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml");
                            if (dependencyPomResource != null) {
                                // found it
                                dependencyJar = Which.jarFile(dependencyPomResource);
                                break;
                            } else {
                                Artifact a;
                                a = embedder.createArtifact(groupId, artifactId, version, "compile", /*doesn't matter*/
                                "hpi");
                                try {
                                    embedder.resolve(a, Arrays.asList(embedder.createRepository("http://maven.glassfish.org/content/groups/public/", "repo")), embedder.getLocalRepository());
                                    dependencyJar = a.getFile();
                                } catch (AbstractArtifactResolutionException x) {
                                    // could be a wrong groupId
                                    resolutionError = x;
                                }
                            }
                        }
                        if (dependencyJar == null)
                            throw new Exception("Failed to resolve plugin: " + dep, resolutionError);
                        File dst = new File(home, "plugins/" + artifactId + ".hpi");
                        if (!dst.exists() || dst.lastModified() != dependencyJar.lastModified()) {
                            FileUtils.copyFile(dependencyJar, dst);
                        }
                    }
                }
            }
        }
    });
}
Also used : Runner(org.jvnet.hudson.test.recipes.Recipe.Runner) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) Manifest(java.util.jar.Manifest) URL(java.net.URL) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) BadCredentialsException(org.acegisecurity.BadCredentialsException) UsernameNotFoundException(org.acegisecurity.userdetails.UsernameNotFoundException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) CSSParseException(org.w3c.css.sac.CSSParseException) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) AuthenticationException(org.acegisecurity.AuthenticationException) SAXException(org.xml.sax.SAXException) DataAccessException(org.springframework.dao.DataAccessException) CSSException(org.w3c.css.sac.CSSException) MalformedURLException(java.net.MalformedURLException) Artifact(org.apache.maven.artifact.Artifact) MavenEmbedder(hudson.maven.MavenEmbedder) File(java.io.File)

Example 4 with AbstractArtifactResolutionException

use of org.apache.maven.artifact.resolver.AbstractArtifactResolutionException in project sling by apache.

the class BundleInstallFileMojo method resolveBundleFileFromArtifact.

@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
private String resolveBundleFileFromArtifact() throws MojoExecutionException {
    if (artifactId == null && artifact == null) {
        return null;
    }
    if (artifactId == null) {
        String[] tokens = StringUtils.split(artifact, ":");
        if (tokens.length != 3 && tokens.length != 4 && tokens.length != 5) {
            throw new MojoExecutionException("Invalid artifact, you must specify " + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
        }
        groupId = tokens[0];
        artifactId = tokens[1];
        version = tokens[2];
        if (tokens.length >= 4)
            packaging = tokens[3];
        if (tokens.length == 5)
            classifier = tokens[4];
    }
    Artifact packageArtifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, packaging, classifier);
    if (pomRemoteRepositories == null) {
        pomRemoteRepositories = new ArrayList();
    }
    List repoList = new ArrayList(pomRemoteRepositories);
    if (repositoryUrl != null) {
        ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
        ArtifactRepository remoteRepo = artifactRepositoryFactory.createArtifactRepository(repositoryId, repositoryUrl, repositoryLayout, policy, policy);
        repoList.add(remoteRepo);
    }
    try {
        artifactResolver.resolve(packageArtifact, repoList, localRepository);
        getLog().info("Resolved artifact to " + packageArtifact.getFile().getAbsolutePath());
    } catch (AbstractArtifactResolutionException e) {
        throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
    }
    return packageArtifact.getFile().getAbsolutePath();
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact)

Example 5 with AbstractArtifactResolutionException

use of org.apache.maven.artifact.resolver.AbstractArtifactResolutionException in project tycho by eclipse.

the class P2DependencyResolver method collectPomDependencies.

private PomDependencyCollector collectPomDependencies(MavenProject project, List<ReactorProject> reactorProjects, MavenSession session) {
    Set<String> projectIds = new HashSet<>();
    for (ReactorProject p : reactorProjects) {
        String key = ArtifactUtils.key(p.getGroupId(), p.getArtifactId(), p.getVersion());
        projectIds.add(key);
    }
    ArrayList<String> scopes = new ArrayList<>();
    scopes.add(Artifact.SCOPE_COMPILE);
    Collection<Artifact> artifacts;
    try {
        artifacts = projectDependenciesResolver.resolve(project, scopes, session);
    } catch (MultipleArtifactsNotFoundException e) {
        Collection<Artifact> missing = new HashSet<>(e.getMissingArtifacts());
        for (Iterator<Artifact> it = missing.iterator(); it.hasNext(); ) {
            Artifact a = it.next();
            String key = ArtifactUtils.key(a.getGroupId(), a.getArtifactId(), a.getBaseVersion());
            if (projectIds.contains(key)) {
                it.remove();
            }
        }
        if (!missing.isEmpty()) {
            throw new RuntimeException("Could not resolve project dependencies", e);
        }
        artifacts = e.getResolvedArtifacts();
        artifacts.removeAll(e.getMissingArtifacts());
    } catch (AbstractArtifactResolutionException e) {
        throw new RuntimeException("Could not resolve project dependencies", e);
    }
    List<Artifact> externalArtifacts = new ArrayList<>(artifacts.size());
    for (Artifact artifact : artifacts) {
        String key = ArtifactUtils.key(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion());
        if (projectIds.contains(key)) {
            // resolved to an older snapshot from the repo, we only want the current project in the reactor
            continue;
        }
        externalArtifacts.add(artifact);
    }
    PomDependencyProcessor pomDependencyProcessor = new PomDependencyProcessor(session, repositorySystem, resolverFactory, equinox.getService(LocalRepositoryP2Indices.class), getLogger());
    return pomDependencyProcessor.collectPomDependencies(project, externalArtifacts);
}
Also used : AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) ReactorProject(org.eclipse.tycho.ReactorProject) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) ArrayList(java.util.ArrayList) MultipleArtifactsNotFoundException(org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException) Artifact(org.apache.maven.artifact.Artifact) AttachedArtifact(org.eclipse.tycho.p2.facade.internal.AttachedArtifact) LocalRepositoryP2Indices(org.eclipse.tycho.p2.repository.LocalRepositoryP2Indices) Iterator(java.util.Iterator) Collection(java.util.Collection) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Artifact (org.apache.maven.artifact.Artifact)5 AbstractArtifactResolutionException (org.apache.maven.artifact.resolver.AbstractArtifactResolutionException)5 ArrayList (java.util.ArrayList)3 File (java.io.File)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 MultipleArtifactsNotFoundException (org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ReactorProject (org.eclipse.tycho.ReactorProject)2 DefaultReactorProject (org.eclipse.tycho.core.osgitools.DefaultReactorProject)2 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)1 MavenEmbedder (hudson.maven.MavenEmbedder)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1