Skip to content

Commit

Permalink
Calculate CRC32 for license mapping at build time instead of hardcoding
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasblaesing authored and jlahoda committed May 11, 2018
1 parent 569f736 commit 9b819cf
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 14 deletions.
5 changes: 3 additions & 2 deletions c.jcraft.jsch/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
-->
<project name="c.jcraft.jsch" default="build" basedir=".">
<import file="../nbbuild/templates/projectized.xml"/>
<target name="jar">
<target name="jar" depends="-define-FileCRC32Calculator">
<FileCRC32Calculator file="external/jsch-0.1.54.jar" property="c.jcraft.jsch.crc32" />
<jar jarfile="${cluster}/${module.jar}">
<zipfileset src="external/jsch-0.1.54.jar"/>
<manifest>
Expand All @@ -30,7 +31,7 @@
<attribute name="Export-Package" value="com.jcraft.jsch"/>
<attribute name="Import-Package" value="javax.crypto,javax.crypto.spec,javax.crypto.interfaces,org.ietf.jgss"/>
<attribute name="Require-Bundle" value="com.jcraft.jzlib"/>
<attribute name="NB-Original-CRC" value="226563049"/>
<attribute name="NB-Original-CRC" value="${c.jcraft.jsch.crc32}"/>
</manifest>
</jar>
</target>
Expand Down
5 changes: 3 additions & 2 deletions c.jcraft.jzlib/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
-->
<project name="c.jcraft.jzlib" default="build" basedir=".">
<import file="../nbbuild/templates/projectized.xml"/>
<target name="jar">
<target name="jar" depends="-define-FileCRC32Calculator">
<FileCRC32Calculator file="external/jzlib-1.0.7.jar" property="c.jcraft.jzlib.crc32" />
<jar jarfile="${cluster}/${module.jar}">
<zipfileset src="external/jzlib-1.0.7.jar"/>
<manifest>
<attribute name="Bundle-SymbolicName" value="com.jcraft.jzlib"/>
<attribute name="Bundle-Version" value="1.0.7"/>
<attribute name="Export-Package" value="com.jcraft.jzlib"/>
<attribute name="NB-Original-CRC" value="2186560448"/>
<attribute name="NB-Original-CRC" value="${c.jcraft.jzlib.crc32}"/>
</manifest>
</jar>
</target>
Expand Down
60 changes: 60 additions & 0 deletions nbbuild/antsrc/org/netbeans/nbbuild/FileCRC32Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package org.netbeans.nbbuild;

import java.io.File;
import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.StandardOpenOption;
import java.util.zip.CRC32;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

/**
* Calculate the CRC32 checksum for the given file. The resulting long value
* is converted to a string and placed in the property denoted with the name
* of {@code property}.
*/
public class FileCRC32Calculator extends Task {

private File file;
public void setFile(File file) {
this.file = file;
}

private String property;
public void setProperty(String property) {
this.property = property;
}

public @Override void execute() throws BuildException {

try {
CRC32 crc32 = new CRC32();
try(FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.READ)) {
MappedByteBuffer mbb = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
crc32.update(mbb);
}
getProject().setProperty(property, Long.toString(crc32.getValue()));
} catch (IOException ex) {
throw new BuildException(ex);
}
}
}
4 changes: 4 additions & 0 deletions nbbuild/templates/projectized.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ If you are sure you want to build with JDK 9+ anyway, use: -Dpermit.jdk9.builds=
<taskdef name="downloadbinaries" classname="org.netbeans.nbbuild.extlibs.DownloadBinaries" classpath="${nbantext.jar}"/>
</target>

<target name="-define-FileCRC32Calculator">
<taskdef name="FileCRC32Calculator" classname="org.netbeans.nbbuild.FileCRC32Calculator" classpath="${nbantext.jar}"/>
</target>

<target name="-process.release.files"/>

