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

(-)a/java.j2seproject/apichanges.xml (+16 lines)
Lines 107-112 Link Here
107
107
108
    <changes>
108
    <changes>
109
109
110
        <change id="GeneratedFilesInterceptor">
111
            <api name="jseprojects"/>
112
            <summary></summary>
113
            <version major="1" minor="58"/>
114
            <date day="25" month="2" year="2013"/>
115
            <author login="tzezula"/>
116
            <compatibility addition="yes"/>
117
            <description>
118
                The J2SEProject calls all the instances of the <code>GeneratedFilesInterceptor</code>
119
                registered in the project <code>Lookup</code> when a a build script file has been updated
120
                or created.
121
            </description>
122
            <class package="org.netbeans.modules.java.j2seproject.api" name="GeneratedFilesInterceptor"/>
123
            <issue number="226433"/>
124
        </change>
125
110
        <change>
126
        <change>
111
            <api name="jseprojects"/>
127
            <api name="jseprojects"/>
112
            <summary>Enable correct handling of properties in Project Property dialog of an extension of JSE Project</summary>
128
            <summary>Enable correct handling of properties in Project Property dialog of an extension of JSE Project</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.6
44
javac.source=1.6
45
spec.version.base=1.57.0
45
spec.version.base=1.58.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/GeneratedFilesInterceptorSupport.java (+99 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 java.net.URL;
46
import org.netbeans.api.annotations.common.NonNull;
47
import org.netbeans.api.project.Project;
48
import org.netbeans.modules.java.j2seproject.api.GeneratedFilesInterceptor;
49
import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
50
import org.openide.util.Parameters;
51
52
/**
53
 *
54
 * @author Tomas Zezula
55
 */
56
class GeneratedFilesInterceptorSupport {
57
58
    private final Project prj;
59
    private final GeneratedFilesHelper genFilesHelper;
60
61
    GeneratedFilesInterceptorSupport(
62
            @NonNull final Project prj,
63
            @NonNull final GeneratedFilesHelper genFilesHelper) {
64
        Parameters.notNull("prj", prj); //NOI18N
65
        Parameters.notNull("genFilesHelper", genFilesHelper);   //NOI18N
66
        this.prj = prj;
67
        this.genFilesHelper = genFilesHelper;
68
    }
69
70
    void generateBuildScriptFromStylesheet(
71
            @NonNull final String path,
72
            @NonNull final URL stylesheet) throws IOException {
73
        genFilesHelper.generateBuildScriptFromStylesheet(path, stylesheet);
74
        callInterceptors(prj, path);
75
    }
76
    
77
    boolean refreshBuildScript(
78
            @NonNull final String path,
79
            @NonNull final URL stylesheet,
80
            @NonNull final boolean checkForProjectXmlModified) throws IOException {                
81
         final boolean ret = genFilesHelper.refreshBuildScript(path, stylesheet, checkForProjectXmlModified);
82
         if (ret) {
83
             callInterceptors(prj, path);
84
         }
85
         return ret;
86
    }   
87
88
    private static void callInterceptors(
89
            @NonNull final Project prj,
90
            @NonNull final String path) {
91
        final Iterable<? extends GeneratedFilesInterceptor> interceptors =
92
                prj.getLookup().lookupAll(GeneratedFilesInterceptor.class);
93
        for (GeneratedFilesInterceptor interceptor : interceptors) {
94
            interceptor.fileGenerated(prj, path);
95
        }
96
    }
97
    
98
99
}
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java (-5 / +7 lines)
Lines 199-204 Link Here
199
    private SourceRoots testRoots;
199
    private SourceRoots testRoots;
200
    private final ClassPathProviderImpl cpProvider;
200
    private final ClassPathProviderImpl cpProvider;
201
    private final ClassPathModifier cpMod;
201
    private final ClassPathModifier cpMod;
202
    private final GeneratedFilesInterceptorSupport gfis;
202
203
203
    private AntBuildExtender buildExtender;
204
    private AntBuildExtender buildExtender;
204
205
Lines 232-237 Link Here
232
        this.cpProvider = new ClassPathProviderImpl(this.helper, evaluator(), getSourceRoots(),getTestSourceRoots()); //Does not use APH to get/put properties/cfgdata
233
        this.cpProvider = new ClassPathProviderImpl(this.helper, evaluator(), getSourceRoots(),getTestSourceRoots()); //Does not use APH to get/put properties/cfgdata
233
        this.cpMod = new ClassPathModifier(this, this.updateHelper, evaluator(), refHelper, null, createClassPathModifierCallback(), null);
234
        this.cpMod = new ClassPathModifier(this, this.updateHelper, evaluator(), refHelper, null, createClassPathModifierCallback(), null);
234
        lookup = createLookup(aux, new J2SEProjectOperations(this, updateProject));
235
        lookup = createLookup(aux, new J2SEProjectOperations(this, updateProject));
236
        this.gfis = new GeneratedFilesInterceptorSupport(this, genFilesHelper);
235
    }
237
    }
236
238
237
    private ClassPathModifier.Callback createClassPathModifierCallback() {
239
    private ClassPathModifier.Callback createClassPathModifierCallback() {
Lines 522-537 Link Here
522
                                }
524
                                }
523
                            }
525
                            }
