karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [1/2] karaf git commit: [KARAF-5308] Use upfront loading for repositories
Date Tue, 15 Aug 2017 13:39:56 GMT
Repository: karaf
Updated Branches:
  refs/heads/master eb95bce7d -> 549740347


[KARAF-5308] Use upfront loading for repositories


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

Branch: refs/heads/master
Commit: a75fabaf071b8274c7f266affa7ce7cdd87a2a22
Parents: eb95bce
Author: Christian Schneider <chris@die-schneider.net>
Authored: Tue Aug 15 15:39:26 2017 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Tue Aug 15 15:39:26 2017 +0200

----------------------------------------------------------------------
 .../internal/service/FeaturesServiceImpl.java   | 15 ++++----
 .../internal/service/RepositoryCache.java       |  7 ++--
 .../internal/service/RepositoryImpl.java        | 25 +++++--------
 .../apache/karaf/features/RepositoryTest.java   |  3 +-
 .../internal/service/BlacklistTest.java         | 23 ++++++------
 .../features/internal/service/DeployerTest.java |  5 ---
 .../service/FeaturesValidationTest.java         | 37 +++++++++++---------
 7 files changed, 52 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/a75fabaf/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
----------------------------------------------------------------------
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 90f4969..27ccf97 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
@@ -254,15 +254,14 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
     public void registerListener(FeaturesListener listener) {
         listeners.add(listener);
         try {
-            Set<String> repositories = new TreeSet<>();
+            Set<String> repositoriesList = new TreeSet<>();
             Map<String, Set<String>> installedFeatures = new TreeMap<>();
             synchronized (lock) {
-                repositories.addAll(state.repositories);
+                repositoriesList.addAll(state.repositories);
                 installedFeatures.putAll(copy(state.installedFeatures));
             }
-            Blacklist blacklist = new Blacklist(cfg.blacklisted);
-            for (String uri : repositories) {
-                Repository repository = new RepositoryImpl(URI.create(uri), blacklist);
+            for (String uri : repositoriesList) {
+                Repository repository = repositories.create(URI.create(uri), false);
                 listener.repositoryEvent(new RepositoryEvent(repository, RepositoryEvent.EventType.RepositoryAdded,
true));
             }
             for (Map.Entry<String, Set<String>> entry : installedFeatures.entrySet())
{
@@ -357,7 +356,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
 
     @Override
     public void addRepository(URI uri, boolean install) throws Exception {
-        Repository repository = repositories.create(uri, true, true);
+        Repository repository = repositories.create(uri, true);
         synchronized (lock) {
             repositories.addRepository(repository);
             featureCache = null;
@@ -610,7 +609,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
             }
             try {
                 if (repo == null) {
-                    repo = repositories.create(URI.create(uri), true, false);
+                    repo = repositories.create(URI.create(uri), false);
                     synchronized (lock) {
                         repositories.addRepository(repo);
                     }
@@ -979,7 +978,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
 
     @Override
     public Repository createRepository(URI uri) throws Exception {
-        return repositories.create(uri, true, true);
+        return repositories.create(uri, true);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/karaf/blob/a75fabaf/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryCache.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryCache.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryCache.java
index 4898566..801ffeb 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryCache.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryCache.java
@@ -38,11 +38,8 @@ public class RepositoryCache {
         this.blacklist = blacklist;
     }
 
-    public Repository create(URI uri, boolean load, boolean validate) throws Exception {
-        RepositoryImpl repo = new RepositoryImpl(uri, blacklist);
-        if (load)
-            repo.load(validate);
-        return repo;
+    public Repository create(URI uri, boolean validate) throws Exception {
+        return new RepositoryImpl(uri, blacklist, validate);
     }
 
     public void addRepository(Repository repository) throws Exception {

http://git-wip-us.apache.org/repos/asf/karaf/blob/a75fabaf/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
index 0bdc174..0e9d703 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
@@ -38,51 +38,44 @@ public class RepositoryImpl implements Repository {
     private Features features;
     
     public RepositoryImpl(URI uri) {
-        this(uri, null);
+        this(uri, null, false);
     }
 
-    public RepositoryImpl(URI uri, Blacklist blacklist) {
+    public RepositoryImpl(URI uri, Blacklist blacklist, boolean validate) {
         this.uri = uri;
         this.blacklist = blacklist;
+        load(validate);
     }
 
     public URI getURI() {
         return uri;
     }
 
-    public String getName() throws IOException {
-        load();
+    public String getName() {
         return features.getName();
     }
 
-    public URI[] getRepositories() throws IOException {
-        load();
+    public URI[] getRepositories() {
         return features.getRepository().stream()
                 .map(String::trim)
                 .map(URI::create)
                 .toArray(URI[]::new);
     }
 
-    public URI[] getResourceRepositories() throws IOException {
-        load();
+    public URI[] getResourceRepositories() {
         return features.getResourceRepository().stream()
                 .map(String::trim)
                 .map(URI::create)
                 .toArray(URI[]::new);
     }
 
-    public Feature[] getFeatures() throws IOException {
-        load();
+    public Feature[] getFeatures() {
         return features.getFeature()
                 .toArray(new Feature[features.getFeature().size()]);
     }
 
 
-    public void load() throws IOException {
-        load(false);
-    }
-
-    public void load(boolean validate) throws IOException {
+    private void load(boolean validate) {
         if (features == null) {
             try (
                     InputStream inputStream = new InterruptibleInputStream(uri.toURL().openStream())
@@ -92,7 +85,7 @@ public class RepositoryImpl implements Repository {
                     blacklist.blacklist(features);
                 }
             } catch (Exception e) {
-                throw new IOException(e.getMessage() + " : " + uri, e);
+                throw new RuntimeException(e.getMessage() + " : " + uri, e);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/a75fabaf/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java
----------------------------------------------------------------------
diff --git a/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java b/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java
index c630c6f..a6c7ede 100644
--- a/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java
@@ -177,9 +177,8 @@ public class RepositoryTest extends TestCase {
 
     public void testShowWrongUriInException() throws Exception {
         String uri = "src/test/resources/org/apache/karaf/shell/features/repo1.xml";
-        RepositoryImpl r = new RepositoryImpl(new URI(uri));
         try {
-            r.load();
+            new RepositoryImpl(new URI(uri));
         } catch (Exception e) {
             assertTrue(e.getMessage().contains(uri));
         }

http://git-wip-us.apache.org/repos/asf/karaf/blob/a75fabaf/features/core/src/test/java/org/apache/karaf/features/internal/service/BlacklistTest.java
----------------------------------------------------------------------
diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/service/BlacklistTest.java
b/features/core/src/test/java/org/apache/karaf/features/internal/service/BlacklistTest.java
index 9d09e56..956d04b 100644
--- a/features/core/src/test/java/org/apache/karaf/features/internal/service/BlacklistTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/internal/service/BlacklistTest.java
@@ -18,14 +18,14 @@ package org.apache.karaf.features.internal.service;
 
 import static org.junit.Assert.assertTrue;
 
-import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.stream.Stream;
 
 import org.apache.karaf.features.BundleInfo;
-import org.apache.karaf.features.internal.model.Feature;
-import org.apache.karaf.features.internal.model.Features;
-import org.apache.karaf.features.internal.model.JaxbUtil;
+import org.apache.karaf.features.Feature;
 import org.junit.Test;
 
 public class BlacklistTest {
@@ -56,12 +56,15 @@ public class BlacklistTest {
         assertTrue(bundles.noneMatch(b -> b.getLocation().equals(blacklisted)));
     }
 
-    private Stream<Feature> blacklistWith(String blacklistClause) {
-        URL url = getClass().getResource("f02.xml");
-        Features features = JaxbUtil.unmarshal(url.toExternalForm(), true);
-
+    private Stream<org.apache.karaf.features.Feature> blacklistWith(String blacklistClause)
{
+        URI uri;
+        try {
+            uri = getClass().getResource("f02.xml").toURI();
+        } catch (URISyntaxException e) {
+            throw new RuntimeException(e);
+        }
         Blacklist blacklist = new Blacklist(Collections.singletonList(blacklistClause));
-        blacklist.blacklist(features);
-        return features.getFeature().stream();
+        RepositoryImpl features = new RepositoryImpl(uri, blacklist, true);
+        return Arrays.asList(features.getFeatures()).stream();
     }
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/a75fabaf/features/core/src/test/java/org/apache/karaf/features/internal/service/DeployerTest.java
----------------------------------------------------------------------
diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/service/DeployerTest.java
b/features/core/src/test/java/org/apache/karaf/features/internal/service/DeployerTest.java
index c9cc4ae..a08d7c5 100644
--- a/features/core/src/test/java/org/apache/karaf/features/internal/service/DeployerTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/internal/service/DeployerTest.java
@@ -71,7 +71,6 @@ public class DeployerTest {
         TestDownloadManager manager = new TestDownloadManager(getClass(), dataDir);
 
         RepositoryImpl repo = new RepositoryImpl(getClass().getResource(dataDir + "/features.xml").toURI());
-        repo.load(true);
         Feature f100 = repo.getFeatures()[0];
         Feature f101 = repo.getFeatures()[1];
 
@@ -145,7 +144,6 @@ public class DeployerTest {
         TestDownloadManager manager = new TestDownloadManager(getClass(), dataDir);
 
         RepositoryImpl repo = new RepositoryImpl(getClass().getResource(dataDir + "/features.xml").toURI());
-        repo.load(true);
         Feature f100 = repo.getFeatures()[0];
         Feature f101 = repo.getFeatures()[1];
 
@@ -247,7 +245,6 @@ public class DeployerTest {
         TestDownloadManager manager = new TestDownloadManager(getClass(), dataDir);
 
         RepositoryImpl repo = new RepositoryImpl(getClass().getResource(dataDir + "/features.xml").toURI());
-        repo.load(true);
         Feature f1 = repo.getFeatures()[0];
 
         Bundle serviceBundle = createTestBundle(1, Bundle.ACTIVE, dataDir, "a100");
@@ -318,7 +315,6 @@ public class DeployerTest {
         TestDownloadManager manager = new TestDownloadManager(getClass(), dataDir);
 
         RepositoryImpl repo = new RepositoryImpl(getClass().getResource(dataDir + "/features.xml").toURI());
-        repo.load(true);
         Feature f1 = repo.getFeatures()[0];
         Feature f2 = repo.getFeatures()[1];
 
@@ -479,7 +475,6 @@ public class DeployerTest {
         TestDownloadManager manager = new TestDownloadManager(getClass(), dataDir);
 
         RepositoryImpl repo = new RepositoryImpl(getClass().getResource(dataDir + "/features.xml").toURI());
-        repo.load(true);
 
         Map<String, Bundle> bundles = new HashMap<>();
         bundles.put("a100", createTestBundle(1, Bundle.ACTIVE, dataDir, "a100"));

http://git-wip-us.apache.org/repos/asf/karaf/blob/a75fabaf/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesValidationTest.java
----------------------------------------------------------------------
diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesValidationTest.java
b/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesValidationTest.java
index 09badc5..e21c854 100644
--- a/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesValidationTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesValidationTest.java
@@ -24,28 +24,28 @@ import static org.junit.Assert.fail;
 
 import java.net.URI;
 
+import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.Library;
-import org.apache.karaf.features.internal.model.Features;
-import org.apache.karaf.features.internal.model.JaxbUtil;
+import org.apache.karaf.features.Repository;
 import org.junit.Test;
 
 public class FeaturesValidationTest {
 
     @Test
     public void testNs10() throws Exception {
-        Features features = unmarshalAndValidate("f02.xml");
+        Repository features = unmarshalAndValidate("f02.xml");
         assertNotNull(features);
     }
 
     @Test
     public void testNs10NoName() throws Exception {
-        Features features = unmarshalAndValidate("f03.xml");
+        Repository features = unmarshalAndValidate("f03.xml");
         assertNotNull(features);
     }
 
     @Test
     public void testNs11() throws Exception {
-        Features features = unmarshalAndValidate("f04.xml");;
+        Repository features = unmarshalAndValidate("f04.xml");;
         assertNotNull(features);
     }
 
@@ -61,27 +61,30 @@ public class FeaturesValidationTest {
 
     @Test
     public void testNs12Unmarshall() throws Exception {
-        Features features = unmarshalAndValidate("f06.xml");
+        Repository features = unmarshalAndValidate("f06.xml");
         assertNotNull(features);
     }
 
     @Test
     public void testNs13() throws Exception {
-        Features features = unmarshalAndValidate("f07.xml");
+        Repository features = unmarshalAndValidate("f07.xml");
         assertNotNull(features);
-        assertEquals("2.5.6.SEC02", features.getFeature().get(0).getVersion());
-        assertTrue(features.getFeature().get(1).isHidden());
-        assertNotNull(features.getFeature().get(1).getLibraries());
-        assertEquals(1, features.getFeature().get(0).getLibraries().size());
-        assertEquals("my-library", features.getFeature().get(0).getLibraries().get(0).getLocation());
-        assertEquals(Library.TYPE_ENDORSED, features.getFeature().get(0).getLibraries().get(0).getType());
-        assertFalse(features.getFeature().get(0).getLibraries().get(0).isExport());
-        assertTrue(features.getFeature().get(0).getLibraries().get(0).isDelegate());
+        Feature f0 = features.getFeatures()[0];
+        Feature f1 = features.getFeatures()[1];
+        assertEquals("2.5.6.SEC02", f0.getVersion());
+        assertTrue(f1.isHidden());
+        assertNotNull(f1.getLibraries());
+        assertEquals(1, f0.getLibraries().size());
+        Library lib = f0.getLibraries().get(0);
+        assertEquals("my-library", lib.getLocation());
+        assertEquals(Library.TYPE_ENDORSED, lib.getType());
+        assertFalse(lib.isExport());
+        assertTrue(lib.isDelegate());
     }
 
-    private Features unmarshalAndValidate(String path) throws Exception {
+    private Repository unmarshalAndValidate(String path) throws Exception {
         URI uri = getClass().getResource(path).toURI();
-        return JaxbUtil.unmarshal(uri.toASCIIString(), true);
+        return new RepositoryImpl(uri, null, true);
     }
 
 }


Mime
View raw message