1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.eclipse.writers.rad;
20
21 import java.io.File;
22 import java.io.FileOutputStream;
23 import java.io.IOException;
24 import java.io.OutputStreamWriter;
25 import java.io.Writer;
26
27 import org.apache.maven.artifact.repository.ArtifactRepository;
28 import org.apache.maven.plugin.MojoExecutionException;
29 import org.apache.maven.plugin.eclipse.Constants;
30 import org.apache.maven.plugin.eclipse.EclipseSourceDir;
31 import org.apache.maven.plugin.eclipse.Messages;
32 import org.apache.maven.plugin.eclipse.writers.AbstractEclipseWriter;
33 import org.apache.maven.plugin.eclipse.writers.wtp.AbstractWtpResourceWriter;
34 import org.apache.maven.plugin.ide.JeeUtils;
35 import org.codehaus.plexus.util.IOUtil;
36 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
37 import org.codehaus.plexus.util.xml.XMLWriter;
38
39
40
41
42
43
44
45 public class RadJ2EEWriter
46 extends AbstractEclipseWriter
47 {
48
49 private static final String J2EE_FILENAME = ".j2ee";
50
51 private static final String J2EE_J2EESETTINGS = "j2eesettings";
52
53 private static final String J2EE_MODULEVERSION = "moduleversion";
54
55 private static final String J2EE_VERSION = "version";
56
57
58
59
60
61
62
63
64
65
66 public void write()
67 throws MojoExecutionException
68 {
69 Writer w;
70 String packaging = config.getPackaging();
71
72 if ( Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase( packaging )
73 || Constants.PROJECT_PACKAGING_EJB.equalsIgnoreCase( packaging )
74 || Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) )
75 {
76 try
77 {
78 w =
79 new OutputStreamWriter( new FileOutputStream( new File( config.getEclipseProjectDirectory(),
80 J2EE_FILENAME ) ), "UTF-8" );
81 }
82 catch ( IOException ex )
83 {
84 throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex );
85 }
86
87 XMLWriter writer = new PrettyPrintXMLWriter( w, "UTF-8", null );
88 writeModuleTypeFacetCore( writer, packaging );
89 IOUtil.close( w );
90 }
91 }
92
93
94
95
96
97
98
99 private void writeModuleTypeFacetCore( XMLWriter writer, String packaging )
100 {
101 writer.startElement( J2EE_J2EESETTINGS );
102 writer.addAttribute( J2EE_VERSION, "600" );
103 writer.startElement( J2EE_MODULEVERSION );
104 if ( Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase( packaging ) )
105 {
106
107 String servletVersion;
108 if ( config.getJeeVersion() != null )
109 {
110 servletVersion = JeeUtils.getJeeDescriptorFromJeeVersion( config.getJeeVersion() ).getServletVersion();
111 }
112 else
113 {
114 servletVersion = JeeUtils.resolveServletVersion( config.getProject() );
115 }
116 writer.writeText( "" + servletVersion.charAt( 0 ) + servletVersion.charAt( 2 ) );
117 }
118 else if ( Constants.PROJECT_PACKAGING_EJB.equalsIgnoreCase( packaging ) )
119 {
120
121 String ejbVersion;
122 if ( config.getJeeVersion() != null )
123 {
124 ejbVersion = JeeUtils.getJeeDescriptorFromJeeVersion( config.getJeeVersion() ).getEjbVersion();
125 }
126 else
127 {
128 ejbVersion = JeeUtils.resolveEjbVersion( config.getProject() );
129 }
130 writer.writeText( "" + ejbVersion.charAt( 0 ) + ejbVersion.charAt( 2 ) );
131 }
132 else if ( Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) )
133 {
134
135 String jeeVersion;
136 if ( config.getJeeVersion() != null )
137 {
138 jeeVersion = JeeUtils.getJeeDescriptorFromJeeVersion( config.getJeeVersion() ).getJeeVersion();
139 }
140 else
141 {
142 jeeVersion = JeeUtils.resolveJeeVersion( config.getProject() );
143 }
144 writer.writeText( "" + jeeVersion.charAt( 0 ) + jeeVersion.charAt( 2 ) );
145 }
146 writer.endElement();
147 writer.endElement();
148 }
149
150 }