Package org.apache.karaf.features

Examples of org.apache.karaf.features.FeaturesService


            if (!startupPropertiesFile.getParentFile().exists()) {
                startupPropertiesFile.getParentFile().mkdirs();
            }
        }

        FeaturesService featuresService = new OfflineFeaturesService();

        Collection<Artifact> dependencies = project.getDependencyArtifacts();
        StringBuilder buf = new StringBuilder();
        byte[] buffer = new byte[4096];
        for (Artifact artifact : dependencies) {
            dontAddToStartup = "runtime".equals(artifact.getScope());
            if ("kar".equals(artifact.getType()) && acceptScope(artifact)) {
                File file = artifact.getFile();
                try {
                    Kar kar = new Kar(file.toURI());
                    kar.extract(new File(system.getPath()), new File(workDirectory));
                    for (URI repoUri : kar.getFeatureRepos()) {
                        featuresService.removeRepository(repoUri);
                        featuresService.addRepository(repoUri);
                    }
                } catch (Exception e) {
                    throw new RuntimeException("Could not install kar: " + artifact.toString() + "\n", e);
                    //buf.append("Could not install kar: ").append(artifact.toString()).append("\n");
                    //buf.append(e.getMessage()).append("\n\n");
                }
            }
            if ("features".equals(artifact.getClassifier()) && acceptScope(artifact)) {
                String uri = MavenUtil.artifactToMvn(artifact);

                File source = artifact.getFile();
                DefaultRepositoryLayout layout = new DefaultRepositoryLayout();

                //remove timestamp version
                artifact = factory.createArtifactWithClassifier(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact.getType(), artifact.getClassifier());
                File target = new File(system.resolve(layout.pathOf(artifact)));

                if (!target.exists()) {
                    target.getParentFile().mkdirs();
                    try {
                        InputStream is = new FileInputStream(source);
                        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(target));
                        int count = 0;
                        while ((count = is.read(buffer)) > 0) {
                            bos.write(buffer, 0, count);
                        }
                        bos.close();
                    } catch (IOException e) {
                        getLog().error("Could not copy features " + uri + " from source file " + source, e);
                    }

                    // for snapshot, generate the repository metadata in order to avoid override of snapshot from remote repositories
                    if (artifact.isSnapshot()) {
                        getLog().debug("Feature " + uri + " is a SNAPSHOT, generate the maven-metadata-local.xml file");
                        File metadataTarget = new File(target.getParentFile(), "maven-metadata-local.xml");
                        try {
                            MavenUtil.generateMavenMetadata(artifact, metadataTarget);
                        } catch (Exception e) {
                            getLog().warn("Could not create maven-metadata-local.xml", e);
                            getLog().warn("It means that this SNAPSHOT could be overwritten by an older one present on remote repositories");
                        }
                    }

                }
                try {
                    featuresService.addRepository(URI.create(uri));
                } catch (Exception e) {
                    buf.append("Could not install feature: ").append(artifact.toString()).append("\n");
                    buf.append(e.getMessage()).append("\n\n");
                }
            }
View Full Code Here


*/
public class FeaturesMatchingFilterTest {

