org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/projects/StaticIncludePathProvider.java
changeset 461 7a8f9fa8d278
child 468 a05c6e5cc7d9
equal deleted inserted replaced
460:c0bff5ed874c 461:7a8f9fa8d278
       
     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.internal.projects;
       
    20 
       
    21 import java.io.File;
       
    22 import java.io.IOException;
       
    23 import java.net.URISyntaxException;
       
    24 import java.net.URL;
       
    25 
       
    26 import org.eclipse.core.runtime.FileLocator;
       
    27 import org.eclipse.core.runtime.IConfigurationElement;
       
    28 import org.eclipse.core.runtime.Path;
       
    29 import org.eclipse.core.runtime.Platform;
       
    30 import org.eclipse.wst.jsdt.core.IIncludePathEntry;
       
    31 import org.eclipse.wst.jsdt.core.JavaScriptCore;
       
    32 import org.osgi.framework.Bundle;
       
    33 import org.symbian.tools.tmw.core.TMWCore;
       
    34 import org.symbian.tools.tmw.core.projects.IFacetIncludePathProvider;
       
    35 import org.symbian.tools.tmw.core.projects.IMTWProject;
       
    36 
       
    37 public class StaticIncludePathProvider implements IFacetIncludePathProvider {
       
    38     private final IConfigurationElement element;
       
    39     private IIncludePathEntry[] entries;
       
    40 
       
    41     public StaticIncludePathProvider(IConfigurationElement element) {
       
    42         this.element = element;
       
    43     }
       
    44 
       
    45     public IIncludePathEntry[] getEntries(IMTWProject project) {
       
    46         if (entries == null) {
       
    47             final String name = element.getContributor().getName();
       
    48             final String path = element.getAttribute("file");
       
    49             final Bundle bundle = Platform.getBundle(name);
       
    50             final URL url = FileLocator.find(bundle, new Path(path), null);
       
    51             try {
       
    52                 final URL fileURL = FileLocator.toFileURL(url);
       
    53                 final File file = new File(fileURL.toURI());
       
    54                 final IIncludePathEntry entry = JavaScriptCore.newLibraryEntry(new Path(file.getAbsolutePath()), null,
       
    55                         null);
       
    56                 entries = new IIncludePathEntry[] { entry };
       
    57             } catch (IOException e) {
       
    58                 TMWCore.log(String.format("Can't find file %s in plugin %s", path, name), e);
       
    59             } catch (URISyntaxException e) {
       
    60                 TMWCore.log(String.format("Can't find file %s in plugin %s", path, name), e);
       
    61             }
       
    62         }
       
    63         return entries;
       
    64     }
       
    65 
       
    66 }