Search in sources :

Example 31 with Repository

use of org.apache.karaf.features.Repository in project karaf by apache.

the class RepositoryCacheTest method refCountForIncludedRepositories.

@Test
@Ignore("Ignoring to check if it's real problem")
public void refCountForIncludedRepositories() throws Exception {
    RepositoryCacheImpl cache = new RepositoryCacheImpl(null);
    Repository repo1 = cache.create(getClass().getResource("/org/apache/karaf/features/repo1.xml").toURI(), false);
    Repository repo2 = cache.create(getClass().getResource("/org/apache/karaf/features/repo2.xml").toURI(), false);
    cache.addRepository(repo1);
    cache.addRepository(repo2);
    cache.addRepository(new RepositoryImpl(URI.create("urn:r1"), false));
    assertNotNull(cache.getRepository("urn:r1"));
    cache.removeRepository(repo2.getURI());
    assertNotNull("Repository referenced from two different repositories should not be cascade-removed", cache.getRepository("urn:r1"));
}
Also used : Repository(org.apache.karaf.features.Repository) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 32 with Repository

use of org.apache.karaf.features.Repository in project fabric8 by jboss-fuse.

the class FeatureUtils method search.

public static Feature search(String name, String version, Collection<Repository> repositories) {
    VersionRange range = new VersionRange(version, false, true);
    Feature bestFeature = null;
    Version bestVersion = null;
    for (Repository repo : repositories) {
        Feature[] features;
        try {
            features = repo.getFeatures();
        } catch (Exception e) {
            // This should not happen as the repository has been loaded already
            throw new IllegalStateException(e);
        }
        for (Feature feature : features) {
            if (name.equals(feature.getName())) {
                Version v = new Version(VersionCleaner.clean(feature.getVersion()));
                if (range.contains(v)) {
                    if (bestVersion == null || bestVersion.compareTo(v) < 0) {
                        bestFeature = feature;
                        bestVersion = v;
                    }
                }
            }
        }
    }
    return bestFeature;
}
Also used : Repository(org.apache.karaf.features.Repository) Version(org.osgi.framework.Version) VersionRange(org.apache.felix.utils.version.VersionRange) Feature(org.apache.karaf.features.Feature)

Example 33 with Repository

use of org.apache.karaf.features.Repository in project ddf by codice.

the class ApplicationServiceImplTest method testGetAllFeaturesFTRException.

/**
 * Tests the {@link ApplicationServiceImpl#getAllFeatures()} method for the case where an
 * exception is thrown in getFeatureToRepository(..)
 */
@Test
public void testGetAllFeaturesFTRException() throws Exception {
    Set<Repository> activeRepos = new HashSet<>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl(featuresService);
    doThrow(new NullPointerException()).when(featuresService).listRepositories();
    List<FeatureDetails> details = appService.getAllFeatures();
    assertThat("List of feature details should have 7 entries", details, hasSize(4));
    details.forEach(d -> assertThat(d.getName() + " should not have a mapped repository", d.getRepository(), is(nullValue())));
}
Also used : Repository(org.apache.karaf.features.Repository) FeatureDetails(org.codice.ddf.admin.application.rest.model.FeatureDetails) FeaturesService(org.apache.karaf.features.FeaturesService) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 34 with Repository

use of org.apache.karaf.features.Repository in project ddf by codice.

the class ApplicationServiceImplTest method testGetInstallProfilesException.

/**
 * Tests the {@link ApplicationServiceImpl#getInstallationProfiles()} method for the case where
 * featuresService.listFeatures() throws an exception
 */
@Test
public void testGetInstallProfilesException() throws Exception {
    Set<Repository> activeRepos = new HashSet<>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = new ApplicationServiceImpl(featuresService, new Security()) {

        @Override
        protected BundleContext getContext() {
            return bundleContext;
        }
    };
    doThrow(new NullPointerException()).when(featuresService).listFeatures();
    assertThat("No installation profiles should of been found, expected an empty collection", appService.getInstallationProfiles(), is(empty()));
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Security(org.codice.ddf.security.impl.Security) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 35 with Repository

use of org.apache.karaf.features.Repository in project karaf by apache.

the class RepositoryCache method tranGetRepositories.

public Set<Repository> tranGetRepositories(Repository repo) throws Exception {
    HashSet<Repository> repos = new HashSet<>();
    repos.add(repo);
    Set<Repository> deps = getRepositories(repo);
    for (Repository depRepo : deps) {
        if (!repos.contains(depRepo)) {
            repos.addAll(tranGetRepositories(depRepo));
        }
    }
    return repos;
}
Also used : Repository(org.apache.karaf.features.Repository) HashSet(java.util.HashSet)

Aggregations

Repository (org.apache.karaf.features.Repository)84 Test (org.junit.Test)52 HashSet (java.util.HashSet)51 FeaturesService (org.apache.karaf.features.FeaturesService)44 Feature (org.apache.karaf.features.Feature)38 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)37 URI (java.net.URI)20 Application (org.codice.ddf.admin.application.service.Application)20 LinkedHashSet (java.util.LinkedHashSet)9 ArrayList (java.util.ArrayList)8 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)8 Logger (org.slf4j.Logger)7 Appender (ch.qos.logback.core.Appender)6 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 ArgumentMatcher (org.mockito.ArgumentMatcher)6 Mockito.anyString (org.mockito.Mockito.anyString)6 EnumSet (java.util.EnumSet)5 Map (java.util.Map)5 TreeMap (java.util.TreeMap)4