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 | |
String servletVersion; |
108 | 0 | if ( config.getJeeVersion() != null ) |
109 | |
{ |
110 | 0 | servletVersion = JeeUtils.getJeeDescriptorFromJeeVersion( config.getJeeVersion() ).getServletVersion(); |
111 | |
} |
112 | |
else |
113 | |
{ |
114 | 0 | servletVersion = JeeUtils.resolveServletVersion( config.getProject() ); |
115 | |
} |
116 | 0 | writer.writeText( "" + servletVersion.charAt( 0 ) + servletVersion.charAt( 2 ) ); |
117 | 0 | } |
118 | 0 | else if ( Constants.PROJECT_PACKAGING_EJB.equalsIgnoreCase( packaging ) ) |
119 | |
{ |
120 | |
|
121 | |
String ejbVersion; |
122 | 0 | if ( config.getJeeVersion() != null ) |
123 | |
{ |
124 | 0 | ejbVersion = JeeUtils.getJeeDescriptorFromJeeVersion( config.getJeeVersion() ).getEjbVersion(); |
125 | |
} |
126 | |
else |
127 | |
{ |
128 | 0 | ejbVersion = JeeUtils.resolveEjbVersion( config.getProject() ); |
129 | |
} |
130 | 0 | writer.writeText( "" + ejbVersion.charAt( 0 ) + ejbVersion.charAt( 2 ) ); |
131 | 0 | } |
132 | 0 | else if ( Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) ) |
133 | |
{ |
134 | |
|
135 | |
String jeeVersion; |
136 | 0 | if ( config.getJeeVersion() != null ) |
137 | |
{ |
138 | 0 | jeeVersion = JeeUtils.getJeeDescriptorFromJeeVersion( config.getJeeVersion() ).getJeeVersion(); |
139 | |
} |
140 | |
else |
141 | |
{ |
142 | 0 | jeeVersion = JeeUtils.resolveJeeVersion( config.getProject() ); |
143 | |
} |
144 | 0 | writer.writeText( "" + jeeVersion.charAt( 0 ) + jeeVersion.charAt( 2 ) ); |
145 | |
} |
146 | 0 | writer.endElement(); |
147 | 0 | writer.endElement(); |
148 | 0 | } |
149 | |
|
150 | |
} |