All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rempl-maven-plugin-1.1.3.src.main.java.com.rempl.maven.RemplReportMojo Maven / Gradle / Ivy

Go to download

Reverse Engineering Meta Programming Library (REMPL) that enables manipulations with source code meta constructs, like classes, methods, files, packages, etc. in runtime.

There is a newer version: 1.4
Show newest version
/**
 * Copyright (c) 2011, REMPL.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1) Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 2) Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided
 * with the distribution.
 * 3) Neither the name of the REMPL.com nor the names of its
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.rempl.maven;

// REMPL API from com.rempl:rempl-api
import com.rempl.api.Model;
import com.rempl.api.Rempler;

// file management
import java.io.File;

// for locale management
import java.util.Locale;

// Maven Reporting API
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.reporting.MavenReportException;
// @todo #15/1 This class is deprecated and has to be replaced
//       with org.apache.maven.doxia.sink.Sink. Unfortunately
//       I can't do this since maven-reporting-api is not
//       changed yet for new version of doxia. Because of this
//       deprecated class Java compiler throws WARNINGs during
//       compilation.
import org.codehaus.doxia.sink.Sink;

// SLF4J logger
import org.slf4j.impl.StaticLoggerBinder;

/**
 * Reporting entry point.
 *
 * @author Yegor Bugayenko ([email protected])
 * @version $Id: RemplReportMojo.java 1721 2011-07-27 23:58:18Z guard $
 * @goal rempl
 * @todo #15:3 We need to generate proper Maven report page
 *             with a list of REMPL reports. Currently it is just
 *             an empty HTML page with a few links to sub-reports
 * @todo #15:1 Would be nice to have "windowtitle" option, just like
 *             javadoc plugin has.
 */
public final class RemplReportMojo extends AbstractRemplMojo
    implements MavenReport {

    /**
     * Location of the report.
     */
    private File outputDir;

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean canGenerateReport() {
        return true;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getCategoryName() {
        return this.CATEGORY_PROJECT_REPORTS;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getDescription(final Locale locale) {
        final StringBuilder desc = new StringBuilder();
        desc.append("Summary report of all REMPL reporters");
        if (!locale.equals(Locale.ENGLISH)) {
            desc.append(" (").append(locale.getDisplayName()).append(")");
        }
        return desc.toString();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getName(final Locale locale) {
        final StringBuilder name = new StringBuilder();
        name.append("REMPL reports");
        if (!locale.equals(Locale.ENGLISH)) {
            name.append("/").append(locale.getDisplayName());
        }
        return name.toString();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getOutputName() {
        return "rempl/index";
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public File getReportOutputDirectory() {
        return this.outputDir;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setReportOutputDirectory(final File dir) {
        this.outputDir = new File(dir, "rempl");
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean isExternalReport() {
        return true;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void generate(final Sink sink, final Locale locale)
        throws MavenReportException {
        StaticLoggerBinder.getSingleton().setMavenLog(this.getLog());
        if (this.skip()) {
            this.getLog().info("Reporting skipped");
        } else if (this.romFile() == null && this.ignoreIfAbsent()) {
            this.getLog().info("Ignore since ROM is not found");
        } else if (this.runOnce() && !this.isParentModule(this.getProject())) {
            this.getLog().info("Report skipped  since we are in a child module"
                + " and runOnce option is set to true");
        } else {
            this.getLog().info("Reporting into " + this.outputDir);
            Rempler rempler;
            Model model;
            try {
                rempler = this.rempler();
                model = this.model(rempler);
            } catch (MojoExecutionException ex) {
                throw new MavenReportException("Failed to start", ex);
            }
            try {
                rempler.report(model, this.outputDir);
            } catch (java.io.IOException ex) {
                throw new MavenReportException("Failed to report", ex);
            }
            this.getLog().info("Report building finished");
        }

    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void run() throws MojoExecutionException {
        throw new MojoExecutionException("not implemented");
    }

    /**
     * Read model instance.
     * @param rempler The rempler to use
     * @return The model just read
     * @throws MojoExecutionException If something goes wrong
     */
    private Model model(final Rempler rempler) throws MojoExecutionException {
        Model model;
        try {
            model = rempler.read();
        } catch (java.io.IOException ex) {
            throw new MojoExecutionException("Failed to read", ex);
        }
        this.getLog().debug("Model built");
        return model;
    }

    /**
     * Are we in the parent module?
     * @param project Project that we check.
     * @return Are we in the parent module?
     */
    private boolean isParentModule(final MavenProject project) {
        return project.getParent() == null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy