-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementation of ability to plug in custom CI providers using the Se…
…rviceLoader
- Loading branch information
Showing
4 changed files
with
73 additions
and
8 deletions.
There are no files selected for viewing
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
27 changes: 27 additions & 0 deletions
27
src/main/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoProviderResolver.groovy
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package nebula.plugin.info.ci; | ||
|
||
import java.util.Collection; | ||
import java.util.LinkedList; | ||
import java.util.ServiceLoader; | ||
|
||
public class ContinuousIntegrationInfoProviderResolver { | ||
|
||
private static ServiceLoader<ContinuousIntegrationInfoProvider> continuousIntegrationInfoProviderServiceLoader = ServiceLoader | ||
.load(ContinuousIntegrationInfoProvider.class); | ||
|
||
def all () { | ||
return continuousIntegrationInfoProviderServiceLoader.asList() << new UnknownContinuousIntegrationProvider(); | ||
} | ||
|
||
ContinuousIntegrationInfoProvider findProvider(project) { | ||
|
||
def provider = continuousIntegrationInfoProviderServiceLoader.find { it.supports(project) } | ||
|
||
if (provider) { | ||
return provider | ||
} else { | ||
return new UnknownContinuousIntegrationProvider() | ||
} | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
src/main/resources/META-INF/services/nebula.plugin.info.ci.ContinuousIntegrationInfoProvider
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nebula.plugin.info.ci.JenkinsProvider |
41 changes: 41 additions & 0 deletions
41
src/test/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoProviderResolverSpec.groovy
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package nebula.plugin.info.ci | ||
|
||
import nebula.plugin.info.InfoBrokerPlugin | ||
import nebula.plugin.info.InfoBrokerPlugin.ManifestEntry | ||
import nebula.plugin.info.basic.BasicInfoPlugin | ||
import nebula.test.ProjectSpec | ||
|
||
import org.gradle.api.NamedDomainObjectContainer | ||
|
||
import spock.lang.Ignore | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean | ||
|
||
class ContinuousIntegrationInfoProviderResolverSpec extends ProjectSpec { | ||
|
||
def 'get all configured info providers'() { | ||
when: | ||
def resolver = new ContinuousIntegrationInfoProviderResolver() | ||
|
||
then: | ||
def providers = resolver.all() | ||
providers != null | ||
providers.size() == 2 | ||
providers[0].getClass().equals(JenkinsProvider.class) | ||
providers[1].getClass().equals(UnknownContinuousIntegrationProvider.class) | ||
} | ||
|
||
def 'get Jenkins provider if running on Jenkins'() { | ||
when: | ||
def onJenkins = System.getenv('BUILD_NUMBER') && System.getenv('JOB_NAME') | ||
def resolver = new ContinuousIntegrationInfoProviderResolver() | ||
|
||
then: | ||
def provider = resolver.findProvider(project) | ||
if(onJenkins) { | ||
provider.getClass().equals(JenkinsProvider.class) | ||
} else { | ||
provider.getClass().equals(UnknownContinuousIntegrationProvider.class) | ||
} | ||
} | ||
} |