2424import java .io .FileOutputStream ;
2525import java .io .IOException ;
2626import java .io .OutputStream ;
27- import java .nio .file .Files ;
28- import java .nio .file .Path ;
2927import java .util .Collections ;
3028import java .util .List ;
3129import java .util .Properties ;
4947import org .netbeans .modules .maven .model .pom .Project ;
5048import org .netbeans .modules .maven .model .pom .Repository ;
5149import org .netbeans .modules .maven .model .pom .RepositoryPolicy ;
50+ import org .netbeans .modules .maven .options .MavenVersionSettings ;
5251import org .netbeans .modules .maven .spi .newproject .CreateProjectBuilder ;
5352import org .openide .util .Exceptions ;
5453
5857 */
5958final class NBMNativeMWI {
6059
61- static void instantiate (ProjectInfo vi , File projFile , String version , boolean useOsgi , MavenProject mp ) {
60+ static void instantiate (ProjectInfo vi , File projFile , String nbVersion , boolean useOsgi , MavenProject mp ) {
6261 CreateProjectBuilder builder = new CreateProjectBuilder (projFile , vi .groupId , vi .artifactId , vi .version )
6362 .setPackageName (vi .packageName )
6463 .setPackaging ("nbm" )
6564 .setAdditionalNonPomWork (new AdditionalFiles ())
66- .setAdditionalOperations (new AdditionalOperations (version , useOsgi ));
65+ .setAdditionalOperations (new AdditionalOperations (nbVersion , useOsgi ));
6766 if (mp != null ) {
6867 builder = builder .setParentProject (mp );
6968 }
@@ -237,7 +236,6 @@ public void performOperation(POMModel model) {
237236 //nbm-maven-plugin
238237 boolean addPlugin = true ;
239238 String managedPVersion = null ;
240- String pVersion = MavenNbModuleImpl .getLatestNbmPluginVersion ();
241239// boolean useOsgiDepsSet = false;
242240 if (parent != null ) {
243241 //TODO do we want to support the case when the plugin is defined in parent pom with inherited=true?
@@ -259,12 +257,13 @@ public void performOperation(POMModel model) {
259257 }
260258 }
261259 }
260+ MavenVersionSettings settings = MavenVersionSettings .getDefault ();
262261 if (addPlugin ) {
263262 Plugin p = model .getFactory ().createPlugin ();
264263 p .setGroupId (MavenNbModuleImpl .GROUPID_APACHE );
265264 p .setArtifactId (MavenNbModuleImpl .NBM_PLUGIN );
266265 if (managedPVersion == null ) {
267- p .setVersion (pVersion );
266+ p .setVersion (MavenNbModuleImpl . getLatestNbmPluginVersion () );
268267 }
269268 p .setExtensions (true );
270269 if (useOsgi ) {
@@ -278,52 +277,44 @@ public void performOperation(POMModel model) {
278277 //now comes the compiler plugin
279278 addPlugin = true ;
280279 managedPVersion = null ;
281- String source = null ;
282- String target = null ;
283- pVersion = "3.11.0" ;
284280 if (parent != null ) {
285281 //TODO do we want to support the case when the plugin is defined in parent pom with inherited=true?
286282 PluginManagement pm = parent .getPluginManagement ();
287283 if (pm != null ) {
288- for (org .apache .maven .model .Plugin p : pm .getPlugins ()) {
289- if (Constants .GROUP_APACHE_PLUGINS .equals (p .getGroupId ()) && Constants .PLUGIN_COMPILER .equals (p .getArtifactId ())) {
290- managedPVersion = p .getVersion ();
291- Xpp3Dom conf = (Xpp3Dom ) p .getConfiguration ();
292- if (conf != null ) {
293- Xpp3Dom sourceEl = conf .getChild ("source" );
294- if (sourceEl != null ) {
295- source = sourceEl .getValue ();
296- }
297- Xpp3Dom targetEl = conf .getChild ("target" );
298- if (targetEl != null ) {
299- target = targetEl .getValue ();
284+ if (parent .getProperties ().getProperty ("maven.compiler.release" ) != null ) {
285+ addPlugin = false ;
286+ } else {
287+ for (org .apache .maven .model .Plugin p : pm .getPlugins ()) {
288+ if (Constants .GROUP_APACHE_PLUGINS .equals (p .getGroupId ()) && Constants .PLUGIN_COMPILER .equals (p .getArtifactId ())) {
289+ managedPVersion = p .getVersion ();
290+ Xpp3Dom conf = (Xpp3Dom ) p .getConfiguration ();
291+ if (conf != null ) {
292+ if ( conf .getChild ("release" ) != null
293+ || conf .getChild ("source" ) != null
294+ || conf .getChild ("target" ) != null ) {
295+ addPlugin = false ;
296+ }
300297 }
298+ break ;
301299 }
302- break ;
303300 }
304301 }
305302 }
306303 }
307- addPlugin = target == null || source == null ;
308304 if (addPlugin ) {
309305 Plugin p = model .getFactory ().createPlugin ();
310306 p .setGroupId (Constants .GROUP_APACHE_PLUGINS );
311307 p .setArtifactId (Constants .PLUGIN_COMPILER );
312308 if (managedPVersion == null ) {
313- p .setVersion (pVersion );
309+ p .setVersion (settings . getVersion ( Constants . GROUP_APACHE_PLUGINS , Constants . PLUGIN_COMPILER ) );
314310 }
315- Configuration c = model .getFactory ().createConfiguration ();
316- c .setSimpleParameter ("source" , "1.8" );
317- c .setSimpleParameter ("target" , "1.8" );
318- p .setConfiguration (c );
319311 getOrCreateBuild (model ).addPlugin (p );
312+ model .getProject ().getProperties ().setProperty ("maven.compiler.release" , "17" );
320313 }
321314
322315 //now the jar plugin
323- addPlugin = true ;
324316 managedPVersion = null ;
325317 String useManifest = null ;
326- pVersion = "3.3.0" ;
327318 if (parent != null ) {
328319 //TODO do we want to support the case when the plugin is defined in parent pom with inherited=true?
329320 PluginManagement pm = parent .getPluginManagement ();
@@ -359,6 +350,7 @@ public void performOperation(POMModel model) {
359350 p .setGroupId (Constants .GROUP_APACHE_PLUGINS );
360351 p .setArtifactId (Constants .PLUGIN_JAR );
361352 if (managedPVersion == null ) {
353+ String pVersion = settings .getVersion (Constants .GROUP_APACHE_PLUGINS , Constants .PLUGIN_JAR );
362354 p .setVersion (pVersion );
363355 managedPVersion = pVersion ;
364356 }
0 commit comments