org.codehaus.mojo.groovy.compile.AbstractCompileMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of groovy-maven-plugin Show documentation
Show all versions of groovy-maven-plugin Show documentation
Provides support for execution, compilation and other facets of Groovy development.
The newest version!
/*
* Copyright (C) 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.mojo.groovy.compile;
import java.io.File;
import java.util.Iterator;
import java.util.Set;
import org.apache.maven.shared.io.scan.mapping.SourceMapping;
import org.apache.maven.shared.io.scan.mapping.SuffixMapping;
import org.apache.maven.shared.model.fileset.FileSet;
import org.codehaus.mojo.groovy.CompilerMojoSupport;
import org.codehaus.mojo.groovy.feature.Component;
import org.codehaus.mojo.groovy.feature.Configuration;
import org.codehaus.mojo.groovy.runtime.ClassCompiler;
/**
* Support for compile mojos that generate classes.
*
* @version $Id: AbstractCompileMojo.java 5554 2007-10-25 17:12:34Z user57 $
* @author Jason Dillon
*/
public abstract class AbstractCompileMojo
extends CompilerMojoSupport
implements ClassCompiler.Keys
{
protected AbstractCompileMojo() {
super(ClassCompiler.KEY);
}
/**
* Sets the encoding to be used when reading source files.
*
* @parameter expression="${sourceEncoding}" default-value="${file.encoding}"
*
* @noinspection UnusedDeclaration
*/
private String sourceEncoding;
/**
* Turns verbose operation on or off.
*
* @parameter expression="${verbose}" default-value="false"
*
* @noinspection UnusedDeclaration
*/
private boolean verbose;
/**
* Turns debugging operation on or off.
*
* @parameter expression="${debug}" default-value="false"
*
* @noinspection UnusedDeclaration
*/
private boolean debug;
/**
* Enable compiler to report stack trace information if a problem occurs.
*
* @parameter expression="${stacktrace}" default-value="false"
*
* @noinspection UnusedDeclaration
*/
private boolean stacktrace;
/**
* Sets the error tolerance, which is the number of non-fatal errors (per unit)
* that should be tolerated before compilation is aborted.
*
* @parameter expression="${tolerance}" default-value="0"
*
* @noinspection UnusedDeclaration
*/
private int tolerance;
/**
* Sets the name of the base class for scripts. It must be a subclass of groovy.lang.Script.
*
* @parameter expression="${scriptBaseClassname}"
*
* @noinspection UnusedDeclaration
*/
private String scriptBaseClassname;
/**
* Set the default extention for Groovy script source files.
*
* @parameter expression="${defaultScriptExtension}" default-value=".groovy"
*
* @noinspection UnusedDeclaration
*/
private String defaultScriptExtension;
protected abstract Set getForcedCompileSources();
protected void process(final Component component) throws Exception {
assert component != null;
ClassCompiler compiler = (ClassCompiler)component;
compiler.setTargetDirectory(getOutputDirectory());
compiler.setClassPath(createClassPath());
Configuration config = component.config();
config.set(VERBOSE, verbose);
config.set(DEBUG, debug);
config.set(TOLERANCE, tolerance);
if (scriptBaseClassname != null) {
config.set(SCRIPT_BASE_CLASSNAME, scriptBaseClassname);
}
if (defaultScriptExtension != null) {
config.set(DEFAULT_SCRIPT_EXTENSION, defaultScriptExtension);
}
compile(compiler, sources != null ? sources : getDefaultSources());
}
protected void compile(final ClassCompiler compiler, final FileSet[] sources) throws Exception {
assert compiler != null;
assert sources != null;
for (int i=0; i 1 ? "s" : ""));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy