Skip to content

Commit

Permalink
OmniParser plainTextMasks have moved to PlainTextParser
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed Aug 29, 2023
1 parent 277afca commit c34b0cc
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.openrewrite.marker.ci.BuildEnvironment;
import org.openrewrite.polyglot.OmniParser;
import org.openrewrite.quark.Quark;
import org.openrewrite.quark.QuarkParser;
import org.openrewrite.remote.Remote;
import org.openrewrite.style.NamedStyles;
import org.openrewrite.text.PlainTextParser;
Expand Down Expand Up @@ -833,7 +834,7 @@ private Stream<SourceFile> parseGradleFiles(
if (!isExcluded(exclusions, buildScriptPath) && buildGradleFile.exists()) {
alreadyParsed.add(buildScriptPath);
GradleProject gp = GradleProjectBuilder.gradleProject(project);
if(buildScriptPath.toString().endsWith(".gradle")) {
if (buildScriptPath.toString().endsWith(".gradle")) {
gradleParser = gradleParser();
sourceFiles = gradleParser.parse(singleton(buildGradleFile.toPath()), baseDir, ctx);
} else {
Expand All @@ -845,25 +846,25 @@ private Stream<SourceFile> parseGradleFiles(
}
}

if(project == project.getRootProject()) {
if (project == project.getRootProject()) {
File settingsGradleFile = project.file("settings.gradle");
File settingsGradleKtsFile = project.file("settings.gradle.kts");
GradleSettings gs = null;
if(GradleVersion.current().compareTo(GradleVersion.version("4.4")) >= 0 && (settingsGradleFile.exists() || settingsGradleKtsFile.exists())) {
if (GradleVersion.current().compareTo(GradleVersion.version("4.4")) >= 0 && (settingsGradleFile.exists() || settingsGradleKtsFile.exists())) {
gs = GradleSettingsBuilder.gradleSettings(((DefaultGradle) project.getGradle()).getSettings());
}
GradleSettings finalGs = gs;
if(settingsGradleFile.exists()) {
if (settingsGradleFile.exists()) {
Path settingsPath = baseDir.relativize(settingsGradleFile.toPath());
if(gradleParser == null) {
if (gradleParser == null) {
gradleParser = gradleParser();
}
sourceFiles = Stream.concat(
sourceFiles,
gradleParser
.parse(singleton(settingsGradleFile.toPath()), baseDir, ctx)
.map(sourceFile -> {
if(finalGs == null) {
if (finalGs == null) {
return sourceFile;
}
return sourceFile.withMarkers(sourceFile.getMarkers().add(finalGs));
Expand All @@ -876,7 +877,7 @@ private Stream<SourceFile> parseGradleFiles(
PlainTextParser.builder().build()
.parse(singleton(settingsGradleKtsFile.toPath()), baseDir, ctx)
.map(sourceFile -> {
if(finalGs == null) {
if (finalGs == null) {
return sourceFile;
}
return sourceFile.withMarkers(sourceFile.getMarkers().add(finalGs));
Expand All @@ -894,8 +895,13 @@ protected Stream<SourceFile> parseNonProjectResources(Project subproject, Set<Pa
}

private OmniParser omniParser(Set<Path> alreadyParsed) {
return OmniParser.builder()
.plainTextMasks(pathMatchers(baseDir, extension.getPlainTextMasks()))
return OmniParser.builder(
OmniParser.RESOURCE_PARSERS,
PlainTextParser.builder()

This comment has been minimized.

Copy link
@knutwannheden

knutwannheden Aug 29, 2023

Contributor

@jkschneider Should the plain text parser possibly come first, so that the plain text masks can be used to force certain sources to be parsed as plain text?

.plainTextMasks(baseDir, extension.getPlainTextMasks())
.build(),
QuarkParser.builder().build()
)
.exclusionMatchers(pathMatchers(baseDir, mergeExclusions(project, baseDir, extension)))
.exclusions(alreadyParsed)
.sizeThresholdMb(extension.getSizeThresholdMb())
Expand Down

0 comments on commit c34b0cc

Please sign in to comment.