1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| public boolean performFinish() {
boolean ret = super.performFinish();
if (ret) {
try {
WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
protected void execute(IProgressMonitor monitor) {
createProject(monitor != null ? monitor
: new NullProgressMonitor());
}
};
getContainer().run(false, false, op);
} catch (InvocationTargetException x) {
} catch (InterruptedException x) {
}
}
return ret;
}
private void createProject(IProgressMonitor monitor) {
monitor.beginTask("Creating BDDF project...", 50);
try {
IPath projetAbsolutePath = getProjectLocationPath().makeAbsolute();
File fdProject = projetAbsolutePath.toFile();
while (!fdProject.exists()) {
fdProject = fdProject;
}
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
try {
createRessources(Platform.getBundle(
BDDFUMLProjectActivator.getDefault().PLUGIN_ID)
.findEntries("ressources/", "*", true), this
.getProjectLocationPath(), "ressources", root, monitor);
} catch (CoreException e) {
BDDFUMLProjectActivator.error("Cannot create project tree", e);
}
} finally {
monitor.done();
}
}
private void createRessources(Enumeration ressources, IPath projectRoot,
String parentAsString, IWorkspaceRoot wks, IProgressMonitor monitor)
throws CoreException {
while (ressources.hasMoreElements()) {
URL pathURL = (URL) ressources.nextElement();
String pathString = pathURL.getFile();
pathString = pathString.substring("ressources/".length());
if (pathString.endsWith("/")) {
IPath subPath = projectRoot.append(pathString);
File fd = subPath.toFile();
if (!fd.exists())
fd.mkdirs();
} else {
IPath subFile = projectRoot.append(pathString);
InputStream stream = this.getClass().getResourceAsStream(
"/" + parentAsString + pathString);
File fd = subFile.toFile();
FileOutputStream fout;
DataInputStream reader=null;
DataOutputStream writer=null;
try {
reader = new DataInputStream(stream);
fout = new FileOutputStream(fd);
writer = new DataOutputStream(fout);
int oread;
byte buffer[] = new byte[255];
while ((oread = reader.read(buffer, 0, 255)) != -1)
writer.write(buffer, 0, oread);
reader.close();
writer.close();
} catch (FileNotFoundException e) {
BDDFUMLProjectActivator.debug(e.getMessage(), e);
try {
if (reader!=null)reader.close();
if (writer!=null)writer.close();
} catch (Exception ex) {
}
}
catch (IOException e) {
BDDFUMLProjectActivator.debug(e.getMessage(), e);
}
}
}
} |
Partager