Bug 2514 - Allow the user to package applications even if there are errors
authorEugene Ostroukhov <eugeneo@symbian.org>
Thu, 15 Apr 2010 16:00:54 -0700
changeset 308 c521df56b15d
parent 305 be8783adb3a8
child 309 c01f5ab28a11
Bug 2514 - Allow the user to package applications even if there are errors
org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/PreviewerUtil.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/WRTStatusListener.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/PreferenceConstants.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/PreferenceInitializer.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WrtPackageActionDelegate.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/status/IWRTStatusListener.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/deploy/DeployWizard.java
--- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/PreviewerUtil.java	Wed Apr 14 14:54:13 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/PreviewerUtil.java	Thu Apr 15 16:00:54 2010 -0700
@@ -74,7 +74,7 @@
     }
 
     public static boolean isRelevantResource(IResource resource) {
-        if (resource.getType() == IResource.FILE) {
+        if (resource.exists() && resource.getType() == IResource.FILE) {
             return !resource.getFullPath().segment(1).equalsIgnoreCase("preview")
                     && !"wgz".equalsIgnoreCase(resource.getFileExtension())
                     && !(PreviewerPlugin.PLUGIN_ID + ".xml").equals(resource.getName());
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/WRTStatusListener.java	Wed Apr 14 14:54:13 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/WRTStatusListener.java	Thu Apr 15 16:00:54 2010 -0700
@@ -21,16 +21,17 @@
 
 import java.io.IOException;
 
+import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.ui.console.MessageConsoleStream;
-
 import org.symbian.tools.wrttools.core.status.IWRTStatusListener;
 import org.symbian.tools.wrttools.core.status.WRTStatus;
+import org.symbian.tools.wrttools.util.ProjectUtils;
 
 public class WRTStatusListener implements IWRTStatusListener {
 	
-	private MessageConsoleStream consoleStream;
-	private boolean activateOnFirstStatus = true;
+	private final MessageConsoleStream consoleStream;
+	private final boolean activateOnFirstStatus = true;
 	private int statusCount;
 
 	public WRTStatusListener() {
@@ -61,4 +62,8 @@
 		return true;
 	}
 
+    public boolean canPackageWithErrors(IProject project) {
+        return ProjectUtils.canPackageWithErrors(project);
+    }
+
 }
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/PreferenceConstants.java	Wed Apr 14 14:54:13 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/PreferenceConstants.java	Thu Apr 15 16:00:54 2010 -0700
@@ -43,4 +43,6 @@
 	public static final String SELECTED_EMULATOR_NAME = "selectedEmulatorDeviceName";
 	
 	public static final String DEBUG_ENABLED = "debugEnabled";
+
+    public static final String PACKAGE_WITH_ERRORS = "packageWithErrors";
 }
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/PreferenceInitializer.java	Wed Apr 14 14:54:13 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/deploy/PreferenceInitializer.java	Thu Apr 15 16:00:54 2010 -0700
@@ -20,8 +20,8 @@
 package org.symbian.tools.wrttools.core.deploy;
 
 import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
 import org.eclipse.jface.preference.IPreferenceStore;
-
 import org.symbian.tools.wrttools.Activator;
 
 /**
@@ -36,10 +36,8 @@
 	 */
 	public void initializeDefaultPreferences() {
 		IPreferenceStore store = Activator.getDefault().getPreferenceStore();		
-		store.setDefault(PreferenceConstants.WRT_DEPLOY_CHOICE, PreferenceConstants.WRT_DEPLOY_CHOICE_DEVICE);
-		store.setDefault(PreferenceConstants.WRT_DEPLOY_CHOICE, PreferenceConstants.WRT_DEPLOY_CHOICE_EMULATOR);
-//		store.setDefault(PreferenceConstants.WRT_EMULATOR_PATH, "none");	
-		
+
+        store.setDefault(PreferenceConstants.PACKAGE_WITH_ERRORS, MessageDialogWithToggle.PROMPT);
 	}
 
 }
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WrtPackageActionDelegate.java	Wed Apr 14 14:54:13 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WrtPackageActionDelegate.java	Thu Apr 15 16:00:54 2010 -0700
@@ -86,7 +86,7 @@
 						break;
 					}
 				}
