in netbeansintegration/tags/4.1.0/src/org/openoffice/extensions/util/ClasspathUpdater.java [126:222]
public static void removeIdlTypesFromJavaClasspath(Project project) {
final FileObject projectDir = project.getProjectDirectory();
final String IDL_JAR_NAME = ProjectTypeHelper.getObjectFromUnoProperties(projectDir,
"idl_types.jar").toString(); // NOI18N
final String propName = "file.reference.".concat(IDL_JAR_NAME);
final String javacPropName = "javac.classpath";
Vector<String> allLines = new Vector<String>();
FileObject nbProject = projectDir.getFileObject("nbproject");
if (nbProject == null) return; // may happen when project is in process of deleting
FileObject projectProps = nbProject.getFileObject("project.properties");
if (projectProps == null) return; // may happen when project is in process of deleting
boolean writeOut = false;
// read the stuff
BufferedReader buf = null;
InputStream in = null;
try {
in = projectProps.getInputStream();
if (in == null) {
LogWriter.getLogWriter().log(LogWriter.LEVEL_CRITICAL, "cannot get inputstream from project properties"); // NOI18N
return;
}
buf = new BufferedReader(new InputStreamReader(in));
String line = null;
while(buf.ready() && (line = buf.readLine()) != null) {
if (line.startsWith(javacPropName)) {
writeOut = true;
removeEntryFromClassPath(line, propName, allLines);
// handle javac.classpath extending over several lines
while (buf.ready() && line.endsWith(LINE_ENDING) &&
(line = buf.readLine()) != null) {
removeEntryFromClassPath(line, propName, allLines);
}
}
else if (line.startsWith(propName)) {
writeOut = true;
// handle file.reference.IDL_types.jar extending over several lines
while (buf.ready() && line.endsWith(LINE_ENDING) && (line = buf.readLine()) != null) {
// all done in while statement...
}
}
else {
allLines.add(line);
}
}
} catch (IOException ex) {
writeOut = false;
LogWriter.getLogWriter().printStackTrace(ex);
}
finally { // all other exceptions produce a message box in ide: nothing will be written...
if (buf != null) {
try {
buf.close();
} catch (IOException ex) {
LogWriter.getLogWriter().printStackTrace(ex);
}
}
else if (in != null) {
try {
in.close();
} catch (IOException ex) {
LogWriter.getLogWriter().printStackTrace(ex);
}
}
}
// write out again, but only when something was changed
if (writeOut) {
OutputStream out = null;
BufferedWriter write = null;
try {
out = projectProps.getOutputStream();
write = new BufferedWriter(new OutputStreamWriter(out));
for (int i=0; i<allLines.size(); i++) {
write.write(allLines.get(i));
write.newLine();
}
write.flush();
} catch (IOException ex) {
LogWriter.getLogWriter().printStackTrace(ex);
}
finally {
if (write != null) {
try {
write.close();
} catch (IOException ex) {
LogWriter.getLogWriter().printStackTrace(ex);
}
}
else if (out != null) {
try {
out.close();
} catch (IOException ex) {
LogWriter.getLogWriter().printStackTrace(ex);
}
}
}
}
}