# HG changeset patch # User tasneems@symbian.org # Date 1265066861 28800 # Node ID 1f72e81a1aa7515a3d2a5d6d2fc929267f6e5a9a # Parent c56c874eef475411c66ec6c6d23bcd6fd0a68ca4 Added WRT packaging diff -r c56c874eef47 -r 1f72e81a1aa7 org.bluecove.Ver2.1.1/.classpath --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.bluecove.Ver2.1.1/.classpath Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,8 @@ + + + + + + + + diff -r c56c874eef47 -r 1f72e81a1aa7 org.bluecove.Ver2.1.1/.project --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.bluecove.Ver2.1.1/.project Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,28 @@ + + + org.bluecove.Ver2.1.1 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff -r c56c874eef47 -r 1f72e81a1aa7 org.bluecove.Ver2.1.1/.settings/org.eclipse.jdt.core.prefs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.bluecove.Ver2.1.1/.settings/org.eclipse.jdt.core.prefs Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,8 @@ +#Wed Jan 27 23:37:09 PST 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff -r c56c874eef47 -r 1f72e81a1aa7 org.bluecove.Ver2.1.1/META-INF/MANIFEST.MF --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.bluecove.Ver2.1.1/META-INF/MANIFEST.MF Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: BlueCove +Bundle-SymbolicName: org.bluecove.v2_1_1 +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.bluecove.ver2_1_1.Activator +Require-Bundle: org.eclipse.core.runtime +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Import-Package: com.intel.bluetooth, + javax.bluetooth, + javax.microedition.io, + javax.obex +Export-Package: com.intel.bluetooth, + javax.bluetooth, + javax.microedition.io, + javax.obex diff -r c56c874eef47 -r 1f72e81a1aa7 org.bluecove.Ver2.1.1/build.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.bluecove.Ver2.1.1/build.properties Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff -r c56c874eef47 -r 1f72e81a1aa7 org.bluecove.Ver2.1.1/src/org/bluecove/ver2_1_1/Activator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.bluecove.Ver2.1.1/src/org/bluecove/ver2_1_1/Activator.java Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,50 @@ +package org.bluecove.ver2_1_1; + +import org.eclipse.core.runtime.Plugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends Plugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.bluecove.v2_1_1"; + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/icons/Thumbs.db Binary file org.symbian.tools.wrttools/icons/Thumbs.db has changed diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/icons/exclude_archive.gif Binary file org.symbian.tools.wrttools/icons/exclude_archive.gif has changed diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/icons/include_archive.gif Binary file org.symbian.tools.wrttools/icons/include_archive.gif has changed diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/icons/package_widget.gif Binary file org.symbian.tools.wrttools/icons/package_widget.gif has changed diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/plugin.xml --- a/org.symbian.tools.wrttools/plugin.xml Mon Feb 01 13:47:20 2010 -0800 +++ b/org.symbian.tools.wrttools/plugin.xml Mon Feb 01 15:27:41 2010 -0800 @@ -59,7 +59,7 @@ - + + - + + + + + + menubarPath="org.symbian.tools.wrttools.contextMenuGroupMarker"> - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -194,13 +256,6 @@ icon="icons/main16.gif" id="org.symbian.tools.wrttools.import.aptanaImport" name="Aptana IDE WRT Project"> - - @@ -488,29 +543,9 @@ - - - - - - - - - - - - - - - - + + diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/ConsoleFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/ConsoleFactory.java Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ +package org.symbian.tools.wrttools; + +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleFactory; +import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.console.MessageConsoleStream; + +public class ConsoleFactory implements IConsoleFactory { + + private static MessageConsole console; + + public void openConsole() { + getConsole(); + console.activate(); + } + + public static MessageConsoleStream createStream() { + getConsole(); + return console.newMessageStream(); + } + + public static void activateConsole() { + getConsole(); + console.activate(); + } + + private synchronized static MessageConsole getConsole() { + if (console == null) { + console = new MessageConsole("Web Runtime Console", null, true); + IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager(); + consoleManager.addConsoles(new IConsole[]{console}); + } + return console; + } + +} diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/WRTStatusListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/WRTStatusListener.java Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ + +package org.symbian.tools.wrttools; + +import java.io.IOException; + +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; + +public class WRTStatusListener implements IWRTStatusListener { + + private MessageConsoleStream consoleStream; + private boolean activateOnFirstStatus = true; + private int statusCount; + + public WRTStatusListener() { + consoleStream = ConsoleFactory.createStream(); + } + + public void close() { + try { + consoleStream.close(); + } catch (IOException x) { + Activator.log(IStatus.ERROR, "Error closing console stream", x); + } + } + + public void emitStatus(WRTStatus status) { + Object description = status.getStatusDescription(); + if (description != null) { + ++statusCount; + if (activateOnFirstStatus && statusCount == 1) { + ConsoleFactory.activateConsole(); + } + + consoleStream.println(description.toString()); + } + } + + public boolean isStatusHandled(WRTStatus status) { + return true; + } + +} diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/exception/WRTException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/exception/WRTException.java Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,61 @@ +/** + * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ + +package org.symbian.tools.wrttools.core.exception; + +/** + * The main class for the widget exception. + * Specific modules need to inherit the class and customize their corresponding + * exceptions. + * @author avraina + * + */ +public class WRTException extends Exception { + + private static final long serialVersionUID = -1450794313853330624L; + + /** + * Default constructor. + */ + public WRTException() { + super(); + } + + /** + * @param message + * @param cause + */ + public WRTException(String message, Throwable cause) { + super(message, cause); + } + + /** + * @param message + */ + public WRTException(String message) { + super(message); + } + + /** + * @param cause + */ + public WRTException(Throwable cause) { + super(cause); + } +} \ No newline at end of file diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/ExcludeFileAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/ExcludeFileAction.java Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,118 @@ +/** + * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ + +package org.symbian.tools.wrttools.core.packager; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceVisitor; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IObjectActionDelegate; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; + +import org.symbian.tools.wrttools.Activator; + +public class ExcludeFileAction implements IObjectActionDelegate { + + private List selectedFiles = new ArrayList(); + private List selectedFolders = new ArrayList(); + public ExcludeFileAction() { + super(); + } + + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + } + + public void run(IAction action) { + for (IFile file : selectedFiles) { + try { + file.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString()); + } catch (CoreException x) { + Activator.log(IStatus.ERROR, "error setting exclude property on file: "+file.getName(), x); + } + } + + for(IFolder folder : selectedFolders){ + try{ + folder.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString()); + excludeFolder( folder); + } + catch (CoreException x) { + Activator.log(IStatus.ERROR, "error setting exclude property on folder: "+folder.getName(), x); + } + } + /*Refresh project tree when property is changed */ + PlatformUI.getWorkbench().getDecoratorManager().update("com.nokia.wrt.decorator"); + } + + public void selectionChanged(IAction action, ISelection selection) { + selectedFiles.clear(); + selectedFolders.clear(); + if (selection instanceof IStructuredSelection) { + IStructuredSelection ss = (IStructuredSelection) selection; + for (Iterator iter = ss.iterator(); iter.hasNext();) { + Object obj = iter.next(); + if (obj instanceof IFile) { + + IFile file = (IFile) obj; + selectedFiles.add(file); + + } + + if(obj instanceof IFolder){ + IFolder folder = (IFolder) obj; + selectedFolders.add(folder); + } + } + } + } + + + /** + * + * @param folder + * @throws CoreException + */ + + private void excludeFolder(IFolder folder) throws CoreException{ + folder.accept(new IResourceVisitor() { + public boolean visit(IResource resource)throws CoreException { + if (resource instanceof IFile) { + IFile file = (IFile) resource; + file.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString()); + } + else if (resource instanceof IFolder) { + IFolder folder = (IFolder) resource; + folder.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString()); + } + return true; + } + }); + } +} diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/IWRTPackager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/IWRTPackager.java Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ + +package org.symbian.tools.wrttools.core.packager; + +import java.io.IOException; +import java.util.List; + +import org.symbian.tools.wrttools.core.exception.WRTException; + +/** + * Main Interface for Packaging. + * @author Nutan + * + */ +public interface IWRTPackager { + + /** + * This method is used to check user Input for Packaging (A project folder or .Zip file) + * Returns 0 for file type .zip and 1 for Project folder and 2 for any thing else + * @return int returns project input type format + * @throws WRTException + */ + public int checkInputType() throws PackageException; + + /** + * This method will convert validated folder into .zip file + * Method implementation using java.util.zip package + * This method will rename the file from .zip extension to .wgz + * @throws PackageException + * @throws IOException + */ + public void packageWidget(String sPath, String dPath, List fileList) throws PackageException ; + +} diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/IncludeFileAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/IncludeFileAction.java Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,121 @@ +/** + * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ + +package org.symbian.tools.wrttools.core.packager; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceVisitor; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IActionDelegate; +import org.eclipse.ui.IObjectActionDelegate; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; + +import org.symbian.tools.wrttools.Activator; + +public class IncludeFileAction implements IObjectActionDelegate { + + private List selectedFiles = new ArrayList(); + private List selectedFolders = new ArrayList(); + + + public IncludeFileAction() { + super(); + } + + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + } + + public void run(IAction action) { + for (IFile file : selectedFiles) { + try { + file.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, null); + } catch (CoreException x) { + Activator.log(IStatus.ERROR, "error setting exclude property on file: "+file.getName(), x); + } + } + + for(IFolder folder : selectedFolders){ + try{ + folder.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, null); + includeFolder( folder); + } + catch (CoreException x) { + Activator.log(IStatus.ERROR, "error setting exclude property on folder: "+folder.getName(), x); + } + } + /*Refresh project tree when property is changed */ + PlatformUI.getWorkbench().getDecoratorManager().update("com.nokia.wrt.decorator"); + } + + /** + * @see IActionDelegate#selectionChanged(IAction, ISelection) + */ + public void selectionChanged(IAction action, ISelection selection) { + selectedFiles.clear(); + selectedFolders.clear(); + if (selection instanceof IStructuredSelection) { + IStructuredSelection ss = (IStructuredSelection) selection; + for (Iterator iter = ss.iterator(); iter.hasNext();) { + Object obj = iter.next(); + if (obj instanceof IFile) { + IFile file = (IFile) obj; + selectedFiles.add(file); + } + + if(obj instanceof IFolder){ + IFolder folder = (IFolder) obj; + selectedFolders.add(folder); + } + } + } + } + + /** + * + * @param folder + * @throws CoreException + */ + + private void includeFolder(IFolder folder) throws CoreException{ + folder.accept(new IResourceVisitor() { + public boolean visit(IResource resource) throws CoreException { + if (resource instanceof IFile) { + IFile file = (IFile) resource; + file.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, null); + } + else if (resource instanceof IFolder) { + IFolder folder = (IFolder) resource; + folder.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, null); + } + return true; + } + }); + } +} diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/PackageException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/PackageException.java Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ + +package org.symbian.tools.wrttools.core.packager; + +import org.symbian.tools.wrttools.core.exception.WRTException; + +public class PackageException extends WRTException { + + /** + * Default serial version ID + */ + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public PackageException() { + super(); + } + + /** + * @param message + * @param cause + */ + public PackageException(String message, Throwable cause) { + super(message, cause); + } + + /** + * @param message + */ + public PackageException(String message) { + super(message); + } + + /** + * @param cause + */ + public PackageException(Throwable cause) { + super(cause); + } + +} diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/PackagerFileManipulation.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/PackagerFileManipulation.java Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,132 @@ +/** + * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ + +package org.symbian.tools.wrttools.core.packager; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.symbian.tools.wrttools.core.exception.WRTException; + +public class PackagerFileManipulation { + + private Logger logger = Logger.getLogger(getClass().getName()); + public PackagerFileManipulation() { + } + + /** + * This method copies zip file from source folder to destination folder. + * @param sPath + * @param dPath + * @throws PackagerException + * @throws PackageException + * @throws IOException + * @throws WRTException + * @throws IOException + */ + public void copyFile(String fromFileName, String toFileName) throws PackageException { + File fromFile = new File(fromFileName); + File toFile = new File(toFileName); + FileInputStream from = null; + FileOutputStream to = null; + + if (!fromFile.exists()) + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_SOURCE_NOT_FOUND, + WRTPackagerConstants.ERR_SOURCE_NOT_FOUND); + if (fromFile.isDirectory()) + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_FILE_COPY_FAIL, + WRTPackagerConstants.ERR_FILE_COPY_FAIL); + if (!fromFile.canRead()) + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_UNREADABLE, + WRTPackagerConstants.ERR_UNREADABLE); + + if (toFile.isDirectory()) + toFile = new File(toFile, fromFile.getName()); + + if (toFile.exists()) { + if (!toFile.canWrite()) + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_NOT_WRITABLE, + WRTPackagerConstants.ERR_NOT_WRITABLE); + + } else { + String parent = toFile.getParent(); + if (parent == null) + parent = System.getProperty(PackagerMessages.getString("PackagerFileManipulation.useDir")); //$NON-NLS-1$ + File dir = new File(parent); + if (!dir.exists()) + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_DEST_NOT_FOUND, + WRTPackagerConstants.ERR_DEST_NOT_FOUND); + if (dir.isFile()) + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_FILE_COPY_FAIL, + WRTPackagerConstants.ERR_FILE_COPY_FAIL); + if (!dir.canWrite()) + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_NOT_WRITABLE, + WRTPackagerConstants.ERR_NOT_WRITABLE); + } + + try { + from = new FileInputStream(fromFile); + to = new FileOutputStream(toFile); + byte[] buffer = new byte[4096]; + int bytesRead; + + while ((bytesRead = from.read(buffer)) != -1) + to.write(buffer, 0, bytesRead); // write + } catch (FileNotFoundException e) { + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_READ_WRITE_FAIL, + e.getMessage()); + } catch (IOException e) { + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_READ_WRITE_FAIL, + e.getMessage()); + } + finally { + if (from != null) + try { + from.close(); + } catch (IOException e) { + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_FILE_CLOSE_FAIL, + e.getMessage()); + } + if (to != null) + try { + to.close(); + } catch (IOException e) { + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_FILE_CLOSE_FAIL, + e.getMessage()); + } + } + } + + /** + * This method is used for logging and exception handling + * @param lev -- severity Level + * @param logMessage -- message to log + * @param errException -- exception to throw + * @throws PackagerException + */ + private void logAndThrowErrors(Level lev , String logMessage, String errException) throws PackageException { + logger.log(lev, logMessage); + throw new PackageException(errException); + } +} diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/PackagerMessages.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/PackagerMessages.java Mon Feb 01 13:47:20 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/PackagerMessages.java Mon Feb 01 15:27:41 2010 -0800 @@ -22,7 +22,7 @@ import java.util.ResourceBundle; public class PackagerMessages { - private static final String BUNDLE_NAME = "com.nokia.wrt.core.packager.packageMessages"; //$NON-NLS-1$ + private static final String BUNDLE_NAME = "org.symbian.tools.wrttools.core.packager.packageMessages"; //$NON-NLS-1$ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle .getBundle(BUNDLE_NAME); diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/PackagerZipFolder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/PackagerZipFolder.java Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,351 @@ +/** + * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ + +package org.symbian.tools.wrttools.core.packager; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; + + +import java.io.IOException; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; + + +//import org.apache.commons.io.IOUtils; + +//import com.nokia.wrt.core.report.IMessageListener; +//import com.nokia.wrt.core.report.Message; +import org.symbian.tools.wrttools.core.status.IWRTConstants; +import org.symbian.tools.wrttools.core.status.IWRTStatusListener; +import org.symbian.tools.wrttools.core.status.WRTStatus; +import org.symbian.tools.wrttools.util.Util; + +/** + * A class is used to Zip folders and files in the same way as WinZip does. + * @author ranoliya + * + */ +class PackagerZipFolder { + + //ZIP output stream + private ZipOutputStream pkgZipOutputStream = null; + + //Logger to log info. errors and messages + private Logger logger = Logger.getLogger(getClass().getName()); + + //List of files to be zipped + private List fileList; + + //Status handler for status reporting to GUI + private IWRTStatusListener statusListener; + + //Source path from where files are to be zipped + private String srcPath; + + //Widget file to be zipped + private File wFile; + + //package root folder path + private String rootFolderPath=""; + + /** + * The default buffer size to use. + */ + private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; + + /** + * This method creates a zip file for the given input at the given destination path + * @param srcpath - Input for the zip + * @param destPath - The destination path + * @param listOfFiles - list of files to be included in the zip. for null list it will zip all the files and folders + * @param statushandler - Status handler form GUI + * @throws PackageException - exception during Zipping + */ + public void zipProjectFolder(String srcpath, String destPath, List listOfFiles, IWRTStatusListener statushandler) throws PackageException{ + fileList = listOfFiles; + this.statusListener = statushandler; + this.srcPath=srcpath; + try + { + wFile = new File (srcPath); + //invlid file or directory + if (!wFile.isFile() && !wFile.isDirectory() + || null == destPath || !(destPath.length()>0)) { + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_SOURCE_NOT_FOUND,null); + } + + //create zip outputstream + FileOutputStream outzip=null; + + outzip=new FileOutputStream(destPath); + + pkgZipOutputStream = new ZipOutputStream(outzip); + + zipFilesInFolder( wFile, rootFolderPath); + + + pkgZipOutputStream.finish(); + pkgZipOutputStream.close(); + }catch (IOException e){ + e.printStackTrace(); + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_ZIP_FAILED,e); + } + + } + + public void zipProjectFolder(String srcpath, String destPath, List listOfFiles) throws PackageException{ + fileList = listOfFiles; +// this.statusListener = statushandler; + this.srcPath=srcpath; + try + { + wFile = new File (srcPath); + //invlid file or directory + if (!wFile.isFile() && !wFile.isDirectory() + || null == destPath || !(destPath.length()>0)) { + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_SOURCE_NOT_FOUND,null); + } + + //create zip outputstream + + + pkgZipOutputStream = new ZipOutputStream(new FileOutputStream(destPath)); + zipFilesInFolder( wFile, rootFolderPath); + pkgZipOutputStream.finish(); + pkgZipOutputStream.close(); + }catch (IOException e){ + e.printStackTrace(); + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_ZIP_FAILED,e); + } + + } + + + /** + * This method scans one by one files inside the srcPath and + * add it to the zip folder + * Method is called recursively to add each file of the folder to the Zip entry + * @param pkgFile -- File or folder to add to zip + * @param baseName -- name under which it will add the pkgFile + * @throws PackageException - exception from Zip + */ + private void zipFilesInFolder(File pkgFile, String baseName) throws PackageException { + + if (pkgFile.isDirectory()) { + File [] fList = pkgFile.listFiles() ; + if(fList.length>0){ + //package selected files + if(null != fileList && fileList.size()>0){ + for (int i=0; i< fList.length; i++){ +// System.out.println(i+" fileList name ----------------- :"+fileList.get(i)); + rootFolderPath=""; + retrieveFileName(fList[i]); + //if directory then call function to add all files in it + if(fList[i].isDirectory()) + { + zipFilesInFolder(fList[i], baseName); + } + for(int j=0; j3 && null!= name){ + String tempStr = name.substring(name.length()-4, name.length()); + compare = tempStr; + } + + //Discard .wgz file + if(compare.length()>0 && compare.equalsIgnoreCase(".wgz")){ + logger.log(Level.INFO, ".wgz file discarded for Package: "+name); + reportStatus(MessageFormat.format(PackagerMessages.getString("package.discard.wgz") + ,new Object[] {name})); + } + else{ + FileInputStream fis = null; + try { + fis = new FileInputStream(pkgFile); + + ZipEntry zipEntry = new ZipEntry(baseName); + pkgZipOutputStream.putNextEntry(zipEntry); + + +// System.out.println("Copy >>>-->> "); + try{ + copy(fis, pkgZipOutputStream); + +// IOUtils.copy(fis, pkgZipOutputStream); +// IOUtils.copyLarge(fis, pkgZipOutputStream); + + + } catch (Exception e) { + + e.printStackTrace(); + + } +// System.out.println("Copy <<----<< "); + + pkgZipOutputStream.closeEntry(); + fis.close(); + } catch (IOException e) { + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_ZIP_FAILED,e); + } + finally{ + try { + pkgZipOutputStream.closeEntry(); + fis.close(); + } catch (IOException e) { + logAndThrowErrors(Level.SEVERE, e.getMessage(), e); + } + } + } + } + } + + /** + * retrieve file name from source folder to current path + * @param file + */ + private void retrieveFileName(File file) { + if(null !=file.getParent()){ + rootFolderPath=file.getParentFile().getName().toString().trim().concat("/") //$NON-NLS-1$ + .concat(rootFolderPath); + //if it reaches to package source filder then return +// if(file.getParentFile().getName().toString().trim().equals(wFile.getName())){ + if(file.getParentFile().getAbsolutePath().toString().trim() + .equalsIgnoreCase(wFile.getAbsolutePath())){ + return; + } + else{ + retrieveFileName(file.getParentFile()); + } + } + + } + + + /** + * Reporting status to the GUI + * @param statusMessage - message to be delivered + */ + public void reportStatus(String statusMessage) { + WRTStatus status = new WRTStatus(); + status.setStatusSource(IWRTConstants.StatusSourceType.PACKAGER.name()); + status.setStatusDescription(statusMessage); + statusListener.emitStatus(status); + + + } + /** + * This method is used for logging and exception handling + * @param lev -- severity Level + * @param logMessage -- message to log + * @param e -- exception to throw, if its not an exception then it should be null + * @throws PackagerException + */ + private void logAndThrowErrors(Level lev , String logMessage, Exception e) throws PackageException { + logger.log(lev, logMessage); + reportStatus(WRTPackagerConstants.STA_PKG_FAILED); + //for exceptions log error message and stack trace + if(null!=e){ + Util.logEvent(logger, Level.SEVERE, e); + throw new PackageException(e); + } + } +/** + * + * @param input + * @param output + * @return + * @throws IOException + */ + + public static int copy(InputStream input, OutputStream output) throws IOException { + + long count = copyLarge(input, output); + if (count > Integer.MAX_VALUE) { + return -1; + } + + return (int) count; + } + + /** + * Copy bytes from a large (over 2GB) InputStream to an + * OutputStream. + *

