Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: pkg/code_transformers/lib/assets.dart

Issue 221673005: Use warning instead of error in a couple places. In polymer we are hitting (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/code_transformers/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Common methods used by transfomers for dealing with asset IDs. 5 /// Common methods used by transfomers for dealing with asset IDs.
6 library code_transformers.assets; 6 library code_transformers.assets;
7 7
8 import 'dart:math' show min, max; 8 import 'dart:math' show min, max;
9 9
10 import 'package:barback/barback.dart'; 10 import 'package:barback/barback.dart';
11 import 'package:path/path.dart' as path; 11 import 'package:path/path.dart' as path;
12 import 'package:source_maps/span.dart' show Span; 12 import 'package:source_maps/span.dart' show Span;
13 13
14 /// Create an [AssetId] for a [url] seen in the [source] asset. By default this 14 /// Create an [AssetId] for a [url] seen in the [source] asset.
15 /// is used to resolve relative urls that occur in HTML assets, including 15 ///
16 /// cross-package urls of the form "packages/foo/bar.html". Dart "package:" 16 /// By default this is used to resolve relative urls that occur in HTML assets,
17 /// urls are not resolved unless [source] is Dart file (has a .dart extension). 17 /// including cross-package urls of the form "packages/foo/bar.html". Dart
18 /// "package:" urls are not resolved unless [source] is Dart file (has a .dart
19 /// extension).
20 ///
21 /// This function returns null if [url] can't be resolved. We log a warning
22 /// message in [logger] if we know the reason why resolution failed. This
23 /// happens, for example, when using incorrect paths to reach into another
24 /// package, or when [errorsOnAbsolute] is true and the url seems to be
25 /// absolute.
18 // TODO(sigmund): delete once this is part of barback (dartbug.com/12610) 26 // TODO(sigmund): delete once this is part of barback (dartbug.com/12610)
19 AssetId uriToAssetId(AssetId source, String url, TransformLogger logger, 27 AssetId uriToAssetId(AssetId source, String url, TransformLogger logger,
20 Span span, {bool errorOnAbsolute: true}) { 28 Span span, {bool errorOnAbsolute: true}) {
21 if (url == null || url == '') return null; 29 if (url == null || url == '') return null;
22 var uri = Uri.parse(url); 30 var uri = Uri.parse(url);
23 var urlBuilder = path.url; 31 var urlBuilder = path.url;
24 if (uri.host != '' || uri.scheme != '' || urlBuilder.isAbsolute(url)) { 32 if (uri.host != '' || uri.scheme != '' || urlBuilder.isAbsolute(url)) {
25 if (source.extension == '.dart' && uri.scheme == 'package') { 33 if (source.extension == '.dart' && uri.scheme == 'package') {
26 var index = uri.path.indexOf('/'); 34 var index = uri.path.indexOf('/');
27 if (index != -1) { 35 if (index != -1) {
28 return new AssetId(uri.path.substring(0, index), 36 return new AssetId(uri.path.substring(0, index),
29 'lib${uri.path.substring(index)}'); 37 'lib${uri.path.substring(index)}');
30 } 38 }
31 } 39 }
32 40
33 if (errorOnAbsolute) { 41 if (errorOnAbsolute) {
34 logger.error('absolute paths not allowed: "$url"', span: span); 42 logger.warning('absolute paths not allowed: "$url"', span: span);
35 } 43 }
36 return null; 44 return null;
37 } 45 }
38 46
39 var targetPath = urlBuilder.normalize( 47 var targetPath = urlBuilder.normalize(
40 urlBuilder.join(urlBuilder.dirname(source.path), url)); 48 urlBuilder.join(urlBuilder.dirname(source.path), url));
41 var segments = urlBuilder.split(targetPath); 49 var segments = urlBuilder.split(targetPath);
42 var sourceSegments = urlBuilder.split(source.path); 50 var sourceSegments = urlBuilder.split(source.path);
43 assert (sourceSegments.length > 0); 51 assert (sourceSegments.length > 0);
44 var topFolder = sourceSegments[0]; 52 var topFolder = sourceSegments[0];
(...skipping 19 matching lines...) Expand all
64 // folder lives (otherwise the app would not work in Dartium). Since 72 // folder lives (otherwise the app would not work in Dartium). Since
65 // [targetPath] has been normalized, "packages" or "assets" should be at 73 // [targetPath] has been normalized, "packages" or "assets" should be at
66 // index 1. 74 // index 1.
67 return _extractOtherPackageId(1, segments, logger, span); 75 return _extractOtherPackageId(1, segments, logger, span);
68 } else { 76 } else {
69 var prefix = segments[index]; 77 var prefix = segments[index];
70 var fixedSegments = []; 78 var fixedSegments = [];
71 fixedSegments.addAll(sourceSegments.map((_) => '..')); 79 fixedSegments.addAll(sourceSegments.map((_) => '..'));
72 fixedSegments.addAll(segments.sublist(index)); 80 fixedSegments.addAll(segments.sublist(index));
73 var fixedUrl = urlBuilder.joinAll(fixedSegments); 81 var fixedUrl = urlBuilder.joinAll(fixedSegments);
74 logger.error('Invalid url to reach to another package: $url. Path ' 82 logger.warning('Invalid url to reach to another package: $url. Path '
75 'reaching to other packages must first reach up all the ' 83 'reaching to other packages must first reach up all the '
76 'way to the $prefix folder. For example, try changing the url above ' 84 'way to the $prefix folder. For example, try changing the url above '
77 'to: $fixedUrl', span: span); 85 'to: $fixedUrl', span: span);
78 return null; 86 return null;
79 } 87 }
80 } 88 }
81 89
82 // Otherwise, resolve as a path in the same package. 90 // Otherwise, resolve as a path in the same package.
83 return new AssetId(source.package, targetPath); 91 return new AssetId(source.package, targetPath);
84 } 92 }
85 93
86 AssetId _extractOtherPackageId(int index, List segments, 94 AssetId _extractOtherPackageId(int index, List segments,
87 TransformLogger logger, Span span) { 95 TransformLogger logger, Span span) {
88 if (index >= segments.length) return null; 96 if (index >= segments.length) return null;
89 var prefix = segments[index]; 97 var prefix = segments[index];
90 if (prefix != 'packages' && prefix != 'assets') return null; 98 if (prefix != 'packages' && prefix != 'assets') return null;
91 var folder = prefix == 'packages' ? 'lib' : 'asset'; 99 var folder = prefix == 'packages' ? 'lib' : 'asset';
92 if (segments.length < index + 3) { 100 if (segments.length < index + 3) {
93 logger.error("incomplete $prefix/ path. It should have at least 3 " 101 logger.warning("incomplete $prefix/ path. It should have at least 3 "
94 "segments $prefix/name/path-from-name's-$folder-dir", span: span); 102 "segments $prefix/name/path-from-name's-$folder-dir", span: span);
95 return null; 103 return null;
96 } 104 }
97 return new AssetId(segments[index + 1], 105 return new AssetId(segments[index + 1],
98 path.url.join(folder, path.url.joinAll(segments.sublist(index + 2)))); 106 path.url.join(folder, path.url.joinAll(segments.sublist(index + 2))));
99 } 107 }
OLDNEW
« no previous file with comments | « no previous file | pkg/code_transformers/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698