Skip to content

Commit

Permalink
Add TomlParser (#925)
Browse files Browse the repository at this point in the history
* Add TomlParser

* Use TomlParser
  • Loading branch information
timtebeek authored Jan 3, 2025
1 parent e740c70 commit fe6287b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-protobuf</artifactId>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-toml</artifactId>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-yaml</artifactId>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/openrewrite/maven/ResourceParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.openrewrite.protobuf.ProtoParser;
import org.openrewrite.quark.QuarkParser;
import org.openrewrite.text.PlainTextParser;
import org.openrewrite.toml.TomlParser;
import org.openrewrite.xml.XmlParser;
import org.openrewrite.yaml.YamlParser;

Expand Down Expand Up @@ -152,6 +153,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
ProtoParser protoParser = new ProtoParser();
List<Path> protoPaths = new ArrayList<>();

TomlParser tomlParser = new TomlParser();
List<Path> tomlPaths = new ArrayList<>();

KotlinParser kotlinParser = kotlinParserBuilder.build();
List<Path> kotlinPaths = new ArrayList<>();

Expand Down Expand Up @@ -180,6 +184,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
propertiesPaths.add(path);
} else if (protoParser.accept(path)) {
protoPaths.add(path);
} else if (tomlParser.accept(path)) {
tomlPaths.add(path);
} else if (kotlinParser.accept(path)) {
kotlinPaths.add(path);
} else if (groovyParser.accept(path)) {
Expand Down Expand Up @@ -221,6 +227,11 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
alreadyParsed.addAll(protoPaths);
}

if (!tomlPaths.isEmpty()) {
sourceFiles = Stream.concat(sourceFiles, (Stream<S>) tomlParser.parse(tomlPaths, baseDir, ctx));
alreadyParsed.addAll(tomlPaths);
}

if (!kotlinPaths.isEmpty()) {
sourceFiles = Stream.concat(sourceFiles, (Stream<S>) kotlinParser.parse(kotlinPaths, baseDir, ctx));
alreadyParsed.addAll(kotlinPaths);
Expand Down

0 comments on commit fe6287b

Please sign in to comment.