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;
}
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);
}
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;
}
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
}
}
}
}
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;
}
Aggregations