17 * Failures and causes: |
17 * Failures and causes: |
18 */ |
18 */ |
19 package org.symbian.tools.tmw.core.internal.facets; |
19 package org.symbian.tools.tmw.core.internal.facets; |
20 |
20 |
21 import java.util.HashSet; |
21 import java.util.HashSet; |
|
22 import java.util.List; |
|
23 import java.util.Map; |
|
24 import java.util.Map.Entry; |
22 import java.util.Set; |
25 import java.util.Set; |
23 |
26 |
24 import org.eclipse.core.runtime.CoreException; |
27 import org.eclipse.core.runtime.CoreException; |
25 import org.eclipse.wst.common.project.facet.core.IProjectFacet; |
28 import org.eclipse.wst.common.project.facet.core.IProjectFacet; |
26 import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; |
29 import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; |
27 import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; |
30 import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; |
28 import org.eclipse.wst.common.project.facet.core.VersionFormatException; |
31 import org.eclipse.wst.common.project.facet.core.VersionFormatException; |
29 import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; |
32 import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; |
|
33 import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponent; |
|
34 import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentVersion; |
30 import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager; |
35 import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager; |
|
36 import org.symbian.tools.tmw.core.TMWCore; |
31 import org.symbian.tools.tmw.core.projects.IFProjSupport; |
37 import org.symbian.tools.tmw.core.projects.IFProjSupport; |
32 import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; |
38 import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; |
33 |
39 |
34 public final class FProjSupportImpl implements IFProjSupport { |
40 public final class FProjSupportImpl implements IFProjSupport { |
35 public IRuntime getRuntime(IMobileWebRuntime runtime) { |
41 public IRuntime getRuntime(IMobileWebRuntime runtime) { |
44 return facets; |
50 return facets; |
45 } |
51 } |
46 |
52 |
47 private IProjectFacetVersion getFacet(String id, String version) { |
53 private IProjectFacetVersion getFacet(String id, String version) { |
48 final IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet(id); |
54 final IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet(id); |
|
55 if (projectFacet == null) { |
|
56 TMWCore.log("Facet %s version %s was not found", id, version); |
|
57 return null; |
|
58 } |
49 try { |
59 try { |
50 return version != null ? projectFacet.getVersion(version) : projectFacet.getLatestVersion(); |
60 return version != null ? projectFacet.getVersion(version) : projectFacet.getLatestVersion(); |
51 } catch (VersionFormatException e) { |
61 } catch (VersionFormatException e) { |
52 throw new RuntimeException(e); |
62 throw new RuntimeException(e); |
53 } catch (CoreException e) { |
63 } catch (CoreException e) { |
61 |
71 |
62 public Set<IProjectFacetVersion> getFixedFacetsVersions(IMobileWebRuntime runtime) { |
72 public Set<IProjectFacetVersion> getFixedFacetsVersions(IMobileWebRuntime runtime) { |
63 final Set<IProjectFacetVersion> facets = new HashSet<IProjectFacetVersion>(); |
73 final Set<IProjectFacetVersion> facets = new HashSet<IProjectFacetVersion>(); |
64 facets.add(getFacet("wst.jsdt.web", null)); |
74 facets.add(getFacet("wst.jsdt.web", null)); |
65 facets.add(getFacet("tmw.core", null)); |
75 facets.add(getFacet("tmw.core", null)); |
66 // facets.add(getFacet("wst.jsdt.web", "1.0")); |
76 final Map<String, String> fixedFacets = runtime.getFixedFacets(); |
|
77 for (Entry<String, String> entry : fixedFacets.entrySet()) { |
|
78 final IProjectFacetVersion facet = getFacet(entry.getKey(), entry.getValue()); |
|
79 if (facet != null) { |
|
80 facets.add(facet); |
|
81 } |
|
82 } |
67 return facets; |
83 return facets; |
68 } |
84 } |
69 |
85 |
70 public IProjectFacet getTMWFacet() { |
86 public IProjectFacet getTMWFacet() { |
71 return getFacet("tmw.core", null).getProjectFacet(); |
87 return getFacet("tmw.core", null).getProjectFacet(); |
72 } |
88 } |
|
89 |
|
90 public IMobileWebRuntime getTMWRuntime(IRuntime runtime) { |
|
91 if (runtime != null) { |
|
92 final List<IRuntimeComponent> components = runtime.getRuntimeComponents(); |
|
93 if (!components.isEmpty()) { |
|
94 final IRuntimeComponentVersion version = components.get(0).getRuntimeComponentVersion(); |
|
95 return TMWCore.getRuntimesManager().getRuntime(version.getRuntimeComponentType().getId(), |
|
96 version.getVersionString()); |
|
97 } |
|
98 } |
|
99 return null; |
|
100 } |
73 } |
101 } |