plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/internal/runtimes/RuntimeClasspathManager.java
author Eugene Ostroukhov <eugeneo@symbian.org>
Thu, 19 Aug 2010 17:48:04 -0700
changeset 470 d4809db37847
parent 468 org.symbian.tools.mtw.core/src/org/symbian/tools/tmw/core/internal/runtimes/RuntimeClasspathManager.java@a05c6e5cc7d9
child 483 109da596fa9d
permissions -rw-r--r--
Changed repository layout and renamed project files. This revision is untested and may not run.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
461
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     1
/**
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     2
 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     3
 * All rights reserved.
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     8
 *
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     9
 * Initial Contributors:
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    10
 * Symbian Foundation - initial contribution.
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    11
 * Contributors:
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    12
 * Description:
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    13
 * Overview:
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    14
 * Details:
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    15
 * Platforms/Drives/Compatibility:
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    16
 * Assumptions/Requirement/Pre-requisites:
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    17
 * Failures and causes:
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    18
 */
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    19
package org.symbian.tools.tmw.core.internal.runtimes;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    20
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    21
import java.util.Arrays;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    22
import java.util.Collection;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    23
import java.util.Collections;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    24
import java.util.HashMap;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    25
import java.util.HashSet;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    26
import java.util.LinkedList;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    27
import java.util.Map;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    28
import java.util.Set;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    29
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    30
import org.eclipse.core.runtime.CoreException;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    31
import org.eclipse.core.runtime.IConfigurationElement;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    32
import org.eclipse.core.runtime.Platform;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    33
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    34
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    35
import org.eclipse.wst.common.project.facet.core.IVersion;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    36
import org.eclipse.wst.common.project.facet.core.IVersionExpr;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    37
import org.eclipse.wst.common.project.facet.core.util.internal.VersionExpr;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    38
import org.eclipse.wst.common.project.facet.core.util.internal.Versionable;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    39
import org.eclipse.wst.jsdt.core.IIncludePathEntry;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    40
import org.symbian.tools.tmw.core.TMWCore;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    41
import org.symbian.tools.tmw.core.internal.projects.LazyIncludePathProvider;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    42
import org.symbian.tools.tmw.core.internal.projects.StaticIncludePathProvider;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    43
import org.symbian.tools.tmw.core.projects.IFacetIncludePathProvider;
468
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 463
diff changeset
    44
import org.symbian.tools.tmw.core.projects.ITMWProject;
461
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    45
import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    46
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    47
@SuppressWarnings("restriction")
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    48
public class RuntimeClasspathManager {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    49
    private static final class VersionedEntry<T> {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    50
        protected final IVersionExpr versionExpression;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    51
        protected final T entry;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    52
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    53
        public VersionedEntry(String versionExpression, T entry) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    54
            if (versionExpression == null) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    55
                this.versionExpression = null;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    56
            } else {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    57
                IVersionExpr expr;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    58
                try {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    59
                    expr = new VersionExpr<Version>(new VersionableObject(), versionExpression, null);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    60
                } catch (CoreException e) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    61
                    expr = null;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    62
                    TMWCore.log(null, e);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    63
                }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    64
                this.versionExpression = expr;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    65
            }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    66
            this.entry = entry;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    67
        }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    68
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    69
        public boolean matches(String version) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    70
            if (versionExpression == null) { // Any version
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    71
                return true;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    72
            }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    73
            if (version == null) { // Unspecified
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    74
                return false;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    75
            }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    76
            return versionExpression.check(new Version(version));
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    77
        }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    78
    }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    79
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    80
    private static final class VersionableObject extends Versionable<Version> {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    81
        @Override
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    82
        public String getPluginId() {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    83
            return TMWCore.PLUGIN_ID;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    84
        }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    85
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    86
        @Override
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    87
        public String createVersionNotFoundErrMsg(String verstr) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    88
            return "Version not found";
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    89
        }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    90
    }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    91
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    92
    private static final class Version implements IVersion {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    93
        private final String version;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    94
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    95
        public Version(String version) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    96
            this.version = version;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    97
        }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    98
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    99
        public int compareTo(Object o) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   100
            return version.compareTo(((IVersion) o).getVersionString());
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   101
        }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   102
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   103
        public String getVersionString() {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   104
            return version;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   105
        }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   106
    }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   107
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   108
    private final Map<String, Collection<VersionedEntry<Map<String, Collection<VersionedEntry<IFacetIncludePathProvider[]>>>>>> providers = new HashMap<String, Collection<VersionedEntry<Map<String, Collection<VersionedEntry<IFacetIncludePathProvider[]>>>>>>();
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   109
    private final boolean ready = false;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   110
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   111
    public IIncludePathEntry[] getProjectClasspathEntries(IFacetedProject project) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   112
        collectProviders();
