You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gg...@apache.org on 2017/12/09 18:47:01 UTC
[karaf] 18/19: [KARAF-5376] Provide feature:refresh no-arg command
that re-reads all feature XMLs and feature processing XML
This is an automated email from the ASF dual-hosted git repository.
ggrzybek pushed a commit to branch KARAF-5376-overrides_v2
in repository https://gitbox.apache.org/repos/asf/karaf.git
commit eae1b83bbf713ae8d7f395e9a8ce593c904b9f3f
Author: Grzegorz Grzybek <gr...@gmail.com>
AuthorDate: Fri Dec 8 12:43:17 2017 +0100
[KARAF-5376] Provide feature:refresh no-arg command that re-reads all feature XMLs and feature processing XML
---
.../features/command/RefreshFeaturesCommand.java | 35 ++++++++++++++++++++++
.../org/apache/karaf/features/FeaturesService.java | 2 ++
.../internal/service/FeaturesServiceImpl.java | 20 +++++++++++--
3 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/features/command/src/main/java/org/apache/karaf/features/command/RefreshFeaturesCommand.java b/features/command/src/main/java/org/apache/karaf/features/command/RefreshFeaturesCommand.java
new file mode 100644
index 0000000..6a89978
--- /dev/null
+++ b/features/command/src/main/java/org/apache/karaf/features/command/RefreshFeaturesCommand.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.karaf.features.command;
+
+import org.apache.karaf.features.FeaturesService;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+
+@Command(scope = "feature", name = "refresh", description = "Reloads features processing instructions and reprovisions existing features.")
+@Service
+public class RefreshFeaturesCommand extends FeaturesCommandSupport {
+
+ protected void doExecute(FeaturesService featuresService) throws Exception {
+ try {
+ featuresService.refreshFeatures();
+ } catch (Exception e) {
+ System.err.println("Error refreshing features: " + e.getMessage());
+ }
+ }
+
+}
diff --git a/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java b/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
index 9ff9cdb..0a7ebaa 100644
--- a/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
+++ b/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
@@ -222,4 +222,6 @@ public interface FeaturesService {
String getFeatureXml(Feature feature);
+ void refreshFeatures() throws Exception;
+
}
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
index 4f92c57..f4b8a00 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
@@ -34,6 +34,7 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
@@ -111,8 +112,8 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
private final Resolver resolver;
private final BundleInstallSupport installSupport;
private final FeaturesServiceConfig cfg;
- private final RepositoryCache repositories;
- private final FeaturesProcessor featuresProcessor;
+ private RepositoryCache repositories;
+ private FeaturesProcessor featuresProcessor;
private final ThreadLocal<String> outputFile = new ThreadLocal<>();
@@ -1166,4 +1167,19 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
return null;
}
}
+
+ @Override
+ public void refreshFeatures() throws Exception {
+ Set<URI> uris = new LinkedHashSet<>();
+ for (Repository r : this.repositories.listRepositories()) {
+ uris.add(r.getURI());
+ }
+ this.refreshRepositories(uris);
+ this.featuresProcessor = new FeaturesProcessorImpl(cfg);
+ this.repositories = new RepositoryCacheImpl(featuresProcessor);
+
+ State state = copyState();
+ doProvisionInThread(state.requirements, emptyMap(), state, getFeaturesById(), EnumSet.noneOf(Option.class));
+ }
+
}
--
To stop receiving notification emails like this one, please contact
"commits@karaf.apache.org" <co...@karaf.apache.org>.