if (monitor == null) {
monitor = new NullProgressMonitor();
}
try {
monitor.beginTask("Incremental updating wga deployment.", 1);
IResourceDelta delta = projectDelta.findMember(new Path("WebContent"));
if (delta != null) {
IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() {
public boolean visit(IResourceDelta delta) throws CoreException {
if (delta.getResource() != null) {
if (delta.getResource() instanceof IFile) {
IFile file = (IFile)delta.getResource();
String absolutePath = file.getLocation().toString();
// make path relative to WebContent folder
int pos = absolutePath.lastIndexOf("WebContent/");
if (pos != -1) {
String relativePathToFile = absolutePath.substring(pos + "WebContent/".length());
File targetFile = new File(getDeployDir(), relativePathToFile);
File sourceFile = file.getLocation().toFile();
if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.CHANGED) {
try {
if (WGADesignerPlugin.getDefault().isDebugging()) {
System.out.println("Updating resource '" + targetFile.getAbsolutePath() + "' of deployment '" + getName() + "'.");
}
// ensure that target folder exists
if (!targetFile.getParentFile().exists()) {
targetFile.getParentFile().mkdirs();
}
FileUtils.copy(sourceFile, targetFile);
} catch (IOException e) {
WGADesignerPlugin.getDefault().logError("Unable to update resource '" + targetFile.getAbsolutePath() + "' in wga deployment '" + getName() + "'. Deployment is out of sync.");
}
} else if (delta.getKind() == IResourceDelta.REMOVED) {
if (targetFile.exists()) {
if (WGADesignerPlugin.getDefault().isDebugging()) {
System.out.println("Deleting resource '" + targetFile.getAbsolutePath() + "' of deployment '" + getName() + "'.");
}
if (!targetFile.delete()) {
WGADesignerPlugin.getDefault().logError("Unable to delete resource '" + targetFile.getAbsolutePath() + "' in wga deployment '" + getName() + "'. Deployment is out of sync.");
}
}
}
} else {
// invalid resource - should not happen - ignore
}
} else if (delta.getResource() instanceof IFolder) {
IFolder folder = (IFolder)delta.getResource();
String absolutePath = folder.getLocation().toString();
// make path relative to WebContent folder
int pos = absolutePath.lastIndexOf("WebContent/");
if (pos != -1) {
String relativePathToFolder = absolutePath.substring(pos + "WebContent/".length());
File targetFolder = new File(getDeployDir(), relativePathToFolder);
if (delta.getKind() == IResourceDelta.ADDED) {
if (WGADesignerPlugin.getDefault().isDebugging()) {
System.out.println("Creating folder '" + targetFolder.getAbsolutePath() + "' in deployment '" + getName() + "'.");
}
targetFolder.mkdirs();
} else if (delta.getKind() == IResourceDelta.REMOVED) {
if (WGADesignerPlugin.getDefault().isDebugging()) {
System.out.println("Deleting folder '" + targetFolder.getAbsolutePath() + "' of deployment '" + getName() + "'.");
}
if (targetFolder.exists()) {
WGUtils.delTree(targetFolder);
}
}
} else {
// invalid resource - should not happen - ignore
}
}
}
// continue with children
return true;
}
};
delta.accept(visitor);
}
monitor.worked(1);
} finally {
monitor.done();
}