|
Lines 9-15
Link Here
|
| 9 |
******************************************************************************/ |
9 |
******************************************************************************/ |
| 10 |
package org.eclipse.equinox.internal.p2.reconciler.dropins; |
10 |
package org.eclipse.equinox.internal.p2.reconciler.dropins; |
| 11 |
|
11 |
|
| 12 |
import java.io.IOException; |
12 |
import java.io.*; |
| 13 |
import java.net.MalformedURLException; |
13 |
import java.net.MalformedURLException; |
| 14 |
import java.net.URL; |
14 |
import java.net.URL; |
| 15 |
import java.util.*; |
15 |
import java.util.*; |
|
Lines 20-25
Link Here
|
| 20 |
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; |
20 |
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; |
| 21 |
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IFileArtifactRepository; |
21 |
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IFileArtifactRepository; |
| 22 |
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; |
22 |
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; |
|
|
23 |
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository; |
| 23 |
import org.eclipse.equinox.internal.provisional.p2.director.*; |
24 |
import org.eclipse.equinox.internal.provisional.p2.director.*; |
| 24 |
import org.eclipse.equinox.internal.provisional.p2.engine.*; |
25 |
import org.eclipse.equinox.internal.provisional.p2.engine.*; |
| 25 |
import org.eclipse.equinox.internal.provisional.p2.metadata.*; |
26 |
import org.eclipse.equinox.internal.provisional.p2.metadata.*; |
|
Lines 33-38
Link Here
|
| 33 |
* Synchronizes a profile with a set of repositories. |
34 |
* Synchronizes a profile with a set of repositories. |
| 34 |
*/ |
35 |
*/ |
| 35 |
public class ProfileSynchronizer { |
36 |
public class ProfileSynchronizer { |
|
|
37 |
private static final String TIMESTAMPS_FILE_PREFIX = "timestamps"; //$NON-NLS-1$ |
| 38 |
private static final String PROFILE_TIMESTAMP = "PROFILE"; //$NON-NLS-1$ |
| 39 |
private static final String NO_TIMESTAMP = "-1"; //$NON-NLS-1$ |
| 40 |
|
| 36 |
private static final String SUPER_IU = "org.eclipse.equinox.p2.dropins"; //$NON-NLS-1$ |
41 |
private static final String SUPER_IU = "org.eclipse.equinox.p2.dropins"; //$NON-NLS-1$ |
| 37 |
|
42 |
|
| 38 |
public class ListCollector extends Collector { |
43 |
public class ListCollector extends Collector { |
|
Lines 46-51
Link Here
|
| 46 |
final IProfile profile; |
51 |
final IProfile profile; |
| 47 |
|
52 |
|
| 48 |
final Map repositoryMap; |
53 |
final Map repositoryMap; |
|
|
54 |
private Properties timestamps; |
| 49 |
|
55 |
|
| 50 |
/* |
56 |
/* |
| 51 |
* Constructor for the class. |
57 |
* Constructor for the class. |
|
Lines 63-68
Link Here
|
| 63 |
* Synchronize the profile with the list of metadata repositories. |
69 |
* Synchronize the profile with the list of metadata repositories. |
| 64 |
*/ |
70 |
*/ |
| 65 |
public IStatus synchronize(IProgressMonitor monitor) { |
71 |
public IStatus synchronize(IProgressMonitor monitor) { |
|
|
72 |
readTimestamps(); |
| 73 |
if (isUpToDate()) |
| 74 |
return Status.OK_STATUS; |
| 66 |
|
75 |
|
| 67 |
IStatus status = synchronizeCacheExtensions(); |
76 |
IStatus status = synchronizeCacheExtensions(); |
| 68 |
if (!status.isOK()) |
77 |
if (!status.isOK()) |
|
Lines 70-75
Link Here
|
| 70 |
|
79 |
|
| 71 |
ProvisioningContext context = getContext(); |
80 |
ProvisioningContext context = getContext(); |
| 72 |
ProfileChangeRequest request = createProfileChangeRequest(context); |
81 |
ProfileChangeRequest request = createProfileChangeRequest(context); |
|
|
82 |
|
| 73 |
if (request == null) |
83 |
if (request == null) |
| 74 |
return Status.OK_STATUS; |
84 |
return Status.OK_STATUS; |
| 75 |
|
85 |
|
|
Lines 77-98
Link Here
|
| 77 |
try { |
87 |
try { |
| 78 |
//create the provisioning plan |
88 |
//create the provisioning plan |
| 79 |
ProvisioningPlan plan = createProvisioningPlan(request, context, sub.newChild(50)); |
89 |
ProvisioningPlan plan = createProvisioningPlan(request, context, sub.newChild(50)); |
|
|
90 |
|
| 80 |
status = plan.getStatus(); |
91 |
status = plan.getStatus(); |
| 81 |
if (status.getSeverity() == IStatus.ERROR || plan.getOperands().length == 0) |
92 |
if (status.getSeverity() == IStatus.ERROR || plan.getOperands().length == 0) |
| 82 |
return status; |
93 |
return status; |
| 83 |
|
94 |
|
| 84 |
//invoke the engine to perform installs/uninstalls |
95 |
//invoke the engine to perform installs/uninstalls |
| 85 |
IStatus engineResult = executePlan(plan, context, sub.newChild(50)); |
96 |
IStatus engineResult = executePlan(plan, context, sub.newChild(50)); |
|
|
97 |
|
| 86 |
if (!engineResult.isOK()) |
98 |
if (!engineResult.isOK()) |
| 87 |
return engineResult; |
99 |
return engineResult; |
|
|
100 |
writeTimestamps(); |
| 88 |
|
101 |
|
| 89 |
applyConfiguration(); |
102 |
applyConfiguration(); |
|
|
103 |
|
| 90 |
return status; |
104 |
return status; |
| 91 |
} finally { |
105 |
} finally { |
| 92 |
sub.done(); |
106 |
sub.done(); |
| 93 |
} |
107 |
} |
| 94 |
} |
108 |
} |
| 95 |
|
109 |
|
|
|
110 |
private void writeTimestamps() { |
| 111 |
timestamps.clear(); |
| 112 |
timestamps.put(PROFILE_TIMESTAMP, Long.toString(profile.getTimestamp())); |
| 113 |
for (Iterator it = repositoryMap.entrySet().iterator(); it.hasNext();) { |
| 114 |
Entry entry = (Entry) it.next(); |
| 115 |
IMetadataRepository repository = (IMetadataRepository) entry.getValue(); |
| 116 |
Map props = repository.getProperties(); |
| 117 |
String timestamp = null; |
| 118 |
if (props != null) |
| 119 |
timestamp = (String) props.get(IRepository.PROP_TIMESTAMP); |
| 120 |
|
| 121 |
if (timestamp == null) |
| 122 |
timestamp = NO_TIMESTAMP; |
| 123 |
|
| 124 |
timestamps.put(entry.getKey(), timestamp); |
| 125 |
} |
| 126 |
|
| 127 |
try { |
| 128 |
File file = Activator.getContext().getDataFile(TIMESTAMPS_FILE_PREFIX + profile.getProfileId().hashCode()); |
| 129 |
OutputStream os = new BufferedOutputStream(new FileOutputStream(file)); |
| 130 |
try { |
| 131 |
timestamps.save(os, "Timestamps for " + profile.getProfileId()); //$NON-NLS-1$ |
| 132 |
} finally { |
| 133 |
if (os != null) |
| 134 |
os.close(); |
| 135 |
} |
| 136 |
} catch (FileNotFoundException e) { |
| 137 |
//Ignore |
| 138 |
} catch (IOException e) { |
| 139 |
//Ignore |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
private boolean isUpToDate() { |
| 144 |
String lastKnownProfileTimeStamp = (String) timestamps.remove(PROFILE_TIMESTAMP); |
| 145 |
if (lastKnownProfileTimeStamp == null) |
| 146 |
return false; |
| 147 |
if (!lastKnownProfileTimeStamp.equals(Long.toString(profile.getTimestamp()))) |
| 148 |
return false; |
| 149 |
|
| 150 |
//When we get here the timestamps map only contains information related to repos |
| 151 |
for (Iterator it = repositoryMap.entrySet().iterator(); it.hasNext();) { |
| 152 |
Entry entry = (Entry) it.next(); |
| 153 |
IMetadataRepository repository = (IMetadataRepository) entry.getValue(); |
| 154 |
|
| 155 |
Map props = repository.getProperties(); |
| 156 |
String currentTimestamp = null; |
| 157 |
if (props != null) |
| 158 |
currentTimestamp = (String) props.get(IRepository.PROP_TIMESTAMP); |
| 159 |
|
| 160 |
if (currentTimestamp == null) |
| 161 |
currentTimestamp = NO_TIMESTAMP; |
| 162 |
|
| 163 |
String lastKnownTimestamp = (String) timestamps.remove(entry.getKey()); |
| 164 |
//A repo has been added |
| 165 |
if (lastKnownTimestamp == null) |
| 166 |
return false; |
| 167 |
if (!lastKnownTimestamp.equals(currentTimestamp)) { |
| 168 |
return false; |
| 169 |
} |
| 170 |
} |
| 171 |
//A repo has been removed |
| 172 |
if (timestamps.size() != 0) |
| 173 |
return false; |
| 174 |
|
| 175 |
return true; |
| 176 |
} |
| 177 |
|
| 178 |
private void readTimestamps() { |
| 179 |
File file = Activator.getContext().getDataFile(TIMESTAMPS_FILE_PREFIX + profile.getProfileId().hashCode()); |
| 180 |
timestamps = new Properties(); |
| 181 |
try { |
| 182 |
InputStream is = new BufferedInputStream(new FileInputStream(file)); |
| 183 |
try { |
| 184 |
timestamps.load(is); |
| 185 |
} finally { |
| 186 |
if (is != null) |
| 187 |
is.close(); |
| 188 |
} |
| 189 |
} catch (FileNotFoundException e) { |
| 190 |
//Ignore |
| 191 |
} catch (IOException e) { |
| 192 |
//Ignore |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 96 |
private ProvisioningContext getContext() { |
196 |
private ProvisioningContext getContext() { |
| 97 |
ArrayList repoURLs = new ArrayList(); |
197 |
ArrayList repoURLs = new ArrayList(); |
| 98 |
for (Iterator iterator = repositoryMap.keySet().iterator(); iterator.hasNext();) { |
198 |
for (Iterator iterator = repositoryMap.keySet().iterator(); iterator.hasNext();) { |