+ * This method buffers the input internally, so there is no need to use a + * BufferedInputStream. + * + * @param input the InputStream to read from + * @param output the OutputStream to write to + * @return the number of bytes copied + * @throws NullPointerException if the input or output is null + * @throws IOException if an I/O error occurs + * + * */ + public static long copyLarge(InputStream input, OutputStream output) + throws IOException { + + byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; + long count = 0; + int n = 0; + while (-1 != (n = input.read(buffer))) { + output.write(buffer, 0, n); + count += n; + } + + return count; + } + + + +} diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WidgetPackager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WidgetPackager.java Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,352 @@ +/** + * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ + +package org.symbian.tools.wrttools.core.packager; + +import java.io.File; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.symbian.tools.wrttools.core.status.IWRTConstants; +import org.symbian.tools.wrttools.core.status.IWRTStatusListener; +import org.symbian.tools.wrttools.core.status.WRTStatus; +import org.symbian.tools.wrttools.core.status.WRTStatusHandler; +import org.symbian.tools.wrttools.util.Util; + +/** + * This is the main class for core component Packager. + * This class reads from the given source file and creates widget package at + * the given destination path + * @author ranoliya + * + */ +public class WidgetPackager implements IWRTPackager { + + // source path for packager + private String srcPath = ""; + + //destination path for packager + private String destPath = ""; + + //name of the package + private String packageName = ""; + + //list of files to package + private List listOfFiles ; + + //status handler for creating status listener + private WRTStatusHandler statusHandler; + + private IWRTStatusListener statusListener; + + //Logger to log errors and info + private Logger logger = Logger.getLogger(getClass().getName()); + + private String errorMessage = ""; + + /** + * Class Constructor the packaging process + */ + public WidgetPackager(IWRTStatusListener wrtStatusListener) { + statusHandler = new WRTStatusHandler(); + statusHandler.addListener(wrtStatusListener); + statusListener = wrtStatusListener; + } + + /** + * Method packages the input folder, Initial step for Packaging + * @param sPath -- Project Source path + * @param dPath -- Package destination path + * @param fileList -- List of files to be included in the package + * @throws PackageException + */ + public void packageWidget(String sPath, String dPath,List fileList) throws PackageException + { + if(null != sPath || null != dPath){ + + listOfFiles = new ArrayList(); + this.listOfFiles = fileList; + + sPath = Util.replaceChar(sPath, File.separatorChar, '/'); + this.srcPath = sPath; + reportStatus(WRTPackagerConstants.STA_PKG_START); + if(!validateFilesToPackage()){ + + reportStatus(WRTPackagerConstants.STA_PKG_FAILED); + errorMessage = PackagerMessages.getString("package.missing.mandatory.files"); + throw new PackageException(PackagerMessages.getString("package.missing.mandatory.files")); + + } + // if destination path is not specified + if(dPath.equals("")){ //$NON-NLS-1$ + dPath=sPath; + } + this.packageName=new File(dPath).getName(); + File destDir = new File(dPath); + dPath = destDir.getParentFile().getAbsolutePath().concat("/"); + this.destPath = Util.replaceChar(dPath, File.separatorChar, '/'); + + + initPackage(); + } + else + { + reportStatus(WRTPackagerConstants.LOG_NULL_INPUT); + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_NULL_INPUT, null); + } + } + + /** + * This is the packager invocation method that calls packager main API + * @throws PackagerException + */ + private void initPackage() throws PackageException { + File destFile = new File(destPath); + if(!destFile.canWrite() || !destFile.exists()|| (destFile.exists() && destFile.isFile())){ // to avoid considering file as existing dir + boolean success = destFile.mkdir(); + if(!success){ + reportStatus(WRTPackagerConstants.ERR_DIR_CREATE_FAIL); + reportStatus(WRTPackagerConstants.STA_PKG_FAILED); + throw new PackageException(); +// return; + } + } + + + int fileType = checkInputType(); + + String srcStatus = MessageFormat.format(PackagerMessages.getString("WidgetPackager.WidgetPackager.filesFrom") + ,new Object[]{srcPath}); + + + + reportStatus(srcStatus); + + boolean pass = createWidgetPackage(fileType); + if(pass){ + String destStatus = MessageFormat.format(PackagerMessages.getString("WidgetPackager.WidgetPackager.fileDest") + ,new Object[]{destPath.concat(packageName)}); + reportStatus(destStatus); + reportStatus(WRTPackagerConstants.STA_PKG_PASSED); + } + } + + + /** + * This method checks for the user input for Packager and returns File Type + * @return int -- File Type + * @throws PackagerException + */ + public int checkInputType() throws PackageException { + int fileType = 2; + File checkInput ; + + checkInput = new File(srcPath); + if(checkInput.exists()){ + + // user input for packaging is project directory + if (checkInput.isDirectory()) { + fileType = 1; + } + + // user input is unknown to packager - report to status + else { + fileType = 2; + + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_UNSUPPORTED_INPUT,null); + } + } + return fileType; + } + + /** + * This method returns the Destination path for the packaged widget + * @return + */ + public String getDestPath() { + return destPath; + } + + /** + * Reporting status + * @param statusMessage + */ + public void reportStatus(String statusMessage) { + WRTStatus status = new WRTStatus(); + status.setStatusSource(IWRTConstants.StatusSourceType.PACKAGER.name()); + status.setStatusDescription(statusMessage); + statusListener.emitStatus(status); + } + + /** + * This method is used for logging and exception handling + * @param lev -- severity Level + * @param logMessage -- message to log + * @param e -- exception to throw, if its not an exception then it should be null + * @throws PackagerException + */ + private void logAndThrowErrors(Level lev , String logMessage, Exception e) throws PackageException { + logger.log(lev, logMessage); + + //for exceptions log error message and stack trace + if(null!=e){ + reportStatus(WRTPackagerConstants.STA_PKG_FAILED); + Util.logEvent(logger, Level.SEVERE, e); + throw new PackageException(e); + } + } + + /** + * This method creates Widget package-- overridden + * @param - Input file type + */ + private boolean createWidgetPackage(int fileType) throws PackageException { + String widgetPath= ""; + String zipPath = ""; + boolean sucess = false; + boolean packageDone = false; + PackagerZipFolder zipFolder = new PackagerZipFolder(); + + widgetPath = destPath.concat(packageName); //$NON-NLS-1$ + File reWrite = new File(widgetPath); + if(reWrite.exists()) + reWrite.delete(); + //if source path and destination path are same + if(srcPath.equals(destPath)){ + // Project folder as an input + if (fileType==1){ + zipPath = destPath.concat("tmpwid.zip"); //$NON-NLS-1$ + zipFolder.zipProjectFolder(srcPath, zipPath,listOfFiles,statusListener); +// zipFolder.zipProjectFolder(srcPath, zipPath,listOfFiles); + + } + //unsupported file type + else{ + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_UNSUPPORTED_INPUT,null); + } + } + else { + if (fileType==1){ + zipPath = destPath.concat("tmpwid.zip");//$NON-NLS-1$ +// zipFolder.zipProjectFolder(srcPath,zipPath,listOfFiles,statusListener ); + zipFolder.zipProjectFolder(srcPath, zipPath,listOfFiles); + } + else{ + logAndThrowErrors(Level.SEVERE, WRTPackagerConstants.LOG_UNSUPPORTED_INPUT, null); + } + } + + //rename file + //created zip file + File zFile = new File(zipPath); + + + //new package name to use for rename appended wgz. This logic should be removed from package zip folder. + File newFile = new File(widgetPath+".wgz"); + + //delete .wgz if already exists + if(newFile.exists()){ + newFile.delete(); + } + //rename file + if(zFile.exists()){ + sucess = zFile.renameTo(newFile); + } + //overwrite the existing file + if(!sucess) + { + logAndThrowErrors(Level.WARNING, PackagerMessages.getString("WidgetPackager.fileOverwriteMsg"),null); + } + + File tempZip = new File(zipPath); + //delete temp file if exists + if(tempZip.exists()) + { + tempZip.delete(); + } + packageDone = true; + return packageDone; + } + + public String getErrorMessage() { + return errorMessage; + } + + /** + * This method validates basic files (.html and .plist) checked in packaging option tree + * @return -- mandatory files exists or not + */ + private boolean validateFilesToPackage(){ + boolean isPlist = false; + boolean isHtml = false; + File srcDir = new File(srcPath); + String plistFile = srcDir.getName().concat("/info.plist"); + + if(listOfFiles.size()>0 && null != listOfFiles){ + for (String fileName : listOfFiles) { + try{ + if (fileName.equalsIgnoreCase(plistFile)) { + isPlist = true; + } + int len = fileName.lastIndexOf("/"); + String fName=fileName.substring(len+1, fileName.length()); +// files with out extention will have index out of bound exception + int extLen = fName.lastIndexOf('.'); + String extention = ""; + if(extLen > 0){ + extention = fName.substring(extLen, fName.length()); + } + + String htmlFile = srcDir.getName().concat("/").concat(fName); + if(htmlFile.equalsIgnoreCase(fileName) && + (extention.equalsIgnoreCase(".htm")|| extention.equalsIgnoreCase(".html"))){ + isHtml = true; + } + + if(isPlist && isHtml){ + return true; + } + } + // files with out extention will have index out of bound exception +// try catch will catch that and will proceed to the next file in the +// for loop + catch(Exception e){ +// e.printStackTrace(); + } + } + } + String srcStatus = MessageFormat.format(PackagerMessages.getString("WidgetPackager.WidgetPackager.filesFrom") + ,new Object[]{srcPath}); + reportStatus( srcStatus); + if(!isPlist ){ + reportStatus( WRTPackagerConstants.ERR_PKG_MAN_PLIST_FILE_MISSING); + + } + if(!isHtml){ + reportStatus( WRTPackagerConstants.ERR_PKG_MAN_HTML_FILE_MISSING); + + } + + return (isPlist && isHtml); + } + +} diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WrtPackageActionDelegate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/WrtPackageActionDelegate.java Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,203 @@ +/** + * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ + +package org.symbian.tools.wrttools.core.packager; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceVisitor; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IObjectActionDelegate; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.ActionDelegate; + +import org.symbian.tools.wrttools.Activator; +import org.symbian.tools.wrttools.WRTStatusListener; +import org.symbian.tools.wrttools.core.status.IWRTStatusListener; + +import org.symbian.tools.wrttools.core.status.IWRTConstants; +import org.symbian.tools.wrttools.core.status.WRTStatus; +import org.symbian.tools.wrttools.core.validator.ValidateAction; + +public class WrtPackageActionDelegate extends ActionDelegate implements + IObjectActionDelegate { + + + /** + * @see ActionDelegate#run(IAction) + */ + + private final List projectList = new ArrayList(); + + + public void run(IAction action) { + PlatformUI.getWorkbench().saveAllEditors(true); + if (projectList != null && projectList.size() > 0) { + for (IProject project : projectList) { + if (project != null) { + packageProject( project); + } + } + } + } + + public boolean packageProject(IProject project) { + boolean packaedSucess=false; + if (project != null) { + +/* + ValidateAction validator = new ValidateAction(); + if(!validator.isValidProject(project)) { + System.out.println("Invalid widget, can not be packaged!"); + reportStatus("For the project "+ project.getLocation()); + reportStatus(WRTPackagerConstants.STA_PKG_FAILED); + reportStatus("See errors from the Problems View for more details..."); + return packaedSucess; + } +*/ + + try { + final List fileList = new ArrayList(); + //--->> + project.accept(new IResourceVisitor() { + public boolean visit(IResource resource) throws CoreException { + if (resource instanceof IFile) { + IFile file = (IFile) resource; + boolean add = true; + // skip user-excluded and automatically-excluded files + String value = file.getPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY); + if (value != null) { + add = false; + } + String name = file.getName(); + // skip Aptana temporarily generated files + if (name.startsWith(".tmp_")) { + add = false; + } + //Bug fix when import project with different name was unable to package it + if(name.endsWith(".wgz")){ + add = false; + } + if (add) { + if(file.getProject().getLocation().toString().endsWith(file.getProject().getName())){ + fileList.add(file.getLocation().toString().substring(file.getProject().getLocation().toString().length()-file.getProject().getName().length())); + } + else{ + String projectDir=file.getProject().getLocation().toString().substring(file.getProject().getLocation().toString().lastIndexOf("/")+1); + String fullpath=file.getFullPath().toString(); + fullpath=fullpath.substring(fullpath.indexOf(file.getProject().getName())+file.getProject().getName().length()); + fullpath=projectDir+fullpath; + fileList.add(fullpath); + + } + } + } + return true; + } + }); + //<<--<< + + String projectPath = project.getLocation().toString(); + String prjName = project.getName(); + String dprojectPath = projectPath+"/"+prjName; + WRTStatusListener statusListener = new WRTStatusListener(); + WidgetPackager widgetPackager = new WidgetPackager(statusListener); + + try { + IProgressMonitor pm = new NullProgressMonitor(); + // deleting the previous build --->> + IPath wgzPath = new Path(project.getName()+".wgz"); + IFile wgz = project.getFile(wgzPath); + //do not delete the here, delete only if packaging is success + /*if (wgz.exists()) { + wgz.delete(true, false, pm); + }*/ + widgetPackager.packageWidget(projectPath, dprojectPath, fileList); + packaedSucess=true; + project.refreshLocal(IResource.DEPTH_ONE, pm); + wgz = project.getFile(wgzPath); + if (wgz.exists()) { + wgz.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, Boolean.TRUE.toString()); + } + + } catch (PackageException e) { + Activator.log(IStatus.ERROR, "Error packaging widget archive", e); + } finally { + statusListener.close(); + } + } catch (CoreException x) { + Activator.log(IStatus.ERROR, "Error packaging widget archive", x); + } + + } + return packaedSucess; + } + /** + * Reporting status + * @param statusMessage + */ + private void reportStatus(String statusMessage) { + WRTStatus status = new WRTStatus(); + WRTStatusListener statusListener = new WRTStatusListener(); + status.setStatusSource(IWRTConstants.StatusSourceType.PACKAGER.name()); + status.setStatusDescription(statusMessage); + statusListener.emitStatus(status); + } + @SuppressWarnings("unchecked") + @Override + public void selectionChanged(IAction action, ISelection selection) { + if (selection instanceof IStructuredSelection) { + projectList.clear(); + IStructuredSelection ss = (IStructuredSelection) selection; + for (Iterator iter = ss.iterator(); iter.hasNext();) { + + Object obj = iter.next(); + if (obj instanceof IProject) { + projectList.add((IProject) obj); + + } + } + } + } + + /** + * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) + */ + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + + } + + + +} + diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/packageMessages.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/packager/packageMessages.properties Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,42 @@ +WidgetPackager.pathAppend=\\ +WidgetPackager.WidgetPackager.filesFrom=Packaging Files from : "{0}" +WidgetPackager.WidgetPackager.fileDest=Packaged files to destination\: "{0}" +WRTPackagerConstants.success=Packaging Successful\n +WRTPackagerConstants.failed=Packaging Failed\n +WRTPackagerConstants.inProgress=Packaging in Progress... +WRTPackagerConstants.started=Packaging Started... +WRTPackagerConstants.nullpera=Input parameters are NULL +WRTPackagerConstants.nullInput=Selected input is NULL -- Invalid input +WRTPackagerConstants.directoryCreateErr=Can not create output directory +WRTPackagerConstants.checkPermission=Can not create specified directory at the destination. +WRTPackagerConstants.unSupportedInput=Any input other then a folder is not supported +WRTPackagerConstants.InputNotSupported=Input type not supported by WRT Packager +WRTPackagerConstants.renameFailed=Packager failed while renaming a .zip file +WRTPackagerConstants.failureGenerate=Packager failed while generating package files +WRTPackagerConstants.srcNotFound=Source folder not found +WRTPackagerConstants.inputSourceNotFound=Input source not Found +WRTPackagerConstants.srcNotReadable=Package source is not readable +WRTPackagerConstants.unReadable=Unreadable Input, Please check Source and Destination +WRTPackagerConstants.canNotcopy=Can not copy file +WRTPackagerConstants.copyErr=Packager can not copy required files +WRTPackagerConstants.NoDestination=Destination directory does not exists +WRTPackagerConstants.noLocateDest=Packager could not locate destination directory +WRTPackagerConstants.destNotWritable=Destination directory is not writable +WRTPackagerConstants.destNotwritableErr=packager can not write to destination directory, check permissions +WRTPackagerConstants.readWriteFail=File read/write Failed +WRTPackagerConstants.readWritePermission=Packager read/write failed, check for permissions +WRTPackagerConstants.closeFile=Can not close files +WRTPackagerConstants.closeFileerr=Package could not close files +WRTPackagerConstants.ZipFailed=File Zipping failed +WRTPackagerConstants.packFailed=Packager could not perform packaging, File I/O not available for zip utility +WRTPackagerConstants.emptyInputFolder=Input project folder is empty +WRTPackagerConstants.emptyFolderErr=Input project folder is empty, Please give a valid source folder +PackagerFileManipulation.useDir=user.dir + +package.missing.mandatory.files = Please select mandatory files +package.discard.wgz = \nDiscarded already packaged file - "{0}" ... \n + +WRTPackagerConstants.package.missing.mandatory.files.plist = Mandatory Plist file is Misssing +WRTPackagerConstants.package.missing.mandatory.files.html = Mandatory Html file is Missing + + diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/report/messages.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/report/messages.properties Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,12 @@ +HtmlReportHandler.convert.title=Dashboard widget conversion report +HtmlReportHandler.convert.description=Automatic conversions performed by the converter to match Nokia Web Runtime. +HtmlReportHandler.analysis.report.title=Dashboard widget analysis report +HtmlReportHandler.analysis.report.description=This analysis report lists the mandatory or optional conversions needed to port the widget to Nokia Web Runtime. +HtmlReportHandler.file.name=File name +HtmlReportHandler.line.number=Line number +HtmlReportHandler.convert.action.needed=Action needed +HtmlReportHandler.description.column=Description +HtmlReportHandler.severity.info.column=Severity + +HtmlReportHandler.keyword.entry = \ Entry +HtmlReportHandler.add.project = ADD Project diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/status/Messages.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/status/Messages.java Mon Feb 01 13:47:20 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/status/Messages.java Mon Feb 01 15:27:41 2010 -0800 @@ -23,7 +23,7 @@ import java.util.ResourceBundle; public class Messages { - private static final String BUNDLE_NAME = "com.nokia.wrt.core.status.messages"; //$NON-NLS-1$ + private static final String BUNDLE_NAME = "org.symbian.tools.wrttools.core.status.messages"; //$NON-NLS-1$ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle .getBundle(BUNDLE_NAME); diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/status/messages.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/status/messages.properties Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,13 @@ +IWRTConstants.validator=Validator +IWRTConstants.packager=Packager +IWRTConstants.deployer=Deployer +IWRTConstants.converter=Converter + +IWRTConstants.report.error = Error +IWRTConstants.report.warning = Warning +IWRTConstants.report.fatal = Fatal +IWRTConstants.report.information = Information +IWRTConstants.report.success = Success +IWRTConstants.report.mandatory = Mandatory +IWRTConstants.report.optional = Optional + diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/Messages.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/Messages.java Mon Feb 01 13:47:20 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/Messages.java Mon Feb 01 15:27:41 2010 -0800 @@ -23,7 +23,7 @@ import java.util.ResourceBundle; public class Messages { - private static final String BUNDLE_NAME = "com.nokia.wrt.core.validator"; //$NON-NLS-1$ + private static final String BUNDLE_NAME = "org.symbian.tools.wrttools.core.validator"; //$NON-NLS-1$ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle .getBundle(BUNDLE_NAME); diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/ValidatorPropMessages.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/ValidatorPropMessages.java Mon Feb 01 13:47:20 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/ValidatorPropMessages.java Mon Feb 01 15:27:41 2010 -0800 @@ -27,11 +27,11 @@ import org.symbian.tools.wrttools.util.Util; public class ValidatorPropMessages { - private static final String BUNDLE_NAME = "com.nokia.wrt.core.validator.messages"; //$NON-NLS-1$ + private static final String BUNDLE_NAME = "org.symbian.tools.wrttools.core.validator.messages"; //$NON-NLS-1$ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle .getBundle(BUNDLE_NAME); - private static Logger log = Logger.getLogger("com.nokia.wrt.core.validator.ValidatorPropMessages"); + private static Logger log = Logger.getLogger("org.symbian.tools.wrttools.core.validator.ValidatorPropMessages"); private ValidatorPropMessages() { } diff -r c56c874eef47 -r 1f72e81a1aa7 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/messages.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/validator/messages.properties Mon Feb 01 15:27:41 2010 -0800 @@ -0,0 +1,134 @@ +plist.File.Not.Present=Mandatory file info.plist is missing in the widget project. For further processing please include info.plist and try again. +html.File.Not.Present=Main HTML file is missing. For further processing please include the main html file and try again. +WidgetModel.Divergent.Files.Present=Unnecessary files are included. To minimize the widget size please only include the required files. The supported file types are .htm, .html, .png, .gif, .jpg. + +todo.WidgetModel.Divergent.Files.Present=Remove the unsupported file + +todo.include.plist=Please include the info.plist file to the project +todo.include.html=Please include the html file to the project + +plist.html.element.mismatch= HTML element for the key MainHTML in Info.plist differs from the actual HTML file Name . Please correct the plist file for the MainHTML key. + +todo.correct.plist =Correct Plist Entry for MainHTML +plist.html.element.mailHtml.missing =HTML Element MainHTML in Info.plist is not present or the previous tag was not closed properly . Please correct the plist file for the MainHTML key. + +todo.correct.plist.for.html =Correct Plist Entry for MainHTML + +plist.mankey.mising =Mandatory Plist element +not.in.plist.file=not in plist file. Please add plist element values to the info.plist file. +todo.add.mankey.plist.element =Add the mandatory Plist element values to Info.plist. +contains.invalid.character =contains invalid characters +todo.valid.character=Enter valid character to Info.plist. + +plist.key.string.mising =Missing string pair for the key element. Please add the string element for the key. +todo.add.mankey.string =Add the string element of mandatory Info.plist key element + +plist.element.not.closed =A malformed XML element was found. Please delete or change the plist element from info.plist file. +todo.element.not.closed = Delete or change the Plist element from Info.plist + +plist.element.not.supported=An unsupported Info.plist element was found. Please delete or add a valid info.plist element. +todo.plist.element.not.Valid =Add a valid Info.plist element + +WidgetModel.File.NotDirectory=Error validating a widget project directory. The input is not a directory or does not exist. + +todo.widgetmodel =Please add a widget project which contains the mandatory files Info.plist and the main HTML file. + +WidgetModel.File.NotZipFile =The project is not of Widget Type. + +widget.validation.complete =Widget validation succeeded. There were no errors. + +widget.project.not.selected =Please select a widget project to validate. + +no.html.element=The HTML file is empty or invalid HTML. Please verify html file and try again. +todo.no.html.element =Verify html file. + +todo.correct.html.tag =Correct the HTML tag at line + +no.plist.element=The Info.plist file does not contain any valid plist elements. Please add elements to the plist file. +todo.no.plist.element =Add elements to the plist. +## These are not being used anymore should delete +## It looks like these are used with string concatenation. Replace with strings using MessageFormat +project.dir.more.plist.file.present=More than one Plist file is present in the project directory, extra plist file count is : +todo.project.dir.more.plist.file.present=Verify all the plist files and remove the extra ones +project.inner.dir.more.plist.file.present=Plist files detected in inner directories count is: +todo.project.inner.dir.more.plist.file.present=Remove Plist File from the subdirectory. + +initialize.messagemanager = Message Manager must be initialized +validate.man.file.started =Mandatory files validation started +validate.man.file.finished =Validating mandatory files complete. +validate.plist.started =Info.plist validation started +validate.plist.finished =Info.plist validation complete. + +validate.html.started =HTML validation started +validate.html.finished=HTML validation complete. + +## It looks like these are used with string concatenation. Replace with strings using MessageFormat +more.outer.html.File.Present.and.count.is=Extra HTML files are present in project directory, count is : +more.inner.html.File.Present.and.count.is= Html files are present in inner directory, count is : + +todo.more.outer.html.File.Present.and.count.is=Extra HTML files are present in project directory. Verify and remove, count is : +todo.more.inner.html.File.Present.and.count.is=Html files are present in inner directory. Verify and remove, count is : + +xml.declaration.error.missing.close= XML declaration missing close '>'. Please close the tag. +xml.declaration.error.missing.open= XML declaration missing open'<'. Please close the tag. +xml.declaration.error.missing.open.and.close= XML declaration missing open'<' and close'>'. Please verify. + +todo.xml.declaration.error.missing.close= XML declaration missing close '>' +todo.xml.declaration.error.missing.open= XML declaration missing open'<' +todo.xml.declaration.error.missing.open.and.close= XML declaration missing open'<' and close'>' + +xml.doctype.error.missing.close=XML doctype missing close '>' +xml.doctype.error.missing.open=XML doctype missing open'<' +xml.doctype.error.missing.open.and.close= XML doctype missing open'<' and close'>' + +todo.xml.doctype.error.missing.close=XML doctype missing close '>' +todo.xml.doctype.error.missing.open=XML doctype missing open'<' +todo.xml.doctype.error.missing.open.and.close=XML doctype missing open'<' and close'>' + +xml.element.error.missing.close=XML start element missing close'>' +xml.element.error.missing.open=XML start element missing open'<' +xml.element.error.missing.open.and.close=XML start element missing open'<' and close'>' + +todo.xml.element.error.missing.close=XML start element missing close'>' +todo.xml.element.error.missing.open=XML start element missing open'<' +todo.xml.element.error.missing.open.and.close=XML start element missing open'<' and close'>' + + +xml.element.end.error.missing.close=XML end element missing close'> +xml.element.end.error.missing.open=XML end element missing open'<' +xml.element.end.error.missing.open.and.close=XML end element missing open'<' and close'>' + +todo.xml.element.end.error.missing.close=XML end element missing close'>' +todo.xml.element.end.error.missing.open=XML end element missing open'<' +todo.xml.element.end.error.missing.open.and.close= XML end element missing open'<' and close'>' + +char.present.before.start.line= Invalid Character present before Starting of document +todo.char.present.before.start.line=Remove Invalid Character present + +plist.parser.error.at.line.no= Plist Parse Error at line number : +todo.plist.parser.error.at.line.no= Verify Plist Element at line number +non.referenced.html.File.Present=Non referenced Html File Present. To minimize the widget size please only include the required files. +todo.non.referenced.html.File.Present= Verify Non referenced Html File +duplicate.plist.file.present=Duplicate plist file detected in the widget project. To minimize the widget size please only include the required files. +subfolder.duplicate.plist.file.present = More Plist files are present in the project sub directory. Please include only required files. + +todo.duplicate.plist.file.present= Remove Duplicate plist file +plist.File.Not.selected= Plist File is not selected from package option. +todo.plist.File.Not.selected Plist file needs to be selected for packaging + +html.File.Not.selected= Html file is not selected from package option. +todo.html.File.Not.selected=Main Html needs to be selected for packaging + +widgetmodel.plist.notpresent = info.plist is not present in the widget project. +widgetmodel.html.notpresent = main html is not present in the widget project. + +validation.sucess = Validation is success without any errors. +conversion.sucess= Partial conversion is completed. +WidgetModel.refrenced.html.missing=Refrenced html file not present +plist.parsing.error.mainHtmlkey.missing= While parsing plist, main html key is missing or incorrect. +xml.element.not.closed = The element not closed, please close the element and try again. +xml.empty.element.not.closed = The element not closed properly, please close the element and try again. +xml.close.element.not.opened = The closed element not Opened , please verify. +plist.parsing.error.mainHtmlkey.missing= While parsing plist, main html key is missing or incorrect. +todo.xml.element.not.closed=XML element not closed +todo.xml.empty.element.not.closed=Empty element not close