use of jetbrains.buildServer.util.Option in project teamcity-rest by JetBrains.
the class BuildTypeUtil method resetSettingsParameter.
public static void resetSettingsParameter(final BuildTypeOrTemplate buildType, final String paramName) {
if (BUILD_NUMBER_COUNTER.equals(paramName)) {
setSettingsParameter(buildType, paramName, String.valueOf(1));
return;
}
Option option = Option.fromKey(paramName);
if (option == null) {
throw new BadRequestException("Unknown option: '" + paramName + "'");
}
setSettingsParameter(buildType, paramName, String.valueOf(option.getDefaultValue()));
}
use of jetbrains.buildServer.util.Option in project teamcity-rest by JetBrains.
the class BuildTypeUtil method setSettingsParameter.
/**
* Caller must ensure 'name' is a valid name of a BuildType setting
* @see #getSettingsParameters(jetbrains.buildServer.serverSide.SBuildType)
*/
public static void setSettingsParameter(final BuildTypeOrTemplate buildType, final String name, final String value) {
if (BUILD_NUMBER_COUNTER.equals(name)) {
if (buildType.getBuildType() != null) {
buildType.getBuildType().getBuildNumbers().setBuildNumberCounter(new Long(value));
} else {
throw new BadRequestException("Templates do not have build counter: could not set setting '" + BUILD_NUMBER_COUNTER + "'");
}
} else {
final Option option = Option.fromKey(name);
if (option == null) {
List<Option> allSupportedOptions = getAllSupportedOptions(buildType.get());
List<String> allOptionNames = new ArrayList<>();
allOptionNames.addAll(CollectionsUtil.convertCollection(allSupportedOptions, source -> source.getKey()));
allOptionNames.add(BUILD_NUMBER_COUNTER);
throw new IllegalArgumentException("No BuildType setting found for name '" + name + "'. Supported settings names are: " + allOptionNames);
}
final Object optionValue = option.fromString(value);
// noinspection unchecked
buildType.get().setOption(option, optionValue);
}
}
use of jetbrains.buildServer.util.Option in project teamcity-rest by JetBrains.
the class BuildTypeUtil method getAllSupportedOptions.
// todo: might use a generic util for this (e.g. Static HTML plugin has alike code to get all Page Places)
@NotNull
private static List<Option> getAllSupportedOptions(@NotNull final OptionSupport buildType) {
ArrayList<Option> result = new ArrayList<>();
Field[] declaredFields = BuildTypeOptions.class.getDeclaredFields();
for (Field declaredField : declaredFields) {
try {
if (Option.class.isAssignableFrom(declaredField.get(buildType).getClass())) {
Option option = null;
option = (Option) declaredField.get(buildType);
if (option == null) {
LOG.error("Error getting field for option '" + declaredField.getName() + "'");
} else {
result.add(option);
}
}
} catch (IllegalAccessException e) {
LOG.error("Error retrieving option '" + declaredField.getName() + "' , error: " + e.getMessage());
}
}
return result;
}
use of jetbrains.buildServer.util.Option in project teamcity-rest by JetBrains.
the class PropEntitySnapshotDep method setDependencyOption.
private void setDependencyOption(final String name, final String value, final Dependency dependency) {
final Option option = Option.fromKey(name);
if (option == null) {
throw new IllegalArgumentException("No option found for name '" + name + "'");
}
// noinspection unchecked
// todo: try to provide possible values for ENUM options in error message
dependency.setOption(option, option.fromString(value));
}
Aggregations