View Javadoc
1   package org.andromda.maven.plugin.andromdapp.eclipse;
2   
3   import java.io.File;
4   import java.io.FileWriter;
5   import org.apache.maven.plugin.logging.Log;
6   import org.apache.maven.project.MavenProject;
7   import org.codehaus.plexus.util.IOUtil;
8   import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
9   import org.codehaus.plexus.util.xml.XMLWriter;
10  
11  /**
12   * Writes .project files for Eclipse.
13   *
14   * @author Chad Brandon
15   */
16  public class ProjectWriter
17      extends EclipseWriter
18  {
19      /**
20       * @param project
21       * @param logger
22       */
23      public ProjectWriter(
24          final MavenProject project,
25          final Log logger)
26      {
27          super(project, logger);
28      }
29  
30      /**
31       * Writes the .classpath file for Eclipse.
32       * @throws Exception
33       */
34      public void write()
35          throws Exception
36      {
37          final File projectFile = this.getFile(".project");
38          final FileWriter fileWriter = new FileWriter(projectFile);
39          final XMLWriter writer = new PrettyPrintXMLWriter(fileWriter);
40          writer.startElement("projectDescription");
41          writer.startElement("name");
42          writer.writeText(this.project.getArtifactId());
43          writer.endElement();
44          writer.startElement("comment");
45          writer.endElement();
46          writer.startElement("projects");
47          writer.endElement();
48          writer.startElement("buildSpec");
49          writer.startElement("buildCommand");
50          writer.startElement("name");
51          writer.writeText("org.eclipse.jdt.core.javabuilder");
52          writer.endElement();
53          writer.startElement("arguments");
54          writer.endElement();
55          writer.endElement();
56          writer.endElement();
57          writer.startElement("natures");
58          writer.startElement("nature");
59          writer.writeText("org.eclipse.jdt.core.javanature");
60          writer.endElement();
61          writer.endElement();
62          writer.endElement();
63          IOUtil.close(fileWriter);
64          this.logger.info("Project file written --> '" + projectFile + '\'');
65      }
66  }