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 2014/12/16 09:09:32 UTC
[4/4] tomee git commit: TOMEE-1477 correct handling of tomee maven
plugin args
TOMEE-1477 correct handling of tomee maven plugin args
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/bc4afb84
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/bc4afb84
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/bc4afb84
Branch: refs/heads/develop
Commit: bc4afb84374c29b7935a4e297122c8f1e406b4c5
Parents: 99de2f6
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Tue Dec 16 09:09:14 2014 +0100
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Tue Dec 16 09:09:14 2014 +0100
----------------------------------------------------------------------
.../openejb/maven/plugin/AbstractTomEEMojo.java | 3 +-
.../apache/openejb/maven/plugin/cli/Args.java | 58 ++++++++++++++++++++
.../openejb/maven/plugin/cli/ArgsTest.java | 35 ++++++++++++
3 files changed, 95 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/bc4afb84/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 b27f007..d28f204 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
@@ -36,6 +36,7 @@ import org.apache.openejb.config.RemoteServer;
import org.apache.openejb.loader.Files;
import org.apache.openejb.loader.IO;
import org.apache.openejb.loader.Zips;
+import org.apache.openejb.maven.plugin.cli.Args;
import org.apache.openejb.util.Join;
import org.apache.openejb.util.OpenEjbVersion;
import org.apache.tomee.util.QuickServerXmlParser;
@@ -965,7 +966,7 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo {
}
}
if (args != null) {
- strings.addAll(Arrays.asList(args.split(" ")));
+ strings.addAll(Args.parse(args));
}
if (javaagents != null) {
addJavaagents(strings);
http://git-wip-us.apache.org/repos/asf/tomee/blob/bc4afb84/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/cli/Args.java
----------------------------------------------------------------------
diff --git a/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/cli/Args.java b/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/cli/Args.java
new file mode 100644
index 0000000..d96335f
--- /dev/null
+++ b/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/cli/Args.java
@@ -0,0 +1,58 @@
+/*
+ * 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.cli;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+public final class Args {
+ public static Collection<String> parse(final String raw) {
+ final Collection<String> result = new LinkedList<>();
+
+ Character end = null;
+ boolean escaped = false;
+ final StringBuilder current = new StringBuilder();
+ for (int i = 0; i < raw.length(); i++) {
+ final char c = raw.charAt(i);
+ if (escaped) {
+ escaped = false;
+ current.append(c);
+ } else if ((end != null && end == c) || (c == ' ' && end == null)) {
+ if (current.length() > 0) {
+ result.add(current.toString());
+ current.setLength(0);
+ }
+ end = null;
+ } else if (c == '\\') {
+ escaped = true;
+ } else if (c == '"' || c == '\'') {
+ end = c;
+ } else {
+ current.append(c);
+ }
+ }
+ if (current.length() > 0) {
+ result.add(current.toString());
+ }
+
+ return result;
+ }
+
+ private Args() {
+ // no-op
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/bc4afb84/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/cli/ArgsTest.java
----------------------------------------------------------------------
diff --git a/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/cli/ArgsTest.java b/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/cli/ArgsTest.java
new file mode 100644
index 0000000..4603cb1
--- /dev/null
+++ b/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/cli/ArgsTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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.cli;
+
+import org.junit.Test;
+
+import static java.util.Arrays.asList;
+import static org.junit.Assert.assertEquals;
+
+public class ArgsTest {
+ @Test
+ public void checkParsing() {
+ assertEquals(asList("-Dfoo=bar"), Args.parse("-Dfoo=bar"));
+ assertEquals(asList("-Dfoo=bar", "-D2=3", "-Dty"), Args.parse("-Dfoo=bar -D2=3 -Dty"));
+ assertEquals(asList("-Dfoo=bar", "-D2=3", "-Dty"), Args.parse("-Dfoo=bar -D2=3 -Dty"));
+ assertEquals(asList("-Dkey with space=value"), Args.parse("\"-Dkey with space=value\""));
+ assertEquals(asList("-Dkey with space"), Args.parse("\"-Dkey with space\""));
+ assertEquals(asList("-Dkey with space=value with space"), Args.parse("\"-Dkey with space=value with space\""));
+ assertEquals(asList("-Dfoo1=bar", "-Dkey with space=value with space", "-Dfoo=bar"), Args.parse("-Dfoo1=bar \"-Dkey with space=value with space\" -Dfoo=bar"));
+ }
+}