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 | |
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.EclipseSourceDir; |
30 | |
import org.apache.maven.plugin.eclipse.Messages; |
31 | |
import org.apache.maven.plugin.ide.IdeUtils; |
32 | |
import org.apache.maven.plugin.ide.JeeUtils; |
33 | |
import org.codehaus.plexus.util.IOUtil; |
34 | |
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; |
35 | |
import org.codehaus.plexus.util.xml.XMLWriter; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public class EclipseWtpmodulesWriter |
44 | |
extends AbstractWtpResourceWriter |
45 | |
{ |
46 | |
|
47 | |
protected static final String FILE_DOT_WTPMODULES = ".wtpmodules"; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public void write() |
53 | |
throws MojoExecutionException |
54 | |
{ |
55 | |
Writer w; |
56 | |
|
57 | |
try |
58 | |
{ |
59 | 0 | w = |
60 | |
new OutputStreamWriter( new FileOutputStream( new File( config.getEclipseProjectDirectory(), |
61 | |
FILE_DOT_WTPMODULES ) ), "UTF-8" ); |
62 | |
} |
63 | 0 | catch ( IOException ex ) |
64 | |
{ |
65 | 0 | throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); |
66 | 0 | } |
67 | |
|
68 | 0 | XMLWriter writer = new PrettyPrintXMLWriter( w ); |
69 | 0 | writer.startElement( ELT_PROJECT_MODULES ); |
70 | 0 | writer.addAttribute( ATTR_MODULE_ID, "moduleCoreId" ); |
71 | |
|
72 | 0 | writer.startElement( ELT_WB_MODULE ); |
73 | |
|
74 | 0 | writer.addAttribute( ATTR_DEPLOY_NAME, this.config.getEclipseProjectName() ); |
75 | |
|
76 | 0 | writer.startElement( ELT_MODULE_TYPE ); |
77 | 0 | writeModuleTypeAccordingToPackaging( config.getProject(), writer, config.getBuildOutputDirectory() ); |
78 | 0 | writer.endElement(); |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | 0 | String target = "/"; |
84 | 0 | if ( Constants.PROJECT_PACKAGING_WAR.equals( config.getPackaging() ) ) |
85 | |
{ |
86 | 0 | String warSourceDirectory = |
87 | |
IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN, |
88 | |
"warSourceDirectory", |
89 | |
config.getProject().getBasedir() + "/src/main/webapp" ); |
90 | |
|
91 | 0 | writer.startElement( ELT_WB_RESOURCE ); |
92 | 0 | writer.addAttribute( ATTR_DEPLOY_PATH, "/" ); |
93 | 0 | writer.addAttribute( ATTR_SOURCE_PATH, "/" |
94 | |
+ IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), |
95 | |
new File( warSourceDirectory ), false ) ); |
96 | 0 | writer.endElement(); |
97 | |
|
98 | 0 | writeWarOrEarResources( writer, config.getProject(), config.getLocalRepository() ); |
99 | |
|
100 | 0 | target = "/WEB-INF/classes"; |
101 | |
} |
102 | 0 | else if ( Constants.PROJECT_PACKAGING_EAR.equals( config.getPackaging() ) ) |
103 | |
{ |
104 | 0 | writer.startElement( ELT_WB_RESOURCE ); |
105 | 0 | writer.addAttribute( ATTR_DEPLOY_PATH, "/" ); |
106 | 0 | writer.addAttribute( ATTR_SOURCE_PATH, "/" ); |
107 | 0 | writer.endElement(); |
108 | |
|
109 | 0 | writeWarOrEarResources( writer, config.getProject(), config.getLocalRepository() ); |
110 | |
} |
111 | |
|
112 | 0 | for ( int j = 0; j < config.getSourceDirs().length; j++ ) |
113 | |
{ |
114 | 0 | EclipseSourceDir dir = config.getSourceDirs()[j]; |
115 | |
|
116 | 0 | if ( !dir.isTest() ) |
117 | |
{ |
118 | |
|
119 | 0 | writer.startElement( ELT_WB_RESOURCE ); |
120 | 0 | writer.addAttribute( ATTR_DEPLOY_PATH, target ); |
121 | 0 | writer.addAttribute( ATTR_SOURCE_PATH, dir.getPath() ); |
122 | 0 | writer.endElement(); |
123 | |
} |
124 | |
} |
125 | |
|
126 | 0 | writer.endElement(); |
127 | 0 | writer.endElement(); |
128 | |
|
129 | 0 | IOUtil.close( w ); |
130 | 0 | } |
131 | |
|
132 | |
} |