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