From 31ef68f132269c22745616528f8a40babf943131 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Fri, 3 Nov 2023 11:11:25 +0100 Subject: [PATCH 01/39] progress --- .../PathBasedAnalysisInputLocation.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java index 36ba5d3b30f..4a945b0ca11 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java @@ -81,6 +81,10 @@ public abstract class PathBasedAnalysisInputLocation protected PathBasedAnalysisInputLocation(Path path, SourceType srcType) { this.path = path; this.sourceType = srcType; + + if (!Files.exists(path)) { + throw new IllegalArgumentException("The provided path does not exist."); + } } @Nullable @@ -199,11 +203,8 @@ protected Optional> getSingleClass( private static class ClassFileBasedAnalysisInputLocation extends PathBasedAnalysisInputLocation { public ClassFileBasedAnalysisInputLocation( - @Nonnull Path classPath, @Nonnull SourceType srcType) { - super(classPath, srcType); - if (!Files.exists(classPath)) { - throw new IllegalArgumentException("The provided .class file does not exist."); - } + @Nonnull Path classFilePath, @Nonnull SourceType srcType) { + super(classFilePath, srcType); } @Override @@ -789,4 +790,15 @@ public List retrieveServletClasses(String extractedWARPath) { return classesInXML; } } + + private static class DefaultRTJarAnalysisInputLocation extends ArchiveBasedAnalysisInputLocation { + + private DefaultRTJarAnalysisInputLocation() { + this(SourceType.Library); + } + + private DefaultRTJarAnalysisInputLocation(@Nullable SourceType srcType) { + super(Paths.get(System.getProperty("java.home") + "/lib/rt.jar"), srcType); + } + } } From 22e9691c54e2f768540cfd1efad5724576162a52 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Fri, 3 Nov 2023 11:16:15 +0100 Subject: [PATCH 02/39] restructure if-else tree --- .../PathBasedAnalysisInputLocation.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java index 4a945b0ca11..fe5791d5521 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java @@ -100,14 +100,21 @@ public static PathBasedAnalysisInputLocation create( if (Files.isDirectory(path)) { inputLocation = new DirectoryBasedAnalysisInputLocation(path, srcType); } else if (PathUtils.isArchive(path)) { - if (PathUtils.hasExtension(path, FileType.WAR)) { - inputLocation = new WarArchiveAnalysisInputLocation(path, srcType); - } else if (isMultiReleaseJar(path)) { // check if mainfest contains multi release flag - inputLocation = new MultiReleaseJarAnalysisInputLocation(path, srcType); + if (PathUtils.hasExtension(path, FileType.JAR)) { + if (isMultiReleaseJar(path)) { + inputLocation = new MultiReleaseJarAnalysisInputLocation(path, srcType); + } else { + inputLocation = new ArchiveBasedAnalysisInputLocation(path, srcType); + } } else if (PathUtils.hasExtension(path, FileType.APK)) { inputLocation = new ApkAnalysisInputLocation(path, srcType); + } else if (PathUtils.hasExtension(path, FileType.WAR)) { + inputLocation = new WarArchiveAnalysisInputLocation(path, srcType); } else { - inputLocation = new ArchiveBasedAnalysisInputLocation(path, srcType); + throw new IllegalArgumentException( + "Path '" + + path.toAbsolutePath() + + "' has to be pointing to the root of a class container, e.g. directory, jar, zip, apk, war etc."); } } else if (PathUtils.hasExtension(path, FileType.CLASS)) { inputLocation = new ClassFileBasedAnalysisInputLocation(path, srcType); From 5fb0649381a387ceddd56aaf4aac3fea3a7d6be2 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Fri, 3 Nov 2023 11:21:57 +0100 Subject: [PATCH 03/39] path check for JavaSourcePathAnalysisInputLocation --- .../JavaSourcePathAnalysisInputLocation.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/inputlocation/JavaSourcePathAnalysisInputLocation.java b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/inputlocation/JavaSourcePathAnalysisInputLocation.java index 7fd91ca9cfd..9d6bc837b90 100644 --- a/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/inputlocation/JavaSourcePathAnalysisInputLocation.java +++ b/sootup.java.sourcecode/src/main/java/sootup/java/sourcecode/inputlocation/JavaSourcePathAnalysisInputLocation.java @@ -21,6 +21,7 @@ * #L% */ +import java.nio.file.Files; import java.nio.file.Paths; import java.util.*; import javax.annotation.Nonnull; @@ -84,6 +85,13 @@ public JavaSourcePathAnalysisInputLocation( this.sourcePaths = sourcePaths; this.exclusionFilePath = exclusionFilePath; this.classProvider = new WalaJavaClassProvider(sourcePaths, exclusionFilePath); + + final Optional any = + sourcePaths.stream().filter(path -> !Files.exists(Paths.get(path))).findAny(); + any.ifPresent( + s -> { + throw new IllegalArgumentException("The provided path " + any.get() + " does not exist."); + }); } /** From 18fa111e2867c6cca09ee435db913124b3eca034 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Fri, 3 Nov 2023 12:19:16 +0100 Subject: [PATCH 04/39] propagate SourceType into ModuleFinder and where it would flow from there --- .../JavaModulePathAnalysisInputLocation.java | 2 +- .../bytecode/inputlocation/ModuleFinder.java | 13 ++++++++++--- ...rtFileSystemAnalysisInputLocationTest.java | 10 ++++++++-- .../inputlocation/ModuleFinderTest.java | 19 +++++++++++++++++-- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaModulePathAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaModulePathAnalysisInputLocation.java index fe55c72d6f5..2c1a672ef84 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaModulePathAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaModulePathAnalysisInputLocation.java @@ -87,7 +87,7 @@ public JavaModulePathAnalysisInputLocation( public JavaModulePathAnalysisInputLocation( @Nonnull String modulePath, @Nonnull FileSystem fileSystem, @Nonnull SourceType sourcetype) { this.sourcetype = sourcetype; - moduleFinder = new ModuleFinder(modulePath, fileSystem); + moduleFinder = new ModuleFinder(modulePath, fileSystem, sourcetype); } @Nonnull diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/ModuleFinder.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/ModuleFinder.java index ce7eadecae0..dcb11c46a35 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/ModuleFinder.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/ModuleFinder.java @@ -65,7 +65,7 @@ public class ModuleFinder { private int next = 0; @Nonnull private final List modulePathEntries; - private SourceType sourceType = null; // FIXME ! + private final SourceType sourceType; public boolean hasMoreToResolve() { return next < modulePathEntries.size(); @@ -75,8 +75,11 @@ public boolean hasMoreToResolve() { * Helper Class to discover modules in a given module path. * * @param modulePath the module path + * @param sourceType */ - public ModuleFinder(@Nonnull String modulePath, @Nonnull FileSystem fileSystem) { + public ModuleFinder( + @Nonnull String modulePath, @Nonnull FileSystem fileSystem, @Nonnull SourceType sourceType) { + this.sourceType = sourceType; this.modulePathEntries = JavaClassPathAnalysisInputLocation.explode(modulePath, fileSystem) .collect(Collectors.toList()); @@ -92,8 +95,12 @@ public ModuleFinder(@Nonnull String modulePath, @Nonnull FileSystem fileSystem) } } + public ModuleFinder(@Nonnull String modulePath, @Nonnull SourceType sourceType) { + this(modulePath, FileSystems.getDefault(), sourceType); + } + public ModuleFinder(@Nonnull String modulePath) { - this(modulePath, FileSystems.getDefault()); + this(modulePath, FileSystems.getDefault(), SourceType.Application); } @Nonnull diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocationTest.java index e6344ced91e..868f28e0926 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocationTest.java @@ -56,11 +56,17 @@ public void getClassSources() { final ClassType sig2 = JavaModuleIdentifierFactory.getInstance().getClassType("System", "java.lang", "java.base"); + final JavaView view = project.createView(); final Collection> classSources = - inputLocation.getClassSources(project.createView()); - assertTrue(classSources.size() > 26000); + inputLocation.getClassSources(view); + assertTrue( + classSources.size() + > 20000); // not precise as this amount can differ depending on the included runtime + // library assertTrue(classSources.stream().anyMatch(cs -> cs.getClassType().equals(sig1))); + assertTrue(view.getClass(sig1).isPresent()); assertTrue(classSources.stream().anyMatch(cs -> cs.getClassType().equals(sig2))); + assertTrue(view.getClass(sig2).isPresent()); } @Test diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/ModuleFinderTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/ModuleFinderTest.java index f2a845a03ee..9e93e56379a 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/ModuleFinderTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/ModuleFinderTest.java @@ -17,7 +17,22 @@ public class ModuleFinderTest extends AnalysisInputLocationTest { @Test - public void discoverModuleByName() { + public void discoverJarModuleByName() { + ModuleFinder moduleFinder = new ModuleFinder(jar.toString()); + AnalysisInputLocation inputLocation = + moduleFinder.getModule(JavaModuleIdentifierFactory.getModuleSignature("MiniApp")); + assertTrue(inputLocation instanceof PathBasedAnalysisInputLocation); + } + + @Test + public void discoverJarModuleInAllModules() { + ModuleFinder moduleFinder = new ModuleFinder(jar.toString()); + Collection modules = moduleFinder.getAllModules(); + assertTrue(modules.contains(JavaModuleIdentifierFactory.getModuleSignature("MiniApp"))); + } + + @Test + public void discoverWarModuleByName() { ModuleFinder moduleFinder = new ModuleFinder(war.toString()); AnalysisInputLocation inputLocation = moduleFinder.getModule(JavaModuleIdentifierFactory.getModuleSignature("dummyWarApp")); @@ -25,7 +40,7 @@ public void discoverModuleByName() { } @Test - public void discoverModuleInAllModules() { + public void discoverWarModuleInAllModules() { ModuleFinder moduleFinder = new ModuleFinder(war.toString()); Collection modules = moduleFinder.getAllModules(); assertTrue(modules.contains(JavaModuleIdentifierFactory.getModuleSignature("dummyWarApp"))); From ce7cd389de7ff731379c9676a125fe130044a74f Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Fri, 3 Nov 2023 13:05:27 +0100 Subject: [PATCH 05/39] fix warFile path --- .../PathBasedAnalysisInputLocation.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java index fe5791d5521..4c2c7a1e4aa 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java @@ -109,7 +109,11 @@ public static PathBasedAnalysisInputLocation create( } else if (PathUtils.hasExtension(path, FileType.APK)) { inputLocation = new ApkAnalysisInputLocation(path, srcType); } else if (PathUtils.hasExtension(path, FileType.WAR)) { - inputLocation = new WarArchiveAnalysisInputLocation(path, srcType); + try { + inputLocation = new WarArchiveAnalysisInputLocation(path, srcType); + } catch (IOException e) { + throw new RuntimeException(e); + } } else { throw new IllegalArgumentException( "Path '" @@ -616,15 +620,18 @@ private static final class WarArchiveAnalysisInputLocation public static int maxAllowedBytesToExtract = 1024 * 1024 * 500; // limit of extracted file size to protect against archive bombs - private WarArchiveAnalysisInputLocation(@Nonnull Path warPath, @Nullable SourceType srcType) { + private WarArchiveAnalysisInputLocation(@Nonnull Path warPath, @Nullable SourceType srcType) + throws IOException { super( - Paths.get( - System.getProperty("java.io.tmpdir") - + File.separator - + "sootOutput" - + "-war" - + warPath.hashCode() - + "/"), + Files.createDirectory( + Paths.get( + System.getProperty("java.io.tmpdir") + + File.separator + + "sootOutput" + + "-war" + + warPath.hashCode() + + "/")) + .toAbsolutePath(), srcType); extractWarFile(warPath, path); From 10f26bae49888b1a8c4c529c11cc856496a6be15 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Fri, 3 Nov 2023 13:58:22 +0100 Subject: [PATCH 06/39] revert / fix already existing temp dir --- .../PathBasedAnalysisInputLocation.java | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java index 4c2c7a1e4aa..fe5791d5521 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java @@ -109,11 +109,7 @@ public static PathBasedAnalysisInputLocation create( } else if (PathUtils.hasExtension(path, FileType.APK)) { inputLocation = new ApkAnalysisInputLocation(path, srcType); } else if (PathUtils.hasExtension(path, FileType.WAR)) { - try { - inputLocation = new WarArchiveAnalysisInputLocation(path, srcType); - } catch (IOException e) { - throw new RuntimeException(e); - } + inputLocation = new WarArchiveAnalysisInputLocation(path, srcType); } else { throw new IllegalArgumentException( "Path '" @@ -620,18 +616,15 @@ private static final class WarArchiveAnalysisInputLocation public static int maxAllowedBytesToExtract = 1024 * 1024 * 500; // limit of extracted file size to protect against archive bombs - private WarArchiveAnalysisInputLocation(@Nonnull Path warPath, @Nullable SourceType srcType) - throws IOException { + private WarArchiveAnalysisInputLocation(@Nonnull Path warPath, @Nullable SourceType srcType) { super( - Files.createDirectory( - Paths.get( - System.getProperty("java.io.tmpdir") - + File.separator - + "sootOutput" - + "-war" - + warPath.hashCode() - + "/")) - .toAbsolutePath(), + Paths.get( + System.getProperty("java.io.tmpdir") + + File.separator + + "sootOutput" + + "-war" + + warPath.hashCode() + + "/"), srcType); extractWarFile(warPath, path); From 7fdba82585ee55a800944345ecf8ebebc25fb4d8 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Fri, 3 Nov 2023 14:36:33 +0100 Subject: [PATCH 07/39] add recurring helper methods to MethodSubSignature --- .../core/signatures/MethodSubSignature.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sootup.core/src/main/java/sootup/core/signatures/MethodSubSignature.java b/sootup.core/src/main/java/sootup/core/signatures/MethodSubSignature.java index 6944f50bea2..f1455142113 100644 --- a/sootup.core/src/main/java/sootup/core/signatures/MethodSubSignature.java +++ b/sootup.core/src/main/java/sootup/core/signatures/MethodSubSignature.java @@ -134,4 +134,22 @@ public void toString(StmtPrinter printer) { printer.literal(")"); } + + boolean isMainSignature() { + if (getName().equals("main")) { + if (getParameterTypes().size() == 1) { + // FIXME: handle modules with 'java.base' in the signature as well + return getParameterTypes().get(0).toString().equals("java.lang.String[]"); + } + } + return false; + } + + boolean isStaticInitializerSignature() { + return getName().equals(""); + } + + boolean isConstructor() { + return getName().equals(""); + } } From 5f014995844713d346a9e999e41558b34731c4bf Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Fri, 3 Nov 2023 14:37:11 +0100 Subject: [PATCH 08/39] add more info to exception --- .../bytecode/inputlocation/PathBasedAnalysisInputLocation.java | 2 +- .../inputlocation/JrtFileSystemAnalysisInputLocationTest.java | 2 +- .../sootup/java/bytecode/interceptors/LocalSplitterTest.java | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java index fe5791d5521..b820175ae52 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java @@ -83,7 +83,7 @@ protected PathBasedAnalysisInputLocation(Path path, SourceType srcType) { this.sourceType = srcType; if (!Files.exists(path)) { - throw new IllegalArgumentException("The provided path does not exist."); + throw new IllegalArgumentException("The provided path '" + path + "' does not exist."); } } diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocationTest.java index 868f28e0926..5c96cabc826 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/JrtFileSystemAnalysisInputLocationTest.java @@ -62,7 +62,7 @@ public void getClassSources() { assertTrue( classSources.size() > 20000); // not precise as this amount can differ depending on the included runtime - // library + // library assertTrue(classSources.stream().anyMatch(cs -> cs.getClassType().equals(sig1))); assertTrue(view.getClass(sig1).isPresent()); assertTrue(classSources.stream().anyMatch(cs -> cs.getClassType().equals(sig2))); diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/LocalSplitterTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/LocalSplitterTest.java index baee876f4e3..54e2b956ecb 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/LocalSplitterTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/LocalSplitterTest.java @@ -560,8 +560,6 @@ private Body.BodyBuilder createTrapBody() { graph.setStartingStmt(startingStmt); - System.out.println(graph); - return builder; } From c259fe007d0fddd1c51fe20c3e8547bd7507301f Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Mon, 6 Nov 2023 17:09:12 +0100 Subject: [PATCH 09/39] doc --- .../core/inputlocation/AnalysisInputLocation.java | 2 +- .../inputlocation/PathBasedAnalysisInputLocation.java | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/inputlocation/AnalysisInputLocation.java b/sootup.core/src/main/java/sootup/core/inputlocation/AnalysisInputLocation.java index 8c66380901f..b4de840f5ce 100644 --- a/sootup.core/src/main/java/sootup/core/inputlocation/AnalysisInputLocation.java +++ b/sootup.core/src/main/java/sootup/core/inputlocation/AnalysisInputLocation.java @@ -46,7 +46,7 @@ * @author Ben Hermann * @author Linghui Luo */ -public interface AnalysisInputLocation { +public interface AnalysisInputLocation> { /** * Create or find a class source for a given type. * diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java index b820175ae52..ad5e54b3085 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java @@ -78,7 +78,7 @@ public abstract class PathBasedAnalysisInputLocation private final SourceType sourceType; protected Path path; - protected PathBasedAnalysisInputLocation(Path path, SourceType srcType) { + protected PathBasedAnalysisInputLocation(@Nonnull Path path, @Nonnull SourceType srcType) { this.path = path; this.sourceType = srcType; @@ -576,7 +576,7 @@ private static class ArchiveBasedAnalysisInputLocation extends PathBasedAnalysis } })); - private ArchiveBasedAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType srcType) { + private ArchiveBasedAnalysisInputLocation(@Nonnull Path path, @Nonnull SourceType srcType) { super(path, srcType); } @@ -798,13 +798,18 @@ public List retrieveServletClasses(String extractedWARPath) { } } + /** + * Refers to the rt.jar from <=Java8 as an AnalysisInputLocation requires: JAVA_HOME to be set and + * expects the jar in the "lib/" subdirectory. If you need to include the rt.jar from a custom + * Location please make use of JavaClassPathAnalysisInputLocation. + */ private static class DefaultRTJarAnalysisInputLocation extends ArchiveBasedAnalysisInputLocation { private DefaultRTJarAnalysisInputLocation() { this(SourceType.Library); } - private DefaultRTJarAnalysisInputLocation(@Nullable SourceType srcType) { + private DefaultRTJarAnalysisInputLocation(@Nonnull SourceType srcType) { super(Paths.get(System.getProperty("java.home") + "/lib/rt.jar"), srcType); } } From 944e345941c775cf4847256d7ac0879edf16e276 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 9 Nov 2023 16:18:30 +0100 Subject: [PATCH 10/39] fix creating temp dir for warfiles --- .../JavaClassPathAnalysisInputLocation.java | 15 ++++------- .../PathBasedAnalysisInputLocation.java | 27 +++++++++---------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaClassPathAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaClassPathAnalysisInputLocation.java index f84ca90d9e7..fc1e86f43da 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaClassPathAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaClassPathAnalysisInputLocation.java @@ -80,12 +80,12 @@ public JavaClassPathAnalysisInputLocation( @Nonnull String classPath, @Nonnull SourceType srcType) { this.srcType = srcType; if (classPath.length() <= 0) { - throw new IllegalStateException("Empty class path given"); + throw new IllegalArgumentException("Empty class path given"); } cpEntries = explodeClassPath(classPath); if (cpEntries.isEmpty()) { - throw new IllegalStateException("Empty class path is given."); + throw new IllegalArgumentException("Empty class path is given."); } } @@ -213,14 +213,9 @@ private List> explodeClassPath(@Nonnull Str */ private List> explodeClassPath( @Nonnull String jarPath, @Nonnull FileSystem fileSystem) { - try { - return explode(jarPath, fileSystem) - .flatMap(cp -> StreamUtils.optionalToStream(inputLocationForPath(cp))) - .collect(Collectors.toList()); - - } catch (IllegalArgumentException e) { - throw new IllegalStateException("Malformed class path given: " + jarPath, e); - } + return explode(jarPath, fileSystem) + .flatMap(cp -> StreamUtils.optionalToStream(inputLocationForPath(cp))) + .collect(Collectors.toList()); } @Override diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java index ad5e54b3085..76526937866 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java @@ -109,7 +109,11 @@ public static PathBasedAnalysisInputLocation create( } else if (PathUtils.hasExtension(path, FileType.APK)) { inputLocation = new ApkAnalysisInputLocation(path, srcType); } else if (PathUtils.hasExtension(path, FileType.WAR)) { - inputLocation = new WarArchiveAnalysisInputLocation(path, srcType); + try { + inputLocation = new WarArchiveAnalysisInputLocation(path, srcType); + } catch (IOException e) { + throw new RuntimeException(e); + } } else { throw new IllegalArgumentException( "Path '" @@ -236,7 +240,7 @@ public Collection> getClassSources( private static class DirectoryBasedAnalysisInputLocation extends PathBasedAnalysisInputLocation { - private DirectoryBasedAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType srcType) { + private DirectoryBasedAnalysisInputLocation(@Nonnull Path path, @Nonnull SourceType srcType) { super(path, srcType); } @@ -273,7 +277,7 @@ public static class MultiReleaseJarAnalysisInputLocation extends ArchiveBasedAna boolean isResolved = false; - private MultiReleaseJarAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType srcType) { + private MultiReleaseJarAnalysisInputLocation(@Nonnull Path path, @Nonnull SourceType srcType) { super(path, srcType); int[] tmp; @@ -296,7 +300,7 @@ private MultiReleaseJarAnalysisInputLocation(@Nonnull Path path, @Nullable Sourc } /** Discovers all input locations for different java versions in this multi release jar */ - private void discoverInputLocations(@Nullable SourceType srcType) { + private void discoverInputLocations(@Nonnull SourceType srcType) { FileSystem fs = null; try { fs = fileSystemCache.get(path); @@ -531,7 +535,7 @@ public int hashCode() { private static class ApkAnalysisInputLocation extends ArchiveBasedAnalysisInputLocation { - private ApkAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType srcType) { + private ApkAnalysisInputLocation(@Nonnull Path path, @Nonnull SourceType srcType) { super(path, srcType); String jarPath = dex2jar(path); this.path = Paths.get(jarPath); @@ -616,16 +620,11 @@ private static final class WarArchiveAnalysisInputLocation public static int maxAllowedBytesToExtract = 1024 * 1024 * 500; // limit of extracted file size to protect against archive bombs - private WarArchiveAnalysisInputLocation(@Nonnull Path warPath, @Nullable SourceType srcType) { + private WarArchiveAnalysisInputLocation(@Nonnull Path warPath, @Nonnull SourceType srcType) + throws IOException { super( - Paths.get( - System.getProperty("java.io.tmpdir") - + File.separator - + "sootOutput" - + "-war" - + warPath.hashCode() - + "/"), - srcType); + Files.createTempDirectory("sootUp-war-" + warPath.hashCode()).toAbsolutePath(), srcType); + extractWarFile(warPath, path); Path webInfPath = path.resolve("WEB-INF"); From c8c8160411d56c9f5bf779028dffe6a31221de0c Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 22 Nov 2023 15:53:50 +0100 Subject: [PATCH 11/39] adapt testcases to DefaultRTJarAnalysisInputLocation; made it public --- docs/call-graph-construction.md | 4 +--- .../icfg/ICFGDotExporterTest.java | 17 +++++--------- .../interprocedural/ifds/CGEdgeUtilTest.java | 6 ++--- .../ifds/IFDSTaintTestSetUp.java | 5 ++--- .../sootup/callgraph/CallGraphTestBase.java | 6 ++--- .../InstantiateClassValueVisitorTest.java | 6 ++--- .../examples/callgraph/CallgraphExample.java | 5 ++--- .../classhierarchy/ClassHierarchy.java | 5 ++--- .../DefaultRTJarAnalysisInputLocation.java | 22 +++++++++++++++++++ .../PathBasedAnalysisInputLocation.java | 20 ++--------------- .../bytecode/RuntimeJarConversionTests.java | 7 ++---- .../frontend/AsmMethodSourceTest.java | 6 ++--- .../PathBasedAnalysisInputLocationTest.java | 8 ++----- .../typeresolving/TypeAssignerTestSuite.java | 5 +++-- .../test/java/sootup/tests/CallGraphTest.java | 6 ++--- .../typehierarchy/MethodDispatchBase.java | 6 ++--- 16 files changed, 55 insertions(+), 79 deletions(-) create mode 100644 sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/DefaultRTJarAnalysisInputLocation.java diff --git a/docs/call-graph-construction.md b/docs/call-graph-construction.md index 60bc3d93b40..ebf1462cdba 100644 --- a/docs/call-graph-construction.md +++ b/docs/call-graph-construction.md @@ -19,9 +19,7 @@ Below, we show how to create a type hierarchy: JavaProject project = JavaProject.builder(language) .addInputLocation(inputLocation) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) .build(); JavaView view = project.createView(); diff --git a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/icfg/ICFGDotExporterTest.java b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/icfg/ICFGDotExporterTest.java index 2a009388e75..00ff4a38010 100644 --- a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/icfg/ICFGDotExporterTest.java +++ b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/icfg/ICFGDotExporterTest.java @@ -16,6 +16,7 @@ import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; +import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation; import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaProject; @@ -41,9 +42,7 @@ public CallGraph loadCallGraph(JavaView view) { public void ICFGDotExportTest() { JavaProject javaProject = JavaProject.builder(new JavaLanguage(8)) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) .addInputLocation( new JavaClassPathAnalysisInputLocation("src/test/resources/icfg/binary")) .build(); @@ -81,9 +80,7 @@ public void ICFGDotExportTest() { public void ICFGDotExportTest2() { JavaProject javaProject = JavaProject.builder(new JavaLanguage(8)) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) .addInputLocation( new JavaClassPathAnalysisInputLocation("src/test/resources/icfg/binary")) .build(); @@ -121,9 +118,7 @@ public void ICFGDotExportTest2() { public void ICFGArrayListDotExport() { JavaProject javaProject = JavaProject.builder(new JavaLanguage(8)) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) .addInputLocation( new JavaClassPathAnalysisInputLocation("src/test/resources/icfg/binary")) .build(); @@ -153,9 +148,7 @@ public void ICFGArrayListDotExport() { public void ICFGInterfaceDotExport() { JavaProject javaProject = JavaProject.builder(new JavaLanguage(8)) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) .addInputLocation( new JavaClassPathAnalysisInputLocation("src/test/resources/icfg/binary")) .build(); diff --git a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/CGEdgeUtilTest.java b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/CGEdgeUtilTest.java index 286a465ff8f..e76296062a4 100644 --- a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/CGEdgeUtilTest.java +++ b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/CGEdgeUtilTest.java @@ -41,7 +41,7 @@ import sootup.core.types.PrimitiveType; import sootup.core.types.Type; import sootup.core.util.printer.StmtPrinter; -import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; +import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaProject; import sootup.java.core.language.JavaLanguage; @@ -137,9 +137,7 @@ public void testGetCallEdges() { JavaView view = JavaProject.builder(new JavaLanguage(8)) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) .addInputLocation( new JavaSourcePathAnalysisInputLocation("src/test/resources/callgraph/")) .build() diff --git a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/IFDSTaintTestSetUp.java b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/IFDSTaintTestSetUp.java index 57e091d2445..0ad5a5b31e4 100644 --- a/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/IFDSTaintTestSetUp.java +++ b/sootup.analysis/src/test/java/sootup/analysis/interprocedural/ifds/IFDSTaintTestSetUp.java @@ -30,6 +30,7 @@ import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; +import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation; import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaProject; @@ -73,9 +74,7 @@ private void runAnalysis() { private void setupSoot(String targetTestClassName) { JavaProject javaProject = JavaProject.builder(new JavaLanguage(8)) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) .addInputLocation( new JavaClassPathAnalysisInputLocation("src/test/resources/taint/binary")) .build(); diff --git a/sootup.callgraph/src/test/java/sootup/callgraph/CallGraphTestBase.java b/sootup.callgraph/src/test/java/sootup/callgraph/CallGraphTestBase.java index f504b20b337..061ece7331e 100644 --- a/sootup.callgraph/src/test/java/sootup/callgraph/CallGraphTestBase.java +++ b/sootup.callgraph/src/test/java/sootup/callgraph/CallGraphTestBase.java @@ -7,8 +7,8 @@ import org.junit.Test; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; -import sootup.core.model.SourceType; import sootup.core.signatures.MethodSignature; +import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation; import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaProject; @@ -35,9 +35,7 @@ private JavaView createViewForClassPath(String classPath) { private JavaView createViewForClassPath(String classPath, boolean useSourceCodeFrontend) { JavaProject.JavaProjectBuilder javaProjectBuilder = JavaProject.builder(new JavaLanguage(8)) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar", SourceType.Library)); + .addInputLocation(new DefaultRTJarAnalysisInputLocation()); if (useSourceCodeFrontend) { javaProjectBuilder.addInputLocation(new JavaSourcePathAnalysisInputLocation(classPath)); } else { diff --git a/sootup.callgraph/src/test/java/sootup/callgraph/InstantiateClassValueVisitorTest.java b/sootup.callgraph/src/test/java/sootup/callgraph/InstantiateClassValueVisitorTest.java index 2313bfaea48..3ae875e2878 100644 --- a/sootup.callgraph/src/test/java/sootup/callgraph/InstantiateClassValueVisitorTest.java +++ b/sootup.callgraph/src/test/java/sootup/callgraph/InstantiateClassValueVisitorTest.java @@ -64,7 +64,7 @@ import sootup.core.types.ClassType; import sootup.core.types.PrimitiveType; import sootup.core.views.View; -import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; +import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation; import sootup.java.core.JavaProject; import sootup.java.core.JavaSootClass; import sootup.java.core.language.JavaJimple; @@ -77,9 +77,7 @@ public void testVisitor() { JavaProject javaProject = JavaProject.builder(new JavaLanguage(8)) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) .build(); View view = javaProject.createView(); IdentifierFactory identifierFactory = view.getIdentifierFactory(); diff --git a/sootup.examples/src/test/java/sootup/examples/callgraph/CallgraphExample.java b/sootup.examples/src/test/java/sootup/examples/callgraph/CallgraphExample.java index 1c551b0a44d..bbdf3e08430 100644 --- a/sootup.examples/src/test/java/sootup/examples/callgraph/CallgraphExample.java +++ b/sootup.examples/src/test/java/sootup/examples/callgraph/CallgraphExample.java @@ -10,6 +10,7 @@ import sootup.core.typehierarchy.ViewTypeHierarchy; import sootup.core.types.ClassType; import sootup.core.types.VoidType; +import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation; import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaProject; @@ -34,9 +35,7 @@ public void test() { JavaProject project = JavaProject.builder(language) .addInputLocation(inputLocation) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) // add rt.jar + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) // add rt.jar .build(); JavaView view = project.createView(); diff --git a/sootup.examples/src/test/java/sootup/examples/classhierarchy/ClassHierarchy.java b/sootup.examples/src/test/java/sootup/examples/classhierarchy/ClassHierarchy.java index 408ab93736f..70baf917263 100644 --- a/sootup.examples/src/test/java/sootup/examples/classhierarchy/ClassHierarchy.java +++ b/sootup.examples/src/test/java/sootup/examples/classhierarchy/ClassHierarchy.java @@ -8,6 +8,7 @@ import sootup.core.inputlocation.AnalysisInputLocation; import sootup.core.typehierarchy.ViewTypeHierarchy; import sootup.core.types.ClassType; +import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation; import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaProject; @@ -44,9 +45,7 @@ public void test() { JavaProject project = JavaProject.builder(language) .addInputLocation(inputLocation) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) // add rt.jar + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) // add rt.jar .build(); JavaView view = project.createView(); diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/DefaultRTJarAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/DefaultRTJarAnalysisInputLocation.java new file mode 100644 index 00000000000..eb1811f8be2 --- /dev/null +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/DefaultRTJarAnalysisInputLocation.java @@ -0,0 +1,22 @@ +package sootup.java.bytecode.inputlocation; + +import java.nio.file.Paths; +import javax.annotation.Nonnull; +import sootup.core.model.SourceType; + +/** + * Refers to the rt.jar from <=Java8 as an AnalysisInputLocation requires: JAVA_HOME to be set and + * expects the jar in the "lib/" subdirectory. If you need to include the rt.jar from a custom + * Location please make use of JavaClassPathAnalysisInputLocation. + */ +public class DefaultRTJarAnalysisInputLocation + extends PathBasedAnalysisInputLocation.ArchiveBasedAnalysisInputLocation { + + public DefaultRTJarAnalysisInputLocation() { + this(SourceType.Library); + } + + public DefaultRTJarAnalysisInputLocation(@Nonnull SourceType srcType) { + super(Paths.get(System.getProperty("java.home") + "/lib/rt.jar"), srcType); + } +} diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java index 76526937866..56e59839e19 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java @@ -552,7 +552,7 @@ private String dex2jar(Path path) { } } - private static class ArchiveBasedAnalysisInputLocation extends PathBasedAnalysisInputLocation { + static class ArchiveBasedAnalysisInputLocation extends PathBasedAnalysisInputLocation { // We cache the FileSystem instances as their creation is expensive. // The Guava Cache is thread-safe (see JavaDoc of LoadingCache) hence this @@ -580,7 +580,7 @@ private static class ArchiveBasedAnalysisInputLocation extends PathBasedAnalysis } })); - private ArchiveBasedAnalysisInputLocation(@Nonnull Path path, @Nonnull SourceType srcType) { + ArchiveBasedAnalysisInputLocation(@Nonnull Path path, @Nonnull SourceType srcType) { super(path, srcType); } @@ -796,20 +796,4 @@ public List retrieveServletClasses(String extractedWARPath) { return classesInXML; } } - - /** - * Refers to the rt.jar from <=Java8 as an AnalysisInputLocation requires: JAVA_HOME to be set and - * expects the jar in the "lib/" subdirectory. If you need to include the rt.jar from a custom - * Location please make use of JavaClassPathAnalysisInputLocation. - */ - private static class DefaultRTJarAnalysisInputLocation extends ArchiveBasedAnalysisInputLocation { - - private DefaultRTJarAnalysisInputLocation() { - this(SourceType.Library); - } - - private DefaultRTJarAnalysisInputLocation(@Nonnull SourceType srcType) { - super(Paths.get(System.getProperty("java.home") + "/lib/rt.jar"), srcType); - } - } } diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/RuntimeJarConversionTests.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/RuntimeJarConversionTests.java index 241d631c33a..38b704145fa 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/RuntimeJarConversionTests.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/RuntimeJarConversionTests.java @@ -1,12 +1,11 @@ package sootup.java.bytecode; -import java.nio.file.Paths; import org.junit.Test; import sootup.core.inputlocation.AnalysisInputLocation; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; import sootup.java.bytecode.inputlocation.BytecodeClassLoadingOptions; -import sootup.java.bytecode.inputlocation.PathBasedAnalysisInputLocation; +import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaProject; import sootup.java.core.JavaSootClass; @@ -16,9 +15,7 @@ public class RuntimeJarConversionTests { private static void execute(String methodSignature1) { - AnalysisInputLocation inputLocation = - PathBasedAnalysisInputLocation.create( - Paths.get(System.getProperty("java.home") + "/lib/rt.jar"), null); + AnalysisInputLocation inputLocation = new DefaultRTJarAnalysisInputLocation(); JavaProject project = JavaProject.builder(new JavaLanguage(8)).addInputLocation(inputLocation).build(); diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/frontend/AsmMethodSourceTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/frontend/AsmMethodSourceTest.java index c16724ab7e1..6e6e3cb0f4a 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/frontend/AsmMethodSourceTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/frontend/AsmMethodSourceTest.java @@ -10,7 +10,7 @@ import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; -import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; +import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaProject; import sootup.java.core.language.JavaLanguage; @@ -31,9 +31,7 @@ public void testFix_StackUnderrun_convertPutFieldInsn_init() { JavaProject javaProject = JavaProject.builder(new JavaLanguage(8)) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) .build(); JavaView view = javaProject.createView(); diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java index d9123df9dee..701d0143a22 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocationTest.java @@ -421,9 +421,7 @@ void runtimeContains(View view, String classname, String packageName) { @Test public void testRuntimeJar() { - PathBasedAnalysisInputLocation pathBasedNamespace = - PathBasedAnalysisInputLocation.create( - Paths.get(System.getProperty("java.home") + "/lib/rt.jar"), null); + PathBasedAnalysisInputLocation pathBasedNamespace = new DefaultRTJarAnalysisInputLocation(); JavaView v = JavaProject.builder(new JavaLanguage(8)) @@ -450,9 +448,7 @@ public void testInputLocationLibraryMode() { JavaProject javaProject = JavaProject.builder(new JavaLanguage(8)) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar", SourceType.Library)) + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) .build(); JavaView view = javaProject.createView(); diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/TypeAssignerTestSuite.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/TypeAssignerTestSuite.java index f837968b729..89e8df57694 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/TypeAssignerTestSuite.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/TypeAssignerTestSuite.java @@ -4,11 +4,13 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import sootup.core.inputlocation.AnalysisInputLocation; import sootup.core.jimple.basic.Local; import sootup.core.model.Body; import sootup.core.signatures.MethodSignature; import sootup.core.types.ClassType; import sootup.core.types.Type; +import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation; import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaProject; @@ -28,8 +30,7 @@ public void buildView(String baseDir, String className) { JavaClassPathAnalysisInputLocation analysisInputLocation = new JavaClassPathAnalysisInputLocation(baseDir); - JavaClassPathAnalysisInputLocation rtJar = - new JavaClassPathAnalysisInputLocation(System.getProperty("java.home") + "/lib/rt.jar"); + AnalysisInputLocation rtJar = new DefaultRTJarAnalysisInputLocation(); JavaProject project = JavaProject.builder(new JavaLanguage(8)) .addInputLocation(analysisInputLocation) diff --git a/sootup.tests/src/test/java/sootup/tests/CallGraphTest.java b/sootup.tests/src/test/java/sootup/tests/CallGraphTest.java index 440ac9bb96c..306c5a38dad 100644 --- a/sootup.tests/src/test/java/sootup/tests/CallGraphTest.java +++ b/sootup.tests/src/test/java/sootup/tests/CallGraphTest.java @@ -13,7 +13,7 @@ import sootup.core.model.SootClass; import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; -import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; +import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaProject; import sootup.java.core.language.JavaLanguage; @@ -40,9 +40,7 @@ protected AbstractCallGraphAlgorithm createAlgorithm(JavaView view) { private JavaView createViewForClassPath(String classPath) { JavaProject javaProject = JavaProject.builder(new JavaLanguage(8)) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) .addInputLocation(new JavaSourcePathAnalysisInputLocation(classPath)) .build(); return javaProject.createView(); diff --git a/sootup.tests/src/test/java/sootup/tests/typehierarchy/MethodDispatchBase.java b/sootup.tests/src/test/java/sootup/tests/typehierarchy/MethodDispatchBase.java index 2cab39ad2dc..eecde811547 100644 --- a/sootup.tests/src/test/java/sootup/tests/typehierarchy/MethodDispatchBase.java +++ b/sootup.tests/src/test/java/sootup/tests/typehierarchy/MethodDispatchBase.java @@ -6,7 +6,7 @@ import org.junit.experimental.categories.Category; import org.junit.rules.TestWatcher; import org.junit.runner.Description; -import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; +import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaProject; import sootup.java.core.language.JavaLanguage; @@ -38,9 +38,7 @@ protected void starting(Description description) { .addInputLocation( new JavaSourcePathAnalysisInputLocation( Collections.singleton(baseDir + "/" + getClassName()))) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) .build(); setView(project.createView()); } From 7c9ca1babc23e9ec21e3c2e264677cb5be13ed16 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 22 Nov 2023 17:06:44 +0100 Subject: [PATCH 12/39] adapt isMain(...) --- .../java/core/JavaIdentifierFactory.java | 26 +++++++++++++++++++ .../core/JavaModuleIdentifierFactory.java | 12 +++++++++ 2 files changed, 38 insertions(+) diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java b/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java index 421ee70db9d..e8bdd1971de 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java @@ -56,6 +56,32 @@ public class JavaIdentifierFactory implements IdentifierFactory { @Nonnull private static final JavaIdentifierFactory INSTANCE = new JavaIdentifierFactory(); + public boolean isStaticInitializerSignature(@Nonnull MethodSubSignature methodSubSignature) { + return methodSubSignature.getName().equals(""); + } + + public boolean isStaticInitializerSignature(@Nonnull MethodSignature methodSignature) { + return isStaticInitializerSignature(methodSignature.getSubSignature()); + } + + public boolean isConstructor(@Nonnull MethodSubSignature methodSubSignature) { + return methodSubSignature.getName().equals(""); + } + + public boolean isConstructor(@Nonnull MethodSignature methodSignature) { + return isConstructor(methodSignature.getSubSignature()); + } + + boolean isMainSignature(@Nonnull MethodSignature methodSignature) { + if (methodSignature.getName().equals("main")) { + final List parameterTypes = methodSignature.getParameterTypes(); + if (parameterTypes.size() == 1) { + return parameterTypes.get(0).toString().equals("java.lang.String[]"); + } + } + return false; + } + /** Caches the created PackageNames for packages. */ @Nonnull protected final Cache packageCache = diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java b/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java index 0a24d88ac3f..9d75c9885cd 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java @@ -28,6 +28,7 @@ import javax.annotation.Nonnull; import org.apache.commons.lang3.ClassUtils; import sootup.core.signatures.MethodSignature; +import sootup.core.types.Type; import sootup.java.core.signatures.ModulePackageName; import sootup.java.core.signatures.ModuleSignature; import sootup.java.core.types.ModuleJavaClassType; @@ -69,6 +70,17 @@ public static JavaModuleIdentifierFactory getInstance(@Nonnull ModuleSignature m modules.put(ModuleSignature.UNNAMED_MODULE.getModuleName(), ModuleSignature.UNNAMED_MODULE); } + @Override + boolean isMainSignature(@Nonnull MethodSignature methodSignature) { + if (methodSignature.getName().equals("main")) { + final List parameterTypes = methodSignature.getParameterTypes(); + if (parameterTypes.size() == 1) { + return parameterTypes.get(0).toString().equals("java.base/java.lang.String[]"); + } + } + return false; + } + @Override public ModuleJavaClassType getClassType(final String className, final String packageName) { return getClassType(className, packageName, ModuleSignature.UNNAMED_MODULE.getModuleName()); From a95e7e714b638a558e3eb9d28a273eba0b9a3654 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 22 Nov 2023 17:15:52 +0100 Subject: [PATCH 13/39] add license --- .../DefaultRTJarAnalysisInputLocation.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/DefaultRTJarAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/DefaultRTJarAnalysisInputLocation.java index eb1811f8be2..971f55e321b 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/DefaultRTJarAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/DefaultRTJarAnalysisInputLocation.java @@ -1,4 +1,25 @@ package sootup.java.bytecode.inputlocation; +/*- + * #%L + * Soot - a J*va Optimization Framework + * %% + * Copyright (C) 2023 Markus Schmidt + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ import java.nio.file.Paths; import javax.annotation.Nonnull; From 6a8f0d7f5ed8867f9906491aefa2b7e75c691bff Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 22 Nov 2023 17:20:32 +0100 Subject: [PATCH 14/39] adapt leftovers --- .../src/test/java/sootup/callgraph/CallGraphTestBase.java | 5 ++--- .../test/java/sootup/callgraph/ConcreteDispatchTest.java | 5 ++--- .../sootup/tests/typehierarchy/HierarchyComparatorTest.java | 6 ++---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/sootup.callgraph/src/test/java/sootup/callgraph/CallGraphTestBase.java b/sootup.callgraph/src/test/java/sootup/callgraph/CallGraphTestBase.java index 8466336c06f..e853b94fd40 100644 --- a/sootup.callgraph/src/test/java/sootup/callgraph/CallGraphTestBase.java +++ b/sootup.callgraph/src/test/java/sootup/callgraph/CallGraphTestBase.java @@ -7,6 +7,7 @@ import org.junit.Test; import sootup.core.model.SootClass; import sootup.core.model.SootMethod; +import sootup.core.model.SourceType; import sootup.core.signatures.MethodSignature; import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation; import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; @@ -723,9 +724,7 @@ public void testStopAtLibraryClass() { String classPath = "src/test/resources/callgraph/Library/binary/"; JavaProject.JavaProjectBuilder javaProjectBuilder = JavaProject.builder(new JavaLanguage(8)) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar", SourceType.Library)) + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) .addInputLocation( new JavaClassPathAnalysisInputLocation( classPath + "application/", SourceType.Application)) diff --git a/sootup.callgraph/src/test/java/sootup/callgraph/ConcreteDispatchTest.java b/sootup.callgraph/src/test/java/sootup/callgraph/ConcreteDispatchTest.java index d8d8ce95836..a69d9ef20d7 100644 --- a/sootup.callgraph/src/test/java/sootup/callgraph/ConcreteDispatchTest.java +++ b/sootup.callgraph/src/test/java/sootup/callgraph/ConcreteDispatchTest.java @@ -14,6 +14,7 @@ import sootup.core.IdentifierFactory; import sootup.core.signatures.MethodSignature; import sootup.core.types.ClassType; +import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation; import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; import sootup.java.core.JavaProject; import sootup.java.core.language.JavaLanguage; @@ -35,9 +36,7 @@ public static void setUp() { .addInputLocation( new JavaClassPathAnalysisInputLocation( "src/test/resources/callgraph/ConcreteDispatch/binary")) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) .build(); view = project.createView(); } diff --git a/sootup.tests/src/test/java/sootup/tests/typehierarchy/HierarchyComparatorTest.java b/sootup.tests/src/test/java/sootup/tests/typehierarchy/HierarchyComparatorTest.java index e431486ae2d..e73369d7ae2 100644 --- a/sootup.tests/src/test/java/sootup/tests/typehierarchy/HierarchyComparatorTest.java +++ b/sootup.tests/src/test/java/sootup/tests/typehierarchy/HierarchyComparatorTest.java @@ -14,7 +14,7 @@ import sootup.core.typehierarchy.HierarchyComparator; import sootup.core.types.ClassType; import sootup.core.views.View; -import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; +import sootup.java.bytecode.inputlocation.DefaultRTJarAnalysisInputLocation; import sootup.java.core.JavaProject; import sootup.java.core.language.JavaLanguage; import sootup.java.sourcecode.inputlocation.JavaSourcePathAnalysisInputLocation; @@ -31,9 +31,7 @@ public static void setUp() { .addInputLocation( new JavaSourcePathAnalysisInputLocation( Collections.singleton("src/test/resources/javatypehierarchy/Comparator"))) - .addInputLocation( - new JavaClassPathAnalysisInputLocation( - System.getProperty("java.home") + "/lib/rt.jar")) + .addInputLocation(new DefaultRTJarAnalysisInputLocation()) .build(); view = project.createView(); } From 303e04c3ceea55a316da4140c552fb3f9e174c2a Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Wed, 22 Nov 2023 17:23:52 +0100 Subject: [PATCH 15/39] fix link to doc in auto comment --- .github/workflows/gh-pages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index d29995cdcda..07e95cf2e1e 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -79,7 +79,7 @@ jobs: uses: marocchino/sticky-pull-request-comment@v2 with: message: | - You updated the documentation - [Doc Preview](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}_preview/${{ github.head_ref }}/). + You updated the documentation - [Doc Preview](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ github.head_ref }}_preview/). # on PR close - delete preview - name: delete the deployed preview From c24d88cb59df4e0866702c752982c06216e149e9 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 11:13:30 +0100 Subject: [PATCH 16/39] fix test --- sootup.tests/src/test/java/sootup/tests/CallGraphTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sootup.tests/src/test/java/sootup/tests/CallGraphTest.java b/sootup.tests/src/test/java/sootup/tests/CallGraphTest.java index 306c5a38dad..034d7a762c8 100644 --- a/sootup.tests/src/test/java/sootup/tests/CallGraphTest.java +++ b/sootup.tests/src/test/java/sootup/tests/CallGraphTest.java @@ -244,9 +244,7 @@ public void checkCallGraphDotExporter() { + "\t\"()>\" -> \"()>\";\n" + "\t\"()>\" -> \"()>\";\n" + "\t\"()>\" -> \"()>\";\n" - + "\t\"()>\" -> \"()>\";\n" - + "\t\"()>\" -> \"()>\";\n" - + "\t\"()>\" -> \"\";\n}"; - assertEquals(actualContent, expectedContent); + + "\t\"()>\" -> \"()>\";\n"; + assertEquals(expectedContent, actualContent); } } From 3321a68a34f1b2a347ad9e5f95831197985d4338 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 11:34:45 +0100 Subject: [PATCH 17/39] fix test; remove method draft --- .../core/signatures/MethodSubSignature.java | 18 ------------------ .../test/java/sootup/tests/CallGraphTest.java | 3 ++- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/signatures/MethodSubSignature.java b/sootup.core/src/main/java/sootup/core/signatures/MethodSubSignature.java index f1455142113..6944f50bea2 100644 --- a/sootup.core/src/main/java/sootup/core/signatures/MethodSubSignature.java +++ b/sootup.core/src/main/java/sootup/core/signatures/MethodSubSignature.java @@ -134,22 +134,4 @@ public void toString(StmtPrinter printer) { printer.literal(")"); } - - boolean isMainSignature() { - if (getName().equals("main")) { - if (getParameterTypes().size() == 1) { - // FIXME: handle modules with 'java.base' in the signature as well - return getParameterTypes().get(0).toString().equals("java.lang.String[]"); - } - } - return false; - } - - boolean isStaticInitializerSignature() { - return getName().equals(""); - } - - boolean isConstructor() { - return getName().equals(""); - } } diff --git a/sootup.tests/src/test/java/sootup/tests/CallGraphTest.java b/sootup.tests/src/test/java/sootup/tests/CallGraphTest.java index 034d7a762c8..49d7385a66c 100644 --- a/sootup.tests/src/test/java/sootup/tests/CallGraphTest.java +++ b/sootup.tests/src/test/java/sootup/tests/CallGraphTest.java @@ -244,7 +244,8 @@ public void checkCallGraphDotExporter() { + "\t\"()>\" -> \"()>\";\n" + "\t\"()>\" -> \"()>\";\n" + "\t\"()>\" -> \"()>\";\n" - + "\t\"()>\" -> \"()>\";\n"; + + "\t\"()>\" -> \"()>\";\n" + + "}"; assertEquals(expectedContent, actualContent); } } From 6b4434bf219aab6c43fe44a10c718d2e0dc34ae6 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 11:41:58 +0100 Subject: [PATCH 18/39] make use of autoclosable --- .../inputlocation/JavaClassPathAnalysisInputLocation.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaClassPathAnalysisInputLocation.java b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaClassPathAnalysisInputLocation.java index fc1e86f43da..b129a360a32 100644 --- a/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaClassPathAnalysisInputLocation.java +++ b/sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/JavaClassPathAnalysisInputLocation.java @@ -133,9 +133,8 @@ public SourceType getSourceType() { @Nonnull String entry, FileSystem fileSystem) { if (entry.endsWith(WILDCARD_CHAR)) { Path baseDir = fileSystem.getPath(entry.substring(0, entry.indexOf(WILDCARD_CHAR))); - try { - return StreamUtils.iteratorToStream( - Files.newDirectoryStream(baseDir, "*.{jar,JAR}").iterator()); + try (final DirectoryStream paths = Files.newDirectoryStream(baseDir, "*.{jar,JAR}"); ) { + return StreamUtils.iteratorToStream(paths.iterator()); } catch (PatternSyntaxException | NotDirectoryException e) { throw new IllegalStateException("Malformed wildcard entry", e); } catch (IOException e) { From 1e98066369599a3196acc92542a97c22a7d5bc7c Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 12:40:47 +0100 Subject: [PATCH 19/39] sanitize branch name for doc --- .github/workflows/gh-pages.yml | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 07e95cf2e1e..1e7bdf92117 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -63,6 +63,9 @@ jobs: git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" + # sanitive head_ref name + - run: echo "DOC_VERSION_NAME=${${{github.head_ref}}////_}" >> "$GITHUB_ENV" + # on push to develop branch - keep a doc around for develop to show the current state - name: deploy doc in subdirectory if: github.event_name == 'push' @@ -71,27 +74,37 @@ jobs: # on PR events.. - name: deploy doc in subdirectory if: github.event_name == 'pull_request' - run: mike deploy ${{ github.head_ref }}_preview --push - # TODO: set to true when the release is capable of the documentation ;) && mike props ${{ github.head_ref }}_preview --set-string hidden=true --push + run: mike deploy ${{ $DOC_VERSION_NAME }}_preview --push + # TODO: set to true when the release is capable of the documentation ;) && mike props ${{ $DOC_VERSION_NAME }}_preview --set-string hidden=true --push - name: comment link to preview if: github.event_name == 'pull_request' && github.event.action != 'closed' uses: marocchino/sticky-pull-request-comment@v2 with: message: | - You updated the documentation - [Doc Preview](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ github.head_ref }}_preview/). + You updated the documentation - [Doc Preview](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ $DOC_VERSION_NAME }}_preview/). # on PR close - delete preview - name: delete the deployed preview if: github.event_name == 'pull_request' && github.event.action == 'closed' - run: mike delete ${{ github.head_ref }}_preview --push + run: mike delete ${{ $DOC_VERSION_NAME }}_preview --push # on release events.. + # sanitive head_ref name + - name: sanitize tag name + if: github.event_name == 'release' + run: echo "DOC_VERSION_NAME=${${{github.ref_name}}////_}" >> "$GITHUB_ENV" + + - name: deploy doc in subdirectory + if: github.event_name == 'release' + run: mike deploy ${{ $DOC_VERSION_NAME }} --push + + - name: deploy doc in subdirectory if: github.event_name == 'release' - run: mike deploy ${{ github.ref_name }} --push + run: mike deploy ${{ $DOC_VERSION_NAME }} --push - name: set the new release doc as default (release published) if: github.event_name == 'release' && github.event.action == 'published' - run: mike deploy --push --update-aliases ${{ github.ref_name }} latest + run: mike deploy --push --update-aliases ${{ $DOC_VERSION_NAME }} latest From b1b9d588d60fc2bd8276202ccfa608dafbcd32c8 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 12:47:24 +0100 Subject: [PATCH 20/39] sanitize all non alphanumeric branch/tag names --- .github/workflows/gh-pages.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 1e7bdf92117..d61031bbd9b 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -64,7 +64,7 @@ jobs: git config --local user.name "github-actions[bot]" # sanitive head_ref name - - run: echo "DOC_VERSION_NAME=${${{github.head_ref}}////_}" >> "$GITHUB_ENV" + - run: echo "DOC_VERSION_NAME=${${{github.head_ref}}//[^[:alnum:]]/_}" >> "$GITHUB_ENV" # on push to develop branch - keep a doc around for develop to show the current state - name: deploy doc in subdirectory @@ -94,7 +94,7 @@ jobs: # sanitive head_ref name - name: sanitize tag name if: github.event_name == 'release' - run: echo "DOC_VERSION_NAME=${${{github.ref_name}}////_}" >> "$GITHUB_ENV" + run: echo "DOC_VERSION_NAME=${${{github.ref_name}}//[^[:alnum:]]/_}" >> "$GITHUB_ENV" - name: deploy doc in subdirectory if: github.event_name == 'release' From 94eff49ed1c3013eb61e85ba666912c54c7638d0 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 12:49:11 +0100 Subject: [PATCH 21/39] trigger on config change --- .github/workflows/gh-pages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index d61031bbd9b..e0476cc22ce 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -12,6 +12,7 @@ on: - 'mkdocs.yml' - 'sootup.examples/**' - 'docs/**' + - '.github/workflows/gh-pages.yml' release: types: [ created, published ] From 39756898a183cdfeec8edc58a0269c31694442ab Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 12:54:04 +0100 Subject: [PATCH 22/39] again --- .github/workflows/gh-pages.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index e0476cc22ce..e4e00a6a9a5 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -75,20 +75,20 @@ jobs: # on PR events.. - name: deploy doc in subdirectory if: github.event_name == 'pull_request' - run: mike deploy ${{ $DOC_VERSION_NAME }}_preview --push - # TODO: set to true when the release is capable of the documentation ;) && mike props ${{ $DOC_VERSION_NAME }}_preview --set-string hidden=true --push + run: mike deploy ${DOC_VERSION_NAME}_preview --push + # TODO: set to true when the release is capable of the documentation ;) && mike props ${DOC_VERSION_NAME}_preview --set-string hidden=true --push - name: comment link to preview if: github.event_name == 'pull_request' && github.event.action != 'closed' uses: marocchino/sticky-pull-request-comment@v2 with: message: | - You updated the documentation - [Doc Preview](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ $DOC_VERSION_NAME }}_preview/). + You updated the documentation - [Doc Preview](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${DOC_VERSION_NAME}_preview/). # on PR close - delete preview - name: delete the deployed preview if: github.event_name == 'pull_request' && github.event.action == 'closed' - run: mike delete ${{ $DOC_VERSION_NAME }}_preview --push + run: mike delete ${DOC_VERSION_NAME}_preview --push # on release events.. @@ -99,13 +99,13 @@ jobs: - name: deploy doc in subdirectory if: github.event_name == 'release' - run: mike deploy ${{ $DOC_VERSION_NAME }} --push + run: mike deploy ${DOC_VERSION_NAME} --push - name: deploy doc in subdirectory if: github.event_name == 'release' - run: mike deploy ${{ $DOC_VERSION_NAME }} --push + run: mike deploy ${DOC_VERSION_NAME} --push - name: set the new release doc as default (release published) if: github.event_name == 'release' && github.event.action == 'published' - run: mike deploy --push --update-aliases ${{ $DOC_VERSION_NAME }} latest + run: mike deploy --push --update-aliases ${DOC_VERSION_NAME} latest From 708cdfb5331c6c780c9b2450c466db96c628fd83 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 13:48:30 +0100 Subject: [PATCH 23/39] aaand again --- .github/workflows/gh-pages.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index e4e00a6a9a5..b1540e9c831 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -27,6 +27,7 @@ on: - 'mkdocs.yml' - 'sootup.examples/**' - 'docs/**' + - '.github/workflows/gh-pages.yml' concurrency: pages @@ -75,20 +76,20 @@ jobs: # on PR events.. - name: deploy doc in subdirectory if: github.event_name == 'pull_request' - run: mike deploy ${DOC_VERSION_NAME}_preview --push - # TODO: set to true when the release is capable of the documentation ;) && mike props ${DOC_VERSION_NAME}_preview --set-string hidden=true --push + run: mike deploy "$DOC_VERSION_NAME"_preview --push + # TODO: set to true when the release is capable of the documentation ;) && mike props "$DOC_VERSION_NAME"_preview --set-string hidden=true --push - name: comment link to preview if: github.event_name == 'pull_request' && github.event.action != 'closed' uses: marocchino/sticky-pull-request-comment@v2 with: message: | - You updated the documentation - [Doc Preview](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${DOC_VERSION_NAME}_preview/). + You updated the documentation - [Doc Preview](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/"$DOC_VERSION_NAME"_preview/). # on PR close - delete preview - name: delete the deployed preview if: github.event_name == 'pull_request' && github.event.action == 'closed' - run: mike delete ${DOC_VERSION_NAME}_preview --push + run: mike delete "$DOC_VERSION_NAME"_preview --push # on release events.. @@ -99,13 +100,13 @@ jobs: - name: deploy doc in subdirectory if: github.event_name == 'release' - run: mike deploy ${DOC_VERSION_NAME} --push + run: mike deploy "$DOC_VERSION_NAME" --push - name: deploy doc in subdirectory if: github.event_name == 'release' - run: mike deploy ${DOC_VERSION_NAME} --push + run: mike deploy "$DOC_VERSION_NAME" --push - name: set the new release doc as default (release published) if: github.event_name == 'release' && github.event.action == 'published' - run: mike deploy --push --update-aliases ${DOC_VERSION_NAME} latest + run: mike deploy --push --update-aliases "$DOC_VERSION_NAME" latest From 20a1f0a54b5e765ea79e288cabbe0bcbfacc2169 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 14:04:02 +0100 Subject: [PATCH 24/39] trigger ci --- .github/workflows/gh-pages.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index b1540e9c831..fc3de76d965 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -66,7 +66,19 @@ jobs: git config --local user.name "github-actions[bot]" # sanitive head_ref name - - run: echo "DOC_VERSION_NAME=${${{github.head_ref}}//[^[:alnum:]]/_}" >> "$GITHUB_ENV" + - run: echo "DOC_VERSION_NAME=${github.head_ref//[^[:alnum:]]/_}" >> "$GITHUB_ENV" + + - run: echo $DOC_VERSION_NAME; + - run: echo "$DOC_VERSION_NAME"; + - run: echo "$DOC_VERSION_NAME_preview"; + - run: echo "$DOC_VERSION_NAME"_preview; + + - run: echo ${DOC_VERSION_NAME}; + - run: echo ${DOC_VERSION_NAME}_preview; + + - run: echo ${{ $DOC_VERSION_NAME }}; + - run: echo ${{ DOC_VERSION_NAME }}_preview;; + # on push to develop branch - keep a doc around for develop to show the current state - name: deploy doc in subdirectory From a8c0b80a9b63a132cf41a2461928f2e38668e38a Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 14:08:34 +0100 Subject: [PATCH 25/39] trigger ci --- .github/workflows/gh-pages.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index fc3de76d965..80074e9ec66 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -76,7 +76,6 @@ jobs: - run: echo ${DOC_VERSION_NAME}; - run: echo ${DOC_VERSION_NAME}_preview; - - run: echo ${{ $DOC_VERSION_NAME }}; - run: echo ${{ DOC_VERSION_NAME }}_preview;; From 3f4d84207b8c74a3a1b199cae0e1f7bce0b9c41c Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 14:09:30 +0100 Subject: [PATCH 26/39] trigger ci --- .github/workflows/gh-pages.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 80074e9ec66..c16a97d3376 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -76,9 +76,6 @@ jobs: - run: echo ${DOC_VERSION_NAME}; - run: echo ${DOC_VERSION_NAME}_preview; - - run: echo ${{ DOC_VERSION_NAME }}_preview;; - - # on push to develop branch - keep a doc around for develop to show the current state - name: deploy doc in subdirectory if: github.event_name == 'push' From 81f28c0c180aead664d0129e484d52729290e156 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 14:14:27 +0100 Subject: [PATCH 27/39] trigger ci --- .github/workflows/gh-pages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index c16a97d3376..d4de379e419 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -66,7 +66,7 @@ jobs: git config --local user.name "github-actions[bot]" # sanitive head_ref name - - run: echo "DOC_VERSION_NAME=${github.head_ref//[^[:alnum:]]/_}" >> "$GITHUB_ENV" + - run: echo DOC_VERSION_NAME="${github.head_ref//[^[:alnum:]]/_}" >> "$GITHUB_ENV" - run: echo $DOC_VERSION_NAME; - run: echo "$DOC_VERSION_NAME"; From 2fc5e90d0276f5320a54f8d62420443c17974d3a Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 14:27:21 +0100 Subject: [PATCH 28/39] trigger ci --- .github/workflows/gh-pages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index d4de379e419..2dce389e0bc 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -66,7 +66,7 @@ jobs: git config --local user.name "github-actions[bot]" # sanitive head_ref name - - run: echo DOC_VERSION_NAME="${github.head_ref//[^[:alnum:]]/_}" >> "$GITHUB_ENV" + - run: echo DOC_VERSION_NAME="test_preview" >> "$GITHUB_ENV" - run: echo $DOC_VERSION_NAME; - run: echo "$DOC_VERSION_NAME"; From f399f151bfa7cb84b85ff98972fc0f45eac90b7f Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 14:31:28 +0100 Subject: [PATCH 29/39] trigger ci --- .github/workflows/gh-pages.yml | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 2dce389e0bc..d9369fed360 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -66,15 +66,7 @@ jobs: git config --local user.name "github-actions[bot]" # sanitive head_ref name - - run: echo DOC_VERSION_NAME="test_preview" >> "$GITHUB_ENV" - - - run: echo $DOC_VERSION_NAME; - - run: echo "$DOC_VERSION_NAME"; - - run: echo "$DOC_VERSION_NAME_preview"; - - run: echo "$DOC_VERSION_NAME"_preview; - - - run: echo ${DOC_VERSION_NAME}; - - run: echo ${DOC_VERSION_NAME}_preview; + - run: echo "DOC_VERSION_NAME=${github.head_ref//[^[:alnum:]]/_}" >> $GITHUB_ENV # on push to develop branch - keep a doc around for develop to show the current state - name: deploy doc in subdirectory @@ -84,37 +76,37 @@ jobs: # on PR events.. - name: deploy doc in subdirectory if: github.event_name == 'pull_request' - run: mike deploy "$DOC_VERSION_NAME"_preview --push - # TODO: set to true when the release is capable of the documentation ;) && mike props "$DOC_VERSION_NAME"_preview --set-string hidden=true --push + run: mike deploy ${{ env.DOC_VERSION_NAME }}_preview --push + # TODO: set to true when the release is capable of the documentation ;) && mike props ${{ env.DOC_VERSION_NAME }}_preview --set-string hidden=true --push - name: comment link to preview if: github.event_name == 'pull_request' && github.event.action != 'closed' uses: marocchino/sticky-pull-request-comment@v2 with: message: | - You updated the documentation - [Doc Preview](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/"$DOC_VERSION_NAME"_preview/). + You updated the documentation - [Doc Preview](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ env.DOC_VERSION_NAME }}_preview/). # on PR close - delete preview - name: delete the deployed preview if: github.event_name == 'pull_request' && github.event.action == 'closed' - run: mike delete "$DOC_VERSION_NAME"_preview --push + run: mike delete ${{ env.DOC_VERSION_NAME }}_preview --push # on release events.. # sanitive head_ref name - name: sanitize tag name if: github.event_name == 'release' - run: echo "DOC_VERSION_NAME=${${{github.ref_name}}//[^[:alnum:]]/_}" >> "$GITHUB_ENV" + run: echo "DOC_VERSION_NAME=${github.ref_name//[^[:alnum:]]/_}" >> $GITHUB_ENV - name: deploy doc in subdirectory if: github.event_name == 'release' - run: mike deploy "$DOC_VERSION_NAME" --push + run: mike deploy ${{ env.DOC_VERSION_NAME }} --push - name: deploy doc in subdirectory if: github.event_name == 'release' - run: mike deploy "$DOC_VERSION_NAME" --push + run: mike deploy ${{ env.DOC_VERSION_NAME }} --push - name: set the new release doc as default (release published) if: github.event_name == 'release' && github.event.action == 'published' - run: mike deploy --push --update-aliases "$DOC_VERSION_NAME" latest + run: mike deploy --push --update-aliases ${{ env.DOC_VERSION_NAME }} latest From c1e78dc2cf81406dace3de421ca2031e17d41dee Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 14:37:25 +0100 Subject: [PATCH 30/39] trigger ci --- .github/workflows/gh-pages.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index d9369fed360..f1281293109 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -65,9 +65,14 @@ jobs: git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" + + - run: which sh + # sanitive head_ref name - run: echo "DOC_VERSION_NAME=${github.head_ref//[^[:alnum:]]/_}" >> $GITHUB_ENV + + # on push to develop branch - keep a doc around for develop to show the current state - name: deploy doc in subdirectory if: github.event_name == 'push' From 4921740110fccbe5e4350a1fbc662885de3475df Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 14:44:11 +0100 Subject: [PATCH 31/39] trigger ci --- .github/workflows/gh-pages.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index f1281293109..4971045293d 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -65,11 +65,8 @@ jobs: git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" - - - run: which sh - # sanitive head_ref name - - run: echo "DOC_VERSION_NAME=${github.head_ref//[^[:alnum:]]/_}" >> $GITHUB_ENV + - run: echo "DOC_VERSION_NAME=$(echo ${{ github.head_ref }} | sed "s/[^[:alnum:]-]//g" )" >> $GITHUB_ENV From 0a06a3812ad3b7f2013690953d7d6b374f0e2476 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 14:55:16 +0100 Subject: [PATCH 32/39] trigger ci --- .github/workflows/gh-pages.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 4971045293d..f613c5c9e24 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -66,13 +66,13 @@ jobs: git config --local user.name "github-actions[bot]" # sanitive head_ref name - - run: echo "DOC_VERSION_NAME=$(echo ${{ github.head_ref }} | sed "s/[^[:alnum:]-]//g" )" >> $GITHUB_ENV + - run: echo "DOC_VERSION_NAME=$(echo ${{ github.head_ref }} | sed "s/[^[:alnum:]-]/_/g" )" >> $GITHUB_ENV # on push to develop branch - keep a doc around for develop to show the current state - name: deploy doc in subdirectory - if: github.event_name == 'push' + if: github.event_name == 'push'se run: mike deploy develop # on PR events.. @@ -98,7 +98,7 @@ jobs: # sanitive head_ref name - name: sanitize tag name if: github.event_name == 'release' - run: echo "DOC_VERSION_NAME=${github.ref_name//[^[:alnum:]]/_}" >> $GITHUB_ENV + run: echo "DOC_VERSION_NAME=$(echo ${{ github.ref_name }} | sed "s/[^[:alnum:]-]/_/g" )" >> $GITHUB_ENV - name: deploy doc in subdirectory if: github.event_name == 'release' From a6ea22dc8c19037029a4e99bdc16d2a3aaf4173e Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 18:17:29 +0100 Subject: [PATCH 33/39] cleanup typo --- .github/workflows/gh-pages.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index f613c5c9e24..f82c892aa79 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -68,11 +68,9 @@ jobs: # sanitive head_ref name - run: echo "DOC_VERSION_NAME=$(echo ${{ github.head_ref }} | sed "s/[^[:alnum:]-]/_/g" )" >> $GITHUB_ENV - - # on push to develop branch - keep a doc around for develop to show the current state - name: deploy doc in subdirectory - if: github.event_name == 'push'se + if: github.event_name == 'push' run: mike deploy develop # on PR events.. From 95cac417897faa7a34bc042794272381056f670c Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 18:27:24 +0100 Subject: [PATCH 34/39] not anymore --- .../java/sootup/java/core/JavaSootMethod.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaSootMethod.java b/sootup.java.core/src/main/java/sootup/java/core/JavaSootMethod.java index b9e84dc6b71..d7271cbe0b9 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaSootMethod.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaSootMethod.java @@ -38,8 +38,6 @@ import sootup.java.core.views.JavaView; public class JavaSootMethod extends SootMethod { - @Nonnull protected static final String CONSTRUCTOR_NAME = ""; - @Nonnull protected static final String STATIC_INITIALIZER_NAME = ""; @Nonnull private final Iterable annotations; public JavaSootMethod( @@ -53,19 +51,6 @@ public JavaSootMethod( this.annotations = annotations; } - /** - * @return yes, if this function is a constructor. Please not that <clinit> methods are not - * treated as constructors in this methodRef. - */ - public boolean isConstructor() { - return this.getSignature().getName().equals(CONSTRUCTOR_NAME); - } - - /** @return yes, if this function is a static initializer. */ - public boolean isStaticInitializer() { - return this.getSignature().getName().equals(STATIC_INITIALIZER_NAME); - } - @Nonnull public Iterable getAnnotations(@Nonnull Optional view) { resolveDefaultsForAnnotationTypes(view, annotations); From b6f1486da0c3a7ba942f0bd9ec3ee8fad177831e Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 20:50:34 +0100 Subject: [PATCH 35/39] not anymore; refactored the java specifics froms sootclass --- .../java/sootup/core/IdentifierFactory.java | 6 ++++++ .../java/sootup/core/model/SootMethod.java | 7 ++++--- .../java6/DeclareEnumWithConstructorTest.java | 5 +++++ .../java/core/JavaIdentifierFactory.java | 21 +++++++------------ .../core/JavaModuleIdentifierFactory.java | 7 ++++--- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/IdentifierFactory.java b/sootup.core/src/main/java/sootup/core/IdentifierFactory.java index cd747f44586..6814d56e6cd 100644 --- a/sootup.core/src/main/java/sootup/core/IdentifierFactory.java +++ b/sootup.core/src/main/java/sootup/core/IdentifierFactory.java @@ -253,4 +253,10 @@ FieldSignature getFieldSignature( * @return the class type */ ClassType fromPath(Path rootDirectory, Path file); + + boolean isStaticInitializerSubSignature(@Nonnull MethodSubSignature methodSubSignature); + + boolean isConstructorSubSignature(@Nonnull MethodSubSignature methodSubSignature); + + boolean isMainSubSignature(@Nonnull MethodSubSignature methodSubSignature); } diff --git a/sootup.core/src/main/java/sootup/core/model/SootMethod.java b/sootup.core/src/main/java/sootup/core/model/SootMethod.java index ad2ecc7184c..155d79ff722 100644 --- a/sootup.core/src/main/java/sootup/core/model/SootMethod.java +++ b/sootup.core/src/main/java/sootup/core/model/SootMethod.java @@ -35,6 +35,7 @@ import java.util.function.Supplier; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import sootup.core.IdentifierFactory; import sootup.core.frontend.BodySource; import sootup.core.frontend.OverridingBodySource; import sootup.core.frontend.ResolveException; @@ -208,10 +209,10 @@ public boolean isSynchronized() { } /** @return yes if this is the main method */ - public boolean isMain() { + public boolean isMain(@Nonnull IdentifierFactory idf) { return isPublic() && isStatic() - && getSignature().getSubSignature().toString().equals("void main(java.lang.String[])"); + && idf.isConstructorSubSignature(getSignature().getSubSignature()); } /** We rely on the JDK class recognition to decide if a method is JDK method. */ @@ -228,7 +229,7 @@ public void toString(@Nonnull StmtPrinter printer) { // print modifiers final Set modifiers = getModifiers(); printer.modifier(MethodModifier.toString(modifiers)); - if (modifiers.size() != 0) { + if (!modifiers.isEmpty()) { printer.literal(" "); } diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/DeclareEnumWithConstructorTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/DeclareEnumWithConstructorTest.java index ac43bb021b2..eafcd52e7a7 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/DeclareEnumWithConstructorTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/minimaltestsuite/java6/DeclareEnumWithConstructorTest.java @@ -61,9 +61,14 @@ public void test() { assertJimpleStmts(sootMethod, expectedBodyStmts()); sootMethod = loadMethod(getMainMethodSignature()); + assertTrue(sootMethod.isMain(identifierFactory)); + assertTrue(identifierFactory.isMainSubSignature(sootMethod.getSignature().getSubSignature())); assertJimpleStmts(sootMethod, expectedMainBodyStmts()); sootMethod = loadMethod(getEnumConstructorSignature()); + assertTrue( + identifierFactory.isStaticInitializerSubSignature( + sootMethod.getSignature().getSubSignature())); assertJimpleStmts(sootMethod, expectedEnumConstructorStmts()); sootMethod = loadMethod(getEnumGetValueSignature()); diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java b/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java index e8bdd1971de..19732777fd7 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaIdentifierFactory.java @@ -56,25 +56,20 @@ public class JavaIdentifierFactory implements IdentifierFactory { @Nonnull private static final JavaIdentifierFactory INSTANCE = new JavaIdentifierFactory(); - public boolean isStaticInitializerSignature(@Nonnull MethodSubSignature methodSubSignature) { + @Override + public boolean isStaticInitializerSubSignature(@Nonnull MethodSubSignature methodSubSignature) { return methodSubSignature.getName().equals(""); } - public boolean isStaticInitializerSignature(@Nonnull MethodSignature methodSignature) { - return isStaticInitializerSignature(methodSignature.getSubSignature()); - } - - public boolean isConstructor(@Nonnull MethodSubSignature methodSubSignature) { + @Override + public boolean isConstructorSubSignature(@Nonnull MethodSubSignature methodSubSignature) { return methodSubSignature.getName().equals(""); } - public boolean isConstructor(@Nonnull MethodSignature methodSignature) { - return isConstructor(methodSignature.getSubSignature()); - } - - boolean isMainSignature(@Nonnull MethodSignature methodSignature) { - if (methodSignature.getName().equals("main")) { - final List parameterTypes = methodSignature.getParameterTypes(); + @Override + public boolean isMainSubSignature(@Nonnull MethodSubSignature methodSubSignature) { + if (methodSubSignature.getName().equals("main")) { + final List parameterTypes = methodSubSignature.getParameterTypes(); if (parameterTypes.size() == 1) { return parameterTypes.get(0).toString().equals("java.lang.String[]"); } diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java b/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java index 9d75c9885cd..bf5c49ad4fc 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaModuleIdentifierFactory.java @@ -28,6 +28,7 @@ import javax.annotation.Nonnull; import org.apache.commons.lang3.ClassUtils; import sootup.core.signatures.MethodSignature; +import sootup.core.signatures.MethodSubSignature; import sootup.core.types.Type; import sootup.java.core.signatures.ModulePackageName; import sootup.java.core.signatures.ModuleSignature; @@ -71,9 +72,9 @@ public static JavaModuleIdentifierFactory getInstance(@Nonnull ModuleSignature m } @Override - boolean isMainSignature(@Nonnull MethodSignature methodSignature) { - if (methodSignature.getName().equals("main")) { - final List parameterTypes = methodSignature.getParameterTypes(); + public boolean isMainSubSignature(@Nonnull MethodSubSignature methodSubSignature) { + if (methodSubSignature.getName().equals("main")) { + final List parameterTypes = methodSubSignature.getParameterTypes(); if (parameterTypes.size() == 1) { return parameterTypes.get(0).toString().equals("java.base/java.lang.String[]"); } From 272762bbe6582b58f394c8074daf8722a57ab4b9 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 20:53:47 +0100 Subject: [PATCH 36/39] fix exception type --- .../main/java/sootup/java/core/JavaModuleInfo.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaModuleInfo.java b/sootup.java.core/src/main/java/sootup/java/core/JavaModuleInfo.java index 5fb889990ef..11340609077 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaModuleInfo.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaModuleInfo.java @@ -24,7 +24,6 @@ import java.util.*; import javax.annotation.Nonnull; -import sootup.core.frontend.ResolveException; import sootup.java.core.signatures.ModulePackageName; import sootup.java.core.signatures.ModuleSignature; import sootup.java.core.types.JavaClassType; @@ -87,33 +86,33 @@ public ModuleSignature getModuleSignature() { @Override public Collection requires() { // can read all other modules and the unnamed module (modules on the classpath) - throw new ResolveException( + throw new UnsupportedOperationException( "All modules can be required from the automatic module. Handle it separately."); } @Override public Collection exports() { // all Packages are exported - throw new ResolveException( + throw new UnsupportedOperationException( "All Packages are exported in the automatic module. Handle it separately."); } @Override public Collection opens() { // all Packages are open - throw new ResolveException( + throw new UnsupportedOperationException( "All Packages are open in the automatic module. Handle it separately."); } @Override public Collection provides() { - throw new ResolveException( + throw new UnsupportedOperationException( "All Packages are open in the automatic module. Handle it separately."); } @Override public Collection uses() { - throw new ResolveException( + throw new UnsupportedOperationException( "All Packages are open in the automatic module. Handle it separately."); } From dcc2ac504b013a720dc6520042427d964524cacb Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 21:13:45 +0100 Subject: [PATCH 37/39] fixed tests --- .../java/sootup/core/model/SootMethod.java | 4 +--- .../frontend/AsmMethodSourceTest.java | 22 +++++++++---------- .../java/core/views/JavaModuleView.java | 3 +-- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/model/SootMethod.java b/sootup.core/src/main/java/sootup/core/model/SootMethod.java index 155d79ff722..809a7adba6e 100644 --- a/sootup.core/src/main/java/sootup/core/model/SootMethod.java +++ b/sootup.core/src/main/java/sootup/core/model/SootMethod.java @@ -210,9 +210,7 @@ public boolean isSynchronized() { /** @return yes if this is the main method */ public boolean isMain(@Nonnull IdentifierFactory idf) { - return isPublic() - && isStatic() - && idf.isConstructorSubSignature(getSignature().getSubSignature()); + return isPublic() && isStatic() && idf.isMainSubSignature(getSignature().getSubSignature()); } /** We rely on the JDK class recognition to decide if a method is JDK method. */ diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/frontend/AsmMethodSourceTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/frontend/AsmMethodSourceTest.java index 6e6e3cb0f4a..d5f54b0bacb 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/frontend/AsmMethodSourceTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/frontend/AsmMethodSourceTest.java @@ -1,10 +1,10 @@ package sootup.java.bytecode.frontend; +import static junit.framework.Assert.assertTrue; import static junit.framework.TestCase.fail; import categories.Java8Test; import java.util.Arrays; -import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; import sootup.core.model.SootClass; @@ -21,7 +21,6 @@ public class AsmMethodSourceTest { @Test - @Ignore("FIXME") public void testFix_StackUnderrun_convertPutFieldInsn_init() { double version = Double.parseDouble(System.getProperty("java.specification.version")); @@ -36,17 +35,18 @@ public void testFix_StackUnderrun_convertPutFieldInsn_init() { JavaView view = javaProject.createView(); + final JavaIdentifierFactory idf = JavaIdentifierFactory.getInstance(); JavaClassType mainClassSignature = - JavaIdentifierFactory.getInstance() - .getClassType("javax.management.NotificationBroadcasterSupport"); + idf.getClassType("javax.management.NotificationBroadcasterSupport"); MethodSignature mainMethodSignature = - JavaIdentifierFactory.getInstance() - .getMethodSignature( - mainClassSignature, - "", - "void", - Arrays.asList( - "java.util.concurrent.Executor", "javax.management.MBeanNotificationInfo[]")); + idf.getMethodSignature( + mainClassSignature, + "", + "void", + Arrays.asList( + "java.util.concurrent.Executor", "javax.management.MBeanNotificationInfo[]")); + + assertTrue(idf.isConstructorSubSignature(mainMethodSignature.getSubSignature())); final SootClass abstractClass = view.getClass(mainClassSignature).get(); diff --git a/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java b/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java index c434e537f57..95e70adc76d 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java +++ b/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java @@ -31,7 +31,6 @@ import sootup.core.cache.FullCache; import sootup.core.cache.provider.FullCacheProvider; import sootup.core.frontend.AbstractClassSource; -import sootup.core.frontend.ResolveException; import sootup.core.inputlocation.AnalysisInputLocation; import sootup.core.inputlocation.ClassLoadingOptions; import sootup.core.inputlocation.EmptyClassLoadingOptions; @@ -118,7 +117,7 @@ private boolean isPackageVisibleToModule( Optional moduleInfoOpt = getModuleInfo(packageName.getModuleSignature()); if (!moduleInfoOpt.isPresent()) { - throw new ResolveException("ModuleDescriptor not available."); + throw new IllegalStateException("ModuleDescriptor not available."); } JavaModuleInfo moduleInfo = moduleInfoOpt.get(); From 1b96a412f3ca4f8d9268ae4e618f2662a6efba64 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 21:19:00 +0100 Subject: [PATCH 38/39] enable hiding pr previews in the version selector --- .github/workflows/gh-pages.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index f82c892aa79..c0f4757b04b 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -76,8 +76,7 @@ jobs: # on PR events.. - name: deploy doc in subdirectory if: github.event_name == 'pull_request' - run: mike deploy ${{ env.DOC_VERSION_NAME }}_preview --push - # TODO: set to true when the release is capable of the documentation ;) && mike props ${{ env.DOC_VERSION_NAME }}_preview --set-string hidden=true --push + run: mike deploy ${{ env.DOC_VERSION_NAME }}_preview && mike props ${{ env.DOC_VERSION_NAME }}_preview --set-string hidden=true --push - name: comment link to preview if: github.event_name == 'pull_request' && github.event.action != 'closed' From 888358e284307dc29c6efee8e76c65d72b183291 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 23 Nov 2023 21:35:39 +0100 Subject: [PATCH 39/39] title for preview --- .github/workflows/gh-pages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index c0f4757b04b..501160c33d5 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -76,7 +76,7 @@ jobs: # on PR events.. - name: deploy doc in subdirectory if: github.event_name == 'pull_request' - run: mike deploy ${{ env.DOC_VERSION_NAME }}_preview && mike props ${{ env.DOC_VERSION_NAME }}_preview --set-string hidden=true --push + run: mike deploy ${{ env.DOC_VERSION_NAME }}_preview -t "PR Preview ${{ env.DOC_VERSION_NAME }}" && mike props ${{ env.DOC_VERSION_NAME }}_preview --set-string hidden=true --push - name: comment link to preview if: github.event_name == 'pull_request' && github.event.action != 'closed'