use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException 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.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.
the class AbstractJavadocMojo method addTagletsFromTagletArtifacts.
/**
* Auto-detect taglets class name from <code>tagletArtifacts</code> and add them to arguments.
*
* @param arguments not null
* @throws MavenReportException if any
* @see JavadocUtil#getTagletClassNames(File)
*/
private void addTagletsFromTagletArtifacts(List<String> arguments) throws MavenReportException {
Set<TagletArtifact> tArtifacts = new LinkedHashSet<TagletArtifact>();
if (tagletArtifacts != null && tagletArtifacts.length > 0) {
tArtifacts.addAll(Arrays.asList(tagletArtifacts));
}
if (includeDependencySources) {
try {
resolveDependencyBundles();
} catch (IOException e) {
throw new MavenReportException("Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e);
}
if (isNotEmpty(dependencyJavadocBundles)) {
for (JavadocBundle bundle : dependencyJavadocBundles) {
JavadocOptions options = bundle.getOptions();
if (options != null && isNotEmpty(options.getTagletArtifacts())) {
tArtifacts.addAll(options.getTagletArtifacts());
}
}
}
}
if (isEmpty(tArtifacts)) {
return;
}
List<String> tagletsPath = new ArrayList<String>();
for (TagletArtifact aTagletArtifact : tArtifacts) {
if ((StringUtils.isNotEmpty(aTagletArtifact.getGroupId())) && (StringUtils.isNotEmpty(aTagletArtifact.getArtifactId())) && (StringUtils.isNotEmpty(aTagletArtifact.getVersion()))) {
Artifact artifact;
try {
artifact = createAndResolveArtifact(aTagletArtifact);
} catch (ArtifactResolverException e) {
throw new MavenReportException("Unable to resolve artifact:" + aTagletArtifact, e);
}
tagletsPath.add(artifact.getFile().getAbsolutePath());
}
}
tagletsPath = JavadocUtil.pruneFiles(tagletsPath);
for (String tagletJar : tagletsPath) {
if (!tagletJar.toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
continue;
}
List<String> tagletClasses;
try {
tagletClasses = JavadocUtil.getTagletClassNames(new File(tagletJar));
} catch (IOException e) {
if (getLog().isWarnEnabled()) {
getLog().warn("Unable to auto-detect Taglet class names from '" + tagletJar + "'. Try to specify them with <taglets/>.");
}
if (getLog().isDebugEnabled()) {
getLog().debug("IOException: " + e.getMessage(), e);
}
continue;
} catch (ClassNotFoundException e) {
if (getLog().isWarnEnabled()) {
getLog().warn("Unable to auto-detect Taglet class names from '" + tagletJar + "'. Try to specify them with <taglets/>.");
}
if (getLog().isDebugEnabled()) {
getLog().debug("ClassNotFoundException: " + e.getMessage(), e);
}
continue;
} catch (NoClassDefFoundError e) {
if (getLog().isWarnEnabled()) {
getLog().warn("Unable to auto-detect Taglet class names from '" + tagletJar + "'. Try to specify them with <taglets/>.");
}
if (getLog().isDebugEnabled()) {
getLog().debug("NoClassDefFoundError: " + e.getMessage(), e);
}
continue;
}
if (tagletClasses != null && !tagletClasses.isEmpty()) {
for (String tagletClass : tagletClasses) {
addArgIfNotEmpty(arguments, "-taglet", JavadocUtil.quotedArgument(tagletClass), SINCE_JAVADOC_1_4);
}
}
}
}
use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.
the class AbstractJavadocMojo method resolveDependency.
/**
* @param dependency {@link Dependency}
* @return {@link Artifact}
* @throws MavenReportException
*/
public Artifact resolveDependency(Dependency dependency) throws MavenReportException {
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
coordinate.setGroupId(dependency.getGroupId());
coordinate.setArtifactId(dependency.getArtifactId());
coordinate.setVersion(dependency.getVersion());
coordinate.setClassifier(dependency.getClassifier());
coordinate.setExtension(artifactHandlerManager.getArtifactHandler(dependency.getType()).getExtension());
try {
return artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), coordinate).getArtifact();
} catch (ArtifactResolverException e) {
throw new MavenReportException("artifact resolver problem - " + e.getMessage(), e);
}
}
use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-dependency-plugin by apache.
the class PurgeLocalRepositoryMojo method getFilteredResolvedArtifacts.
private Set<Artifact> getFilteredResolvedArtifacts(MavenProject theProject, List<Dependency> dependencies, TransformableFilter filter) {
try {
Iterable<ArtifactResult> results = dependencyResolver.resolveDependencies(session.getProjectBuildingRequest(), theProject.getModel(), filter);
Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>();
for (ArtifactResult artResult : results) {
resolvedArtifacts.add(artResult.getArtifact());
}
return resolvedArtifacts;
} catch (DependencyResolverException e) {
getLog().info("Unable to resolve all dependencies for: " + theProject.getGroupId() + ":" + theProject.getArtifactId() + ":" + theProject.getVersion() + ". Falling back to non-transitive mode for initial artifact resolution.");
}
Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>();
ArtifactFilter artifactFilter = filter.transform(new ArtifactIncludeFilterTransformer());
for (Dependency dependency : dependencies) {
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
coordinate.setGroupId(dependency.getGroupId());
coordinate.setArtifactId(dependency.getArtifactId());
coordinate.setVersion(dependency.getVersion());
coordinate.setExtension(artifactHandlerManager.getArtifactHandler(dependency.getType()).getExtension());
try {
Artifact artifact = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), coordinate).getArtifact();
if (artifactFilter.include(artifact)) {
resolvedArtifacts.add(artifact);
}
} catch (ArtifactResolverException e) {
getLog().debug("Unable to resolve artifact: " + coordinate);
}
}
return resolvedArtifacts;
}
use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-dependency-plugin by apache.
the class AbstractFromConfigurationMojo method getArtifact.
/**
* Resolves the Artifact from the remote repository if necessary. If no version is specified, it will be retrieved
* from the dependency list or from the DependencyManagement section of the pom.
*
* @param artifactItem containing information about artifact from plugin configuration.
* @return Artifact object representing the specified file.
* @throws MojoExecutionException with a message if the version can't be found in DependencyManagement.
*/
protected Artifact getArtifact(ArtifactItem artifactItem) throws MojoExecutionException {
Artifact artifact;
try {
// mdep-50 - rolledback for now because it's breaking some functionality.
/*
* List listeners = new ArrayList(); Set theSet = new HashSet(); theSet.add( artifact );
* ArtifactResolutionResult artifactResolutionResult = artifactCollector.collect( theSet, project
* .getArtifact(), managedVersions, this.local, project.getRemoteArtifactRepositories(),
* artifactMetadataSource, null, listeners ); Iterator iter =
* artifactResolutionResult.getArtifactResolutionNodes().iterator(); while ( iter.hasNext() ) {
* ResolutionNode node = (ResolutionNode) iter.next(); artifact = node.getArtifact(); }
*/
ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
if (localRepositoryDirectory != null) {
buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, localRepositoryDirectory);
}
// Map dependency to artifact coordinate
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
coordinate.setGroupId(artifactItem.getGroupId());
coordinate.setArtifactId(artifactItem.getArtifactId());
coordinate.setVersion(artifactItem.getVersion());
coordinate.setClassifier(artifactItem.getClassifier());
final String extension;
ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(artifactItem.getType());
if (artifactHandler != null) {
extension = artifactHandler.getExtension();
} else {
extension = artifactItem.getType();
}
coordinate.setExtension(extension);
artifact = artifactResolver.resolveArtifact(buildingRequest, coordinate).getArtifact();
} catch (ArtifactResolverException e) {
throw new MojoExecutionException("Unable to find/resolve artifact.", e);
}
return artifact;
}
Aggregations