Skip to content

Commit

Permalink
[resolves #2503] Add license information to feature pack
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed Apr 25, 2018
1 parent 982f502 commit accf31c
Show file tree
Hide file tree
Showing 80 changed files with 37,379 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void before() throws Exception {
mapping.put("version.camel.hadoop2", "hadoop2-version");
mapping.put("version.camel.hadoop2.protobuf", "hadoop2-protobuf-version");
mapping.put("version.camel.hbase", "hbase-version");
mapping.put("version.camel.httpclient", "httpclient4-version");
mapping.put("version.camel.javacrumbs", "javacrumbs-version");
mapping.put("version.camel.lucene", "lucene-version");
mapping.put("version.camel.qpid.proton", "qpid-proton-j-version");
Expand Down
172 changes: 171 additions & 1 deletion feature/pack/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<packaging>pom</packaging>

<properties>
<license.dir>${project.basedir}/src/main/resources/license</license.dir>
<license.output.dir>${project.build.directory}/licenses</license.output.dir>
<wildfly.module.dir>${project.build.directory}/wildfly-${version.wildfly}/modules/system/layers/base</wildfly.module.dir>
<wildfly.camel.module.dir>${project.build.directory}/wildfly-camel-${project.version}/modules/system/layers/fuse</wildfly.camel.module.dir>
</properties>
Expand Down Expand Up @@ -160,7 +162,7 @@
<goals>
<goal>execute</goal>
</goals>
<phase>package</phase>
<phase>compile</phase>
<configuration>
<source>${project.basedir}/scripts/module-checker.groovy</source>
</configuration>
Expand All @@ -186,6 +188,174 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.ec4j.maven</groupId>
<artifactId>editorconfig-maven-plugin</artifactId>
<configuration>
<excludes combine.children="append">
<exclude>**/license/**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>update-licenses-xml</id>
<activation>
<property>
<name>!skip-update-licenses-xml</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<executions>
<execution>
<id>update-licenses-xml</id>
<goals>
<goal>execute</goal>
</goals>
<phase>compile</phase>
<configuration>
<source>${project.basedir}/scripts/update-licenses-xml.groovy</source>
</configuration>
</execution>
<execution>
<id>update-licenses-dependencies</id>
<goals>
<goal>execute</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<source>${project.basedir}/scripts/update-licenses-dependencies.groovy</source>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${version.camel.httpclient}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-license-assets</id>
<phase>compile</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${license.output.dir}</outputDirectory>
<resources>
<resource>
<directory>${license.dir}/licenses</directory>
<includes>
<include>*</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>${license.dir}/assets</directory>
<includes>
<include>*</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wildfly.maven.plugins</groupId>
<artifactId>licenses-plugin</artifactId>
<executions>
<execution>
<id>update-licenses-xml</id>
<goals>
<goal>insert-versions</goal>
</goals>
<phase>compile</phase>
<configuration>
<licensesConfigFile>${license.dir}/licenses.xml</licensesConfigFile>
<licensesOutputDirectory>${license.output.dir}</licensesOutputDirectory>
<licensesOutputFile>${license.output.dir}/licenses.xml</licensesOutputFile>
<sortByGroupIdAndArtifactId>true</sortByGroupIdAndArtifactId>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-licenses-html</id>
<goals>
<goal>transform</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<transformationSets>
<transformationSet>
<dir>${license.output.dir}</dir>
<includes>
<include>*licenses.xml</include>
</includes>
<stylesheet>${license.dir}/assets/licenses.xsl</stylesheet>
<outputDir>${license.output.dir}</outputDir>
<fileMappers>
<fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
<targetExtension>.html</targetExtension>
</fileMapper>
</fileMappers>
<parameters>
<parameter>
<name>version</name>
<value>${project.version}</value>
</parameter>
</parameters>
</transformationSet>
</transformationSets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<!-- Activate this profile to download license info -->
<profile>
<id>generate-licenses-xml</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>download-licenses</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<licensesOutputDirectory>${license.dir}/licenses</licensesOutputDirectory>
<licensesOutputFile>${license.dir}/licenses.xml</licensesOutputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
4 changes: 4 additions & 0 deletions feature/pack/scripts/assembly-feature-pack.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
<directory>target/wildfly-feature-pack</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<directory>target/licenses</directory>
<outputDirectory>content/docs/licenses-fuse</outputDirectory>
</fileSet>
</fileSets>

</assembly>
12 changes: 12 additions & 0 deletions feature/pack/scripts/module-checker.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* #L%
*/
import groovy.transform.EqualsAndHashCode
import groovy.text.SimpleTemplateEngine

/**
* Script to help ensure that there is minimum dependency duplication between the wildfly-camel 'fuse'
Expand Down Expand Up @@ -207,4 +208,15 @@ if (problems.size() > 0) {

println ""
fail("Module dependency conflicts were detected. Please fix your module dependencies.")
} else {
// Write a list of resources so that we can look them up for generating licenses.xml
def binding = ["modules" : modules]
def engine = new SimpleTemplateEngine()
def text = '''
<%
modules.findAll({module -> module.layer == "fuse"}).each {it.resources.each {resource -> println resource}}
%>
'''
def template = engine.createTemplate(text).make(binding)
new File("${project.build.directory}/fuse-resources.txt").setText(template.toString().trim())
}
87 changes: 87 additions & 0 deletions feature/pack/scripts/update-licenses-dependencies.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/groovy
/*
* #%L
* Wildfly Camel
* %%
* Copyright (C) 2013 - 2018 RedHat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

String[] fuseJars = new File("${project.build.directory}/fuse-resources.txt")
def skip = properties.get("skip-update-licenses-xml")
def licenseOutputDir = properties.get("license.output.dir")
def licenseSourceDir = properties.get("license.dir")
def licenseOutputXmlFile = new File("${licenseOutputDir}/licenses.xml")
def licenseSourceXmlFile = new File("${licenseSourceDir}/licenses.xml")

if (skip != null) {
return
}

if (licenseOutputXmlFile.exists()) {
licenseXml = new XmlParser().parse(licenseOutputXmlFile)
other = new XmlParser().parse(licenseSourceXmlFile)

licenseXml.dependencies.dependency.each { dependency ->
String jarName = "${dependency.artifactId.text()}-${dependency.version.text()}.jar"

// Remove all license entries for dependencies that are not in the fuse module layer
def matchedJars = fuseJars.find({ jar -> jar.matches(jarName) })
if (matchedJars == null) {
dependency.replaceNode {}
}
}

def urls = [:]
licenseXml.dependencies.dependency.licenses.license.each { license ->
String licenseName = license.name.text()
String licenseFileName = ""
String licenseUrlFileName = ""

String licenseUrl = license.url.text()
if (licenseUrl == null || licenseUrl.isEmpty()) {
return
}

try {
licenseUrlFileName = new File(new URL(licenseUrl).path).name
} catch (MalformedURLException e) {
return
}

if (urls[licenseUrl]) {
licenseFileName = urls[licenseUrl]
} else {
if (licenseName != null && !licenseName.isEmpty()) {
licenseFileName = licenseName.replaceAll( "/", "_" ) + " - " + licenseUrlFileName
}

int idx = licenseFileName.lastIndexOf(".")
if (idx == -1 || idx > (licenseFileName.length() - 3 )) {
licenseFileName += ".txt"
}

licenseFileName = licenseFileName.toLowerCase()
urls[licenseUrl] = licenseFileName
}

license.append(new Node(null, "file", licenseFileName))
}

// Output modified XML
def printer = new XmlNodePrinter(new PrintWriter(new FileWriter(licenseOutputXmlFile)))
printer.preserveWhitespace = true
printer.print(licenseXml)
}
Loading

0 comments on commit accf31c

Please sign in to comment.