Example usage for org.apache.maven.artifact.resolver ArtifactResolutionResult getExceptions

List of usage examples for org.apache.maven.artifact.resolver ArtifactResolutionResult getExceptions

Introduction

In this page you can find the example usage for org.apache.maven.artifact.resolver ArtifactResolutionResult getExceptions.

Prototype

public List<Exception> getExceptions() 

Source Link

Usage

From source file:com.clearstorydata.maven.plugins.shadediff.mojo.ShadeDiffMojo.java

License:Apache License

private ArtifactResolutionResult resolveShadedJarToExclude(ShadedJarExclusion excludedShadedJar)
        throws MojoExecutionException {
    Artifact excludedShadedJarArtifact = this.factory.createArtifactWithClassifier(
            excludedShadedJar.getGroupId(), excludedShadedJar.getArtifactId(), excludedShadedJar.getVersion(),
            "jar", excludedShadedJar.getClassifier() == null ? "" : excludedShadedJar.getClassifier());

    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(excludedShadedJarArtifact);
    request.setRemoteRepositories(remoteRepositories);
    request.setLocalRepository(localRepository);
    ArtifactResolutionResult result = artifactResolver.resolve(request);
    for (Exception ex : result.getExceptions()) {
        getLog().error(ex);/*from w ww  .j a va 2  s.c o  m*/
    }
    if (result.hasExceptions()) {
        throw new MojoExecutionException("Artifact resolution failed");
    }
    return result;
}

From source file:com.xpn.xwiki.tool.backup.DataMojo.java

License:Open Source License

private Set<Artifact> resolve(List<ExtensionArtifact> input) throws MojoExecutionException {
    if (input != null) {
        Set<Artifact> artifacts = new LinkedHashSet<>(input.size());
        for (ExtensionArtifact extensionArtifact : input) {
            artifacts.add(this.repositorySystem.createArtifact(extensionArtifact.getGroupId(),
                    extensionArtifact.getArtifactId(), extensionArtifact.getVersion(), null,
                    extensionArtifact.getType()));
        }/*from  w w w .j ava  2s  . c om*/

        ArtifactResolutionRequest request = new ArtifactResolutionRequest()
                .setArtifact(this.project.getArtifact()).setRemoteRepositories(this.remoteRepositories)
                .setArtifactDependencies(artifacts).setLocalRepository(this.localRepository)
                .setManagedVersionMap(this.project.getManagedVersionMap()).setResolveRoot(false);
        ArtifactResolutionResult resolutionResult = this.repositorySystem.resolve(request);
        if (resolutionResult.hasExceptions()) {
            throw new MojoExecutionException(String.format("Failed to resolve artifacts [%s]", input,
                    resolutionResult.getExceptions().get(0)));
        }

        return resolutionResult.getArtifacts();
    }

    return null;
}

From source file:jp.co.tis.gsp.tools.dba.mojo.ImportSchemaMojo.java

License:Apache License

@Override
protected void executeMojoSpec() throws MojoExecutionException, MojoFailureException {
    Dialect dialect = DialectFactory.getDialect(url);
    dialect.dropAll(user, password, adminUser, adminPassword, schema);
    dialect.createUser(user, password, adminUser, adminPassword);

    Artifact artifact = repositorySystem.createArtifact(groupId, artifactId, version, "jar");
    ArtifactResolutionRequest schemaArtifactRequest = new ArtifactResolutionRequest()
            .setRemoteRepositories(project.getRemoteArtifactRepositories()).setArtifact(artifact);
    ArtifactResolutionResult schemaArtifactResult = repositorySystem.resolve(schemaArtifactRequest);
    if (schemaArtifactResult.hasExceptions()) {
        for (Exception e : schemaArtifactResult.getExceptions()) {
            getLog().error("?????????", e);
        }/*w w w  .  j a v a 2s. c  o  m*/
    }

    JarFile jarFile = JarFileUtil
            .create(new File(localRepository.getBasedir(), localRepository.pathOf(artifact)));
    String importFilename = StringUtils.defaultIfEmpty(dmpFile, schema + ".dmp");
    InputStream is = null;
    File importFile = new File(inputDirectory, importFilename);
    JarEntry jarEntry = jarFile.getJarEntry(importFilename);
    if (jarEntry == null)
        throw new MojoExecutionException(importFilename + " is not found?");
    try {
        is = jarFile.getInputStream(jarEntry);
        FileUtils.copyInputStreamToFile(is, importFile);
    } catch (IOException e) {
        throw new MojoExecutionException("", e);
    } finally {
        IOUtils.closeQuietly(is);
    }

    getLog().info("?????:" + importFile);
    dialect.importSchema(user, password, schema, importFile);
    getLog().info("??????");
}

