use of org.apache.ivy.core.module.descriptor.License in project ant-ivy by apache.
the class PomModuleDescriptorParserTest method testLicenseFromParent.
/**
* Tests that if a module doesn't have a license specified, then parent pom's license (if any)
* is used for the child module
*
* @throws Exception if something goes wrong
*/
@Test
public void testLicenseFromParent() throws Exception {
final IvySettings customIvySettings = createIvySettingsForParentLicenseTesting("test-parent-with-licenses.pom", "org.apache", "test-ivy-license-parent");
final String pomFile = "test-project-with-parent-licenses.pom";
final ModuleDescriptor childModule = PomModuleDescriptorParser.getInstance().parseDescriptor(customIvySettings, this.getClass().getResource(pomFile), false);
assertNotNull("Could not find " + pomFile, pomFile);
final License[] licenses = childModule.getLicenses();
assertNotNull("No licenses found in the module " + childModule, licenses);
assertEquals("Unexpected number of licenses found in the module " + childModule, 1, licenses.length);
assertEquals("Unexpected license name", "MIT License", licenses[0].getName());
assertEquals("Unexpected license URL", "http://opensource.org/licenses/MIT", licenses[0].getUrl());
}
use of org.apache.ivy.core.module.descriptor.License in project ant-ivy by apache.
the class XmlModuleDescriptorParserTest method testFull.
@Test
public void testFull() throws Exception {
ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test.xml"), true);
assertNotNull(md);
assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
assertEquals("mymodule", md.getModuleRevisionId().getName());
assertEquals("myrev", md.getModuleRevisionId().getRevision());
assertEquals("integration", md.getStatus());
Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
assertEquals(pubdate, md.getPublicationDate());
License[] licenses = md.getLicenses();
assertEquals(1, licenses.length);
assertEquals("MyLicense", licenses[0].getName());
assertEquals("http://www.my.org/mymodule/mylicense.html", licenses[0].getUrl());
assertEquals("http://www.my.org/mymodule/", md.getHomePage());
assertEquals("This module is <b>great</b> !<br/>\n\t" + "You can use it especially with myconf1 and myconf2, " + "and myconf4 is not too bad too.", md.getDescription().replaceAll("\r\n", "\n").replace('\r', '\n'));
assertEquals(1, md.getExtraInfos().size());
ExtraInfoHolder someExtraElement = md.getExtraInfos().get(0);
assertEquals("e:someExtra", someExtraElement.getName());
assertEquals("56576", someExtraElement.getContent());
assertEquals(0, someExtraElement.getAttributes().size());
Configuration[] confs = md.getConfigurations();
assertNotNull(confs);
assertEquals(5, confs.length);
assertConf(md, "myconf1", "desc 1", PUBLIC, new String[0]);
assertConf(md, "myconf2", "desc 2", PUBLIC, new String[0]);
assertConf(md, "myconf3", "desc 3", PRIVATE, new String[0]);
assertConf(md, "myconf4", "desc 4", PUBLIC, new String[] { "myconf1", "myconf2" });
assertConf(md, "myoldconf", "my old desc", PUBLIC, new String[0]);
assertArtifacts(md.getArtifacts("myconf1"), new String[] { "myartifact1", "myartifact2", "myartifact3", "myartifact4" });
assertArtifacts(md.getArtifacts("myconf2"), new String[] { "myartifact1", "myartifact3" });
assertArtifacts(md.getArtifacts("myconf3"), new String[] { "myartifact1", "myartifact3", "myartifact4" });
assertArtifacts(md.getArtifacts("myconf4"), new String[] { "myartifact1" });
DependencyDescriptor[] dependencies = md.getDependencies();
assertNotNull(dependencies);
assertEquals(13, dependencies.length);
// no conf def => equivalent to *->*
DependencyDescriptor dd = getDependency(dependencies, "mymodule2");
assertNotNull(dd);
assertEquals("myorg", dd.getDependencyId().getOrganisation());
assertEquals("2.0", dd.getDependencyRevisionId().getRevision());
assertEquals(Collections.singletonList("*"), Arrays.asList(dd.getModuleConfigurations()));
assertEquals(Collections.singletonList("*"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
assertEquals(Collections.singletonList("*"), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf2", "myconf3", "myconf4" })));
assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
assertFalse(dd.isChanging());
assertTrue(dd.isTransitive());
// changing = true
dd = getDependency(dependencies, "mymodule3");
assertNotNull(dd);
assertTrue(dd.isChanging());
assertFalse(dd.isTransitive());
// conf="myconf1" => equivalent to myconf1->myconf1
dd = getDependency(dependencies, "yourmodule1");
assertNotNull(dd);
assertEquals("yourorg", dd.getDependencyId().getOrganisation());
assertEquals("trunk", dd.getDependencyRevisionId().getBranch());
assertEquals("1.1", dd.getDependencyRevisionId().getRevision());
assertEquals("branch1", dd.getDynamicConstraintDependencyRevisionId().getBranch());
assertEquals("1+", dd.getDynamicConstraintDependencyRevisionId().getRevision());
assertEquals("yourorg#yourmodule1#branch1;1+", dd.getDynamicConstraintDependencyRevisionId().toString());
assertEquals(Collections.singletonList("myconf1"), Arrays.asList(dd.getModuleConfigurations()));
assertEquals(Collections.singletonList("myconf1"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
assertEquals(Collections.emptyList(), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf2", "myconf3", "myconf4" })));
assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
// conf="myconf1->yourconf1"
dd = getDependency(dependencies, "yourmodule2");
assertNotNull(dd);
assertEquals("yourorg", dd.getDependencyId().getOrganisation());
assertEquals("2+", dd.getDependencyRevisionId().getRevision());
assertEquals(Collections.singletonList("myconf1"), Arrays.asList(dd.getModuleConfigurations()));
assertEquals(Collections.singletonList("yourconf1"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
assertEquals(Collections.emptyList(), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf2", "myconf3", "myconf4" })));
assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
// conf="myconf1->yourconf1, yourconf2"
dd = getDependency(dependencies, "yourmodule3");
assertNotNull(dd);
assertEquals("yourorg", dd.getDependencyId().getOrganisation());
assertEquals("3.1", dd.getDependencyRevisionId().getRevision());
assertEquals(Collections.singletonList("myconf1"), Arrays.asList(dd.getModuleConfigurations()));
assertEquals(Arrays.asList("yourconf1", "yourconf2"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
assertEquals(Collections.emptyList(), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf2", "myconf3", "myconf4" })));
assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
// conf="myconf1, myconf2->yourconf1, yourconf2"
dd = getDependency(dependencies, "yourmodule4");
assertNotNull(dd);
assertEquals("yourorg", dd.getDependencyId().getOrganisation());
assertEquals("4.1", dd.getDependencyRevisionId().getRevision());
assertEquals(new HashSet<>(Arrays.asList("myconf1", "myconf2")), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
assertEquals(Arrays.asList("yourconf1", "yourconf2"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
assertEquals(Arrays.asList("yourconf1", "yourconf2"), Arrays.asList(dd.getDependencyConfigurations("myconf2")));
assertEquals(Collections.emptyList(), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf3", "myconf4" })));
assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
// conf="myconf1->yourconf1;myconf2->yourconf1, yourconf2"
dd = getDependency(dependencies, "yourmodule5");
assertNotNull(dd);
assertEquals("yourorg", dd.getDependencyId().getOrganisation());
assertEquals("5.1", dd.getDependencyRevisionId().getRevision());
assertEquals(new HashSet<>(Arrays.asList("myconf1", "myconf2")), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
assertEquals(Collections.singletonList("yourconf1"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
assertEquals(Arrays.asList("yourconf1", "yourconf2"), Arrays.asList(dd.getDependencyConfigurations("myconf2")));
assertEquals(Collections.emptyList(), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf3", "myconf4" })));
assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
// conf="*->@"
dd = getDependency(dependencies, "yourmodule11");
assertNotNull(dd);
assertEquals("yourorg", dd.getDependencyId().getOrganisation());
assertEquals("11.1", dd.getDependencyRevisionId().getRevision());
assertEquals(Collections.singleton("*"), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
assertEquals(Collections.singletonList("myconf1"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
assertEquals(Collections.singletonList("myconf2"), Arrays.asList(dd.getDependencyConfigurations("myconf2")));
assertEquals(Collections.singletonList("myconf3"), Arrays.asList(dd.getDependencyConfigurations("myconf3")));
assertEquals(Collections.singletonList("myconf4"), Arrays.asList(dd.getDependencyConfigurations("myconf4")));
dd = getDependency(dependencies, "yourmodule6");
assertNotNull(dd);
assertEquals("yourorg", dd.getDependencyId().getOrganisation());
assertEquals("latest.integration", dd.getDependencyRevisionId().getRevision());
assertEquals(new HashSet<>(Arrays.asList("myconf1", "myconf2")), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
assertEquals(Collections.singletonList("yourconf1"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
assertEquals(Arrays.asList("yourconf1", "yourconf2"), Arrays.asList(dd.getDependencyConfigurations("myconf2")));
assertEquals(Collections.emptyList(), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf3", "myconf4" })));
assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
dd = getDependency(dependencies, "yourmodule7");
assertNotNull(dd);
assertEquals("yourorg", dd.getDependencyId().getOrganisation());
assertEquals("7.1", dd.getDependencyRevisionId().getRevision());
assertEquals(new HashSet<>(Arrays.asList("myconf1", "myconf2")), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
assertEquals(Collections.singletonList("yourconf1"), Arrays.asList(dd.getDependencyConfigurations("myconf1")));
assertEquals(Arrays.asList("yourconf1", "yourconf2"), Arrays.asList(dd.getDependencyConfigurations("myconf2")));
assertEquals(Collections.emptyList(), Arrays.asList(dd.getDependencyConfigurations(new String[] { "myconf3", "myconf4" })));
assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1", "myconf2", "myconf3", "myconf4" }, new String[0]);
dd = getDependency(dependencies, "yourmodule8");
assertNotNull(dd);
assertEquals("yourorg", dd.getDependencyId().getOrganisation());
assertEquals("8.1", dd.getDependencyRevisionId().getRevision());
assertEquals(new HashSet<>(Collections.singletonList("*")), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
assertDependencyArtifacts(dd, new String[] { "myconf1" }, new String[] { "yourartifact8-1", "yourartifact8-2" });
assertDependencyArtifacts(dd, new String[] { "myconf2" }, new String[] { "yourartifact8-1", "yourartifact8-2" });
assertDependencyArtifacts(dd, new String[] { "myconf3" }, new String[] { "yourartifact8-1", "yourartifact8-2" });
assertDependencyArtifacts(dd, new String[] { "myconf4" }, new String[] { "yourartifact8-1", "yourartifact8-2" });
dd = getDependency(dependencies, "yourmodule9");
assertNotNull(dd);
assertEquals("yourorg", dd.getDependencyId().getOrganisation());
assertEquals("9.1", dd.getDependencyRevisionId().getRevision());
assertEquals(new HashSet<>(Arrays.asList("myconf1", "myconf2", "myconf3")), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
assertDependencyArtifacts(dd, new String[] { "myconf1" }, new String[] { "yourartifact9-1" });
assertDependencyArtifacts(dd, new String[] { "myconf2" }, new String[] { "yourartifact9-1", "yourartifact9-2" });
assertDependencyArtifacts(dd, new String[] { "myconf3" }, new String[] { "yourartifact9-2" });
assertDependencyArtifacts(dd, new String[] { "myconf4" }, new String[] {});
assertDependencyArtifactExcludeRules(dd, new String[] { "myconf1" }, new String[] {});
assertDependencyArtifactExcludeRules(dd, new String[] { "myconf2" }, new String[] {});
assertDependencyArtifactExcludeRules(dd, new String[] { "myconf3" }, new String[] {});
assertDependencyArtifactExcludeRules(dd, new String[] { "myconf4" }, new String[] {});
dd = getDependency(dependencies, "yourmodule10");
assertNotNull(dd);
assertEquals("yourorg", dd.getDependencyId().getOrganisation());
assertEquals("10.1", dd.getDependencyRevisionId().getRevision());
assertEquals(Collections.singleton("*"), new HashSet<>(Arrays.asList(dd.getModuleConfigurations())));
assertDependencyArtifactIncludeRules(dd, new String[] { "myconf1" }, new String[] { "your.*", PatternMatcher.ANY_EXPRESSION });
assertDependencyArtifactIncludeRules(dd, new String[] { "myconf2" }, new String[] { "your.*", PatternMatcher.ANY_EXPRESSION });
assertDependencyArtifactIncludeRules(dd, new String[] { "myconf3" }, new String[] { "your.*", PatternMatcher.ANY_EXPRESSION });
assertDependencyArtifactIncludeRules(dd, new String[] { "myconf4" }, new String[] { "your.*", PatternMatcher.ANY_EXPRESSION });
assertDependencyArtifactExcludeRules(dd, new String[] { "myconf1" }, new String[] { "toexclude" });
assertDependencyArtifactExcludeRules(dd, new String[] { "myconf2" }, new String[] { "toexclude" });
assertDependencyArtifactExcludeRules(dd, new String[] { "myconf3" }, new String[] { "toexclude" });
assertDependencyArtifactExcludeRules(dd, new String[] { "myconf4" }, new String[] { "toexclude" });
ConflictManager cm = md.getConflictManager(new ModuleId("yourorg", "yourmodule1"));
assertNotNull(cm);
assertTrue(cm instanceof NoConflictManager);
cm = md.getConflictManager(new ModuleId("yourorg", "yourmodule2"));
assertNotNull(cm);
assertTrue(cm instanceof NoConflictManager);
cm = md.getConflictManager(new ModuleId("theirorg", "theirmodule1"));
assertNotNull(cm);
assertTrue(cm instanceof FixedConflictManager);
FixedConflictManager fcm = (FixedConflictManager) cm;
assertEquals(2, fcm.getRevs().size());
assertTrue(fcm.getRevs().contains("1.0"));
assertTrue(fcm.getRevs().contains("1.1"));
cm = md.getConflictManager(new ModuleId("theirorg", "theirmodule2"));
assertNull(cm);
assertEquals(ModuleRevisionId.parse("yourorg#yourmodule1#BRANCH;1.0"), md.mediate(new DefaultDependencyDescriptor(ModuleRevisionId.parse("yourorg#yourmodule1;2.0"), false)).getDependencyRevisionId());
ExcludeRule[] rules = md.getAllExcludeRules();
assertNotNull(rules);
assertEquals(2, rules.length);
assertEquals(GlobPatternMatcher.INSTANCE, rules[0].getMatcher());
assertEquals(ExactPatternMatcher.INSTANCE, rules[1].getMatcher());
assertEquals(Collections.singletonList("myconf1"), Arrays.asList(rules[0].getConfigurations()));
assertEquals(Arrays.asList("myconf1", "myconf2", "myconf3", "myconf4", "myoldconf"), Arrays.asList(rules[1].getConfigurations()));
}
use of org.apache.ivy.core.module.descriptor.License in project ant-ivy by apache.
the class PomReader method getLicenses.
public License[] getLicenses() {
Element licenses = getFirstChildElement(projectElement, LICENSES);
if (licenses == null) {
return new License[0];
}
licenses.normalize();
List<License> lics = new ArrayList<>();
for (Element license : getAllChilds(licenses)) {
if (LICENSE.equals(license.getNodeName())) {
String name = getFirstChildText(license, LICENSE_NAME);
String url = getFirstChildText(license, LICENSE_URL);
if (name == null && url == null) {
// move to next license
continue;
}
if (name == null) {
// The license name is required in Ivy but not in a POM!
name = "Unknown License";
}
lics.add(new License(name, url));
}
}
return lics.toArray(new License[lics.size()]);
}
use of org.apache.ivy.core.module.descriptor.License in project ant-ivy by apache.
the class AbstractWorkspaceResolver method createWorkspaceMd.
protected WorkspaceModuleDescriptor createWorkspaceMd(ModuleDescriptor md) {
DefaultWorkspaceModuleDescriptor newMd = new DefaultWorkspaceModuleDescriptor(md.getModuleRevisionId(), "release", null, true);
newMd.addConfiguration(new Configuration(ModuleDescriptor.DEFAULT_CONFIGURATION));
newMd.setLastModified(System.currentTimeMillis());
newMd.setDescription(md.getDescription());
newMd.setHomePage(md.getHomePage());
newMd.setLastModified(md.getLastModified());
newMd.setPublicationDate(md.getPublicationDate());
newMd.setResolvedPublicationDate(md.getResolvedPublicationDate());
newMd.setStatus(md.getStatus());
Configuration[] allConfs = md.getConfigurations();
for (Artifact af : createWorkspaceArtifacts(md)) {
if (allConfs.length == 0) {
newMd.addArtifact(ModuleDescriptor.DEFAULT_CONFIGURATION, af);
} else {
for (Configuration conf : allConfs) {
newMd.addConfiguration(conf);
newMd.addArtifact(conf.getName(), af);
}
}
}
for (DependencyDescriptor dependency : md.getDependencies()) {
newMd.addDependency(dependency);
}
for (ExcludeRule excludeRule : md.getAllExcludeRules()) {
newMd.addExcludeRule(excludeRule);
}
newMd.getExtraInfos().addAll(md.getExtraInfos());
for (License license : md.getLicenses()) {
newMd.addLicense(license);
}
return newMd;
}
use of org.apache.ivy.core.module.descriptor.License in project ant-ivy by apache.
the class XmlReportWriter method outputRevision.
private void outputRevision(ConfigurationResolveReport report, PrintWriter out, List<ModuleRevisionId> dependencies, IvyNode dep) {
Map<String, String> extraAttributes;
ModuleDescriptor md = null;
if (dep.getModuleRevision() != null) {
md = dep.getModuleRevision().getDescriptor();
}
StringBuilder details = new StringBuilder();
if (dep.isLoaded()) {
details.append(" status=\"");
details.append(XMLHelper.escape(dep.getDescriptor().getStatus()));
details.append("\" pubdate=\"");
details.append(DateUtil.format(new Date(dep.getPublication())));
details.append("\" resolver=\"");
details.append(XMLHelper.escape(dep.getModuleRevision().getResolver().getName()));
details.append("\" artresolver=\"");
details.append(XMLHelper.escape(dep.getModuleRevision().getArtifactResolver().getName()));
details.append("\"");
}
if (dep.isEvicted(report.getConfiguration())) {
EvictionData ed = dep.getEvictedData(report.getConfiguration());
if (ed.getConflictManager() != null) {
details.append(" evicted=\"").append(XMLHelper.escape(ed.getConflictManager().toString())).append("\"");
} else {
details.append(" evicted=\"transitive\"");
}
details.append(" evicted-reason=\"").append(XMLHelper.escape(ed.getDetail() == null ? "" : ed.getDetail())).append("\"");
}
if (dep.hasProblem()) {
details.append(" error=\"").append(XMLHelper.escape(dep.getProblem().getMessage())).append("\"");
}
if (md != null && md.getHomePage() != null) {
details.append(" homepage=\"").append(XMLHelper.escape(md.getHomePage())).append("\"");
}
extraAttributes = (md != null) ? md.getExtraAttributes() : dep.getResolvedId().getExtraAttributes();
details.append(extraToString(extraAttributes, SEPARATOR));
out.println(String.format("\t\t\t<revision name=\"%s\"%s%s downloaded=\"%s\" searched=\"%s\"%s conf=\"%s\" position=\"%d\">", XMLHelper.escape(dep.getResolvedId().getRevision()), (dep.getResolvedId().getBranch() == null) ? "" : " branch=\"" + XMLHelper.escape(dep.getResolvedId().getBranch()) + "\"", details, dep.isDownloaded(), dep.isSearched(), (dep.getDescriptor() == null) ? "" : " default=\"" + dep.getDescriptor().isDefault() + "\"", XMLHelper.escape(joinArray(dep.getConfigurations(report.getConfiguration()), ", ")), dependencies.indexOf(dep.getResolvedId())));
if (md != null) {
License[] licenses = md.getLicenses();
for (License license : licenses) {
out.println(String.format("\t\t\t\t<license name=\"%s\"%s/>", XMLHelper.escape(license.getName()), license.getUrl() == null ? "" : " url=\"" + XMLHelper.escape(license.getUrl()) + "\""));
}
}
outputMetadataArtifact(out, dep);
outputEvictionInformation(report, out, dep);
outputCallers(report, out, dep);
outputArtifacts(report, out, dep);
out.println("\t\t\t</revision>");
}
Aggregations