001package com.dev9.mvnwatcher.event;
002
003import com.google.common.eventbus.EventBus;
004import com.google.inject.Inject;
005import com.google.inject.Provider;
006import com.google.inject.name.Named;
007
008import java.io.IOException;
009import java.nio.file.Paths;
010
011/**
012 * Created by IntelliJ IDEA.
013 * User: bbejeck
014 * Date: 2/25/12
015 * Time: 9:19 PM
016 */
017
018public class DirectoryEventWatcherProvider implements Provider<DirectoryEventWatcher> {
019
020    private EventBus eventBus;
021    private String startPath;
022
023
024    @Inject
025    public DirectoryEventWatcherProvider(EventBus eventBus, @Named("START_PATH") String startPath) {
026        this.eventBus = eventBus;
027        this.startPath = startPath;
028    }
029
030    @Override
031    public DirectoryEventWatcher get() {
032
033        DirectoryEventWatcherImpl directoryEventWatcher = null;
034        try {
035            directoryEventWatcher = new DirectoryEventWatcherImpl(eventBus);
036            directoryEventWatcher.add(Paths.get(startPath));
037        } catch (IOException e) {
038            e.printStackTrace();
039        }
040
041        return directoryEventWatcher;
042    }
043}