You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by eo...@apache.org on 2020/03/26 21:21:04 UTC

[zookeeper] branch master updated: ZOOKEEPER-3755: Use maven to create fatjar

This is an automated email from the ASF dual-hosted git repository.

eolivelli 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 1ff1b77  ZOOKEEPER-3755: Use maven to create fatjar
1ff1b77 is described below

commit 1ff1b779b70dd794c9e45f35f8ca305229df10e0
Author: Sushant Mane <su...@sjsu.edu>
AuthorDate: Thu Mar 26 22:20:51 2020 +0100

    ZOOKEEPER-3755: Use maven to create fatjar
    
    - replace ant build.xml with maven pom.xml for zookeeper-contrib-fatjar module
    - create maven profile "fatjar" to build a fatjar file.
    - update readme files
    
    Author: Sushant Mane <su...@sjsu.edu>
    
    Reviewers: Enrico Olivelli <eo...@apache.org>, Benjamin Reed <br...@apache.org>
    
    Closes #1284 from sushantmane/master
---
 pom.xml                                            |   7 +
 zookeeper-contrib/pom.xml                          |   9 ++
 .../zookeeper-contrib-fatjar/README.md             |  21 +++
 .../zookeeper-contrib-fatjar/README.txt            |   2 -
 .../zookeeper-contrib-fatjar/build.xml             |  74 -----------
 zookeeper-contrib/zookeeper-contrib-fatjar/pom.xml | 145 +++++++++++++++++++++
 .../src/main/resources/mainClasses                 |   2 -
 zookeeper-it/README.txt                            |   9 +-
 zookeeper-it/pom.xml                               |  77 +++++++++++
 .../apache/zookeeper/server/watch/WatchBench.java  |   4 +-
 .../apache/zookeeper/test/system/BaseSysTest.java  |  13 +-
 .../zookeeper/test/system/InstanceContainer.java   |   2 +-
 12 files changed, 274 insertions(+), 91 deletions(-)

diff --git a/pom.xml b/pom.xml
index 041b415..6fad123 100755
--- a/pom.xml
+++ b/pom.xml
@@ -262,6 +262,13 @@
       </modules>
     </profile>
     <profile>
+      <id>fatjar</id>
+      <modules>
+        <module>zookeeper-it</module>
+        <module>zookeeper-contrib/zookeeper-contrib-fatjar</module>
+      </modules>
+    </profile>
+    <profile>
       <id>java-build</id>
       <activation>
         <activeByDefault>true</activeByDefault>
diff --git a/zookeeper-contrib/pom.xml b/zookeeper-contrib/pom.xml
index edc3cb3..228a520 100755
--- a/zookeeper-contrib/pom.xml
+++ b/zookeeper-contrib/pom.xml
@@ -40,6 +40,15 @@
     <module>zookeeper-contrib-zooinspector</module>
   </modules>
 
+  <profiles>
+    <profile>
+      <id>fatjar</id>
+      <modules>
+        <module>zookeeper-contrib-fatjar</module>
+      </modules>
+    </profile>
+  </profiles>
+
   <build>
     <pluginManagement>
       <plugins>
