Java Code Examples for jetbrains.buildServer.util.StringUtil#isEmptyOrSpaces()

The following examples show how to use jetbrains.buildServer.util.StringUtil#isEmptyOrSpaces() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KubeProfilePropertiesProcessor.java    From teamcity-kubernetes-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<InvalidProperty> process(Map<String, String> map) {
    Collection<InvalidProperty> invalids = new ArrayList<>();
    if(StringUtil.isEmptyOrSpaces(map.get(API_SERVER_URL))) invalids.add(new InvalidProperty(API_SERVER_URL, "Kubernetes API server URL must not be empty"));
    final String authStrategy = map.get(AUTH_STRATEGY);
    if (StringUtil.isEmptyOrSpaces(authStrategy)) {
        invalids.add(new InvalidProperty(AUTH_STRATEGY, "Authentication strategy must be selected"));
        return invalids;
    }
    KubeAuthStrategy strategy = myKubeAuthStrategyProvider.find(authStrategy);
    if (strategy != null) {
        Collection<InvalidProperty> strategyCollection = strategy.process(map);
        if (strategyCollection != null && !strategyCollection.isEmpty()){
            invalids.addAll(strategyCollection);
        }
    }

    return invalids;
}
 
Example 2
Source File: KubePodNameGeneratorImpl.java    From teamcity-kubernetes-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
public String generateNewVmName(@NotNull KubeCloudImage image) {
  try {
    myLock.readLock().lock();
    if (!myIsAvailable.get()){
      throw new CloudException("Unable to generate a name for image " + image.getId() + " - server is shutting down");
    }
    String newVmName;
    do {
      String prefix = image.getAgentNamePrefix();
      if (StringUtil.isEmptyOrSpaces(prefix)) {
        prefix = image.getDockerImage();
      }
      if (StringUtil.isEmptyOrSpaces(prefix)) {
        return UUID.randomUUID().toString();
      }
      prefix = StringUtil.replaceNonAlphaNumericChars(prefix.trim().toLowerCase(), '-');
      newVmName = String.format("%s-%d", prefix, getNextCounter(prefix));
      setTouched(prefix);

    } while (image.findInstanceById(newVmName) != null);
    return newVmName;
  } finally {
    myLock.readLock().unlock();
  }
}
 
Example 3
Source File: KubeApiConnectorImpl.java    From teamcity-kubernetes-plugin with Apache License 2.0 6 votes vote down vote up
protected Config createConfig(@NotNull KubeApiConnection connectionSettings, @NotNull KubeAuthStrategy authStrategy){
    ConfigBuilder configBuilder = new ConfigBuilder()
      .withMasterUrl(connectionSettings.getApiServerUrl())
      .withNamespace(connectionSettings.getNamespace())
      .withRequestTimeout(DEFAULT_REQUEST_TIMEOUT_MS)
      .withHttp2Disable(true)
      .withConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT_MS);
    final String caCertData = connectionSettings.getCACertData();
    if(StringUtil.isEmptyOrSpaces(caCertData)){
        configBuilder.withTrustCerts(true);
    } else {
        configBuilder.withCaCertData(KubeUtils.encodeBase64IfNecessary(caCertData));
    }
    configBuilder = authStrategy.apply(configBuilder, connectionSettings);
    return configBuilder.build();
}
 
Example 4
Source File: TelegramSettingsController.java    From teamcity-telegram-plugin with Apache License 2.0 6 votes vote down vote up
private ActionErrors validate(@NotNull TelegramSettingsBean settings) {
  ActionErrors errors = new ActionErrors();
  if (StringUtil.isEmptyOrSpaces(settings.getBotToken())) {
    errors.addError("emptyBotToken", "Bot token must not be empty");
  }
  if (settings.isUseProxy()) {
    if (StringUtils.isEmpty(settings.getProxyServer())) {
      errors.addError("emptyProxyServer", "Proxy server must not be empty");
    }
    if (StringUtils.isEmpty(settings.getProxyPort())) {
      errors.addError("emptyProxyPort", "Proxy port must not be empty");
    }
  }
  String port = settings.getProxyPort();
  if (!StringUtils.isEmpty(port) &&
      (!StringUtil.isNumber(port) || Integer.valueOf(port) < 1 || Integer.valueOf(port) > 65535)) {
    errors.addError("badProxyPort", "Proxy port must be integer between 1 and 65535");
  }
  return errors;
}
 
