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.bugzilla; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 import org.apache.maven.artifact.versioning.ArtifactVersion; 21 22 import de.smartics.maven.issues.VersionType; 23 24 /** 25 * Aribiter to determine if a version should be skipped from or included in a 26 * report. 27 * 28 * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a> 29 * @version $Revision:591 $ 30 */ 31 public class DefaultVersionSkipper extends AbstractVersionSkipper 32 { 33 // ********************************* Fields ********************************* 34 35 // --- constants ------------------------------------------------------------ 36 37 /** 38 * Reference to the logger for this class. 39 */ 40 private static final Log LOG = LogFactory.getLog(DefaultVersionSkipper.class); 41 42 // --- members -------------------------------------------------------------- 43 44 /** 45 * Flag to indicate the only the current release is to be rendered. 46 */ 47 private final boolean currentReleaseOnly; 48 49 // ****************************** Initializer ******************************* 50 51 // ****************************** Constructors ****************************** 52 53 /** 54 * Default constructor. 55 * 56 * @param versionType the version type to be accepted. 57 * @param hasVersionRange defines if the configuration has a version range 58 * defined. 59 */ 60 public DefaultVersionSkipper(final VersionType versionType, 61 final boolean hasVersionRange) 62 { 63 super(versionType); 64 this.currentReleaseOnly = useCurrentReleaseVersionOnly(hasVersionRange); 65 } 66 67 // ****************************** Inner Classes ***************************** 68 69 // ********************************* Methods ******************************** 70 71 // --- init ----------------------------------------------------------------- 72 73 // --- get&set -------------------------------------------------------------- 74 75 // --- business ------------------------------------------------------------- 76 77 /** 78 * Checks if only issues matching the current release version should be taken 79 * into account. 80 * 81 * @param hasVersionRange defines if the configuration has a version range 82 * defined. 83 * @return <code>true</code> if only the current version is valid, 84 * <code>false</code> if all issues are to be considered. Please note 85 * that if there is a version range this range has been used as a 86 * constraint for the query. So all issues returned already meet the 87 * version constraint. 88 */ 89 private boolean useCurrentReleaseVersionOnly(final boolean hasVersionRange) 90 { 91 return !hasVersionRange && versionType != VersionType.MICRO; 92 } 93 94 /** 95 * Checks if the <code>version</code> should be skipped so that issues 96 * associated with this version are not rendered in the report. 97 * 98 * @param releaseVersion the version of the release. 99 * @param version the version to check for skipping its issues. 100 * @return <code>true</code> if the issues should be skipped and not rendered 101 * in the report, <code>false</code> otherwise. 102 */ 103 @SuppressWarnings("unchecked") 104 public boolean skipVersion(final ArtifactVersion releaseVersion, 105 final ArtifactVersion version) 106 { 107 final boolean isLaterVersionThanRelease = 108 releaseVersion.compareTo(version) < 0; 109 final boolean notCurrentReleaseButRequired = 110 (currentReleaseOnly && !releaseVersion.equals(version)); 111 final boolean isAllowedAsCurrentSnapshot = 112 isReleaseSnapshotOfVersion(releaseVersion, version); 113 final boolean isAllowedOnSamePage = 114 versionType.isSameType(releaseVersion, version) 115 && !isLaterVersionThanRelease; 116 final boolean skip = 117 !isAllowedAsCurrentSnapshot && !isAllowedOnSamePage 118 && (isLaterVersionThanRelease || notCurrentReleaseButRequired); 119 if (LOG.isTraceEnabled()) 120 { 121 LOG.trace("currentReleaseOnly=" + currentReleaseOnly + ", release=" 122 + releaseVersion + ", version=" + version 123 + ", isLaterVersionThanRelease=" + isLaterVersionThanRelease 124 + ", notCurrentReleaseButRequired=" 125 + notCurrentReleaseButRequired 126 + ", isAllowedAsCurrentSnapshot=" + isAllowedAsCurrentSnapshot 127 + ", isAllowedOnSamePage=" + isAllowedOnSamePage + ", skip=" 128 + skip); 129 } 130 return (skip); 131 } 132 133 // --- object basics -------------------------------------------------------- 134 135 }