}
void obfuscate() throws Exception {
final boolean batch = this.batchCheck.isSelected();
final FileSet originalFileSet = project.getFileSet();
List<String> classNames = SystemFacade.getInstance().getClassIndex().getClassNames(originalFileSet);
if (batch && project.isModified()) {
JOptionPane.showMessageDialog(this, "The batch mode requires that you save all your unsaved changes first.");
return; // early return
}
File temp = File.createTempFile("rejava", "folder");
boolean deleteSuccess = temp.delete();
if (!deleteSuccess) {
JOptionPane.showMessageDialog(this, "Could not remove temporary file (" + temp.getAbsolutePath() + ") needed for batch operation.");
return; // early return
}
boolean mkdirSuccess = temp.mkdirs();
if (!mkdirSuccess) {
JOptionPane.showMessageDialog(this, "Could not create temporary folder (" + temp.getAbsolutePath() + ") needed for batch operation.");
return; // early return
}
if (batch) {
final Folder tempFileSet = new Folder(temp);
tempFileSet.getContentsFrom(originalFileSet);
project.setFileSet(tempFileSet);
}
List<IteratorAgent> obfuscators = new ArrayList<IteratorAgent>();
if (this.stripLineInfo.isSelected()) {
obfuscators.add(new LineNumberStripper(batch) {
@Override
public void processException(Exception ex) {
SystemFacade.getInstance().handleException(ex);
}
@Override
public void postProcessFile(IterationContext ic) {
super.postProcessFile(ic);
if (batch) {
save(ic);
}
}
});
}
if (this.stripVarsCheck.isSelected()) {
obfuscators.add(new LocalVarStripper(batch) {
@Override
public void processException(Exception ex) {
SystemFacade.getInstance().handleException(ex);
}
@Override
public void postProcessFile(IterationContext ic) {
super.postProcessFile(ic);
if (batch) {
save(ic);
}
}
});
}
if (this.renameClassesCheck.isSelected()) {
ClassNameObfuscatingAdvisor nameObfuscatorAdvisor = new ClassNameObfuscatingAdvisor(classNames);
AbstractIteratorAgent agent = new RefactoringIterator(nameObfuscatorAdvisor, batch) {
@Override
public void processException(Exception ex) {
SystemFacade.getInstance().handleException(ex);
}
@Override
public void postProcessFile(IterationContext ic) {
super.postProcessFile(ic);
if (batch) {
save(ic);
}
}
};
obfuscators.add(agent);
}
/*
if (this.renameFieldsCheck.isSelected()) {
List<String> classNames = SystemFacade.getInstance().getClassIndex().getClassNames(project.getFileSet());
FieldNameObfuscatingAdvisor nameObfuscatorAdvisor = new FieldNameObfuscatingAdvisor(classNames);
AbstractIteratorAgent agent = new RefactoringIterator(nameObfuscatorAdvisor);
obfuscators.add(agent);
}*/
if (this.legalizeClassesCheck.isSelected()) {
ClassNameLegalizingAdvisor nameLegalizingAdvisor = new ClassNameLegalizingAdvisor(classNames);
AbstractIteratorAgent agent = new RefactoringIterator(nameLegalizingAdvisor, batch) {
@Override
public void processException(Exception ex) {
SystemFacade.getInstance().handleException(ex);
}
@Override
public void postProcessFile(IterationContext ic) {
super.postProcessFile(ic);
if (batch) {
save(ic);
}
}
};
obfuscators.add(agent);
}
if (this.legalizeMethodsCheck.isSelected()) {
MethodNameLegalizingAdvisor nameLegalizingAdvisor = new MethodNameLegalizingAdvisor(classNames);
AbstractIteratorAgent agent = new RefactoringIterator(nameLegalizingAdvisor, batch) {
@Override
public void processException(Exception ex) {
SystemFacade.getInstance().handleException(ex);
}
@Override
public void postProcessFile(IterationContext ic) {
super.postProcessFile(ic);
if (batch) {
save(ic);
}
}
};
obfuscators.add(agent);
}
if (this.legalizeFieldsCheck.isSelected()) {
FieldNameLegalizingAdvisor nameLegalizingAdvisor = new FieldNameLegalizingAdvisor(classNames);
AbstractIteratorAgent agent = new RefactoringIterator(nameLegalizingAdvisor, batch) {
@Override
public void processException(Exception ex) {
SystemFacade.getInstance().handleException(ex);
}
@Override
public void postProcessFile(IterationContext ic) {
super.postProcessFile(ic);
if (batch) {
save(ic);
}
}
};
obfuscators.add(agent);
}
for (int i = 0; i < obfuscators.size(); i++) {
AbstractIteratorAgent obf = (AbstractIteratorAgent)obfuscators.get(i);
obf.setProgressMonitor(SystemFacade.getInstance().
getProgressMonitor());
}
ProjectIterator.iterate(project, obfuscators, new IterationNotificationListener() {
public void finished() {
if (batch) {
try {
FileSet temp = project.getFileSet();
originalFileSet.getContentsFrom(temp);
project.setFileSet(originalFileSet);
temp.removeAllFiles();
dispatcher.notifyObservers(new Event(EventType.PROJECT_UPDATE));
} catch (IOException ioe) {
SystemFacade.getInstance().handleException(ioe);
}
}