This is an automated email from the ASF dual-hosted git repository. mbien 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 82374c2662 make maven project properties window aware of the javac release option new d5c444f151 Merge pull request #5744 from mbien/project-properties-release 82374c2662 is described below commit 82374c2662111cf77c5b0143a195c43b1ba25003 Author: Michael Bien <mbie...@gmail.com> AuthorDate: Thu Mar 30 04:42:13 2023 +0200 make maven project properties window aware of the javac release option the properties window will now update the release option if it can be found and will continue to use source/target otherwise. it will also make sure that both are not used at the same time. --- .../org/netbeans/modules/maven/api/ModelUtils.java | 17 ++++++++++----- .../modules/maven/customizer/SourcesPanel.java | 24 ++++++++++++++++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/java/maven/src/org/netbeans/modules/maven/api/ModelUtils.java b/java/maven/src/org/netbeans/modules/maven/api/ModelUtils.java index 2f6b82485a..8cd39a6216 100644 --- a/java/maven/src/org/netbeans/modules/maven/api/ModelUtils.java +++ b/java/maven/src/org/netbeans/modules/maven/api/ModelUtils.java @@ -305,13 +305,13 @@ public final class ModelUtils { } /** - * Sets the Java source level of a project. + * Sets the Java source and target level of a project (will set release if previously set). * Use {@link PluginPropertyUtils#getPluginProperty(org.netbeans.api.project.Project,String,String,String,String,String)} first * ({@link Constants#GROUP_APACHE_PLUGINS}, {@link Constants#PLUGIN_COMPILER}, {@link Constants#SOURCE_PARAM}, {@code "compile"}) * to make sure that the current level is actually not what you want. * - * Please Note: THis method will not take existing configuration into account, especially the use of property (maven.compiler.source, maven.compiler.target) - * instead of plugin configuration is ignored. + * Please Note: This method will not take existing properties into account (maven.compiler.source, maven.compiler.target or maven.compiler.release), + * it is only updating the plugin configuration itself. * @param mdl a POM model * @param sourceLevel the desired source level * @since 2.19 @@ -339,8 +339,15 @@ public final class ModelUtils { conf = mdl.getFactory().createConfiguration(); plugin.setConfiguration(conf); } - conf.setSimpleParameter(Constants.SOURCE_PARAM, sourceLevel); - conf.setSimpleParameter(Constants.TARGET_PARAM, sourceLevel); + if (conf.getSimpleParameter(Constants.RELEASE_PARAM) != null) { + conf.setSimpleParameter(Constants.RELEASE_PARAM, sourceLevel); + conf.setSimpleParameter(Constants.SOURCE_PARAM, null); + conf.setSimpleParameter(Constants.TARGET_PARAM, null); + } else { + conf.setSimpleParameter(Constants.SOURCE_PARAM, sourceLevel); + conf.setSimpleParameter(Constants.TARGET_PARAM, sourceLevel); + } + } /** diff --git a/java/maven/src/org/netbeans/modules/maven/customizer/SourcesPanel.java b/java/maven/src/org/netbeans/modules/maven/customizer/SourcesPanel.java index 52b6e0965c..2b6203e9b3 100644 --- a/java/maven/src/org/netbeans/modules/maven/customizer/SourcesPanel.java +++ b/java/maven/src/org/netbeans/modules/maven/customizer/SourcesPanel.java @@ -76,8 +76,10 @@ public class SourcesPanel extends JPanel implements HelpCtx.Provider { @Override public void performOperation(POMModel model) { String s = PluginPropertyUtils.getPluginProperty(handle.getProject(), Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER, "source", null, null); - String t = PluginPropertyUtils.getPluginProperty(handle.getProject(), Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER, "source", null, null); - if (s == null && t == null) { + String t = PluginPropertyUtils.getPluginProperty(handle.getProject(), Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER, "target", null, null); + String r = PluginPropertyUtils.getPluginProperty(handle.getProject(), Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER, "release", null, null); + if (s == null && t == null && r == null) { + // set in project properties Project p = model.getProject(); if (p != null) { Properties prop = p.getProperties(); @@ -85,11 +87,25 @@ public class SourcesPanel extends JPanel implements HelpCtx.Provider { prop = model.getFactory().createProperties(); p.setProperties(prop); } - prop.setProperty("maven.compiler.source", sourceLevel); - prop.setProperty("maven.compiler.target", sourceLevel); + if (prop.getProperty("maven.compiler.release") != null) { + prop.setProperty("maven.compiler.release", sourceLevel); + prop.setProperty("maven.compiler.source", null); + prop.setProperty("maven.compiler.target", null); + } else { + prop.setProperty("maven.compiler.source", sourceLevel); + prop.setProperty("maven.compiler.target", sourceLevel); + } } } else { + // set in plugin config ModelUtils.setSourceLevel(model, sourceLevel); + // clear props, just in case + if (model.getProject() != null && model.getProject().getProperties() != null) { + Properties prop = model.getProject().getProperties(); + prop.setProperty("maven.compiler.source", null); + prop.setProperty("maven.compiler.target", null); + prop.setProperty("maven.compiler.release", null); + } } } }; --------------------------------------------------------------------- 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