# HG changeset patch # User Eugene Ostroukhov # Date 1283281133 25200 # Node ID 518afa7c6d2fa82f1e3ad6c589741da5de57a68b # Parent 6c07c755d0c719e74fe9dd61641c61d2845b75ff Minor refactoring to make API more clear diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.core/META-INF/MANIFEST.MF --- a/plugins/org.symbian.tools.tmw.core/META-INF/MANIFEST.MF Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.core/META-INF/MANIFEST.MF Tue Aug 31 11:58:53 2010 -0700 @@ -11,7 +11,9 @@ org.eclipse.core.expressions;bundle-version="3.4.200", org.eclipse.wst.common.project.facet.core;bundle-version="1.4.100", org.eclipse.wst.jsdt.core;bundle-version="1.1.0", - org.eclipse.wst.validation;bundle-version="1.2.200" + org.eclipse.wst.validation;bundle-version="1.2.200", + org.eclipse.wst.sse.core;bundle-version="1.1.500", + org.eclipse.wst.xml.core;bundle-version="1.1.500" Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy Export-Package: org.symbian.tools.tmw.core, diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.core/plugin.xml --- a/plugins/org.symbian.tools.tmw.core/plugin.xml Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.core/plugin.xml Tue Aug 31 11:58:53 2010 -0700 @@ -5,6 +5,7 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/internal/projects/LibraryAdditionConfigObject.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/internal/projects/LibraryAdditionConfigObject.java Tue Aug 31 11:58:53 2010 -0700 @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2010 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.tmw.core.internal.projects; + +import java.io.IOException; +import java.io.InputStream; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.wst.sse.core.StructuredModelManager; +import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.IProjectSetupConfig; +import org.symbian.tools.tmw.core.projects.ITMWProject; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +@SuppressWarnings("restriction") +public class LibraryAdditionConfigObject implements IProjectSetupConfig { + + public void initialize(IProject project, IProgressMonitor monitor) { + // Do nothing + } + + public IFile addFile(IProject project, IPath name, InputStream contents, IProgressMonitor monitor) + throws CoreException { + IFile file = project.getFile(name); + if (!file.exists()) { + file.create(contents, false, monitor); + } + return file; + } + + public void addIncludedJsFile(IProject project, IFile file) { + // It is highly likely this code is extremely specific to Symbian web runtime. + // Please open a bug and clarify the requirements + final ITMWProject tmwProject = TMWCore.create(project); + if (tmwProject != null && tmwProject.getTargetRuntime() != null) { + final IFile page = tmwProject.getTargetRuntime().getLayoutProvider().getIndexPage(tmwProject.getProject()); + if (page != null && page.exists()) { + IStructuredModel model = null; + try { + model = StructuredModelManager.getModelManager().getModelForEdit(page); + if (model instanceof IDOMModel) { + IDOMDocument document = ((IDOMModel) model).getDocument(); + String path = file.getProjectRelativePath().makeAbsolute().toString(); + + NodeList scripts = document.getElementsByTagName("script"); + for (int i = 0; i < scripts.getLength(); i++) { + + } + + NodeList heads = document.getElementsByTagName("head"); + if (heads.getLength() > 0) { + Element el = document.createElement("script"); + el.setAttribute("type", "text/javascript"); + el.setAttribute("src", path); + heads.item(0).appendChild(el); + model.save(); + } + } + } catch (IOException e) { + TMWCore.log(null, e); + } catch (CoreException e) { + TMWCore.log(null, e); + } finally { + if (model != null) { + model.releaseFromEdit(); + } + } + } + } + } + +} diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/internal/projects/TMWFacetedProject.java --- a/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/internal/projects/TMWFacetedProject.java Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/internal/projects/TMWFacetedProject.java Tue Aug 31 11:58:53 2010 -0700 @@ -18,6 +18,7 @@ */ package org.symbian.tools.tmw.core.internal.projects; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -79,4 +80,8 @@ return "240x320"; } + public IFile getMainHtmlPage() { + return null; + } + } diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileWebRuntime.java --- a/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileWebRuntime.java Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/internal/runtimes/MobileWebRuntime.java Tue Aug 31 11:58:53 2010 -0700 @@ -22,37 +22,45 @@ import java.util.TreeMap; import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.internal.runtimes.RuntimesManagerImpl.LazyProvider; +import org.symbian.tools.tmw.core.runtimes.IApplicationLayoutProvider; import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; import org.symbian.tools.tmw.core.utilities.CoreUtil; public final class MobileWebRuntime implements IMobileWebRuntime { private final IConfigurationElement element; + private IApplicationLayoutProvider layout; public MobileWebRuntime(IConfigurationElement element) { this.element = element; - } - - public String getId() { - return element.getAttribute("component-id"); + checkRegistry(); } - public String getVersion() { - return element.getAttribute("component-version"); - } - - public String getName() { - return element.getAttribute("name"); + private synchronized void checkRegistry() { + if (layout == null) { + final IConfigurationElement[] configuration = Platform.getExtensionRegistry().getConfigurationElementsFor( + TMWCore.PLUGIN_ID, "runtimeAppLayout"); + for (IConfigurationElement element : configuration) { + final String runtimeId = element.getAttribute("runtime-id"); + final String version = element.getAttribute("runtime-version"); + if (getId().endsWith(runtimeId) && getVersion().endsWith(version)) { + layout = new LazyProvider(element); + break; + } + } + if (layout == null) { + TMWCore.log("No layout provider for runtime %s:%s (from plugin %s)", getId(), getVersion(), element + .getContributor().getName()); + } + } } public IConfigurationElement[] getComponentElements() { return element.getChildren("runtime-component"); } - @Override - public String toString() { - return getId() + ":" + getVersion(); - } - public Map getFixedFacets() { final Map facets = new TreeMap(); final IConfigurationElement[] children = element.getChildren("fixed-facet"); @@ -62,4 +70,25 @@ return facets; } + public String getId() { + return element.getAttribute("component-id"); + } + + public IApplicationLayoutProvider getLayoutProvider() { + return layout; + } + + public String getName() { + return element.getAttribute("name"); + } + + public String getVersion() { + return element.getAttribute("component-version"); + } + + @Override + public String toString() { + return getId() + ":" + getVersion(); + } + } diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/internal/runtimes/RuntimesManagerImpl.java --- a/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/internal/runtimes/RuntimesManagerImpl.java Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/internal/runtimes/RuntimesManagerImpl.java Tue Aug 31 11:58:53 2010 -0700 @@ -18,15 +18,21 @@ */ package org.symbian.tools.tmw.core.internal.runtimes; +import java.io.InputStream; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.TreeMap; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Platform; import org.symbian.tools.tmw.core.TMWCore; import org.symbian.tools.tmw.core.projects.ITMWProject; +import org.symbian.tools.tmw.core.runtimes.IApplicationLayoutProvider; import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntimeManager; import org.symbian.tools.tmw.core.runtimes.IPackager; @@ -102,4 +108,57 @@ return id + ":" + version; } + public static final class LazyProvider implements IApplicationLayoutProvider { + private final IConfigurationElement element; + private IApplicationLayoutProvider instance; + + public LazyProvider(IConfigurationElement element) { + this.element = element; + } + + public IPath getResourcePath(IFile file) { + return getDelegate().getResourcePath(file); + } + + private IApplicationLayoutProvider getDelegate() { + if (instance == null) { + try { + instance = (IApplicationLayoutProvider) element.createExecutableExtension("class"); + } catch (CoreException e) { + TMWCore.log(null, e); + instance = new IApplicationLayoutProvider() { + + public IPath getResourcePath(IFile file) { + return null; + } + + public InputStream getResourceFromPath(IProject project, IPath path) { + return null; + } + + public IFile getWorkspaceFile(IProject project, IPath applicationPath) { + return null; + } + + public IFile getIndexPage(IProject project) { + return null; + } + }; + } + } + return instance; + } + + public InputStream getResourceFromPath(IProject project, IPath path) throws CoreException { + return getDelegate().getResourceFromPath(project, path); + } + + public IFile getWorkspaceFile(IProject project, IPath applicationPath) throws CoreException { + return getDelegate().getWorkspaceFile(project, applicationPath); + } + + public IFile getIndexPage(IProject project) { + return getDelegate().getIndexPage(project); + } + } } diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/projects/IProjectSetupConfig.java --- a/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/projects/IProjectSetupConfig.java Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/projects/IProjectSetupConfig.java Tue Aug 31 11:58:53 2010 -0700 @@ -57,5 +57,5 @@ * @param file workspace file. Framework is responsible to create proper * application root-relative path */ - void addIncludedJsFile(IFile file); + void addIncludedJsFile(IProject project, IFile file); } diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/runtimes/IApplicationLayoutProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/runtimes/IApplicationLayoutProvider.java Tue Aug 31 11:58:53 2010 -0700 @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2010 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.tmw.core.runtimes; + +import java.io.InputStream; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; + +/** + * This interface provides application structure as it will be used in web + * runtime. Note that project layout may not directly correspond to application + * layout. + * + * @author Eugene Ostroukhov (eugeneo@symbian.org) + */ +public interface IApplicationLayoutProvider { + /** + * @param file workspace resource + * @return path relative to application package root + */ + IPath getResourcePath(IFile file); + + /** + * @param path path relative to application root + * @return workspace resource + * @throws CoreException if cannot access resource contents + */ + InputStream getResourceFromPath(IProject project, IPath path) throws CoreException; + + /** + * @return workspace file that corresponds to applicationPath or + * null if none + */ + IFile getWorkspaceFile(IProject project, IPath applicationPath) throws CoreException; + + /** + * @return main HTML page (application entry point) + */ + IFile getIndexPage(IProject project); +} diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/runtimes/IMobileWebRuntime.java --- a/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/runtimes/IMobileWebRuntime.java Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/runtimes/IMobileWebRuntime.java Tue Aug 31 11:58:53 2010 -0700 @@ -45,4 +45,10 @@ * @return fixed facets (that are always enabled for the runtime) as id-version pairs */ Map getFixedFacets(); + + /** + * @return layout provider that bridges application runtime structure and + * workspace project structure + */ + IApplicationLayoutProvider getLayoutProvider(); } diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/runtimes/IMobileWebRuntimeManager.java --- a/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/runtimes/IMobileWebRuntimeManager.java Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/runtimes/IMobileWebRuntimeManager.java Tue Aug 31 11:58:53 2010 -0700 @@ -53,4 +53,5 @@ * @return list of all runtimes known to an IDE */ IMobileWebRuntime[] getAllRuntimes(); + } diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/runtimes/LibraryInstallDelegate.java --- a/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/runtimes/LibraryInstallDelegate.java Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/runtimes/LibraryInstallDelegate.java Tue Aug 31 11:58:53 2010 -0700 @@ -52,7 +52,7 @@ final IFile f = setupConfig.addFile(project, basePath.append(entry), stream, new NullProgressMonitor()); if (isIncludeFile(entry)) { - setupConfig.addIncludedJsFile(f); + setupConfig.addIncludedJsFile(project, f); } } diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/runtimes/ProjectCreationConfigFactory.java --- a/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/runtimes/ProjectCreationConfigFactory.java Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/runtimes/ProjectCreationConfigFactory.java Tue Aug 31 11:58:53 2010 -0700 @@ -24,7 +24,7 @@ public class ProjectCreationConfigFactory implements IActionConfigFactory { // Basically this is an ugly hack. Our project wizard will replace this config // object with WizardContext - public static final Object CONFIG_STANDIN = "standing_config"; + public static final Object CONFIG_STANDIN = "standin_config"; public Object create() throws CoreException { return CONFIG_STANDIN; diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.previewer/META-INF/MANIFEST.MF --- a/plugins/org.symbian.tools.tmw.previewer/META-INF/MANIFEST.MF Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.previewer/META-INF/MANIFEST.MF Tue Aug 31 11:58:53 2010 -0700 @@ -18,10 +18,9 @@ org.symbian.tools.tmw.ui;bundle-version="1.0.0" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Export-Package: org.symbian.tools.tmw.previewer.core, - org.symbian.tools.tmw.previewer.internal, - org.symbian.tools.tmw.previewer, - org.symbian.tools.tmw.previewer.http +Export-Package: org.symbian.tools.tmw.previewer, + org.symbian.tools.tmw.previewer.http, + org.symbian.tools.tmw.previewer.internal Import-Package: javax.servlet;version="2.5.0", javax.servlet.http;version="2.5.0", org.eclipse.equinox.jsp.jasper;version="1.0.0", diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.previewer/plugin.xml --- a/plugins/org.symbian.tools.tmw.previewer/plugin.xml Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.previewer/plugin.xml Tue Aug 31 11:58:53 2010 -0700 @@ -2,7 +2,6 @@ - - - - - - - - - [Enter description of this extension point.] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [Enter the first release in which this extension point appears.] - - - - - - - - - [Enter extension point usage example here.] - - - - - - - - - [Enter API information here.] - - - - - - - - - [Enter information about supplied implementation of this extension point.] - - - - - diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/PreviewerPlugin.java --- a/plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/PreviewerPlugin.java Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/PreviewerPlugin.java Tue Aug 31 11:58:53 2010 -0700 @@ -32,9 +32,7 @@ import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; -import org.symbian.tools.tmw.previewer.core.IPreviewerExtensionsManager; import org.symbian.tools.tmw.previewer.http.HttpPreviewer; -import org.symbian.tools.tmw.previewer.internal.PreviewerExtensionsManagerImpl; /** * The activator class controls the plug-in life cycle @@ -62,7 +60,6 @@ // The shared instance private static PreviewerPlugin plugin; - private final IPreviewerExtensionsManager extensionsManager = new PreviewerExtensionsManagerImpl(); private final CommandHandlerManager handlerManager = new CommandHandlerManager(); private final HttpPreviewer previewer = new HttpPreviewer(); private MessageConsole console; @@ -149,8 +146,4 @@ console.newMessageStream().write( message); } - - public static IPreviewerExtensionsManager getExtensionsManager() { - return getDefault().extensionsManager; - } } diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/core/IApplicationLayoutProvider.java --- a/plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/core/IApplicationLayoutProvider.java Tue Aug 24 17:21:16 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/** - * Copyright (c) 2010 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.tmw.previewer.core; - -import java.io.InputStream; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; - -/** - * This interface provides application structure as it will be used in web - * runtime. Note that project layout may not directly correspond to application - * layout. - * - * @author Eugene Ostroukhov (eugeneo@symbian.org) - */ -public interface IApplicationLayoutProvider { - /** - * @param file workspace resource - * @return path relative to application package root - */ - IPath getResourcePath(IFile file); - - /** - * @param path path relative to application root - * @return workspace resource - * @throws CoreException if cannot access resource contents - */ - InputStream getResourceFromPath(IProject project, IPath path) throws CoreException; - - /** - * @return workspace file that corresponds to applicationPath or - * null if none - */ - IFile getWorkspaceFile(IProject project, IPath applicationPath) throws CoreException; -} diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/core/IPreviewerExtensionsManager.java --- a/plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/core/IPreviewerExtensionsManager.java Tue Aug 24 17:21:16 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2010 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.tmw.previewer.core; - -import org.eclipse.core.resources.IProject; - -public interface IPreviewerExtensionsManager { - IApplicationLayoutProvider getLayoutProvider(IProject project); -} diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/http/WorkspaceResourcesServlet.java --- a/plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/http/WorkspaceResourcesServlet.java Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/http/WorkspaceResourcesServlet.java Tue Aug 31 11:58:53 2010 -0700 @@ -50,16 +50,17 @@ import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.ITMWProject; +import org.symbian.tools.tmw.core.runtimes.IApplicationLayoutProvider; import org.symbian.tools.tmw.previewer.PreviewerException; import org.symbian.tools.tmw.previewer.PreviewerPlugin; -import org.symbian.tools.tmw.previewer.core.IApplicationLayoutProvider; import org.symbian.tools.tmw.previewer.http.handlers.DebuggerResourceProvider; import org.symbian.tools.tmw.previewer.http.handlers.PreviewerStaticResourceProvider; import org.symbian.tools.tmw.previewer.http.handlers.Providers; public class WorkspaceResourcesServlet extends HttpServlet { private static final Map EXTENSION_CONTENT_TYPE = new TreeMap(); - private static final long serialVersionUID = -3217197074249607950L; static { @@ -99,49 +100,41 @@ } } + public static URI getDebugStartingPage(IProject project, String session) { + return getServerURIForResource(project.getFullPath().append(HttpPreviewer.DEBUG_STARTING_PAGE).makeAbsolute(), + session); + } + public static IFile getFileFromUrl(String name) { final IPath path = getResourcePath(name); if (path != null) { final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0)); - final IApplicationLayoutProvider provider = PreviewerPlugin.getExtensionsManager().getLayoutProvider( - project); - if (provider != null) { - try { - return provider.getWorkspaceFile(project, path.removeFirstSegments(1)); - } catch (CoreException e) { - PreviewerPlugin.log(e); + final ITMWProject p = TMWCore.create(project); + if (p != null && p.getTargetRuntime() != null) { + final IApplicationLayoutProvider provider = p.getTargetRuntime().getLayoutProvider(); + if (provider != null) { + try { + return provider.getWorkspaceFile(project, path.removeFirstSegments(1)); + } catch (CoreException e) { + PreviewerPlugin.log(e); + } } } } return null; } - private static IPath getResourcePath(String name) { - IPath p = null; - try { - String root = getHttpUrl(null); - if (name != null && name.startsWith(root)) { - final String fileName = URLDecoder.decode(name.substring(root.length()), "UTF-8"); - final IPath path = new Path(fileName); - if (path.segmentCount() > 1) { - p = path; - } - } - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - return p; - } - public static String getHttpUrl(IFile file) { IPath p = new Path("/"); if (file != null) { - IApplicationLayoutProvider provider = PreviewerPlugin.getExtensionsManager().getLayoutProvider( - file.getProject()); - if (provider != null) { - IPath path = provider.getResourcePath(file); - if (path != null) { - p = p.append(file.getProject().getName()).append(path).makeAbsolute(); + final ITMWProject project = TMWCore.create(file.getProject()); + if (project != null && project.getTargetRuntime() != null) { + final IApplicationLayoutProvider provider = project.getTargetRuntime().getLayoutProvider(); + if (provider != null) { + IPath path = provider.getResourcePath(file); + if (path != null) { + p = p.append(file.getProject().getName()).append(path).makeAbsolute(); + } } } } @@ -192,6 +185,23 @@ null); } + private static IPath getResourcePath(String name) { + IPath p = null; + try { + String root = getHttpUrl(null); + if (name != null && name.startsWith(root)) { + final String fileName = URLDecoder.decode(name.substring(root.length()), "UTF-8"); + final IPath path = new Path(fileName); + if (path.segmentCount() > 1) { + p = path; + } + } + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + return p; + } + private static URI getServerURIForResource(IPath resourcePath, String debugSessionId) { try { String path = encode(WebappManager.WORKSPACE_RESOURCES_CONTEXT + resourcePath); @@ -273,9 +283,4 @@ } resp.setStatus(HttpServletResponse.SC_OK); } - - public static URI getDebugStartingPage(IProject project, String session) { - return getServerURIForResource(project.getFullPath().append(HttpPreviewer.DEBUG_STARTING_PAGE).makeAbsolute(), - session); - } } diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/http/handlers/WorkspaceResourceProvider.java --- a/plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/http/handlers/WorkspaceResourceProvider.java Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/http/handlers/WorkspaceResourceProvider.java Tue Aug 31 11:58:53 2010 -0700 @@ -26,7 +26,9 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.json.simple.JSONObject; -import org.symbian.tools.tmw.previewer.PreviewerPlugin; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.ITMWProject; +import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; public class WorkspaceResourceProvider implements IResourceProvider { public String[] getPaths() { @@ -35,7 +37,14 @@ public InputStream getResourceStream(IProject project, IPath resource, Map parameters, String sessionId) throws CoreException { - return PreviewerPlugin.getExtensionsManager().getLayoutProvider(project).getResourceFromPath(project, resource); + final ITMWProject p = TMWCore.create(project); + if (p != null) { + final IMobileWebRuntime targetRuntime = p.getTargetRuntime(); + if (targetRuntime != null) { + return targetRuntime.getLayoutProvider().getResourceFromPath(project, resource); + } + } + return null; } public void post(IProject project, IPath resource, Map parameterMap, JSONObject object, diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/internal/PreviewerExtensionsManagerImpl.java --- a/plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/internal/PreviewerExtensionsManagerImpl.java Tue Aug 24 17:21:16 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -/** - * Copyright (c) 2010 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.tmw.previewer.internal; - -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Platform; -import org.symbian.tools.tmw.core.TMWCore; -import org.symbian.tools.tmw.core.projects.ITMWProject; -import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; -import org.symbian.tools.tmw.previewer.PreviewerPlugin; -import org.symbian.tools.tmw.previewer.core.IApplicationLayoutProvider; -import org.symbian.tools.tmw.previewer.core.IPreviewerExtensionsManager; - -public class PreviewerExtensionsManagerImpl implements IPreviewerExtensionsManager { - public static final class LazyProvider implements IApplicationLayoutProvider { - private final IConfigurationElement element; - private IApplicationLayoutProvider instance; - - public LazyProvider(IConfigurationElement element) { - this.element = element; - } - - public IPath getResourcePath(IFile file) { - return getDelegate().getResourcePath(file); - } - - private IApplicationLayoutProvider getDelegate() { - if (instance == null) { - try { - instance = (IApplicationLayoutProvider) element.createExecutableExtension("class"); - } catch (CoreException e) { - PreviewerPlugin.log(e); - instance = new IApplicationLayoutProvider() { - - public IPath getResourcePath(IFile file) { - return null; - } - - public InputStream getResourceFromPath(IProject project, IPath path) { - return null; - } - - public IFile getWorkspaceFile(IProject project, IPath applicationPath) { - return null; - } - }; - } - } - return instance; - } - - public InputStream getResourceFromPath(IProject project, IPath path) throws CoreException { - return getDelegate().getResourceFromPath(project, path); - } - - public IFile getWorkspaceFile(IProject project, IPath applicationPath) throws CoreException { - return getDelegate().getWorkspaceFile(project, applicationPath); - } - } - - private Map providers; - - public IApplicationLayoutProvider getLayoutProvider(IProject project) { - final ITMWProject p = TMWCore.create(project); - if (p != null && p.getTargetRuntime() != null) { - checkRegistry(); - return providers.get(p.getTargetRuntime()); - } - return null; - } - - private synchronized void checkRegistry() { - if (providers == null) { - providers = new HashMap(); - final IConfigurationElement[] configuration = Platform.getExtensionRegistry().getConfigurationElementsFor( - PreviewerPlugin.PLUGIN_ID, "layoutProviders"); - for (IConfigurationElement element : configuration) { - final String runtimeId = element.getAttribute("runtime-id"); - final String version = element.getAttribute("runtime-version"); - final IMobileWebRuntime runtime = TMWCore.getRuntimesManager().getRuntime(runtimeId, version); - if (runtime != null) { - providers.put(runtime, new LazyProvider(element)); - } else { - PreviewerPlugin.log(String.format("Runtime %s:$s referenced from %s was not found", runtimeId, - version, element.getContributor().getName()), null); - } - } - } - } -} diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/internal/PreviewerUtil.java --- a/plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/internal/PreviewerUtil.java Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/internal/PreviewerUtil.java Tue Aug 31 11:58:53 2010 -0700 @@ -30,8 +30,10 @@ import org.eclipse.core.resources.IResourceDeltaVisitor; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.ITMWProject; +import org.symbian.tools.tmw.core.runtimes.IApplicationLayoutProvider; import org.symbian.tools.tmw.previewer.PreviewerPlugin; -import org.symbian.tools.tmw.previewer.core.IApplicationLayoutProvider; public class PreviewerUtil { public static final class ChangedResourcesCollector implements IResourceDeltaVisitor { @@ -53,16 +55,18 @@ } break; case IResource.FILE: - IApplicationLayoutProvider layoutProvider = PreviewerPlugin.getExtensionsManager().getLayoutProvider( - resource.getProject()); - if (layoutProvider != null) { - if (layoutProvider.getResourcePath((IFile) resource) != null) { - final boolean kind = delta.getKind() == IResourceDelta.ADDED - | delta.getKind() == IResourceDelta.REMOVED; - final boolean flag = (delta.getFlags() & (IResourceDelta.CONTENT | IResourceDelta.ENCODING - | IResourceDelta.LOCAL_CHANGED | IResourceDelta.REPLACED | IResourceDelta.SYNC)) != 0; - if (kind || flag) { - files.add((IFile) resource); + final ITMWProject p = TMWCore.create(resource.getProject()); + if (p != null && p.getTargetRuntime() != null) { + IApplicationLayoutProvider layoutProvider = p.getTargetRuntime().getLayoutProvider(); + if (layoutProvider != null) { + if (layoutProvider.getResourcePath((IFile) resource) != null) { + final boolean kind = delta.getKind() == IResourceDelta.ADDED + | delta.getKind() == IResourceDelta.REMOVED; + final boolean flag = (delta.getFlags() & (IResourceDelta.CONTENT | IResourceDelta.ENCODING + | IResourceDelta.LOCAL_CHANGED | IResourceDelta.REPLACED | IResourceDelta.SYNC)) != 0; + if (kind || flag) { + files.add((IFile) resource); + } } } } diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/preview/PreviewView.java --- a/plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/preview/PreviewView.java Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.previewer/src/org/symbian/tools/tmw/previewer/preview/PreviewView.java Tue Aug 31 11:58:53 2010 -0700 @@ -33,6 +33,8 @@ import org.eclipse.ui.part.MessagePage; import org.eclipse.ui.part.PageBook; import org.eclipse.ui.part.PageBookView; +import org.symbian.tools.tmw.core.TMWCore; +import org.symbian.tools.tmw.core.projects.ITMWProject; import org.symbian.tools.tmw.previewer.IWrtEditingPreferences; import org.symbian.tools.tmw.previewer.PreviewerPlugin; @@ -143,7 +145,10 @@ if (part instanceof IEditorPart) { IResource resource = (IResource) ((IEditorPart) part).getEditorInput().getAdapter(IResource.class); if (resource != null) { - return PreviewerPlugin.getExtensionsManager().getLayoutProvider(resource.getProject()) != null; + final ITMWProject project = TMWCore.create(resource.getProject()); + if (project != null && project.getTargetRuntime() != null) { + return project.getTargetRuntime().getLayoutProvider() != null; + } } } return false; diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/WizardContext.java --- a/plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/WizardContext.java Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/WizardContext.java Tue Aug 31 11:58:53 2010 -0700 @@ -321,7 +321,7 @@ } } - public void addIncludedJsFile(IFile file) { + public void addIncludedJsFile(IProject project, IFile file) { jsIncludes.add(file.getProjectRelativePath().makeRelative().toString()); } } diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.wrttools/plugin.xml --- a/plugins/org.symbian.tools.wrttools/plugin.xml Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.wrttools/plugin.xml Tue Aug 31 11:58:53 2010 -0700 @@ -136,18 +136,6 @@ - - - - - - - - - - - - + point="org.symbian.tools.tmw.core.runtimeAppLayout"> INDEX_FILES = new HashMap(); - public static synchronized String getIndexFile(IProject project) throws CoreException { + public static synchronized IFile getIndexFile(IProject project) throws CoreException { // There will really be a lot of calls to this method. We need to cache values. IFile file = getFile(project, METADATA_FILE); if (file == null) { @@ -132,15 +132,19 @@ } } String fileName = getIndexFileName(readFile(file)); - INDEX_FILES.put(project, new IndexFileRecord(fileName, file.getModificationStamp())); - return fileName; + if (fileName != null) { + IFile f = getFile(project, fileName); + INDEX_FILES.put(project, new IndexFileRecord(f, file.getModificationStamp())); + return f; + } + return null; } private static class IndexFileRecord { - public final String fileName; + public final IFile fileName; public final long timeStamp; - public IndexFileRecord(String fileName, long timeStamp) { + public IndexFileRecord(IFile fileName, long timeStamp) { this.fileName = fileName; this.timeStamp = timeStamp; } diff -r 6c07c755d0c7 -r 518afa7c6d2f plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java --- a/plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java Tue Aug 24 17:21:16 2010 -0700 +++ b/plugins/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/ProjectUtils.java Tue Aug 31 11:58:53 2010 -0700 @@ -100,12 +100,9 @@ try { final Collection files = new HashSet(projects.length); for (IProject project : projects) { - String file = CoreUtil.getIndexFile(project); - if (file != null) { - IFile index = project.getFile(file); - if (index.isAccessible()) { - files.add(index); - } + IFile index = CoreUtil.getIndexFile(project); + if (index != null && index.isAccessible()) { + files.add(index); } } final IFile[] filesArray = files.toArray(new IFile[files.size()]); @@ -414,8 +411,7 @@ return false; } try { - IMarker[] markers = resource - .findMarkers(EXCLUDE_MARKER_ID, false, IResource.DEPTH_ZERO); + IMarker[] markers = resource.findMarkers(EXCLUDE_MARKER_ID, false, IResource.DEPTH_ZERO); IPath path = resource.getProjectRelativePath(); return markers.length != 0 || (path.segmentCount() > 1 && ".settings".equals(path.segment(0))) || isExcluded(resource.getParent()); @@ -437,8 +433,7 @@ public static void include(IResource resource) { try { - IMarker[] markers = resource - .findMarkers(EXCLUDE_MARKER_ID, false, IResource.DEPTH_ZERO); + IMarker[] markers = resource.findMarkers(EXCLUDE_MARKER_ID, false, IResource.DEPTH_ZERO); resource.setPersistentProperty(WRTPackagerConstants.EXCLUDE_PROPERTY, null); for (IMarker marker : markers) { marker.delete();