From source file:net.flexmojos.oss.plugin.war.CopyMojo.java

License:Open Source License

public Artifact resolve(String groupId, String artifactId, String version, String classifier, String type)
        throws RuntimeMavenResolutionException {
    Artifact artifact = repositorySystem.createArtifactWithClassifier(groupId, artifactId, version, type,
            classifier);//  w  w  w  .  j av  a  2s  . com
    if (!artifact.isResolved()) {
        ArtifactResolutionRequest req = new ArtifactResolutionRequest();
        req.setArtifact(artifact);
        req.setLocalRepository(localRepository);
        req.setRemoteRepositories(remoteRepositories);
        ArtifactResolutionResult res = repositorySystem.resolve(req);
        if (!res.isSuccess()) {
            if (getLog().isDebugEnabled()) {
                for (Exception e : res.getExceptions()) {
                    getLog().error(e);
                }
            }
            throw new RuntimeMavenResolutionException("Failed to resolve artifact " + artifact, res, artifact);
        }
    }
    return artifact;
}

From source file:org.codehaus.tycho.osgicompiler.AbstractOsgiCompilerMojo.java

License:Apache License

public List<String> getClasspathElements() throws MojoExecutionException {
    TychoProject projectType = getBundleProject();
    List<String> classpath = new ArrayList<String>();
    for (ClasspathEntry cpe : ((BundleProject) projectType).getClasspath(project)) {
        String rules = toString(cpe.getAccessRules());
        for (File location : cpe.getLocations()) {
            classpath.add(location.getAbsolutePath() + rules);
        }/*from  w  w w  .  j  a  va 2  s. c om*/
    }

    if (extraClasspathElements != null) {
        ArtifactRepository localRepository = session.getLocalRepository();
        List<ArtifactRepository> remoteRepositories = project.getRemoteArtifactRepositories();
        for (MavenArtifactRef a : extraClasspathElements) {
            Artifact artifact = repositorySystem.createArtifact(a.getGroupId(), a.getArtifactId(),
                    a.getVersion(), "jar");

            ArtifactResolutionRequest request = new ArtifactResolutionRequest();
            request.setArtifact(artifact);
            request.setLocalRepository(localRepository);
            request.setRemoteRepositories(remoteRepositories);
            request.setResolveRoot(true);
            request.setResolveTransitively(true);
            ArtifactResolutionResult result = repositorySystem.resolve(request);

            if (result.hasExceptions()) {
                throw new MojoExecutionException("Could not resolve extra classpath entry",
                        result.getExceptions().get(0));
            }

            for (Artifact b : result.getArtifacts()) {
                classpath.add(b.getFile().getAbsolutePath() + "[+**/*]");
            }
        }
    }

    return classpath;
}

From source file:org.debian.dependency.DefaultDependencyCollection.java

License:Apache License

private Artifact resolveArtifact(final Artifact toResolve, final MavenSession session)
        throws DependencyResolutionException {
    // otherwise resolve through the normal means
    ArtifactResolutionRequest request = new ArtifactResolutionRequest()
            .setLocalRepository(session.getLocalRepository())
            .setRemoteRepositories(session.getRequest().getRemoteRepositories())
            .setMirrors(session.getSettings().getMirrors()).setServers(session.getRequest().getServers())
            .setProxies(session.getRequest().getProxies()).setOffline(session.isOffline())
            .setForceUpdate(session.getRequest().isUpdateSnapshots()).setResolveRoot(true)
            .setArtifact(toResolve);/* ww  w  .java 2  s.  co  m*/

    ArtifactResolutionResult result = repositorySystem.resolve(request);
    if (!result.isSuccess()) {
        if (result.getExceptions() != null) {
            for (Exception exception : result.getExceptions()) {
                getLogger().error("Error resolving artifact " + toResolve, exception);
            }
        }
        throw new DependencyResolutionException("Unable to resolve artifact " + toResolve);
    }

    return result.getArtifacts().iterator().next();
}

