Skip to content

Commit

Permalink
[Fix] Fix the reflexion warning on ontology generation in s-pipes-mod…
Browse files Browse the repository at this point in the history
…ules
  • Loading branch information
Tim committed Jul 31, 2023
1 parent 3d177a0 commit ffb19cd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 32 deletions.
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
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

0 comments on commit ffb19cd

Please sign in to comment.