blob: 19f027a6582ddd4f404954852c3a325f7c3e5076 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/*******************************************************************************
* Copyright (c) 2009, 2015 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
* Red Hat Inc. - Bug 460967
*******************************************************************************/
package org.eclipse.equinox.p2.internal.repository.tools;
import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
public static final String ID = "org.eclipse.equinox.p2.transformer"; //$NON-NLS-1$
private static BundleContext bundleContext;
/*
* Return the bundle context or <code>null</code>.
*/
public static BundleContext getBundleContext() {
return bundleContext;
}
/* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
bundleContext = context;
}
/* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
bundleContext = null;
}
/*
* Construct and return a URI from the given String. Log
* and return null if there was a problem.
*/
public static URI getURI(String spec) {
if (spec == null)
return null;
try {
return URIUtil.fromString(spec);
} catch (URISyntaxException e) {
LogHelper.log(new Status(IStatus.WARNING, ID, NLS.bind(Messages.unable_to_process_uri, spec), e));
}
return null;
}
/*
* Return the provisioning agent. Throw an exception if it cannot be obtained.
*/
public static IProvisioningAgent getAgent() throws ProvisionException {
IProvisioningAgent agent = ServiceHelper.getService(getBundleContext(), IProvisioningAgent.class);
if (agent == null)
throw new ProvisionException(Messages.no_provisioning_agent);
return agent;
}
/*
* Return the artifact repository manager. Throw an exception if it cannot be obtained.
*/
public static IArtifactRepositoryManager getArtifactRepositoryManager() throws ProvisionException {
IArtifactRepositoryManager manager = (IArtifactRepositoryManager) getAgent().getService(IArtifactRepositoryManager.SERVICE_NAME);
if (manager == null)
throw new ProvisionException(Messages.no_artifactRepo_manager);
return manager;
}
/*
* Return the profile registry. Throw an exception if it cannot be found.
*/
static IProfileRegistry getProfileRegistry() throws ProvisionException {
IProfileRegistry registry = (IProfileRegistry) getAgent().getService(IProfileRegistry.SERVICE_NAME);
if (registry == null)
throw new ProvisionException(Messages.no_profile_registry);
return registry;
}
/*
* Return the metadata repository manager. Throw an exception if it cannot be obtained.
*/
public static IMetadataRepositoryManager getMetadataRepositoryManager() throws ProvisionException {
IMetadataRepositoryManager manager = (IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
if (manager == null)
throw new ProvisionException(Messages.no_metadataRepo_manager);
return manager;
}
}
|