Java Code Examples for org.apache.ivy.core.module.descriptor.ModuleDescriptor#getLicenses()

The following examples show how to use org.apache.ivy.core.module.descriptor.ModuleDescriptor#getLicenses() . 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: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@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 2
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * 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 3
Source File: PomModuleDescriptorParserTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * 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 4
Source File: XmlModuleDescriptorWriter.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
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 5
Source File: XmlModuleDescriptorWriter.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private static boolean requireInnerInfoElement(ModuleDescriptor md) {
    return md.getExtraInfos().size() > 0 || md.getHomePage() != null
            || !isNullOrEmpty(md.getDescription())
            || md.getLicenses().length > 0 || md.getInheritedDescriptors().length > 0;
}
 
Example 6
Source File: XmlReportWriter.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
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 7
Source File: AbstractWorkspaceResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
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;
}