Index: nbbuild/build.xml =================================================================== RCS file: /cvs/nbbuild/build.xml,v retrieving revision 1.507 diff -u -r1.507 build.xml --- nbbuild/build.xml 3 Jun 2004 20:55:06 -0000 1.507 +++ nbbuild/build.xml 4 Jun 2004 16:59:22 -0000 @@ -1101,6 +1101,11 @@ + + + + + Index: nbbuild/cluster.properties =================================================================== RCS file: /cvs/nbbuild/cluster.properties,v retrieving revision 1.43 diff -u -r1.43 cluster.properties --- nbbuild/cluster.properties 3 Jun 2004 20:55:08 -0000 1.43 +++ nbbuild/cluster.properties 4 Jun 2004 16:59:22 -0000 @@ -172,6 +172,7 @@ ide/branding \ ide/updatecenters, \ ide/welcome, \ + ide/launcher/upgrade, \ tomcatint/tomcat5/bundled nb.pkg.test.dir=test Index: core/arch/arch-core-launcher.xml =================================================================== RCS file: /cvs/core/arch/arch-core-launcher.xml,v retrieving revision 1.20 diff -u -r1.20 arch-core-launcher.xml --- core/arch/arch-core-launcher.xml 3 Jun 2004 13:30:19 -0000 1.20 +++ core/arch/arch-core-launcher.xml 4 Jun 2004 16:59:34 -0000 @@ -344,8 +344,6 @@ After creating bootstrap classpath another low level set of JARs is loaded with a new classloader from core/*.jar directories in each clusters. -

- @@ -502,6 +500,29 @@ from the default package is supressed. +

  • + + There is a special support for importing the settings from previous + versions. As only the product itself knows about what to import and + where this cannot be done directly in the launcher, but we need at + a well defined moment (user directory is missing and no modules + have been initialized yet) to call the product to ask the user + and do the actual copy of userdir. +

    + After all core/*.jar files has been initialized + and the user dir has not yet been updated (see bellow) the + launcher checks for value of netbeans.importclass + system property and if provided it loads that class and invokes + its main method (in AWT thread) and if no exception is thrown it + marks the userdir as already upgraded. + . + + This is used to identify whether a userdir has already been updated + or it still needs an update. Can be created by installer if no update + check should be performed, no other code is supposed to realy on + this file. + +

  • Additionally, the launcher in cooperation with the core makes all Index: core/src/org/netbeans/core/NonGui.java =================================================================== RCS file: /cvs/core/src/org/netbeans/core/NonGui.java,v retrieving revision 1.111 diff -u -r1.111 NonGui.java --- core/src/org/netbeans/core/NonGui.java 30 Apr 2004 04:09:26 -0000 1.111 +++ core/src/org/netbeans/core/NonGui.java 4 Jun 2004 16:59:35 -0000 @@ -86,6 +86,13 @@ /** The Class that logs the IDE events to a log file */ protected static TopLogging logger; + + /** Tests need to clear some static variables. + */ + static final void clearForTests () { + homeDir = null; + userDir = null; + } /** Getter for home directory. */ protected static String getHomeDir () { @@ -194,6 +201,87 @@ StartLog.logProgress ("PropertyEditors registered"); // NOI18N editorsRegistered = true; } + + /** Does import of userdir. Made non-private just for testing purposes. + * + * @return true if the execution should continue or false if it should + * stop + */ + static boolean handleImportOfUserDir () { + class ImportHandler implements Runnable { + private File installed = new File (new File (getUserDir (), "var"), "imported"); // NOI18N + private String classname; + private boolean executedOk; + + public boolean shouldDoAnImport () { + classname = System.getProperty ("netbeans.importclass"); // NOI18N + + return classname != null && !installed.exists (); + } + + + public void run() { + Class clazz = getKlass (classname); + + // This module is included in our distro somewhere... may or may not be turned on. + // Whatever - try running some classes from it anyway. + try { + // Method showMethod = wizardClass.getMethod( "handleUpgrade", new Class[] { Splash.SplashOutput.class } ); // NOI18N + Method showMethod = clazz.getMethod( "main", new Class[] { String[].class } ); // NOI18N + showMethod.invoke (null, new Object[] { + new String[0] + }); + executedOk = true; + } catch (java.lang.reflect.InvocationTargetException ex) { + // canceled by user, all is fine + if (ex.getTargetException () instanceof org.openide.util.UserCancelException) { + executedOk = true; + } + } catch (Exception e) { + // If exceptions are thrown, notify them - something is broken. + e.printStackTrace(); + } catch (LinkageError e) { + // These too... + e.printStackTrace(); + } + } + + + public boolean canContinue () { + if (shouldDoAnImport ()) { + try { + SwingUtilities.invokeAndWait (this); + if (executedOk) { + // if the import went fine, then we are fine + // just create the file + installed.getParentFile ().mkdirs (); + installed.createNewFile (); + return true; + } else { + return false; + } + } catch (IOException ex) { + // file was not created a bit of problem but go on + ex.printStackTrace(); + return true; + } catch (java.lang.reflect.InvocationTargetException ex) { + return false; + } catch (InterruptedException ex) { + ex.printStackTrace(); + return false; + } + } else { + // if there is no need to upgrade that every thing is good + return true; + } + } + } + + + ImportHandler handler = new ImportHandler (); + + return handler.canContinue (); + } /** Initialization of the manager. */ @@ -245,52 +333,9 @@ } if ((System.getProperty ("netbeans.full.hack") == null) && (System.getProperty ("netbeans.close") == null) && !dontshowisw) { - System.setProperty("import.canceled", "false"); // NOI18N - - - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - // Original code - //boolean canceled = org.netbeans.core.upgrade.UpgradeWizard.showWizard(getSplash()); - //System.setProperty("import.canceled", canceled ? "true" : "false"); // NOI18N - - // Let's use reflection - InstalledFileLocator ifl = new InstalledFileLocatorImpl(); - File coreide = ifl.locate("modules/org-netbeans-core-ide.jar", "org.netbeans.core.ide", false); // NOI18N - if (coreide != null) { - // This module is included in our distro somewhere... may or may not be turned on. - // Whatever - try running some classes from it anyway. - try { - List urls = new ArrayList(); - urls.add(coreide.toURI().toURL()); - // #30502: don't forget locale variants! - Iterator it = NbBundle.getLocalizingSuffixes(); - while (it.hasNext()) { - String suffix = (String)it.next(); - File var = ifl.locate("modules/locale/org-netbeans-core-ide" + suffix + ".jar", "org.netbeans.core.ide", false); // NOI18N - if (var != null) { - urls.add(var.toURI().toURL()); - } - } - ClassLoader l = new URLClassLoader((URL[])urls.toArray(new URL[urls.size()]), NonGui.class.getClassLoader()); - Class wizardClass = Class.forName("org.netbeans.core.upgrade.AutoUpgrade", true, l); // NOI18N - Method showMethod = wizardClass.getMethod( "handleUpgrade", new Class[] { Splash.SplashOutput.class } ); // NOI18N - - Boolean canceled = (Boolean)showMethod.invoke( null, new Object[] { getSplash() } ); - System.setProperty("import.canceled", canceled.toString()); // NOI18N - } catch (Exception e) { - // If exceptions are thrown, notify them - something is broken. - e.printStackTrace(); - } catch (LinkageError e) { - // These too... - e.printStackTrace(); - } - } - - } - }); - if (Boolean.getBoolean("import.canceled")) + if (!handleImportOfUserDir ()) { TopSecurityManager.exit(0); + } } } catch (Exception e) { ErrorManager.getDefault().notify(e); Index: core/test/unit/src/org/netbeans/core/NonGuiHandleImportOfUserDirTest.java =================================================================== RCS file: core/test/unit/src/org/netbeans/core/NonGuiHandleImportOfUserDirTest.java diff -N core/test/unit/src/org/netbeans/core/NonGuiHandleImportOfUserDirTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ core/test/unit/src/org/netbeans/core/NonGuiHandleImportOfUserDirTest.java 4 Jun 2004 16:59:42 -0000 @@ -0,0 +1,109 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.core; + +import java.io.File; +import java.util.Enumeration; +import java.util.MissingResourceException; +import java.util.Properties; +import java.util.ResourceBundle; +import java.util.StringTokenizer; +import junit.framework.*; +import org.netbeans.junit.*; + +/** Tests the behaviour of the import user dir "api". + */ +public class NonGuiHandleImportOfUserDirTest extends NbTestCase { + private static NonGuiHandleImportOfUserDirTest instance; + + private File user; + private boolean updaterInvoked; + private Throwable toThrow; + + + public static void main(java.lang.String[] args) throws Throwable { + if (instance != null) { + // ok this is invoked from the test by the core-launcher + instance.nowDoTheInstall (); + return; + } else { + // initial start + junit.textui.TestRunner.run(new junit.framework.TestSuite (NonGuiHandleImportOfUserDirTest.class)); + } + } + public NonGuiHandleImportOfUserDirTest (String name) { + super(name); + } + + protected void setUp () throws Exception { + clearWorkDir (); + NonGui.clearForTests (); + + File home = new File (getWorkDir (), "home"); + user = new File (getWorkDir (), "user"); + + assertTrue ("Home dir created", home.mkdirs ()); + assertTrue ("User dir created", user.mkdirs ()); + + System.setProperty ("netbeans.home", home.toString ()); + System.setProperty ("netbeans.user", user.toString ()); + + System.setProperty ("netbeans.importclass", NonGuiHandleImportOfUserDirTest.class.getName ()); + + instance = this; + } + + protected void tearDown () throws Exception { + instance = null; + } + + + private void nowDoTheInstall () throws Throwable { + assertTrue ("Called from AWT thread", javax.swing.SwingUtilities.isEventDispatchThread ()); + if (toThrow != null) { + Throwable t = toThrow; + toThrow = null; + throw t; + } + + updaterInvoked = true; + } + + public void testIfTheUserDirIsEmptyTheUpdaterIsInvoked () { + assertTrue ("Ok, returns without problems", NonGui.handleImportOfUserDir ()); + assertTrue ("the main method invoked", updaterInvoked); + + toThrow = new RuntimeException (); + + assertTrue ("The install is not called anymore 1", NonGui.handleImportOfUserDir ()); + assertTrue ("The install is not called anymore 2", NonGui.handleImportOfUserDir ()); + assertTrue ("The install is not called anymore 3", NonGui.handleImportOfUserDir ()); + assertTrue ("The install is not called anymore 4", NonGui.handleImportOfUserDir ()); + } + + public void testIfInvokedAndThrowsExceptionTheExecutionStops () { + toThrow = new RuntimeException (); + + assertFalse ("Says no as exception was thrown", NonGui.handleImportOfUserDir ()); + assertNull ("Justs to be sure the exception was cleared", toThrow); + } + + public void testIfThrowsUserCancelExThenUpdateIsFinished () { + toThrow = new org.openide.util.UserCancelException (); + + assertTrue ("Says yes as user canceled the import", NonGui.handleImportOfUserDir ()); + assertNull ("Justs to be sure the exception was cleared", toThrow); + + assertTrue ("The install is not called anymore 1", NonGui.handleImportOfUserDir ()); + } +} Index: ide/launcher/os2/netbeans.cmd =================================================================== RCS file: /cvs/ide/launcher/os2/netbeans.cmd,v retrieving revision 1.2 diff -u -r1.2 netbeans.cmd --- ide/launcher/os2/netbeans.cmd 2 Jun 2004 08:05:17 -0000 1.2 +++ ide/launcher/os2/netbeans.cmd 4 Jun 2004 16:59:42 -0000 @@ -35,7 +35,7 @@ platdir = directory(progdir||"\platform4\launcher") -__launcher = 'call "'||platdir||'\nbexec.cmd" ("--branding nb --clusters '||netbeans_clusters||' '||nb_args||'")' +__launcher = 'call "'||platdir||'\nbexec.cmd" ("-J-Dnetbeans.importclass=org.netbeans.upgrade.AutoUpgrade --branding nb --clusters '||netbeans_clusters||' '||nb_args||'")' interpret __launcher exit rc Index: ide/launcher/unix/netbeans =================================================================== RCS file: /cvs/ide/launcher/unix/netbeans,v retrieving revision 1.5 diff -u -r1.5 netbeans --- ide/launcher/unix/netbeans 22 May 2004 16:11:06 -0000 1.5 +++ ide/launcher/unix/netbeans 4 Jun 2004 16:59:42 -0000 @@ -53,5 +53,6 @@ --branding nb \ --clusters "$netbeans_clusters" \ --userdir "${netbeans_default_userdir}" \ + -J-Dnetbeans.importclass=org.netbeans.upgrade.AutoUpgrade \ ${netbeans_default_options} \ "$@" Index: ide/launcher/upgrade/.cvsignore =================================================================== RCS file: ide/launcher/upgrade/.cvsignore diff -N ide/launcher/upgrade/.cvsignore --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/.cvsignore 4 Jun 2004 16:59:42 -0000 @@ -0,0 +1 @@ +build Index: ide/launcher/upgrade/build.xml =================================================================== RCS file: ide/launcher/upgrade/build.xml diff -N ide/launcher/upgrade/build.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/build.xml 4 Jun 2004 16:59:42 -0000 @@ -0,0 +1,19 @@ + + + + + + + + Index: ide/launcher/upgrade/manifest.mf =================================================================== RCS file: ide/launcher/upgrade/manifest.mf diff -N ide/launcher/upgrade/manifest.mf --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/manifest.mf 4 Jun 2004 16:59:42 -0000 @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +OpenIDE-Module: org.netbeans.upgrader +OpenIDE-Module-Specification-Version: 4.0 +_OpenIDE-Module-Localizing-Bundle: org/openide/io/Bundle.properties + Index: ide/launcher/upgrade/nbproject/project.properties =================================================================== RCS file: ide/launcher/upgrade/nbproject/project.properties diff -N ide/launcher/upgrade/nbproject/project.properties --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/nbproject/project.properties 4 Jun 2004 16:59:42 -0000 @@ -0,0 +1,16 @@ +# Sun Public License Notice +# +# The contents of this file are subject to the Sun Public License +# Version 1.0 (the "License"). You may not use this file except in +# compliance with the License. A copy of the License is available at +# http://www.sun.com/ +# +# The Original Code is NetBeans. The Initial Developer of the Original +# Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun +# Microsystems, Inc. All Rights Reserved. + +module.jar.dir=core +test.unit.cp.extra=${nb_all}/openide/test/unit/src:\ + ${nb_all}/openide/build/test/unit/classes:\ + ${nb_all}/ide/launcher/upgrade/src + Index: ide/launcher/upgrade/nbproject/project.xml =================================================================== RCS file: ide/launcher/upgrade/nbproject/project.xml diff -N ide/launcher/upgrade/nbproject/project.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/nbproject/project.xml 4 Jun 2004 16:59:42 -0000 @@ -0,0 +1,36 @@ + + + + org.netbeans.modules.apisupport.project + org.netbeans.upgrade + + + ide/launcher/upgrade + + + org.openide + + + + 1 + 4.0 + + + + + + + + + Index: ide/launcher/upgrade/src/org/netbeans/upgrade/AutoUpgrade.java =================================================================== RCS file: ide/launcher/upgrade/src/org/netbeans/upgrade/AutoUpgrade.java diff -N ide/launcher/upgrade/src/org/netbeans/upgrade/AutoUpgrade.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/src/org/netbeans/upgrade/AutoUpgrade.java 4 Jun 2004 16:59:42 -0000 @@ -0,0 +1,167 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.upgrade; + +import java.awt.Dialog; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.*; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.ErrorManager; +import org.openide.NotifyDescriptor; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.LocalFileSystem; +import org.openide.filesystems.Repository; +import org.openide.util.NbBundle; + +/** pending + * + * @author Jiri Rechtacek + */ +public final class AutoUpgrade { + + /** Shows the import dialog if there is no folder under the Projects + * subfolder of system default filesystem. This condition is met during + * the first start only. + * + * @return true when and only when the dialog was displayed and user has canceled it, + * false otherwise (upgrade is done or not needed). + */ + //public static boolean handleUpgrade (SplashOutput splash) { + + public static void main (String[] args) throws Exception { + String[] version = new String[1]; + File sourceFolder = checkPrevious (version); + if (sourceFolder != null) { + if (!showUpgradeDialog (sourceFolder)) { + throw new org.openide.util.UserCancelException (); + } + doUpgrade (sourceFolder, version[0]); + } + } + + // XXX: the versions will be read from properties files to allow branding + final static private List VERSION_TO_CHECK = Arrays.asList (new String[] { "3.6" }); + final static private String USER_DIR_PREFIX = ".netbeans"; // NOI18N + + static private File checkPrevious (String[] version) { + boolean exists; + + String userHome = System.getProperty ("user.home"); // NOI18N + File sourceFolder = null; + + if (userHome != null) { + File userHomeFile = new File (userHome); + exists = userHomeFile.isDirectory (); + + Iterator it = VERSION_TO_CHECK.iterator (); + String ver; + while (it.hasNext () && sourceFolder == null) { + ver = (String) it.next (); + sourceFolder = new File ( + new File (userHomeFile.getAbsolutePath (), USER_DIR_PREFIX), + ver + ); + + if (sourceFolder.isDirectory ()) { + version[0] = ver; + break; + } + sourceFolder = null; + } + return sourceFolder; + } else { + return null; + } + } + + private static boolean showUpgradeDialog (final File source) { + /* + if (splash != null) { + Splash.hideSplash (splash); + } + */ + + DialogDescriptor dd = new DialogDescriptor ( + new AutoUpgradePanel (source.getAbsolutePath ()), + NbBundle.getMessage (AutoUpgrade.class, "MSG_Confirmation_Title"), // NOI18N + true, + NotifyDescriptor.YES_NO_OPTION, + NotifyDescriptor.NO_OPTION, + null + ); + + + Dialog dlg = DialogDisplayer.getDefault ().createDialog (dd); + dlg.show (); + + return dd.getValue () == NotifyDescriptor.YES_OPTION; + } + + private static void doUpgrade (File source, String oldVersion) + throws java.io.IOException, java.beans.PropertyVetoException { + + + if ("3.6".equals (oldVersion)) { + File userdir = new File(System.getProperty ("netbeans.user", "")); // NOI18N + + Reader r = new InputStreamReader ( + AutoUpgrade.class.getResourceAsStream ("copy3.6"), // NOI18N + "utf-8" + ); + java.util.Set includeExclude = IncludeExclude.create (r); + r.close (); + + + ErrorManager.getDefault ().log ( + ErrorManager.USER, "Import: Old version: " // NOI18N + + oldVersion + ". Importing from " + source + " to " + userdir // NOI18N + ); + + File oldConfig = new File (source, "system"); // NOI18N + LocalFileSystem old = new LocalFileSystem (); + old.setRootDirectory (oldConfig); + org.openide.filesystems.FileSystem mine = Repository.getDefault ().getDefaultFileSystem (); + + FileObject defaultProject = old.findResource ("Projects/Default/"); // NOI18N + if (defaultProject != null) { + // first copy content from default project + Copy.copyDeep (defaultProject, mine.getRoot (), includeExclude); + } + + FileObject projects = old.findResource ("Projects"); // NOI18N + if (projects != null) { + FileObject[] allProjects = projects.getChildren (); + for (int i = 0; i < allProjects.length; i++) { + // content from projects is prefered + Copy.copyDeep (allProjects[i], mine.getRoot (), includeExclude); + } + } + + + Copy.copyDeep (old.getRoot (), mine.getRoot (), includeExclude); + return; + } + + throw new IOException ("Cannot import from version: " + oldVersion); + } +} Index: ide/launcher/upgrade/src/org/netbeans/upgrade/AutoUpgradePanel.form =================================================================== RCS file: ide/launcher/upgrade/src/org/netbeans/upgrade/AutoUpgradePanel.form diff -N ide/launcher/upgrade/src/org/netbeans/upgrade/AutoUpgradePanel.form --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/src/org/netbeans/upgrade/AutoUpgradePanel.form 4 Jun 2004 16:59:42 -0000 @@ -0,0 +1,47 @@ + + +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: ide/launcher/upgrade/src/org/netbeans/upgrade/AutoUpgradePanel.java =================================================================== RCS file: ide/launcher/upgrade/src/org/netbeans/upgrade/AutoUpgradePanel.java diff -N ide/launcher/upgrade/src/org/netbeans/upgrade/AutoUpgradePanel.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/src/org/netbeans/upgrade/AutoUpgradePanel.java 4 Jun 2004 16:59:42 -0000 @@ -0,0 +1,117 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.upgrade; + +import java.awt.Dialog; +import java.util.ArrayList; +import java.util.ResourceBundle; +import javax.swing.JPanel; +import javax.swing.event.ChangeListener; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.util.NbBundle; + + +/** + * @author Jiri Rechtacek + */ +final class AutoUpgradePanel extends JPanel { + + public static void main(String args[]) { + // display dialog + DialogDescriptor descriptor = new DialogDescriptor ( + new AutoUpgradePanel(""), // NOI18N + bundle.getString("MSG_Confirmation_Title") // NOI18N + ); + Dialog dialog = DialogDisplayer.getDefault().createDialog(descriptor); + dialog.show(); + dialog.dispose(); + } + + String source; + + /** Creates new form UpgradePanel */ + public AutoUpgradePanel (String directory) { + this.source = directory; + initComponents(); + initAccessibility(); + + } + + /** Remove a listener to changes of the panel's validity. + * @param l the listener to remove + */ + void removeChangeListener(ChangeListener l) { + changeListeners.remove(l); + } + + /** Add a listener to changes of the panel's validity. + * @param l the listener to add + * @see #isValid + */ + void addChangeListener(ChangeListener l) { + if (!changeListeners.contains(l)) { + changeListeners.add(l); + } + } + + private void initAccessibility() { + this.getAccessibleContext().setAccessibleDescription(bundle.getString("MSG_Confirmation")); // NOI18N + } + + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + private void initComponents() {//GEN-BEGIN:initComponents + java.awt.GridBagConstraints gridBagConstraints; + + txtVersions = new javax.swing.JTextArea(); + + setLayout(new java.awt.GridBagLayout()); + + setMaximumSize(new java.awt.Dimension(123456, 123456)); + setMinimumSize(new java.awt.Dimension(500, 279)); + setName(bundle.getString("LBL_UpgradePanel_Name")); + txtVersions.setColumns(50); + txtVersions.setLineWrap(true); + txtVersions.setRows(3); + txtVersions.setText(NbBundle.getMessage (AutoUpgradePanel.class, "MSG_Confirmation", source)); + txtVersions.setWrapStyleWord(true); + txtVersions.setDisabledTextColor(new java.awt.Color(0, 0, 0)); + txtVersions.setDoubleBuffered(true); + txtVersions.setMinimumSize(new java.awt.Dimension(100, 50)); + txtVersions.setEnabled(false); + txtVersions.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE; + gridBagConstraints.gridheight = java.awt.GridBagConstraints.RELATIVE; + gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); + gridBagConstraints.weightx = 1.0; + gridBagConstraints.weighty = 1.0; + add(txtVersions, gridBagConstraints); + + }//GEN-END:initComponents + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JTextArea txtVersions; + // End of variables declaration//GEN-END:variables + + private static final ResourceBundle bundle = NbBundle.getBundle(AutoUpgradePanel.class); + private ArrayList changeListeners = new ArrayList(1); + +} Index: ide/launcher/upgrade/src/org/netbeans/upgrade/Bundle.properties =================================================================== RCS file: ide/launcher/upgrade/src/org/netbeans/upgrade/Bundle.properties diff -N ide/launcher/upgrade/src/org/netbeans/upgrade/Bundle.properties --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/src/org/netbeans/upgrade/Bundle.properties 4 Jun 2004 16:59:42 -0000 @@ -0,0 +1,108 @@ +# Sun Public License Notice +# +# The contents of this file are subject to the Sun Public License +# Version 1.0 (the "License"). You may not use this file except in +# compliance with the License. A copy of the License is available at +# http://www.sun.com/ +# +# The Original Code is NetBeans. The Initial Developer of the Original +# Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun +# Microsystems, Inc. All Rights Reserved. + +MSG_NO_BACKUP_EMPTY=Backup directory is not empty. +MSG_NO_BACKUP_CREATED=Backup directory has not been created. +CTL_README=README.html +MSG_NOT_FOUNDED= File {0} not found. +MSG_IS_NOT_FOLDER={0} is not a folder. +MSG_BACKUP_EXISTS=Backup directory does not exist. +MSG_UPDATE_FROM=Import from {0} +MSG_BAD_IDE=Source IDE must be one of these versions: +MSG_TITLE=Update IDE Environments From Old Releases +MSG_COMMAND_LINE="{0} " +LBL_lblVersion=Version: +MSG_BackupDir_exists=Backup directory {0} already exists. + +LBL_Upgrade_Description_Top=Enter the location of your previous IDE's user directory in the Previous IDE field. \n\ +\n\ +The default location for IDE settings is: +LBL_Upgrade_Description_Versions=Microsoft Windows systems:\n\ +\ NetBeans 3.5.x software - /.netbeans/3.5\n\ +\ NetBeans 3.4.x software - /.netbeans/3.4\n\ +\ NetBeans 3.3.x software and earlier editions - user-specified directory\n\ +UNIX systems:\n\ +\ NetBeans 3.5.x software - /.netbeans/3.5\n\ +\ NetBeans 3.4.x software - /.netbeans/3.4\n\ +\ NetBeans 3.3.x software - /nbuser33\n\ +\ NetBeans 3.2.x software - /nbuser32\n\ +\ NetBeans software (3.0 and 3.1 releases) - IDE installation directory\n\ +\ Forte For Java software (3.0 and 4.0 releases) - /nbuser\n\ +\ Forte For Java, release 2.0, software - IDE installation directory\n\ +\ Sun ONE Studio 4 update 1 Community Edition software - /ffjuser40ce +LBL_Upgrade_Description_Note=Note: If you cannot locate your previous IDE's user directory,\ +\ open your previous IDE and choose About from the Help menu.\ +\ The user directory location is listed under User Dir in the Details tab. + + +MSG_Upgrade_Succeeded=Settings imported successfully. +MSG_Upgrade_Failed=The import procedure has failed. +MSG_Upgrade_Finished=Done. +MSG_Upgrade_Started=Importing ... +LBL_lblUpgradeStatus=Import Settings Status: +LBL_cmdSelectDir=Browse... +LBL_cmdSelectDir_Mnem=r +LBL_UpgradeWizard_Title=Settings Import Wizard +MSG_SplashScreen_status=Importing old settings ... +BTN_Exit_IDE=Exit IDE +BTN_Exit_IDE_Mnem=E +BTN_Start_IDE=Start IDE +BTN_Start_IDE_Mnem=S +BTN_Import=Import +BTN_Import_Mnem=I +LBL_lblSelection=Do you wish to import settings from a previous installation? +LBL_PreUpgradePanel_Name=Do you need to import settings? +LBL_rbUpgrade=\ Yes, please import my settings from the previous version. +LBL_rbDontUpgrade=\ No, skip the settings import. +LBL_PreUpgradeText_Bottom=Note: It is not possible to import settings at a later time. + +LBL_PreUpgradeText_Top=This wizard lets you import your IDE environment and settings from previous versions of the IDE. + +MSG_recovery_finished=System recovered successfully. +MSG_recovery_started=Import failed, recovery started. +LBL_TransferSettingsPanel_Name=Import Settings +LBL_UpgradePanel_Name=Locate Previous IDE +LBL_lblLocation=Previous IDE: +LBL_lblLocation_Mnem=P +MSG_Old_IDE_Location_Invalid=You did not select a valid IDE directory or the version of the IDE is unknown. +LBL_SelectDir_Dialog_Title=Select Previous IDE Location +LBL_Open_Button=Open +CTL_UNIX_SCRIPT=import.sh +CTL_WINDOWS_SCRIPT=import.bat +LBL_rbDontUpgrade_Mnemonic=N +LBL_rbUpgrade_Mnemonic=Y +ACS_rbDontUpgrade=N/A +ACS_rbUpgrade=N/A +ACS_txtUpgrade2_Bottom_Name=Result status +ACS_txtUpgrade2_Bottom_Desc=Status of IDE settings import. +ACS_txtLocation=N/A +ACS_txtVersion=N/A +ACS_cmdSelectDir=N/A +ACS_TransferSettingsPanel=Import settings status + +MSG_directory_not_exist=Directory {0} can not be found or mounted. + +# NewUserPanel +NU_LBL_Label=Were any of these IDEs previously installed on this system? +NU_BTN_Yes=Yes, other versions of the IDE were installed on this system +NU_BTN_Yes_Mnem=Y +NU_BTN_No=No, none of the above versions were previously installed on this system +NU_BTN_No_Mnem=N +NU_LBL_Versions=NetBeans software (3.5.x, 3.4.x, 3.3.x, 3.2.x, 3.1 or 3.0 releases)\n\ +Forte for Java software (4.0, 3.0 or 2.0 releases)\n\ +Sun ONE Studio 4 update 1 software +NU_MSG_Title=Are you a returning user? +ACS_BTN_Yes=N/A +ACS_BTN_No=N/A + +#AutoUpgdare dialog +MSG_Confirmation = Settings created by a previous version of the IDE were found on your system at {0}. Do you want to import them? +MSG_Confirmation_Title = Confirm Import Settings Index: ide/launcher/upgrade/src/org/netbeans/upgrade/Copy.java =================================================================== RCS file: ide/launcher/upgrade/src/org/netbeans/upgrade/Copy.java diff -N ide/launcher/upgrade/src/org/netbeans/upgrade/Copy.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/src/org/netbeans/upgrade/Copy.java 4 Jun 2004 16:59:42 -0000 @@ -0,0 +1,463 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.upgrade; + +import java.io.*; +import java.util.*; +import org.openide.util.*; +import java.util.jar.*; +import org.w3c.dom.*; +import org.xml.sax.*; +import org.openide.xml.XMLUtil; + +import org.openide.filesystems.*; +import org.openide.filesystems.FileSystem; + + +/** Does copy of objects on filesystems. + * + * @author Jaroslav Tulach + */ +final class Copy extends Object { + + + /** Does a selective copy of one source tree to another. + * @param source file object to copy from + * @param target file object to copy to + * @param thoseToCopy set on which contains (relativeNameOfAFileToCopy) + * is being called to find out whether to copy or not + * @throws IOException if coping fails + */ + public static void copyDeep (FileObject source, FileObject target, Set thoseToCopy) + throws IOException { + copyDeep (source, target, thoseToCopy, null); + } + + private static void copyDeep ( + FileObject source, FileObject target, Set thoseToCopy, String prefix + ) throws IOException { + FileObject src = prefix == null ? source : FileUtil.createFolder (source, prefix); + + FileObject[] arr = src.getChildren(); + for (int i = 0; i < arr.length; i++) { + String fullname; + if (prefix == null) { + fullname = arr[i].getNameExt (); + } else { + fullname = prefix + "/" + arr[i].getNameExt (); + } + if (arr[i].isData ()) { + if (!thoseToCopy.contains (fullname)) { + continue; + } + } + + + if (arr[i].isFolder()) { + copyDeep (source, target, thoseToCopy, fullname); + if (thoseToCopy.contains (fullname) && arr[i].getAttributes ().hasMoreElements ()) { + FileObject tg = FileUtil.createFolder (target, fullname); + FileUtil.copyAttributes (arr[i], tg); + } + } else { + FileObject folder = prefix == null ? target : FileUtil.createFolder (target, prefix); + FileObject tg = folder.getFileObject (arr[i].getNameExt ()); + if (tg == null) { + // copy the file otherwise keep old content + tg = FileUtil.copyFile (arr[i], folder, arr[i].getName(), arr[i].getExt ()); + } + + FileUtil.copyAttributes (arr[i], tg); + } + } + + + } + + + + /** Updates the IDE. + * @param sourceDir original instalation of the IDE + * @param targetSystem target system to copy files to + * @param backupSystem filesystem to do backupSystemFo to (or null) + * @exception IOException if the copying fails + * + protected final void upgradeIde (String ver, File src, File trg) throws Exception { + + + int version = getIdeVersion (ver); + if (version < 0 || version >= versions.length) { + message (getString ("MSG_BAD_IDE")); + for (int i = 0 ; i < versions.length ; i++ ) { + message (versions[i]); + } + throw new Exception ("Invalid IDE version"); //NOI18N + } + + message (getString ("MSG_UPDATE_FROM", versions[version])); + + FileSystem srcFS = null; + FileSystem trgFS = null; + FileSystem tmpFS = null; + Object filter [] = null; + + if (-1 != ver.indexOf (DIRTYPE_INST)) { + File srcFile = new File (src, "system"); //NOI18N + File trgFile = new File (trg, "system"); //NOI18N + srcFS = createFileSystem (srcFile); + trgFS = createFileSystem (trgFile); + + if (srcFS == null) { + message (getString ("MSG_directory_not_exist", srcFile.getAbsolutePath ())); //NOI18N + throw new Exception ("Directory doesn't exist - " + srcFile.getAbsolutePath ()); //NOI18N + } + + if (trgFS == null) { + message (getString ("MSG_directory_not_exist", trgFile.getAbsolutePath ())); + throw new Exception ("Directory doesn't exist - " + trgFile.getAbsolutePath ()); //NOI18N + } + + File tmpRoot = new File (trg, "system_backup"); //NOI18N + if (!tmpRoot.exists ()) { +// message (getString ("MSG_BackupDir_exists", tmpRoot.getAbsolutePath ())); //NOI18N +// throw new Exception ("Backup directory already exists - " + tmpRoot.getAbsolutePath ()); //NOI18N +// } else { + tmpRoot.mkdirs (); + } + tmpFS = createFileSystem (tmpRoot); + + filter = originalFiles (nonCpFiles[version]); + } else { + srcFS = createFileSystem (src); //NOI18N + trgFS = createFileSystem (trg); //NOI18N + + if (srcFS == null) { + message (getString ("MSG_directory_not_exist", src.getAbsolutePath ())); //NOI18N + throw new Exception ("Directory doesn't exist - " + src.getAbsolutePath ()); //NOI18N + } + + if (trgFS == null) { + message (getString ("MSG_directory_not_exist", trg.getAbsolutePath ())); //NOI18N + throw new Exception ("Directory doesn't exist - " + trg.getAbsolutePath ()); //NOI18N + } + + File tmpRoot = new File (trg.getParentFile (), "userdir_backup"); //NOI18N + if (!tmpRoot.exists ()) { +// message (getString ("MSG_BackupDir_exists", tmpRoot.getAbsolutePath ())); //NOI18N +// throw new Exception ("Backup directory already exists - " + tmpRoot.getAbsolutePath ()); //NOI18N +// } else { + tmpRoot.mkdirs (); + } + tmpFS = createFileSystem (tmpRoot); + + filter = originalFiles (userdirNonCpFiles); + } + + if (tmpFS != null) { + // clean up temporary filesystem + FileObject ch [] = tmpFS.getRoot ().getChildren (); + for (int i = 0; i < ch.length; i++) { + deleteAll (ch[i]); + } + // make a backup copy + copyAttributes(trgFS.getRoot (), tmpFS.getRoot ()); + recursiveCopy(trgFS.getRoot (), tmpFS.getRoot ()); + } + + try { + update (srcFS, trgFS, getLastModified (src), filter); + } + catch (Exception e) { + if (tmpFS != null) { + message (getString ("MSG_recovery_started")); //NOI18N + deleteAll (trgFS.getRoot ()); + copyAttributes (tmpFS.getRoot (), trgFS.getRoot ()); + recursiveCopy (tmpFS.getRoot (), trgFS.getRoot ()); + message (getString ("MSG_recovery_finished")); //NOI18N + } + throw e; + } + } + + private FileSystem createFileSystem (File root) { + LocalFileSystem lfs = null; + + if (root.exists () && root.isDirectory ()) { + try { + lfs = new LocalFileSystem (); + lfs.setRootDirectory (root); + } + catch (Exception e) { + lfs = null; + } + } + + return lfs == null ? null : new AttrslessLocalFileSystem (lfs); + } + + private void update( + FileSystem src, FileSystem trg, long sourceBaseTime, Object[] filter + ) throws IOException { + + items = 0; + maxItems = 0; + + copyAttributes (src.getRoot (),trg.getRoot ()); + recursiveCopyWithFilter ( + src.getRoot (), + trg.getRoot (), + filter, + sourceBaseTime + ); + } + + /** copies recursively directory, skips files existing in target location + * @param source source directory + * @param dest destination directory + */ + private void recursiveCopy (FileObject sourceFolder, FileObject destFolder) throws IOException { + FileObject childrens [] = sourceFolder.getChildren(); + for (int i = 0 ; i < childrens.length ; i++ ) { + final FileObject subSourceFo = childrens[i]; + FileObject subTargetFo = null; + + if (subSourceFo.isFolder()) { + subTargetFo = destFolder.getFileObject(subSourceFo.getName()); + if (subTargetFo == null) { + subTargetFo = destFolder.createFolder(subSourceFo.getName()); + + } + copyAttributes(subSourceFo,subTargetFo); + recursiveCopy(subSourceFo,subTargetFo); + } else { + subTargetFo = destFolder.getFileObject(subSourceFo.getNameExt()); + if (subTargetFo == null) { + if ( Utilities.getOperatingSystem () == Utilities.OS_VMS + && subSourceFo.getNameExt ().equalsIgnoreCase ( "_nbattrs.") ) + subTargetFo = FileUtil.copyFile(subSourceFo, destFolder, subSourceFo.getNameExt(), subSourceFo.getExt()); + else + subTargetFo = FileUtil.copyFile(subSourceFo, destFolder, subSourceFo.getName(), subSourceFo.getExt()); + } + copyAttributes(subSourceFo,subTargetFo); + } + } + } + + private void message (String s) { + + } + private void progress (int x, int y) { + + } + private int maxItems; + private int items; + private int timeDev; + + /** Copies recursively dircectory. Files are copied when when basicTime + timeDev < time of file. + * @param source source directory + * @param #dest destination dirctory + */ + private void recursiveCopyWithFilter ( + FileObject source, FileObject dest, Object[] filter, long basicTime + ) throws IOException { + FileObject childrens [] = source.getChildren(); + if (source.isFolder() == false ) { + message (getString("MSG_IS_NOT_FOLDER", source.getName())); + } + + // adjust max number of items + maxItems += childrens.length; + + for (int i = 0 ; i < childrens.length ; i++ ) { + FileObject subSourceFo = childrens[i]; + + // report progress + items++; + progress(items, maxItems); + + if (!canCopy (subSourceFo, filter, basicTime)) + continue; + + FileObject subTargetFo = null; + if (subSourceFo.isFolder ()) { + subTargetFo = dest.getFileObject (subSourceFo.getNameExt ()); + if (subTargetFo == null) { + subTargetFo = dest.createFolder (subSourceFo.getNameExt ()); + + } + copyAttributes (subSourceFo, subTargetFo); + recursiveCopyWithFilter (subSourceFo, subTargetFo, filter, basicTime); + } else { + subTargetFo = dest.getFileObject (subSourceFo.getName (), subSourceFo.getExt ()); + + if (subTargetFo != null) { + FileLock lock = subTargetFo.lock (); + subTargetFo.delete (lock); + lock.releaseLock (); + } + + if ( Utilities.getOperatingSystem () == Utilities.OS_VMS + && subSourceFo.getNameExt ().equalsIgnoreCase ( "_nbattrs.") ) + subTargetFo = copyFile (subSourceFo, dest, subSourceFo.getNameExt ()); + else + subTargetFo = copyFile (subSourceFo, dest, subSourceFo.getName ()); + copyAttributes (subSourceFo, subTargetFo); + } + } + } + + private FileObject copyFile (FileObject src, FileObject trg, String newName) throws IOException { + return FileUtil.copyFile (src, trg, newName); + } + + private static void copyAttributes (FileObject source, FileObject dest) throws IOException { + Enumeration attrKeys = source.getAttributes(); + while (attrKeys.hasMoreElements()) { + String key = (String) attrKeys.nextElement(); + Object value = source.getAttribute(key); + if (value != null) { + dest.setAttribute(key, value); + } + } + } + /** test if file can be copied + */ + private boolean canCopy (FileObject fo, Object[] filter, long basicTime) throws IOException { + String nonCopiedFiles [] = (String []) filter [0]; + String wildcards [] = (String []) filter [1]; + String name = fo.getPath(); + + if (fo.isFolder ()) { + return Arrays.binarySearch (nonCopiedFiles, name + "/*") < 0; //NOI18N + } + + for (int i = 0; i < wildcards.length; i++) { + if (name.endsWith (wildcards [i])) { + return false; + } + } + + long time = fo.lastModified().getTime(); + + boolean canCopy = Arrays.binarySearch (nonCopiedFiles, name) < 0 && + basicTime + timeDev <= time; + if (!canCopy) { + return false; + } + + // #31623 - the fastjavac settings should not be imported. + // In NB3.5 the fastjavac was separated into its own module. + // Its old settings (bounded to java module) must not be imported. + // For fastjavac settings created by NB3.5 this will work, because they + // will be bound to new "org.netbeans.modules.java.fastjavac" module. + if (fo.getExt().equals("settings")) { //NOI18N + boolean tag1 = false; + boolean tag2 = false; + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(fo.getInputStream())); + String line; + while (null != (line = reader.readLine())) { + if (line.indexOf("") != -1) { //NOI18N + tag2 = true; // it is fastjavac setting + if (tag1) { + break; + } + } else { + break; // some other setting, ignore this file + } + } + } + } catch (IOException ex) { + // ignore this problem. + // in worst case the fastjavac settings will be copied. + } finally { + if (reader != null) { + reader.close(); + } + } + if (tag1 && tag2) { + return false; // ignore this file. it is fastjavac settings + } + } + + return true; + } + // ************************* version retrieving code ******************** + + + /** We support import just from release 3.6 + * @param dir user dir to check for version + * @return either null or name of the version + */ + public static String getIdeVersion (File dir) { + String version = null; + String dirType = null; + String branding = null; + + if (new File (dir, "system").exists ()) { + return "3.6"; + } + return null; + } + + // ************** strings from bundle *************** + + protected static String getString (String key) { + return NbBundle.getMessage (Copy.class, key); + } + + protected static String getString (String key,String param) { + return NbBundle.getMessage(Copy.class,key,param); + } + + private static class AttrslessLocalFileSystem extends AbstractFileSystem implements AbstractFileSystem.Attr { + public AttrslessLocalFileSystem (LocalFileSystem fs) { + super (); + this.change = new LocalFileSystem.Impl (fs); + this.info = (AbstractFileSystem.Info) this.change; + this.list = (AbstractFileSystem.List) this.change; + this.attr = this; + } + public boolean isReadOnly () { + return false; + } + public String getDisplayName () { + return getClass ().toString (); // this will never be shown to user + } + + // ***** no-op implementation of AbstractFileSystem.Attr ***** + + public void deleteAttributes (String name) { + } + public Enumeration attributes (String name) { + return org.openide.util.enum.EmptyEnumeration.EMPTY; + } + public void renameAttributes (String oldName, String newName) { + } + public void writeAttribute (String name, String attrName, Object value) throws IOException { + } + public Object readAttribute (String name, String attrName) { + return null; + } + } +} Index: ide/launcher/upgrade/src/org/netbeans/upgrade/IncludeExclude.java =================================================================== RCS file: ide/launcher/upgrade/src/org/netbeans/upgrade/IncludeExclude.java diff -N ide/launcher/upgrade/src/org/netbeans/upgrade/IncludeExclude.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/src/org/netbeans/upgrade/IncludeExclude.java 4 Jun 2004 16:59:43 -0000 @@ -0,0 +1,102 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.upgrade; + +import java.io.*; +import java.util.*; +import java.util.jar.*; +import java.util.regex.*; + + + +/** A test that is initialized based on includes and excludes. + * + * @author Jaroslav Tulach + */ +final class IncludeExclude extends AbstractSet { + /** List + */ + private ArrayList patterns = new ArrayList (); + + private IncludeExclude () { + } + + /** Reads the include/exclude set from a given reader. + * @param r reader + * @return set that accepts names based on include exclude from the file + */ + public static Set create (Reader r) throws IOException { + IncludeExclude set = new IncludeExclude (); + + BufferedReader buf = new BufferedReader (r); + for (;;) { + String line = buf.readLine (); + if (line == null) break; + + line = line.trim (); + if (line.length () == 0 || line.startsWith ("#")) { + continue; + } + + Boolean plus; + if (line.startsWith ("include ")) { + line = line.substring (8); + plus = Boolean.TRUE; + } else { + if (line.startsWith ("exclude ")) { + line = line.substring (8); + plus = Boolean.FALSE; + } else { + throw new java.io.IOException ("Wrong line: " + line); + } + } + + Pattern p = Pattern.compile (line); + + set.patterns.add (plus); + set.patterns.add (p); + } + + return set; + } + + + public Iterator iterator () { + return null; + } + + public int size () { + return 0; + } + + public boolean contains (Object o) { + String s = (String)o; + + boolean yes = false; + + Iterator it = patterns.iterator (); + while (it.hasNext ()) { + Boolean include = (Boolean)it.next (); + Pattern p = (Pattern)it.next (); + + Matcher m = p.matcher (s); + if (m.matches ()) { + yes = include.booleanValue (); + } + } + + return yes; + } + +} Index: ide/launcher/upgrade/src/org/netbeans/upgrade/copy3.6 =================================================================== RCS file: ide/launcher/upgrade/src/org/netbeans/upgrade/copy3.6 diff -N ide/launcher/upgrade/src/org/netbeans/upgrade/copy3.6 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/src/org/netbeans/upgrade/copy3.6 4 Jun 2004 16:59:43 -0000 @@ -0,0 +1,58 @@ +# Sun Public License Notice +# +# The contents of this file are subject to the Sun Public License +# Version 1.0 (the "License"). You may not use this file except in +# compliance with the License. A copy of the License is available at +# http://www.sun.com/ +# +# The Original Code is NetBeans. The Initial Developer of the Original +# Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun +# Microsystems, Inc. All Rights Reserved. + +# start the line either with # to begin a comment +# or include to describe a file(s) to be included during copy +# or exclude to describe a file(s) to be excluded +# use of regular expressions allowed in file names +# +# the list is iterated from first to last and the last match +# decides the result + +include Services/org-netbeans-core-IDESettings\.settings +include Shortcuts/.* + +include vcs/config/.* +include Services/Hidden/org-netbeans-modules-vcscore-settings-GeneralVcsSettings\.settings + +include Services/DiffProviders/.* +include Services/Diffs/.* +include Services/DiffVisualizers/.* +include Services/MergeVisualizers/.* +include Services/Hidden/org-netbeans-modules-diff-DiffSettings\.settings + +include Services/Browsers/.* +include Services/org-netbeans-modules-httpserver-HttpServerSettings\.settings + +include HTTPMonitor/.* + +include J2ee/.* + +include Services/JDBCDrivers/.* +include Services/org-netbeans-modules-db-explorer-DatabaseOption\.settings + +include Editors/.* +include Editors/AnnotationTypes/.* +include Services/org-openide-text-PrintSettings\.settings +include Services/IndentEngine/.* + +include Services/org-netbeans-modules-java-settings-JavaSettings\.settings +include Services/org-openide-src-nodes-SourceOptions\.settings +include Templates/Classes/.* +include Editors/AnnotationTypes/org-netbeans-modules-java-.*\.xml + +include Services/org-netbeans-modules-beans-beans\.settings +include Templates/Beans/.* + +include Services/JavadocSearchType/.* +include Services/org-netbeans-modules-javadoc-settings-DocumentationSettings\.settings + + Index: ide/launcher/upgrade/test/.cvsignore =================================================================== RCS file: ide/launcher/upgrade/test/.cvsignore diff -N ide/launcher/upgrade/test/.cvsignore --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/test/.cvsignore 4 Jun 2004 16:59:43 -0000 @@ -0,0 +1,3 @@ +lib +results +work Index: ide/launcher/upgrade/test/build-unit.xml =================================================================== RCS file: ide/launcher/upgrade/test/build-unit.xml diff -N ide/launcher/upgrade/test/build-unit.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/test/build-unit.xml 4 Jun 2004 16:59:43 -0000 @@ -0,0 +1,18 @@ + + + + + + Index: ide/launcher/upgrade/test/build.xml =================================================================== RCS file: ide/launcher/upgrade/test/build.xml diff -N ide/launcher/upgrade/test/build.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/test/build.xml 4 Jun 2004 16:59:43 -0000 @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + Index: ide/launcher/upgrade/test/cfg-unit.xml =================================================================== RCS file: ide/launcher/upgrade/test/cfg-unit.xml diff -N ide/launcher/upgrade/test/cfg-unit.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/test/cfg-unit.xml 4 Jun 2004 16:59:43 -0000 @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + Index: ide/launcher/upgrade/test/unit/src/org/netbeans/upgrade/CopyTest.java =================================================================== RCS file: ide/launcher/upgrade/test/unit/src/org/netbeans/upgrade/CopyTest.java diff -N ide/launcher/upgrade/test/unit/src/org/netbeans/upgrade/CopyTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/test/unit/src/org/netbeans/upgrade/CopyTest.java 4 Jun 2004 16:59:43 -0000 @@ -0,0 +1,183 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.upgrade; +import java.util.*; + +import org.openide.filesystems.FileObject; + +import org.openide.filesystems.FileSystem; + +/** Tests to check that copy of files works. + * + * @author Jaroslav Tulach + */ +public final class CopyTest extends org.netbeans.junit.NbTestCase { + public CopyTest (String name) { + super (name); + } + public static void main (String[] args) { + junit.textui.TestRunner.run (new junit.framework.TestSuite (CopyTest.class)); + } + + protected void setUp() throws java.lang.Exception { + super.setUp(); + + org.openide.filesystems.TestUtilHid.destroyLocalFileSystem(getName ()); + } + + public void testDoesSomeCopy () throws Exception { + FileSystem fs = org.openide.filesystems.TestUtilHid.createLocalFileSystem (getName (), new String[] { + "root/X.txt", + "root/Y.txt", + "nonroot/Z.txt" + }); + + FileObject fo = fs.findResource ("root"); + FileObject tg = fs.getRoot().createFolder ("target"); + + java.util.HashSet set = new java.util.HashSet (); + set.add ("X.txt"); + Copy.copyDeep (fo, tg, set); + + assertEquals ("One file copied", 1, tg.getChildren().length); + String n = tg.getChildren ()[0].getNameExt(); + assertEquals ("Name is X.txt", "X.txt", n); + + } + + public void testDoesDeepCopy () throws Exception { + FileSystem fs = org.openide.filesystems.TestUtilHid.createLocalFileSystem (getName (), new String[] { + "root/subdir/X.txt", + "root/Y.txt", + "nonroot/Z.txt" + }); + + FileObject fo = fs.findResource ("root"); + FileObject tg = fs.getRoot().createFolder ("target"); + + java.util.HashSet set = new java.util.HashSet (); + set.add ("subdir/X.txt"); + Copy.copyDeep (fo, tg, set); + + assertEquals ("One file copied", 1, tg.getChildren().length); + assertEquals ("Name is X.txt", "subdir", tg.getChildren ()[0].getNameExt()); + assertEquals ("One children of one child", 1, tg.getChildren()[0].getChildren().length); + assertEquals ("X.txt", "X.txt", tg.getChildren()[0].getChildren()[0].getNameExt()); + + } + + public void testCopyAttributes () throws Exception { + FileSystem fs = org.openide.filesystems.TestUtilHid.createLocalFileSystem (getName (), new String[] { + "root/X.txt", + "root/Y.txt", + "nonroot/Z.txt" + }); + FileObject x = fs.findResource ("root/X.txt"); + x.setAttribute ("ahoj", "yarda"); + + FileObject fo = fs.findResource ("root"); + FileObject tg = fs.getRoot().createFolder ("target"); + + java.util.HashSet set = new java.util.HashSet (); + set.add ("X.txt"); + Copy.copyDeep (fo, tg, set); + + assertEquals ("One file copied", 1, tg.getChildren().length); + assertEquals ("Name is X.txt", "X.txt", tg.getChildren ()[0].getNameExt()); + assertEquals ("attribute copied", "yarda", tg.getChildren()[0].getAttribute("ahoj")); + } + + public void testCopyFolderAttributes () throws Exception { + FileSystem fs = org.openide.filesystems.TestUtilHid.createLocalFileSystem (getName (), new String[] { + "root/sub/X.txt", + "root/Y.txt", + "nonroot/Z.txt" + }); + FileObject x = fs.findResource ("root/sub"); + x.setAttribute ("ahoj", "yarda"); + + FileObject fo = fs.findResource ("root"); + FileObject tg = fs.getRoot().createFolder ("target"); + + java.util.HashSet set = new java.util.HashSet (); + set.add ("sub"); + set.add ("sub/X.txt"); + Copy.copyDeep (fo, tg, set); + + assertEquals ("One file copied", 1, tg.getChildren().length); + assertEquals ("Name of the dir is sub", "sub", tg.getChildren ()[0].getNameExt()); + assertEquals ("attribute copied", "yarda", tg.getChildren()[0].getAttribute("ahoj")); + assertEquals ("X.txt", "X.txt", tg.getChildren()[0].getChildren()[0].getNameExt()); + } + + public void testDoNotCopyEmptyDirs () throws Exception { + FileSystem fs = org.openide.filesystems.TestUtilHid.createLocalFileSystem (getName (), new String[] { + "root/sub/X.txt", + "root/Y.txt", + "nonroot/Z.txt" + }); + FileObject x = fs.findResource ("root/sub"); + + FileObject fo = fs.findResource ("root"); + FileObject tg = fs.getRoot().createFolder ("target"); + + java.util.HashSet set = new java.util.HashSet (); + Copy.copyDeep (fo, tg, set); + + assertEquals ("Nothing copied", 0, tg.getChildren().length); + } + + public void testDoNotOverwriteFiles () throws Exception { + java.util.HashSet set = new java.util.HashSet (); + set.add ("X.txt"); + + FileSystem fs = org.openide.filesystems.TestUtilHid.createLocalFileSystem (getName (), new String[] { + "root/project/X.txt", + "root/X.txt", + "nonroot/Z.txt" + }); + + writeTo (fs, "root/project/X.txt", "content-project"); + writeTo (fs, "root/X.txt", "content-global"); + + FileObject tg = fs.getRoot().createFolder ("target"); + + FileObject project = fs.findResource ("root/project"); + Copy.copyDeep (project, tg, set); + + + + FileObject root = fs.findResource ("root"); + Copy.copyDeep (root, tg, set); + + + FileObject x = tg.getFileObject ("X.txt"); + assertNotNull ("File copied", x); + + byte[] arr = new byte[300]; + int len = x.getInputStream ().read (arr); + String content = new String (arr, 0, len); + + assertEquals ("The content is kept from project", content, "content-project"); + } + + private static void writeTo (FileSystem fs, String res, String content) throws java.io.IOException { + FileObject fo = org.openide.filesystems.FileUtil.createData (fs.getRoot (), res); + org.openide.filesystems.FileLock lock = fo.lock (); + java.io.OutputStream os = fo.getOutputStream (lock); + os.write (content.getBytes ()); + os.close (); + lock.releaseLock (); + } + } Index: ide/launcher/upgrade/test/unit/src/org/netbeans/upgrade/IncludeExcludeTest.java =================================================================== RCS file: ide/launcher/upgrade/test/unit/src/org/netbeans/upgrade/IncludeExcludeTest.java diff -N ide/launcher/upgrade/test/unit/src/org/netbeans/upgrade/IncludeExcludeTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ide/launcher/upgrade/test/unit/src/org/netbeans/upgrade/IncludeExcludeTest.java 4 Jun 2004 16:59:43 -0000 @@ -0,0 +1,71 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.upgrade; + +import java.util.*; + +/** Tests to check that copy of files works. + * + * @author Jaroslav Tulach + */ +public final class IncludeExcludeTest extends org.netbeans.junit.NbTestCase { + private Set includeExclude; + + public IncludeExcludeTest (String name) { + super (name); + } + public static void main (String[] args) { + junit.textui.TestRunner.run (new junit.framework.TestSuite (IncludeExcludeTest.class)); + } + + protected void setUp() throws java.lang.Exception { + super.setUp(); + + String reader = "# ignore comment\n" + + "include one/file.txt\n" + + "include two/dir/.*\n" + + "\n" + + "exclude two/dir/sub/.*\n"; + + includeExclude = IncludeExclude.create (new java.io.StringReader (reader)); + } + + public void testOneFileIsThere () { + assertTrue (includeExclude.contains ("one/file.txt")); + } + + public void testDoesNotContainRoot () { + assertFalse (includeExclude.contains ("")); + } + + public void testContainsSomethingInDir () { + assertTrue (includeExclude.contains ("two/dir/a.file")); + } + + public void testContainsSomethingUnderTheDir () { + assertTrue (includeExclude.contains ("two/dir/some/folder/a.file")); + } + + public void testDoesNotContainSubDir () { + assertFalse (includeExclude.contains ("two/dir/sub/not.there")); + } + + public void testWrongContentDetected () { + try { + IncludeExclude.create (new java.io.StringReader ("some strange line")); + fail ("Should throw exception"); + } catch (java.io.IOException ex) { + } + } + } Index: ide/launcher/windows/netbeans.cpp =================================================================== RCS file: /cvs/ide/launcher/windows/netbeans.cpp,v retrieving revision 1.5 diff -u -r1.5 netbeans.cpp --- ide/launcher/windows/netbeans.cpp 21 May 2004 15:01:24 -0000 1.5 +++ ide/launcher/windows/netbeans.cpp 4 Jun 2004 16:59:43 -0000 @@ -151,7 +151,7 @@ } } sprintf(nbexec, "%s\\platform4\\launcher\\nbexec.exe", topdir); - sprintf(cmdline2, "\"%s\" %s --branding nb --clusters \"%s\" --userdir \"%s\" %s %s", + sprintf(cmdline2, "\"%s\" %s -J-Dnetbeans.importclass=org.netbeans.upgrade.AutoUpgrade --branding nb --clusters \"%s\" --userdir \"%s\" %s %s", nbexec, jdkswitch, dirs,