MavenVersion.java

  1. package com.soebes.itf.jupiter.extension;

  2. /*
  3.  * Licensed to the Apache Software Foundation (ASF) under one
  4.  * or more contributor license agreements.  See the NOTICE file
  5.  * distributed with this work for additional information
  6.  * regarding copyright ownership.  The ASF licenses this file
  7.  * to you under the Apache License, Version 2.0 (the
  8.  * "License"); you may not use this file except in compliance
  9.  * with the License.  You may obtain a copy of the License at
  10.  *
  11.  *  http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing,
  14.  * software distributed under the License is distributed on an
  15.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16.  * KIND, either express or implied.  See the License for the
  17.  * specific language governing permissions and limitations
  18.  * under the License.
  19.  */

  20. import org.apiguardian.api.API;

  21. import static com.soebes.itf.jupiter.extension.MavenVersionComparator.of;
  22. import static com.soebes.itf.jupiter.extension.Preconditions.requireNotEmpty;
  23. import static com.soebes.itf.jupiter.extension.Preconditions.requireNotNull;
  24. import static org.apiguardian.api.API.Status.EXPERIMENTAL;

  25. /**
  26.  * @author Karl Heinz Marbaise
  27.  */
  28. @API(status = EXPERIMENTAL, since = "0.1.0")
  29. public enum MavenVersion {
  30.   /**
  31.    * @deprecated Please use {@link #ANY} instead. Will be removed with Release 0.14.0
  32.    */
  33.   @Deprecated
  34.   UNKNOWN(of()),
  35.   /**
  36.    * Represent any Maven version.
  37.    */
  38.   ANY(of()),
  39.   /**
  40.    * Apache Maven Version 3.0.X
  41.    * Do not use them anymore, because Maven 3.0.X is very old!
  42.    */
  43.   @Deprecated
  44.   M3_0(of(3,0)),
  45.   @Deprecated
  46.   M3_0_5(of(3,0,5)),
  47.   /**
  48.    * Apache Maven Version 3.1.X
  49.    * Do not use them anymore, because Maven 3.0.X is very old!
  50.    */
  51.   @Deprecated
  52.   M3_1(of(3,1)),
  53.   @Deprecated
  54.   M3_1_0(of(3,1,0)),
  55.   @Deprecated
  56.   M3_1_1(of(3,1,1)),
  57.   /**
  58.    * Apache Maven Version 3.2.X
  59.    * Do not use them anymore, because Maven 3.0.X is very old!
  60.    */
  61.   @Deprecated
  62.   M3_2(of(3,2)),
  63.   @Deprecated
  64.   M3_2_1(of(3,2,1)),
  65.   @Deprecated
  66.   M3_2_2(of(3,2,2)),
  67.   @Deprecated
  68.   M3_2_3(of(3,2,3)),
  69.   @Deprecated
  70.   M3_2_5(of(3,2,5)),
  71.   /**
  72.    * Apache Maven Version 3.3.X
  73.    * Do not use them anymore, because Maven 3.0.X is very old!
  74.    */
  75.   @Deprecated
  76.   M3_3(of(3,3)),
  77.   @Deprecated
  78.   M3_3_1(of(3,3,1)),
  79.   @Deprecated
  80.   M3_3_3(of(3,3,3)),
  81.   @Deprecated
  82.   M3_3_9(of(3,3,9)),
  83.   /**
  84.    * Apache Maven Version 3.5.X
  85.    * Do not use them anymore, because Maven 3.0.X is very old!
  86.    */
  87.   @Deprecated
  88.   M3_5(of(3,5)),
  89.   @Deprecated
  90.   M3_5_0(of(3,5,0)),
  91.   @Deprecated
  92.   M3_5_2(of(3,5,2)),
  93.   @Deprecated
  94.   M3_5_3(of(3,5,3)),
  95.   @Deprecated
  96.   M3_5_4(of(3,5,4)),
  97.   /**
  98.    * Apache Maven Version 3.6.X
  99.    * Do not use them anymore, because Maven 3.0.X is very old!
  100.    */
  101.   M3_6(of(3,6)),
  102.   M3_6_0(of(3,6,0)),
  103.   M3_6_1(of(3,6,1)),
  104.   M3_6_2(of(3,6,2)),
  105.   M3_6_3(of(3,6,3)),
  106.   /**
  107.    * Apache Maven Version 3.8.X
  108.    */
  109.   M3_8(of(3,8)),
  110.   M3_8_1(of(3,8,1)),
  111.   M3_8_2(of(3,8,2)),
  112.   M3_8_3(of(3,8,3)),
  113.   M3_8_4(of(3,8,4)),
  114.   M3_8_5(of(3,8,5)),
  115.   M3_8_6(of(3,8,6)),
  116.   M3_8_7(of(3,8,7)),
  117.   M3_8_8(of(3,8,8)),
  118.   /**
  119.    * Apache Maven Version 3.9.X
  120.    */
  121.   M3_9(of(3,9)),
  122.   M3_9_0(of(3,9,0)),
  123.   M3_9_1(of(3,9,1)),
  124.   M3_9_2(of(3,9,2)),
  125.   M3_9_3(of(3,9,3)),
  126.   M3_9_4(of(3,9,4)),
  127.   M3_9_5(of(3,9,5)),
  128.   M3_9_6(of(3,9,6)),
  129.   /**
  130.    * Apache Maven Version 4.0.X
  131.    */
  132.   M4_0(of(4,0)),
  133.   M4_0_0(of(4,0,0)),
  134.   M4_0_1(of(4,0,1));

  135.   private static final MavenVersionComparator CURRENT_MAVEN_VERSION = determineCurrentVersion();

  136.   private final MavenVersionComparator versionComparator;

  137.   MavenVersion(MavenVersionComparator versionComparator) {
  138.     this.versionComparator = versionComparator;
  139.   }

  140.   private static MavenVersionComparator determineCurrentVersion() {
  141.     String currentVersion = requireNotNull(System.getProperty("maven.version"), "JVM system property 'maven.version' is empty.");
  142.     requireNotEmpty(currentVersion, "JVM system property 'maven.version' is empty. The maven version can not being detected.");
  143.     return MavenVersionParser.parseVersion(currentVersion);
  144.   }

  145.   /**
  146.    * @return {@code true} if <em>this</em> {@link MavenVersion} is known to be the Maven version for the currently being
  147.    * executed Maven version.
  148.    */
  149.   public boolean isCurrentVersion() {
  150.     return this.getVersion().compareTo(CURRENT_MAVEN_VERSION) == 0;
  151.   }

  152.   public MavenVersionComparator getVersion() {
  153.     return versionComparator;
  154.   }
  155. }