diff --git a/api/infoGatherer/specDetails.go b/api/infoGatherer/specDetails.go index 07811a825..95207ee27 100644 --- a/api/infoGatherer/specDetails.go +++ b/api/infoGatherer/specDetails.go @@ -8,12 +8,10 @@ package infoGatherer import ( "io/ioutil" - "path/filepath" "sync" "github.com/fsnotify/fsnotify" "github.com/getgauge/gauge-proto/go/gauge_messages" - "github.com/getgauge/gauge/config" "github.com/getgauge/gauge/gauge" "github.com/getgauge/gauge/logger" "github.com/getgauge/gauge/parser" @@ -364,115 +362,115 @@ func (s *SpecInfoGatherer) OnConceptFileModify(file string) { s.updateParamsCacheFromConcepts(file, s.conceptsCache.concepts[file]) } -func (s *SpecInfoGatherer) onSpecFileRemove(file string) { - logger.Debugf(false, "Spec file removed: %s", file) - s.specsCache.mutex.Lock() - defer s.specsCache.mutex.Unlock() - delete(s.specsCache.specDetails, file) - s.removeStepsFromCache(file) -} -func (s *SpecInfoGatherer) removeStepsFromCache(fileName string) { - s.stepsCache.mutex.Lock() - defer s.stepsCache.mutex.Unlock() - delete(s.stepsCache.steps, fileName) -} - -func (s *SpecInfoGatherer) onConceptFileRemove(file string) { - logger.Debugf(false, "Concept file removed: %s", file) - s.conceptsCache.mutex.Lock() - defer s.conceptsCache.mutex.Unlock() - s.deleteFromConceptDictionary(file) - delete(s.conceptsCache.concepts, file) - s.removeStepsFromCache(file) -} - -func (s *SpecInfoGatherer) onFileAdd(watcher *fsnotify.Watcher, file string) { - if util.IsDir(file) { - addDirToFileWatcher(watcher, file) - } - s.onFileModify(watcher, file) -} - -func (s *SpecInfoGatherer) onFileModify(watcher *fsnotify.Watcher, file string) { - if util.IsSpec(file) { - s.OnSpecFileModify(file) - } else if util.IsConcept(file) { - s.OnConceptFileModify(file) - } -} - -func (s *SpecInfoGatherer) onFileRemove(watcher *fsnotify.Watcher, file string) { - if util.IsSpec(file) { - s.onSpecFileRemove(file) - } else if util.IsConcept(file) { - s.onConceptFileRemove(file) - } else { - removeWatcherOn(watcher, file) - } -} - -func (s *SpecInfoGatherer) onFileRename(watcher *fsnotify.Watcher, file string) { - s.onFileRemove(watcher, file) -} - -func (s *SpecInfoGatherer) handleEvent(event fsnotify.Event, watcher *fsnotify.Watcher) { - s.waitGroup.Wait() - - file, err := filepath.Abs(event.Name) - if err != nil { - logger.Errorf(false, "Failed to get abs file path for %s: %s", event.Name, err) - return - } - if util.IsSpec(file) || util.IsConcept(file) || util.IsDir(file) { - switch event.Op { - case fsnotify.Create: - s.onFileAdd(watcher, file) - case fsnotify.Write: - s.onFileModify(watcher, file) - case fsnotify.Rename: - s.onFileRename(watcher, file) - case fsnotify.Remove: - s.onFileRemove(watcher, file) - } - } -} - -func (s *SpecInfoGatherer) watchForFileChanges() { - s.waitGroup.Add(1) - - watcher, err := fsnotify.NewWatcher() - if err != nil { - logger.Errorf(false, "Error creating fileWatcher: %s", err) - } - defer watcher.Close() - - done := make(chan bool) - go func() { - for { - select { - case event := <-watcher.Events: - s.handleEvent(event, watcher) - case err := <-watcher.Errors: - logger.Errorf(false, "Error event while watching specs %s", err) - } - } - }() - - var allDirsToWatch []string - var specDir string - - for _, dir := range s.SpecDirs { - specDir = filepath.Join(config.ProjectRoot, dir) - allDirsToWatch = append(allDirsToWatch, specDir) - allDirsToWatch = append(allDirsToWatch, util.FindAllNestedDirs(specDir)...) - } - - for _, dir := range allDirsToWatch { - addDirToFileWatcher(watcher, dir) - } - s.waitGroup.Done() - <-done -} +// func (s *SpecInfoGatherer) onSpecFileRemove(file string) { +// logger.Debugf(false, "Spec file removed: %s", file) +// s.specsCache.mutex.Lock() +// defer s.specsCache.mutex.Unlock() +// delete(s.specsCache.specDetails, file) +// s.removeStepsFromCache(file) +// } +// func (s *SpecInfoGatherer) removeStepsFromCache(fileName string) { +// s.stepsCache.mutex.Lock() +// defer s.stepsCache.mutex.Unlock() +// delete(s.stepsCache.steps, fileName) +// } + +// func (s *SpecInfoGatherer) onConceptFileRemove(file string) { +// logger.Debugf(false, "Concept file removed: %s", file) +// s.conceptsCache.mutex.Lock() +// defer s.conceptsCache.mutex.Unlock() +// s.deleteFromConceptDictionary(file) +// delete(s.conceptsCache.concepts, file) +// s.removeStepsFromCache(file) +// } + +// func (s *SpecInfoGatherer) onFileAdd(watcher *fsnotify.Watcher, file string) { +// if util.IsDir(file) { +// addDirToFileWatcher(watcher, file) +// } +// s.onFileModify(watcher, file) +// } + +// func (s *SpecInfoGatherer) onFileModify(watcher *fsnotify.Watcher, file string) { +// if util.IsSpec(file) { +// s.OnSpecFileModify(file) +// } else if util.IsConcept(file) { +// s.OnConceptFileModify(file) +// } +// } + +// func (s *SpecInfoGatherer) onFileRemove(watcher *fsnotify.Watcher, file string) { +// if util.IsSpec(file) { +// s.onSpecFileRemove(file) +// } else if util.IsConcept(file) { +// s.onConceptFileRemove(file) +// } else { +// removeWatcherOn(watcher, file) +// } +// } + +// func (s *SpecInfoGatherer) onFileRename(watcher *fsnotify.Watcher, file string) { +// s.onFileRemove(watcher, file) +// } + +// func (s *SpecInfoGatherer) handleEvent(event fsnotify.Event, watcher *fsnotify.Watcher) { +// s.waitGroup.Wait() + +// file, err := filepath.Abs(event.Name) +// if err != nil { +// logger.Errorf(false, "Failed to get abs file path for %s: %s", event.Name, err) +// return +// } +// if util.IsSpec(file) || util.IsConcept(file) || util.IsDir(file) { +// switch event.Op { +// case fsnotify.Create: +// s.onFileAdd(watcher, file) +// case fsnotify.Write: +// s.onFileModify(watcher, file) +// case fsnotify.Rename: +// s.onFileRename(watcher, file) +// case fsnotify.Remove: +// s.onFileRemove(watcher, file) +// } +// } +// } + +// func (s *SpecInfoGatherer) watchForFileChanges() { +// s.waitGroup.Add(1) + +// watcher, err := fsnotify.NewWatcher() +// if err != nil { +// logger.Errorf(false, "Error creating fileWatcher: %s", err) +// } +// defer watcher.Close() + +// done := make(chan bool) +// go func() { +// for { +// select { +// case event := <-watcher.Events: +// s.handleEvent(event, watcher) +// case err := <-watcher.Errors: +// logger.Errorf(false, "Error event while watching specs %s", err) +// } +// } +// }() + +// var allDirsToWatch []string +// var specDir string + +// for _, dir := range s.SpecDirs { +// specDir = filepath.Join(config.ProjectRoot, dir) +// allDirsToWatch = append(allDirsToWatch, specDir) +// allDirsToWatch = append(allDirsToWatch, util.FindAllNestedDirs(specDir)...) +// } + +// for _, dir := range allDirsToWatch { +// addDirToFileWatcher(watcher, dir) +// } +// s.waitGroup.Done() +// <-done +// } // GetAvailableSpecs returns the list of all the specs in the gauge project func (s *SpecInfoGatherer) GetAvailableSpecDetails(specs []string) []*SpecDetail {