KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Map JavaDoc;
31
32 /**
33  * @author Michal Zlamal
34  */

35 public class CheckClustersContent extends Task {
36     private String JavaDoc clustersName = null;
37     private File JavaDoc trackingPath = null;
38     private File JavaDoc kitDir = null;
39     private List JavaDoc<Exclude> excludes = new ArrayList JavaDoc<Exclude>();
40
41     /** List of clusters to test */
42     public void setClusters( String JavaDoc clusters ) {
43         this.clustersName = clusters;
44     }
45     
46     public void setTrackingPath( File JavaDoc path ) {
47         this.trackingPath = path;
48     }
49     
50     public void setKitDestDir( File JavaDoc kitDir ) {
51         this.kitDir = kitDir;
52     }
53     
54     public Exclude createExclude() {
55         Exclude ex = new Exclude();
56         excludes.add(ex);
57         return ex;
58     }
59     
60     public void execute() throws BuildException {
61         if (clustersName == null) {
62             throw new BuildException("Cluster property must be set", getLocation());
63         }
64         if (trackingPath == null) {
65             throw new BuildException("Path to module_tracking.xml file must be set.", getLocation());
66         }
67         Map JavaDoc<String JavaDoc,String JavaDoc> listOfFiles = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
68         
69         StringTokenizer JavaDoc clusterTokens = new StringTokenizer JavaDoc(clustersName, " \t\n\f\r,");
70         boolean error = false;
71         String JavaDoc message = "";
72         while (clusterTokens.hasMoreTokens()) {
73             String JavaDoc clusterName = clusterTokens.nextToken();
74             String JavaDoc clusterList = this.getProject().getProperty(clusterName);
75             if (clusterList == null) {
76                 throw new BuildException("Cluster " + clusterName + " doesn't exist", getLocation());
77             }
78             ModuleTracking tracking = new ModuleTracking(trackingPath.getAbsolutePath());
79             StringTokenizer JavaDoc moduleTokens = new StringTokenizer JavaDoc(clusterList, " \t\n\f\r,");
80             while (moduleTokens.hasMoreTokens()) {
81                 String JavaDoc module = moduleTokens.nextToken();
82                 String JavaDoc path = tracking.getModulePath(module);
83                 Iterator JavaDoc files = tracking.getFilesForModule(module);
84                 if (files==null) {
85                     log("This module doesn't have module tracking info: " + module, Project.MSG_INFO);
86                     continue;
87                 }
88                 while (files.hasNext()) {
89                     // Slash "/" is intentional as all tracking files now contain "/" as file separators
90
String JavaDoc file = path.replace(File.separatorChar, '/') + '/' + ((String JavaDoc)files.next()).replace(File.separatorChar, '/'); //NOI18N
91
if (listOfFiles.containsKey(file)) {
92                         error = true;
93                         message += "\nThe file: " + file + " from module: " + module + " is also in module: " + listOfFiles.get(file);
94                     }
95                     listOfFiles.put(file,module);
96                 }
97             }
98         }
99         FileSet fileset = new FileSet();
100         fileset.setDir(kitDir);
101         if (excludes.size() > 0) {
102             Iterator JavaDoc it = excludes.iterator();
103             while (it.hasNext()) {
104                 Exclude ex = (Exclude) it.next();
105                 fileset.createExclude().setName(ex.getName());
106             }
107         }
108         DirectoryScanner ds = fileset.getDirectoryScanner(this.getProject());
109         ds.scan();
110         String JavaDoc included[] = ds.getIncludedFiles();
111         for (int i = 0; i < included.length; i++)
112             if (!listOfFiles.containsKey(included[i].replace(File.separatorChar, '/'))) {
113                 error = true;
114                 message += "\nThe file: " + included[i] + " isn't included in any module's NBM";
115             }
116         if (error)
117             throw new BuildException("Check of content of clusters and NBMs FAILED because of those issues:" + message, getLocation());
118     }
119     
120     public class Exclude {
121         String JavaDoc name = null;
122         public void setName(String JavaDoc name) {
123             this.name = name;
124         }
125         public String JavaDoc getName() {
126             return name;
127         }
128     }
129 }
130
Popular Tags