Skip to content

Commit

Permalink
Moved version to conf/VERSION.properties; Version reads this file
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed Apr 28, 2015
1 parent 728677f commit dacfbe3
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 28 deletions.
13 changes: 5 additions & 8 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
Ant/ivy based build.xml file for JGroups. Needs ant to run
</description>

<property file="VERSION"/> <!-- Defines jgroups.version -->
<property name="root.dir" value="${basedir}"/>
<property name="conf.dir" value="${root.dir}/conf"/>
<property file="${conf.dir}/VERSION.properties"/> <!-- Defines jgroups.version -->
<property name="version" value="${jgroups.version}"/>
<property name="build.properties.file" value="build.properties"/>
<property file="${build.properties.file}"/>
<property name="root.dir" value="${basedir}"/>
<property name="src.dir" value="${root.dir}/src"/>
<property name="tests.dir" value="${root.dir}/tests"/>
<property name="other.dir" value="${tests.dir}/other"/>
Expand All @@ -29,7 +30,6 @@
<property name="manual.dir" value="${doc.dir}/manual"/>
<property name="tutorial.dir" value="${doc.dir}/tutorial"/>
<property name="javadoc.dir" value="${dist.dir}/javadoc"/>
<property name="conf.dir" value="${root.dir}/conf"/>
<property name="bin.dir" value="${root.dir}/bin"/>
<property name="keystore.dir" value="${root.dir}/keystore"/>
<property name="javadoc.packages" value="org.jgroups.*"/>
Expand Down Expand Up @@ -302,15 +302,14 @@
basedir="${compile.dir}"
manifest="${conf.dir}/MANIFEST.MF"
includes="org/jgroups/**">
<fileset dir="${conf.dir}" includes="*.xml, jg-messages*.properties"/>
<fileset dir="${conf.dir}" includes="*.xml, jg-messages*.properties, VERSION.properties"/>
<fileset dir="${compile.dir}/schema">
<include name="*.xsd"/>
</fileset>
<fileset dir="${root.dir}">
<include name="INSTALL.html"/>
<include name="LICENSE"/>
<include name="README"/>
<include name="VERSION"/>
</fileset>
<fileset dir="${lib.dir}">
<include name="licenses/thirdparty*"/>
Expand Down Expand Up @@ -340,8 +339,6 @@
</target>



<!-- generate java doc -->
<target name="javadoc"
depends="prepare,check-javadoc" unless="javadoc.exists"
description="Creates Javadoc documentation in ./dist/javadoc">
Expand All @@ -353,7 +350,7 @@
author="true"
version="true"
use="true"
bottom="Copyright &#169; 1998-2014 Bela Ban / Red Hat. All Rights Reserved."
bottom="Copyright &#169; 1998-2020 Red Hat. All Rights Reserved."
useexternalfile="yes"
doctitle="JGroups"
overview="${src.dir}/org/jgroups/overview.html">
Expand Down
2 changes: 1 addition & 1 deletion VERSION → conf/VERSION.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

## Defines the JGroups version
## This file should be the *only place* to change when changing the version number
jgroups.version=3.6.3.Final
jgroups.version=3.6.4.Final
2 changes: 1 addition & 1 deletion ivysettings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<ivysettings>
<settings defaultResolver="default"/>
<credentials host="repository.jboss.org" realm="jboss-releases-repository" username="${username}" passwd="${password}"/>
<properties file="VERSION"/>
<properties file="conf/VERSION.properties"/>

<property name="nexus-public"
value="https://repository.jboss.org/nexus/service/local/staging/deploy/maven2"/>
Expand Down
67 changes: 54 additions & 13 deletions src/org/jgroups/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
package org.jgroups;

import org.jgroups.annotations.Immutable;
import org.jgroups.util.Util;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* We're using the scheme described at http://www.jboss.com/index.html?module=bb&op=viewtopic&t=77231
Expand All @@ -19,21 +26,55 @@
*/
@Immutable
public class Version {
public static final short major = 3;
public static final short minor = 6;
public static final short micro = 3;
public static final String description=major + "." + minor + "." + micro + ".Final";

public static final short version=encode(major, minor, micro);
public static final String string_version=print(version);

private static final int MAJOR_SHIFT = 11;
private static final int MINOR_SHIFT = 6;
private static final int MAJOR_MASK = 0x00f800; // 1111100000000000 bit mask
private static final int MINOR_MASK = 0x0007c0; // 11111000000 bit mask
private static final int MICRO_MASK = 0x00003f; // 111111 bit mask
public static final short major;
public static final short minor;
public static final short micro;
public static final String description;

public static final short version;
public static final String string_version;

private static final int MAJOR_SHIFT = 11;
private static final int MINOR_SHIFT = 6;
private static final int MAJOR_MASK = 0x00f800; // 1111100000000000 bit mask
private static final int MINOR_MASK = 0x0007c0; // 11111000000 bit mask
private static final int MICRO_MASK = 0x00003f; // 111111 bit mask

public static final String VERSION_FILE="VERSION.properties";
public static final String VERSION_PROPERTY = "jgroups.version";
private static final Pattern VERSION_REGEXP = Pattern.compile("((\\d+)\\.(\\d+)\\.(\\d+)\\..*)");



static {
Properties properties=new Properties();
String value=null;
InputStream manifestAsStream=null;
try {
manifestAsStream=Util.getResourceAsStream(VERSION_FILE, Version.class);
if(manifestAsStream == null)
throw new FileNotFoundException(VERSION_FILE);
properties.load(manifestAsStream);
value=properties.getProperty(VERSION_PROPERTY);
if(value == null)
throw new Exception("value for " + VERSION_PROPERTY + " not found in " + VERSION_FILE);
} catch(Exception e) {
throw new IllegalStateException("Could not initialize version", e);
} finally {
Util.close(manifestAsStream);
}

Matcher versionMatcher = VERSION_REGEXP.matcher(value);
versionMatcher.find();

description = value;
major = Short.parseShort(versionMatcher.group(2));
minor = Short.parseShort(versionMatcher.group(3));
micro = Short.parseShort(versionMatcher.group(4));
version=encode(major, minor, micro);
string_version=print(version);
}


/**
* Prints the value of the description and cvs fields to System.out.
Expand Down
24 changes: 19 additions & 5 deletions tests/junit-functional/org/jgroups/tests/VersionTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package org.jgroups.tests;

import org.jgroups.Version;
import org.jgroups.Global;
import org.jgroups.Version;
import org.jgroups.util.Util;
import org.testng.annotations.Test;

import java.util.Properties;

import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

/**
* @author Bela Ban April 4 2003
* @version $Revision: 1.2 $
Expand All @@ -12,12 +18,20 @@
public class VersionTest {



public static void testVersionPrint() {
System.out.println("version is " +Version.printVersion());
assert true;
public void testIfManifestContainsImplementationVersion() throws Exception {
Properties properties=new Properties();
properties.load(Util.getResourceAsStream(Version.VERSION_FILE, getClass()));
String version=properties.getProperty(Version.VERSION_PROPERTY);
assertNotNull(version);
}

public void testIfVersionWasExtracted() throws Exception {
String version=Version.printDescription();
assertTrue(version.matches("JGroups [1-9].\\d.\\d\\..*"), "Extracted version: " + version);
}
public void testVersionPrint() {
assertNotNull(Version.printVersion());
}

public static void testNullVersion() {
assert !(Version.isSame((short)0));
Expand Down

0 comments on commit dacfbe3

Please sign in to comment.