Permalink
Browse files

New project properties: Script platform, Gradle home (they are not us…

…ed for anything currently).
  • Loading branch information...
kelemen committed Dec 4, 2012
1 parent 1ed057e commit d0adbd0b2397801428fcb61bdc95cc07fc243cd3
@@ -102,6 +102,18 @@ public void load(final ProjectProperties properties, final boolean usedConcurren
return snapshot.getCommonTasks();
}
}));
+ setters.add(newPropertySetter(properties.getScriptPlatform(), new PropertyGetter<JavaPlatform>() {
+ @Override
+ public PropertySource<JavaPlatform> get(PropertiesSnapshot snapshot) {
+ return snapshot.getScriptPlatform();
+ }
+ }));
+ setters.add(newPropertySetter(properties.getGradleHome(), new PropertyGetter<File>() {
+ @Override
+ public PropertySource<File> get(PropertiesSnapshot snapshot) {
+ return snapshot.getGradleHome();
+ }
+ }));
for (final String command: AbstractProjectProperties.getCustomizableCommands()) {
MutableProperty<PredefinedTask> taskProperty = properties.tryGetBuiltInTask(command);
if (taskProperty == null) {
@@ -47,6 +47,10 @@
private static final String PLATFORM_NODE = "target-platform";
private static final String SOURCE_LEVEL_NODE = "source-level";
private static final String COMMON_TASKS_NODE = "common-tasks";
+ private static final String SCRIPT_PLATFORM_NODE = "script-platform";
+ private static final String GENERIC_PLATFORM_NAME_NODE = "spec-name";
+ private static final String GENERIC_PLATFORM_VERSION_NODE = "spec-version";
+ private static final String GRADLE_HOME_NODE = "gradle-home";
private static final String BUILT_IN_TASKS_NODE = "built-in-tasks";
private static final String TASK_DISPLAY_NAME_NODE = "display-name";
private static final String TASK_NON_BLOCKING_NODE = "non-blocking";
@@ -140,6 +144,13 @@ private static void addBuiltInTasks(Node node, PropertiesSnapshot snapshot) {
}
}
+ private static void addGenericPlatform(Node node, String nodeName, JavaPlatform platform) {
+ Element platformNode = addChild(node, nodeName);
+
+ addSimpleChild(platformNode, GENERIC_PLATFORM_NAME_NODE, platform.getSpecification().getName());
+ addSimpleChild(platformNode, GENERIC_PLATFORM_VERSION_NODE, platform.getSpecification().getVersion().toString());
+ }
+
public static void saveToXml(File propertyfile, PropertiesSnapshot snapshot) {
if (propertyfile == null) throw new NullPointerException("propertyfile");
if (snapshot == null) throw new NullPointerException("snapshot");
@@ -184,6 +195,18 @@ public static void saveToXml(File propertyfile, PropertiesSnapshot snapshot) {
}
}
+ if (!snapshot.getScriptPlatform().isDefault()) {
+ JavaPlatform scriptPlatform = snapshot.getScriptPlatform().getValue();
+ addGenericPlatform(root, SCRIPT_PLATFORM_NODE, scriptPlatform);
+ }
+
+ if (!snapshot.getGradleHome().isDefault()) {
+ File gradleHome = snapshot.getGradleHome().getValue();
+ if (gradleHome != null) {
+ addSimpleChild(root, GRADLE_HOME_NODE, gradleHome.getPath());
+ }
+ }
+
addBuiltInTasks(root, snapshot);
try {
@@ -306,6 +329,24 @@ private static PredefinedTask readTask(Element root) {
return readTasks(BUILT_IN_TASKS_NODE, root);
}
+ private static PropertySource<JavaPlatform> readPlatform(Element root, String nodeName) {
+ Element platformNode = getFirstChildByTagName(root, nodeName);
+ if (platformNode == null) {
+ return null;
+ }
+
+ String platformName = tryGetValueOfNode(platformNode, GENERIC_PLATFORM_NAME_NODE);
+ if (platformName == null) {
+ platformName = DEFAULT_SPECIFICATION_NAME;
+ }
+
+ String versionStr = tryGetValueOfNode(platformNode, GENERIC_PLATFORM_VERSION_NODE);
+ if (versionStr != null) {
+ return DefaultPropertySources.findPlatformSource(platformName, versionStr, false);
+ }
+ return null;
+ }
+
public static PropertiesSnapshot readFromXml(File propertiesFile) {
PropertiesSnapshot.Builder result = new PropertiesSnapshot.Builder();
@@ -357,6 +398,17 @@ public static PropertiesSnapshot readFromXml(File propertiesFile) {
result.setPlatform(DefaultPropertySources.findPlatformSource(platformName, platformStr, false));
}
+ String gradleHomeStr = tryGetValueOfNode(root, GRADLE_HOME_NODE);
+ if (gradleHomeStr != null) {
+ File gradleHome = !gradleHomeStr.isEmpty() ? new File(gradleHomeStr.trim()) : null;
+ result.setGradleHome(asConst(gradleHome, false));
+ }
+
+ PropertySource<JavaPlatform> scriptPlatform = readPlatform(root, SCRIPT_PLATFORM_NODE);
+ if (scriptPlatform != null) {
+ result.setScriptPlatform(scriptPlatform);
+ }
+
List<PredefinedTask> commonTasks = Collections.unmodifiableList(readCommonTasks(root));
result.setCommonTasks(asConst(commonTasks, commonTasks.isEmpty()));
@@ -61,6 +61,8 @@ public static String getSourceLevelFromPlatform(JavaPlatform platform) {
result.add(getSourceEncoding());
result.add(getSourceLevel());
result.add(getCommonTasks());
+ result.add(getScriptPlatform());
+ result.add(getGradleHome());
for (String command: CUSTOMIZABLE_TASKS) {
MutableProperty<PredefinedTask> task = tryGetBuiltInTask(command);
@@ -31,3 +31,8 @@ AddNewProfilePanel.jProfileEdit.text=
ManageBuiltInTasksPanel.jInheritCheck.text=Inherit
ProjectPropertiesPanel.jManageBuiltInTasks.text=Manage Built-In Tasks
GradleSettingsPanel.jDontAddInitScriptCheck.text=Don't add tasks to build scripts automatically (e.g.: run)
+ProjectPropertiesPanel.jGradleHomeCaption.text=Gradle home (leave empty to autodetect from the Gradle wrapper):
+ProjectPropertiesPanel.jGradleHomeEdit.text=
+ProjectPropertiesPanel.jGradleHomeInherit.text=Inherit
+ProjectPropertiesPanel.jScriptPlatformCaption.text=Platform for build scripts:
+ProjectPropertiesPanel.jScriptPlatformInherit.text=Inherit
@@ -1,5 +1,6 @@
package org.netbeans.gradle.project.properties;
+import java.io.File;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
@@ -17,6 +18,8 @@
private final MutableProperty<String> sourceLevel;
private final MutableProperty<JavaPlatform> platform;
+ private final MutableProperty<JavaPlatform> scriptPlatform;
+ private final MutableProperty<File> gradleHome;
private final MutableProperty<Charset> sourceEncoding;
private final MutableProperty<List<PredefinedTask>> commonTasks;
@@ -35,6 +38,14 @@ public FallbackProjectProperties(ProjectProperties mainProperties, ProjectProper
mainProperties.getPlatform(),
defaultProperties.getPlatform());
+ this.scriptPlatform = new FallbackProperty<JavaPlatform>(
+ mainProperties.getScriptPlatform(),
+ defaultProperties.getScriptPlatform());
+
+ this.gradleHome = new FallbackProperty<File>(
+ mainProperties.getGradleHome(),
+ defaultProperties.getGradleHome());
+
this.sourceEncoding = new FallbackProperty<Charset>(
mainProperties.getSourceEncoding(),
defaultProperties.getSourceEncoding());
@@ -64,6 +75,16 @@ public FallbackProjectProperties(ProjectProperties mainProperties, ProjectProper
return commonTasks;
}
+ @Override
+ public MutableProperty<JavaPlatform> getScriptPlatform() {
+ return scriptPlatform;
+ }
+
+ @Override
+ public MutableProperty<File> getGradleHome() {
+ return gradleHome;
+ }
+
@Override
public MutableProperty<PredefinedTask> tryGetBuiltInTask(String command) {
MutableProperty<PredefinedTask> mainProperty = mainProperties.tryGetBuiltInTask(command);
@@ -1,5 +1,6 @@
package org.netbeans.gradle.project.properties;
+import java.io.File;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.HashMap;
@@ -12,6 +13,8 @@
public final class MemProjectProperties extends AbstractProjectProperties {
private final MutableProperty<String> sourceLevel;
private final MutableProperty<JavaPlatform> platform;
+ private final MutableProperty<JavaPlatform> scriptPlatform;
+ private final MutableProperty<File> gradleHome;
private final MutableProperty<Charset> sourceEncoding;
private final MutableProperty<List<PredefinedTask>> commonTasks;
private final Map<String, MutableProperty<PredefinedTask>> builtInTasks;
@@ -20,6 +23,8 @@ public MemProjectProperties() {
JavaPlatform defaultPlatform = JavaPlatform.getDefault();
this.sourceLevel = new DefaultMutableProperty<String>(getSourceLevelFromPlatform(defaultPlatform), true, false);
this.platform = new DefaultMutableProperty<JavaPlatform>(defaultPlatform, true, false);
+ this.scriptPlatform = new DefaultMutableProperty<JavaPlatform>(defaultPlatform, true, false);
+ this.gradleHome = new DefaultMutableProperty<File>(null, true, true);
this.sourceEncoding = new DefaultMutableProperty<Charset>(DEFAULT_SOURCE_ENCODING, true, false);
this.commonTasks = new MutableListProperty<PredefinedTask>(Collections.<PredefinedTask>emptyList(), true);
@@ -42,6 +47,16 @@ public MemProjectProperties() {
return platform;
}
+ @Override
+ public MutableProperty<JavaPlatform> getScriptPlatform() {
+ return scriptPlatform;
+ }
+
+ @Override
+ public MutableProperty<File> getGradleHome() {
+ return gradleHome;
+ }
+
@Override
public MutableProperty<Charset> getSourceEncoding() {
return sourceEncoding;
@@ -1,5 +1,6 @@
package org.netbeans.gradle.project.properties;
+import java.io.File;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.List;
@@ -20,6 +21,8 @@
public MutableProperty<String> getSourceLevel();
public MutableProperty<JavaPlatform> getPlatform();
+ public MutableProperty<JavaPlatform> getScriptPlatform();
+ public MutableProperty<File> getGradleHome();
public MutableProperty<Charset> getSourceEncoding();
public MutableProperty<List<PredefinedTask>> getCommonTasks();
@@ -19,19 +19,6 @@
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
- <Group type="102" alignment="1" attributes="0">
- <Group type="103" groupAlignment="1" attributes="0">
- <Component id="jSourceLevelCombo" alignment="0" max="32767" attributes="0"/>
- <Component id="jPlatformCombo" alignment="0" max="32767" attributes="0"/>
- <Component id="jSourceEncoding" alignment="0" max="32767" attributes="0"/>
- </Group>
- <EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
- <Group type="103" groupAlignment="0" attributes="0">
- <Component id="jSourceEncodingInherit" alignment="1" min="-2" max="-2" attributes="0"/>
- <Component id="jPlatformComboInherit" alignment="1" min="-2" max="-2" attributes="0"/>
- <Component id="jSourceLevelComboInherit" alignment="1" min="-2" max="-2" attributes="0"/>
- </Group>
- </Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jProfileCaption" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
@@ -51,9 +38,28 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="jManageBuiltInTasks" min="-2" max="-2" attributes="0"/>
</Group>
+ <Component id="jGradleHomeCaption" alignment="0" min="-2" max="-2" attributes="0"/>
+ <Component id="jScriptPlatformCaption" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
+ <Group type="102" alignment="1" attributes="0">
+ <Group type="103" groupAlignment="1" attributes="0">
+ <Component id="jScriptPlatformCombo" max="32767" attributes="0"/>
+ <Component id="jGradleHomeEdit" max="32767" attributes="0"/>
+ <Component id="jSourceLevelCombo" alignment="0" max="32767" attributes="0"/>
+ <Component id="jPlatformCombo" alignment="0" max="32767" attributes="0"/>
+ <Component id="jSourceEncoding" alignment="0" max="32767" attributes="0"/>
+ </Group>
+ <EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
+ <Group type="103" groupAlignment="0" max="-2" attributes="0">
+ <Component id="jSourceEncodingInherit" alignment="1" max="32767" attributes="0"/>
+ <Component id="jGradleHomeInherit" alignment="1" max="32767" attributes="0"/>
+ <Component id="jScriptPlatformInherit" alignment="1" max="32767" attributes="0"/>
+ <Component id="jPlatformComboInherit" alignment="1" max="32767" attributes="0"/>
+ <Component id="jSourceLevelComboInherit" alignment="1" max="32767" attributes="0"/>
+ </Group>
+ </Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@@ -69,14 +75,28 @@
<Component id="jAddProfileButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jRemoveProfileButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
- <EmptySpace pref="13" max="32767" attributes="0"/>
+ <EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="jSourceEncodingCaption" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jSourceEncoding" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jSourceEncodingInherit" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
+ <Component id="jGradleHomeCaption" min="-2" pref="14" max="-2" attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
+ <Group type="103" groupAlignment="3" attributes="0">
+ <Component id="jGradleHomeEdit" alignment="3" min="-2" max="-2" attributes="0"/>
+ <Component id="jGradleHomeInherit" alignment="3" min="-2" max="-2" attributes="0"/>
+ </Group>
+ <EmptySpace type="unrelated" max="-2" attributes="0"/>
+ <Component id="jScriptPlatformCaption" min="-2" max="-2" attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
+ <Group type="103" groupAlignment="3" attributes="0">
+ <Component id="jScriptPlatformCombo" alignment="3" min="-2" max="-2" attributes="0"/>
+ <Component id="jScriptPlatformInherit" alignment="3" min="-2" max="-2" attributes="0"/>
+ </Group>
+ <EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jPlatformCaption" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
@@ -90,11 +110,12 @@
<Component id="jSourceLevelCombo" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jSourceLevelComboInherit" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
- <EmptySpace min="-2" pref="9" max="-2" attributes="0"/>
+ <EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jManageTasksButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jManageBuiltInTasks" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
+ <EmptySpace min="0" pref="8" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@@ -224,5 +245,47 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jManageBuiltInTasksActionPerformed"/>
</Events>
</Component>
+ <Component class="javax.swing.JLabel" name="jGradleHomeCaption">
+ <Properties>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/netbeans/gradle/project/properties/Bundle.properties" key="ProjectPropertiesPanel.jGradleHomeCaption.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+ </Property>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JTextField" name="jGradleHomeEdit">
+ <Properties>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/netbeans/gradle/project/properties/Bundle.properties" key="ProjectPropertiesPanel.jGradleHomeEdit.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+ </Property>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JCheckBox" name="jGradleHomeInherit">
+ <Properties>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/netbeans/gradle/project/properties/Bundle.properties" key="ProjectPropertiesPanel.jGradleHomeInherit.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+ </Property>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JLabel" name="jScriptPlatformCaption">
+ <Properties>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/netbeans/gradle/project/properties/Bundle.properties" key="ProjectPropertiesPanel.jScriptPlatformCaption.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+ </Property>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JComboBox" name="jScriptPlatformCombo">
+ <Properties>
+ <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
+ <StringArray count="0"/>
+ </Property>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JCheckBox" name="jScriptPlatformInherit">
+ <Properties>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="org/netbeans/gradle/project/properties/Bundle.properties" key="ProjectPropertiesPanel.jScriptPlatformInherit.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+ </Property>
+ </Properties>
+ </Component>
</SubComponents>
</Form>
Oops, something went wrong.

0 comments on commit d0adbd0

Please sign in to comment.