Skip to main content
summaryrefslogtreecommitdiffstats
blob: e17bde096c8ad87c52895503866230c353dae268 (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
/*******************************************************************************
 * Copyright (c) 2010, 2017 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.p2.tests.gc;

import java.io.File;
import java.net.URI;
import java.util.HashMap;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.garbagecollector.CoreGarbageCollector;
import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.repository.artifact.*;
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;

/**
 * Tests for the sweep (clean) phase of the garbage collection
 */
public class GCCleanTest extends AbstractProvisioningTest {
	private IArtifactRepository createRepository(File location) throws ProvisionException {
		URI repositoryURI = location.toURI();

		IArtifactRepository repo = getArtifactRepositoryManager().createRepository(repositoryURI, "test", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, new HashMap<>());

		ArtifactDescriptor d1 = new ArtifactDescriptor(new ArtifactKey("osgi.bundle", "a", Version.create("1.0.0")));
		ArtifactDescriptor d2 = new ArtifactDescriptor(new ArtifactKey("osgi.bundle", "a", Version.create("2.0.0")));
		ArtifactDescriptor d3 = new ArtifactDescriptor(new ArtifactKey("osgi.bundle", "a", Version.create("2.0.0")));
		d3.setProperty(IArtifactDescriptor.FORMAT, IArtifactDescriptor.FORMAT_PACKED);
		IProgressMonitor monitor = new NullProgressMonitor();
		repo.addDescriptor(d1, monitor);
		repo.addDescriptor(d2, monitor);
		repo.addDescriptor(d3, monitor);
		return repo;
	}

	public void testRemoveAll() throws ProvisionException {
		File folder = getTestFolder("GCCleanTest.testRemoveAll");
		IArtifactRepository repository = createRepository(folder);

		CoreGarbageCollector gc = new CoreGarbageCollector();

		gc.clean(new IArtifactKey[0], repository);

		assertEquals("1.0", 0, repository.query(ArtifactKeyQuery.ALL_KEYS, null).toSet().size());

	}
}

Back to the top