524
                            if (forceRewriteBuildImpl) {
526
                            if (forceRewriteBuildImpl) {
525
                                genFilesHelper.generateBuildScriptFromStylesheet(                                        
527
                                gfis.generateBuildScriptFromStylesheet(
526
                                    GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
528
                                    GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
527
                                    J2SEProject.class.getResource("resources/build-impl.xsl"));
529
                                    J2SEProject.class.getResource("resources/build-impl.xsl"));
528
                            } else {
530
                            } else {
529
                                genFilesHelper.refreshBuildScript(
531
                                gfis.refreshBuildScript(
530
                                    GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
532
                                    GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
531
                                    J2SEProject.class.getResource("resources/build-impl.xsl"),
533
                                    J2SEProject.class.getResource("resources/build-impl.xsl"),
532
                                    false);
534
                                    false);
533
                            }
535
                            }
534
                            genFilesHelper.refreshBuildScript(
536
                            gfis.refreshBuildScript(
535
                                J2SEProjectUtil.getBuildXmlName(J2SEProject.this),
537
                                J2SEProjectUtil.getBuildXmlName(J2SEProject.this),
536
                                J2SEProject.class.getResource("resources/build.xsl"),
538
                                J2SEProject.class.getResource("resources/build.xsl"),
537
                                false);
539
                                false);
