// Path: cicomponents-api/src/main/java/org/cicomponents/ResourceListener.java
// @FunctionalInterface
// public interface ResourceListener<T extends Resource> {
//     void onEmittedResource(ResourceHolder<T> holder,
//                            ResourceEmitter<T> emitter);
// 
//     default boolean isMatchingListener(Class klass) {
//         for (Type type : getClass().getGenericInterfaces()) {
//             if (type instanceof ParameterizedType &&
//                     ((ParameterizedType) type).getRawType() == ResourceListener.class) {
//                 ParameterizedType parameterizedType = (ParameterizedType) type;
//                 Type target = parameterizedType.getActualTypeArguments()[0];
//                 if (target == klass) {
//                     return true;
//                 }
//             }
//         }
//         return false;
//     }
// }
// 
// Path: cicomponents-git-api/src/main/java/org/cicomponents/git/GitRevision.java
// public interface GitRevision extends File, Resource {
//     Git getRepository();
//     ObjectId getRef();
// }
// 
// Path: cicomponents-git-api/src/main/java/org/cicomponents/git/GitRevisionEmitter.java
// public interface GitRevisionEmitter extends ResourceEmitter<GitRevision> {
// }


import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.cicomponents.ResourceListener;
import org.cicomponents.git.GitRevision;
import org.cicomponents.git.GitRevisionEmitter;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.*;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Consumer;
                    log.info("Adding GitRevision listener {} {}" + listener.getValue(), props);
                    for (ServiceReference<GitRevisionEmitter> reference : references) {
                        GitRevisionEmitter service = context.getBundleContext().getService(reference);
                        service.addResourceListener(listener.getValue());
                        context.getBundleContext().ungetService(reference);
                    }
                } else {
                    log.info("Starting GitRevisionEmitter for listener {} {}", listener.getValue(), props);
                    Dictionary<String, String> properties = new Hashtable<>();
                    properties.put("type", (String) props.get("type"));
                    properties.put("repository", (String) props.get("repository"));
                    String branch = (String) props.get("branch");
                    properties.put("branch", branch == null ? "master" : branch);
                    AbstractGitMonitor monitor = instantiators.get(emitters.get(props.get("type")))
                                                              .apply(environment, properties);
                    monitor.addResourceListener(listener.getValue());
                    context.getBundleContext().registerService(GitRevisionEmitter.class, monitor, properties);
                }
            }
        }
        forEachService(context, (emitter) -> {
            if (emitter instanceof AbstractGitMonitor) {
                ((AbstractGitMonitor) emitter).resume();
            }
        });
        log.info("Activation complete");
    }

    @Deactivate
    protected void deactivate(ComponentContext context) {
// Path: cicomponents-api/src/main/java/org/cicomponents/ResourceListener.java
// @FunctionalInterface
// public interface ResourceListener<T extends Resource> {
//     void onEmittedResource(ResourceHolder<T> holder,
//                            ResourceEmitter<T> emitter);
// 
//     default boolean isMatchingListener(Class klass) {
//         for (Type type : getClass().getGenericInterfaces()) {
//             if (type instanceof ParameterizedType &&
//                     ((ParameterizedType) type).getRawType() == ResourceListener.class) {
//                 ParameterizedType parameterizedType = (ParameterizedType) type;
//                 Type target = parameterizedType.getActualTypeArguments()[0];
//                 if (target == klass) {
//                     return true;
//                 }
//             }
//         }
//         return false;
//     }
// }
// 
// Path: cicomponents-git-api/src/main/java/org/cicomponents/git/GitRevision.java
// public interface GitRevision extends File, Resource {
//     Git getRepository();
//     ObjectId getRef();
// }
// 
// Path: cicomponents-git-api/src/main/java/org/cicomponents/git/GitRevisionEmitter.java
// public interface GitRevisionEmitter extends ResourceEmitter<GitRevision> {
// }


// Path: cicomponents-git/src/main/java/org/cicomponents/git/impl/GitEmitterProvider.java
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.cicomponents.ResourceListener;
import org.cicomponents.git.GitRevision;
import org.cicomponents.git.GitRevisionEmitter;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.*;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Consumer;

                    log.info("Adding GitRevision listener {} {}" + listener.getValue(), props);
                    for (ServiceReference<GitRevisionEmitter> reference : references) {
                        GitRevisionEmitter service = context.getBundleContext().getService(reference);
                        service.addResourceListener(listener.getValue());
                        context.getBundleContext().ungetService(reference);
                    }
                } else {
                    log.info("Starting GitRevisionEmitter for listener {} {}", listener.getValue(), props);
                    Dictionary<String, String> properties = new Hashtable<>();
                    properties.put("type", (String) props.get("type"));
                    properties.put("repository", (String) props.get("repository"));
                    String branch = (String) props.get("branch");
                    properties.put("branch", branch == null ? "master" : branch);
                    AbstractGitMonitor monitor = instantiators.get(emitters.get(props.get("type")))
                                                              .apply(environment, properties);
                    monitor.addResourceListener(listener.getValue());
                    context.getBundleContext().registerService(GitRevisionEmitter.class, monitor, properties);
                }
            }
        }
        forEachService(context, (emitter) -> {
            if (emitter instanceof AbstractGitMonitor) {
                ((AbstractGitMonitor) emitter).resume();
            }
        });
        log.info("Activation complete");
    }

    @Deactivate
    protected void deactivate(ComponentContext context) {
        for (Map.Entry<Map<String, Object>, ResourceListener<GitRevision>> listener : listeners) {