This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 120508
Collapse All | Expand All

(-)src/org/netbeans/modules/ant/freeform/FreeformFileEncodingQueryImpl.java (-2 / +13 lines)
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
    
(-)src/org/netbeans/modules/ant/freeform/resources/freeform-project-general-2.xsd (+2 lines)
Lines 60-65 Link Here
60
                <xsd:element name="name" type="xsd:token"/>
60
                <xsd:element name="name" type="xsd:token"/>
61
                <!-- Declaration of properties. -->
61
                <!-- Declaration of properties. -->
62
                <xsd:element name="properties" minOccurs="0" type="properties"/>
62
                <xsd:element name="properties" minOccurs="0" type="properties"/>
63
                <!-- Project encoding value -->
64
                <xsd:element name="encoding" minOccurs="0" maxOccurs="1" type="substitutable-text"/>
63
                <!-- List of sources. Default: just project directory. -->
65
                <!-- List of sources. Default: just project directory. -->
64
                <xsd:element name="folders" minOccurs="0" type="folders"/>
66
                <xsd:element name="folders" minOccurs="0" type="folders"/>
65
                <!-- List of actions to run. -->
67
                <!-- List of actions to run. -->

Return to bug 120508