Lines 8-30
Link Here
|
8 |
*******************************************************************************/ |
8 |
*******************************************************************************/ |
9 |
package org.eclipse.equinox.internal.simpleconfigurator.manipulator; |
9 |
package org.eclipse.equinox.internal.simpleconfigurator.manipulator; |
10 |
|
10 |
|
11 |
import java.io.File; |
11 |
import java.io.*; |
12 |
import java.io.IOException; |
|
|
13 |
import java.net.URI; |
12 |
import java.net.URI; |
14 |
import java.net.URL; |
|
|
15 |
import java.util.*; |
13 |
import java.util.*; |
16 |
import org.eclipse.core.runtime.URIUtil; |
14 |
import org.eclipse.core.runtime.URIUtil; |
|
|
15 |
import org.eclipse.equinox.frameworkadmin.BundleInfo; |
17 |
import org.eclipse.equinox.internal.frameworkadmin.equinox.ParserUtils; |
16 |
import org.eclipse.equinox.internal.frameworkadmin.equinox.ParserUtils; |
18 |
import org.eclipse.equinox.internal.frameworkadmin.utils.Utils; |
17 |
import org.eclipse.equinox.internal.frameworkadmin.utils.Utils; |
|
|
18 |
import org.eclipse.equinox.internal.provisional.configuratormanipulator.ConfiguratorManipulator; |
19 |
import org.eclipse.equinox.internal.provisional.frameworkadmin.*; |
19 |
import org.eclipse.equinox.internal.provisional.frameworkadmin.*; |
20 |
import org.eclipse.equinox.internal.provisional.simpleconfigurator.manipulator.SimpleConfiguratorManipulator; |
20 |
import org.eclipse.equinox.internal.simpleconfigurator.utils.EquinoxUtils; |
21 |
import org.eclipse.equinox.internal.simpleconfigurator.utils.SimpleConfiguratorUtils; |
21 |
import org.eclipse.equinox.internal.simpleconfigurator.utils.SimpleConfiguratorUtils; |
|
|
22 |
import org.eclipse.equinox.simpleconfigurator.manipulator.SimpleConfiguratorManipulator; |
23 |
import org.eclipse.osgi.service.datalocation.Location; |
24 |
import org.osgi.framework.BundleContext; |
22 |
import org.osgi.framework.Constants; |
25 |
import org.osgi.framework.Constants; |
23 |
|
26 |
|
24 |
/** |
27 |
/** |
25 |
* |
28 |
* |
26 |
*/ |
29 |
*/ |
27 |
public class SimpleConfiguratorManipulatorImpl implements SimpleConfiguratorManipulator { |
30 |
public class SimpleConfiguratorManipulatorImpl implements SimpleConfiguratorManipulator, ConfiguratorManipulator { |
28 |
class LocationInfo { |
31 |
class LocationInfo { |
29 |
URI[] prerequisiteLocations = null; |
32 |
URI[] prerequisiteLocations = null; |
30 |
URI systemBundleLocation = null; |
33 |
URI systemBundleLocation = null; |
Lines 289-299
Link Here
|
289 |
} |
292 |
} |
290 |
} |
293 |
} |
291 |
|
294 |
|
292 |
public BundleInfo[] loadConfiguration(URL url, File base) throws IOException { |
295 |
public BundleInfo[] loadConfiguration(BundleContext context, String infoPath) throws IOException { |
293 |
if (url == null) |
296 |
URI installArea = EquinoxUtils.getInstallLocationURI(context); |
|
|
297 |
Location configLocation = EquinoxUtils.getConfigLocation(context); |
298 |
|
299 |
return loadConfiguration(configLocation.getDataArea(infoPath).openStream(), installArea); |
300 |
} |
301 |
|
302 |
/* |
303 |
* InputStream must be closed |
304 |
* (non-Javadoc) |
305 |
* @see org.eclipse.equinox.simpleconfigurator.manipulator.SimpleConfiguratorManipulator#loadConfiguration(java.io.InputStream, java.net.URI) |
306 |
*/ |
307 |
public BundleInfo[] loadConfiguration(InputStream stream, URI installArea) throws IOException { |
308 |
if (stream == null) |
294 |
return NULL_BUNDLEINFOS; |
309 |
return NULL_BUNDLEINFOS; |
295 |
|
310 |
|
296 |
List simpleBundles = SimpleConfiguratorUtils.readConfiguration(url, base != null ? base.toURI() : null); |
311 |
List simpleBundles = SimpleConfiguratorUtils.readConfiguration(stream, installArea); |
297 |
|
312 |
|
298 |
// convert to FrameworkAdmin BundleInfo Type |
313 |
// convert to FrameworkAdmin BundleInfo Type |
299 |
BundleInfo[] result = new BundleInfo[simpleBundles.size()]; |
314 |
BundleInfo[] result = new BundleInfo[simpleBundles.size()]; |
Lines 310-320
Link Here
|
310 |
return result; |
325 |
return result; |
311 |
} |
326 |
} |
312 |
|
327 |
|
313 |
public void saveConfiguration(BundleInfo[] configuration, File outputFile, File base) throws IOException { |
328 |
public void saveConfiguration(BundleInfo[] configuration, OutputStream stream, URI installArea) throws IOException { |
314 |
saveConfiguration(configuration, outputFile, base, false); |
329 |
org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[] simpleInfos = convertBundleInfos(configuration, installArea); |
|
|
330 |
SimpleConfiguratorManipulatorUtils.writeConfiguration(simpleInfos, stream); |
315 |
} |
331 |
} |
316 |
|
332 |
|
317 |
private void saveConfiguration(BundleInfo[] configuration, File outputFile, File base, boolean backup) throws IOException { |
333 |
public void saveConfiguration(BundleInfo[] configuration, File outputFile, URI installArea) throws IOException { |
|
|
334 |
saveConfiguration(configuration, outputFile, installArea, false); |
335 |
} |
336 |
|
337 |
private void saveConfiguration(BundleInfo[] configuration, File outputFile, URI installArea, boolean backup) throws IOException { |
318 |
if (backup && outputFile.exists()) { |
338 |
if (backup && outputFile.exists()) { |
319 |
File backupFile = Utils.getSimpleDataFormattedFile(outputFile); |
339 |
File backupFile = Utils.getSimpleDataFormattedFile(outputFile); |
320 |
if (!outputFile.renameTo(backupFile)) { |
340 |
if (!outputFile.renameTo(backupFile)) { |
Lines 322-339
Link Here
|
322 |
} |
342 |
} |
323 |
} |
343 |
} |
324 |
|
344 |
|
|
|
345 |
org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[] simpleInfos = convertBundleInfos(configuration, installArea); |
346 |
|
347 |
// if empty remove the configuration file |
348 |
if (simpleInfos == null || simpleInfos.length == 0) { |
349 |
if (outputFile.exists()) { |
350 |
outputFile.delete(); |
351 |
} |
352 |
File parentDir = outputFile.getParentFile(); |
353 |
if (parentDir.exists()) { |
354 |
parentDir.delete(); |
355 |
} |
356 |
return; |
357 |
} |
358 |
SimpleConfiguratorManipulatorUtils.writeConfiguration(simpleInfos, outputFile); |
359 |
} |
360 |
|
361 |
private org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[] convertBundleInfos(BundleInfo[] configuration, URI installArea) { |
325 |
// convert to SimpleConfigurator BundleInfo Type |
362 |
// convert to SimpleConfigurator BundleInfo Type |
326 |
org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[] simpleInfos = new org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[configuration.length]; |
363 |
org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[] simpleInfos = new org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[configuration.length]; |
327 |
for (int i = 0; i < configuration.length; i++) { |
364 |
for (int i = 0; i < configuration.length; i++) { |
328 |
BundleInfo bundleInfo = configuration[i]; |
365 |
BundleInfo bundleInfo = configuration[i]; |
329 |
String symbolicName = bundleInfo.getSymbolicName(); |
366 |
URI location = bundleInfo.getLocation(); |
330 |
String bundleVersion = bundleInfo.getVersion(); |
367 |
if (bundleInfo.getSymbolicName() == null || bundleInfo.getVersion() == null || location == null) |
331 |
URI location = base != null ? URIUtil.makeRelative(bundleInfo.getLocation(), base.toURI()) : bundleInfo.getLocation(); |
|
|
332 |
if (symbolicName == null || bundleVersion == null || location == null) |
333 |
throw new IllegalArgumentException("Cannot persist bundleinfo: " + bundleInfo.toString()); |
368 |
throw new IllegalArgumentException("Cannot persist bundleinfo: " + bundleInfo.toString()); |
334 |
simpleInfos[i] = new org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo(symbolicName, bundleVersion, location, bundleInfo.getStartLevel(), bundleInfo.isMarkedAsStarted()); |
369 |
//only need to make a new BundleInfo if we are changing it. |
|
|
370 |
if (installArea != null) |
371 |
location = URIUtil.makeRelative(location, installArea); |
372 |
simpleInfos[i] = new org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo(bundleInfo.getSymbolicName(), bundleInfo.getVersion(), location, bundleInfo.getStartLevel(), bundleInfo.isMarkedAsStarted()); |
335 |
} |
373 |
} |
336 |
SimpleConfiguratorManipulatorUtils.writeConfiguration(simpleInfos, outputFile); |
374 |
return simpleInfos; |
337 |
} |
375 |
} |
338 |
|
376 |
|
339 |
public BundleInfo[] save(Manipulator manipulator, boolean backup) throws IOException { |
377 |
public BundleInfo[] save(Manipulator manipulator, boolean backup) throws IOException { |
Lines 345-351
Link Here
|
345 |
return configData.getBundles(); |
383 |
return configData.getBundles(); |
346 |
|
384 |
|
347 |
File outputFile = getConfigFile(manipulator); |
385 |
File outputFile = getConfigFile(manipulator); |
348 |
saveConfiguration((BundleInfo[]) setToSimpleConfig.toArray(new BundleInfo[setToSimpleConfig.size()]), outputFile, ParserUtils.getOSGiInstallArea(Arrays.asList(manipulator.getLauncherData().getProgramArgs()), manipulator.getConfigData().getProperties(), manipulator.getLauncherData()), backup); |
386 |
URI installArea = ParserUtils.getOSGiInstallArea(Arrays.asList(manipulator.getLauncherData().getProgramArgs()), manipulator.getConfigData().getProperties(), manipulator.getLauncherData()).toURI(); |
|
|
387 |
saveConfiguration((BundleInfo[]) setToSimpleConfig.toArray(new BundleInfo[setToSimpleConfig.size()]), outputFile, installArea, backup); |
349 |
configData.setProperty(SimpleConfiguratorManipulatorImpl.PROP_KEY_CONFIGURL, outputFile.toURL().toExternalForm()); |
388 |
configData.setProperty(SimpleConfiguratorManipulatorImpl.PROP_KEY_CONFIGURL, outputFile.toURL().toExternalForm()); |
350 |
return orderingInitialConfig(setToInitialConfig); |
389 |
return orderingInitialConfig(setToInitialConfig); |
351 |
} |
390 |
} |
Lines 414-420
Link Here
|
414 |
boolean exclusiveInstallation = Boolean.valueOf(properties.getProperty(SimpleConfiguratorManipulatorImpl.PROP_KEY_EXCLUSIVE_INSTALLATION)).booleanValue(); |
453 |
boolean exclusiveInstallation = Boolean.valueOf(properties.getProperty(SimpleConfiguratorManipulatorImpl.PROP_KEY_EXCLUSIVE_INSTALLATION)).booleanValue(); |
415 |
File configFile = getConfigFile(manipulator); |
454 |
File configFile = getConfigFile(manipulator); |
416 |
|
455 |
|
417 |
BundleInfo[] toInstall = loadConfiguration(configFile.toURL(), ParserUtils.getOSGiInstallArea(Arrays.asList(manipulator.getLauncherData().getProgramArgs()), manipulator.getConfigData().getProperties(), manipulator.getLauncherData())); |
456 |
File installArea = ParserUtils.getOSGiInstallArea(Arrays.asList(manipulator.getLauncherData().getProgramArgs()), manipulator.getConfigData().getProperties(), manipulator.getLauncherData()); |
|
|
457 |
//input stream will be closed for us |
458 |
BundleInfo[] toInstall = loadConfiguration(new FileInputStream(configFile), installArea.toURI()); |
418 |
|
459 |
|
419 |
List toUninstall = new LinkedList(); |
460 |
List toUninstall = new LinkedList(); |
420 |
if (exclusiveInstallation) |
461 |
if (exclusiveInstallation) |