    @Test
    public void testMatches() throws Exception {
        FeaturesService service = createMockFeaturesService();

        FabResolverFactoryImpl.FeaturesMatchingFilter filter = new FabResolverFactoryImpl.FeaturesMatchingFilter(service, new FabConfiguration() {
            @Override
            public String getStringProperty(String name) {
                // no configuration
View Full Code Here

        assertTrue(filter.getCollection().contains("feature-a/1.0"));
    }

    @Test
    public void testMatchesWithFilter() throws Exception {
        FeaturesService service = createMockFeaturesService();
        FabConfiguration configuration = new FabConfiguration() {

            @Override
            public String getStringProperty(String name) {
                if (ServiceConstants.INSTR_FAB_SKIP_MATCHING_FEATURE_DETECTION.equals(name)) {
View Full Code Here

        assertEquals(0, filter.getCollection().size());
    }

    private FeaturesService createMockFeaturesService() throws Exception {
        FeaturesService service = createNiceMock(FeaturesService.class);

        Feature feature1 =
            FeaturesTest.createMockFeatureWithOptionalBundles("feature-a",
                    "mvn:required/bundle1/1.0",
                    "mvn:optional/bundle1/1.0");
        Feature feature2 =
            FeaturesTest.createMockFeatureWithOptionalBundles("feature-b",
                                                              "mvn:required/bundle2/1.0",
                                                              "mvn:optional/bundle2/1.0");

        Feature[] features = new Feature[] { feature1, feature2 };
        expect(service.listFeatures()).andReturn(features).anyTimes();
        replay(service);
        return service;
    }
View Full Code Here

                bundleContext,
                FeaturesService.class,
                null) {
            @Override
            public FeaturesService addingService(ServiceReference<FeaturesService> reference) {
                FeaturesService fs = super.addingService(reference);
                factory.setFeaturesService(fs);
                return fs;
            }

            @Override
View Full Code Here

     * Install all the required feature URLs and features for this FAB
     */
    private void installMissingFeatures(FabBundleInfo info) {
        ServiceReference reference = bundleContext.getServiceReference(FeaturesService.class.getName());
        try {
            final FeaturesService service = (FeaturesService) bundleContext.getService(reference);

            for (URI uri : info.getFeatureURLs()) {
                try {
                    service.addRepository(uri);
                } catch (Exception e) {
                    LOG.warn("Unable to add feature repository URL {} - FAB {} may not get installed properly", uri, url);
                }
            }

View Full Code Here

    /**
     * Installs a feature and checks that feature is properly installed.
     */
    public void installAndCheckFeature(String feature) throws Exception {
        System.err.println(executeCommand("features:install " + feature));
        FeaturesService featuresService = ServiceLocator.awaitService(bundleContext, FeaturesService.class);
        System.err.println(executeCommand("osgi:list -t 0"));
        Assert.assertTrue("Expected " + feature + " feature to be installed.", featuresService.isInstalled(featuresService.getFeature(feature)));
    }
View Full Code Here

    /**
     * Uninstalls a feature and checks that feature is properly uninstalled.
     */
    public void unInstallAndCheckFeature(String feature) throws Exception {
        System.err.println(executeCommand("features:uninstall " + feature));
        FeaturesService featuresService = ServiceLocator.awaitService(bundleContext, FeaturesService.class);
        System.err.println(executeCommand("osgi:list -t 0"));
        Assert.assertFalse("Expected " + feature + " feature to be installed.", featuresService.isInstalled(featuresService.getFeature(feature)));
    }
View Full Code Here

public class ListFeaturesCommandTest {

    @Test
    public void testHiddenFeatures() throws Exception {

        FeaturesService service = EasyMock.createMock(FeaturesService.class);
        Repository repo = EasyMock.createMock(Repository.class);
        Feature feature = EasyMock.createMock(Feature.class);

        EasyMock.expect(service.listRepositories()).andReturn(new Repository[] { repo });
        EasyMock.expect(repo.getFeatures()).andReturn(new Feature[] { feature });
        EasyMock.expect(feature.isHidden()).andReturn(true);

        EasyMock.replay(service, repo, feature);
View Full Code Here

    }

    @Test
    public void testShowHiddenFeatures() throws Exception {

        FeaturesService service = EasyMock.createMock(FeaturesService.class);
        Repository repo = EasyMock.createMock(Repository.class);
        Feature feature = EasyMock.createMock(Feature.class);

        EasyMock.expect(service.listRepositories()).andReturn(new Repository[] { repo });
        EasyMock.expect(repo.getFeatures()).andReturn(new Feature[] { feature });
        EasyMock.expect(feature.isHidden()).andReturn(true).anyTimes();
        EasyMock.expect(feature.getName()).andReturn("feature");
        EasyMock.expect(feature.getDescription()).andReturn("description");
        EasyMock.expect(feature.getVersion()).andReturn("1.0.0");
        EasyMock.expect(service.isRequired(feature)).andReturn(true);
        EasyMock.expect(service.isInstalled(feature)).andReturn(true);
        EasyMock.expect(repo.getName()).andReturn("repository").anyTimes();

        EasyMock.replay(service, repo, feature);

        ListFeaturesCommand command = new ListFeaturesCommand();
View Full Code Here

TOP

Related Classes of org.apache.karaf.features.FeaturesService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.