use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class ChangeLogReport method generateChangeSetsFromSCM.
/**
* creates a ChangeLog object and then connects to the SCM to generate the changed sets
*
* @return changedlogsets generated from the SCM
* @throws MavenReportException
*/
protected List<ChangeLogSet> generateChangeSetsFromSCM() throws MavenReportException {
try {
List<ChangeLogSet> changeSets = new ArrayList<ChangeLogSet>();
ScmRepository repository = getScmRepository();
ScmProvider provider = manager.getProviderByRepository(repository);
ChangeLogScmResult result;
if ("range".equals(type)) {
result = provider.changeLog(repository, new ScmFileSet(basedir), null, null, range, (ScmBranch) null, dateFormat);
checkResult(result);
changeSets.add(result.getChangeLog());
} else if ("tag".equals(type)) {
Iterator<String> tagsIter = tags.iterator();
String startTag = tagsIter.next();
String endTag = null;
if (tagsIter.hasNext()) {
while (tagsIter.hasNext()) {
endTag = tagsIter.next();
String endRevision = getRevisionForTag(endTag, repository, provider);
String startRevision = getRevisionForTag(startTag, repository, provider);
result = provider.changeLog(repository, new ScmFileSet(basedir), new ScmRevision(startRevision), new ScmRevision(endRevision));
checkResult(result);
result.getChangeLog().setStartVersion(new ScmRevision(startTag));
result.getChangeLog().setEndVersion(new ScmRevision(endTag));
changeSets.add(result.getChangeLog());
startTag = endTag;
}
} else {
String startRevision = getRevisionForTag(startTag, repository, provider);
String endRevision = getRevisionForTag(endTag, repository, provider);
result = provider.changeLog(repository, new ScmFileSet(basedir), new ScmRevision(startRevision), new ScmRevision(endRevision));
checkResult(result);
result.getChangeLog().setStartVersion(new ScmRevision(startTag));
result.getChangeLog().setEndVersion(null);
changeSets.add(result.getChangeLog());
}
} else if ("date".equals(type)) {
Iterator<String> dateIter = dates.iterator();
String startDate = dateIter.next();
String endDate = null;
if (dateIter.hasNext()) {
while (dateIter.hasNext()) {
endDate = dateIter.next();
result = provider.changeLog(repository, new ScmFileSet(basedir), parseDate(startDate), parseDate(endDate), 0, (ScmBranch) null);
checkResult(result);
changeSets.add(result.getChangeLog());
startDate = endDate;
}
} else {
result = provider.changeLog(repository, new ScmFileSet(basedir), parseDate(startDate), parseDate(endDate), 0, (ScmBranch) null);
checkResult(result);
changeSets.add(result.getChangeLog());
}
} else {
throw new MavenReportException("The type '" + type + "' isn't supported.");
}
filter(changeSets);
return changeSets;
} catch (ScmException e) {
throw new MavenReportException("Cannot run changelog command : ", e);
} catch (MojoExecutionException e) {
throw new MavenReportException("An error has occurred during changelog command : ", e);
}
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class ChangeLogReport method getChangedSets.
/**
* populates the changedSets field by either connecting to the SCM or using an existing XML generated in a previous
* run of the report
*
* @throws MavenReportException
*/
protected List<ChangeLogSet> getChangedSets() throws MavenReportException {
List<ChangeLogSet> changelogList = null;
if (!outputXML.isAbsolute()) {
outputXML = new File(project.getBasedir(), outputXML.getPath());
}
if (outputXML.exists()) {
// CHECKSTYLE_OFF: MagicNumber
if (outputXMLExpiration > 0 && outputXMLExpiration * 60000 > System.currentTimeMillis() - outputXML.lastModified()) // CHECKSTYLE_ON: MagicNumber
{
try {
//ReaderFactory.newReader( outputXML, getOutputEncoding() );
//FileInputStream fIn = new FileInputStream( outputXML );
getLog().info("Using existing changelog.xml...");
changelogList = ChangeLog.loadChangedSets(ReaderFactory.newReader(outputXML, getOutputEncoding()));
} catch (FileNotFoundException e) {
//do nothing, just regenerate
} catch (Exception e) {
throw new MavenReportException("An error occurred while parsing " + outputXML.getAbsolutePath(), e);
}
}
}
if (changelogList == null) {
if (offline) {
throw new MavenReportException("This report requires online mode.");
}
getLog().info("Generating changed sets xml to: " + outputXML.getAbsolutePath());
changelogList = generateChangeSetsFromSCM();
try {
writeChangelogXml(changelogList);
} catch (FileNotFoundException e) {
throw new MavenReportException("Can't create " + outputXML.getAbsolutePath(), e);
} catch (UnsupportedEncodingException e) {
throw new MavenReportException("Can't create " + outputXML.getAbsolutePath(), e);
} catch (IOException e) {
throw new MavenReportException("Can't create " + outputXML.getAbsolutePath(), e);
}
}
return changelogList;
}
use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.
the class ChangesMojo method getChangesFromFile.
/* --------------------------------------------------------------------- */
/* Private methods */
/* --------------------------------------------------------------------- */
/**
* Parses specified changes.xml file. It also makes filtering if needed. If specified file doesn't exist it will log
* warning and return <code>null</code>.
*
* @param changesXml changes xml file to parse
* @param project maven project to parse changes for
* @param additionalProperties additional properties used for filtering
* @return parsed <code>ChangesXML</code> instance or null if file doesn't exist
* @throws MavenReportException if any errors occurs while parsing
*/
private ChangesXML getChangesFromFile(File changesXml, MavenProject project, Properties additionalProperties) throws MavenReportException {
if (!changesXml.exists()) {
getLog().warn("changes.xml file " + changesXml.getAbsolutePath() + " does not exist.");
return null;
}
if (filteringChanges) {
if (!filteredOutputDirectory.exists()) {
filteredOutputDirectory.mkdirs();
}
XmlStreamReader xmlStreamReader = null;
try {
// so we get encoding from the file itself
xmlStreamReader = new XmlStreamReader(changesXml);
String encoding = xmlStreamReader.getEncoding();
File resultFile = new File(filteredOutputDirectory, project.getGroupId() + "." + project.getArtifactId() + "-changes.xml");
final MavenFileFilterRequest mavenFileFilterRequest = new MavenFileFilterRequest(changesXml, resultFile, true, project, Collections.<String>emptyList(), false, encoding, session, additionalProperties);
mavenFileFilter.copyFile(mavenFileFilterRequest);
changesXml = resultFile;
xmlStreamReader.close();
xmlStreamReader = null;
} catch (IOException e) {
throw new MavenReportException("Exception during filtering changes file : " + e.getMessage(), e);
} catch (MavenFilteringException e) {
throw new MavenReportException("Exception during filtering changes file : " + e.getMessage(), e);
} finally {
IOUtil.close(xmlStreamReader);
}
}
return new ChangesXML(changesXml, getLog());
}
use of org.apache.maven.reporting.MavenReportException 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.reporting.MavenReportException 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);
}
}
Aggregations