Author: bdelacretaz
Date: Mon Jun 15 10:35:00 2015
New Revision: 1685532
URL: http://svn.apache.org/r1685532
Log:
SLING-4728 - refactor artifacts visit
Added:
sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/ArtifactsVisitor.java
Modified:
sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/BundlesInstaller.java
Added:
sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/ArtifactsVisitor.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/ArtifactsVisitor.java?rev=1685532&view=auto
==============================================================================
---
sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/ArtifactsVisitor.java
(added)
+++
sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/ArtifactsVisitor.java
Mon Jun 15 10:35:00 2015
@@ -0,0 +1,67 @@
+/*
+ * 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.crankstart.launcher;
+
+import org.apache.sling.provisioning.model.Artifact;
+import org.apache.sling.provisioning.model.ArtifactGroup;
+import org.apache.sling.provisioning.model.Feature;
+import org.apache.sling.provisioning.model.Model;
+import org.apache.sling.provisioning.model.RunMode;
+
+/** Visit the Artifacts of a Model */
+public abstract class ArtifactsVisitor {
+ private final Model model;
+
+ public ArtifactsVisitor(Model m) {
+ model = m;
+ }
+
+ protected abstract void visitArtifact(Feature f, RunMode rm, ArtifactGroup
g, Artifact a) throws Exception;
+
+ public void visit() throws Exception {
+ for(Feature f : model.getFeatures()) {
+ if(!acceptFeature(f)) {
+ continue;
+ }
+ for(RunMode rm : f.getRunModes()) {
+ if(!acceptRunMode(rm)) {
+ continue;
+ }
+ for(ArtifactGroup g : rm.getArtifactGroups()) {
+ if(!acceptArtifactGroup(g)) {
+ continue;
+ }
+ for(Artifact a : g) {
+ visitArtifact(f, rm, g, a);
+ }
+ }
+ }
+ }
+ }
+
+ protected boolean acceptFeature(Feature f) {
+ return true;
+ }
+
+ protected boolean acceptRunMode(RunMode rm) {
+ return true;
+ }
+
+ protected boolean acceptArtifactGroup(ArtifactGroup g) {
+ return true;
+ }
+}
\ No newline at end of file
Modified:
sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/BundlesInstaller.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/BundlesInstaller.java?rev=1685532&r1=1685531&r2=1685532&view=diff
==============================================================================
---
sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/BundlesInstaller.java
(original)
+++
sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/BundlesInstaller.java
Mon Jun 15 10:35:00 2015
@@ -44,36 +44,44 @@ public class BundlesInstaller {
this.rmFilter = rmFilter;
}
- public void installBundles(BundleContext ctx, FeatureFilter filter) throws
IOException, BundleException {
- for(Feature f : model.getFeatures()) {
- if(filter.ignoreFeature(f)) {
- log.info("Ignoring feature: {}", f.getName());
- continue;
+ public void installBundles(final BundleContext ctx, final FeatureFilter
filter) throws Exception {
+ final String JAR_TYPE = "jar";
+
+ final ArtifactsVisitor v = new ArtifactsVisitor(model) {
+
+ @Override
+ protected void visitArtifact(Feature f, RunMode rm, ArtifactGroup
g, Artifact a) throws Exception {
+ if(JAR_TYPE.equals(a.getType())) {
+ installBundle(ctx, a, g.getStartLevel());
+ } else {
+ log.info("Ignoring Artifact, not a bundle: {}", a);
+ }
}
-
- log.info("Processing feature: {}", f.getName());
- for(RunMode rm : f.getRunModes()) {
- if(!rmFilter.runModeActive(rm)) {
- log.info("RunMode is not active, ignored: {}",
Arrays.asList(rm.getNames()));
- continue;
+
+ @Override
+ protected boolean acceptFeature(Feature f) {
+ final boolean accept = !filter.ignoreFeature(f);
+ if(!accept) {
+ log.info("Ignoring feature: {}", f.getName());
}
- for(ArtifactGroup g : rm.getArtifactGroups()) {
- final int startLevel = g.getStartLevel();
- for(Artifact a : g) {
- // TODO for now, naively assume a is a bundle, and
mvn: protocol
- final String url = "mvn:" + a.getGroupId() + "/" +
a.getArtifactId() + "/" + a.getVersion();
- installBundle(ctx, url, startLevel);
- }
+ return accept;
+ }
+
+ @Override
+ protected boolean acceptRunMode(RunMode rm) {
+ final boolean accept = rmFilter.runModeActive(rm);
+ if(!accept) {
+ log.info("RunMode is not active, ignored: {}",
Arrays.asList(rm.getNames()));
}
+ return accept;
}
- }
- }
-
- protected boolean ignoreFeature(Feature f) {
- return false;
+ };
+
+ v.visit();
}
- public void installBundle(BundleContext ctx, String bundleUrl, int
startLevel) throws IOException, BundleException {
+ public void installBundle(BundleContext ctx, Artifact a, int startLevel)
throws IOException, BundleException {
+ final String bundleUrl = "mvn:" + a.getGroupId() + "/" +
a.getArtifactId() + "/" + a.getVersion();
final URL url = new URL(bundleUrl);
final InputStream bundleStream = url.openStream();
try {