diff --git a/zookeeper-contrib/zookeeper-contrib-fatjar/README.md b/zookeeper-contrib/zookeeper-contrib-fatjar/README.md
new file mode 100644
index 0000000..baf2f95
--- /dev/null
+++ b/zookeeper-contrib/zookeeper-contrib-fatjar/README.md
@@ -0,0 +1,21 @@
+ZooKeeper Fatjar
+================
+
+This package contains build to create a fat zookeeper jar. Fatjar can be used to run:
+- zookeeper server
+- zookeeper client
+- distributed load generator for testing (generateLoad)
+- container that will instantiate classes as directed by an instance manager (ic)
+- system test (systest)
+- jmh micro benchmarks (jmh)
+
+
+Use following command to build fatjar
+```
+mvn clean install -P fatjar -DskipTests
+```
+
+To run the fatjar use:
+```
+java -jar zoookeeper-<version>-fatjar.jar
+```
diff --git a/zookeeper-contrib/zookeeper-contrib-fatjar/README.txt b/zookeeper-contrib/zookeeper-contrib-fatjar/README.txt
deleted file mode 100644
index f8027ae..0000000
--- a/zookeeper-contrib/zookeeper-contrib-fatjar/README.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-This package contains build to create a fat zookeeper jar. You need to run ant to create the fat jar.
-To run the fatjar you can use. java -jar zoookeeper-*fatjar.jar 
diff --git a/zookeeper-contrib/zookeeper-contrib-fatjar/build.xml b/zookeeper-contrib/zookeeper-contrib-fatjar/build.xml
deleted file mode 100644
index 3a1dd95..0000000
--- a/zookeeper-contrib/zookeeper-contrib-fatjar/build.xml
+++ /dev/null
@@ -1,74 +0,0 @@
-<?xml version="1.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.
--->
-
-<project name="fatjar" default="jar">
-  <import file="../build-contrib.xml"/>
-
-  <target name="setjarname">
-    <property name="jarname"
-              value="${build.dir}/zookeeper-${version}-${name}.jar"/>
-  </target>
-
-  <!-- Override jar target to specify main class -->
-  <target name="jar" depends="checkMainCompiled, setjarname, compile">
-    <echo message="contrib: ${name}"/>
-    <jar jarfile="${jarname}">
-      <manifest>
-        <attribute name="Main-Class" value="org.apache.zookeeper.util.FatJarMain" />
-        <attribute name="Built-By" value="${user.name}"/>
-        <attribute name="Built-At" value="${build.time}"/>
-        <attribute name="Built-On" value="${host.name}" />
-        <attribute name="Implementation-Title" value="org.apache.zookeeper"/>
-        <attribute name="Implementation-Version" value="${revision}"/>
-        <attribute name="Implementation-Vendor" value="The Apache Software Foundation"/>
-      </manifest>
-      <fileset file="${basedir}/src/main/resources/mainClasses" />
-      <fileset dir="${build.classes}"/>
-      <fileset dir="${build.test}"/>
-      <fileset file="${zk.root}/LICENSE.txt" />
-      <fileset file="${zk.root}/conf/log4j.properties" />
-      <fileset dir="${zk.root}/build/classes" excludes="**/.generated"/>
-      <fileset dir="${zk.root}/build/test/classes"/>
-      <zipgroupfileset dir="${zk.root}/build/lib" includes="*.jar" />
-      <zipgroupfileset dir="${zk.root}/build/test/lib" includes="*.jar" />
-      <zipgroupfileset dir="${zk.root}/zookeeper-server/src/main/resources/lib" includes="*.jar" />
-    </jar>
-  </target>
-
-  <target name="package" depends="jar, zookeeperbuildcontrib.package"
-          unless="skip.contrib">
-
-    <copy file="${basedir}/build.xml" todir="${dist.dir}/zookeeper-contrib/zookeeper-contrib-${name}"/>
-
-    <mkdir dir="${dist.dir}/zookeeper-contrib/zookeeper-contrib-${name}/conf"/>
-    <copy todir="${dist.dir}/zookeeper-contrib/zookeeper-contrib-${name}/conf">
-      <fileset dir="${basedir}/src/main/resources"/>
-    </copy>
-
-    <mkdir dir="${dist.dir}/zookeeper-contrib/zookeeper-contrib-${name}/src"/>
-    <copy todir="${dist.dir}/zookeeper-contrib/zookeeper-contrib-${name}/src">
-      <fileset dir="${basedir}/src"/>
-    </copy>
-  </target>
-
-	<target name="test">
-		<echo message="No test target defined for this package" />
-	</target>
-</project>
-
diff --git a/zookeeper-contrib/zookeeper-contrib-fatjar/pom.xml b/zookeeper-contrib/zookeeper-contrib-fatjar/pom.xml
new file mode 100755
index 0000000..9a90dd7
--- /dev/null
+++ b/zookeeper-contrib/zookeeper-contrib-fatjar/pom.xml
@@ -0,0 +1,145 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <!--
+  /**
+   * 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.
+   */
+  -->
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.zookeeper</groupId>
+    <artifactId>zookeeper-contrib</artifactId>
+    <version>3.7.0-SNAPSHOT</version>
+  </parent>
+
+  <groupId>org.apache.zookeeper</groupId>
+  <artifactId>zookeeper-contrib-fatjar</artifactId>
+  <packaging>jar</packaging>
+  <name>Apache ZooKeeper - Contrib - Fatjar</name>
+
+  <properties>
+    <maven.javadoc.skip>true</maven.javadoc.skip>
+    <maven.source.skip>true</maven.source.skip>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.zookeeper</groupId>
+      <artifactId>zookeeper-jute</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.zookeeper</groupId>
+      <artifactId>zookeeper</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.zookeeper</groupId>
+      <artifactId>zookeeper</artifactId>
+      <version>${project.version}</version>
+      <type>test-jar</type>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.zookeeper</groupId>
+      <artifactId>zookeeper-it</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-cli</groupId>
+      <artifactId>commons-cli</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.jetty</groupId>
+      <artifactId>jetty-server</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.jetty</groupId>
+      <artifactId>jetty-servlet</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-databind</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.googlecode.json-simple</groupId>
+      <artifactId>json-simple</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>jline</groupId>
+      <artifactId>jline</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>io.dropwizard.metrics</groupId>
+      <artifactId>metrics-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.xerial.snappy</groupId>
+      <artifactId>snappy-java</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <resources>
+      <resource>
+        <directory>${project.basedir}/src/main/resources</directory>
+      </resource>
+      <resource>
+        <directory>${project.basedir}/../../conf</directory>
+        <includes>
+          <include>log4j.properties</include>
+        </includes>
+      </resource>
+    </resources>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <configuration>
+          <descriptorRefs>
+            <descriptorRef>jar-with-dependencies</descriptorRef>
+          </descriptorRefs>
+          <archive>
+            <manifest>
+              <mainClass>org.apache.zookeeper.util.FatJarMain</mainClass>
+            </manifest>
+          </archive>
+          <finalName>zookeeper-${project.version}-fatjar</finalName>
+          <appendAssemblyId>false</appendAssemblyId>
+          <attach>false</attach>
+        </configuration>
+        <executions>
+          <execution>
+          <id>make-assembly</id>
+          <phase>package</phase>
+          <goals>
+            <goal>single</goal>
+          </goals>
+        </execution>
+      </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/zookeeper-contrib/zookeeper-contrib-fatjar/src/main/resources/mainClasses b/zookeeper-contrib/zookeeper-contrib-fatjar/src/main/resources/mainClasses
index ba29e89..c7b27a1 100644
--- a/zookeeper-contrib/zookeeper-contrib-fatjar/src/main/resources/mainClasses
+++ b/zookeeper-contrib/zookeeper-contrib-fatjar/src/main/resources/mainClasses
@@ -4,8 +4,6 @@ client:org.apache.zookeeper.ZooKeeperMain:Client shell to ZooKeeper
 server:org.apache.zookeeper.server.quorum.QuorumPeerMain:Start ZooKeeper server
 ::Test Commands
 generateLoad:org.apache.zookeeper.test.system.GenerateLoad:A distributed load generator for testing
