2121import java .io .InputStream ;
2222import java .util .List ;
2323import java .util .Properties ;
24- import org .apache .commons .io .FilenameUtils ;
25- import org .apache .commons .io .IOCase ;
2624import org .apache .maven .execution .MavenSession ;
2725import org .apache .maven .model .io .xpp3 .MavenXpp3Reader ;
2826import org .apache .maven .plugin .AbstractMojo ;
3129import org .apache .maven .plugins .annotations .Mojo ;
3230import org .apache .maven .plugins .annotations .Parameter ;
3331import org .apache .maven .project .MavenProject ;
32+ import org .codehaus .plexus .util .SelectorUtils ;
3433import org .eclipse .aether .RepositorySystem ;
3534import org .eclipse .aether .artifact .Artifact ;
3635import org .eclipse .aether .artifact .DefaultArtifact ;
@@ -48,6 +47,49 @@ private static String getId(Bom bom) {
4847 return bom .getGroupId () + ":" + bom .getArtifactId () + ":" + bom .getVersion ();
4948 }
5049
50+ private static void validateBom (Bom bom ) throws MojoExecutionException {
51+ if (bom .getGroupId () == null || bom .getGroupId ().isBlank ()) {
52+ throw new MojoExecutionException ("BOM groupId is required" );
53+ }
54+ if (bom .getArtifactId () == null || bom .getArtifactId ().isBlank ()) {
55+ throw new MojoExecutionException ("BOM artifactId is required" );
56+ }
57+ if (bom .getVersion () == null || bom .getVersion ().isBlank ()) {
58+ throw new MojoExecutionException ("BOM version is required" );
59+ }
60+ if (bom .getIncludes () == null || bom .getIncludes ().isEmpty ()) {
61+ throw new MojoExecutionException ("BOM has no includes" );
62+ }
63+ if (bom .getPrefix () == null || bom .getPrefix ().isBlank ()) {
64+ throw new MojoExecutionException ("BOM has no prefix" );
65+ }
66+ }
67+
68+ private static boolean isPropertyIncluded (String key , Bom bom ) {
69+ boolean included = false ;
70+ boolean excluded = false ;
71+
72+ for (var include : bom .getIncludes ()) {
73+ if (SelectorUtils .match (include , key , bom .isCaseSensitive ())) {
74+ included = true ;
75+ break ;
76+ }
77+ }
78+ if (!included ) {
79+ return false ;
80+ }
81+
82+ if (bom .getExcludes () != null ) {
83+ for (var exclude : bom .getExcludes ()) {
84+ if (SelectorUtils .match (exclude , key , bom .isCaseSensitive ())) {
85+ excluded = true ;
86+ break ;
87+ }
88+ }
89+ }
90+ return !excluded ;
91+ }
92+
5193 @ Parameter (defaultValue = "${project}" , readonly = true )
5294 private MavenProject project ;
5395
@@ -72,45 +114,15 @@ public void execute() throws MojoExecutionException {
72114 for (var bom : boms ) {
73115 getLog ().info ("Processing BOM: " + getId (bom ));
74116 validateBom (bom );
75-
76- IOCase iOCase = IOCase .SENSITIVE ;
77- if (!bom .isCaseSensitive ()) {
78- iOCase = IOCase .INSENSITIVE ;
79- }
80-
81117 try {
82118 var properties = getBomProperties (bom );
83119 var count = 0 ;
84-
85120 for (var entry : properties .entrySet ()) {
86121 var key = (String ) entry .getKey ();
87-
88- boolean included = false ;
89- boolean excluded = false ;
90-
91- for (var include : bom .getIncludes ()) {
92- if (FilenameUtils .wildcardMatch (key , include , iOCase )) {
93- included = true ;
94- break ;
95- }
96- }
97- if (!included ) {
98- continue ;
122+ if (isPropertyIncluded (key , bom )) {
123+ props .put (bom .getPrefix () + "." + key , entry .getValue ());
124+ count ++;
99125 }
100-
101- if (bom .getExcludes () != null ) {
102- for (var exclude : bom .getExcludes ()) {
103- if (FilenameUtils .wildcardMatch (key , exclude , iOCase )) {
104- excluded = true ;
105- break ;
106- }
107- }
108- }
109- if (excluded ) {
110- continue ;
111- }
112- props .put (bom .getPrefix () + "." + key , entry .getValue ());
113- count ++;
114126 }
115127 getLog ().info ("Added " + count + " properties with prefix: " + bom .getPrefix ());
116128 } catch (Exception ex ) {
@@ -120,24 +132,6 @@ public void execute() throws MojoExecutionException {
120132 }
121133 }
122134
123- private void validateBom (Bom bom ) throws MojoExecutionException {
124- if (bom .getGroupId () == null || bom .getGroupId ().isBlank ()) {
125- throw new MojoExecutionException ("BOM groupId is required" );
126- }
127- if (bom .getArtifactId () == null || bom .getArtifactId ().isBlank ()) {
128- throw new MojoExecutionException ("BOM artifactId is required" );
129- }
130- if (bom .getVersion () == null || bom .getVersion ().isBlank ()) {
131- throw new MojoExecutionException ("BOM version is required" );
132- }
133- if (bom .getIncludes () == null || bom .getIncludes ().isEmpty ()) {
134- throw new MojoExecutionException ("BOM has no includes" );
135- }
136- if (bom .getPrefix () == null || bom .getPrefix ().isBlank ()) {
137- throw new MojoExecutionException ("BOM has no scope" );
138- }
139- }
140-
141135 private Properties getBomProperties (Bom bom ) throws Exception {
142136 var file = resolveBomFile (bom );
143137 try (InputStream is = new FileInputStream (file )) {
0 commit comments