File tempFile = getTempFolder(modules[0]);
// tempFile needs to be in the same location as the war file
// otherwise PublishHelper will fail
File targetFile = new File(tempFile, modules[0].getName() + ".war"); //$NON-NLS-1$
targetFile.deleteOnExit();
PublishHelper helper = new PublishHelper(tempFile);
ArrayList<IModuleResource> resources = new ArrayList<IModuleResource>(Arrays.asList(server
.getResources(modules)));
IWebModule webModule = getWebModule(modules);
if (webModule != null) {
IModule[] children = webModule.getModules();
if (children != null) {
for (IModule child : children) {
String childUri = null;
if (webModule != null) {
childUri = webModule.getURI(child);
}
IJ2EEModule childModule = (IJ2EEModule) child.loadAdapter(IJ2EEModule.class, monitor);
boolean isBinary = false;
if (childModule != null) {
isBinary = childModule.isBinary();
}
if (isBinary) {
// binaries are copied to the destination
// directory
if (childUri == null) {
childUri = "WEB-INF/lib/" + child.getName(); //$NON-NLS-1$
}
IPath jarPath = new Path(childUri);
File jarFile = new File(tempFile, jarPath.lastSegment());
jarPath = jarPath.removeLastSegments(1);
IModuleResource[] mr = server.getResources(new IModule[] { child });
IStatus[] status = helper.publishToPath(mr, new Path(jarFile.getAbsolutePath()), monitor);
merge(result, status);
resources.add(new ModuleFile(jarFile, jarFile.getName(), jarPath));
}
else {
// other modules are assembled into a jar
if (childUri == null) {
childUri = "WEB-INF/lib/" + child.getName() + ".jar"; //$NON-NLS-1$ //$NON-NLS-2$
}
IPath jarPath = new Path(childUri);
File jarFile = new File(tempFile, jarPath.lastSegment());
jarPath = jarPath.removeLastSegments(1);
IModuleResource[] mr = server.getResources(new IModule[] { child });
IStatus[] status = helper.publishZip(mr, new Path(jarFile.getAbsolutePath()), monitor);
merge(result, status);
resources.add(new ModuleFile(jarFile, jarFile.getName(), jarPath));
}
}
}
}
List<IModuleResource> newResources = new ArrayList<IModuleResource>();
for (IModuleResource mr : resources) {
newResources.add(processModuleResource(mr));
}
IStatus[] status = helper.publishZip(newResources.toArray(new IModuleResource[0]),
new Path(targetFile.getAbsolutePath()), monitor);
merge(result, status);
throwException(result, "Publishing of " + modules[0].getName() + " failed"); //$NON-NLS-1$ //$NON-NLS-2$
return targetFile;