-quorumBench:org.apache.zookeeper.server.QuorumBenchmark:A benchmark of just the quorum protocol
-abBench:org.apache.zookeeper.server.quorum.AtomicBroadcastBenchmark:A benchmark of just the atomic broadcast
 ic:org.apache.zookeeper.test.system.InstanceContainer:A container that will instantiate classes as directed by an instance manager
 systest:org.apache.zookeeper.test.system.BaseSysTest:Start system test
 jmh:org.apache.zookeeper.BenchMain:Run jmh micro benchmarks
diff --git a/zookeeper-it/README.txt b/zookeeper-it/README.txt
index 8a2985c..2c4b1cc 100644
--- a/zookeeper-it/README.txt
+++ b/zookeeper-it/README.txt
@@ -7,11 +7,12 @@ The easiest way to do all of this is to use the zookeeper fat jar.
 
 Steps to run system test
 ------------------------
-1) transfer the fatjar from the release directory to all systems
-   participating in the test. fatjar is in contrib/fatjar directory.
+1) build and transfer the fatjar from the `zookeeper-contrib/zookeeper-contrib-fatjar/target`
+   directory to all systems participating in the test
 
-   (developers can generate by running "ant jar compile-test"
-   targets in trunk, then compiling using "ant jar" in src/contrib/jarjar)
+   Command to build fatjar without executing the tests:
+
+   `mvn clean install -P fatjar -DskipTests`
 
 2) run a zookeeper standalone instance (cluster is ok too)
 
