Browse files

Add idea projects to .gitignore, add build properties to jar, and log…

… build's git revision once upon static load.
  • Loading branch information...
1 parent 0f43411 commit 5f0333b7ce3f0f16fc88c71f918b9f0e5ed8eb5d @kevinweil kevinweil committed Nov 1, 2009
Showing with 60 additions and 19 deletions.
  1. +3 −0 .gitignore
  2. +29 −2 build.xml
  3. +28 −17 src/java/com/hadoop/compression/lzo/LzoCodec.java
View
3 .gitignore
@@ -20,3 +20,6 @@
.svn
build/
bin/
+*.ipr
+*.iml
+*.iws
View
31 build.xml
@@ -89,7 +89,7 @@
<property name="make.cmd" value="make"/>
- <!-- IVY properteis set here -->
+ <!-- IVY properties set here -->
<property name="ivy.dir" location="ivy" />
<loadproperties srcfile="${ivy.dir}/libraries.properties"/>
<property name="ivy.jar" location="${ivy.dir}/ivy-${ivy.version}.jar"/>
@@ -177,6 +177,33 @@
</target>
<!-- ====================================================== -->
+ <!-- Build properties file -->
+ <!-- ====================================================== -->
+ <target name="buildinfo">
+ <tstamp>
+ <format property="build_time" pattern="MM/dd/yyyy hh:mm aa" timezone="GMT"/>
+ </tstamp>
+ <exec executable="git" outputproperty="build_revision">
+ <arg value="rev-parse"/>
+ <arg value="HEAD"/>
+ </exec>
+ <exec executable="whoami" outputproperty="build_author"/>
+ <exec executable="uname" outputproperty="build_os">
+ <arg value="-a"/>
+ </exec>
+
+ <propertyfile file="${build.classes}/build.properties"
+ comment="This file is automatically generated - DO NOT EDIT">
+ <entry key="build_time" value="${build_time}"/>
+ <entry key="build_revision" value="${build_revision}"/>
+ <entry key="build_author" value="${build_author}"/>
+ <entry key="build_version" value="${version}"/>
+ <entry key="build_os" value="${build_os}"/>
+ </propertyfile>
+ </target>
+
+
+ <!-- ====================================================== -->
<!-- Compile the Java files -->
<!-- ====================================================== -->
<target name="compile-java" depends="init">
@@ -243,7 +270,7 @@
<!-- ================================================================== -->
<!-- -->
<!-- ================================================================== -->
- <target name="jar" depends="compile-java" description="Make jar">
+ <target name="jar" depends="compile-java, buildinfo" description="Make jar">
<jar jarfile="${build.dir}/${final.name}.jar"
basedir="${build.classes}">
<manifest>
View
45 src/java/com/hadoop/compression/lzo/LzoCodec.java
@@ -15,12 +15,13 @@
* along with Hadoop-Gpl-Compression. If not, see
* <http://www.gnu.org/licenses/>.
*/
-
+
package com.hadoop.compression.lzo;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -38,10 +39,9 @@
* A {@link org.apache.hadoop.io.compress.CompressionCodec} for a streaming
* <b>lzo</b> compression/decompression pair.
* http://www.oberhumer.com/opensource/lzo/
- *
+ *
*/
public class LzoCodec implements Configurable, CompressionCodec {
-
private static final Log LOG = LogFactory.getLog(LzoCodec.class.getName());
private Configuration conf;
@@ -62,7 +62,7 @@ public Configuration getConf() {
LzoDecompressor.isNativeLzoLoaded();
if (nativeLzoLoaded) {
- LOG.info("Successfully loaded & initialized native-lzo library");
+ LOG.info("Successfully loaded & initialized native-lzo library [hadoop-lzo rev " + getRevisionHash() + "]");
} else {
LOG.error("Failed to load/initialize native-lzo library");
}
@@ -73,7 +73,7 @@ public Configuration getConf() {
/**
* Check if native-lzo library is loaded & initialized.
- *
+ *
* @param conf configuration
* @return <code>true</code> if native-lzo library is loaded & initialized;
* else <code>false</code>
@@ -82,12 +82,23 @@ public static boolean isNativeLzoLoaded(Configuration conf) {
return nativeLzoLoaded && conf.getBoolean("hadoop.native.lib", true);
}
- public CompressionOutputStream createOutputStream(OutputStream out)
+ public static String getRevisionHash() {
+ try {
+ Properties p = new Properties();
+ p.load(LzoCodec.class.getResourceAsStream("/build.properties"));
+ return p.getProperty("build_revision");
+ } catch (IOException e) {
+ LOG.error("Could not find build properties file with revision hash");
+ return "UNKNOWN";
+ }
+ }
+
+ public CompressionOutputStream createOutputStream(OutputStream out)
throws IOException {
return createOutputStream(out, createCompressor());
}
- public CompressionOutputStream createOutputStream(OutputStream out,
+ public CompressionOutputStream createOutputStream(OutputStream out,
Compressor compressor) throws IOException {
// Ensure native-lzo library is loaded & initialized
if (!isNativeLzoLoaded(conf)) {
@@ -102,20 +113,20 @@ public CompressionOutputStream createOutputStream(OutputStream out,
* LZO will expand incompressible data by a little amount.
* I still haven't computed the exact values, but I suggest using
* these formulas for a worst-case expansion calculation:
- *
+ *
* Algorithm LZO1, LZO1A, LZO1B, LZO1C, LZO1F, LZO1X, LZO1Y, LZO1Z:
* ----------------------------------------------------------------
* output_block_size = input_block_size + (input_block_size / 16) + 64 + 3
- *
+ *
* This is about 106% for a large block size.
- *
+ *
* Algorithm LZO2A:
* ----------------
* output_block_size = input_block_size + (input_block_size / 8) + 128 + 3
*/
// Create the lzo output-stream
- LzoCompressor.CompressionStrategy strategy =
+ LzoCompressor.CompressionStrategy strategy =
LzoCompressor.CompressionStrategy.valueOf(
conf.get("io.compression.codec.lzo.compressor",
LzoCompressor.CompressionStrategy.LZO1X_1.name()));
@@ -143,7 +154,7 @@ public Compressor createCompressor() {
throw new RuntimeException("native-lzo library not available");
}
- LzoCompressor.CompressionStrategy strategy =
+ LzoCompressor.CompressionStrategy strategy =
LzoCompressor.CompressionStrategy.valueOf(
conf.get("io.compression.codec.lzo.compressor",
LzoCompressor.CompressionStrategy.LZO1X_1.name()));
@@ -158,14 +169,14 @@ public CompressionInputStream createInputStream(InputStream in)
return createInputStream(in, createDecompressor());
}
- public CompressionInputStream createInputStream(InputStream in,
- Decompressor decompressor)
+ public CompressionInputStream createInputStream(InputStream in,
+ Decompressor decompressor)
throws IOException {
// Ensure native-lzo library is loaded & initialized
if (!isNativeLzoLoaded(conf)) {
throw new RuntimeException("native-lzo library not available");
}
- return new BlockDecompressorStream(in, decompressor,
+ return new BlockDecompressorStream(in, decompressor,
conf.getInt("io.compression.codec.lzo.buffersize", 64*1024));
}
@@ -183,14 +194,14 @@ public Decompressor createDecompressor() {
throw new RuntimeException("native-lzo library not available");
}
- LzoDecompressor.CompressionStrategy strategy =
+ LzoDecompressor.CompressionStrategy strategy =
LzoDecompressor.CompressionStrategy.valueOf(
conf.get("io.compression.codec.lzo.decompressor",
LzoDecompressor.CompressionStrategy.LZO1X.name()));
int bufferSize =
conf.getInt("io.compression.codec.lzo.buffersize", 64*1024);
- return new LzoDecompressor(strategy, bufferSize);
+ return new LzoDecompressor(strategy, bufferSize);
}
/**

0 comments on commit 5f0333b

Please sign in to comment.