Lines 558-568 Link Here
558
            try {
560
            try {
559
                if (updateHelper.isCurrent()) {
561
                if (updateHelper.isCurrent()) {
560
                    //Refresh build-impl.xml only for j2seproject/2
562
                    //Refresh build-impl.xml only for j2seproject/2
561
                    genFilesHelper.refreshBuildScript(
563
                    gfis.refreshBuildScript(
562
                        GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
564
                        GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
563
                        J2SEProject.class.getResource("resources/build-impl.xsl"),
565
                        J2SEProject.class.getResource("resources/build-impl.xsl"),
564
                        true);
566
                        true);
565
                    genFilesHelper.refreshBuildScript(
567
                    gfis.refreshBuildScript(
566
                        J2SEProjectUtil.getBuildXmlName(J2SEProject.this),
568
                        J2SEProjectUtil.getBuildXmlName(J2SEProject.this),
567
                        J2SEProject.class.getResource("resources/build.xsl"),
569
                        J2SEProject.class.getResource("resources/build.xsl"),
568
                        true);
570
                        true);
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/api/GeneratedFilesInterceptor.java (+64 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 org.netbeans.api.annotations.common.NonNull;
45
import org.netbeans.api.project.Project;
46
import org.openide.util.Lookup;
47
48
/**
49
 * Notifies the J2SE Project extension about build script update.
50
 * The J2SEProject calls all the instances of the @link GeneratedFilesInterceptor}
51
 * registered in the project {@link Lookup} when a a build script file has been
52
 * updated or created.
53
 * @author Tomas Zezula
54
 * @since 1.58
55
 */
56
public interface GeneratedFilesInterceptor {
57
58
    /**
59
     * Called when the build script file has been updated or created.
60
     * @param project the project for which the build script was updated.
61
     * @param path the relative path to generated file from project directory.
62
     */
63
    void fileGenerated(@NonNull Project project, @NonNull String path);
64
}
(-)a/javawebstart/nbproject/project.xml (-1 / +1 lines)
Lines 90-96 Link Here
90
                    <compile-dependency/>
90
                    <compile-dependency/>
91
                    <run-dependency>
91
                    <run-dependency>
92
                        <release-version>1</release-version>
92
                        <release-version>1</release-version>
93
                        <specification-version>1.46</specification-version>
93
                        <specification-version>1.58</specification-version>
94
                    </run-dependency>
94
                    </run-dependency>
95
                </dependency>
95
                </dependency>
96
                <dependency>
96
                <dependency>
(-)a/javawebstart/src/org/netbeans/modules/javawebstart/JWSGeneratedFilesInterceptor.java (+132 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.javawebstart;
43
44
import java.io.IOException;
45
import java.util.logging.Level;
46
import java.util.logging.Logger;
47
import org.netbeans.api.project.Project;
48
import org.netbeans.api.project.ProjectManager;
49
import org.netbeans.api.project.ProjectUtils;
50
import org.netbeans.api.project.ant.AntBuildExtender;
51
import org.netbeans.modules.java.j2seproject.api.GeneratedFilesInterceptor;
52
import org.netbeans.modules.javawebstart.ui.customizer.JWSProjectPropertiesUtils;
53
import org.netbeans.spi.project.ProjectServiceProvider;
54
import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
55
import org.openide.filesystems.FileUtil;
56
import org.openide.util.Exceptions;
57
58
/**
59
 *
60
 * @author Tomas Zezula
61
 */
62
@ProjectServiceProvider(
63
        service = GeneratedFilesInterceptor.class,
64
        projectType = "org-netbeans-modules-java-j2seproject")
65
public class JWSGeneratedFilesInterceptor implements GeneratedFilesInterceptor {
66
67
    private static final Logger LOG = Logger.getLogger(JWSGeneratedFilesInterceptor.class.getName());
68
69
    private final ThreadLocal<Boolean> reentered = new ThreadLocal<Boolean>();
70
71
    
72
    @Override
73
    public void fileGenerated(
74
            final Project project,
75
            final String path) {
76
        if (reentered.get() == Boolean.TRUE) {
77
            return;
78
        }
79
        if (GeneratedFilesHelper.BUILD_IMPL_XML_PATH.equals(path)) {
80
            final AntBuildExtender extender = project.getLookup().lookup(AntBuildExtender.class);
81
            if (extender == null) {
82
                LOG.log(
83
                    Level.WARNING,
84
                    "The project {0} ({1}) does not support AntBuildExtender.",     //NOI18N
85
                    new Object[] {
86
                        ProjectUtils.getInformation(project).getDisplayName(),
87
                        FileUtil.getFileDisplayName(project.getProjectDirectory())
88
                    });
89
                return;
90
            }
91
            ProjectManager.mutex().writeAccess(new Runnable() {
92
                @Override
93
                public void run() {
94
                    if (extender.getExtension(JWSProjectPropertiesUtils.getCurrentExtensionName()) != null) {
95
                        //Already has a current version of extension
96
                        if (LOG.isLoggable(Level.FINE)) {
97
                            LOG.log(
98
                                Level.FINE,
99
                                "The project {0} ({1}) already has a current version ({2}) of JWS extension.", //NOI18N
100
                                new Object[] {
101
                                    ProjectUtils.getInformation(project).getDisplayName(),
102
                                    FileUtil.getFileDisplayName(project.getProjectDirectory()),
103
                                    JWSProjectPropertiesUtils.getCurrentExtensionName()
104
                                });
105
                        }
106
                        return;
107
                    }
108
                    boolean needsUpdate = false;
109
                    for (String oldExt : JWSProjectPropertiesUtils.getOldExtensionNames()) {
110
                        final AntBuildExtender.Extension extension = extender.getExtension(oldExt);
111
                        if (extension != null) {
112
                            extender.removeExtension(oldExt);
113
                            needsUpdate = true;
114
                        }
115
                    }
116
                    if (needsUpdate) {
117
                        //There was an old extension which needs to be updated
118
                        reentered.set(Boolean.TRUE);
119
                        try {
120
                            JWSProjectPropertiesUtils.updateJnlpExtension(project);
121
                        } catch (IOException ioe) {
122
                            Exceptions.printStackTrace(ioe);
123
                        } finally {
124
                            reentered.remove();
125
                        }
126
                    }
127
                }
128
            });
129
        }
130
    }
131
132
}
(-)a/javawebstart/src/org/netbeans/modules/javawebstart/JWSProjectOpenHook.java (+62 lines)
Lines 42-52 Link Here
42
package org.netbeans.modules.javawebstart;
42
package org.netbeans.modules.javawebstart;
43
43
44
import java.io.IOException;
44
import java.io.IOException;
45
import java.io.InputStream;
46
import java.util.logging.Level;
47
import java.util.logging.Logger;
45
import org.netbeans.api.project.Project;
48
import org.netbeans.api.project.Project;
49
import org.netbeans.api.project.ProjectManager;
50
import org.netbeans.api.project.ProjectUtils;
51
import org.netbeans.api.project.ant.AntBuildExtender;
46
import org.netbeans.modules.java.j2seproject.api.J2SEPropertyEvaluator;
52
import org.netbeans.modules.java.j2seproject.api.J2SEPropertyEvaluator;
47
import org.netbeans.modules.javawebstart.ui.customizer.JWSProjectProperties;
53
import org.netbeans.modules.javawebstart.ui.customizer.JWSProjectProperties;
54
import org.netbeans.modules.javawebstart.ui.customizer.JWSProjectPropertiesUtils;
48
import org.netbeans.spi.project.ProjectServiceProvider;
55
import org.netbeans.spi.project.ProjectServiceProvider;
49
import org.netbeans.spi.project.ui.ProjectOpenedHook;
56
import org.netbeans.spi.project.ui.ProjectOpenedHook;
57
import org.openide.filesystems.FileObject;
58
import org.openide.filesystems.FileUtil;
50
import org.openide.util.Exceptions;
59
import org.openide.util.Exceptions;
51
import org.openide.util.Lookup;
60
import org.openide.util.Lookup;
52
import org.openide.util.Parameters;
61
import org.openide.util.Parameters;
Lines 59-64 Link Here
59
@ProjectServiceProvider(service=ProjectOpenedHook.class, projectType="org-netbeans-modules-java-j2seproject")
68
@ProjectServiceProvider(service=ProjectOpenedHook.class, projectType="org-netbeans-modules-java-j2seproject")
60
public class JWSProjectOpenHook extends ProjectOpenedHook {
69
public class JWSProjectOpenHook extends ProjectOpenedHook {
61
70
71
    private static final Logger LOG = Logger.getLogger(JWSProjectOpenHook.class.getName());
72
62
    private final Project prj;
73
    private final Project prj;
63
    private final J2SEPropertyEvaluator eval;
74
    private final J2SEPropertyEvaluator eval;
64
75
Lines 72-77 Link Here
72
83
73
    @Override
84
    @Override
74
    protected void projectOpened() {
85
    protected void projectOpened() {
86
        ProjectManager.mutex().writeAccess(
87
            new Runnable() {
88
                @Override
89
                public void run() {
90
                    updateBuildScript();
91
                    updateLibraries();
92
                }
93
        });
94
    }
95
96
    private void updateBuildScript() {
97
        final AntBuildExtender extender = prj.getLookup().lookup(AntBuildExtender.class);
98
        if (extender == null) {
99
            LOG.log(
100
                Level.WARNING,
101
                "The project {0} ({1}) does not support AntBuildExtender.",     //NOI18N
102
                new Object[] {
103
                    ProjectUtils.getInformation(prj).getDisplayName(),
104
                    FileUtil.getFileDisplayName(prj.getProjectDirectory())
105
                });
106
            return;
107
        }
108
        if (extender.getExtension(JWSProjectPropertiesUtils.getCurrentExtensionName()) == null) {
109
            LOG.log(
110
                Level.FINE,
111
                "The project {0} ({1}) does not have a current version ({2}) of JWS extension.", //NOI18N
112
                new Object[] {
113
                    ProjectUtils.getInformation(prj).getDisplayName(),
114
                    FileUtil.getFileDisplayName(prj.getProjectDirectory()),
115
                    JWSProjectPropertiesUtils.getCurrentExtensionName()
116
                });
117
            return;
118
        }
119
        if (JWSProjectPropertiesUtils.isJnlpImplUpToDate(prj)) {
120
            LOG.log(
121
                Level.FINE,
122
                "The project {0} ({1}) have an up to date JWS extension.", //NOI18N
123
                new Object[] {
124
                    ProjectUtils.getInformation(prj).getDisplayName(),
125
                    FileUtil.getFileDisplayName(prj.getProjectDirectory())
126
                });
127
            return;
128
        }
129
        try {
130
            JWSProjectPropertiesUtils.copyJnlpImplTemplate(prj);
131
        } catch (IOException ex) {
132
            Exceptions.printStackTrace(ex);
133
        }
134
    }
135
136
    private void updateLibraries() {
75
        try {
137
        try {
76
            if (isTrue(eval.evaluator().getProperty(JWSProjectProperties.JNLP_ENABLED))) {  //JNLP_ENABLED - inlined by compiler
138
            if (isTrue(eval.evaluator().getProperty(JWSProjectProperties.JNLP_ENABLED))) {  //JNLP_ENABLED - inlined by compiler
77
                JWSProjectProperties.updateOnOpen(prj, eval.evaluator());
139
                JWSProjectProperties.updateOnOpen(prj, eval.evaluator());
(-)a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCompositeCategoryProvider.java (-2 / +1 lines)
Lines 98-105 Link Here
98
                    if(project != null) {
98
                    if(project != null) {
99
                        JWSProjectProperties prop = projectProperties.get(project.getProjectDirectory().getPath());
99
                        JWSProjectProperties prop = projectProperties.get(project.getProjectDirectory().getPath());
100
                        if(prop != null) {
100
                        if(prop != null) {
101
                            JWSProjectPropertiesUtils.updateMasterFiles(prop, project);
101
                            JWSProjectPropertiesUtils.updateJnlpExtensionAndSave(prop, project);
102
                            JWSProjectPropertiesUtils.savePropsAndUpdateMetaFiles(prop, project);
103
                        }
102
                        }
104
                        projectProperties.remove(project.getProjectDirectory().getPath());
103
                        projectProperties.remove(project.getProjectDirectory().getPath());
105
                    }
104
                    }
(-)a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCustomizerPanel.form (-54 lines)
Lines 419-478 Link Here
419
        </Component>
419
        </Component>
420
      </SubComponents>
420
      </SubComponents>
421
    </Container>
421
    </Container>
422
    <Container class="javax.swing.JPanel" name="resolvePanel">
423
      <Constraints>
424
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
425
          <GridBagConstraints gridX="0" gridY="11" gridWidth="0" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="8" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
426
        </Constraint>
427
      </Constraints>
428
429
      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
430
      <SubComponents>
431
        <Component class="javax.swing.JTextArea" name="warningArea">
432
          <Properties>
433
            <Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
434
              <Color blue="ee" green="ee" id="Panel.background" palette="3" red="ee" type="palette"/>
435
            </Property>
436
            <Property name="columns" type="int" value="20"/>
437
            <Property name="editable" type="boolean" value="false"/>
438
            <Property name="lineWrap" type="boolean" value="true"/>
439
            <Property name="rows" type="int" value="2"/>
440
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
441
              <ResourceString bundle="org/netbeans/modules/javawebstart/ui/customizer/Bundle.properties" key="Previous_Version_Script_Warning" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
442
            </Property>
443
            <Property name="wrapStyleWord" type="boolean" value="true"/>
444
            <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
445
              <Border info="null"/>
446
            </Property>
447
          </Properties>
448
          <Constraints>
449
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
450
              <GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="1.0" weightY="0.0"/>
451
            </Constraint>
452
          </Constraints>
453
        </Component>
454
        <Component class="javax.swing.JButton" name="resolve">
455
          <Properties>
456
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
457
              <ResourceString bundle="org/netbeans/modules/javawebstart/ui/customizer/Bundle.properties" key="TXT_ResolveModifiedBuildScript" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
458
            </Property>
459
          </Properties>
460
          <AccessibilityProperties>
461
            <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
462
              <ResourceString bundle="org/netbeans/modules/javawebstart/ui/customizer/Bundle.properties" key="AD_Resolve" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
463
            </Property>
464
          </AccessibilityProperties>
465
          <Events>
466
            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="resolveOldBuildScript"/>
467
          </Events>
468
          <Constraints>
469
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
470
              <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
471
            </Constraint>
472
          </Constraints>
473
        </Component>
474
      </SubComponents>
475
    </Container>
476
    <Container class="javax.swing.JPanel" name="jPanel2">
422
    <Container class="javax.swing.JPanel" name="jPanel2">
477
      <Constraints>
423
      <Constraints>
478
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
424
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
(-)a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSCustomizerPanel.java (-57 / +1 lines)
Lines 112-125 Link Here
112
        setEnabledRunComponent(enableSelected);
112
        setEnabledRunComponent(enableSelected);
113
113
114
        setEnabledAppletControls(appletDescRadioButton.isSelected());
114
        setEnabledAppletControls(appletDescRadioButton.isSelected());
115
115
        
116
        if (jwsProps.jnlpImplOldOrModified) {
117
            warningArea.setVisible(true);
118
            setEnabledAllComponents(false);
119
        } else {
120
            resolvePanel.setVisible(false);
121
        }
122
123
        extResColumnNames = new String[] {
116
        extResColumnNames = new String[] {
124
            NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.extResources.href"),
117
            NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.extResources.href"),
125
            NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.extResources.name"),
118
            NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.extResources.name"),
Lines 176-184 Link Here
176
        appletDescRadioButton = new javax.swing.JRadioButton();
169
        appletDescRadioButton = new javax.swing.JRadioButton();
177
        appletClassComboBox = new javax.swing.JComboBox();
170
        appletClassComboBox = new javax.swing.JComboBox();
178
        appletParamsButton = new javax.swing.JButton();
171
        appletParamsButton = new javax.swing.JButton();
179
        resolvePanel = new javax.swing.JPanel();
180
        warningArea = new javax.swing.JTextArea();
181
        resolve = new javax.swing.JButton();
182
        jPanel2 = new javax.swing.JPanel();
172
        jPanel2 = new javax.swing.JPanel();
183
        extResButton = new javax.swing.JButton();
173
        extResButton = new javax.swing.JButton();
184
        filler3 = new javax.swing.Box.Filler(new java.awt.Dimension(10, 0), new java.awt.Dimension(10, 0), new java.awt.Dimension(10, 32767));
174
        filler3 = new javax.swing.Box.Filler(new java.awt.Dimension(10, 0), new java.awt.Dimension(10, 0), new java.awt.Dimension(10, 32767));
Lines 430-471 Link Here
430
        gridBagConstraints.insets = new java.awt.Insets(1, 0, 0, 0);
420
        gridBagConstraints.insets = new java.awt.Insets(1, 0, 0, 0);
431
        add(jPanel1, gridBagConstraints);
421
        add(jPanel1, gridBagConstraints);
432
422
433
        resolvePanel.setLayout(new java.awt.GridBagLayout());
434
435
        warningArea.setBackground(javax.swing.UIManager.getDefaults().getColor("Panel.background"));
436
        warningArea.setColumns(20);
437
        warningArea.setEditable(false);
438
        warningArea.setLineWrap(true);
439
        warningArea.setRows(2);
440
        warningArea.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "Previous_Version_Script_Warning")); // NOI18N
441
        warningArea.setWrapStyleWord(true);
442
        warningArea.setBorder(null);
443
        gridBagConstraints = new java.awt.GridBagConstraints();
444
        gridBagConstraints.gridx = 0;
445
        gridBagConstraints.gridy = 0;
446
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
447
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
448
        gridBagConstraints.weightx = 1.0;
449
        resolvePanel.add(warningArea, gridBagConstraints);
450
451
        org.openide.awt.Mnemonics.setLocalizedText(resolve, org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "TXT_ResolveModifiedBuildScript")); // NOI18N
452
        resolve.addActionListener(new java.awt.event.ActionListener() {
453
            public void actionPerformed(java.awt.event.ActionEvent evt) {
454
                resolveOldBuildScript(evt);
455
            }
456
        });
457
        resolvePanel.add(resolve, new java.awt.GridBagConstraints());
458
        resolve.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "AD_Resolve")); // NOI18N
459
460
        gridBagConstraints = new java.awt.GridBagConstraints();
461
        gridBagConstraints.gridx = 0;
462
        gridBagConstraints.gridy = 11;
463
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
464
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
465
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
466
        gridBagConstraints.insets = new java.awt.Insets(8, 0, 0, 0);
467
        add(resolvePanel, gridBagConstraints);
468
469
        jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.LINE_AXIS));
423
        jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.LINE_AXIS));
470
424
471
        org.openide.awt.Mnemonics.setLocalizedText(extResButton, org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.extResButton.text")); // NOI18N
425
        org.openide.awt.Mnemonics.setLocalizedText(extResButton, org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.extResButton.text")); // NOI18N
Lines 619-631 Link Here
619
    
573
    
620
}//GEN-LAST:event_manageResources
574
}//GEN-LAST:event_manageResources
621
575
622
private void resolveOldBuildScript(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resolveOldBuildScript
623
    jwsProps.jnlpImplOldOrModified = false;
624
    jwsProps.updateJnlpImpl();
625
    resolvePanel.setVisible(false);
626
    setEnabledAllComponents(true);
627
}//GEN-LAST:event_resolveOldBuildScript
628
629
    private void setEnabledAppletControls(boolean b) {
576
    private void setEnabledAppletControls(boolean b) {
630
        appletClassLabel.setEnabled(b);
577
        appletClassLabel.setEnabled(b);
631
        appletClassComboBox.setEnabled(b);
578
        appletClassComboBox.setEnabled(b);
Lines 743-753 Link Here
743
    private javax.swing.JSeparator jSeparator3;
690
    private javax.swing.JSeparator jSeparator3;
744
    private javax.swing.JCheckBox offlineCheckBox;
691
    private javax.swing.JCheckBox offlineCheckBox;
745
    private javax.swing.JLabel panelDescLabel;
692
    private javax.swing.JLabel panelDescLabel;
746
    private javax.swing.JButton resolve;
747
    private javax.swing.JPanel resolvePanel;
748
    private javax.swing.JButton signingCustomizeButton;
693
    private javax.swing.JButton signingCustomizeButton;
749
    private javax.swing.JLabel signingInfolabel;
694
    private javax.swing.JLabel signingInfolabel;
750
    private javax.swing.JTextArea warningArea;
751
    // End of variables declaration//GEN-END:variables
695
    // End of variables declaration//GEN-END:variables
752
696
753
}
697
}
(-)a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSProjectProperties.java (-32 / +3 lines)
Lines 200-206 Link Here
200
200
201
    private DescType selectedDescType = null;
201
    private DescType selectedDescType = null;
202
202
203
    boolean jnlpImplOldOrModified = false;
204
203
205
    // signing
204
    // signing
206
    String signing;
205
    String signing;
Lines 361-391 Link Here
361
            extResProperties = readProperties(evaluator, JNLP_EXT_RES_PREFIX, extResSuffixes);
360
            extResProperties = readProperties(evaluator, JNLP_EXT_RES_PREFIX, extResSuffixes);
362
            appletParamsProperties = readProperties(evaluator, JNLP_APPLET_PARAMS_PREFIX, appletParamsSuffixes);
361
            appletParamsProperties = readProperties(evaluator, JNLP_APPLET_PARAMS_PREFIX, appletParamsSuffixes);
363
            
362
            
364
            initResources(evaluator, project);            
363
            initResources(evaluator, project);                        
365
            // check if the jnlp-impl.xml script is of previous version -> should be upgraded
366
            FileObject jnlpImlpFO = project.getProjectDirectory().getFileObject("nbproject/jnlp-impl.xml");
367
            if (jnlpImlpFO != null) {
368
                try {
369
                    final InputStream in = jnlpImlpFO.getInputStream();
370
                    if(in != null) {
371
                        try {
372
                            String crc = JWSProjectPropertiesUtils.computeCrc32( in );
373
                            jnlpImplOldOrModified = !JWSProjectPropertiesUtils.isJnlpImplCurrentVer(crc);
374
                        } finally {
375
                            in.close();
376
                        }
377
                    }
378
                } catch (IOException ex) {
379
                    // nothing to do really
380
                }
381
            }
382
383
        } 
364
        } 
384
        
365
        
385
    }
366
    }
386
    
367
    
387
    boolean isJWSEnabled() {
368
    boolean isJWSEnabled() {
388
        return !jnlpImplOldOrModified && enabledModel.isSelected();
369
        return enabledModel.isSelected();
389
    }
370
    }
390
371
391
    /**
372
    /**
Lines 577-593 Link Here
577
            props.remove(name);
558
            props.remove(name);
578
        }
559
        }
579
    }
560
    }
580
    
561
            
581
    public void updateJnlpImpl() {
582
        if (project != null) {
583
            try {
584
                JWSProjectPropertiesUtils.copyTemplate(project);
585
            } catch (IOException ioe) {
586
                Exceptions.printStackTrace(ioe);
587
            }
588
        }
589
    }
590
    
591
    public void store() throws IOException {
562
    public void store() throws IOException {
592
        
563
        
593
        final EditableProperties ep = new EditableProperties(true);
564
        final EditableProperties ep = new EditableProperties(true);
(-)a/javawebstart/src/org/netbeans/modules/javawebstart/ui/customizer/JWSProjectPropertiesUtils.java (-76 / +101 lines)
Lines 45-50 Link Here
45
import java.io.InputStream;
45
import java.io.InputStream;
46
import java.io.OutputStream;
46
import java.io.OutputStream;
47
import java.io.PrintWriter;
47
import java.io.PrintWriter;
48
import java.util.Arrays;
48
import java.util.Collection;
49
import java.util.Collection;
49
import java.util.logging.Level;
50
import java.util.logging.Level;
50
import java.util.logging.Logger;
51
import java.util.logging.Logger;
Lines 70-75 Link Here
70
import org.openide.util.Mutex;
71
import org.openide.util.Mutex;
71
import org.openide.util.MutexException;
72
import org.openide.util.MutexException;
72
import org.openide.util.NbBundle;
73
import org.openide.util.NbBundle;
74
import org.openide.util.Parameters;
73
import org.openide.xml.XMLUtil;
75
import org.openide.xml.XMLUtil;
74
import org.w3c.dom.Document;
76
import org.w3c.dom.Document;
75
import org.w3c.dom.Element;
77
import org.w3c.dom.Element;
Lines 93-98 Link Here
93
95
94
    private static final String JWS_ANT_TASKS_LIB_NAME = "JWSAntTasks"; // NOI18N
96
    private static final String JWS_ANT_TASKS_LIB_NAME = "JWSAntTasks"; // NOI18N
95
    private static final String BUILD_TEMPLATE = "Templates/JWS/jnlp-impl.xml"; //NOI18N
97
    private static final String BUILD_TEMPLATE = "Templates/JWS/jnlp-impl.xml"; //NOI18N
98
    private static final String CURRENT_EXTENSION = "jws";  //NOI18N
99
    private static final String[] OLD_EXTENSIONS = new String[0];
100
    private static final String JNLP_BUILD_IMPL_PATH = "nbproject/jnlp-impl.xml";   //NOI18N
96
101
97
    private static final Logger LOG = Logger.getLogger(JWSProjectPropertiesUtils.class.getName());
102
    private static final Logger LOG = Logger.getLogger(JWSProjectPropertiesUtils.class.getName());
98
103
Lines 101-107 Link Here
101
    private JWSProjectPropertiesUtils() {
106
    private JWSProjectPropertiesUtils() {
102
    }
107
    }
103
108
104
    public static void updateMasterFiles(JWSProjectProperties props, Project proj) {
109
    public static String getCurrentExtensionName() {
110
        return CURRENT_EXTENSION;
111
    }
112
113
    public static Iterable<? extends String> getOldExtensionNames() {
114
        return Arrays.asList(OLD_EXTENSIONS);
115
    }    
116
117
    public static void copyJnlpImplTemplate(Project proj) throws IOException {
118
        final FileObject projDir = proj.getProjectDirectory();
119
        FileObject jnlpBuildFile = projDir.getFileObject(JNLP_BUILD_IMPL_PATH);
120
        if (jnlpBuildFile != null && !isJnlpImplUpToDate(proj)) {
121
            // try to close the file just in case the file is already opened in editor
122
            DataObject dobj = DataObject.find(jnlpBuildFile);
123
            CloseCookie closeCookie = dobj.getLookup().lookup(CloseCookie.class);
124
            if (closeCookie != null) {
125
                closeCookie.close();
126
            }
127
            final FileObject nbproject = projDir.getFileObject("nbproject");                    //NOI18N
128
            final FileObject backupFile = nbproject.getFileObject("jnlp-impl_backup", "xml");   //NOI18N
129
            if (backupFile != null) {
130
                backupFile.delete();
131
            }
132
            FileUtil.moveFile(jnlpBuildFile, nbproject, "jnlp-impl_backup");                    //NOI18N
133
            jnlpBuildFile = null;
134
        }
135
        if (jnlpBuildFile == null) {
136
            FileObject templateFO = FileUtil.getConfigFile(BUILD_TEMPLATE);
137
            if (templateFO != null) {
138
                FileUtil.copyFile(templateFO, projDir.getFileObject("nbproject"), "jnlp-impl"); // NOI18N
139
            }
140
        }
141
    }
142
143
    public static boolean isJnlpImplUpToDate(final Project prj) {
144
        Parameters.notNull("prj", prj); //NOI18N
145
        final FileObject jnlpImlpFO = prj.getProjectDirectory().getFileObject(JNLP_BUILD_IMPL_PATH);
146
        if (jnlpImlpFO == null) {
147
            return false;
148
        }
149
        try {
150
            String _currentJnlpImplCRC = currentJnlpImplCRCCache;
151
            if (_currentJnlpImplCRC == null) {
152
                final FileObject template = FileUtil.getConfigFile(BUILD_TEMPLATE);
153
                 currentJnlpImplCRCCache = _currentJnlpImplCRC = computeCrc32(template);
154
            }
155
            return _currentJnlpImplCRC.equals(computeCrc32(jnlpImlpFO));
156
        } catch (IOException ex) {
157
            LOG.log(
158
                Level.INFO,
159
                "Cannot read: " + JNLP_BUILD_IMPL_PATH, //NOI18N
160
                ex);
161
            return false;
162
        }
163
    }
164
165
    public static void updateJnlpExtension(final Project project) throws IOException {
166
        copyJnlpImplTemplate(project);
167
        modifyBuildXml(project);
168
        copyJWSAntTasksLibrary(project);
169
    }
170
171
    static void updateJnlpExtensionAndSave(
172
            final JWSProjectProperties props,
173
            final Project project) {
174
        updateMasterFiles(props, project);
175
        savePropsAndUpdateMetaFiles(props, project);
176
    }
177
178
    private static void updateMasterFiles(JWSProjectProperties props, Project proj) {
105
        try {
179
        try {
106
            if (props.isJWSEnabled()) {
180
            if (props.isJWSEnabled()) {
107
                // test if the file already exists, if so do not generate, just set as active
181
                // test if the file already exists, if so do not generate, just set as active
Lines 257-263 Link Here
257
        }
331
        }
258
    }
332
    }
259
333
260
    public static void savePropsAndUpdateMetaFiles(JWSProjectProperties props, Project proj) {        
334
    private static void savePropsAndUpdateMetaFiles(JWSProjectProperties props, Project proj) {
261
        try {
335
        try {
262
            try {
336
            try {
263
                props.store();
337
                props.store();
Lines 268-274 Link Here
268
                proj.getLookup().lookup(ProjectConfigurationProvider.class);
342
                proj.getLookup().lookup(ProjectConfigurationProvider.class);
269
            if (props.wasJWSActivated()) {
343
            if (props.wasJWSActivated()) {
270
                setActiveConfig(configProvider, NbBundle.getMessage(JWSCompositeCategoryProvider.class, "LBL_Category_WebStart")); // NOI18N
344
                setActiveConfig(configProvider, NbBundle.getMessage(JWSCompositeCategoryProvider.class, "LBL_Category_WebStart")); // NOI18N
271
                copyTemplate(proj);
345
                copyJnlpImplTemplate(proj);
272
                modifyBuildXml(proj);
346
                modifyBuildXml(proj);
273
                copyJWSAntTasksLibrary(proj);
347
                copyJWSAntTasksLibrary(proj);
274
            } else if (props.wasJWSDeactivated()){
348
            } else if (props.wasJWSDeactivated()){
Lines 298-341 Link Here
298
                }
372
                }
299
            }
373
            }
300
        }
374
        }
301
    }
375
    }    
302
303
    public static void copyTemplate(Project proj) throws IOException {
304
        boolean isJnlpCurrent = true;
305
        FileObject projDir = proj.getProjectDirectory();
306
        FileObject jnlpBuildFile = projDir.getFileObject("nbproject/jnlp-impl.xml"); // NOI18N
307
        if (jnlpBuildFile != null) {
308
            final InputStream in = jnlpBuildFile.getInputStream();
309
            if(in != null) {
310
                try {
311
                    isJnlpCurrent = isJnlpImplCurrentVer(computeCrc32( in ));
312
                } finally {
313
                    in.close();
314
                }
315
            }
316
        }
317
        if (!isJnlpCurrent) {
318
            // try to close the file just in case the file is already opened in editor
319
            DataObject dobj = DataObject.find(jnlpBuildFile);
320
            CloseCookie closeCookie = dobj.getLookup().lookup(CloseCookie.class);
321
            if (closeCookie != null) {
322
                closeCookie.close();
323
            }
324
            final FileObject nbproject = projDir.getFileObject("nbproject");                    //NOI18N
325
            final FileObject backupFile = nbproject.getFileObject("jnlp-impl_backup", "xml");   //NOI18N
326
            if (backupFile != null) {
327
                backupFile.delete();
328
            }
329
            FileUtil.moveFile(jnlpBuildFile, nbproject, "jnlp-impl_backup");                    //NOI18N
330
            jnlpBuildFile = null;
331
        }
332
        if (jnlpBuildFile == null) {
333
            FileObject templateFO = FileUtil.getConfigFile(BUILD_TEMPLATE);
334
            if (templateFO != null) {
335
                FileUtil.copyFile(templateFO, projDir.getFileObject("nbproject"), "jnlp-impl"); // NOI18N
336
            }
337
        }
338
    }
339
376
340
    private static void modifyBuildXml(Project proj) throws IOException {
377
    private static void modifyBuildXml(Project proj) throws IOException {
341
        FileObject projDir = proj.getProjectDirectory();
378
        FileObject projDir = proj.getProjectDirectory();
Lines 350-361 Link Here
350
        } catch (SAXException ex) {
387
        } catch (SAXException ex) {
351
            Exceptions.printStackTrace(ex);
388
            Exceptions.printStackTrace(ex);
352
        }
389
        }
353
        FileObject jnlpBuildFile = projDir.getFileObject("nbproject/jnlp-impl.xml"); // NOI18N
390
        FileObject jnlpBuildFile = projDir.getFileObject(JNLP_BUILD_IMPL_PATH);
354
        AntBuildExtender extender = proj.getLookup().lookup(AntBuildExtender.class);
391
        AntBuildExtender extender = proj.getLookup().lookup(AntBuildExtender.class);
355
        if (extender != null) {
392
        if (extender != null) {
356
            assert jnlpBuildFile != null;
393
            assert jnlpBuildFile != null;
357
            if (extender.getExtension("jws") == null) { // NOI18N
394
            if (extender.getExtension(CURRENT_EXTENSION) == null) { // NOI18N
358
                AntBuildExtender.Extension ext = extender.addExtension("jws", jnlpBuildFile); // NOI18N
395
                AntBuildExtender.Extension ext = extender.addExtension(CURRENT_EXTENSION, jnlpBuildFile); // NOI18N
359
                ext.addDependency("jar", "jnlp"); // NOI18N
396
                ext.addDependency("jar", "jnlp"); // NOI18N
360
                ext.addDependency("-post-jar", "jnlp"); //NOI18N
397
                ext.addDependency("-post-jar", "jnlp"); //NOI18N
361
            }
398
            }
Lines 397-403 Link Here
397
        nl = docElem.getElementsByTagName("import"); // NOI18N
434
        nl = docElem.getElementsByTagName("import"); // NOI18N
398
        for (int i = 0; i < nl.getLength(); i++) {
435
        for (int i = 0; i < nl.getLength(); i++) {
399
            Element e = (Element) nl.item(i);
436
            Element e = (Element) nl.item(i);
400
            if (e.getAttribute("file") != null && "nbproject/jnlp-impl.xml".equals(e.getAttribute("file"))) { // NOI18N
437
            if (e.getAttribute("file") != null && JNLP_BUILD_IMPL_PATH.equals(e.getAttribute("file"))) { // NOI18N
401
                e.getParentNode().removeChild(e);
438
                e.getParentNode().removeChild(e);
402
                changed = true;
439
                changed = true;
403
                break;
440
                break;
Lines 450-493 Link Here
450
        return prj.getProjectDirectory().getFileObject (buildScriptPath);
487
        return prj.getProjectDirectory().getFileObject (buildScriptPath);
451
    }
488
    }
452
489
453
    static String computeCrc32(InputStream is) throws IOException {
490
    private static String computeCrc32(final FileObject fo) throws IOException {
454
        Checksum crc = new CRC32();
491
        final Checksum crc = new CRC32();
455
        int last = -1;
492
        final InputStream in = fo.getInputStream();
456
        int curr;
493
        try {            
457
        while ((curr = is.read()) != -1) {
494
            int last = -1;
458
            if (curr != '\n' && last == '\r') {
495
            int curr;
459
                crc.update('\n');
496
            while ((curr = in.read()) != -1) {
497
                if (curr != '\n' && last == '\r') { //NOI18N
498
                    crc.update('\n');               //NOI18N
499
                }
500
                if (curr != '\r') {                 //NOI18N
501
                    crc.update(curr);
502
                }
503
                last = curr;
460
            }
504
            }
461
            if (curr != '\r') {
505
            if (last == '\r') {                     //NOI18N
462
                crc.update(curr);
506
                crc.update('\n');                   //NOI18N
463
            }
507
            }
464
            last = curr;
508
        } finally {
465
        }
509
            in.close();
466
        if (last == '\r') {
467
            crc.update('\n');
468
        }
510
        }
469
        int val = (int)crc.getValue();
511
        int val = (int)crc.getValue();
470
        String hex = Integer.toHexString(val);
512
        String hex = Integer.toHexString(val);
471
        while (hex.length() < 8) {
513
        while (hex.length() < 8) {
472
            hex = "0" + hex; // NOI18N
514
            hex = "0" + hex; // NOI18N
473
        }
515
        }
474
        return hex;
516
        return hex;        
475
    }
517
    }
476
477
    static boolean isJnlpImplCurrentVer(String crc) throws IOException {
478
        String _currentJnlpImplCRC = currentJnlpImplCRCCache;
479
        if (_currentJnlpImplCRC == null) {
480
            final FileObject template = FileUtil.getConfigFile(BUILD_TEMPLATE);
481
            final InputStream in = template.getInputStream();
482
            if(in != null) {
483
                try {
484
                    currentJnlpImplCRCCache = _currentJnlpImplCRC = computeCrc32(in);
485
                } finally {
486
                    in.close();
487
                }
488
            }
489
        }
490
        return _currentJnlpImplCRC.equals(crc);
491
    }
492
493
}
518
}

Return to bug 226433