1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.codehaus.plexus.archiver.ear;
18
19 import javax.inject.Named;
20
21 import java.io.File;
22 import java.io.IOException;
23
24 import org.codehaus.plexus.archiver.ArchiveEntry;
25 import org.codehaus.plexus.archiver.ArchiverException;
26 import org.codehaus.plexus.archiver.jar.JarArchiver;
27 import org.codehaus.plexus.archiver.util.ResourceUtils;
28 import org.codehaus.plexus.archiver.zip.ConcurrentJarCreator;
29
30
31
32
33 @Named("ear")
34 public class EarArchiver extends JarArchiver {
35
36 private File deploymentDescriptor;
37
38 private boolean descriptorAdded;
39
40
41
42
43 public EarArchiver() {
44 super();
45 archiveType = "ear";
46 }
47
48
49
50
51 public void setAppxml(File descr) throws ArchiverException {
52 deploymentDescriptor = descr;
53 if (!deploymentDescriptor.exists()) {
54 throw new ArchiverException("Deployment descriptor: " + deploymentDescriptor + " does not exist.");
55 }
56
57 addFile(descr, "META-INF/application.xml");
58 }
59
60
61
62
63 public void addArchive(File fileName) throws ArchiverException {
64 addDirectory(fileName.getParentFile(), "/", new String[] {fileName.getName()}, null);
65 }
66
67
68
69
70 public void addArchives(File directoryName, String[] includes, String[] excludes) throws ArchiverException {
71 addDirectory(directoryName, "/", includes, excludes);
72 }
73
74 @Override
75 protected void initZipOutputStream(ConcurrentJarCreator zOut) throws ArchiverException, IOException {
76
77 if (deploymentDescriptor == null && !isInUpdateMode()) {
78 throw new ArchiverException("appxml attribute is required");
79 }
80
81 super.initZipOutputStream(zOut);
82 }
83
84
85
86
87 protected void zipFile(ArchiveEntry entry, ConcurrentJarCreator zOut, String vPath, int mode)
88 throws IOException, ArchiverException {
89
90
91
92
93
94 if (vPath.equalsIgnoreCase("META-INF/application.xml")) {
95 if (deploymentDescriptor == null
96 || !ResourceUtils.isCanonicalizedSame(entry.getResource(), deploymentDescriptor)
97 || descriptorAdded) {
98 getLogger()
99 .warn("Warning: selected " + archiveType
100 + " files include a META-INF/application.xml which will be ignored "
101 + "(please use appxml attribute to " + archiveType + " task)");
102 } else {
103 super.zipFile(entry, zOut, vPath);
104 descriptorAdded = true;
105 }
106 } else {
107 super.zipFile(entry, zOut, vPath);
108 }
109 }
110
111
112
113
114
115 @Override
116 protected void cleanUp() throws IOException {
117 descriptorAdded = false;
118 super.cleanUp();
119 }
120 }