| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, 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.sdk.DartSdk; | 17 import com.google.dart.engine.sdk.DartSdk; |
| 18 import com.google.dart.engine.source.DirectoryBasedSourceContainer; | 18 import com.google.dart.engine.source.DirectoryBasedSourceContainer; |
| 19 import com.google.dart.engine.source.ExplicitPackageUriResolver; |
| 19 import com.google.dart.engine.source.Source; | 20 import com.google.dart.engine.source.Source; |
| 20 import com.google.dart.engine.source.SourceContainer; | 21 import com.google.dart.engine.source.SourceContainer; |
| 22 import com.google.dart.engine.source.UriResolver; |
| 21 import com.google.dart.tools.core.DartCore; | 23 import com.google.dart.tools.core.DartCore; |
| 22 import com.google.dart.tools.core.analysis.model.PubFolder; | 24 import com.google.dart.tools.core.analysis.model.PubFolder; |
| 23 import com.google.dart.tools.core.pub.PubspecModel; | 25 import com.google.dart.tools.core.pub.PubspecModel; |
| 24 | 26 |
| 25 import static com.google.dart.tools.core.DartCore.PUBSPEC_FILE_NAME; | 27 import static com.google.dart.tools.core.DartCore.PUBSPEC_FILE_NAME; |
| 26 import static com.google.dart.tools.core.utilities.io.FileUtilities.getContents; | 28 import static com.google.dart.tools.core.utilities.io.FileUtilities.getContents; |
| 27 | 29 |
| 28 import org.eclipse.core.resources.IContainer; | 30 import org.eclipse.core.resources.IContainer; |
| 29 import org.eclipse.core.resources.IFile; | 31 import org.eclipse.core.resources.IFile; |
| 30 import org.eclipse.core.resources.IFolder; | 32 import org.eclipse.core.resources.IFolder; |
| 31 import org.eclipse.core.runtime.CoreException; | 33 import org.eclipse.core.runtime.CoreException; |
| 32 import org.eclipse.core.runtime.Path; | 34 import org.eclipse.core.runtime.Path; |
| 33 | 35 |
| 34 import java.io.File; | 36 import java.io.File; |
| 35 import java.io.FileFilter; | 37 import java.io.FileFilter; |
| 36 import java.io.IOException; | 38 import java.io.IOException; |
| 37 import java.io.InputStreamReader; | 39 import java.io.InputStreamReader; |
| 38 import java.io.Reader; | 40 import java.io.Reader; |
| 39 import java.util.ArrayList; | 41 import java.util.ArrayList; |
| 40 import java.util.List; | 42 import java.util.List; |
| 41 | 43 |
| 42 /** | 44 /** |
| 43 * Represents a project or folder within a project containing a pubspec file. | 45 * Represents a project or folder within a project containing a pubspec file. |
| 44 * | 46 * |
| 45 * @coverage dart.tools.core.model | 47 * @coverage dart.tools.core.model |
| 46 */ | 48 */ |
| 47 public class PubFolderImpl extends PubResourceMapImpl implements PubFolder { | 49 public class PubFolderImpl extends PubResourceMapImpl implements PubFolder { |
| 48 | 50 |
| 49 /** | 51 /** |
| 50 * The Dart SDK used when constructing the context. | 52 * The Dart SDK used when constructing the context. |
| 51 */ | 53 */ |
| 52 private final DartSdk sdk; | 54 private final DartSdk sdk; |
| 53 | 55 |
| 54 /** | 56 /** |
| 55 * The pubspec model or {@code null} if it is not yet cached. | 57 * The pubspec model or {@code null} if it is not yet cached. |
| 56 */ | 58 */ |
| 57 private PubspecModel pubspec; | 59 private PubspecModel pubspec; |
| 58 | 60 |
| 59 public PubFolderImpl(IContainer container, AnalysisContext context, DartSdk sd
k) { | 61 /** |
| 62 * The package resolver used to resolve package: uris |
| 63 */ |
| 64 private UriResolver pkgResolver; |
| 65 |
| 66 public PubFolderImpl( |
| 67 IContainer container, AnalysisContext context, DartSdk sdk, UriResolver pk
gResolver) { |
| 60 super(container, context); | 68 super(container, context); |
| 61 this.sdk = sdk; | 69 this.sdk = sdk; |
| 70 this.pkgResolver = pkgResolver; |
| 62 } | 71 } |
| 63 | 72 |
| 64 @Override | 73 @Override |
| 65 public InvertedSourceContainer getInvertedSourceContainer() { | 74 public InvertedSourceContainer getInvertedSourceContainer() { |
| 66 return new InvertedSourceContainer(getSourceContainer()); | 75 return new InvertedSourceContainer(getSourceContainer()); |
| 67 } | 76 } |
| 68 | 77 |
| 69 @Override | 78 @Override |
| 70 public PubspecModel getPubspec() throws CoreException, IOException { | 79 public PubspecModel getPubspec() throws CoreException, IOException { |
| 71 if (pubspec == null) { | 80 if (pubspec == null) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 97 @Override | 106 @Override |
| 98 public DartSdk getSdk() { | 107 public DartSdk getSdk() { |
| 99 return sdk; | 108 return sdk; |
| 100 } | 109 } |
| 101 | 110 |
| 102 @Override | 111 @Override |
| 103 public void invalidatePubspec() throws IOException, CoreException { | 112 public void invalidatePubspec() throws IOException, CoreException { |
| 104 pubspec = null; | 113 pubspec = null; |
| 105 } | 114 } |
| 106 | 115 |
| 116 @Override |
| 117 public String resolvePathToPackage(String path) { |
| 118 if (pkgResolver instanceof ExplicitPackageUriResolver) { |
| 119 return ((ExplicitPackageUriResolver) pkgResolver).resolvePathToPackage(pat
h); |
| 120 } |
| 121 return null; |
| 122 } |
| 123 |
| 107 private CompositeSourceContainer getSourceContainer() { | 124 private CompositeSourceContainer getSourceContainer() { |
| 108 List<SourceContainer> containers = new ArrayList<SourceContainer>(); | 125 List<SourceContainer> containers = new ArrayList<SourceContainer>(); |
| 109 containers.add(new DirectoryBasedSourceContainer(container.getLocation().toF
ile())); | 126 containers.add(new DirectoryBasedSourceContainer(container.getLocation().toF
ile())); |
| 110 IFolder packagesFolder = container.getFolder(new Path(DartCore.PACKAGES_DIRE
CTORY_NAME)); | 127 IFolder packagesFolder = container.getFolder(new Path(DartCore.PACKAGES_DIRE
CTORY_NAME)); |
| 111 | 128 |
| 112 if (packagesFolder != null) { | 129 if (packagesFolder != null) { |
| 113 File packagesDir = packagesFolder.getLocation().toFile(); | 130 File packagesDir = packagesFolder.getLocation().toFile(); |
| 114 File[] packages = packagesDir.listFiles(new FileFilter() { | 131 File[] packages = packagesDir.listFiles(new FileFilter() { |
| 115 @Override | 132 @Override |
| 116 public boolean accept(File pathname) { | 133 public boolean accept(File pathname) { |
| 117 if (pathname.isDirectory()) { | 134 if (pathname.isDirectory()) { |
| 118 return true; | 135 return true; |
| 119 } | 136 } |
| 120 return false; | 137 return false; |
| 121 } | 138 } |
| 122 }); | 139 }); |
| 123 if (packages != null) { | 140 if (packages != null) { |
| 124 for (File file : packages) { | 141 for (File file : packages) { |
| 125 try { | 142 try { |
| 126 containers.add(new DirectoryBasedSourceContainer(file.getCanonicalFi
le())); | 143 containers.add(new DirectoryBasedSourceContainer(file.getCanonicalFi
le())); |
| 127 } catch (IOException e) { | 144 } catch (IOException e) { |
| 128 DartCore.logError(e); | 145 DartCore.logError(e); |
| 129 } | 146 } |
| 130 } | 147 } |
| 131 } | 148 } |
| 132 } | 149 } |
| 133 return new CompositeSourceContainer(containers); | 150 return new CompositeSourceContainer(containers); |
| 134 } | 151 } |
| 135 } | 152 } |
| OLD | NEW |