-				if(hasErrors) {
+                if (hasErrors && !statusListener.canPackageWithErrors(project)) {
 					reportStatus("For the project "+ project.getLocation());
 					reportStatus(WRTPackagerConstants.STA_PKG_FAILED);
 					reportStatus("See errors from the Problems View for more details...");
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/status/IWRTStatusListener.java	Wed Apr 14 14:54:13 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/status/IWRTStatusListener.java	Thu Apr 15 16:00:54 2010 -0700
@@ -19,6 +19,8 @@
 
 package org.symbian.tools.wrttools.core.status;
 
+import org.eclipse.core.resources.IProject;
+
 public interface IWRTStatusListener {
 	/**
 	 * Tell if the status should be emitted by this listener,
@@ -36,4 +38,6 @@
     public void emitStatus(WRTStatus status);
 
     public void close();
+
+    public boolean canPackageWithErrors(IProject project);
 }
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java	Wed Apr 14 14:54:13 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java	Thu Apr 15 16:00:54 2010 -0700
@@ -57,10 +57,13 @@
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IViewReference;
 import org.eclipse.ui.IWorkbenchPage;
@@ -79,6 +82,7 @@
 import org.eclipse.wst.validation.ValidationFramework;
 import org.symbian.tools.wrttools.Activator;
 import org.symbian.tools.wrttools.WidgetProjectNature;
+import org.symbian.tools.wrttools.core.deploy.PreferenceConstants;
 import org.symbian.tools.wrttools.core.packager.WRTPackagerConstants;
 import org.symbian.tools.wrttools.wizards.WrtLibraryWizardPage;
 
@@ -423,6 +427,9 @@
     }
 
     public static boolean isExcluded(IResource resource) {
+        if (!resource.exists()) {
+            return false;
+        }
         try {
             IMarker[] markers = resource
                     .findMarkers(EXCLUDE_MARKER_ID, false, IResource.DEPTH_ZERO);
@@ -456,4 +463,32 @@
         }
     }
 
+    public static boolean canPackageWithErrors(final IProject project) {
+        final boolean[] flag = new boolean[1];
+        String value = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.PACKAGE_WITH_ERRORS);
+        if (MessageDialogWithToggle.ALWAYS.equals(value)) {
+            flag[0] = true;
+        } else if (MessageDialogWithToggle.NEVER.equals(value)) {
+            flag[0] = false;
+        } else if (MessageDialogWithToggle.PROMPT.equals(value)) {
+            Display.getDefault().syncExec(new Runnable() {
+                public void run() {
+                    flag[0] = queryUser(project);
+                }
+            });
+        }
+        return flag[0];
+    }
+
+    protected static boolean queryUser(IProject project) {
+        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+        MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(shell, "WRT Application Packages",
+                String
+                        .format("Project %s has errors. Are you sure you want to package the project?", project
+                                .getName()), "Remember my selection", false, Activator.getDefault()
+                        .getPreferenceStore(),
+                PreferenceConstants.PACKAGE_WITH_ERRORS);
+        return dialog.getReturnCode() == IDialogConstants.YES_ID;
+    }
+
 }
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/deploy/DeployWizard.java	Wed Apr 14 14:54:13 2010 -0700
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/deploy/DeployWizard.java	Thu Apr 15 16:00:54 2010 -0700
@@ -39,6 +39,7 @@
 import org.symbian.tools.wrttools.core.status.IWRTStatusListener;
 import org.symbian.tools.wrttools.core.status.WRTStatus;
 import org.symbian.tools.wrttools.sdt.utils.Logging;
+import org.symbian.tools.wrttools.util.ProjectUtils;
 
 public class DeployWizard extends Wizard {
     public class PagePrinter implements IWRTStatusListener {
@@ -60,6 +61,10 @@
             // Do nothing
         }
 
+        public boolean canPackageWithErrors(IProject project) {
+            return ProjectUtils.canPackageWithErrors(project);
+        }
+
     }
 
     private final DeployWizardContext context;