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.util.Iterator; |
23 | |
|
24 | |
import org.apache.maven.model.Resource; |
25 | |
import org.apache.maven.plugin.MojoExecutionException; |
26 | |
import org.apache.maven.plugin.eclipse.Constants; |
27 | |
import org.apache.maven.plugin.eclipse.EclipseSourceDir; |
28 | |
import org.apache.maven.plugin.eclipse.writers.AbstractEclipseManifestWriter; |
29 | |
import org.apache.maven.plugin.ide.IdeUtils; |
30 | |
import org.apache.maven.plugin.ide.JeeUtils; |
31 | |
import org.apache.maven.project.MavenProject; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class RadManifestWriter |
42 | |
extends AbstractEclipseManifestWriter |
43 | |
{ |
44 | |
|
45 | 0 | private static final String DEFAULT_WEBAPP_RESOURCE_DIR = |
46 | |
"src" + File.separatorChar + "main" + File.separatorChar + "webapp"; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
protected String getMetaInfBaseDirectory( MavenProject project ) |
55 | |
throws MojoExecutionException |
56 | |
{ |
57 | 0 | String metaInfBaseDirectory = null; |
58 | |
|
59 | 0 | if ( config.getProject().getPackaging().equals( Constants.PROJECT_PACKAGING_WAR ) ) |
60 | |
{ |
61 | |
|
62 | 0 | File warSourceDirectory = |
63 | |
new File( IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN, |
64 | |
"warSourceDirectory", |
65 | |
DEFAULT_WEBAPP_RESOURCE_DIR ) ); |
66 | |
|
67 | 0 | String webContentDir = |
68 | |
IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), warSourceDirectory, false ); |
69 | |
|
70 | 0 | metaInfBaseDirectory = |
71 | |
config.getProject().getBasedir().getAbsolutePath() + File.separatorChar + webContentDir; |
72 | |
|
73 | 0 | log.debug( "Attempting to use: " + metaInfBaseDirectory + " for location of META-INF in war project." ); |
74 | |
|
75 | 0 | File metaInfDirectoryFile = new File( metaInfBaseDirectory + File.separatorChar + META_INF_DIRECTORY ); |
76 | |
|
77 | 0 | if ( metaInfDirectoryFile.exists() && !metaInfDirectoryFile.isDirectory() ) |
78 | |
{ |
79 | 0 | metaInfBaseDirectory = null; |
80 | |
} |
81 | |
} |
82 | |
|
83 | 0 | if ( metaInfBaseDirectory == null ) |
84 | |
{ |
85 | 0 | for ( Iterator iterator = project.getResources().iterator(); iterator.hasNext(); ) |
86 | |
{ |
87 | 0 | metaInfBaseDirectory = ( (Resource) iterator.next() ).getDirectory(); |
88 | |
|
89 | 0 | File metaInfDirectoryFile = new File( metaInfBaseDirectory + File.separatorChar + META_INF_DIRECTORY ); |
90 | |
|
91 | 0 | log.debug( "Checking for existence of META-INF directory: " + metaInfDirectoryFile ); |
92 | |
|
93 | 0 | if ( metaInfDirectoryFile.exists() && !metaInfDirectoryFile.isDirectory() ) |
94 | |
{ |
95 | 0 | metaInfBaseDirectory = null; |
96 | |
} |
97 | 0 | } |
98 | |
} |
99 | |
|
100 | 0 | return metaInfBaseDirectory; |
101 | |
} |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public void write() |
107 | |
throws MojoExecutionException |
108 | |
{ |
109 | 0 | super.write(); |
110 | 0 | verifyManifestBasedirInSourceDirs( getMetaInfBaseDirectory( config.getProject() ) ); |
111 | 0 | } |
112 | |
|
113 | |
|
114 | |
private void verifyManifestBasedirInSourceDirs( String metaInfBaseDirectory ) |
115 | |
{ |
116 | 0 | EclipseSourceDir[] sourceDirs = config.getSourceDirs(); |
117 | |
|
118 | 0 | if ( sourceDirs != null ) |
119 | |
{ |
120 | 0 | boolean foundMetaInfBaseDirectory = false; |
121 | |
|
122 | 0 | for ( int i = 0; i < sourceDirs.length; i++ ) |
123 | |
{ |
124 | 0 | EclipseSourceDir esd = sourceDirs[i]; |
125 | |
|
126 | 0 | if ( esd.getPath().equals( metaInfBaseDirectory ) ) |
127 | |
{ |
128 | 0 | foundMetaInfBaseDirectory = true; |
129 | 0 | break; |
130 | |
} |
131 | |
} |
132 | |
|
133 | 0 | if ( !foundMetaInfBaseDirectory ) |
134 | |
{ |
135 | 0 | EclipseSourceDir dir = |
136 | |
new EclipseSourceDir( metaInfBaseDirectory, null, true, false, null, null, false ); |
137 | |
|
138 | 0 | EclipseSourceDir[] newSourceDirs = new EclipseSourceDir[sourceDirs.length + 1]; |
139 | 0 | newSourceDirs[sourceDirs.length] = dir; |
140 | |
|
141 | 0 | System.arraycopy( sourceDirs, 0, newSourceDirs, 0, sourceDirs.length ); |
142 | |
|
143 | 0 | config.setSourceDirs( newSourceDirs ); |
144 | |
} |
145 | |
} |
146 | 0 | } |
147 | |
} |