1 19 20 package org.netbeans.nbbuild; 21 22 import java.io.IOException ; 23 import java.util.HashMap ; 24 import java.util.Hashtable ; 25 import java.util.Map ; 26 import java.util.Set ; 27 import java.util.SortedMap ; 28 import java.util.TreeMap ; 29 import org.apache.tools.ant.BuildException; 30 import org.apache.tools.ant.Project; 31 import org.apache.tools.ant.Target; 32 import org.apache.tools.ant.Task; 33 import org.apache.tools.ant.taskdefs.Ant; 34 import org.apache.tools.ant.taskdefs.CallTarget; 35 import org.apache.tools.ant.taskdefs.Echo; 36 import org.apache.tools.ant.taskdefs.Property; 37 38 55 public final class InsertModuleAllTargets extends Task { 56 57 public InsertModuleAllTargets() {} 58 59 public void execute() throws BuildException { 60 try { 61 Project project = getProject(); 62 @SuppressWarnings ("unchecked") 63 Set <String > existingTargets = project.getTargets().keySet(); 64 if (existingTargets.contains("all-openide/util")) { 65 log("Already seem to have inserted targets into this project; will not do it twice", Project.MSG_VERBOSE); 66 return; 67 } 68 @SuppressWarnings ("unchecked") 69 Hashtable <String ,String > props = project.getProperties(); 70 Map <String ,String > clustersOfModules = new HashMap <String ,String >(); 71 for (Map.Entry <String ,String > pair : props.entrySet()) { 72 String cluster = pair.getKey(); 73 if (!cluster.startsWith("nb.cluster.") || cluster.endsWith(".depends") || cluster.endsWith(".dir")) { 74 continue; 75 } 76 for (String module : pair.getValue().split(", *")) { 77 clustersOfModules.put(module, cluster); 78 } 79 } 80 ModuleListParser mlp = new ModuleListParser(props, ParseProjectXml.TYPE_NB_ORG, project); 81 SortedMap <String ,ModuleListParser.Entry> entries = new TreeMap <String ,ModuleListParser.Entry>(); 82 for (ModuleListParser.Entry entry : mlp.findAll()) { 83 String path = entry.getNetbeansOrgPath(); 84 assert path != null : entry; 85 entries.put(path, entry); 86 } 87 for (ModuleListParser.Entry entry : entries.values()) { 88 String path = entry.getNetbeansOrgPath(); 89 assert path != null : entry; 90 String target = "all-" + path; 91 if (existingTargets.contains(target)) { 92 log("Not adding target " + target + " because one already exists", Project.MSG_INFO); 93 continue; 94 } 95 String [] prereqsAsCnb = entry.getBuildPrerequisites(); 96 StringBuffer namedDeps = new StringBuffer ("init"); 97 String myCluster = clustersOfModules.get(path); 98 for (String cnb : prereqsAsCnb ) { 99 ModuleListParser.Entry other = mlp.findByCodeNameBase(cnb); 100 if (other == null) { 101 log("Cannot find build prerequisite " + cnb + " of " + entry, Project.MSG_WARN); 102 continue; 103 } 104 String otherPath = other.getNetbeansOrgPath(); 105 assert otherPath != null : other; 106 String otherCluster = clustersOfModules.get(otherPath); 107 if (myCluster == null || otherCluster == null || myCluster.equals(otherCluster)) { 108 namedDeps.append(",all-"); 109 namedDeps.append(otherPath); 110 } 111 } 112 String namedDepsS = namedDeps.toString(); 113 log("Adding target " + target + " with depends=\"" + namedDepsS + "\"", Project.MSG_VERBOSE); 114 Target t = new Target(); 115 t.setName(target); 116 t.setLocation(getLocation()); 117 t.setDepends(namedDepsS); 118 project.addTarget(t); 119 if (myCluster != null) { 120 CallTarget call = (CallTarget) project.createTask("antcall"); 121 call.setTarget("build-one-cluster-dependencies"); 122 call.setInheritAll(false); 123 Property param = call.createParam(); 124 param.setName("one.cluster.dependencies"); 125 param.setValue(props.get(myCluster + ".depends")); 126 param = call.createParam(); 127 param.setName("one.cluster.name"); 128 param.setValue("this-cluster"); 129 t.addTask(call); 130 } 131 Echo echo = (Echo) project.createTask("echo"); 132 echo.setMessage("Building " + path + "..."); 133 t.addTask(echo); 134 Ant ant = (Ant) project.createTask("ant"); 135 ant.setDir(project.resolveFile("../" + path)); 136 ant.setTarget("netbeans"); 137 t.addTask(ant); 138 } 139 } catch (IOException e) { 140 throw new BuildException(e.toString(), e, getLocation()); 141 } 142 } 143 144 } 145 | Popular Tags |