Skip to content
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

[#180] Fix the reflexion warning on ontology generation in s-pipes-modules #186

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,32 @@ public class RdfAnnotationProcessorMojo extends AbstractMojo {
@Parameter(defaultValue = "${project}", readonly = true, required = true)
MavenProject project;

@Parameter(defaultValue = "${project.groupId}", readonly = true, required = true)
String javaModuleName;

@Parameter(required = false, readonly = true)
String moduleClassName;
/**
* The mode in which the plugin is running. 2 values are supported:
* <ul>
* <li><b>RDF_FOR_MODULE</b> - Generate an RDF ontology for a single module.
* Presumes that the pom.xml belongs to the module itself.</li>
* <li><b>RDF_FOR_ALL_CHILDREN</b> - Generate an RDF ontology that contains
* all modules from this Maven project's submodules. In this mode, the plugin will try to
* look through all available classes and find those annotated as SPipes Modules.</li>
* </ul>
* Defaults to <b>RDF_FOR_ALL_CHILDREN</b> if no mode is explicitly specified.
*/
@Parameter(readonly = true)
GenerationMode mode;

@Parameter(required = false, readonly = true)
/**
* The Java module which should be scanned for the SPipes Module classes.
*/
@Parameter(required = true, readonly = true)
String modulePackageName;

@Parameter(required = false, readonly = true)
/**
* Filename of the ontology file generated by the plugin.
*/
@Parameter(required = true, readonly = true)
String ontologyFilename;

@Parameter(required = false, readonly = true)
GenerationMode mode;

enum GenerationMode {
RDF_FOR_MODULE,
RDF_FOR_ALL_CHILDREN
Expand Down Expand Up @@ -105,6 +116,7 @@ public void execute() throws MojoExecutionException {

}

@SuppressWarnings("unchecked") // Maven returns untyped list which must be manually retyped
private void generateRdfForAllModules() throws MalformedURLException, ClassNotFoundException, FileNotFoundException {
//read all submodules
getLog().info("Generating an RDF for all sub-modules");
Expand All @@ -113,7 +125,8 @@ private void generateRdfForAllModules() throws MalformedURLException, ClassNotFo

//find module's main class
var moduleClasses = readAllModuleClasses(submodule);
getLog().info("Module: " + submodule.getName() + " | Classes: [" + moduleClasses.stream()
getLog().info("Scanned maven module '" + submodule.getName() + "' and found " + moduleClasses.size()
+ " SPipes Module(s): [" + moduleClasses.stream()
.map(Class::getSimpleName)
.collect(Collectors.joining(", ")) + "]");

Expand All @@ -129,7 +142,7 @@ private void generateRdfForAllModules() throws MalformedURLException, ClassNotFo
}
writeModelToStdout(model);
try {
writeToTargetFolderFile(model, "all-modules.ttl");
writeToTargetFolderFile(model, ontologyFilename);
} catch (IOException e) {
getLog().error("Failed to write model to the output file", e);
}
Expand Down Expand Up @@ -164,7 +177,9 @@ private Set<Class<?>> readAllModuleClasses(MavenProject project) throws Malforme
var reflectionConfig = new ConfigurationBuilder()
.setUrls(ClasspathHelper.forClassLoader(classLoader))
.setScanners(new SubTypesScanner(false), new TypeAnnotationsScanner())
.filterInputsBy(new FilterBuilder().includePackage(modulePackageName));
.filterInputsBy(new FilterBuilder().includePackage(modulePackageName))
.setExpandSuperTypes(false);

var classSearcher = new Reflections(reflectionConfig);

//Find classes with the module annotation
Expand Down
37 changes: 18 additions & 19 deletions s-pipes-modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,24 @@
</configuration>
</plugin>

<!-- <plugin>-->
<!-- <groupId>cz.cvut.kbss</groupId>-->
<!-- <artifactId>s-pipes-module-creator-maven-plugin</artifactId>-->
<!-- <version>${project.parent.version}</version>-->
<!-- <inherited>false</inherited>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <goals>-->
<!-- <goal>process-annotations</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <mode>RDF_FOR_ALL_CHILDREN</mode>-->
<!-- <moduleClassName>FoobarModule</moduleClassName>-->
<!-- <modulePackageName>cz.cvut.spipes.modules</modulePackageName>-->
<!-- <ontologyFilename>test-own-artifact-generated.ttl</ontologyFilename>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<plugin>
<groupId>cz.cvut.kbss</groupId>
<artifactId>s-pipes-module-creator-maven-plugin</artifactId>
<version>${project.parent.version}</version>
<inherited>false</inherited>
<executions>
<execution>
<goals>
<goal>process-annotations</goal>
</goals>
<configuration>
<mode>RDF_FOR_ALL_CHILDREN</mode>
<modulePackageName>cz.cvut.spipes</modulePackageName>
<ontologyFilename>all-modules.ttl</ontologyFilename>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>
Expand Down
Loading