|
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-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.core.modules; //import junit.framework.TestCase; import org.netbeans.junit.NbTestCase; import java.io.*; import java.util.*; import java.beans.*; import java.net.URL; import java.util.jar.Manifest; import org.openide.filesystems.*; import org.openide.filesystems.FileSystem; // override java.io.FileSystem import org.netbeans.core.NbTopManager; /** Some infrastructure for module system tests. * @author Jesse Glick */ abstract class SetupHid extends NbTestCase { public SetupHid(String name) { super(name); } /** directory full of JAR files to test */ protected File jars; protected void setUp() throws Exception { java.util.Locale.setDefault (java.util.Locale.US); jars = new File(ModuleManagerTest.class.getResource("jars").getFile()); } protected static void deleteRec(File f) throws IOException { if (f.isDirectory()) { File[] kids = f.listFiles(); if (kids == null) throw new IOException("Could not list: " + f); for (int i = 0; i < kids.length; i++) { deleteRec(kids[i]); } } if (! f.delete()) throw new IOException("Could not delete: " + f); } protected static void copyStreams(InputStream is, OutputStream os) throws IOException { byte[] buf = new byte[4096]; try { int i; while ((i = is.read(buf)) != -1) { os.write(buf, 0, i); } } finally { is.close(); } } protected static void copy(File a, File b) throws IOException { OutputStream os = new FileOutputStream(b); try { copyStreams(new FileInputStream(a), os); } finally { os.close(); } } protected static void copy(File a, FileObject b) throws IOException { FileLock lock = b.lock(); try { OutputStream os = b.getOutputStream(lock); try { copyStreams(new FileInputStream(a), os); } finally { os.close(); } } finally { lock.releaseLock(); } } protected static String slurp(String path) throws IOException { NbTopManager.get(); // #26451 FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource(path); if (fo == null) return null; InputStream is = fo.getInputStream(); StringBuffer text = new StringBuffer((int)fo.getSize()); byte[] buf = new byte[1024]; int read; while ((read = is.read(buf)) != -1) { text.append(new String(buf, 0, read, "US-ASCII")); } return text.toString(); } protected void addOpenide(ModuleManager mgr) throws Exception { ClassLoader l = SetupHid.class.getClassLoader(); Enumeration e = l.getResources("META-INF/MANIFEST.MF"); Manifest mani = null; while (e.hasMoreElements()) { URL u = (URL)e.nextElement(); Manifest m = new Manifest(u.openStream()); if ("org.openide/1".equals(m.getMainAttributes().getValue("OpenIDE-Module"))) { mani = m; break; } } if (mani == null) throw new IllegalStateException("openide.jar not in classpath?"); mgr.enable(mgr.createFixed(mani, null, l)); } protected static class FakeModuleInstaller extends ModuleInstaller { // For examining results of what happened: public final List actions = new ArrayList(); // List |
... 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.