use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.
the class AbstractJavadocMojo method copyAdditionalJavadocResources.
/**
* Method that copy additional Javadoc resources from given artifacts.
*
* @param anOutputDirectory the output directory
* @throws MavenReportException if any
* @see #resourcesArtifacts
*/
private void copyAdditionalJavadocResources(File anOutputDirectory) throws MavenReportException {
Set<ResourcesArtifact> resourcesArtifacts = collectResourcesArtifacts();
if (isEmpty(resourcesArtifacts)) {
return;
}
UnArchiver unArchiver;
try {
unArchiver = archiverManager.getUnArchiver("jar");
} catch (NoSuchArchiverException e) {
throw new MavenReportException("Unable to extract resources artifact. " + "No archiver for 'jar' available.", e);
}
for (ResourcesArtifact item : resourcesArtifacts) {
Artifact artifact;
try {
artifact = createAndResolveArtifact(item);
} catch (ArtifactResolverException e) {
throw new MavenReportException("Unable to resolve artifact:" + item, e);
}
unArchiver.setSourceFile(artifact.getFile());
unArchiver.setDestDirectory(anOutputDirectory);
// remove the META-INF directory from resource artifact
IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
selectors[0].setExcludes(new String[] { "META-INF/**" });
unArchiver.setFileSelectors(selectors);
getLog().info("Extracting contents of resources artifact: " + artifact.getArtifactId());
try {
unArchiver.extract();
} catch (ArchiverException e) {
throw new MavenReportException("Extraction of resources failed. Artifact that failed was: " + artifact.getArtifactId(), e);
}
}
}
use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.
the class AbstractJavadocMojo method getDependenciesLinks.
/**
* Using Maven, a Javadoc link is given by <code>${project.url}/apidocs</code>.
*
* @return the detected Javadoc links using the Maven conventions for all dependencies defined in the current
* project or an empty list.
* @see #detectLinks
* @see #isValidJavadocLink(String)
* @since 2.6
*/
private List<String> getDependenciesLinks() {
if (!detectLinks) {
return Collections.emptyList();
}
getLog().debug("Trying to add links for dependencies...");
List<String> dependenciesLinks = new ArrayList<String>();
final Set<Artifact> dependencies = project.getDependencyArtifacts();
for (Artifact artifact : dependencies) {
if (artifact.getFile() == null || !artifact.getFile().exists()) {
continue;
}
try {
MavenProject artifactProject = mavenProjectBuilder.build(artifact, session.getProjectBuildingRequest()).getProject();
if (StringUtils.isNotEmpty(artifactProject.getUrl())) {
String url = getJavadocLink(artifactProject);
if (isValidJavadocLink(url, true)) {
getLog().debug("Added Javadoc link: " + url + " for " + artifactProject.getId());
dependenciesLinks.add(url);
}
}
} catch (ProjectBuildingException e) {
logError("ProjectBuildingException for " + artifact.toString() + ": " + e.getMessage(), e);
}
}
return dependenciesLinks;
}
use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.
the class ResourceResolver method resolveDependencyJavadocBundles.
/**
* @param config {@link SourceResolverConfig}
* @return list of {@link JavadocBundle}.
* @throws IOException {@link IOException}
*/
public List<JavadocBundle> resolveDependencyJavadocBundles(final SourceResolverConfig config) throws IOException {
final List<JavadocBundle> bundles = new ArrayList<JavadocBundle>();
final Map<String, MavenProject> projectMap = new HashMap<String, MavenProject>();
if (config.reactorProjects() != null) {
for (final MavenProject p : config.reactorProjects()) {
projectMap.put(key(p.getGroupId(), p.getArtifactId()), p);
}
}
final List<Artifact> artifacts = config.project().getTestArtifacts();
final List<Artifact> forResourceResolution = new ArrayList<Artifact>(artifacts.size());
for (final Artifact artifact : artifacts) {
final String key = key(artifact.getGroupId(), artifact.getArtifactId());
final MavenProject p = projectMap.get(key);
if (p != null) {
bundles.addAll(resolveBundleFromProject(config, p, artifact));
} else {
forResourceResolution.add(artifact);
}
}
bundles.addAll(resolveBundlesFromArtifacts(config, forResourceResolution));
return bundles;
}
use of org.apache.maven.artifact.Artifact 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.Artifact in project maven-plugins by apache.
the class ResourceResolver method resolveAndUnpack.
private List<String> resolveAndUnpack(final List<Artifact> artifacts, final SourceResolverConfig config, final List<String> validClassifiers, final boolean propagateErrors) throws ArtifactResolutionException, ArtifactNotFoundException {
// NOTE: Since these are '-sources' and '-test-sources' artifacts, they won't actually
// resolve transitively...this is just used to aggregate resolution failures into a single
// exception.
final Set<Artifact> artifactSet = new LinkedHashSet<Artifact>(artifacts);
final Artifact pomArtifact = config.project().getArtifact();
final ArtifactRepository localRepo = config.localRepository();
final List<ArtifactRepository> remoteRepos = config.project().getRemoteArtifactRepositories();
final ArtifactFilter filter;
if (config.filter() != null) {
filter = new ArtifactIncludeFilterTransformer().transform(config.filter());
} else {
filter = null;
}
ArtifactFilter resolutionFilter = null;
if (filter != null) {
// Wrap the filter in a ProjectArtifactFilter in order to always include the pomArtifact for resolution.
// NOTE that this is necessary, b/c the -sources artifacts are added dynamically to the pomArtifact
// and the resolver also checks the dependency trail with the given filter, thus the pomArtifact has
// to be explicitly included by the filter, otherwise the -sources artifacts won't be resolved.
resolutionFilter = new ProjectArtifactFilter(pomArtifact, filter);
}
Map<String, Artifact> managed = config.project().getManagedVersionMap();
final ArtifactResolutionResult resolutionResult = resolver.resolveTransitively(artifactSet, pomArtifact, managed, localRepo, remoteRepos, artifactMetadataSource, resolutionFilter);
final List<String> result = new ArrayList<String>(artifacts.size());
for (final Artifact a : (Collection<Artifact>) resolutionResult.getArtifacts()) {
if (!validClassifiers.contains(a.getClassifier()) || (filter != null && !filter.include(a))) {
continue;
}
final File d = new File(config.outputBasedir(), a.getArtifactId() + "-" + a.getVersion() + "-" + a.getClassifier());
if (!d.exists()) {
d.mkdirs();
}
try {
final UnArchiver unArchiver = archiverManager.getUnArchiver(a.getType());
unArchiver.setDestDirectory(d);
unArchiver.setSourceFile(a.getFile());
unArchiver.extract();
result.add(d.getAbsolutePath());
} catch (final NoSuchArchiverException e) {
if (propagateErrors) {
throw new ArtifactResolutionException("Failed to retrieve valid un-archiver component: " + a.getType(), a, e);
}
} catch (final ArchiverException e) {
if (propagateErrors) {
throw new ArtifactResolutionException("Failed to unpack: " + a.getId(), a, e);
}
}
}
return result;
}
Aggregations