}
@Override
public void execute() {
Build build = (Build) getProject().getReference(Key.build.referenceId());
Console console = build.getConsole();
if (!configured) {
// called from moxie.compile
configure(build);
}
if (scope == null) {
scope = Scope.defaultScope;
}
if (builds == null) {
// top-level mx:javac instantiates the build stack
builds = new HashSet<Build>();
}
if (compileLinkedProjects) {
for (Build linkedProject: build.getSolver().getLinkedModules()) {
if (builds.contains(linkedProject)) {
// already built, skip
console.debug(1, "skipping {0}, already compiled", linkedProject.getPom().getManagementId());
continue;
}
// add the build to the stack so we do not rebuild
builds.add(linkedProject);
try {
// compile the linked project
Project project = new Project();
project.setBaseDir(linkedProject.getConfig().getProjectDirectory());
project.addReference(Key.build.referenceId(), linkedProject);
MxJavac subCompile = new MxJavac(builds);
subCompile.setProject(project);
subCompile.setShowtitle(false);
subCompile.perform();
} catch (Exception e) {
console.error(e);
throw new MoxieException(e);
}
}
}
if (isShowTitle()) {
console.title(getClass(), build.getPom().getCoordinates() + ", " + scope.name());
}
console.debug("mxjavac configuration");
// display specified mxjavac attributes
MaxmlMap attributes = build.getConfig().getTaskAttributes(getTaskName());
AttributeReflector.logAttributes(this, attributes, console);
// project folder
console.debug(1, "projectdir = {0}", build.getConfig().getProjectDirectory());
// create sourcepath
Path sources = createSrc();
for (File file : build.getConfig().getSourceDirectories(scope, tag)) {
PathElement element = sources.createPathElement();
element.setLocation(file);
}
console.debug(1, "sources = {0}", sources);
// set output folder
setDestdir(build.getConfig().getOutputDirectory(scope));
console.debug(1, "destdir = {0}", getDestdir());
// create classpath
Path classpath = createClasspath();
if (Scope.test.equals(scope)) {
// add the compile output folder
PathElement element = classpath.createPathElement();
element.setLocation(build.getConfig().getOutputDirectory(Scope.compile));
}
for (File file : build.getSolver().getClasspath(scope)) {
PathElement element = classpath.createPathElement();
element.setLocation(file);
}
for (Build subbuild : build.getSolver().getLinkedModules()) {
PathElement element = classpath.createPathElement();
element.setLocation(subbuild.getConfig().getOutputDirectory(Scope.compile));
}
console.debug(1, "classpath = {0}", classpath);
for (SourceDirectory sd : build.getConfig().getSourceDirectories()) {
// clean apt source directories before compiling
if (sd.apt) {
console.log("Cleaning apt source directory {0}", sd.name);
FileUtils.delete(sd.getSources());
sd.getSources().mkdirs();
}
}
if (clean) {
// clean the output folder before compiling
console.log("Cleaning output directory {0}", getDestdir().getAbsolutePath());
FileUtils.delete(getDestdir());
}
getDestdir().mkdirs();
// set the update property name so we know if nothing compiled
String prop = build.getPom().getCoordinates().replace(':', '.') + ".compiled";
setUpdatedProperty(prop);
super.execute();
if (getProject().getProperty(prop) == null) {
console.log(1, "compiled classes are up-to-date");
}
Copy copy = new Copy();
copy.setTaskName(getTaskName());
copy.setProject(getProject());
copy.setTodir(getDestdir());
copy.setVerbose(getVerbose());
if (getVerbose()) {
console.log("copying resources => {0}", getDestdir());
}
if (excludes == null) {
// default exclusions
excludes = Toolkit.DEFAULT_CODE_EXCLUDES;
}
for (String path : getSrcdir().list()) {
File file = new File(path);
if (file.isDirectory()) {
FileSet set = prepareResourceSet(file);
copy.addFileset(set);
if (getVerbose()) {
console.log("adding resource path {0}", path);
}
}
}
copy.execute();