Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  The MIT License
   *
   *  Copyright 2012 Sony Ericsson Mobile Communications. All rights reserved.
   *  Copyright 2012 Sony Mobile Communications AB. All rights reserved.
   *
   *  Permission is hereby granted, free of charge, to any person obtaining a copy
   *  of this software and associated documentation files (the "Software"), to deal
   *  in the Software without restriction, including without limitation the rights
  *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  *  copies of the Software, and to permit persons to whom the Software is
  *  furnished to do so, subject to the following conditions:
  *
  *  The above copyright notice and this permission notice shall be included in
  *  all copies or substantial portions of the Software.
  *
  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  *  THE SOFTWARE.
  */
 package com.sonyericsson.hudson.plugins.gerrit.trigger.version;
 
Util class used to determine if the current Gerrit version is high enough to run a specific feature..

Author(s):
Tomas Westling <thomas.westling@sonyericsson.com>
 
 public final class GerritVersionChecker {
 
     private static final Logger logger = LoggerFactory.getLogger(GerritVersionChecker.class);

    
The feature version we want to compare the current Gerrit version with.
 
     public static enum Feature {
        
Triggering on files, added in Gerrit 2.3.
 
         fileTrigger("Trigger on files""2.3"),

        
Triggering on draft change published, added in Gerrit 2.5.
 
         triggerOnDraftPublished("Trigger on draft published""2.5");
 
         private final String displayName;
         private final String version;
         private final VersionNumber versionNumber;

        
Standard constructor.

Parameters:
displayName human readable name.
version the version number.
 
         Feature(String displayNameString version) {
             this. = displayName;
             this. = version;
              = new VersionNumber(version);
         }

        
Human readable name.

Returns:
the display name.
 
         public String getDisplayName() {
             return ;
         }

        
The required version string.

Returns:
the version.
 
         public String getVersion() {
             return ;
         }
     }
 
     ;

    
Private constructor to prevent instantiation of the util class.
 
     private GerritVersionChecker() {
     }

    
Tells us if we are running the correct version for a particular feature.

Parameters:
feature the feature we want to check.
Returns:
true if the Gerrit version is high enough for us to use this feature.
    public static boolean isCorrectVersion(Feature feature) {
        GerritVersionNumber gerritVersion = createVersionNumber(PluginImpl.getInstance().getGerritVersion());
        return isCorrectVersion(gerritVersionfeature);
    }

    
Tells us if we are running the correct version for a particular feature.

Parameters:
gerritVersion the version of Gerrit we are running.
feature the feature we want to check.
Returns:
true if the Gerrit version is high enough for us to use this feature.
    public static boolean isCorrectVersion(GerritVersionNumber gerritVersionFeature feature) {
        return (gerritVersion.isSnapshot() || !feature.versionNumber.isNewerThan(gerritVersion));
    }

    
Creates a new VersionNumber from the response of the gerrit server.

Parameters:
version the version as a String.
Returns:
the version as a versionNumber.
    public static GerritVersionNumber createVersionNumber(String version) {
        if (version == null || version.equals("")) {
            .error("Gerrit version number is null or the empty string.");
            return new HighestVersionNumber();
        }
        return GerritVersionNumber.getGerritVersionNumber(version);
    }
New to GrepCode? Check out our FAQ X