Fixes issue 1049.  Generated files were not being considered generated/transient if the -gen flag was specified.  This is not so much a fix as it is a band-aid.  We need to reconsider the hosted mode cache design when we look at "instant" hosted mode; it may not be necessary to have the cache at all.

Patch by: mmendez, rdayal
Review by: scottb



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1044 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jdt/CacheManager.java b/dev/core/src/com/google/gwt/dev/jdt/CacheManager.java
index ae39226..8d0189e 100644
--- a/dev/core/src/com/google/gwt/dev/jdt/CacheManager.java
+++ b/dev/core/src/com/google/gwt/dev/jdt/CacheManager.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006 Google Inc.
+ * Copyright 2007 Google Inc.
  * 
  * Licensed 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
@@ -272,7 +272,7 @@
     private void extractTypeNamesFromTypeArg(String typeArg, Set typeNames) {
       // Remove all whitespace
       typeArg.replaceAll("\\\\s", "");
-      
+
       // Remove anything that is not a raw type name
       String[] typeArgs = typeArg.split("[\\[\\]<>,]");
 
@@ -518,7 +518,7 @@
     }
   }
 
-  // This method must be outside of DiskCache because of the restruction against
+  // This method must be outside of DiskCache because of the restriction against
   // defining static methods in inner classes.
   private static String possiblyAddTmpExtension(Object className) {
     String fileName = className.toString();
@@ -533,7 +533,7 @@
     return fileName;
   }
 
-  // This method must be outside of DiskCache because of the restruction against
+  // This method must be outside of DiskCache because of the restriction against
   // defining static methods in inner classes.
   private static String possiblyRemoveTmpExtension(Object fileName) {
     String className = fileName.toString();
@@ -559,6 +559,15 @@
 
   private boolean firstTime = true;
 
+  /**
+   * Set of {@link CompilationUnitProvider} locations for all of the compilation
+   * units generated by {@link com.google.gwt.core.ext.Generator Generator}s.
+   * 
+   * TODO: This seems like it should be a Set of CUPs rather than a set of CUP
+   * locations.
+   */
+  private final Set generatedCupLocations = new HashSet();
+
   private final Mapper identityMapper = new Mapper();
 
   private final Set invalidatedTypes = new HashSet();
@@ -571,8 +580,6 @@
 
   private final Map unitsByCup = new HashMap();
 
-  private final Set volatileFiles = new HashSet();
-
   /**
    * Creates a new <code>CacheManager</code>, creating a new
    * <code>TypeOracle</code>. This constructor does not specify a cache
@@ -620,6 +627,17 @@
   }
 
   /**
+   * Adds the specified {@link CompilationUnitProvider} to the set of CUPs
+   * generated by {@link com.google.gwt.core.ext.Generator Generator}s. Generated
+   * <code>CompilationUnitProviders</code> are not cached across reloads.
+   */
+  public void addGeneratedCup(CompilationUnitProvider generatedCup) {
+    assert (generatedCup != null);
+
+    generatedCupLocations.add(generatedCup.getLocation());
+  }
+
+  /**
    * This method returns the <code>TypeOracle</code> associated with this
    * <code>CacheManager</code>.
    */
@@ -635,27 +653,13 @@
   public void invalidateVolatileFiles() {
     for (Iterator iter = addedCups.iterator(); iter.hasNext();) {
       CompilationUnitProvider cup = (CompilationUnitProvider) iter.next();
-      if (isVolatileFile(cup.getLocation())) {
+      if (isGeneratedCup(cup)) {
         iter.remove();
       }
     }
   }
 
   /**
-   * This method marks the supplied compilation units as volatile, ensuring that
-   * they are not cached across a reload. This is used to ensure
-   * generator-created code is not improperly preserved.
-   * 
-   * @param committedGeneratedCups the set of compilation units to not preserve
-   */
-  public void markVolatileFiles(Set committedGeneratedCups) {
-    for (Iterator iter = committedGeneratedCups.iterator(); iter.hasNext();) {
-      CompilationUnitProvider cup = (CompilationUnitProvider) iter.next();
-      volatileFiles.add(cup.getLocation());
-    }
-  }
-
-  /**
    * This method adds byte.
    * 
    * @param logger
@@ -726,10 +730,6 @@
     }
   }
 
-  void addVolatileFiles(Set files) {
-    files.addAll(volatileFiles);
-  }
-
   ICompilationUnit findUnitForCup(CompilationUnitProvider cup) {
     if (!unitsByCup.containsKey(cup.getLocation())) {
       unitsByCup.put(cup.getLocation(), new ICompilationUnitAdapter(cup));
@@ -814,11 +814,11 @@
   void invalidateOnRefresh(TypeOracle typeOracle) {
     // If a class is changed, the set of classes in the transitive closure
     // of "refers to" must be marked changed as well.
-    // The inital change set is computed in addCompilationUnit.
+    // The initial change set is computed in addCompilationUnit.
     // For the first time we do not do this because the compiler
     // has no cached info.
     if (!isTypeOracleBuilderFirstTime()) {
-      addVolatileFiles(changedFiles);
+      changedFiles.addAll(generatedCupLocations);
       addDependentsToChangedFiles();
 
       for (Iterator iter = changedFiles.iterator(); iter.hasNext();) {
@@ -986,15 +986,11 @@
     return firstTime;
   }
 
-  private boolean isTypeOracleBuilderFirstTime() {
-    return typeOracleBuilderFirstTime;
+  private boolean isGeneratedCup(CompilationUnitProvider cup) {
+    return generatedCupLocations.contains(cup.getLocation());
   }
 
-  private boolean isVolatileFile(String location) {
-    if (volatileFiles.contains(location)) {
-      return true;
-    } else {
-      return false;
-    }
+  private boolean isTypeOracleBuilderFirstTime() {
+    return typeOracleBuilderFirstTime;
   }
 }
diff --git a/dev/core/src/com/google/gwt/dev/shell/StandardGeneratorContext.java b/dev/core/src/com/google/gwt/dev/shell/StandardGeneratorContext.java
index 9a22a36..b11ea07 100644
--- a/dev/core/src/com/google/gwt/dev/shell/StandardGeneratorContext.java
+++ b/dev/core/src/com/google/gwt/dev/shell/StandardGeneratorContext.java
@@ -96,6 +96,11 @@
     }
   }
 
+  /**
+   * {@link CompilationUnitProvider} used to represent generated source code 
+   * which is stored on disk.  This class is only used if the -gen flag is
+   * specified.
+   */
   private static final class GeneratedCUP extends URLCompilationUnitProvider {
     private GeneratedCUP(URL url, String name) {
       super(url, name);
@@ -106,6 +111,10 @@
       //
       return 0L;
     }
+    
+    public boolean isTransient() {
+      return true;
+    }
   }
 
   /**
@@ -274,12 +283,13 @@
           genTypeNames.add(genTypeName);
           CompilationUnitProvider cup = writeSource(logger, gcup, typeName);
           builder.addCompilationUnit(cup);
-
+          cacheManager.addGeneratedCup(cup);
+          
           if (subBranch != null) {
             subBranch.log(TreeLogger.DEBUG, cup.getLocation(), null);
           }
         }
-        cacheManager.markVolatileFiles(committedGeneratedCups);
+        
         builder.build(branch);
       }
 
@@ -486,4 +496,4 @@
             + srcFile.getAbsolutePath() + "'", caught);
     throw new UnableToCompleteException();
   }
-}
+}
\ No newline at end of file