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