This is an automated email from the ASF dual-hosted git repository.
symat pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git
The following commit(s) were added to refs/heads/master by this push:
new f9a0803 ZOOKEEPER-3786: Simplify version generation
f9a0803 is described below
commit f9a08032c5cdf6ca4dc4649992436207576fbe9e
Author: Christopher Tubbs <[email protected]>
AuthorDate: Thu Apr 9 10:59:02 2020 +0000
ZOOKEEPER-3786: Simplify version generation
Simplify generation of VersionInfoMain.java and Info.java by using
maven-resource-plugin's built-in resource filtering at build time.
This eliminates the need to use VerGen to generate java source files
during the build.
Also make other slight pom improvements:
1. Remove trailing tab character in Ted's name in pom.xml
2. Simplify spotbugs skipping in contrib pom.xml
3. Add m2e configuration for build plugin executions to be ignored by
Eclipse, for developers (like me) using Eclipse IDE
4. Format build time in a more international-friendly and less ambiguous
way (year first, then month, then day, using UTC instead of GMT)
Link to issue: https://issues.apache.org/jira/browse/ZOOKEEPER-3786
Author: Christopher Tubbs <[email protected]>
Reviewers: Enrico Olivelli <[email protected]>, Mate Szalay-Beko
<[email protected]>
Closes #1310 from ctubbsii/use-resource-filtering-for-version-info
---
pom.xml | 2 +-
zookeeper-contrib/pom.xml | 13 +-
zookeeper-server/pom.xml | 55 ++----
.../org/apache/zookeeper/version/Info.java | 29 +++
.../apache/zookeeper/version/VersionInfoMain.java | 25 +++
.../org/apache/zookeeper/version/util/VerGen.java | 202 ---------------------
.../test/java/org/apache/zookeeper/VerGenTest.java | 71 --------
7 files changed, 79 insertions(+), 318 deletions(-)
diff --git a/pom.xml b/pom.xml
index 6fad123..79e88df 100755
--- a/pom.xml
+++ b/pom.xml
@@ -117,7 +117,7 @@
<developers>
<developer>
<id>tdunning</id>
- <name>Ted Dunning </name>
+ <name>Ted Dunning</name>
<email>[email protected]</email>
<timezone>-8</timezone>
</developer>
diff --git a/zookeeper-contrib/pom.xml b/zookeeper-contrib/pom.xml
index 228a520..0e2959d 100755
--- a/zookeeper-contrib/pom.xml
+++ b/zookeeper-contrib/pom.xml
@@ -49,19 +49,14 @@
</profile>
</profiles>
+ <properties>
+ <spotbugs.skip>true</spotbugs.skip>
+ </properties>
+
<build>
<pluginManagement>
<plugins>
<plugin>
- <groupId>com.github.spotbugs</groupId>
- <artifactId>spotbugs-maven-plugin</artifactId>
- <version>3.1.9</version>
- <configuration>
- <!-- No spotbugs for contrib modules -->
- <skip>true</skip>
- </configuration>
- </plugin>
- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
diff --git a/zookeeper-server/pom.xml b/zookeeper-server/pom.xml
index 21c30ea..117a77b 100755
--- a/zookeeper-server/pom.xml
+++ b/zookeeper-server/pom.xml
@@ -166,23 +166,30 @@
<build>
<plugins>
- <plugin> <!-- ${maven.build.timestamp} does not support timezone :( -->
+ <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
+ <!-- ${maven.build.timestamp} does not support timezone :( -->
<id>tbuild-time</id>
<goals>
<goal>timestamp-property</goal>
</goals>
<configuration>
<name>build.time</name>
- <pattern>MM/dd/yyyy HH:mm zz</pattern>
+ <pattern>yyyy-MM-dd HH:mm zz</pattern>
<locale>en_US</locale>
- <timeZone>GMT</timeZone>
+ <timeZone>UTC</timeZone>
</configuration>
</execution>
<execution>
+ <id>parse-version</id>
+ <goals>
+ <goal>parse-version</goal>
+ </goals>
+ </execution>
+ <execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
@@ -197,44 +204,22 @@
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
+ <artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
- <id>pre-compile-vergen</id>
- <phase>generate-sources</phase>
- <configuration>
- <includes>
- <include>org/apache/zookeeper/version/**/*.java</include>
- </includes>
- </configuration>
+ <id>prepare-filtered-java-source</id>
<goals>
- <goal>compile</goal>
+ <goal>copy-resources</goal>
</goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>exec-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>generate-version-info</id>
<phase>generate-sources</phase>
- <goals>
- <goal>exec</goal>
- </goals>
<configuration>
-
<workingDirectory>${project.basedir}/src/main/java/</workingDirectory>
- <executable>java</executable>
- <arguments>
- <argument>-classpath</argument>
- <classpath />
- <argument>org.apache.zookeeper.version.util.VerGen</argument>
- <argument>${project.version}</argument>
- <argument>${mvngit.commit.id}</argument>
- <argument>${build.time}</argument>
-
<argument>${project.basedir}/target/generated-sources/java</argument>
- </arguments>
+
<outputDirectory>${project.build.directory}/generated-sources/java</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/java-filtered</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
</configuration>
</execution>
</executions>
diff --git
a/zookeeper-server/src/main/java-filtered/org/apache/zookeeper/version/Info.java
b/zookeeper-server/src/main/java-filtered/org/apache/zookeeper/version/Info.java
new file mode 100644
index 0000000..5570ecc
--- /dev/null
+++
b/zookeeper-server/src/main/java-filtered/org/apache/zookeeper/version/Info.java
@@ -0,0 +1,29 @@
+/*
+ * 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.zookeeper.version;
+
+public interface Info {
+ int MAJOR=${parsedVersion.majorVersion};
+ int MINOR=${parsedVersion.minorVersion};
+ int MICRO=${parsedVersion.incrementalVersion};
+ String QUALIFIER="${parsedVersion.qualifier}".isEmpty() ? null :
"${parsedVersion.qualifier}";
+ int REVISION=-1; //@deprecated, please use REVISION_HASH
+ String REVISION_HASH="${mvngit.commit.id}";
+ String BUILD_DATE="${build.time}";
+}
diff --git
a/zookeeper-server/src/main/java-filtered/org/apache/zookeeper/version/VersionInfoMain.java
b/zookeeper-server/src/main/java-filtered/org/apache/zookeeper/version/VersionInfoMain.java
new file mode 100644
index 0000000..b7d0054
--- /dev/null
+++
b/zookeeper-server/src/main/java-filtered/org/apache/zookeeper/version/VersionInfoMain.java
@@ -0,0 +1,25 @@
+/*
+ * 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.zookeeper.version;
+
+public class VersionInfoMain implements org.apache.zookeeper.version.Info {
+ public static void main(String[] args) {
+ System.out.println("Apache ZooKeeper, version ${project.version}
${build.time}");
+ }
+}
diff --git
a/zookeeper-server/src/main/java/org/apache/zookeeper/version/util/VerGen.java
b/zookeeper-server/src/main/java/org/apache/zookeeper/version/util/VerGen.java
deleted file mode 100644
index 9bb699f..0000000
---
a/zookeeper-server/src/main/java/org/apache/zookeeper/version/util/VerGen.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * 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.zookeeper.version.util;
-
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.apache.zookeeper.server.ExitCode;
-
-@SuppressFBWarnings("DM_EXIT")
-public class VerGen {
-
- private static final String PACKAGE_NAME = "org.apache.zookeeper.version";
- private static final String VERSION_CLASS_NAME = "VersionInfoMain";
- private static final String VERSION_INTERFACE_NAME = "Info";
-
- static void printUsage() {
- System.out.print("Usage:\tjava -cp <classpath> org.apache.zookeeper."
- + "version.util.VerGen maj.min.micro[-qualifier] rev
buildDate outputDirectory");
- System.exit(ExitCode.UNEXPECTED_ERROR.getValue());
- }
-
- public static void generateFile(File outputDir, Version version, String
rev, String buildDate) {
- String path = PACKAGE_NAME.replaceAll("\\.", "/");
- File pkgdir = new File(outputDir, path);
- if (!pkgdir.exists()) {
- // create the pkg directory
- boolean ret = pkgdir.mkdirs();
- if (!ret) {
- System.out.println("Cannnot create directory: " + path);
- System.exit(ExitCode.UNEXPECTED_ERROR.getValue());
- }
- } else if (!pkgdir.isDirectory()) {
- // not a directory
- System.out.println(path + " is not a directory.");
- System.exit(ExitCode.UNEXPECTED_ERROR.getValue());
- }
-
- try (FileWriter w = new FileWriter(new File(pkgdir,
VERSION_INTERFACE_NAME + ".java"))) {
- w.write("// Do not edit!\n// File generated by
org.apache.zookeeper" + ".version.util.VerGen.\n");
- w.write("/**\n");
- w.write("* Licensed to the Apache Software Foundation (ASF) under
one\n");
- w.write("* or more contributor license agreements. See the NOTICE
file\n");
- w.write("* distributed with this work for additional
information\n");
- w.write("* regarding copyright ownership. The ASF licenses this
file\n");
- w.write("* to you under the Apache License, Version 2.0 (the\n");
- w.write("* \"License\"); you may not use this file except in
compliance\n");
- w.write("* with the License. You may obtain a copy of the License
at\n");
- w.write("*\n");
- w.write("* http://www.apache.org/licenses/LICENSE-2.0\n");
- w.write("*\n");
- w.write("* Unless required by applicable law or agreed to in
writing, software\n");
- w.write("* distributed under the License is distributed on an \"AS
IS\" BASIS,\n");
- w.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied.\n");
- w.write("* See the License for the specific language governing
permissions and\n");
- w.write("* limitations under the License.\n");
- w.write("*/\n");
- w.write("\n");
- w.write("package " + PACKAGE_NAME + ";\n\n");
- w.write("public interface " + VERSION_INTERFACE_NAME + " {\n");
- w.write(" int MAJOR=" + version.maj + ";\n");
- w.write(" int MINOR=" + version.min + ";\n");
- w.write(" int MICRO=" + version.micro + ";\n");
- w.write(" String QUALIFIER=" + (version.qualifier == null ?
"\"\"" : "\"" + version.qualifier + "\"") + ";\n");
- if (rev.equals("-1")) {
- System.out.println("Unknown REVISION number, using " + rev);
- }
- w.write(" int REVISION=-1; //@deprecated, please use
REVISION_HASH\n");
- w.write(" String REVISION_HASH=\"" + rev + "\";\n");
- w.write(" String BUILD_DATE=\"" + buildDate + "\";\n");
- w.write("}\n");
- } catch (IOException e) {
- System.out.println("Unable to generate version.Info file: " +
e.getMessage());
- System.exit(ExitCode.UNEXPECTED_ERROR.getValue());
- }
-
- // Generate a main class to display version data
- // that can be exec'd in zkServer.sh
- try (FileWriter w = new FileWriter(new File(pkgdir, VERSION_CLASS_NAME
+ ".java"))) {
- w.write("// Do not edit!\n// File generated by
org.apache.zookeeper" + ".version.util.VerGen.\n");
- w.write("/**\n");
- w.write("* Licensed to the Apache Software Foundation (ASF) under
one\n");
- w.write("* or more contributor license agreements. See the NOTICE
file\n");
- w.write("* distributed with this work for additional
information\n");
- w.write("* regarding copyright ownership. The ASF licenses this
file\n");
- w.write("* to you under the Apache License, Version 2.0 (the\n");
- w.write("* \"License\"); you may not use this file except in
compliance\n");
- w.write("* with the License. You may obtain a copy of the License
at\n");
- w.write("*\n");
- w.write("* http://www.apache.org/licenses/LICENSE-2.0\n");
- w.write("*\n");
- w.write("* Unless required by applicable law or agreed to in
writing, software\n");
- w.write("* distributed under the License is distributed on an \"AS
IS\" BASIS,\n");
- w.write("* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied.\n");
- w.write("* See the License for the specific language governing
permissions and\n");
- w.write("* limitations under the License.\n");
- w.write("*/\n");
- w.write("\n");
- w.write("package " + PACKAGE_NAME + ";\n\n");
- w.write("public class " + VERSION_CLASS_NAME + " implements " +
PACKAGE_NAME + ".Info {\n");
- w.write(" public static void main(String[] args) {\n");
- w.write(" final String VER_STRING = MAJOR + \".\" + MINOR +
\".\" + MICRO +");
- w.write(" (QUALIFIER == null ? \"\" : \"-\" +
QUALIFIER) + \" \" +");
- w.write(" BUILD_DATE;" + "\n");
- w.write(" System.out.println(\"Apache ZooKeeper, version \"
+ VER_STRING);\n");
- w.write(" }\n");
- w.write("}\n");
- } catch (IOException e) {
- System.out.println("Unable to generate version.VersionInfoMain
file: " + e.getMessage());
- System.exit(ExitCode.UNEXPECTED_ERROR.getValue());
- }
- }
-
- public static class Version {
-
- public int maj;
- public int min;
- public int micro;
- public String qualifier;
-
- }
-
- public static Version parseVersionString(String input) {
- Version result = new Version();
-
- Pattern p =
Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+)((\\.\\d+)*)(-(.+))?$");
- Matcher m = p.matcher(input);
-
- if (!m.matches()) {
- return null;
- }
- result.maj = Integer.parseInt(m.group(1));
- result.min = Integer.parseInt(m.group(2));
- result.micro = Integer.parseInt(m.group(3));
- if (m.groupCount() == 7) {
- result.qualifier = m.group(7);
- } else {
- result.qualifier = null;
- }
- return result;
- }
-
- /**
- * Emits a org.apache.zookeeper.version.Info interface file with version
and
- * revision information constants set to the values passed in as command
- * line parameters. The file is created in the current directory. <br>
- * Usage: java org.apache.zookeeper.version.util.VerGen
maj.min.micro[-qualifier]
- * rev buildDate
- *
- * @param args
- * <ul>
- * <li>maj - major version number
- * <li>min - minor version number
- * <li>micro - minor minor version number
- * <li>qualifier - optional qualifier (dash followed by
qualifier text)
- * <li>rev - current Git revision number
- * <li>buildDate - date the build
- * </ul>
- */
- public static void main(String[] args) {
- if (args.length != 4) {
- printUsage();
- }
- try {
- Version version = parseVersionString(args[0]);
- if (version == null) {
- System.err.println("Invalid version number format, must be
\"x.y.z(-.*)?\"");
- System.exit(ExitCode.UNEXPECTED_ERROR.getValue());
- }
- String rev = args[1];
- if (rev == null || rev.trim().isEmpty()) {
- rev = "-1";
- } else {
- rev = rev.trim();
- }
- generateFile(new File(args[3]), version, rev, args[2]);
- } catch (NumberFormatException e) {
- System.err.println("All version-related parameters must be valid
integers!");
- throw e;
- }
- }
-
-}
diff --git
a/zookeeper-server/src/test/java/org/apache/zookeeper/VerGenTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/VerGenTest.java
deleted file mode 100644
index 1542df0..0000000
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/VerGenTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.zookeeper;
-
-import static org.junit.Assert.assertEquals;
-import java.io.File;
-import java.util.Arrays;
-import java.util.Collection;
-import org.apache.zookeeper.test.ClientBase;
-import org.apache.zookeeper.version.util.VerGen;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-/**
- * Test VerGen, used during the build.
- *
- */
-@RunWith(Parameterized.class)
[email protected](ZKParameterized.RunnerFactory.class)
-public class VerGenTest extends ZKTestCase {
-
- @Parameters
- public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{{"1.2.3", new Object[]{1, 2, 3,
null}}, {"1.2.3-dev", new Object[]{1, 2, 3, "dev"}}, {"1.2.3-SNAPSHOT", new
Object[]{1, 2, 3, "SNAPSHOT"}}, {"1.2.3-SNAPSHOT", new Object[]{1, 2, 3,
"SNAPSHOT"}}, {"1.2.3-foo-bar+123", new Object[]{1, 2, 3, "foo-bar+123"}},
{"1.2.3.4.5-SNAPSHOT", new Object[]{1, 2, 3, "SNAPSHOT"}},
{"1.2.3.4.5-foo-bar+123", new Object[]{1, 2, 3, "foo-bar+123"}}});
- }
-
- private String input;
-
- private Object[] expected;
-
- public VerGenTest(String input, Object[] expected) {
- this.input = input;
- this.expected = expected;
- }
-
- @Test
- public void testParser() {
- VerGen.Version v = VerGen.parseVersionString(input);
- assertEquals(expected[0], v.maj);
- assertEquals(expected[1], v.min);
- assertEquals(expected[2], v.micro);
- assertEquals(expected[3], v.qualifier);
- }
-
- @Test
- public void testGenFile() throws Exception {
- VerGen.Version v = VerGen.parseVersionString(input);
- File outputDir = ClientBase.createTmpDir();
- VerGen.generateFile(outputDir, v, "1", "Nov1");
- ClientBase.recursiveDelete(outputDir);
- }
-
-}