/*
 * Licensed to the Indoqa Software Design und Beratung GmbH (Indoqa) under
 * one or more contributor license agreements. See the NOTICE file distributed
 * with this work for additional information regarding copyright ownership.
 * Indoqa 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 com.indoqa.osgi.embedded.sample.config;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.indoqa.osgi.embedded.container.ContainerConfiguration;
import com.indoqa.osgi.embedded.container.EmbeddedOSGiContainer;
import com.indoqa.osgi.embedded.container.EmbeddedOSGiContainerInitializationException;

@Configuration
public class SampleConfig {

    @Bean
    public EmbeddedOSGiContainer createEmbeddedOSGiContainer() {
        EmbeddedOSGiContainer embeddedOSGiContainer = new EmbeddedOSGiContainer();
        embeddedOSGiContainer.setSystemPackages("com.indoqa.osgi.embedded.sample.interfaces");

        Path bundlesDirectory = this.initializeDirectory(Paths.get("./target/sample-bundles"));
        Path storageDirectory = this.initializeDirectory(Paths.get("./target/sample-storage"));

        ContainerConfiguration config = new ContainerConfiguration().setFileInstallDir(bundlesDirectory)
            .setFrameworkStorage(storageDirectory)
            .setEnableRemoteShell(true);
        embeddedOSGiContainer.setContainerConfiguration(config);

        return embeddedOSGiContainer;
    }

    private Path initializeDirectory(Path dir) {
        try {
            Files.createDirectories(dir);
        } catch (IOException e) {
            throw new EmbeddedOSGiContainerInitializationException("Error while creating directory '" + dir.toAbsolutePath() + "'.",
                e);
        }
        return dir;
    }
}

@@ -970,16 +970,74 @@
 e.Paths;
+%0Aimport java.util.Collection;%0A%0Aimport javax.inject.Inject;
 %0A%0Aimport
@@ -1367,51 +1367,204 @@
 on;%0A
-%0A@Configuration%0Apublic class SampleConfig %7B
+import com.indoqa.osgi.embedded.services.EmbeddedOSGiServiceProvider;%0A%0A@Configuration%0Apublic class SampleConfig %7B%0A%0A    @Inject%0A    private Collection%3CEmbeddedOSGiServiceProvider%3E serviceProviders;
 %0A%0A  
@@ -2267,24 +2267,111 @@
 n(config);%0A%0A
+        embeddedOSGiContainer.setEmbeddedOSGiServiceProviders(this.serviceProviders);%0A%0A
         retu

add missing serviceProviders to the container (enable webapp demo again)