/*
 * 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.felix.fileinstall;

import java.util.*;

import org.osgi.framework.*;
import org.osgi.service.cm.*;
import org.osgi.service.packageadmin.*;
import org.osgi.util.tracker.*;

/**
 * This clever little bundle watches a directory and will install any jar file
 * if finds in that directory (as long as it is a valid bundle and not a
 * fragment).
 * 
 */
public class FileInstall implements BundleActivator, ManagedServiceFactory
{
    static ServiceTracker padmin;
    static ServiceTracker cmTracker;
    BundleContext context;
    Map watchers = new HashMap();

    public void start(BundleContext context) throws Exception
    {
        this.context = context;
        Hashtable props = new Hashtable();
        props.put(Constants.SERVICE_PID, getName());
        context.registerService(ManagedServiceFactory.class.getName(), this, props);

        padmin = new ServiceTracker(context, PackageAdmin.class.getName(), null);
        padmin.open();
        cmTracker = new ServiceTracker(context, ConfigurationAdmin.class.getName(), null);
        cmTracker.open();

        // Created the initial configuration
        Hashtable ht = new Hashtable();
        set(ht, DirectoryWatcher.POLL);
        set(ht, DirectoryWatcher.DIR);
        set(ht, DirectoryWatcher.DEBUG);
        updated("initial", ht);
    }

    private void set(Hashtable ht, String key)
    {
        Object o = context.getProperty(key);
        if (o == null)
        {
            return;
        }
        ht.put(key, o);
    }

    public void stop(BundleContext context) throws Exception
    {
        for (Iterator w = watchers.values().iterator(); w.hasNext();)
        {
            try
            {
                DirectoryWatcher dir = (DirectoryWatcher) w.next();
                w.remove();
                dir.close();
            }
            catch (Exception e)
            {
            // Ignore
            }
        }
        cmTracker.close();
        padmin.close();
    }

    public void deleted(String pid)
    {
        DirectoryWatcher watcher = (DirectoryWatcher) watchers.remove(pid);
        if (watcher != null)
        {
            watcher.close();
        }
    }

    public String getName()
    {
        return "org.apache.felix.fileinstall";
    }

    public void updated(String pid, Dictionary properties)
        throws ConfigurationException
    {
        deleted(pid);
        DirectoryWatcher watcher = new DirectoryWatcher(properties, context);
        watchers.put(pid, watcher);
        watcher.start();
    }
}
@@ -801,16 +801,17 @@
 se.%0A */%0A
+%0A
 package 
@@ -1163,16 +1163,21 @@
 agment).
+ Test
 %0A * %0A */
@@ -3356,8 +3356,9 @@
 %0A    %7D%0A%7D
+%0A

Test commit