在license-maven-plugin第三方许可证FreeMarker模板中可以获得哪些数据?

时间:2015-07-08 10:09:46

标签: maven licensing license-maven-plugin

我使用Mojo License Maven plugin生成third party licenses列表。根据文档,我可以使用自定义FreeMarker模板使用fileTemplate parameter格式化文件,但是没有关于将传递给FreeMarker模板的数据的文档。 <{3}}到存在的模板上有一个链接,但该链接已损坏。

1 个答案:

答案 0 :(得分:1)

经过一番搜索,我找到了template on GitHub

...

<#-- To render the third-party file.
 Available context :
 - dependencyMap a collection of Map.Entry with
   key are dependencies (as a MavenProject) (from the maven project)
   values are licenses of each dependency (array of string)
 - licenseMap a collection of Map.Entry with
   key are licenses of each dependency (array of string)
   values are all dependencies using this license
-->
<#function licenseFormat licenses>
    <#assign result = ""/>
    <#list licenses as license>
        <#assign result = result + " (" +license + ")"/>
    </#list>
    <#return result>
</#function>
<#function artifactFormat p>
    <#if p.name?index_of('Unnamed') &gt; -1>
        <#return p.artifactId + " (" + p.groupId + ":" + p.artifactId + ":" + p.version + " - " + (p.url!"no url defined") + ")">
    <#else>
        <#return p.name + " (" + p.groupId + ":" + p.artifactId + ":" + p.version + " - " + (p.url!"no url defined") + ")">
    </#if>
</#function>

<#if dependencyMap?size == 0>
The project has no dependencies.
<#else>
Lists of ${dependencyMap?size} third-party dependencies.
    <#list dependencyMap as e>
        <#assign project = e.getKey()/>
        <#assign licenses = e.getValue()/>
    ${licenseFormat(licenses)} ${artifactFormat(project)}
    </#list>
</#if>

它使用此LicenseMap