am dc0b6e0d: Merge "Add the ability to specify packages or classes to ignore for ApiCheck." into lmp-mr1-app-dev

* commit 'dc0b6e0df8c93f408d44823dc4151e8ec8359407':
  Add the ability to specify packages or classes to ignore for ApiCheck.
diff --git a/MODULE_LICENSE_APACHE2 b/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_APACHE2
diff --git a/src/com/google/doclava/DocFile.java b/src/com/google/doclava/DocFile.java
index 24bcbb6..a71b884 100644
--- a/src/com/google/doclava/DocFile.java
+++ b/src/com/google/doclava/DocFile.java
@@ -246,6 +246,7 @@
         hdf.setValue("wear", "true");
       } else if (filename.indexOf("preview") == 0) {
         hdf.setValue("preview", "true");
+        hdf.setValue("page.type", "preview");
       } else if (filename.indexOf("auto") == 0) {
         hdf.setValue("auto", "true");
       } else if (filename.indexOf("tv") == 0) {
diff --git a/src/com/google/doclava/Stubs.java b/src/com/google/doclava/Stubs.java
index bc5e586..647c921 100644
--- a/src/com/google/doclava/Stubs.java
+++ b/src/com/google/doclava/Stubs.java
@@ -27,8 +27,10 @@
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
+import java.util.regex.Pattern;
 
 public class Stubs {
   public static void writeStubsAndApi(String stubsDir, String apiFile, String keepListFile,
@@ -161,9 +163,10 @@
 
     // packages contains all the notStrippable classes mapped by their containing packages
     HashMap<PackageInfo, List<ClassInfo>> packages = new HashMap<PackageInfo, List<ClassInfo>>();
+    final HashSet<Pattern> stubPackageWildcards = extractWildcards(stubPackages);
     for (ClassInfo cl : notStrippable) {
       if (!cl.isDocOnly()) {
-        if (stubPackages == null || stubPackages.contains(cl.containingPackage().name())) {
+        if (shouldWriteStub(cl.containingPackage().name(), stubPackages, stubPackageWildcards)) {
           // write out the stubs
           if (stubsDir != null) {
             writeClassFile(stubsDir, notStrippable, cl);
@@ -211,6 +214,46 @@
     }
   }
 
+  private static boolean shouldWriteStub(final String packageName,
+          final HashSet<String> stubPackages, final HashSet<Pattern> stubPackageWildcards) {
+    if (stubPackages == null) {
+      // There aren't any stub packages set, write all stubs
+      return true;
+    }
+    if (stubPackages.contains(packageName)) {
+      // Stub packages contains package, return true
+      return true;
+    }
+    if (stubPackageWildcards != null) {
+      // Else, we will iterate through the wildcards to see if there's a match
+      for (Pattern wildcard : stubPackageWildcards) {
+        if (wildcard.matcher(packageName).matches()) {
+          return true;
+        }
+      }
+    }
+    return false;
+  }
+
+  private static HashSet<Pattern> extractWildcards(HashSet<String> stubPackages) {
+    HashSet<Pattern> wildcards = null;
+    if (stubPackages != null) {
+      for (Iterator<String> i = stubPackages.iterator(); i.hasNext();) {
+        final String pkg = i.next();
+        if (pkg.indexOf('*') != -1) {
+          if (wildcards == null) {
+            wildcards = new HashSet<Pattern>();
+          }
+          // Add the compiled wildcard, replacing * with the regex equivalent
+          wildcards.add(Pattern.compile(pkg.replace("*", ".*?")));
+          // And remove the raw wildcard from the packages
+          i.remove();
+        }
+      }
+    }
+    return wildcards;
+  }
+
   private static ClassInfo findHiddenClasses(TypeInfo ti) {
     ClassInfo ci = ti.asClassInfo();
     if (ci == null) return null;