Skip to content

Commit

Permalink
fix PathBasedInputLocation ctor #642 and cleanup related chaos
Browse files Browse the repository at this point in the history
  • Loading branch information
swissiety committed Jul 15, 2023
1 parent 889b9dd commit 0c275aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,39 +78,31 @@
public class PathBasedAnalysisInputLocation implements AnalysisInputLocation<JavaSootClass> {
protected Path path;

/**
* Variable to track if user has specified the SourceType. By default, it will be set to false.
*/
private SourceType srcType = null;

/**
* Variable to store AnalysisInputLocation, which can be DirectoryBasedAnalysisInputLocation,
* WarArchiveAnalysisInputLocation, MultiReleaseJarAnalysisInputLocation,
* ArchiveBasedAnalysisInputLocation
*/
PathBasedAnalysisInputLocation pathBasedAnalysisInputLocationObj;

public PathBasedAnalysisInputLocation getPathBasedAnalysisInputLocationObj() {
return pathBasedAnalysisInputLocationObj;
}
PathBasedAnalysisInputLocation inputLocation;

public PathBasedAnalysisInputLocation(@Nonnull Path path) {
this.path = path;
this(path, SourceType.Application);
}

public PathBasedAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType srcType) {
this.path = path;
if (Files.isDirectory(path)) {
pathBasedAnalysisInputLocationObj = new DirectoryBasedAnalysisInputLocation(path, srcType);
inputLocation = new DirectoryBasedAnalysisInputLocation(path, srcType);
} else if (PathUtils.isArchive(path)) {

if (PathUtils.hasExtension(path, FileType.WAR)) {
pathBasedAnalysisInputLocationObj = new WarArchiveAnalysisInputLocation(path, srcType);
inputLocation = new WarArchiveAnalysisInputLocation(path, srcType);
} else if (isMultiReleaseJar(path)) { // check if mainfest contains multi release flag
pathBasedAnalysisInputLocationObj = new MultiReleaseJarAnalysisInputLocation(path, srcType);
inputLocation = new MultiReleaseJarAnalysisInputLocation(path, srcType);
} else if (PathUtils.hasExtension(path, FileType.APK)) {
pathBasedAnalysisInputLocationObj = new ApkAnalysisInputLocation(path, srcType);
inputLocation = new ApkAnalysisInputLocation(path, srcType);
} else {
pathBasedAnalysisInputLocationObj = new ArchiveBasedAnalysisInputLocation(path, srcType);
inputLocation = new ArchiveBasedAnalysisInputLocation(path, srcType);
}
} else {
throw new IllegalArgumentException(
Expand All @@ -120,13 +112,8 @@ public PathBasedAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType s
}
}

/**
* The method sets the value of the variable srcType.
*
* @param srcType the source type for the path can be Library, Application, Phantom.
*/
public void setSpecifiedAsBuiltInByUser(@Nonnull SourceType srcType) {
this.srcType = srcType;
public PathBasedAnalysisInputLocation getInputLocation() {
return inputLocation;
}

/**
Expand All @@ -140,7 +127,7 @@ public void setSpecifiedAsBuiltInByUser(@Nonnull SourceType srcType) {
@Override
public Optional<? extends AbstractClassSource<JavaSootClass>> getClassSource(
@Nonnull ClassType type, @Nonnull View<?> view) {
return pathBasedAnalysisInputLocationObj.getClassSource(type, view);
return inputLocation.getClassSource(type, view);
}

/**
Expand All @@ -153,12 +140,12 @@ public Optional<? extends AbstractClassSource<JavaSootClass>> getClassSource(
@Override
public Collection<? extends AbstractClassSource<JavaSootClass>> getClassSources(
@Nonnull View<?> view) {
return pathBasedAnalysisInputLocationObj.getClassSources(view);
return inputLocation.getClassSources(view);
}

@Override
public SourceType getSourceType() {
return srcType;
return inputLocation.getSourceType();
}

private static boolean isMultiReleaseJar(Path path) {
Expand Down Expand Up @@ -234,8 +221,7 @@ protected Optional<? extends AbstractClassSource<JavaSootClass>> getClassSourceI
private static class DirectoryBasedAnalysisInputLocation extends PathBasedAnalysisInputLocation {

private DirectoryBasedAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType srcType) {
super(path);
super.setSpecifiedAsBuiltInByUser(srcType);
super(path, srcType);
}

@Override
Expand Down Expand Up @@ -575,8 +561,7 @@ private static class ArchiveBasedAnalysisInputLocation extends PathBasedAnalysis
}));

private ArchiveBasedAnalysisInputLocation(@Nonnull Path path, @Nullable SourceType srcType) {
super(path);
super.setSpecifiedAsBuiltInByUser(srcType);
super(path, srcType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ public void modularMultiReleaseJar() {
.enableModules()
.addInputLocation(
(ModuleInfoAnalysisInputLocation)
new PathBasedAnalysisInputLocation(mmrj, null)
.getPathBasedAnalysisInputLocationObj())
new PathBasedAnalysisInputLocation(mmrj, null).getInputLocation())
.build();

final JavaModuleView view_9 = project_9.createView();
Expand Down

0 comments on commit 0c275aa

Please sign in to comment.