Bug 2480 - Excluded resources are still available in preview and debugger
authorEugene Ostroukhov <eugeneo@symbian.org>
Fri, 04 Jun 2010 09:44:40 -0700
changeset 345 7723a46fe224
parent 344 0f103d99721b
child 346 98b70930d8f9
Bug 2480 - Excluded resources are still available in preview and debugger
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/PreviewerPlugin.java
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/ProjectIndexResourceProvider.java
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/WorkspaceResourceProvider.java
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/PreviewerPlugin.java	Tue Jun 01 14:53:02 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/PreviewerPlugin.java	Fri Jun 04 09:44:40 2010 -0700
@@ -18,6 +18,8 @@
  */
 package org.symbian.tools.wrttools.previewer;
 
+import java.io.IOException;
+
 import org.eclipse.core.net.proxy.IProxyService;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Platform;
@@ -137,4 +139,11 @@
         }
         return console;
     }
+
+    public static void print(String message) throws IOException {
+        MessageConsole console = getDefault().getConsole();
+        console.activate();
+        console.newMessageStream().write(
+                message);
+    }
 }
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/ProjectIndexResourceProvider.java	Tue Jun 01 14:53:02 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/ProjectIndexResourceProvider.java	Fri Jun 04 09:44:40 2010 -0700
@@ -25,12 +25,15 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.json.simple.JSONObject;
+import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
 import org.symbian.tools.wrttools.util.CoreUtil;
+import org.symbian.tools.wrttools.util.ProjectUtils;
 
 public class ProjectIndexResourceProvider implements IResourceProvider {
     public static final String INDEX = "wrt_preview_main.html";
@@ -43,8 +46,7 @@
     }
 
     public InputStream getResourceStream(IProject project, IPath resource, Map<String, String[]> parameters,
-            String sessionId)
-            throws IOException, CoreException {
+            String sessionId) throws IOException, CoreException {
         return getProjectIndexPage(project.getName());
     }
 
@@ -53,22 +55,26 @@
         if (project.isAccessible()) {
             String indexFileName = CoreUtil.getIndexFile(project);
             if (indexFileName != null) {
-                String string = CoreUtil.readFile(project, CoreUtil.getFile(project, indexFileName));
-                if (string != null) {
-                    Matcher matcher = HEAD_TAG_PATTERN.matcher(string);
-                    if (matcher.find()) {
-                        string = matcher.replaceFirst(matcher.group() + SCRIPT);
+                final IFile file = CoreUtil.getFile(project, indexFileName);
+                if (!ProjectUtils.isExcluded(file)) {
+                    String string = CoreUtil.readFile(project, file);
+                    if (string != null) {
+                        Matcher matcher = HEAD_TAG_PATTERN.matcher(string);
+                        if (matcher.find()) {
+                            string = matcher.replaceFirst(matcher.group() + SCRIPT);
+                        }
+                        return new ByteArrayInputStream(string.getBytes("UTF-8"));
                     }
-                    return new ByteArrayInputStream(string.getBytes("UTF-8"));
                 }
             }
+            PreviewerPlugin.print(String.format("Can not find main page (%s) in project %s.\n", indexFileName,
+                    project.getName()));
         }
         return null;
     }
 
     public void post(IProject project, IPath resource, Map<String, String[]> parameterMap, JSONObject object,
-            String sessionId)
-            throws IOException, CoreException {
+            String sessionId) throws IOException, CoreException {
         // Do nothing
     }
 
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/WorkspaceResourceProvider.java	Tue Jun 01 14:53:02 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/handlers/WorkspaceResourceProvider.java	Fri Jun 04 09:44:40 2010 -0700
@@ -26,7 +26,6 @@
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
-import org.eclipse.ui.console.MessageConsole;
 import org.json.simple.JSONObject;
 import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
 import org.symbian.tools.wrttools.util.ProjectUtils;
@@ -43,11 +42,8 @@
         if (file.isAccessible() && !ProjectUtils.isExcluded(file)) {
             return file.getContents();
         } else {
-            MessageConsole console = PreviewerPlugin.getDefault().getConsole();
-            console.activate();
-            console.newMessageStream().write(
-                    String.format("%s was not found in the workspace. It was requested by the previewer.\n", file
-                            .getFullPath().toString()));
+            PreviewerPlugin.print(String.format("%s was not found in the workspace. It was requested by the previewer.\n", file
+                    .getFullPath().toString()));
             return null;
         }
     }