Bug 544065 - Remove Activator from
org.eclipse.equinox.p2.directorywatcher

Change-Id: I38c28303d56b0025f9bf6edbd76074ddce08824a
Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.directorywatcher/META-INF/MANIFEST.MF
index 47d3167..1a42883 100644
--- a/bundles/org.eclipse.equinox.p2.directorywatcher/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.directorywatcher/META-INF/MANIFEST.MF
@@ -3,7 +3,6 @@
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.equinox.p2.directorywatcher;singleton:=true
 Bundle-Version: 1.2.200.qualifier
-Bundle-Activator: org.eclipse.equinox.internal.provisional.p2.directorywatcher.Activator
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
 Export-Package: org.eclipse.equinox.internal.provisional.p2.directorywatcher;x-friends:="org.eclipse.equinox.p2.reconciler.dropins,org.eclipse.equinox.p2.extensionlocation"
diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/Activator.java b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/Activator.java
deleted file mode 100644
index a34fb45..0000000
--- a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/Activator.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2017 IBM Corporation and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- * 
- * Contributors:
- *     IBM Corporation - initial API and implementation
- *     Code 9 - ongoing development
- *     Red Hat Inc. - Bug 460967
- *******************************************************************************/
-package org.eclipse.equinox.internal.provisional.p2.directorywatcher;
-
-import java.io.File;
-import java.net.URI;
-import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
-import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
-import org.osgi.framework.*;
-
-/**
- * Bundle activator for directory watcher bundle.
- */
-public class Activator implements BundleActivator {
-	public static final String ID = "org.eclipse.equinox.p2.directorywatcher"; //$NON-NLS-1$
-
-	private static BundleContext context;
-
-	public static BundleContext getContext() {
-		return context;
-	}
-
-	@Override
-	public void start(BundleContext aContext) throws Exception {
-		context = aContext;
-	}
-
-	@Override
-	public void stop(BundleContext aContext) throws Exception {
-		context = null;
-	}
-
-	public static IArtifactRepositoryManager getArtifactRepositoryManager() {
-		return ServiceHelper.getService(context, IProvisioningAgent.class).getService(IArtifactRepositoryManager.class);
-	}
-
-	public static IMetadataRepositoryManager getMetadataRepositoryManager() {
-		return ServiceHelper.getService(context, IProvisioningAgent.class).getService(IMetadataRepositoryManager.class);
-	}
-
-	public static URI getDefaultRepositoryLocation(Object object, String repositoryName) {
-		Bundle bundle = FrameworkUtil.getBundle(object.getClass());
-		BundleContext context = bundle.getBundleContext();
-		File base = context.getDataFile(""); //$NON-NLS-1$
-		File result = new File(base, "listener_" + repositoryName.hashCode()); //$NON-NLS-1$
-		result.mkdirs();
-		return result.toURI();
-	}
-}
diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/CachingArtifactRepository.java b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/CachingArtifactRepository.java
index 9fdd03a..104bb1e 100644
--- a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/CachingArtifactRepository.java
+++ b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/CachingArtifactRepository.java
@@ -412,9 +412,9 @@
 		try {
 			runnable.run(monitor);
 		} catch (OperationCanceledException oce) {
-			return new Status(IStatus.CANCEL, Activator.ID, oce.getMessage(), oce);
+			return new Status(IStatus.CANCEL, Constants.BUNDLE_ID, oce.getMessage(), oce);
 		} catch (Exception e) {
-			return new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e);
+			return new Status(IStatus.ERROR, Constants.BUNDLE_ID, e.getMessage(), e);
 		}
 		return Status.OK_STATUS;
 	}
diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/Constants.java b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/Constants.java
new file mode 100644
index 0000000..a1b13e3
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/Constants.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2017 IBM Corporation and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ * 
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *     Code 9 - ongoing development
+ *     Red Hat Inc. - Bug 460967
+ *******************************************************************************/
+package org.eclipse.equinox.internal.provisional.p2.directorywatcher;
+
+/**
+ * Constants interface for the bundle ID
+ */
+public interface Constants {
+	public static final String BUNDLE_ID = "org.eclipse.equinox.p2.directorywatcher"; //$NON-NLS-1$
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/RepositoryListener.java b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/RepositoryListener.java
index 0880cef..3b99982 100644
--- a/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/RepositoryListener.java
+++ b/bundles/org.eclipse.equinox.p2.directorywatcher/src/org/eclipse/equinox/internal/provisional/p2/directorywatcher/RepositoryListener.java
@@ -19,9 +19,9 @@
 import java.util.*;
 import org.eclipse.core.runtime.*;
 import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactDescriptor;
-import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
-import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
+import org.eclipse.equinox.internal.p2.core.helpers.*;
 import org.eclipse.equinox.internal.p2.update.Site;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
 import org.eclipse.equinox.p2.core.ProvisionException;
 import org.eclipse.equinox.p2.metadata.IInstallableUnit;
 import org.eclipse.equinox.p2.publisher.*;
@@ -33,6 +33,7 @@
 import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
 import org.eclipse.osgi.service.resolver.BundleDescription;
 import org.eclipse.osgi.util.NLS;
+import org.osgi.framework.*;
 
 public class RepositoryListener extends DirectoryChangeListener {
 	public static final String ARTIFACT_FOLDER = "artifact.folder"; //$NON-NLS-1$
@@ -58,7 +59,7 @@
 	 * @param properties the map of repository properties or <code>null</code>
 	 */
 	public RepositoryListener(String repositoryName, Map<String, String> properties) {
-		URI location = Activator.getDefaultRepositoryLocation(this, repositoryName);
+		URI location = getDefaultRepositoryLocation(this, repositoryName);
 		metadataRepository = initializeMetadataRepository(repositoryName, location, properties);
 		artifactRepository = initializeArtifactRepository(repositoryName, location, properties);
 		initializePublisher();
@@ -79,7 +80,7 @@
 	}
 
 	protected CachingArtifactRepository initializeArtifactRepository(String name, URI repositoryLocation, Map<String, String> properties) {
-		IArtifactRepositoryManager manager = Activator.getArtifactRepositoryManager();
+		IArtifactRepositoryManager manager = getArtifactRepositoryManager();
 		if (manager == null)
 			throw new IllegalStateException(Messages.artifact_repo_manager_not_registered);
 
@@ -99,7 +100,7 @@
 	}
 
 	protected IMetadataRepository initializeMetadataRepository(String name, URI repositoryLocation, Map<String, String> properties) {
-		IMetadataRepositoryManager manager = Activator.getMetadataRepositoryManager();
+		IMetadataRepositoryManager manager = getMetadataRepositoryManager();
 		if (manager == null)
 			throw new IllegalStateException(Messages.metadata_repo_manager_not_registered);
 
@@ -244,7 +245,7 @@
 				if (filename == null) {
 					if (Tracing.DEBUG) {
 						String message = NLS.bind(Messages.filename_missing, "artifact", descriptor.getArtifactKey()); //$NON-NLS-1$
-						LogHelper.log(new Status(IStatus.ERROR, Activator.ID, message, null));
+						LogHelper.log(new Status(IStatus.ERROR, Constants.BUNDLE_ID, message, null));
 					}
 				} else {
 					File artifactFile = new File(filename);
@@ -270,7 +271,7 @@
 				if (filename == null) {
 					if (Tracing.DEBUG) {
 						String message = NLS.bind(Messages.filename_missing, "installable unit", iu.getId()); //$NON-NLS-1$
-						LogHelper.log(new Status(IStatus.ERROR, Activator.ID, message, null));
+						LogHelper.log(new Status(IStatus.ERROR, Constants.BUNDLE_ID, message, null));
 					}
 				} else {
 					File iuFile = new File(filename);
@@ -304,4 +305,24 @@
 	public IArtifactRepository getArtifactRepository() {
 		return artifactRepository;
 	}
+
+	private static IMetadataRepositoryManager getMetadataRepositoryManager() {
+		BundleContext bundleContext = FrameworkUtil.getBundle(RepositoryListener.class).getBundleContext();
+		return ServiceHelper.getService(bundleContext, IProvisioningAgent.class).getService(IMetadataRepositoryManager.class);
+	}
+
+	private static IArtifactRepositoryManager getArtifactRepositoryManager() {
+		BundleContext bundleContext = FrameworkUtil.getBundle(RepositoryListener.class).getBundleContext();
+		return ServiceHelper.getService(bundleContext, IProvisioningAgent.class).getService(IArtifactRepositoryManager.class);
+	}
+
+	private static URI getDefaultRepositoryLocation(Object object, String repositoryName) {
+		Bundle bundle = FrameworkUtil.getBundle(object.getClass());
+		BundleContext context = bundle.getBundleContext();
+		File base = context.getDataFile(""); //$NON-NLS-1$
+		File result = new File(base, "listener_" + repositoryName.hashCode()); //$NON-NLS-1$
+		result.mkdirs();
+		return result.toURI();
+	}
+
 }