w = new OutputStreamWriter(new FileOutputStream(dotProject), "UTF-8");
} catch (IOException ex) {
throw new MojoExecutionException(Messages.getString("EclipsePlugin.erroropeningfile"), ex); //$NON-NLS-1$
}
XMLWriter writer = new PrettyPrintXMLWriter(w, "UTF-8", null);
writer.startElement("projectDescription"); //$NON-NLS-1$
writer.startElement(ELT_NAME);
writer.writeText(config.getEclipseProjectName());
writer.endElement();
addComment(writer, config.getProject().getDescription());
writer.startElement("projects"); //$NON-NLS-1$
IdeDependency[] dependencies = config.getDeps();
// referenced projects should not be added for plugins
if (!config.isPde()) {
List duplicates = new ArrayList();
for (int j = 0; j < dependencies.length; j++) {
IdeDependency dep = dependencies[j];
// Avoid duplicates entries when same project is refered using multiple types
// (ejb, test-jar ...)
if (dep.isReferencedProject() && !duplicates.contains(dep.getEclipseProjectName())) {
writer.startElement("project"); //$NON-NLS-1$
writer.writeText(dep.getEclipseProjectName());
writer.endElement();
duplicates.add(dep.getEclipseProjectName());
}
}
}
writer.endElement(); // projects
writer.startElement(ELT_BUILD_SPEC);
for (Iterator it = buildCommands.iterator(); it.hasNext(); ) {
((BuildCommand) it.next()).print(writer);
}
writer.endElement(); // buildSpec
writer.startElement(ELT_NATURES);
for (Iterator it = projectnatures.iterator(); it.hasNext(); ) {
writer.startElement(ELT_NATURE);
writer.writeText((String) it.next());
writer.endElement(); // name
}
writer.endElement(); // natures
boolean addLinks = !config.getProjectBaseDir().equals(config.getEclipseProjectDirectory());
if (addLinks || (config.isPde() && dependencies.length > 0) || linkedResources.size() > 0) {
writer.startElement("linkedResources"); //$NON-NLS-1$
// preserve the symbolic links
if (linkedResources.size() > 0) {
for (Iterator it = linkedResources.iterator(); it.hasNext(); ) {
((LinkedResource) it.next()).print(writer);
}
}
if (addLinks) {
addFileLink(writer, config.getProjectBaseDir(), config.getEclipseProjectDirectory(),
config.getProject().getFile());
addSourceLinks(writer, config.getProjectBaseDir(), config.getEclipseProjectDirectory(),
config.getProject().getCompileSourceRoots());
addResourceLinks(writer, config.getProjectBaseDir(), config.getEclipseProjectDirectory(),
config.getProject().getBuild().getResources());
addSourceLinks(writer, config.getProjectBaseDir(), config.getEclipseProjectDirectory(),
config.getProject().getTestCompileSourceRoots());
addResourceLinks(writer, config.getProjectBaseDir(), config.getEclipseProjectDirectory(),
config.getProject().getBuild().getTestResources());
}
writeResourceLinksForPdeProject(writer, dependencies);
writer.endElement(); // linkedResources
}
writer.endElement(); // projectDescription
IOUtil.close(w);
}