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 228278
Collapse All | Expand All

(-)a/api.java/apichanges.xml (+16 lines)
Lines 76-81 Link Here
76
<!-- ACTUAL CHANGES BEGIN HERE: -->
76
<!-- ACTUAL CHANGES BEGIN HERE: -->
77
77
78
<changes>
78
<changes>
79
        <change id="JDK8-profiles-2">
80
            <api name="queries"/>
81
            <summary>The <code>SourceLevelQuery</code> supports JDK 8 profiles</summary>
82
            <version major="1" minor="47"/>
83
            <date day="10" month="4" year="2013"/>
84
            <author login="tzezula"/>
85
            <compatibility semantic="compatible" source="incompatible" binary="incompatible">
86
                Incompatible change of not released API.
87
            </compatibility>
88
            <description>
89
                <p>
90
                    The JDK Profile was changed to enum type.
91
                </p>
92
            </description>
93
            <issue number="228278"/>
94
        </change>
79
        <change id="JDK8-profiles">
95
        <change id="JDK8-profiles">
80
            <api name="queries"/>
96
            <api name="queries"/>
81
            <summary>The <code>SourceLevelQuery</code> supports JDK 8 profiles</summary>
97
            <summary>The <code>SourceLevelQuery</code> supports JDK 8 profiles</summary>
(-)a/api.java/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.api.java/1
2
OpenIDE-Module: org.netbeans.api.java/1
3
OpenIDE-Module-Specification-Version: 1.46
3
OpenIDE-Module-Specification-Version: 1.47
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/java/queries/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/java/queries/Bundle.properties
5
AutoUpdate-Show-In-Client: false
5
AutoUpdate-Show-In-Client: false
6
6
(-)a/api.java/nbproject/project.xml (+8 lines)
Lines 76-81 Link Here
76
                    </run-dependency>
76
                    </run-dependency>
77
                </dependency>
77
                </dependency>
78
                <dependency>
78
                <dependency>
79
                    <code-name-base>org.openide.modules</code-name-base>
80
                    <build-prerequisite/>
81
                    <compile-dependency/>
82
                    <run-dependency>
83
                        <specification-version>7.38</specification-version>
84
                    </run-dependency>
85
                </dependency>
86
                <dependency>
79
                    <code-name-base>org.openide.util</code-name-base>
87
                    <code-name-base>org.openide.util</code-name-base>
80
                    <build-prerequisite/>
88
                    <build-prerequisite/>
81
                    <compile-dependency/>
89
                    <compile-dependency/>
(-)a/api.java/src/org/netbeans/api/java/queries/SourceLevelQuery.java (-8 / +139 lines)
Lines 45-50 Link Here
45
package org.netbeans.api.java.queries;
45
package org.netbeans.api.java.queries;
46
46
47
import java.text.MessageFormat;
47
import java.text.MessageFormat;
48
import java.util.Collections;
49
import java.util.HashMap;
50
import java.util.HashSet;
51
import java.util.Map;
52
import java.util.Set;
48
import java.util.logging.Level;
53
import java.util.logging.Level;
49
import java.util.logging.Logger;
54
import java.util.logging.Logger;
50
import java.util.regex.Pattern;
55
import java.util.regex.Pattern;
Lines 55-62 Link Here
55
import org.netbeans.api.annotations.common.NullAllowed;
60
import org.netbeans.api.annotations.common.NullAllowed;
56
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
61
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
57
import org.openide.filesystems.FileObject;
62
import org.openide.filesystems.FileObject;
63
import org.openide.modules.SpecificationVersion;
58
import org.openide.util.ChangeSupport;
64
import org.openide.util.ChangeSupport;
59
import org.openide.util.Lookup;
65
import org.openide.util.Lookup;
66
import org.openide.util.NbBundle;
60
import org.openide.util.Parameters;
67
import org.openide.util.Parameters;
61
import org.openide.util.Union2;
68
import org.openide.util.Union2;
62
import org.openide.util.WeakListeners;
69
import org.openide.util.WeakListeners;
Lines 74-79 Link Here
74
81
75
    private static final Pattern SOURCE_LEVEL = Pattern.compile("\\d+\\.\\d+"); //NOI18N
82
    private static final Pattern SOURCE_LEVEL = Pattern.compile("\\d+\\.\\d+"); //NOI18N
76
    private static final Pattern SYNONYM = Pattern.compile("\\d+");             //noI18N
83
    private static final Pattern SYNONYM = Pattern.compile("\\d+");             //noI18N
84
    private static final SpecificationVersion JDK8 = new SpecificationVersion("1.8");   //NOI18N
77
85
78
    @SuppressWarnings("deprecation")
86
    @SuppressWarnings("deprecation")
79
    private static final Lookup.Result<? extends org.netbeans.spi.java.queries.SourceLevelQueryImplementation> implementations =
87
    private static final Lookup.Result<? extends org.netbeans.spi.java.queries.SourceLevelQueryImplementation> implementations =
Lines 147-152 Link Here
147
        LOGGER.log(Level.FINE, "No source level found for {0}", javaFile);
155
        LOGGER.log(Level.FINE, "No source level found for {0}", javaFile);
148
        return new Result(javaFile);
156
        return new Result(javaFile);
149
    }
157
    }
158
    
159
    /**
160
     * The JRE profiles defined by Java 8.
161
     * <div class="nonnormative">
162
     * The JDK 8 provides three limited profiles (compact1, compact2, compact3) in addition
163
     * to the full JDK. Each profile specifies a specific set of Java API packages and
164
     * contains all of the APIs of the smaller profile, @see http://openjdk.java.net/jeps/161
165
     * </div>
166
     * @since 1.47
167
     */
168
    public static enum Profile {
169
170
        /**
171
         * The compact1 profile.
172
         */
173
        COMPACT1("compact1", Bundle.NAME_Compact1(), JDK8),   //NOI18N
174
175
        /**
176
         * The compact2 profile.
177
         */
178
        COMPACT2("compact2", Bundle.NAME_Compact2(), JDK8),   //NOI18N
179
180
        /**
181
         * The compact3 profile.
182
         */
183
        COMPACT3("compact3", Bundle.NAME_Compact3(), JDK8),   //NOI18N
184
185
        /**
186
         * The default full JRE profile.
187
         */
188
        DEFAULT(Bundle.NAME_FullJRE()) {
189
            @Override
190
            public boolean isSupportedIn(@NonNull final String sourceLevel) {
191
                return true;
192
            }
193
        };
194
195
        private static final Map<String,Profile> profilesByName = new HashMap<>();
196
        static {
197
            for (Profile sp : values()) {
198
                profilesByName.put(sp.getName(), sp);
199
            }
200
        }
201
202
        private final String name;
203
        private final String displayName;
204
        private final SpecificationVersion supportedFrom;
205
206
        @NbBundle.Messages({
207
        "NAME_Compact1=Compact 1",
208
        "NAME_Compact2=Compact 2",
209
        "NAME_Compact3=Compact 3",
210
        "NAME_FullJRE=Full JRE"
211
        })
212
        private Profile(
213
                @NonNull final String name,
214
                @NonNull final String displayName,
215
                @NonNull final SpecificationVersion supportedFrom) {
216
            assert name != null;
217
            assert displayName != null;
218
            assert supportedFrom != null;
219
            this.name = name;
220
            this.displayName = displayName;
221
            this.supportedFrom = supportedFrom;
222
        }
223
224
        private Profile(@NonNull final String displayName) {
225
            assert displayName != null;
226
            this.name = "";   //NOI18N
227
            this.displayName = displayName;
228
            this.supportedFrom = null;
229
        }
230
231
        /**
232
         * Returns the name of the profile.
233
         * @return the name of the profile
234
         */
235
        @NonNull
236
        public String getName() {
237
            return name;
238
        }
239
240
        /**
241
         * Returns the display name of the profile.
242
         * @return the display name of the profile
243
         */
244
        @NonNull
245
        public String getDisplayName() {
246
            return displayName;
247
        }
248
249
        /**
250
         * Tests if the profile is supported in gives source level.
251
         * @param sourceLevel to test if the profile is supported in it
252
         * @return true if the profile is supported in given source level
253
         */
254
        public boolean isSupportedIn(@NonNull String sourceLevel) {
255
            Parameters.notNull("sourceLevel", sourceLevel); //NOI18N
256
            sourceLevel = normalize(sourceLevel);
257
            if (!SOURCE_LEVEL.matcher(sourceLevel).matches()) {
258
                throw new IllegalArgumentException(sourceLevel);
259
            }
260
            return supportedFrom.compareTo(new SpecificationVersion(sourceLevel)) <= 0;
261
        }
262
263
        /**
264
         * Returns the {@link Profile} for given profile name.
265
         * @param profileName the name of the profile
266
         * @return the {@link Profile} for given profile name or null
267
         * for unknown profile name.
268
         */
269
        @CheckForNull
270
        public static Profile forName(@NullAllowed String profileName) {
271
            if (profileName == null) {
272
                profileName = Profile.DEFAULT.getName();
273
            }
274
            return Profile.profilesByName.get(profileName);
275
        }
276
    }    
150
277
151
    /**
278
    /**
152
     * Result of finding source level, encapsulating the answer as well as the
279
     * Result of finding source level, encapsulating the answer as well as the
Lines 195-217 Link Here
195
        }
322
        }
196
323
197
        /**
324
        /**
198
         * Returns the name of the required profile.
325
         * Returns the required profile.
199
         * @return a name of the required profile or null if the profile is either unknown
326
         * @return the required profile. If the profile is either unknown
200
         * or unsupported by actual source level.
327
         * or unsupported by actual source level it returns the {@link Profile#DEFAULT}.
201
         * <div class="nonnormative">
328
         * <div class="nonnormative">
202
         * The JDK 8 provides three limited profiles (compact1, compact2, compact3) in addition
329
         * The JDK 8 provides three limited profiles (compact1, compact2, compact3) in addition
203
         * to the full JDK. Each profile specifies a specific set of Java API packages and
330
         * to the full JDK. Each profile specifies a specific set of Java API packages and
204
         * contains all of the APIs of the smaller profile, @see http://openjdk.java.net/jeps/161
331
         * contains all of the APIs of the smaller profile, @see http://openjdk.java.net/jeps/161
205
         * </div>
332
         * </div>
206
         * @since 1.45
333
         * @since 1.47
207
         */
334
         */
208
        @CheckForNull
335
        @NonNull
209
        public String getProfile() {
336
        public Profile getProfile() {
210
            final SourceLevelQueryImplementation2.Result delegate = getDelegate();
337
            final SourceLevelQueryImplementation2.Result delegate = getDelegate();
211
            if (!(delegate instanceof SourceLevelQueryImplementation2.Result2)) {
338
            if (!(delegate instanceof SourceLevelQueryImplementation2.Result2)) {
212
                return null;
339
                return Profile.DEFAULT;
213
            }
340
            }
214
            return ((SourceLevelQueryImplementation2.Result2)delegate).getProfile();
341
            final Profile result = ((SourceLevelQueryImplementation2.Result2)delegate).getProfile();
342
            assert result != null : String.format(
343
                "Null result returned by provider: %s", //NOI18N
344
                delegate);
345
            return result;
215
        }
346
        }
