Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0aae2a45711dda2efdbc06b2b88ee7176461c1f2 (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
/*******************************************************************************
 *  Copyright (c) 2010, 2017 Sonatype, Inc 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:
 *     Sonatype, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.p2.tests.metadata;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.metadata.*;
import org.eclipse.equinox.p2.metadata.expression.*;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;

public class PersistFragment extends AbstractProvisioningTest {

	public void testPersistFragmentIn35Repo() throws ProvisionException {
		//Pre 3.6, the host requirements were also persisted as part of the requirements
		IInstallableUnitFragment fragment = createIUFragment(createEclipseIU("A"), "MyHost", Version.createOSGi(1, 0, 0));
		File repoFolder = getTempFolder();
		IMetadataRepository repo = createMetadataRepository(repoFolder.toURI(), null);
		Collection<IInstallableUnit> ius = new ArrayList<>();
		ius.add(fragment);
		repo.addInstallableUnits(ius);

		getMetadataRepositoryManager().removeRepository(repoFolder.toURI());

		IInstallableUnit iu = getMetadataRepositoryManager().loadRepository(repoFolder.toURI(), null).query(QueryUtil.createIUQuery("MyHost"), null).toArray(IInstallableUnit.class)[0];
		assertEquals(1, iu.getRequirements().size());

		assertEquals(fragment.getHost().iterator().next(), iu.getRequirements().iterator().next());
		assertNoContents(new File(repoFolder, "content.xml"), new String[] {"generation='2'"});
	}

	//Verify that in a 3.6 formatted IU, the host requirements are not persisted as part of the requirements
	public void testPersistFragmentIn36Repo() throws ProvisionException {
		String orExpression = "providedCapabilities.exists(pc | pc.namespace == 'org.eclipse.equinox.p2.iu' && (pc.name == 'org.eclipse.mylyn34' || pc.name == 'org.eclipse.mylyn35'))";
		IExpression expr = ExpressionUtil.parse(orExpression);
		IMatchExpression<IInstallableUnit> matchExpression = ExpressionUtil.getFactory().matchExpression(expr);
		IRequirement orRequirement = MetadataFactory.createRequirement(matchExpression, null, 0, 1, true);

		IInstallableUnitFragment fragment = createIUFragment(createEclipseIU("A"), "MyHost", Version.createOSGi(1, 0, 0), new IRequirement[] {orRequirement}, null, null);
		File repoFolder = getTempFolder();
		IMetadataRepository repo = createMetadataRepository(repoFolder.toURI(), null);
		Collection<IInstallableUnit> ius = new ArrayList<>();
		ius.add(fragment);
		repo.addInstallableUnits(ius);

		getMetadataRepositoryManager().removeRepository(repoFolder.toURI());

		IInstallableUnit iu = getMetadataRepositoryManager().loadRepository(repoFolder.toURI(), null).query(QueryUtil.createIUQuery("MyHost"), null).toArray(IInstallableUnit.class)[0];
		assertEquals(1, iu.getRequirements().size());

		assertFalse(fragment.getHost().iterator().next().equals(iu.getRequirements().iterator().next()));
		assertContents(new File(repoFolder, "content.xml"), new String[] {"generation='2'"});
	}
}

Back to the top