|
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.tmw.core.runtimes; |
|
20 |
|
21 import java.io.IOException; |
|
22 import java.io.InputStream; |
|
23 import java.util.zip.ZipEntry; |
|
24 import java.util.zip.ZipInputStream; |
|
25 |
|
26 import org.eclipse.core.resources.IFile; |
|
27 import org.eclipse.core.resources.IProject; |
|
28 import org.eclipse.core.runtime.CoreException; |
|
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 |
|
38 public abstract class LibraryInstallDelegate implements IDelegate { |
|
39 |
|
40 public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor) |
|
41 throws CoreException { |
|
42 if (config instanceof IProjectSetupConfig) { |
|
43 final IProjectSetupConfig setupConfig = (IProjectSetupConfig) config; |
|
44 final IPath basePath = getBasePath(project, setupConfig); |
|
45 final InputStream file = openInputStream(); |
|
46 final ZipInputStream stream = new ZipInputStream(file); |
|
47 try { |
|
48 ZipEntry en = stream.getNextEntry(); |
|
49 while (en != null) { |
|
50 if (!en.isDirectory()) { |
|
51 final IPath entry = new Path(en.getName()); |
|
52 final IFile f = setupConfig.addFile(project, basePath.append(entry), stream, |
|
53 new NullProgressMonitor()); |
|
54 if (isIncludeFile(entry)) { |
|
55 setupConfig.addIncludedJsFile(f); |
|
56 } |
|
57 |
|
58 } |
|
59 en = stream.getNextEntry(); |
|
60 } |
|
61 } catch (IOException e) { |
|
62 TMWCore.log(null, e); |
|
63 } finally { |
|
64 try { |
|
65 file.close(); |
|
66 } catch (IOException e) { |
|
67 TMWCore.log(null, e); |
|
68 } |
|
69 } |
|
70 } |
|
71 } |
|
72 |
|
73 protected abstract IPath getBasePath(IProject project, IProjectSetupConfig setupConfig); |
|
74 |
|
75 protected abstract boolean isIncludeFile(IPath entry); |
|
76 |
|
77 protected abstract InputStream openInputStream() throws CoreException; |
|
78 |
|
79 } |