KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.File JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Set JavaDoc;
27 import java.util.StringTokenizer JavaDoc;
28 import java.util.TreeSet JavaDoc;
29 import org.apache.tools.ant.BuildException;
30 import org.apache.tools.ant.Task;
31 import org.apache.tools.ant.types.FileSet;
32
33 /** Pseudo-task to unpack a set of modules.
34  * Resolves build-time dependencies of modules in selected moduleconfig
35  * and print list of cvs modules which you need to checkout from cvs
36  *
37  * @author Rudolf Balada
38  * based on dependency resolving code originally by Jesse Glick in NbMerge.java
39  */

40 public class PrintCvsModules extends Task {
41     
42     private List JavaDoc<String JavaDoc> modules; // list of modules defined by build.xml
43
private String JavaDoc selectorId;
44     private File JavaDoc dir;
45     private String JavaDoc cvsModulesProperty;
46     
47     /** Comma-separated list of modules to include. */
48     public void setModules (String JavaDoc s) {
49         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc (s, ", ");
50         modules = new ArrayList JavaDoc<String JavaDoc>();
51         while (tok.hasMoreTokens ())
52             modules.add(tok.nextToken ());
53     }
54     
55     /**
56      * Specify a property which will be given the list of CVS modules, separated by spaces.
57      */

58     public void setCvsModulesProperty(String JavaDoc p) {
59         cvsModulesProperty = p;
60     }
61     
62     /** Name of property to set the file set to.
63      */

64     public void setId (String JavaDoc s) {
65         selectorId = s;
66     }
67     
68     /** Directory with sources (meaningful only with {@link #setId}) */
69     public void setDir (File JavaDoc f) {
70         dir = f;
71     }
72
73     public void execute () throws BuildException {
74         Set JavaDoc<String JavaDoc> cvslist = new TreeSet JavaDoc<String JavaDoc>();
75         cvslist.add("nbbuild");
76         for (String JavaDoc module: modules) {
77             int slash = module.indexOf('/');
78             if (slash > 0) {
79                 module = module.substring(0, slash);
80             }
81             cvslist.add(module);
82         }
83
84         log("selectedmodules="+modules);
85         log("cvsmodules="+cvslist);
86         if (cvsModulesProperty != null) {
87             StringBuffer JavaDoc cvslistSpaces = new StringBuffer JavaDoc();
88             Iterator JavaDoc cvsIt = cvslist.iterator();
89             while (cvsIt.hasNext()) {
90                 if (cvslistSpaces.length() > 0) {
91                     cvslistSpaces.append(' ');
92                 }
93                 cvslistSpaces.append((String JavaDoc) cvsIt.next());
94             }
95             getProject().setNewProperty(cvsModulesProperty, cvslistSpaces.toString());
96         }
97         
98         if (selectorId != null) {
99             FileSet set = new CvsFileSet();
100             set.setDir(dir);
101             Iterator JavaDoc it = cvslist.iterator();
102             while (it.hasNext()) {
103                 String JavaDoc modname = (String JavaDoc) it.next();
104                 set.createInclude().setName(modname + "/**/*");
105                 set.createExclude().setName(modname + "/www/**/*");
106                 set.createExclude().setName(modname + "/test/**/*");
107             }
108             set.createExclude().setName("*/*/test/**/*");
109             getProject().addReference(selectorId, set);
110         }
111     }
112
113 }
114
Popular Tags