I don't know exactly what you mean, with build number. I am using something like the attached mojo.

This creates a build number in a file and increments it for every build you started.

Heiko

dan tran wrote:

not that i know of, you may want write your own plugin to do that.

What SCM are you using?

-Dan



On 12/16/05, Karthik Manimaran <[EMAIL PROTECTED]> wrote:
Thanks. Is there a way to increment build version numbers without the
involvement of SCM (SCM is involved in release plugin)?

regards,
Karthik.


On 12/16/05, dan tran <[EMAIL PROTECTED]> wrote:
maven-release-plugin is the one but it increaments all modules.
-D


On 12/16/05, Karthik Manimaran <[EMAIL PROTECTED]> wrote:
Hi,

With every build I do for my J2EE project, I want the version of all
modules
to be automatically incremented. What is the best way of accomplishing
this?
Also is there a way to increment the version numbers only for modules
which
have had changes?

Thanks and regards,
Karthik.




/*
 * Main.java
 *
 * Created on 13. November 2005, 17:02
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.form105.maven.plugin;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

/**
 *
 * @goal create
 * @phase compile
 * @description a sample maven plugin
 */
public class CreateNumberMojo extends AbstractMojo {
    public void execute() throws MojoExecutionException, MojoFailureException {
        FileInputStream fileInStream = null;
        FileOutputStream fileOutStream = null;
        File file = new File(getFileName());
        getLog().info("Properties file to load: "+file);
        try {
            fileInStream = new FileInputStream(getFileName());
        } catch (FileNotFoundException ex) {
            try {
                file.createNewFile();
            } catch (IOException ioe) {
                getLog().error("Can't create file: " + file);
                ex.printStackTrace();
            }
        }
        Properties properties = new Properties();
        try {
            properties.load(fileInStream);
            fileInStream.close();
        } catch (IOException ex) {
            getLog().error(ex.getCause());
            ex.printStackTrace();
        }
        getLog().info("buildnumber: "+properties.getProperty(keyName));
        getLog().debug("Keyname: "+keyName);
        if (properties.getProperty(keyName) == null) {
            properties.setProperty(keyName,startNumber);
            getLog().info("Started a new BuildNumber from "+startNumber);
        } else {
            int i = Integer.parseInt(properties.getProperty(keyName));
            i++;
            properties.setProperty(keyName, new Integer(i).toString());
            getLog().info("Set BuildNumber to: "+i);
        }
        try {
            fileOutStream = new FileOutputStream(file);
            properties.store(fileOutStream, "Do not edit by hand. This counts 
build numbers");
            fileOutStream.close();
        } catch (IOException ex) {
            getLog().error(ex.getCause());
            getLog().error(ex.fillInStackTrace().toString());
        }        
    }

    /**
     * Holds value of property version.
     * @parameter expression="${settings.localRepository}"
     */
    private String version;

    /**
     * Getter for property version.
     * @return Value of property version.
     */
    public String getVersion() {
        return this.version;
    }

    /**
     * Setter for property version.
     * @param version New value of property version.
     */
    public void setVersion(String version) {
        this.version = version;
    }

    /**
     * Holds value of property file.
     * 
     * @parameter expression="buildnumber.properties"
     */
    private String fileName;

    /**
     * Getter for property file.
     * @return Value of property file.
     */
    public String getFileName() {
        return this.fileName;
    }

    /**
     * Setter for property file.
     * @param file New value of property file.
     */
    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    /**
     * Holds value of property startNumber.
     * @parameter expression="1"
     */
    private String startNumber;

    /**
     * Getter for property startNumber.
     * @return Value of property startNumber.
     */
    public String getStartNumber() {
        return this.startNumber;
    }

    /**
     * Setter for property startNumber.
     * @param startNumber New value of property startNumber.
     */
    public void setStartNumber(String startNumber) {
        this.startNumber = startNumber;
    }

    /**
     * Holds value of property keyName.
     *
     * @parameter expression="buildnumber"
     */
    private String keyName;

    /**
     * Getter for property keyName.
     * @return Value of property keyName.
     */
    public String getKeyName() {
        return this.keyName;
    }

    /**
     * Setter for property keyName.
     * @param keyName New value of property keyName.
     */
    public void setKeyName(String keyName) {
        this.keyName = keyName;
    }
    
    public static void main(String[] args) throws MojoExecutionException, 
MojoFailureException {
        
        Properties prop = new Properties();
        FileInputStream inStream;
        File file = new File("buildnumber.properties");
        try {
            inStream = new FileInputStream(file);
            prop.load(inStream);
            
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        prop.list(System.out);
        
        CreateNumberMojo buildnumber = new CreateNumberMojo();
        buildnumber.setFileName("buildnumber.properties");
        buildnumber.setKeyName("buildnumber");
        buildnumber.setStartNumber("1");
        
        buildnumber.execute();
    }
    
}
<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : pom.xml.xml
    Created on : 14. November 2005, 10:34
    Author     : Administrator
    Description:
        Purpose of the document follows.
-->

<project>
  <modelVersion>4.0.0</modelVersion>
  <!-- groupId = path to the plugin -->
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-buildnumber-plugin</artifactId>
  <packaging>maven-plugin</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Plugin to generate/increment a buildnumber</name>
  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>2.0</version>
    </dependency>
  </dependencies>
  <build>
    <sourceDirectory>src</sourceDirectory>
  </build>
</project>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to