001/* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014 015package org.basepom.mojo.propertyhelper.definitions; 016 017import static com.google.common.base.Preconditions.checkNotNull; 018 019import java.util.List; 020import java.util.Objects; 021import java.util.StringJoiner; 022 023import com.google.common.annotations.VisibleForTesting; 024import com.google.common.base.Splitter; 025 026public class PropertyDefinition { 027 028 /** 029 * Name. Field injected by maven. 030 */ 031 String name = null; 032 033 /** 034 * Value. Field injected by maven. 035 */ 036 String value = null; 037 038 /** 039 * Transformers. Field injected by maven. 040 */ 041 private List<String> transformers = List.of(); 042 043 // called by maven 044 public void setTransformers(String transformers) { 045 this.transformers = Splitter.on(",") 046 .omitEmptyStrings() 047 .trimResults() 048 .splitToList(transformers); 049 } 050 051 @VisibleForTesting 052 PropertyDefinition(final String name, final String value) { 053 this.name = checkNotNull(name, "name is null"); 054 this.value = checkNotNull(value, "value is null"); 055 } 056 057 public PropertyDefinition() { 058 } 059 060 public void check() { 061 checkNotNull(name, "property name is null"); 062 checkNotNull(value, "property value is null"); 063 } 064 065 public String getName() { 066 return name; 067 } 068 069 public String getValue() { 070 return value; 071 } 072 073 public List<String> getTransformers() { 074 return transformers; 075 } 076 077 @Override 078 public boolean equals(Object o) { 079 if (this == o) { 080 return true; 081 } 082 if (o == null || getClass() != o.getClass()) { 083 return false; 084 } 085 PropertyDefinition that = (PropertyDefinition) o; 086 return Objects.equals(name, that.name) && Objects.equals(value, that.value) && Objects.equals(transformers, 087 that.transformers); 088 } 089 090 @Override 091 public String toString() { 092 return new StringJoiner(", ", PropertyDefinition.class.getSimpleName() + "[", "]") 093 .add("name='" + name + "'") 094 .add("value='" + value + "'") 095 .add("transformers='" + transformers + "'") 096 .toString(); 097 } 098 099 @Override 100 public int hashCode() { 101 return Objects.hash(name, value, transformers); 102 } 103} 104 105