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.plugin.MojoExecutionException; |
28 | |
import org.apache.maven.plugin.eclipse.Constants; |
29 | |
import org.apache.maven.plugin.eclipse.Messages; |
30 | |
import org.apache.maven.plugin.eclipse.writers.AbstractEclipseWriter; |
31 | |
import org.apache.maven.plugin.ide.IdeDependency; |
32 | |
import org.apache.maven.plugin.ide.IdeUtils; |
33 | |
import org.apache.maven.plugin.ide.JeeUtils; |
34 | |
import org.codehaus.plexus.util.IOUtil; |
35 | |
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; |
36 | |
import org.codehaus.plexus.util.xml.XMLWriter; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public class RadWebSettingsWriter |
44 | |
extends AbstractEclipseWriter |
45 | |
{ |
46 | |
|
47 | |
private static final String COM_IBM_ETOOLS_SITEEDIT_WIZARDS_PROJECTFEATURE_WEB_SITE_FEATURE = |
48 | |
"com.ibm.etools.siteedit.wizards.projectfeature.WebSiteFeature"; |
49 | |
|
50 | |
private static final String WEBSETTINGS_CONTEXT_ROOT = "context-root"; |
51 | |
|
52 | |
private static final String WEBSETTINGS_FEATURE = "feature"; |
53 | |
|
54 | |
private static final String WEBSETTINGS_FEATURE_ID = "feature-id"; |
55 | |
|
56 | |
private static final String WEBSETTINGS_FEATURES = "features"; |
57 | |
|
58 | |
private static final String WEBSETTINGS_FILENAME = ".websettings"; |
59 | |
|
60 | |
private static final String WEBSETTINGS_JSP_LEVEL = "jsp-level"; |
61 | |
|
62 | |
private static final String WEBSETTINGS_PROJECT_TYPE = "project-type"; |
63 | |
|
64 | |
private static final String WEBSETTINGS_TEMPLATEFEATURE = "templatefeature"; |
65 | |
|
66 | |
private static final String WEBSETTINGS_VERSION = "version"; |
67 | |
|
68 | |
private static final String WEBSETTINGS_WEBCONTENT = "webcontent"; |
69 | |
|
70 | |
private static final String WEBSETTINGS_WEBSETTINGS = "websettings"; |
71 | |
|
72 | |
private static final String WEBSETTINGS_LIBMODULES = "lib-modules"; |
73 | |
|
74 | |
private static final String WEBSETTINGS_LIBMODULE = "lib-module"; |
75 | |
|
76 | |
private static final String WEBSETTINGS_LM_JAR = "jar"; |
77 | |
|
78 | |
private static final String WEBSETTINGS_LM_PROJECT = "project"; |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
private String warContextRoot; |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public RadWebSettingsWriter( String warContextRoot ) |
91 | 0 | { |
92 | 0 | this.warContextRoot = warContextRoot; |
93 | 0 | } |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
public void write() |
101 | |
throws MojoExecutionException |
102 | |
{ |
103 | |
Writer w; |
104 | 0 | if ( Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase( config.getPackaging() ) ) |
105 | |
{ |
106 | |
try |
107 | |
{ |
108 | 0 | w = |
109 | |
new OutputStreamWriter( new FileOutputStream( new File( config.getEclipseProjectDirectory(), |
110 | |
WEBSETTINGS_FILENAME ) ), "UTF-8" ); |
111 | |
} |
112 | 0 | catch ( IOException ex ) |
113 | |
{ |
114 | 0 | throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); |
115 | 0 | } |
116 | |
|
117 | 0 | XMLWriter writer = new PrettyPrintXMLWriter( w, "UTF-8", null ); |
118 | 0 | writeModuleTypeFacetCore( writer ); |
119 | 0 | IOUtil.close( w ); |
120 | |
} |
121 | 0 | } |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
private void writeModuleTypeFacetCore( XMLWriter writer ) |
130 | |
throws MojoExecutionException |
131 | |
{ |
132 | 0 | writer.startElement( WEBSETTINGS_WEBSETTINGS ); |
133 | 0 | writer.addAttribute( WEBSETTINGS_VERSION, "600" ); |
134 | 0 | writer.startElement( WEBSETTINGS_WEBCONTENT ); |
135 | |
|
136 | |
|
137 | 0 | File warSourceDirectory = |
138 | |
new File( IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN, |
139 | |
"warSourceDirectory", |
140 | |
config.getProject().getBasedir() + "/src/main/webapp" ) ); |
141 | 0 | String webContentDir = |
142 | |
IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), warSourceDirectory, false ); |
143 | |
|
144 | 0 | writer.writeText( webContentDir ); |
145 | |
|
146 | 0 | writer.endElement(); |
147 | 0 | writer.startElement( WEBSETTINGS_CONTEXT_ROOT ); |
148 | 0 | writer.writeText( getContextRoot( warContextRoot ) ); |
149 | 0 | writer.endElement(); |
150 | 0 | writer.startElement( WEBSETTINGS_PROJECT_TYPE ); |
151 | 0 | writer.writeText( "J2EE" ); |
152 | 0 | writer.endElement(); |
153 | 0 | writer.startElement( WEBSETTINGS_JSP_LEVEL ); |
154 | 0 | writer.writeText( JeeUtils.resolveJspVersion( config.getProject() ) ); |
155 | 0 | writer.endElement(); |
156 | 0 | writer.startElement( WEBSETTINGS_FEATURES ); |
157 | 0 | writer.startElement( WEBSETTINGS_FEATURE ); |
158 | 0 | writer.startElement( WEBSETTINGS_FEATURE_ID ); |
159 | 0 | writer.writeText( WEBSETTINGS_TEMPLATEFEATURE ); |
160 | 0 | writer.endElement(); |
161 | 0 | writer.endElement(); |
162 | 0 | writer.startElement( WEBSETTINGS_FEATURE ); |
163 | 0 | writer.startElement( WEBSETTINGS_FEATURE_ID ); |
164 | 0 | writer.writeText( COM_IBM_ETOOLS_SITEEDIT_WIZARDS_PROJECTFEATURE_WEB_SITE_FEATURE ); |
165 | 0 | writer.endElement(); |
166 | 0 | writer.endElement(); |
167 | 0 | writer.endElement(); |
168 | |
|
169 | |
|
170 | 0 | writer.startElement( WEBSETTINGS_LIBMODULES ); |
171 | |
|
172 | |
|
173 | 0 | IdeDependency[] deps = config.getDepsOrdered(); |
174 | 0 | if ( deps != null ) |
175 | |
{ |
176 | 0 | for ( int i = 0; i < deps.length; i++ ) |
177 | |
{ |
178 | 0 | final IdeDependency dependency = deps[i]; |
179 | 0 | log.debug( "RadWebSettingsWriter: checking dependency " + dependency.toString() ); |
180 | |
|
181 | 0 | if ( dependency.isReferencedProject() && !dependency.isTestDependency() && !dependency.isProvided() ) |
182 | |
{ |
183 | 0 | log.debug( "RadWebSettingsWriter: dependency " + dependency.toString() |
184 | |
+ " selected for inclusion as lib-module" ); |
185 | |
|
186 | 0 | String depName = dependency.getEclipseProjectName(); |
187 | 0 | String depJar = dependency.getArtifactId() + ".jar"; |
188 | |
|
189 | 0 | writer.startElement( WEBSETTINGS_LIBMODULE ); |
190 | |
|
191 | 0 | writer.startElement( WEBSETTINGS_LM_JAR ); |
192 | 0 | writer.writeText( depJar ); |
193 | 0 | writer.endElement(); |
194 | |
|
195 | 0 | writer.startElement( WEBSETTINGS_LM_PROJECT ); |
196 | 0 | writer.writeText( depName ); |
197 | 0 | writer.endElement(); |
198 | |
|
199 | 0 | writer.endElement(); |
200 | |
} |
201 | |
} |
202 | |
} |
203 | |
|
204 | 0 | writer.endElement(); |
205 | 0 | writer.endElement(); |
206 | |
|
207 | 0 | } |
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
private String getContextRoot( String warContextRoot ) |
216 | |
{ |
217 | 0 | if ( warContextRoot == null || warContextRoot.length() == 0 ) |
218 | |
{ |
219 | 0 | return config.getProject().getArtifactId(); |
220 | |
} |
221 | |
else |
222 | |
{ |
223 | 0 | return warContextRoot; |
224 | |
} |
225 | |
} |
226 | |
|
227 | |
} |