OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 package com.google.dart.tools.core.internal.analysis.model; | 14 package com.google.dart.tools.core.internal.analysis.model; |
15 | 15 |
16 import com.google.dart.engine.context.AnalysisContext; | 16 import com.google.dart.engine.context.AnalysisContext; |
17 import com.google.dart.engine.element.LibraryElement; | 17 import com.google.dart.engine.element.LibraryElement; |
18 import com.google.dart.engine.index.Index; | 18 import com.google.dart.engine.index.Index; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 private MockProject projectContainer; | 75 private MockProject projectContainer; |
76 private MockFolder webContainer; | 76 private MockFolder webContainer; |
77 private MockFolder subContainer; | 77 private MockFolder subContainer; |
78 private MockFolder appContainer; | 78 private MockFolder appContainer; |
79 private MockFolder subAppContainer; | 79 private MockFolder subAppContainer; |
80 private File[] packageRoots = new File[0]; | 80 private File[] packageRoots = new File[0]; |
81 | 81 |
82 private Index index; | 82 private Index index; |
83 | 83 |
84 public void assertUriResolvedToPackageRoot(Project project, IPath expectedPack
ageRoot) { | 84 public void assertUriResolvedToPackageRoot(Project project, IPath expectedPack
ageRoot) { |
85 IPath expected = expectedPackageRoot != null ? expectedPackageRoot.append("f
oo").append( | 85 IPath expected = expectedPackageRoot != null ? expectedPackageRoot.append("f
oo") |
86 "foo.dart") : null; | 86 .append("foo.dart") : null; |
87 | 87 |
88 SourceFactory factory = project.getDefaultContext().getSourceFactory(); | 88 SourceFactory factory = project.getDefaultContext().getSourceFactory(); |
89 Source source = factory.forUri("package:foo/foo.dart"); | 89 Source source = factory.forUri("package:foo/foo.dart"); |
90 IPath actual = new Path(source.getFullName()); | 90 IPath actual = new Path(source.getFullName()); |
91 | 91 |
92 assertEquals(expected.setDevice(null), actual.setDevice(null)); | 92 assertEquals(expected.setDevice(null), actual.setDevice(null)); |
93 } | 93 } |
94 | 94 |
95 public void test_AnalysisContextFactory() throws Exception { | 95 public void test_AnalysisContextFactory() throws Exception { |
96 AnalysisContextFactory contextFactory = new AnalysisContextFactory(); | 96 AnalysisContextFactory contextFactory = new AnalysisContextFactory(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 MockFolder folder = projectContainer.getMockFolder("web"); | 206 MockFolder folder = projectContainer.getMockFolder("web"); |
207 MockFile file = new MockFile(folder, "libraryA.dart", "library libraryA;\n\n
main(){}"); | 207 MockFile file = new MockFile(folder, "libraryA.dart", "library libraryA;\n\n
main(){}"); |
208 folder.add(file); | 208 folder.add(file); |
209 Source[] sources = project.getLibrarySources(); | 209 Source[] sources = project.getLibrarySources(); |
210 assertNotNull(sources); | 210 assertNotNull(sources); |
211 } | 211 } |
212 | 212 |
213 public void test_getMultiplePackageRoots_project() throws Exception { | 213 public void test_getMultiplePackageRoots_project() throws Exception { |
214 CmdLineOptions options = CmdLineOptions.parseCmdLine(new String[] {}); | 214 CmdLineOptions options = CmdLineOptions.parseCmdLine(new String[] {}); |
215 final IEclipsePreferences prefs = mock(IEclipsePreferences.class); | 215 final IEclipsePreferences prefs = mock(IEclipsePreferences.class); |
216 when(prefs.get(DartCore.PROJECT_PREF_PACKAGE_ROOT, "")).thenReturn( | 216 when(prefs.get(DartCore.PROJECT_PREF_PACKAGE_ROOT, "")) |
217 "bar" + File.pathSeparator + "foo"); | 217 .thenReturn("bar" + File.pathSeparator + "foo"); |
218 final DartCore core = mock(DartCore.class); | 218 final DartCore core = mock(DartCore.class); |
219 when(core.getProjectPreferences(projectContainer)).thenReturn(prefs); | 219 when(core.getProjectPreferences(projectContainer)).thenReturn(prefs); |
220 | 220 |
221 File[] roots = ProjectImpl.getPackageRoots(core, options, projectContainer); | 221 File[] roots = ProjectImpl.getPackageRoots(core, options, projectContainer); |
222 assertNotNull(roots); | 222 assertNotNull(roots); |
223 assertEquals(2, roots.length); | 223 assertEquals(2, roots.length); |
224 assertEquals("bar", roots[0].getName()); | 224 assertEquals("bar", roots[0].getName()); |
225 assertEquals("foo", roots[1].getName()); | 225 assertEquals("foo", roots[1].getName()); |
226 } | 226 } |
227 | 227 |
228 public void test_getPackageRoots() throws Exception { | 228 public void test_getPackageRoots() throws Exception { |
229 CmdLineOptions options = CmdLineOptions.parseCmdLine(new String[] {}); | 229 CmdLineOptions options = CmdLineOptions.parseCmdLine(new String[] {}); |
230 DartCore core = DartCore.getPlugin(); | 230 DartCore core = DartCore.getPlugin(); |
231 | 231 |
232 File[] roots = ProjectImpl.getPackageRoots(core, options, projectContainer); | 232 File[] roots = ProjectImpl.getPackageRoots(core, options, projectContainer); |
233 assertNotNull(roots); | 233 assertNotNull(roots); |
234 assertEquals(0, roots.length); | 234 assertEquals(0, roots.length); |
235 } | 235 } |
236 | 236 |
237 public void test_getPackageRoots_global() throws Exception { | 237 public void test_getPackageRoots_global() throws Exception { |
238 CmdLineOptions options = CmdLineOptions.parseCmdLine(new String[] { | 238 CmdLineOptions options = CmdLineOptions.parseCmdLine( |
239 "--package-root", "foo", "bar"}); | 239 new String[] {"--package-root", "foo", "bar"}); |
240 DartCore core = DartCore.getPlugin(); | 240 DartCore core = DartCore.getPlugin(); |
241 | 241 |
242 File[] roots = ProjectImpl.getPackageRoots(core, options, projectContainer); | 242 File[] roots = ProjectImpl.getPackageRoots(core, options, projectContainer); |
243 assertNotNull(roots); | 243 assertNotNull(roots); |
244 assertEquals(2, roots.length); | 244 assertEquals(2, roots.length); |
245 assertEquals("foo", roots[0].getName()); | 245 assertEquals("foo", roots[0].getName()); |
246 assertEquals("bar", roots[1].getName()); | 246 assertEquals("bar", roots[1].getName()); |
247 } | 247 } |
248 | 248 |
249 public void test_getPackageRoots_project() throws Exception { | 249 public void test_getPackageRoots_project() throws Exception { |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 project, | 539 project, |
540 projectContainer.getLocation().append(PACKAGES_DIRECTORY_NAME)); | 540 projectContainer.getLocation().append(PACKAGES_DIRECTORY_NAME)); |
541 | 541 |
542 projectContainer.remove(PUBSPEC_FILE_NAME); | 542 projectContainer.remove(PUBSPEC_FILE_NAME); |
543 project.pubspecRemoved(projectContainer); | 543 project.pubspecRemoved(projectContainer); |
544 | 544 |
545 assertEquals(0, project.getPubFolders().length); | 545 assertEquals(0, project.getPubFolders().length); |
546 assertUriResolvedToPackageRoot(project, new Path(packageRoots[0].getPath()))
; | 546 assertUriResolvedToPackageRoot(project, new Path(packageRoots[0].getPath()))
; |
547 } | 547 } |
548 | 548 |
| 549 public void test_resolvePathToPackage() { |
| 550 ProjectImpl project = newTarget(); |
| 551 //TODO(keertip): implement project with ExplicitUriResolver and package map |
| 552 // use that to verify path to package |
| 553 } |
| 554 |
549 public void test_resolveUriTofileInfoFile() throws IOException { | 555 public void test_resolveUriTofileInfoFile() throws IOException { |
550 projectContainer.remove(PUBSPEC_FILE_NAME); | 556 projectContainer.remove(PUBSPEC_FILE_NAME); |
551 File parent = projectContainer.getLocation().toFile().getParentFile(); | 557 File parent = projectContainer.getLocation().toFile().getParentFile(); |
552 File packages = new File(parent, "packagesRoot"); | 558 File packages = new File(parent, "packagesRoot"); |
553 File dartFile = new File(packages, "bar/foo.dart"); | 559 File dartFile = new File(packages, "bar/foo.dart"); |
554 FileUtilities.create(dartFile); | 560 FileUtilities.create(dartFile); |
555 | 561 |
556 final IEclipsePreferences prefs = mock(IEclipsePreferences.class); | 562 final IEclipsePreferences prefs = mock(IEclipsePreferences.class); |
557 when(prefs.get(DartCore.PROJECT_PREF_PACKAGE_ROOT, "")).thenReturn(packages.
getAbsolutePath()); | 563 when(prefs.get(DartCore.PROJECT_PREF_PACKAGE_ROOT, "")).thenReturn(packages.
getAbsolutePath()); |
558 final DartCore core = mock(DartCore.class); | 564 final DartCore core = mock(DartCore.class); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 assertEquals("doesNotExist3", parent3.getName()); | 657 assertEquals("doesNotExist3", parent3.getName()); |
652 } | 658 } |
653 | 659 |
654 private void assertUriDoesNotResolve(Project project) { | 660 private void assertUriDoesNotResolve(Project project) { |
655 SourceFactory factory = project.getDefaultContext().getSourceFactory(); | 661 SourceFactory factory = project.getDefaultContext().getSourceFactory(); |
656 Source source = factory.forUri("package:foo/foo.dart"); | 662 Source source = factory.forUri("package:foo/foo.dart"); |
657 assertNotNull(source); | 663 assertNotNull(source); |
658 assertFalse(new File(source.getFullName()).exists()); | 664 assertFalse(new File(source.getFullName()).exists()); |
659 } | 665 } |
660 } | 666 } |
OLD | NEW |