216
347
217
        /**
348
        /**
(-)a/api.java/src/org/netbeans/spi/java/queries/SourceLevelQueryImplementation2.java (-6 / +6 lines)
Lines 111-131 Link Here
111
    /**
111
    /**
112
     * Result of finding a source level and profile as well as the ability
112
     * Result of finding a source level and profile as well as the ability
113
     * to listen on changes.
113
     * to listen on changes.
114
     * @since 1.45
114
     * @since 1.47
115
     */
115
     */
116
    interface Result2 extends Result {
116
    interface Result2 extends Result {
117
117
118
        /**
118
        /**
119
         * Returns the name of the required profile.
119
         * Returns the required profile.
120
         * @return a name of the required profile or null if the profile is either unknown
120
         * @return the required profile. If the profile is either unknown
121
         * or unsupported by actual source level.
121
         * or unsupported by actual source level it returns the {@link SourceLevelQuery.Profile#DEFAULT}.
122
         * <div class="nonnormative">
122
         * <div class="nonnormative">
123
         * The JDK 8 provides three limited profiles (compact1, compact2, compact3) in addition
123
         * The JDK 8 provides three limited profiles (compact1, compact2, compact3) in addition
124
         * to the full JDK. Each profile specifies a specific set of Java API packages and
124
         * to the full JDK. Each profile specifies a specific set of Java API packages and
125
         * contains all of the APIs of the smaller profile, @see http://openjdk.java.net/jeps/161
125
         * contains all of the APIs of the smaller profile, @see http://openjdk.java.net/jeps/161
126
         * </div>
126
         * </div>
127
         */
127
         */
128
        @CheckForNull
128
        @NonNull
129
        String getProfile();
129
        SourceLevelQuery.Profile getProfile();
130
    }
130
    }
131
}
131
}
(-)a/java.api.common/manifest.mf (-1 / +1 lines)
Lines 1-4 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.java.api.common/0
2
OpenIDE-Module: org.netbeans.modules.java.api.common/0
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/api/common/resources/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/api/common/resources/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.46
4
OpenIDE-Module-Specification-Version: 1.47
(-)a/java.api.common/nbproject/project.xml (-1 / +1 lines)
Lines 29-35 Link Here
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>1</release-version>
31
                        <release-version>1</release-version>
32
                        <specification-version>1.45</specification-version>
32
                        <specification-version>1.47</specification-version>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
35
                <dependency>
35
                <dependency>
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/queries/SourceLevelQueryImpl2.java (-5 / +9 lines)
Lines 47-52 Link Here
47
import java.util.regex.Pattern;
47
import java.util.regex.Pattern;
48
import javax.swing.event.ChangeListener;
48
import javax.swing.event.ChangeListener;
49
import org.netbeans.api.annotations.common.NonNull;
49
import org.netbeans.api.annotations.common.NonNull;
50
import org.netbeans.api.java.queries.SourceLevelQuery;
50
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
51
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
51
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
52
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
52
import org.netbeans.spi.project.support.ant.EditableProperties;
53
import org.netbeans.spi.project.support.ant.EditableProperties;
Lines 100-114 Link Here
100
        return null;
101
        return null;
101
    }
102
    }
102
103
103
    private static String findProfile(
104
    private static SourceLevelQuery.Profile findProfile(
104
            @NonNull final PropertyEvaluator eval) {
105
            @NonNull final PropertyEvaluator eval) {
106
        SourceLevelQuery.Profile res;
105
        if (supportsProfiles(findSourceLevel(eval))) {
107
        if (supportsProfiles(findSourceLevel(eval))) {
106
            final String profile = eval.getProperty(JAVAC_PROFILE);
108
            final String profile = eval.getProperty(JAVAC_PROFILE);
107
            if (profile != null && profile.length() > 0) {
109
            res = SourceLevelQuery.Profile.forName(profile);
108
                return profile;
110
            if (res != null) {
111
                return res;
109
            }
112
            }
110
        }
113
        }
111
        return null;
114
        res = SourceLevelQuery.Profile.DEFAULT;
115
        return res;
112
    }
116
    }
113
117
114
    private static boolean supportsProfiles(
118
    private static boolean supportsProfiles(
Lines 132-138 Link Here
132
        }
136
        }
133
137
134
        @Override
138
        @Override
135
        public String getProfile() {
139
        public SourceLevelQuery.Profile getProfile() {
136
            return findProfile(eval);
140
            return findProfile(eval);
137
        }
141
        }
138
142
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/ui/PlatformUiSupport.java (-181 / +54 lines)
Lines 49-62 Link Here
49
import java.beans.PropertyChangeListener;
49
import java.beans.PropertyChangeListener;
50
import java.text.MessageFormat;
50
import java.text.MessageFormat;
51
import java.util.ArrayList;
51
import java.util.ArrayList;
52
import java.util.Arrays;
53
import java.util.Collection;
52
import java.util.Collection;
54
import java.util.Collections;
53
import java.util.Collections;
55
import java.util.Comparator;
56
import java.util.HashMap;
57
import java.util.HashSet;
58
import java.util.List;
54
import java.util.List;
59
import java.util.Map;
60
import java.util.Set;
55
import java.util.Set;
61
import java.util.TreeSet;
56
import java.util.TreeSet;
62
import java.util.logging.Logger;
57
import java.util.logging.Logger;
Lines 69-74 Link Here
69
import org.netbeans.api.java.platform.JavaPlatform;
64
import org.netbeans.api.java.platform.JavaPlatform;
70
import org.netbeans.api.java.platform.JavaPlatformManager;
65
import org.netbeans.api.java.platform.JavaPlatformManager;
71
import org.netbeans.api.java.platform.Specification;
66
import org.netbeans.api.java.platform.Specification;
67
import org.netbeans.api.java.queries.SourceLevelQuery;
72
import org.netbeans.modules.java.api.common.ant.UpdateHelper;
68
import org.netbeans.modules.java.api.common.ant.UpdateHelper;
73
import org.netbeans.spi.java.project.support.PreferredProjectPlatform;
69
import org.netbeans.spi.java.project.support.PreferredProjectPlatform;
74
import org.netbeans.spi.project.support.ant.EditableProperties;
70
import org.netbeans.spi.project.support.ant.EditableProperties;
Lines 78-83 Link Here
78
import org.openide.modules.SpecificationVersion;
74
import org.openide.modules.SpecificationVersion;
79
import org.openide.util.NbBundle;
75
import org.openide.util.NbBundle;
80
import org.openide.util.Parameters;
76
import org.openide.util.Parameters;
77
import org.openide.util.Union2;
81
import org.openide.util.WeakListeners;
78
import org.openide.util.WeakListeners;
82
import org.w3c.dom.Element;
79
import org.w3c.dom.Element;
83
import org.w3c.dom.Node;
80
import org.w3c.dom.Node;
Lines 90-96 Link Here
90
public final class PlatformUiSupport {
87
public final class PlatformUiSupport {
91
88
92
    private static final SpecificationVersion JDK_1_5 = new SpecificationVersion("1.5"); //NOI18N
89
    private static final SpecificationVersion JDK_1_5 = new SpecificationVersion("1.5"); //NOI18N
93
    private static final SpecificationVersion JDK_8 = new SpecificationVersion("1.8");  //NOI18N
94
    private static final Logger LOGGER = Logger.getLogger(PlatformUiSupport.class.getName());
90
    private static final Logger LOGGER = Logger.getLogger(PlatformUiSupport.class.getName());
95
91
96
    private PlatformUiSupport() {
92
    private PlatformUiSupport() {
Lines 229-235 Link Here
229
                    sourceLevelKey,
225
                    sourceLevelKey,
230
                    sourceLevelKey.getClass()));
226
                    sourceLevelKey.getClass()));
231
        }
227
        }
