Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 224269
Collapse All | Expand All

(-)src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java (-4 / +11 lines)
Lines 20-25 Link Here
20
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
20
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
21
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
21
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
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.metadata.IInstallableUnit;
24
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
24
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
25
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
25
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
26
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
Lines 76-81 Link Here
76
	}
77
	}
77
78
78
	public void addInstallableUnits(IInstallableUnit[] installableUnits) {
79
	public void addInstallableUnits(IInstallableUnit[] installableUnits) {
80
		if (installableUnits == null || installableUnits.length == 0)
81
			return;
79
		units.addAll(Arrays.asList(installableUnits));
82
		units.addAll(Arrays.asList(installableUnits));
80
		save();
83
		save();
81
	}
84
	}
Lines 110-121 Link Here
110
	}
113
	}
111
114
112
	public boolean removeInstallableUnits(Query query, IProgressMonitor monitor) {
115
	public boolean removeInstallableUnits(Query query, IProgressMonitor monitor) {
113
		int sizeBefore = units.size();
116
		boolean changed = false;
114
		for (Iterator it = units.iterator(); it.hasNext();)
117
		for (Iterator it = units.iterator(); it.hasNext();)
115
			if (query.isMatch(it.next()))
118
			if (query.isMatch(it.next())) {
116
				it.remove();
119
				it.remove();
117
		save();
120
				changed = true;
118
		return units.size() != sizeBefore;
121
			}
122
		if (changed)
123
			save();
124
		return changed;
119
	}
125
	}
120
126
121
	public void revertToBackup(LocalMetadataRepository backup) {
127
	public void revertToBackup(LocalMetadataRepository backup) {
Lines 159-164 Link Here
159
				jOutput.putNextEntry(jarEntry);
165
				jOutput.putNextEntry(jarEntry);
160
				output = jOutput;
166
				output = jOutput;
161
			}
167
			}
168
			super.setProperty(IRepository.PROP_TIMESTAMP, Long.toString(System.currentTimeMillis()));
162
			new MetadataRepositoryIO().write(this, output);
169
			new MetadataRepositoryIO().write(this, output);
163
		} catch (IOException e) {
170
		} catch (IOException e) {
164
			LogHelper.log(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_WRITE, "Error saving metadata repository: " + location, e)); //$NON-NLS-1$
171
			LogHelper.log(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_WRITE, "Error saving metadata repository: " + location, e)); //$NON-NLS-1$
(-)src/org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer.java (-1 / +101 lines)
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();) {
(-)src/org/eclipse/equinox/internal/provisional/p2/core/repository/IRepository.java (+5 lines)
Lines 53-58 Link Here
53
	public static final String PROP_MIRRORS_URL = "p2.mirrorsURL"; //$NON-NLS-1$
53
	public static final String PROP_MIRRORS_URL = "p2.mirrorsURL"; //$NON-NLS-1$
54
54
55
	/**
55
	/**
56
	 * The key for a string property containing the time when the repository was last modified.
57
	 */
58
	public static final String PROP_TIMESTAMP = "p2.timestamp"; //$NON-NLS-1$
59
60
	/**
56
	 * A repository type constant (value 0) representing a metadata repository.
61
	 * A repository type constant (value 0) representing a metadata repository.
57
	 */
62
	 */
58
	public static final int TYPE_METADATA = 0;
63
	public static final int TYPE_METADATA = 0;
(-)src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java (+2 lines)
Lines 24-29 Link Here
24
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
24
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
25
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepHandler;
25
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepHandler;
26
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
26
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
27
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository;
27
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
28
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
28
import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.AbstractArtifactRepository;
29
import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.AbstractArtifactRepository;
29
import org.eclipse.osgi.util.NLS;
30
import org.eclipse.osgi.util.NLS;
Lines 790-795 Link Here
790
					jOs.putNextEntry(new JarEntry(new Path(actualLocation.getFile()).lastSegment()));
791
					jOs.putNextEntry(new JarEntry(new Path(actualLocation.getFile()).lastSegment()));
791
					os = jOs;
792
					os = jOs;
792
				}
793
				}
794
				super.setProperty(IRepository.PROP_TIMESTAMP, Long.toString(System.currentTimeMillis()));
793
				new SimpleArtifactRepositoryIO().write(this, os);
795
				new SimpleArtifactRepositoryIO().write(this, os);
794
			} catch (IOException e) {
796
			} catch (IOException e) {
795
				// TODO proper exception handling
797
				// TODO proper exception handling

Return to bug 224269