Skip to content

Commit

Permalink
Allow modules to be located in cluster.dir/cnb structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaroslav Tulach committed May 28, 2018
1 parent 5a497c9 commit a979899
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -88,10 +91,7 @@ public final class ModuleList {
static int jarsOpened;

/** Synch with org.netbeans.nbbuild.ModuleListParser.FOREST: */
private static final String[] FOREST = {
/*root*/null,
"contrib",
};
private final String[] FOREST;

/**
* Cache of source-derived lists, by source root.
Expand Down Expand Up @@ -1176,7 +1176,7 @@ public static File findNetBeansOrg(File basedir) {
// Check for post-Hg layout:
File repo = f.getParentFile();
if (repo != null) {
for (String tree : FOREST) {
for (String tree : new String[] { null, "contrib" }) {
File mainrepo;
if (tree == null) {
mainrepo = repo;
Expand All @@ -1196,7 +1196,7 @@ public static File findNetBeansOrg(File basedir) {
if (f == null) {
return null;
}
if (new File(f, "nbbuild").isDirectory() && new File(f, "core").isDirectory()) { // NOI18N
if (new File(f, "nbbuild").isDirectory()) { // NOI18N
return f;
}
}
Expand Down Expand Up @@ -1263,6 +1263,18 @@ public static String findClusterLocation(File basedir, File nbroot, NbModuleType
clusterLocations.put(nbroot, clusterLocationsHere);
}
cluster = clusterLocationsHere.get(path);
if (cluster == null && path != null) {
int clusterSep = path.lastIndexOf('/');
if (clusterSep >= 0) {
String id = path.substring(clusterSep + 1);
String expCluster = path.substring(0, clusterSep);

cluster = clusterLocationsHere.get(id);
if (!expCluster.equals(cluster)) {
cluster = null;
}
}
}
if (cluster == null) {
cluster = "extra"; // NOI18N
}
Expand Down Expand Up @@ -1290,6 +1302,26 @@ public static String findClusterLocation(File basedir, File nbroot, NbModuleType
private ModuleList(Map<String,ModuleEntry> entries, File home) {
this.entries = entries;
this.home = home;
Set<String> forest = new LinkedHashSet<>();
forest.add(null);
forest.add("contrib");
File cluster = new File(new File(home, "nbbuild"), "cluster.properties");
if (cluster.exists()) {
Properties p = new Properties();
try (FileInputStream is = new FileInputStream(cluster)) {
p.load(is);
} catch (IOException ex) {
ex.printStackTrace();
}
Enumeration<?> en = p.propertyNames();
while (en.hasMoreElements()) {
String propName = (String) en.nextElement();
if (propName.endsWith(".dir")) {
forest.add(p.getProperty(propName));
}
}
}
FOREST = forest.toArray(new String[0]);
}

public @Override String toString() {
Expand Down
25 changes: 19 additions & 6 deletions nbbuild/antsrc/org/netbeans/nbbuild/GetModuleName.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,28 @@
* @author Michal Zlamal
*/
public class GetModuleName extends Task {
String name = null;
File root = null;
String name;
String id;
File root;

// XXX this is a lousy attr name; conventional for such attrs to
// end in 'property' so you realize they refer to a property name
public void setName (String name) {
this.name = name;
}

/** Root directory of the whole project - ${nb_all} */
public void setRoot( File root ) {
public void setId (String id) {
this.id = id;
}

/** Root directory of the whole project - ${nb_all}
* @param root the root
*/
public void setRoot(File root) {
this.root = root;
}

@Override
public void execute() throws BuildException {
if (name == null)
throw new BuildException("You must set the property name, where to store the module name", this.getLocation());
Expand All @@ -54,7 +62,7 @@ public void execute() throws BuildException {
dir = dir.getParentFile ();
}
String rootdir = root.getCanonicalPath();
StringBuffer modulename = new StringBuffer ();
StringBuilder modulename = new StringBuilder ();
while (dir != null) {
if (dir.getCanonicalPath ().equals (rootdir)) {
break;
Expand All @@ -70,7 +78,12 @@ public void execute() throws BuildException {
if (dir == null) {
throw new BuildException("This module (" + this.getProject().getBaseDir() + ") is on different path than the root dir", this.getLocation());
}
this.getProject().setProperty(name, modulename.toString()); // XXX should be setNewProperty, when that is possible
final String mName = modulename.toString();
this.getProject().setNewProperty(name, mName);
if (id != null) {
int last = mName.lastIndexOf('/');
this.getProject().setNewProperty(id, mName.substring(last + 1));
}
}
catch (IOException ex) {
throw new BuildException("Root dir or module's base dir wasn't recognized", ex, this.getLocation());
Expand Down
18 changes: 11 additions & 7 deletions nbbuild/antsrc/org/netbeans/nbbuild/InsertModuleAllTargets.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ public void setUseClusters(boolean b) {
for( String module: clusterModules) {
File moduleBuild = new File(nbRoot, module + File.separator + "build.xml");
if (!moduleBuild.exists() || !moduleBuild.isFile()) {
missingModules = true;
log("This module is missing from checkout: " + module + " - at least can't find: " + moduleBuild.getAbsolutePath());
String clusterDir = (String) props.get(cluster + ".dir");
File subModuleBuild = new File(new File(nbRoot, clusterDir), module + File.separator + "build.xml");
if (!subModuleBuild.exists() || !subModuleBuild.isFile()) {
missingModules = true;
log("This module is missing from checkout: " + module + " - at least can't find: " + moduleBuild.getAbsolutePath());
}
}
}
}
Expand Down Expand Up @@ -126,7 +130,7 @@ public void setUseClusters(boolean b) {
for (ModuleListParser.Entry entry : entries.values()) {
String path = entry.getNetbeansOrgPath();
assert path != null : entry;
String trg = "all-" + path;
String trg = "all-" + entry.getNetbeansOrgId();
if (existingTargets.contains(trg)) {
log("Not adding target " + trg + " because one already exists", Project.MSG_INFO);
continue;
Expand All @@ -140,12 +144,12 @@ public void setUseClusters(boolean b) {
log("Cannot find build prerequisite " + cnb + " of " + entry, Project.MSG_WARN);
continue;
}
String otherPath = other.getNetbeansOrgPath();
if (otherPath == null) continue; // Do not add the all-module dependency for module which is in the binaries
String otherCluster = clustersOfModules.get(otherPath);
String otherId = other.getNetbeansOrgId();
if (otherId == null) continue; // Do not add the all-module dependency for module which is in the binaries
String otherCluster = clustersOfModules.get(otherId);
if (myCluster == null || otherCluster == null || myCluster.equals(otherCluster)) {
namedDeps.append(",all-");
namedDeps.append(otherPath);
namedDeps.append(otherId);
}
}
String namedDepsS = namedDeps.toString();
Expand Down
65 changes: 39 additions & 26 deletions nbbuild/antsrc/org/netbeans/nbbuild/ModuleListParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ private static Map<String,Entry> scanNetBeansOrgSources(File root, Map<String,Ob
Set<String> standardModules = new HashSet<>();
boolean doFastScan = false;
String basedir = (String) properties.get("basedir");
String clusterList = (String) properties.get("nb.clusters.list");
if (basedir != null) {
File basedirF = new File(basedir);
String clusterList = (String) properties.get("nb.clusters.list");
if (clusterList == null) {
String config = (String) properties.get("cluster.config");
if (config != null) {
Expand Down Expand Up @@ -190,6 +190,9 @@ private static Map<String,Entry> scanNetBeansOrgSources(File root, Map<String,Ob
registerTimestampAndSize(new File(root, "nbbuild" + File.separatorChar + "cluster.properties"), timestampsAndSizes);
registerTimestampAndSize(new File(root, "nbbuild" + File.separatorChar + "build.properties"), timestampsAndSizes);
registerTimestampAndSize(new File(root, "nbbuild" + File.separatorChar + "user.build.properties"), timestampsAndSizes);

doFastScan = false;

if (doFastScan) {
if (project != null) {
project.log("Scanning for modules in " + root + " among standard clusters");
Expand All @@ -203,7 +206,18 @@ private static Map<String,Entry> scanNetBeansOrgSources(File root, Map<String,Ob
project.log("Scanning for modules in " + root);
project.log("Quick scan mode disabled since " + basedir + " not among standard modules of " + root + " which are " + standardModules, Project.MSG_VERBOSE);
}
for (String tree : FOREST) {
List<String> subDirs = new ArrayList<>();
subDirs.addAll(Arrays.asList(FOREST));
StringTokenizer tok = new StringTokenizer(clusterList, ", ");
while (tok.hasMoreTokens()) {
String clusterName = tok.nextToken();
String clusterDir = project.getProperty(clusterName + ".dir");
if (subDirs.contains(clusterDir)) {
continue;
}
subDirs.add(clusterDir);
}
for (String tree : subDirs) {
File dir = tree == null ? root : new File(root, tree);
File[] kids = dir.listFiles();
if (kids == null) {
Expand Down Expand Up @@ -339,35 +353,24 @@ private static boolean scanPossibleProject(File dir, Map<String,Entry> entries,
faketask.setName("module.jar");
faketask.setValue(fakeproj.replaceProperties("${module.jar.dir}/${module.jar.basename}"));
faketask.execute();
String id = null;
switch (moduleType) {
case NB_ORG:
assert path != null;
// Find the associated cluster.
// first try direct mapping in nbbuild/netbeans/moduleCluster.properties
String clusterDir = (String) properties.get(path + ".dir");
if (clusterDir != null) {
clusterDir = clusterDir.substring(clusterDir.lastIndexOf('/') + 1);
} else {
// not found, try indirect nbbuild/cluster.properties
for (Map.Entry<String,Object> entry : properties.entrySet()) {
String val = (String) entry.getValue();
String[] modules = val.split(", *");
if (Arrays.asList(modules).contains(path)) {
String key = entry.getKey();
clusterDir = (String) properties.get(key + ".dir");
if (clusterDir != null) {
faketask.setName("cluster.dir");
faketask.setValue(clusterDir);
faketask.execute();
break;
}
}
String[] clusterDir = { (String) properties.get(path + ".dir") };
if (clusterDir[0] != null) {
final String subStr = clusterDir[0].substring(clusterDir[0].lastIndexOf('/') + 1);
if (path.startsWith(subStr + "/")) {
id = path.substring(subStr.length() + 1);
}
if (clusterDir == null)
clusterDir = "extra"; // fallback
clusterDir[0] = subStr;
} else {
id = SetCluster.findClusterAndId("cluster.dir", clusterDir, properties, path, faketask, "extra");
}
faketask.setName("cluster.dir");
faketask.setValue(clusterDir);
faketask.setValue(clusterDir[0]);
faketask.execute();
faketask.setName("netbeans.dest.dir");
faketask.setValue(properties.get("netbeans.dest.dir"));
Expand Down Expand Up @@ -482,7 +485,7 @@ private static boolean scanPossibleProject(File dir, Map<String,Entry> entries,
prereqs.add(cnb2);
}
String cluster = fakeproj.getProperty("cluster.dir"); // may be null
Entry entry = new Entry(cnb, jar, exts.toArray(new File[exts.size()]), dir, path,
Entry entry = new Entry(cnb, jar, exts.toArray(new File[exts.size()]), dir, path, id == null ? path : id,
prereqs.toArray(new String[prereqs.size()]),
cluster,
rundeps.toArray(new String[rundeps.size()]),
Expand Down Expand Up @@ -886,7 +889,7 @@ static boolean scanOneBinary(File m, File cluster, Map<String, Entry> entries, F
String moduleDependencies = attr.getValue("OpenIDE-Module-Module-Dependencies");


Entry entry = new Entry(codenamebase, m, exts, null, null, null, cluster.getName(),
Entry entry = new Entry(codenamebase, m, exts, null, null, null, null, cluster.getName(),
parseRuntimeDependencies(moduleDependencies), Collections.<String,String[]>emptyMap(),
new File(moduleAutoDepsDir, codenamebase.replace('.', '-') + ".xml"));
Entry prev = entries.put(codenamebase, entry);
Expand All @@ -910,20 +913,22 @@ public static final class Entry implements Serializable {
private final File[] classPathExtensions;
private final File sourceLocation;
private final String netbeansOrgPath;
private final String netbeansOrgId;
private final String[] buildPrerequisites;
private final String clusterName;
private final String[] runtimeDependencies;
// dependencies on other tests
private final Map<String,String[]> testDependencies;
private final File moduleAutoDeps;

Entry(String cnb, File jar, File[] classPathExtensions, File sourceLocation, String netbeansOrgPath,
Entry(String cnb, File jar, File[] classPathExtensions, File sourceLocation, String netbeansOrgPath, String netbeansOrgId,
String[] buildPrerequisites, String clusterName,String[] runtimeDependencies, Map<String,String[]> testDependencies, File moduleAutoDeps) {
this.cnb = cnb;
this.jar = jar;
this.classPathExtensions = classPathExtensions;
this.sourceLocation = sourceLocation;
this.netbeansOrgPath = netbeansOrgPath;
this.netbeansOrgId = netbeansOrgId;
this.buildPrerequisites = buildPrerequisites;
this.clusterName = clusterName;
this.runtimeDependencies = runtimeDependencies;
Expand Down Expand Up @@ -1033,6 +1038,9 @@ public boolean equals(Object obj) {
if ((this.netbeansOrgPath == null) ? (other.netbeansOrgPath != null) : !this.netbeansOrgPath.equals(other.netbeansOrgPath)) {
return false;
}
if ((this.netbeansOrgId == null) ? (other.netbeansOrgId != null) : !this.netbeansOrgId.equals(other.netbeansOrgId)) {
return false;
}
if (!Arrays.deepEquals(this.buildPrerequisites, other.buildPrerequisites)) {
return false;
}
Expand All @@ -1056,13 +1064,18 @@ public int hashCode() {
hash = 83 * hash + Arrays.deepHashCode(this.classPathExtensions);
hash = 83 * hash + (this.sourceLocation != null ? this.sourceLocation.hashCode() : 0);
hash = 83 * hash + (this.netbeansOrgPath != null ? this.netbeansOrgPath.hashCode() : 0);
hash = 83 * hash + (this.netbeansOrgId != null ? this.netbeansOrgId.hashCode() : 0);
hash = 83 * hash + Arrays.deepHashCode(this.buildPrerequisites);
hash = 83 * hash + (this.clusterName != null ? this.clusterName.hashCode() : 0);
hash = 83 * hash + Arrays.deepHashCode(this.runtimeDependencies);
hash = 83 * hash + (this.testDependencies != null ? this.testDependencies.hashCode() : 0);
return hash;
}

String getNetbeansOrgId() {
return netbeansOrgId;
}


}

Expand Down
Loading

0 comments on commit a979899

Please sign in to comment.