You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2016/08/03 15:25:07 UTC
tomee git commit: TOMEE-1895 allow classpath from gav in tomee maven
plugin
Repository: tomee
Updated Branches:
refs/heads/master fffd51229 -> cbec77332
TOMEE-1895 allow classpath from gav in tomee maven plugin
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/cbec7733
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/cbec7733
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/cbec7733
Branch: refs/heads/master
Commit: cbec77332582cc89e42cde60a65c05432eb92390
Parents: fffd512
Author: Romain manni-Bucau <rm...@gmail.com>
Authored: Wed Aug 3 17:24:52 2016 +0200
Committer: Romain manni-Bucau <rm...@gmail.com>
Committed: Wed Aug 3 17:24:52 2016 +0200
----------------------------------------------------------------------
.../org/apache/openejb/config/RemoteServer.java | 10 ++--
.../openejb/maven/plugin/AbstractTomEEMojo.java | 38 ++++++++++++--
.../plugin/test/ClasspathCustomizationTest.java | 53 ++++++++++++++++++++
3 files changed, 93 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/cbec7733/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java b/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
index 6cb1ef4..db664e7 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
@@ -240,7 +240,7 @@ public class RemoteServer {
}
if (javaOpts != null) {
- argsList.addAll(parse(javaOpts));
+ argsList.addAll(parse(javaOpts.replace("${openejb.base}", home.getAbsolutePath())));
}
final Map<String, String> addedArgs = new HashMap<String, String>();
@@ -250,9 +250,9 @@ public class RemoteServer {
if (equal < 0) {
addedArgs.put(arg, "null");
} else {
- addedArgs.put(arg.substring(0, equal), arg.substring(equal + 1));
+ addedArgs.put(arg.substring(0, equal), arg.substring(equal + 1).replace("${openejb.base}", home.getAbsolutePath()));
}
- argsList.add(arg);
+ argsList.add(arg.replace("${openejb.base}", home.getAbsolutePath()));
}
}
@@ -273,7 +273,7 @@ public class RemoteServer {
final File openejbJar = lib("openejb-core", lib, webapplib);
final StringBuilder cp = new StringBuilder(openejbJar.getAbsolutePath());
if (additionalClasspath != null) {
- cp.append(ps).append(additionalClasspath);
+ cp.append(ps).append(additionalClasspath.replace("${openejb.base}", home.getAbsolutePath()));
}
argsList.add("-cp");
@@ -332,7 +332,7 @@ public class RemoteServer {
cp.append(ps).append(commonsLoggingJar.getAbsolutePath());
}
if (additionalClasspath != null) {
- cp.append(ps).append(additionalClasspath);
+ cp.append(ps).append(additionalClasspath.replace("${openejb.base}", home.getAbsolutePath()));
}
argsList.add(cp.toString());
http://git-wip-us.apache.org/repos/asf/tomee/blob/cbec7733/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java
----------------------------------------------------------------------
diff --git a/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java b/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java
index f103ddd..86a8633 100644
--- a/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java
+++ b/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java
@@ -93,6 +93,7 @@ import static org.apache.maven.artifact.repository.ArtifactRepositoryPolicy.CHEC
import static org.apache.maven.artifact.repository.ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY;
import static org.apache.maven.artifact.repository.ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER;
import static org.apache.maven.artifact.versioning.VersionRange.createFromVersion;
+import static org.apache.openejb.loader.Files.mkdirs;
import static org.apache.openejb.util.JarExtractor.delete;
import static org.codehaus.plexus.util.FileUtils.deleteDirectory;
import static org.codehaus.plexus.util.IOUtil.close;
@@ -234,6 +235,9 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo {
@Parameter
protected List<String> classpaths;
+ @Parameter(property = "tomee-plugin.classpathSeparator")
+ protected String classpathSeparator;
+
@Parameter
protected List<String> customizers;
@@ -641,8 +645,36 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo {
if (!classpaths.isEmpty()) {
final StringBuilder cpBuilder = new StringBuilder();
for (final String cp : classpaths) {
- cpBuilder.append(cp);
- cpBuilder.append(File.pathSeparatorChar);
+ final String[] split = cp.split(":");
+ if (split.length >= 3 /*GAV*/) {
+ final FileWithMavenMeta jar;
+ try {
+ jar = resolve(split[0], split[1], split[2],
+ split.length > 4 ? split[4] : null, split.length > 3 ? split[3] : "jar");
+ } catch (final ArtifactResolutionException | ArtifactNotFoundException e) {
+ throw new IllegalArgumentException(e);
+ }
+
+ final File classpathRoot = new File(catalinaBase, "boot");
+ if (!classpathRoot.isDirectory()) {
+ mkdirs(classpathRoot);
+ }
+
+ final File target = new File(classpathRoot, stripVersion ? jar.stripVersion(true) : jar.resolved.getName());
+ try {
+ IO.copy(jar.resolved, target);
+ } catch (final IOException e) {
+ throw new IllegalArgumentException(e);
+ }
+
+ cpBuilder.append("${openejb.base}/boot/").append(target.getName());
+ } else { // else plain path
+ cpBuilder.append(cp);
+ }
+ if (classpathSeparator == null) {
+ classpathSeparator = File.pathSeparator;
+ }
+ cpBuilder.append(classpathSeparator);
}
return cpBuilder.substring(0, cpBuilder.length() - 1); // Dump the final path separator
}
@@ -1621,7 +1653,7 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo {
}
String stripVersion(final boolean keepExtension) {
- return artifact + (classifier != null && !classifier.isEmpty() ? "-" + classifier : "") + "." + type;
+ return artifact + (classifier != null && !classifier.isEmpty() ? "-" + classifier : "") + (keepExtension ? "." + type : "");
}
}
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/cbec7733/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/test/ClasspathCustomizationTest.java
----------------------------------------------------------------------
diff --git a/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/test/ClasspathCustomizationTest.java b/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/test/ClasspathCustomizationTest.java
new file mode 100644
index 0000000..894060a
--- /dev/null
+++ b/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/test/ClasspathCustomizationTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.openejb.maven.plugin.test;
+
+import org.apache.openejb.maven.plugin.Config;
+import org.apache.openejb.maven.plugin.TomEEMavenPluginRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.List;
+
+import static java.util.Arrays.asList;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class ClasspathCustomizationTest {
+ @Rule
+ public TomEEMavenPluginRule TMPRule = new TomEEMavenPluginRule();
+
+ @Config
+ private final List<String> classpaths = asList("org.apache.logging.log4j:log4j-api:2.6.2", "org.apache.logging.log4j:log4j-jul:2.6.2");
+
+ @Config
+ private final File catalinaBase = new File("target/tomee-classpath");
+
+ @Test
+ public void log4j2WasCopied() throws Exception {
+ final File boot = new File(catalinaBase, "boot");
+ assertTrue(boot.isDirectory());
+ assertEquals(2, boot.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(final File dir, final String name) {
+ return name.startsWith("log4j-") && name.endsWith("-2.6.2.jar");
+ }
+ }).length);
+ }
+}