5555import org .apache .maven .project .MavenProject ;
5656
5757import org .eclipse .m2e .core .MavenPlugin ;
58+ import org .eclipse .m2e .core .embedder .IMaven .ConfigurationElement ;
59+ import org .eclipse .m2e .core .embedder .IMaven .ConfigurationParameter ;
5860import org .eclipse .m2e .core .internal .M2EUtils ;
5961import org .eclipse .m2e .core .project .IMavenProjectFacade ;
6062import org .eclipse .m2e .core .project .IProjectConfigurationManager ;
@@ -311,57 +313,41 @@ protected void addProjectSourceFolders(IClasspathDescriptor classpath, Map<Strin
311313 IPath [] inclusionTest = new IPath [0 ];
312314 IPath [] exclusionTest = new IPath [0 ];
313315
314- String mainSourceEncoding = null ;
315- String testSourceEncoding = null ;
316+ ConfigurationParameter mainSourceEncoding = null ;
317+ ConfigurationParameter testSourceEncoding = null ;
316318
317319 String mainResourcesEncoding = null ;
318320 String testResourcesEncoding = null ;
319321
320322 List <MojoExecution > executions = getCompilerMojoExecutions (request , mon .newChild (1 ));
321323 for (MojoExecution compile : executions ) {
322324 if (isCompileExecution (compile , mavenProject , options , monitor )) {
323- mainSourceEncoding = maven .getMojoParameterValue (mavenProject , compile , "encoding" , String .class , monitor ); //$NON-NLS-1$
324- try {
325- inclusion = toPaths (
326- maven .getMojoParameterValue (mavenProject , compile , "includes" , String [].class , monitor )); //$NON-NLS-1$
327- } catch (CoreException ex ) {
328- log .error ("Failed to determine compiler inclusions, assuming defaults" , ex );
329- }
330- try {
331- exclusion = toPaths (
332- maven .getMojoParameterValue (mavenProject , compile , "excludes" , String [].class , monitor )); //$NON-NLS-1$
333- } catch (CoreException ex ) {
334- log .error ("Failed to determine compiler exclusions, assuming defaults" , ex );
335- }
325+ ConfigurationElement mojoConfig = maven .getMojoConfiguration (mavenProject , compile , monitor );
326+ mainSourceEncoding = mojoConfig .get ("encoding" ); //$NON-NLS-1$
327+ inclusion = toPaths (mojoConfig .get ("includes" )); //$NON-NLS-1$
328+ exclusion = toPaths (mojoConfig .get ("excludes" )); //$NON-NLS-1$
336329 }
337330 }
338331
339332 for (MojoExecution compile : executions ) {
340333 if (isTestCompileExecution (compile , mavenProject , options , monitor )) {
341- testSourceEncoding = maven .getMojoParameterValue (mavenProject , compile , "encoding" , String .class , monitor ); //$NON-NLS-1$
342- try {
343- inclusionTest = toPaths (
344- maven .getMojoParameterValue (mavenProject , compile , "testIncludes" , String [].class , monitor )); //$NON-NLS-1$
345- } catch (CoreException ex ) {
346- log .error ("Failed to determine compiler test inclusions, assuming defaults" , ex );
347- }
348- try {
349- exclusionTest = toPaths (
350- maven .getMojoParameterValue (mavenProject , compile , "testExcludes" , String [].class , monitor )); //$NON-NLS-1$
351- } catch (CoreException ex ) {
352- log .error ("Failed to determine compiler test exclusions, assuming defaults" , ex );
353- }
334+ ConfigurationElement mojoConfiguration = maven .getMojoConfiguration (mavenProject , compile , monitor );
335+ testSourceEncoding = mojoConfiguration .get ("encoding" );
336+ inclusionTest = toPaths (mojoConfiguration .get ("testIncludes" )); //$NON-NLS-1$
337+ exclusionTest = toPaths (mojoConfiguration .get ("testExcludes" )); //$NON-NLS-1$
354338 }
355339 }
356340
357341 for (MojoExecution resources : projectFacade .getMojoExecutions (RESOURCES_PLUGIN_GROUP_ID ,
358342 RESOURCES_PLUGIN_ARTIFACT_ID , mon .newChild (1 ), GOAL_RESOURCES )) {
359- mainResourcesEncoding = maven .getMojoParameterValue (mavenProject , resources , "encoding" , String .class , monitor ); //$NON-NLS-1$
343+ mainResourcesEncoding = maven .getMojoConfiguration (mavenProject , resources , monitor ).get ("encoding" ) //$NON-NLS-1$
344+ .as (String .class );
360345 }
361346
362347 for (MojoExecution resources : projectFacade .getMojoExecutions (RESOURCES_PLUGIN_GROUP_ID ,
363348 RESOURCES_PLUGIN_ARTIFACT_ID , mon .newChild (1 ), GOAL_TESTRESOURCES )) {
364- testResourcesEncoding = maven .getMojoParameterValue (mavenProject , resources , "encoding" , String .class , monitor ); //$NON-NLS-1$
349+ testResourcesEncoding = maven .getMojoConfiguration (mavenProject , resources , monitor ).get ("encoding" ) //$NON-NLS-1$
350+ .as (String .class );
365351 }
366352 addSourceDirs (classpath , project , mavenProject .getCompileSourceRoots (), classes .getFullPath (), inclusion ,
367353 exclusion , mainSourceEncoding , mon .newChild (1 ), false );
@@ -391,16 +377,16 @@ protected boolean isCompileExecution(MojoExecution execution, MavenProject maven
391377
392378 private boolean isCompliant (MojoExecution execution , MavenProject mavenProject , Map <String , String > options ,
393379 IProgressMonitor monitor ) throws CoreException {
394- String release = maven .getMojoParameterValue (mavenProject , execution , "release" , String .class , monitor ); //$NON-NLS-1$
380+ String release = maven .getMojoConfiguration (mavenProject , execution , monitor ). get ( "release" ). as ( String .class ); //$NON-NLS-1$
395381 if (release != null && !sanitizeJavaVersion (release ).equals (options .get (JavaCore .COMPILER_COMPLIANCE ))) {
396382 return false ;
397383 }
398384 if (release == null ) {
399- String source = maven .getMojoParameterValue (mavenProject , execution , "source" , String .class , monitor ); //$NON-NLS-1$
385+ String source = maven .getMojoConfiguration (mavenProject , execution , monitor ). get ( "source" ). as ( String .class ); //$NON-NLS-1$
400386 if (source != null && !sanitizeJavaVersion (source ).equals (options .get (JavaCore .COMPILER_SOURCE ))) {
401387 return false ;
402388 }
403- String target = maven .getMojoParameterValue (mavenProject , execution , "target" , String .class , monitor ); //$NON-NLS-1$
389+ String target = maven .getMojoConfiguration (mavenProject , execution , monitor ). get ( "target" ). as ( String .class ); //$NON-NLS-1$
404390 if (target != null
405391 && !sanitizeJavaVersion (target ).equals (options .get (JavaCore .COMPILER_CODEGEN_TARGET_PLATFORM ))) {
406392 return false ;
@@ -409,22 +395,17 @@ private boolean isCompliant(MojoExecution execution, MavenProject mavenProject,
409395 return true ;
410396 }
411397
412- private IPath [] toPaths (String [] values ) {
413- if (values == null ) {
398+ private IPath [] toPaths (ConfigurationParameter configParameter ) {
399+ if (! configParameter . exists () ) {
414400 return new IPath [0 ];
415401 }
416- IPath [] paths = new IPath [values .length ];
417- for (int i = 0 ; i < values .length ; i ++ ) {
418- if (values [i ] != null && !"" .equals (values [i ].trim ())) {
419- paths [i ] = new Path (values [i ]);
420- }
421- }
422- return paths ;
402+ return Arrays .stream (configParameter .as (String [].class )).filter (v -> v != null && !v .isBlank ()).map (Path ::new )
403+ .toArray (Path []::new );
423404 }
424405
425406 private void addSourceDirs (IClasspathDescriptor classpath , IProject project , List <String > sourceRoots ,
426- IPath outputPath , IPath [] inclusion , IPath [] exclusion , String sourceEncoding , IProgressMonitor monitor ,
427- boolean addTestFlag ) throws CoreException {
407+ IPath outputPath , IPath [] inclusion , IPath [] exclusion , ConfigurationParameter sourceEncoding ,
408+ IProgressMonitor monitor , boolean addTestFlag ) throws CoreException {
428409
429410 for (String sourceRoot : sourceRoots ) {
430411 IFolder sourceFolder = getFolder (project , sourceRoot );
@@ -445,7 +426,7 @@ private void addSourceDirs(IClasspathDescriptor classpath, IProject project, Lis
445426
446427 // Set folder encoding (null = platform/container default)
447428 if (sourceFolder .exists ()) {
448- sourceFolder .setDefaultCharset (sourceEncoding , monitor );
429+ sourceFolder .setDefaultCharset (sourceEncoding . exists () ? sourceEncoding . as ( String . class ) : null , monitor );
449430 }
450431
451432 IClasspathEntryDescriptor enclosing = getEnclosingEntryDescriptor (classpath , sourceFolder .getFullPath ());
@@ -619,8 +600,8 @@ protected void addJavaProjectOptions(Map<String, String> options, ProjectConfigu
619600 || isEnablePreviewFeatures (request .mavenProject (), execution , monitor );
620601
621602 // process -err:+deprecation , -warn:-serial ...
622- for (Object o : maven .getMojoParameterValue (request .mavenProject (), execution , "compilerArgs" , List . class ,
623- monitor )) {
603+ for (Object o : maven .getMojoConfiguration (request .mavenProject (), execution , monitor ). get ( "compilerArgs" )
604+ . as ( List . class )) {
624605 if (o instanceof String compilerArg ) {
625606 boolean err = false /*, warn = false*/ ;
626607 String [] settings = new String [0 ];
@@ -706,15 +687,16 @@ private boolean isGenerateParameters(MavenProject mavenProject, MojoExecution ex
706687 Boolean generateParameters = null ;
707688 //1st, check the parameters option
708689 try {
709- generateParameters = maven .getMojoParameterValue (mavenProject , execution , "parameters" , Boolean .class , monitor );//$NON-NLS-1$
690+ generateParameters = maven .getMojoConfiguration (mavenProject , execution , monitor ).get ("parameters" ) //$NON-NLS-1$
691+ .as (Boolean .class );
710692 } catch (Exception ex ) {
711693 //ignore
712694 }
713695
714696 //2nd, check the parameters flag in the compilerArgs list
715697 if (!Boolean .TRUE .equals (generateParameters )) {
716698 try {
717- List <?> args = maven .getMojoParameterValue (mavenProject , execution , "compilerArgs" , List .class , monitor );//$NON-NLS-1$
699+ List <?> args = maven .getMojoConfiguration (mavenProject , execution , monitor ). get ( "compilerArgs" ). as ( List .class );//$NON-NLS-1$
718700 if (args != null ) {
719701 generateParameters = args .contains (JavaSettingsUtils .PARAMETERS_JVM_FLAG );
720702 }
@@ -726,8 +708,8 @@ private boolean isGenerateParameters(MavenProject mavenProject, MojoExecution ex
726708 //3rd, check the parameters flag in the compilerArgument String
727709 if (!Boolean .TRUE .equals (generateParameters )) {
728710 try {
729- String compilerArgument = maven .getMojoParameterValue (mavenProject , execution , "compilerArgument" , String . class , //$NON-NLS-1$
730- monitor );
711+ String compilerArgument = maven .getMojoConfiguration (mavenProject , execution , monitor ). get ( "compilerArgument" )
712+ . as ( String . class );
731713 if (compilerArgument != null ) {
732714 generateParameters = compilerArgument .contains (JavaSettingsUtils .PARAMETERS_JVM_FLAG );
733715 }
@@ -743,7 +725,7 @@ private boolean isEnablePreviewFeatures(MavenProject mavenProject, MojoExecution
743725 IProgressMonitor monitor ) {
744726 //1st, check the --enable-preview flag in the compilerArgs list
745727 try {
746- List <?> args = maven .getMojoParameterValue (mavenProject , execution , "compilerArgs" , List .class , monitor );//$NON-NLS-1$
728+ List <?> args = maven .getMojoConfiguration (mavenProject , execution , monitor ). get ( "compilerArgs" ). as ( List .class );//$NON-NLS-1$
747729 if (args != null && args .contains (JavaSettingsUtils .ENABLE_PREVIEW_JVM_FLAG )) {
748730 return true ;
749731 }
@@ -753,8 +735,8 @@ private boolean isEnablePreviewFeatures(MavenProject mavenProject, MojoExecution
753735
754736 //2nd, check the --enable-preview flag in the compilerArgument String
755737 try {
756- String compilerArgument = maven .getMojoParameterValue (mavenProject , execution , "compilerArgument" , String . class , //$NON-NLS-1$
757- monitor );
738+ String compilerArgument = maven .getMojoConfiguration (mavenProject , execution , monitor ). get ( "compilerArgument" )
739+ . as ( String . class );
758740 if (compilerArgument != null && compilerArgument .contains (JavaSettingsUtils .ENABLE_PREVIEW_JVM_FLAG )) {
759741 return true ;
760742 }
@@ -804,7 +786,7 @@ private String getCompilerLevel(MavenProject mavenProject, MojoExecution executi
804786 int levelIdx = getLevelIndex (source , levels );
805787
806788 try {
807- source = maven .getMojoParameterValue (mavenProject , execution , parameter , String .class , monitor );
789+ source = maven .getMojoConfiguration (mavenProject , execution , monitor ). get ( parameter ). as ( String .class );
808790 } catch (CoreException ex ) {
809791 log .error ("Failed to determine compiler " + parameter + " setting, assuming default" , ex );
810792 }
@@ -958,7 +940,7 @@ private List<String> getCompilerArguments(MavenProject mavenProject, MojoExecuti
958940
959941 //1st, get the arguments in the compilerArgs list
960942 try {
961- List <?> args = maven .getMojoParameterValue (mavenProject , execution , "compilerArgs" , List .class , monitor );//$NON-NLS-1$
943+ List <?> args = maven .getMojoConfiguration (mavenProject , execution , monitor ). get ( "compilerArgs" ). as ( List .class );//$NON-NLS-1$
962944 if (args != null ) {//$NON-NLS-1$
963945 args .stream ().filter (a -> a != null ).forEach (a -> arguments .add (a .toString ()));
964946 }
0 commit comments