e.g. Calendar Search Help
You must enter a value before pressing Search
ant

Class: org.apache.tools.ant.taskdefs.optional.extension.JarLibDisplayTask   ©

 OK to copy?
001 /*
002  * Copyright  2002-2004 The Apache Software Foundation
003  *
004  *  Licensed under the Apache License, Version 2.0 (the "License");
005  *  you may not use this file except in compliance with the License.
006  *  You may obtain a copy of the License at
007  *
008  *      http://www.apache.org/licenses/LICENSE-2.0
009  *
010  *  Unless required by applicable law or agreed to in writing, software
011  *  distributed under the License is distributed on an "AS IS" BASIS,
012  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013  *  See the License for the specific language governing permissions and
014  *  limitations under the License.
015  *
016  */
017 package org.apache.tools.ant.taskdefs.optional.extension;
018 
019 import java.io.File;
020 import java.util.Iterator;
021 import java.util.Vector;
022 import org.apache.tools.ant.BuildException;
023 import org.apache.tools.ant.DirectoryScanner;
024 import org.apache.tools.ant.Task;
025 import org.apache.tools.ant.types.FileSet;
026 
027 /**
028  * Displays the "Optional Package" and "Package Specification" information
029  * contained within the specified JARs.
030  *
031  * <p>Prior to JDK1.3, an "Optional Package" was known as an Extension.
032  * The specification for this mechanism is available in the JDK1.3
033  * documentation in the directory
034  * $JDK_HOME/docs/guide/extensions/versioning.html. Alternatively it is
035  * available online at <a href="http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html">
036  * http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html</a>.</p>
037  *
038  * @ant.task name="jarlib-display"
039  */
040 public class JarLibDisplayTask extends Task {
041     /**
042      * The library to display information about.
043      */
044     private File libraryFile;
045 
046     /**
047      * Filesets specifying all the librarys
048      * to display information about.
049      */
050     private final Vector libraryFileSets = new Vector();
051 
052     /**
053      * The JAR library to display information for.
054      *
055      * @param file The jar library to display information for.
056      */
057     public void setFile(final File file) {
058         this.libraryFile = file;
059     }
060 
061     /**
062      * Adds a set of files about which library data will be displayed.
063      *
064      * @param fileSet a set of files about which library data will be displayed.
065      */
066     public void addFileset(final FileSet fileSet) {
067         libraryFileSets.addElement(fileSet);
068     }
069 
070     /**
071      * Execute the task.
072      *
073      * @throws BuildException if the task fails.
074      */
075     public void execute() throws BuildException {
076         validate();
077 
078         final LibraryDisplayer displayer = new LibraryDisplayer();
079         // Check if list of files to check has been specified
Rate080         if (!libraryFileSets.isEmpty()) {
081             final Iterator iterator = libraryFileSets.iterator();
082             while (iterator.hasNext()) {
083                 final FileSet fileSet = (FileSet) iterator.next();
084                 final DirectoryScanner scanner
085                     = fileSet.getDirectoryScanner(getProject());
086                 final File basedir = scanner.getBasedir();
087                 final String[] files = scanner.getIncludedFiles();
088                 for (int i = 0; i < files.length; i++) {
089                     final File file = new File(basedir, files[ i ]);
090                     displayer.displayLibrary(file);
091                 }
092             }
093         } else {
094             displayer.displayLibrary(libraryFile);
095         }
096     }
097 
098     /**
099      * Validate the tasks parameters.
100      *
101      * @throws BuildException if invalid parameters found
102      */
103     private void validate() throws BuildException {
Rate104         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 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
80 0% of 0
104 0% of 0