Lines 12-23
Link Here
|
12 |
*******************************************************************************/ |
12 |
*******************************************************************************/ |
13 |
package org.eclipse.equinox.internal.p2.touchpoint.eclipse; |
13 |
package org.eclipse.equinox.internal.p2.touchpoint.eclipse; |
14 |
|
14 |
|
15 |
import java.io.*; |
15 |
import java.io.File; |
|
|
16 |
import java.io.IOException; |
16 |
import java.net.*; |
17 |
import java.net.*; |
17 |
import java.util.*; |
18 |
import java.util.*; |
18 |
import org.eclipse.core.runtime.*; |
19 |
import org.eclipse.core.runtime.*; |
19 |
import org.eclipse.equinox.frameworkadmin.BundleInfo; |
20 |
import org.eclipse.equinox.frameworkadmin.BundleInfo; |
20 |
import org.eclipse.equinox.internal.p2.core.helpers.*; |
21 |
import org.eclipse.equinox.internal.p2.core.helpers.*; |
|
|
22 |
import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability; |
21 |
import org.eclipse.equinox.p2.core.*; |
23 |
import org.eclipse.equinox.p2.core.*; |
22 |
import org.eclipse.equinox.p2.engine.IProfile; |
24 |
import org.eclipse.equinox.p2.engine.IProfile; |
23 |
import org.eclipse.equinox.p2.metadata.*; |
25 |
import org.eclipse.equinox.p2.metadata.*; |
Lines 25-34
Link Here
|
25 |
import org.eclipse.equinox.p2.repository.artifact.*; |
27 |
import org.eclipse.equinox.p2.repository.artifact.*; |
26 |
import org.eclipse.osgi.service.datalocation.Location; |
28 |
import org.eclipse.osgi.service.datalocation.Location; |
27 |
import org.eclipse.osgi.service.environment.EnvironmentInfo; |
29 |
import org.eclipse.osgi.service.environment.EnvironmentInfo; |
28 |
import org.eclipse.osgi.util.ManifestElement; |
|
|
29 |
import org.eclipse.osgi.util.NLS; |
30 |
import org.eclipse.osgi.util.NLS; |
30 |
import org.osgi.framework.BundleException; |
|
|
31 |
import org.osgi.framework.Constants; |
32 |
|
31 |
|
33 |
public class Util { |
32 |
public class Util { |
34 |
|
33 |
|
Lines 157-198
Link Here
|
157 |
return listProperty; |
156 |
return listProperty; |
158 |
} |
157 |
} |
159 |
|
158 |
|
160 |
public static BundleInfo createBundleInfo(File bundleFile, String manifest) { |
159 |
public static BundleInfo createBundleInfo(File bundleFile, IInstallableUnit unit) { |
161 |
BundleInfo bundleInfo = new BundleInfo(); |
160 |
BundleInfo bundleInfo = new BundleInfo(); |
162 |
if (bundleFile != null) |
161 |
if (bundleFile != null) |
163 |
bundleInfo.setLocation(bundleFile.toURI()); |
162 |
bundleInfo.setLocation(bundleFile.toURI()); |
164 |
|
163 |
|
165 |
bundleInfo.setManifest(manifest); |
164 |
Collection<IProvidedCapability> capabilities = unit.getProvidedCapabilities(); |
166 |
try { |
165 |
for (IProvidedCapability capability : capabilities) { |
167 |
Map<String, String> headers = ManifestElement.parseBundleManifest(new ByteArrayInputStream(manifest.getBytes("UTF-8")), new HashMap<String, String>()); //$NON-NLS-1$ |
166 |
String nameSpace = capability.getNamespace(); |
168 |
ManifestElement[] element = ManifestElement.parseHeader("bsn", headers.get(Constants.BUNDLE_SYMBOLICNAME)); //$NON-NLS-1$ |
167 |
if (nameSpace.equals("osgi.bundle")) { //$NON-NLS-1$ |
169 |
if (element == null || element.length == 0) |
168 |
bundleInfo.setSymbolicName(capability.getName()); |
170 |
return null; |
169 |
} else if (nameSpace.equals("osgi.fragment")) { //$NON-NLS-1$ |
171 |
bundleInfo.setSymbolicName(element[0].getValue()); |
170 |
String fragmentName = capability.getName(); |
172 |
|
171 |
bundleInfo.setFragmentHost(getFragmentHost(unit, fragmentName)); |
173 |
String version = headers.get(Constants.BUNDLE_VERSION); |
172 |
} |
174 |
if (version == null) |
|
|
175 |
return null; |
176 |
// convert to a Version object first to ensure we are consistent with our version number w.r.t. |
177 |
// padding zeros at the end |
178 |
bundleInfo.setVersion(Version.parseVersion(version).toString()); |
179 |
|
180 |
String fragmentHost = headers.get(Constants.FRAGMENT_HOST); |
181 |
if (fragmentHost != null) |
182 |
bundleInfo.setFragmentHost(fragmentHost.trim()); |
183 |
|
184 |
} catch (BundleException e) { |
185 |
// unexpected |
186 |
LogHelper.log(new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e)); |
187 |
return null; |
188 |
} catch (IOException e) { |
189 |
// unexpected |
190 |
LogHelper.log(new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e)); |
191 |
return null; |
192 |
} |
173 |
} |
|
|
174 |
|
175 |
bundleInfo.setVersion(unit.getVersion().toString()); |
176 |
|
193 |
return bundleInfo; |
177 |
return bundleInfo; |
194 |
} |
178 |
} |
195 |
|
179 |
|
|
|
180 |
private static String getFragmentHost(IInstallableUnit unit, String fragmentName) { |
181 |
Collection<IRequirement> requires = unit.getRequirements(); |
182 |
for (IRequirement iRequirement : requires) { |
183 |
if (iRequirement instanceof IRequiredCapability) { |
184 |
IRequiredCapability requiredCapability = (IRequiredCapability) iRequirement; |
185 |
if (fragmentName.equals(requiredCapability.getName())) { |
186 |
String fragmentHost = requiredCapability.getName(); |
187 |
if (!requiredCapability.getRange().toString().equals("0.0.0")) { //$NON-NLS-1$ |
188 |
fragmentHost += ";bundle-version=\"" + requiredCapability.getRange() + '"'; //$NON-NLS-1$ |
189 |
} |
190 |
return fragmentHost; |
191 |
} |
192 |
} |
193 |
} |
194 |
return null; |
195 |
} |
196 |
|
196 |
public static File getArtifactFile(IProvisioningAgent agent, IArtifactKey artifactKey, IProfile profile) { |
197 |
public static File getArtifactFile(IProvisioningAgent agent, IArtifactKey artifactKey, IProfile profile) { |
197 |
IFileArtifactRepository aggregatedView = getAggregatedBundleRepository(agent, profile); |
198 |
IFileArtifactRepository aggregatedView = getAggregatedBundleRepository(agent, profile); |
198 |
File bundleJar = aggregatedView.getArtifactFile(artifactKey); |
199 |
File bundleJar = aggregatedView.getArtifactFile(artifactKey); |
Lines 313-330
Link Here
|
313 |
return null; |
314 |
return null; |
314 |
} |
315 |
} |
315 |
|
316 |
|
316 |
public static String getManifest(Collection<ITouchpointData> data) { |
|
|
317 |
for (ITouchpointData td : data) { |
318 |
ITouchpointInstruction manifestInstruction = td.getInstruction("manifest"); //$NON-NLS-1$ |
319 |
if (manifestInstruction == null) |
320 |
return null; |
321 |
String manifest = manifestInstruction.getBody(); |
322 |
if (manifest != null && manifest.length() > 0) |
323 |
return manifest; |
324 |
} |
325 |
return null; |
326 |
} |
327 |
|
328 |
public static IStatus createError(String message) { |
317 |
public static IStatus createError(String message) { |
329 |
return createError(message, null); |
318 |
return createError(message, null); |
330 |
} |
319 |
} |