Lines 67-72
Link Here
|
67 |
|
67 |
|
68 |
private AntProjectHelper helper; |
68 |
private AntProjectHelper helper; |
69 |
private Map<FileObject,String> encodingsCache = null; // source folder -> encoding |
69 |
private Map<FileObject,String> encodingsCache = null; // source folder -> encoding |
|
|
70 |
private Charset projectEncoding = null; |
70 |
|
71 |
|
71 |
public FreeformFileEncodingQueryImpl(AntProjectHelper aph) { |
72 |
public FreeformFileEncodingQueryImpl(AntProjectHelper aph) { |
72 |
helper = aph; |
73 |
helper = aph; |
Lines 74-80
Link Here
|
74 |
|
75 |
|
75 |
public Charset getEncoding(FileObject file) { |
76 |
public Charset getEncoding(FileObject file) { |
76 |
synchronized (this) { |
77 |
synchronized (this) { |
77 |
if (encodingsCache == null) { |
78 |
if (encodingsCache == null || projectEncoding == null) { |
78 |
encodingsCache = computeEncodingsCache(); |
79 |
encodingsCache = computeEncodingsCache(); |
79 |
} |
80 |
} |
80 |
for (Iterator<Entry<FileObject,String>> iter = encodingsCache.entrySet().iterator(); iter.hasNext(); ) { |
81 |
for (Iterator<Entry<FileObject,String>> iter = encodingsCache.entrySet().iterator(); iter.hasNext(); ) { |
Lines 88-100
Link Here
|
88 |
} |
89 |
} |
89 |
} |
90 |
} |
90 |
} |
91 |
} |
|
|
92 |
// #120508: return projectEncoding for any file under project folder |
93 |
if (FileUtil.isParentOf(helper.getProjectDirectory(), file) && projectEncoding != null) { |
94 |
return projectEncoding; |
95 |
} |
91 |
} |
96 |
} |
92 |
// return null if no encoding for the file was found |
97 |
// return null if no encoding for the file was found or the file wasn't under project dir |
93 |
return null; |
98 |
return null; |
94 |
} |
99 |
} |
95 |
|
100 |
|
96 |
private Map<FileObject,String> computeEncodingsCache() { |
101 |
private Map<FileObject,String> computeEncodingsCache() { |
97 |
Element data = Util.getPrimaryConfigurationData(helper); |
102 |
Element data = Util.getPrimaryConfigurationData(helper); |
|
|
103 |
Element encodingEl = Util.findElement(data, "encoding", Util.NAMESPACE); // NOI18N |
104 |
if (encodingEl != null) { |
105 |
String encodingName = Util.findText(encodingEl); |
106 |
projectEncoding = (encodingName != null) ? Charset.forName(encodingName) : null; |
107 |
} |
98 |
Element foldersEl = Util.findElement(data, "folders", Util.NAMESPACE); // NOI18N |
108 |
Element foldersEl = Util.findElement(data, "folders", Util.NAMESPACE); // NOI18N |
99 |
if (foldersEl == null) { |
109 |
if (foldersEl == null) { |
100 |
return Collections.<FileObject,String>emptyMap(); |
110 |
return Collections.<FileObject,String>emptyMap(); |
Lines 128-133
Link Here
|
128 |
// invalidate cache |
138 |
// invalidate cache |
129 |
synchronized (this) { |
139 |
synchronized (this) { |
130 |
encodingsCache = null; |
140 |
encodingsCache = null; |
|
|
141 |
projectEncoding = null; |
131 |
} |
142 |
} |
132 |
} |
143 |
} |
133 |
|
144 |
|