blob: f6fa267861163bb269b2797254bb88f89c69786b (
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
|
/*******************************************************************************
* Copyright (c) 2007 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
******************************************************************************/
package org.eclipse.equinox.internal.prov.rollback;
import java.util.EventObject;
import java.util.Hashtable;
import org.eclipse.equinox.internal.prov.director.IUTransformationHelper;
import org.eclipse.equinox.prov.core.eventbus.ProvisioningEventBus;
import org.eclipse.equinox.prov.core.eventbus.SynchronousProvisioningListener;
import org.eclipse.equinox.prov.engine.*;
import org.eclipse.equinox.prov.metadata.*;
import org.eclipse.equinox.prov.metadata.repository.IWritableMetadataRepository;
import org.osgi.framework.Version;
public class FormerState {
IWritableMetadataRepository storage = null;
Hashtable generatedIUs = new Hashtable(); //key profile id, value the iu representing this profile
public FormerState(ProvisioningEventBus bus, IWritableMetadataRepository repo) {
if (bus == null || repo == null) {
throw new IllegalArgumentException("bus and storage can' be null"); //$NON-NLS-1$
}
storage = repo;
//listen for pre-event. to memorize the state of the profile
bus.addListener(new SynchronousProvisioningListener() {
public void notify(EventObject o) {
if (o instanceof BeginOperationEvent) {
BeginOperationEvent event = (BeginOperationEvent) o;
IInstallableUnit iuForProfile = profileToIU(event.getProfile());
generatedIUs.put(event.getProfile().getProfileId(), iuForProfile);
} else if (o instanceof CommitOperationEvent) {
CommitOperationEvent event = (CommitOperationEvent) o;
storage.addInstallableUnits(new IInstallableUnit[] {(IInstallableUnit) generatedIUs.get(event.getProfile().getProfileId())});
return;
} else if (o instanceof RollbackOperationEvent) {
RollbackOperationEvent event = (RollbackOperationEvent) o;
generatedIUs.remove(event.getProfile().getProfileId());
return;
}
//TODO We need to decide what to do on profile removal
// else if (o instanceof ProfileEvent) {
// ProfileEvent pe = (ProfileEvent) o;
// if (pe.getReason() == ProfileEvent.REMOVED) {
// profileRegistries.remove(pe.getProfile().getProfileId());
// persist();
// }
// }
}
});
}
IInstallableUnit profileToIU(Profile toConvert) {
InstallableUnit result = new InstallableUnit();
result.setProperty(IInstallableUnitConstants.PROFILE_IU_KEY, Boolean.TRUE.toString());
result.setId(toConvert.getProfileId());
result.setVersion(new Version(0, 0, 0, Long.toString(System.currentTimeMillis())));
result.setRequiredCapabilities(IUTransformationHelper.toRequirements(toConvert.getInstallableUnits(), false));
//TODO Need to do the properties in the profile
//TODO Do we need to mark profile with a special marker
return result;
}
// private copyProperty(Profile p) {
// Map profileProperties = p.getValues();
// }
}
|