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

(-)a/java.j2seproject/apichanges.xml (-2 / +13 lines)
Lines 106-112 Link Here
106
    <!-- ACTUAL CHANGES BEGIN HERE: -->
106
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
107
108
    <changes>
108
    <changes>
109
109
        <change id="J2SEProjectPlatform">
110
            <api name="jseprojects"/>
111
            <summary>Added API to allow J2SE Project extension to get and set active project platform</summary>
112
            <version major="1" minor="63"/>
113
            <date day="2" month="5" year="2013"/>
114
            <author login="tzezula"/>
115
            <compatibility addition="yes"/>
116
            <description>
117
                Added a new friend API to allow J2SE Project extension to obtain and set active project platform.
118
            </description>
119
            <class package="org.netbeans.modules.java.j2seproject.api" name="J2SEProjectPlatform"/>
120
            <issue number="229085"/>
121
        </change>
110
        <change id="J2SECategoryExtensionProvider">
122
        <change id="J2SECategoryExtensionProvider">
111
            <api name="jseprojects"/>
123
            <api name="jseprojects"/>
112
            <summary></summary>
124
            <summary></summary>
Lines 122-128 Link Here
122
            <class package="org.netbeans.modules.java.j2seproject.api" name="J2SECategoryExtensionProvider"/>
134
            <class package="org.netbeans.modules.java.j2seproject.api" name="J2SECategoryExtensionProvider"/>
123
            <issue number="218422"/>
135
            <issue number="218422"/>
124
        </change>
136
        </change>
125
126
        <change id="GeneratedFilesInterceptor">
137
        <change id="GeneratedFilesInterceptor">
127
            <api name="jseprojects"/>
138
            <api name="jseprojects"/>
128
            <summary></summary>
139
            <summary></summary>
(-)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.62.0
45
spec.version.base=1.63.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/src/org/netbeans/modules/java/j2seproject/J2SEProject.java (-39 / +3 lines)
Lines 407-413 Link Here
407
            BrokenReferencesSupport.createReferenceProblemsProvider(helper, refHelper, eval, lvp.getBreakableProperties(), lvp.getPlatformProperties()),
407
            BrokenReferencesSupport.createReferenceProblemsProvider(helper, refHelper, eval, lvp.getBreakableProperties(), lvp.getPlatformProperties()),
408
            BrokenReferencesSupport.createPlatformVersionProblemProvider(helper, eval, new PlatformChangedHook(), JavaPlatform.getDefault().getSpecification().getName(), J2SEProjectProperties.JAVA_PLATFORM, J2SEProjectProperties.JAVAC_SOURCE, J2SEProjectProperties.JAVAC_TARGET),
408
            BrokenReferencesSupport.createPlatformVersionProblemProvider(helper, eval, new PlatformChangedHook(), JavaPlatform.getDefault().getSpecification().getName(), J2SEProjectProperties.JAVA_PLATFORM, J2SEProjectProperties.JAVAC_SOURCE, J2SEProjectProperties.JAVAC_TARGET),
409
            BrokenReferencesSupport.createProfileProblemProvider(helper, refHelper, eval, J2SEProjectProperties.JAVAC_PROFILE, ProjectProperties.RUN_CLASSPATH, ProjectProperties.ENDORSED_CLASSPATH),
409
            BrokenReferencesSupport.createProfileProblemProvider(helper, refHelper, eval, J2SEProjectProperties.JAVAC_PROFILE, ProjectProperties.RUN_CLASSPATH, ProjectProperties.ENDORSED_CLASSPATH),
410
            UILookupMergerSupport.createProjectProblemsProviderMerger()
410
            UILookupMergerSupport.createProjectProblemsProviderMerger(),
411
            new J2SEProjectPlatformImpl(this)
411
        );
412
        );
412
        lookup = base; // in case LookupProvider's call Project.getLookup
413
        lookup = base; // in case LookupProvider's call Project.getLookup
413
        return LookupProviderSupport.createCompositeLookup(base, "Projects/org-netbeans-modules-java-j2seproject/Lookup"); //NOI18N
414
        return LookupProviderSupport.createCompositeLookup(base, "Projects/org-netbeans-modules-java-j2seproject/Lookup"); //NOI18N
Lines 1054-1100 Link Here
1054
    }
1055
    }
1055
1056
1056
    private final class PlatformChangedHook implements BrokenReferencesSupport.PlatformUpdatedCallBack {
1057
    private final class PlatformChangedHook implements BrokenReferencesSupport.PlatformUpdatedCallBack {
1057
1058
        @Override
1058
        @Override
1059
        public void platformPropertyUpdated(@NonNull final JavaPlatform platform) {
1059
        public void platformPropertyUpdated(@NonNull final JavaPlatform platform) {
1060
            final boolean remove = platform.equals(JavaPlatformManager.getDefault().getDefaultPlatform());
1060
            J2SEProjectPlatformImpl.updateProjectXml(platform, updateHelper);
1061
            final Element root = helper.getPrimaryConfigurationData(true);
1062
            boolean changed = false;
1063
            if (remove) {
1064
                final Element platformElement = XMLUtil.findElement(
1065
                    root,
1066
                    "explicit-platform",    //NOI18N
1067
                    PROJECT_CONFIGURATION_NAMESPACE);
1068
                if (platformElement != null) {
1069
                    root.removeChild(platformElement);
1070
                    changed = true;
1071
                }
1072
            } else {
1073
                Element insertBefore = null;
1074
                for (Element e : XMLUtil.findSubElements(root)) {
1075
                    final String name = e.getNodeName();
1076
                    if (! "name".equals(name) &&                  //NOI18N
1077
                        ! "minimum-ant-version".equals(name)) {   //NOI18N
1078
                        insertBefore = e;
1079
                        break;
1080
                    }
1081
                }
1082
                final Element platformNode = insertBefore.getOwnerDocument().createElementNS(
1083
                        PROJECT_CONFIGURATION_NAMESPACE,
1084
                        "explicit-platform"); //NOI18N
1085
                platformNode.setAttribute(
1086
                        "explicit-source-supported",                                                             //NOI18N
1087
                        platform.getSpecification().getVersion().compareTo(new SpecificationVersion("1.3"))>0?   //NOI18N
1088
                            "true":                                                                              //NOI18N
1089
                            "false");                                                                            //NOI18N
1090
                root.insertBefore(platformNode, insertBefore);
1091
                changed = true;
1092
            }
1093
            if (changed) {
1094
                helper.putPrimaryConfigurationData(root, true);
1095
            }
1096
        }
1061
        }
1097
1098
    }
1062
    }
1099
1063
1100
}
1064
}
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProjectPlatformImpl.java (+169 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.j2seproject;
43
44
import java.io.IOException;
45
import org.netbeans.api.annotations.common.CheckForNull;
46
import org.netbeans.api.annotations.common.NonNull;
47
import org.netbeans.api.java.platform.JavaPlatform;
48
import org.netbeans.api.java.platform.JavaPlatformManager;
49
import org.netbeans.api.project.ProjectManager;
50
import org.netbeans.modules.java.api.common.ant.UpdateHelper;
51
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
52
import org.netbeans.modules.java.j2seproject.api.J2SEProjectPlatform;
53
import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties;
54
import org.netbeans.spi.project.support.ant.AntProjectHelper;
55
import org.netbeans.spi.project.support.ant.EditableProperties;
56
import org.openide.modules.SpecificationVersion;
57
import org.openide.util.Mutex;
58
import org.openide.util.MutexException;
59
import org.openide.util.Parameters;
60
import org.openide.xml.XMLUtil;
61
import org.w3c.dom.Element;
62
63
/**
64
 *
65
 * @author Tomas Zezula
66
 */
67
class J2SEProjectPlatformImpl implements J2SEProjectPlatform {
68
69
    private static final String SE_PLATFORM = "j2se";   //NOI18N
70
    private static final String PROP_PLATFORM_ANT_NAME = "platform.ant.name";    //NOI18N
71
72
    private final J2SEProject project;
73
74
    J2SEProjectPlatformImpl(@NonNull final J2SEProject project) {
75
        assert project != null;
76
        this.project = project;
77
    }
78
79
    @Override
80
    @CheckForNull
81
    public JavaPlatform getProjectPlatform() {
82
        return ProjectManager.mutex().readAccess(new Mutex.Action<JavaPlatform>(){
83
            @Override
84
            public JavaPlatform run() {
85
                return CommonProjectUtils.getActivePlatform(
86
                    project.evaluator().getProperty(J2SEProjectProperties.JAVA_PLATFORM));
87
            }
88
        });
89
    }
90
91
    @Override
92
    public void setProjectPlatform(@NonNull final JavaPlatform platform) throws IOException {
93
        Parameters.notNull("platform", platform);
94
        if (!SE_PLATFORM.equals(platform.getSpecification().getName())) {
95
            throw new IllegalArgumentException(
96
                String.format(
97
                    "Not J2SE Platform: %s (%s)",       //NOI18N
98
                    platform.getDisplayName(),
99
                    platform.getSpecification().getName()));
100
        }
101
        if (platform.getInstallFolders().isEmpty()) {
102
            throw new IllegalArgumentException(
103
                String.format(
104
                    "Broken Platform %s",       //NOI18N
105
                    platform.getDisplayName()));
106
        }
107
        try {
108
            ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
109
                @Override
110
                public Void run() throws IOException {
111
                    final String platformId = platform.getProperties().get(PROP_PLATFORM_ANT_NAME);
112
                    final UpdateHelper uh = project.getUpdateHelper();
113
                    final EditableProperties props = uh.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
114
                    props.setProperty(J2SEProjectProperties.JAVA_PLATFORM, platformId);
115
                    uh.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
116
                    updateProjectXml(platform, uh);
117
                    ProjectManager.getDefault().saveProject(project);
118
                    return null;
119
                }
120
            });
121
        } catch (MutexException e) {
122
            throw (IOException) e.getCause();
123
        }
124
    }
