|
What this is
Other links
The source code/* * 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-2000 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.autoupdate; import java.lang.ref.*; import java.util.*; //import junit.framework.*; import org.netbeans.junit.*; import java.util.List; import java.awt.Image; import java.awt.datatransfer.Transferable; import java.beans.*; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.jar.*; import java.util.jar.Manifest; import java.util.regex.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; //import org.openide.ErrorManager; public abstract class AbstractTestHid extends NbTestCase { protected File userDir, platformDir, clusterDir, nextDir; public AbstractTestHid (String name) { super (name); } protected void setUp () throws Exception { System.setProperty("org.openide.util.Lookup", "-"); super.setUp (); // clear directories first this.clearWorkDir(); userDir = new File (getWorkDir(), "user"); assertTrue (userDir.mkdirs ()); platformDir = new File (getWorkDir(), "platform"); assertTrue (platformDir.mkdirs ()); clusterDir = new File (getWorkDir (), "clstr"); assertTrue (clusterDir.mkdirs ()); nextDir = new File (getWorkDir (), "nxtclstr"); assertTrue (nextDir.mkdirs ()); System.setProperty("netbeans.dirs", ""); System.setProperty("netbeans.home", platformDir.toString ()); assertEquals (platformDir.toString (), System.getProperty ("netbeans.home")); System.setProperty("netbeans.user", userDir.toString ()); assertEquals (userDir.toString (), System.getProperty ("netbeans.user")); } protected final void initClusters () { System.setProperty( "netbeans.dirs", clusterDir.toString() + File.pathSeparatorChar + nextDir ); } // // Utilities // private final File createNewNBMFile () throws IOException { int i = 0; for (;;) { File f = new File (this.getWorkDir(), this.getName() + i++ + ".nbm"); if (!f.exists ()) return f; } } protected final File generateNBM(String[] content, String info) throws IOException { File f = createNewNBMFile (); ZipOutputStream os = new ZipOutputStream (new FileOutputStream (f)); for (int i = 0; i < content.length; i++) { os.putNextEntry(new ZipEntry (content[i])); os.closeEntry(); } os.putNextEntry (new ZipEntry ("Info/info.xml")); os.write (info.getBytes()); os.closeEntry (); os.close(); return f; } protected final File generateNBM(java.util.jar.Manifest[] content, String info) throws IOException { File f = createNewNBMFile (); ZipOutputStream os = new ZipOutputStream (new FileOutputStream (f)); for (int i = 0; i < content.length; i++) { ZipEntry entry = new ZipEntry (content[i].getMainAttributes ().getValue ("name")); os.putNextEntry(entry); java.io.ByteArrayOutputStream array = new java.io.ByteArrayOutputStream (); java.util.jar.JarOutputStream jar = new java.util.jar.JarOutputStream (array, content[i]); jar.close (); os.write (array.toByteArray ()); os.closeEntry(); } os.putNextEntry (new ZipEntry ("Info/info.xml")); os.write (info.getBytes()); os.closeEntry (); os.close(); return f; } protected final static void installNBM (File nbm) { installNBMs (new File[] { nbm }); } protected final static void installNBMs (File[] nbms) { class L implements PropertyChangeListener { private PropertyChangeEvent ev; public synchronized void propertyChange (PropertyChangeEvent ev) { if ("FINISHED".equals (ev.getPropertyName())) { this.ev = ev; notify (); } } public PropertyChangeEvent waitForEvent () { while (ev == null) { try { wait (); } catch (InterruptedException ex) { fail ("No exceptions expected"); } } return ev; } } L listener = new L (); synchronized (listener) { org.netbeans.updater.UpdaterFrame.runFromIDE(nbms, listener); listener.waitForEvent (); } } /** Scans files in user dir * @return Map |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.