| 1 | |
package org.apache.maven.plugin.acr; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
import org.apache.maven.archiver.MavenArchiveConfiguration; |
| 23 | |
import org.apache.maven.archiver.MavenArchiver; |
| 24 | |
import org.apache.maven.artifact.DependencyResolutionRequiredException; |
| 25 | |
import org.apache.maven.execution.MavenSession; |
| 26 | |
import org.apache.maven.plugin.AbstractMojo; |
| 27 | |
import org.apache.maven.plugin.MojoExecutionException; |
| 28 | |
import org.apache.maven.project.MavenProject; |
| 29 | |
import org.apache.maven.shared.filtering.MavenFileFilter; |
| 30 | |
import org.apache.maven.shared.filtering.MavenFilteringException; |
| 31 | |
import org.apache.maven.shared.filtering.MavenResourcesExecution; |
| 32 | |
import org.codehaus.plexus.archiver.ArchiverException; |
| 33 | |
import org.codehaus.plexus.archiver.jar.JarArchiver; |
| 34 | |
import org.codehaus.plexus.archiver.jar.ManifestException; |
| 35 | |
import org.codehaus.plexus.util.FileUtils; |
| 36 | |
import org.codehaus.plexus.util.xml.XmlStreamReader; |
| 37 | |
|
| 38 | |
import java.io.File; |
| 39 | |
import java.io.IOException; |
| 40 | |
import java.util.List; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | 0 | public class AcrMojo |
| 54 | |
extends AbstractMojo |
| 55 | |
{ |
| 56 | |
|
| 57 | |
private static final String APP_CLIENT_XML = "META-INF/application-client.xml"; |
| 58 | |
|
| 59 | |
|
| 60 | 0 | private static final String[] DEFAULT_INCLUDES = new String[]{ "**/**" }; |
| 61 | |
|
| 62 | 0 | private static final String[] DEFAULT_EXCLUDES = new String[]{ APP_CLIENT_XML }; |
| 63 | |
|
| 64 | 0 | private static final String[] EMPTY_STRING_ARRAY = new String[0]; |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
private File basedir; |
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
private File outputDirectory; |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
private String jarName; |
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
private List excludes; |
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
private MavenProject project; |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
private JarArchiver jarArchiver; |
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | 0 | private MavenArchiveConfiguration archive = new MavenArchiveConfiguration(); |
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
private boolean escapeBackslashesInFilePath; |
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
protected String escapeString; |
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
private boolean filterDeploymentDescriptor; |
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
private List filters; |
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
private MavenFileFilter mavenFileFilter; |
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
private MavenSession session; |
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
public void execute() |
| 175 | |
throws MojoExecutionException |
| 176 | |
{ |
| 177 | |
|
| 178 | |
|
| 179 | 0 | if ( getLog().isInfoEnabled() ) |
| 180 | |
{ |
| 181 | 0 | getLog().info( "Building JavaEE Application client: " + jarName ); |
| 182 | |
} |
| 183 | |
|
| 184 | 0 | File jarFile = getAppClientJarFile( basedir, jarName ); |
| 185 | |
|
| 186 | 0 | MavenArchiver archiver = new MavenArchiver(); |
| 187 | |
|
| 188 | 0 | archiver.setArchiver( jarArchiver ); |
| 189 | |
|
| 190 | 0 | archiver.setOutputFile( jarFile ); |
| 191 | |
|
| 192 | 0 | File deploymentDescriptor = new File( outputDirectory, APP_CLIENT_XML ); |
| 193 | |
try |
| 194 | |
{ |
| 195 | 0 | String[] mainJarExcludes = DEFAULT_EXCLUDES; |
| 196 | |
|
| 197 | 0 | if ( excludes != null && !excludes.isEmpty() ) |
| 198 | |
{ |
| 199 | 0 | excludes.add( APP_CLIENT_XML ); |
| 200 | 0 | mainJarExcludes = (String[]) excludes.toArray( EMPTY_STRING_ARRAY ); |
| 201 | |
} |
| 202 | |
|
| 203 | 0 | if ( !outputDirectory.exists() ) |
| 204 | |
{ |
| 205 | 0 | getLog().info( |
| 206 | |
"JAR will only contain the META-INF/application-client.xml as no content was marked for inclusion" ); |
| 207 | |
} |
| 208 | |
else |
| 209 | |
{ |
| 210 | 0 | archiver.getArchiver().addDirectory( outputDirectory, DEFAULT_INCLUDES, mainJarExcludes ); |
| 211 | |
} |
| 212 | |
|
| 213 | 0 | if ( deploymentDescriptor.exists() ) |
| 214 | |
{ |
| 215 | 0 | if ( filterDeploymentDescriptor ) |
| 216 | |
{ |
| 217 | 0 | getLog().debug( "Filtering deployment descriptor." ); |
| 218 | 0 | MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(); |
| 219 | 0 | mavenResourcesExecution.setEscapeString( escapeString ); |
| 220 | 0 | List filterWrappers = |
| 221 | |
mavenFileFilter.getDefaultFilterWrappers( project, filters, escapeBackslashesInFilePath, |
| 222 | |
this.session, mavenResourcesExecution ); |
| 223 | |
|
| 224 | |
|
| 225 | 0 | File unfilteredDeploymentDescriptor = new File( outputDirectory, APP_CLIENT_XML + ".unfiltered" ); |
| 226 | 0 | FileUtils.copyFile( deploymentDescriptor, unfilteredDeploymentDescriptor ); |
| 227 | 0 | mavenFileFilter.copyFile( unfilteredDeploymentDescriptor, deploymentDescriptor, true, |
| 228 | |
filterWrappers, getEncoding( unfilteredDeploymentDescriptor ) ); |
| 229 | |
|
| 230 | 0 | FileUtils.forceDelete( unfilteredDeploymentDescriptor ); |
| 231 | |
} |
| 232 | 0 | archiver.getArchiver().addFile( deploymentDescriptor, APP_CLIENT_XML ); |
| 233 | |
} |
| 234 | |
|
| 235 | |
|
| 236 | 0 | archiver.createArchive( project, archive ); |
| 237 | |
} |
| 238 | 0 | catch ( ArchiverException e ) |
| 239 | |
{ |
| 240 | 0 | throw new MojoExecutionException( |
| 241 | |
"There was a problem creating the JavaEE Application Client archive: " + e.getMessage(), e ); |
| 242 | |
} |
| 243 | 0 | catch ( ManifestException e ) |
| 244 | |
{ |
| 245 | 0 | throw new MojoExecutionException( |
| 246 | |
"There was a problem reading / creating the manifest for the JavaEE Application Client archive: " + |
| 247 | |
e.getMessage(), e ); |
| 248 | |
} |
| 249 | 0 | catch ( IOException e ) |
| 250 | |
{ |
| 251 | 0 | throw new MojoExecutionException( |
| 252 | |
"There was a I/O problem creating the JavaEE Application Client archive: " + e.getMessage(), e ); |
| 253 | |
} |
| 254 | 0 | catch ( DependencyResolutionRequiredException e ) |
| 255 | |
{ |
| 256 | 0 | throw new MojoExecutionException( |
| 257 | |
"There was a problem resolving dependencies while creating the JavaEE Application Client archive: " + |
| 258 | |
e.getMessage(), e ); |
| 259 | |
} |
| 260 | 0 | catch ( MavenFilteringException e ) |
| 261 | |
{ |
| 262 | 0 | throw new MojoExecutionException( |
| 263 | |
"There was a problem filtering the deployment descriptor: " + e.getMessage(), e ); |
| 264 | 0 | } |
| 265 | |
|
| 266 | 0 | project.getArtifact().setFile( jarFile ); |
| 267 | |
|
| 268 | |
|
| 269 | 0 | } |
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
private static File getAppClientJarFile( File basedir, String finalName ) |
| 279 | |
{ |
| 280 | 0 | return new File( basedir, finalName + ".jar" ); |
| 281 | |
} |
| 282 | |
|
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
private String getEncoding( File xmlFile ) |
| 291 | |
throws IOException |
| 292 | |
{ |
| 293 | 0 | XmlStreamReader xmlReader = new XmlStreamReader( xmlFile ); |
| 294 | 0 | return xmlReader.getEncoding(); |
| 295 | |
} |
| 296 | |
} |