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 static com.google.common.base.Preconditions.checkNotNull; 018 019import javax.inject.Named; 020import javax.inject.Singleton; 021 022import org.apache.maven.artifact.versioning.ArtifactVersion; 023import org.apache.maven.artifact.versioning.ComparableVersion; 024import org.apache.maven.artifact.versioning.DefaultArtifactVersion; 025 026/** 027 * Single Digit, may have a prefix. Assume that larger numbers are backwards compatible. 028 * <p> 029 * e.g. used for google guava. 030 */ 031@Named("single-digit") 032@Singleton 033public class SingleDigitVersionStrategy 034 implements Strategy { 035 036 @Override 037 public String getName() { 038 return "single-digit"; 039 } 040 041 @Override 042 public boolean isCompatible(final ComparableVersion expectedVersion, final ComparableVersion resolvedVersion) { 043 final ArtifactVersion aprExpectedVersion = new DefaultArtifactVersion(checkNotNull(expectedVersion, "expectedVersion is null").getCanonical()); 044 final ArtifactVersion aprResolvedVersion = new DefaultArtifactVersion(checkNotNull(resolvedVersion, "resolvedVersion is null").getCanonical()); 045 046 return aprResolvedVersion.getMajorVersion() >= aprExpectedVersion.getMajorVersion(); 047 } 048}