diff --git a/.gitignore b/.gitignore
index f65949b..9f41526 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,4 +10,5 @@ target
*.pyc
build.log
**/*.versionsBackup
-.DS_Store
\ No newline at end of file
+.DS_Store
+logdir*
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d3058af..199e727 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
## Unreleased
* Fixed a bug for Java 11 compatibility
+* Changed Jenkins Maven repo URL from http:// to https://
+* The LocalProjectPipelineExtensionDetectorSpec#getClassesOfTypeInPackage method now finds classes that are
+ descendants of `java.lang.Object` but aren't direct subtypes.
## 2.1.5
diff --git a/examples/helper-script/pom.xml b/examples/helper-script/pom.xml
index e1d28f2..4d44970 100644
--- a/examples/helper-script/pom.xml
+++ b/examples/helper-script/pom.xml
@@ -15,12 +15,12 @@
jenkins-releases
Jenkins Releases
- http://repo.jenkins-ci.org/releases
+ https://repo.jenkins-ci.org/releases
jenkins-public
Jenkins Public
- http://repo.jenkins-ci.org/public
+ https://repo.jenkins-ci.org/public
diff --git a/examples/shared-library/pom.xml b/examples/shared-library/pom.xml
index 11da360..cbf3da5 100644
--- a/examples/shared-library/pom.xml
+++ b/examples/shared-library/pom.xml
@@ -15,12 +15,12 @@
jenkins-releases
Jenkins Releases
- http://repo.jenkins-ci.org/releases
+ https://repo.jenkins-ci.org/releases
jenkins-public
Jenkins Public
- http://repo.jenkins-ci.org/public
+ https://repo.jenkins-ci.org/public
diff --git a/examples/whole-pipeline/pom.xml b/examples/whole-pipeline/pom.xml
index 101748f..d4b8f82 100644
--- a/examples/whole-pipeline/pom.xml
+++ b/examples/whole-pipeline/pom.xml
@@ -15,12 +15,12 @@
jenkins-releases
Jenkins Releases
- http://repo.jenkins-ci.org/releases
+ https://repo.jenkins-ci.org/releases
jenkins-public
Jenkins Public
- http://repo.jenkins-ci.org/public
+ https://repo.jenkins-ci.org/public
diff --git a/pom.xml b/pom.xml
index a78bb11..125e1de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -41,7 +41,12 @@
jenkins-releases
Jenkins Releases
- http://repo.jenkins-ci.org/releases
+ https://repo.jenkins-ci.org/releases
+
+
+ repo.jenkins-ci.org
+ Jenkins Repo
+ https://repo.jenkins-ci.org/public
@@ -271,12 +276,6 @@
${objenesis.version}
-
- org.reflections
- reflections
- 0.9.12
-
-
io.github.classgraph
classgraph
@@ -419,10 +418,10 @@
-
org.mockito
@@ -436,7 +435,6 @@
-
org.apache.maven.plugins
maven-assembly-plugin
@@ -477,7 +475,7 @@
maven-dependency-plugin
-
cglib:cglib-nodep
junit:junit
diff --git a/src/main/java/com/homeaway/devtools/jenkins/testing/LocalProjectPipelineExtensionDetector.java b/src/main/java/com/homeaway/devtools/jenkins/testing/LocalProjectPipelineExtensionDetector.java
index 30a796c..cb2a6a6 100644
--- a/src/main/java/com/homeaway/devtools/jenkins/testing/LocalProjectPipelineExtensionDetector.java
+++ b/src/main/java/com/homeaway/devtools/jenkins/testing/LocalProjectPipelineExtensionDetector.java
@@ -18,18 +18,17 @@
package com.homeaway.devtools.jenkins.testing;
import java.lang.annotation.Annotation;
-import java.util.HashMap;
import java.util.HashSet;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
-import org.reflections.Reflections;
-import org.reflections.ReflectionsException;
-import org.reflections.scanners.SubTypesScanner;
-import org.reflections.util.ClasspathHelper;
-import org.reflections.util.ConfigurationBuilder;
+import groovy.lang.Closure;
+import io.github.classgraph.ClassGraph;
+import io.github.classgraph.ScanResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,38 +50,26 @@ public class LocalProjectPipelineExtensionDetector extends APipelineExtensionDet
@Override
public Set> getClassesOfTypeInPackage(Class> _supertype, Optional _package) {
- Set> classes = new HashSet<>();
-
- Map failures = new HashMap<>();
-
- Reflections reflector = new Reflections(
- new ConfigurationBuilder()
- .setScanners(new SubTypesScanner(false))
- .setUrls(ClasspathHelper.forPackage(_package.orElse(""))));
-
- Set all_types = new HashSet<>();
-
- try {
- all_types = reflector.getAllTypes();
- } catch( ReflectionsException re ) {
- if( re.getMessage().contains( "Couldn't find subtypes of Object." ) ) {
- // this can happen if there are no classes local to the project.
- // the full error message is
- // Couldn't find subtypes of Object.
- // Make sure SubTypesScanner initialized to include Object class - new SubTypesScanner(false)
- // which we have done above, so that is NOT the actual cause.
- // If there are no classes local to the project, that's OK!
- // Just use an empty set instead of throwing an exception.
- LOG.info( "Looks like there aren't any classes compiled by this project." );
- } else {
- // We still do want to error with "real" exceptions, though.
- throw re;
- }
+ List classnames;
+ try (
+ ScanResult scanResult = new ClassGraph()
+ .acceptPackages(_package.orElse(""))
+ .disableJarScanning()
+ .scan()
+ ) {
+ classnames = scanResult
+ .getAllClasses()
+ .filter(ci -> !ci.extendsSuperclass(Closure.class.getName()))
+ .filter(ci -> !ci.extendsSuperclass("spock.lang.Specification"))
+ .filter(ci -> !(ci.extendsSuperclass(InvalidlyNamedScriptWrapper.class.getName()) || ci.getName().equals(InvalidlyNamedScriptWrapper.class.getName())))
+ .filter(ci -> ci.extendsSuperclass(_supertype.getName()))
+ .getNames();
}
- for(String classname : all_types ) {
-
- Class> clazz = null;
+ Set> classes = new HashSet<>();
+ Map failures = new HashMap<>();
+ for(String classname : classnames ) {
+ Class> clazz;
try {
clazz = Class.forName( classname );
@@ -90,7 +77,6 @@ public Set> getClassesOfTypeInPackage(Class> _supertype, Optional> getClassesOfTypeInPackage(Class> _supertype, Optional> getClassesWithAnnotationOfTypeInPackage( Class extends Annotation> _annotation, Class> _supertype, Optional _package) {
- Set> annotated_classes = new HashSet<>();
-
- for( Class> annotated_class : new Reflections( _package.orElse("") ).getTypesAnnotatedWith( _annotation ) ) {
- if( _supertype.isAssignableFrom( annotated_class ) ) {
- annotated_classes.add( annotated_class );
- }
+ Set> annotated_classes;
+ try (
+ ScanResult scanResult = new ClassGraph()
+ .acceptPackages(_package.orElse(""))
+ .enableAnnotationInfo()
+ .scan()
+ ) {
+ annotated_classes = new HashSet<>(scanResult
+ .getClassesWithAnnotation(_annotation.getName())
+ .filter(ci -> ci.extendsSuperclass(_supertype.getName()))
+ .loadClasses(true));
}
return annotated_classes;
diff --git a/src/main/java/com/homeaway/devtools/jenkins/testing/WholeClasspathPipelineExtensionDetector.java b/src/main/java/com/homeaway/devtools/jenkins/testing/WholeClasspathPipelineExtensionDetector.java
index 370a81e..0541b94 100644
--- a/src/main/java/com/homeaway/devtools/jenkins/testing/WholeClasspathPipelineExtensionDetector.java
+++ b/src/main/java/com/homeaway/devtools/jenkins/testing/WholeClasspathPipelineExtensionDetector.java
@@ -25,10 +25,11 @@
import java.util.Optional;
import java.util.Set;
+import io.github.classgraph.ClassGraph;
+import io.github.classgraph.ScanResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import io.github.classgraph.ClassGraph;
/**
* Search through classes in the entire classpath for Jenkins Pipeline extensions.
@@ -44,14 +45,19 @@ public class WholeClasspathPipelineExtensionDetector extends APipelineExtensionD
@Override
public Set> getClassesOfTypeInPackage(Class> _supertype, Optional _package) {
- Set> classes = new HashSet<>();
-
- List classnames = new ClassGraph()
- .enableAnnotationInfo()
- .enableClassInfo()
- .acceptPackages(_package.orElse(""))
- .scan().getAllStandardClasses().getNames();
+ List classnames;
+ try (
+ ScanResult scanResult = new ClassGraph()
+ .acceptPackages(_package.orElse(""))
+ .scan()
+ ) {
+ classnames = scanResult
+ .getAllClasses()
+ .filter(ci -> ci.extendsSuperclass(_supertype.getName()))
+ .getNames();
+ }
+ Set> classes = new HashSet<>();
HashMap failures = new HashMap<>();
for(String classname: classnames) {
@@ -60,7 +66,7 @@ public Set> getClassesOfTypeInPackage(Class> _supertype, Optional> getClassesOfTypeInPackage(Class> _supertype, Optional> getClassesWithAnnotationOfTypeInPackage( Class extends Annotation> _annotation, Class> _supertype, Optional _package) {
- Set> annotated_classes = new HashSet<>();
+ List annotated_classnames;
+ try (
+ ScanResult scanResult = new ClassGraph()
+ .acceptPackages(_package.orElse(""))
+ .enableAnnotationInfo()
+ .scan();
+ ) {
+ annotated_classnames = scanResult
+ .getClassesWithAnnotation(_annotation.getName())
+ .filter(ci -> ci.extendsSuperclass(_supertype.getName()))
+ .getNames();
+ }
+ Set> annotated_classes = new HashSet<>();
HashMap failures = new HashMap<>();
- List annotated_classnames = new ClassGraph()
- .enableAnnotationInfo()
- .enableClassInfo()
- .acceptPackages(_package.orElse(""))
- .scan().getClassesWithAnnotation( _annotation.getName() ).getNames();
-
for(String classname: annotated_classnames) {
Class> clazz = null;
diff --git a/src/test/groovy/com/homeaway/devtools/jenkins/testing/LocalProjectPipelineExtensionDetectorSpec.groovy b/src/test/groovy/com/homeaway/devtools/jenkins/testing/LocalProjectPipelineExtensionDetectorSpec.groovy
new file mode 100644
index 0000000..d94e93b
--- /dev/null
+++ b/src/test/groovy/com/homeaway/devtools/jenkins/testing/LocalProjectPipelineExtensionDetectorSpec.groovy
@@ -0,0 +1,18 @@
+package com.homeaway.devtools.jenkins.testing
+
+import com.homeaway.devtools.jenkins.testing.functions.ScriptToTest
+
+class LocalProjectPipelineExtensionDetectorSpec extends JenkinsPipelineSpecification {
+
+ def "LocalProjectPipelineExtensionDetectorSpec should detect classes that aren't direct subtypes of java-lang-Object" () {
+ when:
+ Set> classes = new LocalProjectPipelineExtensionDetector()
+ .getClassesOfTypeInPackage(
+ Object.class,
+ Optional.empty()
+ )
+
+ then:
+ classes.contains(ScriptToTest)
+ }
+}
diff --git a/src/test/groovy/com/homeaway/devtools/jenkins/testing/functions/ScriptToTest.groovy b/src/test/groovy/com/homeaway/devtools/jenkins/testing/functions/ScriptToTest.groovy
new file mode 100644
index 0000000..8ef1383
--- /dev/null
+++ b/src/test/groovy/com/homeaway/devtools/jenkins/testing/functions/ScriptToTest.groovy
@@ -0,0 +1,5 @@
+package com.homeaway.devtools.jenkins.testing.functions
+
+def helloWorld(String argument) {
+ echo argument
+}