diff --git a/zookeeper-it/pom.xml b/zookeeper-it/pom.xml
new file mode 100755
index 0000000..163930f
--- /dev/null
+++ b/zookeeper-it/pom.xml
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <!--
+  /**
+   * 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.
+   */
+  -->
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.zookeeper</groupId>
+    <artifactId>parent</artifactId>
+    <version>3.7.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>zookeeper-it</artifactId>
+  <packaging>jar</packaging>
+  <name>Apache ZooKeeper - Tests</name>
+  <description>
+    ZooKeeper system tests
+  </description>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.zookeeper</groupId>
+      <artifactId>zookeeper</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.zookeeper</groupId>
+      <artifactId>zookeeper</artifactId>
+      <classifier>tests</classifier>
+      <type>test-jar</type>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.openjdk.jmh</groupId>
+      <artifactId>jmh-core</artifactId>
+      <version>1.23</version>
+    </dependency>
+    <dependency>
+      <groupId>org.openjdk.jmh</groupId>
+      <artifactId>jmh-generator-annprocess</artifactId>
+      <version>1.23</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <sourceDirectory>src</sourceDirectory>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <configuration>
+          <sourcepath>src</sourcepath>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/zookeeper-it/src/test/bench/org/apache/zookeeper/server/watch/WatchBench.java b/zookeeper-it/src/test/bench/org/apache/zookeeper/server/watch/WatchBench.java
index 0510df7..aee5b2f 100644
--- a/zookeeper-it/src/test/bench/org/apache/zookeeper/server/watch/WatchBench.java
+++ b/zookeeper-it/src/test/bench/org/apache/zookeeper/server/watch/WatchBench.java
@@ -35,9 +35,9 @@ public class WatchBench {
     static final EventType event = EventType.NodeDataChanged;
 
     static IWatchManager createWatchManager(String className) throws Exception {
-        Class clazz = Class.forName(
+        Class<?> clazz = Class.forName(
                 "org.apache.zookeeper.server.watch." + className);
-        return (IWatchManager) clazz.newInstance();
+        return (IWatchManager) clazz.getConstructor().newInstance();
     }
 
     static void forceGC() {
diff --git a/zookeeper-it/src/test/java/org/apache/zookeeper/test/system/BaseSysTest.java b/zookeeper-it/src/test/java/org/apache/zookeeper/test/system/BaseSysTest.java
index 8856282..6816f2d 100644
--- a/zookeeper-it/src/test/java/org/apache/zookeeper/test/system/BaseSysTest.java
+++ b/zookeeper-it/src/test/java/org/apache/zookeeper/test/system/BaseSysTest.java
@@ -20,6 +20,7 @@ package org.apache.zookeeper.test.system;
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
@@ -223,15 +224,15 @@ public class BaseSysTest {
 
     }
     private Instance fakeBaseClients[];
-    private void fakeConfigureClients(int count, Class<? extends Instance> clazz, String params) throws IOException, ClassNotFoundException {
+    private void fakeConfigureClients(int count, Class<? extends Instance> clazz, String params) {
         fakeBaseClients = new Instance[count];
         for(int i = 0; i < count; i++) {
             try {
-                fakeBaseClients[i] = clazz.newInstance();
-            } catch (InstantiationException e) {
-                e.printStackTrace();
-                return;
-            } catch (IllegalAccessException e) {
+                fakeBaseClients[i] = clazz.getConstructor().newInstance();
+            } catch (InstantiationException
+                    | IllegalAccessException
+                    | NoSuchMethodException
+                    | InvocationTargetException e) {
                 e.printStackTrace();
                 return;
             }
diff --git a/zookeeper-it/src/test/java/org/apache/zookeeper/test/system/InstanceContainer.java b/zookeeper-it/src/test/java/org/apache/zookeeper/test/system/InstanceContainer.java
index 1cb7bc0..44f6531 100644
--- a/zookeeper-it/src/test/java/org/apache/zookeeper/test/system/InstanceContainer.java
+++ b/zookeeper-it/src/test/java/org/apache/zookeeper/test/system/InstanceContainer.java
@@ -271,7 +271,7 @@ public class InstanceContainer implements Watcher, AsyncCallback.ChildrenCallbac
                     }
                     try {
                         Class<?> c = Class.forName(clazz);
-                        i = (Instance)c.newInstance();
+                        i = (Instance) c.getConstructor().newInstance();
                         Reporter reporter = new MyReporter(child);
                         i.setReporter(reporter);
                         i.configure(conf);