-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from groupon/validation
split each .ci.yml section into a self validating module
- Loading branch information
Showing
13 changed files
with
535 additions
and
84 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
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
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
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
43 changes: 43 additions & 0 deletions
43
...om/groupon/jenkins/buildtype/dockercompose/buildconfiguration/ComposeFileNameSection.java
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,43 @@ | ||
/* | ||
The MIT License (MIT) | ||
Copyright (c) 2016, Groupon, Inc. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
package com.groupon.jenkins.buildtype.dockercompose.buildconfiguration; | ||
|
||
import com.groupon.jenkins.buildtype.InvalidBuildConfigurationException; | ||
|
||
public class ComposeFileNameSection { | ||
public static final String KEY = "docker-compose-file"; | ||
protected static final String INVALID_CI_YML_COMPOSE_FILE_NAME = "Invalid .ci.yml. Compose file name should be a string."; | ||
private final String commposeFileName; | ||
|
||
public ComposeFileNameSection(final Object composeFileNameConfig) { | ||
if (composeFileNameConfig != null && !(composeFileNameConfig instanceof String)) { | ||
throw new InvalidBuildConfigurationException(INVALID_CI_YML_COMPOSE_FILE_NAME); | ||
} | ||
this.commposeFileName = (String) composeFileNameConfig; | ||
} | ||
|
||
public String getComposeFileName() { | ||
return this.commposeFileName != null ? this.commposeFileName : "docker-compose.yml"; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...om/groupon/jenkins/buildtype/dockercompose/buildconfiguration/GenericCommandsSection.java
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,63 @@ | ||
/* | ||
The MIT License (MIT) | ||
Copyright (c) 2016, Groupon, Inc. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
package com.groupon.jenkins.buildtype.dockercompose.buildconfiguration; | ||
|
||
import com.groupon.jenkins.buildtype.InvalidBuildConfigurationException; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class GenericCommandsSection { | ||
public static final String INVALID_CI_YML_COMMANDS_SHOULD_BE_STRING_OR_LIST = "Invalid .ci.yml. Commands should be a list of string or a single string."; | ||
private final Object commandsConfig; | ||
|
||
public GenericCommandsSection(final Object commandSectionConfig) { | ||
|
||
if (commandSectionConfig != null && !(commandSectionConfig instanceof String) && !(commandSectionConfig instanceof List)) { | ||
throw new InvalidBuildConfigurationException(INVALID_CI_YML_COMMANDS_SHOULD_BE_STRING_OR_LIST); | ||
} | ||
|
||
this.commandsConfig = commandSectionConfig; | ||
|
||
} | ||
|
||
public List<String> getCommands() { | ||
if (this.commandsConfig == null) return new ArrayList<>(); | ||
|
||
final List<String> commands = new ArrayList<>(); | ||
if (this.commandsConfig instanceof String) { | ||
commands.add((String) this.commandsConfig); | ||
} else if (this.commandsConfig instanceof List) { | ||
final List l = (List) this.commandsConfig; | ||
|
||
for (final Object v : l) { | ||
if (!(v instanceof String)) { | ||
throw new RuntimeException(String.format("Unexpected type: %s. Expected String .", v.getClass().getName())); | ||
} | ||
commands.add((String) v); | ||
} | ||
} | ||
return commands; | ||
} | ||
} |
Oops, something went wrong.