Search in sources :

Example 6 with ArtifactNotFoundException

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

the class ResourceResolver method resolveBundlesFromArtifacts.

private List<JavadocBundle> resolveBundlesFromArtifacts(final SourceResolverConfig config, final List<Artifact> artifacts) throws IOException {
    final List<Artifact> toResolve = new ArrayList<Artifact>(artifacts.size());
    for (final Artifact artifact : artifacts) {
        if (config.filter() != null && !new ArtifactIncludeFilterTransformer().transform(config.filter()).include(artifact)) {
            continue;
        }
        if (config.includeCompileSources()) {
            toResolve.add(createResourceArtifact(artifact, AbstractJavadocMojo.JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER, config));
        }
        if (config.includeTestSources()) {
            toResolve.add(createResourceArtifact(artifact, AbstractJavadocMojo.TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER, config));
        }
    }
    List<String> dirs = null;
    try {
        dirs = resolveAndUnpack(toResolve, config, RESOURCE_VALID_CLASSIFIERS, false);
    } catch (ArtifactResolutionException e) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(e.getMessage(), e);
        }
    } catch (ArtifactNotFoundException e) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(e.getMessage(), e);
        }
    }
    List<JavadocBundle> result = new ArrayList<JavadocBundle>();
    if (dirs != null) {
        for (String d : dirs) {
            File dir = new File(d);
            File resources = new File(dir, ResourcesBundleMojo.RESOURCES_DIR_PATH);
            JavadocOptions options = null;
            File javadocOptions = new File(dir, ResourcesBundleMojo.BUNDLE_OPTIONS_PATH);
            if (javadocOptions.exists()) {
                FileInputStream reader = null;
                try {
                    reader = new FileInputStream(javadocOptions);
                    options = new JavadocOptionsXpp3Reader().read(reader);
                } catch (XmlPullParserException e) {
                    IOException error = new IOException("Failed to parse javadoc options: " + e.getMessage());
                    error.initCause(e);
                    throw error;
                } finally {
                    close(reader);
                }
            }
            result.add(new JavadocBundle(options, resources));
        }
    }
    return result;
}
Also used : ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) FileInputStream(java.io.FileInputStream) JavadocOptionsXpp3Reader(org.apache.maven.plugin.javadoc.options.io.xpp3.JavadocOptionsXpp3Reader) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) JavadocOptions(org.apache.maven.plugin.javadoc.options.JavadocOptions) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) File(java.io.File)

Example 7 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException 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)

Example 8 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException 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 9 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException in project tomee by apache.

the class JarsTxtMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (!outputFile.getParentFile().exists()) {
        FileUtils.mkdir(outputFile.getParentFile().getAbsolutePath());
    }
    FileWriter writer = null;
    try {
        writer = new FileWriter(outputFile);
        final TreeSet<String> set = new TreeSet<>();
        for (final Artifact a : (Set<Artifact>) project.getArtifacts()) {
            if (!acceptScope(a.getScope()) || !acceptType(a.getType())) {
                continue;
            }
            a.setScope(Artifact.SCOPE_PROVIDED);
            final StringBuilder line = new StringBuilder("mvn:").append(a.getGroupId()).append("/").append(a.getArtifactId()).append("/").append(version(a));
            final boolean isJar = JAR.equals(a.getType());
            if (!isJar) {
                line.append("/").append(a.getType());
            }
            if (a.getClassifier() != null) {
                if (isJar) {
                    line.append("/").append(JAR);
                }
                line.append("/").append(a.getClassifier());
            }
            if (hashAlgo != null) {
                final Artifact artifact = factory.createDependencyArtifact(a.getGroupId(), a.getArtifactId(), VersionRange.createFromVersion(a.getVersion()), a.getType(), a.getClassifier(), a.getScope());
                try {
                    resolver.resolve(artifact, remoteRepos, local);
                } catch (final ArtifactResolutionException | ArtifactNotFoundException e) {
                    throw new MojoExecutionException(e.getMessage(), e);
                }
                final File file = artifact.getFile();
                line.append("|").append(Files.hash((Set<URL>) Collections.singleton(file.toURI().toURL()), hashAlgo)).append("|").append(hashAlgo);
            }
            set.add(line.toString());
        }
        if (additionals != null) {
            if (placeHolders == null) {
                placeHolders = new HashMap<>();
            }
            final StrSubstitutor lookup = new StrSubstitutor(StrLookup.mapLookup(placeHolders));
            for (final String line : additionals) {
                final StringBuilder builder = new StringBuilder(line);
                if (hashAlgo != null) {
                    builder.append("|").append(Files.hash(urls(line, lookup), hashAlgo)).append("|").append(hashAlgo);
                }
                set.add(builder.toString());
            }
        }
        // written after to be sorted, more readable
        for (final String line : set) {
            writer.write(line);
            writer.write("\n");
        }
        writer.flush();
    } catch (final IOException e) {
        getLog().error(e.getMessage(), e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (final IOException e) {
            // no-op
            }
        }
    }
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileWriter(java.io.FileWriter) IOException(java.io.IOException) Artifact(org.apache.maven.artifact.Artifact) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) TreeSet(java.util.TreeSet) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) File(java.io.File)

Example 10 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException in project tomee by apache.

the class AbstractTomEEMojo method getAdditionalClasspath.

protected String getAdditionalClasspath() {
    if (!classpaths.isEmpty()) {
        final StringBuilder cpBuilder = new StringBuilder();
        for (final String cp : classpaths) {
            final String[] split = cp.split(":");
            if (split.length >= 3) /*GAV*/
            {
                final FileWithMavenMeta jar;
                try {
                    jar = resolve(split[0], split[1], split[2], split.length > 4 ? split[4] : null, split.length > 3 ? split[3] : "jar");
                } catch (final ArtifactResolutionException | ArtifactNotFoundException e) {
                    throw new IllegalArgumentException(e);
                }
                final File classpathRoot = new File(catalinaBase, "boot");
                if (!classpathRoot.isDirectory()) {
                    mkdirs(classpathRoot);
                }
                final File target = new File(classpathRoot, stripVersion ? jar.stripVersion(true) : jar.resolved.getName());
                try {
                    IO.copy(jar.resolved, target);
                } catch (final IOException e) {
                    throw new IllegalArgumentException(e);
                }
                cpBuilder.append("${openejb.base}/boot/").append(target.getName());
            } else {
                // else plain path
                cpBuilder.append(cp);
            }
            if (classpathSeparator == null) {
                classpathSeparator = File.pathSeparator;
            }
            cpBuilder.append(classpathSeparator);
        }
        // Dump the final path separator
        return cpBuilder.substring(0, cpBuilder.length() - 1);
    }
    return null;
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) IOException(java.io.IOException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)20 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)20 Artifact (org.apache.maven.artifact.Artifact)15 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 File (java.io.File)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)2 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)2 ArtifactMetadataRetrievalException (org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)2 SnapshotArtifactRepositoryMetadata (org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata)2 AbstractArtifactResolutionException (org.apache.maven.artifact.resolver.AbstractArtifactResolutionException)2 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)2 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2 VersionRange (org.apache.maven.artifact.versioning.VersionRange)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 MavenProject (org.apache.maven.project.MavenProject)2 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)2 MavenReportException (org.apache.maven.reporting.MavenReportException)2 TransformableFilter (org.apache.maven.shared.artifact.filter.resolve.TransformableFilter)2