-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #604 from jonesbusy/feature/java-file-visitor
Add a Java ISO visitor for metadata collection
- Loading branch information
Showing
6 changed files
with
119 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/extractor/JavaFileVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.jenkins.tools.pluginmodernizer.core.extractor; | ||
|
||
import org.openrewrite.java.JavaIsoVisitor; | ||
import org.openrewrite.java.tree.J; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* A visitor to extract metadata from Java files. | ||
*/ | ||
public class JavaFileVisitor extends JavaIsoVisitor<PluginMetadata> { | ||
|
||
/** | ||
* LOGGER. | ||
*/ | ||
private static final Logger LOG = LoggerFactory.getLogger(JavaFileVisitor.class); | ||
|
||
@Override | ||
public J.Import visitImport(J.Import _import, PluginMetadata pluginMetadata) { | ||
_import = super.visitImport(_import, pluginMetadata); | ||
// Rather a naive approach, but let's assume we can detect testcontainers usage by the package name | ||
if (_import.getPackageName().startsWith("org.testcontainers.containers")) { | ||
LOG.info("Found testcontainers import: {}. Plugin is using container tests", _import.getPackageName()); | ||
pluginMetadata.setUseContainerTests(true); | ||
} | ||
if (_import.getPackageName().startsWith("org.jenkinsci.test.acceptance.docker")) { | ||
LOG.info("Found docker-fixtures import: {}. Plugin is using container tests", _import.getPackageName()); | ||
pluginMetadata.setUseContainerTests(true); | ||
} | ||
return _import; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters