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

The following examples show how to use jetbrains.buildServer.util.StringUtil#isNotEmpty() . 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: S3Util.java    From teamcity-s3-artifact-storage-plugin with Apache License 2.0 6 votes vote down vote up
public static String getContentType(final File file) {
  String contentType = URLConnection.guessContentTypeFromName(file.getName());
  if (StringUtil.isNotEmpty(contentType)) {
    return contentType;
  }
  if (PROBE_CONTENT_TYPE_METHOD != null && FILE_TO_PATH_METHOD != null) {
    try {
      final Object result = PROBE_CONTENT_TYPE_METHOD.invoke(null, FILE_TO_PATH_METHOD.invoke(file));
      if (result instanceof String) {
        contentType = (String)result;
      }
    } catch (Exception ignored) {
    }
  }
  return StringUtil.notEmpty(contentType, DEFAULT_CONTENT_TYPE);
}
 
Example 2
Source File: KubeCloudClient.java    From teamcity-kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public String generateAgentName(@NotNull AgentDescription agentDescription) {
    final Map<String, String> agentParameters = agentDescription.getAvailableParameters();
    final String imageId = agentParameters.get(Constants.ENV_PREFIX + IMAGE_NAME);
    final String instanceName = agentParameters.get(Constants.ENV_PREFIX + INSTANCE_NAME);
    if (!StringUtil.isNotEmpty(imageId) || !StringUtil.isNotEmpty(instanceName))
        return null;

    final KubeCloudImage cloudImage = myImageIdToImageMap.get(imageId);
    if(cloudImage == null)
        return null;

    return cloudImage.getAgentName(instanceName);
}
 
Example 3
Source File: S3ArtifactContentProvider.java    From teamcity-s3-artifact-storage-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public InputStream getContent(@NotNull StoredBuildArtifactInfo storedBuildArtifactInfo) throws IOException {
  final Map<String, String> params;
  final ArtifactData artifactData = storedBuildArtifactInfo.getArtifactData();
  if (artifactData == null) {
    throw new IOException("Invalid artifact data: S3 object path property is not set");
  }

  final String artifactPath = artifactData.getPath();
  try {
    params = S3Util.validateParameters(storedBuildArtifactInfo.getStorageSettings());
  } catch (IllegalArgumentException e) {
    throw new IOException("Failed to get artifact " + artifactPath + " content: Invalid storage settings " + e.getMessage(), e);
  }

  final String bucketName = S3Util.getBucketName(params);
  final String key = S3Util.getPathPrefix(storedBuildArtifactInfo.getCommonProperties()) + artifactPath;

  try {
    return S3Util.withS3Client(
      ParamUtil.putSslValues(myServerPaths, params),
      client -> client.getObject(bucketName, key).getObjectContent()
    );
  } catch (Throwable t) {
    final AWSException awsException = new AWSException(t);
    final String details = awsException.getDetails();
    if (StringUtil.isNotEmpty(details)) {
      final String message = awsException.getMessage() + details;
      LOG.warn(message);
    }
    throw new IOException(String.format(
      "Failed to get artifact '%s' content in bucket '%s': %s",
      artifactPath, bucketName, awsException.getMessage()
    ), awsException);
  }
}
 
Example 4
Source File: SSHSessionProvider.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
private Session initSessionKeyFile(String username, String password, File keyFile, JSch jsch) throws JSchException {
  try {
    if (StringUtil.isNotEmpty(password)) {
      myLog.debug("Adding password");
      jsch.addIdentity(keyFile.getCanonicalPath(), password);
    } else {
      jsch.addIdentity(keyFile.getCanonicalPath());
    }
    final Session session = jsch.getSession(username, myHost, myPort);
    session.setConfig("PreferredAuthentications", "publickey");
    return session;
  } catch (IOException e) {
    throw new JSchException("Failed to use key file", e);
  }
}
 
Example 5
Source File: VMWarePropertiesReader.java    From teamcity-vmware-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getToolPath(@NotNull final BuildAgentConfiguration configuration) {
  final String rpctoolPath = TeamCityProperties.getProperty(RPC_TOOL_PARAMETER);
  if (StringUtil.isNotEmpty(rpctoolPath)){
    return rpctoolPath;
  }

  if (SystemInfo.isUnix) { // Linux, MacOSX, FreeBSD
    final Map<String, String> envs = configuration.getBuildParameters().getEnvironmentVariables();
    final String path = envs.get("PATH");
    if (path != null) for (String p : StringUtil.splitHonorQuotes(path, File.pathSeparatorChar)) {
      final File file = new File(p, VMWARE_RPCTOOL_NAME);
      if (file.exists()) {
        return file.getAbsolutePath();
      }
    }
  }
  if (SystemInfo.isLinux) {
    return getExistingCommandPath(LINUX_COMMANDS);
  } else if (SystemInfo.isWindows) {
    return getExistingCommandPath(WINDOWS_COMMANDS);
  } else if (SystemInfo.isMac) {
    return getExistingCommandPath(MAC_COMMANDS);
  } else {
    return getExistingCommandPath(LINUX_COMMANDS); //todo: update for other OS'es
  }
}
 
Example 6
Source File: SSHSessionProvider.java    From teamcity-deployer-plugin with Apache License 2.0 4 votes vote down vote up
public String getSessionString() {
  return (StringUtil.isNotEmpty(myRemotePath) ? "[" + myRemotePath + "] on " : "") + "host [" + myHost + ":" + myPort + "]";
}
 
Example 7
Source File: VmwareCloudImage.java    From teamcity-vmware-plugin with Apache License 2.0 4 votes vote down vote up
public void updateActualSourceState(@NotNull final VmwareSourceState state){
  if (StringUtil.isNotEmpty(state.getSnapshotName()) && !state.equals(myActualSourceState.get())){
      myActualSourceState.set(state);
      LOG.info("Updated actual vm source state name for " + myImageDetails.getSourceId() + " to " + state);
  }
}
 
Example 8
Source File: SlackNotificator.java    From tcSlackBuildNotifier with MIT License 4 votes vote down vote up
private boolean userHasSlackIdConfigured(SUser sUser) {
    String userName = sUser.getPropertyValue(USERID_KEY);

    return StringUtil.isNotEmpty(userName);
}
 
Example 9
Source File: Commit.java    From tcSlackBuildNotifier with MIT License 4 votes vote down vote up
public boolean hasSlackUserId(){
    return StringUtil.isNotEmpty(slackUserId);
}