[maven-debian-helper] 03/03: Split java wrappers for Maven 2 and Maven 3
Jakub Adam
xhaakon-guest at alioth.debian.org
Tue Sep 10 13:01:00 UTC 2013
This is an automated email from the git hooks/post-receive script.
xhaakon-guest pushed a commit to branch topic-maven3
in repository maven-debian-helper.
commit 76515304b1c529a569f7f23dbfd447904bbe1d2f
Author: Jakub Adam <jakub.adam at ktknet.cz>
Date: Fri May 3 19:28:07 2013 +0200
Split java wrappers for Maven 2 and Maven 3
This is needed because Maven 3 requires newer classworlds with
changed API. Wrappers now don't import Maven classes, the main()
method is called with help of reflection and classworlds itself.
---
debian/control | 2 +-
debian/rules | 2 +-
etc/maven/m2-debian-nodocs.conf | 2 +-
etc/maven/m2-debian.conf | 2 +-
.../src/main/java/org/debian/maven/Wrapper.java | 83 ++++++--------------
.../maven/{Wrapper.java => WrapperBase.java} | 27 +++----
.../main/java/org/debian/maven/WrapperMaven3.java | 54 +++++++++++++
7 files changed, 90 insertions(+), 82 deletions(-)
diff --git a/debian/control b/debian/control
index 6b28af2..9e4609a 100644
--- a/debian/control
+++ b/debian/control
@@ -6,7 +6,7 @@ Uploaders: Torsten Werner <twerner at debian.org>, Ludovic Claude <ludovic.claude at l
Damien Raude-Morvan <drazzib at debian.org>, Thomas Koch <thomas at koch.ro>, Emmanuel Bourg <ebourg at apache.org>, Wolodja Wentland <debian at babilen5.org>
Build-Depends: cdbs, debhelper (>= 7), default-jdk, maven-ant-helper (>= 7.0), ant-optional, help2man
Build-Depends-Indep: maven-repo-helper (>= 1.8.3), junit4, libmaven-plugin-tools-java,
- libplexus-velocity-java, libcommons-io-java
+ libplexus-velocity-java, libcommons-io-java, libplexus-classworlds2-java
Standards-Version: 3.9.4
Vcs-Git: git://anonscm.debian.org/pkg-java/maven-debian-helper.git
Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-java/maven-debian-helper.git
diff --git a/debian/rules b/debian/rules
index cfcf982..8beec24 100755
--- a/debian/rules
+++ b/debian/rules
@@ -9,7 +9,7 @@ JAVA_HOME := /usr/lib/jvm/default-java
PERL_DIR := $(shell perl -MConfig -e 'print $$Config{vendorlib}')
DEB_JARS := ant-junit junit commons-io classworlds maven-core maven-artifact maven-artifact-manager maven-model \
maven-compat maven-plugin-api maven-project maven-scm-api velocity file-management plexus-utils \
- plexus-container-default-alpha maven-repo-helper
+ plexus-container-default-alpha maven-repo-helper plexus-classworlds2
DEB_ANT_BUILD_TARGET := package #javadoc
DEB_ANT_BUILDFILE := debian/build.xml
DEB_ANT_ARGS := -Dpackage=$(PACKAGE) -Dbin.package=$(PACKAGE)
diff --git a/etc/maven/m2-debian-nodocs.conf b/etc/maven/m2-debian-nodocs.conf
index 92cbe58..da67eee 100644
--- a/etc/maven/m2-debian-nodocs.conf
+++ b/etc/maven/m2-debian-nodocs.conf
@@ -1,4 +1,4 @@
-main is org.debian.maven.Wrapper from debian
+main is org.debian.maven.WrapperMaven3 from debian
set maven.home default /usr/share/maven
diff --git a/etc/maven/m2-debian.conf b/etc/maven/m2-debian.conf
index c790246..cb0f3ed 100644
--- a/etc/maven/m2-debian.conf
+++ b/etc/maven/m2-debian.conf
@@ -1,4 +1,4 @@
-main is org.debian.maven.Wrapper from debian
+main is org.debian.maven.WrapperMaven3 from debian
set maven.home default /usr/share/maven
diff --git a/maven-debian-helper/src/main/java/org/debian/maven/Wrapper.java b/maven-debian-helper/src/main/java/org/debian/maven/Wrapper.java
index cc6cfbe..f58460e 100644
--- a/maven-debian-helper/src/main/java/org/debian/maven/Wrapper.java
+++ b/maven-debian-helper/src/main/java/org/debian/maven/Wrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2009 Torsten Werner.
+ * Copyright 2013 Debian Java Developers.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,79 +16,40 @@
package org.debian.maven;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.util.Enumeration;
-import java.util.Properties;
+import java.lang.reflect.Method;
-import org.apache.maven.cli.MavenCli;
import org.codehaus.classworlds.ClassWorld;
+import org.codehaus.classworlds.ClassRealm;
+import org.codehaus.classworlds.NoSuchRealmException;
/**
- * This is a wrapper for Maven's main function that reads 2 property
- * files: debian/auto.properties and debian/manual.properties and adds
- * their content to maven's commandline.
+ * This is a wrapper for the main function of Maven 2.
*/
-public class Wrapper {
+public class Wrapper extends WrapperBase {
- /** Holds system properties */
- private static Properties systemProperties = System.getProperties();
-
- /** Holds extra properties that are read from property files */
- private static Properties extraProperties = new Properties();
+ public static int main(String[] args, ClassWorld classWorld) throws IOException {
+ init(args);
- /** The extended command line for maven's main function */
- private static String[] newArgs;
+ int result = -1;
- /**
- * Opens the filename specified by property 'key' and loads its
- * properties into extraProperties
- */
- public static void updateProperties(String key) throws IOException {
- String filename = systemProperties.getProperty(key);
- if (filename == null) {
- return;
- }
- FileInputStream stream = null;
try {
- stream = new FileInputStream(filename);
- extraProperties.load(stream);
- } finally {
- if (stream != null) {
- stream.close();
- }
- }
- }
+ ClassRealm realm = classWorld.getRealm("debian");
- /**
- * Fill new commandline array 'newArgs' with properties from
- * extraProperties and the current commandline array 'args.
- */
- public static void updateCommandLine(String[] args) throws IOException {
- int argsSize = args.length;
- int extraSize = extraProperties.size();
+ Class cwClass = realm.loadClass(ClassWorld.class.getName());
+ Class mainClass = realm.loadClass("org.apache.maven.cli.MavenCli");
+ Method mainMethod = mainClass.getMethod("main", new Class[]{ String[].class, cwClass });
- newArgs = new String[argsSize + extraSize];
+ Object ret = mainMethod.invoke(mainClass, new Object[]{ newArgs, classWorld } );
- int i = 0;
- for (Enumeration e = extraProperties.propertyNames(); e.hasMoreElements(); ) {
- String key = (String) e.nextElement();
- String value = extraProperties.getProperty(key);
- newArgs[i] = "-D" + key + "=" + value;
- i++;
+ result = ((Integer)ret).intValue();
+ } catch (NoSuchRealmException e) {
+ System.err.println("ClassWorld realm 'debian' not found!");
+ } catch (Exception e) {
+ System.err.println("Unable to invoke Maven main method: " + e.toString());
+ } finally {
+ return result;
}
-
- System.arraycopy(args, 0, newArgs, extraSize, argsSize);
- }
-
- /**
- * Wraps maven's main function
- */
- public static int main(String[] args, ClassWorld classWorld) throws IOException {
- updateProperties("properties.file.manual");
-
- updateCommandLine(args);
-
- return MavenCli.main(newArgs, classWorld);
}
}
+
diff --git a/maven-debian-helper/src/main/java/org/debian/maven/Wrapper.java b/maven-debian-helper/src/main/java/org/debian/maven/WrapperBase.java
similarity index 82%
copy from maven-debian-helper/src/main/java/org/debian/maven/Wrapper.java
copy to maven-debian-helper/src/main/java/org/debian/maven/WrapperBase.java
index cc6cfbe..211afce 100644
--- a/maven-debian-helper/src/main/java/org/debian/maven/Wrapper.java
+++ b/maven-debian-helper/src/main/java/org/debian/maven/WrapperBase.java
@@ -1,5 +1,8 @@
+package org.debian.maven;
+
/*
* Copyright 2009 Torsten Werner.
+ * Copyright 2013 Debian Java Developers.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,22 +17,17 @@
* limitations under the License.
*/
-package org.debian.maven;
-
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
-import org.apache.maven.cli.MavenCli;
-import org.codehaus.classworlds.ClassWorld;
-
/**
- * This is a wrapper for Maven's main function that reads 2 property
- * files: debian/auto.properties and debian/manual.properties and adds
- * their content to maven's commandline.
+ * This is a base class for Maven's main function wrappers. A subclass for
+ * specific Maven version should read 2 property files: debian/auto.properties
+ * and debian/manual.properties and add their content to maven's commandline.
*/
-public class Wrapper {
+public class WrapperBase {
/** Holds system properties */
private static Properties systemProperties = System.getProperties();
@@ -38,7 +36,7 @@ public class Wrapper {
private static Properties extraProperties = new Properties();
/** The extended command line for maven's main function */
- private static String[] newArgs;
+ protected static String[] newArgs;
/**
* Opens the filename specified by property 'key' and loads its
@@ -81,14 +79,9 @@ public class Wrapper {
System.arraycopy(args, 0, newArgs, extraSize, argsSize);
}
- /**
- * Wraps maven's main function
- */
- public static int main(String[] args, ClassWorld classWorld) throws IOException {
+ public static void init(String[] args) throws IOException {
updateProperties("properties.file.manual");
-
+
updateCommandLine(args);
-
- return MavenCli.main(newArgs, classWorld);
}
}
diff --git a/maven-debian-helper/src/main/java/org/debian/maven/WrapperMaven3.java b/maven-debian-helper/src/main/java/org/debian/maven/WrapperMaven3.java
new file mode 100644
index 0000000..43f318c
--- /dev/null
+++ b/maven-debian-helper/src/main/java/org/debian/maven/WrapperMaven3.java
@@ -0,0 +1,54 @@
+package org.debian.maven;
+
+/*
+ * Copyright 2013 Debian Java Developers.
+ *
+ * Licensed 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.
+ */
+
+import java.io.IOException;
+import java.lang.reflect.Method;
+
+import org.codehaus.plexus.classworlds.ClassWorld;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
+
+/**
+ * This is a wrapper for the main function of Maven 3.
+ */
+public class WrapperMaven3 extends WrapperBase {
+
+ public static int main(String[] args, ClassWorld classWorld) throws IOException {
+ init(args);
+
+ int result = -1;
+
+ try {
+ ClassRealm realm = classWorld.getRealm("debian");
+
+ Class cwClass = realm.loadClass(ClassWorld.class.getName());
+ Class mainClass = realm.loadClass("org.apache.maven.cli.MavenCli");
+ Method mainMethod = mainClass.getMethod("main", new Class[]{ String[].class, cwClass });
+
+ Object ret = mainMethod.invoke(mainClass, new Object[]{ newArgs, classWorld } );
+
+ result = ((Integer)ret).intValue();
+ } catch (NoSuchRealmException e) {
+ System.err.println("ClassWorld realm 'debian' not found!");
+ } catch (Exception e) {
+ System.err.println("Unable to invoke Maven main method: " + e.toString());
+ } finally {
+ return result;
+ }
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/maven-debian-helper.git
More information about the pkg-java-commits
mailing list