org.apache.ivy.core.module.descriptor.License Java Examples
The following examples show how to use
org.apache.ivy.core.module.descriptor.License.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PomReader.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public List<License> getLicenses() { Element licenses = getFirstChildElement(projectElement, LICENSES); if (licenses == null) { return Collections.emptyList(); } licenses.normalize(); List<License> lics = new ArrayList<License>(); 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; }
Example #2
Source File: PomReader.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public List<License> getLicenses() { Element licenses = getFirstChildElement(projectElement, LICENSES); if (licenses == null) { return Collections.emptyList(); } licenses.normalize(); List<License> lics = new ArrayList<License>(); 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; }
Example #3
Source File: PomReader.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public List<License> getLicenses() { Element licenses = getFirstChildElement(projectElement, LICENSES); if (licenses == null) { return Collections.emptyList(); } licenses.normalize(); List<License> lics = new ArrayList<License>(); 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; }
Example #4
Source File: PomReader.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public List<License> getLicenses() { Element licenses = getFirstChildElement(projectElement, LICENSES); if (licenses == null) { return Collections.emptyList(); } licenses.normalize(); List<License> lics = new ArrayList<License>(); 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; }
Example #5
Source File: PomReader.java From ant-ivy with Apache License 2.0 | 5 votes |
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()]); }
Example #6
Source File: PomModuleDescriptorParserTest.java From ant-ivy with Apache License 2.0 | 5 votes |
@Test public void testLicense() throws Exception { ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("spring-hibernate3-2.0.2.pom"), false); License[] licenses = md.getLicenses(); assertNotNull(licenses); assertEquals(1, licenses.length); assertEquals("The Apache Software License, Version 2.0", licenses[0].getName()); assertEquals("https://www.apache.org/licenses/LICENSE-2.0.txt", licenses[0].getUrl()); }
Example #7
Source File: PomModuleDescriptorParserTest.java From ant-ivy with Apache License 2.0 | 5 votes |
/** * 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()); }
Example #8
Source File: PomModuleDescriptorParserTest.java From ant-ivy with Apache License 2.0 | 5 votes |
/** * Tests that if a project explicitly specifies the licenses, then the licenses (if any) from * its parent pom aren't applied to the child project * * @throws Exception if something goes wrong */ @Test public void testOverriddenLicense() throws Exception { final IvySettings customIvySettings = createIvySettingsForParentLicenseTesting("test-parent-with-licenses.pom", "org.apache", "test-ivy-license-parent"); final String pomFile = "test-project-with-overridden-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", "The Apache Software License, Version 2.0", licenses[0].getName()); assertEquals("Unexpected license URL", "https://www.apache.org/licenses/LICENSE-2.0.txt", licenses[0].getUrl()); }
Example #9
Source File: PomModuleDescriptorParserTest.java From ant-ivy with Apache License 2.0 | 5 votes |
private IvySettings createIvySettingsForParentLicenseTesting(final String parentPomFileName, final String parentOrgName, final String parentModuleName) throws Exception { final URL parentPomURL = this.getClass().getResource(parentPomFileName); assertNotNull("Could not find " + parentPomFileName, parentPomURL); final PomReader parentPomReader = new PomReader(parentPomURL, new URLResource(parentPomURL)); final License[] parentLicenses = parentPomReader.getLicenses(); assertNotNull("Missing licenses in parent pom " + parentPomFileName, parentLicenses); assertEquals("Unexpected number of licenses in parent pom " + parentPomFileName, 1, parentLicenses.length); final DependencyResolver dependencyResolver = new MockedDependencyResolver() { @Override protected ModuleDescriptor getModuleDescriptor(DependencyDescriptor dependencyDescriptor) { final String depOrg = dependencyDescriptor.getDependencyId().getOrganisation(); final String depModuleName = dependencyDescriptor.getDependencyId().getName(); if (depOrg.equals(parentOrgName) && depModuleName.equals(parentModuleName)) { final DefaultModuleDescriptor moduleDescriptor = DefaultModuleDescriptor.newDefaultInstance(dependencyDescriptor.getDependencyRevisionId()); for (final License license : parentLicenses) { moduleDescriptor.addLicense(license); } return moduleDescriptor; } else { return super.getModuleDescriptor(dependencyDescriptor); } } }; final IvySettings ivySettings = new IvySettings(); ivySettings.setDictatorResolver(dependencyResolver); return ivySettings; }
Example #10
Source File: PomModuleDescriptorBuilder.java From ant-ivy with Apache License 2.0 | 4 votes |
public void setLicenses(License[] licenses) { for (License license : licenses) { ivyModuleDescriptor.addLicense(license); } }
Example #11
Source File: XmlModuleDescriptorWriter.java From ant-ivy with Apache License 2.0 | 4 votes |
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/>"); } }
Example #12
Source File: XmlModuleDescriptorParser.java From ant-ivy with Apache License 2.0 | 4 votes |
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { try { if (state == State.DESCRIPTION) { // make sure we don't interpret any tag while in description tag getBuffer().append("<").append(qName); for (int i = 0; i < attributes.getLength(); i++) { getBuffer().append(" "); getBuffer().append(attributes.getQName(i)); getBuffer().append("=\""); getBuffer().append(attributes.getValue(i)); getBuffer().append("\""); } getBuffer().append(">"); } else if ("ivy-module".equals(qName)) { ivyModuleStarted(attributes); } else if ("info".equals(qName)) { infoStarted(attributes); } else if (state == State.INFO && "extends".equals(qName)) { extendsStarted(attributes); } else if (state == State.INFO && "license".equals(qName)) { getMd().addLicense( new License(settings.substitute(attributes.getValue("name")), settings .substitute(attributes.getValue("url")))); } else if (state == State.INFO && "description".equals(qName)) { getMd().setHomePage(settings.substitute(attributes.getValue("homepage"))); state = State.DESCRIPTION; buffer = new StringBuilder(); } else if (state == State.INFO && "ivyauthor".equals(qName)) { // nothing to do, we don't store this } else if (state == State.INFO && "repository".equals(qName)) { // nothing to do, we don't store this } else if (state == State.EXTRA_INFO || state == State.INFO && isOtherNamespace(qName)) { buffer = new StringBuilder(); state = State.EXTRA_INFO; ExtraInfoHolder extraInfo = new ExtraInfoHolder(); extraInfo.setName(qName); for (int i = 0; i < attributes.getLength(); i++) { extraInfo.getAttributes().put(attributes.getQName(i), attributes.getValue(i)); } extraInfoStack.push(extraInfo); } else if ("configurations".equals(qName)) { configurationStarted(attributes); } else if ("publications".equals(qName)) { publicationsStarted(attributes); } else if ("dependencies".equals(qName)) { dependenciesStarted(attributes); } else if ("conflicts".equals(qName)) { if (!descriptorVersion.startsWith("1.")) { Message.deprecated("using conflicts section is deprecated: " + "please use hints section instead. Ivy file URL: " + descriptorURL); } state = State.CONFLICT; checkConfigurations(); } else if ("artifact".equals(qName)) { artifactStarted(qName, attributes); } else if ("include".equals(qName) && state == State.DEP) { addIncludeRule(qName, attributes); } else if ("exclude".equals(qName) && state == State.DEP) { addExcludeRule(qName, attributes); } else if ("exclude".equals(qName) && state == State.DEPS) { state = State.EXCLUDE; parseRule(qName, attributes); getMd().addExcludeRule((ExcludeRule) confAware); } else if ("dependency".equals(qName)) { dependencyStarted(attributes); } else if ("conf".equals(qName)) { confStarted(attributes); } else if ("mapped".equals(qName)) { dd.addDependencyConfiguration(conf, settings.substitute(attributes.getValue("name"))); } else if ("conflict".equals(qName) && state == State.DEPS || "manager".equals(qName) && state == State.CONFLICT) { managerStarted(attributes, state == State.CONFLICT ? "name" : "manager"); } else if ("override".equals(qName) && state == State.DEPS) { mediationOverrideStarted(attributes); } else if ("include".equals(qName) && state == State.CONF) { includeConfStarted(attributes); } else if (validate && state != State.EXTRA_INFO && state != State.DESCRIPTION) { addError("unknown tag " + qName); } } catch (Exception ex) { if (ex instanceof SAXException) { throw (SAXException) ex; } throw new SAXException("Problem occurred while parsing ivy file: " + ex.getMessage(), ex); } }
Example #13
Source File: XmlReportWriter.java From ant-ivy with Apache License 2.0 | 4 votes |
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.getQualifiedExtraAttributes() : dep.getResolvedId().getQualifiedExtraAttributes(); 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>"); }
Example #14
Source File: AbstractWorkspaceResolver.java From ant-ivy with Apache License 2.0 | 4 votes |
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; }
Example #15
Source File: XmlModuleDescriptorParser.java From ant-ivy with Apache License 2.0 | 2 votes |
/** * Describes how to merge licenses * * @param licenses * licenses going to be inherited */ public void mergeLicenses(License[] licenses) { for (License license : licenses) { getMd().addLicense(license); } }