# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /doma/jarda/netbeans-src # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: autoupdate/src/org/netbeans/modules/autoupdate/AutoupdateClusterCreator.java *** /doma/jarda/netbeans-src/autoupdate/src/org/netbeans/modules/autoupdate/AutoupdateClusterCreator.java No Base Revision --- /doma/jarda/netbeans-src/autoupdate/src/org/netbeans/modules/autoupdate/AutoupdateClusterCreator.java Locally New *************** *** 1,0 **** --- 1,53 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.netbeans.modules.autoupdate; + + import java.io.File; + import java.io.IOException; + + /** Class that is supposed to be implemented by application + * providers that can control launcher in order to modify + * the list of provided clusters. + * + * @since 2.21 + * @author Jaroslav Tulach + */ + public abstract class AutoupdateClusterCreator extends Object { + /** Finds the right cluster directory for given cluster name. + * This method can return null if no such cluster name is known or + * understandable, otherwise it returns a file object representing + * not existing directory that will be created later + * to host hold the content of the cluster. + * + * @param clusterName the name of the cluster the autoupdate client is searching for + * @return null or File object of the cluster to be created + */ + protected abstract File findCluster(String clusterName); + + /** Changes the launcher to know about the new cluster and + * use it next time the system starts. + * + * @param clusterName the name of the cluster + * @param cluster file previously returned by findCluster + * @return the list of current cluster directories, including the newly added one + * @exception IOException if the registration fails + */ + protected abstract File[] registerCluster(String clusterName, File cluster) throws IOException; + } Index: ide/updatecenters/manifest.mf *** /doma/jarda/netbeans-src/ide/updatecenters/manifest.mf Base (1.7) --- /doma/jarda/netbeans-src/ide/updatecenters/manifest.mf Locally Modified (Based On 1.7) *************** *** 1,6 **** Manifest-Version: 1.0 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/updatecenters/resources/Bundle.properties ! OpenIDE-Module-Specification-Version: 1.7 OpenIDE-Module: org.netbeans.modules.updatecenters/1 OpenIDE-Module-Layer: org/netbeans/modules/updatecenters/resources/mf-layer.xml --- 1,6 ---- Manifest-Version: 1.0 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/updatecenters/resources/Bundle.properties ! OpenIDE-Module-Specification-Version: 1.8 OpenIDE-Module: org.netbeans.modules.updatecenters/1 OpenIDE-Module-Layer: org/netbeans/modules/updatecenters/resources/mf-layer.xml Index: ide/updatecenters/src/org/netbeans/modules/updatecenters/resources/NetBeansClusterCreator.java *** /doma/jarda/netbeans-src/ide/updatecenters/src/org/netbeans/modules/updatecenters/resources/NetBeansClusterCreator.java No Base Revision --- /doma/jarda/netbeans-src/ide/updatecenters/src/org/netbeans/modules/updatecenters/resources/NetBeansClusterCreator.java Locally New *************** *** 1,0 **** --- 1,81 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.netbeans.modules.updatecenters.resources; + + import java.io.File; + import java.io.FileOutputStream; + import java.io.IOException; + import java.io.OutputStream; + import java.util.ArrayList; + import java.util.List; + import java.util.StringTokenizer; + import org.netbeans.modules.autoupdate.AutoupdateClusterCreator; + + + /** Modifies the etc/netbeans.conf if necessary. + * + * @author Jaroslav Tulach + */ + public final class NetBeansClusterCreator extends AutoupdateClusterCreator { + protected File findCluster(String clusterName) { + File[] parent = new File[1]; + File conf = findConf(parent, new ArrayList()); + return conf != null && conf.isFile() && conf.canWrite() ? new File(parent[0], clusterName) : null; + } + + private static File findConf(File[] parent, List clusters) { + StringTokenizer tok = new StringTokenizer(System.getProperty("netbeans.dirs"), File.pathSeparator); // NOI18N + while (tok.hasMoreElements()) { + File cluster = new File(tok.nextToken()); + clusters.add(cluster); + if (!cluster.exists()) { + continue; + } + + + + if (parent[0] == null) { + parent[0] = cluster.getParentFile(); + } + + if (!parent[0].equals(cluster.getParentFile())) { + // we can handle only case when all clusters are in + // the same directory these days + return null; + } + } + + return new File(new File(parent[0], "etc"), "netbeans.clusters"); + } + + protected File[] registerCluster(String clusterName, File cluster) throws IOException { + File[] parent = new File[1]; + List clusters = new ArrayList(); + File conf = findConf(parent, clusters); + assert conf != null; + clusters.add(cluster); + OutputStream os = new FileOutputStream(conf, true); + os.write("\n".getBytes()); + os.write(clusterName.getBytes()); + os.write("\n".getBytes()); + os.close(); + return clusters.toArray(new File[0]); + } + } Index: ide/updatecenters/src/META-INF/services/org.netbeans.modules.autoupdate.AutoupdateClusterCreator *** /doma/jarda/netbeans-src/ide/updatecenters/src/META-INF/services/org.netbeans.modules.autoupdate.AutoupdateClusterCreator No Base Revision --- /doma/jarda/netbeans-src/ide/updatecenters/src/META-INF/services/org.netbeans.modules.autoupdate.AutoupdateClusterCreator Locally New *************** *** 1,0 **** --- 1,1 ---- + org.netbeans.modules.updatecenters.resources.NetBeansClusterCreator Index: autoupdate/src/org/netbeans/modules/autoupdate/Downloader.java *** /doma/jarda/netbeans-src/autoupdate/src/org/netbeans/modules/autoupdate/Downloader.java Base (1.56) --- /doma/jarda/netbeans-src/autoupdate/src/org/netbeans/modules/autoupdate/Downloader.java Locally Modified (Based On 1.56) *************** *** 31,36 **** --- 31,37 ---- import org.netbeans.updater.UpdateTracking; import org.openide.DialogDisplayer; + import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.NotifyDescriptor; *************** *** 520,525 **** --- 521,567 ---- } static boolean tryMove( ModuleUpdate mu ) { + File toCluster = mu.findInstallDirectory(); + + boolean existingCluster = false; + for (Iterator it = UpdateTracking.clusters(true).iterator(); it.hasNext(); ) { + File f = (File)it.next(); + if (f.equals(toCluster)) { + existingCluster = true; + break; + } + } + + DO_CLUSTER: if (!existingCluster) { + for (Iterator it = Lookup.getDefault().lookupAll(AutoupdateClusterCreator.class).iterator(); it.hasNext(); ) { + AutoupdateClusterCreator a = (AutoupdateClusterCreator)it.next(); + + if (toCluster.equals(a.findCluster(toCluster.getName()))) { + File[] allClusters; + try { + allClusters = a.registerCluster(toCluster.getName(), toCluster); + } catch (IOException ex) { + return false; + } + + StringBuffer sb = new StringBuffer(); + String sep = ""; + for (int i = 0; i < allClusters.length; i++) { + sb.append(sep); + sb.append(allClusters[i].getPath()); + sep = File.pathSeparator; + } + System.setProperty("netbeans.dirs", sb.toString()); // NOI18N + + break DO_CLUSTER; + } + } + assert false; + } + + + + File inst = new File ( Autoupdater.Support.getDownloadDirectory (mu.findInstallDirectory ()), mu.getDistributionFilename() Index: autoupdate/test/unit/src/org/netbeans/modules/autoupdate/NbmsTest.java *** /doma/jarda/netbeans-src/autoupdate/test/unit/src/org/netbeans/modules/autoupdate/NbmsTest.java Base (1.17) --- /doma/jarda/netbeans-src/autoupdate/test/unit/src/org/netbeans/modules/autoupdate/NbmsTest.java Locally Modified (Based On 1.17) *************** *** 20,46 **** package org.netbeans.modules.autoupdate; import java.util.*; - - import org.netbeans.junit.*; import java.io.File; ! import org.netbeans.updater.UpdateTracking; public class NbmsTest extends AbstractTestHid { public NbmsTest(String name) { super (name); } - public static void main(java.lang.String[] args) { - if (args.length == 1) { - junit.textui.TestRunner.run(new NbmsTest (args[0])); - } else { - junit.textui.TestRunner.run(new NbTestSuite(NbmsTest.class)); - } - System.exit (0); - } - - public void testNBMFileIsGenerated () throws Exception { File f = generateBasicNbm ("3.8"); --- 20,37 ---- package org.netbeans.modules.autoupdate; import java.util.*; import java.io.File; ! import org.netbeans.modules.autoupdate.AbstractTestHid.Lkp; public class NbmsTest extends AbstractTestHid { public NbmsTest(String name) { super (name); } public void testNBMFileIsGenerated () throws Exception { File f = generateBasicNbm ("3.8"); *************** *** 352,357 **** --- 340,396 ---- } + public void testTargetClusterNotDeclaredInClustersButThereIsAClusterCreator() throws Exception { + initClusters (); + + MockClusterCreator mcc = new MockClusterCreator(); + Lkp.ic.add(mcc); + + + File f = generateBasicNbm ("3.8", Boolean.TRUE, "strange"); + + File update = new File (platformDir, "update_tracking"); + update.mkdirs (); + update = new File (clusterDir, "update_tracking"); + update.mkdirs (); + File strangeDir = new File (getWorkDir (), "strange"); + + assertFalse (strangeDir + " cluster doesn't exist.", strangeDir.exists ()); + + mcc.expectedCluster = strangeDir; + + ModuleUpdate mu = ModuleUpdate.getModuleUpdate (f); + assertTrue ("ModuleUpdate is global.", mu.isGlobal ().booleanValue ()); + assertEquals("strange", mu.getTargetCluster()); + + assertEquals ( + "If the cluster does not exists, our MockClusterCreator is queried about it", + strangeDir, mu.findInstallDirectory () + ); + + assertEquals("The findInstallDirectory method called with", "strange", mcc.cluster); + assertFalse("Nothing created", mcc.registered); + + download (mu); + + mcc.allClusters = new File[] { clusterDir, nextDir, strangeDir, otherDir }; + + assertTrue ("Moved to install cluster", Downloader.tryMove (mu)); + File movedNbm = Downloader.getMovedNBM (mu); + installNBM (movedNbm); + + assertEquals ("Empty user dir", 0, findFiles (userDir).size ()); + assertEquals ("Empty platform dir", 0, findFiles (platformDir).size ()); + assertEquals ("Empty cluster dir", 0, findFiles (platformDir).size ()); + assertEquals ("Non empty strange dir: " + findFiles (strangeDir), 5, findFiles (strangeDir).size ()); + + Map filesInCluster = findFiles (strangeDir); + assertNotNull ("Contains x.jar", filesInCluster.get ("modules/x.jar")); + assertNotNull ("Contains y.jar", filesInCluster.get ("modules/y.jar")); + assertNotNull ("Contains update tracking", filesInCluster.get ("update_tracking/org-openide.xml")); + + } + public void testTargetClusterIfApproximatelyDeclared () throws Exception { initClusters (); *************** *** 747,753 **** --- 786,818 ---- return f; } + + public static final class MockClusterCreator extends AutoupdateClusterCreator { + + File expectedCluster; + File[] allClusters; + String cluster; + boolean registered; + + public MockClusterCreator() { } + + protected File findCluster(String clusterName) { + assertNotNull(expectedCluster); + cluster = clusterName; + return expectedCluster; + } + + protected File[] registerCluster(String clusterName, File f) { + assertNotNull(allClusters); + assertEquals("Same name", cluster, clusterName); + assertEquals("Same dir", expectedCluster, f); + registered = true; + return allClusters; + } + } + } Index: autoupdate/manifest.mf *** /doma/jarda/netbeans-src/autoupdate/manifest.mf Base (1.62) --- /doma/jarda/netbeans-src/autoupdate/manifest.mf Locally Modified (Based On 1.62) *************** *** 3,9 **** OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/autoupdate/Bundle.properties OpenIDE-Module-Install: org/netbeans/modules/autoupdate/AutoUpdateModule.class OpenIDE-Module-Layer: org/netbeans/modules/autoupdate/resources/mf-layer.xml ! OpenIDE-Module-Specification-Version: 2.20 Name: org/netbeans/modules/autoupdate/NbmDataLoader.class OpenIDE-Module-Class: Loader --- 3,9 ---- OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/autoupdate/Bundle.properties OpenIDE-Module-Install: org/netbeans/modules/autoupdate/AutoUpdateModule.class OpenIDE-Module-Layer: org/netbeans/modules/autoupdate/resources/mf-layer.xml ! OpenIDE-Module-Specification-Version: 2.21 Name: org/netbeans/modules/autoupdate/NbmDataLoader.class OpenIDE-Module-Class: Loader Index: autoupdate/test/unit/src/org/netbeans/modules/autoupdate/AbstractTestHid.java *** /doma/jarda/netbeans-src/autoupdate/test/unit/src/org/netbeans/modules/autoupdate/AbstractTestHid.java Base (1.8) --- /doma/jarda/netbeans-src/autoupdate/test/unit/src/org/netbeans/modules/autoupdate/AbstractTestHid.java Locally Modified (Based On 1.8) *************** *** 19,25 **** package org.netbeans.modules.autoupdate; - import java.lang.ref.*; import java.util.*; //import junit.framework.*; --- 19,24 ---- *************** *** 30,42 **** import java.io.FileOutputStream; import java.io.IOException; import java.util.jar.*; - import java.util.regex.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import org.openide.util.NbBundle; --- 29,39 ---- import java.io.FileOutputStream; import java.io.IOException; import java.util.jar.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import org.openide.util.NbBundle; + import org.openide.util.lookup.AbstractLookup; + import org.openide.util.lookup.InstanceContent; public abstract class AbstractTestHid extends NbTestCase { *************** *** 44,50 **** } protected void setUp () throws Exception { ! System.setProperty("org.openide.util.Lookup", "-"); super.setUp (); --- 44,50 ---- } protected void setUp () throws Exception { ! System.setProperty("org.openide.util.Lookup", Lkp.class.getName()); super.setUp (); *************** *** 193,199 **** --- 193,209 ---- jf.close (); assertTrue ("Download ok for " + nbm.getDistributionFile (), res); } + + + public static final class Lkp extends AbstractLookup { + static InstanceContent ic = new InstanceContent(); + + public Lkp() { + super(ic); } + } + } Index: ide/updatecenters/nbproject/project.properties *** /doma/jarda/netbeans-src/ide/updatecenters/nbproject/project.properties Base (1.3) --- /doma/jarda/netbeans-src/ide/updatecenters/nbproject/project.properties Locally Modified (Based On 1.3) *************** *** 16,18 **** --- 16,20 ---- # Microsystems, Inc. All Rights Reserved. is.eager=true + javac.compilerargs=-Xlint:unchecked + javac.source=1.5 Index: ide/updatecenters/nbproject/project.xml *** /doma/jarda/netbeans-src/ide/updatecenters/nbproject/project.xml Base (1.5) --- /doma/jarda/netbeans-src/ide/updatecenters/nbproject/project.xml Locally Modified (Based On 1.5) *************** *** 25,33 **** org.netbeans.modules.autoupdate 1 ! 0.1 --- 25,35 ---- org.netbeans.modules.autoupdate + + 1 ! 2.21 Index: autoupdate/apichanges.xml *** /doma/jarda/netbeans-src/autoupdate/apichanges.xml Base (1.3) --- /doma/jarda/netbeans-src/autoupdate/apichanges.xml Locally Modified (Based On 1.3) *************** *** 23,28 **** --- 23,41 ---- Auto Update API + + + New attribute AutoupdateClusterCreator to talk to launchers + + + + + Autoupdate offers launcher to provide an interface that is then consulted when an NBM for not yet existing cluster is + about to be installed. + + + + New attribute targetcluster in autoupdate-catalog-2_4.dtd Index: autoupdate/src/org/netbeans/modules/autoupdate/ModuleUpdate.java *** /doma/jarda/netbeans-src/autoupdate/src/org/netbeans/modules/autoupdate/ModuleUpdate.java Base (1.71) --- /doma/jarda/netbeans-src/autoupdate/src/org/netbeans/modules/autoupdate/ModuleUpdate.java Locally Modified (Based On 1.71) *************** *** 49,54 **** --- 49,55 ---- import org.openide.NotifyDescriptor; import org.openide.modules.ModuleInfo; import org.openide.util.Exceptions; + import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.w3c.dom.Attr; import org.w3c.dom.Document; *************** *** 170,185 **** private boolean toInstallDir; /** Holds value of property downloadStarted. */ ! private boolean downloadStarted = false; /** Holds value of property safeToInstall. */ ! private boolean safeToInstall = false; /** Holds value of property isGlobal. */ ! private Boolean isGlobal = null; /** Holds value of property targetCluster. */ ! private String targetCluster = null; /** Holds value of property jarList. */ private List jarList = new ArrayList(); --- 171,186 ---- private boolean toInstallDir; /** Holds value of property downloadStarted. */ ! private boolean downloadStarted; /** Holds value of property safeToInstall. */ ! private boolean safeToInstall; /** Holds value of property isGlobal. */ ! private Boolean isGlobal; /** Holds value of property targetCluster. */ ! private String targetCluster; /** Holds value of property jarList. */ private List jarList = new ArrayList(); *************** *** 617,631 **** File f = (File) en.next (); if (p.matcher (f.getName ()).matches ()) { targetCluster = f.getName (); ! break; } } } } // GETTERS AND SETTERS ------------------------------------------------------ --- 618,642 ---- File f = (File) en.next (); if (p.matcher (f.getName ()).matches ()) { targetCluster = f.getName (); ! return; } } + + for ( + Iterator it = Lookup.getDefault().lookupAll(AutoupdateClusterCreator.class).iterator(); + it.hasNext() && targetCluster == null; + ) { + AutoupdateClusterCreator creator = (AutoupdateClusterCreator)it.next(); + File f = creator.findCluster(attr); + if (f != null) { + targetCluster = f.getName(); + return; } } + } + } + // GETTERS AND SETTERS ------------------------------------------------------ /** Getter for property codeNameBase. *************** *** 1269,1275 **** if (updateTarget != null) { target = updateTarget; } else { ! target = declaredTarget == null ? firstInstallable : declaredTarget; if (target != null && ! target.exists ()) { new File (target, UpdateTracking.TRACKING_FILE_NAME).mkdirs (); } --- 1283,1303 ---- if (updateTarget != null) { target = updateTarget; } else { ! if (declaredTarget != null) { ! target = declaredTarget; ! } ! if (getTargetCluster() != null) { ! for ( ! Iterator it = Lookup.getDefault().lookupAll(AutoupdateClusterCreator.class).iterator(); ! it.hasNext() && target == null; ! ) { ! AutoupdateClusterCreator creator = (AutoupdateClusterCreator)it.next(); ! target = creator.findCluster(getTargetCluster()); ! } ! } ! if (target == null) { ! target = firstInstallable; ! } if (target != null && ! target.exists ()) { new File (target, UpdateTracking.TRACKING_FILE_NAME).mkdirs (); }