aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps
diff options
context:
space:
mode:
authorGravatar cnsun <cnsun@google.com>2018-04-13 14:54:10 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-13 14:55:26 -0700
commit40f91b00a88554de7adcff7b24e8b1902289ca6d (patch)
tree29a8749edd4b454d152c40ee4d51eab45999a95b /src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps
parente4e8e9ef4e4e56b7abfa5bdb20182c983e8247d3 (diff)
Split the single classpath (combining bootclasspath and regular classpath
together) into two separate classpaths. This is the preparation cl. In the following cls, I will graduately make the dependency issues clear, i.e., wether it is a problem in the bootclasspath or the regular classpath. RELNOTES: n/a. PiperOrigin-RevId: 192828237
Diffstat (limited to 'src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps')
-rw-r--r--src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/ClassCacheTest.java62
-rw-r--r--src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/DepsCheckerClassVisitorTest.java2
2 files changed, 56 insertions, 8 deletions
diff --git a/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/ClassCacheTest.java b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/ClassCacheTest.java
index 8049621449..a7cb666291 100644
--- a/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/ClassCacheTest.java
+++ b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/ClassCacheTest.java
@@ -19,7 +19,12 @@ import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.importdeps.AbstractClassEntryState.ExistingState;
+import com.google.devtools.build.importdeps.ClassCache.LazyClassEntry;
+import com.google.devtools.build.importdeps.ClassCache.LazyClasspath;
+import com.google.devtools.build.importdeps.ClassInfo.MemberInfo;
import java.io.IOException;
+import java.util.Optional;
+import java.util.stream.Collectors;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -30,7 +35,8 @@ public class ClassCacheTest extends AbstractClassCacheTest {
@Test
public void testLibraryJar() throws Exception {
- try (ClassCache cache = new ClassCache(bootclasspath, libraryJar)) {
+ try (ClassCache cache =
+ new ClassCache(ImmutableList.of(bootclasspath), ImmutableList.of(libraryJar))) {
assertCache(
cache,
libraryJarPositives,
@@ -44,7 +50,9 @@ public class ClassCacheTest extends AbstractClassCacheTest {
@Test
public void testClientJarWithSuperClasses() throws IOException {
try (ClassCache cache =
- new ClassCache(bootclasspath, clientJar, libraryJar, libraryInterfaceJar)) {
+ new ClassCache(
+ ImmutableList.of(bootclasspath),
+ ImmutableList.of(clientJar, libraryJar, libraryInterfaceJar))) {
assertCache(
cache,
clientJarPositives,
@@ -54,7 +62,8 @@ public class ClassCacheTest extends AbstractClassCacheTest {
@Test
public void testClientJarWithoutSuperClasses() throws IOException {
- try (ClassCache cache = new ClassCache(bootclasspath, clientJar)) {
+ try (ClassCache cache =
+ new ClassCache(ImmutableList.of(bootclasspath), ImmutableList.of(clientJar))) {
// Client should be incomplete, as its parent class and interfaces are not available on the
// classpath. The following is the resolution path.
{
@@ -76,7 +85,8 @@ public class ClassCacheTest extends AbstractClassCacheTest {
@Test
public void testLibraryException() throws IOException {
- try (ClassCache cache = new ClassCache(bootclasspath, libraryExceptionJar)) {
+ try (ClassCache cache =
+ new ClassCache(ImmutableList.of(bootclasspath), ImmutableList.of(libraryExceptionJar))) {
assertCache(
cache,
libraryExceptionJarPositives,
@@ -86,7 +96,8 @@ public class ClassCacheTest extends AbstractClassCacheTest {
@Test
public void testLibraryAnnotations() throws IOException {
- try (ClassCache cache = new ClassCache(bootclasspath, libraryAnnotationsJar)) {
+ try (ClassCache cache =
+ new ClassCache(ImmutableList.of(bootclasspath), ImmutableList.of(libraryAnnotationsJar))) {
assertCache(
cache,
libraryAnnotationsJarPositives,
@@ -96,7 +107,7 @@ public class ClassCacheTest extends AbstractClassCacheTest {
@Test
public void testCannotAccessClosedCache() throws IOException {
- ClassCache cache = new ClassCache(ImmutableList.of());
+ ClassCache cache = new ClassCache(ImmutableList.of(), ImmutableList.of());
cache.close();
cache.close(); // Can close multiple times.
assertThrows(IllegalStateException.class, () -> cache.getClassState("empty"));
@@ -110,7 +121,9 @@ public class ClassCacheTest extends AbstractClassCacheTest {
public void testSuperNotExistThenSubclassNotExist() throws IOException {
try (ClassCache cache =
new ClassCache(
- libraryJar, libraryJar, libraryAnnotationsJar, libraryInterfaceJar, clientJar)) {
+ ImmutableList.of(),
+ ImmutableList.of(
+ libraryJar, libraryJar, libraryAnnotationsJar, libraryInterfaceJar, clientJar))) {
assertThat(
cache
.getClassState("com/google/devtools/build/importdeps/testdata/Library$Class9")
@@ -124,6 +137,41 @@ public class ClassCacheTest extends AbstractClassCacheTest {
}
}
+ @Test
+ public void testLazyClasspathLoadsBootclasspathFirst() throws IOException {
+ {
+ LazyClasspath classpath =
+ new LazyClasspath(ImmutableList.of(libraryJar), ImmutableList.of(libraryWoMembersJar));
+ LazyClassEntry entry =
+ classpath.getLazyEntry("com/google/devtools/build/importdeps/testdata/Library$Class4");
+ AbstractClassEntryState state = entry.getState(classpath);
+ Optional<ClassInfo> classInfo = state.classInfo();
+ assertThat(classInfo.isPresent()).isTrue();
+ assertThat(classInfo.get().declaredMembers()).hasSize(2);
+ assertThat(
+ classInfo
+ .get()
+ .declaredMembers()
+ .stream()
+ .map(MemberInfo::memberName)
+ .collect(Collectors.toSet()))
+ .containsExactly("<init>", "createClass5");
+ }
+ {
+ LazyClasspath classpath =
+ new LazyClasspath(ImmutableList.of(libraryWoMembersJar), ImmutableList.of(libraryJar));
+ LazyClassEntry entry =
+ classpath.getLazyEntry("com/google/devtools/build/importdeps/testdata/Library$Class4");
+ AbstractClassEntryState state = entry.getState(classpath);
+ Optional<ClassInfo> classInfo = state.classInfo();
+ assertThat(classInfo.isPresent()).isTrue();
+ // The empty class has a default constructor.
+ assertThat(classInfo.get().declaredMembers()).hasSize(1);
+ assertThat(classInfo.get().declaredMembers().iterator().next().memberName())
+ .isEqualTo("<init>");
+ }
+ }
+
private void assertCache(
ClassCache cache, ImmutableList<String> positives, ImmutableList<String> negatives) {
for (String positive : positives) {
diff --git a/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/DepsCheckerClassVisitorTest.java b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/DepsCheckerClassVisitorTest.java
index 277fd808a4..089e3c2e6d 100644
--- a/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/DepsCheckerClassVisitorTest.java
+++ b/src/java_tools/import_deps_checker/javatests/com/google/devtools/build/importdeps/DepsCheckerClassVisitorTest.java
@@ -109,7 +109,7 @@ public class DepsCheckerClassVisitorTest extends AbstractClassCacheTest {
ImmutableList<String> clientClasses =
ImmutableList.of(PACKAGE_NAME + "Client", PACKAGE_NAME + "Client$NestedAnnotation");
ResultCollector resultCollector = new ResultCollector();
- try (ClassCache cache = new ClassCache(ImmutableList.copyOf(classpath));
+ try (ClassCache cache = new ClassCache(ImmutableList.copyOf(classpath), ImmutableList.of());
ZipFile zipFile = new ZipFile(clientJar.toFile())) {
assertThat(cache.getClassState("java/lang/invoke/LambdaMetafactory").isExistingState())
.isTrue();