1 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.Project; 28 import org.apache.tools.ant.Task; 29 30 34 public class SetCluster extends Task { 35 private String name = null; 36 private String propertiesList = null; 37 private String cluster; 38 private String thisModuleName = null; 39 private String defaultLocation = null; 40 41 42 public void setName(String name) { 43 this.name = name; 44 } 45 46 47 public void setList( String propertiesList ) { 48 this.propertiesList = propertiesList; 49 } 50 51 52 public void setCluster (String cluster) { 53 this.cluster = cluster; 54 } 55 56 57 public void setModule(String module) { 58 thisModuleName = module; 59 } 60 61 62 public void setDefaultLocation(String defaultLocation) { 63 this.defaultLocation = defaultLocation; 64 } 65 66 public void execute() throws BuildException { 67 if (name == null) 68 throw new BuildException("Name of property to set have to be specified",this.getLocation()); 69 if (propertiesList != null) { 70 if (cluster != null) 71 throw new BuildException("Either list or cluster property can be specified not both",this.getLocation()); 72 if (thisModuleName == null) 73 throw new BuildException("The name of current module have to be set", this.getLocation()); 74 } else { 75 if (cluster == null) { 76 throw new BuildException("Either list or cluster property have to be specified",this.getLocation()); 77 } 78 if (thisModuleName != null) { 79 throw new BuildException("When cluster property is used thisModuleName should not be set",this.getLocation()); 80 } 81 } 82 83 if (cluster != null) { 84 String clusterDir = this.getProject().getProperty(cluster + ".dir"); 85 if (clusterDir == null) throw new BuildException( "Property: " + cluster + ".dir have to be defined", this.getLocation()); 86 this.getProject().setProperty( name, clusterDir ); 87 return; 88 } 89 90 HashSet modules = new HashSet(); 91 92 StringTokenizer tokens = new StringTokenizer( propertiesList, " \t\n\f\r," ); 93 while (tokens.hasMoreTokens()) { 94 String property = tokens.nextToken().trim(); 95 String list = this.getProject().getProperty( property ); 96 if (list == null) throw new BuildException("Property: " + property + " is not defined anywhere",this.getLocation()); 97 StringTokenizer modTokens = new StringTokenizer(list," \t\n\f\r,"); 98 while (modTokens.hasMoreTokens()) { 99 String module = modTokens.nextToken(); 100 log( property + " " + module, Project.MSG_VERBOSE ); 101 if (module.equals(thisModuleName)) { 102 String clusterDir = this.getProject().getProperty(property + ".dir"); 104 if (clusterDir == null) throw new BuildException( "Property: " + property + ".dir have to be defined", this.getLocation()); 105 log( "Property: " + name + " will be set to " + clusterDir, Project.MSG_VERBOSE); 106 this.getProject().setProperty( name, clusterDir ); 107 return; 108 } 109 } 110 } 111 log("No cluster list with this module: " + thisModuleName + " was found. Using default cluster location: " + defaultLocation, Project.MSG_WARN); 112 if (defaultLocation == null) 113 throw new BuildException("No default cluster location defined", this.getLocation()); 114 115 log( "Property: " + name + " will be set to " + defaultLocation, Project.MSG_VERBOSE); 116 this.getProject().setProperty( name, defaultLocation ); 117 } 118 } 119 | Popular Tags |