Java Code Examples for org.apache.maven.project.MavenProject#getLicenses()

The following examples show how to use org.apache.maven.project.MavenProject#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: TemplateAttrProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static String findLicenseByMavenProjectContent(MavenProject mp) {
    // try to match the project's license URL and the mavenLicenseURL attribute of license template
    FileObject licensesFO = FileUtil.getConfigFile("Templates/Licenses"); //NOI18N
    if (licensesFO == null) {
        return null;
    }
    FileObject[] licenseFiles = licensesFO.getChildren();
    for (License license : mp.getLicenses()) {
        String url = license.getUrl();
        if (url != null) {
            for (FileObject fo : licenseFiles) {
                String str = (String)fo.getAttribute("mavenLicenseURL"); //NOI18N
                if (str != null && Arrays.asList(str.split(" ")).contains(url)) {
                    if (fo.getName().startsWith("license-")) { // NOI18N
                        return fo.getName().substring("license-".length()); //NOI18N
                    } else {
                        Logger.getLogger(TemplateAttrProvider.class.getName()).log(Level.WARNING, "Bad license file name {0} (expected to start with ''license-'' prefix)", fo.getName());
                    }
                    break;
                }
            }
        }
    }
    return null;
}
 
Example 2
Source File: MavenHelper.java    From cyclonedx-gradle-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * Extracts data from a project and adds the data to the component.
 * @param project the project to extract data from
 * @param component the component to add data to
 */
private void extractMetadata(MavenProject project, Component component) {
    if (component.getPublisher() == null) {
        // If we don't already have publisher information, retrieve it.
        if (project.getOrganization() != null) {
            component.setPublisher(project.getOrganization().getName());
        }
    }
    if (component.getDescription() == null) {
        // If we don't already have description information, retrieve it.
        component.setDescription(project.getDescription());
    }
    if (component.getLicenseChoice() == null || component.getLicenseChoice().getLicenses() == null || component.getLicenseChoice().getLicenses().isEmpty()) {
        // If we don't already have license information, retrieve it.
        if (project.getLicenses() != null) {
            component.setLicenseChoice(resolveMavenLicenses(project.getLicenses()));
        }
    }
    if (CycloneDxSchema.Version.VERSION_10 != schemaVersion) {
        if (project.getOrganization() != null && project.getOrganization().getUrl() != null) {
            if (!doesComponentHaveExternalReference(component, ExternalReference.Type.WEBSITE)) {
                addExternalReference(ExternalReference.Type.WEBSITE, project.getOrganization().getUrl(), component);
            }
        }
        if (project.getCiManagement() != null && project.getCiManagement().getUrl() != null) {
            if (!doesComponentHaveExternalReference(component, ExternalReference.Type.BUILD_SYSTEM)) {
                addExternalReference(ExternalReference.Type.BUILD_SYSTEM, project.getCiManagement().getUrl(), component);
            }
        }
        if (project.getDistributionManagement() != null && project.getDistributionManagement().getDownloadUrl() != null) {
            if (!doesComponentHaveExternalReference(component, ExternalReference.Type.DISTRIBUTION)) {
                addExternalReference(ExternalReference.Type.DISTRIBUTION, project.getDistributionManagement().getDownloadUrl(), component);
            }
        }
        if (project.getDistributionManagement() != null && project.getDistributionManagement().getRepository() != null) {
            if (!doesComponentHaveExternalReference(component, ExternalReference.Type.DISTRIBUTION)) {
                addExternalReference(ExternalReference.Type.DISTRIBUTION, project.getDistributionManagement().getRepository().getUrl(), component);
            }
        }
        if (project.getIssueManagement() != null && project.getIssueManagement().getUrl() != null) {
            if (!doesComponentHaveExternalReference(component, ExternalReference.Type.ISSUE_TRACKER)) {
                addExternalReference(ExternalReference.Type.ISSUE_TRACKER, project.getIssueManagement().getUrl(), component);
            }
        }
        if (project.getMailingLists() != null && project.getMailingLists().size() > 0) {
            for (MailingList list : project.getMailingLists()) {
                if (list.getArchive() != null) {
                    if (!doesComponentHaveExternalReference(component, ExternalReference.Type.MAILING_LIST)) {
                        addExternalReference(ExternalReference.Type.MAILING_LIST, list.getArchive(), component);
                    }
                } else if (list.getSubscribe() != null) {
                    if (!doesComponentHaveExternalReference(component, ExternalReference.Type.MAILING_LIST)) {
                        addExternalReference(ExternalReference.Type.MAILING_LIST, list.getSubscribe(), component);
                    }
                }
            }
        }
        if (project.getScm() != null && project.getScm().getUrl() != null) {
            if (!doesComponentHaveExternalReference(component, ExternalReference.Type.VCS)) {
                addExternalReference(ExternalReference.Type.VCS, project.getScm().getUrl(), component);
            }
        }
    }
}
 
