Last active
March 11, 2021 15:47
-
-
Save steven-terrana/4b5beadcb3bff86c5179dc9b92a85825 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package git | |
import org.boozallen.plugins.jte.util.TemplateLogger | |
abstract class GitServerProvider{ | |
abstract void doThingOne() | |
void doThingTwo(){ | |
echo "doing thing 2 from base class" | |
} | |
void echo(String message){ | |
TemplateLogger.createDuringRun().printWarning(message) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package github | |
import example.GitServerProvider | |
class gitHub extends GitServerProvider{ | |
@Override | |
void doThingOne(){ | |
echo "GitHub doing thing one" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gitlab | |
import example.GitServerProvider | |
class GitLab extends GitServerProvider{ | |
@Override | |
void doThingOne(){ | |
echo "GitLab doing thing one" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import example.GitServerProvider | |
ExtensionPoint.lookup(GitServerProvider).each{ s -> | |
def provider = s.newInstance() | |
provider.doThingOne() | |
provider.doThingTwo() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
libraries{ | |
sdp | |
git | |
gitlab | |
github | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sdp | |
import hudson.FilePath | |
import org.jenkinsci.plugins.workflow.cps.CpsThread | |
import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner | |
import java.lang.SecurityManager | |
import org.boozallen.plugins.jte.util.TemplateLogger | |
import org.codehaus.groovy.reflection.ReflectionUtils | |
class ExtensionPoint implements Serializable{ | |
@NonCPS | |
static List<Class> lookup(Class extension){ | |
CpsThread thread = CpsThread.current() | |
FlowExecutionOwner flowOwner = thread.getExecution().getOwner() | |
FilePath buildRoot = new FilePath(flowOwner.getRootDir()) | |
FilePath src = buildRoot.child("jte/src") | |
List<Class> classes = [] | |
recurseChildren(src){ file -> | |
String fullPath = file.getRemote() | |
if(fullPath.endsWith(".groovy")){ | |
String clazz = ((fullPath - ".groovy") - "${src.getRemote()}/").split("/").join(".") | |
Class c = Class.forName(clazz) | |
if(c in extension && c != extension){ | |
classes << c | |
} | |
} | |
} | |
return classes | |
} | |
@NonCPS | |
static void recurseChildren(FilePath file, Closure action){ | |
if(file.exists()){ | |
file.list().each{ child -> | |
if(child.isDirectory()){ | |
recurseChildren(child, action) | |
} else{ | |
action(child) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment