diff --git a/java.j2seproject/apichanges.xml b/java.j2seproject/apichanges.xml --- a/java.j2seproject/apichanges.xml +++ b/java.j2seproject/apichanges.xml @@ -107,6 +107,22 @@ + + + + + + + + + The J2SEProject calls all the instances of the GeneratedFilesInterceptor + registered in the project Lookup when a a build script file has been updated + or created. + + + + + Enable correct handling of properties in Project Property dialog of an extension of JSE Project diff --git a/java.j2seproject/nbproject/project.properties b/java.j2seproject/nbproject/project.properties --- a/java.j2seproject/nbproject/project.properties +++ b/java.j2seproject/nbproject/project.properties @@ -42,7 +42,7 @@ javac.compilerargs=-Xlint -Xlint:-serial javac.source=1.6 -spec.version.base=1.57.0 +spec.version.base=1.58.0 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/GeneratedFilesInterceptorSupport.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/GeneratedFilesInterceptorSupport.java new file mode 100644 --- /dev/null +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/GeneratedFilesInterceptorSupport.java @@ -0,0 +1,99 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.java.j2seproject; + +import java.io.IOException; +import java.net.URL; +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.project.Project; +import org.netbeans.modules.java.j2seproject.api.GeneratedFilesInterceptor; +import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; +import org.openide.util.Parameters; + +/** + * + * @author Tomas Zezula + */ +class GeneratedFilesInterceptorSupport { + + private final Project prj; + private final GeneratedFilesHelper genFilesHelper; + + GeneratedFilesInterceptorSupport( + @NonNull final Project prj, + @NonNull final GeneratedFilesHelper genFilesHelper) { + Parameters.notNull("prj", prj); //NOI18N + Parameters.notNull("genFilesHelper", genFilesHelper); //NOI18N + this.prj = prj; + this.genFilesHelper = genFilesHelper; + } + + void generateBuildScriptFromStylesheet( + @NonNull final String path, + @NonNull final URL stylesheet) throws IOException { + genFilesHelper.generateBuildScriptFromStylesheet(path, stylesheet); + callInterceptors(prj, path); + } + + boolean refreshBuildScript( + @NonNull final String path, + @NonNull final URL stylesheet, + @NonNull final boolean checkForProjectXmlModified) throws IOException { + final boolean ret = genFilesHelper.refreshBuildScript(path, stylesheet, checkForProjectXmlModified); + if (ret) { + callInterceptors(prj, path); + } + return ret; + } + + private static void callInterceptors( + @NonNull final Project prj, + @NonNull final String path) { + final Iterable interceptors = + prj.getLookup().lookupAll(GeneratedFilesInterceptor.class); + for (GeneratedFilesInterceptor interceptor : interceptors) { + interceptor.fileGenerated(prj, path); + } + } + + +} diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java @@ -199,6 +199,7 @@ private SourceRoots testRoots; private final ClassPathProviderImpl cpProvider; private final ClassPathModifier cpMod; + private final GeneratedFilesInterceptorSupport gfis; private AntBuildExtender buildExtender; @@ -232,6 +233,7 @@ this.cpProvider = new ClassPathProviderImpl(this.helper, evaluator(), getSourceRoots(),getTestSourceRoots()); //Does not use APH to get/put properties/cfgdata this.cpMod = new ClassPathModifier(this, this.updateHelper, evaluator(), refHelper, null, createClassPathModifierCallback(), null); lookup = createLookup(aux, new J2SEProjectOperations(this, updateProject)); + this.gfis = new GeneratedFilesInterceptorSupport(this, genFilesHelper); } private ClassPathModifier.Callback createClassPathModifierCallback() { @@ -522,16 +524,16 @@ } } if (forceRewriteBuildImpl) { - genFilesHelper.generateBuildScriptFromStylesheet( + gfis.generateBuildScriptFromStylesheet( GeneratedFilesHelper.BUILD_IMPL_XML_PATH, J2SEProject.class.getResource("resources/build-impl.xsl")); } else { - genFilesHelper.refreshBuildScript( + gfis.refreshBuildScript( GeneratedFilesHelper.BUILD_IMPL_XML_PATH, J2SEProject.class.getResource("resources/build-impl.xsl"), false); } - genFilesHelper.refreshBuildScript( + gfis.refreshBuildScript( J2SEProjectUtil.getBuildXmlName(J2SEProject.this), J2SEProject.class.getResource("resources/build.xsl"), false); @@ -558,11 +560,11 @@ try { if (updateHelper.isCurrent()) { //Refresh build-impl.xml only for j2seproject/2 - genFilesHelper.refreshBuildScript( + gfis.refreshBuildScript( GeneratedFilesHelper.BUILD_IMPL_XML_PATH, J2SEProject.class.getResource("resources/build-impl.xsl"), true); - genFilesHelper.refreshBuildScript( + gfis.refreshBuildScript( J2SEProjectUtil.getBuildXmlName(J2SEProject.this), J2SEProject.class.getResource("resources/build.xsl"), true); diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/api/GeneratedFilesInterceptor.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/api/GeneratedFilesInterceptor.java new file mode 100644 --- /dev/null +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/api/GeneratedFilesInterceptor.java @@ -0,0 +1,64 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.java.j2seproject.api; + +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.project.Project; +import org.openide.util.Lookup; + +/** + * Notifies the J2SE Project extension about build script update. + * The J2SEProject calls all the instances of the @link GeneratedFilesInterceptor} + * registered in the project {@link Lookup} when a a build script file has been + * updated or created. + * @author Tomas Zezula + * @since 1.58 + */ +public interface GeneratedFilesInterceptor { + + /** + * Called when the build script file has been updated or created. + * @param project the project for which the build script was updated. + * @param path the relative path to generated file from project directory. + */ + void fileGenerated(@NonNull Project project, @NonNull String path); +} diff --git a/javawebstart/nbproject/project.xml b/javawebstart/nbproject/project.xml --- a/javawebstart/nbproject/project.xml +++ b/javawebstart/nbproject/project.xml @@ -90,7 +90,7 @@ 1 - 1.46 + 1.58 diff --git a/javawebstart/src/org/netbeans/modules/javawebstart/JWSGeneratedFilesInterceptor.java b/javawebstart/src/org/netbeans/modules/javawebstart/JWSGeneratedFilesInterceptor.java new file mode 100644 --- /dev/null +++ b/javawebstart/src/org/netbeans/modules/javawebstart/JWSGeneratedFilesInterceptor.java @@ -0,0 +1,132 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.javawebstart; + +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.api.project.ProjectUtils; +import org.netbeans.api.project.ant.AntBuildExtender; +import org.netbeans.modules.java.j2seproject.api.GeneratedFilesInterceptor; +import org.netbeans.modules.javawebstart.ui.customizer.JWSProjectPropertiesUtils; +import org.netbeans.spi.project.ProjectServiceProvider; +import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; +import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; + +/** + * + * @author Tomas Zezula + */ +@ProjectServiceProvider( + service = GeneratedFilesInterceptor.class, + projectType = "org-netbeans-modules-java-j2seproject") +public class JWSGeneratedFilesInterceptor implements GeneratedFilesInterceptor { + + private static final Logger LOG = Logger.getLogger(JWSGeneratedFilesInterceptor.class.getName()); + + private final ThreadLocal reentered = new ThreadLocal(); + + + @Override + public void fileGenerated( + final Project project, + final String path) { + if (reentered.get() == Boolean.TRUE) { + return; + } + if (GeneratedFilesHelper.BUILD_IMPL_XML_PATH.equals(path)) { + final AntBuildExtender extender = project.getLookup().lookup(AntBuildExtender.class); + if (extender == null) { + LOG.log( + Level.WARNING, + "The project {0} ({1}) does not support AntBuildExtender.", //NOI18N + new Object[] { + ProjectUtils.getInformation(project).getDisplayName(), + FileUtil.getFileDisplayName(project.getProjectDirectory()) + }); + return; + } + ProjectManager.mutex().writeAccess(new Runnable() { + @Override + public void run() { + if (extender.getExtension(JWSProjectPropertiesUtils.getCurrentExtensionName()) != null) { + //Already has a current version of extension + if (LOG.isLoggable(Level.FINE)) { + LOG.log( + Level.FINE, + "The project {0} ({1}) already has a current version ({2}) of JWS extension.", //NOI18N + new Object[] { + ProjectUtils.getInformation(project).getDisplayName(), + FileUtil.getFileDisplayName(project.getProjectDirectory()), + JWSProjectPropertiesUtils.getCurrentExtensionName() + }); + } + return; + } + boolean needsUpdate = false; + for (String oldExt : JWSProjectPropertiesUtils.getOldExtensionNames()) { + final AntBuildExtender.Extension extension = extender.getExtension(oldExt); + if (extension != null) { + extender.removeExtension(oldExt); + needsUpdate = true; + } + } + if (needsUpdate) { + //There was an old extension which needs to be updated + reentered.set(Boolean.TRUE); + try { + JWSProjectPropertiesUtils.updateJnlpExtension(project); + } catch (IOException ioe) { + Exceptions.printStackTrace(ioe); + } finally { + reentered.remove(); + } + } + } + }); + } + } + +} diff --git a/javawebstart/src/org/netbeans/modules/javawebstart/JWSProjectOpenHook.java b/javawebstart/src/org/netbeans/modules/javawebstart/JWSProjectOpenHook.java --- a/javawebstart/src/org/netbeans/modules/javawebstart/JWSProjectOpenHook.java +++ b/javawebstart/src/org/netbeans/modules/javawebstart/JWSProjectOpenHook.java @@ -42,11 +42,20 @@ package org.netbeans.modules.javawebstart; import java.io.IOException; +import java.io.InputStream; +import java.util.logging.Level; +import java.util.logging.Logger; import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.api.project.ProjectUtils; +import org.netbeans.api.project.ant.AntBuildExtender; import org.netbeans.modules.java.j2seproject.api.J2SEPropertyEvaluator; import org.netbeans.modules.javawebstart.ui.customizer.JWSProjectProperties; +import org.netbeans.modules.javawebstart.ui.customizer.JWSProjectPropertiesUtils; import org.netbeans.spi.project.ProjectServiceProvider; import org.netbeans.spi.project.ui.ProjectOpenedHook; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.Parameters; @@ -59,6 +68,8 @@ @ProjectServiceProvider(service=ProjectOpenedHook.class, projectType="org-netbeans-modules-java-j2seproject") public class JWSProjectOpenHook extends ProjectOpenedHook { + private static final Logger LOG = Logger.getLogger(JWSProjectOpenHook.class.getName()); + private final Project prj; private final J2SEPropertyEvaluator eval; @@ -72,6 +83,57 @@ @Override protected void projectOpened() { + ProjectManager.mutex().writeAccess( + new Runnable() { + @Override + public void run() { + updateBuildScript(); + updateLibraries(); + } + }); + } + + private void updateBuildScript() { + final AntBuildExtender extender = prj.getLookup().lookup(AntBuildExtender.class); + if (extender == null) { + LOG.log( + Level.WARNING, + "The project {0} ({1}) does not support AntBuildExtender.", //NOI18N + new Object[] { + ProjectUtils.getInformation(prj).getDisplayName(), + FileUtil.getFileDisplayName(prj.getProjectDirectory()) + }); + return; + } + if (extender.getExtension(JWSProjectPropertiesUtils.getCurrentExtensionName()) == null) { + LOG.log( + Level.FINE, + "The project {0} ({1}) does not have a current version ({2}) of JWS extension.", //NOI18N + new Object[] { + ProjectUtils.getInformation(prj).getDisplayName(), + FileUtil.getFileDisplayName(prj.getProjectDirectory()), + JWSProjectPropertiesUtils.getCurrentExtensionName() + }); + return; + } + if (JWSProjectPropertiesUtils.isJnlpImplUpToDate(prj)) { + LOG.log( + Level.FINE, + "The project {0} ({1}) have an up to date JWS extension.", //NOI18N + new Object[] { + ProjectUtils.getInformation(prj).getDisplayName(), + FileUtil.getFileDisplayName(prj.getProjectDirectory()) + }); + return; + } + try { + JWSProjectPropertiesUtils.copyJnlpImplTemplate(prj); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + + private void updateLibraries() { try { if (isTrue(eval.evaluator().getProperty(JWSProjectProperties.JNLP_ENABLED))) { //JNLP_ENABLED - inlined by compiler JWSProjectProperties.updateOnOpen(prj, eval.evaluator()); diff --git a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCompositeCategoryProvider.java b/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCompositeCategoryProvider.java --- a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCompositeCategoryProvider.java +++ b/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCompositeCategoryProvider.java @@ -98,8 +98,7 @@ if(project != null) { JWSProjectProperties prop = projectProperties.get(project.getProjectDirectory().getPath()); if(prop != null) { - JWSProjectPropertiesUtils.updateMasterFiles(prop, project); - JWSProjectPropertiesUtils.savePropsAndUpdateMetaFiles(prop, project); + JWSProjectPropertiesUtils.updateJnlpExtensionAndSave(prop, project); } projectProperties.remove(project.getProjectDirectory().getPath()); } diff --git a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCustomizerPanel.form b/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCustomizerPanel.form --- a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCustomizerPanel.form +++ b/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCustomizerPanel.form @@ -419,60 +419,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCustomizerPanel.java b/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCustomizerPanel.java --- a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCustomizerPanel.java +++ b/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCustomizerPanel.java @@ -112,14 +112,7 @@ setEnabledRunComponent(enableSelected); setEnabledAppletControls(appletDescRadioButton.isSelected()); - - if (jwsProps.jnlpImplOldOrModified) { - warningArea.setVisible(true); - setEnabledAllComponents(false); - } else { - resolvePanel.setVisible(false); - } - + extResColumnNames = new String[] { NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.extResources.href"), NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.extResources.name"), @@ -176,9 +169,6 @@ appletDescRadioButton = new javax.swing.JRadioButton(); appletClassComboBox = new javax.swing.JComboBox(); appletParamsButton = new javax.swing.JButton(); - resolvePanel = new javax.swing.JPanel(); - warningArea = new javax.swing.JTextArea(); - resolve = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); extResButton = new javax.swing.JButton(); filler3 = new javax.swing.Box.Filler(new java.awt.Dimension(10, 0), new java.awt.Dimension(10, 0), new java.awt.Dimension(10, 32767)); @@ -430,42 +420,6 @@ gridBagConstraints.insets = new java.awt.Insets(1, 0, 0, 0); add(jPanel1, gridBagConstraints); - resolvePanel.setLayout(new java.awt.GridBagLayout()); - - warningArea.setBackground(javax.swing.UIManager.getDefaults().getColor("Panel.background")); - warningArea.setColumns(20); - warningArea.setEditable(false); - warningArea.setLineWrap(true); - warningArea.setRows(2); - warningArea.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "Previous_Version_Script_Warning")); // NOI18N - warningArea.setWrapStyleWord(true); - warningArea.setBorder(null); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 0; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - resolvePanel.add(warningArea, gridBagConstraints); - - org.openide.awt.Mnemonics.setLocalizedText(resolve, org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "TXT_ResolveModifiedBuildScript")); // NOI18N - resolve.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - resolveOldBuildScript(evt); - } - }); - resolvePanel.add(resolve, new java.awt.GridBagConstraints()); - resolve.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "AD_Resolve")); // NOI18N - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 11; - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(8, 0, 0, 0); - add(resolvePanel, gridBagConstraints); - jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.LINE_AXIS)); org.openide.awt.Mnemonics.setLocalizedText(extResButton, org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.extResButton.text")); // NOI18N @@ -619,13 +573,6 @@ }//GEN-LAST:event_manageResources -private void resolveOldBuildScript(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resolveOldBuildScript - jwsProps.jnlpImplOldOrModified = false; - jwsProps.updateJnlpImpl(); - resolvePanel.setVisible(false); - setEnabledAllComponents(true); -}//GEN-LAST:event_resolveOldBuildScript - private void setEnabledAppletControls(boolean b) { appletClassLabel.setEnabled(b); appletClassComboBox.setEnabled(b); @@ -743,11 +690,8 @@ private javax.swing.JSeparator jSeparator3; private javax.swing.JCheckBox offlineCheckBox; private javax.swing.JLabel panelDescLabel; - private javax.swing.JButton resolve; - private javax.swing.JPanel resolvePanel; private javax.swing.JButton signingCustomizeButton; private javax.swing.JLabel signingInfolabel; - private javax.swing.JTextArea warningArea; // End of variables declaration//GEN-END:variables } diff --git a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSProjectProperties.java b/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSProjectProperties.java --- a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSProjectProperties.java +++ b/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSProjectProperties.java @@ -200,7 +200,6 @@ private DescType selectedDescType = null; - boolean jnlpImplOldOrModified = false; // signing String signing; @@ -361,31 +360,13 @@ extResProperties = readProperties(evaluator, JNLP_EXT_RES_PREFIX, extResSuffixes); appletParamsProperties = readProperties(evaluator, JNLP_APPLET_PARAMS_PREFIX, appletParamsSuffixes); - initResources(evaluator, project); - // check if the jnlp-impl.xml script is of previous version -> should be upgraded - FileObject jnlpImlpFO = project.getProjectDirectory().getFileObject("nbproject/jnlp-impl.xml"); - if (jnlpImlpFO != null) { - try { - final InputStream in = jnlpImlpFO.getInputStream(); - if(in != null) { - try { - String crc = JWSProjectPropertiesUtils.computeCrc32( in ); - jnlpImplOldOrModified = !JWSProjectPropertiesUtils.isJnlpImplCurrentVer(crc); - } finally { - in.close(); - } - } - } catch (IOException ex) { - // nothing to do really - } - } - + initResources(evaluator, project); } } boolean isJWSEnabled() { - return !jnlpImplOldOrModified && enabledModel.isSelected(); + return enabledModel.isSelected(); } /** @@ -577,17 +558,7 @@ props.remove(name); } } - - public void updateJnlpImpl() { - if (project != null) { - try { - JWSProjectPropertiesUtils.copyTemplate(project); - } catch (IOException ioe) { - Exceptions.printStackTrace(ioe); - } - } - } - + public void store() throws IOException { final EditableProperties ep = new EditableProperties(true); diff --git a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSProjectPropertiesUtils.java b/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSProjectPropertiesUtils.java --- a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSProjectPropertiesUtils.java +++ b/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSProjectPropertiesUtils.java @@ -45,6 +45,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; +import java.util.Arrays; import java.util.Collection; import java.util.logging.Level; import java.util.logging.Logger; @@ -70,6 +71,7 @@ import org.openide.util.Mutex; import org.openide.util.MutexException; import org.openide.util.NbBundle; +import org.openide.util.Parameters; import org.openide.xml.XMLUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -93,6 +95,9 @@ private static final String JWS_ANT_TASKS_LIB_NAME = "JWSAntTasks"; // NOI18N private static final String BUILD_TEMPLATE = "Templates/JWS/jnlp-impl.xml"; //NOI18N + private static final String CURRENT_EXTENSION = "jws"; //NOI18N + private static final String[] OLD_EXTENSIONS = new String[0]; + private static final String JNLP_BUILD_IMPL_PATH = "nbproject/jnlp-impl.xml"; //NOI18N private static final Logger LOG = Logger.getLogger(JWSProjectPropertiesUtils.class.getName()); @@ -101,7 +106,76 @@ private JWSProjectPropertiesUtils() { } - public static void updateMasterFiles(JWSProjectProperties props, Project proj) { + public static String getCurrentExtensionName() { + return CURRENT_EXTENSION; + } + + public static Iterable getOldExtensionNames() { + return Arrays.asList(OLD_EXTENSIONS); + } + + public static void copyJnlpImplTemplate(Project proj) throws IOException { + final FileObject projDir = proj.getProjectDirectory(); + FileObject jnlpBuildFile = projDir.getFileObject(JNLP_BUILD_IMPL_PATH); + if (jnlpBuildFile != null && !isJnlpImplUpToDate(proj)) { + // try to close the file just in case the file is already opened in editor + DataObject dobj = DataObject.find(jnlpBuildFile); + CloseCookie closeCookie = dobj.getLookup().lookup(CloseCookie.class); + if (closeCookie != null) { + closeCookie.close(); + } + final FileObject nbproject = projDir.getFileObject("nbproject"); //NOI18N + final FileObject backupFile = nbproject.getFileObject("jnlp-impl_backup", "xml"); //NOI18N + if (backupFile != null) { + backupFile.delete(); + } + FileUtil.moveFile(jnlpBuildFile, nbproject, "jnlp-impl_backup"); //NOI18N + jnlpBuildFile = null; + } + if (jnlpBuildFile == null) { + FileObject templateFO = FileUtil.getConfigFile(BUILD_TEMPLATE); + if (templateFO != null) { + FileUtil.copyFile(templateFO, projDir.getFileObject("nbproject"), "jnlp-impl"); // NOI18N + } + } + } + + public static boolean isJnlpImplUpToDate(final Project prj) { + Parameters.notNull("prj", prj); //NOI18N + final FileObject jnlpImlpFO = prj.getProjectDirectory().getFileObject(JNLP_BUILD_IMPL_PATH); + if (jnlpImlpFO == null) { + return false; + } + try { + String _currentJnlpImplCRC = currentJnlpImplCRCCache; + if (_currentJnlpImplCRC == null) { + final FileObject template = FileUtil.getConfigFile(BUILD_TEMPLATE); + currentJnlpImplCRCCache = _currentJnlpImplCRC = computeCrc32(template); + } + return _currentJnlpImplCRC.equals(computeCrc32(jnlpImlpFO)); + } catch (IOException ex) { + LOG.log( + Level.INFO, + "Cannot read: " + JNLP_BUILD_IMPL_PATH, //NOI18N + ex); + return false; + } + } + + public static void updateJnlpExtension(final Project project) throws IOException { + copyJnlpImplTemplate(project); + modifyBuildXml(project); + copyJWSAntTasksLibrary(project); + } + + static void updateJnlpExtensionAndSave( + final JWSProjectProperties props, + final Project project) { + updateMasterFiles(props, project); + savePropsAndUpdateMetaFiles(props, project); + } + + private static void updateMasterFiles(JWSProjectProperties props, Project proj) { try { if (props.isJWSEnabled()) { // test if the file already exists, if so do not generate, just set as active @@ -257,7 +331,7 @@ } } - public static void savePropsAndUpdateMetaFiles(JWSProjectProperties props, Project proj) { + private static void savePropsAndUpdateMetaFiles(JWSProjectProperties props, Project proj) { try { try { props.store(); @@ -268,7 +342,7 @@ proj.getLookup().lookup(ProjectConfigurationProvider.class); if (props.wasJWSActivated()) { setActiveConfig(configProvider, NbBundle.getMessage(JWSCompositeCategoryProvider.class, "LBL_Category_WebStart")); // NOI18N - copyTemplate(proj); + copyJnlpImplTemplate(proj); modifyBuildXml(proj); copyJWSAntTasksLibrary(proj); } else if (props.wasJWSDeactivated()){ @@ -298,44 +372,7 @@ } } } - } - - public static void copyTemplate(Project proj) throws IOException { - boolean isJnlpCurrent = true; - FileObject projDir = proj.getProjectDirectory(); - FileObject jnlpBuildFile = projDir.getFileObject("nbproject/jnlp-impl.xml"); // NOI18N - if (jnlpBuildFile != null) { - final InputStream in = jnlpBuildFile.getInputStream(); - if(in != null) { - try { - isJnlpCurrent = isJnlpImplCurrentVer(computeCrc32( in )); - } finally { - in.close(); - } - } - } - if (!isJnlpCurrent) { - // try to close the file just in case the file is already opened in editor - DataObject dobj = DataObject.find(jnlpBuildFile); - CloseCookie closeCookie = dobj.getLookup().lookup(CloseCookie.class); - if (closeCookie != null) { - closeCookie.close(); - } - final FileObject nbproject = projDir.getFileObject("nbproject"); //NOI18N - final FileObject backupFile = nbproject.getFileObject("jnlp-impl_backup", "xml"); //NOI18N - if (backupFile != null) { - backupFile.delete(); - } - FileUtil.moveFile(jnlpBuildFile, nbproject, "jnlp-impl_backup"); //NOI18N - jnlpBuildFile = null; - } - if (jnlpBuildFile == null) { - FileObject templateFO = FileUtil.getConfigFile(BUILD_TEMPLATE); - if (templateFO != null) { - FileUtil.copyFile(templateFO, projDir.getFileObject("nbproject"), "jnlp-impl"); // NOI18N - } - } - } + } private static void modifyBuildXml(Project proj) throws IOException { FileObject projDir = proj.getProjectDirectory(); @@ -350,12 +387,12 @@ } catch (SAXException ex) { Exceptions.printStackTrace(ex); } - FileObject jnlpBuildFile = projDir.getFileObject("nbproject/jnlp-impl.xml"); // NOI18N + FileObject jnlpBuildFile = projDir.getFileObject(JNLP_BUILD_IMPL_PATH); AntBuildExtender extender = proj.getLookup().lookup(AntBuildExtender.class); if (extender != null) { assert jnlpBuildFile != null; - if (extender.getExtension("jws") == null) { // NOI18N - AntBuildExtender.Extension ext = extender.addExtension("jws", jnlpBuildFile); // NOI18N + if (extender.getExtension(CURRENT_EXTENSION) == null) { // NOI18N + AntBuildExtender.Extension ext = extender.addExtension(CURRENT_EXTENSION, jnlpBuildFile); // NOI18N ext.addDependency("jar", "jnlp"); // NOI18N ext.addDependency("-post-jar", "jnlp"); //NOI18N } @@ -397,7 +434,7 @@ nl = docElem.getElementsByTagName("import"); // NOI18N for (int i = 0; i < nl.getLength(); i++) { Element e = (Element) nl.item(i); - if (e.getAttribute("file") != null && "nbproject/jnlp-impl.xml".equals(e.getAttribute("file"))) { // NOI18N + if (e.getAttribute("file") != null && JNLP_BUILD_IMPL_PATH.equals(e.getAttribute("file"))) { // NOI18N e.getParentNode().removeChild(e); changed = true; break; @@ -450,44 +487,32 @@ return prj.getProjectDirectory().getFileObject (buildScriptPath); } - static String computeCrc32(InputStream is) throws IOException { - Checksum crc = new CRC32(); - int last = -1; - int curr; - while ((curr = is.read()) != -1) { - if (curr != '\n' && last == '\r') { - crc.update('\n'); + private static String computeCrc32(final FileObject fo) throws IOException { + final Checksum crc = new CRC32(); + final InputStream in = fo.getInputStream(); + try { + int last = -1; + int curr; + while ((curr = in.read()) != -1) { + if (curr != '\n' && last == '\r') { //NOI18N + crc.update('\n'); //NOI18N + } + if (curr != '\r') { //NOI18N + crc.update(curr); + } + last = curr; } - if (curr != '\r') { - crc.update(curr); + if (last == '\r') { //NOI18N + crc.update('\n'); //NOI18N } - last = curr; - } - if (last == '\r') { - crc.update('\n'); + } finally { + in.close(); } int val = (int)crc.getValue(); String hex = Integer.toHexString(val); while (hex.length() < 8) { hex = "0" + hex; // NOI18N } - return hex; + return hex; } - - static boolean isJnlpImplCurrentVer(String crc) throws IOException { - String _currentJnlpImplCRC = currentJnlpImplCRCCache; - if (_currentJnlpImplCRC == null) { - final FileObject template = FileUtil.getConfigFile(BUILD_TEMPLATE); - final InputStream in = template.getInputStream(); - if(in != null) { - try { - currentJnlpImplCRCCache = _currentJnlpImplCRC = computeCrc32(in); - } finally { - in.close(); - } - } - } - return _currentJnlpImplCRC.equals(crc); - } - }