|
1 /** |
|
2 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Symbian Foundation - initial contribution. |
|
11 * Contributors: |
|
12 * Description: |
|
13 * Overview: |
|
14 * Details: |
|
15 * Platforms/Drives/Compatibility: |
|
16 * Assumptions/Requirement/Pre-requisites: |
|
17 * Failures and causes: |
|
18 */ |
|
19 package org.symbian.tools.wrttools.core.libraries; |
|
20 |
|
21 import java.io.IOException; |
|
22 import java.io.InputStream; |
|
23 import java.net.URL; |
|
24 |
|
25 import org.eclipse.core.resources.IFile; |
|
26 import org.eclipse.core.resources.IProject; |
|
27 import org.eclipse.core.runtime.CoreException; |
|
28 import org.eclipse.core.runtime.FileLocator; |
|
29 import org.eclipse.core.runtime.IPath; |
|
30 import org.eclipse.core.runtime.IProgressMonitor; |
|
31 import org.eclipse.core.runtime.NullProgressMonitor; |
|
32 import org.eclipse.core.runtime.Path; |
|
33 import org.eclipse.wst.common.project.facet.core.IDelegate; |
|
34 import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; |
|
35 import org.symbian.tools.tmw.core.TMWCore; |
|
36 import org.symbian.tools.tmw.core.projects.IProjectSetupConfig; |
|
37 import org.symbian.tools.wrttools.Activator; |
|
38 |
|
39 public final class InstallPhoneGapDelegate implements IDelegate { |
|
40 private static final String PHONEGAP_JS = "phonegap.js"; |
|
41 |
|
42 private IPath getBasePath(IProject project, IProjectSetupConfig setupConfig) { |
|
43 return new Path("phonegap"); |
|
44 } |
|
45 |
|
46 public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor) |
|
47 throws CoreException { |
|
48 if (config instanceof IProjectSetupConfig) { |
|
49 final IProjectSetupConfig setupConfig = (IProjectSetupConfig) config; |
|
50 final IPath basePath = getBasePath(project, setupConfig); |
|
51 InputStream file = null; |
|
52 try { |
|
53 URL url = FileLocator.find(Activator.getDefault().getBundle(), |
|
54 new Path("libraries").append(PHONEGAP_JS), null); |
|
55 if (url != null) { |
|
56 file = url.openStream(); |
|
57 final IFile f = setupConfig.addFile(project, basePath.append(PHONEGAP_JS), file, |
|
58 new NullProgressMonitor()); |
|
59 setupConfig.addIncludedJsFile(f); |
|
60 } |
|
61 } catch (IOException e) { |
|
62 Activator.log(e); |
|
63 } finally { |
|
64 try { |
|
65 if (file != null) { |
|
66 file.close(); |
|
67 } |
|
68 } catch (IOException e) { |
|
69 TMWCore.log(null, e); |
|
70 } |
|
71 } |
|
72 } |
|
73 } |
|
74 } |