Search in sources :

Example 11 with MavenReportException

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);
    }
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) ScmBranch(org.apache.maven.scm.ScmBranch) ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmException(org.apache.maven.scm.ScmException) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ScmRevision(org.apache.maven.scm.ScmRevision) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 12 with MavenReportException

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;
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ChangeFile(org.apache.maven.scm.ChangeFile) File(java.io.File) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) ScmException(org.apache.maven.scm.ScmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MavenReportException(org.apache.maven.reporting.MavenReportException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 13 with MavenReportException

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());
}
Also used : MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) MavenFileFilterRequest(org.apache.maven.shared.filtering.MavenFileFilterRequest) XmlStreamReader(org.apache.commons.io.input.XmlStreamReader) IOException(java.io.IOException) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 14 with MavenReportException

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);
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) JavadocBundle(org.apache.maven.plugin.javadoc.resolver.JavadocBundle) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ArrayList(java.util.ArrayList) TagletArtifact(org.apache.maven.plugin.javadoc.options.TagletArtifact) IOException(java.io.IOException) JavadocPathArtifact(org.apache.maven.plugin.javadoc.options.JavadocPathArtifact) Artifact(org.apache.maven.artifact.Artifact) DocletArtifact(org.apache.maven.plugin.javadoc.options.DocletArtifact) BootclasspathArtifact(org.apache.maven.plugin.javadoc.options.BootclasspathArtifact) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) TagletArtifact(org.apache.maven.plugin.javadoc.options.TagletArtifact) JavadocOptions(org.apache.maven.plugin.javadoc.options.JavadocOptions) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 15 with MavenReportException

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);
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) MavenReportException(org.apache.maven.reporting.MavenReportException)

Aggregations

MavenReportException (org.apache.maven.reporting.MavenReportException)48 File (java.io.File)23 IOException (java.io.IOException)23 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)14 ArrayList (java.util.ArrayList)10 Artifact (org.apache.maven.artifact.Artifact)7 FileOutputStream (java.io.FileOutputStream)6 Locale (java.util.Locale)6 BootclasspathArtifact (org.apache.maven.plugin.javadoc.options.BootclasspathArtifact)6 DocletArtifact (org.apache.maven.plugin.javadoc.options.DocletArtifact)6 JavadocPathArtifact (org.apache.maven.plugin.javadoc.options.JavadocPathArtifact)6 ResourcesArtifact (org.apache.maven.plugin.javadoc.options.ResourcesArtifact)6 TagletArtifact (org.apache.maven.plugin.javadoc.options.TagletArtifact)6 FileNotFoundException (java.io.FileNotFoundException)5 Writer (java.io.Writer)5 LinkedHashSet (java.util.LinkedHashSet)5 SiteRendererSink (org.apache.maven.doxia.siterenderer.sink.SiteRendererSink)5 OutputStreamWriter (java.io.OutputStreamWriter)4 MalformedURLException (java.net.MalformedURLException)3 HashMap (java.util.HashMap)3