use of net.sourceforge.usbdm.packageParser.ProjectVariable in project usbdm-eclipse-plugins by podonoghue.
the class ProcessProjectActions method process.
/**
* Process a project action list
*
* @param projectHandle Project being manipulated
* @param actionList Actions to do
* @param variableMap Variables that may be needed
* @param monitor Progress monitor
*
* @throws Exception
*/
public void process(final IProject projectHandle, final ProjectActionList actionList, final Map<String, String> variableMap, final IProgressMonitor monitor) throws Exception {
if (actionList == null) {
return;
}
System.err.println("ProcessProjectActions.process " + actionList.getId());
final ApplyOptions applyOptions = new ApplyOptions(projectHandle);
class MyVisitor implements ProjectActionList.Visitor {
@Override
public Result applyTo(ProjectAction action, Value result, IProgressMonitor monitor) {
SubMonitor subMonitor = SubMonitor.convert(monitor);
subMonitor.subTask(action.toString());
// System.err.println("ProjectCustomAction: "+action.toString());
try {
if (action instanceof FileAction) {
new AddTargetFiles().process(projectHandle, variableMap, (FileAction) action, subMonitor);
} else if (action instanceof DeleteResourceAction) {
new DeleteResource().process(projectHandle, variableMap, (DeleteResourceAction) action, subMonitor);
} else if (action instanceof CreateFolderAction) {
// ProjectUtilities.createFolder(projectHandle, variableMap, (CreateFolderAction)action, subMonitor);
} else if (action instanceof ProjectOption) {
applyOptions.process(variableMap, (ProjectOption) action, subMonitor);
} else if (action instanceof ExcludeAction) {
ProjectUtilities.excludeItem(projectHandle, (ExcludeAction) action, subMonitor);
} else if (action instanceof ProjectActionList) {
ProjectActionList projectActionList = (ProjectActionList) action;
if (projectActionList.isDoOnceOnly()) {
if (previousActions.contains(projectActionList.getId())) {
// Don't repeat action
System.err.println("ProcessProjectActions.process - not repeating action " + projectActionList.getId());
return new Result(Status.PRUNE);
}
previousActions.add(projectActionList.getId());
}
return new Result(projectActionList.applies(variableMap) ? Status.CONTINUE : Status.PRUNE);
} else if (action instanceof ProjectCustomAction) {
ProjectCustomAction customAction = (ProjectCustomAction) action;
Class<?> actionClass = Class.forName(customAction.getclassName());
Object clsInstance = actionClass.newInstance();
if (!(clsInstance instanceof CustomAction)) {
throw new Exception("Custom action does not implement required interface");
}
((CustomAction) clsInstance).action(projectHandle, variableMap, subMonitor, customAction.getValue());
} else if (action instanceof ProjectConstant) {
// Ignore as already added to paramMap
} else if (action instanceof WizardGroup) {
// Ignore as already added to paramMap
} else if (action instanceof ProjectVariable) {
// Ignore as already added to paramMap
} else if (action instanceof WizardPageInformation) {
// Ignore as only applicable to wizard dialogues
} else {
throw new Exception("Unexpected action class: " + action.getClass());
}
} catch (Exception e) {
// e.printStackTrace();
StringBuffer sb = new StringBuffer();
sb.append("Unable to process Action " + action.toString() + "\n");
sb.append("Action id = " + action.getId() + "\n");
sb.append("Action owned by = " + action.getOwnerId() + "\n");
sb.append(e.getMessage());
return new Result(new Exception(sb.toString(), e));
}
return new Result(Status.CONTINUE);
}
}
;
MyVisitor visitor = new MyVisitor();
Result res = actionList.visit(visitor, null, monitor);
if (res.getStatus() == Status.EXCEPTION) {
throw res.getException();
}
}
Aggregations