[Schmitzm-commits] r800 - in trunk/src/skrueger: . geotools versionnumber

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Apr 14 18:33:31 CEST 2010


Author: alfonx
Date: 2010-04-14 18:33:30 +0200 (Wed, 14 Apr 2010)
New Revision: 800

Added:
   trunk/src/skrueger/versionnumber/
   trunk/src/skrueger/versionnumber/ReleaseUtil.java
Modified:
   trunk/src/skrueger/AttributeMetadataInterface.java
   trunk/src/skrueger/geotools/AttributeMetadataImplMap.java
Log:
Neue Hilfsklasse ReleaseUtil bietet zwei nette Funktionen 
1. LGPL und GPL Lizentexte auf Logger ausgeben
2. Version-String aus /release.proeprties Dateien erstellen. Weiterhin ist im JavaDoc beschrieben, wie man das mit Maven sauber einrichtet.

Modified: trunk/src/skrueger/AttributeMetadataInterface.java
===================================================================
--- trunk/src/skrueger/AttributeMetadataInterface.java	2010-04-14 11:13:22 UTC (rev 799)
+++ trunk/src/skrueger/AttributeMetadataInterface.java	2010-04-14 16:33:30 UTC (rev 800)
@@ -2,7 +2,6 @@
 
 import java.util.HashSet;
 
-import org.geotools.feature.NameImpl;
 import org.opengis.feature.type.Name;
 
 import skrueger.geotools.Copyable;

Modified: trunk/src/skrueger/geotools/AttributeMetadataImplMap.java
===================================================================
--- trunk/src/skrueger/geotools/AttributeMetadataImplMap.java	2010-04-14 11:13:22 UTC (rev 799)
+++ trunk/src/skrueger/geotools/AttributeMetadataImplMap.java	2010-04-14 16:33:30 UTC (rev 800)
@@ -2,7 +2,6 @@
 
 import java.util.List;
 
-import org.geotools.feature.NameImpl;
 import org.opengis.feature.type.Name;
 
 import skrueger.AttributeMetadataImpl;

