Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.codehaus.mojo.rpm;
  
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you 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
  *
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
  * 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.
  */
 
 import java.util.Date;
 
Assists in calculating an rpm compatible version and build number (release) from the maven version.

If not populated, the release will be generated from the modifier portion of the project version using the following rules:

  • If no modifier exists, the release will be 1.
  • If the modifier ends with SNAPSHOT, the timestamp (in UTC) of the build will be appended to end.
  • All instances of '-' in the modifier will be replaced with '_'.
  • If a modifier exists and does not end with SNAPSHOT, "_1" will be appended to end.

Author(s):
Brett Okken
Version:
$Id: VersionHelper.java 11853 2010-02-08 13:41:10Z bokken $
Since:
2.0
 
 final class VersionHelper
 {
    
Wraps the version and release components that make up the entire version.
 
     static final class Version
     {
         String version;
 
         String release;
 
         public String toString()
         {
             return  + '-' + ;
         }
     }

    
Interface for the rpm related Mojos to implement. Provides access to the configured/default version and release attributes.
 
     static interface RPMVersionableMojo
         extends Mojo
     {
         String getVersion();
 
         String getRelease();
     }
 
     private final RPMVersionableMojo mojo;

    

Parameters:
mojo
 
     public VersionHelperRPMVersionableMojo mojo )
     {
         super();
         this. = mojo;
     }

    
Calculates and formats the version and release attributes based on the documented rules.

Returns:
The calculated/formatted version attributes.
 
     {
         final Version response = new Version();
 
         final String version = .getVersion();
         final String release = .getRelease();
         
         //this will get overwritten if we calculate a "release" value
         response.release = release;
 
        int modifierIndex = version.indexOf'-' );
        if ( modifierIndex == -1 )
        {
            response.version = version;
            
            if ( release == null || release.length() == 0 )
            {
                response.release = "1";
            }
        }
        else
        {
            response.version = version.substring( 0, modifierIndex );
            .getLog().warn"rpm version string truncated to " + response.version );
            if ( release == null || release.length() == 0 )
            {
                String modifier = version.substringmodifierIndex + 1, version.length() );
                modifier = modifier.replace'-''_' );
                if ( modifier.endsWith"SNAPSHOT" ) )
                {
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat"yyyyMMddHHmmss" );
                    simpleDateFormat.setTimeZone( TimeZone.getTimeZone"UTC" ) );
                    modifier += simpleDateFormat.formatnew Date() );
                }
                else
                {
                    modifier += "_1";
                }
                response.release = modifier;
            }
        }
        return response;
    }
New to GrepCode? Check out our FAQ X