1 |
|
package org.apache.maven.plugin.eclipse.writers; |
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
import java.io.File; |
20 |
|
import java.io.FileWriter; |
21 |
|
import java.io.IOException; |
22 |
|
|
23 |
|
import org.apache.maven.plugin.MojoExecutionException; |
24 |
|
import org.apache.maven.plugin.eclipse.Messages; |
25 |
|
import org.codehaus.plexus.util.IOUtil; |
26 |
|
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; |
27 |
|
import org.codehaus.plexus.util.xml.XMLWriter; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
2 |
public class EclipseWtpFacetsWriter |
37 |
|
extends AbstractWtpResourceWriter |
38 |
|
{ |
39 |
|
|
40 |
|
private static final String FACET_JST_EAR = "jst.ear"; |
41 |
|
|
42 |
|
private static final String FACET_JST_UTILITY = "jst.utility"; |
43 |
|
|
44 |
|
private static final String FACET_JST_EJB = "jst.ejb"; |
45 |
|
|
46 |
|
private static final String FACET_JST_WEB = "jst.web"; |
47 |
|
|
48 |
|
private static final String FACET_JST_JAVA = "jst.java"; |
49 |
|
|
50 |
|
private static final String ATTR_VERSION = "version"; |
51 |
|
|
52 |
|
private static final String ELT_INSTALLED = "installed"; |
53 |
|
|
54 |
|
private static final String ATTR_FACET = "facet"; |
55 |
|
|
56 |
|
private static final String ELT_FIXED = "fixed"; |
57 |
|
|
58 |
|
private static final String ELT_FACETED_PROJECT = "faceted-project"; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
private static final String DIR_WTP_SETTINGS = ".settings"; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
private static final String FILE_FACET_CORE_XML = "org.eclipse.wst.common.project.facet.core.xml"; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
public void write() |
74 |
|
throws MojoExecutionException |
75 |
|
{ |
76 |
|
|
77 |
|
|
78 |
2 |
File settingsDir = new File( config.getEclipseProjectDirectory(), DIR_WTP_SETTINGS ); |
79 |
2 |
settingsDir.mkdirs(); |
80 |
|
|
81 |
|
FileWriter w; |
82 |
|
|
83 |
2 |
String packaging = config.getProject().getPackaging(); |
84 |
|
|
85 |
|
|
86 |
|
try |
87 |
|
{ |
88 |
2 |
w = new FileWriter( new File( settingsDir, FILE_FACET_CORE_XML ) ); |
89 |
|
} |
90 |
0 |
catch ( IOException ex ) |
91 |
|
{ |
92 |
0 |
throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); |
93 |
2 |
} |
94 |
2 |
XMLWriter writer = new PrettyPrintXMLWriter( w ); |
95 |
2 |
writeModuleTypeFacetCore( writer, packaging ); |
96 |
2 |
IOUtil.close( w ); |
97 |
2 |
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
private void writeModuleTypeFacetCore( XMLWriter writer, String packaging ) |
106 |
|
{ |
107 |
2 |
writer.startElement( ELT_FACETED_PROJECT ); |
108 |
|
|
109 |
2 |
writer.startElement( ELT_FIXED ); |
110 |
2 |
writer.addAttribute( ATTR_FACET, FACET_JST_JAVA ); |
111 |
2 |
writer.endElement(); |
112 |
2 |
if ( "war".equalsIgnoreCase( packaging ) ) |
113 |
|
{ |
114 |
1 |
writer.startElement( ELT_FIXED ); |
115 |
1 |
writer.addAttribute( ATTR_FACET, FACET_JST_WEB ); |
116 |
1 |
writer.endElement(); |
117 |
1 |
writer.startElement( ELT_INSTALLED ); |
118 |
1 |
writer.addAttribute( ATTR_FACET, FACET_JST_WEB ); |
119 |
1 |
writer.addAttribute( ATTR_VERSION, resolveServletVersion() ); |
120 |
1 |
writer.endElement(); |
121 |
1 |
} |
122 |
1 |
else if ( "ejb".equalsIgnoreCase( packaging ) ) |
123 |
|
{ |
124 |
0 |
writer.startElement( ELT_FIXED ); |
125 |
0 |
writer.addAttribute( ATTR_FACET, FACET_JST_EJB ); |
126 |
0 |
writer.endElement(); |
127 |
0 |
writer.startElement( ELT_INSTALLED ); |
128 |
0 |
writer.addAttribute( ATTR_FACET, FACET_JST_EJB ); |
129 |
0 |
writer.addAttribute( ATTR_VERSION, resolveEjbVersion() ); |
130 |
0 |
writer.endElement(); |
131 |
0 |
} |
132 |
1 |
else if ( "ear".equalsIgnoreCase( packaging ) ) |
133 |
|
{ |
134 |
1 |
writer.startElement( ELT_FIXED ); |
135 |
1 |
writer.addAttribute( ATTR_FACET, FACET_JST_EAR ); |
136 |
1 |
writer.endElement(); |
137 |
1 |
writer.startElement( ELT_INSTALLED ); |
138 |
1 |
writer.addAttribute( ATTR_FACET, FACET_JST_EAR ); |
139 |
1 |
writer.addAttribute( ATTR_VERSION, resolveJ2eeVersion() ); |
140 |
1 |
writer.endElement(); |
141 |
1 |
} |
142 |
0 |
else if ( "jar".equalsIgnoreCase( packaging ) ) |
143 |
|
{ |
144 |
0 |
writer.startElement( ELT_FIXED ); |
145 |
0 |
writer.addAttribute( ATTR_FACET, FACET_JST_UTILITY ); |
146 |
0 |
writer.endElement(); |
147 |
0 |
writer.startElement( ELT_INSTALLED ); |
148 |
0 |
writer.addAttribute( ATTR_FACET, FACET_JST_UTILITY ); |
149 |
0 |
writer.addAttribute( ATTR_VERSION, "1.0" ); |
150 |
0 |
writer.endElement(); |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
2 |
writer.startElement( ELT_INSTALLED ); |
155 |
2 |
writer.addAttribute( ATTR_FACET, FACET_JST_JAVA ); |
156 |
2 |
writer.addAttribute( ATTR_VERSION, resolveJavaVersion() ); |
157 |
2 |
writer.endElement(); |
158 |
2 |
writer.endElement(); |
159 |
2 |
} |
160 |
|
|
161 |
|
} |