Example 5
Source File: S3Util.java    From teamcity-s3-artifact-storage-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
public static Map<String, String> validateParameters(@NotNull final Map<String, String> params, final boolean acceptReferences) {
  final Map<String, String> commonErrors = AWSCommonParams.validate(params, acceptReferences);
  if (!commonErrors.isEmpty()) {
    return commonErrors;
  }
  final Map<String, String> invalids = new HashMap<>();
  if (StringUtil.isEmptyOrSpaces(getBucketName(params))) {
    invalids.put(beanPropertyNameForBucketName(), "S3 bucket name must not be empty");
  }
  final String pathPrefix = params.getOrDefault(S3_PATH_PREFIX_SETTING, "");
  if (TeamCityProperties.getBoolean("teamcity.internal.storage.s3.bucket.prefix.enable") && !StringUtil.isEmptyOrSpaces(pathPrefix)) {
    if (pathPrefix.length() > OUT_MAX_PREFIX_LENGTH) {
      invalids.put(S3_PATH_PREFIX_SETTING, "Should be less than " + OUT_MAX_PREFIX_LENGTH + " characters");
    }
    if (!OUR_OBJECT_KEY_PATTERN.matcher(pathPrefix).matches()) {
      invalids.put(S3_PATH_PREFIX_SETTING, "Should match the regexp [" + OUR_OBJECT_KEY_PATTERN.pattern() + "]");
    }
  }
  return invalids;
}
 
Example 6
Source File: AnsibleRunType.java    From tc-ansible-runner with MIT License 6 votes vote down vote up
@NotNull
@Override
public PropertiesProcessor getRunnerPropertiesProcessor() {
  return new PropertiesProcessor() {
    public Collection<InvalidProperty> process(final Map<String, String> properties) {
        List<InvalidProperty> errors = new ArrayList<InvalidProperty>();
        AnsibleRunConfig config = new AnsibleRunConfig(properties);
        if (AnsibleCommand.EXECUTABLE.equals(config.getCommandType())) {
            if (StringUtil.isEmptyOrSpaces(config.getExecutable())) {
                errors.add(new InvalidProperty(AnsibleRunnerConstants.EXECUTABLE_KEY, "Cannot be empty"));
            }
            if (StringUtil.isEmptyOrSpaces(config.getPlaybook())) {
                errors.add(new InvalidProperty(AnsibleRunnerConstants.PLAYBOOK_FILE_KEY, "Cannot be empty"));
            }
        } else if (AnsibleCommand.CUSTOM_SCRIPT.equals(config.getCommandType())) {
            if (StringUtil.isEmptyOrSpaces(config.getSourceCode())) {
                errors.add(new InvalidProperty(AnsibleRunnerConstants.SOURCE_CODE_KEY, "Cannot be empty"));
            }
        }
      return errors;
    }
  };
}
 
Example 7
Source File: VMRunType.java    From TeamCity.Virtual with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public PropertiesProcessor getRunnerPropertiesProcessor() {
  return new PropertiesProcessor() {
    @NotNull
    public Collection<InvalidProperty> process(Map<String, String> properties) {
      List<InvalidProperty> result = new ArrayList<InvalidProperty>();
      if (StringUtil.isEmptyOrSpaces(properties.get(VMConstants.PARAMETER_SCRIPT))) {
        result.add(new InvalidProperty(VMConstants.PARAMETER_SCRIPT, "Script should not be empty"));
      }

      final String vm = properties.get(VMConstants.PARAMETER_VM);
      final VM w = VM.find(vm);
      if (w == null) {
        result.add(new InvalidProperty(VMConstants.PARAMETER_VM, "Unknown VM"));
      } else {
        result.addAll(w.validate(properties));
      }
      return result;
    }
  };
}
 
Example 8
Source File: S3ArtifactsPublisher.java    From teamcity-s3-artifact-storage-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private String getPathPrefix(@NotNull final AgentRunningBuild build) {
  final List<String> pathSegments = new ArrayList<>();
  final String prefix = build.getArtifactStorageSettings().getOrDefault(S3Constants.S3_PATH_PREFIX_SETTING, "");
  if (!StringUtil.isEmptyOrSpaces(prefix)) {
    pathSegments.add(prefix);
  }
  pathSegments.add(build.getSharedConfigParameters().get(ServerProvidedProperties.TEAMCITY_PROJECT_ID_PARAM));
  pathSegments.add(build.getBuildTypeExternalId());
  pathSegments.add(Long.toString(build.getBuildId()));
  return StringUtil.join("/", pathSegments) + "/";
}
 
