Search in sources :

Example 26 with Configuration

use of org.apache.ivy.core.module.descriptor.Configuration in project ant-ivy by apache.

the class OSGiManifestParserTest method testSimple.

@Test
public void testSimple() throws Exception {
    ModuleDescriptor md = OSGiManifestParser.getInstance().parseDescriptor(settings, getClass().getResource("MANIFEST_classpath.MF"), true);
    assertNotNull(md);
    assertEquals("bundle", md.getModuleRevisionId().getOrganisation());
    assertEquals("org.apache.ivy.test", md.getModuleRevisionId().getName());
    assertEquals("1.0.0", md.getModuleRevisionId().getRevision());
    assertNotNull(md.getConfigurations());
    assertEquals(Arrays.asList(new Configuration("default"), new Configuration("optional"), new Configuration("transitive-optional")), Arrays.asList(md.getConfigurations()));
    assertEquals(0, md.getAllArtifacts().length);
    assertNotNull(md.getDependencies());
    assertEquals(0, md.getDependencies().length);
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) Configuration(org.apache.ivy.core.module.descriptor.Configuration) Test(org.junit.Test)

Example 27 with Configuration

use of org.apache.ivy.core.module.descriptor.Configuration in project ant-ivy by apache.

the class AbstractOSGiResolver method buildResolvedCapabilityMd.

private MDResolvedResource buildResolvedCapabilityMd(DependencyDescriptor dd, ModuleDescriptor md) {
    String org = dd.getDependencyRevisionId().getOrganisation();
    String name = dd.getDependencyRevisionId().getName();
    String rev = md.getExtraInfoContentByTagName(BundleInfoAdapter.EXTRA_INFO_EXPORT_PREFIX + name);
    ModuleRevisionId capabilityRev = ModuleRevisionId.newInstance(org, name, rev, Collections.singletonMap(CAPABILITY_EXTRA_ATTR, md.getModuleRevisionId().toString()));
    DefaultModuleDescriptor capabilityMd = new DefaultModuleDescriptor(capabilityRev, getSettings().getStatusManager().getDefaultStatus(), new Date());
    String useConf = BundleInfoAdapter.CONF_USE_PREFIX + dd.getDependencyRevisionId().getName();
    capabilityMd.addConfiguration(BundleInfoAdapter.CONF_DEFAULT);
    capabilityMd.addConfiguration(BundleInfoAdapter.CONF_OPTIONAL);
    capabilityMd.addConfiguration(BundleInfoAdapter.CONF_TRANSITIVE_OPTIONAL);
    capabilityMd.addConfiguration(new Configuration(useConf));
    DefaultDependencyDescriptor capabilityDD = new DefaultDependencyDescriptor(md.getModuleRevisionId(), false);
    capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_DEFAULT, BundleInfoAdapter.CONF_NAME_DEFAULT);
    capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_OPTIONAL, BundleInfoAdapter.CONF_NAME_OPTIONAL);
    capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_TRANSITIVE_OPTIONAL, BundleInfoAdapter.CONF_NAME_TRANSITIVE_OPTIONAL);
    capabilityDD.addDependencyConfiguration(useConf, useConf);
    capabilityMd.addDependency(capabilityDD);
    MetadataArtifactDownloadReport report = new MetadataArtifactDownloadReport(null);
    report.setDownloadStatus(DownloadStatus.NO);
    report.setSearched(true);
    ResolvedModuleRevision rmr = new ResolvedModuleRevision(this, this, capabilityMd, report);
    return new MDResolvedResource(null, capabilityMd.getRevision(), rmr);
}
Also used : MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) Date(java.util.Date) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource)

Example 28 with Configuration

use of org.apache.ivy.core.module.descriptor.Configuration in project ant-ivy by apache.

the class BundleInfoAdapter method toModuleDescriptor.

/**
 * @param parser ModuleDescriptorParser
 * @param baseUri
 *            uri to help build the absolute url if the bundle info has a relative uri.
 * @param bundle BundleInfo
 * @param manifest Manifest
 * @param profileProvider ExecutionEnvironmentProfileProvider
 * @return DefaultModuleDescriptor ditto
 * @throws ProfileNotFoundException if descriptor is not found
 */
