blob: 54c196c30144b0e8285956f45b91a4d71f02797f [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2008 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
* Code 9 - ongoing development
*******************************************************************************/
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.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
import org.osgi.framework.*;
import org.osgi.service.packageadmin.PackageAdmin;
/**
* 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;
}
public void start(BundleContext aContext) throws Exception {
context = aContext;
}
public void stop(BundleContext aContext) throws Exception {
context = null;
}
public static IArtifactRepositoryManager getArtifactRepositoryManager() {
return (IArtifactRepositoryManager) ServiceHelper.getService(context, IArtifactRepositoryManager.class.getName());
}
public static IMetadataRepositoryManager getMetadataRepositoryManager() {
return (IMetadataRepositoryManager) ServiceHelper.getService(context, IMetadataRepositoryManager.class.getName());
}
public static URI getDefaultRepositoryLocation(Object object, String repositoryName) {
PackageAdmin packageAdmin = (PackageAdmin) ServiceHelper.getService(context, PackageAdmin.class.getName());
Bundle bundle = packageAdmin.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();
}
}