[
https://issues.apache.org/jira/browse/KARAF-4336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16698059#comment-16698059
]
ASF GitHub Bot commented on KARAF-4336:
---------------------------------------
jbonofre closed pull request #660: [KARAF-4336] Add rank support for commands
and scripts in the karaf:client mojo
URL: https://github.com/apache/karaf/pull/660
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/client/ClientMojo.java
b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/client/ClientMojo.java
index 68199449d2..1a1871af24 100644
---
a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/client/ClientMojo.java
+++
b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/client/ClientMojo.java
@@ -52,8 +52,11 @@
import java.io.StringWriter;
import java.net.URL;
import java.security.KeyPair;
+import java.util.Comparator;
import java.util.EnumSet;
import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
/**
@@ -81,10 +84,10 @@
private int delay;
@Parameter
- private List<String> commands;
+ private List<CommandDescriptor> commands;
@Parameter
- private List<File> scripts;
+ private List<ScriptDescriptor> scripts;
@Parameter
private File keyFile;
@@ -92,32 +95,42 @@
private static final String NEW_LINE =
System.getProperty("line.separator");
public void execute() throws MojoExecutionException {
- // Add commands from scripts to already declared commands
+ // ranking the commands and scripts
+ Comparator<CommandDescriptor> comparator =
Comparator.comparingInt(CommandDescriptor::getRank);
+ SortedSet<CommandDescriptor> sortedCommands = new
TreeSet<>(comparator);
if (scripts != null) {
- for (File script : scripts) {
- try (BufferedReader br = new BufferedReader(new
FileReader(script))) {
+ for (ScriptDescriptor script : scripts) {
+ File file = script.getScript();
+ try (BufferedReader br = new BufferedReader(new
FileReader(file))) {
String line;
while ((line = br.readLine()) != null) {
line = line.trim();
if (line.isEmpty()) {
continue;
}
- commands.add(line);
+ CommandDescriptor descriptor = new CommandDescriptor();
+ descriptor.setCommand(line);
+ descriptor.setRank(script.getRank());
+ sortedCommands.add(descriptor);
}
} catch (Exception e) {
throw new MojoExecutionException(e, e.getMessage(),
e.toString());
}
}
}
+ if (commands != null) {
+ sortedCommands.addAll(commands);
+ }
- if (commands == null || commands.isEmpty()) {
- getLog().warn("No OSGi command was specified");
+ if (sortedCommands == null || sortedCommands.isEmpty()) {
+ getLog().warn("No command specified");
return;
}
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
- for (String cmd : commands) {
+ for (CommandDescriptor command : sortedCommands) {
+ String cmd = command.getCommand();
getLog().info(cmd);
pw.println(cmd);
}
diff --git
a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/client/CommandDescriptor.java
b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/client/CommandDescriptor.java
new file mode 100644
index 0000000000..c532360995
--- /dev/null
+++
b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/client/CommandDescriptor.java
@@ -0,0 +1,40 @@
+/*
+ * 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.karaf.tooling.client;
+
+public class CommandDescriptor {
+
+ private int rank;
+ private String command;
+
+ public int getRank() {
+ return rank;
+ }
+
+ public void setRank(int rank) {
+ this.rank = rank;
+ }
+
+ public String getCommand() {
+ return command;
+ }
+
+ public void setCommand(String command) {
+ this.command = command;
+ }
+
+}
diff --git
a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/client/ScriptDescriptor.java
b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/client/ScriptDescriptor.java
new file mode 100644
index 0000000000..3728c088df
--- /dev/null
+++
b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/client/ScriptDescriptor.java
@@ -0,0 +1,42 @@
+/*
+ * 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.karaf.tooling.client;
+
+import java.io.File;
+
+public class ScriptDescriptor {
+
+ private int rank;
+ private File script;
+
+ public int getRank() {
+ return rank;
+ }
+
+ public void setRank(int rank) {
+ this.rank = rank;
+ }
+
+ public File getScript() {
+ return script;
+ }
+
+ public void setScript(File script) {
+ this.script = script;
+ }
+
+}
diff --git
a/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/client/SortedCommand.java
b/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/client/SortedCommand.java
new file mode 100644
index 0000000000..6960cdcb95
--- /dev/null
+++
b/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/client/SortedCommand.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.karaf.tooling.client;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+public class SortedCommand {
+
+ @Test
+ public void testSort() throws Exception {
+ List<CommandDescriptor> commands = new ArrayList<>();
+ CommandDescriptor command = new CommandDescriptor();
+ command.setRank(2);
+ command.setCommand("test2");
+ commands.add(command);
+ command = new CommandDescriptor();
+ command.setRank(1);
+ command.setCommand("test1");
+ commands.add(command);
+
+ // ranking the commands and scripts
+ Comparator<CommandDescriptor> comparator =
Comparator.comparingInt(CommandDescriptor::getRank);
+ SortedSet<CommandDescriptor> sortedCommands = new
TreeSet<>(comparator);
+ sortedCommands.addAll(commands);
+
+ for (CommandDescriptor cmd : sortedCommands) {
+ System.out.println("Rank: " + cmd.getRank());
+ System.out.println("Command: " + cmd.getCommand());
+ System.out.println("");
+ }
+ }
+
+}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Add support for ordering of CLI scripts and commands in karaf-maven-plugin
> --------------------------------------------------------------------------
>
> Key: KARAF-4336
> URL: https://issues.apache.org/jira/browse/KARAF-4336
> Project: Karaf
> Issue Type: Improvement
> Components: karaf
> Affects Versions: 4.0.4
> Reporter: Martin BasovnĂk
> Assignee: Jean-Baptiste Onofré
> Priority: Major
> Labels: client, maven, tooling
> Fix For: 4.2.2
>
>
> {code:xml}
> <configuration>
> <scripts>
> <script order="1">setup1.cli</script>
> <script order="3">setup2.cli</script>
> </scripts>
> <commands order="2">
> <command>feature:repo-add camel ${version.camel}</command>
> </commands>
> </configuration>
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)