<target name="-download.release.files" depends="-define-downloadbinaries-task">
Expand Down
5 changes: 3 additions & 2 deletions o.apache.commons.codec/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
-->
<project name="o.apache.commons.codec" default="build" basedir=".">
<import file="../nbbuild/templates/projectized.xml"/>
<target name="jar">
<target name="jar" depends="-define-FileCRC32Calculator">
<FileCRC32Calculator file="external/commons-codec-1.3.jar" property="o.apache.commons.codec.crc32" />
<jar jarfile="${cluster}/${module.jar}">
<zipfileset src="external/commons-codec-1.3.jar"/>
<manifest>
<attribute name="Bundle-SymbolicName" value="org.apache.commons.codec"/>
<attribute name="Bundle-Version" value="1.3.0"/>
<attribute name="Export-Package" value="org.apache.commons.codec;version=&quot;1.3.0&quot;,org.apache.commons.codec.binary;version=&quot;1.3.0&quot;,org.apache.commons.codec.digest;version=&quot;1.3.0&quot;,org.apache.commons.codec.language;version=&quot;1.3.0&quot;,org.apache.commons.codec.net;version=&quot;1.3.0&quot;"/>
<attribute name="NB-Original-CRC" value="1856893722"/>
<attribute name="NB-Original-CRC" value="${o.apache.commons.codec.crc32}"/>
</manifest>
</jar>
</target>
Expand Down
5 changes: 3 additions & 2 deletions o.apache.commons.httpclient/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
-->
<project name="o.apache.commons.httpclient" default="build" basedir=".">
<import file="../nbbuild/templates/projectized.xml"/>
<target name="jar">
<target name="jar" depends="-define-FileCRC32Calculator">
<FileCRC32Calculator file="external/commons-httpclient-3.1.jar" property="o.apache.commons.httpclient.crc32" />
<jar jarfile="${cluster}/${module.jar}">
<zipfileset src="external/commons-httpclient-3.1.jar"/>
<manifest>
Expand All @@ -30,7 +31,7 @@
<attribute name="Export-Package" value="org.apache.commons.httpclient;version=&quot;3.1.0&quot;,org.apache.commons.httpclient.auth;version=&quot;3.1.0&quot;,org.apache.commons.httpclient.cookie;version=&quot;3.1.0&quot;,org.apache.commons.httpclient.methods;version=&quot;3.1.0&quot;,org.apache.commons.httpclient.methods.multipart;version=&quot;3.1.0&quot;,org.apache.commons.httpclient.params;version=&quot;3.1.0&quot;,org.apache.commons.httpclient.protocol;version=&quot;3.1.0&quot;,org.apache.commons.httpclient.util;version=&quot;3.1.0&quot;"/>
<attribute name="Import-Package" value="javax.crypto;resolution:=optional,javax.crypto.spec;resolution:=optional,javax.net;resolution:=optional,javax.net.ssl;resolution:=optional,org.apache.commons.codec;version=&quot;[1.2.0,2.0.0)&quot;,org.apache.commons.codec.binary;version=&quot;[1.2.0,2.0.0)&quot;,org.apache.commons.codec.net;version=&quot;[1.2.0,2.0.0)&quot;,org.apache.commons.logging;version=&quot;[1.0.4,2.0.0)&quot;"/>
<attribute name="Bundle-ManifestVersion" value="2"/>
<attribute name="NB-Original-CRC" value="1640872803"/>
<attribute name="NB-Original-CRC" value="${o.apache.commons.httpclient.crc32}"/>
</manifest>
</jar>
</target>
Expand Down
5 changes: 3 additions & 2 deletions o.apache.commons.logging/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
-->
<project name="o.apache.commons.logging" default="build" basedir=".">
<import file="../nbbuild/templates/projectized.xml"/>
<target name="jar">
<target name="jar" depends="-define-FileCRC32Calculator">
<FileCRC32Calculator file="external/commons-logging-1.1.1.jar" property="o.apache.commons.logging.crc32" />
<jar jarfile="${cluster}/${module.jar}">
<zipfileset src="external/commons-logging-1.1.1.jar"/>
<manifest>
<attribute name="Bundle-SymbolicName" value="org.apache.commons.logging"/>
<attribute name="Bundle-Version" value="1.1.1"/>
<attribute name="Export-Package" value="org.apache.commons.logging;version=&quot;1.1.1&quot;,org.apache.commons.logging.impl;version=&quot;1.1.1&quot;"/>
<attribute name="NB-Original-CRC" value="3077296198"/>
<attribute name="NB-Original-CRC" value="${o.apache.commons.logging.crc32}"/>
</manifest>
</jar>
</target>
Expand Down
5 changes: 3 additions & 2 deletions o.apache.ws.commons.util/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
-->
<project name="o.apache.ws.commons.util" default="build" basedir=".">
<import file="../nbbuild/templates/projectized.xml"/>
<target name="jar">
<target name="jar" depends="-define-FileCRC32Calculator">
<FileCRC32Calculator file="external/ws-commons-util-1.0.1.jar" property="o.apache.ws.commons.util.crc32" />
<jar jarfile="${cluster}/${module.jar}">
<zipfileset src="external/ws-commons-util-1.0.1.jar"/>
<manifest>
<attribute name="Bundle-SymbolicName" value="org.apache.ws.commons.util"/>
<attribute name="Bundle-Version" value="1.0.1"/>
<attribute name="Export-Package" value="org.apache.ws.commons.serialize;version=&quot;1.0.1&quot;,org.apache.ws.commons.util;version=&quot;1.0.1&quot;"/>
<attribute name="Import-Package" value="javax.xml,javax.xml.namespace,org.w3c.dom,org.xml.sax,org.xml.sax.ext,org.xml.sax.helpers"/>
<attribute name="NB-Original-CRC" value="1266531998"/>
<attribute name="NB-Original-CRC" value="${o.apache.ws.commons.util.crc32}"/>
</manifest>
</jar>
</target>
Expand Down
5 changes: 3 additions & 2 deletions o.apache.xmlrpc/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
-->
<project name="o.apache.xmlrpc" default="build" basedir=".">
<import file="../nbbuild/templates/projectized.xml"/>
<target name="jar">
<target name="jar" depends="-define-FileCRC32Calculator">
<FileCRC32Calculator file="external/xmlrpc-common-3.0.jar" property="o.apache.xmlrpc.crc32" />
<jar jarfile="${cluster}/${module.jar}">
<zipfileset src="external/xmlrpc-common-3.0.jar"/>
<zipfileset src="external/xmlrpc-client-3.0.jar"/>
Expand All @@ -31,7 +32,7 @@
<attribute name="Bundle-Version" value="3.0.0"/>
<attribute name="Export-Package" value="org.apache.xmlrpc,org.apache.xmlrpc.client,org.apache.xmlrpc.client.util,org.apache.xmlrpc.common,org.apache.xmlrpc.jaxb,org.apache.xmlrpc.metadata,org.apache.xmlrpc.parser,org.apache.xmlrpc.serializer,org.apache.xmlrpc.server,org.apache.xmlrpc.util,org.apache.xmlrpc.webserver"/>
<attribute name="Import-Package" value="javax.xml.bind,javax.xml.namespace,javax.xml.parsers,org.apache.commons.httpclient,org.apache.commons.httpclient.auth,org.apache.commons.httpclient.methods,org.apache.commons.httpclient.params,org.apache.commons.logging,org.apache.ws.commons.serialize,org.apache.ws.commons.util,org.w3c.dom,org.xml.sax,org.xml.sax.helpers"/>
<attribute name="NB-Original-CRC" value="1455537817"/> <!--CRC of xmlrpc-common-3.0.jar-->
<attribute name="NB-Original-CRC" value="${o.apache.xmlrpc.crc32}"/> <!-- CRC of xmlrpc-common-3.0.jar -->
</manifest>
</jar>
</target>
Expand Down

0 comments on commit 9b819cf

Please sign in to comment.