Skip to content

Commit

Permalink
[OSJC-203] Expose context dir for buildconfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
jcantrill committed Aug 7, 2015
1 parent f47745e commit fba467e
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 6 deletions.
Expand Up @@ -137,7 +137,7 @@ public String getSourceURI() {
public <T extends IBuildSource> T getBuildSource() {
switch(asString(BUILDCONFIG_SOURCE_TYPE)){
case BuildSourceType.GIT:
return (T) new GitBuildSource(asString(BUILDCONFIG_SOURCE_URI), asString(BUILDCONFIG_SOURCE_REF));
return (T) new GitBuildSource(asString(BUILDCONFIG_SOURCE_URI), asString(BUILDCONFIG_SOURCE_REF), asString(BUILDCONFIG_SOURCE_CONTEXTDIR));
default:
}
return null;
Expand All @@ -156,6 +156,7 @@ public void setBuildSource(IBuildSource source){
}
set(BUILDCONFIG_SOURCE_URI, source.getURI());
set(BUILDCONFIG_SOURCE_TYPE, source.getType().toString());
set(BUILDCONFIG_SOURCE_CONTEXTDIR, source.getContextDir());
}

@Override
Expand Down
Expand Up @@ -18,10 +18,12 @@ public class GitBuildSource implements IGitBuildSource {

private String ref;
private String uri;
private String contextDir;

public GitBuildSource(String uri, String ref){
public GitBuildSource(String uri, String ref, String contextDir){
this.ref = ref;
this.uri = uri;
this.contextDir = contextDir;
}

@Override
Expand All @@ -39,4 +41,9 @@ public String getRef() {
return ref;
}

@Override
public String getContextDir() {
return contextDir;
}

}
Expand Up @@ -12,6 +12,7 @@
* @author Jeff Cantrill
*/
public interface BuildConfigPropertyKeys {
static final String BUILDCONFIG_SOURCE_CONTEXTDIR = "buildconfig.source.contextdir";
static final String BUILDCONFIG_SOURCE_TYPE = "buildconfig.source.type";
static final String BUILDCONFIG_SOURCE_REF = "buildconfig.source.ref";
static final String BUILDCONFIG_SOURCE_URI = "buildconfig.sourceuri";
Expand Down
Expand Up @@ -35,6 +35,7 @@ public interface OpenShiftApiModelProperties extends ResourcePropertyKeys{
put(BUILD_PODNAME, new String[]{"podName"});
put(BUILD_STATUS, new String[]{"status","phase"});

put(BUILDCONFIG_SOURCE_CONTEXTDIR, new String[]{"spec","source","contextDir"});
put(BUILDCONFIG_SOURCE_TYPE, new String[]{"spec","source","type"});
put(BUILDCONFIG_SOURCE_URI, new String[]{"spec","source","git","uri"});
put(BUILDCONFIG_SOURCE_REF, new String[]{"spec","source","git","ref"});
Expand Down Expand Up @@ -104,7 +105,8 @@ public interface OpenShiftApiModelProperties extends ResourcePropertyKeys{
put(BUILD_MESSAGE, new String[]{"status","message"});
put(BUILD_PODNAME, new String[]{"podName"});
put(BUILD_STATUS, new String[]{"status","phase"});


put(BUILDCONFIG_SOURCE_CONTEXTDIR, new String[]{"spec","source","contextDir"});
put(BUILDCONFIG_SOURCE_TYPE, new String[]{"spec","source","type"});
put(BUILDCONFIG_SOURCE_URI, new String[]{"spec","source","git","uri"});
put(BUILDCONFIG_SOURCE_REF, new String[]{"spec","source","git","ref"});
Expand Down
Expand Up @@ -24,4 +24,12 @@ public interface IBuildSource {
* @return
*/
String getURI();

/**
* The sub-directory relative to the repo root where the source code for the application exists.
* This allows to have buildable sources in directory other than root of repository.
*
* @return
*/
String getContextDir();
}
Expand Up @@ -103,7 +103,7 @@ public void setGitBuildSource() {

Map<String, String> env = new HashMap<String, String>();
env.put("foo", "bar");
writeConfig.setBuildSource(new GitBuildSource("git://github.com/openshift/ruby-hello-world.git", ""));
writeConfig.setBuildSource(new GitBuildSource("git://github.com/openshift/ruby-hello-world.git", "", "foobar"));

assertGitBuildSource(reCreateBuildConfig(writeConfig).getBuildSource());
}
Expand Down Expand Up @@ -137,6 +137,7 @@ private void assertBuildTriggers(IBuildTrigger[] triggers) {
private void assertGitBuildSource(IBuildSource source) {
assertEquals(BuildSourceType.GIT, source.getType());
assertEquals("git://github.com/openshift/ruby-hello-world.git", source.getURI());
assertEquals("foobar", source.getContextDir());
assertTrue(source instanceof IGitBuildSource);

IGitBuildSource git = (IGitBuildSource)source;
Expand Down
Expand Up @@ -103,7 +103,7 @@ public void setGitBuildSource() {

Map<String, String> env = new HashMap<String, String>();
env.put("foo", "bar");
writeConfig.setBuildSource(new GitBuildSource("git://github.com/openshift/ruby-hello-world.git", ""));
writeConfig.setBuildSource(new GitBuildSource("git://github.com/openshift/ruby-hello-world.git", "", "foobar"));

assertGitBuildSource(reCreateBuildConfig(writeConfig).getBuildSource());
}
Expand Down Expand Up @@ -137,6 +137,7 @@ private void assertBuildTriggers(IBuildTrigger[] triggers) {
private void assertGitBuildSource(IBuildSource source) {
assertEquals(BuildSourceType.GIT, source.getType());
assertEquals("git://github.com/openshift/ruby-hello-world.git", source.getURI());
assertEquals("foobar", source.getContextDir());
assertTrue(source instanceof IGitBuildSource);

IGitBuildSource git = (IGitBuildSource)source;
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/samples/openshift3/v1_build_config.json
Expand Up @@ -40,6 +40,7 @@
"git": {
"uri": "git://github.com/openshift/ruby-hello-world.git"
},
"contextDir" : "foobar"
},
"strategy": {
"type": "Source",
Expand Down
Expand Up @@ -39,7 +39,8 @@
"type": "Git",
"git": {
"uri": "git://github.com/openshift/ruby-hello-world.git"
}
},
"contextDir" : "foobar"
},
"strategy": {
"type": "Source",
Expand Down

0 comments on commit fba467e

Please sign in to comment.