This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-test-tools.git


The following commit(s) were added to refs/heads/main by this push:
     new 6653597  Fix 'Ignoring does not work in Linux', and update NOTICE. (#3)
6653597 is described below

commit 665359702b471ac94c2f49d66ace6ea66a8b3d3d
Author: Andy Cheung <[email protected]>
AuthorDate: Thu Oct 27 10:50:03 2022 +0800

    Fix 'Ignoring does not work in Linux', and update NOTICE. (#3)
---
 NOTICE                                             | 67 ++++++++++++++++++++++
 .../main/java/org/apache/dubbo/errorcode/Main.java | 12 +---
 .../errorcode/config/ErrorCodeInspectorConfig.java | 17 ++++--
 .../org/apache/dubbo/errorcode/util/FileUtils.java | 17 ++++++
 .../apache/dubbo/errorcode/util/FileUtilsTest.java | 24 +++++++-
 5 files changed, 121 insertions(+), 16 deletions(-)

diff --git a/NOTICE b/NOTICE
index dfe0a27..20f7a59 100644
--- a/NOTICE
+++ b/NOTICE
@@ -3,3 +3,70 @@ Copyright 2018-2022 The Apache Software Foundation
 
 This product includes software developed at
 The Apache Software Foundation (http://www.apache.org/).
+
+This product depends on 'Javassist' to inspect Java class file, which has the 
following notices:
+    /*
+     * Javassist, a Java-bytecode translator toolkit.
+     * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.
+     *
+     * The contents of this file are subject to the Mozilla Public License 
Version
+     * 1.1 (the "License"); you may not use this file except in compliance with
+     * the License.  Alternatively, the contents of this file may be used under
+     * the terms of the GNU Lesser General Public License Version 2.1 or later,
+     * or the Apache License Version 2.0.
+     *
+     * Software distributed under the License is distributed on an "AS IS" 
basis,
+     * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+     * for the specific language governing rights and limitations under the
+     * License.
+     */
+
+This product depends on 'Eclipse JDT' to perform inspection of source files, 
which has the following notices:
+
+    # Notices for Eclipse Java development tools
+
+    This content is produced and maintained by the Eclipse Java development 
tools
+    project.
+
+    * Project home: https://projects.eclipse.org/projects/eclipse.jdt
+
+    ## Trademarks
+
+    Eclipse Java development tools, Java development tools, Eclipse JDT, and 
JDT are
+    trademarks of the Eclipse Foundation.
+
+    ## Copyright
+
+    All content is the property of the respective authors or their employers. 
For
+    more information regarding authorship of content, please consult the listed
+    source code repository logs.
+
+    ## Declared Project Licenses
+
+    This program and the accompanying materials are made available under the 
terms
+    of the Eclipse Public License v. 2.0 which is available at
+    http://www.eclipse.org/legal/epl-2.0.
+
+    SPDX-License-Identifier: EPL-2.0
+
+    ## Source Code
+
+    The project maintains the following source code repositories:
+
+    * http://git.eclipse.org/c/jdt/eclipse.jdt.core.binaries.git
+    * http://git.eclipse.org/c/jdt/eclipse.jdt.core.git
+    * http://git.eclipse.org/c/jdt/eclipse.jdt.debug.git
+    * http://git.eclipse.org/c/jdt/eclipse.jdt.git
+    * http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git
+
+This product uses 'junit' to perform unit tests, which has the following 
notices:
+    /*
+     * Copyright 2015-2022 the original author or authors.
+     *
+     * All rights reserved. This program and the accompanying materials are
+     * made available under the terms of the Eclipse Public License v2.0 which
+     * accompanies this distribution and is available at
+     *
+     * https://www.eclipse.org/legal/epl-v20.html
+     */
+
diff --git 
a/dubbo-error-code-inspector/src/main/java/org/apache/dubbo/errorcode/Main.java 
b/dubbo-error-code-inspector/src/main/java/org/apache/dubbo/errorcode/Main.java
index 6d1d3b4..6209d61 100644
--- 
a/dubbo-error-code-inspector/src/main/java/org/apache/dubbo/errorcode/Main.java
+++ 
b/dubbo-error-code-inspector/src/main/java/org/apache/dubbo/errorcode/Main.java
@@ -28,8 +28,6 @@ import org.apache.dubbo.errorcode.model.MethodDefinition;
 import org.apache.dubbo.errorcode.reporter.InspectionResult;
 import org.apache.dubbo.errorcode.util.FileUtils;
 
-import java.io.IOException;
-import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -44,7 +42,6 @@ import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 /**
  * Error code extractor main class.
@@ -168,12 +165,9 @@ public class Main {
                                                   CountDownLatch 
countDownLatch,
                                                   Path folder) {
 
-        try (Stream<Path> classFilesStream = Files.walk(folder)) {
+        try {
 
-            List<Path> classFiles = classFilesStream
-                .filter(x -> x.toFile().isFile())
-                .filter(x -> 
!ErrorCodeInspectorConfig.EXCLUSIONS.contains(Paths.get(directoryToInspect).relativize(x).toString()))
-                .collect(Collectors.toList());
+            List<Path> classFiles = 
FileUtils.getAllClassFilesInDirectory(Paths.get(directoryToInspect), folder);
 
             classFiles.forEach(x -> {
 
@@ -189,8 +183,6 @@ public class Main {
                 }
             });
 
-        } catch (IOException ignored) {
-            // ignored.
         } finally {
             countDownLatch.countDown();
         }
diff --git 
a/dubbo-error-code-inspector/src/main/java/org/apache/dubbo/errorcode/config/ErrorCodeInspectorConfig.java
 
b/dubbo-error-code-inspector/src/main/java/org/apache/dubbo/errorcode/config/ErrorCodeInspectorConfig.java
index 2ad7b4d..87837ed 100644
--- 
a/dubbo-error-code-inspector/src/main/java/org/apache/dubbo/errorcode/config/ErrorCodeInspectorConfig.java
+++ 
b/dubbo-error-code-inspector/src/main/java/org/apache/dubbo/errorcode/config/ErrorCodeInspectorConfig.java
@@ -20,10 +20,12 @@ package org.apache.dubbo.errorcode.config;
 import org.apache.dubbo.errorcode.reporter.Reporter;
 import org.apache.dubbo.errorcode.util.FileUtils;
 
+import java.io.File;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * Configuration of Error Code Inspector.
@@ -38,13 +40,12 @@ public class ErrorCodeInspectorConfig {
             Boolean.getBoolean("dubbo.eci.report-as-error") ||
             Boolean.parseBoolean(System.getenv("dubbo.eci.report-as-error"));
 
-    public static final List<Reporter> REPORTERS;
+    public static final List<Reporter> REPORTERS = loadReporters();
 
-    public static final List<String> EXCLUSIONS = 
FileUtils.loadConfigurationFileInResources("exclusions.cfg");
+    public static final List<String> EXCLUSIONS = loadExclusions();
 
-    static {
+    private static List<Reporter> loadReporters() {
         List<String> classNames = 
FileUtils.loadConfigurationFileInResources("reporter-classes.cfg");
-
         List<Reporter> tempReporters = new ArrayList<>();
 
         for (String clsName : classNames) {
@@ -60,6 +61,12 @@ public class ErrorCodeInspectorConfig {
             }
         }
 
-        REPORTERS = Collections.unmodifiableList(tempReporters);
+        return Collections.unmodifiableList(tempReporters);
+    }
+
+    private static List<String> loadExclusions() {
+        List<String> exclusions = 
FileUtils.loadConfigurationFileInResources("exclusions.cfg");
+
+        return exclusions.stream().map(x -> x.replace('\\', 
File.separatorChar)).collect(Collectors.toList());
     }
 }
diff --git 
a/dubbo-error-code-inspector/src/main/java/org/apache/dubbo/errorcode/util/FileUtils.java
 
b/dubbo-error-code-inspector/src/main/java/org/apache/dubbo/errorcode/util/FileUtils.java
index 51db472..a4f0b82 100644
--- 
a/dubbo-error-code-inspector/src/main/java/org/apache/dubbo/errorcode/util/FileUtils.java
+++ 
b/dubbo-error-code-inspector/src/main/java/org/apache/dubbo/errorcode/util/FileUtils.java
@@ -17,6 +17,8 @@
 
 package org.apache.dubbo.errorcode.util;
 
+import org.apache.dubbo.errorcode.config.ErrorCodeInspectorConfig;
+
 import java.io.File;
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -27,6 +29,7 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 import java.util.Scanner;
@@ -138,4 +141,18 @@ public final class FileUtils {
 
         return resourceFilePath;
     }
+
+    public static List<Path> getAllClassFilesInDirectory(Path codeBaseFolder, 
Path moduleFolder) {
+        try (Stream<Path> classFilesStream = Files.walk(moduleFolder)) {
+
+            return classFilesStream
+                    .filter(x -> x.toFile().isFile())
+                    .filter(x -> 
!ErrorCodeInspectorConfig.EXCLUSIONS.contains(codeBaseFolder.relativize(x).toString()))
+                    .collect(Collectors.toList());
+
+        } catch (IOException e) {
+            e.printStackTrace();
+            return Collections.emptyList();
+        }
+    }
 }
diff --git 
a/dubbo-error-code-inspector/src/test/java/org/apache/dubbo/errorcode/util/FileUtilsTest.java
 
b/dubbo-error-code-inspector/src/test/java/org/apache/dubbo/errorcode/util/FileUtilsTest.java
index 50b3ace..084c17a 100644
--- 
a/dubbo-error-code-inspector/src/test/java/org/apache/dubbo/errorcode/util/FileUtilsTest.java
+++ 
b/dubbo-error-code-inspector/src/test/java/org/apache/dubbo/errorcode/util/FileUtilsTest.java
@@ -17,9 +17,15 @@
 
 package org.apache.dubbo.errorcode.util;
 
+import org.apache.dubbo.errorcode.config.ErrorCodeInspectorConfig;
+
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
 /**
  * Tests of FileUtils.
  */
@@ -39,6 +45,22 @@ class FileUtilsTest {
         byte[] magic = new byte[]{(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, 
(byte) 0xBE};
         byte[] actualBytes = new byte[]{bytes[0], bytes[1], bytes[2], 
bytes[3]};
 
-        Assertions.assertArrayEquals(actualBytes, magic);
+        Assertions.assertArrayEquals(magic, actualBytes);
+    }
+
+    @Test
+    void testIgnoranceOfGetAllClassFilesInDirectory() {
+        ErrorCodeInspectorConfig.EXCLUSIONS.add(
+                
"testing-mock-source\\target\\classes\\org\\apache\\dubbo\\errorcode\\mock\\GrandChildClass.class"
+                        .replace('\\', File.separatorChar));
+
+        Path rootOfResources = 
Paths.get(FileUtils.getResourceFilePath("FileCacheStore.jcls")).getParent();
+
+        Path mockCodeBasePath = Paths.get(rootOfResources.toString(), 
"mock-source");
+        Path mockModulePath = Paths.get(mockCodeBasePath.toString(), 
"testing-mock-source");
+        Path fileToIgnore = Paths.get(mockModulePath.toString(), "target", 
"classes",
+                "org", "apache", "dubbo", "errorcode", "mock", 
"GrandChildClass.class");
+
+        
Assertions.assertFalse(FileUtils.getAllClassFilesInDirectory(mockCodeBasePath, 
mockModulePath).contains(fileToIgnore));
     }
 }

Reply via email to