Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9c274bab6af3dda1818e7affb0dd192fbeb4116d (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
/*******************************************************************************
 *  Copyright (c) 2009 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.ant;

import java.io.File;
import java.net.URI;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
import org.eclipse.equinox.p2.tests.AbstractAntProvisioningTest;

public class RepoTasksTests extends AbstractAntProvisioningTest {
	private static final String MIRROR_TASK = "p2.mirror";
	private static final String REMOVE_IU_TASK = "p2.remove.iu";

	private URI destinationRepo;
	private URI sourceRepo;

	public void setUp() throws Exception {
		super.setUp();
		// Get a random location to create a repository
		destinationRepo = getTestFolder(getName()).toURI();
		sourceRepo = getTestData("error loading data", "testData/mirror/mirrorSourceRepo2").toURI();
	}

	public void tearDown() throws Exception {
		// Remove repository manager references
		getArtifactRepositoryManager().removeRepository(destinationRepo);
		getMetadataRepositoryManager().removeRepository(destinationRepo);
		getArtifactRepositoryManager().removeRepository(sourceRepo);
		getMetadataRepositoryManager().removeRepository(sourceRepo);
		// Cleanup disk
		delete(new File(destinationRepo).getParentFile());
		super.tearDown();
	}

	public void testRemoveIU() throws Exception {
		AntTaskElement mirror = new AntTaskElement(MIRROR_TASK);
		AntTaskElement source = new AntTaskElement("source");
		source.addElement(getRepositoryElement(sourceRepo, TYPE_BOTH));
		mirror.addElement(source);
		mirror.addElement(getRepositoryElement(destinationRepo, TYPE_BOTH));
		addTask(mirror);

		AntTaskElement removeIU = new AntTaskElement(REMOVE_IU_TASK);
		removeIU.addElement(getRepositoryElement(destinationRepo, TYPE_BOTH));
		removeIU.addElement(getIUElement("anotherplugin", null));
		addTask(removeIU);

		runAntTask();

		IMetadataRepository metadata = loadMetadataRepository(destinationRepo);
		IInstallableUnit iu = getIU(metadata, "anotherplugin");
		assertNull(iu);

		IArtifactRepository artifacts = getArtifactRepositoryManager().loadRepository(destinationRepo, null);
		IArtifactKey[] keys = artifacts.getArtifactKeys();
		for (int i = 0; i < keys.length; i++) {
			assertFalse(keys[i].getId().equals("anotherplugin"));
		}
		assertFalse(new File(getTestFolder(getName()), "plugins/anotherplugin_1.0.0.jar").exists());
	}
}

Back to the top