use of org.apache.maven.reporting.MavenReportException 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.reporting.MavenReportException in project maven-plugins by apache.
the class AbstractJavadocMojo method validateJavadocOptions.
/**
* Checks for the validity of the Javadoc options used by the user.
*
* @throws MavenReportException if error
*/
private void validateJavadocOptions() throws MavenReportException {
// encoding
if (StringUtils.isNotEmpty(getEncoding()) && !JavadocUtil.validateEncoding(getEncoding())) {
throw new MavenReportException("Unsupported option <encoding/> '" + getEncoding() + "'");
}
// locale
if (StringUtils.isNotEmpty(this.locale)) {
StringTokenizer tokenizer = new StringTokenizer(this.locale, "_");
final int maxTokens = 3;
if (tokenizer.countTokens() > maxTokens) {
throw new MavenReportException("Unsupported option <locale/> '" + this.locale + "', should be language_country_variant.");
}
Locale localeObject = null;
if (tokenizer.hasMoreTokens()) {
String language = tokenizer.nextToken().toLowerCase(Locale.ENGLISH);
if (!Arrays.asList(Locale.getISOLanguages()).contains(language)) {
throw new MavenReportException("Unsupported language '" + language + "' in option <locale/> '" + this.locale + "'");
}
localeObject = new Locale(language);
if (tokenizer.hasMoreTokens()) {
String country = tokenizer.nextToken().toUpperCase(Locale.ENGLISH);
if (!Arrays.asList(Locale.getISOCountries()).contains(country)) {
throw new MavenReportException("Unsupported country '" + country + "' in option <locale/> '" + this.locale + "'");
}
localeObject = new Locale(language, country);
if (tokenizer.hasMoreTokens()) {
String variant = tokenizer.nextToken();
localeObject = new Locale(language, country, variant);
}
}
}
if (localeObject == null) {
throw new MavenReportException("Unsupported option <locale/> '" + this.locale + "', should be language_country_variant.");
}
this.locale = localeObject.toString();
final List<Locale> availableLocalesList = Arrays.asList(Locale.getAvailableLocales());
if (StringUtils.isNotEmpty(localeObject.getVariant()) && !availableLocalesList.contains(localeObject)) {
StringBuilder sb = new StringBuilder();
sb.append("Unsupported option <locale/> with variant '").append(this.locale);
sb.append("'");
localeObject = new Locale(localeObject.getLanguage(), localeObject.getCountry());
this.locale = localeObject.toString();
sb.append(", trying to use <locale/> without variant, i.e. '").append(this.locale).append("'");
if (getLog().isWarnEnabled()) {
getLog().warn(sb.toString());
}
}
if (!availableLocalesList.contains(localeObject)) {
throw new MavenReportException("Unsupported option <locale/> '" + this.locale + "'");
}
}
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class AbstractJavadocMojo method collectLinks.
private Set<String> collectLinks() throws MavenReportException {
Set<String> links = new LinkedHashSet<String>();
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.getLinks())) {
links.addAll(options.getLinks());
}
}
}
}
if (isNotEmpty(this.links)) {
links.addAll(this.links);
}
links.addAll(getDependenciesLinks());
return links;
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class AbstractJavadocMojo method addCommandLinePackages.
/**
* Generate a file called <code>packages</code> to hold all package names and add the <code>@packages</code> in
* the command line.
*
* @param cmd not null
* @param javadocOutputDirectory not null
* @param packageNames not null
* @throws MavenReportException if any
* @see <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#argumentfiles">
* Reference Guide, Command line argument files</a>
* @see #PACKAGES_FILE_NAME
*/
private void addCommandLinePackages(Commandline cmd, File javadocOutputDirectory, List<String> packageNames) throws MavenReportException {
File packagesFile = new File(javadocOutputDirectory, PACKAGES_FILE_NAME);
try {
FileUtils.fileWrite(packagesFile.getAbsolutePath(), null, /* platform encoding */
StringUtils.join(packageNames.iterator(), SystemUtils.LINE_SEPARATOR));
} catch (IOException e) {
throw new MavenReportException("Unable to write '" + packagesFile.getName() + "' temporary file for command execution", e);
}
cmd.createArg().setValue("@" + PACKAGES_FILE_NAME);
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class AbstractJavadocMojo method addCommandLineArgFile.
/**
* Generate a file called <code>argfile</code> (or <code>files</code>, depending the JDK) to hold files and add
* the <code>@argfile</code> (or <code>@file</code>, depending the JDK) in the command line.
*
* @param cmd not null
* @param javadocOutputDirectory not null
* @param files not null
* @throws MavenReportException if any
* @see <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#argumentfiles">
* Reference Guide, Command line argument files
* </a>
* @see <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/whatsnew-1.4.html#runningjavadoc">
* What s New in Javadoc 1.4
* </a>
* @see #isJavaDocVersionAtLeast(float)
* @see #ARGFILE_FILE_NAME
* @see #FILES_FILE_NAME
*/
private void addCommandLineArgFile(Commandline cmd, File javadocOutputDirectory, List<String> files) throws MavenReportException {
File argfileFile;
if (isJavaDocVersionAtLeast(SINCE_JAVADOC_1_4)) {
argfileFile = new File(javadocOutputDirectory, ARGFILE_FILE_NAME);
cmd.createArg().setValue("@" + ARGFILE_FILE_NAME);
} else {
argfileFile = new File(javadocOutputDirectory, FILES_FILE_NAME);
cmd.createArg().setValue("@" + FILES_FILE_NAME);
}
try {
FileUtils.fileWrite(argfileFile.getAbsolutePath(), null, /* platform encoding */
StringUtils.join(files.iterator(), SystemUtils.LINE_SEPARATOR));
} catch (IOException e) {
throw new MavenReportException("Unable to write '" + argfileFile.getName() + "' temporary file for command execution", e);
}
}
Aggregations