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 | 0 | 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 | 0 | String packaging = config.getPackaging(); |
71 | |
|
72 | 0 | 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 | 0 | w = |
79 | |
new OutputStreamWriter( new FileOutputStream( new File( config.getEclipseProjectDirectory(), |
80 | |
J2EE_FILENAME ) ), "UTF-8" ); |
81 | |
} |
82 | 0 | catch ( IOException ex ) |
83 | |
{ |
84 | 0 | throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); |
85 | 0 | } |
86 | |
|
87 | 0 | XMLWriter writer = new PrettyPrintXMLWriter( w, "UTF-8", null ); |
88 | 0 | writeModuleTypeFacetCore( writer, packaging ); |
89 | 0 | IOUtil.close( w ); |
90 | |
} |
91 | 0 | } |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
private void writeModuleTypeFacetCore( XMLWriter writer, String packaging ) |
100 | |
{ |
101 | 0 | writer.startElement( J2EE_J2EESETTINGS ); |
102 | 0 | writer.addAttribute( J2EE_VERSION, "600" ); |
103 | 0 | writer.startElement( J2EE_MODULEVERSION ); |
104 | 0 | if ( Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase( packaging ) ) |
105 | |
{ |
106 | |
|
107 | 0 | String servletVersion = JeeUtils.resolveServletVersion( config.getProject() ); |
108 | 0 | writer.writeText( "" + servletVersion.charAt( 0 ) + servletVersion.charAt( 2 ) ); |
109 | 0 | } |
110 | 0 | else if ( Constants.PROJECT_PACKAGING_EJB.equalsIgnoreCase( packaging ) ) |
111 | |
{ |
112 | |
|
113 | 0 | String ejbVersion = JeeUtils.resolveEjbVersion( config.getProject() ); |
114 | 0 | writer.writeText( "" + ejbVersion.charAt( 0 ) + ejbVersion.charAt( 2 ) ); |
115 | 0 | } |
116 | 0 | else if ( Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) ) |
117 | |
{ |
118 | |
|
119 | 0 | String jeeVersion = JeeUtils.resolveJeeVersion( config.getProject() ); |
120 | 0 | writer.writeText( "" + jeeVersion.charAt( 0 ) + jeeVersion.charAt( 2 ) ); |
121 | |
} |
122 | 0 | writer.endElement(); |
123 | 0 | writer.endElement(); |
124 | 0 | } |
125 | |
|
126 | |
} |