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.ReporterMojo 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;
import com.ymock.util.Logger;

// for file management
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

// MOJO API
import org.apache.maven.plugin.MojoExecutionException;

/**
 * Maven Object Java Object (MOJO), plugin entry point.
 *
 * @author Yegor Bugayenko ([email protected])
 * @version $Id: ReporterMojo.java 1662 2011-07-18 19:45:01Z guard $
 * @goal report
 * @phase package
 */
public class ReporterMojo extends AbstractRemplMojo {

    /**
     * The location of reporting directory.
     * @parameter expression="${rempl.dir}" default-value="${project.build.directory}/site/rempl" property="dir"
     * @required
     */
    private File dir;

    /**
     * Public ctor.
     */
    public ReporterMojo() {
        super();
        this.dir = null;
    }

    /**
     * Set the location of reporting directory.
     * @param location The location of the directory
     */
    public final void setDir(final File location) {
        this.dir = location;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected final void run() throws MojoExecutionException {
        this.getLog().info("Reporting started");
        final Rempler rempler = this.rempler();
        final Model model = this.model(rempler);
        final File output = this.dir();
        try {
            rempler.report(model, output);
        } catch (java.io.IOException ex) {
            throw new MojoExecutionException("Failed to report", ex);
        }
        this.getLog().debug("Report saved to: " + output);
        this.getLog().info("Reporting finished");
    }

    /**
     * Read model instance.
     *
     * @param rempler The rempler to use
     * @return The model just read
     * @throws MojoExecutionException If something goes wrong
     */
    protected final Model model(final Rempler rempler)
        throws MojoExecutionException {
        final Model model = rempler.emptyModel();
        Reader reader = null;
        try {
            reader = new FileReader(this.xmiForReading());
            model.load(reader);
        } catch (java.io.FileNotFoundException ex) {
            throw new MojoExecutionException("File not found", ex);
        } catch (IOException e) {
            throw new MojoExecutionException("IO Exception", e);
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                //not throw e outside not to loose main exception which
                // is much important to propagate
                Logger.error(e, "IO failure");
            }
        }

        this.getLog().debug("Model loaded from XMI");
        return model;
    }

    /**
     * Get directory where to save report.
     * @return The directory
     * @throws MojoExecutionException If something goes wrong
     */
    private File dir() throws MojoExecutionException {
        if (this.dir.mkdirs()) {
            this.getLog().debug("Directory created: " + this.dir);
        }
        this.getLog().info("Reporting to: " + this.dir);
        return this.dir;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy