source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/jlink/JlinkTask.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 5.1 KB
Line 
1/*
2 * Copyright 2000,2002,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 */
17package org.apache.tools.ant.taskdefs.optional.jlink;
18
19import java.io.File;
20import org.apache.tools.ant.BuildException;
21import org.apache.tools.ant.Project;
22import org.apache.tools.ant.taskdefs.MatchingTask;
23import org.apache.tools.ant.types.Path;
24
25/**
26 * This class defines objects that can link together various jar and
27 * zip files.
28 *
29 * <p>It is basically a wrapper for the jlink code written originally
30 * by <a href="mailto:[email protected]">Patrick Beard</a>. The
31 * classes org.apache.tools.ant.taskdefs.optional.jlink.Jlink and
32 * org.apache.tools.ant.taskdefs.optional.jlink.ClassNameReader
33 * support this class.</p>
34 *
35 * <p>For example:
36 * <code>
37 * <pre>
38 * &lt;jlink compress=&quot;false&quot; outfile=&quot;out.jar&quot;/&gt;
39 * &lt;mergefiles&gt;
40 * &lt;pathelement path=&quot;${build.dir}/mergefoo.jar&quot;/&gt;
41 * &lt;pathelement path=&quot;${build.dir}/mergebar.jar&quot;/&gt;
42 * &lt;/mergefiles&gt;
43 * &lt;addfiles&gt;
44 * &lt;pathelement path=&quot;${build.dir}/mac.jar&quot;/&gt;
45 * &lt;pathelement path=&quot;${build.dir}/pc.zip&quot;/&gt;
46 * &lt;/addfiles&gt;
47 * &lt;/jlink&gt;
48 * </pre>
49 * </code>
50 *
51 * @ant.task ignore="true"
52 */
53public class JlinkTask extends MatchingTask {
54
55 /**
56 * The output file for this run of jlink. Usually a jar or zip file.
57 */
58 public void setOutfile(File outfile) {
59 this.outfile = outfile;
60 }
61
62 /**
63 * Establishes the object that contains the files to
64 * be merged into the output.
65 */
66 public Path createMergefiles() {
67 if (this.mergefiles == null) {
68 this.mergefiles = new Path(getProject());
69 }
70 return this.mergefiles.createPath();
71 }
72
73 /**
74 * Sets the files to be merged into the output.
75 */
76 public void setMergefiles(Path mergefiles) {
77 if (this.mergefiles == null) {
78 this.mergefiles = mergefiles;
79 } else {
80 this.mergefiles.append(mergefiles);
81 }
82 }
83
84 /**
85 * Establishes the object that contains the files to
86 * be added to the output.
87 */
88 public Path createAddfiles() {
89 if (this.addfiles == null) {
90 this.addfiles = new Path(getProject());
91 }
92 return this.addfiles.createPath();
93 }
94
95 /**
96 * Sets the files to be added into the output.
97 */
98 public void setAddfiles(Path addfiles) {
99 if (this.addfiles == null) {
100 this.addfiles = addfiles;
101 } else {
102 this.addfiles.append(addfiles);
103 }
104 }
105
106 /**
107 * Defines whether or not the output should be compacted.
108 */
109 public void setCompress(boolean compress) {
110 this.compress = compress;
111 }
112
113 /**
114 * Does the adding and merging.
115 */
116 public void execute() throws BuildException {
117 //Be sure everything has been set.
118 if (outfile == null) {
119 throw new BuildException("outfile attribute is required! "
120 + "Please set.");
121 }
122 if (!haveAddFiles() && !haveMergeFiles()) {
123 throw new BuildException("addfiles or mergefiles required! "
124 + "Please set.");
125 }
126 log("linking: " + outfile.getPath());
127 log("compression: " + compress, Project.MSG_VERBOSE);
128 jlink linker = new jlink();
129 linker.setOutfile(outfile.getPath());
130 linker.setCompression(compress);
131 if (haveMergeFiles()) {
132 log("merge files: " + mergefiles.toString(), Project.MSG_VERBOSE);
133 linker.addMergeFiles(mergefiles.list());
134 }
135 if (haveAddFiles()) {
136 log("add files: " + addfiles.toString(), Project.MSG_VERBOSE);
137 linker.addAddFiles(addfiles.list());
138 }
139 try {
140 linker.link();
141 } catch (Exception ex) {
142 throw new BuildException(ex, getLocation());
143 }
144 }
145
146 private boolean haveAddFiles() {
147 return haveEntries(addfiles);
148 }
149
150 private boolean haveMergeFiles() {
151 return haveEntries(mergefiles);
152 }
153
154 private boolean haveEntries(Path p) {
155 if (p == null) {
156 return false;
157 }
158 if (p.size() > 0) {
159 return true;
160 }
161 return false;
162 }
163
164 private File outfile = null;
165
166 private Path mergefiles = null;
167
168 private Path addfiles = null;
169
170 private boolean compress = false;
171
172}
173
174
Note: See TracBrowser for help on using the repository browser.