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

(-)nbbuild/build.xml (+5 lines)
Lines 1101-1106 Link Here
1101
    <ant dir="../ide/branding" target="netbeans"/>
1101
    <ant dir="../ide/branding" target="netbeans"/>
1102
  </target>
1102
  </target>
1103
1103
1104
  <!-- target for upgrader of NetBeans IDE -->
1105
  <target name="all-ide/launcher/upgrade" depends="init">
1106
    <echo message="Building module ide/launcher/upgrade..."/>
1107
    <ant dir="../ide/launcher/upgrade" target="netbeans"/>
1108
  </target>
1104
  
1109
  
1105
  <target name="build-platform" depends="init" unless="platform-is-built">
1110
  <target name="build-platform" depends="init" unless="platform-is-built">
1106
    <echo message="Building platform modules"/>
1111
    <echo message="Building platform modules"/>
(-)nbbuild/cluster.properties (+1 lines)
Lines 172-177 Link Here
172
        ide/branding \
172
        ide/branding \
173
        ide/updatecenters, \
173
        ide/updatecenters, \
174
        ide/welcome, \
174
        ide/welcome, \
175
        ide/launcher/upgrade, \
175
        tomcatint/tomcat5/bundled
176
        tomcatint/tomcat5/bundled
176
177
177
nb.pkg.test.dir=test
178
nb.pkg.test.dir=test
(-)core/arch/arch-core-launcher.xml (-2 / +23 lines)
Lines 344-351 Link Here
344
            After creating bootstrap classpath another low level set of JARs is loaded with a new
344
            After creating bootstrap classpath another low level set of JARs is loaded with a new
345
            classloader from <samp>core/*.jar</samp> directories in each clusters.
345
            classloader from <samp>core/*.jar</samp> directories in each clusters.
346
        </api>
346
        </api>
347
        <p/>
348
        
349
    </answer>
347
    </answer>
350
348
351
349
Lines 502-507 Link Here
502
                    from the default package is supressed.
500
                    from the default package is supressed.
503
                </api>
501
                </api>
504
            </li>
502
            </li>
503
            <li>
504
                <api name="netbeans.importclass" category="friend" group="property" type="export" >
505
                    There is a special support for importing the settings from previous
506
                    versions. As only the product itself knows about what to import and
507
                    where this cannot be done directly in the launcher, but we need at 
508
                    a well defined moment (user directory is missing and no modules
509
                    have been initialized yet) to call the product to ask the user 
510
                    and do the actual copy of userdir. 
511
                    <p/>
512
                    After all <code>core/*.jar</code> files has been initialized
513
                    and the user dir has not yet been updated (see bellow) the 
514
                    launcher checks for value of <code>netbeans.importclass</code>
515
                    system property and if provided it loads that class and invokes
516
                    its main method (in AWT thread) and if no exception is thrown it 
517
                    marks the userdir as already upgraded.
518
                </api>. 
519
                <api name="${netbeans.user}/var/imported" category="friend" group="java.io.File" type="export" >
520
                    This is used to identify whether a userdir has already been updated
521
                    or it still needs an update. Can be created by installer if no update
522
                    check should be performed, no other code is supposed to realy on 
523
                    this file.
524
                </api>
525
             </li>
505
        </ul>
526
        </ul>
506
        <p>
527
        <p>
507
            Additionally, the launcher in cooperation with the core makes all
528
            Additionally, the launcher in cooperation with the core makes all
(-)core/src/org/netbeans/core/NonGui.java (-45 / +90 lines)
Lines 86-91 Link Here
86
86
87
    /** The Class that logs the IDE events to a log file */
87
    /** The Class that logs the IDE events to a log file */
88
    protected static TopLogging logger;
88
    protected static TopLogging logger;
89
    
90
    /** Tests need to clear some static variables.
91
     */
92
    static final void clearForTests () {
93
        homeDir = null;
94
        userDir = null;
95
    }
89
96
90
    /** Getter for home directory. */
97
    /** Getter for home directory. */
91
    protected static String getHomeDir () {
98
    protected static String getHomeDir () {
Lines 194-199 Link Here
194
        StartLog.logProgress ("PropertyEditors registered"); // NOI18N
201
        StartLog.logProgress ("PropertyEditors registered"); // NOI18N
195
        editorsRegistered = true;
202
        editorsRegistered = true;
196
    }
203
    }
204
    
205
    /** Does import of userdir. Made non-private just for testing purposes.
206
     *
207
     * @return true if the execution should continue or false if it should
208
     *     stop
209
     */
210
    static boolean handleImportOfUserDir () {
211
        class ImportHandler implements Runnable {
212
            private File installed = new File (new File (getUserDir (), "var"), "imported"); // NOI18N
213
            private String classname;
214
            private boolean executedOk; 
215
            
216
            public boolean shouldDoAnImport () {
217
                classname = System.getProperty ("netbeans.importclass"); // NOI18N
218
                
219
                return classname != null && !installed.exists ();
220
            }
221
            
222
            
223
            public void run() {
224
                Class clazz = getKlass (classname);
225
                
226
                // This module is included in our distro somewhere... may or may not be turned on.
227
                // Whatever - try running some classes from it anyway.
228
                try {
229
                    // Method showMethod = wizardClass.getMethod( "handleUpgrade", new Class[] { Splash.SplashOutput.class } ); // NOI18N
230
                    Method showMethod = clazz.getMethod( "main", new Class[] { String[].class } ); // NOI18N
231
                    showMethod.invoke (null, new Object[] {
232
                        new String[0]
233
                    });
234
                    executedOk = true;
235
                } catch (java.lang.reflect.InvocationTargetException ex) {
236
                    // canceled by user, all is fine
237
                    if (ex.getTargetException () instanceof org.openide.util.UserCancelException) {
238
                        executedOk = true;
239
                    }
240
                } catch (Exception e) {
241
                    // If exceptions are thrown, notify them - something is broken.
242
                    e.printStackTrace();
243
                } catch (LinkageError e) {
244
                    // These too...
245
                    e.printStackTrace();
246
                }
247
            }
248
            
249
            
250
            public boolean canContinue () {
251
                if (shouldDoAnImport ()) {
252
                    try {
253
                        SwingUtilities.invokeAndWait (this);
254
                        if (executedOk) {
255
                            // if the import went fine, then we are fine
256
                            // just create the file
257
                            installed.getParentFile ().mkdirs ();
258
                            installed.createNewFile ();
259
                            return true;
260
                        } else {
261
                            return false;
262
                        }
263
                    } catch (IOException ex) {
264
                        // file was not created a bit of problem but go on
265
                        ex.printStackTrace();
266
                        return true;
267
                    } catch (java.lang.reflect.InvocationTargetException ex) {
268
                        return false;
269
                    } catch (InterruptedException ex) {
270
                        ex.printStackTrace();
271
                        return false;
272
                    }
273
                } else {
274
                    // if there is no need to upgrade that every thing is good
275
                    return true;
276
                }
277
            }
278
        }
279
        
280
        
281
        ImportHandler handler = new ImportHandler ();
282
283
        return handler.canContinue ();
284
    }
197
285
198
    /** Initialization of the manager.
286
    /** Initialization of the manager.
199
    */
287
    */
Lines 245-296 Link Here
245
            }
333
            }
246
            
334
            
247
            if ((System.getProperty ("netbeans.full.hack") == null) && (System.getProperty ("netbeans.close") == null) && !dontshowisw) {
335
            if ((System.getProperty ("netbeans.full.hack") == null) && (System.getProperty ("netbeans.close") == null) && !dontshowisw) {
248
                System.setProperty("import.canceled", "false"); // NOI18N
336
                if (!handleImportOfUserDir ()) {
249
                
250
                
251
                SwingUtilities.invokeAndWait(new Runnable() {
252
                    public void run() {
253
                        // Original code
254
                        //boolean canceled = org.netbeans.core.upgrade.UpgradeWizard.showWizard(getSplash());
255
                        //System.setProperty("import.canceled", canceled ? "true" : "false"); // NOI18N
256
                        
257
                        // Let's use reflection
258
                        InstalledFileLocator ifl = new InstalledFileLocatorImpl();
259
                        File coreide = ifl.locate("modules/org-netbeans-core-ide.jar", "org.netbeans.core.ide", false); // NOI18N
260
                        if (coreide != null) {
261
                            // This module is included in our distro somewhere... may or may not be turned on.
262
                            // Whatever - try running some classes from it anyway.
263
                            try {
264
                                List urls = new ArrayList();
265
                                urls.add(coreide.toURI().toURL());
266
                                // #30502: don't forget locale variants!
267
                                Iterator it = NbBundle.getLocalizingSuffixes();
268
                                while (it.hasNext()) {
269
                                    String suffix = (String)it.next();
270
                                    File var = ifl.locate("modules/locale/org-netbeans-core-ide" + suffix + ".jar", "org.netbeans.core.ide", false); // NOI18N
271
                                    if (var != null) {
272
                                        urls.add(var.toURI().toURL());
273
                                    }
274
                                }
275
                                ClassLoader l = new URLClassLoader((URL[])urls.toArray(new URL[urls.size()]), NonGui.class.getClassLoader());
276
                                Class wizardClass = Class.forName("org.netbeans.core.upgrade.AutoUpgrade", true, l); // NOI18N
277
                                Method showMethod = wizardClass.getMethod( "handleUpgrade", new Class[] { Splash.SplashOutput.class } ); // NOI18N
278
279
                                Boolean canceled = (Boolean)showMethod.invoke( null, new Object[] { getSplash() } );
280
                                System.setProperty("import.canceled", canceled.toString()); // NOI18N
281
                            } catch (Exception e) {
282
                                // If exceptions are thrown, notify them - something is broken.
283
                                e.printStackTrace();
284
                            } catch (LinkageError e) {
285
                                // These too...
286
                                e.printStackTrace();
287
                            }
288
                        }
289
                        
290
                    }
291
                });
292
                if (Boolean.getBoolean("import.canceled"))
293
                    TopSecurityManager.exit(0);
337
                    TopSecurityManager.exit(0);
338
                }
294
            }
339
            }
