vgosain-psg commented on code in PR #1146:
URL: https://github.com/apache/tomcat/pull/1146#discussion_r4591227320


##########
test/org/apache/tomcat/categories/CategoryScanner.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.tomcat.categories;
+
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.experimental.categories.Category;
+
+/**
+ * Scans compiled test classes for a given JUnit {@link Category} annotation
+ * and prints the matching source file paths as a comma-separated list suitable
+ * for use as an Ant {@code test.name} include pattern.
+ *
+ * <p>Usage: {@code CategoryScanner <category-class-name> <test-classes-dir>}
+ *
+ * <p>Output is written to stdout as a single comma-separated line, e.g.:
+ * {@code org/apache/catalina/core/TestFoo.java,org/apache/coyote/TestBar.java}
+ */
+public class CategoryScanner {
+
+    public static void main(String[] args) throws Exception {
+        if (args.length < 2) {
+            throw new IllegalArgumentException(
+                    "Usage: CategoryScanner <category-class-name> 
<test-classes-dir>");
+        }
+
+        String categoryClassName = args[0];
+        File testClassesDir = new File(args[1]);
+
+        if (!testClassesDir.isDirectory()) {
+            throw new IllegalArgumentException("Not a directory: " + 
testClassesDir);
+        }
+
+        try (URLClassLoader loader = new URLClassLoader(
+                new URL[] { testClassesDir.toURI().toURL() },
+                CategoryScanner.class.getClassLoader())) {
+
+            Class<?> categoryClass = loader.loadClass(categoryClassName);
+            List<String> matches = new ArrayList<>();
+            scanDir(testClassesDir, testClassesDir, categoryClass, loader, 
matches);
+            Collections.sort(matches);
+            System.out.print(String.join(",", matches));

Review Comment:
   Done — scanner throws `IllegalStateException` if `matches` is empty.



##########
test/org/apache/tomcat/categories/CategoryScanner.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.tomcat.categories;
+
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.experimental.categories.Category;
+
+/**
+ * Scans compiled test classes for a given JUnit {@link Category} annotation
+ * and prints the matching source file paths as a comma-separated list suitable
+ * for use as an Ant {@code test.name} include pattern.
+ *
+ * <p>Usage: {@code CategoryScanner <category-class-name> <test-classes-dir>}
+ *
+ * <p>Output is written to stdout as a single comma-separated line, e.g.:
+ * {@code org/apache/catalina/core/TestFoo.java,org/apache/coyote/TestBar.java}
+ */
+public class CategoryScanner {
+
+    public static void main(String[] args) throws Exception {
+        if (args.length < 2) {
+            throw new IllegalArgumentException(
+                    "Usage: CategoryScanner <category-class-name> 
<test-classes-dir>");
+        }
+
+        String categoryClassName = args[0];
+        File testClassesDir = new File(args[1]);
+
+        if (!testClassesDir.isDirectory()) {
+            throw new IllegalArgumentException("Not a directory: " + 
testClassesDir);
+        }
+
+        try (URLClassLoader loader = new URLClassLoader(
+                new URL[] { testClassesDir.toURI().toURL() },
+                CategoryScanner.class.getClassLoader())) {
+
+            Class<?> categoryClass = loader.loadClass(categoryClassName);
+            List<String> matches = new ArrayList<>();
+            scanDir(testClassesDir, testClassesDir, categoryClass, loader, 
matches);
+            Collections.sort(matches);
+            System.out.print(String.join(",", matches));
+        }
+    }
+
+    private static void scanDir(File root, File dir, Class<?> categoryClass,
+            ClassLoader loader, List<String> results) {
+        File[] files = dir.listFiles();
+        if (files == null) {
+            return;
+        }
+        for (File f : files) {
+            if (f.isDirectory()) {
+                scanDir(root, f, categoryClass, loader, results);
+            } else if (f.getName().endsWith(".class") && 
!f.getName().contains("$")) {

Review Comment:
   Done — scanner now filters to files whose name starts with `Test` but not 
`Tester`, skips abstract classes via `Modifier.isAbstract()`, and skips any 
class whose corresponding `.java` source file no longer exists (the source dir 
is passed as a third argument).



##########
BUILDING.txt:
##########
@@ -603,7 +603,48 @@ NOTE: Cobertura is licensed under GPL v2 with parts of it 
being under
 
         test.verbose=false
 
-(7.5) Running httpd integration tests
+(7.5) Running tests by profile
+
+Tomcat provides named test profiles for running curated subsets of tests
+without specifying file patterns manually.
+
+Available profiles:
+
+  smoke        - Core smoke tests covering key subsystems
+  catalina     - All Catalina servlet container tests
+  coyote       - All Coyote protocol/connector tests
+  tribes       - All Tribes clustering tests
+  performance  - Performance benchmark tests (excluded by default)

Review Comment:
   Fixed — removed '(excluded by default)' from the performance line.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to