-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix best guess related APT compiler crash with underscore in package …
…name.
- Loading branch information
1 parent
a1f5f10
commit 99723e3
Showing
5 changed files
with
175 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...t/java/com/bumptech/glide/annotation/compiler/AppGlideModuleWithLibraryInPackageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.bumptech.glide.annotation.compiler; | ||
|
||
import static com.bumptech.glide.annotation.compiler.test.Util.appResource; | ||
import static com.bumptech.glide.annotation.compiler.test.Util.asUnixChars; | ||
import static com.bumptech.glide.annotation.compiler.test.Util.glide; | ||
import static com.bumptech.glide.annotation.compiler.test.Util.subpackage; | ||
import static com.google.testing.compile.CompilationSubject.assertThat; | ||
import static com.google.testing.compile.Compiler.javac; | ||
|
||
import com.bumptech.glide.annotation.compiler.test.ReferencedResource; | ||
import com.bumptech.glide.annotation.compiler.test.RegenerateResourcesRule; | ||
import com.bumptech.glide.annotation.compiler.test.Util; | ||
import com.google.testing.compile.Compilation; | ||
import java.io.IOException; | ||
import javax.tools.JavaFileObject; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
/** | ||
* Tests AppGlideModules that use the @Excludes annotation | ||
* with a single excluded Module class in a strangely named subpackage. | ||
*/ | ||
@RunWith(JUnit4.class) | ||
public class AppGlideModuleWithLibraryInPackageTest { | ||
@Rule public final RegenerateResourcesRule regenerateResourcesRule = | ||
new RegenerateResourcesRule(getClass()); | ||
private Compilation compilation; | ||
|
||
@Before | ||
public void setUp() { | ||
compilation = | ||
javac() | ||
.withProcessors(new GlideAnnotationProcessor()) | ||
.compile( | ||
forResource("AppModuleWithLibraryInPackage.java"), | ||
forResource("LibraryModuleInPackage.java")); | ||
assertThat(compilation).succeededWithoutWarnings(); | ||
} | ||
|
||
@Test | ||
@ReferencedResource | ||
public void compilation_generatesExpectedGlideOptionsClass() throws IOException { | ||
assertThat(compilation) | ||
.generatedSourceFile(subpackage("GlideOptions")) | ||
.contentsAsUtf8String() | ||
.isEqualTo(asUnixChars(appResource("GlideOptions.java").getCharContent(true))); | ||
} | ||
|
||
@Test | ||
@ReferencedResource | ||
public void compilation_generatesExpectedGlideRequestClass() throws IOException { | ||
assertThat(compilation) | ||
.generatedSourceFile(subpackage("GlideRequest")) | ||
.contentsAsUtf8String() | ||
.isEqualTo(asUnixChars(appResource("GlideRequest.java").getCharContent(true))); | ||
} | ||
|
||
@Test | ||
@ReferencedResource | ||
public void compilation_generatesExpectedGlideRequestsClass() throws IOException { | ||
assertThat(compilation) | ||
.generatedSourceFile(subpackage("GlideRequests")) | ||
.contentsAsUtf8String() | ||
.isEqualTo(asUnixChars(appResource("GlideRequests.java").getCharContent(true))); | ||
} | ||
|
||
@Test | ||
@ReferencedResource | ||
public void compilationGeneratesExpectedGlideAppClass() throws IOException { | ||
assertThat(compilation) | ||
.generatedSourceFile(subpackage("GlideApp")) | ||
.contentsAsUtf8String() | ||
.isEqualTo(asUnixChars(appResource("GlideApp.java").getCharContent(true))); | ||
} | ||
|
||
@Test | ||
public void compilation_generatesExpectedGeneratedAppGlideModuleImpl() throws IOException { | ||
assertThat(compilation) | ||
.generatedSourceFile(glide("GeneratedAppGlideModuleImpl")) | ||
.contentsAsUtf8String() | ||
.isEqualTo( | ||
asUnixChars(forResource("GeneratedAppGlideModuleImpl.java").getCharContent(true))); | ||
} | ||
|
||
@Test | ||
@ReferencedResource | ||
public void compilation_generatesExpectedGeneratedRequestManagerFactory() throws IOException { | ||
assertThat(compilation) | ||
.generatedSourceFile(glide("GeneratedRequestManagerFactory")) | ||
.contentsAsUtf8String() | ||
.isEqualTo( | ||
asUnixChars(appResource("GeneratedRequestManagerFactory.java").getCharContent(true))); | ||
} | ||
|
||
private JavaFileObject forResource(String name) { | ||
return Util.forResource(getClass().getSimpleName(), name); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
.../test/resources/AppGlideModuleWithLibraryInPackageTest/AppModuleWithLibraryInPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.bumptech.glide.test; | ||
|
||
import com.bumptech.glide.annotation.Excludes; | ||
import com.bumptech.glide.annotation.GlideModule; | ||
import com.bumptech.glide.module.AppGlideModule; | ||
import com.bumptech.glide.test._package.LibraryModuleInPackage; | ||
|
||
@GlideModule | ||
@Excludes(LibraryModuleInPackage.class) | ||
public final class AppModuleWithLibraryInPackage extends AppGlideModule {} |
54 changes: 54 additions & 0 deletions
54
...rc/test/resources/AppGlideModuleWithLibraryInPackageTest/GeneratedAppGlideModuleImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.bumptech.glide; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.NonNull; | ||
import android.util.Log; | ||
import com.bumptech.glide.test.AppModuleWithLibraryInPackage; | ||
import java.lang.Class; | ||
import java.lang.Override; | ||
import java.lang.SuppressWarnings; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@SuppressWarnings("deprecation") | ||
final class GeneratedAppGlideModuleImpl extends GeneratedAppGlideModule { | ||
private final AppModuleWithLibraryInPackage appGlideModule; | ||
|
||
GeneratedAppGlideModuleImpl() { | ||
appGlideModule = new AppModuleWithLibraryInPackage(); | ||
if (Log.isLoggable("Glide", Log.DEBUG)) { | ||
Log.d("Glide", "Discovered AppGlideModule from annotation: com.bumptech.glide.test.AppModuleWithLibraryInPackage"); | ||
Log.d("Glide", "AppGlideModule excludes LibraryGlideModule from annotation: com.bumptech.glide.test._package.LibraryModuleInPackage"); | ||
} | ||
} | ||
|
||
@Override | ||
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) { | ||
appGlideModule.applyOptions(context, builder); | ||
} | ||
|
||
@Override | ||
public void registerComponents(@NonNull Context context, @NonNull Glide glide, | ||
@NonNull Registry registry) { | ||
appGlideModule.registerComponents(context, glide, registry); | ||
} | ||
|
||
@Override | ||
public boolean isManifestParsingEnabled() { | ||
return appGlideModule.isManifestParsingEnabled(); | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public Set<Class<?>> getExcludedModuleClasses() { | ||
Set<Class<?>> excludedClasses = new HashSet<Class<?>>(); | ||
excludedClasses.add(com.bumptech.glide.test._package.LibraryModuleInPackage.class); | ||
return excludedClasses; | ||
} | ||
|
||
@Override | ||
@NonNull | ||
GeneratedRequestManagerFactory getRequestManagerFactory() { | ||
return new GeneratedRequestManagerFactory(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...est/src/test/resources/AppGlideModuleWithLibraryInPackageTest/LibraryModuleInPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// _ in the name is important otherwise everything would work | ||
package com.bumptech.glide.test._package; | ||
|
||
import com.bumptech.glide.annotation.GlideModule; | ||
import com.bumptech.glide.module.LibraryGlideModule; | ||
|
||
@GlideModule | ||
public final class LibraryModuleInPackage extends LibraryGlideModule {} |