public static DefaultModuleDescriptor toModuleDescriptor(ModuleDescriptorParser parser, URI baseUri, BundleInfo bundle, Manifest manifest, ExecutionEnvironmentProfileProvider profileProvider) throws ProfileNotFoundException {
    DefaultModuleDescriptor md = new DefaultModuleDescriptor(parser, null);
    md.addExtraAttributeNamespace("o", Ivy.getIvyHomeURL() + "osgi");
    ModuleRevisionId mrid = asMrid(BundleInfo.BUNDLE_TYPE, bundle.getSymbolicName(), bundle.getVersion());
    md.setResolvedPublicationDate(new Date());
    md.setModuleRevisionId(mrid);
    md.addConfiguration(CONF_DEFAULT);
    md.addConfiguration(CONF_OPTIONAL);
    md.addConfiguration(CONF_TRANSITIVE_OPTIONAL);
    Set<String> exportedPkgNames = new HashSet<>(bundle.getExports().size());
    for (ExportPackage exportPackage : bundle.getExports()) {
        md.getExtraInfos().add(new ExtraInfoHolder(EXTRA_INFO_EXPORT_PREFIX + exportPackage.getName(), exportPackage.getVersion().toString()));
        exportedPkgNames.add(exportPackage.getName());
        String[] confDependencies = new String[exportPackage.getUses().size() + 1];
        int i = 0;
        for (String use : exportPackage.getUses()) {
            confDependencies[i++] = CONF_USE_PREFIX + use;
        }
        confDependencies[i] = CONF_NAME_DEFAULT;
        md.addConfiguration(new Configuration(CONF_USE_PREFIX + exportPackage.getName(), PUBLIC, "Exported package " + exportPackage.getName(), confDependencies, true, null));
    }
    requirementAsDependency(md, bundle, exportedPkgNames);
    if (baseUri != null) {
        for (BundleArtifact bundleArtifact : bundle.getArtifacts()) {
            String type = "jar";
            String ext = "jar";
            String packaging = null;
            if (bundle.hasInnerClasspath() && !bundleArtifact.isSource()) {
                packaging = "bundle";
            }
            if ("packed".equals(bundleArtifact.getFormat())) {
                ext = "jar.pack.gz";
                if (packaging != null) {
                    packaging += ",pack200";
                } else {
                    packaging = "pack200";
                }
            }
            if (bundleArtifact.isSource()) {
                type = "source";
            }
            URI uri = bundleArtifact.getUri();
            if (uri != null) {
                DefaultArtifact artifact = buildArtifact(mrid, baseUri, uri, type, ext, packaging);
                md.addArtifact(CONF_NAME_DEFAULT, artifact);
            }
        }
    }
    if (profileProvider != null) {
        for (String env : bundle.getExecutionEnvironments()) {
            ExecutionEnvironmentProfile profile = profileProvider.getProfile(env);
            if (profile == null) {
                throw new ProfileNotFoundException("Execution environment profile " + env + " not found");
            }
            for (String pkg : profile.getPkgNames()) {
                ArtifactId id = new ArtifactId(ModuleId.newInstance(BundleInfo.PACKAGE_TYPE, pkg), PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION);
                DefaultExcludeRule rule = new DefaultExcludeRule(id, ExactOrRegexpPatternMatcher.INSTANCE, null);
                for (String conf : md.getConfigurationsNames()) {
                    rule.addConfiguration(conf);
                }
                md.addExcludeRule(rule);
            }
        }
    }
    if (manifest != null) {
        for (Map.Entry<Object, Object> entries : manifest.getMainAttributes().entrySet()) {
            md.addExtraInfo(new ExtraInfoHolder(entries.getKey().toString(), entries.getValue().toString()));
        }
    }
    return md;
}
Also used : Configuration(org.apache.ivy.core.module.descriptor.Configuration) ArtifactId(org.apache.ivy.core.module.id.ArtifactId) ExtraInfoHolder(org.apache.ivy.core.module.descriptor.ExtraInfoHolder) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) URI(java.net.URI) Date(java.util.Date) DefaultExcludeRule(org.apache.ivy.core.module.descriptor.DefaultExcludeRule) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) HashMap(java.util.HashMap) Map(java.util.Map) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) HashSet(java.util.HashSet)

Example 29 with Configuration

