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.wtp; |
20 | |
|
21 | |
import java.io.File; |
22 | |
|
23 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
24 | |
import org.apache.maven.plugin.MojoExecutionException; |
25 | |
import org.apache.maven.plugin.eclipse.Constants; |
26 | |
import org.apache.maven.plugin.eclipse.Messages; |
27 | |
import org.apache.maven.plugin.eclipse.writers.AbstractEclipseWriter; |
28 | |
import org.apache.maven.plugin.ide.IdeDependency; |
29 | |
import org.apache.maven.plugin.ide.IdeUtils; |
30 | |
import org.apache.maven.plugin.ide.JeeUtils; |
31 | |
import org.apache.maven.project.MavenProject; |
32 | |
import org.codehaus.plexus.util.xml.XMLWriter; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public abstract class AbstractWtpResourceWriter |
41 | |
extends AbstractEclipseWriter |
42 | |
{ |
43 | |
|
44 | |
private static final String ELT_DEPENDENCY_OBJECT = "dependent-object"; |
45 | |
|
46 | |
private static final String ELT_DEPENDENCY_TYPE = "dependency-type"; |
47 | |
|
48 | |
private static final String ATTR_HANDLE = "handle"; |
49 | |
|
50 | |
private static final String ELT_DEPENDENT_MODULE = "dependent-module"; |
51 | |
|
52 | |
protected static final String ATTR_VALUE = "value"; |
53 | |
|
54 | |
protected static final String ATTR_NAME = "name"; |
55 | |
|
56 | |
protected static final String ELT_PROPERTY = "property"; |
57 | |
|
58 | |
protected static final String ELT_VERSION = "version"; |
59 | |
|
60 | |
protected static final String ATTR_MODULE_TYPE_ID = "module-type-id"; |
61 | |
|
62 | |
protected static final String ATTR_SOURCE_PATH = "source-path"; |
63 | |
|
64 | |
protected static final String ATTR_DEPLOY_PATH = "deploy-path"; |
65 | |
|
66 | |
protected static final String ELT_WB_RESOURCE = "wb-resource"; |
67 | |
|
68 | |
protected static final String ELT_MODULE_TYPE = "module-type"; |
69 | |
|
70 | |
protected static final String ATTR_DEPLOY_NAME = "deploy-name"; |
71 | |
|
72 | |
protected static final String ELT_WB_MODULE = "wb-module"; |
73 | |
|
74 | |
protected static final String ATTR_MODULE_ID = "id"; |
75 | |
|
76 | |
protected static final String ATTR_PROJECT_VERSION = "project-version"; |
77 | |
|
78 | |
protected static final String ELT_PROJECT_MODULES = "project-modules"; |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
protected void writeModuleTypeAccordingToPackaging( MavenProject project, XMLWriter writer, |
86 | |
File buildOutputDirectory ) |
87 | |
throws MojoExecutionException |
88 | |
{ |
89 | 0 | if ( Constants.PROJECT_PACKAGING_WAR.equals( config.getPackaging() ) ) |
90 | |
{ |
91 | 0 | writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.web" ); |
92 | |
|
93 | 0 | writer.startElement( ELT_VERSION ); |
94 | |
|
95 | 0 | writer.writeText( JeeUtils.resolveServletVersion( config.getProject() ) ); |
96 | 0 | writer.endElement(); |
97 | |
|
98 | 0 | String contextRoot = config.getContextName(); |
99 | |
|
100 | 0 | writer.startElement( ELT_PROPERTY ); |
101 | 0 | writer.addAttribute( ATTR_NAME, "context-root" ); |
102 | 0 | writer.addAttribute( ATTR_VALUE, contextRoot ); |
103 | 0 | writer.endElement(); |
104 | |
} |
105 | 0 | else if ( Constants.PROJECT_PACKAGING_EJB.equals( config.getPackaging() ) ) |
106 | |
{ |
107 | 0 | writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.ejb" ); |
108 | |
|
109 | 0 | writer.startElement( ELT_VERSION ); |
110 | 0 | writer.writeText( JeeUtils.resolveEjbVersion( config.getProject() ) ); |
111 | |
|
112 | 0 | writer.endElement(); |
113 | |
|
114 | 0 | writer.startElement( ELT_PROPERTY ); |
115 | 0 | writer.addAttribute( ATTR_NAME, "java-output-path" ); |
116 | 0 | writer.addAttribute( ATTR_VALUE, "/" + |
117 | |
IdeUtils.toRelativeAndFixSeparator( config.getProject().getBasedir(), buildOutputDirectory, false ) ); |
118 | 0 | writer.endElement(); |
119 | |
|
120 | |
} |
121 | 0 | else if ( Constants.PROJECT_PACKAGING_EAR.equals( config.getPackaging() ) ) |
122 | |
{ |
123 | 0 | writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.ear" ); |
124 | |
|
125 | 0 | writer.startElement( ELT_VERSION ); |
126 | 0 | writer.writeText( JeeUtils.resolveJeeVersion( config.getProject() ) ); |
127 | 0 | writer.endElement(); |
128 | |
} |
129 | |
else |
130 | |
{ |
131 | |
|
132 | 0 | writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.utility" ); |
133 | |
|
134 | 0 | writer.startElement( ELT_PROPERTY ); |
135 | 0 | writer.addAttribute( ATTR_NAME, "java-output-path" ); |
136 | 0 | writer.addAttribute( ATTR_VALUE, "/" + |
137 | |
IdeUtils.toRelativeAndFixSeparator( config.getProject().getBasedir(), buildOutputDirectory, false ) ); |
138 | 0 | writer.endElement(); |
139 | |
} |
140 | 0 | } |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
protected void addDependency( XMLWriter writer, IdeDependency dep, ArtifactRepository localRepository, |
152 | |
File basedir, String deployPath ) |
153 | |
throws MojoExecutionException |
154 | |
{ |
155 | |
String handle; |
156 | 0 | String dependentObject = null; |
157 | |
String archiveName; |
158 | |
|
159 | |
|
160 | 0 | if ( Constants.PROJECT_PACKAGING_WAR.equals( dep.getType() ) |
161 | |
|| Constants.PROJECT_PACKAGING_EJB.equals( dep.getType() ) ) |
162 | |
{ |
163 | 0 | deployPath = "/"; |
164 | |
} |
165 | |
|
166 | 0 | if ( dep.isReferencedProject() ) |
167 | |
{ |
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | 0 | handle = "module:/resource/" + dep.getEclipseProjectName() + "/" + dep.getEclipseProjectName(); |
174 | 0 | if ( Constants.PROJECT_PACKAGING_EJB.equals( dep.getType() ) ) |
175 | |
{ |
176 | 0 | dependentObject = "EjbModule_"; |
177 | |
} |
178 | 0 | else if ( Constants.PROJECT_PACKAGING_WAR.equals( dep.getType() ) ) |
179 | |
{ |
180 | 0 | dependentObject = "WebModule_"; |
181 | |
} |
182 | 0 | archiveName = dep.getEclipseProjectName() + "." + dep.getType(); |
183 | |
} |
184 | |
else |
185 | |
{ |
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | 0 | File artifactPath = dep.getFile(); |
192 | |
|
193 | 0 | if ( artifactPath == null ) |
194 | |
{ |
195 | 0 | log.error( Messages.getString( "EclipsePlugin.artifactpathisnull", dep.getId() ) ); |
196 | 0 | return; |
197 | |
} |
198 | |
|
199 | 0 | String fullPath = artifactPath.getPath(); |
200 | 0 | File repoFile = new File( fullPath ); |
201 | |
|
202 | 0 | if ( dep.isSystemScoped() ) |
203 | |
{ |
204 | 0 | handle = "module:/classpath/lib/" |
205 | |
+ IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), repoFile, false ); |
206 | |
} |
207 | |
else |
208 | |
{ |
209 | 0 | File localRepositoryFile = new File( localRepository.getBasedir() ); |
210 | 0 | String relativePath = IdeUtils.toRelativeAndFixSeparator( localRepositoryFile, repoFile, false ); |
211 | |
|
212 | 0 | if ( !new File( relativePath ).isAbsolute() ) |
213 | |
{ |
214 | 0 | handle = "module:/classpath/var/M2_REPO/" |
215 | |
+ relativePath; |
216 | |
} |
217 | |
else |
218 | |
{ |
219 | 0 | handle = "module:/classpath/lib/" |
220 | |
+ IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), repoFile, false ); |
221 | |
} |
222 | |
} |
223 | 0 | if ( Constants.PROJECT_PACKAGING_EAR.equals( this.config.getPackaging() ) && !"/".equals( deployPath ) ) |
224 | |
{ |
225 | |
|
226 | |
|
227 | |
|
228 | 0 | archiveName = "../" + artifactPath.getName(); |
229 | |
} |
230 | |
else |
231 | |
{ |
232 | 0 | archiveName = artifactPath.getName(); |
233 | |
} |
234 | |
} |
235 | |
|
236 | 0 | writer.startElement( ELT_DEPENDENT_MODULE ); |
237 | |
|
238 | 0 | writer.addAttribute( "archiveName", archiveName ); |
239 | |
|
240 | 0 | writer.addAttribute( ATTR_DEPLOY_PATH, deployPath ); |
241 | 0 | writer.addAttribute( ATTR_HANDLE, handle ); |
242 | |
|
243 | 0 | if ( dependentObject != null && config.getWtpVersion() >= 2.0f ) |
244 | |
{ |
245 | 0 | writer.startElement( ELT_DEPENDENCY_OBJECT ); |
246 | 0 | writer.writeText( dependentObject + System.identityHashCode( dep ) ); |
247 | 0 | writer.endElement(); |
248 | |
} |
249 | |
|
250 | 0 | writer.startElement( ELT_DEPENDENCY_TYPE ); |
251 | 0 | writer.writeText( "uses" ); |
252 | 0 | writer.endElement(); |
253 | |
|
254 | 0 | writer.endElement(); |
255 | 0 | } |
256 | |
|
257 | |
protected void writeWarOrEarResources( XMLWriter writer, MavenProject project, ArtifactRepository localRepository ) |
258 | |
throws MojoExecutionException |
259 | |
{ |
260 | |
|
261 | 0 | String deployDir = |
262 | |
IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN, "defaultLibBundleDir", |
263 | |
"/" ); |
264 | |
|
265 | 0 | if ( project.getPackaging().equals( Constants.PROJECT_PACKAGING_WAR ) ) |
266 | |
{ |
267 | 0 | deployDir = "/WEB-INF/lib"; |
268 | |
} |
269 | |
|
270 | 0 | for ( int j = 0; j < config.getDepsOrdered().length; j++ ) |
271 | |
{ |
272 | 0 | IdeDependency dep = config.getDepsOrdered()[j]; |
273 | 0 | String type = dep.getType(); |
274 | |
|
275 | |
|
276 | |
|
277 | 0 | if ( ( !dep.isTestDependency() && !dep.isProvided() && !dep.isSystemScopedOutsideProject( project ) ) |
278 | |
&& ( Constants.PROJECT_PACKAGING_JAR.equals( type ) || Constants.PROJECT_PACKAGING_EJB.equals( type ) |
279 | |
|| "ejb-client".equals( type ) || Constants.PROJECT_PACKAGING_WAR.equals( type ) ) ) |
280 | |
{ |
281 | 0 | addDependency( writer, dep, localRepository, config.getProject().getBasedir(), deployDir ); |
282 | |
} |
283 | |
} |
284 | 0 | } |
285 | |
|
286 | |
} |