ProjectAnalyzer implements ArtifactAnalyzer { @Override @CheckReturnValue public ImmutableList<Suggestion> analyze(File projectDirectory) { File buildFile = new File(projectDirectory, Project.BUILD_GRADLE); Project project = buildFile.exists() ? Project.create(projectDirectory, null) : null; return analyzeProject( projectDirectory, project, projectDirectory, projectSuggesters, suggesters); } ProjectAnalyzer(
      ImmutableList<ProjectSuggester> projectSuggesters,
      ImmutableList<ProjectTreeSuggester> suggesters); @Override @CheckReturnValue ImmutableList<Suggestion> analyze(File projectDirectory);  }
@Test public void analyze_iteratesOverAppProject() throws Exception { ProjectAnalyzer analyzer = new ProjectAnalyzer(testProjectSuggesters, testSuggesters); File appProject = TestUtils.getTestDataFile(APP_PROJECT); GradleContext context = GradleContext.builder() .setMinSdkVersion(15) .setOnDemand(false) .setPluginType(GradleContext.PluginType.APPLICATION) .setProguardConfigs( ImmutableMap.of( "release", ProguardConfig.builder() .setMinifyEnabled(false) .setHasProguardRules(true) .build())) .setLibraryDependencies( ImmutableSet.of( Library.newBuilder() .setMavenLibrary( MavenLibrary.newBuilder() .setGroupId("com.google.inject") .setArtifactId("guice") .setVersion("3.0") .build()) .build(), Library.newBuilder() .setMavenLibrary( MavenLibrary.newBuilder() .setGroupId("com.android.support.constraint") .setArtifactId("constraint-layout") .setVersion("1.1.3") .build()) .build(), Library.newBuilder() .setMavenLibrary( MavenLibrary.newBuilder() .setGroupId("com.android.support") .setArtifactId("appcompat-v7") .setVersion("28.0.0") .build()) .build())) .setBundleConfig( BundleConfig.builder() .setBundleConfigLocation(BundleConfigLocation.builder().build()) .build()) .build(); Suggestion stubSuggestion = Suggestion.create( Suggestion.IssueType.WEBP, Suggestion.Category.WEBP, Payload.getDefaultInstance(), "Stub Suggestion", null, null); Suggestion stubArtifactSuggestion = Suggestion.create( Suggestion.IssueType.PROGUARD_NO_OBFUSCATION, Suggestion.Category.PROGUARD, Payload.getDefaultInstance(), "Stub Artifact Suggestion", null, null); suggester.setArtifactSuggestions(ImmutableMultimap.of(context, stubArtifactSuggestion)); suggester.setEntrySuggestions( ImmutableMultimap.of( ContextAndEntryPath.create(context, "src/main/AndroidManifest.xml"), stubSuggestion)); ImmutableList<Suggestion> suggestions = analyzer.analyze(appProject); assertThat(suggestions).containsExactly(stubSuggestion, stubArtifactSuggestion); assertThat(suggester.getAnalyzedEntries()) .containsExactlyElementsIn(filesUnderDirectory(appProject.toPath())); }
@Test public void analyze_iteratesOverRootProject() throws Exception { ProjectAnalyzer analyzer = new ProjectAnalyzer(testProjectSuggesters, testSuggesters); File rootProject = TestUtils.getTestDataFile(ROOT_PROJECT); GradleContext appContext = GradleContext.builder() .setMinSdkVersion(15) .setOnDemand(false) .setPluginType(GradleContext.PluginType.APPLICATION) .setProguardConfigs( ImmutableMap.of( "release", ProguardConfig.builder() .setMinifyEnabled(false) .setHasProguardRules(true) .build())) .setAndroidPluginVersion(AndroidPluginVersion.create("3.4.0")) .setLibraryDependencies( ImmutableSet.of( Library.newBuilder() .setMavenLibrary( MavenLibrary.newBuilder() .setGroupId("com.google.inject") .setArtifactId("guice") .setVersion("3.0") .build()) .build(), Library.newBuilder() .setMavenLibrary( MavenLibrary.newBuilder() .setGroupId("com.android.support.constraint") .setArtifactId("constraint-layout") .setVersion("1.1.3") .build()) .build(), Library.newBuilder() .setMavenLibrary( MavenLibrary.newBuilder() .setGroupId("com.android.support") .setArtifactId("appcompat-v7") .setVersion("28.0.0") .build()) .build())) .setBundleConfig( BundleConfig.builder() .setBundleConfigLocation(BundleConfigLocation.builder().build()) .build()) .build(); Suggestion stubSuggestion = Suggestion.create( Suggestion.IssueType.WEBP, Suggestion.Category.WEBP, Payload.getDefaultInstance(), "Stub Suggestion", null, null); suggester.setEntrySuggestions( ImmutableMultimap.of( ContextAndEntryPath.create(appContext, "app/src/main/AndroidManifest.xml"), stubSuggestion)); ImmutableList<Suggestion> suggestions = analyzer.analyze(rootProject); assertThat(suggestions).containsExactly(stubSuggestion); assertThat(suggester.getAnalyzedEntries()) .containsExactlyElementsIn(filesUnderDirectory(rootProject.toPath())); }
@Test public void analyze_ignoreNonProjectFiles() throws Exception { ProjectAnalyzer analyzer = new ProjectAnalyzer(testProjectSuggesters, testSuggesters); File appProject = TestUtils.getTestDataFile(IGNORABLE_FILES_PROJECT); ImmutableList<Suggestion> suggestions = analyzer.analyze(appProject); assertThat(suggestions).isEmpty(); assertThat(suggester.getAnalyzedEntries()).containsExactly("build.gradle"); }