From 53e60ba8ac4587ea7963e8a144dcce508ef3f774 Mon Sep 17 00:00:00 2001 From: Laszlo Kishalmi Date: Thu, 21 Apr 2022 15:01:45 -0700 Subject: [PATCH] Initial work to add cluster level to the project structure --- build.gradle | 21 ++++++++- .../nb/support/DefaultNbClusterContainer.java | 47 +++++++++++++------ .../nb/support/NbClusterContainer.java | 2 + .../gradle/nbsupport/nb/support/NbModule.java | 3 +- .../nb/support/NetBeansClusterPlugin.java | 15 +++--- .../nb/support/NetBeansModulePlugin.java | 45 +++++++++++++++--- settings.gradle | 5 +- 7 files changed, 107 insertions(+), 31 deletions(-) diff --git a/build.gradle b/build.gradle index d7badc2cbe5f..cc255fc59365 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,8 @@ apply plugin: org.netbeans.gradle.nbsupport.nb.support.NetBeansClusterPlugin +description = 'NetBeans IDE' + task clean(type: Delete) { delete 'build' } @@ -31,4 +33,21 @@ clusters { "platform" { } -} \ No newline at end of file +} + +project(':apisupport').description = 'API Support' +project(':cpplite').description = 'CPP Lite' +project(':enterprise').description = 'Enterprise' +project(':ergonomics').description = 'Ergonomics' +project(':extide').description = 'IDE Extensions' +project(':groovy').description = 'Groovy' +project(':harness').description = 'IDE Test Harness' +project(':ide').description = 'IDE' +project(':java').description = 'Java' +project(':javafx').description = 'JavaFX' +project(':nb').description = 'NetBeans IDE Branding' +project(':php').description = 'PHP' +project(':platform').description = 'Platform' +project(':profiler').description = 'Profiler' +project(':webcommon').description = 'Web Common' +project(':websvccommon').description = 'Web Services Common' \ No newline at end of file diff --git a/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/DefaultNbClusterContainer.java b/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/DefaultNbClusterContainer.java index e1094540ddff..c2bfbc7fac49 100644 --- a/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/DefaultNbClusterContainer.java +++ b/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/DefaultNbClusterContainer.java @@ -32,6 +32,7 @@ import org.gradle.api.Project; import org.gradle.api.file.FileCollection; import org.gradle.internal.reflect.Instantiator; +import org.gradle.tooling.BuildException; /** * @@ -46,6 +47,7 @@ public class DefaultNbClusterContainer extends AbstractValidatingNamedDomainObje private static final String LIST_SUFFIX = ".list"; private final Project project; + private final Map codeBaseName2ProjectPath = new HashMap<>(); @Inject public DefaultNbClusterContainer(Project project, Instantiator instantiator, CollectionCallbackActionDecorator callbackActionDecorator) { @@ -80,23 +82,27 @@ public void from(File nbclusters) { for (String propName : props.stringPropertyNames()) { if (propName.startsWith(CLUSTER_PREFIX) && propName.endsWith(DIR_SUFFIX)) { String clusterName = propName.substring(CLUSTER_PREFIX.length(), propName.length() - DIR_SUFFIX.length()); + String clusterDirName = props.getProperty(CLUSTER_PREFIX + clusterName + DIR_SUFFIX); String moduleList = props.getProperty(CLUSTER_PREFIX + clusterName); String[] modules = moduleList.split(","); - File clusterDir = new File(project.getRootDir(), clusterName); - Set codeBaseNames = new LinkedHashSet<>(); - for (String module : modules) { - File moduleDir = new File(clusterDir, module); - String codeNameBase = projectsByDir.get(moduleDir); - if (codeNameBase != null) { - codeBaseNames.add(codeNameBase); - } else { - //System.out.println("Cannot identify project at: " + moduleDir.getAbsolutePath()); + File clusterDir = new File(project.getRootDir(), clusterDirName); + if (clusterDir.isDirectory()) { + Set codeBaseNames = new LinkedHashSet<>(); + for (String module : modules) { + File moduleDir = new File(clusterDir, module); + String codeNameBase = projectsByDir.get(moduleDir); + if (codeNameBase != null) { + codeBaseNames.add(codeNameBase); + } else { + //System.out.println("Cannot identify project at: " + moduleDir.getAbsolutePath()); + } } - } - if (!codeBaseNames.isEmpty()) { - NbCluster cluster = maybeCreate(clusterName); - for (String codeBaseName : codeBaseNames) { - cluster.project(codeBaseName); + if (!codeBaseNames.isEmpty()) { + NbCluster cluster = maybeCreate(clusterName); + for (String codeBaseName : codeBaseNames) { + cluster.project(codeBaseName); + codeBaseName2ProjectPath.put(codeBaseName, projectName(clusterDirName, codeBaseName)); + } } } } @@ -148,4 +154,17 @@ public FileCollection getFinalDirs() { return project.files((Object[]) relPaths.toArray(new String[relPaths.size()])); } + @Override + public Project getProjectByCodeName(String codeNameBase) { + String projectPath = codeBaseName2ProjectPath.get(codeNameBase); + if (projectPath == null) { + System.out.println(codeBaseName2ProjectPath); + throw new BuildException("No project found for: " + codeNameBase, new NullPointerException()); + } + return project.project(projectPath); + } + + private static String projectName(String cluster, String codeBaseName) { + return ":" + cluster + ":" + codeBaseName; + } } diff --git a/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/NbClusterContainer.java b/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/NbClusterContainer.java index 9336097147b1..780329a9d3b8 100644 --- a/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/NbClusterContainer.java +++ b/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/NbClusterContainer.java @@ -17,6 +17,7 @@ import java.io.File; import org.gradle.api.NamedDomainObjectCollection; +import org.gradle.api.Project; import org.gradle.api.file.FileCollection; /** @@ -27,4 +28,5 @@ public interface NbClusterContainer extends NamedDomainObjectCollection getDependencies(DependencyType type) { } NbModule findOrLoadModule(String codeNameBase) { - Project prj = project.findProject(":" + codeNameBase); + Project root = project.getRootProject(); + Project prj = root.getExtensions().findByType(NbClusterContainer.class).getProjectByCodeName(codeNameBase); if (prj != null) { NbProjectExtension ext = prj.getExtensions().findByType(NbProjectExtension.class); if (ext == null) { diff --git a/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/NetBeansClusterPlugin.java b/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/NetBeansClusterPlugin.java index ae5409fcf192..2d25150c5ab9 100644 --- a/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/NetBeansClusterPlugin.java +++ b/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/NetBeansClusterPlugin.java @@ -27,17 +27,18 @@ public class NetBeansClusterPlugin implements Plugin{ @Override public void apply(Project project) { + NbClusterContainer clusters = project.getObjects().newInstance(DefaultNbClusterContainer.class, project); + project.getExtensions().add("clusters", clusters); + for (Project subproject : project.getSubprojects()) { - NbBuildExtension nbbuild = new NbBuildExtension(); - NbProjectExtension nbproject = new NbProjectExtension(subproject); - subproject.getExtensions().add("nbbuild", nbbuild); - subproject.getExtensions().add("nbproject", nbproject); + if (subproject.getParent() != subproject.getRootProject()) { + } } for (Project subproject : project.getSubprojects()) { - subproject.getPluginManager().apply(NetBeansModulePlugin.class); + if (subproject.getParent() != subproject.getRootProject()) { + subproject.getPluginManager().apply(NetBeansModulePlugin.class); + } } - NbClusterContainer clusters = project.getObjects().newInstance(DefaultNbClusterContainer.class, project); - project.getExtensions().add("clusters", clusters); project.afterEvaluate((Project prj) -> { NbClusterContainer c = prj.getExtensions().getByType(NbClusterContainer.class); for (NbCluster cluster : c) { diff --git a/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/NetBeansModulePlugin.java b/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/NetBeansModulePlugin.java index fba252fbf910..8f297248ab63 100644 --- a/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/NetBeansModulePlugin.java +++ b/buildSrc/src/main/java/org/netbeans/gradle/nbsupport/nb/support/NetBeansModulePlugin.java @@ -39,6 +39,7 @@ import org.gradle.api.tasks.compile.JavaCompile; import org.gradle.api.tasks.testing.Test; import org.gradle.jvm.tasks.Jar; +import org.gradle.tooling.BuildException; import static org.netbeans.gradle.nbsupport.nb.support.NbProjectExtension.*; @@ -50,21 +51,34 @@ public class NetBeansModulePlugin implements Plugin { @Override public void apply(Project project) { + project.getPluginManager().apply("java"); - NbProjectExtension nbproject = project.getExtensions().getByType(NbProjectExtension.class); JavaPluginExtension java = project.getExtensions().getByType(JavaPluginExtension.class); //java.setSourceCompatibility(JavaVersion.toVersion(nbproject.getProperty("javac.source"))); java.setSourceCompatibility(JavaVersion.VERSION_1_8); - prepareTestConfiguration(project, nbproject); + + NbBuildExtension nbbuild = new NbBuildExtension(); + NbProjectExtension nbproject = new NbProjectExtension(project); + project.getExtensions().add("nbbuild", nbbuild); + project.getExtensions().add("nbproject", nbproject); + project.setDescription(nbproject.getDisplayName()); + + prepareTestConfiguration(project, nbproject); + prepareSourceSets(project); updateCompileTasks(project); + + project.getTasks().register("copyExternals"); + addNbDependenciesTask(project); + + project.afterEvaluate((Project prj) -> afterEvaluate(prj)); - String moduleName = project.getName(); + /* + String moduleName = nbproject.module.getCodeNameBase(); moduleName = nbproject.isTestOnly() ? moduleName.substring(0, moduleName.length() - 5) : moduleName; if (!"nbbuild".equals(moduleName)) { - project.getTasks().register("copyExternals"); project.afterEvaluate((Project prj) -> { copyExternals(prj); if (!nbproject.isTestOnly()) { @@ -75,9 +89,20 @@ public void apply(Project project) { prepareDependencies(project); addNbDependenciesTask(project); copyTestData(project); - } + }*/ } + private void afterEvaluate(Project project) { + NbProjectExtension nbproject = project.getExtensions().getByType(NbProjectExtension.class); + + copyExternals(project); + if (!nbproject.isTestOnly()) { + updateJarTask(project); + } + updateTestTask(project); + + } + private void addNbDependenciesTask(Project prj) { prj.getTasks().register("nbDependencies", (Task task) -> { task.doLast((t) -> { @@ -131,6 +156,9 @@ private void prepareDependencies(Project prj) { NbBuildExtension nbbuild = prj.getExtensions().getByType(NbBuildExtension.class); NbProjectExtension nbProject = prj.getExtensions().getByType(NbProjectExtension.class); NbModule module = nbProject.getModule(); + if (module == null) { + throw new BuildException("" + prj + " does not have module", new NullPointerException()); + } for (String ext : module.getClassPathExtensions().keySet()) { dh.add("api", prj.files(new File(nbProject.getModuleDestDir(), ext))); @@ -328,7 +356,7 @@ private static String openideModuleModuleDependencies(Project prj, Set + File clusterDir = new File(rootDir, cluster) modules.each { name, dir -> - def pname = ':' + name + def pname = ":${cluster}:${name}" include pname - project(pname).projectDir = new File(rootDir, "${cluster}/${dir}") + project(pname).projectDir = new File(clusterDir, dir) } }