blob: 428df2d1769580a1fb240f936e089f10c76dd3c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*
* Copyright 2002-2004 Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.tools.ant.taskdefs.optional.extension;
import java.io.File;
import java.util.Iterator;
import java.util.Vector;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
/**
* Displays the "Optional Package" and "Package Specification" information
* contained within the specified JARs.
*
* <p>Prior to JDK1.3, an "Optional Package" was known as an Extension.
* The specification for this mechanism is available in the JDK1.3
* documentation in the directory
* $JDK_HOME/docs/guide/extensions/versioning.html. Alternatively it is
* available online at <a href="http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html">
* http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html</a>.</p>
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @ant.task name="jarlib-display"
*/
public class JarLibDisplayTask extends Task {
/**
* The library to display information about.
*/
private File libraryFile;
/**
* Filesets specifying all the librarys
* to display information about.
*/
private final Vector libraryFileSets = new Vector();
/**
* The JAR library to display information for.
*
* @param file The jar library to display information for.
*/
public void setFile(final File file) {
this.libraryFile = file;
}
/**
* Adds a set of files about which library data will be displayed.
*
* @param fileSet a set of files about which library data will be displayed.
*/
public void addFileset(final FileSet fileSet) {
libraryFileSets.addElement(fileSet);
}
/**
* Execute the task.
*
* @throws BuildException if the task fails.
*/
public void execute() throws BuildException {
validate();
final LibraryDisplayer displayer = new LibraryDisplayer();
// Check if list of files to check has been specified
if (!libraryFileSets.isEmpty()) {
final Iterator iterator = libraryFileSets.iterator();
while (iterator.hasNext()) {
final FileSet fileSet = (FileSet) iterator.next();
final DirectoryScanner scanner
= fileSet.getDirectoryScanner(getProject());
final File basedir = scanner.getBasedir();
final String[] files = scanner.getIncludedFiles();
for (int i = 0; i < files.length; i++) {
final File file = new File(basedir, files[ i ]);
displayer.displayLibrary(file);
}
}
} else {
displayer.displayLibrary(libraryFile);
}
}
/**
* Validate the tasks parameters.
*
* @throws BuildException if invalid parameters found
*/
private void validate() throws BuildException {
if (null == libraryFile && libraryFileSets.isEmpty()) {
final String message = "File attribute not specified.";
throw new BuildException(message);
}
if (null != libraryFile && !libraryFile.exists()) {
final String message = "File '" + libraryFile + "' does not exist.";
throw new BuildException(message);
}
if (null != libraryFile && !libraryFile.isFile()) {
final String message = "\'" + libraryFile + "\' is not a file.";
throw new BuildException(message);
}
}
}
|