Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package octopus.teamcity.server;

import static octopus.teamcity.server.PropertiesValidator.checkCredentialsUnlessUsingConnection;
import static octopus.teamcity.server.PropertiesValidator.checkNotEmpty;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -25,7 +28,6 @@
import jetbrains.buildServer.serverSide.PropertiesProcessor;
import jetbrains.buildServer.serverSide.RunType;
import jetbrains.buildServer.serverSide.RunTypeRegistry;
import jetbrains.buildServer.util.StringUtil;
import jetbrains.buildServer.web.openapi.PluginDescriptor;
import octopus.teamcity.common.OctopusConstants;
import octopus.teamcity.server.connection.ConnectionInlineFieldCleaner;
Expand Down Expand Up @@ -62,27 +64,13 @@ public String getDescription() {
public PropertiesProcessor getRunnerPropertiesProcessor() {
final OctopusConstants c = new OctopusConstants();
return new PropertiesProcessor() {
private void checkNotEmpty(
@NotNull final Map<String, String> properties,
@NotNull final String key,
@NotNull final String message,
@NotNull final Collection<InvalidProperty> res) {
if (jetbrains.buildServer.util.StringUtil.isEmptyOrSpaces(properties.get(key))) {
res.add(new InvalidProperty(key, message));
}
}

@Override
@NotNull
public Collection<InvalidProperty> process(@Nullable final Map<String, String> p) {
final Collection<InvalidProperty> result = new ArrayList<InvalidProperty>();
if (p == null) return result;

final boolean usingConnection = !StringUtil.isEmptyOrSpaces(p.get(c.getConnectionIdKey()));
if (!usingConnection) {
checkNotEmpty(p, c.getServerKey(), "Server must be specified", result);
checkNotEmpty(p, c.getApiKey(), "API key must be specified", result);
}
checkCredentialsUnlessUsingConnection(p, c, result);
checkNotEmpty(p, c.getPackageIdKey(), "Package ID must be specified", result);
checkNotEmpty(p, c.getPackageVersionKey(), "Package version be specified", result);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package octopus.teamcity.server;

import static octopus.teamcity.server.PropertiesValidator.checkCredentialsUnlessUsingConnection;
import static octopus.teamcity.server.PropertiesValidator.checkNotEmpty;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -9,7 +12,6 @@
import jetbrains.buildServer.serverSide.PropertiesProcessor;
import jetbrains.buildServer.serverSide.RunType;
import jetbrains.buildServer.serverSide.RunTypeRegistry;
import jetbrains.buildServer.util.StringUtil;
import jetbrains.buildServer.web.openapi.PluginDescriptor;
import octopus.teamcity.common.OctopusConstants;
import octopus.teamcity.server.connection.ConnectionInlineFieldCleaner;
Expand Down Expand Up @@ -46,27 +48,13 @@ public String getDescription() {
public PropertiesProcessor getRunnerPropertiesProcessor() {
final OctopusConstants c = new OctopusConstants();
return new PropertiesProcessor() {
private void checkNotEmpty(
@NotNull final Map<String, String> properties,
@NotNull final String key,
@NotNull final String message,
@NotNull final Collection<InvalidProperty> res) {
if (jetbrains.buildServer.util.StringUtil.isEmptyOrSpaces(properties.get(key))) {
res.add(new InvalidProperty(key, message));
}
}

@Override
@NotNull
public Collection<InvalidProperty> process(@Nullable final Map<String, String> p) {
final Collection<InvalidProperty> result = new ArrayList<InvalidProperty>();
if (p == null) return result;

final boolean usingConnection = !StringUtil.isEmptyOrSpaces(p.get(c.getConnectionIdKey()));
if (!usingConnection) {
checkNotEmpty(p, c.getApiKey(), "API key must be specified", result);
checkNotEmpty(p, c.getServerKey(), "Server must be specified", result);
}
checkCredentialsUnlessUsingConnection(p, c, result);
checkNotEmpty(p, c.getProjectNameKey(), "Project name must be specified", result);

if (result.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package octopus.teamcity.server;

import static octopus.teamcity.server.PropertiesValidator.checkCredentialsUnlessUsingConnection;
import static octopus.teamcity.server.PropertiesValidator.checkNotEmpty;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -25,7 +28,6 @@
import jetbrains.buildServer.serverSide.PropertiesProcessor;
import jetbrains.buildServer.serverSide.RunType;
import jetbrains.buildServer.serverSide.RunTypeRegistry;
import jetbrains.buildServer.util.StringUtil;
import jetbrains.buildServer.web.openapi.PluginDescriptor;
import octopus.teamcity.common.OctopusConstants;
import octopus.teamcity.server.connection.ConnectionInlineFieldCleaner;
Expand Down Expand Up @@ -62,27 +64,13 @@ public String getDescription() {
public PropertiesProcessor getRunnerPropertiesProcessor() {
final OctopusConstants c = new OctopusConstants();
return new PropertiesProcessor() {
private void checkNotEmpty(
@NotNull final Map<String, String> properties,
@NotNull final String key,
@NotNull final String message,
@NotNull final Collection<InvalidProperty> res) {
if (jetbrains.buildServer.util.StringUtil.isEmptyOrSpaces(properties.get(key))) {
res.add(new InvalidProperty(key, message));
}
}

@Override
@NotNull
public Collection<InvalidProperty> process(@Nullable final Map<String, String> p) {
final Collection<InvalidProperty> result = new ArrayList<InvalidProperty>();
if (p == null) return result;

final boolean usingConnection = !StringUtil.isEmptyOrSpaces(p.get(c.getConnectionIdKey()));
if (!usingConnection) {
checkNotEmpty(p, c.getApiKey(), "API key must be specified", result);
checkNotEmpty(p, c.getServerKey(), "Server must be specified", result);
}
checkCredentialsUnlessUsingConnection(p, c, result);
checkNotEmpty(p, c.getProjectNameKey(), "Project name must be specified", result);
checkNotEmpty(p, c.getReleaseNumberKey(), "Release number must be specified", result);
checkNotEmpty(p, c.getDeployToKey(), "Deploy to must be specified", result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package octopus.teamcity.server;

import static octopus.teamcity.server.PropertiesValidator.checkNotEmpty;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -60,16 +62,6 @@ public String getDescription() {
public PropertiesProcessor getRunnerPropertiesProcessor() {
final OctopusConstants c = new OctopusConstants();
return new PropertiesProcessor() {
private void checkNotEmpty(
@NotNull final Map<String, String> properties,
@NotNull final String key,
@NotNull final String message,
@NotNull final Collection<InvalidProperty> res) {
if (jetbrains.buildServer.util.StringUtil.isEmptyOrSpaces(properties.get(key))) {
res.add(new InvalidProperty(key, message));
}
}

@Override
@NotNull
public Collection<InvalidProperty> process(@Nullable final Map<String, String> p) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package octopus.teamcity.server;

import static octopus.teamcity.server.PropertiesValidator.checkCredentialsUnlessUsingConnection;
import static octopus.teamcity.server.PropertiesValidator.checkNotEmpty;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -25,7 +28,6 @@
import jetbrains.buildServer.serverSide.PropertiesProcessor;
import jetbrains.buildServer.serverSide.RunType;
import jetbrains.buildServer.serverSide.RunTypeRegistry;
import jetbrains.buildServer.util.StringUtil;
import jetbrains.buildServer.web.openapi.PluginDescriptor;
import octopus.teamcity.common.OctopusConstants;
import octopus.teamcity.server.connection.ConnectionInlineFieldCleaner;
Expand Down Expand Up @@ -62,27 +64,13 @@ public String getDescription() {
public PropertiesProcessor getRunnerPropertiesProcessor() {
final OctopusConstants c = new OctopusConstants();
return new PropertiesProcessor() {
private void checkNotEmpty(
@NotNull final Map<String, String> properties,
@NotNull final String key,
@NotNull final String message,
@NotNull final Collection<InvalidProperty> res) {
if (jetbrains.buildServer.util.StringUtil.isEmptyOrSpaces(properties.get(key))) {
res.add(new InvalidProperty(key, message));
}
}

@Override
@NotNull
public Collection<InvalidProperty> process(@Nullable final Map<String, String> p) {
final Collection<InvalidProperty> result = new ArrayList<InvalidProperty>();
if (p == null) return result;

final boolean usingConnection = !StringUtil.isEmptyOrSpaces(p.get(c.getConnectionIdKey()));
if (!usingConnection) {
checkNotEmpty(p, c.getApiKey(), "API key must be specified", result);
checkNotEmpty(p, c.getServerKey(), "Server must be specified", result);
}
checkCredentialsUnlessUsingConnection(p, c, result);
checkNotEmpty(p, c.getProjectNameKey(), "Project name must be specified", result);
checkNotEmpty(
p, c.getPromoteFromKey(), "Environment to promote from must be specified", result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package octopus.teamcity.server;

import static octopus.teamcity.server.PropertiesValidator.checkCredentialsUnlessUsingConnection;
import static octopus.teamcity.server.PropertiesValidator.checkNotEmpty;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -25,7 +28,6 @@
import jetbrains.buildServer.serverSide.PropertiesProcessor;
import jetbrains.buildServer.serverSide.RunType;
import jetbrains.buildServer.serverSide.RunTypeRegistry;
import jetbrains.buildServer.util.StringUtil;
import jetbrains.buildServer.web.openapi.PluginDescriptor;
import octopus.teamcity.common.OctopusConstants;
import octopus.teamcity.server.connection.ConnectionInlineFieldCleaner;
Expand Down Expand Up @@ -62,27 +64,13 @@ public String getDescription() {
public PropertiesProcessor getRunnerPropertiesProcessor() {
final OctopusConstants c = new OctopusConstants();
return new PropertiesProcessor() {
private void checkNotEmpty(
@NotNull final Map<String, String> properties,
@NotNull final String key,
@NotNull final String message,
@NotNull final Collection<InvalidProperty> res) {
if (jetbrains.buildServer.util.StringUtil.isEmptyOrSpaces(properties.get(key))) {
res.add(new InvalidProperty(key, message));
}
}

@Override
@NotNull
public Collection<InvalidProperty> process(@Nullable final Map<String, String> p) {
final Collection<InvalidProperty> result = new ArrayList<InvalidProperty>();
if (p == null) return result;

final boolean usingConnection = !StringUtil.isEmptyOrSpaces(p.get(c.getConnectionIdKey()));
if (!usingConnection) {
checkNotEmpty(p, c.getApiKey(), "API key must be specified", result);
checkNotEmpty(p, c.getServerKey(), "Server must be specified", result);
}
checkCredentialsUnlessUsingConnection(p, c, result);
checkNotEmpty(p, c.getPackagePathsKey(), "Package paths must be specified", result);

if (result.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) Octopus Deploy and contributors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use
* these files except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package octopus.teamcity.server;

import java.util.Collection;
import java.util.Map;

import jetbrains.buildServer.serverSide.InvalidProperty;
import jetbrains.buildServer.util.StringUtil;
import octopus.teamcity.common.OctopusConstants;
import org.jetbrains.annotations.NotNull;

/** Shared validation helpers for run type {@code PropertiesProcessor}s. */
public final class PropertiesValidator {

private PropertiesValidator() {}

/**
* Adds an {@link InvalidProperty} to {@code result} when the value for {@code key} is missing or
* blank.
*/
public static void checkNotEmpty(
@NotNull final Map<String, String> properties,
@NotNull final String key,
@NotNull final String message,
@NotNull final Collection<InvalidProperty> result) {
if (StringUtil.isEmptyOrSpaces(properties.get(key))) {
result.add(new InvalidProperty(key, message));
}
}

/**
* Requires the inline server URL and API key unless a reusable connection is selected (in which
* case those credentials come from the connection at build start).
*/
public static void checkCredentialsUnlessUsingConnection(
@NotNull final Map<String, String> properties,
@NotNull final OctopusConstants constants,
@NotNull final Collection<InvalidProperty> result) {
final boolean usingConnection =
!StringUtil.isEmptyOrSpaces(properties.get(constants.getConnectionIdKey()));
if (!usingConnection) {
checkNotEmpty(properties, constants.getServerKey(), "Server must be specified", result);
checkNotEmpty(properties, constants.getApiKey(), "API key must be specified", result);
}
}
}
Loading