From source file:org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo.java

License:Apache License

public List<ClasspathEntry> getClasspath() throws MojoExecutionException {
    TychoProject projectType = getBundleProject();
    ArrayList<ClasspathEntry> classpath = new ArrayList<ClasspathEntry>(
            ((BundleProject) projectType).getClasspath(project));

    if (extraClasspathElements != null) {
        ArtifactRepository localRepository = session.getLocalRepository();
        List<ArtifactRepository> remoteRepositories = project.getRemoteArtifactRepositories();
        for (MavenArtifactRef a : extraClasspathElements) {
            Artifact artifact = repositorySystem.createArtifact(a.getGroupId(), a.getArtifactId(),
                    a.getVersion(), "jar");

            ArtifactResolutionRequest request = new ArtifactResolutionRequest();
            request.setArtifact(artifact);
            request.setLocalRepository(localRepository);
            request.setRemoteRepositories(remoteRepositories);
            request.setResolveRoot(true);
            request.setResolveTransitively(true);
            ArtifactResolutionResult result = repositorySystem.resolve(request);

            if (result.hasExceptions()) {
                throw new MojoExecutionException("Could not resolve extra classpath entry",
                        result.getExceptions().get(0));
            }/*from w  ww .j  a v  a 2 s  .c o  m*/

            for (Artifact b : result.getArtifacts()) {
                MavenProject bProject = null;
                if (b instanceof ProjectArtifact) {
                    bProject = ((ProjectArtifact) b).getProject();
                }
                ArrayList<File> bLocations = new ArrayList<File>();
                bLocations.add(b.getFile()); // TODO properly handle multiple project locations maybe
                classpath.add(new DefaultClasspathEntry(DefaultReactorProject.adapt(bProject), null, bLocations,
                        null));
            }
        }
    }
    return classpath;
}

From source file:org.eclipse.tycho.p2.facade.internal.MavenRepositoryReader.java

License:Open Source License

public InputStream getContents(GAV gav, String classifier, String extension) throws IOException {
    Artifact a = repositorySystem.createArtifactWithClassifier(gav.getGroupId(), gav.getArtifactId(),
            gav.getVersion(), extension, classifier);

    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(a);//from w w  w  .  ja va2s.  co  m
    request.setLocalRepository(localRepository);
    request.setRemoteRepositories(repositories);
    ArtifactResolutionResult result = repositorySystem.resolve(request);

    if (!a.isResolved()) {
        IOException exception = new IOException("Could not resolve artifact");
        if (result.hasExceptions()) {
            exception.initCause(result.getExceptions().get(0));
        }
        throw exception;
    }

    return new FileInputStream(a.getFile());
}

From source file:org.fusesource.mop.MOPRepository.java

License:Open Source License