Example 3
Source File: BaseCycloneDxMojo.java    From cyclonedx-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * Extracts data from a project and adds the data to the component.
 * @param project the project to extract data from
 * @param component the component to add data to
 */
private void extractMetadata(MavenProject project, Component component) {
    if (component.getPublisher() == null) {
        // If we don't already have publisher information, retrieve it.
        if (project.getOrganization() != null) {
            component.setPublisher(project.getOrganization().getName());
        }
    }
    if (component.getDescription() == null) {
        // If we don't already have description information, retrieve it.
        component.setDescription(project.getDescription());
    }
    if (component.getLicenseChoice() == null || component.getLicenseChoice().getLicenses() == null || component.getLicenseChoice().getLicenses().isEmpty()) {
        // If we don't already have license information, retrieve it.
        if (project.getLicenses() != null) {
            component.setLicenseChoice(resolveMavenLicenses(project.getLicenses()));
        }
    }
    if (CycloneDxSchema.Version.VERSION_10 != schemaVersion()) {
        if (project.getOrganization() != null && project.getOrganization().getUrl() != null) {
            if (!doesComponentHaveExternalReference(component, ExternalReference.Type.WEBSITE)) {
                addExternalReference(ExternalReference.Type.WEBSITE, project.getOrganization().getUrl(), component);
            }
        }
        if (project.getCiManagement() != null && project.getCiManagement().getUrl() != null) {
            if (!doesComponentHaveExternalReference(component, ExternalReference.Type.BUILD_SYSTEM)) {
                addExternalReference(ExternalReference.Type.BUILD_SYSTEM, project.getCiManagement().getUrl(), component);
            }
        }
        if (project.getDistributionManagement() != null && project.getDistributionManagement().getDownloadUrl() != null) {
            if (!doesComponentHaveExternalReference(component, ExternalReference.Type.DISTRIBUTION)) {
                addExternalReference(ExternalReference.Type.DISTRIBUTION, project.getDistributionManagement().getDownloadUrl(), component);
            }
        }
        if (project.getDistributionManagement() != null && project.getDistributionManagement().getRepository() != null) {
            if (!doesComponentHaveExternalReference(component, ExternalReference.Type.DISTRIBUTION)) {
                addExternalReference(ExternalReference.Type.DISTRIBUTION, project.getDistributionManagement().getRepository().getUrl(), component);
            }
        }
        if (project.getIssueManagement() != null && project.getIssueManagement().getUrl() != null) {
            if (!doesComponentHaveExternalReference(component, ExternalReference.Type.ISSUE_TRACKER)) {
                addExternalReference(ExternalReference.Type.ISSUE_TRACKER, project.getIssueManagement().getUrl(), component);
            }
        }
        if (project.getMailingLists() != null && project.getMailingLists().size() > 0) {
            for (MailingList list : project.getMailingLists()) {
                if (list.getArchive() != null) {
                    if (!doesComponentHaveExternalReference(component, ExternalReference.Type.MAILING_LIST)) {
                        addExternalReference(ExternalReference.Type.MAILING_LIST, list.getArchive(), component);
                    }
                } else if (list.getSubscribe() != null) {
                    if (!doesComponentHaveExternalReference(component, ExternalReference.Type.MAILING_LIST)) {
                        addExternalReference(ExternalReference.Type.MAILING_LIST, list.getSubscribe(), component);
                    }
                }
            }
        }
        if (project.getScm() != null && project.getScm().getUrl() != null) {
            if (!doesComponentHaveExternalReference(component, ExternalReference.Type.VCS)) {
                addExternalReference(ExternalReference.Type.VCS, project.getScm().getUrl(), component);
            }
        }
    }
}