From ba59d21c5e9b1437fb31f9e1295602f4ab24403b Mon Sep 17 00:00:00 2001 From: imbajin Date: Thu, 19 Jan 2023 18:38:19 +0800 Subject: [PATCH] chore(license): fix 3rd party refer in LICENSE also add sky-walking action to check license header --- .github/workflows/check-dependencies.yml | 4 +- .github/workflows/ci.yml | 9 ++- .github/workflows/license-checker.yml | 34 ++++++++ .github/workflows/stale.yml | 4 +- .licenserc.yaml | 77 +++++++++++++++++++ .../hugegraph/rest/AbstractRestClient.java | 9 +-- .../java/org/apache/hugegraph/util/Bytes.java | 3 +- .../apache/hugegraph/util/CheckSocket.java | 66 ++++++---------- .../org/apache/hugegraph/util/DateUtil.java | 6 +- .../java/org/apache/hugegraph/util/E.java | 4 +- .../apache/hugegraph/util/LongEncoding.java | 4 - .../apache/hugegraph/util/NumericUtil.java | 9 +-- .../apache/hugegraph/util/OrderLimitMap.java | 9 +-- .../apache/hugegraph/util/VersionUtil.java | 5 -- 14 files changed, 155 insertions(+), 88 deletions(-) create mode 100644 .github/workflows/license-checker.yml create mode 100644 .licenserc.yaml diff --git a/.github/workflows/check-dependencies.yml b/.github/workflows/check-dependencies.yml index f6b35c41..06a087b9 100644 --- a/.github/workflows/check-dependencies.yml +++ b/.github/workflows/check-dependencies.yml @@ -10,10 +10,10 @@ jobs: steps: - name: Checkout source uses: actions/checkout@v3 - - name: Set up JDK 8 + - name: Set up JDK 11 uses: actions/setup-java@v3 with: - java-version: '8' + java-version: '11' distribution: 'adopt' - name: mvn install run: | diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b7f08d9..b2552479 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ on: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: fail-fast: false matrix: @@ -37,12 +37,13 @@ jobs: - name: License check(RAT) run: | - mvn apache-rat:check | grep -v "Downloading\|Downloaded\|Progress" - find ./ -name rat.txt -print0 | xargs -0 -I file cat file > merged-rat.txt && cat merged-rat.txt + mvn apache-rat:check -ntp + find ./ -name rat.txt -print0 | xargs -0 -I file cat file > merged-rat.txt + grep "Binaries" merged-rat.txt -C 3 && cat merged-rat.txt - name: Compile run: | - mvn compile -Dmaven.javadoc.skip=true | grep -v "Downloading\|Downloaded" + mvn compile -Dmaven.javadoc.skip=true -ntp - name: Run test run: | diff --git a/.github/workflows/license-checker.yml b/.github/workflows/license-checker.yml new file mode 100644 index 00000000..2345f125 --- /dev/null +++ b/.github/workflows/license-checker.yml @@ -0,0 +1,34 @@ +name: License checker + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + check-license: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + # More info could refer to: https://github.com/apache/skywalking-eyes + - name: Check License Header + uses: apache/skywalking-eyes@main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + log: info + config: .licenserc.yaml + + - uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'adopt' + + - name: License check(RAT) + run: | + mvn apache-rat:check -ntp + find ./ -name rat.txt -print0 | xargs -0 -I file cat file > merged-rat.txt + grep "Binaries" merged-rat.txt -C 3 && cat merged-rat.txt diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 93e1bd1c..1d7651bc 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -20,8 +20,8 @@ jobs: stale-pr-message: 'Due to the lack of activity, the current pr is marked as stale and will be closed after 180 days, any update will remove the stale label' stale-issue-label: 'inactive' stale-pr-label: 'inactive' - exempt-issue-labels: 'feature,bug,enhancement,improvement,wontfix,todo,help wanted' - exempt-pr-labels: 'feature,bug,enhancement,improvement,wontfix,todo,help wanted' + exempt-issue-labels: 'feature,bug,enhancement,improvement,todo,guide,doc,help wanted,security' + exempt-pr-labels: 'feature,bug,enhancement,improvement,todo,guide,doc,help wanted,security' exempt-all-milestones: true days-before-issue-stale: 15 diff --git a/.licenserc.yaml b/.licenserc.yaml new file mode 100644 index 00000000..13767b78 --- /dev/null +++ b/.licenserc.yaml @@ -0,0 +1,77 @@ +# +# 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. +# + +header: # `header` section is configurations for source codes license header. + license: + spdx-id: Apache-2.0 # the spdx id of the license, it's convenient when your license is standard SPDX license. + copyright-owner: Apache Software Foundation # the copyright owner to replace the [owner] in the `spdx-id` template. + content: | # `license` will be used as the content when `fix` command needs to insert a license header. + 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. + # `pattern` is optional regexp if all the file headers are the same as `license` or the license of `spdx-id` and `copyright-owner`. + pattern: | + Licensed to the Apache Software Foundation under one or more contributor + license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright + ownership. The Apache Software Foundation 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. + paths: # `paths` are the path list that will be checked (and fixed) by license-eye, default is ['**']. + - '**' + + paths-ignore: # `paths-ignore` are the path list that will be ignored by license-eye. + - '.gitignore' + - 'LICENSE' + - 'NOTICE' + - 'DISCLAIMER' + - '**/*.md' + - '**/*.versionsBackup' + - '**/*.log' + - '**/*.txt' + - '**/*.csv' + - '**/*.json' + - '**/*.svg' + - '**/*.gitattributes' + - '**/.flattened-pom.xml' + - '**/.prettierrc' + - '**/.stylelintrc' + - 'assembly/**' + - '.github/**/*' + - '**/target/*' + comment: on-failure # on what condition license-eye will comment on the pull request, `on-failure`, `always`, `never`. + + # license-location-threshold specifies the index threshold where the license header can be located, + # after all, a "header" cannot be TOO far from the file start. + license-location-threshold: 80 diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/rest/AbstractRestClient.java b/hugegraph-common/src/main/java/org/apache/hugegraph/rest/AbstractRestClient.java index 37c4df86..ea7e923e 100644 --- a/hugegraph-common/src/main/java/org/apache/hugegraph/rest/AbstractRestClient.java +++ b/hugegraph-common/src/main/java/org/apache/hugegraph/rest/AbstractRestClient.java @@ -427,13 +427,8 @@ private static MediaType parseCustomContentType(MultivaluedMap h private static void configConnectionManager(String url, ClientConfig conf) { /* * Using httpclient with connection pooling, and configuring the - * jersey connector, reference: - * http://www.theotherian.com/2013/08/jersey-client-2.0-httpclient-timeouts-max-connections.html - * https://stackoverflow.com/questions/43228051/memory-issue-with-jax-rs-using-jersey/46175943#46175943 - * - * But the jersey that has been released in the maven central - * repository seems to have a bug. - * https://github.com/jersey/jersey/pull/3752 + * jersey connector. But the jersey that has been released in the maven central + * repository seems to have a bug: https://github.com/jersey/jersey/pull/3752 */ PoolingHttpClientConnectionManager pool = connectionManager(url, conf); Object maxTotal = conf.getProperty("maxTotal"); diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/util/Bytes.java b/hugegraph-common/src/main/java/org/apache/hugegraph/util/Bytes.java index 79ece63a..4abd57df 100644 --- a/hugegraph-common/src/main/java/org/apache/hugegraph/util/Bytes.java +++ b/hugegraph-common/src/main/java/org/apache/hugegraph/util/Bytes.java @@ -38,8 +38,7 @@ public final class Bytes { public static final long PB = GB * MB; public static final long EB = GB * GB; - private static final Comparator CMP = - UnsignedBytes.lexicographicalComparator(); + private static final Comparator CMP = UnsignedBytes.lexicographicalComparator(); public static int compare(byte[] bytes1, byte[] bytes2) { return CMP.compare(bytes1, bytes2); diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/util/CheckSocket.java b/hugegraph-common/src/main/java/org/apache/hugegraph/util/CheckSocket.java index 96d83e38..09a36b9a 100644 --- a/hugegraph-common/src/main/java/org/apache/hugegraph/util/CheckSocket.java +++ b/hugegraph-common/src/main/java/org/apache/hugegraph/util/CheckSocket.java @@ -1,55 +1,37 @@ -// Copyright 2017 JanusGraph Authors -// -// 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. +/* + * 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.apache.hugegraph.util; -import java.io.IOException; +import static java.lang.System.exit; + import java.net.InetAddress; import java.net.Socket; -/* - * This doesn't really belong here. It's only used in the zipfile - * distribution to check whether Gremlin Server or ES are listening on - * their respective TCP ports. But it's so tiny that I don't want - * to reorganize the repo to accommodate it (yet). - * - * Many widely available *NIX programs do this task better (e.g. - * netcat, telnet, nmap, socat, ... we could even use netstat since - * we're interested only in the status of local ports). But we want - * to keep the JanusGraph distribution self-contained insofar as is - * reasonable. - */ public final class CheckSocket { - private static final int E_USAGE = 1; - private static final int E_FAILED = 2; - private static final String MSG_USAGE = - "Usage: " + CheckSocket.class.getSimpleName() + " hostname port"; - public static void main(String[] args) { - if (args.length != 2) { - System.err.println(MSG_USAGE); - System.exit(E_USAGE); - } try { - Socket s = new Socket(InetAddress.getByName(args[0]), - Integer.parseInt(args[1])); - s.close(); - System.exit(0); - } catch (IOException e) { - System.err.println(e); - System.exit(E_FAILED); + // Check if the socket connection can be closed normally + new Socket(InetAddress.getByName(args[0]), Integer.parseInt(args[1])).close(); + exit(0); + } catch (Exception e) { + e.printStackTrace(); + exit(-1); } } } diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/util/DateUtil.java b/hugegraph-common/src/main/java/org/apache/hugegraph/util/DateUtil.java index 43c58f80..4e7ce13d 100644 --- a/hugegraph-common/src/main/java/org/apache/hugegraph/util/DateUtil.java +++ b/hugegraph-common/src/main/java/org/apache/hugegraph/util/DateUtil.java @@ -37,8 +37,7 @@ public final class DateUtil { "yyyy-MM-dd HH:mm:ss.SSS" ); - private static final Map DATE_FORMATS = - new ConcurrentHashMap<>(); + private static final Map DATE_FORMATS = new ConcurrentHashMap<>(); public static Date parse(String value) { for (Map.Entry entry : VALID_DFS.entrySet()) { @@ -47,8 +46,7 @@ public static Date parse(String value) { } } throw new IllegalArgumentException(String.format( - "Expected date format is: %s, but got '%s'", - VALID_DFS.values(), value)); + "Expected date format is: %s, but got '%s'", VALID_DFS.values(), value)); } public static Date parse(String value, String df) { diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/util/E.java b/hugegraph-common/src/main/java/org/apache/hugegraph/util/E.java index 162999c6..214add30 100644 --- a/hugegraph-common/src/main/java/org/apache/hugegraph/util/E.java +++ b/hugegraph-common/src/main/java/org/apache/hugegraph/util/E.java @@ -40,9 +40,7 @@ public static void checkNotEmpty(Collection collection, String elem) { "The '%s' can't be empty", elem); } - public static void checkNotEmpty(Collection collection, - String elem, - String owner) { + public static void checkNotEmpty(Collection collection, String elem, String owner) { Preconditions.checkArgument(!collection.isEmpty(), "The '%s' of '%s' can't be empty", elem, owner); diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/util/LongEncoding.java b/hugegraph-common/src/main/java/org/apache/hugegraph/util/LongEncoding.java index 24c857fd..761d72b9 100644 --- a/hugegraph-common/src/main/java/org/apache/hugegraph/util/LongEncoding.java +++ b/hugegraph-common/src/main/java/org/apache/hugegraph/util/LongEncoding.java @@ -17,10 +17,6 @@ package org.apache.hugegraph.util; -/** - * Utility class for encoding longs in strings based on: - * @see encode decode long to string - */ public final class LongEncoding { private static final String B64_SYMBOLS = diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/util/NumericUtil.java b/hugegraph-common/src/main/java/org/apache/hugegraph/util/NumericUtil.java index f567a895..51617081 100644 --- a/hugegraph-common/src/main/java/org/apache/hugegraph/util/NumericUtil.java +++ b/hugegraph-common/src/main/java/org/apache/hugegraph/util/NumericUtil.java @@ -291,12 +291,9 @@ public static boolean isNumber(Object value) { public static boolean isNumber(Class clazz) { if (clazz.isPrimitive()) { - if (clazz == int.class || clazz == long.class || - clazz == float.class || clazz == double.class || - clazz == short.class || clazz == byte.class) { - return true; - } - return false; + return clazz == int.class || clazz == long.class || + clazz == float.class || clazz == double.class || + clazz == short.class || clazz == byte.class; } return Number.class.isAssignableFrom(clazz); } diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/util/OrderLimitMap.java b/hugegraph-common/src/main/java/org/apache/hugegraph/util/OrderLimitMap.java index b8ce4715..b711e3e5 100644 --- a/hugegraph-common/src/main/java/org/apache/hugegraph/util/OrderLimitMap.java +++ b/hugegraph-common/src/main/java/org/apache/hugegraph/util/OrderLimitMap.java @@ -24,12 +24,7 @@ import com.google.common.base.Functions; import com.google.common.collect.Ordering; -/** - * Reference: - * ... - */ -public class OrderLimitMap, V extends Comparable> - extends TreeMap { +public class OrderLimitMap, V extends Comparable> extends TreeMap { private static final long serialVersionUID = 756490437953358633L; @@ -37,7 +32,7 @@ public class OrderLimitMap, V extends Comparable> private final Map valueMap; private static > Ordering incr() { - return Ordering.from((V o1, V o2) -> o1.compareTo(o2)); + return Ordering.from(Comparable::compareTo); } private static > Ordering decr() { diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/util/VersionUtil.java b/hugegraph-common/src/main/java/org/apache/hugegraph/util/VersionUtil.java index c7d6c2ed..b49adda8 100644 --- a/hugegraph-common/src/main/java/org/apache/hugegraph/util/VersionUtil.java +++ b/hugegraph-common/src/main/java/org/apache/hugegraph/util/VersionUtil.java @@ -75,7 +75,6 @@ public static String getImplementationVersion(Class clazz) { /* * We don't use Package.getImplementationVersion() due to * a duplicate package would override the origin package info. - * https://stackoverflow.com/questions/1272648/reading-my-own-jars-manifest */ String className = clazz.getSimpleName() + ".class"; String classPath = Objects.requireNonNull(clazz.getResource(className)).toString(); @@ -137,10 +136,6 @@ public static String getPomVersion() { } } - /** - * class Version for compare - * https://stackoverflow.com/questions/198431/how-do-you-compare-two-version-strings-in-java - */ public static class Version implements Comparable { public static Version of(Class clazz) {