rempl-maven-plugin-1.1.1.src.main.java.com.rempl.maven.ReaderMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rempl-maven-plugin Show documentation
Show all versions of rempl-maven-plugin Show documentation
Reverse Engineering Meta Programming Library (REMPL) that
enables manipulations with source code meta constructs,
like classes, methods, files, packages, etc. in runtime.
/**
* 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;
// for file management
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
// MOJO API
import org.apache.maven.plugin.MojoExecutionException;
/**
* Maven Object Java Object (MOJO), plugin entry point.
*
* @author Yegor Bugayenko ([email protected])
* @version $Id: Main.java 42 2010-12-17 16:16:55Z [email protected] $
* @goal read
* @phase generate-test-resources
*/
public class ReaderMojo extends AbstractRemplMojo {
/**
* {@inheritDoc}
*/
@Override
protected final void run() throws MojoExecutionException {
this.getLog().info("Reading started");
final Model model = this.model();
final File xmi = this.xmiForWriting();
Writer writer;
try {
writer = new FileWriter(xmi);
} catch (java.io.IOException ex) {
throw new MojoExecutionException("IO failure", ex);
}
Exception failure = null;
try {
model.save(writer);
} catch (java.io.IOException ex) {
failure = ex;
}
try {
writer.close();
} catch (java.io.IOException ex) {
failure = ex;
}
if (failure != null) {
throw new MojoExecutionException("Failed to save XMI", failure);
}
this.getLog().debug("XMI saved to: " + xmi);
this.getLog().info("Reading finished");
}
/**
* Read model instance.
* @return The model just read
* @throws MojoExecutionException If something goes wrong
*/
private Model model() throws MojoExecutionException {
Model model;
try {
model = this.rempler().read();
} catch (java.io.IOException ex) {
throw new MojoExecutionException("Failed to read", ex);
}
this.getLog().debug("Model built");
return model;
}
}