Search in sources :

Example 1 with Option

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()));
}
Also used : BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) Option(jetbrains.buildServer.util.Option)

Example 2 with Option

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);
    }
}
Also used : Filter(jetbrains.buildServer.util.filters.Filter) java.util(java.util) Property(jetbrains.buildServer.server.rest.model.Property) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) ParametersProvider(jetbrains.buildServer.parameters.ParametersProvider) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) EntityWithModifiableParameters(jetbrains.buildServer.server.rest.data.parameters.EntityWithModifiableParameters) HistoryRetentionPolicy(jetbrains.buildServer.serverSide.impl.cleanup.HistoryRetentionPolicy) Option(jetbrains.buildServer.util.Option) StringUtil(jetbrains.buildServer.util.StringUtil) LogUtil(jetbrains.buildServer.serverSide.impl.LogUtil) Logger(com.intellij.openapi.diagnostic.Logger) CollectionsUtil(jetbrains.buildServer.util.CollectionsUtil) PermissionChecker(jetbrains.buildServer.server.rest.data.PermissionChecker) ServiceLocator(jetbrains.buildServer.ServiceLocator) jetbrains.buildServer.serverSide(jetbrains.buildServer.serverSide) EntityWithParameters(jetbrains.buildServer.server.rest.data.parameters.EntityWithParameters) Field(java.lang.reflect.Field) Locator(jetbrains.buildServer.server.rest.data.Locator) Nullable(org.jetbrains.annotations.Nullable) CleanupSettingsSupport(jetbrains.buildServer.serverSide.impl.cleanup.CleanupSettingsSupport) Permission(jetbrains.buildServer.serverSide.auth.Permission) OptionSupport(jetbrains.buildServer.util.OptionSupport) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) NotNull(org.jetbrains.annotations.NotNull) ParameterFactory(jetbrains.buildServer.serverSide.parameters.ParameterFactory) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) Option(jetbrains.buildServer.util.Option)

Example 3 with Option

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;
}
Also used : Field(java.lang.reflect.Field) Option(jetbrains.buildServer.util.Option) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with Option

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));
}
Also used : Option(jetbrains.buildServer.util.Option)

Aggregations

Option (jetbrains.buildServer.util.Option)4 Field (java.lang.reflect.Field)2 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)2 NotNull (org.jetbrains.annotations.NotNull)2 Logger (com.intellij.openapi.diagnostic.Logger)1 java.util (java.util)1 ServiceLocator (jetbrains.buildServer.ServiceLocator)1 ParametersProvider (jetbrains.buildServer.parameters.ParametersProvider)1 Locator (jetbrains.buildServer.server.rest.data.Locator)1 PermissionChecker (jetbrains.buildServer.server.rest.data.PermissionChecker)1 EntityWithModifiableParameters (jetbrains.buildServer.server.rest.data.parameters.EntityWithModifiableParameters)1 EntityWithParameters (jetbrains.buildServer.server.rest.data.parameters.EntityWithParameters)1 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 Property (jetbrains.buildServer.server.rest.model.Property)1 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)1 jetbrains.buildServer.serverSide (jetbrains.buildServer.serverSide)1 Permission (jetbrains.buildServer.serverSide.auth.Permission)1 LogUtil (jetbrains.buildServer.serverSide.impl.LogUtil)1 CleanupSettingsSupport (jetbrains.buildServer.serverSide.impl.cleanup.CleanupSettingsSupport)1 HistoryRetentionPolicy (jetbrains.buildServer.serverSide.impl.cleanup.HistoryRetentionPolicy)1