source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibDisplayTask.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: 4.1 KB
Line 
1/*
2 * Copyright 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.extension;
18
19import java.io.File;
20import java.util.Iterator;
21import java.util.Vector;
22import org.apache.tools.ant.BuildException;
23import org.apache.tools.ant.DirectoryScanner;
24import org.apache.tools.ant.Task;
25import org.apache.tools.ant.types.FileSet;
26
27/**
28 * Displays the "Optional Package" and "Package Specification" information
29 * contained within the specified JARs.
30 *
31 * <p>Prior to JDK1.3, an "Optional Package" was known as an Extension.
32 * The specification for this mechanism is available in the JDK1.3
33 * documentation in the directory
34 * $JDK_HOME/docs/guide/extensions/versioning.html. Alternatively it is
35 * available online at <a href="http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html">
36 * http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html</a>.</p>
37 *
38 * @ant.task name="jarlib-display"
39 */
40public class JarLibDisplayTask extends Task {
41 /**
42 * The library to display information about.
43 */
44 private File libraryFile;
45
46 /**
47 * Filesets specifying all the librarys
48 * to display information about.
49 */
50 private final Vector libraryFileSets = new Vector();
51
52 /**
53 * The JAR library to display information for.
54 *
55 * @param file The jar library to display information for.
56 */
57 public void setFile(final File file) {
58 this.libraryFile = file;
59 }
60
61 /**
62 * Adds a set of files about which library data will be displayed.
63 *
64 * @param fileSet a set of files about which library data will be displayed.
65 */
66 public void addFileset(final FileSet fileSet) {
67 libraryFileSets.addElement(fileSet);
68 }
69
70 /**
71 * Execute the task.
72 *
73 * @throws BuildException if the task fails.
74 */
75 public void execute() throws BuildException {
76 validate();
77
78 final LibraryDisplayer displayer = new LibraryDisplayer();
79 // Check if list of files to check has been specified
80 if (!libraryFileSets.isEmpty()) {
81 final Iterator iterator = libraryFileSets.iterator();
82 while (iterator.hasNext()) {
83 final FileSet fileSet = (FileSet) iterator.next();
84 final DirectoryScanner scanner
85 = fileSet.getDirectoryScanner(getProject());
86 final File basedir = scanner.getBasedir();
87 final String[] files = scanner.getIncludedFiles();
88 for (int i = 0; i < files.length; i++) {
89 final File file = new File(basedir, files[ i ]);
90 displayer.displayLibrary(file);
91 }
92 }
93 } else {
94 displayer.displayLibrary(libraryFile);
95 }
96 }
97
98 /**
99 * Validate the tasks parameters.
100 *
101 * @throws BuildException if invalid parameters found
102 */
103 private void validate() throws BuildException {
104 if (null == libraryFile && libraryFileSets.isEmpty()) {
105 final String message = "File attribute not specified.";
106 throw new BuildException(message);
107 }
108 if (null != libraryFile && !libraryFile.exists()) {
109 final String message = "File '" + libraryFile + "' does not exist.";
110 throw new BuildException(message);
111 }
112 if (null != libraryFile && !libraryFile.isFile()) {
113 final String message = "\'" + libraryFile + "\' is not a file.";
114 throw new BuildException(message);
115 }
116 }
117}
Note: See TracBrowser for help on using the repository browser.