64
64
import org .openrewrite .marker .*;
65
65
import org .openrewrite .marker .ci .BuildEnvironment ;
66
66
import org .openrewrite .polyglot .*;
67
+ import org .openrewrite .properties .PropertiesParser ;
67
68
import org .openrewrite .quark .Quark ;
68
69
import org .openrewrite .quark .QuarkParser ;
69
70
import org .openrewrite .remote .Remote ;
@@ -822,8 +823,6 @@ public Stream<SourceFile> parse(Project subproject, Set<Path> alreadyParsed, Exe
822
823
823
824
SourceFileStream gradleWrapperFiles = parseGradleWrapperFiles (exclusions , alreadyParsed , ctx );
824
825
sourceFileStream = sourceFileStream .concat (gradleWrapperFiles , gradleWrapperFiles .size ());
825
- SourceFileStream gradlePropertiesFiles = parseGradlePropertiesFiles (subproject , alreadyParsed , ctx );
826
- sourceFileStream = sourceFileStream .concat (gradlePropertiesFiles , gradlePropertiesFiles .size ());
827
826
828
827
SourceFileStream nonProjectResources = parseNonProjectResources (subproject , alreadyParsed , ctx );
829
828
sourceFileStream = sourceFileStream .concat (nonProjectResources , nonProjectResources .size ());
@@ -872,13 +871,15 @@ private SourceFileStream parseGradleFiles(
872
871
Stream <SourceFile > sourceFiles = Stream .empty ();
873
872
int gradleFileCount = 0 ;
874
873
874
+ // build.gradle
875
875
GradleParser gradleParser = null ;
876
+ GradleProject gradleProject = null ;
876
877
File buildGradleFile = subproject .getBuildscript ().getSourceFile ();
877
878
if (buildGradleFile != null ) {
878
879
Path buildScriptPath = baseDir .relativize (buildGradleFile .toPath ());
879
880
if (!isExcluded (exclusions , buildScriptPath ) && buildGradleFile .exists ()) {
880
881
alreadyParsed .add (buildScriptPath );
881
- GradleProject gp = GradleProjectBuilder .gradleProject (project );
882
+ gradleProject = GradleProjectBuilder .gradleProject (project );
882
883
if (buildScriptPath .toString ().endsWith (".gradle" )) {
883
884
gradleParser = gradleParser ();
884
885
sourceFiles = gradleParser .parse (singleton (buildGradleFile .toPath ()), baseDir , ctx );
@@ -887,11 +888,13 @@ private SourceFileStream parseGradleFiles(
887
888
.parse (singleton (buildGradleFile .toPath ()), baseDir , ctx );
888
889
}
889
890
gradleFileCount ++;
890
- sourceFiles = sourceFiles .map (sourceFile -> sourceFile .withMarkers (sourceFile .getMarkers ().add (gp )));
891
+ final GradleProject finalGradleProject = gradleProject ;
892
+ sourceFiles = sourceFiles .map (sourceFile -> sourceFile .withMarkers (sourceFile .getMarkers ().add (finalGradleProject )));
891
893
alreadyParsed .add (buildGradleFile .toPath ());
892
894
}
893
895
}
894
896
897
+ // settings.gradle
895
898
if (subproject == project .getRootProject ()) {
896
899
File settingsGradleFile = subproject .file ("settings.gradle" );
897
900
File settingsGradleKtsFile = subproject .file ("settings.gradle.kts" );
@@ -938,6 +941,22 @@ private SourceFileStream parseGradleFiles(
938
941
}
939
942
}
940
943
944
+ // gradle.properties
945
+ File gradlePropertiesFile = subproject .file ("gradle.properties" );
946
+ if (gradlePropertiesFile .exists () && gradleProject != null ) {
947
+ Path gradlePropertiesPath = baseDir .relativize (gradlePropertiesFile .toPath ());
948
+ if (!isExcluded (exclusions , gradlePropertiesPath )) {
949
+ final GradleProject finalGradleProject = gradleProject ;
950
+ sourceFiles = Stream .concat (
951
+ sourceFiles ,
952
+ new PropertiesParser ()
953
+ .parse (singleton (gradlePropertiesFile .toPath ()), baseDir , ctx )
954
+ .map (sourceFile -> sourceFile .withMarkers (sourceFile .getMarkers ().add (finalGradleProject ))));
955
+ gradleFileCount ++;
956
+ }
957
+ alreadyParsed .add (gradlePropertiesFile .toPath ());
958
+ }
959
+
941
960
return SourceFileStream .build ("" , s -> {
942
961
}).concat (sourceFiles , gradleFileCount );
943
962
}
@@ -967,20 +986,6 @@ private SourceFileStream parseGradleWrapperFiles(Collection<PathMatcher> exclusi
967
986
}).concat (sourceFiles , fileCount );
968
987
}
969
988
970
- /**
971
- * Parse Gradle properties files such that these get the GradleProject marker used in UpgradeDependencyVersion.
972
- */
973
- private SourceFileStream parseGradlePropertiesFiles (Project subproject , Set <Path > alreadyParsed , ExecutionContext ctx ) {
974
- //Collect any additional yaml/properties/xml files that are NOT already in a source set.
975
- OmniParser omniParser = omniParser (alreadyParsed , subproject );
976
- List <Path > accepted = omniParser .acceptedPaths (baseDir , subproject .getProjectDir ().toPath ())
977
- .stream () // Only parse **/gradle.properties, while still leveraging the OmniParser for ignores/excludes
978
- .filter (it -> it .endsWith ("gradle.properties" ))
979
- .collect (toList ());
980
- return SourceFileStream .build ("" , s -> {
981
- }).concat (omniParser .parse (accepted , baseDir , ctx ), accepted .size ());
982
- }
983
-
984
989
protected SourceFileStream parseNonProjectResources (Project subproject , Set <Path > alreadyParsed , ExecutionContext ctx ) {
985
990
//Collect any additional yaml/properties/xml files that are NOT already in a source set.
986
991
OmniParser omniParser = omniParser (alreadyParsed , subproject );
0 commit comments