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

Side by Side Diff: pkg/analyzer/lib/src/task/general.dart

Issue 2050573003: Issue 26629. Detect cache inconsistency in GetContentTask. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library analyzer.src.task.general; 5 library analyzer.src.task.general;
6 6
7 import 'package:analyzer/src/context/cache.dart';
7 import 'package:analyzer/src/generated/engine.dart'; 8 import 'package:analyzer/src/generated/engine.dart';
8 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
9 import 'package:analyzer/task/general.dart'; 10 import 'package:analyzer/task/general.dart';
10 import 'package:analyzer/task/model.dart'; 11 import 'package:analyzer/task/model.dart';
11 12
12 /** 13 /**
13 * A task that gets the contents of the source associated with an analysis 14 * A task that gets the contents of the source associated with an analysis
14 * target. 15 * target.
15 */ 16 */
16 class GetContentTask extends SourceBasedAnalysisTask { 17 class GetContentTask extends SourceBasedAnalysisTask {
17 /** 18 /**
18 * The task descriptor describing this kind of task. 19 * The task descriptor describing this kind of task.
19 */ 20 */
20 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('GetContentTask', 21 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('GetContentTask',
21 createTask, buildInputs, <ResultDescriptor>[CONTENT, MODIFICATION_TIME]); 22 createTask, buildInputs, <ResultDescriptor>[CONTENT, MODIFICATION_TIME]);
22 23
23 /** 24 /**
24 * Initialize a newly created task to access the content of the source 25 * Initialize a newly created task to access the content of the source
25 * associated with the given [target] in the given [context]. 26 * associated with the given [target] in the given [context].
26 */ 27 */
27 GetContentTask(AnalysisContext context, AnalysisTarget target) 28 GetContentTask(AnalysisContext context, AnalysisTarget target)
28 : super(context, target); 29 : super(context, target);
29 30
30 @override 31 @override
31 TaskDescriptor get descriptor => DESCRIPTOR; 32 TaskDescriptor get descriptor => DESCRIPTOR;
32 33
33 @override 34 @override
34 internalPerform() { 35 internalPerform() {
35 Source source = getRequiredSource(); 36 Source source = getRequiredSource();
37 String content;
38 int modificationTime;
36 try { 39 try {
37 TimestampedData<String> data = context.getContents(source); 40 TimestampedData<String> data = context.getContents(source);
38 outputs[CONTENT] = data.data; 41 content = data.data;
39 outputs[MODIFICATION_TIME] = data.modificationTime; 42 modificationTime = data.modificationTime;
40 } catch (exception) { 43 } catch (exception) {
41 outputs[CONTENT] = ''; 44 content = '';
42 outputs[MODIFICATION_TIME] = -1; 45 modificationTime = -1;
46 }
47 outputs[CONTENT] = content;
48 outputs[MODIFICATION_TIME] = modificationTime;
49 _validateModificationTimeConsistency(modificationTime);
50 }
51
52 /**
53 * Validate that the [target] cache entry has the same modification time
54 * as the given. Otherwise throw a new [ModificationTimeMismatchError] and
55 * instruct to invalidate targets content.
56 */
57 void _validateModificationTimeConsistency(int modificationTime) {
58 AnalysisContext context = this.context;
59 if (context is InternalAnalysisContext) {
60 CacheEntry entry = context.getCacheEntry(target);
61 if (entry != null && entry.modificationTime != modificationTime) {
62 entry.modificationTime = modificationTime;
63 entry.setState(CONTENT, CacheState.INVALID);
64 entry.setState(MODIFICATION_TIME, CacheState.INVALID);
65 throw new ModificationTimeMismatchError(target);
66 }
43 } 67 }
44 } 68 }
45 69
46 /** 70 /**
47 * Return a map from the names of the inputs of this kind of task to the task 71 * Return a map from the names of the inputs of this kind of task to the task
48 * input descriptors describing those inputs for a task with the given [target ]. 72 * input descriptors describing those inputs for a task with the given [target ].
49 */ 73 */
50 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 74 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
51 return <String, TaskInput>{}; 75 return <String, TaskInput>{};
52 } 76 }
(...skipping 19 matching lines...) Expand all
72 SourceBasedAnalysisTask(AnalysisContext context, AnalysisTarget target) 96 SourceBasedAnalysisTask(AnalysisContext context, AnalysisTarget target)
73 : super(context, target); 97 : super(context, target);
74 98
75 @override 99 @override
76 String get description { 100 String get description {
77 Source source = target.source; 101 Source source = target.source;
78 String sourceName = source == null ? '<unknown source>' : source.fullName; 102 String sourceName = source == null ? '<unknown source>' : source.fullName;
79 return '${descriptor.name} for source $sourceName'; 103 return '${descriptor.name} for source $sourceName';
80 } 104 }
81 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698