forked from eclipse-tycho/tycho
/
ReactorRepositoryManagerTest.java
117 lines (97 loc) · 4.89 KB
/
ReactorRepositoryManagerTest.java
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*******************************************************************************
* Copyright (c) 2013, 2021 SAP SE and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* SAP SE - initial API and implementation
* Christoph Läubrich - adjust to new API
*******************************************************************************/
package org.eclipse.tycho.p2.manager;
import static org.eclipse.tycho.p2.testutil.InstallableUnitMatchers.unitWithId;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.Arrays;
import java.util.Collection;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.ReactorProjectIdentities;
import org.eclipse.tycho.core.ee.shared.ExecutionEnvironmentConfigurationStub;
import org.eclipse.tycho.core.resolver.shared.MavenRepositoryLocation;
import org.eclipse.tycho.core.shared.MavenContextImpl;
import org.eclipse.tycho.p2.impl.test.ReactorProjectStub;
import org.eclipse.tycho.p2.impl.test.ResourceUtil;
import org.eclipse.tycho.p2.target.P2TargetPlatform;
import org.eclipse.tycho.p2.target.PomDependencyCollectorImpl;
import org.eclipse.tycho.p2.target.facade.PomDependencyCollector;
import org.eclipse.tycho.p2.target.facade.TargetPlatformConfigurationStub;
import org.eclipse.tycho.repository.registry.ReactorRepositoryManager;
import org.eclipse.tycho.repository.registry.facade.ReactorRepositoryManagerFacade;
import org.eclipse.tycho.test.util.MavenServiceStubbingTestBase;
import org.eclipse.tycho.test.util.ReactorProjectIdentitiesStub;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.osgi.framework.FrameworkUtil;
import org.osgi.util.tracker.ServiceTracker;
public class ReactorRepositoryManagerTest extends MavenServiceStubbingTestBase {
private ReactorRepositoryManagerFacade subject;
@Rule
public final TemporaryFolder tempManager = new TemporaryFolder();
private PomDependencyCollector pomDependencyCollector;
@Before
public void setUpContext() throws Exception {
pomDependencyCollector = new PomDependencyCollectorImpl(
new MavenContextImpl(tempManager.newFolder("localRepo"), logVerifier.getLogger()),
new ReactorProjectStub(tempManager.newFolder(), "test"));
}
@Test
public void testReactorRepositoryManagerServiceAvailability() throws Exception {
subject = getService(ReactorRepositoryManager.class);
assertThat(subject, is(notNullValue()));
}
@Test
public void testReactorRepositoryManagerFacadeServiceAvailability() throws Exception {
subject = getService(ReactorRepositoryManagerFacade.class);
assertThat(subject, is(notNullValue()));
}
@Test
public void testTargetPlatformComputationInIntegration() throws Exception {
subject = getService(ReactorRepositoryManagerFacade.class);
ReactorProject currentProject = new ReactorProjectStub("reactor-artifact");
TargetPlatformConfigurationStub tpConfig = new TargetPlatformConfigurationStub();
tpConfig.addP2Repository(
new MavenRepositoryLocation(null, ResourceUtil.resourceFile("repositories/launchers").toURI()));
subject.computePreliminaryTargetPlatform(currentProject, tpConfig,
new ExecutionEnvironmentConfigurationStub("JavaSE-1.7"), null);
ReactorProjectIdentities upstreamProject = new ReactorProjectIdentitiesStub(
ResourceUtil.resourceFile("projectresult"));
subject.computeFinalTargetPlatform(currentProject, Arrays.asList(upstreamProject), pomDependencyCollector);
P2TargetPlatform finalTP = (P2TargetPlatform) currentProject
.getContextValue("org.eclipse.tycho.core.TychoConstants/targetPlatform");
Collection<IInstallableUnit> units = finalTP.getInstallableUnits();
// units from the p2 repository
assertThat(units, hasItem(unitWithId("org.eclipse.equinox.launcher")));
// units from the upstream project
assertThat(units, hasItem(unitWithId("bundle")));
assertThat(units, hasItem(unitWithId("bundle.source")));
// TODO get artifact
}
private <T> T getService(Class<T> type) throws Exception {
ServiceTracker<T, T> tracker = new ServiceTracker<>(FrameworkUtil.getBundle(this.getClass()).getBundleContext(),
type, null);
tracker.open();
try {
return tracker.waitForService(2000);
} finally {
tracker.close();
}
}
}