From 2a2a0fada23f431250138d6ea6ade73345b9b510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20K=C3=A4ppel?= Date: Fri, 25 Mar 2016 17:51:02 +0100 Subject: [PATCH 01/14] Merge from OCPSOFT --- .../annotation/scan/AbstractClassFinder.java | 2 +- .../annotation/scan/WebClassesFinder.java | 23 +++++++++++-------- .../annotation/scan/WebClassesFinderTest.java | 2 -- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/AbstractClassFinder.java b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/AbstractClassFinder.java index 9bc6e8913..45f0aa440 100644 --- a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/AbstractClassFinder.java +++ b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/AbstractClassFinder.java @@ -196,7 +196,7 @@ protected void processClass(String className, InputStream classFileStream, Class try { // request this class from the ClassLoader - Class clazz = Class.forName(className, false, classLoader); + Class clazz = classLoader.loadClass(className); // call handler visitor.visit(clazz); diff --git a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java index 3047f6a9c..69bf5b1b4 100644 --- a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java +++ b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java @@ -24,13 +24,14 @@ import javax.servlet.ServletContext; +import org.ocpsoft.rewrite.annotation.ClassVisitorImpl; import org.ocpsoft.rewrite.annotation.api.ClassVisitor; import org.ocpsoft.rewrite.annotation.spi.ClassFinder; /** * Implementation of {@link ClassFinder} that searches for classes in the /WEB-INF/classes directory of a * web application. Please note that this class is stateful. It should be used only for one call to - * {@link #findClasses(ClassVisitor)}. + * {@link #findClasses(ClassVisitorImpl)}. * * @author Christian Kaltepoth */ @@ -83,7 +84,7 @@ public void findClasses(ClassVisitor visitor) /** * Scan for classes in a single directory. This method will call itself recursively if it finds other directories and - * call {@link #processClass(String, InputStream, ClassVisitor)} when it finds a file ending with ".class" and + * call {@link #processClass(String, InputStream, ClassVisitorImpl) when it finds a file ending with ".class" and * that is accepted by the {@link PackageFilter} * * @param absoluteUrl The absolute URL of the WEB-INF node to scan @@ -140,7 +141,7 @@ protected void processDirectory(URL absoluteUrl, String relativePath, ClassVisit } if (childNodeRelative.endsWith(".class")) { - handleClassEntry(childNodeName, visitor); + handleClassEntry(childNodeUrl, childNodeName, visitor); } } } @@ -148,7 +149,7 @@ protected void processDirectory(URL absoluteUrl, String relativePath, ClassVisit /** * Handles class entry in a WEB-INF. */ - private void handleClassEntry(String entryName, ClassVisitor visitor) + private void handleClassEntry(URL entryUrl, String entryName, ClassVisitor visitor) { // build class name from relative name @@ -169,15 +170,17 @@ private void handleClassEntry(String entryName, ClassVisitor visitor) { /* - * Try to open the .class file. if this isn't possible, we will scan it anyway. + * Try to open the .class file. If an IOException is thrown, we will scan it anyway. */ - classFileStream = servletContext.getResourceAsStream(entryName); - - if (classFileStream == null) + try + { + classFileStream = servletContext.getResourceAsStream(entryName); + } + catch (Exception e) { if (log.isDebugEnabled()) { - log.debug("Could not obtain InputStream for class file: " + entryName); + log.debug("Cound not obtain InputStream for class file: " + entryName, e); } } @@ -207,7 +210,7 @@ private void handleClassEntry(String entryName, ClassVisitor visitor) } /** - * @param path The path + * @param path * @return last node in a a string representation of URL path. For example for "/a/b/c/d/" returns "d/", for * "/a/b/c/d.class" returns "d.class" */ diff --git a/annotations-impl/src/test/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinderTest.java b/annotations-impl/src/test/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinderTest.java index 3aa650d36..a849602bf 100644 --- a/annotations-impl/src/test/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinderTest.java +++ b/annotations-impl/src/test/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinderTest.java @@ -23,13 +23,11 @@ import javax.servlet.ServletContext; -import org.junit.Ignore; import org.junit.Test; import org.mockito.Mockito; import org.ocpsoft.rewrite.annotation.api.ClassVisitor; @SuppressWarnings({ "unchecked", "rawtypes" }) -@Ignore // ignored since we now user Class.forName(name, false, cl) which we cannot mock public class WebClassesFinderTest { From c7ef24a34a94ddc64bb51467c7b294f8470f1837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20K=C3=A4ppel?= Date: Sun, 5 Aug 2018 16:57:12 +0200 Subject: [PATCH 02/14] Spring Boot 2 Project Layout Support --- .../ocpsoft/rewrite/annotation/scan/WebClassesFinder.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java index 69bf5b1b4..36a65c175 100644 --- a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java +++ b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java @@ -64,11 +64,13 @@ public void findClasses(ClassVisitor visitor) { // get the absolute URL of the classes folder URL classesFolderUrl = servletContext.getResource(CLASSES_FOLDER); - + if (classesFolderUrl == null) + classesFolderUrl = Thread.currentThread().getContextClassLoader().getResource(""); + // abort if classes folder is missing if (classesFolderUrl == null) { - log.warn("Cannot find classes folder: " + CLASSES_FOLDER); + log.warn("Cannot find classes folder"); return; } From a21dc70f1be48f0cc8cc79c340000d56cbb5da1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20K=C3=A4ppel?= Date: Wed, 8 Aug 2018 08:19:55 +0200 Subject: [PATCH 03/14] Spring Boot 2 Support --- .../annotation/scan/WebClassesFinder.java | 92 ++++++++++++++++--- 1 file changed, 79 insertions(+), 13 deletions(-) diff --git a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java index 36a65c175..b9ce4d58c 100644 --- a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java +++ b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java @@ -15,12 +15,16 @@ */ package org.ocpsoft.rewrite.annotation.scan; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.JarURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.util.Enumeration; import java.util.LinkedHashSet; import java.util.Set; +import java.util.jar.JarEntry; import javax.servlet.ServletContext; @@ -47,6 +51,10 @@ public class WebClassesFinder extends AbstractClassFinder * Manage a set of classes already processed */ private final Set processedClasses = new LinkedHashSet(); + + public static final String CLASS_EXTENSION = ".class"; + public static final int CLASS_EXTENSION_LENGTH = CLASS_EXTENSION.length(); + public static final String META_INF = "META-INF"; /** * Initialization @@ -56,7 +64,7 @@ public WebClassesFinder(ServletContext servletContext, ClassLoader classLoader, { super(servletContext, classLoader, packageFilter, byteCodeFilter); } - + @Override public void findClasses(ClassVisitor visitor) { @@ -64,27 +72,85 @@ public void findClasses(ClassVisitor visitor) { // get the absolute URL of the classes folder URL classesFolderUrl = servletContext.getResource(CLASSES_FOLDER); - if (classesFolderUrl == null) - classesFolderUrl = Thread.currentThread().getContextClassLoader().getResource(""); + if (classesFolderUrl != null) { + // call recursive directory processing method + processDirectory(classesFolderUrl, CLASSES_FOLDER, visitor); + return; + } + classesFolderUrl = Thread.currentThread().getContextClassLoader().getResource(""); + if (classesFolderUrl != null) { + processUrl(visitor, classesFolderUrl); + return; + } // abort if classes folder is missing - if (classesFolderUrl == null) - { - log.warn("Cannot find classes folder"); - return; - } - - // call recursive directory processing method - processDirectory(classesFolderUrl, CLASSES_FOLDER, visitor); - + log.warn("Cannot find classes folder"); } catch (MalformedURLException e) { throw new IllegalStateException("Invalid URL: " + e.getMessage(), e); } } + + public void processUrl(ClassVisitor visitor, URL url) { + try { + if ("file".equals(url.getProtocol())) { + File file = new File(url.getFile()); + scanDir(visitor, file, file.getAbsolutePath().length() + 1); + } else if ("jar".equals(url.getProtocol())) { + JarURLConnection connection = (JarURLConnection)url.openConnection(); + scanJar(visitor, connection); + } + } catch (Exception exception) { + throw new IllegalArgumentException("Error scanning url '" + url.toExternalForm() + "'", exception); + } + } + private void scanDir(ClassVisitor visitor, File file, int prefix) throws Exception { + if (file.isDirectory()) { + for (File child : file.listFiles()) { + scanDir(visitor, child, prefix); + } + } else if (file.getName().endsWith(CLASS_EXTENSION)) { + String className = getClassName(file.getAbsolutePath().substring(prefix)); + handleClassUrl(visitor, file.toURI().toURL(), className); + } + } + private void scanJar(ClassVisitor visitor, JarURLConnection connection) throws Exception { + for (Enumeration enumeration = connection.getJarFile().entries(); enumeration.hasMoreElements();) { + JarEntry entry = enumeration.nextElement(); + if (!entry.isDirectory() && !entry.getName().startsWith(META_INF) && + entry.getName().endsWith(CLASS_EXTENSION)) { + String className = getClassName(entry.getName()); + URL url = new URL(connection.getURL(), entry.getName()); + handleClassUrl(visitor, url, className); + } + } + } + private void handleClassUrl(ClassVisitor visitor, URL url, String className) { + if (mustProcessClass(className) && !processedClasses.contains(className)) { + processedClasses.add(className); + InputStream classFileStream = null; + try { + try { + classFileStream = url.openStream(); + } catch (Exception e) { + if (log.isDebugEnabled()) + log.debug("Cound not obtain InputStream for class: " + className, e); + } + processClass(className, classFileStream, visitor); + } finally { + try { + if (classFileStream != null) + classFileStream.close(); + } catch (IOException e) { + if (log.isDebugEnabled()) + log.debug("Failed to close input stream: " + e.getMessage()); + } + } + } + } - /** +/** * Scan for classes in a single directory. This method will call itself recursively if it finds other directories and * call {@link #processClass(String, InputStream, ClassVisitorImpl) when it finds a file ending with ".class" and * that is accepted by the {@link PackageFilter} From 6c2ad0eddda6d56f6a2e717ef1bf39a6500c3559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20K=C3=A4ppel?= Date: Wed, 8 Aug 2018 08:19:55 +0200 Subject: [PATCH 04/14] Spring Boot 2 Support --- .../annotation/scan/AbstractClassFinder.java | 2 +- .../annotation/scan/WebClassesFinder.java | 92 ++++++++++++++++--- 2 files changed, 80 insertions(+), 14 deletions(-) diff --git a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/AbstractClassFinder.java b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/AbstractClassFinder.java index 45f0aa440..07d2a5752 100644 --- a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/AbstractClassFinder.java +++ b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/AbstractClassFinder.java @@ -111,7 +111,7 @@ protected static String getClassName(String filename) String relativePath = filename.substring(0, endIndex); // replace / by . to create FQCN - return relativePath.replace('/', '.'); + return relativePath.replace('/', '.').replace('\\', '.'); } /** diff --git a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java index 36a65c175..b9ce4d58c 100644 --- a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java +++ b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java @@ -15,12 +15,16 @@ */ package org.ocpsoft.rewrite.annotation.scan; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.JarURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.util.Enumeration; import java.util.LinkedHashSet; import java.util.Set; +import java.util.jar.JarEntry; import javax.servlet.ServletContext; @@ -47,6 +51,10 @@ public class WebClassesFinder extends AbstractClassFinder * Manage a set of classes already processed */ private final Set processedClasses = new LinkedHashSet(); + + public static final String CLASS_EXTENSION = ".class"; + public static final int CLASS_EXTENSION_LENGTH = CLASS_EXTENSION.length(); + public static final String META_INF = "META-INF"; /** * Initialization @@ -56,7 +64,7 @@ public WebClassesFinder(ServletContext servletContext, ClassLoader classLoader, { super(servletContext, classLoader, packageFilter, byteCodeFilter); } - + @Override public void findClasses(ClassVisitor visitor) { @@ -64,27 +72,85 @@ public void findClasses(ClassVisitor visitor) { // get the absolute URL of the classes folder URL classesFolderUrl = servletContext.getResource(CLASSES_FOLDER); - if (classesFolderUrl == null) - classesFolderUrl = Thread.currentThread().getContextClassLoader().getResource(""); + if (classesFolderUrl != null) { + // call recursive directory processing method + processDirectory(classesFolderUrl, CLASSES_FOLDER, visitor); + return; + } + classesFolderUrl = Thread.currentThread().getContextClassLoader().getResource(""); + if (classesFolderUrl != null) { + processUrl(visitor, classesFolderUrl); + return; + } // abort if classes folder is missing - if (classesFolderUrl == null) - { - log.warn("Cannot find classes folder"); - return; - } - - // call recursive directory processing method - processDirectory(classesFolderUrl, CLASSES_FOLDER, visitor); - + log.warn("Cannot find classes folder"); } catch (MalformedURLException e) { throw new IllegalStateException("Invalid URL: " + e.getMessage(), e); } } + + public void processUrl(ClassVisitor visitor, URL url) { + try { + if ("file".equals(url.getProtocol())) { + File file = new File(url.getFile()); + scanDir(visitor, file, file.getAbsolutePath().length() + 1); + } else if ("jar".equals(url.getProtocol())) { + JarURLConnection connection = (JarURLConnection)url.openConnection(); + scanJar(visitor, connection); + } + } catch (Exception exception) { + throw new IllegalArgumentException("Error scanning url '" + url.toExternalForm() + "'", exception); + } + } + private void scanDir(ClassVisitor visitor, File file, int prefix) throws Exception { + if (file.isDirectory()) { + for (File child : file.listFiles()) { + scanDir(visitor, child, prefix); + } + } else if (file.getName().endsWith(CLASS_EXTENSION)) { + String className = getClassName(file.getAbsolutePath().substring(prefix)); + handleClassUrl(visitor, file.toURI().toURL(), className); + } + } + private void scanJar(ClassVisitor visitor, JarURLConnection connection) throws Exception { + for (Enumeration enumeration = connection.getJarFile().entries(); enumeration.hasMoreElements();) { + JarEntry entry = enumeration.nextElement(); + if (!entry.isDirectory() && !entry.getName().startsWith(META_INF) && + entry.getName().endsWith(CLASS_EXTENSION)) { + String className = getClassName(entry.getName()); + URL url = new URL(connection.getURL(), entry.getName()); + handleClassUrl(visitor, url, className); + } + } + } + private void handleClassUrl(ClassVisitor visitor, URL url, String className) { + if (mustProcessClass(className) && !processedClasses.contains(className)) { + processedClasses.add(className); + InputStream classFileStream = null; + try { + try { + classFileStream = url.openStream(); + } catch (Exception e) { + if (log.isDebugEnabled()) + log.debug("Cound not obtain InputStream for class: " + className, e); + } + processClass(className, classFileStream, visitor); + } finally { + try { + if (classFileStream != null) + classFileStream.close(); + } catch (IOException e) { + if (log.isDebugEnabled()) + log.debug("Failed to close input stream: " + e.getMessage()); + } + } + } + } - /** +/** * Scan for classes in a single directory. This method will call itself recursively if it finds other directories and * call {@link #processClass(String, InputStream, ClassVisitorImpl) when it finds a file ending with ".class" and * that is accepted by the {@link PackageFilter} From 847915f95608fb1a1b0d4fd1b67522b11a80da41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20K=C3=A4ppel?= Date: Wed, 8 Aug 2018 10:25:41 +0200 Subject: [PATCH 05/14] windows class name fix --- .../ocpsoft/rewrite/annotation/scan/AbstractClassFinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/AbstractClassFinder.java b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/AbstractClassFinder.java index 45f0aa440..07d2a5752 100644 --- a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/AbstractClassFinder.java +++ b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/AbstractClassFinder.java @@ -111,7 +111,7 @@ protected static String getClassName(String filename) String relativePath = filename.substring(0, endIndex); // replace / by . to create FQCN - return relativePath.replace('/', '.'); + return relativePath.replace('/', '.').replace('\\', '.'); } /** From fe662dcc99eede77325b41f3f23ba1d5893d9ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20K=C3=A4ppel?= Date: Fri, 23 Nov 2018 16:04:35 +0100 Subject: [PATCH 06/14] comment out documentation --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9c880c74f..d6ea5f85a 100644 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,7 @@ showcase distribution examples - documentation + From f2313c860c51658bfc2786557cafe64a802e83fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20K=C3=A4ppel?= Date: Thu, 7 Mar 2019 10:29:23 +0100 Subject: [PATCH 07/14] Java 9+ fix --- annotations-impl/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/annotations-impl/pom.xml b/annotations-impl/pom.xml index 18a266ceb..f65cf94e4 100644 --- a/annotations-impl/pom.xml +++ b/annotations-impl/pom.xml @@ -39,5 +39,11 @@ rewrite-config-servlet test + + + javax.annotation + javax.annotation-api + 1.3.1 + From c5d1f02ae011fd9129efafa937f2c89172f5f1a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20K=C3=A4ppel?= Date: Wed, 15 May 2019 15:28:12 +0200 Subject: [PATCH 08/14] log fix --- .../org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java index b9ce4d58c..6952f1788 100644 --- a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java +++ b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java @@ -248,7 +248,7 @@ private void handleClassEntry(URL entryUrl, String entryName, ClassVisitor visit { if (log.isDebugEnabled()) { - log.debug("Cound not obtain InputStream for class file: " + entryName, e); + log.debug("Could not obtain InputStream for class file: " + entryName, e); } } From eb8a2cf4d083e39cf2f24a7fedb21384c3219cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20K=C3=A4ppel?= Date: Thu, 30 Jul 2020 23:10:45 +0200 Subject: [PATCH 09/14] Handle packaged JIB images --- .../rewrite/annotation/scan/WebClassesFinder.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java index 6952f1788..93ee28865 100644 --- a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java +++ b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java @@ -77,7 +77,8 @@ public void findClasses(ClassVisitor visitor) processDirectory(classesFolderUrl, CLASSES_FOLDER, visitor); return; } - classesFolderUrl = Thread.currentThread().getContextClassLoader().getResource(""); + String main = System.getProperty("sun.java.command"); + classesFolderUrl = Class.forName(main).getProtectionDomain().getCodeSource().getLocation(); if (classesFolderUrl != null) { processUrl(visitor, classesFolderUrl); return; @@ -86,7 +87,7 @@ public void findClasses(ClassVisitor visitor) // abort if classes folder is missing log.warn("Cannot find classes folder"); } - catch (MalformedURLException e) + catch (Exception e) { throw new IllegalStateException("Invalid URL: " + e.getMessage(), e); } @@ -94,10 +95,12 @@ public void findClasses(ClassVisitor visitor) public void processUrl(ClassVisitor visitor, URL url) { try { + if ("file".equals(url.getProtocol()) && url.getPath().endsWith(".jar")) + url = new URL("jar:" + url.toExternalForm() + "!/"); if ("file".equals(url.getProtocol())) { File file = new File(url.getFile()); scanDir(visitor, file, file.getAbsolutePath().length() + 1); - } else if ("jar".equals(url.getProtocol())) { + } else if ("jar".equals(url.getProtocol()) || url.getPath().endsWith(".jar")) { JarURLConnection connection = (JarURLConnection)url.openConnection(); scanJar(visitor, connection); } From 228f0e0786788debbd40f4bbf686944641846b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20K=C3=A4ppel?= Date: Thu, 30 Jul 2020 23:10:45 +0200 Subject: [PATCH 10/14] Handle packaged JIB images --- .../rewrite/annotation/scan/WebClassesFinder.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java index 6952f1788..99c603c49 100644 --- a/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java +++ b/annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/WebClassesFinder.java @@ -77,7 +77,14 @@ public void findClasses(ClassVisitor visitor) processDirectory(classesFolderUrl, CLASSES_FOLDER, visitor); return; } - classesFolderUrl = Thread.currentThread().getContextClassLoader().getResource(""); + String main = System.getProperty("sun.java.command"); + if (main.endsWith(".jar")) { + classesFolderUrl = Thread.currentThread().getContextClassLoader().getResource(""); + } else { + classesFolderUrl = Class.forName(main).getProtectionDomain().getCodeSource().getLocation(); + if ("file".equals(classesFolderUrl.getProtocol()) && classesFolderUrl.getPath().endsWith(".jar")) + classesFolderUrl = new URL("jar:" + classesFolderUrl.toExternalForm() + "!/"); + } if (classesFolderUrl != null) { processUrl(visitor, classesFolderUrl); return; @@ -86,7 +93,7 @@ public void findClasses(ClassVisitor visitor) // abort if classes folder is missing log.warn("Cannot find classes folder"); } - catch (MalformedURLException e) + catch (Exception e) { throw new IllegalStateException("Invalid URL: " + e.getMessage(), e); } @@ -97,7 +104,7 @@ public void processUrl(ClassVisitor visitor, URL url) { if ("file".equals(url.getProtocol())) { File file = new File(url.getFile()); scanDir(visitor, file, file.getAbsolutePath().length() + 1); - } else if ("jar".equals(url.getProtocol())) { + } else if ("jar".equals(url.getProtocol()) || url.getPath().endsWith(".jar")) { JarURLConnection connection = (JarURLConnection)url.openConnection(); scanJar(visitor, connection); } From 3e9d16443d005b6a6fa6fe26c7c5b9f7de9732ff Mon Sep 17 00:00:00 2001 From: Intersult Date: Fri, 29 Oct 2021 14:50:58 +0200 Subject: [PATCH 11/14] source version 7 --- pom.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pom.xml b/pom.xml index d6ea5f85a..b5db6ab5a 100644 --- a/pom.xml +++ b/pom.xml @@ -105,6 +105,15 @@ + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + 7 + 7 + + org.apache.maven.plugins maven-surefire-plugin From 36050f69a02de9b422cc6e847cdc867756d70286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20K=C3=A4ppel?= Date: Fri, 29 Oct 2021 15:30:06 +0200 Subject: [PATCH 12/14] remove showcase --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b5db6ab5a..77795e503 100644 --- a/pom.xml +++ b/pom.xml @@ -75,7 +75,7 @@ integration-spring security-integration-shiro rewrite-servlet - showcase + distribution examples From 9256fb7e85e69222ecc7ed258a2294731178b105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20K=C3=A4ppel?= Date: Fri, 29 Oct 2021 15:33:39 +0200 Subject: [PATCH 13/14] remove examples --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 77795e503..15518d38d 100644 --- a/pom.xml +++ b/pom.xml @@ -77,7 +77,7 @@ rewrite-servlet distribution - examples + From 459b6a84ebb06404719d17127c3baeb23f3fa626 Mon Sep 17 00:00:00 2001 From: Dieter Date: Sat, 12 Aug 2023 18:12:39 +0200 Subject: [PATCH 14/14] JDK compatibility fix --- .gitignore | 3 +++ pom.xml | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5afc1da53..4b4f3cdad 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ bin/ .gitignore.swp .faces-config.xml.jsfdia docs/reference/src/main/docbook/en-US/version_info.xml +/config-prettyfaces/dependency-reduced-pom.xml +/config-tuckey/dependency-reduced-pom.xml +/transform-minify/dependency-reduced-pom.xml diff --git a/pom.xml b/pom.xml index 15518d38d..31e69b828 100644 --- a/pom.xml +++ b/pom.xml @@ -110,8 +110,8 @@ maven-compiler-plugin 3.7.0 - 7 - 7 + 8 + 8