Skip to content

Commit

Permalink
Initial work to add cluster level to the project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
lkishalmi committed Nov 14, 2023
1 parent e2ca56e commit 53e60ba
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 31 deletions.
21 changes: 20 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

apply plugin: org.netbeans.gradle.nbsupport.nb.support.NetBeansClusterPlugin

description = 'NetBeans IDE'

task clean(type: Delete) {
delete 'build'
}
Expand All @@ -31,4 +33,21 @@ clusters {
"platform" {

}
}
}

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'
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand All @@ -46,6 +47,7 @@ public class DefaultNbClusterContainer extends AbstractValidatingNamedDomainObje
private static final String LIST_SUFFIX = ".list";

private final Project project;
private final Map<String, String> codeBaseName2ProjectPath = new HashMap<>();

@Inject
public DefaultNbClusterContainer(Project project, Instantiator instantiator, CollectionCallbackActionDecorator callbackActionDecorator) {
Expand Down Expand Up @@ -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<String> 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<String> 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));
}
}
}
}
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.File;
import org.gradle.api.NamedDomainObjectCollection;
import org.gradle.api.Project;
import org.gradle.api.file.FileCollection;

/**
Expand All @@ -27,4 +28,5 @@ public interface NbClusterContainer extends NamedDomainObjectCollection<NbCluste

void from(File nbclusters);
FileCollection getFinalDirs();
Project getProjectByCodeName(String codeNameBase);
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ Set<Dependency> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ public class NetBeansClusterPlugin implements Plugin<Project>{

@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -50,21 +51,34 @@ public class NetBeansModulePlugin implements Plugin<Project> {

@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()) {
Expand All @@ -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) -> {
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -328,7 +356,7 @@ private static String openideModuleModuleDependencies(Project prj, Set<? extends
sb.append('/').append(dep.getReleaseVersion());
}
if (dep.isImplementationVersion()) {
Project dprj = prj.project(":" + dep.getCodeNameBase());
Project dprj = getProjectbyCodeNameBase(prj, dep.getCodeNameBase());
if (dprj != null) {
NbProjectExtension dext = dprj.getExtensions().getByType(NbProjectExtension.class);
sb.append(" = ").append(dext.getImplementationVersion());
Expand All @@ -342,6 +370,11 @@ private static String openideModuleModuleDependencies(Project prj, Set<? extends
return sb.toString();
}

private static Project getProjectbyCodeNameBase(Project project, String codeNameBase) {
NbClusterContainer clusters = project.getRootProject().getExtensions().getByType(NbClusterContainer.class);
return clusters.getProjectByCodeName(codeNameBase);
}

private static String classPathEntry(NbModule module) {
StringBuilder sb = new StringBuilder();
String separator = "";
Expand Down
5 changes: 3 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -892,9 +892,10 @@ def clusters = [
]

clusters.each { cluster, modules ->
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)
}
}

0 comments on commit 53e60ba

Please sign in to comment.