From: Eugene.Petrenko Date: Tue, 23 Aug 2011 09:15:01 +0000 (+0200) Subject: base properties processor class X-Git-Url: https://git.jetbrains.org/?p=teamcity%2FdotNetPackagesSupport.git;a=commitdiff_plain;h=ad3fee4768e85817aca3267d6cc653ae334d3314 base properties processor class --- diff --git a/nuget-server/src/jetbrains/buildServer/nuget/server/util/BasePropertiesProcessor.java b/nuget-server/src/jetbrains/buildServer/nuget/server/util/BasePropertiesProcessor.java new file mode 100644 index 0000000..7c8692a --- /dev/null +++ b/nuget-server/src/jetbrains/buildServer/nuget/server/util/BasePropertiesProcessor.java @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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 jetbrains.buildServer.nuget.server.util; + +import jetbrains.buildServer.serverSide.InvalidProperty; +import jetbrains.buildServer.serverSide.PropertiesProcessor; +import jetbrains.buildServer.util.StringUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; + +/** + * @author Eugene Petrenko (eugene.petrenko@gmail.com) + * Date: 23.08.11 10:59 + */ +public abstract class BasePropertiesProcessor implements PropertiesProcessor { + @Nullable + protected static String notEmpty(@NotNull final String key, + @NotNull String errorMessage, + @NotNull final Map params, + @NotNull final Collection result) { + final String value = params.get(key); + if (StringUtil.isEmptyOrSpaces(value)) { + result.add(new InvalidProperty(key, errorMessage)); + return null; + } + return value; + } + + @NotNull + public final Collection process(final Map properties) { + Collection result = new ArrayList(); + + if (properties == null) return result; + checkProperties(Collections.unmodifiableMap(properties), result); + + return result; + } + + protected abstract void checkProperties(@NotNull final Map map, @NotNull Collection result); +}