-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow usage of additional file extensions per parser. #3993
base: main
Are you sure you want to change the base?
Allow usage of additional file extensions per parser. #3993
Conversation
I like the idea! But I wonder if the execution context shouldn't instead allow registering alternative implementations for |
Perhaps if we just add a file exclusion pattern, similar to the additionalExtensions implemented here, would work? ... |
rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17Parser.java
Show resolved
Hide resolved
|
||
public class ParsingExecutionContextView extends DelegatingExecutionContext { | ||
private static final String PARSING_LISTENER = "org.openrewrite.core.parsingListener"; | ||
private static final String INCLUDE_PATTERNS = "%s.includePatterns"; | ||
private static final String EXCLUDE_PATTERNS = "%s.excludePatterns"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering a bit if we should adopt a gitignore
similar mechanism where the patterns (include and exclude) are an ordered set and evaluated in order before deciding if a particular source is to be included or not. A strict separation of include and exclude patterns is less flexible. That being said, what files to parse and not parse almost certainly doesn't require the same level of flexibility as gitignore
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I now understand that you did it this way so that the Parser#accept(Path)
can remain as is and that the include and exclude patterns can be used to supply a "delta". Depending on how far we want to take this, that may indeed be a good compromise.
rewrite-core/src/main/java/org/openrewrite/tree/ParsingExecutionContextView.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
@NotNull | ||
private Set<String> getPatternsFromSystemProperty(String key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to not have the system property fallback. It seems like the client (e.g. the Maven build plugin) should be responsible for setting everything up.
@@ -96,16 +95,15 @@ public ParsingExecutionContextView setExcludePattern(Class<? extends Parser> par | |||
} | |||
|
|||
public <T extends Parser> boolean accepts(T parser, Path path) { | |||
for (String pattern : getExcludePattern(parser.getClass())) { | |||
for (String pattern : getExcludePattern(parser.getParserClass())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new getParserClass()
is an unfortunate implementation detail that surfaces in the API. I wonder if we can find a cleaner solution. The Parser.Builder#getDslName()
looks like it would have been nicer, but unfortunately we don't have access to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm providing a better implementation.
|
||
public class ParsingExecutionContextView extends DelegatingExecutionContext { | ||
private static final String PARSING_LISTENER = "org.openrewrite.core.parsingListener"; | ||
private static final String INCLUDE_PATTERNS = "%s.includePatterns"; | ||
private static final String EXCLUDE_PATTERNS = "%s.excludePatterns"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I now understand that you did it this way so that the Parser#accept(Path)
can remain as is and that the include and exclude patterns can be used to supply a "delta". Depending on how far we want to take this, that may indeed be a good compromise.
It isn't clear to me that we need to make this extensible. |
This PR adds the option to include/exclude file patterns per parser. In my original use case, I have properties files that have |
I also described my use case in #4062. I have a yaml file without extension. To parse this as YAML required me to not only subclass YamlParser and a few other types, but I had to pass the file pattern as plain text matchers to the Maven plugin. That functionally has been deprecated, so it's not clear to me how I'd go about targeting my desired file mappings without this PR. |
What's changed?
Allow parsers to parse additional file extensions.
What's your motivation?
Parse Karaf's configuration files as properties.
Anything in particular you'd like reviewers to focus on?
No
Anyone you would like to review specifically?
No
Have you considered any alternatives or workarounds?
No
Any additional context
No
Checklist