Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Lippert2008-07-04 18:57:06 +0000
committerMartin Lippert2008-07-04 18:57:06 +0000
commit2f425920ab801b833bc8828a053d8adc1e427aa3 (patch)
tree92830ad0186a56d60ad3eb58cb71098ddc8787e6 /bundles/org.eclipse.equinox.weaving.caching
parenta8ed43f1d037ff5a577f4c36d9876e874964b898 (diff)
downloadrt.equinox.bundles-2f425920ab801b833bc8828a053d8adc1e427aa3.tar.gz
rt.equinox.bundles-2f425920ab801b833bc8828a053d8adc1e427aa3.tar.xz
rt.equinox.bundles-2f425920ab801b833bc8828a053d8adc1e427aa3.zip
Bug 238730 - [aspects] rename bundles and start with new version numbering
Diffstat (limited to 'bundles/org.eclipse.equinox.weaving.caching')
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching/.classpath7
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching/.cvsignore1
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching/.options1
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching/.project28
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching/.settings/org.eclipse.jdt.core.prefs78
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching/.settings/org.eclipse.pde.core.prefs4
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching/.settings/org.eclipse.pde.prefs15
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching/META-INF/MANIFEST.MF13
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching/build.properties4
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/Activator.java108
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/BaseCachingService.java53
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/BundleCachingService.java310
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/IBundleConstants.java26
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/Log.java66
-rw-r--r--bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/SingletonCachingService.java120
15 files changed, 834 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.weaving.caching/.classpath b/bundles/org.eclipse.equinox.weaving.caching/.classpath
new file mode 100644
index 000000000..304e86186
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/bundles/org.eclipse.equinox.weaving.caching/.cvsignore b/bundles/org.eclipse.equinox.weaving.caching/.cvsignore
new file mode 100644
index 000000000..ba077a403
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching/.cvsignore
@@ -0,0 +1 @@
+bin
diff --git a/bundles/org.eclipse.equinox.weaving.caching/.options b/bundles/org.eclipse.equinox.weaving.caching/.options
new file mode 100644
index 000000000..4a1f02a72
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching/.options
@@ -0,0 +1 @@
+org.aspectj.osgi.service.caching/debug=false
diff --git a/bundles/org.eclipse.equinox.weaving.caching/.project b/bundles/org.eclipse.equinox.weaving.caching/.project
new file mode 100644
index 000000000..06b2f9f46
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.equinox.weaving.caching</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/bundles/org.eclipse.equinox.weaving.caching/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.weaving.caching/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..e46d604ee
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,78 @@
+#Sun Feb 17 19:55:33 CET 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.doc.comment.support=enabled
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning
+org.eclipse.jdt.core.compiler.problem.invalidJavadoc=ignore
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=disabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=disabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=disabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nullReference=ignore
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/bundles/org.eclipse.equinox.weaving.caching/.settings/org.eclipse.pde.core.prefs b/bundles/org.eclipse.equinox.weaving.caching/.settings/org.eclipse.pde.core.prefs
new file mode 100644
index 000000000..efde3d153
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,4 @@
+#Sun Jan 13 21:33:28 CET 2008
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
diff --git a/bundles/org.eclipse.equinox.weaving.caching/.settings/org.eclipse.pde.prefs b/bundles/org.eclipse.equinox.weaving.caching/.settings/org.eclipse.pde.prefs
new file mode 100644
index 000000000..382fc744a
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching/.settings/org.eclipse.pde.prefs
@@ -0,0 +1,15 @@
+#Sun Feb 17 19:55:59 CET 2008
+compilers.incompatible-environment=1
+compilers.p.build=1
+compilers.p.deprecated=1
+compilers.p.missing-packages=2
+compilers.p.no-required-att=0
+compilers.p.not-externalized-att=2
+compilers.p.unknown-attribute=1
+compilers.p.unknown-class=1
+compilers.p.unknown-element=1
+compilers.p.unknown-resource=1
+compilers.p.unresolved-ex-points=0
+compilers.p.unresolved-import=0
+compilers.use-project=true
+eclipse.preferences.version=1
diff --git a/bundles/org.eclipse.equinox.weaving.caching/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.weaving.caching/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..bd51e3b7b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching/META-INF/MANIFEST.MF
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.eclipse.equinox.weaving.caching
+Bundle-Version: 1.0.0.qualifier
+Bundle-Name: Standard Caching Service for Equinox Aspects (Incubation)
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-Activator: org.eclipse.equinox.weaving.internal.caching.Activator
+Import-Package: com.ibm.oti.shared;resolution:=optional,
+ org.eclipse.equinox.service.weaving,
+ org.eclipse.osgi.service.datalocation;version="1.0.0",
+ org.eclipse.osgi.service.debug;version="1.0.0",
+ org.osgi.framework;version="1.4.0"
+Export-Package: org.eclipse.equinox.weaving.internal.caching;x-friends:="org.aspectj.osgi.service.caching.test"
diff --git a/bundles/org.eclipse.equinox.weaving.caching/build.properties b/bundles/org.eclipse.equinox.weaving.caching/build.properties
new file mode 100644
index 000000000..34d2e4d2d
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/Activator.java b/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/Activator.java
new file mode 100644
index 000000000..06e3af0ef
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/Activator.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Heiko Seeberger 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:
+ * Heiko Seeberger - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.equinox.weaving.internal.caching;
+
+import org.eclipse.equinox.service.weaving.ICachingService;
+import org.eclipse.osgi.service.debug.DebugOptions;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+import com.ibm.oti.shared.Shared;
+
+/**
+ * {@link BundleActivator} for "org.aspectj.osgi.service.caching".
+ *
+ * @author Heiko Seeberger
+ */
+public class Activator implements BundleActivator {
+
+ public static boolean verbose = Boolean.getBoolean("org.aspectj.osgi.verbose");
+
+ private SingletonCachingService singletonCachingService;
+ private ServiceRegistration singletonCachingServiceRegistration;
+
+ /**
+ * Registers a new {@link SingletonCachingService} instance as OSGi service
+ * under the interface {@link ICachingService}.
+ *
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(final BundleContext bundleContext) {
+ setDebugEnabled(bundleContext);
+
+ if (shouldRegister()) {
+ if (verbose) System.err.println("[org.aspectj.osgi.service.caching] info starting standard caching service ...");
+ registerSingletonCachingService(bundleContext);
+ }
+ else {
+ if (verbose) System.err.println("[org.aspectj.osgi.service.caching] warning cannot start standard caching service on J9 VM");
+ }
+ }
+
+ private boolean shouldRegister() {
+ boolean enabled = true;
+ try {
+ Class.forName("com.ibm.oti.vm.VM"); // if this fails we are not on J9
+ boolean sharing = Shared.isSharingEnabled(); // if not using shared classes we want a different adaptor
+
+ if (sharing) {
+ enabled = false;
+ }
+ } catch (ClassNotFoundException ex) {
+ }
+
+ return enabled;
+ }
+
+ /**
+ * Shuts down the {@link SingletonCachingService}.
+ *
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(final BundleContext context) {
+ singletonCachingService.stop();
+ singletonCachingServiceRegistration.unregister();
+ if (Log.isDebugEnabled()) {
+ Log.debug("Shut down and unregistered SingletonCachingService.");
+ }
+ }
+
+ private void registerSingletonCachingService(
+ final BundleContext bundleContext) {
+ singletonCachingService = new SingletonCachingService(bundleContext);
+ singletonCachingServiceRegistration =
+ bundleContext.registerService(ICachingService.class.getName(),
+ singletonCachingService, null);
+ if (Log.isDebugEnabled()) {
+ Log.debug("Created and registered SingletonCachingService.");
+ }
+ }
+
+ private void setDebugEnabled(final BundleContext bundleContext) {
+ final ServiceReference debugOptionsReference =
+ bundleContext.getServiceReference(DebugOptions.class.getName());
+ if (debugOptionsReference != null) {
+ final DebugOptions debugOptions =
+ (DebugOptions) bundleContext.getService(debugOptionsReference);
+ if (debugOptions != null) {
+ Log.debugEnabled =
+ debugOptions.getBooleanOption(
+ "org.aspectj.osgi.service.caching/debug", true); //$NON-NLS-1$
+ }
+ }
+ if (debugOptionsReference != null) {
+ bundleContext.ungetService(debugOptionsReference);
+ }
+ }
+}
diff --git a/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/BaseCachingService.java b/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/BaseCachingService.java
new file mode 100644
index 000000000..848308e6a
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/BaseCachingService.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Heiko Seeberger 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:
+ * Heiko Seeberger - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.equinox.weaving.internal.caching;
+
+import java.net.URL;
+
+import org.eclipse.equinox.service.weaving.ICachingService;
+import org.osgi.framework.Bundle;
+
+/**
+ * Abstract superclass for {@link ICachingService}. Throws
+ * {@link UnsupportedOperationException}s for every method.
+ *
+ * @author Heiko Seeberger
+ */
+public abstract class BaseCachingService implements ICachingService {
+
+ /**
+ * @see org.eclipse.equinox.service.weaving.ICachingService#findStoredClass(java.lang.String,
+ * java.net.URL, java.lang.String)
+ */
+ public byte[] findStoredClass(final String namespace,
+ final URL sourceFileURL, final String name) {
+ throw new UnsupportedOperationException("Illegal call semantics!");
+ }
+
+ /**
+ * @see org.eclipse.equinox.service.weaving.ICachingService#getInstance(java.lang.ClassLoader,
+ * org.osgi.framework.Bundle, java.lang.String)
+ */
+ public ICachingService getInstance(final ClassLoader classLoader,
+ final Bundle bundle, final String key) {
+ throw new UnsupportedOperationException("Illegal call semantics!");
+ }
+
+ /**
+ * @see org.eclipse.equinox.service.weaving.ICachingService#storeClass(java.lang.String,
+ * java.net.URL, java.lang.Class, byte[])
+ */
+ public boolean storeClass(final String namespace, final URL sourceFileURL,
+ final Class clazz, final byte[] classbytes) {
+ throw new UnsupportedOperationException("Illegal call semantics!");
+ }
+}
diff --git a/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/BundleCachingService.java b/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/BundleCachingService.java
new file mode 100644
index 000000000..81e58a734
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/BundleCachingService.java
@@ -0,0 +1,310 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Heiko Seeberger 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:
+ * Heiko Seeberger - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.equinox.weaving.internal.caching;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.equinox.service.weaving.ICachingService;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * <p>
+ * {@link ICachingService} instantiated by {@link SingletonCachingService} for
+ * each bundle.
+ * </p>
+ * <p>
+ * The maximum number of classes cached in memory before writing to disk is
+ * definded via the system property
+ * <code>org.aspectj.osgi.service.caching.maxCachedClasses</code>. The
+ * default is 20.
+ * </p>
+ *
+ * @author Heiko Seeberger
+ */
+public class BundleCachingService extends BaseCachingService {
+
+ private static final int BUFFER_SIZE = 8 * 1024;
+ private static final Integer MAX_CACHED_CLASSES =
+ Integer.getInteger("org.aspectj.osgi.service.caching.maxCachedClasses",
+ 20);
+
+ private final Bundle bundle;
+ private final BundleContext bundleContext;
+
+ private File cache;
+ private final String cacheKey;
+
+ private final Map<String, byte[]> cachedClasses =
+ new HashMap<String, byte[]>(MAX_CACHED_CLASSES + 10);
+
+
+ /**
+ * @param bundleContext
+ * Must not be null!
+ * @param bundle
+ * Must not be null!
+ * @param key
+ * Must not be null!
+ * @throws IllegalArgumentException
+ * if given bundleContext or bundle is null.
+ */
+ public BundleCachingService(final BundleContext bundleContext,
+ final Bundle bundle, final String key) {
+
+ if (bundleContext == null) {
+ throw new IllegalArgumentException(
+ "Argument \"bundleContext\" must not be null!");
+ }
+ if (bundle == null) {
+ throw new IllegalArgumentException(
+ "Argument \"bundle\" must not be null!");
+ }
+ if (key == null) {
+ throw new IllegalArgumentException(
+ "Argument \"key\" must not be null!");
+ }
+
+ this.bundleContext = bundleContext;
+ this.bundle = bundle;
+ this.cacheKey = hashNamespace(key);
+
+ initCache();
+ }
+
+ /**
+ * @see org.eclipse.equinox.service.weaving.ICachingService#findStoredClass(java.lang.String,
+ * java.net.URL, java.lang.String)
+ */
+ @Override
+ public byte[] findStoredClass(final String namespace,
+ final URL sourceFileURL, final String name) {
+
+ if (name == null) {
+ throw new IllegalArgumentException(
+ "Argument \"name\" must not be null!");
+ }
+
+ byte[] storedClass = null;
+ if (cache != null) {
+ File cachedBytecodeFile = new File(cache, name);
+ if (cachedBytecodeFile.exists()) {
+ storedClass = read(name, cachedBytecodeFile);
+ }
+ }
+
+ if (Log.isDebugEnabled()) {
+ Log.debug(MessageFormat.format("for [{0}]: {1} {2}", bundle
+ .getSymbolicName(), ((storedClass != null) ? "Found"
+ : "Found NOT"), name));
+ }
+ return storedClass;
+ }
+
+ /**
+ * Writes the remaining cache to disk.
+ */
+ public void stop() {
+ if (cache != null) {
+ for (final String name : cachedClasses.keySet()) {
+ write(name);
+ }
+ }
+ }
+
+ /**
+ * @see org.eclipse.equinox.service.weaving.ICachingService#storeClass(java.lang.String,
+ * java.net.URL, java.lang.Class, byte[])
+ */
+ @Override
+ public boolean storeClass(final String namespace, final URL sourceFileURL,
+ final Class clazz, final byte[] classbytes) {
+
+ if (clazz == null) {
+ throw new IllegalArgumentException(
+ "Argument \"clazz\" must not be null!");
+ }
+ if (classbytes == null) {
+ throw new IllegalArgumentException(
+ "Argument \"classbytes\" must not be null!");
+ }
+
+ if (cache == null) {
+ return false;
+ }
+
+ cachedClasses.put(clazz.getName(), classbytes);
+ if (cachedClasses.size() > MAX_CACHED_CLASSES) {
+
+ final Iterator<String> names = cachedClasses.keySet().iterator();
+ while (names.hasNext()) {
+ write(names.next());
+ names.remove();
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Hash the shared class namespace using MD5
+ *
+ * @param keyToHash
+ * @return the MD5 version of the input string
+ */
+ private String hashNamespace(final String namespace) {
+ MessageDigest md = null;
+ try {
+ md = MessageDigest.getInstance("MD5");
+ }
+ catch (final NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ }
+ final byte[] bytes = md.digest(namespace.getBytes());
+ final StringBuffer result = new StringBuffer();
+ for (final byte b : bytes) {
+ int num;
+ if (b < 0) {
+ num = b + 256;
+ }
+ else {
+ num = b;
+ }
+ String s = Integer.toHexString(num);
+ while (s.length() < 2) {
+ s = "0" + s;
+ }
+ result.append(s);
+ }
+ return new String(result);
+ }
+
+ private void initCache() {
+ boolean isInitialized = false;
+ final File dataFile = bundleContext.getDataFile("");
+ if (dataFile != null) {
+ cache =
+ new File(new File(dataFile, cacheKey), bundle.getSymbolicName());
+ if (!cache.exists()) {
+ isInitialized = cache.mkdirs();
+ }
+ else {
+ isInitialized = true;
+ }
+ }
+ if (!isInitialized) {
+ Log.error("Cannot initialize cache!", null);
+ }
+ }
+
+ private byte[] read(final String name, final File file) {
+ int length = (int) file.length();
+
+ InputStream in = null;
+ try {
+ byte[] classbytes = new byte[length];
+ int bytesread = 0;
+ int readcount;
+
+ in = new FileInputStream(file);
+
+ if (length > 0) {
+ classbytes = new byte[length];
+ for (; bytesread < length; bytesread += readcount) {
+ readcount = in.read(classbytes, bytesread, length - bytesread);
+ if (readcount <= 0) /* if we didn't read anything */
+ break; /* leave the loop */
+ }
+ } else /* BundleEntry does not know its own length! */{
+ length = BUFFER_SIZE;
+ classbytes = new byte[length];
+ readloop: while (true) {
+ for (; bytesread < length; bytesread += readcount) {
+ readcount = in.read(classbytes, bytesread, length - bytesread);
+ if (readcount <= 0) /* if we didn't read anything */
+ break readloop; /* leave the loop */
+ }
+ byte[] oldbytes = classbytes;
+ length += BUFFER_SIZE;
+ classbytes = new byte[length];
+ System.arraycopy(oldbytes, 0, classbytes, 0, bytesread);
+ }
+ }
+ if (classbytes.length > bytesread) {
+ byte[] oldbytes = classbytes;
+ classbytes = new byte[bytesread];
+ System.arraycopy(oldbytes, 0, classbytes, 0, bytesread);
+ }
+ return classbytes;
+ }
+ catch (final IOException e) {
+ Log.error(MessageFormat.format(
+ "for [{0}]: Cannot read [1] from cache!", bundle
+ .getSymbolicName(), name), e);
+ return null;
+ }
+ finally {
+ if (in != null) {
+ try {
+ in.close();
+ }
+ catch (final IOException e) {
+ Log.error(MessageFormat.format(
+ "for [{0}]: Cannot close cache file for [1]!", bundle
+ .getSymbolicName(), name), e);
+ }
+ }
+ }
+ }
+
+ private void write(final String name) {
+ // TODO Think about synchronization !!!
+ FileOutputStream out = null;
+ try {
+ out = new FileOutputStream(new File(cache, name));
+ out.write(cachedClasses.get(name));
+ out.close();
+ if (Log.isDebugEnabled()) {
+ Log.debug(MessageFormat.format(
+ "for [{0}]: Written {1} to cache.", bundle
+ .getSymbolicName(), name));
+ }
+ }
+ catch (final IOException e) {
+ Log.error(MessageFormat.format(
+ "for [{0}]: Cannot write [1] to cache!", bundle
+ .getSymbolicName(), name), e);
+ }
+ finally {
+ if (out != null) {
+ try {
+ out.close();
+ }
+ catch (final IOException e) {
+ Log.error(MessageFormat.format(
+ "for [{0}]: Cannot close cache file for [1]!", bundle
+ .getSymbolicName(), name), e);
+ }
+ }
+ }
+ }
+}
diff --git a/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/IBundleConstants.java b/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/IBundleConstants.java
new file mode 100644
index 000000000..14476ceae
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/IBundleConstants.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Heiko Seeberger 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:
+ * Heiko Seeberger - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.equinox.weaving.internal.caching;
+
+/**
+ * Constants for org.aspectj.osgi.service.caching".
+ *
+ * @author Heiko Seeberger
+ */
+public interface IBundleConstants {
+
+ /**
+ * The symbolic name for this bundle: "org.aspectj.osgi.service.caching".
+ */
+ public static final String BUNDLE_SYMBOLIC_NAME =
+ "org.aspectj.osgi.service.caching"; //$NON-NLS-1$
+}
diff --git a/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/Log.java b/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/Log.java
new file mode 100644
index 000000000..7a9e2f60d
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/Log.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Heiko Seeberger 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:
+ * Heiko Seeberger - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.equinox.weaving.internal.caching;
+
+import static org.eclipse.equinox.weaving.internal.caching.IBundleConstants.BUNDLE_SYMBOLIC_NAME;
+
+/**
+ * Logging utility.
+ *
+ * @author Heiko Seeberger
+ */
+public class Log {
+
+ static boolean debugEnabled = false;
+
+ private static final String PREFIX = "[" + BUNDLE_SYMBOLIC_NAME + "] "; //$NON-NLS-1$ //$NON-NLS-2$
+
+ /**
+ * Logging debug information.
+ *
+ * @param message
+ * The tracing message, optional.
+ */
+ public static void debug(final String message) {
+ if (debugEnabled) {
+ if (message != null) {
+ System.out.println(PREFIX + message);
+ }
+ }
+ }
+
+ /**
+ * Logging an error.
+ *
+ * @param message
+ * The error message, optional.
+ * @param t
+ * The Throwable for this error, optional.
+ */
+ public static void error(final String message, final Throwable t) {
+ if (message != null) {
+ System.err.println(PREFIX + message);
+ }
+ if (t != null) {
+ t.printStackTrace(System.err);
+ }
+ }
+
+ /**
+ * Shows debug toggle state.
+ *
+ * @return true, if debug is enabled, else false.
+ */
+ public static boolean isDebugEnabled() {
+ return debugEnabled;
+ }
+}
diff --git a/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/SingletonCachingService.java b/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/SingletonCachingService.java
new file mode 100644
index 000000000..764af442c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.weaving.caching/src/org/eclipse/equinox/weaving/internal/caching/SingletonCachingService.java
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Heiko Seeberger 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:
+ * Heiko Seeberger - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.equinox.weaving.internal.caching;
+
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.equinox.service.weaving.ICachingService;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.SynchronousBundleListener;
+
+/**
+ * {@link ICachingService} used as "singleton" OSGi service by
+ * "org.aspectj.osgi".
+ *
+ * @author Heiko Seeberger
+ */
+public class SingletonCachingService extends BaseCachingService {
+
+ private final Map<String, BundleCachingService> bundleCachingServices =
+ new HashMap<String, BundleCachingService>();
+
+ private final BundleContext bundleContext;
+
+ /**
+ * @param bundleContext
+ * Must not be null!
+ * @throws IllegalArgumentException
+ * if given bundleContext is null.
+ */
+ public SingletonCachingService(final BundleContext bundleContext) {
+ if (bundleContext == null) {
+ throw new IllegalArgumentException(
+ "Argument \"bundleContext\" must not be null!");
+ }
+ this.bundleContext = bundleContext;
+
+ this.bundleContext.addBundleListener(new SynchronousBundleListener() {
+ public void bundleChanged(BundleEvent event) {
+ if (event.getType() == BundleEvent.UNINSTALLED) {
+ stopBundleCachingService(event);
+ }
+ }
+ });
+ }
+
+ /**
+ * Looks for a stored {@link BaseCachingService} for the given bundle. If
+ * this exits it is returned, else created and stored.
+ *
+ * @see org.eclipse.equinox.service.weaving.ICachingService#getInstance(java.lang.ClassLoader,
+ * org.osgi.framework.Bundle, java.lang.String)
+ */
+ @Override
+ public synchronized ICachingService getInstance(
+ final ClassLoader classLoader, final Bundle bundle, String key) {
+
+ if (bundle == null) {
+ throw new IllegalArgumentException(
+ "Argument \"bundle\" must not be null!");
+ }
+
+ BundleCachingService bundleCachingService =
+ bundleCachingServices.get(bundle.getSymbolicName());
+
+ key = key == null || key.length() == 0 ? "defaultCache" : key;
+
+ if (bundleCachingService == null) {
+
+ bundleCachingService =
+ new BundleCachingService(bundleContext, bundle, key);
+ bundleCachingServices.put(bundle.getSymbolicName(),
+ bundleCachingService);
+
+ if (Log.isDebugEnabled()) {
+ Log.debug(MessageFormat.format(
+ "Created BundleCachingService for [{0}].", bundle
+ .getSymbolicName()));
+ }
+ }
+
+ return bundleCachingService;
+ }
+
+ /**
+ * Stops all individual bundle services.
+ */
+ public synchronized void stop() {
+ for (final BundleCachingService bundleCachingService : bundleCachingServices
+ .values()) {
+ bundleCachingService.stop();
+ }
+ bundleCachingServices.clear();
+ }
+
+ /**
+ * Stops individual bundle caching service if the bundle is uninstalled
+ */
+ protected void stopBundleCachingService(BundleEvent event) {
+ String symbolicName = event.getBundle().getSymbolicName();
+ BundleCachingService bundleCachingService = bundleCachingServices.get(symbolicName);
+ if (bundleCachingService != null) {
+ bundleCachingService.stop();
+ bundleCachingServices.remove(symbolicName);
+ }
+ }
+
+}

Back to the top