}
@Override
public void execute() {
Build build = (Build) getProject().getReference(Key.build.referenceId());
console = build.getConsole();
if (main == null && mainJars == null) {
manifestSet = true;
Main main = new Main();
main.setProject(getProject());
if (excludes == null) {
excludes = Toolkit.DEFAULT_CODE_EXCLUDES;
}
// compiled output of this project
File outputFolder = build.getConfig().getOutputDirectory(Scope.compile);
ZipFileSet outputSet = new ZipFileSet();
outputSet.setProject(getProject());
outputSet.setDir(outputFolder);
if (includes != null) {
outputSet.setIncludes(includes);
}
outputSet.setExcludes(excludes);
main.addFileSet(outputSet);
// add the output and resource folders of modules
for (Build module : build.getSolver().getLinkedModules()) {
ZipFileSet projectOutputSet = new ZipFileSet();
projectOutputSet.setProject(getProject());
File dir = module.getConfig().getOutputDirectory(Scope.compile);
projectOutputSet.setDir(dir);
if (includes != null) {
projectOutputSet.setIncludes(includes);
}
projectOutputSet.setExcludes(excludes);
main.addFileSet(projectOutputSet);
if (includeResources) {
// add linked module resources
for (File resDir : module.getConfig().getResourceDirectories(Scope.compile)) {
ZipFileSet resSet = new ZipFileSet();
resSet.setProject(getProject());
resSet.setDir(resDir);
resSet.setExcludes(Toolkit.DEFAULT_RESOURCE_EXCLUDES);
main.addFileSet(resSet);
}
}
}
// resource directories
if (includeResources) {
for (File dir : build.getConfig().getResourceDirectories(Scope.compile, tag)) {
ZipFileSet set = new ZipFileSet();
set.setProject(getProject());
set.setDir(dir);
set.setExcludes(Toolkit.DEFAULT_RESOURCE_EXCLUDES);
main.addFileSet(set);
}
}
createDependencies().setTag(tag);
if (getDestFile() == null) {
setDestFile(build.getBuildArtifact(classifier));
}
File destFile = getDestFile();
if (destFile.getParentFile() != null) {
destFile.getParentFile().mkdirs();
}
if (mainclass == null) {
String mc = build.getConfig().getProjectConfig().getMainclass();
if (!StringUtils.isEmpty(mc)) {
createMainclass().setName(mc);
}
}
addMain(main);
}
if (mainclass != null) {
String mc = mainclass.getName().replace('/', '.');
if (mc.endsWith(".class")) {
mc = mc.substring(0, mc.length() - ".class".length());
}
setOneJarMainClass(mc);
manifestSet = true;
}
for (ZipDependencies deps : dependencies) {
for (File jar : build.getSolver().getClasspath(deps.getScope(), deps.getTag())) {
ZipFileSet fs = new ZipFileSet();
fs.setProject(getProject());
if (!StringUtils.isEmpty(deps.getPrefix())) {
throw new MoxieException("Can not specify custom dependencies prefix for mx:onejar!");
}
fs.setPrefix("lib/");
fs.setDir(jar.getParentFile());
fs.setIncludes(jar.getName());
addZipfileset(fs);
}
}
if (isShowTitle()) {
console.title(getClass(), getDestFile().getName());
}
long start = System.currentTimeMillis();
super.execute();
console.log(1, "{0} KB, generated in {1} ms", (getDestFile().length()/1024), System.currentTimeMillis() - start);
/*
* Build sources jar
*/
if (packageSources) {
String name = getDestFile().getName();
if (!StringUtils.isEmpty(classifier)) {
// replace the classifier with "sources"
name = name.replace(classifier, "sources");
} else {
// append -sources to the filename before the extension
name = name.substring(0, name.lastIndexOf('.')) + "-sources" + name.substring(name.lastIndexOf('.'));
}
File sourcesFile = new File(getDestFile().getParentFile(), name);
if (sourcesFile.exists()) {
sourcesFile.delete();
}
Jar jar = new Jar();
jar.setTaskName(getTaskName());
jar.setProject(getProject());
// set the destination file
jar.setDestFile(sourcesFile);
List<File> folders = build.getConfig().getSourceDirectories(Scope.compile, tag);
for (File folder : folders) {
FileSet srcSet = new FileSet();
srcSet.setProject(getProject());
srcSet.setDir(folder);
srcSet.setIncludes("**/*.java");
jar.addFileset(srcSet);
// include source folder resources
FileSet resSet = new FileSet();
resSet.setProject(getProject());
resSet.setDir(folder);
resSet.setExcludes(excludes);
jar.addFileset(resSet);
}
if (includeResources) {
for (File dir : build.getConfig().getResourceDirectories(Scope.compile, tag)) {
FileSet set = new FileSet();
set.setDir(dir);
set.setExcludes(Toolkit.DEFAULT_RESOURCE_EXCLUDES);
jar.addFileset(set);
}