Example 9
Source File: SSHDeployerPropertiesProcessor.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<InvalidProperty> process(Map<String, String> properties) {
  Collection<InvalidProperty> result = super.process(properties);
  if (StringUtil.isEmptyOrSpaces(properties.get(DeployerRunnerConstants.PARAM_USERNAME)) &&
      !SSHRunnerConstants.AUTH_METHOD_DEFAULT_KEY.equals(properties.get(SSHRunnerConstants.PARAM_AUTH_METHOD))) {
    result.add(new InvalidProperty(DeployerRunnerConstants.PARAM_USERNAME, "Username must be specified."));
  }
  return result;
}
 
Example 10
Source File: CargoPropertiesProcessor.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<InvalidProperty> process(Map<String, String> properties) {
  Collection<InvalidProperty> result = super.process(properties);

  if (StringUtil.isEmptyOrSpaces(properties.get(DeployerRunnerConstants.PARAM_USERNAME))) {
    result.add(new InvalidProperty(DeployerRunnerConstants.PARAM_USERNAME, "Username must be specified."));
  }

  if (StringUtil.isEmptyOrSpaces(properties.get(DeployerRunnerConstants.PARAM_PASSWORD))) {
    result.add(new InvalidProperty(DeployerRunnerConstants.PARAM_PASSWORD, "Password must be specified"));
  }

  return result;
}
 
Example 11
Source File: DeployerPropertiesProcessor.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<InvalidProperty> process(Map<String, String> properties) {
  Collection<InvalidProperty> result = new HashSet<InvalidProperty>();
  if (StringUtil.isEmptyOrSpaces(properties.get(DeployerRunnerConstants.PARAM_TARGET_URL))) {
    result.add(new InvalidProperty(DeployerRunnerConstants.PARAM_TARGET_URL, "The target must be specified."));
  }

  if (StringUtil.isEmptyOrSpaces(properties.get(DeployerRunnerConstants.PARAM_SOURCE_PATH))) {
    result.add(new InvalidProperty(DeployerRunnerConstants.PARAM_SOURCE_PATH, "Artifact to deploy must be specified"));
  }
  return result;
}
 
Example 12
Source File: VmwarePropertiesProcessor.java    From teamcity-vmware-plugin with Apache License 2.0 5 votes vote down vote up
private void notEmpty(@NotNull final Map<String, String> props,
                               @NotNull final String key,
                               @NotNull final Collection<InvalidProperty> col) {
  if (!props.containsKey(key) || StringUtil.isEmptyOrSpaces(props.get(key))) {
    col.add(new InvalidProperty(key, "Value should be set"));
  }
}
 
Example 13
Source File: CommandLineUtils.java    From TeamCity.Virtual with Apache License 2.0 5 votes vote down vote up
@NotNull
public static List<String> additionalCommands(@Nullable final String text) {
  if (StringUtil.isEmptyOrSpaces(text)) return Collections.emptyList();

  final List<String> result = new ArrayList<String>();
  for (String s : text.split("[\\r\\n]+")) {
    final String arg = s.trim();
    if (arg.length() == 0) continue;

    result.addAll(StringUtil.splitHonorQuotes(arg));
  }

  return result;
}
 
Example 14
Source File: VMRunnerContext.java    From TeamCity.Virtual with Apache License 2.0 5 votes vote down vote up
@NotNull
public String getScript() throws RunBuildException {
  final String script = myContext.getRunnerParameters().get(VMConstants.PARAMETER_SCRIPT);
  if (StringUtil.isEmptyOrSpaces(script)) {
    throw new RunBuildException("Script should not be empty");
  }
  return script;
}
 
Example 15
Source File: DockerContext.java    From TeamCity.Virtual with Apache License 2.0 4 votes vote down vote up
@NotNull
public String getImageName() throws RunBuildException {
  final String image = myContext.getRunnerParameters().get(VMConstants.PARAMETER_DOCKER_IMAGE_NAME);
  if (StringUtil.isEmptyOrSpaces(image)) throw new RunBuildException("Docker image is not specified");
  return image;
}
 
Example 16
Source File: VMRunnerContext.java    From TeamCity.Virtual with Apache License 2.0 4 votes vote down vote up
@NotNull
public String getCheckoutMountPoint() {
  String mountPoint = myContext.getRunnerParameters().get(VMConstants.PARAMETER_CHECKOUT_MOUNT_POINT);
  return StringUtil.isEmptyOrSpaces(mountPoint) ? "/checkout" : mountPoint;
}