Skip to content
Commits on Source (3)
......@@ -4,7 +4,7 @@
<parent>
<groupId>org.eclipse.equinox.p2</groupId>
<artifactId>rt.equinox.p2</artifactId>
<version>4.10.0-SNAPSHOT</version>
<version>4.11.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<groupId>org.eclipse.equinox</groupId>
......
......@@ -4,7 +4,7 @@
<parent>
<artifactId>org.eclipse.equinox.p2.tests-parent</artifactId>
<groupId>org.eclipse</groupId>
<version>4.10.0-SNAPSHOT</version>
<version>4.11.0-SNAPSHOT</version>
<relativePath>../../org.eclipse.equinox.p2.releng/org.eclipse.equinox.p2.tests-parent</relativePath>
</parent>
<groupId>org.eclipse.equinox</groupId>
......
......@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.equinox.frameworkadmin;singleton:=true
Bundle-Version: 2.1.100.qualifier
Bundle-Version: 2.1.200.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Import-Package: org.eclipse.osgi.service.pluginconversion;version="1.0.0",
......
......@@ -4,11 +4,11 @@
<parent>
<groupId>org.eclipse.equinox.p2</groupId>
<artifactId>rt.equinox.p2</artifactId>
<version>4.10.0-SNAPSHOT</version>
<version>4.11.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.frameworkadmin</artifactId>
<version>2.1.100-SNAPSHOT</version>
<version>2.1.200-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
/*******************************************************************************
* Copyright (c) 2007, 2010 IBM Corporation and others.
* Copyright (c) 2007, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
......@@ -19,6 +19,7 @@ import org.osgi.framework.Version;
/**
* This object represents information of a bundle.
*
* @since 2.0
*/
public class BundleInfo {
......@@ -47,7 +48,9 @@ public class BundleInfo {
/**
* Create a new BundleInfo object
* @param location - the location of the bundle
*
* @param location
* - the location of the bundle
*/
public BundleInfo(URI location) {
this.location = location;
......@@ -55,9 +58,13 @@ public class BundleInfo {
/**
* Create a new BundleInfo object
* @param location - the location of the bundle
* @param startLevel - the start to be used or {@link BundleInfo#NO_LEVEL}
* @param started - whether or not the bundle should be started
*
* @param location
* - the location of the bundle
* @param startLevel
* - the start to be used or {@link BundleInfo#NO_LEVEL}
* @param started
* - whether or not the bundle should be started
*/
public BundleInfo(URI location, int startLevel, boolean started) {
this.location = location;
......@@ -67,11 +74,19 @@ public class BundleInfo {
/**
* Create a new BundleInfo object
* @param symbolic The Bundle-SymbolicName name for this bundle
* @param version - The version for this bundle, this must be a valid {@link Version} string, if null is passed {@link #EMPTY_VERSION} will be used instead
* @param location - the location of the bundle
* @param startLevel - the start level of the bundle or {@link BundleInfo#NO_LEVEL}
* @param started - whether or not the bundle should be started
*
* @param symbolic
* The Bundle-SymbolicName name for this bundle
* @param version
* - The version for this bundle, this must be a valid
* {@link Version} string, if null is passed {@link #EMPTY_VERSION}
* will be used instead
* @param location
* - the location of the bundle
* @param startLevel
* - the start level of the bundle or {@link BundleInfo#NO_LEVEL}
* @param started
* - whether or not the bundle should be started
*/
public BundleInfo(String symbolic, String version, URI location, int startLevel, boolean started) {
this.symbolicName = symbolic;
......@@ -83,6 +98,7 @@ public class BundleInfo {
/**
* Get the bundle id
*
* @return the bundle id or {@link #NO_BUNDLEID}
*/
public long getBundleId() {
......@@ -90,8 +106,9 @@ public class BundleInfo {
}
/**
* The base location
* An absolute URI which may be used to resolve relative {@link #getLocation()} URIs
* The base location An absolute URI which may be used to resolve relative
* {@link #getLocation()} URIs
*
* @return absolute URI or null if not set
*/
public URI getBaseLocation() {
......@@ -99,8 +116,9 @@ public class BundleInfo {
}
/**
* The location of this bundle.
* A location is required if this bundle will be persisted into a configuration file
* The location of this bundle. A location is required if this bundle will be
* persisted into a configuration file
*
* @return URI location or null if not set
*/
public URI getLocation() {
......@@ -109,6 +127,7 @@ public class BundleInfo {
/**
* The manifest for this bundle
*
* @return the manifest or null if not set
*/
public String getManifest() {
......@@ -117,6 +136,7 @@ public class BundleInfo {
/**
* The start level for this bundle
*
* @return the start level or {@link #NO_LEVEL}
*/
public int getStartLevel() {
......@@ -124,8 +144,9 @@ public class BundleInfo {
}
/**
* The Bundle-SymbolicName for this bundle.
* A symbolic name is required if this bundle will be persisted into a configuration file
* The Bundle-SymbolicName for this bundle. A symbolic name is required if this
* bundle will be persisted into a configuration file
*
* @return the symbolic name or null if not set
*/
public String getSymbolicName() {
......@@ -134,6 +155,7 @@ public class BundleInfo {
/**
* Return the version
*
* @return an {@link Version} string, or "0.0.0" if not set
*/
public String getVersion() {
......@@ -144,6 +166,7 @@ public class BundleInfo {
/**
* Return the host if this bundle is a fragment
*
* @return the host, or null if this is not a fragment
*/
public String getFragmentHost() {
......@@ -151,8 +174,8 @@ public class BundleInfo {
}
/**
* Whether or not this bundle is marked to be started
* Default is false
* Whether or not this bundle is marked to be started Default is false
*
* @return boolean
*/
public boolean isMarkedAsStarted() {
......@@ -160,8 +183,8 @@ public class BundleInfo {
}
/**
* Whether or not this bundle is resolved
* Default is false
* Whether or not this bundle is resolved Default is false
*
* @return boolean
*/
public boolean isResolved() {
......@@ -170,6 +193,7 @@ public class BundleInfo {
/**
* Set the bundle id
*
* @param bundleId
*/
public void setBundleId(long bundleId) {
......@@ -177,8 +201,11 @@ public class BundleInfo {
}
/**
* Set a base location against which relative {@link #getLocation()} URIs may be resolved
* @param baseLocation - an absolute URI
* Set a base location against which relative {@link #getLocation()} URIs may be
* resolved
*
* @param baseLocation
* - an absolute URI
*/
public void setBaseLocation(URI baseLocation) {
this.baseLocation = baseLocation;
......@@ -186,6 +213,7 @@ public class BundleInfo {
/**
* Set the location for this bundle.
*
* @param location
*/
public void setLocation(URI location) {
......@@ -194,6 +222,7 @@ public class BundleInfo {
/**
* Set the manifest for this bundle
*
* @param manifest
*/
public void setManifest(String manifest) {
......@@ -202,6 +231,7 @@ public class BundleInfo {
/**
* Set whether or not this bundle should be started
*
* @param markedAsStarted
*/
public void setMarkedAsStarted(boolean markedAsStarted) {
......@@ -210,6 +240,7 @@ public class BundleInfo {
/**
* Set whether or not the bundle is resolved
*
* @param resolved
*/
public void setResolved(boolean resolved) {
......@@ -218,7 +249,10 @@ public class BundleInfo {
/**
* Set the start level.
* @param level if a value < 0 is passed, the start level will be set to {@link #NO_LEVEL}
*
* @param level
* if a value < 0 is passed, the start level will be set to
* {@link #NO_LEVEL}
*/
public void setStartLevel(int level) {
this.startLevel = level < 0 ? NO_LEVEL : level;
......@@ -226,6 +260,7 @@ public class BundleInfo {
/**
* Set the Bundle-SymbolicName
*
* @param symbolicName
*/
public void setSymbolicName(String symbolicName) {
......@@ -234,6 +269,7 @@ public class BundleInfo {
/**
* Set the version, should be a valid {@link Version} string
*
* @param value
*/
public void setVersion(String value) {
......@@ -245,6 +281,7 @@ public class BundleInfo {
/**
* Set the host if this bundle is a fragment
*
* @param fragmentHost
*/
public void setFragmentHost(String fragmentHost) {
......@@ -253,7 +290,7 @@ public class BundleInfo {
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
buffer.append("BundleInfo("); //$NON-NLS-1$
if (symbolicName != null)
buffer.append(symbolicName);
......@@ -278,7 +315,8 @@ public class BundleInfo {
buffer.append(", resolved="); //$NON-NLS-1$
buffer.append(resolved);
buffer.append(", id="); //$NON-NLS-1$
buffer.append(this.bundleId);// buffer.append(',').append(manifest == null ? "no manifest" : "manifest available");
buffer.append(this.bundleId);// buffer.append(',').append(manifest == null ? "no manifest" : "manifest
// available");
buffer.append(',').append(manifest == null ? "no manifest" : "manifest available"); //$NON-NLS-1$ //$NON-NLS-2$
buffer.append(')');
return buffer.toString();
......
......@@ -12,6 +12,6 @@ Package Specification</h2>
This API package defines the framework admin which is used to manage the bundles.info.
<p>
@since 2.0
<p>
</p>
</body>
</html>
/*******************************************************************************
* Copyright (c) 2007, 2017 IBM Corporation and others.
* Copyright (c) 2007, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
......@@ -22,14 +22,11 @@ import org.eclipse.equinox.internal.provisional.frameworkadmin.*;
import org.osgi.framework.Constants;
/**
* This implementation of BundlesState doesn't support any of
* - resolving bundles,
* - retrieving fw persistent data.
* This implementation of BundlesState doesn't support any of - resolving
* bundles, - retrieving fw persistent data.
*
* This implementation can be used for those cases.
*
*/
public class SimpleBundlesState implements BundlesState {
public static final BundleInfo[] NULL_BUNDLEINFOS = new BundleInfo[0];
......@@ -41,7 +38,8 @@ public class SimpleBundlesState implements BundlesState {
*/
public static void checkAvailability(FrameworkAdmin fwAdmin) throws FrameworkAdminRuntimeException {
if (!fwAdmin.isActive())
throw new FrameworkAdminRuntimeException("FrameworkAdmin creates this object is no more available.", FrameworkAdminRuntimeException.FRAMEWORKADMIN_UNAVAILABLE); //$NON-NLS-1$
throw new FrameworkAdminRuntimeException("FrameworkAdmin creates this object is no more available.", //$NON-NLS-1$
FrameworkAdminRuntimeException.FRAMEWORKADMIN_UNAVAILABLE);
}
/**
......@@ -68,17 +66,19 @@ public class SimpleBundlesState implements BundlesState {
Manipulator manipulator = null;
/**
* If the manifest of the target fw implementation has Constants.BUNDLE_SYMBOLICNAME header,
* this constructor should be used.
* If the manifest of the target fw implementation has
* Constants.BUNDLE_SYMBOLICNAME header, this constructor should be used.
*
* @param ManipulatorAdmin
* @param Manipulator
* @param systemBundleSymbolicName
*/
public SimpleBundlesState(FrameworkAdmin ManipulatorAdmin, Manipulator Manipulator, String systemBundleSymbolicName) {
public SimpleBundlesState(FrameworkAdmin ManipulatorAdmin, Manipulator Manipulator,
String systemBundleSymbolicName) {
super();
this.fwAdmin = ManipulatorAdmin;
// copy Manipulator object for avoiding modifying the parameters of the Manipulator.
// copy Manipulator object for avoiding modifying the parameters of the
// Manipulator.
this.manipulator = ManipulatorAdmin.getManipulator();
this.manipulator.setConfigData(Manipulator.getConfigData());
this.manipulator.setLauncherData(Manipulator.getLauncherData());
......@@ -89,19 +89,21 @@ public class SimpleBundlesState implements BundlesState {
}
/**
* If the manifest of the target fw implementation has not Constants.BUNDLE_SYMBOLICNAME header
* but , Constants.BUNDLE_NAME and BUNDLE_VERSION,
* this constructor should be used.
* If the manifest of the target fw implementation has not
* Constants.BUNDLE_SYMBOLICNAME header but , Constants.BUNDLE_NAME and
* BUNDLE_VERSION, this constructor should be used.
*
* @param ManipulatorAdmin
* @param Manipulator
* @param systemBundleName
* @param systemBundleVender
*/
public SimpleBundlesState(FrameworkAdmin ManipulatorAdmin, Manipulator Manipulator, String systemBundleName, String systemBundleVender) {
public SimpleBundlesState(FrameworkAdmin ManipulatorAdmin, Manipulator Manipulator, String systemBundleName,
String systemBundleVender) {
super();
this.fwAdmin = ManipulatorAdmin;
// copy Manipulator object for avoiding modifying the parameters of the Manipulator.
// copy Manipulator object for avoiding modifying the parameters of the
// Manipulator.
this.manipulator = ManipulatorAdmin.getManipulator();
this.manipulator.setConfigData(Manipulator.getConfigData());
this.manipulator.setLauncherData(Manipulator.getLauncherData());
......@@ -114,14 +116,17 @@ public class SimpleBundlesState implements BundlesState {
@Override
public BundleInfo[] getExpectedState() throws FrameworkAdminRuntimeException {
if (!fwAdmin.isActive())
throw new FrameworkAdminRuntimeException("FrameworkAdmin creates this object is no more available.", FrameworkAdminRuntimeException.FRAMEWORKADMIN_UNAVAILABLE); //$NON-NLS-1$
throw new FrameworkAdminRuntimeException("FrameworkAdmin creates this object is no more available.", //$NON-NLS-1$
FrameworkAdminRuntimeException.FRAMEWORKADMIN_UNAVAILABLE);
return Utils.getBundleInfosFromList(this.bundleInfosList);
}
/*
* Just return required bundles.
*
* @see org.eclipse.equinox.internal.provisional.frameworkadmin.BundlesState#getPrerequisteBundles(org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo)
* @see org.eclipse.equinox.internal.provisional.frameworkadmin.BundlesState#
* getPrerequisteBundles(org.eclipse.equinox.internal.provisional.frameworkadmin
* .BundleInfo)
*/
@Override
public BundleInfo[] getPrerequisteBundles(BundleInfo bInfo) {
......@@ -132,20 +137,19 @@ public class SimpleBundlesState implements BundlesState {
String[] clauses = Utils.getClauses(requiredBundles);
List<String> list = new LinkedList<>();
for (int i = 0; i < clauses.length; i++)
list.add(Utils.getPathFromClause(clauses[i]));
for (String clause : clauses)
list.add(Utils.getPathFromClause(clause));
List<BundleInfo> ret = new LinkedList<>();
ret.add(this.getSystemBundle());
for (Iterator<BundleInfo> ite = this.bundleInfosList.iterator(); ite.hasNext();) {
BundleInfo currentBInfo = ite.next();
for (BundleInfo currentBInfo : this.bundleInfosList) {
URI currentLocation = currentBInfo.getLocation();
String currentSymbolicName = Utils.getManifestMainAttributes(currentLocation, Constants.BUNDLE_SYMBOLICNAME);
String currentSymbolicName = Utils.getManifestMainAttributes(currentLocation,
Constants.BUNDLE_SYMBOLICNAME);
if (currentSymbolicName == null)
continue;
currentSymbolicName = Utils.getPathFromClause(currentSymbolicName);
for (Iterator<String> ite2 = list.iterator(); ite2.hasNext();) {
String symbolicName = ite2.next();
for (String symbolicName : list) {
if (symbolicName.equals(currentSymbolicName)) {
ret.add(currentBInfo);
break;
......@@ -158,8 +162,7 @@ public class SimpleBundlesState implements BundlesState {
@Override
public BundleInfo getSystemBundle() {
if (this.systemBundleSymbolicName == null) {
for (Iterator<BundleInfo> ite = this.bundleInfosList.iterator(); ite.hasNext();) {
BundleInfo bInfo = ite.next();
for (BundleInfo bInfo : this.bundleInfosList) {
// if (bInfo.getStartLevel() != 1)
// return null;;
URI location = bInfo.getLocation();
......@@ -172,8 +175,7 @@ public class SimpleBundlesState implements BundlesState {
}
return null;
}
for (Iterator<BundleInfo> ite = this.bundleInfosList.iterator(); ite.hasNext();) {
BundleInfo bInfo = ite.next();
for (BundleInfo bInfo : this.bundleInfosList) {
URI location = bInfo.getLocation();
String symbolicName = Utils.getManifestMainAttributes(location, Constants.BUNDLE_SYMBOLICNAME);
symbolicName = Utils.getPathFromClause(symbolicName);
......@@ -192,8 +194,7 @@ public class SimpleBundlesState implements BundlesState {
@SuppressWarnings("rawtypes")
List list = new LinkedList();
for (Iterator<BundleInfo> ite = this.bundleInfosList.iterator(); ite.hasNext();) {
BundleInfo bInfo = ite.next();
for (BundleInfo bInfo : this.bundleInfosList) {
URI location = bInfo.getLocation();
String manifestVersion = Utils.getManifestMainAttributes(location, Constants.BUNDLE_MANIFESTVERSION);
if (manifestVersion == null)
......@@ -221,7 +222,9 @@ public class SimpleBundlesState implements BundlesState {
@Override
public String[] getUnsatisfiedConstraints(BundleInfo bInfo) throws FrameworkAdminRuntimeException {
throw new FrameworkAdminRuntimeException("getUnsatisfiedConstraints(BundleInfo bInfo) is not supported in this implementation", FrameworkAdminRuntimeException.UNSUPPORTED_OPERATION); //$NON-NLS-1$
throw new FrameworkAdminRuntimeException(
"getUnsatisfiedConstraints(BundleInfo bInfo) is not supported in this implementation", //$NON-NLS-1$
FrameworkAdminRuntimeException.UNSUPPORTED_OPERATION);
}
private void initialize() {
......@@ -235,8 +238,8 @@ public class SimpleBundlesState implements BundlesState {
// No fw persistent data location is taken into consideration.
BundleInfo[] bInfos = configData.getBundles();
for (int j = 0; j < bInfos.length; j++)
this.installBundle(bInfos[j]);
for (BundleInfo bInfo : bInfos)
this.installBundle(bInfo);
if (getSystemBundle() == null) {
BundleInfo sysBInfo = new BundleInfo(launcherData.getFwJar().toURI(), 0, true);
......@@ -256,10 +259,10 @@ public class SimpleBundlesState implements BundlesState {
}
String newSymbolicName = newManifest.get(Constants.BUNDLE_SYMBOLICNAME);
String newVersion = newManifest.get(Constants.BUNDLE_VERSION);
//System.out.println("> currentInstalledBundles.length=" + currentInstalledBundles.length);
// System.out.println("> currentInstalledBundles.length=" +
// currentInstalledBundles.length);
boolean found = false;
for (Iterator<BundleInfo> ite = this.bundleInfosList.iterator(); ite.hasNext();) {
BundleInfo currentBInfo = ite.next();
for (BundleInfo currentBInfo : this.bundleInfosList) {
URI location = currentBInfo.getLocation();
if (newLocation.equals(location)) {
found = true;
......@@ -313,26 +316,28 @@ public class SimpleBundlesState implements BundlesState {
@Override
public boolean isResolved() throws FrameworkAdminRuntimeException {
throw new FrameworkAdminRuntimeException("isResolved() is not supported in this implementation", FrameworkAdminRuntimeException.UNSUPPORTED_OPERATION); //$NON-NLS-1$
throw new FrameworkAdminRuntimeException("isResolved() is not supported in this implementation", //$NON-NLS-1$
FrameworkAdminRuntimeException.UNSUPPORTED_OPERATION);
}
@Override
public boolean isResolved(BundleInfo bInfo) throws FrameworkAdminRuntimeException {
throw new FrameworkAdminRuntimeException("isResolved(BundleInfo bInfo) is not supported in this implementation", FrameworkAdminRuntimeException.UNSUPPORTED_OPERATION); //$NON-NLS-1$
throw new FrameworkAdminRuntimeException("isResolved(BundleInfo bInfo) is not supported in this implementation", //$NON-NLS-1$
FrameworkAdminRuntimeException.UNSUPPORTED_OPERATION);
}
@Override
public void resolve(boolean increment) throws FrameworkAdminRuntimeException {
throw new FrameworkAdminRuntimeException("resolve(boolean increment) is not supported in this implementation", FrameworkAdminRuntimeException.UNSUPPORTED_OPERATION); //$NON-NLS-1$
throw new FrameworkAdminRuntimeException("resolve(boolean increment) is not supported in this implementation", //$NON-NLS-1$
FrameworkAdminRuntimeException.UNSUPPORTED_OPERATION);
}
@Override
public void uninstallBundle(BundleInfo bInfo) throws FrameworkAdminRuntimeException {
URI targetLocation = bInfo.getLocation();
int index = -1;
for (Iterator<BundleInfo> ite = this.bundleInfosList.iterator(); ite.hasNext();) {
for (BundleInfo currentBInfo : this.bundleInfosList) {
index++;
BundleInfo currentBInfo = ite.next();
URI location = currentBInfo.getLocation();
if (targetLocation.equals(location)) {
break;
......
/*******************************************************************************
* Copyright (c) 2007, 2017 IBM Corporation and others.
* Copyright (c) 2007, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
......@@ -31,10 +31,15 @@ public class Utils {
private static final String PATH_SEP = "/"; //$NON-NLS-1$
/**
* Overwrite all properties of from to the properties of to. Return the result of to.
* Overwrite all properties of from to the properties of to. Return the result
* of to.
*
* @param to Properties whose keys and values of other Properties will be appended to.
* @param from Properties whose keys and values will be set to the other properties.
* @param to
* Properties whose keys and values of other Properties will be
* appended to.
* @param from
* Properties whose keys and values will be set to the other
* properties.
* @return Properties as a result of this method.
*/
public static Properties appendProperties(Properties to, Properties from) {
......@@ -53,7 +58,8 @@ public class Utils {
return to;
}
//Return a dictionary representing a manifest. The data may result from plugin.xml conversion
// Return a dictionary representing a manifest. The data may result from
// plugin.xml conversion
private static Dictionary<String, String> basicLoadManifest(File bundleLocation) {
InputStream manifestStream = null;
ZipFile jarFile = null;
......@@ -70,12 +76,14 @@ public class Utils {
// we have a directory-based bundle
File bundleManifestFile = new File(bundleLocation, JarFile.MANIFEST_NAME);
if (bundleManifestFile.exists())
manifestStream = new BufferedInputStream(new FileInputStream(new File(bundleLocation, JarFile.MANIFEST_NAME)));
manifestStream = new BufferedInputStream(
new FileInputStream(new File(bundleLocation, JarFile.MANIFEST_NAME)));
}
} catch (IOException e) {
// ignore
}
// we were unable to get an OSGi manifest file so try and convert an old-style manifest
// we were unable to get an OSGi manifest file so try and convert an old-style
// manifest
if (manifestStream == null)
return null;
......@@ -85,9 +93,7 @@ public class Utils {
if (manifest.get(Constants.BUNDLE_SYMBOLICNAME) == null)
return null;
return manifestToProperties(manifest);
} catch (IOException ioe) {
return null;
} catch (BundleException e) {
} catch (IOException | BundleException ioe) {
return null;
}
} finally {
......@@ -124,7 +130,9 @@ public class Utils {
throw new IllegalArgumentException(dirName + " is not file but directory"); //$NON-NLS-1$
}
public static URL checkFullUrl(URL url, String urlName) throws IllegalArgumentException {//throws ManipulatorException {
public static URL checkFullUrl(URL url, String urlName) throws IllegalArgumentException {// throws
// ManipulatorException
// {
if (url == null)
throw new IllegalArgumentException(urlName + " is null"); //$NON-NLS-1$
if (!url.getProtocol().endsWith("file")) //$NON-NLS-1$
......@@ -137,7 +145,8 @@ public class Utils {
try {
return getUrl("file", null, PATH_SEP + file.getAbsolutePath()); //$NON-NLS-1$
} catch (MalformedURLException e) {
throw new IllegalArgumentException(urlName + "(" + "file:" + PATH_SEP + file.getAbsolutePath() + ") is not fully quallified"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
throw new IllegalArgumentException(
urlName + "(" + "file:" + PATH_SEP + file.getAbsolutePath() + ") is not fully quallified"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
......@@ -190,9 +199,8 @@ public class Utils {
try {
URL url = new URL("jar:" + location.toString() + "!/"); //$NON-NLS-1$//$NON-NLS-2$
JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
ZipFile jar = jarConnection.getJarFile();
try {
try (ZipFile jar = jarConnection.getJarFile()) {
ZipEntry entry = jar.getEntry(JarFile.MANIFEST_NAME);
if (entry == null)
return null;
......@@ -206,8 +214,6 @@ public class Utils {
return manifestToProperties(manifest);
} catch (BundleException e) {
return null;
} finally {
jar.close();
}
} catch (IOException e) {
if (System.getProperty("osgi.debug") != null) { //$NON-NLS-1$
......@@ -240,7 +246,7 @@ public class Utils {
else
break;
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = index + 1; i < fromTokens.length; i++)
sb.append(".." + PATH_SEP); //$NON-NLS-1$
......@@ -255,9 +261,10 @@ public class Utils {
/**
* This method will be called for create a backup file.
*
* @param file target file
* @return File backup file whose filename consists of "hogehoge.yyyyMMddHHmmss.ext" or
* "hogehoge.yyyyMMddHHmmss".
* @param file
* target file
* @return File backup file whose filename consists of
* "hogehoge.yyyyMMddHHmmss.ext" or "hogehoge.yyyyMMddHHmmss".
*/
public static File getSimpleDataFormattedFile(File file) {
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); //$NON-NLS-1$
......@@ -287,12 +294,13 @@ public class Utils {
return tokens;
}
public static URL getUrl(String protocol, String host, String file) throws MalformedURLException {// throws ManipulatorException {
public static URL getUrl(String protocol, String host, String file) throws MalformedURLException {// throws
// ManipulatorException
file = Utils.replaceAll(file, File.separator, "/"); //$NON-NLS-1$
return new URL(protocol, host, file);
}
public static URL getUrlInFull(String path, URL from) throws MalformedURLException {//throws ManipulatorException {
public static URL getUrlInFull(String path, URL from) throws MalformedURLException {// throws ManipulatorException
Utils.checkFullUrl(from, "from"); //$NON-NLS-1$
path = Utils.replaceAll(path, File.separator, "/"); //$NON-NLS-1$
// System.out.println("from.toExternalForm()=" + from.toExternalForm());
......@@ -306,10 +314,8 @@ public class Utils {
}
private static Dictionary<String, String> manifestToProperties(Map<String, String> d) {
Iterator<String> iter = d.keySet().iterator();
Dictionary<String, String> result = new Hashtable<>();
while (iter.hasNext()) {
String key = iter.next();
for (String key : d.keySet()) {
result.put(key, d.get(key));
}
return result;
......@@ -318,9 +324,12 @@ public class Utils {
/**
* Just used for debug.
*
* @param ps printstream
* @param name name of properties
* @param props properties whose keys and values will be printed out.
* @param ps
* printstream
* @param name
* name of properties
* @param props
* properties whose keys and values will be printed out.
*/
public static void printoutProperties(PrintStream ps, String name, Properties props) {
if (props == null || props.size() == 0) {
......@@ -355,14 +364,16 @@ public class Utils {
/**
* Sort by increasing order of startlevels.
*
* @param bInfos array of BundleInfos to be sorted.
* @param initialBSL initial bundle start level to be used.
* @param bInfos
* array of BundleInfos to be sorted.
* @param initialBSL
* initial bundle start level to be used.
* @return sorted array of BundleInfos
*/
public static BundleInfo[] sortBundleInfos(BundleInfo[] bInfos, int initialBSL) {
SortedMap<Integer, List<BundleInfo>> bslToList = new TreeMap<>();
for (int i = 0; i < bInfos.length; i++) {
Integer sL = Integer.valueOf(bInfos[i].getStartLevel());
for (BundleInfo bInfo : bInfos) {
Integer sL = Integer.valueOf(bInfo.getStartLevel());
if (sL.intValue() == BundleInfo.NO_LEVEL)
sL = Integer.valueOf(initialBSL);
List<BundleInfo> list = bslToList.get(sL);
......@@ -370,16 +381,14 @@ public class Utils {
list = new LinkedList<>();
bslToList.put(sL, list);
}
list.add(bInfos[i]);
list.add(bInfo);
}
// bslToList is sorted by the key (StartLevel).
List<BundleInfo> bundleInfoList = new LinkedList<>();
for (Iterator<Integer> ite = bslToList.keySet().iterator(); ite.hasNext();) {
Integer sL = ite.next();
for (Integer sL : bslToList.keySet()) {
List<BundleInfo> list = bslToList.get(sL);
for (Iterator<BundleInfo> ite2 = list.iterator(); ite2.hasNext();) {
BundleInfo bInfo = ite2.next();
for (BundleInfo bInfo : list) {
bundleInfoList.add(bInfo);
}
}
......@@ -389,14 +398,16 @@ public class Utils {
/**
* get String representing the given properties.
*
* @param name name of properties
* @param props properties whose keys and values will be printed out.
* @param name
* name of properties
* @param props
* properties whose keys and values will be printed out.
*/
public static String toStringProperties(String name, Properties props) {
if (props == null || props.size() == 0) {
return "Props(" + name + ") is empty\n"; //$NON-NLS-1$ //$NON-NLS-2$
}
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append("Props(" + name + ") is \n"); //$NON-NLS-1$ //$NON-NLS-2$
for (Enumeration<Object> enumeration = props.keys(); enumeration.hasMoreElements();) {
String key = (String) enumeration.nextElement();
......
/*******************************************************************************
* Copyright (c) 2007, 2017 IBM Corporation and others.
* Copyright (c) 2007, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
......@@ -18,10 +18,9 @@ import java.util.*;
import org.eclipse.equinox.frameworkadmin.BundleInfo;
/**
* This object is instantiated by {@link Manipulator#getConfigData()};
* The class that keeps some parameters of the {@link Manipulator}
* created this object. The manipulating of the parameters will affect
* the {@link Manipulator}.
* This object is instantiated by {@link Manipulator#getConfigData()}; The class
* that keeps some parameters of the {@link Manipulator} created this object.
* The manipulating of the parameters will affect the {@link Manipulator}.
*
* @see Manipulator
*/
......@@ -112,8 +111,8 @@ public class ConfigData {
public void setBundles(BundleInfo[] bundleInfos) {
bundlesList.clear();
if (bundleInfos != null)
for (int i = 0; i < bundleInfos.length; i++)
bundlesList.add(bundleInfos[i]);
for (BundleInfo bundleInfo : bundleInfos)
bundlesList.add(bundleInfo);
}
public void setProperty(String key, String value) {
......@@ -138,7 +137,7 @@ public class ConfigData {
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append("Class:" + getClass().getName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
sb.append("============Independent===============\n"); //$NON-NLS-1$
sb.append("fwName=" + fwName + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
......@@ -152,8 +151,8 @@ public class ConfigData {
else {
sb.append("bundlesList=\n"); //$NON-NLS-1$
int i = 0;
for (Iterator<BundleInfo> iter = bundlesList.iterator(); iter.hasNext();) {
sb.append("\tbundlesList[" + i + "]=" + iter.next().toString() + "\n"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
for (BundleInfo bundleInfo : bundlesList) {
sb.append("\tbundlesList[" + i + "]=" + bundleInfo.toString() + "\n"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
i++;
}
}
......@@ -164,7 +163,7 @@ public class ConfigData {
return sb.toString();
}
private static void setPropsStrings(StringBuffer sb, Properties props) {
private static void setPropsStrings(StringBuilder sb, Properties props) {
if (props.size() > 0) {
sb.append("\n"); //$NON-NLS-1$
for (Enumeration<Object> enumeration = props.keys(); enumeration.hasMoreElements();) {
......
/*******************************************************************************
* Copyright (c) 2007, 2017 IBM Corporation and others.
* Copyright (c) 2007, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
......@@ -17,10 +17,10 @@ import java.io.File;
import java.util.*;
/**
* This object is instantiated by {@link Manipulator#getLauncherData()};
* The class that keeps some parameters of the {@link Manipulator}
* created this object. The manipulating of the parameters will affect
* the {@link Manipulator}.
* This object is instantiated by {@link Manipulator#getLauncherData()}; The
* class that keeps some parameters of the {@link Manipulator} created this
* object. The manipulating of the parameters will affect the
* {@link Manipulator}.
*
*
* @see Manipulator
......@@ -190,8 +190,8 @@ public class LauncherData {
jvmArgs.clear();
return;
}
for (int i = 0; i < args.length; i++)
this.addJvmArg(args[i]);
for (String arg : args)
this.addJvmArg(arg);
}
public void setLauncher(File launcherFile) {
......@@ -215,8 +215,8 @@ public class LauncherData {
programArgs.clear();
return;
}
for (int i = 0; i < args.length; i++)
this.addProgramArg(args[i]);
for (String arg : args)
this.addProgramArg(arg);
}
@Override
......
......@@ -4,7 +4,7 @@
<parent>
<groupId>org.eclipse.equinox.p2</groupId>
<artifactId>rt.equinox.p2</artifactId>
<version>4.10.0-SNAPSHOT</version>
<version>4.11.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<groupId>org.eclipse.equinox</groupId>
......
......@@ -4,7 +4,7 @@
<parent>
<groupId>org.eclipse.equinox.p2</groupId>
<artifactId>rt.equinox.p2</artifactId>
<version>4.10.0-SNAPSHOT</version>
<version>4.11.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<groupId>org.eclipse.equinox</groupId>
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.equinox.p2.artifact.repository" version="2">
<resource path="META-INF/MANIFEST.MF">
<filter comment="Bug 536282 - Check whether processing step is available" id="926941240">
<message_arguments>
<message_argument value="1.3.0"/>
<message_argument value="1.2.200"/>
</message_arguments>
</filter>
</resource>
</component>
......@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.equinox.p2.artifact.repository;singleton:=true
Bundle-Version: 1.2.200.qualifier
Bundle-Version: 1.3.0.qualifier
Bundle-Activator: org.eclipse.equinox.internal.p2.artifact.repository.Activator
Bundle-Vendor: %providerName
Bundle-Localization: plugin
......
......@@ -33,16 +33,18 @@
<step class="org.eclipse.equinox.internal.p2.artifact.repository.SignatureVerifier"/>
</extension>
<extension
point="org.eclipse.equinox.p2.artifact.repository.processingSteps"
id="org.eclipse.equinox.p2.processing.MD5Verifier">
<step class="org.eclipse.equinox.internal.p2.artifact.processors.md5.MD5Verifier"/>
</extension>
<extension
point="org.eclipse.equinox.p2.artifact.repository.processingSteps"
id="org.eclipse.equinox.p2.processing.ChecksumVerifier">
<step class="org.eclipse.equinox.internal.p2.artifact.processors.checksum.ChecksumVerifier"/>
</extension>
<extension
point="org.eclipse.equinox.p2.artifact.repository.artifactChecksums">
<artifactChecksum
algorithm="MD5"
id="md5">
</artifactChecksum>
</extension>
<extension
point="org.eclipse.equinox.p2.artifact.repository.artifactChecksums">
<artifactChecksum
......
......@@ -4,11 +4,11 @@
<parent>
<groupId>org.eclipse.equinox.p2</groupId>
<artifactId>rt.equinox.p2</artifactId>
<version>4.10.0-SNAPSHOT</version>
<version>4.11.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.p2.artifact.repository</artifactId>
<version>1.2.200-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
......@@ -10,7 +10,7 @@
&lt;p&gt;p2 detects errors which may have been introduced during artifact transmission/storage by calculating artifact checksum using MD5 hash function. As a &lt;a href=&quot;https://en.wikipedia.org/wiki/Collision_attack&quot;&gt;collision attack&lt;/a&gt; and a &lt;a href=&quot;https://en.wikipedia.org/wiki/Chosen-prefix_collision_attack&quot;&gt;chosen-prefix collision attack&lt;/a&gt; against MD5 have been demonstrated in public, it can be used but only to detect unintentional corruption. Current implementation is not extensible and doesn&apos;t allow to use other, more collision-resistant, hash functions.&lt;/p&gt;
&lt;p&gt;With this extension point, any &lt;code&gt;java.security.MessageDigest&lt;/code&gt; from Java Security API can be used to check integrity of artifacts. For more information on these APIs, see &lt;a href=&quot;https://docs.oracle.com/javase/8/docs/technotes/guides/security/crypto/CryptoSpec.html&quot;&gt;Java Cryptography Architecture (JCA) Reference Guide&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;With this extension point, any &lt;code&gt;java.security.MessageDigest&lt;/code&gt; from Java Security API can be used to check integrity of artifacts. For more information on these APIs, see &lt;a href=&quot;https://docs.oracle.com/en/java/javase/11/security/java-cryptography-architecture-jca-reference-guide.html&quot;&gt;Java Cryptography Architecture (JCA) Reference Guide&lt;/a&gt;.&lt;/p&gt;
</documentation>
</annotation>
......@@ -113,6 +113,7 @@ public class Activator implements BundleActivator {
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
......
......@@ -19,13 +19,13 @@ import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.Map.Entry;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.artifact.processors.md5.MD5Verifier;
import org.eclipse.equinox.internal.p2.artifact.repository.Messages;
import org.eclipse.equinox.internal.p2.repository.Activator;
import org.eclipse.equinox.internal.p2.repository.helpers.ChecksumHelper;
import org.eclipse.equinox.internal.p2.repository.helpers.ChecksumProducer;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.spi.ProcessingStepDescriptor;
import org.eclipse.osgi.util.NLS;
public class ChecksumUtilities {
......@@ -57,7 +57,8 @@ public class ChecksumUtilities {
String checksumId = checksumVerifierConfiguration.getAttribute("id"); //$NON-NLS-1$
if (checksumEntry.getKey().equals(checksumId)) {
String checksumAlgorithm = checksumVerifierConfiguration.getAttribute("algorithm"); //$NON-NLS-1$
ChecksumVerifier checksumVerifier = new ChecksumVerifier(checksumAlgorithm, checksumId, checksumEntry.getValue());
ChecksumVerifier checksumVerifier = new ChecksumVerifier(checksumAlgorithm, checksumId);
checksumVerifier.initialize(null, new ProcessingStepDescriptor(null, checksumEntry.getValue(), true), descriptor);
if (checksumVerifier.getStatus().isOK())
steps.add(checksumVerifier);
else
......@@ -67,9 +68,6 @@ public class ChecksumUtilities {
}
}
Optional<MD5Verifier> legacyMd5Verifier = getLegacyMd5Verifier(checksums.get(ChecksumHelper.MD5));
legacyMd5Verifier.ifPresent(verifier -> steps.add(verifier));
return steps;
}
......@@ -138,17 +136,6 @@ public class ChecksumUtilities {
return properties;
}
private static Optional<MD5Verifier> getLegacyMd5Verifier(String md5) {
if (md5 != null) {
@SuppressWarnings("resource") //It's used later so shouldn't be closed
MD5Verifier checksumVerifier = new MD5Verifier(md5);
if (checksumVerifier.getStatus().isOK())
return Optional.of(checksumVerifier);
}
return Optional.empty();
}
private static void putLegacyMd5Property(String propertyNamespace, Map<String, String> checksums, HashMap<String, String> result) {
String md5 = checksums.get(ChecksumHelper.MD5);
if (md5 != null) {
......
......@@ -13,13 +13,13 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.processors.checksum;
import static java.util.Optional.ofNullable;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Optional;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.artifact.repository.Activator;
import org.eclipse.equinox.internal.p2.repository.helpers.ChecksumHelper;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
......@@ -29,42 +29,45 @@ import org.eclipse.osgi.util.NLS;
final public class ChecksumVerifier extends MessageDigestProcessingStep {
private String expectedChecksum;
private String algorithmName;
private String algorithmId;
final private String algorithmName;
final private String algorithmId;
// public to access from tests
public ChecksumVerifier(String digestAlgorithm, String algorithmId, String expectedChecksum) {
public ChecksumVerifier(String digestAlgorithm, String algorithmId) {
this.algorithmName = digestAlgorithm;
this.algorithmId = algorithmId;
this.expectedChecksum = expectedChecksum;
basicInitialize(null);
}
@Override
public final void initialize(IProvisioningAgent agent, IProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
super.initialize(agent, descriptor, context);
String data = descriptor.getData();
if (IArtifactDescriptor.DOWNLOAD_CHECKSUM.concat(".").concat(algorithmId).equals(data)) //$NON-NLS-1$
expectedChecksum = ChecksumHelper.getChecksums(context, IArtifactDescriptor.DOWNLOAD_CHECKSUM).get(algorithmId);
else if (IArtifactDescriptor.ARTIFACT_CHECKSUM.concat(".").concat(algorithmId).equals(data)) //$NON-NLS-1$
expectedChecksum = ChecksumHelper.getChecksums(context, IArtifactDescriptor.ARTIFACT_CHECKSUM).get(algorithmId);
else
expectedChecksum = data;
basicInitialize(descriptor);
if (!getStatus().isOK()) {
return;
}
private void basicInitialize(IProcessingStepDescriptor descriptor) {
int code = (descriptor == null) ? IStatus.ERROR : descriptor.isRequired() ? IStatus.ERROR : IStatus.INFO;
if (Optional.ofNullable(expectedChecksum).orElse("").isEmpty()) //$NON-NLS-1$
expectedChecksum = descriptor.getData();
if (ofNullable(expectedChecksum).orElse("").isEmpty()) { //$NON-NLS-1$
int code = buildErrorCode(descriptor);
setStatus(new Status(code, Activator.ID, NLS.bind(Messages.Error_invalid_checksum, algorithmName, expectedChecksum)));
}
}
private void basicInitialize(IProcessingStepDescriptor descriptor) {
try {
messageDigest = MessageDigest.getInstance(algorithmName);
setStatus(Status.OK_STATUS);
} catch (NoSuchAlgorithmException e) {
int code = buildErrorCode(descriptor);
setStatus(new Status(code, Activator.ID, NLS.bind(Messages.Error_checksum_unavailable, algorithmName), e));
}
}
private int buildErrorCode(IProcessingStepDescriptor descriptor) {
return (descriptor == null) ? IStatus.ERROR : descriptor.isRequired() ? IStatus.ERROR : IStatus.INFO;
}
@Override
final protected void onClose(String digestString) {
// if the hashes don't line up set the status to error.
......@@ -73,4 +76,16 @@ final public class ChecksumVerifier extends MessageDigestProcessingStep {
setStatus(new Status(IStatus.ERROR, Activator.ID, ProvisionException.ARTIFACT_MD5_NOT_MATCH, NLS.bind(Messages.Error_unexpected_checksum, new Object[] {algorithmName, expectedChecksum, digestString}), null));
}
public String getExpectedChecksum() {
return expectedChecksum;
}
public String getAlgorithmName() {
return algorithmName;
}
public String getAlgorithmId() {
return algorithmId;
}
}
/*******************************************************************************
* Copyright (c) 2007, 2017 compeople AG and others.
* Copyright (c) 2007, 2018 compeople AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
......@@ -11,6 +11,7 @@
* Contributors:
* compeople AG (Stefan Liebig) - initial API and implementation
* IBM Corporation - ongoing development
* Mykola Nikishov - continuing development
*******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.processors.pack200;
......@@ -47,7 +48,7 @@ public class Pack200ProcessorStep extends AbstractBufferingStep {
@Override
public void initialize(IProvisioningAgent agent, IProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
super.initialize(agent, descriptor, context);
if (!UnpackStep.canUnpack()) {
if (!isEnabled()) {
IStatus status = null;
if (detailedResult) {
status = new Status(IStatus.ERROR, Activator.ID, MirrorRequest.ARTIFACT_PROCESSING_ERROR, "Unpack facility not configured.", null); //$NON-NLS-1$
......@@ -103,4 +104,9 @@ public class Pack200ProcessorStep extends AbstractBufferingStep {
new JarProcessorExecutor().runJarProcessor(options);
return new File(getWorkDir(), incoming.getName().substring(0, incoming.getName().length() - PACKED_SUFFIX.length()));
}
@Override
public boolean isEnabled() {
return UnpackStep.canUnpack();
}
}