use of org.apache.ivy.core.module.descriptor.Configuration in project ant-ivy by apache.

the class BundleInfoAdapter method requirementAsDependency.

private static void requirementAsDependency(DefaultModuleDescriptor md, BundleInfo bundleInfo, Set<String> exportedPkgNames) {
    for (BundleRequirement requirement : bundleInfo.getRequirements()) {
        String type = requirement.getType();
        String name = requirement.getName();
        if (BundleInfo.PACKAGE_TYPE.equals(type) && exportedPkgNames.contains(name)) {
            // don't declare package exported by the current bundle
            continue;
        }
        if (BundleInfo.EXECUTION_ENVIRONMENT_TYPE.equals(type)) {
            // execution environment are handled elsewhere
            continue;
        }
        ModuleRevisionId ddmrid = asMrid(type, name, requirement.getVersion());
        DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ddmrid, false);
        String conf = CONF_NAME_DEFAULT;
        if (BundleInfo.PACKAGE_TYPE.equals(type)) {
            // declare the configuration for the package
            conf = CONF_USE_PREFIX + name;
            md.addConfiguration(new Configuration(CONF_USE_PREFIX + name, PUBLIC, "Exported package " + name, new String[] { CONF_NAME_DEFAULT }, true, null));
            dd.addDependencyConfiguration(conf, conf);
        }
        if ("optional".equals(requirement.getResolution())) {
            dd.addDependencyConfiguration(CONF_NAME_OPTIONAL, conf);
            dd.addDependencyConfiguration(CONF_NAME_TRANSITIVE_OPTIONAL, CONF_NAME_TRANSITIVE_OPTIONAL);
        } else {
            dd.addDependencyConfiguration(CONF_NAME_DEFAULT, conf);
        }
        md.addDependency(dd);
    }
}
Also used : Configuration(org.apache.ivy.core.module.descriptor.Configuration) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)

Example 30 with Configuration

use of org.apache.ivy.core.module.descriptor.Configuration in project ant-ivy by apache.

the class XmlModuleDescriptorParserTest method testImportConfigurations3.

@Test
public void testImportConfigurations3() throws Exception {
    // import configurations and default mapping
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-configurations-import3.xml"), true);
    assertNotNull(md);
    // should have imported configurations
    assertNotNull(md.getConfigurations());
    assertEquals(Arrays.asList(new Configuration("conf1", PUBLIC, "", new String[0], true, null), new Configuration("conf2", PRIVATE, "", new String[0], true, null)), Arrays.asList(md.getConfigurations()));
    DependencyDescriptor[] dependencies = md.getDependencies();
    assertNotNull(dependencies);
    assertEquals(2, dependencies.length);
    // no conf def => defaults to defaultConf defined in imported file: *->@
    DependencyDescriptor dd = getDependency(dependencies, "mymodule1");
    assertEquals(Collections.singletonList("*"), Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Collections.singletonList("conf1"), Arrays.asList(dd.getDependencyConfigurations("conf1")));
    assertEquals(Collections.singletonList("conf2"), Arrays.asList(dd.getDependencyConfigurations("conf2")));
    // confs def: conf1->*
    dd = getDependency(dependencies, "mymodule2");
    assertEquals(Collections.singletonList("conf1"), Arrays.asList(dd.getModuleConfigurations()));
    assertEquals(Collections.singletonList("*"), Arrays.asList(dd.getDependencyConfigurations("conf1")));
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) Configuration(org.apache.ivy.core.module.descriptor.Configuration) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Test(org.junit.Test)

Aggregations

Configuration (org.apache.ivy.core.module.descriptor.Configuration)45 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)30 Test (org.junit.Test)29 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)17 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)16 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)15 Artifact (org.apache.ivy.core.module.descriptor.Artifact)10 Date (java.util.Date)9 URL (java.net.URL)7 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IvySettings (org.apache.ivy.core.settings.IvySettings)6 BasicResource (org.apache.ivy.plugins.repository.BasicResource)6 File (java.io.File)5 Map (java.util.Map)4 ModuleId (org.apache.ivy.core.module.id.ModuleId)4 GregorianCalendar (java.util.GregorianCalendar)3 License (org.apache.ivy.core.module.descriptor.License)3 IOException (java.io.IOException)2