295
        } catch (Exception e) {
340
        } catch (Exception e) {
296
            ErrorManager.getDefault().notify(e);
341
            ErrorManager.getDefault().notify(e);
(-)core/test/unit/src/org/netbeans/core/NonGuiHandleImportOfUserDirTest.java (+109 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
package org.netbeans.core;
14
15
import java.io.File;
16
import java.util.Enumeration;
17
import java.util.MissingResourceException;
18
import java.util.Properties;
19
import java.util.ResourceBundle;
20
import java.util.StringTokenizer;
21
import junit.framework.*;
22
import org.netbeans.junit.*;
23
24
/** Tests the behaviour of the import user dir "api".
25
 */
26
public class NonGuiHandleImportOfUserDirTest extends NbTestCase {
27
    private static NonGuiHandleImportOfUserDirTest instance;
28
    
29
    private File user;
30
    private boolean updaterInvoked;
31
    private Throwable toThrow;
32
    
33
    
34
    public static void main(java.lang.String[] args) throws Throwable {
35
        if (instance != null) {
36
            // ok this is invoked from the test by the core-launcher
37
            instance.nowDoTheInstall ();
38
            return;
39
        } else {
40
            // initial start
41
            junit.textui.TestRunner.run(new junit.framework.TestSuite (NonGuiHandleImportOfUserDirTest.class));
42
        }
43
    }
44
    public NonGuiHandleImportOfUserDirTest (String name) {
45
        super(name);
46
    }
47
48
    protected void setUp () throws Exception {
49
        clearWorkDir ();
50
        NonGui.clearForTests ();
51
        
52
        File home = new File (getWorkDir (), "home");
53
        user = new File (getWorkDir (), "user");
54
        
55
        assertTrue ("Home dir created", home.mkdirs ());
56
        assertTrue ("User dir created", user.mkdirs ());
57
        
58
        System.setProperty ("netbeans.home", home.toString ());
59
        System.setProperty ("netbeans.user", user.toString ());
60
        
61
        System.setProperty ("netbeans.importclass", NonGuiHandleImportOfUserDirTest.class.getName ());
62
        
63
        instance = this;
64
    }
65
    
66
    protected void tearDown () throws Exception {
67
        instance = null;
68
    }
69
    
70
    
71
    private void nowDoTheInstall () throws Throwable {
72
        assertTrue ("Called from AWT thread", javax.swing.SwingUtilities.isEventDispatchThread ());
73
        if (toThrow != null) {
74
            Throwable t = toThrow;
75
            toThrow = null;
76
            throw t;
77
        }
78
        
79
        updaterInvoked = true;
80
    }
81
    
82
    public void testIfTheUserDirIsEmptyTheUpdaterIsInvoked () {
83
        assertTrue ("Ok, returns without problems", NonGui.handleImportOfUserDir ());
84
        assertTrue ("the main method invoked", updaterInvoked);
85
        
86
        toThrow = new RuntimeException ();
87
88
        assertTrue ("The install is not called anymore 1", NonGui.handleImportOfUserDir ());
89
        assertTrue ("The install is not called anymore 2", NonGui.handleImportOfUserDir ());
90
        assertTrue ("The install is not called anymore 3", NonGui.handleImportOfUserDir ());
91
        assertTrue ("The install is not called anymore 4", NonGui.handleImportOfUserDir ());
92
    }
93
94
    public void testIfInvokedAndThrowsExceptionTheExecutionStops () {
95
        toThrow = new RuntimeException ();
96
        
97
        assertFalse ("Says no as exception was thrown", NonGui.handleImportOfUserDir ());
98
        assertNull ("Justs to be sure the exception was cleared", toThrow);
99
    }
100
    
101
    public void testIfThrowsUserCancelExThenUpdateIsFinished () {
102
        toThrow = new org.openide.util.UserCancelException ();
103
        
104
        assertTrue ("Says yes as user canceled the import", NonGui.handleImportOfUserDir ());
105
        assertNull ("Justs to be sure the exception was cleared", toThrow);
106
        
107
        assertTrue ("The install is not called anymore 1", NonGui.handleImportOfUserDir ());
108
    }
109
}
(-)ide/launcher/os2/netbeans.cmd (-1 / +1 lines)
Lines 35-41 Link Here
35
platdir = directory(progdir||"\platform4\launcher")
35
platdir = directory(progdir||"\platform4\launcher")
36
36
37
37
38
__launcher = 'call "'||platdir||'\nbexec.cmd" ("--branding nb --clusters '||netbeans_clusters||' '||nb_args||'")'
38
__launcher = 'call "'||platdir||'\nbexec.cmd" ("-J-Dnetbeans.importclass=org.netbeans.upgrade.AutoUpgrade --branding nb --clusters '||netbeans_clusters||' '||nb_args||'")'
39
interpret __launcher
39
interpret __launcher
40
exit rc
40
exit rc
41
41
(-)ide/launcher/unix/netbeans (+1 lines)
Lines 53-57 Link Here
53
    --branding nb \
53
    --branding nb \
54
    --clusters "$netbeans_clusters" \
54
    --clusters "$netbeans_clusters" \
55
    --userdir "${netbeans_default_userdir}" \
55
    --userdir "${netbeans_default_userdir}" \
56
    -J-Dnetbeans.importclass=org.netbeans.upgrade.AutoUpgrade \
56
    ${netbeans_default_options} \
57
    ${netbeans_default_options} \
57
    "$@"
58
    "$@"
(-)ide/launcher/upgrade/.cvsignore (+1 lines)
Added Link Here
1
build
(-)ide/launcher/upgrade/build.xml (+19 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
                Sun Public License Notice
4
5
The contents of this file are subject to the Sun Public License
6
Version 1.0 (the "License"). You may not use this file except in
7
compliance with the License. A copy of the License is available at
8
http://www.sun.com/
9
10
The Original Code is NetBeans. The Initial Developer of the Original
11
Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
12
Microsystems, Inc. All Rights Reserved.
13
-->
14
15
<project name="ide/launcher/upgrade" default="netbeans" basedir=".">
16
17
    <import file="../../../nbbuild/templates/projectized.xml"/>
18
19
</project>
(-)ide/launcher/upgrade/manifest.mf (+5 lines)
Added Link Here
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.upgrader
3
OpenIDE-Module-Specification-Version: 4.0
4
_OpenIDE-Module-Localizing-Bundle: org/openide/io/Bundle.properties
5
(-)ide/launcher/upgrade/nbproject/project.properties (+16 lines)
Added Link Here
1
#                 Sun Public License Notice
2
# 
3
# The contents of this file are subject to the Sun Public License
4
# Version 1.0 (the "License"). You may not use this file except in
5
# compliance with the License. A copy of the License is available at
6
# http://www.sun.com/
7
# 
8
# The Original Code is NetBeans. The Initial Developer of the Original
9
# Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
10
# Microsystems, Inc. All Rights Reserved.
11
12
module.jar.dir=core
13
test.unit.cp.extra=${nb_all}/openide/test/unit/src:\
14
  ${nb_all}/openide/build/test/unit/classes:\
15
  ${nb_all}/ide/launcher/upgrade/src
16
(-)ide/launcher/upgrade/nbproject/project.xml (+36 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
                Sun Public License Notice
4
5
The contents of this file are subject to the Sun Public License
6
Version 1.0 (the "License"). You may not use this file except in
7
compliance with the License. A copy of the License is available at
8
http://www.sun.com/
9
10
The Original Code is NetBeans. The Initial Developer of the Original
11
Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
12
Microsystems, Inc. All Rights Reserved.
13
-->
14
<project xmlns="http://www.netbeans.org/ns/project/1">
15
    <type>org.netbeans.modules.apisupport.project</type>
16
    <name>org.netbeans.upgrade</name>
17
    <configuration>
18
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/1">
19
            <path>ide/launcher/upgrade</path>
20
            <module-dependencies>
21
                <dependency>
22
                    <code-name-base>org.openide</code-name-base>
23
                    <build-prerequisite/>
24
                    <compile-dependency/>
25
                    <run-dependency>
26
                        <release-version>1</release-version>
27
                        <specification-version>4.0</specification-version>
28
                    </run-dependency>
29
                </dependency>
30
            </module-dependencies>
31
            <public-packages>
32
            </public-packages>
33
            <javadoc/>
34
        </data>
35
    </configuration>
36
</project>
(-)ide/launcher/upgrade/src/org/netbeans/upgrade/AutoUpgrade.java (+167 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.upgrade;
15
16
import java.awt.Dialog;
17
import java.awt.event.ActionEvent;
18
import java.awt.event.ActionListener;
19
import java.io.*;
20
import java.io.File;
21
import java.io.IOException;
22
import java.lang.reflect.InvocationTargetException;
23
import java.util.Arrays;
24
import java.util.Iterator;
25
import java.util.List;
26
27
import org.openide.DialogDescriptor;
28
import org.openide.DialogDisplayer;
29
import org.openide.ErrorManager;
30
import org.openide.NotifyDescriptor;
31
import org.openide.filesystems.FileObject;
32
import org.openide.filesystems.LocalFileSystem;
33
import org.openide.filesystems.Repository;
34
import org.openide.util.NbBundle;
35
36
/** pending
37
 *
38
 * @author  Jiri Rechtacek
39
 */
40
public final class AutoUpgrade {
41
42
    /** Shows the import dialog if there is no folder under the Projects
43
     * subfolder of system default filesystem. This condition is met during
44
     * the first start only.
45
     * 
46
     * @return true when and only when the dialog was displayed and user has canceled it,
47
     * false otherwise (upgrade is done or not needed).
48
     */
49
    //public static boolean handleUpgrade (SplashOutput splash) {
50
    
51
    public static void main (String[] args) throws Exception {
52
        String[] version = new String[1];
53
        File sourceFolder = checkPrevious (version);
54
        if (sourceFolder != null) {
55
            if (!showUpgradeDialog (sourceFolder)) {
56
                throw new org.openide.util.UserCancelException ();
57
            }
58
            doUpgrade (sourceFolder, version[0]);
59
        }
60
    }
61
    
62
    // XXX: the versions will be read from properties files to allow branding
63
    final static private List VERSION_TO_CHECK = Arrays.asList (new String[] { "3.6" });
64
    final static private String USER_DIR_PREFIX = ".netbeans"; // NOI18N
65
    
66
    static private File checkPrevious (String[] version) {
67
        boolean exists;
68
        
69
        String userHome = System.getProperty ("user.home"); // NOI18N
70
        File sourceFolder = null;
71
        
72
        if (userHome != null) {
73
            File userHomeFile = new File (userHome);
74
            exists = userHomeFile.isDirectory ();
75
76
            Iterator it = VERSION_TO_CHECK.iterator ();
77
            String ver;
78
            while (it.hasNext () && sourceFolder == null) {
79
                ver = (String) it.next ();
80
                sourceFolder = new File (
81
                    new File (userHomeFile.getAbsolutePath (), USER_DIR_PREFIX),
82
                    ver
83
                );
84
                
85
                if (sourceFolder.isDirectory ()) {
86
                    version[0] = ver;
87
                    break;
88
                }
89
                sourceFolder = null;
90
            }
91
            return sourceFolder;
92
        } else {
93
            return null;
94
        }
95
    }
96
    
97
    private static boolean showUpgradeDialog (final File source) {
98
        /*
99
        if (splash != null) {
100
            Splash.hideSplash (splash);
101
        }
102
         */
103
        
104
        DialogDescriptor dd = new DialogDescriptor (
105
            new AutoUpgradePanel (source.getAbsolutePath ()),
106
            NbBundle.getMessage (AutoUpgrade.class, "MSG_Confirmation_Title"), // NOI18N
107
            true,
108
            NotifyDescriptor.YES_NO_OPTION,
109
            NotifyDescriptor.NO_OPTION,
110
            null
111
        );
112
        
113
        
114
        Dialog dlg = DialogDisplayer.getDefault ().createDialog (dd);
115
        dlg.show ();
116
          
117
        return dd.getValue () == NotifyDescriptor.YES_OPTION;
118
    }
119
    
120
    private static void doUpgrade (File source, String oldVersion) 
121
    throws java.io.IOException, java.beans.PropertyVetoException {
122
        
123
        
124
        if ("3.6".equals (oldVersion)) {
125
            File userdir = new File(System.getProperty ("netbeans.user", "")); // NOI18N
126
127
            Reader r = new InputStreamReader (
128
                AutoUpgrade.class.getResourceAsStream ("copy3.6"), // NOI18N
129
                "utf-8"
130
            );
131
            java.util.Set includeExclude = IncludeExclude.create (r);
132
            r.close ();
133
134
135
            ErrorManager.getDefault ().log (
136
                ErrorManager.USER, "Import: Old version: " // NOI18N
137
                + oldVersion + ". Importing from " + source + " to " + userdir // NOI18N
138
            );
139
140
            File oldConfig = new File (source, "system"); // NOI18N
141
            LocalFileSystem old = new LocalFileSystem ();
142
            old.setRootDirectory (oldConfig);
143
            org.openide.filesystems.FileSystem mine = Repository.getDefault ().getDefaultFileSystem ();
144
            
145
            FileObject defaultProject = old.findResource ("Projects/Default/"); // NOI18N
146
            if (defaultProject != null) {
147
                // first copy content from default project
148
                Copy.copyDeep (defaultProject, mine.getRoot (), includeExclude);
149
            }
150
            
151
            FileObject projects = old.findResource ("Projects"); // NOI18N
152
            if (projects != null) {
153
                FileObject[] allProjects = projects.getChildren ();
154
                for (int i = 0; i < allProjects.length; i++) {
155
                    // content from projects is prefered
156
                    Copy.copyDeep (allProjects[i], mine.getRoot (), includeExclude);
157
                }
158
            }
159
            
160
161
            Copy.copyDeep (old.getRoot (), mine.getRoot (), includeExclude);
162
            return;
163
        }
164
        
165
        throw new IOException ("Cannot import from version: " + oldVersion);
166
    }
167
}
(-)ide/launcher/upgrade/src/org/netbeans/upgrade/AutoUpgradePanel.form (+47 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.0" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <Properties>
5
    <Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
6
      <Dimension value="[123456, 123456]"/>
7
    </Property>
8
    <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
9
      <Dimension value="[500, 279]"/>
10
    </Property>
11
    <Property name="name" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
12
      <ResourceString bundle="org/netbeans/core/upgrade/Bundle.properties" key="LBL_UpgradePanel_Name" replaceFormat="bundle.getString(&quot;{key}&quot;)"/>
13
    </Property>
14
  </Properties>
15
  <AuxValues>
16
    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,0,-85,0,0,1,-48"/>
17
  </AuxValues>
18
19
  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
20
  <SubComponents>
21
    <Component class="javax.swing.JTextArea" name="txtVersions">
22
      <Properties>
23
        <Property name="columns" type="int" value="50"/>
24
        <Property name="lineWrap" type="boolean" value="true"/>
25
        <Property name="rows" type="int" value="3"/>
26
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
27
          <ResourceString bundle="org/netbeans/core/upgrade/Bundle.properties" key="MSG_Confirmation" replaceFormat="NbBundle.getMessage (AutoUpgradePanel.class, &quot;{key}&quot;, source)"/>
28
        </Property>
29
        <Property name="wrapStyleWord" type="boolean" value="true"/>
30
        <Property name="disabledTextColor" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
31
          <Color blue="0" green="0" red="0" type="rgb"/>
32
        </Property>
33
        <Property name="doubleBuffered" type="boolean" value="true"/>
34
        <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
35
          <Dimension value="[100, 50]"/>
36
        </Property>
37
        <Property name="enabled" type="boolean" value="false"/>
38
        <Property name="opaque" type="boolean" value="false"/>
39
      </Properties>
40
      <Constraints>
41
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
42
          <GridBagConstraints gridX="-1" gridY="-1" gridWidth="-1" gridHeight="-1" fill="1" ipadX="0" ipadY="0" insetsTop="10" insetsLeft="10" insetsBottom="10" insetsRight="10" anchor="10" weightX="1.0" weightY="1.0"/>
43
        </Constraint>
44
      </Constraints>
45
    </Component>
46
  </SubComponents>
47
</Form>
(-)ide/launcher/upgrade/src/org/netbeans/upgrade/AutoUpgradePanel.java (+117 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.upgrade;
15
16
import java.awt.Dialog;
17
import java.util.ArrayList;
18
import java.util.ResourceBundle;
19
import javax.swing.JPanel;
20
import javax.swing.event.ChangeListener;
21
import org.openide.DialogDescriptor;
22
import org.openide.DialogDisplayer;
23
import org.openide.util.NbBundle;
24
25
26
/**
27
 * @author Jiri Rechtacek
28
 */
29
final class AutoUpgradePanel extends JPanel {
30
31
    public static void main(String args[]) {
32
        // display dialog
33
        DialogDescriptor descriptor = new DialogDescriptor (
34
            new AutoUpgradePanel("<directory>"), // NOI18N
35
            bundle.getString("MSG_Confirmation_Title") // NOI18N
36
        );
37
        Dialog dialog = DialogDisplayer.getDefault().createDialog(descriptor);
38
        dialog.show();
39
        dialog.dispose();
40
    }
41
    
42
    String source;
43
44
    /** Creates new form UpgradePanel */
45
    public AutoUpgradePanel (String directory) {
46
        this.source = directory;
47
        initComponents();
48
        initAccessibility(); 
49
        
50
    }
51
52
    /** Remove a listener to changes of the panel's validity.
53
     * @param l the listener to remove
54
     */
55
    void removeChangeListener(ChangeListener l) {
56
        changeListeners.remove(l);
57
    }
58
59
    /** Add a listener to changes of the panel's validity.
60
     * @param l the listener to add
61
     * @see #isValid
62
     */
63
    void addChangeListener(ChangeListener l) {
64
        if (!changeListeners.contains(l)) {
65
            changeListeners.add(l);
66
        }
67
    }
68
69
    private void initAccessibility() {
70
        this.getAccessibleContext().setAccessibleDescription(bundle.getString("MSG_Confirmation")); // NOI18N
71
    }
72
    
73
    
74
    /** This method is called from within the constructor to
75
     * initialize the form.
76
     * WARNING: Do NOT modify this code. The content of this method is
77
     * always regenerated by the Form Editor.
78
     */
79
    private void initComponents() {//GEN-BEGIN:initComponents
80
        java.awt.GridBagConstraints gridBagConstraints;
81
82
        txtVersions = new javax.swing.JTextArea();
83
84
        setLayout(new java.awt.GridBagLayout());
85
86
        setMaximumSize(new java.awt.Dimension(123456, 123456));
87
        setMinimumSize(new java.awt.Dimension(500, 279));
88
        setName(bundle.getString("LBL_UpgradePanel_Name"));
89
        txtVersions.setColumns(50);
90
        txtVersions.setLineWrap(true);
91
        txtVersions.setRows(3);
92
        txtVersions.setText(NbBundle.getMessage (AutoUpgradePanel.class, "MSG_Confirmation", source));
93
        txtVersions.setWrapStyleWord(true);
94
        txtVersions.setDisabledTextColor(new java.awt.Color(0, 0, 0));
95
        txtVersions.setDoubleBuffered(true);
96
        txtVersions.setMinimumSize(new java.awt.Dimension(100, 50));
97
        txtVersions.setEnabled(false);
98
        txtVersions.setOpaque(false);
99
        gridBagConstraints = new java.awt.GridBagConstraints();
100
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
101
        gridBagConstraints.gridheight = java.awt.GridBagConstraints.RELATIVE;
102
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
103
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
104
        gridBagConstraints.weightx = 1.0;
105
        gridBagConstraints.weighty = 1.0;
106
        add(txtVersions, gridBagConstraints);
107
108
    }//GEN-END:initComponents
109
110
    // Variables declaration - do not modify//GEN-BEGIN:variables
111
    private javax.swing.JTextArea txtVersions;
112
    // End of variables declaration//GEN-END:variables
113
114
    private static final ResourceBundle bundle = NbBundle.getBundle(AutoUpgradePanel.class);
115
    private ArrayList changeListeners = new ArrayList(1);
116
    
117
}
(-)ide/launcher/upgrade/src/org/netbeans/upgrade/Bundle.properties (+108 lines)
Added Link Here
1
#                 Sun Public License Notice
2
# 
3
# The contents of this file are subject to the Sun Public License
4
# Version 1.0 (the "License"). You may not use this file except in
5
# compliance with the License. A copy of the License is available at
6
# http://www.sun.com/
7
# 
8
# The Original Code is NetBeans. The Initial Developer of the Original
9
# Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
10
# Microsystems, Inc. All Rights Reserved.
11
12
MSG_NO_BACKUP_EMPTY=Backup directory is not empty.
13
MSG_NO_BACKUP_CREATED=Backup directory has not been created.
14
CTL_README=README.html
15
MSG_NOT_FOUNDED=  File {0} not found.
16
MSG_IS_NOT_FOLDER={0} is not a folder.
17
MSG_BACKUP_EXISTS=Backup directory does not exist.
18
MSG_UPDATE_FROM=Import from {0}
19
MSG_BAD_IDE=Source IDE must be one of these versions:
20
MSG_TITLE=Update IDE Environments From Old Releases
21
MSG_COMMAND_LINE="{0} <backup.dir> <old_IDE.home> <new_IDE.home>"
22
LBL_lblVersion=Version:
23
MSG_BackupDir_exists=Backup directory {0} already exists.
24
25
LBL_Upgrade_Description_Top=Enter the location of your previous IDE's user directory in the Previous IDE field. \n\
26
\n\
27
The default location for IDE settings is:
28
LBL_Upgrade_Description_Versions=Microsoft Windows systems:\n\
29
\           NetBeans 3.5.x software - <userhome>/.netbeans/3.5\n\
30
\           NetBeans 3.4.x software - <userhome>/.netbeans/3.4\n\
31
\           NetBeans 3.3.x software and earlier editions - user-specified directory\n\
32
UNIX systems:\n\
33
\           NetBeans 3.5.x software - <userhome>/.netbeans/3.5\n\
34
\           NetBeans 3.4.x software - <userhome>/.netbeans/3.4\n\
35
\           NetBeans 3.3.x software - <userhome>/nbuser33\n\
36
\           NetBeans 3.2.x software - <userhome>/nbuser32\n\
37
\           NetBeans software (3.0 and 3.1 releases) - IDE installation directory\n\
38
\           Forte For Java software (3.0 and 4.0 releases) - <userhome>/nbuser\n\
39
\           Forte For Java, release 2.0, software - IDE installation directory\n\
40
\           Sun ONE Studio 4 update 1 Community Edition software - <userhome>/ffjuser40ce
41
LBL_Upgrade_Description_Note=Note: If you cannot locate your previous IDE's user directory,\
42
\ open your previous IDE and choose About from the Help menu.\
43
\ The user directory location is listed under User Dir in the Details tab.
44
45
46
MSG_Upgrade_Succeeded=Settings imported successfully.
47
MSG_Upgrade_Failed=The import procedure has failed.
48
MSG_Upgrade_Finished=Done.
49
MSG_Upgrade_Started=Importing ...
50
LBL_lblUpgradeStatus=Import Settings Status:
51
LBL_cmdSelectDir=Browse...
52
LBL_cmdSelectDir_Mnem=r
53
LBL_UpgradeWizard_Title=Settings Import Wizard
54
MSG_SplashScreen_status=Importing old settings ...
55
BTN_Exit_IDE=Exit IDE
56
BTN_Exit_IDE_Mnem=E
57
BTN_Start_IDE=Start IDE
58
BTN_Start_IDE_Mnem=S
59
BTN_Import=Import
60
BTN_Import_Mnem=I
61
LBL_lblSelection=Do you wish to import settings from a previous installation?
62
LBL_PreUpgradePanel_Name=Do you need to import settings?
63
LBL_rbUpgrade=\ Yes, please import my settings from the previous version.
64
LBL_rbDontUpgrade=\ No, skip the settings import.
65
LBL_PreUpgradeText_Bottom=Note: It is not possible to import settings at a later time.
66
67
LBL_PreUpgradeText_Top=This wizard lets you import your IDE environment and settings from previous versions of the IDE.
68
69
MSG_recovery_finished=System recovered successfully.
70
MSG_recovery_started=Import failed, recovery started.
71
LBL_TransferSettingsPanel_Name=Import Settings
72
LBL_UpgradePanel_Name=Locate Previous IDE
73
LBL_lblLocation=Previous IDE:
74
LBL_lblLocation_Mnem=P
75
MSG_Old_IDE_Location_Invalid=You did not select a valid IDE directory or the version of the IDE is unknown.
76
LBL_SelectDir_Dialog_Title=Select Previous IDE Location
77
LBL_Open_Button=Open
78
CTL_UNIX_SCRIPT=import.sh
79
CTL_WINDOWS_SCRIPT=import.bat
80
LBL_rbDontUpgrade_Mnemonic=N
81
LBL_rbUpgrade_Mnemonic=Y
82
ACS_rbDontUpgrade=N/A
83
ACS_rbUpgrade=N/A
84
ACS_txtUpgrade2_Bottom_Name=Result status
85
ACS_txtUpgrade2_Bottom_Desc=Status of IDE settings import.
86
ACS_txtLocation=N/A
87
ACS_txtVersion=N/A
88
ACS_cmdSelectDir=N/A
89
ACS_TransferSettingsPanel=Import settings status
90
91
MSG_directory_not_exist=Directory {0} can not be found or mounted.
92
93
# NewUserPanel
94
NU_LBL_Label=Were any of these IDEs previously installed on this system?
95
NU_BTN_Yes=Yes, other versions of the IDE were installed on this system
96
NU_BTN_Yes_Mnem=Y
97
NU_BTN_No=No, none of the above versions were previously installed on this system
98
NU_BTN_No_Mnem=N
99
NU_LBL_Versions=NetBeans software (3.5.x, 3.4.x, 3.3.x, 3.2.x, 3.1 or 3.0 releases)\n\
100
Forte for Java software (4.0, 3.0 or 2.0 releases)\n\
101
Sun ONE Studio 4 update 1 software
102
NU_MSG_Title=Are you a returning user?
103
ACS_BTN_Yes=N/A
104
ACS_BTN_No=N/A
105
106
#AutoUpgdare dialog
107
MSG_Confirmation = Settings created by a previous version of the IDE were found on your system at {0}. Do you want to import them?
108
MSG_Confirmation_Title = Confirm Import Settings
(-)ide/launcher/upgrade/src/org/netbeans/upgrade/Copy.java (+463 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.upgrade;
15
16
import java.io.*;
17
import java.util.*;
18
import org.openide.util.*;
19
import java.util.jar.*;
20
import org.w3c.dom.*;
21
import org.xml.sax.*;
22
import org.openide.xml.XMLUtil;
23
24
import org.openide.filesystems.*;
25
import org.openide.filesystems.FileSystem;
26
27
28
/** Does copy of objects on filesystems.
29
 *
30
 * @author Jaroslav Tulach
31
 */
32
final class Copy extends Object {
33
    
34
    
35
    /** Does a selective copy of one source tree to another. 
36
     * @param source file object to copy from
37
     * @param target file object to copy to
38
     * @param thoseToCopy set on which contains (relativeNameOfAFileToCopy) 
39
     *   is being called to find out whether to copy or not
40
     * @throws IOException if coping fails
41
     */
42
    public static void copyDeep (FileObject source, FileObject target, Set thoseToCopy) 
43
    throws IOException {
44
        copyDeep (source, target, thoseToCopy, null);
45
    }
46
    
47
    private static void copyDeep ( 
48
        FileObject source, FileObject target, Set thoseToCopy, String prefix
49
    ) throws IOException {
50
        FileObject src = prefix == null ? source : FileUtil.createFolder (source, prefix);
51
        
52
        FileObject[] arr = src.getChildren();
53
        for (int i = 0; i < arr.length; i++) {
54
            String fullname;
55
            if (prefix == null) {
56
                fullname = arr[i].getNameExt ();
57
            } else {
58
                fullname = prefix + "/" + arr[i].getNameExt ();
59
            }
60
            if (arr[i].isData ()) {
61
                if (!thoseToCopy.contains (fullname)) {
62
                    continue;
63
                }
64
            }
65
66
            
67
            if (arr[i].isFolder()) {
68
                copyDeep (source, target, thoseToCopy, fullname);
69
                if (thoseToCopy.contains (fullname) && arr[i].getAttributes ().hasMoreElements ()) {
70
                    FileObject tg = FileUtil.createFolder (target, fullname);
71
                    FileUtil.copyAttributes (arr[i], tg);
72
                }
73
            } else {
74
                FileObject folder = prefix == null ? target : FileUtil.createFolder (target, prefix);
75
                FileObject tg = folder.getFileObject (arr[i].getNameExt ());
76
                if (tg == null) {
77
                    // copy the file otherwise keep old content
78
                    tg = FileUtil.copyFile (arr[i], folder, arr[i].getName(), arr[i].getExt ());
79
                }
80
                
81
                FileUtil.copyAttributes (arr[i], tg);
82
            }
83
        }
84
        
85
        
86
    }
87
    
88
    
89
90
    /** Updates the IDE.
91
     * @param sourceDir original instalation of the IDE
92
     * @param targetSystem target system to copy files to
93
     * @param backupSystem filesystem to do backupSystemFo to (or null)
94
     * @exception IOException if the copying fails
95
     *
96
    protected final void upgradeIde (String ver, File src, File trg) throws Exception {
97
        
98
        
99
        int version = getIdeVersion (ver);
100
        if (version < 0 || version >= versions.length) {
101
            message (getString ("MSG_BAD_IDE"));
102
            for (int i = 0 ; i < versions.length ; i++ ) {
103
                message (versions[i]);
104
            }
105
            throw new Exception ("Invalid IDE version"); //NOI18N
106
        }
107
108
        message (getString ("MSG_UPDATE_FROM", versions[version]));
109
110
        FileSystem srcFS = null;
111
        FileSystem trgFS = null;
112
        FileSystem tmpFS = null;
113
        Object filter [] = null;
114
115
        if (-1 != ver.indexOf (DIRTYPE_INST)) {
116
            File srcFile = new File (src, "system"); //NOI18N
117
            File trgFile = new File (trg, "system"); //NOI18N
118
            srcFS = createFileSystem (srcFile);
119
            trgFS = createFileSystem (trgFile);
120
121
            if (srcFS == null) {
122
                message (getString ("MSG_directory_not_exist", srcFile.getAbsolutePath ())); //NOI18N
123
                throw new Exception ("Directory doesn't exist - " + srcFile.getAbsolutePath ()); //NOI18N
124
            }
125
126
            if (trgFS == null) {
127
                message (getString ("MSG_directory_not_exist", trgFile.getAbsolutePath ()));
128
                throw new Exception ("Directory doesn't exist - " + trgFile.getAbsolutePath ()); //NOI18N
129
            }
130
131
            File tmpRoot = new File (trg, "system_backup"); //NOI18N
132
            if (!tmpRoot.exists ()) {
133
//                message (getString ("MSG_BackupDir_exists", tmpRoot.getAbsolutePath ())); //NOI18N
134
//                throw new Exception ("Backup directory already exists - " + tmpRoot.getAbsolutePath ()); //NOI18N
135
//            } else {
136
                tmpRoot.mkdirs ();
137
            }
138
            tmpFS = createFileSystem (tmpRoot);
139
140
            filter = originalFiles (nonCpFiles[version]);
141
        } else {
142
            srcFS = createFileSystem (src); //NOI18N
143
            trgFS = createFileSystem (trg); //NOI18N
144
145
            if (srcFS == null) {
146
                message (getString ("MSG_directory_not_exist", src.getAbsolutePath ())); //NOI18N
147
                throw new Exception ("Directory doesn't exist - " + src.getAbsolutePath ()); //NOI18N
148
            }
149
150
            if (trgFS == null) {
151
                message (getString ("MSG_directory_not_exist", trg.getAbsolutePath ())); //NOI18N
152
                throw new Exception ("Directory doesn't exist - " + trg.getAbsolutePath ()); //NOI18N
153
            }
154
155
            File tmpRoot = new File (trg.getParentFile (), "userdir_backup"); //NOI18N
156
            if (!tmpRoot.exists ()) {
157
//                message (getString ("MSG_BackupDir_exists", tmpRoot.getAbsolutePath ())); //NOI18N
158
//                throw new Exception ("Backup directory already exists - " + tmpRoot.getAbsolutePath ()); //NOI18N
159
//            } else {
160
                tmpRoot.mkdirs ();
161
            }
162
            tmpFS = createFileSystem (tmpRoot);
163
164
            filter = originalFiles (userdirNonCpFiles);
165
        }
166
167
        if (tmpFS != null) {
168
            // clean up temporary filesystem
169
            FileObject ch [] = tmpFS.getRoot ().getChildren ();
170
            for (int i = 0; i < ch.length; i++) {
171
                deleteAll (ch[i]);
172
            }
173
            // make a backup copy
174
            copyAttributes(trgFS.getRoot (), tmpFS.getRoot ());
175
            recursiveCopy(trgFS.getRoot (), tmpFS.getRoot ());
176
        }
177
        
178
        try {
179
            update (srcFS, trgFS, getLastModified (src), filter);
180
        }
181
        catch (Exception e) {
182
            if (tmpFS != null) {
183
                message (getString ("MSG_recovery_started")); //NOI18N
184
                deleteAll (trgFS.getRoot ());
185
                copyAttributes (tmpFS.getRoot (), trgFS.getRoot ());
186
                recursiveCopy (tmpFS.getRoot (), trgFS.getRoot ());
187
                message (getString ("MSG_recovery_finished")); //NOI18N
188
            }
189
            throw e;
190
        }
191
    }
192
    
193
    private FileSystem createFileSystem (File root) {
194
        LocalFileSystem lfs = null;
195
196
        if (root.exists () && root.isDirectory ()) {
197
            try {
198
                lfs = new LocalFileSystem ();
199
                lfs.setRootDirectory (root);
200
            }
201
            catch (Exception e) {
202
                lfs = null;
203
            }
204
        }
205
  
206
        return lfs == null ? null : new AttrslessLocalFileSystem (lfs);
207
    }
208
209
    private void update(
210
        FileSystem src, FileSystem trg, long sourceBaseTime, Object[] filter
211
    ) throws IOException {
212
213
        items = 0;
214
        maxItems = 0;
215
216
        copyAttributes (src.getRoot (),trg.getRoot ());
217
        recursiveCopyWithFilter (
218
            src.getRoot (),
219
            trg.getRoot (),
220
            filter,
221
            sourceBaseTime
222
        );
223
    }
224
    
225
    /** copies recursively directory, skips files existing in target location
226
     *  @param source source directory
227
     *  @param dest destination directory
228
     */
229
    private void recursiveCopy (FileObject sourceFolder, FileObject destFolder) throws IOException {
230
        FileObject childrens []  = sourceFolder.getChildren();
231
        for (int i = 0 ; i < childrens.length ; i++ ) {
232
            final FileObject subSourceFo = childrens[i];
233
            FileObject subTargetFo = null;
234
            
235
            if (subSourceFo.isFolder()) {
236
                subTargetFo =  destFolder.getFileObject(subSourceFo.getName());
237
                if (subTargetFo == null) {
238
                    subTargetFo = destFolder.createFolder(subSourceFo.getName());
239
                    
240
                }
241
                copyAttributes(subSourceFo,subTargetFo);
242
                recursiveCopy(subSourceFo,subTargetFo);
243
            } else {
244
                subTargetFo =  destFolder.getFileObject(subSourceFo.getNameExt());
245
                if (subTargetFo == null) {
246
                     if ( Utilities.getOperatingSystem () == Utilities.OS_VMS 
247
                        && subSourceFo.getNameExt ().equalsIgnoreCase ( "_nbattrs.") ) 
248
                        subTargetFo = FileUtil.copyFile(subSourceFo, destFolder, subSourceFo.getNameExt(), subSourceFo.getExt());
249
                     else
250
                        subTargetFo = FileUtil.copyFile(subSourceFo, destFolder, subSourceFo.getName(), subSourceFo.getExt());
251
                }
252
                copyAttributes(subSourceFo,subTargetFo);
253
            }
254
        }
255
    }
256
257
    private void message (String s) {
258
        
259
    }
260
    private void progress (int x, int y) {
261
        
262
    }
263
    private int maxItems;
264
    private int items;
265
    private int timeDev;
266
    
267
    /** Copies recursively dircectory. Files are copied when when basicTime + timeDev < time of file.
268
     *  @param source source directory
269
     *  @param #dest destination dirctory
270
     */
271
    private void recursiveCopyWithFilter (
272
        FileObject source, FileObject dest, Object[] filter, long basicTime
273
    ) throws IOException {
274
        FileObject childrens []  = source.getChildren();
275
        if (source.isFolder() == false ) {
276
            message (getString("MSG_IS_NOT_FOLDER", source.getName()));
277
        }
278
279
        // adjust max number of items
280
        maxItems += childrens.length;
281
282
        for (int i = 0 ; i < childrens.length ; i++ ) {
283
            FileObject subSourceFo = childrens[i];
284
285
            // report progress
286
            items++;
287
            progress(items, maxItems);
288
289
            if (!canCopy (subSourceFo, filter, basicTime))
290
                continue;
291
            
292
            FileObject subTargetFo = null;
293
            if (subSourceFo.isFolder ()) {
294
                subTargetFo =  dest.getFileObject (subSourceFo.getNameExt ());
295
                if (subTargetFo == null) {
296
                    subTargetFo = dest.createFolder (subSourceFo.getNameExt ());
297
                    
298
                }
299
                copyAttributes (subSourceFo, subTargetFo);
300
                recursiveCopyWithFilter (subSourceFo, subTargetFo, filter, basicTime);
301
            } else {
302
                subTargetFo = dest.getFileObject (subSourceFo.getName (), subSourceFo.getExt ());
303
               
304
                if (subTargetFo != null) {
305
                    FileLock lock = subTargetFo.lock ();
306
                    subTargetFo.delete (lock);
307
                    lock.releaseLock ();
308
                } 
309
                
310
                if ( Utilities.getOperatingSystem () == Utilities.OS_VMS 
311
                    && subSourceFo.getNameExt ().equalsIgnoreCase ( "_nbattrs.") ) 
312
                    subTargetFo = copyFile (subSourceFo, dest, subSourceFo.getNameExt ());
313
                else
314
                    subTargetFo = copyFile (subSourceFo, dest, subSourceFo.getName ());
315
                copyAttributes (subSourceFo, subTargetFo);
316
            }
317
        }
318
    }
319
320
    private FileObject copyFile (FileObject src, FileObject trg, String newName) throws IOException {
321
        return FileUtil.copyFile (src, trg, newName);
322
    }
323
        
324
    private static void copyAttributes (FileObject source, FileObject dest) throws IOException {
325
        Enumeration attrKeys = source.getAttributes();
326
        while (attrKeys.hasMoreElements()) {
327
            String key = (String) attrKeys.nextElement();
328
            Object value = source.getAttribute(key);
329
            if (value != null) {
330
                dest.setAttribute(key, value);
331
            }
332
        }
333
    }
334
    /** test if file can be copied
335
     */
336
    private boolean canCopy (FileObject fo, Object[] filter, long basicTime) throws IOException {
337
        String nonCopiedFiles [] = (String []) filter [0];
338
        String wildcards [] = (String []) filter [1];
339
        String name =  fo.getPath();
340
        
341
        if (fo.isFolder ()) {
342
            return Arrays.binarySearch (nonCopiedFiles, name + "/*") < 0; //NOI18N
343
        }
344
345
        for (int i = 0; i < wildcards.length; i++) {
346
            if (name.endsWith (wildcards [i])) {
347
                return false;
348
            }
349
        }
350
351
        long time =  fo.lastModified().getTime();
352
        
353
        boolean canCopy = Arrays.binarySearch (nonCopiedFiles, name) < 0 &&
354
               basicTime + timeDev <= time;
355
        if (!canCopy) {
356
            return false;
357
        }
358
        
359
        // #31623 - the fastjavac settings should not be imported.
360
        // In NB3.5 the fastjavac was separated into its own module.
361
        // Its old settings (bounded to java module) must not be imported.
362
        // For fastjavac settings created by NB3.5 this will work, because they
363
        // will be bound to new "org.netbeans.modules.java.fastjavac" module.
364
        if (fo.getExt().equals("settings")) { //NOI18N
365
            boolean tag1 = false;
366
            boolean tag2 = false;
367
            BufferedReader reader = null;
368
            try {
369
                reader = new BufferedReader(new InputStreamReader(fo.getInputStream()));
370
                String line;
371
                while (null != (line = reader.readLine())) {
372
                    if (line.indexOf("<module name=") != -1) { //NOI18N
373
                        if (line.indexOf("<module name=\"org.netbeans.modules.java/1\"") != -1) { //NOI18N
374
                            tag1 = true; // it is java module setting
375
                        } else {
376
                            break; // some other setting, ignore this file
377
                        }
378
                    }
379
                    if (line.indexOf("<serialdata class=") != -1) { //NOI18N
380
                        if (line.indexOf("<serialdata class=\"org.netbeans.modules.java.FastJavacCompilerType\">") != -1) { //NOI18N
381
                            tag2 = true; // it is fastjavac setting
382
                            if (tag1) {
383
                                break;
384
                            }
385
                        } else {
386
                            break; // some other setting, ignore this file
387
                        }
388
                    }
389
                }
390
            } catch (IOException ex) {
391
                // ignore this problem. 
392
                // in worst case the fastjavac settings will be copied.
393
            } finally {
394
                if (reader != null) {
395
                    reader.close();
396
                }
397
            }
398
            if (tag1 && tag2) {
399
                return false; // ignore this file. it is fastjavac settings
400
            }
401
        }
402
        
403
        return true;
404
    }
405
    // ************************* version retrieving code ********************
406
407
    
408
    /** We support import just from release 3.6
409
     * @param dir user dir to check for version
410
     * @return either null or name of the version
411
     */
412
    public static String getIdeVersion (File dir) {
413
        String version = null;
414
        String dirType = null;
415
        String branding = null;
416
        
417
        if (new File (dir, "system").exists ()) {
418
            return "3.6";
419
        }
420
        return null;
421
    }
422
423
    // ************** strings from bundle ***************
424
425
    protected static String getString (String key) {
426
        return NbBundle.getMessage (Copy.class, key);
427
    }
428
429
    protected static String getString (String key,String param) {
430
        return NbBundle.getMessage(Copy.class,key,param);
431
    }
432
    
433
    private static class AttrslessLocalFileSystem extends AbstractFileSystem implements AbstractFileSystem.Attr {
434
        public AttrslessLocalFileSystem (LocalFileSystem fs) {
435
            super ();
436
            this.change = new LocalFileSystem.Impl (fs);
437
            this.info = (AbstractFileSystem.Info) this.change;
438
            this.list = (AbstractFileSystem.List) this.change;
439
            this.attr = this;
440
        }
441
        public boolean isReadOnly () {
442
            return false;
443
        }
444
        public String getDisplayName () {
445
            return getClass ().toString (); // this will never be shown to user
446
        }
447
448
        // ***** no-op implementation of AbstractFileSystem.Attr *****
449
450
        public void deleteAttributes (String name) {
451
        }
452
        public Enumeration attributes (String name) {
453
            return org.openide.util.enum.EmptyEnumeration.EMPTY;
454
        }
455
        public void renameAttributes (String oldName, String newName) {
456
        }
457
        public void writeAttribute (String name, String attrName, Object value) throws IOException {
458
        }
459
        public Object readAttribute (String name, String attrName) {
460
            return null;
461
        }
462
    }
463
}
(-)ide/launcher/upgrade/src/org/netbeans/upgrade/IncludeExclude.java (+102 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.upgrade;
15
16
import java.io.*;
17
import java.util.*;
18
import java.util.jar.*;
19
import java.util.regex.*;
20
21
22
23
/** A test that is initialized based on includes and excludes.
24
 *
25
 * @author Jaroslav Tulach
26
 */
27
final class IncludeExclude extends AbstractSet {
28
    /** List<Boolean and Pattern> 
29
     */
30
    private ArrayList patterns = new ArrayList ();
31
    
32
    private IncludeExclude () {
33
    }
34
35
    /** Reads the include/exclude set from a given reader.
36
     * @param r reader 
37
     * @return set that accepts names based on include exclude from the file
38
     */
39
    public static Set create (Reader r) throws IOException {
40
        IncludeExclude set = new IncludeExclude ();
41
        
42
        BufferedReader buf = new BufferedReader (r);
43
        for (;;) {
44
            String line = buf.readLine ();
45
            if (line == null) break;
46
            
47
            line = line.trim ();
48
            if (line.length () == 0 || line.startsWith ("#")) {
49
                continue;
50
            }
51
            
52
            Boolean plus;
53
            if (line.startsWith ("include ")) {
54
                line = line.substring (8);
55
                plus = Boolean.TRUE;
56
            } else {
57
                if (line.startsWith ("exclude ")) {
58
                    line = line.substring (8);
59
                    plus = Boolean.FALSE;
60
                } else {
61
                    throw new java.io.IOException ("Wrong line: " + line);
62
                }
63
            }
64
            
65
            Pattern p = Pattern.compile (line);
66
            
67
            set.patterns.add (plus);
68
            set.patterns.add (p);
69
        }
70
        
71
        return set; 
72
    }
73
    
74
    
75
    public Iterator iterator () {
76
        return null;
77
    }
78
    
79
    public int size () {
80
        return 0;
81
    }
82
    
83
    public boolean contains (Object o) {
84
        String s = (String)o;
85
        
86
        boolean yes = false;
87
        
88
        Iterator it = patterns.iterator ();
89
        while (it.hasNext ()) {
90
            Boolean include = (Boolean)it.next ();
91
            Pattern p = (Pattern)it.next ();
92
            
93
            Matcher m = p.matcher (s);
94
            if (m.matches ()) {
95
                yes = include.booleanValue ();
96
            }
97
        }
98
        
99
        return yes;
100
    }
101
    
102
}
(-)ide/launcher/upgrade/src/org/netbeans/upgrade/copy3.6 (+58 lines)
Added Link Here
1
#                 Sun Public License Notice
2
# 
3
# The contents of this file are subject to the Sun Public License
4
# Version 1.0 (the "License"). You may not use this file except in
5
# compliance with the License. A copy of the License is available at
6
# http://www.sun.com/
7
# 
8
# The Original Code is NetBeans. The Initial Developer of the Original
9
# Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
10
# Microsystems, Inc. All Rights Reserved.
11
12
# start the line either with # to begin a comment
13
# or include to describe a file(s) to be included during copy
14
# or exclude to describe a file(s) to be excluded
15
# use of regular expressions allowed in file names 
16
#
17
# the list is iterated from first to last and the last match
18
# decides the result
19
20
include Services/org-netbeans-core-IDESettings\.settings
21
include Shortcuts/.*
22
23
include vcs/config/.*
24
include Services/Hidden/org-netbeans-modules-vcscore-settings-GeneralVcsSettings\.settings
25
26
include Services/DiffProviders/.*
27
include Services/Diffs/.*
28
include Services/DiffVisualizers/.*
29
include Services/MergeVisualizers/.*
30
include Services/Hidden/org-netbeans-modules-diff-DiffSettings\.settings
31
32
include Services/Browsers/.*
33
include Services/org-netbeans-modules-httpserver-HttpServerSettings\.settings
34
35
include HTTPMonitor/.*
36
37
include J2ee/.*
38
39
include Services/JDBCDrivers/.*
40
include Services/org-netbeans-modules-db-explorer-DatabaseOption\.settings
41
42
include Editors/.*
43
include Editors/AnnotationTypes/.*
44
include Services/org-openide-text-PrintSettings\.settings
45
include Services/IndentEngine/.*
46
47
include Services/org-netbeans-modules-java-settings-JavaSettings\.settings
48
include Services/org-openide-src-nodes-SourceOptions\.settings
49
include Templates/Classes/.* 
50
include Editors/AnnotationTypes/org-netbeans-modules-java-.*\.xml
51
52
include Services/org-netbeans-modules-beans-beans\.settings
53
include Templates/Beans/.*
54
55
include Services/JavadocSearchType/.*
56
include Services/org-netbeans-modules-javadoc-settings-DocumentationSettings\.settings
57
58
(-)ide/launcher/upgrade/test/.cvsignore (+3 lines)
Added Link Here
1
lib
2
results
3
work
(-)ide/launcher/upgrade/test/build-unit.xml (+18 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
4
                Sun Public License Notice
5
6
The contents of this file are subject to the Sun Public License
7
Version 1.0 (the "License"). You may not use this file except in
8
compliance with the License. A copy of the License is available at
9
http://www.sun.com/
10
11
The Original Code is NetBeans. The Initial Developer of the Original
12
Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
13
Microsystems, Inc. All Rights Reserved.
14
-->
15
16
<project name="ide/launcher/upgrade/test-unit" basedir="." default="all">
17
    <import file="../../../../nbbuild/templates/xtest-unit.xml"/>
18
</project>
(-)ide/launcher/upgrade/test/build.xml (+25 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
                Sun Public License Notice
4
5
The contents of this file are subject to the Sun Public License
6
Version 1.0 (the "License"). You may not use this file except in
7
compliance with the License. A copy of the License is available at
8
http://www.sun.com/
9
10
The Original Code is NetBeans. The Initial Developer of the Original
11
Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
12
Microsystems, Inc. All Rights Reserved.
13
-->
14
<project name="ide/launcher/upgrade/test" basedir="." default="all" >
15
    
16
    <!-- Name of tested module -->
17
    <property name="xtest.module" value="ide/launcher/upgrade"/>
18
    
19
    <import file="../../../../nbbuild/templates/xtest.xml"/>
20
    
21
    <!-- default testtypes, attributes used when no value is supplied from command line -->
22
    <property name="xtest.testtype" value="unit"/>
23
    <property name="xtest.attribs" value="stable"/>
24
    
25
</project>
(-)ide/launcher/upgrade/test/cfg-unit.xml (+29 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
4
                Sun Public License Notice
5
6
The contents of this file are subject to the Sun Public License
7
Version 1.0 (the "License"). You may not use this file except in
8
compliance with the License. A copy of the License is available at
9
http://www.sun.com/
10
11
The Original Code is NetBeans. The Initial Developer of the Original
12
Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
13
Microsystems, Inc. All Rights Reserved.
14
-->
15
16
<mconfig name="ide/launcher/upgrade">
17
    
18
    <testbag testattribs="stable" executor="unit-executor" name="ide/launcher/upgrade">
19
        <testset dir="unit/src">
20
            <patternset>
21
                <include name="**/*Test.class"/>
22
            </patternset>
23
        </testset>
24
    </testbag>
25
    
26
    <compiler name="default-compiler" antfile="build-unit.xml" target="default-compiler" default="true"/>
27
    <executor name="unit-executor" antfile="build-unit.xml" target="run-unit-test"/>
28
    
29
</mconfig>
(-)ide/launcher/upgrade/test/unit/src/org/netbeans/upgrade/CopyTest.java (+183 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.upgrade;
15
import java.util.*;
16
17
import org.openide.filesystems.FileObject;
18
19
import org.openide.filesystems.FileSystem;
20
21
/** Tests to check that copy of files works.
22
 *
23
 * @author Jaroslav Tulach
24
 */
25
public final class CopyTest extends org.netbeans.junit.NbTestCase {
26
    public CopyTest (String name) {
27
        super (name);
28
    }
29
    public static void main (String[] args) {
30
        junit.textui.TestRunner.run (new junit.framework.TestSuite (CopyTest.class));
31
    }
32
    
33
    protected void setUp() throws java.lang.Exception {
34
        super.setUp();
35
        
36
        org.openide.filesystems.TestUtilHid.destroyLocalFileSystem(getName ());
37
    }    
38
    
39
    public void testDoesSomeCopy () throws Exception {
40
        FileSystem fs = org.openide.filesystems.TestUtilHid.createLocalFileSystem (getName (), new String[] {
41
            "root/X.txt", 
42
            "root/Y.txt",
43
            "nonroot/Z.txt"
44
        });
45
        
46
        FileObject fo = fs.findResource ("root");
47
        FileObject tg = fs.getRoot().createFolder ("target");
48
        
49
        java.util.HashSet set = new java.util.HashSet ();
50
        set.add ("X.txt");
51
          Copy.copyDeep (fo, tg, set);
52
53
        assertEquals ("One file copied", 1, tg.getChildren().length);
54
        String n = tg.getChildren ()[0].getNameExt();
55
        assertEquals ("Name is X.txt", "X.txt", n);
56
        
57
    }
58
    
59
    public void testDoesDeepCopy () throws Exception {
60
        FileSystem fs = org.openide.filesystems.TestUtilHid.createLocalFileSystem (getName (), new String[] {
61
            "root/subdir/X.txt", 
62
            "root/Y.txt",
63
            "nonroot/Z.txt"
64
        });
65
        
66
        FileObject fo = fs.findResource ("root");
67
        FileObject tg = fs.getRoot().createFolder ("target");
68
        
69
        java.util.HashSet set = new java.util.HashSet ();
70
        set.add ("subdir/X.txt");
71
        Copy.copyDeep (fo, tg, set);
72
        
73
        assertEquals ("One file copied", 1, tg.getChildren().length);
74
        assertEquals ("Name is X.txt", "subdir", tg.getChildren ()[0].getNameExt());
75
        assertEquals ("One children of one child", 1, tg.getChildren()[0].getChildren().length);
76
        assertEquals ("X.txt", "X.txt", tg.getChildren()[0].getChildren()[0].getNameExt());
77
        
78
    }
79
    
80
    public void testCopyAttributes () throws Exception {
81
        FileSystem fs = org.openide.filesystems.TestUtilHid.createLocalFileSystem (getName (), new String[] {
82
            "root/X.txt", 
83
            "root/Y.txt",
84
            "nonroot/Z.txt"
85
        });
86
        FileObject x = fs.findResource ("root/X.txt");
87
        x.setAttribute ("ahoj", "yarda");
88
        
89
        FileObject fo = fs.findResource ("root");
90
        FileObject tg = fs.getRoot().createFolder ("target");
91
        
92
        java.util.HashSet set = new java.util.HashSet ();
93
        set.add ("X.txt");
94
        Copy.copyDeep (fo, tg, set);
95
        
96
        assertEquals ("One file copied", 1, tg.getChildren().length);
97
        assertEquals ("Name is X.txt", "X.txt", tg.getChildren ()[0].getNameExt());
98
        assertEquals ("attribute copied", "yarda", tg.getChildren()[0].getAttribute("ahoj"));
99
    }
100
    
101
    public void testCopyFolderAttributes () throws Exception {
102
        FileSystem fs = org.openide.filesystems.TestUtilHid.createLocalFileSystem (getName (), new String[] {
103
            "root/sub/X.txt", 
104
            "root/Y.txt",
105
            "nonroot/Z.txt"
106
        });
107
        FileObject x = fs.findResource ("root/sub");
108
        x.setAttribute ("ahoj", "yarda");
109
        
110
        FileObject fo = fs.findResource ("root");
111
        FileObject tg = fs.getRoot().createFolder ("target");
112
        
113
        java.util.HashSet set = new java.util.HashSet ();
114
        set.add ("sub");
115
        set.add ("sub/X.txt");
116
        Copy.copyDeep (fo, tg, set);
117
        
118
        assertEquals ("One file copied", 1, tg.getChildren().length);
119
        assertEquals ("Name of the dir is sub", "sub", tg.getChildren ()[0].getNameExt());
120
        assertEquals ("attribute copied", "yarda", tg.getChildren()[0].getAttribute("ahoj"));
121
        assertEquals ("X.txt", "X.txt", tg.getChildren()[0].getChildren()[0].getNameExt());
122
    }
123
    
124
    public void testDoNotCopyEmptyDirs () throws Exception {
125
        FileSystem fs = org.openide.filesystems.TestUtilHid.createLocalFileSystem (getName (), new String[] {
126
            "root/sub/X.txt", 
127
            "root/Y.txt",
128
            "nonroot/Z.txt"
129
        });
130
        FileObject x = fs.findResource ("root/sub");
131
        
132
        FileObject fo = fs.findResource ("root");
133
        FileObject tg = fs.getRoot().createFolder ("target");
134
        
135
        java.util.HashSet set = new java.util.HashSet ();
136
        Copy.copyDeep (fo, tg, set);
137
        
138
        assertEquals ("Nothing copied", 0, tg.getChildren().length);
139
    }
140
    
141
    public void testDoNotOverwriteFiles () throws Exception {
142
        java.util.HashSet set = new java.util.HashSet ();
143
        set.add ("X.txt");
144
        
145
        FileSystem fs = org.openide.filesystems.TestUtilHid.createLocalFileSystem (getName (), new String[] {
146
            "root/project/X.txt", 
147
            "root/X.txt",
148
            "nonroot/Z.txt"
149
        });
150
        
151
        writeTo (fs, "root/project/X.txt", "content-project");
152
        writeTo (fs, "root/X.txt", "content-global");
153
154
        FileObject tg = fs.getRoot().createFolder ("target");
155
        
156
        FileObject project = fs.findResource ("root/project");
157
        Copy.copyDeep (project, tg, set);
158
        
159
        
160
        
161
        FileObject root = fs.findResource ("root");
162
        Copy.copyDeep (root, tg, set);
163
164
        
165
        FileObject x = tg.getFileObject ("X.txt");
166
        assertNotNull ("File copied", x);
167
        
168
        byte[] arr = new byte[300];
169
        int len = x.getInputStream ().read (arr);
170
        String content = new String (arr, 0, len);
171
        
172
        assertEquals ("The content is kept from project", content, "content-project");
173
    }
174
    
175
    private static void writeTo (FileSystem fs, String res, String content) throws java.io.IOException {
176
        FileObject fo = org.openide.filesystems.FileUtil.createData (fs.getRoot (), res);
177
        org.openide.filesystems.FileLock lock = fo.lock ();
178
        java.io.OutputStream os = fo.getOutputStream (lock);
179
        os.write (content.getBytes ());
180
        os.close ();
181
        lock.releaseLock ();
182
    }
183
 }
(-)ide/launcher/upgrade/test/unit/src/org/netbeans/upgrade/IncludeExcludeTest.java (+71 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.upgrade;
15
16
import java.util.*;
17
18
/** Tests to check that copy of files works.
19
 *
20
 * @author Jaroslav Tulach
21
 */
22
public final class IncludeExcludeTest extends org.netbeans.junit.NbTestCase {
23
    private Set includeExclude;
24
    
25
    public IncludeExcludeTest (String name) {
26
        super (name);
27
    }
28
    public static void main (String[] args) {
29
        junit.textui.TestRunner.run (new junit.framework.TestSuite (IncludeExcludeTest.class));
30
    }
31
    
32
    protected void setUp() throws java.lang.Exception {
33
        super.setUp();
34
35
        String reader = "# ignore comment\n" +
36
        "include one/file.txt\n" +
37
        "include two/dir/.*\n" +
38
        "\n" +
39
        "exclude two/dir/sub/.*\n";
40
        
41
        includeExclude = IncludeExclude.create (new java.io.StringReader (reader));
42
    }    
43
44
    public void testOneFileIsThere () {
45
        assertTrue (includeExclude.contains ("one/file.txt"));
46
    }
47
    
48
    public void testDoesNotContainRoot () {
49
        assertFalse (includeExclude.contains (""));
50
    }
51
    
52
    public void testContainsSomethingInDir () {
53
        assertTrue (includeExclude.contains ("two/dir/a.file"));
54
    }
55
    
56
    public void testContainsSomethingUnderTheDir () {
57
        assertTrue (includeExclude.contains ("two/dir/some/folder/a.file"));
58
    }
59
    
60
    public void testDoesNotContainSubDir () {
61
        assertFalse (includeExclude.contains ("two/dir/sub/not.there"));
62
    }
63
    
64
    public void testWrongContentDetected () {
65
        try {
66
            IncludeExclude.create (new java.io.StringReader ("some strange line"));
67
            fail ("Should throw exception");
68
        } catch (java.io.IOException ex) {
69
        }
70
    }
71
 }
(-)ide/launcher/windows/netbeans.cpp (-1 / +1 lines)
Lines 151-157 Link Here
151
        }
151
        }
152
    }
152
    }
153
    sprintf(nbexec, "%s\\platform4\\launcher\\nbexec.exe", topdir);
153
    sprintf(nbexec, "%s\\platform4\\launcher\\nbexec.exe", topdir);
154
    sprintf(cmdline2, "\"%s\" %s --branding nb --clusters \"%s\" --userdir \"%s\" %s %s",
154
    sprintf(cmdline2, "\"%s\" %s -J-Dnetbeans.importclass=org.netbeans.upgrade.AutoUpgrade --branding nb --clusters \"%s\" --userdir \"%s\" %s %s",
155
            nbexec,
155
            nbexec,
156
            jdkswitch,
156
            jdkswitch,
157
            dirs,
157
            dirs,

Return to bug 41265