Skip to content

Commit

Permalink
CLM-18367 Include runtime dependencies as the IQ Maven plugin does (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillermo-varela authored Apr 28, 2021
1 parent 558e877 commit 158317f
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Gradle can be used to build projects developed in various programming languages.
- Edit its `build.gradle` file adding this:
```
plugins {
id 'org.sonatype.gradle.plugins.scan' version '2.0.6' // Update the version as needed
id 'org.sonatype.gradle.plugins.scan' version '2.0.9' // Update the version as needed
}
```

Expand All @@ -72,7 +72,7 @@ on this plugin. Cache can also be configured optionally.
ossIndexAudit {
username = 'email' // if not provided, an anonymous query will be made
password = 'pass'
allConfigurations = true // if true includes the dependencies in all resolvable configurations. By default is false, meaning only 'compileClasspath' and 'releaseCompileClasspath' are considered
allConfigurations = true // if true includes the dependencies in all resolvable configurations. By default is false, meaning only 'compileClasspath', 'runtimeClasspath', 'releaseCompileClasspath' and 'releaseRuntimeClasspath' are considered
useCache = true // true by default
cacheDirectory = 'some/path' // by default it uses the user data directory (according to OS)
cacheExpiration = 'PT12H' // 12 hours if omitted. It must follow the Joda Time specification at https://www.javadoc.io/doc/joda-time/joda-time/2.10.4/org/joda/time/Duration.html#parse-java.lang.String-
Expand Down Expand Up @@ -106,7 +106,7 @@ nexusIQScan {
serverUrl = 'http://localhost:8070'
applicationId = 'app'
stage = 'build' // build is used if omitted
allConfigurations = true // if true includes the dependencies in all resolvable configurations. By default is false, meaning only 'compileClasspath' and 'releaseCompileClasspath' are considered
allConfigurations = true // if true includes the dependencies in all resolvable configurations. By default is false, meaning only 'compileClasspath', 'runtimeClasspath', 'releaseCompileClasspath' and 'releaseRuntimeClasspath' are considered
resultFilePath = 'results.json' // Optional. JSON file containing results of the evaluation
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,29 @@
import org.gradle.internal.impldep.com.google.common.annotations.VisibleForTesting;

import static org.gradle.api.plugins.JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME;
import static org.gradle.api.plugins.JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME;

public class DependenciesFinder
{
private static final String RELEASE_COMPILE_LEGACY_CONFIGURATION_NAME = "_releaseCompile";

private static final String RELEASE_RUNTIME_APK_LEGACY_CONFIGURATION_NAME = "_releaseApk";

private static final String RELEASE_RUNTIME_LIBRARY_LEGACY_CONFIGURATION_NAME = "_releasePublish";

private static final String RELEASE_COMPILE_CONFIGURATION_NAME = "releaseCompileClasspath";

private static final String RELEASE_RUNTIME_CONFIGURATION_NAME = "releaseRuntimeClasspath";

private static final Set<String> CONFIGURATION_NAMES =
new HashSet<>(Arrays.asList(
COMPILE_CLASSPATH_CONFIGURATION_NAME,
RUNTIME_CLASSPATH_CONFIGURATION_NAME,
RELEASE_COMPILE_LEGACY_CONFIGURATION_NAME,
RELEASE_COMPILE_CONFIGURATION_NAME));
RELEASE_RUNTIME_APK_LEGACY_CONFIGURATION_NAME,
RELEASE_RUNTIME_LIBRARY_LEGACY_CONFIGURATION_NAME,
RELEASE_COMPILE_CONFIGURATION_NAME,
RELEASE_RUNTIME_CONFIGURATION_NAME));

private static final String COPY_CONFIGURATION_NAME = "sonatypeCopyConfiguration";

Expand Down Expand Up @@ -186,6 +197,9 @@ private boolean isAcceptableConfiguration(Configuration configuration, boolean a
}
return configuration.isCanBeResolved() && (CONFIGURATION_NAMES.contains(configuration.getName())
|| StringUtils.endsWithIgnoreCase(configuration.getName(), RELEASE_COMPILE_LEGACY_CONFIGURATION_NAME)
|| StringUtils.endsWithIgnoreCase(configuration.getName(), RELEASE_COMPILE_CONFIGURATION_NAME));
|| StringUtils.endsWithIgnoreCase(configuration.getName(), RELEASE_RUNTIME_APK_LEGACY_CONFIGURATION_NAME)
|| StringUtils.endsWithIgnoreCase(configuration.getName(), RELEASE_RUNTIME_LIBRARY_LEGACY_CONFIGURATION_NAME)
|| StringUtils.endsWithIgnoreCase(configuration.getName(), RELEASE_COMPILE_CONFIGURATION_NAME)
|| StringUtils.endsWithIgnoreCase(configuration.getName(), RELEASE_RUNTIME_CONFIGURATION_NAME));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.gradle.api.plugins.JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME;
import static org.gradle.api.plugins.JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME;
import static org.gradle.api.plugins.JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -60,33 +61,82 @@ public void testFindResolvedDependencies_includeCompileDependencies() {
}

@Test
public void testFindResolvedDependencies_includeLegacyAndroidDependencies() {
public void testFindResolvedDependencies_includeRuntimeDependencies() {
Project project = buildProject(RUNTIME_CLASSPATH_CONFIGURATION_NAME, false);
Set<ResolvedDependency> result = finder.findResolvedDependencies(project, false);
assertThat(result).hasSize(1);
}

@Test
public void testFindResolvedDependencies_includeLegacyCompileAndroidDependencies() {
Project project = buildProject("_releaseCompile", true);
Set<ResolvedDependency> result = finder.findResolvedDependencies(project, false);
assertThat(result).hasSize(1);
}

@Test
public void testFindResolvedDependencies_includeAndroidDependencies() {
public void testFindResolvedDependencies_includeLegacyRuntimeApkAndroidDependencies() {
Project project = buildProject("_releaseApk", true);
Set<ResolvedDependency> result = finder.findResolvedDependencies(project, false);
assertThat(result).hasSize(1);
}

@Test
public void testFindResolvedDependencies_includeLegacyRuntimeLibraryAndroidDependencies() {
Project project = buildProject("_releasePublish", true);
Set<ResolvedDependency> result = finder.findResolvedDependencies(project, false);
assertThat(result).hasSize(1);
}

@Test
public void testFindResolvedDependencies_includeCompileAndroidDependencies() {
Project project = buildProject("releaseCompileClasspath", true);
Set<ResolvedDependency> result = finder.findResolvedDependencies(project, false);
assertThat(result).hasSize(1);
}

@Test
public void testFindResolvedDependencies_includeLegacyAndroidDependenciesUsingVariant() {
public void testFindResolvedDependencies_includeRuntimeAndroidDependencies() {
Project project = buildProject("releaseRuntimeClasspath", true);
Set<ResolvedDependency> result = finder.findResolvedDependencies(project, false);
assertThat(result).hasSize(1);
}

@Test
public void testFindResolvedDependencies_includeLegacyCompileApkAndroidDependenciesUsingVariant() {
Project project = buildProject("variantProd_ReleaseCompile", true);
Set<ResolvedDependency> result = finder.findResolvedDependencies(project, false);
assertThat(result).hasSize(1);
}

@Test
public void testFindResolvedDependencies_includeAndroidDependenciesUsingVariant() {
public void testFindResolvedDependencies_includeLegacyRuntimeApkAndroidDependenciesUsingVariant() {
Project project = buildProject("variantProd_ReleaseApk", true);
Set<ResolvedDependency> result = finder.findResolvedDependencies(project, false);
assertThat(result).hasSize(1);
}

@Test
public void testFindResolvedDependencies_includeLegacyRuntimeLibraryAndroidDependenciesUsingVariant() {
Project project = buildProject("variantProd_ReleasePublish", true);
Set<ResolvedDependency> result = finder.findResolvedDependencies(project, false);
assertThat(result).hasSize(1);
}

@Test
public void testFindResolvedDependencies_includeAndroidCompileDependenciesUsingVariant() {
Project project = buildProject("variantProdReleaseCompileClasspath", true);
Set<ResolvedDependency> result = finder.findResolvedDependencies(project, false);
assertThat(result).hasSize(1);
}

@Test
public void testFindResolvedDependencies_includeAndroidRuntimeDependenciesUsingVariant() {
Project project = buildProject("variantProdReleaseRuntimeClasspath", true);
Set<ResolvedDependency> result = finder.findResolvedDependencies(project, false);
assertThat(result).hasSize(1);
}

@Test
public void testFindResolvedDependencies_omitTestDependencies() {
Project project = buildProject(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME, false);
Expand All @@ -109,12 +159,26 @@ public void testFindResolvedArtifacts_includeCompileDependencies() {
}

@Test
public void testFindResolvedArtifacts_includeAndroidDependencies() {
public void testFindResolvedArtifacts_includeRuntimeDependencies() {
Project project = buildProject(RUNTIME_CLASSPATH_CONFIGURATION_NAME, false);
Set<ResolvedArtifact> result = finder.findResolvedArtifacts(project, false);
assertThat(result).hasSize(1);
}

@Test
public void testFindResolvedArtifacts_includeAndroidCompileDependencies() {
Project project = buildProject("releaseCompileClasspath", true);
Set<ResolvedArtifact> result = finder.findResolvedArtifacts(project, false);
assertThat(result).hasSize(1);
}

@Test
public void testFindResolvedArtifacts_includeAndroidRuntimeDependencies() {
Project project = buildProject("releaseRuntimeClasspath", true);
Set<ResolvedArtifact> result = finder.findResolvedArtifacts(project, false);
assertThat(result).hasSize(1);
}

@Test
public void testFindResolvedArtifacts_omitTestDependencies() {
Project project = buildProject(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME, false);
Expand Down

0 comments on commit 158317f

Please sign in to comment.