You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2013/11/13 14:21:08 UTC

svn commit: r1541514 - in /karaf/trunk: features/command/src/main/java/org/apache/karaf/features/command/ features/command/src/main/resources/OSGI-INF/blueprint/ features/core/src/main/java/org/apache/karaf/features/ features/core/src/main/java/org/apa...

Author: cschneider
Date: Wed Nov 13 13:21:07 2013
New Revision: 1541514

URL: http://svn.apache.org/r1541514
Log:
KARAF-2545 Adding feature:refresh command

Added:
    karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/RepoRefreshCommand.java
Modified:
    karaf/trunk/features/command/src/main/resources/OSGI-INF/blueprint/features-command.xml
    karaf/trunk/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
    karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
    karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java

Added: karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/RepoRefreshCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/RepoRefreshCommand.java?rev=1541514&view=auto
==============================================================================
--- karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/RepoRefreshCommand.java (added)
+++ karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/RepoRefreshCommand.java Wed Nov 13 13:21:07 2013
@@ -0,0 +1,73 @@
+/*
+ * 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.features.command;
+
+import java.net.URI;
+
+import org.apache.karaf.features.FeaturesService;
+import org.apache.karaf.features.Repository;
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.console.AbstractAction;
+
+@Command(scope = "feature", name = "repo-refresh", description = "Refresh a features repository")
+public class RepoRefreshCommand extends AbstractAction {
+    @Argument(index = 0, name = "Feature name or uri", description = "Shortcut name of the feature repository or the full URI", required = false, multiValued = false)
+    private String nameOrUrl;
+    
+    @Argument(index = 1, name = "Feature version", description = "The version of the feature if using the feature name. Should be empty if using the uri", required = false, multiValued = false)
+    private String version;
+
+    private FeatureFinder featureFinder;
+    private FeaturesService featuresService;
+    
+    public void setFeatureFinder(FeatureFinder featureFinder) {
+        this.featureFinder = featureFinder;
+    }
+
+    public void setFeaturesService(FeaturesService featuresService) {
+        this.featuresService = featuresService;
+    }
+
+    protected Object doExecute() throws Exception {
+    	if (nameOrUrl != null) {
+    		String effectiveVersion = (version == null) ? "LATEST" : version;
+        	URI uri = featureFinder.getUriFor(nameOrUrl, effectiveVersion);
+        	if (uri == null) {
+        		uri = new URI(nameOrUrl);
+        	}
+        	System.out.println("Refreshing feature url " + uri);
+        	featuresService.refreshRepository(uri);
+    	} else {
+    		refreshAll();
+    	}
+        return null;
+    }
+
+	private void refreshAll() {
+		Repository[] repos = featuresService.listRepositories();
+		for (Repository repo : repos) {
+			try {
+				System.out.println("Refreshing feature url " + repo.getURI());
+				featuresService.refreshRepository(repo.getURI());
+			} catch (Exception e) {
+				System.err.println("Error refreshing " + repo.getURI().toString() + ": " +e.getMessage());
+			}
+		}
+	}
+
+}

Modified: karaf/trunk/features/command/src/main/resources/OSGI-INF/blueprint/features-command.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/features/command/src/main/resources/OSGI-INF/blueprint/features-command.xml?rev=1541514&r1=1541513&r2=1541514&view=diff
==============================================================================
--- karaf/trunk/features/command/src/main/resources/OSGI-INF/blueprint/features-command.xml (original)
+++ karaf/trunk/features/command/src/main/resources/OSGI-INF/blueprint/features-command.xml Wed Nov 13 13:21:07 2013
@@ -40,6 +40,16 @@
             </completers>
         </command>
         <command>
+            <action class="org.apache.karaf.features.command.RepoRefreshCommand">
+                <property name="featureFinder" ref="featureFinder" />
+                <property name="featuresService" ref="featuresService" />
+            </action>
+            <completers>
+                <ref component-id="installedRepoUriCompleter" />
+                <null/>
+            </completers>
+        </command>
+        <command>
             <action class="org.apache.karaf.features.command.InstallFeatureCommand"/>
             <completers>
                 <ref component-id="uninstalledFeatureCompleter" />

Modified: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java?rev=1541514&r1=1541513&r2=1541514&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java (original)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java Wed Nov 13 13:21:07 2013
@@ -80,4 +80,6 @@ public interface FeaturesService {
     Feature getFeature(String name, String version) throws Exception;
 
     Feature getFeature(String name) throws Exception;
+
+	void refreshRepository(URI uri) throws Exception;
 }

Modified: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java?rev=1541514&r1=1541513&r2=1541514&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java (original)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java Wed Nov 13 13:21:07 2013
@@ -188,7 +188,8 @@ public class FeaturesServiceImpl impleme
      * @param uri the features repository URI.
      * @throws Exception in case of refresh failure.
      */
-    protected void refreshRepository(URI uri) throws Exception {
+    @Override
+    public void refreshRepository(URI uri) throws Exception {
         this.refreshRepository(uri, false);
     }
 

Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java?rev=1541514&r1=1541513&r2=1541514&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java Wed Nov 13 13:21:07 2013
@@ -586,6 +586,12 @@ public class InstallKarsMojo extends Moj
             // TODO Auto-generated method stub
             return null;
         }
+
+		@Override
+		public void refreshRepository(URI uri) throws Exception {
+			// TODO Auto-generated method stub
+			
+		}
     }
 
     // when FELIX-2887 is ready we can use plain Properties again