diff options
author | Thomas Watson | 2013-05-16 14:07:08 +0000 |
---|---|---|
committer | Thomas Watson | 2013-05-16 14:07:08 +0000 |
commit | a2d99f60d2a4ab0c8ac6f42f6d816f59fbcc18ef (patch) | |
tree | eacfb5eae09f5b25a190deb1461759eb7b83a198 /bundles/org.eclipse.osgi/supplement | |
parent | 8e1302f8ce2a3426c57ff3a653f8734ec7ff399e (diff) | |
download | rt.equinox.framework-a2d99f60d2a4ab0c8ac6f42f6d816f59fbcc18ef.tar.gz rt.equinox.framework-a2d99f60d2a4ab0c8ac6f42f6d816f59fbcc18ef.tar.xz rt.equinox.framework-a2d99f60d2a4ab0c8ac6f42f6d816f59fbcc18ef.zip |
Fix supplement bundle build.
- There are several classes in the supplement bundle that need to be moved to the framework
Diffstat (limited to 'bundles/org.eclipse.osgi/supplement')
15 files changed, 91 insertions, 2594 deletions
diff --git a/bundles/org.eclipse.osgi/supplement/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi/supplement/META-INF/MANIFEST.MF index 6ae846519..3a29753eb 100644 --- a/bundles/org.eclipse.osgi/supplement/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.osgi/supplement/META-INF/MANIFEST.MF @@ -16,11 +16,8 @@ Export-Package: org.eclipse.equinox.log;version="1.0", org.eclipse.osgi.service.urlconversion;version="1.0", org.eclipse.osgi.storagemanager;version="1.0", org.eclipse.osgi.util;version="1.1", - org.eclipse.osgi.framework.debug;x-internal:=true, - org.eclipse.osgi.framework.util;x-internal:=true, org.eclipse.osgi.framework.internal.core;x-internal:=true, - org.eclipse.osgi.framework.internal.reliablefile;x-internal:=true, - org.eclipse.core.runtime.internal.adaptor;x-internal:=true + org.eclipse.osgi.framework.internal.reliablefile;x-internal:=true Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: org.osgi.framework, org.osgi.service.log, diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java index 6db71a435..fb9d5c1b2 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/internal/reliablefile/ReliableFile.java @@ -70,7 +70,7 @@ public class ReliableFile { */ public static final String PROP_MAX_GENERATIONS = "osgi.ReliableFile.maxGenerations"; //$NON-NLS-1$ /** - * @see org.eclipse.osgi.internal.location.BasicLocation#PROP_OSGI_LOCKING + * @see org.eclipse.osgi.internal.location.LocationHelper#PROP_OSGI_LOCKING */ public static final String PROP_OSGI_LOCKING = "osgi.locking"; //$NON-NLS-1$ diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/util/SecureAction.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/util/SecureAction.java deleted file mode 100644 index 7138c36a5..000000000 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/util/SecureAction.java +++ /dev/null @@ -1,482 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2013 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.osgi.framework.util; - -import java.io.*; -import java.net.*; -import java.security.*; -import java.util.zip.ZipException; -import java.util.zip.ZipFile; -import org.eclipse.osgi.container.Module; -import org.osgi.framework.*; -import org.osgi.util.tracker.ServiceTracker; - -/** - * Utility class to execute common privileged code. - * @since 3.1 - */ -public class SecureAction { - // make sure we use the correct controlContext; - private AccessControlContext controlContext; - - // This ClassLoader is used in loadSystemClass if System.getClassLoader() returns null - static final ClassLoader bootClassLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { - public ClassLoader run() { - return new ClassLoader(Object.class.getClassLoader()) { /* boot class loader */}; - } - }); - - /* - * Package privaet constructor a new SecureAction object. - * The constructed SecureAction object uses the caller's AccessControlContext - * to perform security checks - */ - SecureAction() { - // save the control context to be used. - this.controlContext = AccessController.getContext(); - } - - /** - * Creates a privileged action that can be used to construct a SecureAction object. - * The recommended way to construct a SecureAction object is the following: <p> - * <pre> - * SecureAction secureAction = (SecureAction) AccessController.doPrivileged(SecureAction.createSecureAction()); - * </pre> - * @return a privileged action object that can be used to construct a SecureAction object. - */ - public static PrivilegedAction<SecureAction> createSecureAction() { - return new PrivilegedAction<SecureAction>() { - public SecureAction run() { - return new SecureAction(); - } - }; - } - - /** - * Returns a system property. Same as calling - * System.getProperty(String). - * @param property the property key. - * @return the value of the property or null if it does not exist. - */ - public String getProperty(final String property) { - if (System.getSecurityManager() == null) - return System.getProperty(property); - return AccessController.doPrivileged(new PrivilegedAction<String>() { - public String run() { - return System.getProperty(property); - } - }, controlContext); - } - - /** - * Creates a FileInputStream from a File. Same as calling - * new FileInputStream(File). - * @param file the File to craete a FileInputStream from. - * @return The FileInputStream. - * @throws FileNotFoundException if the File does not exist. - */ - public FileInputStream getFileInputStream(final File file) throws FileNotFoundException { - if (System.getSecurityManager() == null) - return new FileInputStream(file); - try { - return AccessController.doPrivileged(new PrivilegedExceptionAction<FileInputStream>() { - public FileInputStream run() throws FileNotFoundException { - return new FileInputStream(file); - } - }, controlContext); - } catch (PrivilegedActionException e) { - if (e.getException() instanceof FileNotFoundException) - throw (FileNotFoundException) e.getException(); - throw (RuntimeException) e.getException(); - } - } - - /** - * Creates a FileInputStream from a File. Same as calling - * new FileOutputStream(File,boolean). - * @param file the File to create a FileOutputStream from. - * @param append indicates if the OutputStream should append content. - * @return The FileOutputStream. - * @throws FileNotFoundException if the File does not exist. - */ - public FileOutputStream getFileOutputStream(final File file, final boolean append) throws FileNotFoundException { - if (System.getSecurityManager() == null) - return new FileOutputStream(file.getAbsolutePath(), append); - try { - return AccessController.doPrivileged(new PrivilegedExceptionAction<FileOutputStream>() { - public FileOutputStream run() throws FileNotFoundException { - return new FileOutputStream(file.getAbsolutePath(), append); - } - }, controlContext); - } catch (PrivilegedActionException e) { - if (e.getException() instanceof FileNotFoundException) - throw (FileNotFoundException) e.getException(); - throw (RuntimeException) e.getException(); - } - } - - /** - * Returns the length of a file. Same as calling - * file.length(). - * @param file a file object - * @return the length of a file. - */ - public long length(final File file) { - if (System.getSecurityManager() == null) - return file.length(); - return AccessController.doPrivileged(new PrivilegedAction<Long>() { - public Long run() { - return new Long(file.length()); - } - }, controlContext).longValue(); - } - - /** - * Returns the canonical path of a file. Same as calling - * file.getCanonicalPath(). - * @param file a file object - * @return the canonical path of a file. - * @throws IOException on error - */ - public String getCanonicalPath(final File file) throws IOException { - if (System.getSecurityManager() == null) - return file.getCanonicalPath(); - try { - return AccessController.doPrivileged(new PrivilegedExceptionAction<String>() { - public String run() throws IOException { - return file.getCanonicalPath(); - } - }, controlContext); - } catch (PrivilegedActionException e) { - if (e.getException() instanceof IOException) - throw (IOException) e.getException(); - throw (RuntimeException) e.getException(); - } - } - - /** - * Returns the absolute file. Same as calling - * file.getAbsoluteFile(). - * @param file a file object - * @return the absolute file. - */ - public File getAbsoluteFile(final File file) { - if (System.getSecurityManager() == null) - return file.getAbsoluteFile(); - return AccessController.doPrivileged(new PrivilegedAction<File>() { - public File run() { - return file.getAbsoluteFile(); - } - }, controlContext); - } - - /** - * Returns the canonical file. Same as calling - * file.getCanonicalFile(). - * @param file a file object - * @return the canonical file. - */ - public File getCanonicalFile(final File file) throws IOException { - if (System.getSecurityManager() == null) - return file.getCanonicalFile(); - try { - return AccessController.doPrivileged(new PrivilegedExceptionAction<File>() { - public File run() throws IOException { - return file.getCanonicalFile(); - } - }, controlContext); - } catch (PrivilegedActionException e) { - if (e.getException() instanceof IOException) - throw (IOException) e.getException(); - throw (RuntimeException) e.getException(); - } - } - - /** - * Returns true if a file exists, otherwise false is returned. Same as calling - * file.exists(). - * @param file a file object - * @return true if a file exists, otherwise false - */ - public boolean exists(final File file) { - if (System.getSecurityManager() == null) - return file.exists(); - return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { - public Boolean run() { - return file.exists() ? Boolean.TRUE : Boolean.FALSE; - } - }, controlContext).booleanValue(); - } - - public boolean mkdirs(final File file) { - if (System.getSecurityManager() == null) - return file.mkdirs(); - return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { - public Boolean run() { - return file.mkdirs() ? Boolean.TRUE : Boolean.FALSE; - } - }, controlContext).booleanValue(); - } - - /** - * Returns true if a file is a directory, otherwise false is returned. Same as calling - * file.isDirectory(). - * @param file a file object - * @return true if a file is a directory, otherwise false - */ - public boolean isDirectory(final File file) { - if (System.getSecurityManager() == null) - return file.isDirectory(); - return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { - public Boolean run() { - return file.isDirectory() ? Boolean.TRUE : Boolean.FALSE; - } - }, controlContext).booleanValue(); - } - - /** - * Returns a file's last modified stamp. Same as calling - * file.lastModified(). - * @param file a file object - * @return a file's last modified stamp. - */ - public long lastModified(final File file) { - if (System.getSecurityManager() == null) - return file.lastModified(); - return AccessController.doPrivileged(new PrivilegedAction<Long>() { - public Long run() { - return new Long(file.lastModified()); - } - }, controlContext).longValue(); - } - - /** - * Returns a file's list. Same as calling - * file.list(). - * @param file a file object - * @return a file's list. - */ - public String[] list(final File file) { - if (System.getSecurityManager() == null) - return file.list(); - return AccessController.doPrivileged(new PrivilegedAction<String[]>() { - public String[] run() { - return file.list(); - } - }, controlContext); - } - - /** - * Returns a ZipFile. Same as calling - * new ZipFile(file) - * @param file the file to get a ZipFile for - * @return a ZipFile - * @throws IOException if an error occured - */ - public ZipFile getZipFile(final File file) throws IOException { - try { - if (System.getSecurityManager() == null) - return new ZipFile(file); - try { - return AccessController.doPrivileged(new PrivilegedExceptionAction<ZipFile>() { - public ZipFile run() throws IOException { - return new ZipFile(file); - } - }, controlContext); - } catch (PrivilegedActionException e) { - if (e.getException() instanceof IOException) - throw (IOException) e.getException(); - throw (RuntimeException) e.getException(); - } - } catch (ZipException e) { - ZipException zipNameException = new ZipException("Exception in opening zip file: " + file.getPath()); //$NON-NLS-1$ - zipNameException.initCause(e); - throw zipNameException; - } catch (IOException e) { - IOException fileNameException = new IOException("Exception in opening zip file: " + file.getPath()); //$NON-NLS-1$ - fileNameException.initCause(e); - throw fileNameException; - } - } - - /** - * Gets a URL. Same a calling - * {@link URL#URL(java.lang.String, java.lang.String, int, java.lang.String, java.net.URLStreamHandler)} - * @param protocol the protocol - * @param host the host - * @param port the port - * @param file the file - * @param handler the URLStreamHandler - * @return a URL - * @throws MalformedURLException - */ - public URL getURL(final String protocol, final String host, final int port, final String file, final URLStreamHandler handler) throws MalformedURLException { - if (System.getSecurityManager() == null) - return new URL(protocol, host, port, file, handler); - try { - return AccessController.doPrivileged(new PrivilegedExceptionAction<URL>() { - public URL run() throws MalformedURLException { - return new URL(protocol, host, port, file, handler); - } - }, controlContext); - } catch (PrivilegedActionException e) { - if (e.getException() instanceof MalformedURLException) - throw (MalformedURLException) e.getException(); - throw (RuntimeException) e.getException(); - } - } - - /** - * Creates a new Thread from a Runnable. Same as calling - * new Thread(target,name).setContextClassLoader(contextLoader). - * @param target the Runnable to create the Thread from. - * @param name The name of the Thread. - * @param contextLoader the context class loader for the thread - * @return The new Thread - */ - public Thread createThread(final Runnable target, final String name, final ClassLoader contextLoader) { - if (System.getSecurityManager() == null) - return createThread0(target, name, contextLoader); - return AccessController.doPrivileged(new PrivilegedAction<Thread>() { - public Thread run() { - return createThread0(target, name, contextLoader); - } - }, controlContext); - } - - Thread createThread0(Runnable target, String name, ClassLoader contextLoader) { - Thread result = new Thread(target, name); - if (contextLoader != null) - result.setContextClassLoader(contextLoader); - return result; - } - - /** - * Gets a service object. Same as calling - * context.getService(reference) - * @param reference the ServiceReference - * @param context the BundleContext - * @return a service object - */ - public <S> S getService(final ServiceReference<S> reference, final BundleContext context) { - if (System.getSecurityManager() == null) - return context.getService(reference); - return AccessController.doPrivileged(new PrivilegedAction<S>() { - public S run() { - return context.getService(reference); - } - }, controlContext); - } - - /** - * Returns a Class. Same as calling - * Class.forName(name) - * @param name the name of the class. - * @return a Class - * @throws ClassNotFoundException - */ - public Class<?> forName(final String name) throws ClassNotFoundException { - if (System.getSecurityManager() == null) - return Class.forName(name); - try { - return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() { - public Class<?> run() throws Exception { - return Class.forName(name); - } - }, controlContext); - } catch (PrivilegedActionException e) { - if (e.getException() instanceof ClassNotFoundException) - throw (ClassNotFoundException) e.getException(); - throw (RuntimeException) e.getException(); - } - } - - /** - * Returns a Class. - * Tries to load a class from the System ClassLoader or if that doesn't exist tries the boot ClassLoader - * @param name the name of the class. - * @return a Class - * @throws ClassNotFoundException - */ - public Class<?> loadSystemClass(final String name) throws ClassNotFoundException { - if (System.getSecurityManager() == null) { - ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); - return (systemClassLoader != null) ? systemClassLoader.loadClass(name) : bootClassLoader.loadClass(name); - } - try { - return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() { - public Class<?> run() throws Exception { - ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); - return (systemClassLoader != null) ? systemClassLoader.loadClass(name) : bootClassLoader.loadClass(name); - } - }, controlContext); - } catch (PrivilegedActionException e) { - if (e.getException() instanceof ClassNotFoundException) - throw (ClassNotFoundException) e.getException(); - throw (RuntimeException) e.getException(); - } - } - - /** - * Opens a ServiceTracker. Same as calling tracker.open() - * @param tracker the ServiceTracker to open. - */ - public void open(final ServiceTracker<?, ?> tracker) { - if (System.getSecurityManager() == null) { - tracker.open(); - return; - } - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - tracker.open(); - return null; - } - }, controlContext); - } - - /** - * Starts a module. - * @param module the module to start - * @param options the start options - * @throws BundleException - */ - public void start(final Module module, final Module.StartOptions... options) throws BundleException { - if (System.getSecurityManager() == null) { - module.start(options); - return; - } - try { - AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { - public Object run() throws BundleException { - module.start(options); - return null; - } - }, controlContext); - return; - } catch (PrivilegedActionException e) { - if (e.getException() instanceof BundleException) - throw (BundleException) e.getException(); - throw (RuntimeException) e.getException(); - } - } - - public BundleContext getContext(final Bundle bundle) { - if (System.getSecurityManager() == null) { - return bundle.getBundleContext(); - } - return AccessController.doPrivileged(new PrivilegedAction<BundleContext>() { - public BundleContext run() { - return bundle.getBundleContext(); - } - }, controlContext); - } -} diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/debug/Debug.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/debug/Debug.java deleted file mode 100644 index ced7f37cc..000000000 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/debug/Debug.java +++ /dev/null @@ -1,379 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.osgi.internal.debug; - -import java.io.PrintStream; -import java.lang.reflect.*; -import org.eclipse.osgi.internal.framework.EquinoxContainer; -import org.eclipse.osgi.service.debug.DebugOptions; - -/** - * This class has debug constants which can be used by the Framework implementation - * and Adaptor implementations - * @since 3.1 - */ -public class Debug { - /** - * Base debug option key (org.eclispe.osgi). - */ - public static final String ECLIPSE_OSGI = EquinoxContainer.NAME; - /** - * General Debug option key. - */ - public static final String OPTION_DEBUG_GENERAL = ECLIPSE_OSGI + "/debug"; //$NON-NLS-1$ - /** - * Bundle time Debug option key. - */ - // TODO remove this or use it somewhere - public static final String OPTION_DEBUG_BUNDLE_TIME = ECLIPSE_OSGI + "/debug/bundleTime"; //$NON-NLS-1$ - /** - * Loader Debug option key. - */ - public static final String OPTION_DEBUG_LOADER = ECLIPSE_OSGI + "/debug/loader"; //$NON-NLS-1$ - /** - * Events Debug option key. - */ - public static final String OPTION_DEBUG_EVENTS = ECLIPSE_OSGI + "/debug/events"; //$NON-NLS-1$ - /** - * Services Debug option key. - */ - public static final String OPTION_DEBUG_SERVICES = ECLIPSE_OSGI + "/debug/services"; //$NON-NLS-1$ - /** - * Services Debug option key. - */ - public static final String OPTION_DEBUG_HOOKS = ECLIPSE_OSGI + "/debug/hooks"; //$NON-NLS-1$ - /** - * Packages Debug option key. - */ - public static final String OPTION_DEBUG_PACKAGES = ECLIPSE_OSGI + "/debug/packages"; //$NON-NLS-1$ - /** - * Manifest Debug option key. - */ - public static final String OPTION_DEBUG_MANIFEST = ECLIPSE_OSGI + "/debug/manifest"; //$NON-NLS-1$ - /** - * Filter Debug option key. - */ - public static final String OPTION_DEBUG_FILTER = ECLIPSE_OSGI + "/debug/filter"; //$NON-NLS-1$ - /** - * Security Debug option key. - */ - public static final String OPTION_DEBUG_SECURITY = ECLIPSE_OSGI + "/debug/security"; //$NON-NLS-1$ - /** - * Start level Debug option key. - */ - public static final String OPTION_DEBUG_STARTLEVEL = ECLIPSE_OSGI + "/debug/startlevel"; //$NON-NLS-1$ - /** - * PackageAdmin Debug option key. - */ - public static final String OPTION_DEBUG_PACKAGEADMIN = ECLIPSE_OSGI + "/debug/packageadmin"; //$NON-NLS-1$ - /** - * PackageAdmin timing Debug option key. - */ - public static final String OPTION_DEBUG_PACKAGEADMIN_TIMING = ECLIPSE_OSGI + "/debug/packageadmin/timing"; //$NON-NLS-1$ - /** - * Monitor activation Debug option key. - */ - public static final String OPTION_MONITOR_ACTIVATION = ECLIPSE_OSGI + "/monitor/activation"; //$NON-NLS-1$ - /** - * Message bundles Debug option key. - */ - public static final String OPTION_DEBUG_MESSAGE_BUNDLES = ECLIPSE_OSGI + "/debug/messageBundles"; //$NON-NLS-1$ - - public static final String OPTION_DEBUG_LOCATION = ECLIPSE_OSGI + "/debug/location"; //$NON-NLS-1$ - - /** - * Indicates if tracing is enabled - */ - public boolean DEBUG_ENABLED = false; - - // these static debug options are left overs because it would be messy to fix references to them - // this means that if multiple frameworks are using this class these debug options may get overwritten - public static boolean STATIC_DEBUG_GENERAL = false; // "debug" - public static boolean STATIC_DEBUG_MANIFEST = false; // "debug.manifest" - public static boolean STATIC_DEBUG_MESSAGE_BUNDLES = false; //"/debug/messageBundles" - - /** - * General debug flag. - */ - public boolean DEBUG_GENERAL = false; // "debug" - /** - * Bundle time debug flag. - */ - public boolean DEBUG_BUNDLE_TIME = false; //"debug.bundleTime" - /** - * Loader debug flag. - */ - public boolean DEBUG_LOADER = false; // "debug.loader" - /** - * Events debug flag. - */ - public boolean DEBUG_EVENTS = false; // "debug.events" - /** - * Services debug flag. - */ - public boolean DEBUG_SERVICES = false; // "debug.services" - - /** - * Hooks debug flag. - */ - public boolean DEBUG_HOOKS = false; // "debug.hooks" - /** - * Packages debug flag. - */ - // TODO remove this or use it somewhere - public boolean DEBUG_PACKAGES = false; // "debug.packages" - /** - * Manifest debug flag. - */ - public boolean DEBUG_MANIFEST = false; // "debug.manifest" - /** - * Filter debug flag. - */ - public boolean DEBUG_FILTER = false; // "debug.filter" - /** - * Security debug flag. - */ - public boolean DEBUG_SECURITY = false; // "debug.security" - /** - * Start level debug flag. - */ - public boolean DEBUG_STARTLEVEL = false; // "debug.startlevel" - /** - * PackageAdmin debug flag. - */ - public boolean DEBUG_PACKAGEADMIN = false; // "debug.packageadmin" - /** - * PackageAdmin timing debug flag. - */ - // TODO remove this or use it somewhere - public boolean DEBUG_PACKAGEADMIN_TIMING = false; //"debug.packageadmin/timing" - /** - * Message debug flag. - */ - public boolean DEBUG_MESSAGE_BUNDLES = false; //"/debug/messageBundles" - /** - * Monitor activation debug flag. - */ - public boolean MONITOR_ACTIVATION = false; // "monitor/bundles" - - public boolean DEBUG_LOCATION = false; // debug/location - - public Debug(DebugOptions dbgOptions) { - if (dbgOptions == null) { - return; - } - DEBUG_ENABLED = dbgOptions.isDebugEnabled(); - DEBUG_GENERAL = dbgOptions.getBooleanOption(OPTION_DEBUG_GENERAL, false); - STATIC_DEBUG_GENERAL = DEBUG_GENERAL; - DEBUG_BUNDLE_TIME = dbgOptions.getBooleanOption(OPTION_DEBUG_BUNDLE_TIME, false) || dbgOptions.getBooleanOption("org.eclipse.core.runtime/timing/startup", false); //$NON-NLS-1$ - DEBUG_LOADER = dbgOptions.getBooleanOption(OPTION_DEBUG_LOADER, false); - DEBUG_EVENTS = dbgOptions.getBooleanOption(OPTION_DEBUG_EVENTS, false); - DEBUG_SERVICES = dbgOptions.getBooleanOption(OPTION_DEBUG_SERVICES, false); - DEBUG_HOOKS = dbgOptions.getBooleanOption(OPTION_DEBUG_HOOKS, false); - DEBUG_PACKAGES = dbgOptions.getBooleanOption(OPTION_DEBUG_PACKAGES, false); - DEBUG_MANIFEST = dbgOptions.getBooleanOption(OPTION_DEBUG_MANIFEST, false); - STATIC_DEBUG_MANIFEST = DEBUG_MANIFEST; - DEBUG_FILTER = dbgOptions.getBooleanOption(OPTION_DEBUG_FILTER, false); - DEBUG_SECURITY = dbgOptions.getBooleanOption(OPTION_DEBUG_SECURITY, false); - DEBUG_STARTLEVEL = dbgOptions.getBooleanOption(OPTION_DEBUG_STARTLEVEL, false); - DEBUG_PACKAGEADMIN = dbgOptions.getBooleanOption(OPTION_DEBUG_PACKAGEADMIN, false); - DEBUG_PACKAGEADMIN_TIMING = dbgOptions.getBooleanOption(OPTION_DEBUG_PACKAGEADMIN_TIMING, false) || dbgOptions.getBooleanOption("org.eclipse.core.runtime/debug", false); //$NON-NLS-1$ - DEBUG_MESSAGE_BUNDLES = dbgOptions.getBooleanOption(OPTION_DEBUG_MESSAGE_BUNDLES, false); - STATIC_DEBUG_MESSAGE_BUNDLES = DEBUG_MESSAGE_BUNDLES; - MONITOR_ACTIVATION = dbgOptions.getBooleanOption(OPTION_MONITOR_ACTIVATION, false); - DEBUG_LOCATION = dbgOptions.getBooleanOption(OPTION_DEBUG_LOCATION, false); - } - - /** - * The PrintStream to print debug messages to. - */ - public static PrintStream out = System.out; - - /** - * Prints x to the PrintStream - * @param x - */ - public static void print(boolean x) { - out.print(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void print(char x) { - out.print(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void print(int x) { - out.print(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void print(long x) { - out.print(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void print(float x) { - out.print(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void print(double x) { - out.print(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void print(char x[]) { - out.print(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void print(String x) { - out.print(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void print(Object x) { - out.print(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void println(boolean x) { - out.println(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void println(char x) { - out.println(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void println(int x) { - out.println(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void println(long x) { - out.println(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void println(float x) { - out.println(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void println(double x) { - out.println(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void println(char x[]) { - out.println(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void println(String x) { - out.println(x); - } - - /** - * Prints x to the PrintStream - * @param x - */ - public static void println(Object x) { - out.println(x); - } - - /** - * Prints t to the PrintStream - * @param t - */ - public static void printStackTrace(Throwable t) { - if (t == null) - return; - t.printStackTrace(out); - - Method[] methods = t.getClass().getMethods(); - - int size = methods.length; - Class<?> throwable = Throwable.class; - - for (int i = 0; i < size; i++) { - Method method = methods[i]; - - if (Modifier.isPublic(method.getModifiers()) && method.getName().startsWith("get") && throwable.isAssignableFrom(method.getReturnType()) && (method.getParameterTypes().length == 0)) { //$NON-NLS-1$ - try { - Throwable nested = (Throwable) method.invoke(t, (Object[]) null); - - if ((nested != null) && (nested != t)) { - out.println("Nested Exception:"); //$NON-NLS-1$ - printStackTrace(nested); - } - } catch (IllegalAccessException e) { - // nothing - } catch (InvocationTargetException e) { - // nothing - } - } - } - } - -} diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/debug/EclipseDebugTrace.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/debug/EclipseDebugTrace.java deleted file mode 100644 index 09cc632d4..000000000 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/debug/EclipseDebugTrace.java +++ /dev/null @@ -1,672 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.osgi.internal.debug; - -import java.io.*; -import java.security.AccessController; -import java.text.MessageFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import org.eclipse.osgi.framework.util.SecureAction; -import org.eclipse.osgi.service.debug.DebugTrace; - -/** - * The DebugTrace implementation for Eclipse. - */ -class EclipseDebugTrace implements DebugTrace { - - /** The system property used to specify size a trace file can grow before it is rotated */ - private static final String PROP_TRACE_SIZE_MAX = "eclipse.trace.size.max"; //$NON-NLS-1$ - /** The system property used to specify the maximum number of backup trace files to use */ - private static final String PROP_TRACE_FILE_MAX = "eclipse.trace.backup.max"; //$NON-NLS-1$ - /** The trace message for a thread stack dump */ - private final static String MESSAGE_THREAD_DUMP = "Thread Stack dump: "; //$NON-NLS-1$ - /** The trace message for a method completing with a return value */ - private final static String MESSAGE_EXIT_METHOD_WITH_RESULTS = "Exiting method {0}with result: "; //$NON-NLS-1$ - /** The trace message for a method completing with no return value */ - private final static String MESSAGE_EXIT_METHOD_NO_RESULTS = "Exiting method {0}with a void return"; //$NON-NLS-1$ - /** The trace message for a method starting with a set of arguments */ - private final static String MESSAGE_ENTER_METHOD_WITH_PARAMS = "Entering method {0}with parameters: ("; //$NON-NLS-1$ - /** The trace message for a method starting with no arguments */ - private final static String MESSAGE_ENTER_METHOD_NO_PARAMS = "Entering method {0}with no parameters"; //$NON-NLS-1$ - /** The version attribute written in the header of a new session */ - private final static String TRACE_FILE_VERSION_COMMENT = "version: "; //$NON-NLS-1$ - /** The verbose attribute written in the header of a new session */ - private final static String TRACE_FILE_VERBOSE_COMMENT = "verbose: "; //$NON-NLS-1$ - /** The version value written in the header of a new session */ - private final static String TRACE_FILE_VERSION = "1.1"; //$NON-NLS-1$ - /** The new session identifier to be written whenever a new session starts */ - private final static String TRACE_NEW_SESSION = "!SESSION "; //$NON-NLS-1$ - /** The date attribute written to the header of the trace file to show when this file was created */ - private final static String TRACE_FILE_DATE = "Time of creation: "; //$NON-NLS-1$ - /** Trace date formatter using the pattern: yyyy-MM-dd HH:mm:ss.SSS */ - private final static SimpleDateFormat TRACE_FILE_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); //$NON-NLS-1$ - /** The comment character used by the trace file */ - private final static String TRACE_COMMENT = "#"; //$NON-NLS-1$ - /** The delimiter used to separate trace elements such as the time stamp, message, etc */ - private final static String TRACE_ELEMENT_DELIMITER = "|"; //$NON-NLS-1$ - /** The string written in place of the {@link EclipseDebugTrace#TRACE_TRACE_ELEMENT_DELIMITER} in entries */ - private final static String TRACE_ELEMENT_DELIMITER_ENCODED = "|"; //$NON-NLS-1$ - /** OS-specific line separator */ - private static final String LINE_SEPARATOR; - static { - String s = System.getProperty("line.separator"); //$NON-NLS-1$ - LINE_SEPARATOR = s == null ? "\n" : s; //$NON-NLS-1$ - } - /** The value written to the trace file if a null object is being traced */ - private final static String NULL_VALUE = "<null>"; //$NON-NLS-1$ - /** */ - private final static SecureAction secureAction = AccessController.doPrivileged(SecureAction.createSecureAction()); - /** A lock object used to synchronize access to the trace file */ - private final static Object writeLock = new Object(); - - /******************* Tracing file attributes **************************/ - /** The default size a trace file can grow before it is rotated */ - private static final int DEFAULT_TRACE_FILE_SIZE = 1000; // The value is in KB. - /** The default number of backup trace files */ - private static final int DEFAULT_TRACE_FILES = 10; - /** The minimum size limit for trace file rotation */ - private static final int DEFAULT_TRACE_FILE_MIN_SIZE = 10; - /** The extension used for log files */ - private static final String TRACE_FILE_EXTENSION = ".trace"; //$NON-NLS-1$ - /** The extension markup to use for backup log files*/ - private static final String BACKUP_MARK = ".bak_"; //$NON-NLS-1$ - /** The maximum size that a trace file should grow (0 = unlimited) */ - private int maxTraceFileSize = DEFAULT_TRACE_FILE_SIZE; // The value is in KB. - /** The maximum number of trace files that should be saved */ - private int maxTraceFiles = DEFAULT_TRACE_FILES; - /** The index of the currently backed-up trace file */ - private int backupTraceFileIndex = 0; - - /** An optional argument to specify the name of the class used by clients to trace messages. If no trace class is specified - * then the class calling this API is assumed to be the class being traced. - */ - private String traceClass = null; - /** The symbolic name of the bundle being traced */ - private String bundleSymbolicName = null; - /** A flag to determine if the message being written is done to a new file (i.e. should the header information be written) */ - static boolean newSession = true; - /** DebugOptions are used to determine if the specified bundle symbolic name + option-path has debugging enabled */ - private FrameworkDebugOptions debugOptions = null; - - /** - * Construct a new EclipseDebugTrace for the specified bundle symbolic name and write messages to the specified - * trace file. The DebugOptions object will be used to determine if tracing should occur. - * - * @param bundleSymbolicName The symbolic name of the bundle being traced - * @param debugOptions Used to determine if the specified bundle symbolic name + option-path has tracing enabled - */ - EclipseDebugTrace(final String bundleSymbolicName, final FrameworkDebugOptions debugOptions) { - - this(bundleSymbolicName, debugOptions, null); - } - - /** - * Construct a new EclipseDebugTrace for the specified bundle symbolic name and write messages to the specified - * trace file. - * - * @param bundleSymbolicName The symbolic name of the bundle being traced - * @param debugOptions Used to determine if the specified bundle symbolic name + option-path has tracing enabled - * @param traceClass The class that the client is using to perform trace API calls - */ - EclipseDebugTrace(final String bundleSymbolicName, final FrameworkDebugOptions debugOptions, final Class<?> traceClass) { - - this.traceClass = traceClass != null ? traceClass.getName() : null; - this.debugOptions = debugOptions; - this.bundleSymbolicName = bundleSymbolicName; - readLogProperties(); - } - - /** - * Is debugging enabled for the specified option-path - * - * @param optionPath The <i>option-path</i> - * @return Returns true if debugging is enabled for the specified option-path on this bundle; Otherwise false. - */ - private final boolean isDebuggingEnabled(final String optionPath) { - if (optionPath == null) - return true; - boolean debugEnabled = false; - if (debugOptions.isDebugEnabled()) { - final String option = bundleSymbolicName + optionPath; - debugEnabled = debugOptions.getBooleanOption(option, false); - } - return debugEnabled; - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.framework.debug.FrameworkDebugTrace#trace(java.lang.String, java.lang.String) - */ - public void trace(final String optionPath, final String message) { - - if (isDebuggingEnabled(optionPath)) { - final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, message, traceClass); - writeRecord(record); - } - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.framework.debug.FrameworkDebugTrace#trace(java.lang.String, java.lang.String, java.lang.Throwable) - */ - public void trace(final String optionPath, final String message, final Throwable error) { - - if (isDebuggingEnabled(optionPath)) { - final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, message, error, traceClass); - writeRecord(record); - } - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.framework.debug.FrameworkDebugTrace#traceEntry(java.lang.String) - */ - public void traceEntry(final String optionPath) { - - if (isDebuggingEnabled(optionPath)) { - final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, null, traceClass); - setMessage(record, EclipseDebugTrace.MESSAGE_ENTER_METHOD_NO_PARAMS); - writeRecord(record); - } - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.framework.debug.FrameworkDebugTrace#traceEntry(java.lang.String, java.lang.Object) - */ - public void traceEntry(final String optionPath, final Object methodArgument) { - - if (isDebuggingEnabled(optionPath)) { - traceEntry(optionPath, new Object[] {methodArgument}); - } - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.framework.debug.FrameworkDebugTrace#traceEntry(java.lang.String, java.lang.Object[]) - */ - public void traceEntry(final String optionPath, final Object[] methodArguments) { - - if (isDebuggingEnabled(optionPath)) { - final StringBuffer messageBuffer = new StringBuffer(EclipseDebugTrace.MESSAGE_ENTER_METHOD_WITH_PARAMS); - if (methodArguments != null) { - int i = 0; - while (i < methodArguments.length) { - if (methodArguments[i] != null) { - messageBuffer.append(methodArguments[i].toString()); - } else { - messageBuffer.append(EclipseDebugTrace.NULL_VALUE); - } - i++; - if (i < methodArguments.length) { - messageBuffer.append(" "); //$NON-NLS-1$ - } - } - messageBuffer.append(")"); //$NON-NLS-1$ - } - final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, null, traceClass); - setMessage(record, messageBuffer.toString()); - writeRecord(record); - } - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.framework.debug.FrameworkDebugTrace#traceExit(java.lang.String) - */ - public void traceExit(final String optionPath) { - - if (isDebuggingEnabled(optionPath)) { - final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, null, traceClass); - setMessage(record, EclipseDebugTrace.MESSAGE_EXIT_METHOD_NO_RESULTS); - writeRecord(record); - } - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.framework.debug.FrameworkDebugTrace#traceExit(java.lang.String, java.lang.Object) - */ - public void traceExit(final String optionPath, final Object result) { - - if (isDebuggingEnabled(optionPath)) { - final StringBuffer messageBuffer = new StringBuffer(EclipseDebugTrace.MESSAGE_EXIT_METHOD_WITH_RESULTS); - if (result == null) { - messageBuffer.append(EclipseDebugTrace.NULL_VALUE); - } else { - messageBuffer.append(result.toString()); - } - final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, null, traceClass); - setMessage(record, messageBuffer.toString()); - writeRecord(record); - } - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.framework.debug.FrameworkDebugTrace#traceDumpStack(java.lang.String) - */ - public void traceDumpStack(final String optionPath) { - - if (isDebuggingEnabled(optionPath)) { - final StringBuffer messageBuffer = new StringBuffer(EclipseDebugTrace.MESSAGE_THREAD_DUMP); - StackTraceElement[] elements = new Exception().getStackTrace(); - // the first element in this stack trace is going to be this class, so ignore it - // the second element in this stack trace is going to either be the caller or the trace class. Ignore it only if a traceClass is defined - // the rest of the elements should be included in the file array - int firstIndex = (traceClass == null) ? 1 : 2; - int endIndex = elements.length - firstIndex; - final StackTraceElement[] newElements = new StackTraceElement[endIndex]; - int i = 0; - while (i < endIndex) { - newElements[i] = elements[firstIndex]; - i++; - firstIndex++; - } - messageBuffer.append(convertStackTraceElementsToString(newElements)); - final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, messageBuffer.toString(), traceClass); - writeRecord(record); - } - } - - /** - * Set the trace message for the specified record to include class and method information - * if verbose debugging is disabled. - * - * @param record The {@link FrameworkDebugTraceEntry} containing the information to persist to the trace file. - * @param originalMessage The original tracing message - */ - private final void setMessage(final FrameworkDebugTraceEntry record, final String originalMessage) { - - String argument = null; - if (!debugOptions.isVerbose()) { - final StringBuffer classMethodName = new StringBuffer(record.getClassName()); - classMethodName.append("#"); //$NON-NLS-1$ - classMethodName.append(record.getMethodName()); - classMethodName.append(" "); //$NON-NLS-1$ - argument = classMethodName.toString(); - } else { - argument = ""; //$NON-NLS-1$ - } - String newMessage = MessageFormat.format(originalMessage, new Object[] {argument}); - record.setMessage(newMessage); - } - - /** - * Utility method to convert an array of StackTraceElement objects to form a String representation of a stack dump - * - * @param elements - * The array of StackTraceElement objects - * @return A String of the stack dump produced by the list of elements - */ - private final String convertStackTraceElementsToString(final StackTraceElement[] elements) { - - final StringBuffer buffer = new StringBuffer(); - if (elements != null) { - buffer.append("java.lang.Throwable: "); //$NON-NLS-1$ - buffer.append(EclipseDebugTrace.LINE_SEPARATOR); - int i = 0; - while (i < elements.length) { - if (elements[i] != null) { - buffer.append("\tat "); //$NON-NLS-1$ - buffer.append(elements[i].toString()); - buffer.append(EclipseDebugTrace.LINE_SEPARATOR); - } - i++; - } - } - return buffer.toString(); - } - - /** - * Write the specified FrameworkTraceEntry to trace file - * - * @param entry The FrameworkTraceEntry to write to the log file. - */ - private void writeRecord(final FrameworkDebugTraceEntry entry) { - - if (entry != null) { - synchronized (EclipseDebugTrace.writeLock) { - final File tracingFile = debugOptions.getFile(); // the tracing file may be null if it has not been set - Writer traceWriter = null; - try { - // check to see if the file should be rotated - checkTraceFileSize(tracingFile, entry.getTimestamp()); - // open the trace file - traceWriter = openWriter(tracingFile); - if (EclipseDebugTrace.newSession) { - writeSession(traceWriter, entry.getTimestamp()); - EclipseDebugTrace.newSession = false; - } - writeMessage(traceWriter, entry); - // flush the writer - traceWriter.flush(); - } catch (Exception ex) { - // any exceptions during tracing should be caught - System.err.println("An exception occurred while writing to the platform trace file: ");//$NON-NLS-1$ - ex.printStackTrace(System.err); - } finally { - // close the trace writer - if (tracingFile != null) { - closeWriter(traceWriter); - } - } - } - } - } - - /** - * Reads the PROP_TRACE_SIZE_MAX and PROP_TRACE_FILE_MAX properties. - */ - private void readLogProperties() { - - String newMaxTraceFileSize = debugOptions.getConfiguration().getConfiguration(PROP_TRACE_SIZE_MAX); - if (newMaxTraceFileSize != null) { - maxTraceFileSize = Integer.parseInt(newMaxTraceFileSize); - if (maxTraceFileSize != 0 && maxTraceFileSize < DEFAULT_TRACE_FILE_MIN_SIZE) { - // If the value is '0', then it means no size limitation. - // Also, make sure no inappropriate(too small) assigned value. - maxTraceFileSize = DEFAULT_TRACE_FILE_MIN_SIZE; - } - } - - String newMaxLogFiles = debugOptions.getConfiguration().getConfiguration(PROP_TRACE_FILE_MAX); - if (newMaxLogFiles != null) { - maxTraceFiles = Integer.parseInt(newMaxLogFiles); - if (maxTraceFiles < 1) { - // Make sure no invalid assigned value. (at least >= 1) - maxTraceFiles = DEFAULT_TRACE_FILES; - } - } - } - - /** - * Checks the trace file size. If the file size reaches the limit then the trace file is rotated. - * - * @param traceFile The tracing file - * @param timestamp the timestamp for the session; this is the same timestamp as the first entry - * @return false if an error occurred trying to rotate the trace file - */ - private boolean checkTraceFileSize(final File traceFile, long timestamp) { - - // 0 file size means there is no size limit - boolean isBackupOK = true; - if (maxTraceFileSize > 0) { - if ((traceFile != null) && traceFile.exists()) { - if ((traceFile.length() >> 10) > maxTraceFileSize) { // Use KB as file size unit. - final String traceFileName = traceFile.getAbsolutePath(); - - // Delete old backup file that will be replaced. - String backupFilename = ""; //$NON-NLS-1$ - if (traceFileName.toLowerCase().endsWith(TRACE_FILE_EXTENSION)) { - backupFilename = traceFileName.substring(0, traceFileName.length() - TRACE_FILE_EXTENSION.length()) + BACKUP_MARK + backupTraceFileIndex + TRACE_FILE_EXTENSION; - } else { - backupFilename = traceFileName + BACKUP_MARK + backupTraceFileIndex; - } - final File backupFile = new File(backupFilename); - if (backupFile.exists()) { - if (!backupFile.delete()) { - System.err.println("Error when trying to delete old trace file: " + backupFile.getName());//$NON-NLS-1$ - if (backupFile.renameTo(new File(backupFile.getAbsolutePath() + System.currentTimeMillis()))) { - System.err.println("So we rename it to filename: " + backupFile.getName()); //$NON-NLS-1$ - } else { - System.err.println("And we also cannot rename it!"); //$NON-NLS-1$ - isBackupOK = false; - } - } - } - - // Rename current log file to backup one. - boolean isRenameOK = traceFile.renameTo(backupFile); - if (!isRenameOK) { - System.err.println("Error when trying to rename trace file to backup one."); //$NON-NLS-1$ - isBackupOK = false; - } - /* - * Write a header to new log file stating that this new file is a continuation file. - * This method should already be called with the file lock set so we should be safe - * to update it here. - */ - Writer traceWriter = null; - try { - traceWriter = openWriter(traceFile); - writeComment(traceWriter, "This is a continuation of trace file " + backupFile.getAbsolutePath()); //$NON-NLS-1$ - writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_VERSION_COMMENT + EclipseDebugTrace.TRACE_FILE_VERSION); - writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_VERBOSE_COMMENT + debugOptions.isVerbose()); - writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_DATE + getFormattedDate(timestamp)); - traceWriter.flush(); - } catch (IOException ioEx) { - ioEx.printStackTrace(); - } finally { - if (traceFile != null) { - closeWriter(traceWriter); - } - } - backupTraceFileIndex = (++backupTraceFileIndex) % maxTraceFiles; - } - } - } - return isBackupOK; - } - - /** - * Writes a comment to the trace file - * - * @param traceWriter the trace writer - * @param comment the comment to be written to the trace file - * @throws IOException If an error occurs while writing the comment - */ - private void writeComment(final Writer traceWriter, final String comment) throws IOException { - - StringBuffer commentText = new StringBuffer(EclipseDebugTrace.TRACE_COMMENT); - commentText.append(" "); //$NON-NLS-1$ - commentText.append(comment); - commentText.append(EclipseDebugTrace.LINE_SEPARATOR); - traceWriter.write(commentText.toString()); - } - - /** - * Accessor to retrieve the time stamp in a formatted manner. - * - * @return A formatted time stamp based on the {@link EclipseDebugTrace#TRACE_FILE_DATE_FORMATTER} formatter - */ - private final String getFormattedDate(long timestamp) { - - return EclipseDebugTrace.TRACE_FILE_DATE_FORMATTER.format(new Date(timestamp)); - } - - /** - * Accessor to retrieve the text of a {@link Throwable} in a formatted manner so that it can be written to the - * trace file. - * - * @param error The {@lnk Throwable} to format - * @return The complete text of a {@link Throwable} as a {@link String} or null if the input error is null. - */ - private final String getFormattedThrowable(Throwable error) { - - String result = null; - if (error != null) { - PrintStream throwableStream = null; - try { - ByteArrayOutputStream throwableByteOutputStream = new ByteArrayOutputStream(); - throwableStream = new PrintStream(throwableByteOutputStream, false); - error.printStackTrace(throwableStream); - result = encodeText(throwableByteOutputStream.toString()); - } finally { - if (throwableStream != null) { - throwableStream.close(); - } - } - } - return result; - } - - /** - * Writes header information to a new trace file - * - * @param traceWriter the trace writer - * @param timestamp the timestamp for the session; this is the same timestamp as the first entry - * @throws IOException If an error occurs while writing this session information - */ - private void writeSession(final Writer traceWriter, long timestamp) throws IOException { - - writeComment(traceWriter, EclipseDebugTrace.TRACE_NEW_SESSION + this.getFormattedDate(timestamp)); - writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_VERSION_COMMENT + EclipseDebugTrace.TRACE_FILE_VERSION); - writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_VERBOSE_COMMENT + debugOptions.isVerbose()); - writeComment(traceWriter, "The following option strings are specified for this debug session:"); //$NON-NLS-1$ - final String[] allOptions = debugOptions.getAllOptions(); - for (int i = 0; i < allOptions.length; i++) { - writeComment(traceWriter, "\t" + allOptions[i]); //$NON-NLS-1$ - } - } - - /** - * Writes the specified trace entry object to the trace file using the - * {@link EclipseDebugTrace#TRACE_ELEMENT_DELIMITER} as the delimiter between - * each element of the entry. - * - * @param traceWriter the trace writer - * @param entry The trace entry object to write to the trace file - * @throws IOException If an error occurs while writing this message - */ - private void writeMessage(final Writer traceWriter, final FrameworkDebugTraceEntry entry) throws IOException { - - final StringBuffer message = new StringBuffer(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER); - message.append(" "); //$NON-NLS-1$ - message.append(encodeText(entry.getThreadName())); - message.append(" "); //$NON-NLS-1$ - message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER); - message.append(" "); //$NON-NLS-1$ - message.append(this.getFormattedDate(entry.getTimestamp())); - message.append(" "); //$NON-NLS-1$ - message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER); - message.append(" "); //$NON-NLS-1$ - if (!debugOptions.isVerbose()) { - // format the trace entry for quiet tracing: only the thread name, timestamp, trace message, and exception (if necessary) - message.append(encodeText(entry.getMessage())); - } else { - // format the trace entry for verbose tracing - message.append(entry.getBundleSymbolicName()); - message.append(" "); //$NON-NLS-1$ - message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER); - message.append(" "); //$NON-NLS-1$ - message.append(encodeText(entry.getOptionPath())); - message.append(" "); //$NON-NLS-1$ - message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER); - message.append(" "); //$NON-NLS-1$ - message.append(entry.getClassName()); - message.append(" "); //$NON-NLS-1$ - message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER); - message.append(" "); //$NON-NLS-1$ - message.append(entry.getMethodName()); - message.append(" "); //$NON-NLS-1$ - message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER); - message.append(" "); //$NON-NLS-1$ - message.append(entry.getLineNumber()); - message.append(" "); //$NON-NLS-1$ - message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER); - message.append(" "); //$NON-NLS-1$ - message.append(encodeText(entry.getMessage())); - } - if (entry.getThrowable() != null) { - message.append(" "); //$NON-NLS-1$ - message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER); - message.append(" "); //$NON-NLS-1$ - message.append(this.getFormattedThrowable(entry.getThrowable())); - } - message.append(" "); //$NON-NLS-1$ - message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER); - message.append(EclipseDebugTrace.LINE_SEPARATOR); - // write the message - if ((traceWriter != null) && (message != null)) { - traceWriter.write(message.toString()); - } - } - - /** - * Encodes the specified string to replace any occurrence of the {@link EclipseDebugTrace#TRACE_ELEMENT_DELIMITER} - * string with the {@link EclipseDebugTrace#TRACE_ELEMENT_DELIMITER_ENCODED} - * string. This can be used to ensure that the delimiter character does not break parsing when - * the entry text contains the delimiter character. - * - * @param inputString The original string to be written to the trace file. - * @return The original input string with all occurrences of - * {@link EclipseDebugTrace#TRACE_ELEMENT_DELIMITER} replaced with - * {@link EclipseDebugTrace#TRACE_ELEMENT_DELIMITER_ENCODED}. A <code>null</code> value will be - * returned if the input string is <code>null</code>. - */ - private static String encodeText(final String inputString) { - if (inputString == null || inputString.indexOf(TRACE_ELEMENT_DELIMITER) < 0) - return inputString; - final StringBuffer tempBuffer = new StringBuffer(inputString); - int currentIndex = tempBuffer.indexOf(TRACE_ELEMENT_DELIMITER); - while (currentIndex >= 0) { - tempBuffer.replace(currentIndex, currentIndex + TRACE_ELEMENT_DELIMITER.length(), TRACE_ELEMENT_DELIMITER_ENCODED); - currentIndex = tempBuffer.indexOf(TRACE_ELEMENT_DELIMITER); - } - return tempBuffer.toString(); - } - - /** - * Returns a Writer for the given OutputStream - * @param output an OutputStream to use for the Writer - * @return A Writer for the given OutputStream - */ - private Writer logForStream(OutputStream output) { - - try { - return new BufferedWriter(new OutputStreamWriter(output, "UTF-8")); //$NON-NLS-1$ - } catch (UnsupportedEncodingException e) { - return new BufferedWriter(new OutputStreamWriter(output)); - } - } - - /** - * Creates the trace writer. - * If the tracing file is null then the writer will use System.out to print any messages. - * - * @param traceFile The tracing file - * @return Returns a new Writer object - */ - private Writer openWriter(final File traceFile) { - - Writer traceWriter = null; - if (traceFile != null) { - try { - traceWriter = logForStream(secureAction.getFileOutputStream(traceFile, true)); - } catch (IOException ioEx) { - traceWriter = logForStream(System.out); - } - } else { - traceWriter = logForStream(System.out); - } - return traceWriter; - } - - /** - * Close the trace writer - * - * @param traceWriter The trace writer - */ - private void closeWriter(Writer traceWriter) { - - if (traceWriter != null) { - try { - traceWriter.close(); - } catch (IOException ioEx) { - // we cannot log here; just print the stacktrace. - ioEx.printStackTrace(); - } - traceWriter = null; - } - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/debug/FrameworkDebugOptions.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/debug/FrameworkDebugOptions.java deleted file mode 100644 index 7c6c13ed7..000000000 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/debug/FrameworkDebugOptions.java +++ /dev/null @@ -1,501 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2013 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.osgi.internal.debug; - -import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.*; -import org.eclipse.osgi.internal.framework.EquinoxConfiguration; -import org.eclipse.osgi.service.debug.*; -import org.osgi.framework.*; -import org.osgi.util.tracker.ServiceTracker; -import org.osgi.util.tracker.ServiceTrackerCustomizer; - -/** - * The DebugOptions implementation class that allows accessing the list of debug options specified - * for the application as well as creating {@link DebugTrace} objects for the purpose of having - * dynamic enablement of debug tracing. - * - * @since 3.1 - */ -public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustomizer<DebugOptionsListener, DebugOptionsListener> { - - private static final String OSGI_DEBUG = "osgi.debug"; //$NON-NLS-1$ - private static final String OSGI_DEBUG_VERBOSE = "osgi.debug.verbose"; //$NON-NLS-1$ - public static final String PROP_TRACEFILE = "osgi.tracefile"; //$NON-NLS-1$ - /** The default name of the .options file if loading when the -debug command-line argument is used */ - private static final String OPTIONS = ".options"; //$NON-NLS-1$ - - /** monitor used to lock the options maps */ - private final Object lock = new Object(); - /** A current map of all the options with values set */ - private Properties options = null; - /** A map of all the disabled options with values set at the time debug was disabled */ - private Properties disabledOptions = null; - /** A cache of all of the bundles <code>DebugTrace</code> in the format <key,value> --> <bundle name, DebugTrace> */ - protected final Map<String, DebugTrace> debugTraceCache = new HashMap<String, DebugTrace>(); - /** The File object to store messages. This value may be null. */ - protected File outFile = null; - /** Is verbose debugging enabled? Changing this value causes a new tracing session to start. */ - protected boolean verboseDebug = true; - private final EquinoxConfiguration environmentInfo; - private volatile BundleContext context; - private volatile ServiceTracker<DebugOptionsListener, DebugOptionsListener> listenerTracker; - - public FrameworkDebugOptions(EquinoxConfiguration environmentInfo) { - this.environmentInfo = environmentInfo; - // check if verbose debugging was set during initialization. This needs to be set even if debugging is disabled - this.verboseDebug = Boolean.valueOf(environmentInfo.getConfiguration(OSGI_DEBUG_VERBOSE, Boolean.TRUE.toString())).booleanValue(); - // if no debug option was specified, don't even bother to try. - // Must ensure that the options slot is null as this is the signal to the - // platform that debugging is not enabled. - String debugOptionsFilename = environmentInfo.getConfiguration(OSGI_DEBUG); - if (debugOptionsFilename == null) - return; - options = new Properties(); - URL optionsFile; - if (debugOptionsFilename.length() == 0) { - // default options location is user.dir (install location may be r/o so - // is not a good candidate for a trace options that need to be updatable by - // by the user) - String userDir = System.getProperty("user.dir").replace(File.separatorChar, '/'); //$NON-NLS-1$ - if (!userDir.endsWith("/")) //$NON-NLS-1$ - userDir += "/"; //$NON-NLS-1$ - debugOptionsFilename = new File(userDir, OPTIONS).toString(); - } - optionsFile = buildURL(debugOptionsFilename, false); - if (optionsFile == null) { - System.out.println("Unable to construct URL for options file: " + debugOptionsFilename); //$NON-NLS-1$ - return; - } - System.out.print("Debug options:\n " + optionsFile.toExternalForm()); //$NON-NLS-1$ - try { - InputStream input = optionsFile.openStream(); - try { - options.load(input); - System.out.println(" loaded"); //$NON-NLS-1$ - } finally { - input.close(); - } - } catch (FileNotFoundException e) { - System.out.println(" not found"); //$NON-NLS-1$ - } catch (IOException e) { - System.out.println(" did not parse"); //$NON-NLS-1$ - e.printStackTrace(System.out); - } - // trim off all the blanks since properties files don't do that. - for (Object key : options.keySet()) { - options.put(key, ((String) options.get(key)).trim()); - } - } - - public void start(BundleContext bc) { - this.context = bc; - listenerTracker = new ServiceTracker<DebugOptionsListener, DebugOptionsListener>(bc, DebugOptionsListener.class.getName(), this); - listenerTracker.open(); - } - - public void stop(BundleContext bc) { - listenerTracker.close(); - listenerTracker = null; - this.context = null; - } - - @SuppressWarnings("deprecation") - private static URL buildURL(String spec, boolean trailingSlash) { - if (spec == null) - return null; - boolean isFile = spec.startsWith("file:"); //$NON-NLS-1$ - try { - if (isFile) - return adjustTrailingSlash(new File(spec.substring(5)).toURL(), trailingSlash); - return new URL(spec); - } catch (MalformedURLException e) { - // if we failed and it is a file spec, there is nothing more we can do - // otherwise, try to make the spec into a file URL. - if (isFile) - return null; - try { - return adjustTrailingSlash(new File(spec).toURL(), trailingSlash); - } catch (MalformedURLException e1) { - return null; - } - } - } - - private static URL adjustTrailingSlash(URL url, boolean trailingSlash) throws MalformedURLException { - String file = url.getFile(); - if (trailingSlash == (file.endsWith("/"))) //$NON-NLS-1$ - return url; - file = trailingSlash ? file + "/" : file.substring(0, file.length() - 1); //$NON-NLS-1$ - return new URL(url.getProtocol(), url.getHost(), file); - } - - /** - * @see DebugOptions#getBooleanOption(String, boolean) - */ - public boolean getBooleanOption(String option, boolean defaultValue) { - String optionValue = getOption(option); - return optionValue != null ? optionValue.equalsIgnoreCase("true") : defaultValue; //$NON-NLS-1$ - } - - /** - * @see DebugOptions#getOption(String) - */ - public String getOption(String option) { - return getOption(option, null); - } - - /** - * @see DebugOptions#getOption(String, String) - */ - public String getOption(String option, String defaultValue) { - synchronized (lock) { - if (options != null) { - return options.getProperty(option, defaultValue); - } - } - return defaultValue; - } - - /** - * @see DebugOptions#getIntegerOption(String, int) - */ - public int getIntegerOption(String option, int defaultValue) { - String value = getOption(option); - try { - return value == null ? defaultValue : Integer.parseInt(value); - } catch (NumberFormatException e) { - return defaultValue; - } - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - public Map<String, String> getOptions() { - Map<String, String> snapShot = new HashMap<String, String>(); - synchronized (lock) { - if (options != null) - snapShot.putAll((Map) options); - else if (disabledOptions != null) - snapShot.putAll((Map) disabledOptions); - } - return snapShot; - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.service.debug.DebugOptions#getAllOptions() - */ - String[] getAllOptions() { - - String[] optionsArray = null; - synchronized (lock) { - if (options != null) { - optionsArray = new String[options.size()]; - final Iterator<Map.Entry<Object, Object>> entrySetIterator = options.entrySet().iterator(); - int i = 0; - while (entrySetIterator.hasNext()) { - Map.Entry<Object, Object> entry = entrySetIterator.next(); - optionsArray[i] = ((String) entry.getKey()) + "=" + ((String) entry.getValue()); //$NON-NLS-1$ - i++; - } - } - } - if (optionsArray == null) { - optionsArray = new String[1]; // TODO this is strange; null is the only element so we can print null in writeSession - } - return optionsArray; - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.service.debug.DebugOptions#removeOption(java.lang.String) - */ - public void removeOption(String option) { - if (option == null) - return; - String fireChangedEvent = null; - synchronized (lock) { - if (options != null && options.remove(option) != null) { - fireChangedEvent = getSymbolicName(option); - } - } - // Send the options change event outside the sync block - if (fireChangedEvent != null) { - optionsChanged(fireChangedEvent); - } - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.service.debug.DebugOptions#setOption(java.lang.String, java.lang.String) - */ - public void setOption(String option, String value) { - - if (option == null || value == null) { - throw new IllegalArgumentException("The option and value must not be null."); //$NON-NLS-1$ - } - String fireChangedEvent = null; - value = value != null ? value.trim() : null; - synchronized (lock) { - if (options != null) { - // get the current value - String currentValue = options.getProperty(option); - - if (currentValue != null) { - if (!currentValue.equals(value)) { - fireChangedEvent = getSymbolicName(option); - } - } else { - if (value != null) { - fireChangedEvent = getSymbolicName(option); - } - } - if (fireChangedEvent != null) { - options.put(option, value); - } - } - } - // Send the options change event outside the sync block - if (fireChangedEvent != null) { - optionsChanged(fireChangedEvent); - } - } - - private String getSymbolicName(String option) { - int firstSlashIndex = option.indexOf("/"); //$NON-NLS-1$ - if (firstSlashIndex > 0) - return option.substring(0, firstSlashIndex); - return null; - } - - @SuppressWarnings("cast") - public void setOptions(Map<String, String> ops) { - if (ops == null) - throw new IllegalArgumentException("The options must not be null."); //$NON-NLS-1$ - Properties newOptions = new Properties(); - for (Iterator<Map.Entry<String, String>> entries = ops.entrySet().iterator(); entries.hasNext();) { - Map.Entry<String, String> entry = entries.next(); - if (!(entry.getKey() instanceof String) || !(entry.getValue() instanceof String)) - throw new IllegalArgumentException("Option keys and values must be of type String: " + entry.getKey() + "=" + entry.getValue()); //$NON-NLS-1$ //$NON-NLS-2$ - newOptions.put(entry.getKey(), entry.getValue().trim()); - } - Set<String> fireChangesTo = null; - - synchronized (lock) { - if (options == null) { - disabledOptions = newOptions; - // no events to fire - return; - } - fireChangesTo = new HashSet<String>(); - // first check for removals - for (Iterator<Object> keys = options.keySet().iterator(); keys.hasNext();) { - String key = (String) keys.next(); - if (!newOptions.containsKey(key)) { - String symbolicName = getSymbolicName(key); - if (symbolicName != null) - fireChangesTo.add(symbolicName); - } - } - // now check for changes to existing values - for (Iterator<Map.Entry<Object, Object>> newEntries = newOptions.entrySet().iterator(); newEntries.hasNext();) { - Map.Entry<Object, Object> entry = newEntries.next(); - String existingValue = (String) options.get(entry.getKey()); - if (!entry.getValue().equals(existingValue)) { - String symbolicName = getSymbolicName((String) entry.getKey()); - if (symbolicName != null) - fireChangesTo.add(symbolicName); - } - } - // finally set the actual options - options = newOptions; - } - if (fireChangesTo != null) - for (Iterator<String> iChanges = fireChangesTo.iterator(); iChanges.hasNext();) - optionsChanged(iChanges.next()); - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.service.debug.DebugOptions#isDebugEnabled() - */ - public boolean isDebugEnabled() { - synchronized (lock) { - return options != null; - } - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.service.debug.DebugOptions#setDebugEnabled() - */ - public void setDebugEnabled(boolean enabled) { - boolean fireChangedEvent = false; - synchronized (lock) { - if (enabled) { - if (options != null) - return; - // notify the trace that a new session is started - EclipseDebugTrace.newSession = true; - - // enable platform debugging - there is no .options file - environmentInfo.setConfiguration(OSGI_DEBUG, ""); //$NON-NLS-1$ - if (disabledOptions != null) { - options = disabledOptions; - disabledOptions = null; - // fire changed event to indicate some options were re-enabled - fireChangedEvent = true; - } else { - options = new Properties(); - } - } else { - if (options == null) - return; - // disable platform debugging. - environmentInfo.clearConfiguration(OSGI_DEBUG); - if (options.size() > 0) { - // Save the current options off in case debug is re-enabled - disabledOptions = options; - // fire changed event to indicate some options were disabled - fireChangedEvent = true; - } - options = null; - } - } - if (fireChangedEvent) { - // (Bug 300911) need to fire event to listeners that options have been disabled - optionsChanged("*"); //$NON-NLS-1$ - } - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.service.debug.DebugOptions#createTrace(java.lang.String) - */ - public final DebugTrace newDebugTrace(String bundleSymbolicName) { - - return this.newDebugTrace(bundleSymbolicName, null); - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.service.debug.DebugOptions#createTrace(java.lang.String, java.lang.Class) - */ - public final DebugTrace newDebugTrace(String bundleSymbolicName, Class<?> traceEntryClass) { - - DebugTrace debugTrace = null; - synchronized (debugTraceCache) { - debugTrace = debugTraceCache.get(bundleSymbolicName); - if (debugTrace == null) { - debugTrace = new EclipseDebugTrace(bundleSymbolicName, this, traceEntryClass); - debugTraceCache.put(bundleSymbolicName, debugTrace); - } - } - return debugTrace; - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.service.debug.DebugOptions#getFile() - */ - public final File getFile() { - - return this.outFile; - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.service.debug.DebugOptions#setFile(java.io.File) - */ - public synchronized void setFile(final File traceFile) { - - this.outFile = traceFile; - if (this.outFile != null) - environmentInfo.setConfiguration(PROP_TRACEFILE, this.outFile.getAbsolutePath()); - else - environmentInfo.clearConfiguration(PROP_TRACEFILE); - // the file changed so start a new session - EclipseDebugTrace.newSession = true; - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.service.debug.DebugOptions#getVerbose() - */ - boolean isVerbose() { - - return this.verboseDebug; - } - - EquinoxConfiguration getConfiguration() { - return this.environmentInfo; - } - - /* - * (non-Javadoc) - * @see org.eclipse.osgi.service.debug.DebugOptions#setVerbose(boolean) - */ - public synchronized void setVerbose(final boolean verbose) { - - this.verboseDebug = verbose; - // the verbose flag changed so start a new session - EclipseDebugTrace.newSession = true; - } - - /** - * Notifies the trace listener for the specified bundle that its option-path has changed. - * @param bundleSymbolicName The bundle of the owning trace listener to notify. - */ - private void optionsChanged(String bundleSymbolicName) { - // use osgi services to get the listeners - BundleContext bc = context; - if (bc == null) - return; - // do not use the service tracker because that is only used to call all listeners initially when they are registered - // here we only want the services with the specified name. - ServiceReference<?>[] listenerRefs = null; - try { - listenerRefs = bc.getServiceReferences(DebugOptionsListener.class.getName(), "(" + DebugOptions.LISTENER_SYMBOLICNAME + "=" + bundleSymbolicName + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - } catch (InvalidSyntaxException e) { - // consider logging; should not happen - } - if (listenerRefs == null) - return; - for (int i = 0; i < listenerRefs.length; i++) { - DebugOptionsListener service = (DebugOptionsListener) bc.getService(listenerRefs[i]); - if (service == null) - continue; - try { - service.optionsChanged(this); - } catch (Throwable t) { - // TODO consider logging - } finally { - bc.ungetService(listenerRefs[i]); - } - } - } - - public DebugOptionsListener addingService(ServiceReference<DebugOptionsListener> reference) { - DebugOptionsListener listener = context.getService(reference); - listener.optionsChanged(this); - return listener; - } - - public void modifiedService(ServiceReference<DebugOptionsListener> reference, DebugOptionsListener service) { - // nothing - } - - public void removedService(ServiceReference<DebugOptionsListener> reference, DebugOptionsListener service) { - context.ungetService(reference); - } -} diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/debug/FrameworkDebugTraceEntry.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/debug/FrameworkDebugTraceEntry.java deleted file mode 100644 index 98678539c..000000000 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/debug/FrameworkDebugTraceEntry.java +++ /dev/null @@ -1,276 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.osgi.internal.debug; - -/** - * A framework trace entry is a bean containing all of the attributes for a single trace message. - */ -public class FrameworkDebugTraceEntry { - /** If a bundles symbolic name is not specified then the default value of /debug can be used */ - public final static String DEFAULT_OPTION_PATH = "/debug"; //$NON-NLS-1$ - - /** - * The name of the thread executing the code - */ - private final String threadName; - - /** - * The date and time when the trace occurred. - * - */ - private final long timestamp; - - /** - * The trace option-path - */ - private final String optionPath; - - /** - * The symbolic name of the bundle being traced - */ - private final String bundleSymbolicName; - - /** - * The class being traced - */ - private final String className; - - /** - * The method being traced - */ - private final String methodName; - - /** - * The line number - */ - private final int lineNumber; - - /** - * The trace message - */ - private String message; - - /** - * The trace exception - */ - private final Throwable throwable; - - /** - * Construct a new FrameworkTraceRecord object - * - * @param bundleSymbolicName - * The symbolic name of the bundle being traced - * @param optionPath - * The trace optionPath - * @param message - * The trace message - * @param traceClass - * The class that calls the trace API - */ - public FrameworkDebugTraceEntry(final String bundleSymbolicName, final String optionPath, final String message, final String traceClass) { - this(bundleSymbolicName, optionPath, message, null, traceClass); - } - - /** - * Construct a new FrameworkTraceRecord object - * - * @param bundleSymbolicName - * The symbolic name of the bundle being traced - * @param optionPath - * The trace optionPath - * @param message - * The trace message - * @param error - * An exception to be traced - * @param traceClass - * The class that calls the trace API - */ - public FrameworkDebugTraceEntry(String bundleSymbolicName, final String optionPath, final String message, final Throwable error, final String traceClass) { - threadName = Thread.currentThread().getName(); - if (optionPath == null) { - this.optionPath = FrameworkDebugTraceEntry.DEFAULT_OPTION_PATH; - } else { - this.optionPath = optionPath; - } - timestamp = System.currentTimeMillis(); - this.bundleSymbolicName = bundleSymbolicName; - this.message = message; - throwable = error; - - String determineClassName = null; - String determineMethodName = null; - int determineLineNumber = 0; - // dynamically determine the class name, method name, and line number of the method calling the trace framework - StackTraceElement[] stackElements = new Exception().getStackTrace(); - int i = 0; - while (i < stackElements.length) { - String fullClassName = stackElements[i].getClassName(); - if (!fullClassName.equals(Thread.class.getName()) && !fullClassName.equals(FrameworkDebugTraceEntry.class.getName()) && !fullClassName.equals(EclipseDebugTrace.class.getName())) { - /* - * The first class which is non-JDK or framework related has been hit. - * If a traceClass has been specified then this current stack element - * is likely that class so we should find out who called it. If a - * trace class has not been specified, or has been specified and this - * stack element is not that class, then we assume this stack element - * is the caller of the trace API. - */ - if ((traceClass == null) || !fullClassName.equals(traceClass)) { - determineClassName = stackElements[i].getClassName(); - determineMethodName = stackElements[i].getMethodName(); - determineLineNumber = stackElements[i].getLineNumber(); - break; // only break when the right stack element has been found; Otherwise keep trying - } - } - i++; - } - - className = determineClassName; - methodName = determineMethodName; - lineNumber = determineLineNumber; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - public String toString() { - - final StringBuffer buffer = new StringBuffer(threadName); - buffer.append(" "); //$NON-NLS-1$ - buffer.append(timestamp); - buffer.append(" "); //$NON-NLS-1$ - buffer.append(bundleSymbolicName); - buffer.append(" "); //$NON-NLS-1$ - buffer.append(optionPath); - buffer.append(" "); //$NON-NLS-1$ - buffer.append(className); - buffer.append(" "); //$NON-NLS-1$ - buffer.append(methodName); - buffer.append(" "); //$NON-NLS-1$ - buffer.append(lineNumber); - if (message != null) { - buffer.append(": "); //$NON-NLS-1$ - buffer.append(message); - } - if (throwable != null) { - buffer.append(throwable); - } - return buffer.toString(); - } - - /** - * Accessor to the threads name - * - * @return the name of the thread - */ - public final String getThreadName() { - - return threadName; - } - - /** - * Accessor to the timestamp for this trace record - * - * @return the date - */ - public final long getTimestamp() { - - return timestamp; - } - - /** - * Accessor for the symbolic name of the bundle being traced - * - * @return The symbolic name of the bundle being traced - */ - public final String getBundleSymbolicName() { - - return bundleSymbolicName; - } - - /** - * Accessor for the trace message - * - * @return the trace message - */ - public final String getMessage() { - - return message; - } - - /** - * Accessor for the trace exception. This may be null if there is no exception. - * - * @return the trace exception or null if none was defined. - */ - public final Throwable getThrowable() { - - return throwable; - } - - /** - * Accessor for the name of the class being traced. - * - * @return The name of the class being traced. - */ - public final String getClassName() { - - return className; - } - - /** - * Accessor for the method being traced. - * - * @return The name of the method being traced. - */ - public final String getMethodName() { - - return methodName; - } - - /** - * Accessor for the option-path being traced. The <i><option-path></i> part of the debug option string - * required for the Eclipse debugging framework. - * - * <pre> - * Examples: - * 1) If a trace string com.ibm.myplugin.core/debug=true is specified then 'debug' is the option-path value. - * 2) If a trace string com.ibm.myplugin.core/debug/perf=true is specified then 'debug/perf' is the option-path value. - * </pre> - * - * - * @return The option-path being traced. - */ - public final String getOptionPath() { - - return optionPath; - } - - /** - * Return the line number in the class/method where the trace originator - * - * @return The line number from the class and method where the trace request originated - */ - public final int getLineNumber() { - - return lineNumber; - } - - /** - * - * @param newMessage - */ - void setMessage(final String newMessage) { - - message = newMessage; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/location/BasicLocation.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/location/BasicLocation.java deleted file mode 100644 index 6cd3e9f77..000000000 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/location/BasicLocation.java +++ /dev/null @@ -1,253 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2013 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.osgi.internal.location; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import org.eclipse.osgi.framework.internal.core.Msg; -import org.eclipse.osgi.internal.framework.EquinoxConfiguration; -import org.eclipse.osgi.service.datalocation.Location; -import org.eclipse.osgi.util.NLS; - -/** - * Internal class. - */ -public class BasicLocation implements Location { - public static final String PROP_OSGI_LOCKING = "osgi.locking"; //$NON-NLS-1$ - private static String DEFAULT_LOCK_FILENAME = ".metadata/.lock"; //$NON-NLS-1$ - - static class MockLocker implements Locker { - /** - * @throws IOException - */ - public boolean lock() throws IOException { - // locking always successful - return true; - } - - public boolean isLocked() { - // this lock is never locked - return false; - } - - public void release() { - // nothing to release - } - - } - - final private boolean isReadOnly; - final private URL defaultValue; - final private String property; - final private String dataAreaPrefix; - final private EquinoxConfiguration environmentInfo; - final private boolean debug; - - private URL location = null; - private Location parent; - - // locking related fields - private File lockFile; - private Locker locker; - - public static Locker createLocker(File lock, String lockMode, boolean debug) { - if ("none".equals(lockMode)) //$NON-NLS-1$ - return new MockLocker(); - - if ("java.io".equals(lockMode)) //$NON-NLS-1$ - return new Locker_JavaIo(lock); - - if ("java.nio".equals(lockMode)) { //$NON-NLS-1$ - return new Locker_JavaNio(lock, debug); - } - - // Backup case if an invalid value has been specified - return new Locker_JavaNio(lock, debug); - } - - public BasicLocation(String property, URL defaultValue, boolean isReadOnly, String dataAreaPrefix, EquinoxConfiguration environmentInfo) { - this.property = property; - this.defaultValue = defaultValue; - this.isReadOnly = isReadOnly; - this.dataAreaPrefix = dataAreaPrefix == null ? "" : dataAreaPrefix; //$NON-NLS-1$ - this.environmentInfo = environmentInfo; - this.debug = environmentInfo.getDebug().DEBUG_LOCATION; - } - - public boolean allowsDefault() { - return defaultValue != null; - } - - public URL getDefault() { - return defaultValue; - } - - public synchronized Location getParentLocation() { - return parent; - } - - public synchronized URL getURL() { - if (location == null && defaultValue != null) - setURL(defaultValue, false); - return location; - } - - public synchronized boolean isSet() { - return location != null; - } - - public boolean isReadOnly() { - return isReadOnly; - } - - /** - * @deprecated - */ - public boolean setURL(URL value, boolean lock) throws IllegalStateException { - try { - return set(value, lock); - } catch (IOException e) { - return false; - } - } - - public synchronized boolean set(URL value, boolean lock) throws IllegalStateException, IOException { - return set(value, lock, null); - } - - public synchronized boolean set(URL value, boolean lock, String lockFilePath) throws IllegalStateException, IOException { - if (location != null) - throw new IllegalStateException(Msg.ECLIPSE_CANNOT_CHANGE_LOCATION); - File file = null; - if (value.getProtocol().equalsIgnoreCase("file")) { //$NON-NLS-1$ - try { - String basePath = new File(value.getFile()).getCanonicalPath(); - value = LocationHelper.buildURL("file:" + basePath, true); //$NON-NLS-1$ - } catch (IOException e) { - // do nothing just use the original value - } - if (lockFilePath != null && lockFilePath.length() > 0) { - File givenLockFile = new File(lockFilePath); - if (givenLockFile.isAbsolute()) { - file = givenLockFile; - } else { - file = new File(value.getFile(), lockFilePath); - } - } else { - file = new File(value.getFile(), DEFAULT_LOCK_FILENAME); - } - } - lock = lock && !isReadOnly; - if (lock) { - if (!lock(file, value)) - return false; - } - lockFile = file; - location = value; - if (property != null) - environmentInfo.setConfiguration(property, location.toExternalForm()); - return lock; - } - - public synchronized void setParent(Location value) { - parent = value; - } - - public synchronized boolean lock() throws IOException { - if (!isSet()) - throw new IOException(Msg.location_notSet); - return lock(lockFile, location); - } - - public synchronized boolean isLocked() throws IOException { - if (!isSet()) - return false; - return isLocked(lockFile); - } - - /* - * This must be called while holding the synchronization lock for (this) - */ - private boolean lock(File lock, URL locationValue) throws IOException { - if (isReadOnly) - throw new IOException(NLS.bind(Msg.location_folderReadOnly, lock)); - if (lock == null) { - if (locationValue != null && !"file".equalsIgnoreCase(locationValue.getProtocol())) //$NON-NLS-1$ - throw new IOException(NLS.bind(Msg.location_notFileProtocol, locationValue)); - throw new IllegalStateException(Msg.location_noLockFile); // this is really unexpected - } - if (isLocked()) - return false; - File parentFile = new File(lock.getParent()); - if (!parentFile.exists()) - if (!parentFile.mkdirs()) - throw new IOException(NLS.bind(Msg.location_folderReadOnly, parentFile)); - - setLocker(lock); - if (locker == null) - return true; - boolean locked = false; - try { - locked = locker.lock(); - return locked; - } finally { - if (!locked) - locker = null; - } - } - - /* - * This must be called while holding the synchronization lock for (this) - */ - private boolean isLocked(File lock) throws IOException { - if (lock == null || isReadOnly) - return true; - if (!lock.exists()) - return false; - setLocker(lock); - return locker.isLocked(); - } - - /* - * This must be called while holding the synchronization lock for (this) - */ - private void setLocker(File lock) { - if (locker != null) - return; - String lockMode = environmentInfo.getConfiguration(PROP_OSGI_LOCKING); - locker = createLocker(lock, lockMode, debug); - } - - public synchronized void release() { - if (locker != null) - locker.release(); - } - - public Location createLocation(Location parentLocation, URL defaultLocation, boolean readonly) { - BasicLocation result = new BasicLocation(null, defaultLocation, readonly, dataAreaPrefix, environmentInfo); - result.setParent(parentLocation); - return result; - } - - public URL getDataArea(String filename) throws IOException { - URL base = getURL(); - if (base == null) - throw new IOException(Msg.location_notSet); - String prefix = base.toExternalForm(); - if (prefix.length() > 0 && prefix.charAt(prefix.length() - 1) != '/') - prefix += '/'; - filename = filename.replace('\\', '/'); - if (filename.length() > 0 && filename.charAt(0) == '/') - filename.substring(1); - return new URL(prefix + dataAreaPrefix + filename); - } -} diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/location/LocationHelper.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/location/LocationHelper.java index a8ee6af5c..84f39b660 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/location/LocationHelper.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/location/LocationHelper.java @@ -13,11 +13,14 @@ package org.eclipse.osgi.internal.location; import java.io.File; import java.net.MalformedURLException; import java.net.URL; +import org.eclipse.osgi.internal.location.Locker.MockLocker; /** * @since 3.3 */ public class LocationHelper { + public static final String PROP_OSGI_LOCKING = "osgi.locking"; //$NON-NLS-1$ + /** * Builds a URL with the given specification * @param spec the URL specification @@ -56,4 +59,18 @@ public class LocationHelper { return new URL(url.getProtocol(), url.getHost(), file); } + public static Locker createLocker(File lock, String lockMode, boolean debug) { + if ("none".equals(lockMode)) //$NON-NLS-1$ + return new MockLocker(); + + if ("java.io".equals(lockMode)) //$NON-NLS-1$ + return new Locker_JavaIo(lock); + + if ("java.nio".equals(lockMode)) { //$NON-NLS-1$ + return new Locker_JavaNio(lock, debug); + } + + // Backup case if an invalid value has been specified + return new Locker_JavaNio(lock, debug); + } } diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/location/Locker.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/location/Locker.java index 91c224e7d..b79130599 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/location/Locker.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/location/Locker.java @@ -21,4 +21,24 @@ public interface Locker { public boolean isLocked() throws IOException; public void release(); + + static class MockLocker implements Locker { + /** + * @throws IOException + */ + public boolean lock() throws IOException { + // locking always successful + return true; + } + + public boolean isLocked() { + // this lock is never locked + return false; + } + + public void release() { + // nothing to release + } + + } } diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/location/Locker_JavaNio.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/location/Locker_JavaNio.java index 1ac9bd4a5..c70fbd07a 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/location/Locker_JavaNio.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/location/Locker_JavaNio.java @@ -45,7 +45,7 @@ public class Locker_JavaNio implements Locker { if (debug) System.out.println(NLS.bind(Msg.location_cannotLock, lockFile)); // produce a more specific message for clients - String specificMessage = NLS.bind(Msg.location_cannotLockNIO, new Object[] {lockFile, ioe.getMessage(), "\"-D" + BasicLocation.PROP_OSGI_LOCKING + "=none\""}); //$NON-NLS-1$ //$NON-NLS-2$ + String specificMessage = NLS.bind(Msg.location_cannotLockNIO, new Object[] {lockFile, ioe.getMessage(), "\"-D" + LocationHelper.PROP_OSGI_LOCKING + "=none\""}); //$NON-NLS-1$ //$NON-NLS-2$ throw new IOException(specificMessage); } catch (OverlappingFileLockException e) { // handle it as null result @@ -95,7 +95,7 @@ public class Locker_JavaNio implements Locker { if (debug) System.out.println(NLS.bind(Msg.location_cannotLock, lockFile)); // produce a more specific message for clients - String specificMessage = NLS.bind(Msg.location_cannotLockNIO, new Object[] {lockFile, ioe.getMessage(), "\"-D" + BasicLocation.PROP_OSGI_LOCKING + "=none\""}); //$NON-NLS-1$ //$NON-NLS-2$ + String specificMessage = NLS.bind(Msg.location_cannotLockNIO, new Object[] {lockFile, ioe.getMessage(), "\"-D" + LocationHelper.PROP_OSGI_LOCKING + "=none\""}); //$NON-NLS-1$ //$NON-NLS-2$ throw new IOException(specificMessage); } if (tempLock != null) { diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/util/SupplementDebug.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/util/SupplementDebug.java new file mode 100644 index 000000000..e77d03694 --- /dev/null +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/internal/util/SupplementDebug.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2013 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.osgi.internal.util; + +public final class SupplementDebug { + + private SupplementDebug() { + // prevent construction + } + + // these static debug options are left overs because it would be messy to fix references to them + // this means that if multiple frameworks are using this class these debug options may get overwritten + /** + * Manifest debug flag. + */ + public static boolean STATIC_DEBUG_MANIFEST = false; // "debug.manifest" + /** + * Message debug flag. + */ + public static boolean STATIC_DEBUG_MESSAGE_BUNDLES = false; //"/debug/messageBundles" +} diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/storagemanager/StorageManager.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/storagemanager/StorageManager.java index c09511280..240a9cd38 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/storagemanager/StorageManager.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/storagemanager/StorageManager.java @@ -11,12 +11,10 @@ package org.eclipse.osgi.storagemanager; import java.io.*; -import java.security.AccessController; import java.util.*; import org.eclipse.osgi.framework.internal.core.Msg; import org.eclipse.osgi.framework.internal.reliablefile.*; -import org.eclipse.osgi.framework.util.SecureAction; -import org.eclipse.osgi.internal.location.BasicLocation; +import org.eclipse.osgi.internal.location.LocationHelper; import org.eclipse.osgi.internal.location.Locker; /** @@ -88,16 +86,15 @@ import org.eclipse.osgi.internal.location.Locker; public final class StorageManager { private static final int FILETYPE_STANDARD = 0; private static final int FILETYPE_RELIABLEFILE = 1; - private static final SecureAction secure = AccessController.doPrivileged(SecureAction.createSecureAction()); private static final String MANAGER_FOLDER = ".manager"; //$NON-NLS-1$ private static final String TABLE_FILE = ".fileTable"; //$NON-NLS-1$ private static final String LOCK_FILE = ".fileTableLock"; //$NON-NLS-1$ private static final int MAX_LOCK_WAIT = 5000; // 5 seconds // these should be static but the tests expect to be able to create new managers after changing this setting dynamically - private final boolean useReliableFiles = Boolean.valueOf(secure.getProperty("osgi.useReliableFiles")).booleanValue(); //$NON-NLS-1$ - private final boolean tempCleanup = Boolean.valueOf(secure.getProperty("osgi.embedded.cleanTempFiles")).booleanValue(); //$NON-NLS-1$ - private final boolean openCleanup = Boolean.valueOf(secure.getProperty("osgi.embedded.cleanupOnOpen")).booleanValue(); //$NON-NLS-1$ - private final boolean saveCleanup = Boolean.valueOf(secure.getProperty("osgi.embedded.cleanupOnSave")).booleanValue(); //$NON-NLS-1$ + private final boolean useReliableFiles = Boolean.valueOf(System.getProperty("osgi.useReliableFiles")).booleanValue(); //$NON-NLS-1$ + private final boolean tempCleanup = Boolean.valueOf(System.getProperty("osgi.embedded.cleanTempFiles")).booleanValue(); //$NON-NLS-1$ + private final boolean openCleanup = Boolean.valueOf(System.getProperty("osgi.embedded.cleanupOnOpen")).booleanValue(); //$NON-NLS-1$ + private final boolean saveCleanup = Boolean.valueOf(System.getProperty("osgi.embedded.cleanupOnSave")).booleanValue(); //$NON-NLS-1$ private class Entry { int readId; @@ -189,7 +186,7 @@ public final class StorageManager { return; this.instanceFile = File.createTempFile(".tmp", ".instance", managerRoot); //$NON-NLS-1$//$NON-NLS-2$ this.instanceFile.deleteOnExit(); - instanceLocker = BasicLocation.createLocker(instanceFile, lockMode, false); + instanceLocker = LocationHelper.createLocker(instanceFile, lockMode, false); instanceLocker.lock(); } @@ -384,7 +381,7 @@ public final class StorageManager { if (readOnly) return false; if (locker == null) { - locker = BasicLocation.createLocker(lockFile, lockMode, false); + locker = LocationHelper.createLocker(lockFile, lockMode, false); if (locker == null) throw new IOException(Msg.fileManager_cannotLock); } @@ -610,7 +607,7 @@ public final class StorageManager { if (files != null) { for (int i = 0; i < files.length; i++) { if (files[i].endsWith(".instance") && (instanceFile == null || !files[i].equalsIgnoreCase(instanceFile.getName()))) { //$NON-NLS-1$ - Locker tmpLocker = BasicLocation.createLocker(new File(managerRoot, files[i]), lockMode, false); + Locker tmpLocker = LocationHelper.createLocker(new File(managerRoot, files[i]), lockMode, false); if (tmpLocker.lock()) { //If I can lock it is a file that has been left behind by a crash tmpLocker.release(); diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/ManifestElement.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/ManifestElement.java index f8d3ab3e5..666129125 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/ManifestElement.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/ManifestElement.java @@ -15,7 +15,7 @@ import java.io.*; import java.util.*; import org.eclipse.osgi.framework.internal.core.Msg; import org.eclipse.osgi.framework.internal.core.Tokenizer; -import org.eclipse.osgi.internal.debug.Debug; +import org.eclipse.osgi.internal.util.SupplementDebug; import org.osgi.framework.BundleException; /** @@ -355,8 +355,8 @@ public class ManifestElement { StringBuffer headerValue = new StringBuffer(next); headerValues.add(next); - if (Debug.STATIC_DEBUG_MANIFEST) - Debug.print("parseHeader: " + next); //$NON-NLS-1$ + if (SupplementDebug.STATIC_DEBUG_MANIFEST) + System.out.print("parseHeader: " + next); //$NON-NLS-1$ boolean directive = false; char c = tokenizer.getChar(); // Header values may be a list of ';' separated values. Just append them all into one value until the first '=' or ',' @@ -379,8 +379,8 @@ public class ManifestElement { if (c == ';' || c == ',' || c == '\0') /* more */{ headerValues.add(next); headerValue.append(";").append(next); //$NON-NLS-1$ - if (Debug.STATIC_DEBUG_MANIFEST) - Debug.print(";" + next); //$NON-NLS-1$ + if (SupplementDebug.STATIC_DEBUG_MANIFEST) + System.out.print(";" + next); //$NON-NLS-1$ } } // found the header value create a manifestElement for it. @@ -413,8 +413,8 @@ public class ManifestElement { if (val == null) throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR); - if (Debug.STATIC_DEBUG_MANIFEST) - Debug.print(";" + next + "=" + val); //$NON-NLS-1$ //$NON-NLS-2$ + if (SupplementDebug.STATIC_DEBUG_MANIFEST) + System.out.print(";" + next + "=" + val); //$NON-NLS-1$ //$NON-NLS-2$ try { if (directive) manifestElement.addDirective(next, val); @@ -433,8 +433,8 @@ public class ManifestElement { } } headerElements.add(manifestElement); - if (Debug.STATIC_DEBUG_MANIFEST) - Debug.println(""); //$NON-NLS-1$ + if (SupplementDebug.STATIC_DEBUG_MANIFEST) + System.out.println(""); //$NON-NLS-1$ if (c == ',') /* another manifest element */ continue parseloop; if (c == '\0') /* end of value */ diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/NLS.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/NLS.java index d69e96403..b604a2c5c 100644 --- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/NLS.java +++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/NLS.java @@ -19,7 +19,7 @@ import java.security.PrivilegedAction; import java.util.*; import org.eclipse.osgi.framework.log.FrameworkLog; import org.eclipse.osgi.framework.log.FrameworkLogEntry; -import org.eclipse.osgi.internal.debug.Debug; +import org.eclipse.osgi.internal.util.SupplementDebug; /** * Common superclass for all message bundle classes. Provides convenience @@ -285,7 +285,7 @@ public abstract class NLS { // log it and continue. This means that the field will (most likely) be un-initialized and // will fail later in the code and if so then we will see both the NPE and this error. String value = "NLS missing message: " + field.getName() + " in: " + bundleName; //$NON-NLS-1$ //$NON-NLS-2$ - if (Debug.STATIC_DEBUG_MESSAGE_BUNDLES) + if (SupplementDebug.STATIC_DEBUG_MESSAGE_BUNDLES) System.out.println(value); log(SEVERITY_WARNING, value, null); if (!isAccessible) @@ -337,7 +337,7 @@ public abstract class NLS { } } computeMissingMessages(bundleName, clazz, fields, fieldArray, isAccessible); - if (Debug.STATIC_DEBUG_MESSAGE_BUNDLES) + if (SupplementDebug.STATIC_DEBUG_MESSAGE_BUNDLES) System.out.println("Time to load message bundle: " + bundleName + " was " + (System.currentTimeMillis() - start) + "ms."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } @@ -410,7 +410,7 @@ public abstract class NLS { return null; if (fieldObject == null) { final String msg = "NLS unused message: " + key + " in: " + bundleName;//$NON-NLS-1$ //$NON-NLS-2$ - if (Debug.STATIC_DEBUG_MESSAGE_BUNDLES) + if (SupplementDebug.STATIC_DEBUG_MESSAGE_BUNDLES) System.out.println(msg); log(SEVERITY_WARNING, msg, null); return null; |