use of org.apache.ivy.core.module.descriptor.ExtraInfoHolder in project ant-ivy by apache.
the class PomModuleDescriptorBuilder method addPlugin.
public void addPlugin(PomDependencyMgt plugin) {
String pluginValue = plugin.getGroupId() + EXTRA_INFO_DELIMITER + plugin.getArtifactId() + EXTRA_INFO_DELIMITER + plugin.getVersion();
ExtraInfoHolder extraInfoByTagName = ivyModuleDescriptor.getExtraInfoByTagName("m:maven.plugins");
if (extraInfoByTagName == null) {
extraInfoByTagName = new ExtraInfoHolder();
extraInfoByTagName.setName("m:maven.plugins");
ivyModuleDescriptor.addExtraInfo(extraInfoByTagName);
}
String pluginExtraInfo = extraInfoByTagName.getContent();
if (pluginExtraInfo == null) {
pluginExtraInfo = pluginValue;
} else {
pluginExtraInfo += "|" + pluginValue;
}
extraInfoByTagName.setContent(pluginExtraInfo);
}
use of org.apache.ivy.core.module.descriptor.ExtraInfoHolder in project ant-ivy by apache.
the class XmlModuleDescriptorWriter method printInfoTag.
private static void printInfoTag(ModuleDescriptor md, PrintWriter out) {
out.println("\t<info organisation=\"" + XMLHelper.escape(md.getModuleRevisionId().getOrganisation()) + "\"");
out.println("\t\tmodule=\"" + XMLHelper.escape(md.getModuleRevisionId().getName()) + "\"");
String branch = md.getResolvedModuleRevisionId().getBranch();
if (branch != null) {
out.println("\t\tbranch=\"" + XMLHelper.escape(branch) + "\"");
}
String revision = md.getResolvedModuleRevisionId().getRevision();
if (revision != null) {
out.println("\t\trevision=\"" + XMLHelper.escape(revision) + "\"");
}
out.println("\t\tstatus=\"" + XMLHelper.escape(md.getStatus()) + "\"");
out.println("\t\tpublication=\"" + DateUtil.format(md.getResolvedPublicationDate()) + "\"");
if (md.isDefault()) {
out.println("\t\tdefault=\"true\"");
}
if (md instanceof DefaultModuleDescriptor) {
DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md;
if (dmd.getNamespace() != null && !dmd.getNamespace().getName().equals("system")) {
out.println("\t\tnamespace=\"" + XMLHelper.escape(dmd.getNamespace().getName()) + "\"");
}
}
if (!md.getExtraAttributes().isEmpty()) {
printExtraAttributes(md, out, "\t\t");
out.println();
}
if (requireInnerInfoElement(md)) {
out.println("\t>");
for (ExtendsDescriptor parent : md.getInheritedDescriptors()) {
ModuleRevisionId mrid = parent.getParentRevisionId();
out.print(String.format("\t\t<extends organisation=\"%s\" module=\"%s\" revision=\"%s\"", XMLHelper.escape(mrid.getOrganisation()), XMLHelper.escape(mrid.getName()), XMLHelper.escape(mrid.getRevision())));
String location = parent.getLocation();
if (location != null) {
out.print(" location=\"" + XMLHelper.escape(location) + "\"");
}
out.print(" extendType=\"" + joinArray(parent.getExtendsTypes(), ",") + "\"");
out.println("/>");
}
License[] licenses = md.getLicenses();
for (License license : licenses) {
out.print("\t\t<license ");
if (license.getName() != null) {
out.print("name=\"" + XMLHelper.escape(license.getName()) + "\" ");
}
if (license.getUrl() != null) {
out.print("url=\"" + XMLHelper.escape(license.getUrl()) + "\" ");
}
out.println("/>");
}
if (md.getHomePage() != null || md.getDescription() != null) {
out.print("\t\t<description");
if (md.getHomePage() != null) {
out.print(" homepage=\"" + XMLHelper.escape(md.getHomePage()) + "\"");
}
if (isNullOrEmpty(md.getDescription())) {
out.println(" />");
} else {
out.println(">");
out.println("\t\t" + XMLHelper.escape(md.getDescription()));
out.println("\t\t</description>");
}
}
for (ExtraInfoHolder extraInfo : md.getExtraInfos()) {
printExtraInfoElement(out, extraInfo, 2);
}
out.println("\t</info>");
} else {
out.println("\t/>");
}
}
use of org.apache.ivy.core.module.descriptor.ExtraInfoHolder in project ant-ivy by apache.
the class XmlModuleDescriptorParserTest method testExtraInfos.
@Test
public void testExtraInfos() throws Exception {
ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-extrainfo.xml"), true);
assertNotNull(md);
assertEquals(2, md.getExtraInfos().size());
ExtraInfoHolder firstExtraInfoElement = md.getExtraInfos().get(0);
assertEquals("e:someExtra", firstExtraInfoElement.getName());
assertEquals("56576", firstExtraInfoElement.getContent());
assertEquals(0, firstExtraInfoElement.getAttributes().size());
assertEquals(0, firstExtraInfoElement.getNestedExtraInfoHolder().size());
ExtraInfoHolder secondExtraInfoElement = md.getExtraInfos().get(1);
assertEquals("e:someExtraWithAttributes", secondExtraInfoElement.getName());
assertEquals("", secondExtraInfoElement.getContent());
assertEquals(2, secondExtraInfoElement.getAttributes().size());
assertEquals("foo", secondExtraInfoElement.getAttributes().get("attr1"));
assertEquals("bar", secondExtraInfoElement.getAttributes().get("attr2"));
assertEquals(0, secondExtraInfoElement.getNestedExtraInfoHolder().size());
}
use of org.apache.ivy.core.module.descriptor.ExtraInfoHolder in project ant-ivy by apache.
the class XmlModuleDescriptorParserTest method testExtraInfosNested.
@Test
public void testExtraInfosNested() throws Exception {
ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-extrainfo-nested.xml"), true);
assertNotNull(md);
assertEquals(2, md.getExtraInfos().size());
ExtraInfoHolder someExtraElement = md.getExtraInfos().get(0);
assertEquals("e:someExtra", someExtraElement.getName());
assertEquals("56576", someExtraElement.getContent());
assertEquals(0, someExtraElement.getAttributes().size());
assertEquals(0, someExtraElement.getNestedExtraInfoHolder().size());
ExtraInfoHolder someExtraElementWithAttributes = md.getExtraInfos().get(1);
assertEquals("e:someExtraWithAttributes", someExtraElementWithAttributes.getName());
assertEquals("", someExtraElementWithAttributes.getContent());
assertEquals(2, someExtraElementWithAttributes.getAttributes().size());
assertEquals("foo", someExtraElementWithAttributes.getAttributes().get("attr1"));
assertEquals("bar", someExtraElementWithAttributes.getAttributes().get("attr2"));
assertEquals(1, someExtraElementWithAttributes.getNestedExtraInfoHolder().size());
ExtraInfoHolder anotherExtraInfoElement = someExtraElementWithAttributes.getNestedExtraInfoHolder().get(0);
assertEquals("e:anotherExtraInfo", anotherExtraInfoElement.getName());
assertEquals("", anotherExtraInfoElement.getContent());
assertEquals(1, anotherExtraInfoElement.getAttributes().size());
assertEquals("foobar", anotherExtraInfoElement.getAttributes().get("myattribute"));
assertEquals(1, anotherExtraInfoElement.getNestedExtraInfoHolder().size());
ExtraInfoHolder yetAnotherExtraInfoElement = anotherExtraInfoElement.getNestedExtraInfoHolder().get(0);
assertEquals("e:yetAnotherExtraInfo", yetAnotherExtraInfoElement.getName());
assertEquals("", yetAnotherExtraInfoElement.getContent());
assertEquals(1, yetAnotherExtraInfoElement.getAttributes().size());
assertEquals("value", yetAnotherExtraInfoElement.getAttributes().get("anAttribute"));
assertEquals(0, yetAnotherExtraInfoElement.getNestedExtraInfoHolder().size());
}
use of org.apache.ivy.core.module.descriptor.ExtraInfoHolder 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;
}
Aggregations