1 | /*
|
---|
2 | * Copyright 2001-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.taskdefs;
|
---|
18 |
|
---|
19 | import java.io.File;
|
---|
20 | import java.io.IOException;
|
---|
21 | import org.apache.tools.ant.BuildException;
|
---|
22 | import org.apache.tools.ant.Project;
|
---|
23 | import org.apache.tools.ant.types.ZipFileSet;
|
---|
24 | import org.apache.tools.ant.util.FileUtils;
|
---|
25 | import org.apache.tools.zip.ZipOutputStream;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Creates a EAR archive. Based on WAR task
|
---|
29 | *
|
---|
30 | *
|
---|
31 | * @since Ant 1.4
|
---|
32 | *
|
---|
33 | * @ant.task category="packaging"
|
---|
34 | */
|
---|
35 | public class Ear extends Jar {
|
---|
36 |
|
---|
37 | private File deploymentDescriptor;
|
---|
38 | private boolean descriptorAdded;
|
---|
39 | private static final FileUtils fu = FileUtils.newFileUtils();
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Create an Ear task.
|
---|
43 | */
|
---|
44 | public Ear() {
|
---|
45 | super();
|
---|
46 | archiveType = "ear";
|
---|
47 | emptyBehavior = "create";
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * @deprecated Use setDestFile(destfile) instead
|
---|
52 | */
|
---|
53 | public void setEarfile(File earFile) {
|
---|
54 | setDestFile(earFile);
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * File to incorporate as application.xml.
|
---|
59 | */
|
---|
60 | public void setAppxml(File descr) {
|
---|
61 | deploymentDescriptor = descr;
|
---|
62 | if (!deploymentDescriptor.exists()) {
|
---|
63 | throw new BuildException("Deployment descriptor: "
|
---|
64 | + deploymentDescriptor
|
---|
65 | + " does not exist.");
|
---|
66 | }
|
---|
67 |
|
---|
68 | // Create a ZipFileSet for this file, and pass it up.
|
---|
69 | ZipFileSet fs = new ZipFileSet();
|
---|
70 | fs.setFile(deploymentDescriptor);
|
---|
71 | fs.setFullpath("META-INF/application.xml");
|
---|
72 | super.addFileset(fs);
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Adds zipfileset.
|
---|
78 | *
|
---|
79 | * @param fs zipfileset to add
|
---|
80 | */
|
---|
81 | public void addArchives(ZipFileSet fs) {
|
---|
82 | // We just set the prefix for this fileset, and pass it up.
|
---|
83 | // Do we need to do this? LH
|
---|
84 | fs.setPrefix("/");
|
---|
85 | super.addFileset(fs);
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | protected void initZipOutputStream(ZipOutputStream zOut)
|
---|
90 | throws IOException, BuildException {
|
---|
91 | // If no webxml file is specified, it's an error.
|
---|
92 | if (deploymentDescriptor == null && !isInUpdateMode()) {
|
---|
93 | throw new BuildException("appxml attribute is required", getLocation());
|
---|
94 | }
|
---|
95 |
|
---|
96 | super.initZipOutputStream(zOut);
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Overridden from Zip class to deal with application.xml
|
---|
101 | */
|
---|
102 | protected void zipFile(File file, ZipOutputStream zOut, String vPath,
|
---|
103 | int mode)
|
---|
104 | throws IOException {
|
---|
105 | // If the file being added is META-INF/application.xml, we
|
---|
106 | // warn if it's not the one specified in the "appxml"
|
---|
107 | // attribute - or if it's being added twice, meaning the same
|
---|
108 | // file is specified by the "appxml" attribute and in a
|
---|
109 | // <fileset> element.
|
---|
110 | if (vPath.equalsIgnoreCase("META-INF/application.xml")) {
|
---|
111 | if (deploymentDescriptor == null
|
---|
112 | || !fu.fileNameEquals(deploymentDescriptor, file)
|
---|
113 | || descriptorAdded) {
|
---|
114 | log("Warning: selected " + archiveType
|
---|
115 | + " files include a META-INF/application.xml which will"
|
---|
116 | + " be ignored (please use appxml attribute to "
|
---|
117 | + archiveType + " task)", Project.MSG_WARN);
|
---|
118 | } else {
|
---|
119 | super.zipFile(file, zOut, vPath, mode);
|
---|
120 | descriptorAdded = true;
|
---|
121 | }
|
---|
122 | } else {
|
---|
123 | super.zipFile(file, zOut, vPath, mode);
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Make sure we don't think we already have a application.xml next
|
---|
129 | * time this task gets executed.
|
---|
130 | */
|
---|
131 | protected void cleanUp() {
|
---|
132 | descriptorAdded = false;
|
---|
133 | super.cleanUp();
|
---|
134 | }
|
---|
135 | }
|
---|