Repository: karaf
Updated Branches:
  refs/heads/master 45afc23cd -> 90d289ee5


[KARAF-5310] Upgrade to maven surefire plugin 2.20 to get colored output


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/90d289ee
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/90d289ee
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/90d289ee

Branch: refs/heads/master
Commit: 90d289ee5ffedd6ff9c4bd27746947553ae1e58a
Parents: 45afc23
Author: Guillaume Nodet <[email protected]>
Authored: Tue Oct 17 19:32:35 2017 +0200
Committer: Guillaume Nodet <[email protected]>
Committed: Tue Oct 17 19:32:35 2017 +0200

----------------------------------------------------------------------
 .../apache/karaf/bundle/command/Headers.java    |   3 +-
 .../org/apache/karaf/itests/BundleTest.java     | 129 +++++++++++++++++++
 .../org/apache/karaf/itests/BundleTests.java    | 121 -----------------
 .../apache/karaf/itests/KarafTestSupport.java   |   7 +-
 pom.xml                                         |   2 +-
 .../shell/impl/console/HeadlessSessionImpl.java |   1 +
 6 files changed, 137 insertions(+), 126 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/90d289ee/bundle/core/src/main/java/org/apache/karaf/bundle/command/Headers.java
----------------------------------------------------------------------
diff --git 
a/bundle/core/src/main/java/org/apache/karaf/bundle/command/Headers.java 
b/bundle/core/src/main/java/org/apache/karaf/bundle/command/Headers.java
index ea83080..a9d8c82 100644
--- a/bundle/core/src/main/java/org/apache/karaf/bundle/command/Headers.java
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/command/Headers.java
@@ -241,8 +241,7 @@ public class Headers extends BundlesCommand {
     }
 
     protected int getTermWidth() {
-        return terminal.getWidth();
-
+        return terminal != null ? terminal.getWidth() : 0;
     }
 
     protected void formatClause(Clause clause, StringBuilder builder, int 
indent) {

http://git-wip-us.apache.org/repos/asf/karaf/blob/90d289ee/itests/src/test/java/org/apache/karaf/itests/BundleTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/BundleTest.java 
b/itests/src/test/java/org/apache/karaf/itests/BundleTest.java
new file mode 100644
index 0000000..38b270f
--- /dev/null
+++ b/itests/src/test/java/org/apache/karaf/itests/BundleTest.java
@@ -0,0 +1,129 @@
+/*
+ * 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.
+ */
+package org.apache.karaf.itests;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.openmbean.TabularDataSupport;
+
+import org.apache.karaf.bundle.core.BundleService;
+import org.apache.karaf.jaas.boot.principal.RolePrincipal;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+import java.lang.management.ManagementFactory;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class BundleTest extends KarafTestSupport {
+
+    private static final RolePrincipal[] ADMIN_ROLES = {
+            new RolePrincipal(BundleService.SYSTEM_BUNDLES_ROLE),
+            new RolePrincipal("admin"),
+            new RolePrincipal("manager")
+    };
+
+    @Test
+    public void listCommand() throws Exception {
+        String listOutput = executeCommand("bundle:list -t 0", ADMIN_ROLES);
+        System.out.println(listOutput);
+        assertFalse(listOutput.isEmpty());
+    }
+
+    @Test
+    public void listViaMBean() throws Exception {
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+            ObjectName name = new 
ObjectName("org.apache.karaf:type=bundle,name=root");
+            TabularDataSupport value = (TabularDataSupport) 
mbeanServer.getAttribute(name, "Bundles");
+            assertTrue(value.size() > 0);
+    }
+
+    @Test
+    public void capabilitiesCommand() throws Exception {
+        String allCapabilitiesOutput = executeCommand("bundle:capabilities", 
ADMIN_ROLES);
+        System.out.println(allCapabilitiesOutput);
+        assertFalse(allCapabilitiesOutput.isEmpty());
+        String jmxWhiteboardBundleCapabilitiesOutput = 
executeCommand("bundle:capabilities org.apache.aries.jmx.whiteboard", 
ADMIN_ROLES);
+        System.out.println(jmxWhiteboardBundleCapabilitiesOutput);
+        
assertTrue(jmxWhiteboardBundleCapabilitiesOutput.contains("osgi.wiring.bundle; 
org.apache.aries.jmx.whiteboard 1.1.5 [UNUSED]"));
+    }
+
+    @Test
+    public void classesCommand() throws Exception {
+        String allClassesOutput = executeCommand("bundle:classes", 
ADMIN_ROLES);
+        assertFalse(allClassesOutput.isEmpty());
+        String jmxWhiteboardBundleClassesOutput = 
executeCommand("bundle:classes org.apache.aries.jmx.whiteboard", ADMIN_ROLES);
+        System.out.println(jmxWhiteboardBundleClassesOutput);
+        
assertTrue(jmxWhiteboardBundleClassesOutput.contains("org/apache/aries/jmx/whiteboard/Activator$MBeanTracker.class"));
+    }
+
+    /**
+     * TODO We need some more thorough tests for diag
+     */
+    @Test
+    public void diagCommand() throws Exception {
+        String allDiagOutput = executeCommand("bundle:diag");
+        assertTrue(allDiagOutput.isEmpty());
+    }
+
+    @Test
+    public void findClassCommand() throws Exception {
+        String findClassOutput = executeCommand("bundle:find-class jmx");
+        System.out.println(findClassOutput);
+        assertFalse(findClassOutput.isEmpty());
+    }
+
+    @Test
+    public void headersCommand() throws Exception {
+        String headersOutput = executeCommand("bundle:headers 
org.apache.aries.jmx.whiteboard", ADMIN_ROLES);
+        System.out.println(headersOutput);
+        assertTrue(headersOutput.contains("Bundle-Activator = 
org.apache.aries.jmx.whiteboard.Activator"));
+    }
+
+    @Test
+    public void infoCommand() throws Exception {
+        String infoOutput = executeCommand("bundle:info 
org.apache.karaf.management.server", ADMIN_ROLES);
+        System.out.println(infoOutput);
+        assertTrue(infoOutput.contains("This bundle starts the Karaf embedded 
MBean server"));
+    }
+
+    @Test
+    public void installUninstallCommand() throws Exception {
+        executeCommand("bundle:install 
mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-lang/2.4_6",
 ADMIN_ROLES);
+        assertBundleInstalled("org.apache.servicemix.bundles.commons-lang");
+        executeCommand("bundle:uninstall 
org.apache.servicemix.bundles.commons-lang", ADMIN_ROLES);
+        assertBundleNotInstalled("org.apache.servicemix.bundles.commons-lang");
+    }
+
+    @Test
+    public void showTreeCommand() throws Exception {
+        String bundleTreeOutput = executeCommand("bundle:tree-show 
org.apache.karaf.management.server", ADMIN_ROLES);
+        System.out.println(bundleTreeOutput);
+        assertFalse(bundleTreeOutput.isEmpty());
+    }
+
+    @Test
+    public void statusCommand() throws Exception {
+        String statusOutput = executeCommand("bundle:status 
org.apache.karaf.management.server", ADMIN_ROLES);
+        System.out.println(statusOutput);
+        assertFalse(statusOutput.isEmpty());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/karaf/blob/90d289ee/itests/src/test/java/org/apache/karaf/itests/BundleTests.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/BundleTests.java 
b/itests/src/test/java/org/apache/karaf/itests/BundleTests.java
deleted file mode 100644
index 7d740ed..0000000
--- a/itests/src/test/java/org/apache/karaf/itests/BundleTests.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * 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.
- */
-package org.apache.karaf.itests;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.management.openmbean.TabularDataSupport;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-
-import java.lang.management.ManagementFactory;
-
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class BundleTests extends KarafTestSupport {
-
-    @Test
-    public void listCommand() throws Exception {
-        String listOutput = executeCommand("bundle:list -t 0");
-        System.out.println(listOutput);
-        assertFalse(listOutput.isEmpty());
-    }
-
-    @Test
-    public void listViaMBean() throws Exception {
-        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
-            ObjectName name = new 
ObjectName("org.apache.karaf:type=bundle,name=root");
-            TabularDataSupport value = (TabularDataSupport) 
mbeanServer.getAttribute(name, "Bundles");
-            assertTrue(value.size() > 0);
-    }
-
-    @Test
-    public void capabilitiesCommand() throws Exception {
-        String allCapabilitiesOutput = executeCommand("bundle:capabilities");
-        System.out.println(allCapabilitiesOutput);
-        assertFalse(allCapabilitiesOutput.isEmpty());
-        String jmxWhiteboardBundleCapabilitiesOutput = 
executeCommand("bundle:capabilities org.apache.aries.jmx.whiteboard");
-        System.out.println(jmxWhiteboardBundleCapabilitiesOutput);
-        
assertTrue(jmxWhiteboardBundleCapabilitiesOutput.contains("osgi.wiring.bundle; 
org.apache.aries.jmx.whiteboard 1.0.0 [UNUSED]"));
-    }
-
-    @Test
-    public void classesCommand() throws Exception {
-        String allClassesOutput = executeCommand("bundle:classes");
-        assertFalse(allClassesOutput.isEmpty());
-        String jmxWhiteboardBundleClassesOutput = 
executeCommand("bundle:classes org.apache.aries.jmx.whiteboard");
-        System.out.println(jmxWhiteboardBundleClassesOutput);
-        
assertTrue(jmxWhiteboardBundleClassesOutput.contains("org/apache/aries/jmx/whiteboard/Activator$MBeanTracker.class"));
-    }
-
-    /**
-     * TODO We need some more thorough tests for diag
-     */
-    @Test
-    public void diagCommand() throws Exception {
-        String allDiagOutput = executeCommand("bundle:diag");
-        assertTrue(allDiagOutput.isEmpty());
-    }
-
-    @Test
-    public void findClassCommand() throws Exception {
-        String findClassOutput = executeCommand("bundle:find-class jmx");
-        System.out.println(findClassOutput);
-        assertFalse(findClassOutput.isEmpty());
-    }
-
-    @Test
-    public void headersCommand() throws Exception {
-        String headersOutput = executeCommand("bundle:headers 
org.apache.aries.jmx.whiteboard");
-        System.out.println(headersOutput);
-        assertTrue(headersOutput.contains("Bundle-Activator = 
org.apache.aries.jmx.whiteboard.Activator"));
-    }
-
-    @Test
-    public void infoCommand() throws Exception {
-        String infoOutput = executeCommand("bundle:info 
org.apache.karaf.management.server");
-        System.out.println(infoOutput);
-        assertTrue(infoOutput.contains("This bundle starts the Karaf embedded 
MBean server"));
-    }
-
-    @Test
-    public void installUninstallCommand() throws Exception {
-        executeCommand("bundle:install 
mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-lang/2.4_6");
-        assertBundleInstalled("org.apache.servicemix.bundles.commons-lang");
-        executeCommand("bundle:uninstall 
org.apache.servicemix.bundles.commons-lang");
-        assertBundleNotInstalled("org.apache.servicemix.bundles.commons-lang");
-    }
-
-    @Test
-    public void showTreeCommand() throws Exception {
-        String bundleTreeOutput = executeCommand("bundle:tree-show 
org.apache.karaf.management.server");
-        System.out.println(bundleTreeOutput);
-        assertFalse(bundleTreeOutput.isEmpty());
-    }
-
-    @Test
-    public void statusCommand() throws Exception {
-        String statusOutput = executeCommand("bundle:status 
org.apache.karaf.management.server");
-        System.out.println(statusOutput);
-        assertFalse(statusOutput.isEmpty());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/90d289ee/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java 
b/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
index 34dec3d..b238b93 100644
--- a/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
+++ b/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
@@ -271,7 +271,10 @@ public class KarafTestSupport {
                 if (!silent) {
                     System.err.println(command);
                 }
-                session.execute(command);
+                Object result = session.execute(command);
+                if (result != null) {
+                    session.getConsole().println(result.toString());
+                }
             } catch (Exception e) {
                 throw new RuntimeException(e.getMessage(), e);
             }
@@ -298,7 +301,7 @@ public class KarafTestSupport {
             e.printStackTrace(System.err);
             response = "SHELL COMMAND TIMED OUT: ";
         } catch (ExecutionException e) {
-            Throwable cause = e.getCause().getCause();
+            Throwable cause = e.getCause() != null ? (e.getCause().getCause() 
!= null ? e.getCause().getCause() : e.getCause()) : e;
             throw new RuntimeException(cause.getMessage(), cause);
        } catch (InterruptedException e) {
            throw new RuntimeException(e.getMessage(), e);

http://git-wip-us.apache.org/repos/asf/karaf/blob/90d289ee/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 2e7778b..ed2f721 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1795,7 +1795,7 @@
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-surefire-plugin</artifactId>
-                    <version>2.18.1</version>
+                    <version>2.20.1</version>
                     <configuration>
                             <forkMode>once</forkMode>
                             <argLine>${surefire.argLine}</argLine>

http://git-wip-us.apache.org/repos/asf/karaf/blob/90d289ee/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
----------------------------------------------------------------------
diff --git 
a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
 
b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
index 28d9121..b496add 100644
--- 
a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
+++ 
b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
@@ -81,6 +81,7 @@ public class HeadlessSessionImpl implements Session {
             session.put("USER", ShellUtil.getCurrentUserName());
             session.put("APPLICATION", System.getProperty("karaf.name", 
"root"));
         }
+        session.put(CommandSession.OPTION_NO_GLOB, Boolean.TRUE);
         
session.currentDir(Paths.get(System.getProperty("user.dir")).toAbsolutePath().normalize());
     }
 

Reply via email to