|
| 1 | +package com.bumptech.glide.annotation.compiler; |
| 2 | + |
| 3 | +import static com.google.testing.compile.Compiler.javac; |
| 4 | + |
| 5 | +import com.bumptech.glide.annotation.compiler.test.CompilationProvider; |
| 6 | +import com.google.testing.compile.Compilation; |
| 7 | +import com.google.testing.compile.CompilationSubject; |
| 8 | +import com.google.testing.compile.JavaFileObjects; |
| 9 | +import java.io.File; |
| 10 | +import java.io.IOException; |
| 11 | +import javax.tools.JavaFileObject; |
| 12 | +import org.junit.Before; |
| 13 | +import org.junit.Rule; |
| 14 | +import org.junit.Test; |
| 15 | +import org.junit.rules.TemporaryFolder; |
| 16 | +import org.junit.runner.RunWith; |
| 17 | +import org.junit.runners.JUnit4; |
| 18 | + |
| 19 | +/** |
| 20 | + * Makes sure that we can handle indexers based on long package or file names, or many modules. |
| 21 | + * |
| 22 | + * <p>See #4106. |
| 23 | + */ |
| 24 | +@RunWith(JUnit4.class) |
| 25 | +public class OverlyLongFileNameTest implements CompilationProvider { |
| 26 | + @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); |
| 27 | + private Compilation compilation; |
| 28 | + private static final String FILE_NAME_LONGER_THAN_255_CHARS = |
| 29 | + "SomeReallyReallyRidiculouslyLongFileNameOrPackageNameIGuessThatExceedsTwoHundredAndFiftyFive" |
| 30 | + + "CharactersThoughThatsOnlyAroundOneHundredCharactersWhichMeansINeedToKeepTypingToGetTo" |
| 31 | + + "TwoHundredAndFiftyFiveSomehowThankfullyOnlyLikeFiftyToGoNowMaybeButNotQuiteYet" |
| 32 | + + "SomewhereAroundNowIsProbablyGood"; |
| 33 | + |
| 34 | + @Before |
| 35 | + public void setUp() { |
| 36 | + compilation = |
| 37 | + javac() |
| 38 | + .withProcessors(new GlideAnnotationProcessor()) |
| 39 | + .compile( |
| 40 | + JavaFileObjects.forSourceLines( |
| 41 | + FILE_NAME_LONGER_THAN_255_CHARS, |
| 42 | + "package com.bumptech.glide.test;", |
| 43 | + "import com.bumptech.glide.annotation.GlideModule;", |
| 44 | + "import com.bumptech.glide.module.LibraryGlideModule;", |
| 45 | + "@GlideModule", |
| 46 | + "public final class " |
| 47 | + + FILE_NAME_LONGER_THAN_255_CHARS |
| 48 | + + " extends LibraryGlideModule {}")); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void compilingLongClassAndOrPackageNameShouldSucceed() throws IOException { |
| 53 | + CompilationSubject.assertThat(compilation).succeededWithoutWarnings(); |
| 54 | + for (JavaFileObject file : compilation.generatedFiles()) { |
| 55 | + temporaryFolder.create(); |
| 56 | + String actualFileName = new File(file.getName()).getName(); |
| 57 | + if (!actualFileName.startsWith(FILE_NAME_LONGER_THAN_255_CHARS)) { |
| 58 | + try { |
| 59 | + temporaryFolder.newFile(actualFileName).createNewFile(); |
| 60 | + } catch (IOException e) { |
| 61 | + throw new RuntimeException("Failed to create: " + actualFileName, e); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public Compilation getCompilation() { |
| 69 | + return compilation; |
| 70 | + } |
| 71 | +} |
0 commit comments