texry-maven-plugin-0.2.src.main.java.com.texry.maven.CompileMojo Maven / Gradle / Ivy
/**
* Copyright (c) 2009-2012, TeXry.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 TeXry.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.texry.maven;
import com.ymock.util.Logger;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoFailureException;
import org.slf4j.impl.StaticLoggerBinder;
/**
* Compile PNG images and PDF documents from TeX/LaTeX sources.
*
* @author Yegor Bugayenko ([email protected])
* @version $Id: CompileMojo.java 100 2012-03-26 04:36:37Z [email protected] $
* @goal compile
* @phase pre-site
* @threadSafe
*/
@SuppressWarnings("PMD.ImmutableField")
public final class CompileMojo extends AbstractMojo {
/**
* Sources directory.
* @parameter expression="${project.basedir}/src/main/texry"
* @required
*/
private transient File sourcesDir;
/**
* Destination directory.
* @parameter expression="${project.build.directory}/site/texry"
* @required
*/
private transient File outputDir;
/**
* Temporary directory.
* @parameter expression="${project.build.directory}/texry-temp"
* @required
*/
private transient File tempDir;
/**
* Sources.
* @parameter
* @required
*/
private transient Set sources = new HashSet();
/**
* Closures.
* @parameter
* @required
*/
private transient Set closures = new HashSet();
/**
* Shall we skip execution?
* @parameter expression="${texry.skip}" default-value="false"
* @required
*/
private transient boolean skip;
/**
* {@inheritDoc}
*/
@Override
public void execute() throws MojoFailureException {
StaticLoggerBinder.getSingleton().setMavenLog(this.getLog());
if (this.skip) {
Logger.info(this, "execution skipped because of 'skip' option");
} else {
this.outputDir.mkdirs();
Compiler compiler;
try {
compiler = new Compiler(this.tempDir);
} catch (java.io.IOException ex) {
throw new MojoFailureException(
"Failed to prepare compiler",
ex
);
}
for (String src : this.sources) {
this.compile(compiler, src);
}
}
}
/**
* Compile one source.
* @param compiler The compiler to use
* @param name The name of the source
* @throws MojoFailureException If some problem
*/
private void compile(final Compiler compiler, final String name)
throws MojoFailureException {
final long start = System.nanoTime();
try {
final Source source = new Source(
this.sourcesDir,
name,
this.closures
);
final Output output = compiler.compile(source);
output.saveTo(this.outputDir);
Logger.info(
this,
"'%s' compiled and saved as '%s', in %[nano]s",
source,
output,
System.nanoTime() - start
);
} catch (java.io.IOException ex) {
throw new MojoFailureException(
String.format("Failed to compile '%s'", name),
ex
);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy