This is an automated email from the ASF dual-hosted git repository. lkishalmi pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new 051f55d21b Gradle Execution Customizer with Runtime (#5158) 051f55d21b is described below commit 051f55d21ba2edba562787482beaaa5b6a29b3d3 Author: Laszlo Kishalmi <laszlo.kisha...@gmail.com> AuthorDate: Sun Jan 15 14:02:52 2023 -0800 Gradle Execution Customizer with Runtime (#5158) * Moved Gradle Java Runtime Selection into Gradle Projects * GradleJavaPlatformProviderImpl uses the JavaRuntimeManager now. * Moved GradleJavaProjectProblemProvider to Gradle Project * Added change aware bridge between JavaRuntime and JavaPlatform * Removed unloadable project warning from customizer, other fixes * Polishing the code according suggestions. * Adjusted Bundle.properties for the customizers. * Added API documentation. * Mage JavaRuntime on top of Gradle Execution Customizer --- extide/gradle/apichanges.xml | 25 ++ extide/gradle/manifest.mf | 4 +- .../gradle/GradleBrokenRuntimeProblemProvider.java | 24 +- .../gradle/GradleJavaCompatProblemsProvider.java | 2 +- .../modules/gradle/api/execute/RunUtils.java | 64 +++- .../modules/gradle/customizer/Bundle.properties | 28 +- .../customizer/GradleCustomizerProvider.java | 23 +- .../gradle/customizer/GradleExecutionPanel.form | 147 +++++++- .../gradle/customizer/GradleExecutionPanel.java | 378 ++++++++++++++++---- .../gradle/execute/DefaultJavaRuntimeManager.java | 54 +++ .../execute/GradleJavaPlatformProviderImpl.java | 23 +- .../gradle/spi/execute/JavaRuntimeManager.java | 176 +++++++++ .../gradle/java/JavaRuntimePlatformBridge.java | 100 ++++++ .../modules/gradle/java/LookupProviders.java | 1 - .../gradle/java/customizer/Bundle.properties | 6 - .../java/customizer/CompileOptionsPanel.form | 156 -------- .../java/customizer/CompileOptionsPanel.java | 394 --------------------- .../modules/gradle/java/execute/JavaRunUtils.java | 40 +-- .../gradle/java/execute/LookupProviders.java | 11 - 19 files changed, 927 insertions(+), 729 deletions(-) diff --git a/extide/gradle/apichanges.xml b/extide/gradle/apichanges.xml index 2c6e7e1fb9..87efe7764f 100644 --- a/extide/gradle/apichanges.xml +++ b/extide/gradle/apichanges.xml @@ -83,6 +83,31 @@ is the proper place. <!-- ACTUAL CHANGES BEGIN HERE: --> <changes> + <change id="java-runtime-manager"> + <api name="general"/> + <summary>Adding JavaRuntimeManager abstracting the Gradle Runtime from Java Platform</summary> + <version major="2" minor="32"/> + <date day="13" month="1" year="2023"/> + <author login="lkishalmi"/> + <compatibility semantic="compatible" addition="yes"/> + <description> + <p> + Introduced a <code><a href="@TOP@/org/netbeans/modules/gradle/spi/execute/JavaRuntimeManager.html">JavaRuntimeManager</a></code> to + create abstraction between the necessary runtime that Gradle needs (just a Java home) and the actual JavaPlatform which is provided by + the modules in the Java cluster. + </p> + <p> + JavaRuntime is bound to be the root project of a project tree from now. The ID of the active rintime is stored in the <code>gradle.properties</code> + of the root project under the property name <code>netbeans.hint.jdkPlatform</code>. + </p> + <p> + There are two new methods provided in <code><a href="@TOP@/org/netbeans/modules/gradle/api/execute/RunUtils.html">RunUtils</a></code> to get and set the + active runtime of a project. + </p> + </description> + <class package="org.netbeans.modules.gradle.spi.execute" name="JavaRuntimeManager"/> + <class package="org.netbeans.modules.gradle.api.execute" name="RunUtils"/> + </change> <change id="external-tasks"> <api name="general"/> <summary>Representing external tasks</summary> diff --git a/extide/gradle/manifest.mf b/extide/gradle/manifest.mf index 03eafb6fbd..0f214efc51 100644 --- a/extide/gradle/manifest.mf +++ b/extide/gradle/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 -AutoUpdate-Show-In-Client: false +AutoUpdate-Show-In-Client: true OpenIDE-Module: org.netbeans.modules.gradle/2 OpenIDE-Module-Layer: org/netbeans/modules/gradle/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/gradle/Bundle.properties -OpenIDE-Module-Specification-Version: 2.31 +OpenIDE-Module-Specification-Version: 2.32 diff --git a/java/gradle.java/src/org/netbeans/modules/gradle/java/GradleJavaProjectProblemProvider.java b/extide/gradle/src/org/netbeans/modules/gradle/GradleBrokenRuntimeProblemProvider.java similarity index 73% rename from java/gradle.java/src/org/netbeans/modules/gradle/java/GradleJavaProjectProblemProvider.java rename to extide/gradle/src/org/netbeans/modules/gradle/GradleBrokenRuntimeProblemProvider.java index 231a00a875..3a993f59c1 100644 --- a/java/gradle.java/src/org/netbeans/modules/gradle/java/GradleJavaProjectProblemProvider.java +++ b/extide/gradle/src/org/netbeans/modules/gradle/GradleBrokenRuntimeProblemProvider.java @@ -16,17 +16,17 @@ * specific language governing permissions and limitations * under the License. */ -package org.netbeans.modules.gradle.java; +package org.netbeans.modules.gradle; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; +import java.util.Collections; import org.netbeans.api.project.Project; import org.netbeans.modules.gradle.api.NbGradleProject; -import org.netbeans.modules.gradle.java.execute.JavaRunUtils; +import org.netbeans.modules.gradle.api.execute.RunUtils; +import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.ui.ProjectProblemsProvider; import static org.netbeans.spi.project.ui.ProjectProblemsProvider.PROP_PROBLEMS; import org.openide.util.NbBundle; @@ -35,12 +35,13 @@ import org.openide.util.NbBundle; * * @author lkishalmi */ -public class GradleJavaProjectProblemProvider implements ProjectProblemsProvider { +@ProjectServiceProvider(service = ProjectProblemsProvider.class, projectType = NbGradleProject.GRADLE_PROJECT_TYPE) +public class GradleBrokenRuntimeProblemProvider implements ProjectProblemsProvider { private final Project project; private final PropertyChangeListener listener; private final PropertyChangeSupport support = new PropertyChangeSupport(this); - public GradleJavaProjectProblemProvider(Project project) { + public GradleBrokenRuntimeProblemProvider(Project project) { this.project = project; listener = (PropertyChangeEvent evt) -> { if (NbGradleProject.PROP_PROJECT_INFO.equals(evt.getPropertyName())) { @@ -54,12 +55,10 @@ public class GradleJavaProjectProblemProvider implements ProjectProblemsProvider @NbBundle.Messages({ "LBL_BrokenPlatform=Broken Platform.", }) - public Collection<? extends ProjectProblem> getProblems() { - List<ProjectProblem> ret = new ArrayList<>(); - if (JavaRunUtils.getActivePlatform(project) == null) { - ret.add(ProjectProblem.createWarning(Bundle.LBL_BrokenPlatform(), Bundle.LBL_BrokenPlatform())); - } - return ret; + public Collection<? extends ProjectProblemsProvider.ProjectProblem> getProblems() { + return RunUtils.getActiveRuntime(project).isBroken() + ? Collections.singleton(ProjectProblemsProvider.ProjectProblem.createWarning(Bundle.LBL_BrokenPlatform(), Bundle.LBL_BrokenPlatform())) + : Collections.emptySet(); } @Override @@ -71,4 +70,5 @@ public class GradleJavaProjectProblemProvider implements ProjectProblemsProvider public void removePropertyChangeListener(PropertyChangeListener listener) { support.removePropertyChangeListener(listener); } + } diff --git a/extide/gradle/src/org/netbeans/modules/gradle/GradleJavaCompatProblemsProvider.java b/extide/gradle/src/org/netbeans/modules/gradle/GradleJavaCompatProblemsProvider.java index e62a85e2aa..b1108a875b 100644 --- a/extide/gradle/src/org/netbeans/modules/gradle/GradleJavaCompatProblemsProvider.java +++ b/extide/gradle/src/org/netbeans/modules/gradle/GradleJavaCompatProblemsProvider.java @@ -82,7 +82,7 @@ public final class GradleJavaCompatProblemsProvider implements ProjectProblemsPr + "The IDE will attempt to use Gradle {3} to gather the project information.<p>" + "Possible solutions:" + "<ul><li>Upgrade your Gradle version on your project" - + "<li>Select Java Platform {1} (or below), on Build > Compile settings, to avoid this problem!" + + "<li>Select Java Runtime {1} (or below), on Build > Gradle Execution settings, to avoid this problem!" + "</ul>" }) @Override diff --git a/extide/gradle/src/org/netbeans/modules/gradle/api/execute/RunUtils.java b/extide/gradle/src/org/netbeans/modules/gradle/api/execute/RunUtils.java index 1b0522f1d2..865805c121 100644 --- a/extide/gradle/src/org/netbeans/modules/gradle/api/execute/RunUtils.java +++ b/extide/gradle/src/org/netbeans/modules/gradle/api/execute/RunUtils.java @@ -55,21 +55,24 @@ import java.util.MissingResourceException; import java.util.Set; import java.util.WeakHashMap; import java.util.function.Function; -import org.gradle.util.GradleVersion; import org.netbeans.api.project.ProjectInformation; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.project.ui.OpenProjects; -import org.netbeans.modules.gradle.NbGradleProjectImpl; import org.netbeans.modules.gradle.ProjectTrust; import org.netbeans.modules.gradle.actions.ActionToTaskUtils; import org.netbeans.modules.gradle.api.execute.GradleDistributionManager.GradleDistribution; import org.netbeans.modules.gradle.api.execute.RunConfig.ExecFlag; +import static org.netbeans.modules.gradle.customizer.GradleExecutionPanel.HINT_JDK_PLATFORM; import org.netbeans.modules.gradle.execute.ConfigurableActionProvider; import org.netbeans.modules.gradle.spi.GradleSettings; import org.netbeans.modules.gradle.execute.ProjectConfigurationSupport; -import org.netbeans.modules.gradle.spi.actions.BeforeBuildActionHook; import org.netbeans.modules.gradle.spi.actions.ProjectActionMappingProvider; import org.netbeans.modules.gradle.spi.execute.GradleDistributionProvider; +import org.netbeans.modules.gradle.spi.execute.JavaRuntimeManager; +import org.netbeans.modules.gradle.spi.execute.JavaRuntimeManager.JavaRuntime; +import org.netbeans.spi.project.AuxiliaryProperties; import org.netbeans.spi.project.ProjectConfiguration; import org.netbeans.spi.project.SingleMethod; import org.openide.DialogDescriptor; @@ -558,13 +561,14 @@ public final class RunUtils { } private static boolean isOptionEnabled(Project project, String option, boolean defaultValue) { - GradleBaseProject gbp = GradleBaseProject.get(project); + Project root = ProjectUtils.rootOf(project); + GradleBaseProject gbp = GradleBaseProject.get(root); if (gbp != null) { String value = gbp.getNetBeansProperty(option); if (value != null) { return Boolean.valueOf(value); } else { - return NbGradleProject.getPreferences(project, false).getBoolean(option, defaultValue); + return NbGradleProject.getPreferences(root, false).getBoolean(option, defaultValue); } } return false; @@ -672,6 +676,56 @@ public final class RunUtils { return getActivePlatform("deprecated"); //NOI18N } + /** + * Return the current active JavaRuntime used by the specified project. + * JavaRuntime is defined in the root project level. If there is no + * runtime specified on the root project, then this method would return the + * default runtime. Usually the one, which is used by the IDE. + * <p> + * It is possible that the ID representing the project runtime, has no + * associated runtime in the IDE. In this case a broken JavaRuntime would be + * returned with the ID, that would be used. + * + * @param project the project which root project specifies the runtime. + * @return the JavaRuntime to be used by the project, could be broken, but + * not {@code null} + * + * @since 2.32 + */ + public static JavaRuntime getActiveRuntime(Project project) { + return ProjectManager.mutex().readAccess(() -> { + Project root = ProjectUtils.rootOf(project); + AuxiliaryProperties aux = root.getLookup().lookup(AuxiliaryProperties.class); + String id = aux.get(HINT_JDK_PLATFORM, true); + id = id != null ? id : JavaRuntimeManager.DEFAULT_RUNTIME_ID; + + JavaRuntimeManager mgr = Lookup.getDefault().lookup(JavaRuntimeManager.class); + Map<String, JavaRuntime> runtimes = mgr.getAvailableRuntimes(); + if (runtimes.containsKey(id)) { + return runtimes.get(id); + } + return JavaRuntimeManager.createJavaRuntime(id, null); + }); + } + + /** + * Sets the active JavaRuntime on the specified project root. + * + * @param project the project , which root project shall be set the runtime on + * @param runtime The JavaRuntime to activate on the project or {@code null} + * can be used to set the default runtime. + * + * @since 2.32 + */ + public static void setActiveRuntime(Project project, JavaRuntime runtime) { + ProjectManager.mutex().postWriteRequest(() -> { + Project root = ProjectUtils.rootOf(project); + AuxiliaryProperties aux = root.getLookup().lookup(AuxiliaryProperties.class); + String id = (runtime != null) && !JavaRuntimeManager.DEFAULT_RUNTIME_ID.equals(runtime.getId()) ? runtime.getId() : null; + aux.put(HINT_JDK_PLATFORM, id, true); + }); + } + static GradleCommandLine getIncludedOpenProjects(Project project) { GradleCommandLine ret = new GradleCommandLine(); Set<File> openRoots = new HashSet<>(); diff --git a/extide/gradle/src/org/netbeans/modules/gradle/customizer/Bundle.properties b/extide/gradle/src/org/netbeans/modules/gradle/customizer/Bundle.properties index b621797e4c..57af8d43f0 100644 --- a/extide/gradle/src/org/netbeans/modules/gradle/customizer/Bundle.properties +++ b/extide/gradle/src/org/netbeans/modules/gradle/customizer/Bundle.properties @@ -27,6 +27,7 @@ ProjectInfoPanel.tfGroup.text= ProjectInfoPanel.tfVersion.text= ProjectInfoPanel.jLabel4.text=Parent Project: ProjectInfoPanel.jLabel5.text=Plugins: + BuildActionsCustomizer.lbActions.text=Configured Actions: BuildActionsCustomizer.lbNoAction.text=No Selected Action BuildActionsCustomizer.lbName.text=&Name: @@ -36,21 +37,32 @@ BuildActionsCustomizer.btRemove.text=Re&set BuildActionsCustomizer.lbReloadRule.text=&Project Reload: BuildActionsCustomizer.cbRepeatable.text=&Repeatable BuildActionsCustomizer.lbTitle.text=Override IDE Default Action Binding and Custom Actions +BuildActionsCustomizer.jLabel1.text=Configure &Action: +BuildActionsCustomizer.cbRepeatable.toolTipText=Is this action allowed to be rerun from the output tab? +BuildActionsCustomizer.lbReloadHints.text=<html>Reload Project after this action:\n<ul>\n<li><b>NEVER:</b> Do not reload.</li>\n<li><b>DEFAULT:</b> Reload only if the project had some problems.</li>\n<li><b>ALWAYS:</b> Always reload the project.</li>\n<li><b>ALWAYS_ONLINE:</b> Always reload the project, allowing Gradle to go online.</li>\n</ul> +BuildActionsCustomizer.lbConfiguration.text=Override in Configuration: +BuildActionsCustomizer.btnDisableAction.text=&Disable +BuildActionsCustomizer.jLabel2.text=The action is disabled in this configuration. +BuildActionsCustomizer.btnRestore.text=&Restore +BuildActionsCustomizer.btnRemove2.text=Re&set + LicenseHeadersPanel.jLabel1.text=License Header LicenseHeadersPanel.rbGlobalLicense.text=Use Global License: LicenseHeadersPanel.rbCustomFile.text=Use Gradle Defined License: LicenseHeadersPanel.jLabel2.text=<html>Use the value of <b>netbeans.license</b> or in its absence <b>license</b>\nproperty of the project (or its parent). It is recommended to set this property on the\nroot project only. The value of the license property can be:\n<ul>\n <li>Short name of a NetBeans Global license<br/>(e.g.: apache20)</li>\n <li>Project directory relative path to a file.</li>\n <li>Root project directory relative path to a file.</li>\n <li>Absolute path to a file.</li [...] -BuildActionsCustomizer.jLabel1.text=Configure &Action: ProjectInfoPanel.jLabel6.text=Included Builds: -BuildActionsCustomizer.cbRepeatable.toolTipText=Is this action allowed to be rerun from the output tab? -BuildActionsCustomizer.lbReloadHints.text=<html>Reload Project after this action:\n<ul>\n<li><b>NEVER:</b> Do not reload.</li>\n<li><b>DEFAULT:</b> Reload only if the project had some problems.</li>\n<li><b>ALWAYS:</b> Always reload the project.</li>\n<li><b>ALWAYS_ONLINE:</b> Always reload the project, allowing Gradle to go online.</li>\n</ul> + + GradleExecutionPanel.lbReadOnly.text=Can be changed on the root project only. GradleExecutionPanel.lbTrustLevel.text=Trust level: GradleExecutionPanel.cbTrustLevel.NONE=Do not trust GradleExecutionPanel.cbTrustLevel.TEMPORARY=Trust just now GradleExecutionPanel.cbTrustLevel.PERMANENT=Trust permanently -BuildActionsCustomizer.lbConfiguration.text=Override in Configuration: -BuildActionsCustomizer.btnDisableAction.text=&Disable -BuildActionsCustomizer.jLabel2.text=The action is disabled in this configuration. -BuildActionsCustomizer.btnRestore.text=&Restore -BuildActionsCustomizer.btnRemove2.text=Re&set +GradleExecutionPanel.cbAugmentedBuild.text=&Augmented Build Execution +GradleExecutionPanel.lbIncludeOpenProjects.text=<html>Create a composite project from this project and the other open Gradle projects by generating '--include-build' parameters. +GradleExecutionPanel.cbIncludeOpenProjects.text=Include Open Projects +GradleExecutionPanel.lbTrustTerms.text=<html><p>Executing Gradle can be potentially un-safe as it allows arbitrary code execution.</p>\n<p/>\n<p>By trusting this project, and with that all its subprojects, you entitle NetBeans to invoke Gradle to load project details without further confirmation.</p><p></p><p>Invoking any build related actions, would mark this project automatically trusted.</p> +GradleExecutionPanel.lbAugmentedBuild.text=<html>Allow NetBeans to make on-the-fly changes to the Gradle build process. This way a few useful IDE actions/options can be enabled without actually changing the build files. +GradleExecutionPanel.lbRuntime.text=Java &Runtime: +GradleExecutionPanel.btManageRuntimes.text=Manage Runtimes... +GradleExecutionPanel.btManageRuntimes.actionCommand= diff --git a/extide/gradle/src/org/netbeans/modules/gradle/customizer/GradleCustomizerProvider.java b/extide/gradle/src/org/netbeans/modules/gradle/customizer/GradleCustomizerProvider.java index 5c1a0a491e..4091f4455b 100644 --- a/extide/gradle/src/org/netbeans/modules/gradle/customizer/GradleCustomizerProvider.java +++ b/extide/gradle/src/org/netbeans/modules/gradle/customizer/GradleCustomizerProvider.java @@ -25,8 +25,6 @@ import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.ui.support.ProjectCustomizer; import org.netbeans.spi.project.ui.CustomizerProvider; import org.netbeans.spi.project.ui.CustomizerProvider2; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; import org.openide.util.NbBundle; import static org.netbeans.modules.gradle.customizer.Bundle.*; @@ -63,19 +61,15 @@ public class GradleCustomizerProvider implements CustomizerProvider2 { @NbBundle.Messages({ "# {0} - project display name", "TIT_Project_Properties=Project Properties - {0}", - "TXT_Unloadable=Project is unloadable, the project information is unreliable. Show Project Properties dialog?", - "TIT_Unloadable=Project Unloadable" + "# {0} - project display name", + "TIT_Unloadable_Project_Properties=Project Properties - {0} (Unloadable)", }) @Override public void showCustomizer(final String preselectedCategory, final String preselectedSubCategory) { - if (NbGradleProject.get(project).isUnloadable()) { - NotifyDescriptor.Confirmation nd = new NotifyDescriptor.Confirmation(TXT_Unloadable(), TIT_Unloadable()); - nd.setOptionType(NotifyDescriptor.YES_NO_OPTION); - if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.NO_OPTION) { - return; - } - } -// try { + String displayName = ProjectUtils.getInformation(project).getDisplayName(); + String title = NbGradleProject.get(project).isUnloadable() + ? TIT_Unloadable_Project_Properties(displayName) + : TIT_Project_Properties(displayName); Mutex.EVENT.readAccess(() -> { assert EventQueue.isDispatchThread(); Lookup context = Lookups.singleton(project); @@ -85,13 +79,10 @@ public class GradleCustomizerProvider implements CustomizerProvider2 { (ActionEvent ae) -> {/*noop*/}, null, HELP_CTX); - dialog.setTitle(TIT_Project_Properties(ProjectUtils.getInformation(project).getDisplayName())); + dialog.setTitle(title); dialog.setModal(true); dialog.setVisible(true); }); -// } catch (Exception ex) { -// Logger.getLogger(GradleCustomizerProvider.class.getName()).log(Level.SEVERE, "Cannot show project customizer", ex); -// } } @Override diff --git a/extide/gradle/src/org/netbeans/modules/gradle/customizer/GradleExecutionPanel.form b/extide/gradle/src/org/netbeans/modules/gradle/customizer/GradleExecutionPanel.form index 03853d6d46..4677f36c89 100644 --- a/extide/gradle/src/org/netbeans/modules/gradle/customizer/GradleExecutionPanel.form +++ b/extide/gradle/src/org/netbeans/modules/gradle/customizer/GradleExecutionPanel.form @@ -38,39 +38,79 @@ <DimensionLayout dim="0"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" attributes="0"> - <EmptySpace min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" attributes="0"> + <EmptySpace min="6" pref="6" max="-2" attributes="0"/> <Component id="lbReadOnly" min="-2" max="-2" attributes="0"/> - <EmptySpace min="0" pref="0" max="32767" attributes="0"/> </Group> <Group type="102" alignment="0" attributes="0"> + <EmptySpace max="-2" attributes="0"/> + <Component id="lbTrustLevel" min="-2" pref="99" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Component id="cbTrustLevel" linkSize="4" min="-2" pref="265" max="-2" attributes="0"/> + </Group> + </Group> + <EmptySpace pref="317" max="32767" attributes="0"/> + </Group> + <Group type="102" alignment="0" attributes="0"> + <EmptySpace max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> <EmptySpace min="21" pref="21" max="-2" attributes="0"/> + <Component id="lbIncludeOpenProjects" pref="0" max="32767" attributes="0"/> + </Group> + <Group type="102" attributes="0"> + <Component id="lbRuntime" min="-2" pref="99" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Component id="cbRuntime" linkSize="4" min="-2" pref="265" max="-2" attributes="0"/> + <EmptySpace type="unrelated" max="-2" attributes="0"/> + <Component id="btManageRuntimes" min="-2" max="-2" attributes="0"/> + <EmptySpace min="0" pref="0" max="32767" attributes="0"/> + </Group> + <Group type="102" attributes="0"> <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" attributes="0"> - <Component id="lbTrustLevel" min="-2" max="-2" attributes="0"/> - <EmptySpace type="unrelated" max="-2" attributes="0"/> - <Component id="cbTrustLevel" max="32767" attributes="0"/> + <Component id="cbIncludeOpenProjects" max="32767" attributes="0"/> + <Group type="102" alignment="1" attributes="0"> + <EmptySpace min="21" pref="21" max="-2" attributes="0"/> + <Component id="lbAugmentedBuild" pref="0" max="32767" attributes="0"/> </Group> - <Component id="lbTrustTerms" max="32767" attributes="0"/> + <Component id="cbAugmentedBuild" alignment="0" max="32767" attributes="0"/> + <Component id="jSeparator1" alignment="0" max="32767" attributes="0"/> + <Component id="lbTrustTerms" alignment="1" pref="0" max="32767" attributes="0"/> </Group> + <EmptySpace max="-2" attributes="0"/> </Group> </Group> - <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> <DimensionLayout dim="1"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0"> - <EmptySpace min="-2" pref="5" max="-2" attributes="0"/> + <EmptySpace min="-2" pref="7" max="-2" attributes="0"/> + <Group type="103" groupAlignment="3" attributes="0"> + <Component id="lbRuntime" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="btManageRuntimes" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="cbRuntime" alignment="3" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace type="unrelated" max="-2" attributes="0"/> + <Component id="cbAugmentedBuild" min="-2" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Component id="lbAugmentedBuild" min="-2" pref="36" max="-2" attributes="0"/> + <EmptySpace max="32767" attributes="0"/> + <Component id="cbIncludeOpenProjects" min="-2" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Component id="lbIncludeOpenProjects" min="-2" pref="56" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Component id="jSeparator1" min="-2" max="-2" attributes="0"/> + <EmptySpace type="unrelated" max="-2" attributes="0"/> <Group type="103" groupAlignment="3" attributes="0"> - <Component id="cbTrustLevel" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="lbTrustLevel" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="cbTrustLevel" alignment="3" min="-2" max="-2" attributes="0"/> </Group> <EmptySpace max="-2" attributes="0"/> - <Component id="lbTrustTerms" min="-2" pref="234" max="-2" attributes="0"/> - <EmptySpace pref="8" max="32767" attributes="0"/> + <Component id="lbTrustTerms" min="-2" pref="128" max="-2" attributes="0"/> + <EmptySpace max="32767" attributes="0"/> <Component id="lbReadOnly" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> </Group> @@ -78,30 +118,99 @@ </DimensionLayout> </Layout> <SubComponents> - <Component class="javax.swing.JLabel" name="lbTrustTerms"> + <Component class="javax.swing.JLabel" name="lbRuntime"> <Properties> + <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor"> + <ComponentRef name="cbRuntime"/> + </Property> + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> + <ResourceString bundle="org/netbeans/modules/gradle/customizer/Bundle.properties" key="GradleExecutionPanel.lbRuntime.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + </Property> + </Properties> + </Component> + <Component class="javax.swing.JComboBox" name="cbRuntime"> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbRuntimeActionPerformed"/> + </Events> + <AuxValues> + <AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<JavaRuntime>"/> + </AuxValues> + </Component> + <Component class="javax.swing.JButton" name="btManageRuntimes"> + <Properties> + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> + <ResourceString bundle="org/netbeans/modules/gradle/customizer/Bundle.properties" key="GradleExecutionPanel.btManageRuntimes.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + </Property> + <Property name="actionCommand" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> + <ResourceString bundle="org/netbeans/modules/gradle/customizer/Bundle.properties" key="GradleExecutionPanel.btManageRuntimes.actionCommand" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + </Property> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btManageRuntimesActionPerformed"/> + </Events> + </Component> + <Component class="javax.swing.JCheckBox" name="cbAugmentedBuild"> + <Properties> + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> + <ResourceString bundle="org/netbeans/modules/gradle/customizer/Bundle.properties" key="GradleExecutionPanel.cbAugmentedBuild.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + </Property> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="lbAugmentedBuild"> + <Properties> + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> + <ResourceString bundle="org/netbeans/modules/gradle/customizer/Bundle.properties" key="GradleExecutionPanel.lbAugmentedBuild.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + </Property> <Property name="verticalAlignment" type="int" value="1"/> </Properties> </Component> - <Component class="javax.swing.JLabel" name="lbReadOnly"> + <Component class="javax.swing.JCheckBox" name="cbIncludeOpenProjects"> <Properties> - <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor"> - <Image iconType="3" name="/org/netbeans/modules/gradle/resources/info.png"/> + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> + <ResourceString bundle="org/netbeans/modules/gradle/customizer/Bundle.properties" key="GradleExecutionPanel.cbIncludeOpenProjects.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> </Property> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="lbIncludeOpenProjects"> + <Properties> <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> - <ResourceString bundle="org/netbeans/modules/gradle/customizer/Bundle.properties" key="GradleExecutionPanel.lbReadOnly.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + <ResourceString bundle="org/netbeans/modules/gradle/customizer/Bundle.properties" key="GradleExecutionPanel.lbIncludeOpenProjects.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + </Property> + <Property name="verticalAlignment" type="int" value="1"/> + </Properties> + </Component> + <Component class="javax.swing.JSeparator" name="jSeparator1"> + </Component> + <Component class="javax.swing.JLabel" name="lbTrustLevel"> + <Properties> + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> + <ResourceString bundle="org/netbeans/modules/gradle/customizer/Bundle.properties" key="GradleExecutionPanel.lbTrustLevel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> </Property> </Properties> </Component> <Component class="javax.swing.JComboBox" name="cbTrustLevel"> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbTrustLevelActionPerformed"/> + </Events> <AuxValues> <AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<TrustLevel>"/> </AuxValues> </Component> - <Component class="javax.swing.JLabel" name="lbTrustLevel"> + <Component class="javax.swing.JLabel" name="lbTrustTerms"> <Properties> <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> - <ResourceString bundle="org/netbeans/modules/gradle/customizer/Bundle.properties" key="GradleExecutionPanel.lbTrustLevel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + <ResourceString bundle="org/netbeans/modules/gradle/customizer/Bundle.properties" key="GradleExecutionPanel.lbTrustTerms.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + </Property> + <Property name="verticalAlignment" type="int" value="1"/> + </Properties> + </Component> + <Component class="javax.swing.JLabel" name="lbReadOnly"> + <Properties> + <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor"> + <Image iconType="3" name="/org/netbeans/modules/gradle/resources/info.png"/> + </Property> + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> + <ResourceString bundle="org/netbeans/modules/gradle/customizer/Bundle.properties" key="GradleExecutionPanel.lbReadOnly.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> </Property> </Properties> </Component> diff --git a/extide/gradle/src/org/netbeans/modules/gradle/customizer/GradleExecutionPanel.java b/extide/gradle/src/org/netbeans/modules/gradle/customizer/GradleExecutionPanel.java index 0904274665..c167e850d6 100644 --- a/extide/gradle/src/org/netbeans/modules/gradle/customizer/GradleExecutionPanel.java +++ b/extide/gradle/src/org/netbeans/modules/gradle/customizer/GradleExecutionPanel.java @@ -18,29 +18,41 @@ */ package org.netbeans.modules.gradle.customizer; +import java.awt.Component; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; +import java.util.prefs.Preferences; +import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.ListCellRenderer; +import javax.swing.UIManager; +import javax.swing.event.ChangeListener; +import javax.swing.plaf.UIResource; import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectUtils; import org.netbeans.modules.gradle.ProjectTrust; import org.netbeans.modules.gradle.api.GradleBaseProject; +import org.netbeans.modules.gradle.api.NbGradleProject; +import org.netbeans.modules.gradle.api.execute.RunUtils; import org.openide.util.NbBundle; -import org.openide.util.NbBundle.Messages; import static org.netbeans.modules.gradle.customizer.GradleExecutionPanel.TrustLevel.*; +import org.netbeans.modules.gradle.spi.execute.JavaRuntimeManager; +import org.netbeans.modules.gradle.spi.execute.JavaRuntimeManager.JavaRuntime; +import org.openide.util.Lookup; +import org.openide.util.NbBundle.Messages; +import org.openide.util.WeakListeners; /** * * @author lkishalmi */ -@Messages({ - "GRADLE_TRUST_MSG=<html><p>Executing Gradle can be potentially un-safe as it " - + "allows arbitrary code execution.</p><p></p>" - + "<p>By trusting this project, and with that all its subprojects, " - + "you entitle NetBeans to invoke Gradle to load project details " - + "without further confirmation.</p><p></p>" - + "<p>Invoking any build related actions, would mark this project " - + "automatically trusted.</p>", -}) public class GradleExecutionPanel extends javax.swing.JPanel { + public static final String HINT_JDK_PLATFORM = "hint.jdkPlatform"; //NOI18N enum TrustLevel { PERMANENT, @@ -54,38 +66,128 @@ public class GradleExecutionPanel extends javax.swing.JPanel { } - Project project; + private Project project; + private final JavaRuntimeManager runtimeManager; + private final ChangeListener runtimeChangeListener = (evt) -> managedRuntimeSetup(); + private boolean readOnly = true; /** * Creates new form GradleExecutionPanel */ + @Messages({ + "NO_RUNTIME_SUPPORT_HINT=Runtime Change is not Supported", + "NO_RUNTIME_MANAGEMENT_HINT=Runtime Management is not Supported", + }) public GradleExecutionPanel() { initComponents(); - lbTrustTerms.setText(Bundle.GRADLE_TRUST_MSG()); + runtimeManager = Lookup.getDefault().lookup(JavaRuntimeManager.class); + if (runtimeManager == null) { + cbRuntime.setToolTipText(Bundle.NO_RUNTIME_SUPPORT_HINT()); + btManageRuntimes.setToolTipText(Bundle.NO_RUNTIME_SUPPORT_HINT()); + } else { + runtimeManager.addChangeListener(WeakListeners.change(runtimeChangeListener, runtimeManager)); + managedRuntimeSetup(); + if (!runtimeManager.manageRuntimesAction().isPresent()) { + btManageRuntimes.setToolTipText(Bundle.NO_RUNTIME_MANAGEMENT_HINT()); + } + } + } public GradleExecutionPanel(Project project) { this(); this.project = project; GradleBaseProject gbp = GradleBaseProject.get(project); + readOnly = (gbp != null) && !gbp.isRoot(); + + lbReadOnly.setVisible(readOnly); + lbTrustLevel.setEnabled(!readOnly); + cbTrustLevel.setEnabled(!readOnly); + lbTrustTerms.setEnabled(!readOnly); + + cbTrustLevel.setModel(new DefaultComboBoxModel<>(TrustLevel.values())); + + if (ProjectTrust.getDefault().isTrustedPermanently(project)) { + cbTrustLevel.setSelectedItem(PERMANENT); + setJavaSettingsEnabled(!readOnly); + } else if (ProjectTrust.getDefault().isTrusted(project)) { + cbTrustLevel.setSelectedItem(TEMPORARY); + setJavaSettingsEnabled(!readOnly); + } else { + cbTrustLevel.setSelectedItem(NONE); + setJavaSettingsEnabled(false); + } + + cbRuntime.setRenderer(new RuntimeRenderer()); + selectRuntime(RunUtils.getActiveRuntime(project)); + + setupCheckBox(cbAugmentedBuild, RunUtils.PROP_AUGMENTED_BUILD, true); + setupCheckBox(cbIncludeOpenProjects, RunUtils.PROP_INCLUDE_OPEN_PROJECTS, false); + } + + private void selectRuntime(JavaRuntime selected) { + ComboBoxModel<JavaRuntime> model = cbRuntime.getModel(); + if (selected == null || selected.isBroken()) { + model.setSelectedItem(selected); + } else { + for (int i = 0; i < model.getSize(); i++) { + JavaRuntime rt = model.getElementAt(i); + if (rt.equals(selected)) { + model.setSelectedItem(model.getElementAt(i)); + break; + } + } + } + } + + @Messages({ + "# {0} - the name of the setting property", + "COMPILE_DISABLED_HINT=<html>This option is currently specificly controlled" + + " through your Gradle project (most likely through " + + "<b>gradle.properties</b>) by <br/> <b>netbeans.{0}</b> property." + }) + private void setupCheckBox(JCheckBox check, String property, boolean defaultValue) { + Project root = ProjectUtils.rootOf(project); + GradleBaseProject gbp = GradleBaseProject.get(root); if (gbp != null) { - lbReadOnly.setVisible(!gbp.isRoot()); - lbTrustLevel.setEnabled(gbp.isRoot()); - cbTrustLevel.setEnabled(gbp.isRoot()); - lbTrustTerms.setEnabled(gbp.isRoot()); - - cbTrustLevel.setModel(new DefaultComboBoxModel<>(TrustLevel.values())); - - if (ProjectTrust.getDefault().isTrustedPermanently(project)) { - cbTrustLevel.setSelectedItem(PERMANENT); - } else if (ProjectTrust.getDefault().isTrusted(project)) { - cbTrustLevel.setSelectedItem(TEMPORARY); + if (gbp.getNetBeansProperty(property) != null) { + check.setEnabled(!readOnly); + check.setSelected(Boolean.parseBoolean(gbp.getNetBeansProperty(property))); + check.setToolTipText(Bundle.COMPILE_DISABLED_HINT(property)); } else { - cbTrustLevel.setSelectedItem(NONE); + Preferences prefs = NbGradleProject.getPreferences(root, false); + check.setSelected(prefs.getBoolean(property, defaultValue)); } } } + private void managedRuntimeSetup() { + int selected = cbRuntime.getSelectedIndex(); + JavaRuntime runtime = selected != -1 ? cbRuntime.getModel().getElementAt(selected) : null; + Map<String, JavaRuntime> availabeRuntimes = runtimeManager != null ? runtimeManager.getAvailableRuntimes() : Collections.emptyMap(); + + JavaRuntime[] runtimes = availabeRuntimes.values().toArray(new JavaRuntime[0]); + Arrays.sort(runtimes); + + DefaultComboBoxModel<JavaRuntime> model = new DefaultComboBoxModel<>(runtimes); + cbRuntime.setModel(model); + selectRuntime(runtime); + } + + private void setJavaSettingsEnabled(boolean b) { + boolean enableRuntime = b && (runtimeManager != null); + + lbRuntime.setEnabled(enableRuntime); + cbRuntime.setEnabled(enableRuntime); + btManageRuntimes.setEnabled(enableRuntime && runtimeManager.manageRuntimesAction().isPresent()); + + cbAugmentedBuild.setEnabled(b); + lbAugmentedBuild.setEnabled(b); + + cbIncludeOpenProjects.setEnabled(b); + lbIncludeOpenProjects.setEnabled(b); + } + /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always @@ -95,82 +197,238 @@ public class GradleExecutionPanel extends javax.swing.JPanel { // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { + lbRuntime = new javax.swing.JLabel(); + cbRuntime = new javax.swing.JComboBox<>(); + btManageRuntimes = new javax.swing.JButton(); + cbAugmentedBuild = new javax.swing.JCheckBox(); + lbAugmentedBuild = new javax.swing.JLabel(); + cbIncludeOpenProjects = new javax.swing.JCheckBox(); + lbIncludeOpenProjects = new javax.swing.JLabel(); + jSeparator1 = new javax.swing.JSeparator(); + lbTrustLevel = new javax.swing.JLabel(); + cbTrustLevel = new javax.swing.JComboBox<>(); lbTrustTerms = new javax.swing.JLabel(); lbReadOnly = new javax.swing.JLabel(); - cbTrustLevel = new javax.swing.JComboBox<>(); - lbTrustLevel = new javax.swing.JLabel(); + lbRuntime.setLabelFor(cbRuntime); + org.openide.awt.Mnemonics.setLocalizedText(lbRuntime, org.openide.util.NbBundle.getMessage(GradleExecutionPanel.class, "GradleExecutionPanel.lbRuntime.text")); // NOI18N + + cbRuntime.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cbRuntimeActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(btManageRuntimes, org.openide.util.NbBundle.getMessage(GradleExecutionPanel.class, "GradleExecutionPanel.btManageRuntimes.text")); // NOI18N + btManageRuntimes.setActionCommand(org.openide.util.NbBundle.getMessage(GradleExecutionPanel.class, "GradleExecutionPanel.btManageRuntimes.actionCommand")); // NOI18N + btManageRuntimes.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btManageRuntimesActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(cbAugmentedBuild, org.openide.util.NbBundle.getMessage(GradleExecutionPanel.class, "GradleExecutionPanel.cbAugmentedBuild.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(lbAugmentedBuild, org.openide.util.NbBundle.getMessage(GradleExecutionPanel.class, "GradleExecutionPanel.lbAugmentedBuild.text")); // NOI18N + lbAugmentedBuild.setVerticalAlignment(javax.swing.SwingConstants.TOP); + + org.openide.awt.Mnemonics.setLocalizedText(cbIncludeOpenProjects, org.openide.util.NbBundle.getMessage(GradleExecutionPanel.class, "GradleExecutionPanel.cbIncludeOpenProjects.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(lbIncludeOpenProjects, org.openide.util.NbBundle.getMessage(GradleExecutionPanel.class, "GradleExecutionPanel.lbIncludeOpenProjects.text")); // NOI18N + lbIncludeOpenProjects.setVerticalAlignment(javax.swing.SwingConstants.TOP); + + org.openide.awt.Mnemonics.setLocalizedText(lbTrustLevel, org.openide.util.NbBundle.getMessage(GradleExecutionPanel.class, "GradleExecutionPanel.lbTrustLevel.text")); // NOI18N + + cbTrustLevel.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cbTrustLevelActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(lbTrustTerms, org.openide.util.NbBundle.getMessage(GradleExecutionPanel.class, "GradleExecutionPanel.lbTrustTerms.text")); // NOI18N lbTrustTerms.setVerticalAlignment(javax.swing.SwingConstants.TOP); lbReadOnly.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/gradle/resources/info.png"))); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(lbReadOnly, org.openide.util.NbBundle.getMessage(GradleExecutionPanel.class, "GradleExecutionPanel.lbReadOnly.text")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(lbTrustLevel, org.openide.util.NbBundle.getMessage(GradleExecutionPanel.class, "GradleExecutionPanel.lbTrustLevel.text")); // NOI18N - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(6, 6, 6) + .addComponent(lbReadOnly)) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(lbTrustLevel, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cbTrustLevel, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addContainerGap(317, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addComponent(lbReadOnly) + .addGap(21, 21, 21) + .addComponent(lbIncludeOpenProjects, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(lbRuntime, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cbRuntime, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(btManageRuntimes) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() - .addGap(21, 21, 21) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(lbTrustLevel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(cbTrustLevel, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addComponent(lbTrustTerms, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) - .addContainerGap()) + .addComponent(cbIncludeOpenProjects, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(21, 21, 21) + .addComponent(lbAugmentedBuild, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)) + .addComponent(cbAugmentedBuild, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jSeparator1) + .addComponent(lbTrustTerms, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)) + .addContainerGap()))) ); + + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cbRuntime, cbTrustLevel}); + layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addGap(5, 5, 5) + .addGap(7, 7, 7) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lbRuntime) + .addComponent(btManageRuntimes) + .addComponent(cbRuntime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(cbAugmentedBuild) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(lbAugmentedBuild, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cbIncludeOpenProjects) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(lbIncludeOpenProjects, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(cbTrustLevel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(lbTrustLevel)) + .addComponent(lbTrustLevel) + .addComponent(cbTrustLevel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(lbTrustTerms, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE) + .addComponent(lbTrustTerms, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(lbReadOnly) .addContainerGap()) ); }// </editor-fold>//GEN-END:initComponents + private void btManageRuntimesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btManageRuntimesActionPerformed + if ((runtimeManager != null) && runtimeManager.manageRuntimesAction().isPresent()) { + runtimeManager.manageRuntimesAction().get().run(); + } + }//GEN-LAST:event_btManageRuntimesActionPerformed + + private void cbTrustLevelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTrustLevelActionPerformed + setJavaSettingsEnabled(!readOnly && (cbTrustLevel.getSelectedItem() != TrustLevel.NONE)); + }//GEN-LAST:event_cbTrustLevelActionPerformed + + private void cbRuntimeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbRuntimeActionPerformed + JavaRuntime rt = (JavaRuntime) cbRuntime.getSelectedItem(); + String fore = (rt != null) && rt.isBroken() ? "nb.errorForeground" : "ComboBox.foreground"; //NOI18N + cbRuntime.setForeground(UIManager.getColor(fore)); + }//GEN-LAST:event_cbRuntimeActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btManageRuntimes; + private javax.swing.JCheckBox cbAugmentedBuild; + private javax.swing.JCheckBox cbIncludeOpenProjects; + private javax.swing.JComboBox<JavaRuntime> cbRuntime; private javax.swing.JComboBox<TrustLevel> cbTrustLevel; + private javax.swing.JSeparator jSeparator1; + private javax.swing.JLabel lbAugmentedBuild; + private javax.swing.JLabel lbIncludeOpenProjects; private javax.swing.JLabel lbReadOnly; + private javax.swing.JLabel lbRuntime; private javax.swing.JLabel lbTrustLevel; private javax.swing.JLabel lbTrustTerms; // End of variables declaration//GEN-END:variables + private void saveTrustLevel(Project project) { + TrustLevel v = (TrustLevel)cbTrustLevel.getSelectedItem(); + if (v == null) { + v = NONE; + } + switch (v) { + case NONE: + ProjectTrust.getDefault().distrustProject(project); + break; + + case PERMANENT: + ProjectTrust.getDefault().trustProject(project, true); + break; + + case TEMPORARY: + if (ProjectTrust.getDefault().isTrustedPermanently(project)) { + ProjectTrust.getDefault().distrustProject(project); + } + ProjectTrust.getDefault().trustProject(project, false); + break; + } + } + + private void saveJavaRuntime(Project project) { + RunUtils.setActiveRuntime(project, (JavaRuntime) cbRuntime.getSelectedItem()); + } + + private void saveCheckBox(JCheckBox check, String property) { + GradleBaseProject gbp = project != null ? GradleBaseProject.get(project) : null; + if ((gbp != null) && (gbp.getNetBeansProperty(property) == null)) { + Preferences prefs = NbGradleProject.getPreferences(project, false); + prefs.putBoolean(property, check.isSelected()); + } + } + void save() { if (project != null) { - TrustLevel v = (TrustLevel)cbTrustLevel.getSelectedItem(); - if (v == null) { - v = NONE; - } - switch (v) { - case NONE: - ProjectTrust.getDefault().distrustProject(project); - break; - - case PERMANENT: - ProjectTrust.getDefault().trustProject(project, true); - break; - - case TEMPORARY: - if (ProjectTrust.getDefault().isTrustedPermanently(project)) { - ProjectTrust.getDefault().distrustProject(project); - } - ProjectTrust.getDefault().trustProject(project, false); - break; + saveTrustLevel(project); + saveJavaRuntime(project); + + saveCheckBox(cbAugmentedBuild, RunUtils.PROP_AUGMENTED_BUILD); + saveCheckBox(cbIncludeOpenProjects, RunUtils.PROP_INCLUDE_OPEN_PROJECTS); + } + } + + private class RuntimeRenderer extends JLabel implements ListCellRenderer, UIResource { + + @Override + @NbBundle.Messages({ + "# {0} - runtimeId", + "LBL_MissingRuntime=Missing Runtime: {0}" + }) + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, + boolean cellHasFocus) { + setOpaque(true); + if (value instanceof JavaRuntime) { + JavaRuntime rt = (JavaRuntime)value; + setText(rt.getDisplayName()); + if ( isSelected ) { + setBackground(list.getSelectionBackground()); + setForeground(list.getSelectionForeground()); + } else { + setBackground(list.getBackground()); + setForeground(list.getForeground()); + } + if (rt.isBroken()) { + setText(Bundle.LBL_MissingRuntime(value)); + } + } else { + if (value == null) { + setText(""); + } } + return this; } } } diff --git a/extide/gradle/src/org/netbeans/modules/gradle/execute/DefaultJavaRuntimeManager.java b/extide/gradle/src/org/netbeans/modules/gradle/execute/DefaultJavaRuntimeManager.java new file mode 100644 index 0000000000..dad0aacb17 --- /dev/null +++ b/extide/gradle/src/org/netbeans/modules/gradle/execute/DefaultJavaRuntimeManager.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.gradle.execute; + +import java.io.File; +import java.util.Collections; +import java.util.Map; +import org.netbeans.modules.gradle.spi.execute.JavaRuntimeManager; +import org.openide.util.NbBundle.Messages; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author Laszlo Kishalmi + */ +@ServiceProvider(service = JavaRuntimeManager.class) +public class DefaultJavaRuntimeManager implements JavaRuntimeManager { + + private final Map<String, JavaRuntime> defaultRuntimes; + + @Messages({ + "# {0} - The version of the Java Runtime", + "DEFAULT_JAVA_RUNTIME_NAME=Java {0} (Default)" + }) + public DefaultJavaRuntimeManager() { + File javaHome = new File(System.getProperty("java.home")); //NOI18N + String javaVersion = System.getProperty("java.specification.version"); //NOI18N + JavaRuntime defaultRuntime = JavaRuntimeManager.createJavaRuntime(DEFAULT_RUNTIME_ID, Bundle.DEFAULT_JAVA_RUNTIME_NAME(javaVersion), javaHome); + + defaultRuntimes = Collections.singletonMap(DEFAULT_RUNTIME_ID, defaultRuntime); + } + + @Override + public Map<String, JavaRuntime> getAvailableRuntimes() { + return defaultRuntimes; + } + +} diff --git a/java/gradle.java/src/org/netbeans/modules/gradle/java/execute/GradleJavaPlatformProviderImpl.java b/extide/gradle/src/org/netbeans/modules/gradle/execute/GradleJavaPlatformProviderImpl.java similarity index 66% rename from java/gradle.java/src/org/netbeans/modules/gradle/java/execute/GradleJavaPlatformProviderImpl.java rename to extide/gradle/src/org/netbeans/modules/gradle/execute/GradleJavaPlatformProviderImpl.java index 309ff5c8d6..99b3995667 100644 --- a/java/gradle.java/src/org/netbeans/modules/gradle/java/execute/GradleJavaPlatformProviderImpl.java +++ b/extide/gradle/src/org/netbeans/modules/gradle/execute/GradleJavaPlatformProviderImpl.java @@ -16,20 +16,22 @@ * specific language governing permissions and limitations * under the License. */ -package org.netbeans.modules.gradle.java.execute; +package org.netbeans.modules.gradle.execute; import java.io.File; import java.io.FileNotFoundException; -import org.netbeans.api.java.platform.JavaPlatform; import org.netbeans.api.project.Project; +import org.netbeans.modules.gradle.api.NbGradleProject; +import org.netbeans.modules.gradle.api.execute.RunUtils; import org.netbeans.modules.gradle.spi.execute.GradleJavaPlatformProvider; -import org.openide.filesystems.FileUtil; -import org.openide.util.Pair; +import org.netbeans.modules.gradle.spi.execute.JavaRuntimeManager.JavaRuntime; +import org.netbeans.spi.project.ProjectServiceProvider; /** * - * @author lkishalmi + * @author Laszlo Kishalmi */ +@ProjectServiceProvider(service = GradleJavaPlatformProvider.class, projectType = NbGradleProject.GRADLE_PROJECT_TYPE) public final class GradleJavaPlatformProviderImpl implements GradleJavaPlatformProvider { final Project project; @@ -38,15 +40,12 @@ public final class GradleJavaPlatformProviderImpl implements GradleJavaPlatformP this.project = project; } - @Override public File getJavaHome() throws FileNotFoundException { - Pair<String, JavaPlatform> platform = JavaRunUtils.getActivePlatform(project); - if (platform.second() == null || !platform.second().isValid() || platform.second().getInstallFolders().isEmpty()) { - throw new FileNotFoundException(platform.first()); + JavaRuntime rt = RunUtils.getActiveRuntime(project); + if (rt.isBroken()) { + throw new FileNotFoundException("Could not found runtime for: " + rt.getId()); } - File javaHome = FileUtil.toFile(platform.second().getInstallFolders().iterator().next()); - return javaHome; + return rt.getJavaHome(); } - } diff --git a/extide/gradle/src/org/netbeans/modules/gradle/spi/execute/JavaRuntimeManager.java b/extide/gradle/src/org/netbeans/modules/gradle/spi/execute/JavaRuntimeManager.java new file mode 100644 index 0000000000..2189ef446a --- /dev/null +++ b/extide/gradle/src/org/netbeans/modules/gradle/spi/execute/JavaRuntimeManager.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.gradle.spi.execute; + +import java.io.File; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import javax.swing.event.ChangeListener; +import org.netbeans.api.annotations.common.NonNull; + +/** + * JavaRuntimeManager is to provide Java Runtime for Gradle execution. Gradle + * is not just a build system for JVM based languages, but can build C, C++, + * NodeJS projects as well. + * <p> + * Gradle just requires a suitable JRE to run on. + * </p> + * <p>Most cases though Gradle build Java libraries/applications, and by default + * Gradle uses the JVM, that it is running on.</p> + * + * <p>This manager separates the JavaRuntime on which Gradle can run from + * the JavaPlatform on which Gradle Java project can be built. Every JavaPlatform + * is a JavaRuntime, but not every JavaRuntime is a JavaPlatform way. + * </p> + * + * @author Laszlo Kishalmi + * @since 2.32 + */ +public interface JavaRuntimeManager { + + /** + * The ID that the Runtime shall use for the Java Runtime the IDE is runnoing on. + */ + public static String DEFAULT_RUNTIME_ID = "default_platform"; //NOI18N + + /** + * Return the available runtimes stored in the IDE with their respective Id-s. + * + * @return the available runtimes stored in the IDE. + */ + Map<String, JavaRuntime> getAvailableRuntimes(); + + /** + * This method is called from the Gradle Execution Customizer when + * the "Manage Runtimes..." button is called. + * + * @return can provide a runnable to configure the available runtimes. + */ + default Optional<Runnable> manageRuntimesAction() { + return Optional.empty(); + } + + /** + * Register a change listener to this manager. + * Implementations shall fire a change event when the available runtimes + * changed. + * <p> + * The default implementation does nothing. + * </p> + * + * @param l the listener to be registered. + */ + default void addChangeListener(ChangeListener l) {} + + /** + * Removes a change listener from this manager. + * <p> + * The default implementation does nothing. + * </p> + * @param l the listener to be removed. + */ + default void removeChangeListener(ChangeListener l) {} + + public static JavaRuntime createJavaRuntime(@NonNull String id, File javaHome) { + return new JavaRuntime(id, null, javaHome); + } + + public static JavaRuntime createJavaRuntime(@NonNull String id, String displayName, File javaHome) { + return new JavaRuntime(id, displayName, javaHome); + } + + /** + * This class represents a java home directory with and id, + * and an optional display name. + * + * @since 2.32 + */ + public final class JavaRuntime implements Comparable<JavaRuntime> { + final String id; + final String displayName; + final File javaHome; + + private JavaRuntime(@NonNull String id, String displayName, File javaHome) { + this.id = id; + this.displayName = displayName != null ? displayName : id; + this.javaHome = javaHome; + } + + public String getId() { + return id; + } + + public String getDisplayName() { + return displayName; + } + + /** + * The Java home directory associated with the id. This can be null or + * non existent directory, that would represent a broken JavaRuntime. + * + * @return the Java home directory of this runtime. + */ + public File getJavaHome() { + return javaHome; + } + + /** + * Returns {@code true} if the Java home of this runtime is {@code null} + * or points to a non-existing directory. + * + * @return {@code true} if this runtime should not be used. + */ + public boolean isBroken() { + return javaHome == null || !javaHome.isDirectory(); + } + + @Override + public int compareTo(JavaRuntime o) { + return getDisplayName().compareToIgnoreCase(o.getDisplayName()); + } + + @Override + public String toString() { + return getDisplayName(); + } + + @Override + public int hashCode() { + return id.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final JavaRuntime other = (JavaRuntime) obj; + return Objects.equals(this.id, other.id); + } + + + } +} diff --git a/java/gradle.java/src/org/netbeans/modules/gradle/java/JavaRuntimePlatformBridge.java b/java/gradle.java/src/org/netbeans/modules/gradle/java/JavaRuntimePlatformBridge.java new file mode 100644 index 0000000000..ad8b02b174 --- /dev/null +++ b/java/gradle.java/src/org/netbeans/modules/gradle/java/JavaRuntimePlatformBridge.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.gradle.java; + +import java.beans.PropertyChangeListener; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import javax.swing.event.ChangeListener; +import org.netbeans.api.java.platform.JavaPlatform; +import org.netbeans.api.java.platform.JavaPlatformManager; +import org.netbeans.api.java.platform.PlatformsCustomizer; +import org.netbeans.modules.gradle.spi.execute.JavaRuntimeManager; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.ChangeSupport; +import org.openide.util.WeakListeners; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author lkishalmi + */ +@ServiceProvider(service = JavaRuntimeManager.class, position = 0) +public class JavaRuntimePlatformBridge implements JavaRuntimeManager { + private static final String PROP_PLATFORM_ID = "platform.ant.name"; //NOI18N + + private Map<String, JavaRuntime> cachedRuntimes = null; + private boolean listenerInitialized = false; + private final PropertyChangeListener clearCache; + + private final ChangeSupport support; + + public JavaRuntimePlatformBridge() { + support = new ChangeSupport(this); + clearCache = (evt) -> { + cachedRuntimes = null; + support.fireChange(); + }; + } + + @Override + public Map<String, JavaRuntime> getAvailableRuntimes() { + synchronized (this) { + if (cachedRuntimes == null) { + + JavaPlatformManager jpm = JavaPlatformManager.getDefault(); + + if (!listenerInitialized) { + jpm.addPropertyChangeListener(WeakListeners.propertyChange(clearCache, jpm)); + listenerInitialized = true; + } + + Map<String, JavaRuntime> runtimes = new HashMap<>(); + for (JavaPlatform platform : jpm.getInstalledPlatforms()) { + String id = platform.getProperties().get(PROP_PLATFORM_ID); + if (platform.isValid() && (id != null)) { + FileObject javaInstallDir = platform.getInstallFolders().iterator().next(); + runtimes.put(id, JavaRuntimeManager.createJavaRuntime(id, platform.getDisplayName(), FileUtil.toFile(javaInstallDir))); + } + } + cachedRuntimes = Collections.unmodifiableMap(runtimes); + } + return cachedRuntimes; + } + } + + @Override + public Optional<Runnable> manageRuntimesAction() { + return Optional.of(() -> PlatformsCustomizer.showCustomizer(null)); + } + + @Override + public void addChangeListener(ChangeListener l) { + support.addChangeListener(l); + } + + @Override + public void removeChangeListener(ChangeListener l) { + support.removeChangeListener(l); + } + +} diff --git a/java/gradle.java/src/org/netbeans/modules/gradle/java/LookupProviders.java b/java/gradle.java/src/org/netbeans/modules/gradle/java/LookupProviders.java index 1dd44729f6..9060acd005 100644 --- a/java/gradle.java/src/org/netbeans/modules/gradle/java/LookupProviders.java +++ b/java/gradle.java/src/org/netbeans/modules/gradle/java/LookupProviders.java @@ -38,7 +38,6 @@ public class LookupProviders { Project project = baseContext.lookup(Project.class); return Lookups.fixed( new GradleJavaDebuggerImpl(project), - new GradleJavaProjectProblemProvider(project), new GradleJavaTokenProvider(project), new RecommendedPrivilegedTemplatesImpl(), new SourceGroupResourceWatchList(project) diff --git a/java/gradle.java/src/org/netbeans/modules/gradle/java/customizer/Bundle.properties b/java/gradle.java/src/org/netbeans/modules/gradle/java/customizer/Bundle.properties index bec58d8bbc..6797c79d18 100644 --- a/java/gradle.java/src/org/netbeans/modules/gradle/java/customizer/Bundle.properties +++ b/java/gradle.java/src/org/netbeans/modules/gradle/java/customizer/Bundle.properties @@ -15,12 +15,6 @@ # specific language governing permissions and limitations # under the License. -CompileOptionsPanel.jLabel2.text=<html>Allow NetBeans to make on-the-fly changes to the Gradle build process. This way a few useful IDE actions/options can be enabled without actually changing the build files. -CompileOptionsPanel.cbAugmentedBuild.text=&Augmented Build Execution -CompileOptionsPanel.btManagePlatforms.text=Manage Platforms... -CompileOptionsPanel.lbPlatform.text=Java &Platform: SourceSetPanel.jLabel1.text=Output Classes: SourceSetPanel.jLabel2.text=Output Resources: SourceSetPanel.jLabel3.text=Source/Binary Format: -CompileOptionsPanel.cbIncludeOpenProjects.text=Include Open Projects -CompileOptionsPanel.lbIncludeOpenProjects.text=<html>Create a composite project from this project and the other open Gradle projects by generating '--include-build' parameters. diff --git a/java/gradle.java/src/org/netbeans/modules/gradle/java/customizer/CompileOptionsPanel.form b/java/gradle.java/src/org/netbeans/modules/gradle/java/customizer/CompileOptionsPanel.form deleted file mode 100644 index 88cf620afd..0000000000 --- a/java/gradle.java/src/org/netbeans/modules/gradle/java/customizer/CompileOptionsPanel.form +++ /dev/null @@ -1,156 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> - -<!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> - -<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> - <AuxValues> - <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/> - <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> - <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/> - <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/> - <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> - <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> - <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> - <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> - </AuxValues> - - <Layout> - <DimensionLayout dim="0"> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" attributes="0"> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" alignment="0" attributes="0"> - <EmptySpace max="-2" attributes="0"/> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" alignment="0" attributes="0"> - <Component id="lbPlatform" min="-2" max="-2" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - <Component id="cbPlatform" pref="222" max="32767" attributes="0"/> - <EmptySpace type="unrelated" max="-2" attributes="0"/> - <Component id="btManagePlatforms" min="-2" max="-2" attributes="0"/> - </Group> - <Component id="cbAugmentedBuild" alignment="0" max="32767" attributes="0"/> - </Group> - </Group> - <Group type="102" alignment="0" attributes="0"> - <EmptySpace min="-2" pref="25" max="-2" attributes="0"/> - <Component id="jLabel2" pref="0" max="32767" attributes="0"/> - </Group> - <Group type="102" alignment="0" attributes="0"> - <EmptySpace max="-2" attributes="0"/> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" attributes="0"> - <EmptySpace min="21" pref="21" max="-2" attributes="0"/> - <Component id="lbIncludeOpenProjects" pref="0" max="32767" attributes="0"/> - </Group> - <Group type="102" attributes="0"> - <Component id="cbIncludeOpenProjects" min="-2" max="-2" attributes="0"/> - <EmptySpace min="0" pref="0" max="32767" attributes="0"/> - </Group> - </Group> - </Group> - </Group> - <EmptySpace max="-2" attributes="0"/> - </Group> - </Group> - </DimensionLayout> - <DimensionLayout dim="1"> - <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" alignment="0" attributes="0"> - <EmptySpace min="-2" pref="4" max="-2" attributes="0"/> - <Group type="103" groupAlignment="3" attributes="0"> - <Component id="lbPlatform" alignment="3" min="-2" max="-2" attributes="0"/> - <Component id="cbPlatform" alignment="3" min="-2" max="-2" attributes="0"/> - <Component id="btManagePlatforms" alignment="3" min="-2" max="-2" attributes="0"/> - </Group> - <EmptySpace type="separate" max="-2" attributes="0"/> - <Component id="cbAugmentedBuild" min="-2" max="-2" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - <Component id="jLabel2" min="-2" pref="71" max="-2" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - <Component id="cbIncludeOpenProjects" min="-2" max="-2" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> - <Component id="lbIncludeOpenProjects" min="-2" pref="56" max="-2" attributes="0"/> - <EmptySpace pref="156" max="32767" attributes="0"/> - </Group> - </Group> - </DimensionLayout> - </Layout> - <SubComponents> - <Component class="javax.swing.JCheckBox" name="cbAugmentedBuild"> - <Properties> - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> - <ResourceString bundle="org/netbeans/modules/gradle/java/customizer/Bundle.properties" key="CompileOptionsPanel.cbAugmentedBuild.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> - </Property> - </Properties> - </Component> - <Component class="javax.swing.JLabel" name="lbPlatform"> - <Properties> - <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor"> - <ComponentRef name="cbPlatform"/> - </Property> - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> - <ResourceString bundle="org/netbeans/modules/gradle/java/customizer/Bundle.properties" key="CompileOptionsPanel.lbPlatform.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> - </Property> - </Properties> - </Component> - <Component class="javax.swing.JComboBox" name="cbPlatform"> - <AuxValues> - <AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<JavaPlatform>"/> - </AuxValues> - </Component> - <Component class="javax.swing.JButton" name="btManagePlatforms"> - <Properties> - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> - <ResourceString bundle="org/netbeans/modules/gradle/java/customizer/Bundle.properties" key="CompileOptionsPanel.btManagePlatforms.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> - </Property> - </Properties> - <Events> - <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btManagePlatformsActionPerformed"/> - </Events> - </Component> - <Component class="javax.swing.JLabel" name="jLabel2"> - <Properties> - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> - <ResourceString bundle="org/netbeans/modules/gradle/java/customizer/Bundle.properties" key="CompileOptionsPanel.jLabel2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> - </Property> - <Property name="verticalAlignment" type="int" value="1"/> - </Properties> - </Component> - <Component class="javax.swing.JCheckBox" name="cbIncludeOpenProjects"> - <Properties> - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> - <ResourceString bundle="org/netbeans/modules/gradle/java/customizer/Bundle.properties" key="CompileOptionsPanel.cbIncludeOpenProjects.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> - </Property> - </Properties> - </Component> - <Component class="javax.swing.JLabel" name="lbIncludeOpenProjects"> - <Properties> - <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> - <ResourceString bundle="org/netbeans/modules/gradle/java/customizer/Bundle.properties" key="CompileOptionsPanel.lbIncludeOpenProjects.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> - </Property> - <Property name="verticalAlignment" type="int" value="1"/> - </Properties> - </Component> - </SubComponents> -</Form> diff --git a/java/gradle.java/src/org/netbeans/modules/gradle/java/customizer/CompileOptionsPanel.java b/java/gradle.java/src/org/netbeans/modules/gradle/java/customizer/CompileOptionsPanel.java deleted file mode 100644 index 60cfa871d1..0000000000 --- a/java/gradle.java/src/org/netbeans/modules/gradle/java/customizer/CompileOptionsPanel.java +++ /dev/null @@ -1,394 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.netbeans.modules.gradle.java.customizer; - -import org.netbeans.modules.gradle.api.GradleBaseProject; -import org.netbeans.modules.gradle.api.NbGradleProject; -import org.netbeans.modules.gradle.api.execute.RunUtils; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.prefs.BackingStoreException; -import java.util.prefs.Preferences; -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxModel; -import javax.swing.JCheckBox; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.ListCellRenderer; -import javax.swing.UIManager; -import javax.swing.plaf.UIResource; -import org.netbeans.api.java.platform.*; -import org.netbeans.api.project.Project; -import org.netbeans.modules.gradle.java.execute.JavaRunUtils; -import org.netbeans.spi.project.AuxiliaryProperties; -import org.netbeans.spi.project.ui.support.ProjectCustomizer; -import org.openide.util.Lookup; -import org.openide.util.NbBundle; -import org.openide.util.NbBundle.Messages; -import org.openide.util.WeakListeners; - -/** - * - * @author Laszlo Kishalmi - */ -public class CompileOptionsPanel extends javax.swing.JPanel { - - private static final Logger LOG = Logger.getLogger(CompileOptionsPanel.class.getName()); - public static final String HINT_JDK_PLATFORM = "netbeans.hint.jdkPlatform"; //NOI18N - private static final String PROP_PLATFORM_ID = "platform.ant.name"; //NOI18N - - final Project project; - private final ActionListener storeListener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - save(); - } - }; - - /** - * Creates new form CompileOptionsPanel - */ - public CompileOptionsPanel() { - this(null); - } - - private CompileOptionsPanel(Project project) { - this.project = project; - initComponents(); - setupCheckBox(cbAugmentedBuild, RunUtils.PROP_AUGMENTED_BUILD, true); - setupCheckBox(cbIncludeOpenProjects, RunUtils.PROP_INCLUDE_OPEN_PROJECTS, false); - setupPlatform(); - } - - @Messages({ - "# {0} - the name of the setting property", - "COMPILE_DISABLED_HINT=<html>This option is currently specificly controlled" - + " through your Gradle project (most likely through " - + "<b>gradle.properties</b>) by <br/> <b>netbeans.{0}</b> property." - }) - private void setupCheckBox(JCheckBox check, String property, boolean defaultValue) { - GradleBaseProject gbp = project != null ? GradleBaseProject.get(project) : null; - if (gbp != null) { - if (gbp.getNetBeansProperty(property) != null) { - check.setEnabled(false); - check.setSelected(Boolean.parseBoolean(gbp.getNetBeansProperty(property))); - check.setToolTipText(Bundle.COMPILE_DISABLED_HINT(property)); - } else { - Preferences prefs = NbGradleProject.getPreferences(project, false); - check.setSelected(prefs.getBoolean(property, defaultValue)); - } - } - } - - private void setupPlatform() { - - GradleBaseProject gbp = project != null ? GradleBaseProject.get(project) : null; - if (gbp != null) { - String platformId = gbp.getNetBeansProperty(RunUtils.PROP_JDK_PLATFORM); - if (platformId != null) { - cbPlatform.setEnabled(false); - cbPlatform.setToolTipText(Bundle.COMPILE_DISABLED_HINT(RunUtils.PROP_JDK_PLATFORM)); - lbPlatform.setEnabled(false); - lbPlatform.setToolTipText(Bundle.COMPILE_DISABLED_HINT(RunUtils.PROP_JDK_PLATFORM)); - } else { - Preferences prefs = NbGradleProject.getPreferences(project, false); - platformId = prefs.get(RunUtils.PROP_JDK_PLATFORM, null); - } - - JavaPlatform sel = JavaRunUtils.getActivePlatform(platformId).second(); - - PlatformsModel model = new PlatformsModel(); - model.setSelectedItem(sel != null ? sel : platformId); - cbPlatform.setModel(model); - cbPlatform.setRenderer(new PlatformsRenderer()); - } - } - - private void saveCheckBox(JCheckBox check, String property) { - GradleBaseProject gbp = project != null ? GradleBaseProject.get(project) : null; - if ((gbp != null) && (gbp.getNetBeansProperty(property) == null)) { - Preferences prefs = NbGradleProject.getPreferences(project, false); - prefs.putBoolean(property, check.isSelected()); - } - } - - private void savePlatform() { - GradleBaseProject gbp = project != null ? GradleBaseProject.get(project) : null; - if ((gbp != null) && (gbp.getNetBeansProperty(RunUtils.PROP_JDK_PLATFORM) == null)) { - Preferences prefs = NbGradleProject.getPreferences(project, false); - Object sel = cbPlatform.getModel().getSelectedItem(); - if (sel != null) { - String platformId = sel instanceof JavaPlatform ? ((JavaPlatform)sel).getProperties().get(PROP_PLATFORM_ID) : sel.toString(); - prefs.put(RunUtils.PROP_JDK_PLATFORM, platformId); - } - } - - } - - private void save() { - saveCheckBox(cbAugmentedBuild, RunUtils.PROP_AUGMENTED_BUILD); - saveCheckBox(cbIncludeOpenProjects, RunUtils.PROP_INCLUDE_OPEN_PROJECTS); - savePlatform(); - try { - NbGradleProject.getPreferences(project, false).flush(); - } catch (BackingStoreException ex) {} - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents - private void initComponents() { - - cbAugmentedBuild = new javax.swing.JCheckBox(); - lbPlatform = new javax.swing.JLabel(); - cbPlatform = new javax.swing.JComboBox<>(); - btManagePlatforms = new javax.swing.JButton(); - jLabel2 = new javax.swing.JLabel(); - cbIncludeOpenProjects = new javax.swing.JCheckBox(); - lbIncludeOpenProjects = new javax.swing.JLabel(); - - org.openide.awt.Mnemonics.setLocalizedText(cbAugmentedBuild, org.openide.util.NbBundle.getMessage(CompileOptionsPanel.class, "CompileOptionsPanel.cbAugmentedBuild.text")); // NOI18N - - lbPlatform.setLabelFor(cbPlatform); - org.openide.awt.Mnemonics.setLocalizedText(lbPlatform, org.openide.util.NbBundle.getMessage(CompileOptionsPanel.class, "CompileOptionsPanel.lbPlatform.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(btManagePlatforms, org.openide.util.NbBundle.getMessage(CompileOptionsPanel.class, "CompileOptionsPanel.btManagePlatforms.text")); // NOI18N - btManagePlatforms.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btManagePlatformsActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(CompileOptionsPanel.class, "CompileOptionsPanel.jLabel2.text")); // NOI18N - jLabel2.setVerticalAlignment(javax.swing.SwingConstants.TOP); - - org.openide.awt.Mnemonics.setLocalizedText(cbIncludeOpenProjects, org.openide.util.NbBundle.getMessage(CompileOptionsPanel.class, "CompileOptionsPanel.cbIncludeOpenProjects.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(lbIncludeOpenProjects, org.openide.util.NbBundle.getMessage(CompileOptionsPanel.class, "CompileOptionsPanel.lbIncludeOpenProjects.text")); // NOI18N - lbIncludeOpenProjects.setVerticalAlignment(javax.swing.SwingConstants.TOP); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(lbPlatform) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cbPlatform, 0, 222, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(btManagePlatforms)) - .addComponent(cbAugmentedBuild, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - .addGroup(layout.createSequentialGroup() - .addGap(25, 25, 25) - .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(21, 21, 21) - .addComponent(lbIncludeOpenProjects, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)) - .addGroup(layout.createSequentialGroup() - .addComponent(cbIncludeOpenProjects) - .addGap(0, 0, Short.MAX_VALUE))))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(4, 4, 4) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(lbPlatform) - .addComponent(cbPlatform, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(btManagePlatforms)) - .addGap(18, 18, 18) - .addComponent(cbAugmentedBuild) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cbIncludeOpenProjects) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(lbIncludeOpenProjects, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(156, Short.MAX_VALUE)) - ); - }// </editor-fold>//GEN-END:initComponents - - private JavaPlatform getSelPlatform () { - String platformId = project.getLookup().lookup(AuxiliaryProperties.class). - get(HINT_JDK_PLATFORM, true); - return JavaRunUtils.getActivePlatform(platformId).second(); - } - - - private void btManagePlatformsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btManagePlatformsActionPerformed - PlatformsCustomizer.showCustomizer(getSelPlatform()); - }//GEN-LAST:event_btManagePlatformsActionPerformed - - @NbBundle.Messages("category.BuildCompile=Compile") - @ProjectCustomizer.CompositeCategoryProvider.Registration( - projectType = NbGradleProject.GRADLE_PROJECT_TYPE, - category = "build/compile", - categoryLabel = "#category.BuildCompile", - position = 300) - public static ProjectCustomizer.CompositeCategoryProvider buildCompileCustomizerProvider() { - return new ProjectCustomizer.CompositeCategoryProvider() { - @Override - public ProjectCustomizer.Category createCategory(Lookup context) { - return null; - } - - @Override - public JComponent createComponent(ProjectCustomizer.Category category, Lookup context) { - Project project = context.lookup(Project.class); - CompileOptionsPanel customizer = new CompileOptionsPanel(project); - category.setStoreListener(customizer.storeListener); - return customizer; - } - }; - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btManagePlatforms; - private javax.swing.JCheckBox cbAugmentedBuild; - private javax.swing.JCheckBox cbIncludeOpenProjects; - private javax.swing.JComboBox<JavaPlatform> cbPlatform; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel lbIncludeOpenProjects; - private javax.swing.JLabel lbPlatform; - // End of variables declaration//GEN-END:variables - - private static class PlatformsModel extends AbstractListModel<JavaPlatform> implements ComboBoxModel<JavaPlatform>, PropertyChangeListener { - - private JavaPlatform[] data; - private Object sel; - - @SuppressWarnings("LeakingThisInConstructor") - public PlatformsModel() { - JavaPlatformManager jpm = JavaPlatformManager.getDefault(); - getPlatforms(jpm); - jpm.addPropertyChangeListener(WeakListeners.propertyChange(this, jpm)); - } - - @Override - public int getSize() { - return data.length; - } - - @Override - public JavaPlatform getElementAt(int index) { - return data[index]; - } - - @Override - public void setSelectedItem(Object anItem) { - sel = anItem; - fireContentsChanged(this, 0, data.length); - } - - @Override - public Object getSelectedItem() { - return sel; - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - String current = sel instanceof JavaPlatform ? ((JavaPlatform)sel).getProperties().get(PROP_PLATFORM_ID):sel.toString(); - JavaPlatformManager jpm = JavaPlatformManager.getDefault(); - getPlatforms(jpm); - JavaPlatform found = null; - for (int i = 0; i < data.length; i++) { - JavaPlatform pf = data[i]; - if (current.equals(pf.getProperties().get(PROP_PLATFORM_ID))) { - found = pf; - break; - } - } - setSelectedItem(found != null ? found : current); - } - - private void getPlatforms(JavaPlatformManager jpm) { - data = jpm.getPlatforms(null, new Specification ("j2se", null)); //NOI18N - if(LOG.isLoggable(Level.FINE)) { - for (JavaPlatform jp : data) { - LOG.log(Level.FINE, "Adding JavaPlaform: {0}", jp.getDisplayName()); - } - } - } - - } - - private class PlatformsRenderer extends JLabel implements ListCellRenderer, UIResource { - - @SuppressWarnings("OverridableMethodCallInConstructor") - public PlatformsRenderer() { - setOpaque(true); - } - - @Override - @NbBundle.Messages({"# {0} - platformId", "LBL_MissingPlatform=Missing platform: {0}"}) - public Component getListCellRendererComponent(JList list, Object value, - int index, boolean isSelected, - boolean cellHasFocus) { - // #89393: GTK needs name to render cell renderer "natively" - setName("ComboBox.listRenderer"); // NOI18N - if (value instanceof JavaPlatform) { - JavaPlatform jp = (JavaPlatform)value; - setText(jp.getDisplayName()); - if ( isSelected ) { - setBackground(list.getSelectionBackground()); - setForeground(list.getSelectionForeground()); - } else { - setBackground(list.getBackground()); - setForeground(list.getForeground()); - } - } else { - if (value == null) { - setText(""); - } else { - setText(Bundle.LBL_MissingPlatform(value)); - setForeground(UIManager.getColor("nb.errorForeground")); //NOI18N - } - } - return this; - } - - // #89393: GTK needs name to render cell renderer "natively" - @Override - public String getName() { - String name = super.getName(); - return name == null ? "ComboBox.renderer" : name; // NOI18N - } - } // end of PlatformsRenderer - -} diff --git a/java/gradle.java/src/org/netbeans/modules/gradle/java/execute/JavaRunUtils.java b/java/gradle.java/src/org/netbeans/modules/gradle/java/execute/JavaRunUtils.java index f637a5d03c..046aa5357c 100644 --- a/java/gradle.java/src/org/netbeans/modules/gradle/java/execute/JavaRunUtils.java +++ b/java/gradle.java/src/org/netbeans/modules/gradle/java/execute/JavaRunUtils.java @@ -18,15 +18,12 @@ */ package org.netbeans.modules.gradle.java.execute; -import java.util.prefs.Preferences; import org.netbeans.api.java.platform.JavaPlatform; import org.netbeans.api.java.platform.JavaPlatformManager; import org.netbeans.api.java.platform.Specification; import org.netbeans.api.project.Project; -import org.netbeans.modules.gradle.api.GradleBaseProject; -import org.netbeans.modules.gradle.api.NbGradleProject; -import static org.netbeans.modules.gradle.api.execute.RunUtils.PROP_COMPILE_ON_SAVE; -import static org.netbeans.modules.gradle.api.execute.RunUtils.PROP_JDK_PLATFORM; +import org.netbeans.modules.gradle.api.execute.RunUtils; +import org.netbeans.modules.gradle.spi.execute.JavaRuntimeManager; import org.openide.util.Pair; /** @@ -37,8 +34,17 @@ public class JavaRunUtils { private JavaRunUtils() {} + /** + * It is unlikely that the compile on save feature would be implemented for + * Gradle, as Gradle's continuous build feature provides a compelling + * alternative. + * + * @return {@code false} + * @deprecated + */ + @Deprecated public static boolean isCompileOnSaveEnabled(Project project) { - return isOptionEnabled(project, PROP_COMPILE_ON_SAVE, false); + return false; } /** @@ -67,26 +73,8 @@ public class JavaRunUtils { } public static Pair<String, JavaPlatform> getActivePlatform(Project project) { - Preferences prefs = NbGradleProject.getPreferences(project, false); - String platformId = prefs.get(PROP_JDK_PLATFORM, null); - if (platformId == null) { - GradleBaseProject gbp = GradleBaseProject.get(project); - platformId = gbp != null ? gbp.getNetBeansProperty(PROP_JDK_PLATFORM) : null; - } - return getActivePlatform(platformId); - } - - private static boolean isOptionEnabled(Project project, String option, boolean defaultValue) { - GradleBaseProject gbp = GradleBaseProject.get(project); - if (gbp != null) { - String value = gbp.getNetBeansProperty(option); - if (value != null) { - return Boolean.valueOf(value); - } else { - return NbGradleProject.getPreferences(project, false).getBoolean(option, defaultValue); - } - } - return false; + JavaRuntimeManager.JavaRuntime rt = RunUtils.getActiveRuntime(project); + return getActivePlatform(rt.getId()); } } diff --git a/java/gradle.java/src/org/netbeans/modules/gradle/java/execute/LookupProviders.java b/java/gradle.java/src/org/netbeans/modules/gradle/java/execute/LookupProviders.java index 41462bc76e..87956d5c0c 100644 --- a/java/gradle.java/src/org/netbeans/modules/gradle/java/execute/LookupProviders.java +++ b/java/gradle.java/src/org/netbeans/modules/gradle/java/execute/LookupProviders.java @@ -30,17 +30,6 @@ import org.openide.util.lookup.Lookups; */ public class LookupProviders { - @LookupProvider.Registration(projectType = NbGradleProject.GRADLE_PROJECT_TYPE) - public static LookupProvider createProvider() { - return new LookupProvider() { - @Override - public Lookup createAdditionalLookup(Lookup baseContext) { - Project project = baseContext.lookup(Project.class); - return Lookups.singleton(new GradleJavaPlatformProviderImpl(project)); - } - }; - } - @LookupProvider.Registration(projectType = NbGradleProject.GRADLE_PLUGIN_TYPE + "/java-base") public static LookupProvider createJavaBaseProvider() { return new LookupProvider() { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists