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 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 w =
60 new OutputStreamWriter( new FileOutputStream( new File( config.getEclipseProjectDirectory(),
61 FILE_DOT_WTPMODULES ) ), "UTF-8" );
62 }
63 catch ( IOException ex )
64 {
65 throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex );
66 }
67
68 XMLWriter writer = new PrettyPrintXMLWriter( w, "UTF-8", null );
69 writer.startElement( ELT_PROJECT_MODULES );
70 writer.addAttribute( ATTR_MODULE_ID, "moduleCoreId" );
71
72 writer.startElement( ELT_WB_MODULE );
73
74 writer.addAttribute( ATTR_DEPLOY_NAME, this.config.getEclipseProjectName() );
75
76 writer.startElement( ELT_MODULE_TYPE );
77 writeModuleTypeAccordingToPackaging( config.getProject(), writer, config.getBuildOutputDirectory() );
78 writer.endElement();
79
80
81
82
83 String target = "/";
84 if ( Constants.PROJECT_PACKAGING_WAR.equals( config.getPackaging() ) )
85 {
86 String warSourceDirectory =
87 IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN,
88 "warSourceDirectory",
89 config.getProject().getBasedir() + "/src/main/webapp" );
90
91 writer.startElement( ELT_WB_RESOURCE );
92 writer.addAttribute( ATTR_DEPLOY_PATH, "/" );
93 writer.addAttribute( ATTR_SOURCE_PATH, "/"
94 + IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(),
95 new File( warSourceDirectory ), false ) );
96 writer.endElement();
97
98 writeWarOrEarResources( writer, config.getProject(), config.getLocalRepository() );
99
100 target = "/WEB-INF/classes";
101 }
102 else if ( Constants.PROJECT_PACKAGING_EAR.equals( config.getPackaging() ) )
103 {
104 writer.startElement( ELT_WB_RESOURCE );
105 writer.addAttribute( ATTR_DEPLOY_PATH, "/" );
106 writer.addAttribute( ATTR_SOURCE_PATH, "/" );
107 writer.endElement();
108
109 writeWarOrEarResources( writer, config.getProject(), config.getLocalRepository() );
110 }
111
112 for ( int j = 0; j < config.getSourceDirs().length; j++ )
113 {
114 EclipseSourceDir dir = config.getSourceDirs()[j];
115
116 if ( !dir.isTest() )
117 {
118
119 writer.startElement( ELT_WB_RESOURCE );
120 writer.addAttribute( ATTR_DEPLOY_PATH, target );
121 writer.addAttribute( ATTR_SOURCE_PATH, dir.getPath() );
122 writer.endElement();
123 }
124 }
125
126 writer.endElement();
127 writer.endElement();
128
129 IOUtil.close( w );
130 }
131
132 }