This is an automated email from the ASF dual-hosted git repository. sushuang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
The following commit(s) were added to refs/heads/master by this push: new 3a67a85 Support run Apache Rat. 3a67a85 is described below commit 3a67a85eeeecb0735e5bcb6064ce34a898a3c7c3 Author: sushuang <sushuang0...@gmail.com> AuthorDate: Sun May 6 21:23:55 2018 +0800 Support run Apache Rat. --- .gitignore | 3 + .rat-excludes | 70 +++++++------ build/addHeader.js | 8 +- build/preamble.js | 31 +++++- build/{ => rat}/apache-rat-0.12.jar | Bin build/{rat.sh => rat/build-run-rat.sh} | 9 +- build/rat/javassist.jar | Bin 0 -> 759215 bytes build/rat/rat.sh | 63 +++++++++++ build/rat/runrat.jar | Bin 0 -> 2561 bytes build/rat/src/MANIFEST.txt | 2 + build/rat/src/RunRat.class | Bin 0 -> 3914 bytes build/rat/src/RunRat.java | 184 +++++++++++++++++++++++++++++++++ build/rat/src/report.xsl | 88 ++++++++++++++++ 13 files changed, 414 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index a76de90..b1ed4aa 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ tmp/ .svn local.properties .classpath +.class .settings/ .loadpath @@ -162,6 +163,8 @@ pip-log.txt # Mac crap .DS_Store .idea +.ideaout +rat.iml node_modules diff --git a/.rat-excludes b/.rat-excludes index 435b9b4..903c4bd 100644 --- a/.rat-excludes +++ b/.rat-excludes @@ -1,43 +1,55 @@ +# Only support regexp, testing against each relative file path +# based on the echart base directory. And the pattern should +# match the relative path completely. +# Do not use wildcard. Although Apache Rat v0.12 implemented +# it, it probably does not do it right, where patterns are +# parsed as Regex firstly but do not catch the exception. + node_modules -\.git -\.github -\.editorconfig -\.gitignore -\.jshintrc -\.jshintrc-dist -\.npmignore -\.rat-excludes -\.DS_Store +.*\.git +.*\.github +.*\.editorconfig +.*\.gitignore +.*\.jshintrc$ +.*\.jshintrc-dist +.*\.npmignore +.*\.rat-excludes +.*\.DS_Store +.*\.idea +.*rat\.iml __MAC_OS -README.md +.*README.md +.*MANIFEST\.txt DISCLAIMER NOTICE KEYS LICENSE licenses -benchmark/dep map/js map/json +benchmark/dep/* test/ut/lib test/data$ test/lib/esl\.js test/lib/perlin\.js test/lib/countup\.js -jquery\.min\.js -configure -IAxisPointer$ -ICoordinateSystem$ -.+\.json$ -.+\.map$ -.+\.gexf$ -.+\.jar$ -.+\.bin$ -.+\.csv$ -.+\.png$ -.+\.PNG$ -.+\.jpg$ -.+\.JPG$ -.+\.jpeg$ -.+\.JPEG$ -.+\.gif$ -.+\.GIF$ +.*jquery\.min\.js +.*rollup\.browser\.js +.*configure +.*IAxisPointer +.*ICoordinateSystem +.+\.json +.+\.map +.+\.gexf +.+\.jar +.+\.bin +.+\.csv +.+\.png +.+\.PNG +.+\.jpg +.+\.JPG +.+\.jpeg +.+\.JPEG +.+\.gif +.+\.GIF +.+\.class diff --git a/build/addHeader.js b/build/addHeader.js index 7f74858..8e9afd5 100644 --- a/build/addHeader.js +++ b/build/addHeader.js @@ -151,7 +151,7 @@ function eachFile(visit) { const content = fs.readFileSync(excludesPath, {encoding: 'utf-8'}); content.replace(/\r/g, '\n').split('\n').forEach(function (line) { line = line.trim(); - if (line) { + if (line && line.charAt(0) !== '#') { excludePatterns.push(new RegExp(line)); } }); @@ -177,10 +177,4 @@ function eachFile(visit) { } } -// function assert(cond, msg) { -// if (!cond) { -// throw new Error(msg); -// } -// } - run(); diff --git a/build/preamble.js b/build/preamble.js index dea0d63..5d815a1 100644 --- a/build/preamble.js +++ b/build/preamble.js @@ -103,6 +103,10 @@ const addFns = { return headStr + fileStr; }, + java: function (headStr, fileStr) { + return headStr + fileStr; + }, + sh: function (headStr, fileStr) { // Git diff enables manual check. if (/^#\!/.test(fileStr)) { @@ -122,16 +126,32 @@ const addFns = { if (resultStr.length === fileStr.length) { resultStr = headStr + fileStr; } - return resultStr; - } + }, + + xml: xmlAddFn, + + xsl: xmlAddFn }; +function xmlAddFn(headStr, fileStr) { + // Git diff enables manual check. + let resultStr = fileStr.replace(/^\s*<\?xml\s[^<>]+\?>/i, '$&' + headStr); + // If no <?xml version='1.0' ?> + if (resultStr.length === fileStr.length) { + resultStr = headStr + fileStr; + } + return resultStr; +} + const preambleMap = { js: cStyleComment, css: cStyleComment, + java: cStyleComment, sh: hashComment, - html: mlComment + html: mlComment, + xml: mlComment, + xsl: mlComment }; const licenseReg = [ @@ -161,8 +181,11 @@ const mlCommentReg = /<\!\-\-[\S\s]*?\-\->/; const commentReg = { js: cStyleCommentReg, css: cStyleCommentReg, + java: cStyleCommentReg, sh: hashCommentReg, - html: mlCommentReg + html: mlCommentReg, + xml: mlCommentReg, + xsl: mlCommentReg }; function extractComment(str, fileExt) { diff --git a/build/apache-rat-0.12.jar b/build/rat/apache-rat-0.12.jar similarity index 100% rename from build/apache-rat-0.12.jar rename to build/rat/apache-rat-0.12.jar diff --git a/build/rat.sh b/build/rat/build-run-rat.sh similarity index 76% rename from build/rat.sh rename to build/rat/build-run-rat.sh index b7ce8b3..d02ffef 100644 --- a/build/rat.sh +++ b/build/rat/build-run-rat.sh @@ -1,3 +1,4 @@ +#!/bin/sh # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file @@ -17,8 +18,8 @@ # under the License. basePath=$(cd `dirname $0`; pwd) -ecPath=${basePath}/.. +ecPath=${basePath}/../.. +runRatSrcDir=${ecPath}/build/rat/src -java -jar "${basePath}/apache-rat-0.12.jar" --exclude-file "${ecPath}/.rat-excludes" --dir "${ecPath}" -# > "${basePath}/rat-result.txt" -# java -jar "${basePath}/apache-rat/apache-rat-0.12.jar" -h \ No newline at end of file +javac -classpath ${ecPath}/build/rat/javassist.jar ${runRatSrcDir}/RunRat.java +jar cfmv ${ecPath}/build/rat/runrat.jar ${runRatSrcDir}/MANIFEST.txt -C ${runRatSrcDir} RunRat.class diff --git a/build/rat/javassist.jar b/build/rat/javassist.jar new file mode 100755 index 0000000..232bb34 Binary files /dev/null and b/build/rat/javassist.jar differ diff --git a/build/rat/rat.sh b/build/rat/rat.sh new file mode 100644 index 0000000..6ce6819 --- /dev/null +++ b/build/rat/rat.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +# 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. + + +# RunRat is used to call Apache Rat. +# +# (1) Usage: +# +# Check all: +# ```shell +# java -jar ${ecPath}/build/rat/runrat.jar +# ``` +# +# Get help: +# ```shell +# java -jar ${ecPath}/build/rat/runrat.jar --help +# ``` +# +# Notice that most of the arguments is the same as Apache Rat, +# only `--dir` and `--exclude` should not be specified. +# +# Ohter feature of Apache Rat: +# ```shell +# java -jar ${ecPath}/build/rat/runrat.jar [option] +# ``` +# +# +# (2) Why call Apache Rat via `RunRat`? +# +# Because Apache Rat only support specifying file name (in regexp or wildcard) in its +# "exclude" file, but not support specifying file path (in regexp or wildcard), which +# is commonly necessary in the "ignore/exclude" file of this kind of features. +# +# For example: +# the file path "aaa/lib" (with slash) is not supported. But if only specifying "lib", +# all of the directories "lib" are excluded, which is not expected. +# +# (See `org.apache.rat.walker.Walker#isIgnore` for details, where the file `dir` is not +# actually used by `org.apache.commons.io.filefilter.RegexFileFilter#accept` and +# `org.apache.commons.io.filefilter.WildcardFileFilter#accept`.) +# So use this tool as a workaround. + + +basePath=$(cd `dirname $0`; pwd) +ecPath=${basePath}/../.. + +java -jar ${ecPath}/build/rat/runrat.jar diff --git a/build/rat/runrat.jar b/build/rat/runrat.jar new file mode 100644 index 0000000..2407c55 Binary files /dev/null and b/build/rat/runrat.jar differ diff --git a/build/rat/src/MANIFEST.txt b/build/rat/src/MANIFEST.txt new file mode 100755 index 0000000..a785f68 --- /dev/null +++ b/build/rat/src/MANIFEST.txt @@ -0,0 +1,2 @@ +Main-Class: RunRat +Class-Path: ./ ./javassist.jar diff --git a/build/rat/src/RunRat.class b/build/rat/src/RunRat.class new file mode 100644 index 0000000..9c008b4 Binary files /dev/null and b/build/rat/src/RunRat.class differ diff --git a/build/rat/src/RunRat.java b/build/rat/src/RunRat.java new file mode 100644 index 0000000..763f936 --- /dev/null +++ b/build/rat/src/RunRat.java @@ -0,0 +1,184 @@ +/* + * 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. + */ + +/** + * RunRat is used to call Apache Rat. + * + * + * (1) Usage: + * + * Prepare, in command line: + * ```shell + * cd ${echartsBaseDir}/build/rat + * ``` + * + * Check all: + * ```shell + * java RunRat + * ``` + * + * Get help: + * ```shell + * java RunRat --help + * ``` + * + * Notice that most of the arguments is the same as Apache Rat, + * only `--dir` and `--exclude` should not be specified. + * + * Ohter feature of Apache Rat: + * ```shell + * java RunRat [option] + * ``` + * + * Rebuild: + * ```shell + * javac RunRat.java + * ``` + * + * + * (2) Why call Apache Rat via `RunRat`? + * + * Because Apache Rat only support specifying file name (in regexp or wildcard) in its + * "exclude" file, but not support specifying file path (in regexp or wildcard), which + * is commonly necessary in the "ignore/exclude" file of this kind of features. + * + * For example: + * the file path "aaa/lib" (with slash) is not supported. But if only specifying "lib", + * all of the directories "lib" are excluded, which is not expected. + * + * (See `org.apache.rat.walker.Walker#isIgnore` for details, where the file `dir` is not + * actually used by `org.apache.commons.io.filefilter.RegexFileFilter#accept` and + * `org.apache.commons.io.filefilter.WildcardFileFilter#accept`.) + * + * So use this tool as a workaround. + */ + +import java.io.File; +import java.lang.reflect.Method; +import java.util.ArrayList; + +import javassist.ClassPool; +import javassist.CtClass; +import javassist.CtMethod; +import javassist.Loader; + +public class RunRat { + + private String defaultRatMainClassName = "org.apache.rat.Report"; + + private Method ratReportMainMethod; + + private File ecBaseDir; + + private ArrayList<String> ratArgList = new ArrayList<String>(); + + public static void main(String[] args) throws Exception { + + RunRat runRat = new RunRat(); + + runRat.prepareArgs(args); + + runRat.prepareLibs(args); + + runRat.callRat(); + } + + private void prepareArgs(String[] args) throws IllegalArgumentException { + boolean reportTplSpecified = false; + for (int i = 0; i < args.length; ) { + String argStr = args[i]; + + if (argStr.equals("--dir") + || argStr.equals("-d") + || argStr.equals("-e") + || argStr.equals("--exclude") + || argStr.equals("-E") + || argStr.equals("-exclude-file") + ) { + throw new IllegalArgumentException(argStr + " should not be specified!"); + } + + if (argStr.equals("-s") || argStr.equals("--stylesheet")) { + reportTplSpecified = true; + } + + if (argStr.equals("--ec-base")) { + this.ecBaseDir = new File(args[i + 1]); + i += 2; + } + else { + this.ratArgList.add(argStr); + i++; + } + } + + if (this.ecBaseDir == null) { + this.ecBaseDir = new File(new File( + this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath() + ).getParent() + "/../.."); + } + + this.ratArgList.add("--dir"); + this.ratArgList.add(this.ecBaseDir.getPath()); + this.ratArgList.add("--exclude-file"); + this.ratArgList.add(this.ecBaseDir.getPath() + "/.rat-excludes"); + if (!reportTplSpecified) { + this.ratArgList.add("-s"); + this.ratArgList.add(this.ecBaseDir.getPath() + "/build/rat/src/report.xsl"); + } + } + + private void prepareLibs(String[] args) throws Exception { + + ClassPool cPool = new ClassPool(true); + Loader loader = new Loader(cPool); + cPool.appendClassPath(this.ecBaseDir + "/build/rat/apache-rat-0.12.jar"); + + CtClass ctclzWalker = cPool.get("org.apache.rat.walker.Walker"); + CtMethod ctmethodIgnored = ctclzWalker.getDeclaredMethod("ignored"); + + String ecBaseDirPath = this.ecBaseDir.getPath(); + + ctmethodIgnored.setBody("" + + "{" + + " boolean result = false;" + + " if (this.filter != null) {" + + " String name = $1.getName();" + + " java.io.File dir = $1.getParentFile();" + + " String relativePath = new java.io.File(\"" + ecBaseDirPath + "\").toURI().relativize($1.toURI()).getPath();" + + " if (relativePath.endsWith(\"/\")) {" + + " relativePath = relativePath.substring(0, relativePath.length() - 1);" + + " }" + + " result = !this.filter.accept(dir, relativePath);" + + " }" + + " return result;" + + "}" + ); + + Class clzRatReport = loader.loadClass(this.defaultRatMainClassName); + this.ratReportMainMethod = clzRatReport.getDeclaredMethod("main", String[].class); + } + + private void callRat() throws Exception { + String[] ratArgs = this.ratArgList.toArray(new String[this.ratArgList.size()]); + + this.ratReportMainMethod.invoke(null, (Object)ratArgs); + } + +} diff --git a/build/rat/src/report.xsl b/build/rat/src/report.xsl new file mode 100644 index 0000000..5138347 --- /dev/null +++ b/build/rat/src/report.xsl @@ -0,0 +1,88 @@ +<?xml version='1.0' ?> +<!-- + 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. * +--> +<xsl:stylesheet version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> +<xsl:output method='text'/> +<xsl:template match='/'> +***************************************************** +Summary +------- +Generated at: <xsl:value-of select='rat-report/@timestamp'/> + +Notes: <xsl:value-of select='count(descendant::type[attribute::name="notice"])'/> +Binaries: <xsl:value-of select='count(descendant::type[attribute::name="binary"])'/> +Archives: <xsl:value-of select='count(descendant::type[attribute::name="archive"])'/> +Standards: <xsl:value-of select='count(descendant::type[attribute::name="standard"])'/> + +Apache Licensed: <xsl:value-of select='count(descendant::header-type[attribute::name="AL "])'/> +Generated Documents: <xsl:value-of select='count(descendant::header-type[attribute::name="GEN "])'/> + +JavaDocs are generated, thus a license header is optional. +Generated files do not require license headers. + +<xsl:value-of select='count(descendant::header-type[attribute::name="?????"])'/> Unknown Licenses +<xsl:if test="descendant::resource[license-approval/@name='false']"> +***************************************************** + +Files with unapproved licenses: + +<xsl:for-each select='descendant::resource[license-approval/@name="false"]'> + <xsl:text> </xsl:text> + <xsl:value-of select='@name'/> + <xsl:text> +</xsl:text> +</xsl:for-each> +***************************************************** +</xsl:if> +<xsl:if test="descendant::resource[type/@name='archive']"> +Archives: +<xsl:for-each select='descendant::resource[type/@name="archive"]'> + + <xsl:value-of select='@name'/> + <xsl:text> + </xsl:text> + </xsl:for-each> +</xsl:if> + + +***************************************************** + Files with Apache License headers will be marked AL + Binary files (which do not require any license headers) will be marked B + Compressed archives will be marked A + Notices, licenses etc. will be marked N + <xsl:for-each select='descendant::resource'> + <xsl:choose> + <xsl:when test='license-approval/@name="false"'>!</xsl:when> + <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise> + </xsl:choose> + <xsl:choose> + <xsl:when test='type/@name="notice"'>N </xsl:when> + <xsl:when test='type/@name="archive"'>A </xsl:when> + <xsl:when test='type/@name="binary"'>B </xsl:when> + <xsl:when test='type/@name="standard"'><xsl:value-of select='header-type/@name'/></xsl:when> + <xsl:otherwise>!!!!!</xsl:otherwise> + </xsl:choose> + <xsl:text> </xsl:text> + <xsl:value-of select='@name'/> + <xsl:text> + </xsl:text> + </xsl:for-each> + +</xsl:template> +</xsl:stylesheet> \ No newline at end of file -- To stop receiving notification emails like this one, please contact sushu...@apache.org. --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org For additional commands, e-mail: commits-h...@echarts.apache.org