KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
23 import java.util.*;
24
25 import org.apache.tools.ant.BuildException;
26 import org.apache.tools.ant.taskdefs.*;
27 import org.apache.tools.ant.Task;
28 import org.apache.tools.ant.Project;
29
30 /** Setting given property to list of clusters on which module depends
31  *
32  * @author Michal Zlamal
33  */

34 public class GetDependsClusters extends Task {
35     private String JavaDoc name = null;
36     private String JavaDoc propertiesList = null;
37     private String JavaDoc thisModuleName = null;
38     
39     /** Comma separated list of properties. One of those properties should contain the name of module from what it ran. */
40     public void setList( String JavaDoc propertiesList ) {
41         this.propertiesList = propertiesList;
42     }
43     
44     /** Name of property to set */
45     public void setName(String JavaDoc name) {
46         this.name = name;
47     }
48     
49     public void execute() throws BuildException {
50         if (name == null)
51             throw new BuildException("Name of property to set have to be specified",this.getLocation());
52         if (propertiesList == null)
53             throw new BuildException("List of clusters have to be specified",this.getLocation());
54         
55         thisModuleName = this.getOwningTarget().getName();
56         if (!thisModuleName.startsWith("all-"))
57             throw new BuildException("This task could be used only in targets \"all-{modulename}\"",this.getLocation());
58         thisModuleName = thisModuleName.substring("all-".length());
59         
60         StringTokenizer tokens = new StringTokenizer( propertiesList, " \t\n\f\r," );
61         while (tokens.hasMoreTokens()) {
62             String JavaDoc property = tokens.nextToken().trim();
63             String JavaDoc list = this.getProject().getProperty( property );
64             if (list == null) throw new BuildException("Property: " + property + " is not defined anywhere",this.getLocation());
65             StringTokenizer modTokens = new StringTokenizer(list," \t\n\f\r,");
66             while (modTokens.hasMoreTokens()) {
67                 String JavaDoc module = modTokens.nextToken();
68                 log( property + " " + module, Project.MSG_VERBOSE );
69                 if (module.equals(thisModuleName)) {
70                     String JavaDoc clusterDepends = this.getProject().getProperty(property + ".depends");
71                     if (clusterDepends == null) throw new BuildException( "Property: " + property + ".depends have to be defined", this.getLocation());
72                     log( "Property: " + name + " will be set to " + clusterDepends, Project.MSG_VERBOSE);
73                     this.getProject().setProperty( name, clusterDepends );
74                     return;
75                 }
76             }
77         }
78         log("No cluster list with this module: " + thisModuleName + " was found. Assume that this module " + thisModuleName + " depends on all clusters: " + propertiesList, Project.MSG_WARN);
79         log( "Property: " + name + " will be set to " + propertiesList, Project.MSG_VERBOSE);
80         this.getProject().setProperty( name, propertiesList );
81         // throw new BuildException("No cluster list with this module: " + thisModuleName + " was found.",this.getLocation());
82
}
83 }
84
Popular Tags