1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.war.util;
20
21 import java.io.File;
22 import java.io.IOException;
23
24 import org.apache.maven.archiver.MavenArchiveConfiguration;
25 import org.apache.maven.archiver.MavenArchiver;
26 import org.apache.maven.artifact.DependencyResolutionRequiredException;
27 import org.apache.maven.execution.MavenSession;
28 import org.apache.maven.plugin.MojoExecutionException;
29 import org.apache.maven.plugins.war.packaging.AbstractWarPackagingTask;
30 import org.apache.maven.project.MavenProject;
31 import org.codehaus.plexus.archiver.ArchiverException;
32 import org.codehaus.plexus.archiver.jar.JarArchiver;
33 import org.codehaus.plexus.archiver.jar.ManifestException;
34
35
36
37
38
39
40 public class ClassesPackager {
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public void packageClasses(
55 File classesDirectory,
56 File targetFile,
57 JarArchiver jarArchiver,
58 MavenSession session,
59 MavenProject project,
60 MavenArchiveConfiguration archiveConfiguration,
61 String outputTimestamp)
62 throws MojoExecutionException {
63
64 try {
65 final MavenArchiver archiver = new MavenArchiver();
66 archiver.setArchiver(jarArchiver);
67 archiver.setOutputFile(targetFile);
68 archiver.setCreatedBy("Maven WAR Plugin", "org.apache.maven.plugins", "maven-war-plugin");
69 archiver.configureReproducibleBuild(outputTimestamp);
70 archiver.getArchiver().addDirectory(classesDirectory);
71 archiver.createArchive(session, project, archiveConfiguration);
72 } catch (ArchiverException | ManifestException | IOException | DependencyResolutionRequiredException e) {
73 throw new MojoExecutionException("Could not create classes archive", e);
74 }
75 }
76
77
78
79
80
81
82
83 public File getClassesDirectory(File webappDirectory) {
84 return new File(webappDirectory, AbstractWarPackagingTask.CLASSES_PATH);
85 }
86 }