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.dvc.strategy; 016 017import javax.inject.Named; 018import javax.inject.Singleton; 019 020/** 021 * Relaxed variant of APR, very suitable for Java code. It is assumed that for every non-backwards compatible change, the artifactId is changed (e.g. by 022 * attaching a number to the artifactId) and the code is repackaged into a different package. So it is possible to have multiple, non-backwards compatible major 023 * versions on the classpath (foo vs. foo2 vs.foo3). So all versions with the same artifactId are backwards compatible; only forwards compatibility must be 024 * ensured. 025 * <p> 026 * By using the APR parser, the major version flags forwards compatibility, the minor and patch are not used. If a qualifier is present, it must match. 027 */ 028@Named("two-digits-backward-compatible") 029@Singleton 030public class TwoDigitsBackwardCompatibleVersionStrategy 031 extends AprVersionStrategy { 032 033 @Override 034 public String getName() { 035 return "two-digits-backward-compatible"; 036 } 037 038 @Override 039 protected int checkMajorCompatible(int expectedMajor, int resolvedMajor) { 040 // treat majors like minors in apache. 041 return super.checkMinorCompatible(expectedMajor, resolvedMajor); 042 } 043 044 @Override 045 protected int checkMinorCompatible(int expectedMinor, int resolvedMinor) { 046 // treat minors like patch in apache. 047 return super.checkPatchCompatible(expectedMinor, resolvedMinor); 048 } 049 050 @Override 051 protected int checkPatchCompatible(int expectedPatch, int resolvedPatch) { 052 if (expectedPatch != 0 || resolvedPatch != 0) { 053 return -1; // ensure that this is really a two digit version. 054 } 055 056 return 0; 057 } 058} 059