125
126
    static boolean updateProjectXml(
127
            @NonNull final JavaPlatform platform,
128
            @NonNull final UpdateHelper helper) {
129
        assert ProjectManager.mutex().isWriteAccess();
130
        final boolean remove = platform.equals(JavaPlatformManager.getDefault().getDefaultPlatform());
131
        final Element root = helper.getPrimaryConfigurationData(true);
132
        boolean changed = false;
133
        if (remove) {
134
            final Element platformElement = XMLUtil.findElement(
135
                root,
136
                "explicit-platform",    //NOI18N
137
                J2SEProject.PROJECT_CONFIGURATION_NAMESPACE);
138
            if (platformElement != null) {
139
                root.removeChild(platformElement);
140
                changed = true;
141
            }
142
        } else {
143
            Element insertBefore = null;
144
            for (Element e : XMLUtil.findSubElements(root)) {
145
                final String name = e.getNodeName();
146
                if (! "name".equals(name) &&                  //NOI18N
147
                    ! "minimum-ant-version".equals(name)) {   //NOI18N
148
                    insertBefore = e;
149
                    break;
150
                }
151
            }
152
            final Element platformNode = insertBefore.getOwnerDocument().createElementNS(
153
                    J2SEProject.PROJECT_CONFIGURATION_NAMESPACE,
154
                    "explicit-platform"); //NOI18N
155
            platformNode.setAttribute(
156
                    "explicit-source-supported",    //NOI18N
157
                    platform.getSpecification().getVersion().compareTo(new SpecificationVersion("1.3"))>0?   //NOI18N
158
                        "true":                                                                              //NOI18N
159
                        "false");                                                                            //NOI18N
160
            root.insertBefore(platformNode, insertBefore);
161
            changed = true;
162
        }
163
        if (changed) {
164
            helper.putPrimaryConfigurationData(root, true);
165
        }
166
        return changed;
167
    }
168
169
}
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/api/J2SEProjectPlatform.java (+73 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.j2seproject.api;
43
44
import java.io.IOException;
45
import org.netbeans.api.annotations.common.CheckForNull;
46
import org.netbeans.api.annotations.common.NonNull;
47
import org.netbeans.api.java.platform.JavaPlatform;
48
49
/**
50
 * Active {@link JavaPlatform} for J2SE project extensions.
51
 * Allows J2SE project extensions to obtain and set the active project platform
52
 * @author Tomas Zezula
53
 * @since 1.63
54
 */
55
public interface J2SEProjectPlatform {
56
57
    /**
58
     * Return the active project platform.
59
     * @return the active {@link JavaPlatform} or null if the
60
     * active platform cannot be resolved (it's broken)
61
     */
62
    @CheckForNull
63
    JavaPlatform getProjectPlatform();
64
65
    /**
66
     * Sets active project platform.
67
     * @param platform the platform to become active project active platform
68
     * @throws IOException in case of IO error.
69
     * @throws IllegalArgumentException if the platform is not a valid J2SE platform.
70
     */
71
    void setProjectPlatform(@NonNull final JavaPlatform platform) throws IOException;
72
73
}

Return to bug 229085