468
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 463
diff changeset
   113
        final ITMWProject p = TMWCore.create(project.getProject());
461
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   114
        if (p != null) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   115
            final IMobileWebRuntime runtime = p.getTargetRuntime();
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   116
            final Map<String, Collection<VersionedEntry<IFacetIncludePathProvider[]>>> facetToEntry;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   117
            if (runtime != null) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   118
                facetToEntry = join(getMatchingEntries(runtime.getId(), runtime.getVersion(), providers));
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   119
            } else {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   120
                facetToEntry = join(getMatchingEntries(null, null, providers));
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   121
            }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   122
            final Collection<IFacetIncludePathProvider[]> entries = getMatchingEntries(null, null, facetToEntry);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   123
            final Set<IProjectFacetVersion> facets = project.getProjectFacets();
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   124
            for (IProjectFacetVersion facet : facets) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   125
                entries.addAll(getMatchingEntries(facet.getProjectFacet().getId(), facet.getVersionString(),
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   126
                        facetToEntry));
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   127
            }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   128
            final Collection<IIncludePathEntry> pathEntries = new HashSet<IIncludePathEntry>();
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   129
            for (IFacetIncludePathProvider[] providers : entries) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   130
                for (IFacetIncludePathProvider provider : providers) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   131
                    pathEntries.addAll(Arrays.asList(provider.getEntries(p)));
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   132
                }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   133
            }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   134
            return pathEntries.toArray(new IIncludePathEntry[pathEntries.size()]);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   135
        }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   136
        return new IIncludePathEntry[0];
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   137
    }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   138
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   139
    @SuppressWarnings({ "rawtypes", "unchecked" })
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   140
    private synchronized void collectProviders() {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   141
        if (!ready) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   142
            final IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   143
                    TMWCore.PLUGIN_ID, "runtimeIncludePath");
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   144
            final Map<String, Collection<VersionedEntry<IFacetIncludePathProvider[]>>> entries = collectFaceletEntries(elements);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   145
            final VersionedEntry<Map<String, Collection<VersionedEntry<IFacetIncludePathProvider[]>>>> entry = new VersionedEntry(
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   146
                    null, entries);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   147
            providers.put(null, Collections.singleton(entry));
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   148
            for (IConfigurationElement element : elements) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   149
                if ("runtime-include-path".equals(element.getName())) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   150
                    final String id = element.getAttribute("id");
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   151
                    Collection<VersionedEntry<Map<String, Collection<VersionedEntry<IFacetIncludePathProvider[]>>>>> versions = providers
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   152
                            .get(id);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   153
                    if (versions == null) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   154
                        versions = new LinkedList<RuntimeClasspathManager.VersionedEntry<Map<String, Collection<VersionedEntry<IFacetIncludePathProvider[]>>>>>();
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   155
                        providers.put(id, versions);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   156
                    }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   157
                    final Map<String, Collection<VersionedEntry<IFacetIncludePathProvider[]>>> facetProviders = new HashMap<String, Collection<VersionedEntry<IFacetIncludePathProvider[]>>>();
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   158
                    final IFacetIncludePathProvider[] collection = collectProviders(element.getChildren());
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   159
                    final VersionedEntry<IFacetIncludePathProvider[]> ent = new VersionedEntry(null, collection);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   160
                    facetProviders.put(null, Collections.singleton(ent));
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   161
                    facetProviders.putAll(collectFaceletEntries(element.getChildren()));
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   162
                    final VersionedEntry<Map<String, Collection<VersionedEntry<IFacetIncludePathProvider[]>>>> ver = new VersionedEntry<Map<String, Collection<VersionedEntry<IFacetIncludePathProvider[]>>>>(
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   163
                            element.getAttribute("version"), facetProviders);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   164
                    versions.add(ver);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   165
                }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   166
            }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   167
        }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   168
    }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   169
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   170
    private IFacetIncludePathProvider[] collectProviders(IConfigurationElement[] children) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   171
        final Collection<IFacetIncludePathProvider> providers = new LinkedList<IFacetIncludePathProvider>();
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   172
        for (IConfigurationElement element : children) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   173
            if ("include-path-entry".equals(element.getName())) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   174
                providers.add(new StaticIncludePathProvider(element));
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   175
            } else if ("include-path-provider".equals(element.getName())) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   176
                providers.add(new LazyIncludePathProvider(element));
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   177
            }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   178
        }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   179
        return providers.toArray(new IFacetIncludePathProvider[providers.size()]);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   180
    }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   181
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   182
    public Map<String, Collection<VersionedEntry<IFacetIncludePathProvider[]>>> collectFaceletEntries(
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   183
            IConfigurationElement[] elements) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   184
        final Map<String, Collection<VersionedEntry<IFacetIncludePathProvider[]>>> faceletsToProviders = new HashMap<String, Collection<VersionedEntry<IFacetIncludePathProvider[]>>>();
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   185
        for (IConfigurationElement element : elements) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   186
            if ("facet-include-path".equals(element.getName())) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   187
                final IFacetIncludePathProvider[] providers = collectProviders(element.getChildren());
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   188
                final VersionedEntry<IFacetIncludePathProvider[]> versionedEntry = new VersionedEntry<IFacetIncludePathProvider[]>(
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   189
                        element.getAttribute("version"), providers);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   190
                final String id = element.getAttribute("facelet-id");
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   191
                Collection<VersionedEntry<IFacetIncludePathProvider[]>> provs = faceletsToProviders.get(id);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   192
                if (provs == null) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   193
                    provs = new LinkedList<RuntimeClasspathManager.VersionedEntry<IFacetIncludePathProvider[]>>();
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   194
                    faceletsToProviders.put(id, provs);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   195
                }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   196
                provs.add(versionedEntry);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   197
            }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   198
        }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   199
        return faceletsToProviders;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   200
    }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   201
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   202
    private <T, V> Map<T, Collection<V>> join(Collection<Map<T, Collection<V>>> maps) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   203
        final Map<T, Collection<V>> res = new HashMap<T, Collection<V>>();
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   204
        for (Map<T, Collection<V>> map : maps) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   205
            for (Map.Entry<T, Collection<V>> entry : map.entrySet()) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   206
                if (res.containsKey(entry.getKey())) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   207
                    res.get(entry.getKey()).addAll(entry.getValue());
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   208
                } else {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   209
                    res.put(entry.getKey(), new LinkedList<V>(entry.getValue()));
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   210
                }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   211
            }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   212
        }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   213
        return res;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   214
    }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   215
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   216
    private <T> Collection<T> getMatchingEntries(String id, String version,
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   217
            Map<String, Collection<VersionedEntry<T>>> map) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   218
        final Collection<VersionedEntry<T>> entries = new LinkedList<VersionedEntry<T>>();
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   219
        Collection<VersionedEntry<T>> versionedEntries = map.get(null);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   220
        if (versionedEntries != null) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   221
            entries.addAll(versionedEntries);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   222
        }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   223
        if (id != null) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   224
            versionedEntries = map.get(id);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   225
            if (versionedEntries != null) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   226
                entries.addAll(versionedEntries);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   227
            }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   228
        }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   229
        final Collection<T> res = new LinkedList<T>();
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   230
        for (VersionedEntry<T> versionedEntry : entries) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   231
            if (versionedEntry.matches(version)) {
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   232
                res.add(versionedEntry.entry);
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   233
            }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   234
        }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   235
        return res;
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   236
    }
7a8f9fa8d278 Project model introduction and JSDT classpath support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   237
}