Search in sources :

Example 6 with ArtifactResolutionException

use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project felix by apache.

the class BundleAllPlugin method resolveArtifact.

private Artifact resolveArtifact(Artifact artifact) throws MojoExecutionException, ArtifactNotFoundException {
    VersionRange versionRange;
    if (artifact.getVersion() != null) {
        versionRange = VersionRange.createFromVersion(artifact.getVersion());
    } else {
        versionRange = artifact.getVersionRange();
    }
    /*
         * there's a bug with ArtifactFactory#createDependencyArtifact(String, String, VersionRange,
         * String, String, String) that ignores the scope parameter, that's why we use the one with
         * the extra null parameter
         */
    Artifact resolvedArtifact = m_factory.createDependencyArtifact(artifact.getGroupId(), artifact.getArtifactId(), versionRange, artifact.getType(), artifact.getClassifier(), artifact.getScope(), null);
    try {
        m_artifactResolver.resolve(resolvedArtifact, remoteRepositories, localRepository);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("Error resolving artifact " + resolvedArtifact, e);
    }
    return resolvedArtifact;
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Artifact(org.apache.maven.artifact.Artifact)

Example 7 with ArtifactResolutionException

use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project midpoint by Evolveum.

the class SchemaDistMojo method getArtifact.

protected Artifact getArtifact(ArtifactItem artifactItem) throws MojoExecutionException, InvalidVersionSpecificationException {
    Artifact artifact;
    VersionRange vr = VersionRange.createFromVersionSpec(artifactItem.getVersion());
    if (StringUtils.isEmpty(artifactItem.getClassifier())) {
        artifact = factory.createDependencyArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), vr, artifactItem.getType(), null, Artifact.SCOPE_COMPILE);
    } else {
        artifact = factory.createDependencyArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), vr, artifactItem.getType(), artifactItem.getClassifier(), Artifact.SCOPE_COMPILE);
    }
    try {
        resolver.resolve(artifact, remoteRepos, local);
    } catch (ArtifactResolutionException | ArtifactNotFoundException e) {
        throw new MojoExecutionException("Error resolving artifact " + artifact, e);
    }
    return artifact;
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) VersionRange(org.apache.maven.artifact.versioning.VersionRange) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) Artifact(org.apache.maven.artifact.Artifact)

Example 8 with ArtifactResolutionException

use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project maven-plugins by apache.

the class ProcessRemoteResourcesMojo method downloadBundles.

private List<File> downloadBundles(List<String> bundles) throws MojoExecutionException {
    List<File> bundleArtifacts = new ArrayList<File>();
    try {
        for (String artifactDescriptor : bundles) {
            // groupId:artifactId:version[:type[:classifier]]
            String[] s = artifactDescriptor.split(":");
            File artifactFile = null;
            // check if the artifact is part of the reactor
            if (mavenSession != null) {
                List<MavenProject> list = mavenSession.getSortedProjects();
                for (MavenProject p : list) {
                    if (s[0].equals(p.getGroupId()) && s[1].equals(p.getArtifactId()) && s[2].equals(p.getVersion())) {
                        if (s.length >= 4 && "test-jar".equals(s[3])) {
                            artifactFile = new File(p.getBuild().getTestOutputDirectory());
                        } else {
                            artifactFile = new File(p.getBuild().getOutputDirectory());
                        }
                    }
                }
            }
            if (artifactFile == null || !artifactFile.exists()) {
                String type = (s.length >= 4 ? s[3] : "jar");
                String classifier = (s.length == 5 ? s[4] : null);
                Artifact artifact = artifactFactory.createDependencyArtifact(s[0], s[1], VersionRange.createFromVersion(s[2]), type, classifier, Artifact.SCOPE_RUNTIME);
                artifactResolver.resolve(artifact, remoteArtifactRepositories, localRepository);
                artifactFile = artifact.getFile();
            }
            bundleArtifacts.add(artifactFile);
        }
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("Error downloading resources archive.", e);
    } catch (ArtifactNotFoundException e) {
        throw new MojoExecutionException("Resources archive cannot be found.", e);
    }
    return bundleArtifacts;
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) File(java.io.File) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) Artifact(org.apache.maven.artifact.Artifact)

