Skip to content

Commit

Permalink
test getClasses; fix typo in ignored Path
Browse files Browse the repository at this point in the history
  • Loading branch information
swissiety committed Jan 30, 2024
1 parent 5922dec commit 564bba0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public Optional<JavaClassType> resolveSuperclass() {
if (classNode.superName == null) {
return Optional.empty();
}
return Optional.ofNullable(AsmUtil.toJimpleClassType(classNode.superName));
return Optional.of(AsmUtil.toJimpleClassType(classNode.superName));
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public Collection<JavaSootClassSource> getClassSources(@Nonnull View view) {
Collection<ModuleSignature> allModules = moduleFinder.getAllModules();
return allModules.stream()
.flatMap(sig -> getClassSourcesInternal(sig, view))
.map(src -> (JavaSootClassSource) src)
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static AnalysisInputLocation create(
}

return PathBasedAnalysisInputLocation.create(
path, srcType, bodyInterceptors, Collections.singletonList(Paths.get("/META_INF")));
path, srcType, bodyInterceptors, Collections.singletonList(Paths.get("/META-INF")));

Check warning on line 79 in sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/MultiReleaseJarAnalysisInputLocation.java

View check run for this annotation

Codecov / codecov/patch

sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/MultiReleaseJarAnalysisInputLocation.java#L78-L79

Added lines #L78 - L79 were not covered by tests
}

public MultiReleaseJarAnalysisInputLocation(@Nonnull Path path, @Nonnull Language language) {
Expand Down Expand Up @@ -155,7 +155,7 @@ protected AnalysisInputLocation createAnalysisInputLocation(
archiveRoot,
sourceType,
bodyInterceptors,
Collections.singletonList(Paths.get("/META_INF")));
Collections.singletonList(Paths.get("/META-INF")));
}

@Override
Expand All @@ -179,8 +179,7 @@ public Collection<JavaSootClassSource> getClassSources(@Nonnull View view) {

Collection<JavaSootClassSource> classSources = new ArrayList<>();
inputLocations.values().stream()
.map(location -> location.getClassSources(view))
.flatMap(Collection::stream)
.flatMap(location -> location.getClassSources(view).stream())
.map(src -> (JavaSootClassSource) src)
.forEach(
cs -> {
Expand Down Expand Up @@ -235,7 +234,7 @@ public List<BodyInterceptor> getBodyInterceptors() {
}

/**
* lists all versions from the version directories inside the META_INF/ directory - excluding the
* lists all versions from the version directories inside the META-INF/ directory - excluding the
* default implemention version
*/
protected static List<Integer> getLanguageVersions(@Nonnull Path path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ public static PathBasedAnalysisInputLocation create(
@Nonnull SourceType srcType,
@Nonnull List<BodyInterceptor> bodyInterceptors,
@Nonnull Collection<Path> ignoredPaths) {

if(ignoredPaths.stream().anyMatch( ignoPath -> path.toString().startsWith(ignoPath.toString()) )){
throw new IllegalArgumentException("The Path for the AnalysisInputLocation is in the ignored paths.");

Check warning on line 133 in sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java

View check run for this annotation

Codecov / codecov/patch

sootup.java.bytecode/src/main/java/sootup/java/bytecode/inputlocation/PathBasedAnalysisInputLocation.java#L133

Added line #L133 was not covered by tests
}

if (Files.isDirectory(path)) {
return new DirectoryBasedAnalysisInputLocation(path, srcType, bodyInterceptors, ignoredPaths);
} else if (PathUtils.isArchive(path)) {
Expand Down Expand Up @@ -157,12 +162,10 @@ Collection<JavaSootClassSource> walkDirectory(
final String moduleInfoFilename = JavaModuleIdentifierFactory.MODULE_INFO_FILE + ".class";
try (final Stream<Path> walk = Files.walk(dirPath)) {
return walk.filter(
filePath ->
ignoredPaths.stream()
.map(Path::toString)
.noneMatch(p -> filePath.toString().startsWith(p))
&& PathUtils.hasExtension(filePath, handledFileType)
&& !filePath.toString().endsWith(moduleInfoFilename))
filePath -> PathUtils.hasExtension(filePath, handledFileType)
&& !filePath.toString().endsWith(moduleInfoFilename)
&& ignoredPaths.stream().noneMatch(p -> filePath.toString().startsWith(p.toString()))
)
.flatMap(
p -> {
final String fullyQualifiedName = fromPath(dirPath, p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,22 @@
* #L%
*/

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import categories.Java8Test;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import sootup.core.model.SourceType;
import sootup.core.signatures.MethodSubSignature;
import sootup.core.types.ClassType;
import sootup.java.core.language.JavaLanguage;
import sootup.java.core.views.JavaView;
Expand Down Expand Up @@ -86,16 +91,17 @@ public void multiReleaseJar() {
"/de/upb/sse/multirelease/Main.class",
view_8.getClass(classType2).get().getClassSource().getSourcePath().toString());
// assert that method is correctly resolved to base
MethodSubSignature printBodyMethodSubSig = getIdentifierFactory()
.getMethodSubSignature(
"printVersion",
getIdentifierFactory().getType("void"),
Collections.emptyList());
Assert.assertTrue(
view_8
.getClass(classType)
.get()
.getMethod(
getIdentifierFactory()
.getMethodSubSignature(
"printVersion",
getIdentifierFactory().getType("void"),
Collections.emptyList()))
printBodyMethodSubSig)
.get()
.getBody()
.toString()
Expand Down Expand Up @@ -123,11 +129,7 @@ public void multiReleaseJar() {
.getClass(classType)
.get()
.getMethod(
getIdentifierFactory()
.getMethodSubSignature(
"printVersion",
getIdentifierFactory().getType("void"),
Collections.emptyList()))
printBodyMethodSubSig)
.get()
.getBody()
.toString()
Expand All @@ -148,6 +150,17 @@ public void multiReleaseJar() {
Assert.assertEquals(
"/de/upb/sse/multirelease/Main.class",
view_max.getClass(classType2).get().getClassSource().getSourcePath().toString());


// getClasses
List<String> collectedClassesWPrintBody9 = view_9.getClasses().stream().map(c -> c.getMethod(printBodyMethodSubSig)).filter(Optional::isPresent).map(m -> m.get().getBody().toString()).collect(Collectors.toList());
assertEquals(1, collectedClassesWPrintBody9.size());
assertTrue(collectedClassesWPrintBody9.get(0).contains("java 9"));

List<String> collectedClassesWPrintBody10 = view_10.getClasses().stream().map(c -> c.getMethod(printBodyMethodSubSig)).filter(Optional::isPresent).map(m -> m.get().getBody().toString()).collect(Collectors.toList());
assertEquals(1, collectedClassesWPrintBody10.size());
assertTrue(collectedClassesWPrintBody10.get(0).contains("java 10"));

}

@Test
Expand Down

0 comments on commit 564bba0

Please sign in to comment.