Revision: 8210
Author: sp...@google.com
Date: Tue May 25 10:26:11 2010
Log: When SoycReportLinker looks for report files, it now tolerates
missing "soycReport" from the beginning of the emitted
artifact paths.

Review at http://gwt-code-reviews.appspot.com/545801

Review by: kpro...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=8210

Added:
/branches/2.1/dev/core/test/com/google/gwt/core/linker/SoycReportLinkerTest.java
Modified:
 /branches/2.1/dev/core/src/com/google/gwt/core/linker/SoycReportLinker.java

=======================================
--- /dev/null
+++ /branches/2.1/dev/core/test/com/google/gwt/core/linker/SoycReportLinkerTest.java Tue May 25 10:26:11 2010
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2010 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
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.core.linker;
+
+import com.google.gwt.core.ext.TreeLogger;
+import com.google.gwt.core.ext.linker.ArtifactSet;
+import com.google.gwt.core.ext.linker.EmittedArtifact;
+
+import junit.framework.TestCase;
+
+import java.io.InputStream;
+
+/**
+ * Tests {...@link SoycReportLinker}.
+ */
+public class SoycReportLinkerTest extends TestCase {
+  private static class NullInputStream extends InputStream {
+    @Override
+    public int read() {
+      return -1;
+    }
+  }
+
+  /**
+   * Create a mock emitted artifact with the given path.
+   */
+  private static EmittedArtifact emitted(String path) {
+    return new EmittedArtifact(SoycReportLinker.class, path) {
+      @Override
+      public InputStream getContents(TreeLogger logger) {
+        return new NullInputStream();
+      }
+    };
+  }
+
+  public void testAnyReportFilesPresent() {
+    SoycReportLinker soyc = new SoycReportLinker();
+
+    // empty artifact set
+    {
+      ArtifactSet artifacts = new ArtifactSet();
+      assertFalse(soyc.anyReportFilesPresent(artifacts));
+    }
+
+    // report files are in /soycReport/compile-report
+    {
+      ArtifactSet artifacts = new ArtifactSet();
+ artifacts.add(emitted("soycReport/compile-report/SoycDashboard-0-index.html"));
+      assertTrue(soyc.anyReportFilesPresent(artifacts));
+    }
+
+    // report files are in /compile-report
+    {
+      ArtifactSet artifacts = new ArtifactSet();
+      artifacts.add(emitted("compile-report/SoycDashboard-0-index.html"));
+      assertTrue(soyc.anyReportFilesPresent(artifacts));
+    }
+
+    // no report files, but other files are present
+    {
+      ArtifactSet artifacts = new ArtifactSet();
+      artifacts.add(emitted("blahblah"));
+      artifacts.add(emitted("blue/blue/blue"));
+      assertFalse(soyc.anyReportFilesPresent(artifacts));
+    }
+  }
+}
=======================================
--- /branches/2.1/dev/core/src/com/google/gwt/core/linker/SoycReportLinker.java Fri Mar 19 08:12:41 2010 +++ /branches/2.1/dev/core/src/com/google/gwt/core/linker/SoycReportLinker.java Tue May 25 10:26:11 2010
@@ -121,14 +121,22 @@
     }
   }

-  private boolean anyReportFilesPresent(ArtifactSet artifacts) {
-    String prefix = "soycReport/"
-        + ArtifactsOutputDirectory.COMPILE_REPORT_DIRECTORY + "/";
+  /**
+   * Check whether an artifact set contains any SOYC report documents.
+   */
+  boolean anyReportFilesPresent(ArtifactSet artifacts) {
+ String prefix1 = ArtifactsOutputDirectory.COMPILE_REPORT_DIRECTORY + "/";
+    String prefix2 = "soycReport/" + prefix1;
+
     for (EmittedArtifact art : artifacts.find(EmittedArtifact.class)) {
-      if (art.getPartialPath().startsWith(prefix)) {
+      if (art.getPartialPath().startsWith(prefix1)) {
         return true;
       }
-    }
+      if (art.getPartialPath().startsWith(prefix2)) {
+        return true;
+      }
+    }
+
     return false;
   }

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to