Search in sources :

Example 51 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project tycho by eclipse.

the class DependencyCollectorTest method missingDependencies.

@Test
public void missingDependencies() {
    InstallableUnitDescription iud = new MetadataFactory.InstallableUnitDescription();
    String time = Long.toString(System.currentTimeMillis());
    iud.setId(time);
    iud.setVersion(Version.createOSGi(0, 0, 0, time));
    ArrayList<IRequirement> requirements = new ArrayList<>();
    VersionRange range = new VersionRange("[1.2.3,1.2.4)");
    requirements.add(MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "this.is.a.missing.iu", range, null, 1, /* min */
    1, /* max */
    true));
    iud.setRequirements(requirements.toArray(new IRequirement[requirements.size()]));
    HashSet<IInstallableUnit> rootUIs = new HashSet<>();
    rootUIs.add(MetadataFactory.createInstallableUnit(iud));
    ResolutionDataImpl data = new ResolutionDataImpl(ExecutionEnvironmentTestUtils.NOOP_EE_RESOLUTION_HINTS);
    data.setRootIUs(rootUIs);
    data.setAdditionalRequirements(new ArrayList<IRequirement>());
    data.setAvailableIUs(Collections.<IInstallableUnit>emptyList());
    DependencyCollector dc = new DependencyCollector(logVerifier.getLogger());
    dc.setData(data);
    try {
        dc.resolve(Collections.<String, String>emptyMap(), new NullProgressMonitor());
        Assert.fail();
    } catch (RuntimeException e) {
        Throwable cause = e.getCause();
        Assert.assertTrue(cause instanceof ProvisionException);
        ProvisionException pe = (ProvisionException) cause;
        Assert.assertTrue(pe.getStatus().isMultiStatus());
        MultiStatus status = (MultiStatus) pe.getStatus();
        Assert.assertEquals(1, status.getChildren().length);
        Assert.assertTrue(e.toString().contains("this.is.a.missing.iu"));
    }
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) InstallableUnitDescription(org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) VersionRange(org.eclipse.equinox.p2.metadata.VersionRange) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 52 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project tycho by eclipse.

the class ProjectorResolutionStrategyTest method testFixSwtWithNLSFragmentPresent.

@Test
public void testFixSwtWithNLSFragmentPresent() throws Exception {
    selectedIUs.add(InstallableUnitUtil.createIU("org.eclipse.swt", "1.0.0"));
    IInstallableUnit swtImplFragment = createSwtFragment("linux", "gtk", "x86_64", null);
    IInstallableUnit swtNLSFragment = createSwtFragment("linux", "gtk", "x86_64", "de");
    final List<IInstallableUnit> availableIUs = new ArrayList<>();
    availableIUs.addAll(selectedIUs);
    availableIUs.add(swtNLSFragment);
    availableIUs.add(swtImplFragment);
    strategy.fixSWT(availableIUs, selectedIUs, createSelectionContext("linux", "gtk", "x86_64"), monitor);
    assertThat(selectedIUs.size(), is(2));
    assertThat(selectedIUs, hasItem(swtImplFragment));
}
Also used : ArrayList(java.util.ArrayList) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) Test(org.junit.Test)

Example 53 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project tycho by eclipse.

the class ProjectorResolutionStrategyTest method testFixSwtSwtFragmentInRootIUs.

@Test
public void testFixSwtSwtFragmentInRootIUs() throws Exception {
    IInstallableUnit rootIU = createSwtFragment("linux", "gtk", "x86_64", null);
    selectedIUs.add(InstallableUnitUtil.createIU("org.eclipse.swt", "1.0.0"));
    invokefixSwtWithLinuxFragmentPresent(rootIU, selectedIUs);
    assertThat(selectedIUs.size(), is(1));
    assertThat(selectedIUs, hasItem(InstallableUnitUtil.createIU("org.eclipse.swt", "1.0.0")));
}
Also used : IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) Test(org.junit.Test)

Example 54 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project tycho by eclipse.

the class ProjectorResolutionStrategyTest method invokefixSwtWithLinuxFragmentPresent.

private void invokefixSwtWithLinuxFragmentPresent(IInstallableUnit rootIU, final List<IInstallableUnit> selectedIUs) {
    data.setRootIUs(Collections.singleton(rootIU));
    final List<IInstallableUnit> availableIUs = new ArrayList<>();
    IInstallableUnit swtImplFragment = createSwtFragment("linux", "gtk", "x86_64", null);
    availableIUs.addAll(selectedIUs);
    availableIUs.add(swtImplFragment);
    strategy.fixSWT(availableIUs, selectedIUs, createSelectionContext("linux", "gtk", "x86_64"), monitor);
}
Also used : ArrayList(java.util.ArrayList) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 55 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project tycho by eclipse.

the class ProjectorResolutionStrategyTest method createSwtFragment.

private IInstallableUnit createSwtFragment(String os, String ws, String arch, String nls) {
    Map<String, String> capsMap = new HashMap<>();
    capsMap.put("osgi.fragment", "org.eclipse.swt");
    if (nls == null) {
        // NLS fragments do not provide packages
        capsMap.put("java.package", "foo");
    }
    String iuSuffix;
    iuSuffix = os + "." + ws + "." + arch;
    if (nls != null) {
        iuSuffix += "." + nls;
    }
    IInstallableUnit linuxSwtFragment = InstallableUnitUtil.createIUWithCapabilitiesAndFilter("org.eclipse.swt." + iuSuffix, "1.0.0", createCapabilities(capsMap), "(&(osgi.arch=" + arch + ")(osgi.os=" + os + ")(osgi.ws=" + ws + "))");
    return linuxSwtFragment;
}
Also used : HashMap(java.util.HashMap) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Aggregations

IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)153 Test (org.junit.Test)58 ArrayList (java.util.ArrayList)44 File (java.io.File)38 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)25 HashSet (java.util.HashSet)18 IStatus (org.eclipse.core.runtime.IStatus)18 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)16 IMetadataRepository (org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)15 HashMap (java.util.HashMap)13 LinkedHashSet (java.util.LinkedHashSet)11 CoreException (org.eclipse.core.runtime.CoreException)11 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)11 ResourceUtil.resourceFile (org.eclipse.tycho.p2.tools.test.util.ResourceUtil.resourceFile)11 URI (java.net.URI)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 SubMonitor (org.eclipse.core.runtime.SubMonitor)9 ArtifactMock (org.eclipse.tycho.p2.impl.test.ArtifactMock)9 Status (org.eclipse.core.runtime.Status)8 IRequiredCapability (org.eclipse.equinox.internal.p2.metadata.IRequiredCapability)8