Skip to content

Commit

Permalink
Merge pull request #740 from soot-oss/PathBasedAnalysisInputLocation_…
Browse files Browse the repository at this point in the history
…path_exists_for_all

input locations: check if specified path exists
  • Loading branch information
swissiety authored Nov 23, 2023
2 parents 0636d58 + 888358e commit 8169e2d
Show file tree
Hide file tree
Showing 34 changed files with 250 additions and 164 deletions.
26 changes: 20 additions & 6 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,6 +65,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=$(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'
Expand All @@ -71,27 +76,36 @@ 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 ${{ 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'
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
6 changes: 6 additions & 0 deletions sootup.core/src/main/java/sootup/core/IdentifierFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
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
9 changes: 4 additions & 5 deletions sootup.core/src/main/java/sootup/core/model/SootMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -208,10 +209,8 @@ public boolean isSynchronized() {
}

/** @return yes if this is the main method */
public boolean isMain() {
return isPublic()
&& isStatic()
&& getSignature().getSubSignature().toString().equals("void main(java.lang.String[])");
public boolean isMain(@Nonnull IdentifierFactory idf) {
return isPublic() && isStatic() && idf.isMainSubSignature(getSignature().getSubSignature());
}

/** We rely on the JDK class recognition to decide if a method is JDK method. */
Expand All @@ -228,7 +227,7 @@ public void toString(@Nonnull StmtPrinter printer) {
// print modifiers
final Set<MethodModifier> modifiers = getModifiers();
printer.modifier(MethodModifier.toString(modifiers));
if (modifiers.size() != 0) {
if (!modifiers.isEmpty()) {
printer.literal(" ");
}

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);
}
}
Loading

0 comments on commit 8169e2d

Please sign in to comment.