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
020import org.apache.maven.artifact.versioning.ComparableVersion;
021
022/**
023 * This is the default versioning strategy used by previous versions of the plugin. It assumes that all smaller versions are compatible when replaced with
024 * larger numbers and compares version elements from left to right. E.g. 3.2.1 > 3.2 and 2.1.1 > 1.0. Usually works pretty ok.
025 */
026@Named("default")
027@Singleton
028public class DefaultVersionStrategy
029        implements Strategy {
030
031    @Override
032    public String getName() {
033        return "default";
034    }
035
036    @Override
037    public final boolean isCompatible(final ComparableVersion expectedVersion, final ComparableVersion resolvedVersion) {
038        // this is the same as converting the versions to the DefaultArtifactVersion and then do compareTo, as this
039        // uses ComparableVersion under the hood.
040        return resolvedVersion.compareTo(expectedVersion) >= 0;
041    }
042}