logger.verbose("Initializing Path Resolvers");
logger.verbose("Classpath:" + classpath);
logger.verbose("Librarypath:" + librarypath);
initPathResolvers();
} catch (IOException ioe) {
throw new MoxieException("Unable to process classpath: " + ioe,
getLocation());
}
//
// run over all the resource and class specifications
// given in the project file
// resources are resolved to full path names while
// class specifications are exploded to dependency
// graphs - when done, getJarEntries() returns a list
// of all entries generated by this JarSpec
//
List<JarEntrySpec> entries = new ArrayList<JarEntrySpec>();
for (JarSpec js : jarSpecs) {
try {
js.resolve(this);
} catch (FileNotFoundException ioe) {
throw new ResolutionFailedException(js.getName(), ioe.getMessage());
} catch (IOException ioe) {
throw new MoxieException("Unable to resolve: " + js.getName()
+ "\nMSG=" + ioe.getMessage(), ioe, getLocation());
}
//
// before adding a new jarspec - see if it already exists
// first entry added to jar always wins
//
for (JarEntrySpec spec : js.getJarEntries()) {
if (!entries.contains(spec)) {
entries.add(spec);
} else {
logger.verbose("Duplicate (ignored): " + spec.getJarName());
}
}
}
//
// we have all the entries we're gonna jar - the manifest
// must be fully built prior to jar generation, so run over
// each entry and and add it to the manifest
//
for (JarEntrySpec jes : entries) {
if (jes.getSourceFile() == null) {
try {
InputStream is = resolveEntry(jes);
if (is != null) {
is.close();
}
} catch (IOException ioe) {
throw new MoxieException(
"Error while generating manifest entry for: "
+ jes.toString(), ioe, getLocation());
}
}
}
JarOutputStream jout = null;
InputStream is = null;
try {
jout = new JarOutputStream(new FileOutputStream(destFile), createJarManifest());
writeJarEntries(jout);
for (JarEntrySpec jes : entries) {
JarEntry entry = new JarEntry(jes.getJarName());
is = resolveEntry(jes);
if (is == null) {
logger.error("Unable to locate previously resolved resource");
logger.error(" Jar Name:" + jes.getJarName());
logger.error("Resolved Source:" + jes.getSourceFile());
try {
if (jout != null) {
jout.close();
}
} catch (IOException ioe) {
}
throw new MoxieException("Jar component not found: "
+ jes.getJarName(), getLocation());
}
jout.putNextEntry(entry);
byte[] buff = new byte[4096]; // stream copy buffer
int len;
while ((len = is.read(buff, 0, buff.length)) != -1) {
jout.write(buff, 0, len);
}
jout.closeEntry();
is.close();
logger.verbose("Added: " + jes.getJarName());
}
} catch (IOException ioe) {
throw new MoxieException("Unable to create jar: "
+ destFile.getName(), ioe, getLocation());
} finally {
try {
if (is != null) {
is.close();