Skip to content

Commit

Permalink
Fix reflection issue inside gradle plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
RoRoche committed May 6, 2020
1 parent 8710e27 commit 175cbac
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,7 @@ class BuildClassDiagramTask extends DefaultTask implements CustomTask {
"Classes to ignore: {}",
extension.ignoredClasses
)
getLogger().lifecycle(
"URLs to scan: " + project.sourceSets.main.output.classesDirs.files
)
final URL[] urls = project.sourceSets.main.output.classesDirs.files.collect { File dir ->
dir.listFiles()
}.flatten().collect {
getLogger().lifecycle(
"File?: " + it
)
final URL[] urls = project.sourceSets.main.output.classesDirs.files.collect {
if (it != null) {
it.toURI().toURL()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.reflections.Configuration
import org.reflections.Reflections
import org.reflections.scanners.SubTypesScanner
import org.reflections.scanners.TypeAnnotationsScanner
import org.reflections.util.ClasspathHelper
import org.reflections.util.ConfigurationBuilder
import java.net.URL
import java.net.URLClassLoader
Expand Down Expand Up @@ -42,13 +43,12 @@ class ClsInPackage(
*/
constructor(
packageName: String,
urls: Array<URL>,
classLoader: ClassLoader
) : this(
packageName = packageName,
configuration = ConfigurationBuilder(
).setUrls(
urls.toList()
ClasspathHelper.forClassLoader(classLoader)
).setScanners(
SubTypesScanner(false),
TypeAnnotationsScanner()
Expand All @@ -68,7 +68,6 @@ class ClsInPackage(
urls: Array<URL>
) : this(
packageName = packageName,
urls = urls,
classLoader = URLClassLoader(urls)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.github.roroche.plantuml.tasks.BuildClassDiagramTask
import com.github.roroche.plantuml.tasks.ClassDiagramExtension
import com.pragmaticobjects.oo.tests.TestCase
import com.pragmaticobjects.oo.tests.junit5.TestsSuite
import org.gradle.testfixtures.ProjectBuilder
import org.junit.jupiter.api.io.TempDir

import java.nio.file.Path
Expand All @@ -23,7 +22,7 @@ class BuildClassDiagramTaskTest extends TestsSuite {
"test buildClassDiagramTask",
new CreateTaskAssertion(
new CreatedTask(
ProjectBuilder.builder().build(),
BuiltProject.instance.toProject(),
"buildClassDiagramTask",
BuildClassDiagramTask.class,
new ClassDiagramExtension(
Expand All @@ -39,7 +38,7 @@ class BuildClassDiagramTaskTest extends TestsSuite {
"test buildClassDiagramTask print diagram to file",
new ExecuteTaskAssertion(
new CreatedTask(
ProjectBuilder.builder().build(),
BuiltProject.instance.toProject(),
"buildClassDiagramTask",
BuildClassDiagramTask.class,
new ClassDiagramExtension(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class BuiltProject {
* @return The Project instance.
*/
Project toProject() {
project.sourceSets.main.output.classesDirs = project.buildDir.toPath().resolve("classes").resolve("java")
return project
}
}

0 comments on commit 175cbac

Please sign in to comment.