Permalink
Browse files

Adjusted the wizard templates according to recommendations: http://fo…

  • Loading branch information...
1 parent 9850220 commit 6f1bde361d9afc57dcb0c0a5793a109d86eec543 @kelemen committed Nov 15, 2012
@@ -37,7 +37,7 @@
private static final String MULTI_PROJECT_BUILD_GRADLE = "org/netbeans/gradle/project/resources/newproject/multi-project-root.gradle";
@StaticResource
- private static final String MULTI_PROJECT_PARENT_GRADLE = "org/netbeans/gradle/project/resources/newproject/multi-project-parent.gradle";
+ private static final String MULTI_PROJECT_COMMON_GRADLE = "org/netbeans/gradle/project/resources/newproject/multi-project-common.gradle";
@StaticResource
private static final String MULTI_PROJECT_SETTINGS_GRADLE = "org/netbeans/gradle/project/resources/newproject/multi-project-settings.gradle";
@@ -73,8 +73,8 @@ private static void createParentGradle(
varReplaceMap.put("${SOURCE_LEVEL}", AbstractProjectProperties.getSourceLevelFromPlatform(JavaPlatform.getDefault()));
NewProjectUtils.copyTemplateFile(
- MULTI_PROJECT_PARENT_GRADLE,
- new File(projectDir, "parent.gradle"),
+ MULTI_PROJECT_COMMON_GRADLE,
+ new File(projectDir, "common.gradle"),
NewProjectUtils.DEFAULT_FILE_ENCODING,
varReplaceMap);
}
@@ -39,22 +39,28 @@ private Problem checkFile(File projectDir, String fileName) {
public Problem validateInput(String inputType) {
File rootProject = new File(inputType);
- Problem problem;
+ Problem problemRootBuild = checkFile(rootProject, GradleProjectConstants.BUILD_FILE_NAME);
+ if (problemRootBuild != null) {
+ return problemRootBuild;
+ }
- problem = checkFile(rootProject, GradleProjectConstants.BUILD_FILE_NAME);
- if (problem != null) {
- return problem;
+ Problem problemRootSettings = checkFile(rootProject, GradleProjectConstants.SETTINGS_FILE_NAME);
+ if (problemRootSettings != null) {
+ return problemRootSettings;
}
- problem = checkFile(rootProject, GradleProjectConstants.SETTINGS_FILE_NAME);
- if (problem != null) {
- return problem;
+ Problem problemOldFormat = checkFile(rootProject, "parent.gradle");
+ Problem problemNewFromat = checkFile(rootProject, "common.gradle");
+
+ if (problemNewFromat != null && problemOldFormat != null) {
+ return problemNewFromat;
}
- problem = checkFile(rootProject, "parent.gradle");
- if (problem != null) {
- return problem;
+ if (problemOldFormat == null && problemNewFromat == null) {
+ // Cannot determine which format.
+ return problemNewFromat;
}
+
return null;
}
});
@@ -30,7 +30,10 @@
WizardDescriptor.BackgroundInstantiatingIterator<WizardDescriptor> {
@StaticResource
- private static final String SINGLE_PROJECT_BUILD_GRADLE = "org/netbeans/gradle/project/resources/newproject/subproject.gradle";
+ private static final String SINGLE_PROJECT_OLD_BUILD_GRADLE = "org/netbeans/gradle/project/resources/newproject/subproject.gradle";
+
+ @StaticResource
+ private static final String SINGLE_PROJECT_BUILD_GRADLE = "org/netbeans/gradle/project/resources/newproject/subproject2.gradle";
private final List<WizardDescriptor.Panel<WizardDescriptor>> descriptors;
private final AtomicReference<GradleSingleProjectConfig> configRef;
@@ -45,10 +48,24 @@ public GradleSubProjectWizardIterator() {
private static void createBuildGradle(
File projectDir,
GradleSingleProjectConfig config) throws IOException {
+ File rootDir = projectDir.getParentFile();
+ if (rootDir == null) {
+ throw new IOException("Invalid project directory for subproject.");
+ }
+
+ boolean oldFormat = new File(rootDir, "parent.gradle").isFile();
+ boolean newFormat = new File(rootDir, "common.gradle").isFile();
+ if (oldFormat && newFormat) {
+ throw new IOException("Cannot determine if the project uses the new or the old format.");
+ }
+ if (!oldFormat && !newFormat) {
+ throw new IOException("The parent directory does nto appear to be created by the multi-project wizard.");
+ }
+
String mainClass = config.getMainClass();
String buildGradleContent = StringUtils.getResourceAsString(
- SINGLE_PROJECT_BUILD_GRADLE,
+ newFormat ? SINGLE_PROJECT_BUILD_GRADLE : SINGLE_PROJECT_OLD_BUILD_GRADLE,
NewProjectUtils.DEFAULT_FILE_ENCODING);
buildGradleContent = buildGradleContent.replace("${MAIN_CLASS}",
@@ -2,6 +2,10 @@ import org.gradle.api.artifacts.*
apply plugin: 'base' // To add "clean" task to the root project.
+subprojects {
+ apply from: rootProject.file('common.gradle')
+}
+
task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the projects.') {
title = 'All modules'
destinationDir = new File(project.buildDir, 'merged-javadoc')
@@ -0,0 +1,24 @@
+// Note: "common.gradle" in the root project contains additional initialization
+// for this project. This initialization is applied in the "build.gradle"
+// of the root project.
+
+// NetBeans will automatically add "run" and "debug" tasks relying on the
+// "mainClass" property. You may however define the property prior executing
+// tasks by passing a "-PmainClass=<QUALIFIED_CLASS_NAME>" argument.
+//
+// Note however, that you may define your own "run" and "debug" task if you
+// prefer. In this case NetBeans will not add these tasks but you may rely on
+// your own implementation.
+if (!hasProperty('mainClass')) {
+ ext.mainClass = '${MAIN_CLASS}'
+}
+
+dependencies {
+ // TODO: Add dependencies here
+ // but note that JUnit should have already been added in parent.gradle.
+ // By default, only the Maven Central Repository is specified in
+ // parent.gradle.
+ //
+ // You can read more about how to add dependency here:
+ // http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies
+}

0 comments on commit 6f1bde3

Please sign in to comment.