Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright (C) 2011 JFrog Ltd.
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 package org.jfrog.hudson.util;
 import hudson.EnvVars;
Utility class that provides methods that are related to Maven version checks.

Tomer Cohen
 public class MavenVersionHelper {
Minimal Maven version that works with AbstractRepositoryListener
     private static final String MINIMUM_MAVEN_VERSION = "3.0.2";
     public static boolean isLowerThanMaven3(MavenModuleSetBuild buildEnvVars varsBuildListener listener)
             throws IOExceptionInterruptedException {
         String version = getMavenVersion(buildvarslistener);
         if (StringUtils.isBlank(version)) {
             return true;
         ComparableVersion foundVersion = new ComparableVersion(version);
         ComparableVersion neededVersion = new ComparableVersion();
         return foundVersion.compareTo(neededVersion) < 0;


True if the Maven version of this build is at least MINIMUM_MAVEN_VERSION
     public static boolean isAtLeastResolutionCapableVersion(MavenModuleSetBuild buildEnvVars vars,
             BuildListener listenerthrows IOExceptionInterruptedException {
         return isAtLeastVersion(buildvarslistener);


True if the Maven version is at least the version that is passed.
     public static boolean isAtLeastVersion(MavenModuleSetBuild buildEnvVars varsBuildListener listener,
             String versionthrows IOExceptionInterruptedException {
         MavenModuleSet project = build.getProject();
         Maven.MavenInstallation mavenInstallation = getMavenInstallation(projectvarslistener);
         return isAtLeast(buildmavenInstallation.getHome(), version);

Get the hudson.model.EnvironmentSpecific and hudson.slaves.NodeSpecific Maven installation. First get the descriptor from the global Jenkins. Then populate it accordingly from the specific environment node that the process is currently running in e.g. the MAVEN_HOME variable may be defined only in the remote node and Jenkins is not persisting it as part of its installations.

project The Maven project that the maven installation is taken from.
vars The build's environment variables.
listener The build's event listener
hudson.AbortException If the hudson.tasks.Maven.MavenInstallation that is taken from the project is null then this exception is thrown.
     private static Maven.MavenInstallation getMavenInstallation(MavenModuleSet projectEnvVars vars,
             BuildListener listenerthrows IOExceptionInterruptedException {
         Maven.MavenInstallation mavenInstallation = project.getMaven();
         if (mavenInstallation == null) {
             throw new AbortException("A Maven installation needs to be available for this project to be built.\n" +
                     "Either your server has no Maven installations defined, or the requested Maven version does not exist.");
         return mavenInstallation.forEnvironment(vars).forNode(Computer.currentComputer().getNode(), listener);
    private static boolean isAtLeast(MavenModuleSetBuild buildString mavenHomeString version)
            throws IOExceptionInterruptedException {
        return build.getWorkspace().act(new MavenVersionCallable(mavenHomeversion));
    private static String getMavenVersion(MavenModuleSetBuild buildEnvVars vars,
            BuildListener listenerthrows IOExceptionInterruptedException {
        final Maven.MavenInstallation installation = getMavenInstallation(build.getProject(), varslistener);
        return build.getWorkspace().act(new FilePath.FileCallable<String>() {
            public String invoke(File fVirtualChannel channelthrows IOExceptionInterruptedException {
                try {
                    return MavenEmbedderUtils.getMavenVersion(new File(installation.getHome())).getVersion();
                } catch (MavenEmbedderException e) {
                    throw new RuntimeException(e);
New to GrepCode? Check out our FAQ X