/** Pseudo-task to unpack a set of modules. *Causesthecontainingtargettobothdependonthebuildingofthemodulesin *thefirstplace;andthentounpackthemalltoacertainlocation. * *@authorvariouspeople * *2002-07-31:RudolfBaladaAddedbuildsuccessgranularity(Issue9701), *fixedmodulescan'tfail,"modules"canfail
*/ publicclass NbMerge extends Task {
private File dest; private Vector<String> modules = new Vector<> (); // list of modules defined by build.xml private Vector<String> buildmodules = new Vector<> (); // list of modules which will be built private Vector<String> fixedmodules = new Vector<> (); // list of fixed modules defined in build.xml private Vector<String> buildfixedmodules = new Vector<> (); // List of fixed modules which will be built private Vector<String> failedmodules = new Vector<> (); // List of failed modules private Vector<String> builtmodules = new Vector<> (); // list of successfully built modules private Vector<String> mergemodules = new Vector<> (); // list of successfully built modules private Vector<String> builttargets = new Vector<> (); // list of successfully built targets private String targetprefix = "all-"; private List<File> topdirs = new ArrayList<> (); private List<Suppress> suppress = new LinkedList<> (); privateboolean failonerror = true; // false = enable build success granularity privateboolean mergedependentmodules = false; // merge also dependent modules private String dummyName; private Target dummy; private Hashtable<String,Target> targets; private String builtmodulesproperty = ""; // if set, update property of the name // to list of successfuly built modules
/** Target directory to unpack to (top of IDE installation). */ publicvoid setDest (File f) {
dest = f;
}
/** At the end of task, set system property to the list of successfuly *builtmodules
*/ publicvoid setBuiltModulesProperty (String s) {
builtmodulesproperty = s;
}
/** Enable/Disable merging also dependencies */ publicvoid setMergeDependentModules (boolean b) {
mergedependentmodules = b;
}
/** Comma-separated list of fixed modules to include. */ publicvoid setFixedModules (String s) {
StringTokenizer tok = new StringTokenizer (s, ", ");
fixedmodules = new Vector<> (); while (tok.hasMoreTokens ())
fixedmodules.addElement (tok.nextToken ());
}
/** Comma-separated list of modules to include. */ publicvoid setModules (String s) {
StringTokenizer tok = new StringTokenizer (s, ", ");
modules = new Vector<> (); while (tok.hasMoreTokens ())
modules.addElement (tok.nextToken ());
}
/** String which will have a module name appended to it. *Thiswillformatargetinthesameprojectwhichshould *createthe<samp>netbeans/</samp>subdirectory.
*/ publicvoid setTargetprefix (String s) {
targetprefix = s;
}
/** Set the top directory. *Thereshouldbesubdirectoriesunderthisforeachnamedmodule.
*/ publicvoid setTopdir (File t) {
topdirs.add (t);
}
/** Nested topdir addition. */ publicclass Topdir { /** Path to an extra topdir. */ publicvoid setPath (File t) {
topdirs.add (t);
}
} /** Add a nested topdir. *Ifthereismorethanonetopdirtotal,buildproducts *maybetakenfromanyofthem,includingfrommultipleplaces *forthesamemodule.(Latertopdirsmayoverridebuild *productsinearliertopdirs.)
*/ public Topdir createTopdir () { returnnew Topdir ();
}
/** Locale to suppress. */ publicclass Suppress { // [PENDING] also support branding here
String locale;
String iftest;
String unlesstest; /** Name of the locale, e.g. <samp>ja</samp>. */ publicvoid setLocale (String l) {
locale = l;
} /** Property which if set will enable the suppression. */ publicvoid setIf (String p) {
iftest = p;
} /** Property which if set will disable the suppression. */ publicvoid setUnless (String p) {
unlesstest = p;
}
} /** Add a locale to suppress. *Filesmatchingthislocalesuffixwillnotbemergedin. *E.g.forthelocale<samp>ja</samp>,thiswillexclude *allfilesanddirectoriesendingin<samp>_ja</samp>aswell *asfilesendingin<samp>_ja.</samp>plussomeextension.
*/ public Suppress createSuppress () {
Suppress s = new Suppress ();
suppress.add (s); return s;
}
/** Execute targets which cannot fail and though throw BuildException */ privatevoid fixedModulesBuild() throws BuildException { // Somewhat convoluted code because Project.executeTargets does not // eliminate duplicates when analyzing dependencies! Ecch. // build fixed modules first
dummy = new Target ();
dummyName = "nbmerge-" + getOwningTarget().getName();
targets = getProject().getTargets(); while (targets.contains (dummyName))
dummyName += "-x";
dummy.setName (dummyName); for (String fixedmodule : buildfixedmodules) {
dummy.addDependency (targetprefix + fixedmodule);
}
getProject().addTarget(dummy);
getProject().setProperty("fixedmodules-built", "1" );
@SuppressWarnings("unchecked")
Vector<Target> fullList = getProject().topoSort(dummyName, targets); // Now remove earlier ones: already done.
Vector<Target> doneList = getProject().topoSort(getOwningTarget().getName(), targets);
List<Target> todo = new ArrayList<>(fullList.subList(0, fullList.indexOf(dummy)));
todo.removeAll(doneList.subList(0, doneList.indexOf(getOwningTarget())));
log("Going to execute targets " + todo); for (Target nexttargit: todo) {
String targetname = nexttargit.getName(); if ( builttargets.indexOf(targetname) < 0 ) { // XXX poor replacement for Project.fireTargetStarted etc.
System.out.println(""); System.out.println(targetname + ":"); try {
nexttargit.execute();
} catch (BuildException ex) {
log("Failed to build target: " + targetname, Project.MSG_ERR); throw ex;
}
builttargets.addElement(targetname);
}
}
builtmodules.addAll(buildfixedmodules); // add already built fixed modules to the list
log("fixedmodules=" + buildfixedmodules, Project.MSG_DEBUG);
log("builtmodules=" + builtmodules, Project.MSG_VERBOSE);
}
/** Execute targets which can fail _without_ throwing BuildException */ privatevoid modulesBuild() throws BuildException { if ( ! failonerror ) { // build the rest of modules for (String module : buildmodules) {
dummy = new Target ();
dummyName = "nbmerge-" + getOwningTarget().getName() + "-" + module; while (targets.contains (dummyName))
dummyName += "-x";
dummy.setName (dummyName);
dummy.addDependency (targetprefix + module);
getProject().addTarget(dummy);
@SuppressWarnings("unchecked")
Vector<Target> fullList = getProject().topoSort(dummyName, targets); // Now remove earlier ones: already done.
@SuppressWarnings("unchecked")
Vector<Target> doneList = getProject().topoSort(getOwningTarget().getName(), targets);
List<Target> todo = new ArrayList<>(fullList.subList(0, fullList.indexOf(dummy)));
todo.removeAll(doneList.subList(0, doneList.indexOf(getOwningTarget())));
publicvoid execute () throws BuildException { if (topdirs.isEmpty ()) { thrownew BuildException("You must set at least one topdir attribute", getLocation());
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.