Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input locations: check if specified path exists #740

Merged
merged 41 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
31ef68f
progress
swissiety Nov 3, 2023
22e9691
restructure if-else tree
swissiety Nov 3, 2023
5fb0649
path check for JavaSourcePathAnalysisInputLocation
swissiety Nov 3, 2023
18fa111
propagate SourceType into ModuleFinder and where it would flow from t…
swissiety Nov 3, 2023
ce7cd38
fix warFile path
swissiety Nov 3, 2023
10f26ba
revert / fix already existing temp dir
swissiety Nov 3, 2023
7fdba82
add recurring helper methods to MethodSubSignature
swissiety Nov 3, 2023
5f01499
add more info to exception
swissiety Nov 3, 2023
c259fe0
doc
swissiety Nov 6, 2023
e6311a8
Merge branch 'develop' into PathBasedAnalysisInputLocation_path_exist…
swissiety Nov 9, 2023
944e345
fix creating temp dir for warfiles
swissiety Nov 9, 2023
c8c8160
adapt testcases to DefaultRTJarAnalysisInputLocation; made it public
swissiety Nov 22, 2023
7c9ca1b
adapt isMain(...)
swissiety Nov 22, 2023
8cc7cfb
Merge branch 'develop' into PathBasedAnalysisInputLocation_path_exist…
swissiety Nov 22, 2023
a95e7e7
add license
swissiety Nov 22, 2023
6a8f0d7
adapt leftovers
swissiety Nov 22, 2023
303e04c
fix link to doc in auto comment
swissiety Nov 22, 2023
c24d88c
fix test
swissiety Nov 23, 2023
3321a68
fix test; remove method draft
swissiety Nov 23, 2023
6b4434b
make use of autoclosable
swissiety Nov 23, 2023
1e98066
sanitize branch name for doc
swissiety Nov 23, 2023
b1b9d58
sanitize all non alphanumeric branch/tag names
swissiety Nov 23, 2023
94eff49
trigger on config change
swissiety Nov 23, 2023
3975689
again
swissiety Nov 23, 2023
708cdfb
aaand again
swissiety Nov 23, 2023
20a1f0a
trigger ci
swissiety Nov 23, 2023
a8c0b80
trigger ci
swissiety Nov 23, 2023
3f4d842
trigger ci
swissiety Nov 23, 2023
81f28c0
trigger ci
swissiety Nov 23, 2023
2fc5e90
trigger ci
swissiety Nov 23, 2023
f399f15
trigger ci
swissiety Nov 23, 2023
c1e78dc
trigger ci
swissiety Nov 23, 2023
4921740
trigger ci
swissiety Nov 23, 2023
0a06a38
trigger ci
swissiety Nov 23, 2023
a6ea22d
cleanup typo
swissiety Nov 23, 2023
95cac41
not anymore
swissiety Nov 23, 2023
b6f1486
not anymore; refactored the java specifics froms sootclass
swissiety Nov 23, 2023
272762b
fix exception type
swissiety Nov 23, 2023
dcc2ac5
fixed tests
swissiety Nov 23, 2023
1b96a41
enable hiding pr previews in the version selector
swissiety Nov 23, 2023
888358e
title for preview
swissiety Nov 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- 'mkdocs.yml'
- 'sootup.examples/**'
- 'docs/**'
- '.github/workflows/gh-pages.yml'

release:
types: [ created, published ]
Expand All @@ -26,6 +27,7 @@ on:
- 'mkdocs.yml'
- 'sootup.examples/**'
- 'docs/**'
- '.github/workflows/gh-pages.yml'

concurrency: pages

Expand Down Expand Up @@ -63,35 +65,50 @@ 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=$(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..
- 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 ${{ 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 }}_preview/${{ github.head_ref }}/).
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 ${{ github.head_ref }}_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=$(echo ${{ github.ref_name }} | sed "s/[^[:alnum:]-]/_/g" )" >> $GITHUB_ENV

- name: deploy doc in subdirectory
if: github.event_name == 'release'
run: mike deploy ${{ env.DOC_VERSION_NAME }} --push


- name: deploy doc in subdirectory
if: github.event_name == 'release'
run: mike deploy ${{ github.ref_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 ${{ github.ref_name }} latest
run: mike deploy --push --update-aliases ${{ env.DOC_VERSION_NAME }} latest
4 changes: 1 addition & 3 deletions docs/call-graph-construction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand All @@ -35,9 +36,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 {
Expand Down Expand Up @@ -725,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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<JavaSootClass> view = javaProject.createView();
IdentifierFactory identifierFactory = view.getIdentifierFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* @author Ben Hermann
* @author Linghui Luo
*/
public interface AnalysisInputLocation<T extends AbstractClass> {
public interface AnalysisInputLocation<T extends AbstractClass<?>> {
/**
* Create or find a class source for a given type.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}

Expand Down Expand Up @@ -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<Path> 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) {
Expand Down Expand Up @@ -213,14 +212,9 @@ private List<AnalysisInputLocation<JavaSootClass>> explodeClassPath(@Nonnull Str
*/
private List<AnalysisInputLocation<JavaSootClass>> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading