This is an automated email from the ASF dual-hosted git repository. davidb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
commit 77f5e11facb91f070f0131326e1583aa5a402573 Author: David Bosschaert <[email protected]> AuthorDate: Mon Oct 15 16:36:44 2018 +0200 Initial refactoring of the Features Service Bundle. --- featuremodel/feature-service/pom.xml | 9 ++- .../org/apache/sling/feature/service/Bundles.java | 35 ----------- .../org/apache/sling/feature/service/Features.java | 22 ++----- .../service/impl/FeaturesInventoryPrinter.java | 72 ++++++++++++++++++++++ .../feature/service/impl/FeaturesServiceImpl.java | 38 +++++++----- 5 files changed, 106 insertions(+), 70 deletions(-) diff --git a/featuremodel/feature-service/pom.xml b/featuremodel/feature-service/pom.xml index 80ca9ab..a6000c8 100644 --- a/featuremodel/feature-service/pom.xml +++ b/featuremodel/feature-service/pom.xml @@ -113,8 +113,6 @@ <version>1.0.6</version> <scope>provided</scope> </dependency> - - <!-- <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.feature</artifactId> @@ -123,11 +121,16 @@ </dependency> <dependency> <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.feature.io</artifactId> + <version>0.1.3-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.feature.launcher</artifactId> <version>0.1.0-SNAPSHOT</version> <scope>provided</scope> </dependency> - --> <!-- Testing --> <dependency> diff --git a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/Bundles.java b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/Bundles.java deleted file mode 100644 index 017b32b..0000000 --- a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/Bundles.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.sling.feature.service; - -import org.osgi.framework.Version; - -/** - * This Service can provide information about bundles in the feature model. - */ -public interface Bundles { - /** - * Obtain the Artifact ID for a given bundle, identified by its - * Symbolic Name and version. - * @param bsn The symbolic name of the bundle. - * @param ver The version of the bundle. - * @return The artifact ID. - */ - String getBundleArtifact(String bsn, Version ver); -} diff --git a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/Features.java b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/Features.java index 0fe5eb6..2b39063 100644 --- a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/Features.java +++ b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/Features.java @@ -18,24 +18,10 @@ */ package org.apache.sling.feature.service; -import org.osgi.framework.Version; +import org.apache.sling.feature.ArtifactId; +import org.apache.sling.feature.Feature; -import java.util.Set; - -/** - * The Features service provides information over Features at runtime. - */ public interface Features { - /** - * Find out what features a given bundle belongs to. - * @param bsn The symbolic name of the bundle. - * @param ver The version of the bundle. - * @return The set of Feature IDs in the Maven ID syntax of the features - * that the bundle belongs to. A bundle can belong to more than one - * feature. If a bundle is not part of a feature then this method - * can return {@code null}, and empty set or the value {@code null} - * as part of a set if the bundle is present both inside as well as - * outside of a feature. - */ - Set<String> getFeaturesForBundle(String bsn, Version ver); + Feature getCurrentFeature(); + String getBundleOrigin(ArtifactId bundleId); } diff --git a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeaturesInventoryPrinter.java b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeaturesInventoryPrinter.java new file mode 100644 index 0000000..5f2c333 --- /dev/null +++ b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeaturesInventoryPrinter.java @@ -0,0 +1,72 @@ +/* + * 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.sling.feature.service.impl; + +import org.apache.felix.inventory.Format; +import org.apache.felix.inventory.InventoryPrinter; +import org.apache.sling.feature.launcher.service.Features; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +import java.io.PrintWriter; + +@Component(property = {InventoryPrinter.NAME + "=launch.features", + InventoryPrinter.TITLE + "=Launch Features", + InventoryPrinter.FORMAT + "=TEXT"}) +public class FeaturesInventoryPrinter implements InventoryPrinter +{ + + @Reference + Features featuresService; + + /* + @Activate + public void activate(BundleContext bc) { + System.out.println("*** Features Service Activated: " + bc); + + printProperty("org.osgi.framework.system.packages.extra", bc); + } + + private void printProperty(String prop, BundleContext bc) { + System.out.println("### prop val:" + bc.getProperty(prop)); + } + */ + + @Override + public void print(PrintWriter printWriter, Format format, boolean isZip) { + printWriter.println(featuresService.getEffectiveFeature()); + } + +// @Reference(target="(" + InventoryPrinter.NAME + "=launch.features)") +// InventoryPrinter printer; +// +// public FeaturesServiceImpl() { +// // TODO Auto-generated constructor stub +// } +// +// @Activate +// public void activate(BundleContext bc) { +// System.out.println("*** Features Service Activated: " + bc); +// } +// +// @Override +// public Set<String> getFeaturesForBundle(String bsn, Version ver) { +// return null; // TODO +// } +} diff --git a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeaturesServiceImpl.java b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeaturesServiceImpl.java index 2230f01..05fa582 100644 --- a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeaturesServiceImpl.java +++ b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeaturesServiceImpl.java @@ -18,33 +18,43 @@ */ package org.apache.sling.feature.service.impl; -import org.apache.felix.inventory.InventoryPrinter; +import org.apache.sling.feature.Artifact; +import org.apache.sling.feature.ArtifactId; +import org.apache.sling.feature.Feature; +import org.apache.sling.feature.io.json.FeatureJSONReader; import org.apache.sling.feature.service.Features; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Version; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; -import java.util.Set; +import java.io.IOException; +import java.io.StringReader; -@Component(immediate = true) +@Component(immediate=true) public class FeaturesServiceImpl implements Features { + private Feature feature; - @Reference(target="(" + InventoryPrinter.NAME + "=launch.features)") - InventoryPrinter printer; + @Reference + org.apache.sling.feature.launcher.service.Features launcherFeaturesService; - public FeaturesServiceImpl() { - // TODO Auto-generated constructor stub + @Activate + public void activate() throws IOException { + feature = FeatureJSONReader.read( + new StringReader(launcherFeaturesService.getEffectiveFeature()), null); } - @Activate - public void activate(BundleContext bc) { - System.out.println("*** Features Service Activated: " + bc); + @Override + public Feature getCurrentFeature() { + return feature; } @Override - public Set<String> getFeaturesForBundle(String bsn, Version ver) { - return null; // TODO + public String getBundleOrigin(ArtifactId bundleId) { + for (Artifact b : feature.getBundles()) { + if (bundleId.equals(b.getId())) { + return b.getMetadata().get("org-feature"); + } + } + return null; } }