Example 9 with ArtifactResolutionException

use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project maven-plugins by apache.

the class BundlePackMojo method execute.

@SuppressWarnings("unchecked")
public void execute() throws MojoExecutionException {
    readArtifactDataFromUser();
    Artifact artifact = artifactFactory.createProjectArtifact(groupId, artifactId, version);
    try {
        artifactResolver.resolve(artifact, Collections.EMPTY_LIST, localRepository);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("Unable to resolve artifact " + artifact.getId(), e);
    } catch (ArtifactNotFoundException e) {
        throw new MojoExecutionException("Artifact " + artifact.getId() + " not found in local repository", e);
    }
    File pom = artifact.getFile();
    File dir = pom.getParentFile();
    Model model = readPom(pom);
    boolean rewrite = false;
    try {
        if (model.getPackaging() == null) {
            model.setPackaging("jar");
            rewrite = true;
        }
        if (model.getName() == null) {
            getLog().info("Project name is missing, please type the project name [" + artifactId + "]:");
            model.setName(inputHandler.readLine());
            if (model.getName() == null) {
                model.setName(artifactId);
            }
            rewrite = true;
        }
        if (model.getDescription() == null) {
            getLog().info("Project description is missing, please type the project description:");
            model.setDescription(inputHandler.readLine());
            rewrite = true;
        }
        if (model.getUrl() == null) {
            getLog().info("Project URL is missing, please type the project URL:");
            model.setUrl(inputHandler.readLine());
            rewrite = true;
        }
        List<License> licenses = model.getLicenses();
        if (licenses.isEmpty()) {
            License license = new License();
            getLog().info("License name is missing, please type the license name:");
            license.setName(inputHandler.readLine());
            getLog().info("License URL is missing, please type the license URL:");
            license.setUrl(inputHandler.readLine());
            licenses.add(license);
            rewrite = true;
        }
        if (disableMaterialization) {
            getLog().warn("Validations to confirm support for project materialization have been DISABLED." + "\n\nYour project may not provide the POM elements necessary to allow " + "users to retrieve sources on-demand," + "\nor to easily checkout your project in an IDE. " + "THIS CAN SERIOUSLY INCONVENIENCE YOUR USERS.\n\nContinue? [y/N]");
            try {
                if ('y' != inputHandler.readLine().toLowerCase().charAt(0)) {
                    disableMaterialization = false;
                }
            } catch (IOException e) {
                getLog().debug("Error reading confirmation: " + e.getMessage(), e);
            }
        }
        if (!disableMaterialization) {
            Scm scm = model.getScm();
            if (scm == null) {
                scm = new Scm();
                model.setScm(scm);
            }
            if (scm.getUrl() == null) {
                if (scmUrl != null) {
                    scm.setUrl(scmUrl);
                } else {
                    getLog().info("SCM view URL is missing, please type the URL for the viewable SCM interface:");
                    scm.setUrl(inputHandler.readLine());
                    rewrite = true;
                }
            }
            if (scm.getConnection() == null) {
                if (scmConnection != null) {
                    scm.setConnection(scmConnection);
                } else {
                    getLog().info("SCM read-only connection URL is missing, please type the read-only SCM URL:");
                    scm.setConnection(inputHandler.readLine());
                    rewrite = true;
                }
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    try {
        if (rewrite) {
            new MavenXpp3Writer().write(WriterFactory.newXmlWriter(pom), model);
        }
        String finalName = null;
        if (model.getBuild() != null) {
            finalName = model.getBuild().getFinalName();
        }
        if (finalName == null) {
            finalName = model.getArtifactId() + "-" + model.getVersion();
        }
        boolean batchMode = settings == null ? false : !settings.isInteractiveMode();
        List<File> files = BundleUtils.selectProjectFiles(dir, inputHandler, finalName, pom, getLog(), batchMode);
        File bundle = new File(basedir, finalName + "-bundle.jar");
        jarArchiver.addFile(pom, POM);
        boolean artifactChecks = !"pom".equals(model.getPackaging());
        boolean sourcesFound = false;
        boolean javadocsFound = false;
        for (File f : files) {
            if (artifactChecks && f.getName().endsWith(finalName + "-sources.jar")) {
                sourcesFound = true;
            } else if (artifactChecks && f.getName().equals(finalName + "-javadoc.jar")) {
                javadocsFound = true;
            }
            jarArchiver.addFile(f, f.getName());
        }
        if (artifactChecks && !sourcesFound) {
            getLog().warn("Sources not included in upload bundle.");
        }
        if (artifactChecks && !javadocsFound) {
            getLog().warn("Javadoc not included in upload bundle.");
        }
        jarArchiver.setDestFile(bundle);
        jarArchiver.createArchive();
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (ArchiverException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) License(org.apache.maven.model.License) IOException(java.io.IOException) Artifact(org.apache.maven.artifact.Artifact) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) Model(org.apache.maven.model.Model) Scm(org.apache.maven.model.Scm) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) File(java.io.File) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer)

Example 10 with ArtifactResolutionException

use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project maven-plugins by apache.

the class RepositoryUtils method getDependencyUrlFromRepository.

/**
 * @param artifact not null
 * @param repo not null
 * @return the artifact url in the given repo for the given artifact. If it is a snapshot artifact, the version
 * will be the timestamp and the build number from the metadata. Could return null if the repo is blacklisted.
 */
public String getDependencyUrlFromRepository(Artifact artifact, ArtifactRepository repo) {
    if (repo.isBlacklisted()) {
        return null;
    }
    Artifact copyArtifact = ArtifactUtils.copyArtifact(artifact);
    // Try to get the last artifact repo name depending the snapshot version
    if ((artifact.isSnapshot() && repo.getSnapshots().isEnabled())) {
        if (artifact.getBaseVersion().equals(artifact.getVersion())) {
            // Try to resolve it if not already done
            if (artifact.getMetadataList() == null || artifact.getMetadataList().isEmpty()) {
                try {
                    resolve(artifact);
                } catch (ArtifactResolutionException e) {
                    log.error("Artifact: " + artifact.getId() + " could not be resolved.");
                } catch (ArtifactNotFoundException e) {
                    log.error("Artifact: " + artifact.getId() + " was not found.");
                }
            }
            for (ArtifactMetadata m : artifact.getMetadataList()) {
                if (m instanceof SnapshotArtifactRepositoryMetadata) {
                    SnapshotArtifactRepositoryMetadata snapshotMetadata = (SnapshotArtifactRepositoryMetadata) m;
                    Metadata metadata = snapshotMetadata.getMetadata();
                    Versioning versioning = metadata.getVersioning();
                    if (versioning == null || versioning.getSnapshot() == null || versioning.getSnapshot().isLocalCopy() || versioning.getSnapshot().getTimestamp() == null) {
                        continue;
                    }
                    // create the version according SnapshotTransformation
                    String version = StringUtils.replace(copyArtifact.getVersion(), Artifact.SNAPSHOT_VERSION, versioning.getSnapshot().getTimestamp()) + "-" + versioning.getSnapshot().getBuildNumber();
                    copyArtifact.setVersion(version);
                }
            }
        }
    }
    return repo.getUrl() + "/" + repo.pathOf(copyArtifact);
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) ArtifactMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ArtifactMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)35 Artifact (org.apache.maven.artifact.Artifact)27 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)27 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)15 ArrayList (java.util.ArrayList)12 File (java.io.File)10 IOException (java.io.IOException)8 ArtifactIncludeFilterTransformer (org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer)7 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)6 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)5 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)5 MojoFailureException (org.apache.maven.plugin.MojoFailureException)5 TransformableFilter (org.apache.maven.shared.artifact.filter.resolve.TransformableFilter)5 VersionRange (org.apache.maven.artifact.versioning.VersionRange)4 Dependency (org.apache.maven.model.Dependency)4 HashMap (java.util.HashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 ArtifactMetadataRetrievalException (org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)3 MavenProject (org.apache.maven.project.MavenProject)3 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)3