Java Code Examples for jetbrains.buildServer.util.StringUtil#isEmpty()
The following examples show how to use
jetbrains.buildServer.util.StringUtil#isEmpty() .
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: KubeDeleteImageDialogController.java From teamcity-kubernetes-plugin with Apache License 2.0 | 6 votes |
@Nullable @Override protected ModelAndView doHandle(@NotNull HttpServletRequest httpServletRequest, @NotNull HttpServletResponse httpServletResponse) throws Exception { String projectId = httpServletRequest.getParameter("projectId"); String profileId = httpServletRequest.getParameter("profileId"); String imageId = httpServletRequest.getParameter("imageId"); if(StringUtil.isEmpty(imageId)) return null; final CloudClientEx client = myCloudManager.getClientIfExistsByProjectExtId(projectId, profileId); CloudImage image = client.findImageById(imageId); if(isGet(httpServletRequest)){ ModelAndView modelAndView = new ModelAndView(myPluginDescriptor.getPluginResourcesPath("deleteImageDialog.jsp")); modelAndView.getModelMap().put("instances", image == null ? Collections.emptyList() : image.getInstances()); return modelAndView; } else if(isPost(httpServletRequest) && image != null){ for (CloudInstance instance : image.getInstances()){ client.terminateInstance(instance); } } return null; }
Example 2
Source File: CustomTemplatePodTemplateProvider.java From teamcity-kubernetes-plugin with Apache License 2.0 | 6 votes |
@Used("tests") /* package local for tests */ Pod getPodTemplateInternal(@NotNull final CloudInstanceUserData cloudInstanceUserData, @NotNull final String imageId, @NotNull final String namespace, final String instanceName, String spec) { spec = spec.replaceAll("%instance\\.id%", instanceName); if (StringUtil.isEmpty(spec)) { throw new KubeCloudException("Custom pod template spec is not specified for image " + imageId); } final PodTemplateSpec podTemplateSpec = Serialization.unmarshal( new ByteArrayInputStream(spec.getBytes()), PodTemplateSpec.class ); return patchedPodTemplateSpec(podTemplateSpec, instanceName, namespace, myServerSettings.getServerUUID(), imageId, cloudInstanceUserData); }
Example 3
Source File: AllureToolProvider.java From allure-teamcity with Apache License 2.0 | 6 votes |
@NotNull @Override public GetPackageVersionResult tryGetPackageVersion(@NotNull File toolPackage) { final String packageName = FilenameUtils.removeExtension(toolPackage.getName()); Pattern pattern = Pattern.compile("allure-commandline-(.+)"); Matcher matcher = pattern.matcher(packageName); if (!matcher.matches()) { return GetPackageVersionResult.error("Not allure-commandline"); } final String toolId = matcher.group(1); if (StringUtil.isEmpty(toolId)) { return GetPackageVersionResult.error(String.format("Failed to determine allure-commandline version based on its package file name %s. Checked package %s", toolPackage.getName(), toolPackage.getAbsolutePath())); } return GetPackageVersionResult.version(new AllureDownloadableToolVersion(toolId)); }
Example 4
Source File: VMWareApiConnectorImpl.java From teamcity-vmware-plugin with Apache License 2.0 | 6 votes |
private String getFullPath(@NotNull final String entityName, @NotNull final ManagedObjectReference mor, @Nullable final ManagedObjectReference firstParent, @Nullable final Datacenter dc){ final String uniqueName = String.format("%s (%s)", entityName, mor.getVal()); if (firstParent == null) { return uniqueName; } try { final String morPath = getFullMORPath(createExactManagedEntity(firstParent), dc); if (StringUtil.isEmpty(morPath)) { return uniqueName; } else if (("Resources".equals(entityName) || "vm".equals(entityName)) && !mor.getType().equals(firstParent.getType())) { LOG.debug("The pool is a special pool. Skipping it..."); return morPath; } else { return morPath + "/" + entityName; } } catch (Exception ex){ LOG.warnAndDebugDetails("Can't calculate full path for " + uniqueName, ex); return uniqueName; } }
Example 5
Source File: ClientCertificateAuthStrategy.java From teamcity-kubernetes-plugin with Apache License 2.0 | 5 votes |
@Override public Collection<InvalidProperty> process(final Map<String, String> properties) { List<InvalidProperty> retval = new ArrayList<>(); String certData = properties.get(SECURE_PREFIX+ CLIENT_CERTIFICATE_DATA); if (StringUtil.isEmpty(certData)){ retval.add(new InvalidProperty(CLIENT_CERTIFICATE_DATA, "Client certificate data is empty")); } String keyData = properties.get(SECURE_PREFIX + CLIENT_KEY_DATA); if (StringUtil.isEmpty(keyData)){ retval.add(new InvalidProperty(CLIENT_KEY_DATA, "Client key data is empty")); } return retval; }
Example 6
Source File: S3PreSignUrlHelper.java From teamcity-s3-artifact-storage-plugin with Apache License 2.0 | 5 votes |
@NotNull public static String writeS3ObjectKeys(@NotNull Collection<String> s3ObjectKeys) { Element rootElement = new Element(S3_OBJECT_KEYS); for (String s3ObjectKey : s3ObjectKeys) { if (StringUtil.isEmpty(s3ObjectKey)) continue; Element xmlElement = new Element(S3_OBJECT_KEY); xmlElement.addContent(s3ObjectKey); rootElement.addContent(xmlElement); } return JDOMUtil.writeDocument(new Document(rootElement), System.getProperty("line.separator")); }
Example 7
Source File: ClientCertificateAuthStrategy.java From teamcity-kubernetes-plugin with Apache License 2.0 | 5 votes |
@NotNull @Override public ConfigBuilder apply(@NotNull ConfigBuilder clientConfig, @NotNull KubeApiConnection connection) { String clientCertData = connection.getCustomParameter(SECURE_PREFIX+ CLIENT_CERTIFICATE_DATA); String clientKeyData = connection.getCustomParameter(SECURE_PREFIX+ CLIENT_KEY_DATA); if(StringUtil.isEmpty(clientCertData)) { throw new KubeCloudException("Client certificate data is empty"); } if(StringUtil.isEmpty(clientKeyData)) { throw new KubeCloudException("Client key data is empty"); } return clientConfig.withClientCertData(KubeUtils.encodeBase64IfNecessary(clientCertData)) .withClientKeyData(KubeUtils.encodeBase64IfNecessary(clientKeyData)); }
Example 8
Source File: DefaultServiceAccountAuthStrategy.java From teamcity-kubernetes-plugin with Apache License 2.0 | 5 votes |
@NotNull @Override public ConfigBuilder apply(@NotNull ConfigBuilder clientConfig, @NotNull KubeApiConnection connection) { String defaultServiceAccountAuthToken = getDefaultServiceAccountAuthToken(); if(StringUtil.isEmpty(defaultServiceAccountAuthToken)) throw new KubeCloudException("Can't locate default Kubernetes service account token."); return clientConfig.withOauthToken(defaultServiceAccountAuthToken); }
Example 9
Source File: TelegramSettingsBean.java From teamcity-telegram-plugin with Apache License 2.0 | 4 votes |
public String getEncryptedProxyPassword() { return StringUtil.isEmpty(proxyPassword) ? "" : RSACipher.encryptDataForWeb(proxyPassword); }
Example 10
Source File: VmwarePropertiesProcessor.java From teamcity-vmware-plugin with Apache License 2.0 | 4 votes |
@NotNull public Collection<InvalidProperty> process(final Map<String, String> properties) { List<InvalidProperty> list = new ArrayList<InvalidProperty>(); notEmpty(properties, VMWareWebConstants.SECURE_PASSWORD, list); notEmpty(properties, VMWareWebConstants.USERNAME, list); notEmpty(properties, VMWareWebConstants.SERVER_URL, list); final String instancesLimit = properties.get(VMWareWebConstants.PROFILE_INSTANCE_LIMIT); if (!StringUtil.isEmpty(instancesLimit)){ if (!StringUtil.isAPositiveNumber(instancesLimit)){ list.add(new InvalidProperty(VMWareWebConstants.PROFILE_INSTANCE_LIMIT, "Must be a positive integer or empty")); } } if (list.size() > 0) return list; final String serverURL = properties.get(VMWareWebConstants.SERVER_URL); final String currentProfileId = properties.get(CloudConstants.PROFILE_ID); final Map<String, String> existingImages = new HashMap<>(); myCloudManager.listAllProfiles().stream() .filter(p->(VmwareConstants.TYPE.equals(p.getCloudCode()) && (currentProfileId == null || !currentProfileId.equals(p.getProfileId())) && (serverURL.equals(p.getProfileProperties().get(VMWareWebConstants.SERVER_URL)))) ) .forEach(p-> myCloudManager .getClient(p.getProjectId(), p.getProfileId()) .getImages() .stream() .forEach(i->existingImages.put(i.getId().toUpperCase(), p.getProfileName())) ); final String imagesData = properties.get(CloudImageParameters.SOURCE_IMAGES_JSON); if (StringUtil.isEmpty(imagesData)) return list; // allowing empty profiles JsonParser parser = new JsonParser(); final JsonElement element = parser.parse(imagesData); if (element.isJsonArray()){ StreamSupport.stream(element.getAsJsonArray().spliterator(), false) .map(JsonElement::getAsJsonObject) .map(obj->obj.getAsJsonPrimitive(CloudImageParameters.SOURCE_ID_FIELD)) .filter(Objects::nonNull) .map(json->json.getAsString().toUpperCase()) .filter(existingImages::containsKey) .map(id->new InvalidProperty(CloudImageParameters.SOURCE_IMAGES_JSON, String.format("The cloud profile '%s' already contains an image named '%s'. Select a different VM or change the custom name.", existingImages.get(id), id) )).forEachOrdered(list::add); } else { list.add(new InvalidProperty(CloudImageParameters.SOURCE_IMAGES_JSON, "Unable to parse images data - bad format")); } return list; }
Example 11
Source File: ChooserController.java From teamcity-kubernetes-plugin with Apache License 2.0 | 4 votes |
@Nullable @Override protected ModelAndView doHandle(@NotNull HttpServletRequest httpServletRequest, @NotNull HttpServletResponse httpServletResponse) throws Exception { BasePropertiesBean propsBean = new BasePropertiesBean(null); PluginPropertiesUtil.bindPropertiesFromRequest(httpServletRequest, propsBean, true); Map<String, String> props = propsBean.getProperties(); KubeApiConnection apiConnection = new KubeApiConnection() { @NotNull @Override public String getApiServerUrl() { return props.get(API_SERVER_URL); } @NotNull @Override public String getNamespace() { String explicitNameSpace = props.get(KUBERNETES_NAMESPACE); return StringUtil.isEmpty(explicitNameSpace) ? DEFAULT_NAMESPACE : explicitNameSpace; } @Nullable @Override public String getCustomParameter(@NotNull String parameterName) { return props.containsKey(parameterName) ? props.get(parameterName) : props.get(SECURE_PROPERTY_PREFIX + parameterName); } @Nullable @Override public String getCACertData() { return props.get(SECURE_PROPERTY_PREFIX + CA_CERT_DATA); } }; String authStrategy = props.get(AUTH_STRATEGY); ModelAndView modelAndView = new ModelAndView(myPluginDescriptor.getPluginResourcesPath(getJspName())); try { KubeApiConnector apiConnector = new KubeApiConnectorImpl("editProfile", apiConnection, myAuthStrategyProvider.get(authStrategy)); modelAndView.getModelMap().put(getItemsName(), getItems(apiConnector)); modelAndView.getModelMap().put("error",""); } catch (Exception ex){ modelAndView.getModelMap().put(getItemsName(), Collections.emptyList()); if (ex.getCause() != null) { modelAndView.getModelMap().put("error", ex.getCause().getLocalizedMessage()); } else { modelAndView.getModelMap().put("error", ex.getLocalizedMessage()); } } return modelAndView; }
Example 12
Source File: FtpBuildProcessAdapter.java From teamcity-deployer-plugin with Apache License 2.0 | 4 votes |
private boolean isNone(String secureMode) { return StringUtil.isEmpty(secureMode) || "0".equals(secureMode); }
Example 13
Source File: KubeCloudImageImpl.java From teamcity-kubernetes-plugin with Apache License 2.0 | 4 votes |
@NotNull @Override public String getAgentName(@NotNull String instanceName) { final String agentNamePrefix = myImageData.getAgentNamePrefix(); return StringUtil.isEmpty(agentNamePrefix) ? instanceName : agentNamePrefix + instanceName; }
Example 14
Source File: SQRBuildService.java From TeamCity.SonarQubePlugin with Apache License 2.0 | 4 votes |
protected static String getProjectKey(String projectKey) { if (!StringUtil.isEmpty(projectKey)) { projectKey = projectKey.replaceAll("[^\\w\\-.:]", "_"); } return projectKey; }
Example 15
Source File: KubeCloudImageData.java From teamcity-kubernetes-plugin with Apache License 2.0 | 4 votes |
public int getInstanceLimit() { String parameter = myRawImageData.getParameter(KubeParametersConstants.IMAGE_INSTANCE_LIMIT); if(StringUtil.isEmpty(parameter)) return -1; return Integer.parseInt(parameter); }
Example 16
Source File: KubeCloudClientParametersImpl.java From teamcity-kubernetes-plugin with Apache License 2.0 | 4 votes |
@NotNull @Override public String getNamespace(){ String explicitNameSpace = myParameters.getParameter(KUBERNETES_NAMESPACE); return StringUtil.isEmpty(explicitNameSpace) ? DEFAULT_NAMESPACE : explicitNameSpace; }
Example 17
Source File: TelegramSettingsManager.java From teamcity-telegram-plugin with Apache License 2.0 | 4 votes |
private String scramble(String str) { return StringUtil.isEmpty(str) ? str : EncryptUtil.scramble(str); }
Example 18
Source File: TelegramSettingsManager.java From teamcity-telegram-plugin with Apache License 2.0 | 4 votes |
private Integer restoreInteger(String str) { return StringUtil.isEmpty(str) ? null : Integer.valueOf(str); }
Example 19
Source File: SimpleRunContainerProvider.java From teamcity-kubernetes-plugin with Apache License 2.0 | 4 votes |
@NotNull @Override public Pod getPodTemplate(@NotNull String instanceName, @NotNull CloudInstanceUserData cloudInstanceUserData, @NotNull KubeCloudImage kubeCloudImage, @NotNull KubeCloudClientParameters clientParameters) { ImagePullPolicy imagePullPolicy = kubeCloudImage.getImagePullPolicy(); String serverAddress = cloudInstanceUserData.getServerAddress(); String serverUUID = myServerSettings.getServerUUID(); String cloudProfileId = cloudInstanceUserData.getProfileId(); ContainerBuilder containerBuilder = new ContainerBuilder() .withName(instanceName) .withImage(kubeCloudImage.getDockerImage()) .withImagePullPolicy(imagePullPolicy == null ? ImagePullPolicy.IfNotPresent.getName() : imagePullPolicy.getName()) .withEnv(new EnvVar(KubeContainerEnvironment.SERVER_URL, serverAddress, null), new EnvVar(KubeContainerEnvironment.SERVER_UUID, serverUUID, null), new EnvVar(KubeContainerEnvironment.OFFICIAL_IMAGE_SERVER_URL, serverAddress, null), new EnvVar(KubeContainerEnvironment.IMAGE_NAME, kubeCloudImage.getId(), null), new EnvVar(KubeContainerEnvironment.PROFILE_ID, cloudProfileId, null), new EnvVar(KubeContainerEnvironment.INSTANCE_NAME, instanceName, null)); String dockerCommand = kubeCloudImage.getDockerCommand(); if(!StringUtil.isEmpty(dockerCommand)) containerBuilder = containerBuilder.withCommand(dockerCommand); String dockerArguments = kubeCloudImage.getDockerArguments(); if(!StringUtil.isEmpty(dockerArguments)) containerBuilder = containerBuilder.withArgs(dockerArguments); return new PodBuilder() .withNewMetadata() .withName(instanceName) .withNamespace(clientParameters.getNamespace()) .withLabels(CollectionsUtil.asMap( KubeTeamCityLabels.TEAMCITY_AGENT_LABEL, "", KubeTeamCityLabels.TEAMCITY_SERVER_UUID, serverUUID, KubeTeamCityLabels.TEAMCITY_CLOUD_PROFILE, cloudProfileId, KubeTeamCityLabels.TEAMCITY_CLOUD_IMAGE, kubeCloudImage.getId())) .endMetadata() .withNewSpec() .withContainers(Collections.singletonList(containerBuilder.build())) .withRestartPolicy(KubeApiConnector.NEVER_RESTART_POLICY) .endSpec() .build(); }
Example 20
Source File: TelegramSettingsBean.java From teamcity-telegram-plugin with Apache License 2.0 | 4 votes |
public String getEncryptedBotToken() { return StringUtil.isEmpty(botToken) ? "" : RSACipher.encryptDataForWeb(botToken); }