use of com.openshift.restclient.model.build.ICustomBuildStrategy in project jbosstools-openshift by jbosstools.
the class OpenshiftEapProfileDetectorTest method createBuildConfig.
@SuppressWarnings("deprecation")
private IBuildConfig createBuildConfig(Class<? extends IBuildStrategy> clazz, String name) {
IBuildConfig bc = mock(IBuildConfig.class);
DockerImageURI image = mock(DockerImageURI.class);
when(image.getName()).thenReturn(name);
IBuildStrategy strategy = null;
if (clazz == null) {
strategy = mock(ISourceBuildStrategy.class);
} else if (IDockerBuildStrategy.class.isAssignableFrom(clazz)) {
IDockerBuildStrategy dbs = mock(IDockerBuildStrategy.class);
when(dbs.getBaseImage()).thenReturn(image);
strategy = dbs;
} else if (ICustomBuildStrategy.class.isAssignableFrom(clazz)) {
ICustomBuildStrategy cbs = mock(ICustomBuildStrategy.class);
when(cbs.getImage()).thenReturn(image);
strategy = cbs;
} else if (ISTIBuildStrategy.class.isAssignableFrom(clazz)) {
ISTIBuildStrategy sts = mock(ISTIBuildStrategy.class);
when(sts.getImage()).thenReturn(image);
strategy = sts;
} else if (ISourceBuildStrategy.class.isAssignableFrom(clazz)) {
ISourceBuildStrategy sbs = mock(ISourceBuildStrategy.class);
when(sbs.getImage()).thenReturn(image);
strategy = sbs;
}
when(bc.getBuildStrategy()).thenReturn(strategy);
Map<String, String> labels = Collections.singletonMap("template", name);
when(bc.getLabels()).thenReturn(labels);
return bc;
}
use of com.openshift.restclient.model.build.ICustomBuildStrategy in project jbosstools-openshift by jbosstools.
the class BuildConfigPropertySourceTest method getCustomPropertyValues.
@Test
public void getCustomPropertyValues() {
ICustomBuildStrategy strategy = givenCustomBuildStrategy();
assertEquals(BuildStrategyType.CUSTOM, source.getPropertyValue(BuildConfigPropertySource.Ids.Type));
assertEquals(strategy.getImage(), source.getPropertyValue(BuildConfigPropertySource.Ids.CUSTOM_IMAGE));
assertEquals(strategy.exposeDockerSocket(), source.getPropertyValue(BuildConfigPropertySource.Ids.CUSTOM_EXPOSE_DOCKER_SOCKET));
assertEquals(new KeyValuePropertySource(strategy.getEnvironmentVariables()), source.getPropertyValue(BuildConfigPropertySource.Ids.CUSTOM_ENV));
}
use of com.openshift.restclient.model.build.ICustomBuildStrategy in project jbosstools-openshift by jbosstools.
the class ResourceDetailsContentProvider method addStrategyTypeProperties.
private void addStrategyTypeProperties(Collection<ResourceProperty> properties, IBuildStrategy buildStrategy) {
if (buildStrategy == null || buildStrategy.getType() == null) {
properties.add(new UnknownResourceProperty(LABEL_STRATEGY));
return;
}
properties.add(new ResourceProperty(LABEL_STRATEGY, buildStrategy.getType().toString()));
switch(buildStrategy.getType()) {
case BuildStrategyType.SOURCE:
ISourceBuildStrategy sti = (ISourceBuildStrategy) buildStrategy;
properties.add(new ResourceProperty("builder image", StringUtils.toStringOrNull(sti.getImage())));
break;
case BuildStrategyType.DOCKER:
IDockerBuildStrategy docker = (IDockerBuildStrategy) buildStrategy;
properties.add(new ResourceProperty("base image", StringUtils.toStringOrNull(docker.getBaseImage())));
break;
case BuildStrategyType.CUSTOM:
ICustomBuildStrategy custom = (ICustomBuildStrategy) buildStrategy;
properties.add(new ResourceProperty("builder image", StringUtils.toStringOrNull(custom.getImage())));
break;
case BuildStrategyType.JENKINS_PIPELINE:
IJenkinsPipelineStrategy jenkins = (IJenkinsPipelineStrategy) buildStrategy;
properties.add(new ResourceProperty("jenkins file", StringUtils.removeAll(StringUtils.getLineSeparator(), jenkins.getJenkinsfile())));
properties.add(new ResourceProperty("jenkins file path", StringUtils.toStringOrNull(jenkins.getJenkinsfilePath())));
break;
default:
}
}
use of com.openshift.restclient.model.build.ICustomBuildStrategy in project jbosstools-openshift by jbosstools.
the class BuildConfigPropertySourceTest method givenCustomBuildStrategy.
private ICustomBuildStrategy givenCustomBuildStrategy() {
ICustomBuildStrategy strategy = mock(ICustomBuildStrategy.class);
when(strategy.getType()).thenReturn(BuildStrategyType.CUSTOM);
Map<String, String> env = new HashMap<>();
env.put("foo", "bar");
when(strategy.getEnvironmentVariables()).thenReturn(env);
when(strategy.exposeDockerSocket()).thenReturn(true);
when(strategy.getImage()).thenReturn(new DockerImageURI("foo/bar:latest"));
when(resource.getBuildStrategy()).thenReturn(strategy);
return strategy;
}
use of com.openshift.restclient.model.build.ICustomBuildStrategy in project jbosstools-openshift by jbosstools.
the class OpenshiftEapProfileDetector method isEapStyle.
@SuppressWarnings({ "deprecation" })
public boolean isEapStyle(IBuildConfig buildConfig) {
if (buildConfig == null) {
return false;
}
// First check buildconfig docker image name
IBuildStrategy strategy = buildConfig.getBuildStrategy();
DockerImageURI image = null;
boolean isEapStyle = false;
if (strategy instanceof ISourceBuildStrategy) {
image = ((ISourceBuildStrategy) strategy).getImage();
} else if (strategy instanceof ICustomBuildStrategy) {
image = ((ICustomBuildStrategy) strategy).getImage();
} else if (strategy instanceof IDockerBuildStrategy) {
image = ((IDockerBuildStrategy) strategy).getBaseImage();
} else if (strategy instanceof ISTIBuildStrategy) {
image = ((ISTIBuildStrategy) strategy).getImage();
}
if (image != null) {
isEapStyle = containsEapLikeKeywords(image.getName());
}
if (!isEapStyle) {
// Check template labels as a last resort
// not sure it's even possible to reach this point
Map<String, String> labels = buildConfig.getLabels();
if (labels != null) {
String template = labels.get("template");
isEapStyle = containsEapLikeKeywords(template);
}
}
return isEapStyle;
}
Aggregations