Ejemplo n.º 1
0
 /**
  * Invalidates the cached build rules if {@code includes} have changed since the last call. If the
  * cache is invalidated the new {@code includes} used to build the new cache are stored.
  *
  * @param includes the files to include before executing the build file.
  * @return true if the cache was invalidated, false if the cache is still valid.
  */
 private synchronized boolean invalidateCacheOnIncludeChange(Iterable<String> includes) {
   List<String> includesList = Lists.newArrayList(includes);
   if (!includesList.equals(this.cacheDefaultIncludes)) {
     invalidateCache();
     this.cacheDefaultIncludes = includesList;
     return true;
   }
   return false;
 }
Ejemplo n.º 2
0
  /**
   * Called when file change events are posted to the file change EventBus to invalidate cached
   * build rules if required.
   */
  @Subscribe
  public synchronized void onFileSystemChange(WatchEvent<?> event) throws IOException {
    if (console.getVerbosity() == Verbosity.ALL) {
      console
          .getStdErr()
          .printf(
              "Parser watched event %s %s\n",
              event.kind(), projectFilesystem.createContextString(event));
    }

    if (projectFilesystem.isPathChangeEvent(event)) {
      Path path = (Path) event.context();

      if (isPathCreateOrDeleteEvent(event)) {

        if (path.endsWith(BuckConstant.BUILD_RULES_FILE_NAME)) {

          // If a build file has been added or removed, reconstruct the build file tree.
          buildFileTreeCache.invalidate();
        }

        // Added or removed files can affect globs, so invalidate the package build file
        // "containing" {@code path} unless its filename matches a temp file pattern.
        if (!isTempFile(path)) {
          invalidateContainingBuildFile(path);
        }
      }

      // Invalidate the raw rules and targets dependent on this file.
      invalidateDependents(path);

    } else {

      // Non-path change event, likely an overflow due to many change events: invalidate everything.
      buildFileTreeCache.invalidate();
      invalidateCache();
    }
  }