karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject [1/2] karaf git commit: [KARAF-2104] Add refreshRepository() operation with regex support on the FeaturesServiceMBean
Date Fri, 12 Dec 2014 13:51:41 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-2.x 26452988c -> fbcefce19


[KARAF-2104] Add refreshRepository() operation with regex support on the FeaturesServiceMBean


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

Branch: refs/heads/karaf-2.x
Commit: c3bece8ac14327874cf69181652a201322bb7e50
Parents: 3648bc2
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Fri Dec 12 14:48:55 2014 +0100
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Fri Dec 12 14:48:55 2014 +0100

----------------------------------------------------------------------
 .../management/FeaturesServiceMBean.java        |  2 ++
 .../internal/FeaturesServiceMBeanImpl.java      | 23 ++++++++++++++++++++
 .../org/apache/karaf/itests/FeaturesTest.java   | 14 ++++++++++++
 3 files changed, 39 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/c3bece8a/features/management/src/main/java/org/apache/karaf/features/management/FeaturesServiceMBean.java
----------------------------------------------------------------------
diff --git a/features/management/src/main/java/org/apache/karaf/features/management/FeaturesServiceMBean.java
b/features/management/src/main/java/org/apache/karaf/features/management/FeaturesServiceMBean.java
index dda5854..4b9284b 100644
--- a/features/management/src/main/java/org/apache/karaf/features/management/FeaturesServiceMBean.java
+++ b/features/management/src/main/java/org/apache/karaf/features/management/FeaturesServiceMBean.java
@@ -32,6 +32,8 @@ public interface FeaturesServiceMBean {
 
     void removeRepository(String url, boolean uninstall) throws Exception;
 
+    void refreshRepository(String url) throws Exception;
+
     void installFeature(String name) throws Exception;
 
     void installFeature(String name, boolean noClean, boolean noRefresh) throws Exception;

http://git-wip-us.apache.org/repos/asf/karaf/blob/c3bece8a/features/management/src/main/java/org/apache/karaf/features/management/internal/FeaturesServiceMBeanImpl.java
----------------------------------------------------------------------
diff --git a/features/management/src/main/java/org/apache/karaf/features/management/internal/FeaturesServiceMBeanImpl.java
b/features/management/src/main/java/org/apache/karaf/features/management/internal/FeaturesServiceMBeanImpl.java
index 063ef46..9a3397f 100644
--- a/features/management/src/main/java/org/apache/karaf/features/management/internal/FeaturesServiceMBeanImpl.java
+++ b/features/management/src/main/java/org/apache/karaf/features/management/internal/FeaturesServiceMBeanImpl.java
@@ -15,6 +15,8 @@ package org.apache.karaf.features.management.internal;
 
 import java.net.URI;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import javax.management.MBeanNotificationInfo;
 import javax.management.MBeanRegistration;
 import javax.management.MBeanServer;
@@ -149,6 +151,27 @@ public class FeaturesServiceMBeanImpl extends StandardEmitterMBean implements
         featuresService.removeRepository(new URI(uri), uninstall);
     }
 
+    public void refreshRepository(String uri) throws Exception {
+        List<URI> uris = new ArrayList<URI>();
+        if (uri != null && uri.length() > 0) {
+            Pattern pattern = Pattern.compile(uri);
+            for (Repository repository : featuresService.listRepositories()) {
+                Matcher matcher = pattern.matcher(repository.getURI().toString());
+                if (matcher.matches()) {
+                    uris.add(repository.getURI());
+                }
+            }
+        } else {
+            for (Repository repository : featuresService.listRepositories()) {
+                uris.add(repository.getURI());
+            }
+        }
+        for (URI u : uris) {
+            featuresService.removeRepository(u);
+            featuresService.addRepository(u);
+        }
+    }
+
     public void installFeature(String name) throws Exception {
         featuresService.installFeature(name);
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/c3bece8a/itests/src/test/java/org/apache/karaf/itests/FeaturesTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/FeaturesTest.java b/itests/src/test/java/org/apache/karaf/itests/FeaturesTest.java
index d395376..1c45a9a 100644
--- a/itests/src/test/java/org/apache/karaf/itests/FeaturesTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/FeaturesTest.java
@@ -112,6 +112,20 @@ public class FeaturesTest extends KarafTestSupport {
     }
 
     @Test
+    public void repoRefreshViaMBean() throws Exception {
+        JMXConnector connector = null;
+        try {
+            connector = this.getJMXConnector();
+            MBeanServerConnection connection = connector.getMBeanServerConnection();
+            ObjectName name = new ObjectName("org.apache.karaf:type=features,name=root");
+            connection.invoke(name, "refreshRepository", new Object[]{ ".*pax-.*" }, new
String[]{ "java.lang.String" });
+        } finally {
+            if (connector != null)
+                connector.close();
+        }
+    }
+
+    @Test
     public void repoAddRemoveCommand() throws Exception {
         System.out.println(executeCommand("features:addurl mvn:org.apache.karaf.cellar/apache-karaf-cellar/2.2.4/xml/features"));
         String repoListOutput = executeCommand("features:listurl");


Mime
View raw message