public Set<Artifact> resolveArtifacts(ArtifactFilter filter, final ArtifactId id)
        throws Exception, InvalidRepositoryException {
    debug("Resolving artifact " + id);

    RepositorySystem repositorySystem = (RepositorySystem) getContainer().lookup(RepositorySystem.class);

    List<ArtifactRepository> remoteRepositories = createRemoteRepositories(repositorySystem);
    ArtifactRepository localRepository = createLocalRepository(repositorySystem, "mop.local",
            getLocalRepo().getAbsolutePath(), false);

    // If group id is not set.. we can still look it up in the db
    // of installed artifacs.
    if (id.getGroupId() == null) {
        database(true, new DBCallback() {
            public void execute(Database database) throws Exception {

                // Makes groupId includeOptional.. we look it up in the database.
                if (id.getGroupId() == null) {
                    Map<String, Set<String>> rc = Database
                            .groupByGroupId(database.findByArtifactId(id.getArtifactId()));
                    if (rc.isEmpty()) {
                        throw new Exception(
                                "Please qualify a group id: No local artifacts match: " + id.getArtifactId());
                    }// ww  w .  j a  v  a 2 s  .co m
                    if (rc.size() > 1) {
                        System.out.println("Local artifacts that match:");
                        for (String s : rc.keySet()) {
                            System.out.println("   " + s + ":" + id.getArtifactId());
                        }
                        throw new Exception("Please qualify a group id: Multiple local artifacts match: " + id);
                    }
                    id.setGroupId(rc.keySet().iterator().next());
                    debug("Resolving artifact " + id);
                }

            }
        });
    }

    if (online) {

        // Keep track that we are trying an install..
        // If an install dies midway.. the repo will have partlly installed dependencies...
        // we may want to continue the install??
        // database.beginInstall(id.toString());

    }

    Artifact artifact = repositorySystem.createArtifactWithClassifier(id.getGroupId(), id.getArtifactId(),
            id.getVersion(), id.getType(), id.getClassifier());

    // Setup the filters which will constrain the resulting dependencies..
    List<ArtifactFilter> constraints = new ArrayList<ArtifactFilter>();
    constraints.add(new ScopeArtifactFilter(scope));
    if (!includeOptional) {
        constraints.add(new ArtifactFilter() {
            public boolean include(Artifact artifact) {
                return !artifact.isOptional();
            }
        });
    }
    if (filter != null) {
        constraints.add(filter);
    }

    ArtifactFilter filters = new AndArtifactFilter(constraints);

    ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(artifact)
            .setResolveRoot(true).setResolveTransitively(isTransitive()).setLocalRepository(localRepository)
            .setRemoteRepositories(remoteRepositories).setOffline(!online).setCollectionFilter(filters);

    ArtifactResolutionResult result = repositorySystem.resolve(request);

    List<Artifact> list = result.getMissingArtifacts();
    if (!list.isEmpty()) {
        throw new Exception("The following artifacts could not be downloaded: " + list);
    }

    if (/* result.getArtifacts().isEmpty() && */!result.getExceptions().isEmpty()) {
        throw new Exception("Error resolving artifact " + artifact, result.getExceptions().get(0));
    }

    Set<Artifact> rc = result.getArtifacts();
    if (online) {
        // Have the DB index the installed the artifacts.
        final LinkedHashSet<String> installed = new LinkedHashSet<String>();
        for (Artifact a : rc) {
            installed.add(a.getId());
        }
        database(false, new DBCallback() {
            public void execute(Database database) throws Exception {
                database.install(installed);
            }
        });
    }

    debug("  Resolved: " + id);
    for (Artifact a : rc) {
        debug("    depends on: " + a.getId() + ", scope: " + a.getScope() + ", optional: " + a.isOptional()
                + ", file: " + a.getFile());
    }

    return rc;

}

From source file:org.phenotips.tool.packager.PackageMojo.java

License:Open Source License

private Set<Artifact> resolveTransitively(Set<Artifact> artifacts) throws MojoExecutionException {
    AndArtifactFilter filter = new AndArtifactFilter(Arrays.asList(new ScopeArtifactFilter("runtime"),
            // - Exclude JCL and LOG4J since we want all logging to go through SLF4J. Note that we're excluding
            // log4j-<version>.jar but keeping log4j-over-slf4j-<version>.jar
            // - Exclude batik-js to prevent conflict with the patched version of Rhino used by yuicompressor used
            // for JSX. See http://jira.xwiki.org/jira/browse/XWIKI-6151 for more details.
            new ExcludesArtifactFilter(Arrays.asList("org.apache.xmlgraphic:batik-js",
                    "org.slf4j:slf4j-log4j12", "commons-logging:commons-logging",
                    "commons-logging:commons-logging-api", "log4j:log4j", "com.bea.xml:jsr173-ri"))));

    ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(this.project.getArtifact())
            .setArtifactDependencies(artifacts).setCollectionFilter(filter)
            .setRemoteRepositories(this.remoteRepositories).setLocalRepository(this.localRepository)
            .setManagedVersionMap(getManagedVersionMap()).setResolveRoot(false).setResolveTransitively(true);
    ArtifactResolutionResult resolutionResult = this.repositorySystem.resolve(request);
    if (resolutionResult.hasExceptions()) {
        throw new MojoExecutionException(String.format("Failed to resolve artifacts [%s]", artifacts,
                resolutionResult.getExceptions().get(0)));
    }/*from ww  w  .j  a  v  a  2  s. c  om*/

    return resolutionResult.getArtifacts();
}