OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014, the Dart project authors. | 2 * Copyright (c) 2014, 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 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 97 } |
98 | 98 |
99 @Override | 99 @Override |
100 public String getUrlForResource(IResource resource) { | 100 public String getUrlForResource(IResource resource) { |
101 | 101 |
102 String url = resourceToUrl.get(resource.getFullPath().toString()); | 102 String url = resourceToUrl.get(resource.getFullPath().toString()); |
103 if (url != null) { | 103 if (url != null) { |
104 return url; | 104 return url; |
105 } | 105 } |
106 | 106 |
107 CountDownLatch latch = new CountDownLatch(1); | |
108 final String[] done = new String[1]; | 107 final String[] done = new String[1]; |
109 | 108 |
110 try { | 109 if (PubServeManager.getManager().isServing()) { |
111 PubServeManager.getManager().sendGetUrlCommand(resource, new UrlForFileCal
lback(latch, done)); | 110 CountDownLatch latch = new CountDownLatch(1); |
112 } catch (IOException e) { | 111 try { |
113 DartCore.logError(e); | 112 PubServeManager.getManager().sendGetUrlCommand( |
114 return done[0]; | 113 resource, |
115 } | 114 new UrlForFileCallback(latch, done)); |
116 try { | 115 } catch (IOException e) { |
117 latch.await(5000, TimeUnit.MILLISECONDS); | 116 DartCore.logError(e); |
118 } catch (InterruptedException e) { | 117 return done[0]; |
119 // do nothing | 118 } |
120 } | 119 try { |
121 if (done[0] != null) { | 120 latch.await(3000, TimeUnit.MILLISECONDS); |
122 resourceToUrl.put(resource.getFullPath().toString(), done[0]); | 121 } catch (InterruptedException e) { |
| 122 // do nothing |
| 123 } |
| 124 if (done[0] != null) { |
| 125 resourceToUrl.put(resource.getFullPath().toString(), done[0]); |
| 126 } |
123 } | 127 } |
124 return done[0]; | 128 return done[0]; |
125 } | 129 } |
126 | 130 |
127 @Override | 131 @Override |
128 public String getUrlRegexForResource(IResource resource) { | 132 public String getUrlRegexForResource(IResource resource) { |
129 IContainer appDir = DartCore.getApplicationDirectory(resource); | 133 IContainer appDir = DartCore.getApplicationDirectory(resource); |
130 // remove till application directory | 134 // remove till application directory |
131 // L/sample/web/sample.dart => web/sample.dart | 135 // L/sample/web/sample.dart => web/sample.dart |
132 | 136 |
(...skipping 18 matching lines...) Expand all Loading... |
151 } | 155 } |
152 | 156 |
153 @Override | 157 @Override |
154 public IResource resolveUrl(String url) { | 158 public IResource resolveUrl(String url) { |
155 | 159 |
156 String assetId = urlToAsset.get(url); | 160 String assetId = urlToAsset.get(url); |
157 if (assetId != null) { | 161 if (assetId != null) { |
158 return getResourceForPath(assetId); | 162 return getResourceForPath(assetId); |
159 } | 163 } |
160 | 164 |
161 CountDownLatch latch = new CountDownLatch(1); | 165 if (PubServeManager.getManager().isServing()) { |
162 final String[] name = new String[1]; | |
163 final String[] path = new String[1]; | |
164 | 166 |
165 try { | 167 CountDownLatch latch = new CountDownLatch(1); |
166 PubServeManager.getManager().sendGetAssetIdCommand( | 168 final String[] name = new String[1]; |
167 url, | 169 final String[] path = new String[1]; |
168 new FilePathForUrlCallback(latch, name, path)); | 170 |
169 } catch (IOException e) { | 171 try { |
170 DartCore.logError(e); | 172 PubServeManager.getManager().sendGetAssetIdCommand( |
171 return null; | 173 url, |
172 } | 174 new FilePathForUrlCallback(latch, name, path)); |
173 try { | 175 } catch (IOException e) { |
174 latch.await(5000, TimeUnit.MILLISECONDS); | 176 DartCore.logError(e); |
175 } catch (InterruptedException e) { | 177 return null; |
176 // do nothing | 178 } |
177 } | 179 try { |
178 if (path[0] != null) { | 180 latch.await(3000, TimeUnit.MILLISECONDS); |
179 urlToAsset.put(url, path[0]); | 181 } catch (InterruptedException e) { |
180 return getResourceForPath(path[0]); | 182 // do nothing |
| 183 } |
| 184 if (path[0] != null) { |
| 185 urlToAsset.put(url, path[0]); |
| 186 return getResourceForPath(path[0]); |
| 187 } |
181 } | 188 } |
182 return null; | 189 return null; |
183 } | 190 } |
184 | 191 |
185 private IResource getResourceForPath(final String path) { | 192 private IResource getResourceForPath(final String path) { |
186 IContainer appDir = PubServeManager.getManager().getCurrentServeWorkingDir()
; | 193 IContainer appDir = PubServeManager.getManager().getCurrentServeWorkingDir()
; |
187 // TODO(keertip): check if appdir has pubfolder with same pubspec name | 194 // TODO(keertip): check if appdir has pubfolder with same pubspec name |
188 IResource resource = appDir.findMember(path); | 195 IResource resource = appDir.findMember(path); |
189 return resource; | 196 return resource; |
190 } | 197 } |
191 | 198 |
192 } | 199 } |
OLD | NEW |