KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > nbbuild > ModuleInfo


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.nbbuild;
21
22 import org.apache.tools.ant.*;
23 import org.apache.tools.ant.types.*;
24 import java.util.StringTokenizer JavaDoc;
25 import java.io.File JavaDoc;
26 import java.util.Iterator JavaDoc;
27
28 /** Task that reads ModuleTracking informations and composes them into
29  * @author Jaroslav Tulach
30  */

31 public class ModuleInfo extends Task {
32     private String JavaDoc property;
33     private String JavaDoc fileset;
34     private String JavaDoc moduleName;
35     private String JavaDoc clusterdir;
36     private File JavaDoc trackingPath;
37     private boolean failOnError;
38
39     public void setModule (String JavaDoc moduleName){
40         this.moduleName = moduleName;
41     }
42     
43     public void setPatternSetName( String JavaDoc name ) {
44         property = name;
45     }
46     
47     public void setFileSetName (String JavaDoc name) {
48         fileset = name;
49     }
50
51     public void setClusterDirName (String JavaDoc name) {
52         clusterdir = name;
53     }
54     
55     public void setTrackingPath( File JavaDoc path ) {
56         trackingPath = path;
57     }
58     
59     public void setFailOnError (boolean b) {
60         failOnError = b;
61     }
62     
63     
64     public void execute() throws BuildException {
65         if (moduleName == null) {
66             throw new BuildException("Module property must be set", getLocation());
67         }
68         if (property == null && fileset == null) {
69             throw new BuildException("Name of the patternset or fileset must be set.", getLocation());
70         }
71         if (trackingPath == null) {
72             throw new BuildException("Path to module_tracking.xml file must be set.", getLocation());
73         }
74         
75         String JavaDoc c = this.getProject ().getProperty (moduleName + ".dir");
76         if (c == null) {
77             throw new BuildException ("No property " + moduleName + ".dir is defined");
78         }
79         File JavaDoc cluster = new File JavaDoc (c);
80         log ("Cluster dir for " + moduleName + " is " + cluster, Project.MSG_VERBOSE);
81         
82         if (this.clusterdir != null) {
83             this.getProject ().setProperty (this.clusterdir, cluster.getPath ());
84         }
85         
86         PatternSet pattern = (PatternSet) this.getProject().createDataType("patternset");
87         
88         ModuleTracking tracking = new ModuleTracking(trackingPath.getAbsolutePath());
89         Iterator JavaDoc files = tracking.getFilesForModule(moduleName);
90         if (files==null) {
91             String JavaDoc msg = moduleName + " module doesn't have module tracking info in " + trackingPath;
92             if (failOnError) {
93                 throw new BuildException (msg);
94             } else {
95                 log (msg, Project.MSG_ERR);
96                 files = java.util.Collections.EMPTY_LIST.iterator ();
97             }
98         }
99         
100         while (files.hasNext()) {
101             String JavaDoc f = (String JavaDoc)files.next ();
102             log ("Adding include " + f, Project.MSG_VERBOSE);
103             pattern.createInclude().setName(f);
104         }
105         
106         if (property != null) {
107             log ("Setting refid " + property);
108             this.getProject().addReference(property, pattern);
109         }
110         
111         if (fileset != null) {
112             FileSet fs = (FileSet) this.getProject().createDataType("fileset");
113             fs.setDir (cluster);
114             fs.createPatternSet ().append (pattern, getProject ());
115             log ("Setting refid " + fileset);
116             this.getProject().addReference(fileset, fs);
117         }
118     }
119 }
120
Popular Tags