232
        if (profileKey != null && !(profileKey instanceof Profile)) {
228
        if (profileKey != null && !(profileKey instanceof Union2)) {
233
            throw new IllegalArgumentException(String.format(
229
            throw new IllegalArgumentException(String.format(
234
                    "Unsupported profile key: %s of type: %s", //NOI18N
230
                    "Unsupported profile key: %s of type: %s", //NOI18N
235
                    profileKey,
231
                    profileKey,
Lines 336-347 Link Here
336
        if (!javacTarget.equals(props.getProperty(javacTargetKey))) {
332
        if (!javacTarget.equals(props.getProperty(javacTargetKey))) {
337
            props.setProperty(javacTargetKey, javacTarget);
333
            props.setProperty(javacTargetKey, javacTarget);
338
        }
334
        }
339
        
335
340
        final String javacProfile;
336
        String javacProfile = null;
341
        if (profileKey != null) {
337
        if (profileKey != null) {
342
            javacProfile = ((Profile)profileKey).getAntName();
338
            Union2<SourceLevelQuery.Profile,String> tv = (Union2<SourceLevelQuery.Profile,String>) profileKey;
343
        } else {
339
            if (tv.hasFirst()) {
344
            javacProfile = null;
340
                final SourceLevelQuery.Profile profile = tv.first();
341
                if (profile != SourceLevelQuery.Profile.DEFAULT) {
342
                    javacProfile = profile.getName();
343
                }
344
            } else {
345
                javacProfile = tv.second();
346
            }
345
        }
347
        }
346
        if (javacProfile != null) {
348
        if (javacProfile != null) {
347
            if(!javacProfile.equals(props.getProperty(javacProfileKey))) {
349
            if(!javacProfile.equals(props.getProperty(javacProfileKey))) {
Lines 446-452 Link Here
446
     * state according to the changes. It is possible to define minimal required
448
     * state according to the changes. It is possible to define minimal required
447
     * JRE profile.
449
     * JRE profile.
448
     * @param sourceLevelModel the source level model used for listening.
450
     * @param sourceLevelModel the source level model used for listening.
449
     * @param initialProfile initial profile, null if unknown.
451
     * @param initialProfileName initial profile name, null if unknown.
450
     * @param minimalProfile minimal JRE profile to be displayed.
452
     * @param minimalProfile minimal JRE profile to be displayed.
451
     * It can be <code>null</code> if all the JRE profiles should be displayed.
453
     * It can be <code>null</code> if all the JRE profiles should be displayed.
452
     * @return {@link ComboBoxModel}.
454
     * @return {@link ComboBoxModel}.
Lines 454-462 Link Here
454
     */
456
     */
455
    public static ComboBoxModel createProfileComboBoxModel(
457
    public static ComboBoxModel createProfileComboBoxModel(
456
            @NonNull final ComboBoxModel sourceLevelModel,
458
            @NonNull final ComboBoxModel sourceLevelModel,
457
            @NullAllowed final String initialProfile,
459
            @NullAllowed final String initialProfileName,
458
            @NullAllowed final String minimalProfile) {
460
            @NullAllowed final SourceLevelQuery.Profile minimalProfile) {
459
        return new ProfileComboBoxModel(sourceLevelModel, initialProfile, minimalProfile);
461
        return new ProfileComboBoxModel(sourceLevelModel, initialProfileName, minimalProfile);
460
    }
462
    }
461
463
462
    /**
464
    /**
Lines 938-1082 Link Here
938
            return delegate.getListCellRendererComponent(list, message, index, isSelected, cellHasFocus);
940
            return delegate.getListCellRendererComponent(list, message, index, isSelected, cellHasFocus);
939
        }
941
        }
940
    }
942
    }
941
943
           
942
    private interface Profile {
943
        @NonNull
944
        String getAntName();
945
946
        @NonNull
947
        String getDisplayName();
948
949
        int getRank();
950
951
        boolean isSupportedIn(@NonNull final SpecificationVersion sourceLevel);
952
    }
953
    
954
    private enum StandardProfile implements  Profile {
955
        COMPACT1(
956
                "compact1", //NOI18N
957
                NbBundle.getMessage(PlatformUiSupport.class, "TXT_Profile_Compact1"),
958
                0,
959
                Arrays.asList(JDK_8)),
960
        COMPACT2(
961
                "compact2", //NOI18N
962
                NbBundle.getMessage(PlatformUiSupport.class, "TXT_Profile_Compact2"),
963
                1,
964
                Arrays.asList(JDK_8)),
965
        COMPACT3(
966
                "compact3", //NOI18N
967
                NbBundle.getMessage(PlatformUiSupport.class, "TXT_Profile_Compact3"),
968
                2,
969
                Arrays.asList(JDK_8)),
970
        DEFAULT(
971
                "",  //NOI18N
972
                NbBundle.getMessage(PlatformUiSupport.class, "TXT_Profile_Default"),
973
                Integer.MAX_VALUE-1,
974
                Arrays.asList(JDK_8));
975
        
976
        private static final Map<String,Profile> profilesByName =
977
                new HashMap<String, Profile>();        
978
        static {
979
            for (Profile p : values()) {
980
                profilesByName.put(p.getAntName(), p);
981
            }
982
        }
983
        
984
        private final String name;
985
        private final String displayName;
986
        private final int rank;
987
        private final Set<? extends SpecificationVersion> supportedIn;
988
        
989
        StandardProfile(
990
            @NonNull final String name,
991
            @NonNull final String displayName,
992
            @NonNull final int rank,
993
            @NonNull final Collection<? extends SpecificationVersion> supportedIn) {
994
            Parameters.notNull("name", name);   //NOI18N
995
            Parameters.notNull("displayName", displayName); //NOI18N
996
            this.name = name;
997
            this.displayName = displayName;
998
            this.rank = rank;
999
            this.supportedIn = Collections.unmodifiableSet(
1000
                new HashSet<SpecificationVersion>(supportedIn));
1001
        }
1002
        
1003
        @Override
1004
        public String getAntName() {
1005
            return name;
1006
        }
1007
        
1008
        @Override
1009
        public String getDisplayName() {
1010
            return displayName;
1011
        }
1012
1013
        @Override
1014
        public int getRank() {
1015
            return rank;
1016
        }
1017
1018
        @Override
1019
        public boolean isSupportedIn(SpecificationVersion sourceLevel) {
1020
            return supportedIn.contains(sourceLevel);
1021
        }
1022
        
1023
        @Override
1024
        public String toString() {
1025
            return String.format(
1026
                "%s (%s)", //NOI18N
1027
                displayName,
1028
                name);
1029
        }
1030
1031
        @CheckForNull
1032
        static Profile forName(@NonNull final String id) {
1033
            return profilesByName.get(id);
1034
        }
1035
        
1036
    }
1037
1038
    private static final class ProfileComboBoxModel extends AbstractListModel implements ComboBoxModel, ListDataListener {
944
    private static final class ProfileComboBoxModel extends AbstractListModel implements ComboBoxModel, ListDataListener {
1039
945
1040
        private final ComboBoxModel sourceLevelModel;
946
        private final ComboBoxModel sourceLevelModel;
1041
        private final String initialProfileName;
947
        private final String initialProfileName;
1042
        private final String minimalProfileName;
948
        private final SourceLevelQuery.Profile minimalProfile;
1043
949
1044
        private Profile[] profiles;
950
        private List<Union2<SourceLevelQuery.Profile,String>> profiles;
1045
        private Profile selectedItem;
951
        private Union2<SourceLevelQuery.Profile,String> selectedItem;
1046
952
1047
        ProfileComboBoxModel(
953
        ProfileComboBoxModel(
1048
                @NonNull final ComboBoxModel sourceLevelModel,
954
                @NonNull final ComboBoxModel sourceLevelModel,
1049
                @NullAllowed final String initialProfileName,
955
                @NullAllowed final String initialProfileName,
1050
                @NullAllowed final String minimalProfileName) {
956
                @NullAllowed final SourceLevelQuery.Profile minimalProfile) {
1051
            this.sourceLevelModel = sourceLevelModel;
957
            this.sourceLevelModel = sourceLevelModel;
1052
            this.initialProfileName = initialProfileName;
958
            this.initialProfileName = initialProfileName;
1053
            this.minimalProfileName = minimalProfileName;
959
            this.minimalProfile = minimalProfile;
1054
            this.sourceLevelModel.addListDataListener(this);
960
            this.sourceLevelModel.addListDataListener(this);
1055
        }
961
        }
1056
962
1057
        @Override
963
        @Override
1058
        public int getSize() {
964
        public int getSize() {
1059
            final Profile[] p = init();
965
            final Collection<? extends Union2<SourceLevelQuery.Profile,String>> p = init();
1060
            return p.length;
966
            return p.size();
1061
        }
967
        }
1062
968
1063
        @Override
969
        @Override
1064
        @CheckForNull
970
        @CheckForNull
1065
        public Object getElementAt(final int index) {
971
        public Object getElementAt(final int index) {
1066
            final Profile[] p = init();
972
            final List<? extends Union2<SourceLevelQuery.Profile,String>> p = init();
1067
            if (index < 0 || index >= p.length) {
973
            if (index < 0 || index >= p.size()) {
1068
                throw new IndexOutOfBoundsException(String.format(
974
                throw new IndexOutOfBoundsException(String.format(
1069
                    "Index: %d, Profiles count: %d",    //NOI18N
975
                    "Index: %d, Profiles count: %d",    //NOI18N
1070
                    index,
976
                    index,
1071
                    p.length));
977
                    p.size()));
1072
            }
978
            }
1073
            return p[index];
979
            return p.get(index);
1074
        }
980
        }
1075
981
1076
        @Override
982
        @Override
1077
        public void setSelectedItem(@NullAllowed final Object anItem) {
983
        public void setSelectedItem(@NullAllowed final Object anItem) {
1078
            assert anItem == null || anItem instanceof Profile;
984
            assert anItem == null || anItem instanceof Union2 : anItem;
1079
            selectedItem = (Profile) anItem;
985
            selectedItem = (Union2<SourceLevelQuery.Profile,String>) anItem;
1080
        }
986
        }
1081
987
1082
        @Override
988
        @Override
Lines 1100-1126 Link Here
1100
            fireContentsChanged(this, 0, oldSize);
1006
            fireContentsChanged(this, 0, oldSize);
1101
        }
1007
        }
1102
1008
1103
        private Profile[] init() {
1009
        private List<? extends Union2<SourceLevelQuery.Profile,String>> init() {
1104
            if (profiles == null) {
1010
            if (profiles == null) {                           
1105
                final Comparator<Profile> c = new Comparator<Profile>() {
1011
                final List<Union2<SourceLevelQuery.Profile,String>> pc = new ArrayList<>();
1106
                    @Override
1107
                    public int compare(
1108
                            @NonNull final Profile p1,
1109
                            @NonNull final Profile p2) {
1110
                        final int r1 = p1.getRank();
1111
                        final int r2 = p2.getRank();
1112
                        return r1 < r2 ?
1113
                            -1 :
1114
                            r1 == r2 ?
1115
                                0 :
1116
                                1;
1117
                    }
1118
                };
1119
                Profile minimalProfile = null;
1120
                if (minimalProfileName != null) {
1121
                    minimalProfile = StandardProfile.forName(minimalProfileName);
1122
                }
1123
                final Collection<Profile> pc = new TreeSet<Profile>(c);
1124
                final Object slk = sourceLevelModel.getSelectedItem();
1012
                final Object slk = sourceLevelModel.getSelectedItem();
1125
                final SpecificationVersion sl;
1013
                final SpecificationVersion sl;
1126
                if (slk instanceof SourceLevelKey) {
1014
                if (slk instanceof SourceLevelKey) {
Lines 1128-1172 Link Here
1128
                } else {
1016
                } else {
1129
                    sl = null;
1017
                    sl = null;
1130
                }
1018
                }
1131
                for (StandardProfile p : StandardProfile.values()) {
1019
                for (SourceLevelQuery.Profile p : SourceLevelQuery.Profile.values()) {
1132
                    if (minimalProfile != null &&
1020
                    if (minimalProfile != null && minimalProfile.compareTo(p) > 0) {
1133
                        c.compare(minimalProfile, selectedItem) > 0) {
1134
                            continue;
1021
                            continue;
1135
                    }
1022
                    }
1136
                    if (sl != null && !p.isSupportedIn(sl)) {
1023
                    if (sl != null && !p.isSupportedIn(sl.toString())) {
1137
                        continue;
1024
                        continue;
1138
                    }
1025
                    }
1139
                    pc.add(p);
1026
                    pc.add(Union2.<SourceLevelQuery.Profile,String>createFirst(p));
1140
                }
1027
                }
1141
                if (selectedItem == null) {
1028
                if (selectedItem == null) {
1142
                    if (initialProfileName != null && !initialProfileName.isEmpty()) {
1029
                    if (initialProfileName != null) {
1143
                        selectedItem = StandardProfile.forName(initialProfileName);
1030
                        SourceLevelQuery.Profile initialProfile = SourceLevelQuery.Profile.forName(initialProfileName);
1144
                        if (selectedItem == null) {
1031
                        if (initialProfile != null) {
1145
                            selectedItem = new Profile() {
1032
                            selectedItem = Union2.<SourceLevelQuery.Profile,String>createFirst(initialProfile);
1146
                                @Override
1033
                        } else {
1147
                                public String getAntName() {
1034
                            selectedItem = Union2.<SourceLevelQuery.Profile,String>createSecond(initialProfileName);
1148
                                    return initialProfileName;
1149
                                }
1150
                                @Override
1151
                                public String getDisplayName() {
1152
                                    return getAntName();
1153
                                }
1154
                                @Override
1155
                                public int getRank() {
1156
                                    return Integer.MAX_VALUE;
1157
                                }
1158
                                @Override
1159
                                public boolean isSupportedIn(SpecificationVersion sourceLevel) {
1160
                                    return true;
1161
                                }
1162
                            };
1163
                            pc.add(selectedItem);
1035
                            pc.add(selectedItem);
1164
                        }
1036
                        }
1165
                    } else {
1037
                    } else {
1166
                        selectedItem = StandardProfile.DEFAULT;
1038
                        selectedItem = Union2.<SourceLevelQuery.Profile,String>createFirst(SourceLevelQuery.Profile.DEFAULT);
1167
                    }
1039
                    }
1168
                }
1040
                }
1169
                this.profiles = pc.toArray(new Profile[pc.size()]);
1041
                this.profiles = Collections.unmodifiableList(pc);
1170
            }
1042
            }
1171
            return profiles;
1043
            return profiles;
1172
        }        
1044
        }        
Lines 1187-1199 Link Here
1187
                final int index,
1059
                final int index,
1188
                final boolean isSelected,
1060
                final boolean isSelected,
1189
                final boolean cellHasFocus) {
1061
                final boolean cellHasFocus) {
1190
            if (value instanceof Profile) {
1062
            if (value instanceof Union2) {
1191
                final Profile p = (Profile) value;
1063
                final Union2<SourceLevelQuery.Profile,String> tv  =
1192
                if (StandardProfile.forName(p.getAntName()) == null) {
1064
                        (Union2<SourceLevelQuery.Profile,String>) value;
1065
                if (tv.hasFirst()) {
1066
                    value = tv.first().getDisplayName();
1067
                } else {
1193
                    value = "<html><font color=\"#A40000\">" + //NOI18N
1068
                    value = "<html><font color=\"#A40000\">" + //NOI18N
1194
                        p.getDisplayName();
1069
                        tv.second();
1195
                } else {
1196
                    value = p.getDisplayName();
1197
                }
1070
                }
1198
            }
1071
            }
1199
            return delegate.getListCellRendererComponent(
1072
            return delegate.getListCellRendererComponent(
(-)a/java.api.common/test/unit/src/org/netbeans/modules/java/api/common/queries/SourceLevelQueryImplTest.java (-17 / +16 lines)
Lines 60-65 Link Here
60
import org.netbeans.api.java.classpath.ClassPath;
60
import org.netbeans.api.java.classpath.ClassPath;
61
import org.netbeans.api.java.platform.JavaPlatform;
61
import org.netbeans.api.java.platform.JavaPlatform;
62
import org.netbeans.api.java.platform.Specification;
62
import org.netbeans.api.java.platform.Specification;
63
import org.netbeans.api.java.queries.SourceLevelQuery;
63
import org.netbeans.api.project.Project;
64
import org.netbeans.api.project.Project;
64
import org.netbeans.api.project.ProjectManager;
65
import org.netbeans.api.project.ProjectManager;
65
import org.netbeans.junit.NbTestCase;
66
import org.netbeans.junit.NbTestCase;
Lines 102-109 Link Here
102
        });
103
        });
103
    }
104
    }
104
105
105
    private static final String COMPACT1 = "compact1";  //NOI18N
106
    private static final String COMPACT2 = "compact2";  //NOI18N
107
    private static final String JDK_8 = "8";    //NOI18N
106
    private static final String JDK_8 = "8";    //NOI18N
108
    private static final String JDK_8_ALIAS = "1.8";    //NOI18N
107
    private static final String JDK_8_ALIAS = "1.8";    //NOI18N
109
    private static final String JAVAC_SOURCE = "1.2";
108
    private static final String JAVAC_SOURCE = "1.2";
Lines 227-247 Link Here
227
    }
226
    }
228
227
229
    public void testProfilesJDK8ProfileGiven() throws IOException {
228
    public void testProfilesJDK8ProfileGiven() throws IOException {
230
        this.prepareProject(TEST_PLATFORM, JDK_8, COMPACT2);
229
        this.prepareProject(TEST_PLATFORM, JDK_8, SourceLevelQuery.Profile.COMPACT2.getName());
231
        final FileObject dummy = projdir.createData("Dummy.java");  //NOI18N
230
        final FileObject dummy = projdir.createData("Dummy.java");  //NOI18N
232
        final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval);
231
        final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval);
233
        final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy);
232
        final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy);
234
        assertTrue(result instanceof SourceLevelQueryImplementation2.Result2);
233
        assertTrue(result instanceof SourceLevelQueryImplementation2.Result2);
235
        assertEquals(COMPACT2, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
234
        assertEquals(SourceLevelQuery.Profile.COMPACT2, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
236
    }
235
    }
237
236
238
    public void testProfilesJDK8AliasProfileGiven() throws IOException {
237
    public void testProfilesJDK8AliasProfileGiven() throws IOException {
239
        this.prepareProject(TEST_PLATFORM, JDK_8_ALIAS, COMPACT2);
238
        this.prepareProject(TEST_PLATFORM, JDK_8_ALIAS, SourceLevelQuery.Profile.COMPACT2.getName());
240
        final FileObject dummy = projdir.createData("Dummy.java");  //NOI18N
239
        final FileObject dummy = projdir.createData("Dummy.java");  //NOI18N
241
        final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval);
240
        final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval);
242
        final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy);
241
        final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy);
243
        assertTrue(result instanceof SourceLevelQueryImplementation2.Result2);
242
        assertTrue(result instanceof SourceLevelQueryImplementation2.Result2);
244
        assertEquals(COMPACT2, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
243
        assertEquals(SourceLevelQuery.Profile.COMPACT2, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
245
    }
244
    }
246
245
247
    public void testProfilesJDK8AliasProfileNotGiven() throws IOException {
246
    public void testProfilesJDK8AliasProfileNotGiven() throws IOException {
Lines 250-279 Link Here
250
        final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval);
249
        final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval);
251
        final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy);
250
        final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy);
252
        assertTrue(result instanceof SourceLevelQueryImplementation2.Result2);
251
        assertTrue(result instanceof SourceLevelQueryImplementation2.Result2);
253
        assertEquals(null, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
252
        assertEquals(SourceLevelQuery.Profile.DEFAULT, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
254
    }
253
    }
255
254
256
    public void testProfilesOldJDKAliasProfileGiven() throws IOException {
255
    public void testProfilesOldJDKAliasProfileGiven() throws IOException {
257
        this.prepareProject(TEST_PLATFORM, JAVAC_SOURCE, COMPACT2);
256
        this.prepareProject(TEST_PLATFORM, JAVAC_SOURCE, SourceLevelQuery.Profile.COMPACT2.getName());
258
        final FileObject dummy = projdir.createData("Dummy.java");  //NOI18N
257
        final FileObject dummy = projdir.createData("Dummy.java");  //NOI18N
259
        final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval);
258
        final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval);
260
        final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy);
259
        final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy);
261
        assertTrue(result instanceof SourceLevelQueryImplementation2.Result2);
260
        assertTrue(result instanceof SourceLevelQueryImplementation2.Result2);
262
        assertEquals(null, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
261
        assertEquals(SourceLevelQuery.Profile.DEFAULT, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
263
    }
262
    }
264
263
265
    public void testProfileChanges() throws Exception {
264
    public void testProfileChanges() throws Exception {
266
        prepareProject(TEST_PLATFORM, JDK_8, COMPACT1);
265
        prepareProject(TEST_PLATFORM, JDK_8, SourceLevelQuery.Profile.COMPACT1.getName());
267
        final FileObject dummy = projdir.createData("Dummy.java");  //NOI18N
266
        final FileObject dummy = projdir.createData("Dummy.java");  //NOI18N
268
        final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval);
267
        final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval);
269
        SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy);
268
        SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy);
270
        assertTrue(result instanceof SourceLevelQueryImplementation2.Result2);
269
        assertTrue(result instanceof SourceLevelQueryImplementation2.Result2);
271
        assertEquals(COMPACT1, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
270
        assertEquals(SourceLevelQuery.Profile.COMPACT1, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
272
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
271
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
273
            @Override
272
            @Override
274
            public Void run() throws Exception {
273
            public Void run() throws Exception {
275
                final EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
274
                final EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
276
                props.setProperty("javac.profile", COMPACT2);   //NOI18N
275
                props.setProperty("javac.profile", SourceLevelQuery.Profile.COMPACT2.getName());   //NOI18N
277
                helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
276
                helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
278
                ProjectManager.getDefault().saveProject(prj);
277
                ProjectManager.getDefault().saveProject(prj);
279
                return null;
278
                return null;
Lines 281-297 Link Here
281
        });
280
        });
282
        result = sourceLevelQuery.getSourceLevel(dummy);
281
        result = sourceLevelQuery.getSourceLevel(dummy);
283
        assertTrue(result instanceof SourceLevelQueryImplementation2.Result2);
282
        assertTrue(result instanceof SourceLevelQueryImplementation2.Result2);
284
        assertEquals(COMPACT2, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
283
        assertEquals(SourceLevelQuery.Profile.COMPACT2, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
285
284
286
    }
285
    }
287
286
288
    public void testProfileListening() throws Exception {
287
    public void testProfileListening() throws Exception {
289
        prepareProject(TEST_PLATFORM, JDK_8, COMPACT1);
288
        prepareProject(TEST_PLATFORM, JDK_8, SourceLevelQuery.Profile.COMPACT1.getName());
290
        final FileObject dummy = projdir.createData("Dummy.java");  //NOI18N
289
        final FileObject dummy = projdir.createData("Dummy.java");  //NOI18N
291
        final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval);
290
        final SourceLevelQueryImplementation2 sourceLevelQuery = QuerySupport.createSourceLevelQuery2(eval);
292
        final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy);
291
        final SourceLevelQueryImplementation2.Result result = sourceLevelQuery.getSourceLevel(dummy);
293
        assertTrue(result instanceof SourceLevelQueryImplementation2.Result2);
292
        assertTrue(result instanceof SourceLevelQueryImplementation2.Result2);
294
        assertEquals(COMPACT1, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
293
        assertEquals(SourceLevelQuery.Profile.COMPACT1, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
295
        final AtomicInteger eventCount = new AtomicInteger();
294
        final AtomicInteger eventCount = new AtomicInteger();
296
        final ChangeListener listener = new ChangeListener() {
295
        final ChangeListener listener = new ChangeListener() {
297
            @Override
296
            @Override
Lines 304-317 Link Here
304
            @Override
303
            @Override
305
            public Void run() throws Exception {
304
            public Void run() throws Exception {
306
                final EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
305
                final EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
307
                props.setProperty("javac.profile", COMPACT2);   //NOI18N
306
                props.setProperty("javac.profile", SourceLevelQuery.Profile.COMPACT2.getName());   //NOI18N
308
                helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
307
                helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
309
                ProjectManager.getDefault().saveProject(prj);
308
                ProjectManager.getDefault().saveProject(prj);
310
                return null;
309
                return null;
311
            }
310
            }
312
        });
311
        });
313
        assertEquals(1, eventCount.get());
312
        assertEquals(1, eventCount.get());
314
        assertEquals(COMPACT2, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
313
        assertEquals(SourceLevelQuery.Profile.COMPACT2, ((SourceLevelQueryImplementation2.Result2)result).getProfile());
315
314
316
    }
315
    }
317
316
(-)a/java.j2seproject/nbproject/project.properties (-1 / +1 lines)
Lines 42-48 Link Here
42
42
43
javac.compilerargs=-Xlint -Xlint:-serial
43
javac.compilerargs=-Xlint -Xlint:-serial
44
javac.source=1.7
44
javac.source=1.7
45
spec.version.base=1.61.0
45
spec.version.base=1.62.0
46
46
47
javadoc.arch=${basedir}/arch.xml
47
javadoc.arch=${basedir}/arch.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
(-)a/java.j2seproject/nbproject/project.xml (-1 / +1 lines)
Lines 142-148 Link Here
142
                    <compile-dependency/>
142
                    <compile-dependency/>
143
                    <run-dependency>
143
                    <run-dependency>
144
                        <release-version>0-1</release-version>
144
                        <release-version>0-1</release-version>
145
                        <specification-version>1.45</specification-version>
145
                        <specification-version>1.47</specification-version>
146
                    </run-dependency>
146
                    </run-dependency>
147
                </dependency>
147
                </dependency>
148
                <dependency>
148
                <dependency>
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java (-1 / +1 lines)
Lines 49-55 Link Here
49
import java.io.File;
49
import java.io.File;
50
import java.io.IOException;
50
import java.io.IOException;
51
import java.io.OutputStream;
51
import java.io.OutputStream;
52
import java.io.StringReader;
53
import java.net.MalformedURLException;
52
import java.net.MalformedURLException;
54
import java.net.URI;
53
import java.net.URI;
55
import java.net.URISyntaxException;
54
import java.net.URISyntaxException;
Lines 81-86 Link Here
81
import javax.swing.text.Document;
80
import javax.swing.text.Document;
82
import javax.swing.text.PlainDocument;
81
import javax.swing.text.PlainDocument;
83
import org.netbeans.api.annotations.common.NonNull;
82
import org.netbeans.api.annotations.common.NonNull;
83
import org.netbeans.api.java.queries.SourceLevelQuery;
84
import org.netbeans.api.queries.FileEncodingQuery;
84
import org.netbeans.api.queries.FileEncodingQuery;
85
import org.netbeans.api.project.ProjectManager;
85
import org.netbeans.api.project.ProjectManager;
86
import org.netbeans.api.project.ProjectUtils;
86
import org.netbeans.api.project.ProjectUtils;
(-)a/java.project/manifest.mf (-1 / +1 lines)
Lines 3-9 Link Here
3
OpenIDE-Module-Layer: org/netbeans/modules/java/project/layer.xml
3
OpenIDE-Module-Layer: org/netbeans/modules/java/project/layer.xml
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/project/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/project/Bundle.properties
5
OpenIDE-Module-Needs: javax.script.ScriptEngine.freemarker
5
OpenIDE-Module-Needs: javax.script.ScriptEngine.freemarker
6
OpenIDE-Module-Specification-Version: 1.53
6
OpenIDE-Module-Specification-Version: 1.54
7
OpenIDE-Module-Recommends: org.netbeans.spi.java.project.runner.JavaRunnerImplementation
7
OpenIDE-Module-Recommends: org.netbeans.spi.java.project.runner.JavaRunnerImplementation
8
AutoUpdate-Show-In-Client: false
8
AutoUpdate-Show-In-Client: false
9
9
(-)a/java.project/nbproject/project.xml (-1 / +1 lines)
Lines 82-88 Link Here
82
                    <compile-dependency/>
82
                    <compile-dependency/>
83
                    <run-dependency>
83
                    <run-dependency>
84
                        <release-version>1</release-version>
84
                        <release-version>1</release-version>
85
                        <specification-version>1.30</specification-version>
85
                        <specification-version>1.47</specification-version>
86
                    </run-dependency>
86
                    </run-dependency>
87
                </dependency>
87
                </dependency>
88
                <dependency>
88
                <dependency>
(-)a/java.project/src/org/netbeans/modules/java/project/FixProfile.java (-15 / +24 lines)
Lines 66-71 Link Here
66
import org.netbeans.api.annotations.common.CheckForNull;
66
import org.netbeans.api.annotations.common.CheckForNull;
67
import org.netbeans.api.annotations.common.NonNull;
67
import org.netbeans.api.annotations.common.NonNull;
68
import org.netbeans.api.annotations.common.NullAllowed;
68
import org.netbeans.api.annotations.common.NullAllowed;
69
import org.netbeans.api.java.queries.SourceLevelQuery.Profile;
69
import org.openide.util.NbBundle;
70
import org.openide.util.NbBundle;
70
71
71
/**
72
/**
Lines 76-89 Link Here
76
 
77
 
77
    private final JButton okOption;
78
    private final JButton okOption;
78
    private final LibsModel libsModel;
79
    private final LibsModel libsModel;
79
    private ProfileProblemsProviderImpl.Profile reqProfile;
80
    private Profile reqProfile;
80
81
81
    /**
82
    /**
82
     * Creates new form FixProfile
83
     * Creates new form FixProfile
83
     */
84
     */
84
    FixProfile(
85
    FixProfile(
85
            @NonNull final JButton okOption,
86
            @NonNull final JButton okOption,
86
            @NonNull final ProfileProblemsProviderImpl.Profile currentProfile,
87
            @NonNull final Profile currentProfile,
87
            @NonNull final Collection<? extends ProfileProblemsProviderImpl.Reference> state) {
88
            @NonNull final Collection<? extends ProfileProblemsProviderImpl.Reference> state) {
88
        assert okOption != null;
89
        assert okOption != null;
89
        assert currentProfile != null;
90
        assert currentProfile != null;
Lines 136-145 Link Here
136
    }
137
    }
137
138
138
    @CheckForNull
139
    @CheckForNull
139
    ProfileProblemsProviderImpl.Profile getProfile() {
140
    Profile getProfile() {
140
        final Object selObj = profiles.getSelectedItem();
141
        final Object selObj = profiles.getSelectedItem();
141
        if (selObj instanceof ProfileProblemsProviderImpl.Profile) {
142
        if (selObj instanceof Profile) {
142
            return (ProfileProblemsProviderImpl.Profile) selObj;
143
            return (Profile) selObj;
143
        } else {
144
        } else {
144
            return null;
145
            return null;
145
        }
146
        }
Lines 152-159 Link Here
152
153
153
    private void updateProfiles() {
154
    private void updateProfiles() {
154
        profiles.removeAllItems();
155
        profiles.removeAllItems();
155
        for (ProfileProblemsProviderImpl.Profile profile : ProfileProblemsProviderImpl.StandardProfile.values()) {
156
        for (Profile profile : Profile.values()) {
156
            if (profile.getRank() >= reqProfile.getRank()) {
157
            if (profile.compareTo(reqProfile) >= 0) {
157
                profiles.addItem(profile);
158
                profiles.addItem(profile);
158
            }
159
            }
159
        }
160
        }
Lines 172-179 Link Here
172
                final int i,
173
                final int i,
173
                final boolean bln,
174
                final boolean bln,
174
                final boolean bln1) {
175
                final boolean bln1) {
175
            if (o instanceof ProfileProblemsProviderImpl.Profile) {
176
            if (o instanceof Profile) {
176
                o = ((ProfileProblemsProviderImpl.Profile)o).getDisplayName();
177
                o = ((Profile)o).getDisplayName();
177
            }
178
            }
178
            return super.getListCellRendererComponent(jlist, o, i, bln, bln1);
179
            return super.getListCellRendererComponent(jlist, o, i, bln, bln1);
179
        }
180
        }
Lines 218-224 Link Here
218
        }
219
        }
219
220
220
        @NbBundle.Messages({
221
        @NbBundle.Messages({
221
        "FMT_RootWithProfile={0} ({1})"
222
        "FMT_RootWithProfile={0} ({1})",
223
        "MSG_InvalidProfile=<Invalid>"
222
        })
224
        })
223
        @Override
225
        @Override
224
        public Component getListCellRendererComponent(
226
        public Component getListCellRendererComponent(
Lines 242-248 Link Here
242
                final ProfileProblemsProviderImpl.Reference e = (ProfileProblemsProviderImpl.Reference) o;
244
                final ProfileProblemsProviderImpl.Reference e = (ProfileProblemsProviderImpl.Reference) o;
243
                root.setText(e.getDisplayName());
245
                root.setText(e.getDisplayName());
244
                root.setIcon(e.getIcon());
246
                root.setIcon(e.getIcon());
245
                profile.setText(e.getRequiredProfile().getDisplayName());
247
                final Profile requiredProfile = e.getRequiredProfile();
248
                if (requiredProfile == null) {
249
                    profile.setText(String.format(
250
                        "<html><font color=\"#A40000\">%s", //NOI18N
251
                        Bundle.MSG_InvalidProfile()));
252
                } else {
253
                    profile.setText(requiredProfile.getDisplayName());
254
                }
246
                container.setToolTipText(e.getToolTipText());
255
                container.setToolTipText(e.getToolTipText());
247
            } else {
256
            } else {
248
                root.setText("");   //NOI18N
257
                root.setText("");   //NOI18N
Lines 256-269 Link Here
256
265
257
    private static final class LibsModel extends AbstractListModel {
266
    private static final class LibsModel extends AbstractListModel {
258
267
259
        private final ProfileProblemsProviderImpl.Profile currentProfile;
268
        private final Profile currentProfile;
260
        private final Collection<? extends ProfileProblemsProviderImpl.Reference> state;
269
        private final Collection<? extends ProfileProblemsProviderImpl.Reference> state;
261
        private final Set<ProfileProblemsProviderImpl.Reference> toRemove;
270
        private final Set<ProfileProblemsProviderImpl.Reference> toRemove;
262
        private final List<ProfileProblemsProviderImpl.Reference> data;
271
        private final List<ProfileProblemsProviderImpl.Reference> data;
263
        private boolean updated;
272
        private boolean updated;
264
273
265
        LibsModel(
274
        LibsModel(
266
                @NonNull final ProfileProblemsProviderImpl.Profile currentProfile,
275
                @NonNull final Profile currentProfile,
267
                @NonNull Collection<? extends ProfileProblemsProviderImpl.Reference> state) {
276
                @NonNull Collection<? extends ProfileProblemsProviderImpl.Reference> state) {
268
            this.currentProfile = currentProfile;
277
            this.currentProfile = currentProfile;
269
            this.state = state;
278
            this.state = state;
Lines 298-304 Link Here
298
        };
307
        };
299
308
300
        @NonNull
309
        @NonNull
301
        ProfileProblemsProviderImpl.Profile requiredProfile() {
310
        Profile requiredProfile() {
302
            return ProfileProblemsProviderImpl.requiredProfile(data, currentProfile);
311
            return ProfileProblemsProviderImpl.requiredProfile(data, currentProfile);
303
        }
312
        }
304
313
Lines 319-325 Link Here
319
            data.clear();
328
            data.clear();
320
            for (ProfileProblemsProviderImpl.Reference ref : state) {
329
            for (ProfileProblemsProviderImpl.Reference ref : state) {
321
                if (!toRemove.contains(ref) &&
330
                if (!toRemove.contains(ref) &&
322
                    !(updated && ref.getRequiredProfile().isValid())) {
331
                    !(updated && ref.getRequiredProfile() != null)) {
323
                    data.add(ref);
332
                    data.add(ref);
324
                }
333
                }
325
            }
334
            }
(-)a/java.project/src/org/netbeans/modules/java/project/ProfileProblemsProviderImpl.java (-177 / +87 lines)
Lines 53-59 Link Here
53
import java.util.Arrays;
53
import java.util.Arrays;
54
import java.util.Collection;
54
import java.util.Collection;
55
import java.util.Collections;
55
import java.util.Collections;
56
import java.util.HashMap;
57
import java.util.HashSet;
56
import java.util.HashSet;
58
import java.util.Iterator;
57
import java.util.Iterator;
59
import java.util.LinkedHashMap;
58
import java.util.LinkedHashMap;
Lines 65-71 Link Here
65
import java.util.concurrent.Future;
64
import java.util.concurrent.Future;
66
import java.util.concurrent.FutureTask;
65
import java.util.concurrent.FutureTask;
67
import java.util.concurrent.RunnableFuture;
66
import java.util.concurrent.RunnableFuture;
68
import java.util.concurrent.atomic.AtomicBoolean;
69
import java.util.jar.Attributes;
67
import java.util.jar.Attributes;
70
import java.util.jar.Manifest;
68
import java.util.jar.Manifest;
71
import java.util.logging.Level;
69
import java.util.logging.Level;
Lines 79-84 Link Here
79
import org.netbeans.api.annotations.common.NullAllowed;
77
import org.netbeans.api.annotations.common.NullAllowed;
80
import org.netbeans.api.java.classpath.ClassPath;
78
import org.netbeans.api.java.classpath.ClassPath;
81
import org.netbeans.api.java.queries.SourceLevelQuery;
79
import org.netbeans.api.java.queries.SourceLevelQuery;
80
import org.netbeans.api.java.queries.SourceLevelQuery.Profile;
82
import org.netbeans.api.project.FileOwnerQuery;
81
import org.netbeans.api.project.FileOwnerQuery;
83
import org.netbeans.api.project.Project;
82
import org.netbeans.api.project.Project;
84
import org.netbeans.api.project.ProjectManager;
83
import org.netbeans.api.project.ProjectManager;
Lines 109-114 Link Here
109
import org.openide.filesystems.URLMapper;
108
import org.openide.filesystems.URLMapper;
110
import org.openide.util.ImageUtilities;
109
import org.openide.util.ImageUtilities;
111
import org.openide.util.RequestProcessor;
110
import org.openide.util.RequestProcessor;
111
import org.openide.util.Union2;
112
/**
112
/**
113
 *
113
 *
114
 * @author Tomas Zezula
114
 * @author Tomas Zezula
Lines 192-210 Link Here
192
                    @Override
192
                    @Override
193
                    public Collection<? extends ProjectProblem> run() {
193
                    public Collection<? extends ProjectProblem> run() {
194
                        final SourceLevelQuery.Result mySL = listenenOnProjectMetadata();
194
                        final SourceLevelQuery.Result mySL = listenenOnProjectMetadata();
195
                        final Profile profile = StandardProfile.forName(mySL.getProfile());
195
                        final Profile profile = mySL.getProfile();
196
                        if (!profile.isValid() || profile == StandardProfile.DEFAULT) {
196
                        if (profile == Profile.DEFAULT) {
197
                            return Collections.<ProjectProblem>emptySet();
197
                            return Collections.<ProjectProblem>emptySet();
198
                        }
198
                        }
199
                        final Set<Reference> problems = collectReferencesWithWrongProfile(profile);
199
                        final Set<Reference> problems = collectReferencesWithWrongProfile(profile);
200
                        if (problems.isEmpty()) {
200
                        if (problems.isEmpty()) {
201
                            return Collections.<ProjectProblem>emptySet();
201
                            return Collections.<ProjectProblem>emptySet();
202
                        }
202
                        }
203
                        final Profile minProfile = requiredProfile(problems, StandardProfile.forName("dummy"));  //NOI18N
203
                        Profile minProfile = null;
204
                        for (Reference problem : problems) {
205
                            final Profile problemProfile = problem.getRequiredProfile();
206
                            minProfile = max(minProfile, problemProfile);
207
                        }
204
                        return Collections.<ProjectProblem>singleton(
208
                        return Collections.<ProjectProblem>singleton(
205
                                ProjectProblem.createError(
209
                                ProjectProblem.createError(
206
                                LBL_InvalidProfile(),
210
                                LBL_InvalidProfile(),
207
                                minProfile.isValid()
211
                                minProfile != null
208
                                ? DESC_InvalidProfile(profile.getDisplayName(), minProfile.getDisplayName())
212
                                ? DESC_InvalidProfile(profile.getDisplayName(), minProfile.getDisplayName())
209
                                : DESC_IllegalProfile(),
213
                                : DESC_IllegalProfile(),
210
                                new ProfileResolver(
214
                                new ProfileResolver(
Lines 322-329 Link Here
322
                    final String libName = rawEntry.substring(LIB_PREFIX.length(),rawEntry.lastIndexOf('.'));
326
                    final String libName = rawEntry.substring(LIB_PREFIX.length(),rawEntry.lastIndexOf('.'));
323
                    final Library lib = refHelper.findLibrary(libName);
327
                    final Library lib = refHelper.findLibrary(libName);
324
                    if (lib != null) {
328
                    if (lib != null) {
325
                        final Profile minProfile = findProfile(lib.getContent(VOL_CLASSPATH));
329
                        final Union2<Profile,String> minProfileOrName = findProfile(lib.getContent(VOL_CLASSPATH));
326
                        if (isBroken(requiredProfile, minProfile)) {
330
                        final Profile minProfile = minProfileOrName.hasFirst() ? minProfileOrName.first() : null;
331
                        if (isBroken(requiredProfile,  minProfile)) {
327
                            collector.add(new LibraryReference(classPathId, rawEntry, minProfile, lib));
332
                            collector.add(new LibraryReference(classPathId, rawEntry, minProfile, lib));
328
                        }
333
                        }
329
                    }
334
                    }
Lines 333-339 Link Here
333
                        AntArtifact artifact = (AntArtifact)ref[0];
338
                        AntArtifact artifact = (AntArtifact)ref[0];
334
                        final SourceLevelQuery.Result slRes = SourceLevelQuery.getSourceLevel2(artifact.getProject().getProjectDirectory());
339
                        final SourceLevelQuery.Result slRes = SourceLevelQuery.getSourceLevel2(artifact.getProject().getProjectDirectory());
335
                        slResCollector.add(slRes);
340
                        slResCollector.add(slRes);
336
                        final Profile minProfile = StandardProfile.forName(slRes.getProfile());
341
                        final Profile minProfile = slRes.getProfile();
337
                        if (isBroken(requiredProfile, minProfile)) {
342
                        if (isBroken(requiredProfile, minProfile)) {
338
                            collector.add(new ProjectReference(classPathId, rawEntry, minProfile, artifact.getProject()));
343
                            collector.add(new ProjectReference(classPathId, rawEntry, minProfile, artifact.getProject()));
339
                        }
344
                        }
Lines 345-351 Link Here
345
                        final File file = antProjectHelper.resolveFile(path);
350
                        final File file = antProjectHelper.resolveFile(path);
346
                        final URL root = FileUtil.urlForArchiveOrDir(file);
351
                        final URL root = FileUtil.urlForArchiveOrDir(file);
347
                        if (root != null) {
352
                        if (root != null) {
348
                            final Profile minProfile = findProfile(root);
353
                            final Union2<Profile,String> minProfileOrName = findProfile(root);
354
                            final Profile minProfile = minProfileOrName.hasFirst() ? minProfileOrName.first() : null;
349
                            if (isBroken(requiredProfile, minProfile)) {
355
                            if (isBroken(requiredProfile, minProfile)) {
350
                                collector.add(new FileReference(classPathId, rawEntry, minProfile, file));
356
                                collector.add(new FileReference(classPathId, rawEntry, minProfile, file));
351
                            }
357
                            }
Lines 367-373 Link Here
367
                    final File file = antProjectHelper.resolveFile(propName);
373
                    final File file = antProjectHelper.resolveFile(propName);
368
                    final URL root = FileUtil.urlForArchiveOrDir(file);
374
                    final URL root = FileUtil.urlForArchiveOrDir(file);
369
                    if (root != null) {
375
                    if (root != null) {
370
                        final Profile minProfile = findProfile(root);
376
                        final Union2<Profile,String> minProfileOrName = findProfile(root);
377
                        final Profile minProfile = minProfileOrName.hasFirst() ? minProfileOrName.first() : null;
371
                        if (isBroken(requiredProfile, minProfile)) {
378
                        if (isBroken(requiredProfile, minProfile)) {
372
                            collector.add(new FileReference(classPathId, rawEntry, minProfile, file));
379
                            collector.add(new FileReference(classPathId, rawEntry, minProfile, file));
373
                        }
380
                        }
Lines 379-390 Link Here
379
386
380
    private static boolean isBroken(
387
    private static boolean isBroken(
381
            @NonNull final Profile requiredProfile,
388
            @NonNull final Profile requiredProfile,
382
            @NonNull final Profile profile) {
389
            @NullAllowed final Profile profile) {
383
        if (!profile.isValid()) {
390
        if (profile == null) {
384
            return true;
391
            return true;
385
        }
392
        }
386
        final Profile max = max(requiredProfile, profile);
393
        final Profile max = max(requiredProfile, profile);
387
        return !max.equals(StandardProfile.DEFAULT) &&
394
        return !max.equals(Profile.DEFAULT) &&
388
               !max.equals(requiredProfile);
395
               !max.equals(requiredProfile);
389
    }
396
    }
390
397
Lines 398-420 Link Here
398
        return reference;
405
        return reference;
399
    }
406
    }
400
407
401
    @CheckForNull
408
    @NonNull
402
    private static Profile findProfile(@NonNull final Iterable<? extends URL> roots) {
409
    private static Union2<Profile,String> findProfile(@NonNull final Iterable<? extends URL> roots) {
403
        Profile current = StandardProfile.DEFAULT;
410
        Profile current = Profile.DEFAULT;
404
        for (URL root : roots) {
411
        for (URL root : roots) {
405
            final Profile rootProfile = findProfile(root);
412
            final Union2<Profile,String> rootProfile = findProfile(root);
406
            if (!rootProfile.isValid()) {
413
            if (!rootProfile.hasFirst()) {
407
                //Broken profile - no need to continue
414
                //Broken profile - no need to continue
408
                return rootProfile;
415
                return rootProfile;
409
            }
416
            }
410
            current = max(current, rootProfile);
417
            current = max(current, rootProfile.first());
411
        }
418
        }
412
        return current;
419
        return Union2.<Profile,String>createFirst(current);
413
    }
420
    }
414
421
415
    @NonNull
422
    @NonNull
416
    private static Profile findProfile(@NonNull URL root) {        
423
    private static Union2<Profile,String> findProfile(@NonNull URL root) {
417
        Profile res;
424
        Union2<Profile,String> res;
418
        final ArchiveCache.Key key = ArchiveCache.createKey(root);
425
        final ArchiveCache.Key key = ArchiveCache.createKey(root);
419
        if (key != null) {
426
        if (key != null) {
420
            res = ArchiveCache.getProfile(key);
427
            res = ArchiveCache.getProfile(key);
Lines 422-440 Link Here
422
                return res;
429
                return res;
423
            }
430
            }
424
        }
431
        }
425
        res = StandardProfile.DEFAULT;
432
        String profileName = null;
426
        final FileObject rootFo = URLMapper.findFileObject(root);
433
        final FileObject rootFo = URLMapper.findFileObject(root);
427
        if (rootFo != null) {
434
        if (rootFo != null) {
428
            final FileObject manifestFile = rootFo.getFileObject(RES_MANIFEST);
435
            final FileObject manifestFile = rootFo.getFileObject(RES_MANIFEST);
429
            if (manifestFile != null) {
436
            if (manifestFile != null) {
430
                try {
437
                try {
431
                    final InputStream in = manifestFile.getInputStream();
438
                    try (InputStream in = manifestFile.getInputStream()) {
432
                    try {
433
                        final Manifest manifest = new Manifest(in);
439
                        final Manifest manifest = new Manifest(in);
434
                        final Attributes attrs = manifest.getMainAttributes();
440
                        final Attributes attrs = manifest.getMainAttributes();
435
                        res = StandardProfile.forName(attrs.getValue(ATTR_PROFILE));
441
                        profileName = attrs.getValue(ATTR_PROFILE);
436
                    } finally {
437
                        in.close();
438
                    }
442
                    }
439
                } catch (IOException ioe) {
443
                } catch (IOException ioe) {
440
                    LOG.log(
444
                    LOG.log(
Lines 444-449 Link Here
444
                }
448
                }
445
            }
449
            }
446
        }
450
        }
451
        final Profile profile = Profile.forName(profileName);
452
        res = profile != null ?
453
                Union2.<Profile,String>createFirst(profile) :
454
                Union2.<Profile,String>createSecond(profileName);
447
        if (key != null) {
455
        if (key != null) {
448
            ArchiveCache.putProfile(key, res);
456
            ArchiveCache.putProfile(key, res);
449
        }
457
        }
Lines 451-585 Link Here
451
    }
459
    }
452
460
453
461
454
    @NonNull
462
    @CheckForNull
455
    static Profile max (@NonNull Profile a, @NonNull Profile b) {        
463
    static Profile max (@NullAllowed Profile a, @NullAllowed Profile b) {
456
        return a.getRank() >= b.getRank() ?
464
        if (b == null) {
457
                a :
465
            return a;
458
                b;
466
        }
467
        if (a == null) {
468
            return b;
469
        }
470
        return a.compareTo(b) <= 0 ?
471
            b :
472
            a;
459
    }
473
    }
460
474
461
    @NonNull
475
    @NonNull
462
    static Profile requiredProfile(
476
    static Profile requiredProfile(
463
            @NonNull final Collection<? extends Reference> state,
477
            @NonNull final Collection<? extends Reference> state,
464
            @NonNull Profile current) {
478
            @NonNull Profile initial) {
479
        Profile current = initial;
465
        for (ProfileProblemsProviderImpl.Reference re : state) {
480
        for (ProfileProblemsProviderImpl.Reference re : state) {
466
            current = max(current, re.getRequiredProfile());
481
            current = max(current, re.getRequiredProfile());
467
        }
482
        }
468
        return current;
483
        return current;
469
    }
484
    }
470
485
    
471
    static interface Profile {
472
        @NonNull
473
        String getAntName();
474
        @NonNull
475
        String getDisplayName();
476
        boolean isValid();
477
        int getRank();
478
    }
479
480
    @NbBundle.Messages({
481
        "NAME_Compact1=Compact 1",
482
        "NAME_Compact2=Compact 2",
483
        "NAME_Compact3=Compact 3",
484
        "NAME_FullJRE=Full JRE"
485
    })
486
    static enum StandardProfile implements Profile {
487
488
        COMPACT1(1, "compact1", Bundle.NAME_Compact1()),
489
        COMPACT2(2, "compact2", Bundle.NAME_Compact2()),
490
        COMPACT3(3, "compact3", Bundle.NAME_Compact3()),
491
        DEFAULT(Integer.MAX_VALUE, "default", Bundle.NAME_FullJRE());
492
493
        private static final Map<String,StandardProfile> profilesByName =
494
                new HashMap<String, StandardProfile>();
495
        static {
496
            for (StandardProfile sp : values()) {
497
                profilesByName.put(sp.getAntName(), sp);
498
            }
499
        }
500
501
        private final int rank;
502
        private final String antName;
503
        private final String displayName;
504
505
        private StandardProfile(
506
                final int rank,
507
                @NonNull final String antName,
508
                @NonNull final String displayName) {
509
            this.rank = rank;
510
            this.antName = antName;
511
            this.displayName = displayName;
512
        }
513
514
515
        @Override
516
        @NonNull
517
        public String getAntName() {
518
            return antName;
519
        }
520
521
        @Override
522
        @NonNull
523
        public String getDisplayName() {
524
            return displayName;
525
        }
526
527
        @Override
528
        public int getRank() {
529
            return rank;
530
        }
531
532
        @Override
533
        public boolean isValid() {
534
            return true;
535
        }
536
537
        @NonNull
538
        static Profile forName(@NullAllowed String antName) {
539
            if (antName == null) {
540
                antName = DEFAULT.getAntName();
541
            }
542
            Profile res = profilesByName.get(antName);
543
            if (res == null) {
544
                res = new UnknownProfile(antName);
545
            }
546
            return res;
547
        }
548
549
550
        private static class UnknownProfile implements Profile {
551
552
            private final String antName;
553
554
            UnknownProfile(@NonNull final String antName) {
555
                Parameters.notEmpty("antName", antName);    //NOI18N
556
                this.antName = antName;
557
            }
558
559
            @Override
560
            public String getAntName() {
561
                return antName;
562
            }
563
564
            @Override
565
            public String getDisplayName() {
566
                return antName;
567
            }
568
569
            @Override
570
            public int getRank() {
571
                return Integer.MIN_VALUE;
572
            }
573
574
            @Override
575
            public boolean isValid() {
576
                return false;
577
            }
578
        }
579
580
581
    }
582
583
    abstract static class Reference {
486
    abstract static class Reference {
584
487
585
        private final String classPathId;
488
        private final String classPathId;
Lines 589-609 Link Here
589
        private Reference(
492
        private Reference(
590
                @NonNull final String classPathId,
493
                @NonNull final String classPathId,
591
                @NonNull final String rawId,
494
                @NonNull final String rawId,
592
                @NonNull final Profile requiredProfile) {
495
                @NullAllowed final Profile requiredProfile) {
593
            Parameters.notNull("classPathId", classPathId); //NOI18N
496
            Parameters.notNull("classPathId", classPathId); //NOI18N
594
            Parameters.notNull("rawId", rawId);             //NOI18N
497
            Parameters.notNull("rawId", rawId);             //NOI18N
595
            Parameters.notNull("requiredProfile", requiredProfile); //NOI18N
596
            this.classPathId = classPathId;
498
            this.classPathId = classPathId;
597
            this.rawId = rawId;
499
            this.rawId = rawId;
598
            this.requiredProfile = requiredProfile;
500
            this.requiredProfile = requiredProfile;
599
        }
501
        }
600
502
503
        @NonNull
601
        abstract String getDisplayName();
504
        abstract String getDisplayName();
602
505
506
        @NonNull
603
        abstract String getToolTipText();
507
        abstract String getToolTipText();
604
        
508
509
        @NonNull
605
        abstract Icon getIcon();        
510
        abstract Icon getIcon();        
606
                        
511
512
        @CheckForNull
607
        final Profile getRequiredProfile() {
513
        final Profile getRequiredProfile() {
608
            return requiredProfile;
514
            return requiredProfile;
609
        }
515
        }
Lines 664-670 Link Here
664
        private LibraryReference(
570
        private LibraryReference(
665
                @NonNull final String classPathId,
571
                @NonNull final String classPathId,
666
                @NonNull final String rawId,
572
                @NonNull final String rawId,
667
                @NonNull final Profile requiredProfile,
573
                @NullAllowed final Profile requiredProfile,
668
                @NonNull final Library lib) {
574
                @NonNull final Library lib) {
669
            super(classPathId, rawId, requiredProfile);
575
            super(classPathId, rawId, requiredProfile);
670
            Parameters.notNull("lib", lib); //NOI18N
576
            Parameters.notNull("lib", lib); //NOI18N
Lines 693-699 Link Here
693
        private ProjectReference(
599
        private ProjectReference(
694
                @NonNull final String classPathId,
600
                @NonNull final String classPathId,
695
                @NonNull final String rawId,
601
                @NonNull final String rawId,
696
                @NonNull final Profile requiredProfile,
602
                @NullAllowed final Profile requiredProfile,
697
                @NonNull final Project prj) {
603
                @NonNull final Project prj) {
698
            super(classPathId, rawId, requiredProfile);
604
            super(classPathId, rawId, requiredProfile);
699
            Parameters.notNull("prj", prj); //NOI18N
605
            Parameters.notNull("prj", prj); //NOI18N
Lines 723-729 Link Here
723
        private FileReference(
629
        private FileReference(
724
                @NonNull final String classPathId,
630
                @NonNull final String classPathId,
725
                @NonNull final String rawId,
631
                @NonNull final String rawId,
726
                @NonNull final Profile requiredProfile,
632
                @NullAllowed final Profile requiredProfile,
727
                @NonNull final File file) {
633
                @NonNull final File file) {
728
            super(classPathId, rawId, requiredProfile);
634
            super(classPathId, rawId, requiredProfile);
729
            Parameters.notNull("file", file);   //NOI18N
635
            Parameters.notNull("file", file);   //NOI18N
Lines 806-815 Link Here
806
                                        final Profile newProfile = panel.getProfile();
712
                                        final Profile newProfile = panel.getProfile();
807
                                        final EditableProperties props = antProjectHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
713
                                        final EditableProperties props = antProjectHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
808
                                        if (newProfile == null ||
714
                                        if (newProfile == null ||
809
                                            newProfile == StandardProfile.DEFAULT) {
715
                                            newProfile == Profile.DEFAULT) {
810
                                            props.remove(profileProperty);
716
                                            props.remove(profileProperty);
811
                                        } else {
717
                                        } else {
812
                                            props.put(profileProperty, newProfile.getAntName());
718
                                            props.put(profileProperty, newProfile.getName());
813
                                        }
719
                                        }
814
                                        antProjectHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
720
                                        antProjectHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
815
                                    }
721
                                    }
Lines 848-856 Link Here
848
                "ProfileProblemsProviderImpl.ArchiveCache.size",    //NOI18N
754
                "ProfileProblemsProviderImpl.ArchiveCache.size",    //NOI18N
849
                1<<10);        
755
                1<<10);        
850
756
851
        private static final Map<Key,Profile> cache = new LinkedHashMap<Key, Profile>(16, 0.75f, true) {
757
        private static final Map<Key,Union2<Profile,String>> cache = new LinkedHashMap<Key,Union2<Profile,String>>(16, 0.75f, true) {
852
            @Override
758
            @Override
853
            protected boolean removeEldestEntry(Map.Entry<Key, Profile> entry) {
759
            protected boolean removeEldestEntry(Map.Entry<Key, Union2<Profile,String>> entry) {
854
                return size() > MAX_CACHE_SIZE;
760
                return size() > MAX_CACHE_SIZE;
855
            }
761
            }
856
        };
762
        };
Lines 858-886 Link Here
858
        private ArchiveCache() {}
764
        private ArchiveCache() {}
859
765
860
        @CheckForNull
766
        @CheckForNull
861
        static Profile getProfile(@NonNull final Key key) {
767
        static Union2<Profile,String> getProfile(@NonNull final Key key) {
862
            final Profile res = cache.get(key);
768
            final Union2<Profile,String> res = cache.get(key);
863
            LOG.log(
769
            if (LOG.isLoggable(Level.FINER)) {
864
                Level.FINER,
770
                LOG.log(
865
                "cache[{0}]->{1}",  //NOI18N
771
                    Level.FINER,
866
                new Object[]{
772
                    "cache[{0}]->{1}",  //NOI18N
867
                    key,
773
                    new Object[]{
868
                    res
774
                        key,
869
                });
775
                        res.hasFirst() ? res.first() : res.second()
776
                    });
777
            }
870
            return res;
778
            return res;
871
        }
779
        }
872
780
873
        static void putProfile(
781
        static void putProfile(
874
            @NonNull final  Key key,
782
            @NonNull final  Key key,
875
            @NonNull final Profile profile) {
783
            @NonNull final Union2<Profile,String> profile) {
876
            LOG.log(
784
            if (LOG.isLoggable(Level.FINER)) {
877
                Level.FINER,
785
                LOG.log(
878
                "cache[{0}]<-{1}",   //NOI18N
786
                    Level.FINER,
879
                new Object[]{
787
                    "cache[{0}]<-{1}",   //NOI18N
880
                    key,
788
                    new Object[]{
881
                    profile
789
                        key,
882
                });
790
                        profile.hasFirst() ? profile.first() : profile.second()
883
            cache.put(key, profile);
791
                    });
792
            }
793
            cache.put(key,profile);
884
        }
794
        }
885
795
886
        @CheckForNull
796
        @CheckForNull
(-)a/java.source/nbproject/project.properties (-1 / +1 lines)
Lines 46-52 Link Here
46
javadoc.title=Java Source
46
javadoc.title=Java Source
47
javadoc.arch=${basedir}/arch.xml
47
javadoc.arch=${basedir}/arch.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
49
spec.version.base=0.117.0
49
spec.version.base=0.118.0
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/nb-javac-api.jar
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/nb-javac-api.jar
51
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
51
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
52
    ${o.n.core.dir}/lib/boot.jar:\
52
    ${o.n.core.dir}/lib/boot.jar:\
(-)a/java.source/nbproject/project.xml (-1 / +1 lines)
Lines 64-70 Link Here
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>1</release-version>
66
                        <release-version>1</release-version>
67
                        <specification-version>1.45</specification-version>
67
                        <specification-version>1.47</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
(-)a/java.source/src/org/netbeans/modules/java/source/indexing/APTUtils.java (-2 / +2 lines)
Lines 305-312 Link Here
305
                if (checkOnly) {
305
                if (checkOnly) {
306
                    return vote;
306
                    return vote;
307
                }
307
                }
308
            }
308
            }            
309
            if (JavaIndex.ensureAttributeValue(url, JRE_PROFILE, sourceLevel.getProfile(), checkOnly)) {
309
            if (JavaIndex.ensureAttributeValue(url, JRE_PROFILE, sourceLevel.getProfile().getName(), checkOnly)) {
310
                JavaIndex.LOG.fine("forcing reindex due to jre profile change"); //NOI18N
310
                JavaIndex.LOG.fine("forcing reindex due to jre profile change"); //NOI18N
311
                vote = true;
311
                vote = true;
312
                if (checkOnly) {
312
                if (checkOnly) {
(-)a/java.source/src/org/netbeans/modules/java/source/indexing/JavaParsingContext.java (-1 / +1 lines)
Lines 161-167 Link Here
161
    }
161
    }
162
162
163
    @CheckForNull
163
    @CheckForNull
164
    String getProfile() {
164
    SourceLevelQuery.Profile getProfile() {
165
        final SourceLevelQuery.Result sl = initSourceLevel();
165
        final SourceLevelQuery.Result sl = initSourceLevel();
166
        return sl == null ? null : sl.getProfile();
166
        return sl == null ? null : sl.getProfile();
167
    }
167
    }
(-)a/java.source/src/org/netbeans/modules/java/source/parsing/JavacParser.java (-15 / +6 lines)
Lines 752-758 Link Here
752
            @NonNull final ClasspathInfo cpInfo,
752
            @NonNull final ClasspathInfo cpInfo,
753
            @NullAllowed final DiagnosticListener<? super JavaFileObject> diagnosticListener,
753
            @NullAllowed final DiagnosticListener<? super JavaFileObject> diagnosticListener,
754
            @NullAllowed final String sourceLevel,
754
            @NullAllowed final String sourceLevel,
755
            @NullAllowed final String sourceProfile,
755
            @NullAllowed final SourceLevelQuery.Profile sourceProfile,
756
            @NullAllowed final ClassNamesForFileOraculum cnih,
756
            @NullAllowed final ClassNamesForFileOraculum cnih,
757
            @NullAllowed final DuplicateClassChecker dcc,
757
            @NullAllowed final DuplicateClassChecker dcc,
758
            @NullAllowed final CancelService cancelService,
758
            @NullAllowed final CancelService cancelService,
Lines 764-770 Link Here
764
            @NonNull final ClasspathInfo cpInfo,
764
            @NonNull final ClasspathInfo cpInfo,
765
            @NullAllowed final DiagnosticListener<? super JavaFileObject> diagnosticListener,
765
            @NullAllowed final DiagnosticListener<? super JavaFileObject> diagnosticListener,
766
            @NullAllowed final String sourceLevel,
766
            @NullAllowed final String sourceLevel,
767
            @NullAllowed final String sourceProfile,
767
            @NullAllowed SourceLevelQuery.Profile sourceProfile,
768
            final boolean backgroundCompilation,
768
            final boolean backgroundCompilation,
769
            @NullAllowed final ClassNamesForFileOraculum cnih,
769
            @NullAllowed final ClassNamesForFileOraculum cnih,
770
            @NullAllowed final DuplicateClassChecker dcc,
770
            @NullAllowed final DuplicateClassChecker dcc,
Lines 773-779 Link Here
773
        final List<String> options = new ArrayList<String>();
773
        final List<String> options = new ArrayList<String>();
774
        String lintOptions = CompilerSettings.getCommandLine();
774
        String lintOptions = CompilerSettings.getCommandLine();
775
        com.sun.tools.javac.code.Source validatedSourceLevel = validateSourceLevel(sourceLevel, cpInfo);
775
        com.sun.tools.javac.code.Source validatedSourceLevel = validateSourceLevel(sourceLevel, cpInfo);
776
        com.sun.tools.javac.jvm.Profile validatedProfile = validateSourceProfile(sourceProfile);
777
        if (lintOptions.length() > 0) {
776
        if (lintOptions.length() > 0) {
778
            options.addAll(Arrays.asList(lintOptions.split(" ")));
777
            options.addAll(Arrays.asList(lintOptions.split(" ")));
779
        }
778
        }
Lines 798-806 Link Here
798
        options.add("-g:vars");  // NOI18N, Make the compiler to maintain local variables table
797
        options.add("-g:vars");  // NOI18N, Make the compiler to maintain local variables table
799
        options.add("-source");  // NOI18N
798
        options.add("-source");  // NOI18N
800
        options.add(validatedSourceLevel.name);
799
        options.add(validatedSourceLevel.name);
801
        if (validatedProfile != null) {
800
        if (sourceProfile != null &&
801
            sourceProfile != SourceLevelQuery.Profile.DEFAULT) {
802
            options.add("-profile");    //NOI18N, Limit JRE to required compact profile
802
            options.add("-profile");    //NOI18N, Limit JRE to required compact profile
803
            options.add(validatedProfile.name);
803
            options.add(sourceProfile.getName());
804
        }
804
        }
805
        options.add("-XDdiags=-source");  // NOI18N
805
        options.add("-XDdiags=-source");  // NOI18N
806
        options.add("-XDdiagsFormat=%L%m|%L%m|%L%m");  // NOI18N
806
        options.add("-XDdiagsFormat=%L%m|%L%m|%L%m");  // NOI18N
Lines 922-937 Link Here
922
            return sources[sources.length-1];
922
            return sources[sources.length-1];
923
        }
923
        }
924
    }
924
    }
925
925
    
926
    @CheckForNull
927
    private static com.sun.tools.javac.jvm.Profile validateSourceProfile(
928
            @NullAllowed String profileName) {
929
        if (profileName == null) {
930
            return null;
931
        }
932
        return com.sun.tools.javac.jvm.Profile.lookup(profileName);
933
    }
934
935
    private static void logTime (FileObject source, Phase phase, long time) {
926
    private static void logTime (FileObject source, Phase phase, long time) {
936
        assert source != null && phase != null;
927
        assert source != null && phase != null;
937
        String message = phase2Message.get(phase);
928
        String message = phase2Message.get(phase);

Return to bug 228278