diff --git a/s-pipes-modules-utils/s-pipes-module-creator-maven-plugin/src/main/java/RdfAnnotationProcessorMojo.java b/s-pipes-modules-utils/s-pipes-module-creator-maven-plugin/src/main/java/RdfAnnotationProcessorMojo.java index 621c5775..4a0d4c76 100644 --- a/s-pipes-modules-utils/s-pipes-module-creator-maven-plugin/src/main/java/RdfAnnotationProcessorMojo.java +++ b/s-pipes-modules-utils/s-pipes-module-creator-maven-plugin/src/main/java/RdfAnnotationProcessorMojo.java @@ -8,6 +8,11 @@ import org.apache.jena.vocabulary.OWL; import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.RDFS; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Dependency; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -171,9 +176,8 @@ private void generateRdfForModule() throws MojoExecutionException { //region Parsing Java classes private Set> readAllModuleClasses(MavenProject project) throws MalformedURLException, ClassNotFoundException { //Configure the class searcher - final File classesDirectory = new File(project.getBuild().getOutputDirectory()); - final URL classesUrl = classesDirectory.toURI().toURL(); - final URLClassLoader classLoader = URLClassLoader.newInstance(new URL[]{classesUrl}, getClass().getClassLoader()); + final URL[] classesUrls = getDependencyURLs(project); + final URLClassLoader classLoader = URLClassLoader.newInstance(classesUrls, getClass().getClassLoader()); var reflectionConfig = new ConfigurationBuilder() .setUrls(ClasspathHelper.forClassLoader(classLoader)) .setScanners(new SubTypesScanner(false), new TypeAnnotationsScanner()) @@ -199,6 +203,37 @@ private Set> readAllModuleClasses(MavenProject project) throws Malforme return moduleClasses; } + private URL[] getDependencyURLs(MavenProject project) throws MalformedURLException { + Set ret = new HashSet<>(); + ret.add(new File(project.getBuild().getOutputDirectory()).toURI().toURL()); + for(Dependency d : project.getDependencies()){ + URL dURL = getURL(getLocalRepository(project), d); + ret.add(dURL); + } + return ret.toArray(new URL[]{}); + } + + /** + * @implNote use of deprecated API to + * @param project + * @return instance of local repository + */ + private ArtifactRepository getLocalRepository(MavenProject project){ + return project.getProjectBuildingRequest().getLocalRepository(); + } + + private URL getURL(ArtifactRepository r, Dependency d) throws MalformedURLException { + return new File(r.getBasedir(), r.pathOf(toArtifact(d))) + .toURI().toURL(); + } + + private Artifact toArtifact(Dependency d){ + DefaultArtifactHandler h = new DefaultArtifactHandler(d.getType()); + return new DefaultArtifact( + d.getGroupId(), d.getArtifactId(), d.getVersion(), d.getScope(), d.getType(),null, h + ); + } + private SPipesModule readModuleAnnotationFromClass(Class classObject) { return classObject.getAnnotation(MODULE_ANNOTATION); } diff --git a/s-pipes-modules/pom.xml b/s-pipes-modules/pom.xml index a5ec20d4..a6f7f996 100644 --- a/s-pipes-modules/pom.xml +++ b/s-pipes-modules/pom.xml @@ -51,24 +51,24 @@ - - - - - - - - - - - - - - - - - - + + cz.cvut.kbss + s-pipes-module-creator-maven-plugin + ${project.parent.version} + false + + + + process-annotations + + + RDF_FOR_ALL_CHILDREN + cz.cvut.spipes + all-modules.ttl + + + +