1 /* 2 * Copyright 2008-2013 smartics, Kronseder & Reiner GmbH 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package de.smartics.maven.issues; 17 18 import org.apache.maven.artifact.versioning.ArtifactVersion; 19 20 /** 21 * Enumeration of version types. The version type identifies a specific part of 22 * a version number. The format is <code>major</code>.<code>minor</code>. 23 * <code>micro</code>. 24 * 25 * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a> 26 * @version $Revision:591 $ 27 */ 28 public enum VersionType 29 { 30 // ****************************** Enumeration ******************************* 31 32 // ********************************* Fields ********************************* 33 34 // --- constants ------------------------------------------------------------ 35 36 /** 37 * The major version type. This is the first number. 38 */ 39 MAJOR("major") 40 { 41 /** 42 * {@inheritDoc} 43 * <p> 44 * The major version must match to return the value <code>true</code>. 45 * </p> 46 * 47 * @see de.smartics.maven.issues.VersionType#isSameType(org.apache.maven.artifact.versioning.ArtifactVersion, 48 * org.apache.maven.artifact.versioning.ArtifactVersion) 49 */ 50 @Override 51 public boolean isSameType(final ArtifactVersion releaseVersion, 52 final ArtifactVersion currentVersion) 53 { 54 return releaseVersion.getMajorVersion() == currentVersion 55 .getMajorVersion(); 56 } 57 }, 58 59 /** 60 * The minor version type. This is the number in the middle. 61 */ 62 MINOR("minor") 63 { 64 /** 65 * {@inheritDoc} 66 * <p> 67 * The major and minor version must match to return the value 68 * <code>true</code>. 69 * </p> 70 * 71 * @see de.smartics.maven.issues.VersionType#isSameType(org.apache.maven.artifact.versioning.ArtifactVersion, 72 * org.apache.maven.artifact.versioning.ArtifactVersion) 73 */ 74 @Override 75 public boolean isSameType(final ArtifactVersion releaseVersion, 76 final ArtifactVersion currentVersion) 77 { 78 return releaseVersion.getMajorVersion() == currentVersion 79 .getMajorVersion() 80 && releaseVersion.getMinorVersion() == currentVersion 81 .getMinorVersion(); 82 } 83 }, 84 85 /** 86 * The micro version type. This it the last number. 87 */ 88 MICRO("micro") 89 { 90 /** 91 * {@inheritDoc} 92 * <p> 93 * The major, minor and micro version must match to return the value 94 * <code>true</code>. 95 * </p> 96 * 97 * @see de.smartics.maven.issues.VersionType#isSameType(org.apache.maven.artifact.versioning.ArtifactVersion, 98 * org.apache.maven.artifact.versioning.ArtifactVersion) 99 */ 100 @Override 101 public boolean isSameType(final ArtifactVersion releaseVersion, 102 final ArtifactVersion currentVersion) 103 { 104 return releaseVersion.getMajorVersion() == currentVersion 105 .getMajorVersion() 106 && releaseVersion.getMinorVersion() == currentVersion 107 .getMinorVersion() 108 && releaseVersion.getIncrementalVersion() == currentVersion 109 .getIncrementalVersion(); 110 } 111 }, 112 113 /** 114 * The all version type. This allows all versions. 115 */ 116 ALL("all") 117 { 118 /** 119 * {@inheritDoc} 120 * <p> 121 * The major, minor and micro version must match to return the value 122 * <code>true</code>. 123 * </p> 124 * 125 * @see de.smartics.maven.issues.VersionType#isSameType(org.apache.maven.artifact.versioning.ArtifactVersion, 126 * org.apache.maven.artifact.versioning.ArtifactVersion) 127 */ 128 @Override 129 public boolean isSameType(final ArtifactVersion releaseVersion, 130 final ArtifactVersion currentVersion) 131 { 132 return true; 133 } 134 }; 135 136 // --- members -------------------------------------------------------------- 137 138 /** 139 * The display name of the version. 140 */ 141 private final String name; 142 143 // ****************************** Constructors ****************************** 144 145 /** 146 * Default constructor. 147 * 148 * @param name the display name of the version. 149 */ 150 private VersionType(final String name) 151 { 152 this.name = name; 153 } 154 155 // ********************************* Methods ******************************** 156 157 // --- init ----------------------------------------------------------------- 158 159 // --- get&set -------------------------------------------------------------- 160 161 /** 162 * Returns the display name of the version. 163 * 164 * @return the display name of the version. 165 */ 166 public String getName() 167 { 168 return name; 169 } 170 171 // --- business ------------------------------------------------------------- 172 173 /** 174 * Returns the version type identified by the given name. 175 * 176 * @param name the name of the version type requested. 177 * @return the version type with the given name. 178 * @throws IllegalArgumentException if there is no version type with the given 179 * name. 180 * @throws NullPointerException if <code>name</code> is <code>null</code>. 181 */ 182 public static VersionType fromName(final String name) 183 throws IllegalArgumentException, NullPointerException 184 { 185 for (VersionType type : VersionType.values()) 186 { 187 if (name.equals(type.getName())) 188 { 189 return type; 190 } 191 } 192 193 throw new IllegalArgumentException("Unknown name '" + name 194 + "' for a version type."); 195 } 196 197 /** 198 * Checks if the release version and the current version are of the same type. 199 * 200 * @param releaseVersion the version to compare to. 201 * @param currentVersion the version to check if it is of the same type. 202 * @return <code>true</code> if the two versions are of the same type, 203 * <code>false</code> otherwise. 204 */ 205 public abstract boolean isSameType(ArtifactVersion releaseVersion, 206 ArtifactVersion currentVersion); 207 208 // --- object basics -------------------------------------------------------- 209 210 }