1 package org.codehaus.mojo.gwt;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Collection;
24 import java.util.List;
25 import java.util.Vector;
26
27 import org.apache.maven.archiver.MavenArchiveConfiguration;
28 import org.apache.maven.archiver.MavenArchiver;
29 import org.apache.maven.plugin.MojoExecutionException;
30 import org.apache.maven.plugin.MojoFailureException;
31 import org.apache.maven.plugins.annotations.Component;
32 import org.apache.maven.plugins.annotations.LifecyclePhase;
33 import org.apache.maven.plugins.annotations.Mojo;
34 import org.apache.maven.plugins.annotations.Parameter;
35 import org.codehaus.plexus.archiver.Archiver;
36 import org.codehaus.plexus.archiver.jar.JarArchiver;
37
38
39
40
41
42
43
44
45
46 @Deprecated
47 @Mojo(name = "source-jar", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true)
48 public class GwtSourcesJarMojo
49 extends GwtResourcesBaseMojo
50 {
51
52
53
54
55 @Parameter(alias = "jarName", property = "jar.finalName", defaultValue = "${project.build.finalName}", required = true)
56 private String finalName;
57
58 @Parameter(defaultValue = "${project.build.directory}", required = true, readonly = true)
59 private File outputDirectory;
60
61
62
63
64 @Component(role = Archiver.class, hint="jar")
65 private JarArchiver jarArchiver;
66
67
68
69
70
71 @Parameter
72 private final MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
73
74
75
76
77
78
79 public void execute()
80 throws MojoExecutionException, MojoFailureException
81 {
82 File jarFile = new File( outputDirectory, finalName + ".jar" );
83 File origJarFile = new File( outputDirectory, finalName + "-b4gwt.jar" );
84 if ( origJarFile.exists() )
85 {
86 if ( !origJarFile.delete() )
87 {
88 throw new MojoExecutionException( "Error removing " + origJarFile );
89 }
90 }
91 if ( !jarFile.renameTo( origJarFile ) )
92 {
93 throw new MojoExecutionException( "Error renaming " + jarFile + " to " + origJarFile );
94 }
95
96 MavenArchiver archiver = new MavenArchiver();
97
98 archiver.setArchiver( jarArchiver );
99 archiver.setOutputFile( jarFile );
100 archive.setForced( false );
101
102 archive.setAddMavenDescriptor( false );
103
104 Collection<ResourceFile> files = getAllResourceFiles();
105 try
106 {
107
108
109 List<String> jarExcludes = new Vector<String>();
110
111
112 for ( ResourceFile file : files )
113 {
114 jarArchiver.addFile( new File( file.basedir, file.fileRelativeName ), file.fileRelativeName );
115 jarExcludes.add( file.fileRelativeName );
116 }
117
118
119 jarArchiver.addArchivedFileSet( origJarFile, null, jarExcludes.toArray( new String[jarExcludes.size()] ) );
120
121 archiver.createArchive( getProject(), archive );
122 }
123 catch ( Exception e )
124 {
125 throw new MojoExecutionException( "Error assembling JAR", e );
126 }
127
128 }
129
130 }