KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
29  * @author Michal Zlamal
30  */

31 public class SetClusterPatternSet extends Task {
32     PatternSet pattern = null;
33
34     private String JavaDoc property = null;
35     private String JavaDoc clusterName = null;
36     private File JavaDoc trackingPath = null;
37     private String JavaDoc clusterDir = null;
38
39     public void setCluster( String JavaDoc cluster ){
40         clusterName = cluster;
41     }
42
43     public void setName( String JavaDoc name ) {
44         property = name;
45     }
46     
47     public void setTrackingPath( File JavaDoc path ) {
48         trackingPath = path;
49     }
50     
51     public void setClusterDir( String JavaDoc dir ) {
52         clusterDir = dir;
53     }
54     
55     public void execute() throws BuildException {
56         if (clusterName == null) {
57             throw new BuildException("Cluster property must be set", getLocation());
58         }
59         if (property == null) {
60             throw new BuildException("Name of the patternset must be set.", getLocation());
61         }
62         if (trackingPath == null) {
63             throw new BuildException("Path to module_tracking.xml file must be set.", getLocation());
64         }
65         if (clusterDir == null) {
66             throw new BuildException("Cluster directory must be set.", getLocation());
67         }
68         
69         String JavaDoc clusterList = this.getProject().getProperty(clusterName);
70         if (clusterList == null) {
71             throw new BuildException("Cluster " + clusterName + " doesn't exist", getLocation());
72         }
73         pattern = (PatternSet) this.getProject().createDataType("patternset");
74         
75         ModuleTracking tracking = new ModuleTracking(trackingPath.getAbsolutePath());
76         StringTokenizer JavaDoc moduleTokens = new StringTokenizer JavaDoc(clusterList, " \t\n\f\r,");
77         while (moduleTokens.hasMoreTokens()) {
78             String JavaDoc module = moduleTokens.nextToken();
79             Iterator JavaDoc files = tracking.getFilesForModule(module);
80             if (files==null) {
81                 log("This module doesn't have module tracking info: " + module, Project.MSG_INFO);
82                 continue;
83             }
84             while (files.hasNext())
85                 pattern.createInclude().setName(clusterDir + File.separator + (String JavaDoc)files.next());
86         }
87         
88         if (pattern.getIncludePatterns(this.getProject()) == null)
89             pattern.createExclude().setName("**");
90         
91         this.getProject().addReference(property, pattern);
92     }
93 }
94
Popular Tags