Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions parquet-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
Expand Down
81 changes: 20 additions & 61 deletions parquet-common/src/main/java/org/apache/parquet/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,83 +18,42 @@
*/
package org.apache.parquet;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.io.InputStream;
import java.util.Properties;
import java.util.jar.Manifest;

/**
* The version of the library
*
* parquet-mr version 1.0.0-SNAPSHOT (build 6cf94d29b2b7115df4de2c06e2ab4326d721eb55)
*
* @author Julien Le Dem
*
*/
public class Version {
private static final Log LOG = Log.getLog(Version.class);

public static final String VERSION_NUMBER = readVersionNumber();
public static final String FULL_VERSION = readFullVersion();

private static String getJarPath() {
final URL versionClassBaseUrl = Version.class.getResource("");
if (versionClassBaseUrl.getProtocol().equals("jar")) {
String path = versionClassBaseUrl.getPath();
int jarEnd = path.indexOf("!");
if (jarEnd != -1) {
String jarPath = path.substring(0, jarEnd);
return jarPath;
}
}
return null;
}
public static final String VERSION_NUMBER;
public static final String FULL_VERSION;

private static URL getResourceFromJar(String jarPath, String path) throws IOException {
Enumeration<URL> resources = Version.class.getClassLoader().getResources(path);
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
if (url.getProtocol().equals("jar") && url.getPath().startsWith(jarPath)) {
return url;
}
}
return null;
}

private static String readVersionNumber() {
String version = null;
try {
String jarPath = getJarPath();
if (jarPath != null) {
URL pomPropertiesUrl = getResourceFromJar(jarPath, "META-INF/maven/com.twitter/parquet-column/pom.properties");
if (pomPropertiesUrl != null) {
Properties properties = new Properties();
properties.load(pomPropertiesUrl.openStream());
version = properties.getProperty("version");
}
}
} catch (Exception e) {
LOG.warn("can't read from META-INF", e);
}
return version;
}
static {
String versionNumber = null;
String fullVersion = null;

private static String readFullVersion() {
String sha = null;
try {
String jarPath = getJarPath();
if (jarPath != null) {
URL manifestUrl = getResourceFromJar(jarPath, "META-INF/MANIFEST.MF");
if (manifestUrl != null) {
Manifest manifest = new Manifest(manifestUrl.openStream());
sha = manifest.getMainAttributes().getValue("git-SHA-1");
}
InputStream in = Version.class.getResourceAsStream("/META-INF/maven/org.apache.parquet/parquet-common/version.properties");
if (in != null) {
try {
Properties props = new Properties();
props.load(in);
versionNumber = props.getProperty("versionNumber");
fullVersion = props.getProperty("fullVersion");
} catch (Exception e) {
LOG.warn("can't read version information", e);
}
} catch (Exception e) {
LOG.warn("can't read from META-INF", e);
} else {
LOG.warn("can't read version information");
}
return "parquet-mr" + (VERSION_NUMBER != null ? " version " + VERSION_NUMBER : "") + (sha != null ? " (build " + sha + ")" : "");

VERSION_NUMBER = versionNumber;
FULL_VERSION = fullVersion;
}

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# 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.

versionNumber = ${project.version}
gitSHA1 = ${buildNumber}
fullVersion = parquet-mr version ${project.version} (build ${buildNumber})
36 changes: 36 additions & 0 deletions parquet-common/src/test/java/org/apache/parquet/TestVersion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* 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.
*/
package org.apache.parquet;

import java.io.IOException;
import java.util.Properties;

import org.junit.Assert;
import org.junit.Test;

public class TestVersion {
@Test
public void testVersionIsPopulatedFromVersionProperties() throws IOException {
Properties expected = new Properties();
expected.load(TestVersion.class.getResourceAsStream("/META-INF/maven/org.apache.parquet/parquet-common/version.properties"));

Assert.assertEquals(expected.getProperty("versionNumber"), Version.VERSION_NUMBER);
Assert.assertEquals(expected.getProperty("fullVersion"), Version.FULL_VERSION);
}
}