Added: trunk/src/skrueger/versionnumber/ReleaseUtil.java
===================================================================
--- trunk/src/skrueger/versionnumber/ReleaseUtil.java	2010-04-14 11:13:22 UTC (rev 799)
+++ trunk/src/skrueger/versionnumber/ReleaseUtil.java	2010-04-14 16:33:30 UTC (rev 800)
@@ -0,0 +1,189 @@
+package skrueger.versionnumber;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Wer sein Maven Projekt wie folgt konfiguriert (oder ähnlich) kann die Maven +
+ * SVN revision nummer als Programmversion verwenden. <br/>
+ * 
+ * 1. pom.xml anpassen: <code>
+			<plugin>
+				<groupId>org.codehaus.mojo</groupId>
+				<artifactId>buildnumber-maven-plugin</artifactId>
+				<version>1.0-beta-4</version>
+				<executions>
+					<execution>
+						<id>buildnumber in phase initialize</id>
+						<phase>initialize</phase>
+						<goals>
+							<goal>create</goal>
+						</goals>
+					</execution>
+				</executions>
+				<configuration>
+				
+					<doCheck>false</doCheck>
+					<doUpdate>false</doUpdate>
+					<providerImplementations>
+						<svn>javasvn</svn>
+					</providerImplementations>
+				</configuration>
+			</plugin>
+		</code><br/>
+ * 2. Datei src/main/resources.properties mit foglenden Inhalt anlegen:<code>
+#Properties describing this release/build
+version=${project.version}
+build=${buildNumber}
+</code><br/>
+ * 3. Filtering für die src/main/resources.properties - Datei einschalten:<code>
+		<resources>
+			<resource>
+				<filtering>true</filtering>
+				<directory>src/main/resources</directory>
+				<includes><include>release.properties</include></includes>
+			</resource>
+		</resources>
+
+</code>
+ */
+public class ReleaseUtil {
+
+	/**
+	 * @return The major.minor version, build number and build date
+	 */
+	public static String getVersionInfo(Class<?> clazz) {
+		/**
+		 * Release properties einlesen
+		 */
+		try {
+			return "v" + getVersion(clazz) + "-r" + getVersionBuild(clazz);
+		} catch (final Exception e) {
+			return "unknown version";
+		}
+	}
+
+	/**
+	 * Return the major part of the software version of GP/AV/AS.
+	 * 
+	 * @throws Exception
+	 *             if release.properties not found
+	 */
+	public static int getVersionBuild(Class<?> clazz) {
+		try {
+			final URL releasePropsURL = clazz
+					.getResource("/release.properties");
+
+			final Properties releaseProps = new Properties();
+			final InputStream openStream = releasePropsURL.openStream();
+			try {
+				releaseProps.load(openStream);
+			} finally {
+				openStream.close();
+			}
+			final String str = releaseProps.getProperty("build", "0");
+
+			if (str.equals("${buildNumber}")) {
+				// We are in development or Maven didn't filter the properties
+				// while building.
+				return 0;
+			}
+
+			return Integer.parseInt(str);
+		} catch (final Exception e) {
+			throw new RuntimeException(
+					"/release.properties could not be read from "
+							+ clazz.getSimpleName(), e);
+		}
+
+	}
+
+	/**
+	 * Return the major part of the software version of GP/AV/AS.
+	 * 
+	 * @throws Exception
+	 *             if release.properties not found
+	 */
+	public static String getVersion(Class<?> clazz) {
+		try {
+
+			final URL releasePropsURL = clazz
+					.getResource("/release.properties");
+
+			final Properties releaseProps = new Properties();
+			final InputStream openStream = releasePropsURL.openStream();
+			try {
+				releaseProps.load(openStream);
+			} finally {
+				openStream.close();
+			}
+
+			final String defaultVer = "DEV";
+			final String versionProperty = releaseProps.getProperty("version",
+					defaultVer);
+			if (versionProperty.equals("${project.version}"))
+				return defaultVer;
+			return versionProperty;
+		} catch (final Exception e) {
+			throw new RuntimeException(
+					"/release.properties could not be read from "
+							+ clazz.getSimpleName(), e);
+		}
+
+	}
+
+	public static int getVersionMaj(Class<?> clazz) {
+		try {
+			return Integer.parseInt(getVersion(clazz).split("\\.")[0]);
+		} catch (final Exception e) {
+			return 0;
+		}
+	}
+
+	public static int getVersionMin(Class<?> clazz) {
+		try {
+			return Integer.parseInt(getVersion(clazz).split("\\.")[1]);
+		} catch (final Exception e) {
+			return 0;
+		}
+
+	}
+
+	/**
+	 * Print the GPL disclaimer to the given {@link Logger} as on INFO level.
+	 */
+	public static void logGPLCopyright(final Logger logger) {
+
+		logger
+				.info("\nThis program is free software: you can redistribute it and/or modify\n"
+						+ "it under the terms of the GNU General Public License as published by\n"
+						+ "the Free Software Foundation, either version 3 of the License, or\n"
+						+ "(at your option) any later version.\n"
+						+ "\n"
+						+ "This program is distributed in the hope that it will be useful,\n"
+						+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+						+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
+						+ "GNU General Public License for more details.\n");
+	}
+
+	/**
+	 * Print the LGPL disclaimer to the given {@link Logger} as on INFO level.
+	 */
+	public static void logLGPLCopyright(final Logger logger) {
+
+		logger
+				.info("\nThis program is free software: you can redistribute it and/or modify\n"
+						+ "it under the terms of the GNU Lesser General Public License as published by\n"
+						+ "the Free Software Foundation, either version 3 of the License, or\n"
+						+ "(at your option) any later version.\n"
+						+ "\n"
+						+ "This program is distributed in the hope that it will be useful,\n"
+						+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+						+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
+						+ "GNU Lesser General Public License for more details.\n");
+
+	}
+}


Property changes on: trunk/src/skrueger/versionnumber/ReleaseUtil.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native



More information about the Schmitzm-commits mailing list