1 | |
package org.apache.maven.plugin.war.util; |
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.MojoExecutionException; |
27 | |
import org.apache.maven.plugin.war.packaging.AbstractWarPackagingTask; |
28 | |
import org.apache.maven.project.MavenProject; |
29 | |
import org.codehaus.plexus.archiver.ArchiverException; |
30 | |
import org.codehaus.plexus.archiver.jar.JarArchiver; |
31 | |
import org.codehaus.plexus.archiver.jar.ManifestException; |
32 | |
|
33 | |
import java.io.File; |
34 | |
import java.io.IOException; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public class ClassesPackager |
43 | |
{ |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
public ClassesPackager() |
49 | |
{ |
50 | 2 | super(); |
51 | 2 | } |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
public void packageClasses( File classesDirectory, File targetFile, JarArchiver jarArchiver, MavenSession session, |
65 | |
MavenProject project, MavenArchiveConfiguration archiveConfiguration ) |
66 | |
throws MojoExecutionException |
67 | |
{ |
68 | |
|
69 | |
try |
70 | |
{ |
71 | 2 | final MavenArchiver archiver = new MavenArchiver(); |
72 | 2 | archiver.setArchiver( jarArchiver ); |
73 | 2 | archiver.setOutputFile( targetFile ); |
74 | 2 | archiver.getArchiver().addDirectory( classesDirectory ); |
75 | 2 | archiver.createArchive( session, project, archiveConfiguration ); |
76 | |
} |
77 | 0 | catch ( ArchiverException e ) |
78 | |
{ |
79 | 0 | throw new MojoExecutionException( "Could not create classes archive", e ); |
80 | |
} |
81 | 0 | catch ( ManifestException e ) |
82 | |
{ |
83 | 0 | throw new MojoExecutionException( "Could not create classes archive", e ); |
84 | |
} |
85 | 0 | catch ( IOException e ) |
86 | |
{ |
87 | 0 | throw new MojoExecutionException( "Could not create classes archive", e ); |
88 | |
} |
89 | 0 | catch ( DependencyResolutionRequiredException e ) |
90 | |
{ |
91 | 0 | throw new MojoExecutionException( "Could not create classes archive", e ); |
92 | 2 | } |
93 | 2 | } |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public File getClassesDirectory( File webappDirectory ) |
102 | |
{ |
103 | 2 | return new File( webappDirectory, AbstractWarPackagingTask.CLASSES_PATH ); |
104 | |
} |
105 | |
} |