Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
target
.flattened-pom.xml

# Gradle
.gradle

# Cache Files
*.cache

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ encrypted-token-will-appear-here
</li>

<li>
<em>Gradle</em> users, add a <em>maven-type repository</em> definition in <em>build.gradle</em>
<em>Gradle</em> users, add a <em>maven-type repository</em> definition in <em>build.gradle</em> (Groovy DSL) or <em>build.gradle.kts</em> (Kotlin DSL)

```groovy
repositories {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/redhat/exhort/providers/GradleProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@

/**
* Concrete implementation of the {@link Provider} used for converting dependency trees for Gradle
* projects (gradle.build) into a content Dot Graphs for Stack analysis or Json for Component
* analysis.
* projects (gradle.build / gradle.build.kts) into a content Dot Graphs for Stack analysis or Json
* for Component analysis.
*/
public final class GradleProvider extends BaseJavaProvider {

Expand Down Expand Up @@ -155,8 +155,9 @@ private String getDepInfo(String dependencyLine) {

private String getDepFromNotation(String dependency, Path manifestPath) throws IOException {
// Extract everything after "libs."
String alias = dependency.substring(dependency.indexOf("libs.") + "libs.".length());
alias = alias.replace(".", "-");
String alias = dependency.substring(dependency.indexOf("libs.") + "libs.".length()).trim();
alias = alias.replace(".", "-").replace(")", "");

// Read and parse the TOML file
TomlParseResult toml = Toml.parse(getLibsVersionsTomlPath(manifestPath));
TomlTable librariesTable = toml.getTable("libraries");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/redhat/exhort/tools/Ecosystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static Provider getProvider(final String manifestType) {
case "requirements.txt":
return new PythonPipProvider();
case "build.gradle":
case "build.gradle.kts":
return new GradleProvider();

default:
Expand Down
57 changes: 31 additions & 26 deletions src/test/java/com/redhat/exhort/impl/ExhortApiIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
Expand All @@ -54,7 +55,9 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
Expand Down Expand Up @@ -85,8 +88,10 @@ static void beforeAll() {
"package.json",
"pypi",
"requirements.txt",
"gradle",
"build.gradle");
"gradle-groovy",
"build.gradle",
"gradle-kotlin",
"build.gradle.kts");
}

@Tag("IntegrationTest")
Expand All @@ -97,17 +102,21 @@ static void afterAll() {
api = null;
}

private static List<Arguments> scenarios() {
return ecoSystemsManifestNames.entrySet().stream()
.map(e -> Arguments.of(e.getKey(), e.getValue()))
.collect(Collectors.toList());
}

@Tag("IntegrationTest")
@ParameterizedTest
@EnumSource(
value = Ecosystem.Type.class,
names = {"GOLANG", "MAVEN", "NPM", "PYTHON", "GRADLE"})
void Integration_Test_End_To_End_Stack_Analysis(Ecosystem.Type packageManager)
@ParameterizedTest(name = "StackAnalysis for: {0} with manifest: {1}")
@MethodSource("scenarios")
void Integration_Test_End_To_End_Stack_Analysis(String useCase, String manifestFileName)
throws IOException, ExecutionException, InterruptedException {
String manifestFileName = ecoSystemsManifestNames.get(packageManager.getType());
var provider = Ecosystem.getProvider(manifestFileName);
var packageManager = provider.ecosystem;
String pathToManifest =
getFileFromResource(
manifestFileName, "tst_manifests", "it", packageManager.getType(), manifestFileName);
getFileFromResource(manifestFileName, "tst_manifests", "it", useCase, manifestFileName);
preparePythonEnvironment(packageManager);
// Github action runner with all maven and java versions seems to enter infinite loop in
// integration tests of
Expand All @@ -126,16 +135,14 @@ private void releaseStaticMock(Ecosystem.Type packageManager) {
}

@Tag("IntegrationTest")
@ParameterizedTest
@EnumSource(
value = Ecosystem.Type.class,
names = {"GOLANG", "MAVEN", "NPM", "PYTHON", "GRADLE"})
void Integration_Test_End_To_End_Stack_Analysis_Mixed(Ecosystem.Type packageManager)
@ParameterizedTest(name = "StackAnalysis Mixed for: {0} with manifest: {1}")
@MethodSource("scenarios")
void Integration_Test_End_To_End_Stack_Analysis_Mixed(String useCase, String manifestFileName)
throws IOException, ExecutionException, InterruptedException {
String manifestFileName = ecoSystemsManifestNames.get(packageManager.getType());
var provider = Ecosystem.getProvider(manifestFileName);
var packageManager = provider.ecosystem;
String pathToManifest =
getFileFromResource(
manifestFileName, "tst_manifests", "it", packageManager.getType(), manifestFileName);
getFileFromResource(manifestFileName, "tst_manifests", "it", useCase, manifestFileName);
preparePythonEnvironment(packageManager);
// Github action runner with all maven and java versions seems to enter infinite loop in
// integration tests of
Expand All @@ -150,16 +157,14 @@ void Integration_Test_End_To_End_Stack_Analysis_Mixed(Ecosystem.Type packageMana
}

@Tag("IntegrationTest")
@ParameterizedTest
@EnumSource(
value = Ecosystem.Type.class,
names = {"GOLANG", "MAVEN", "NPM", "PYTHON", "GRADLE"})
void Integration_Test_End_To_End_Stack_Analysis_Html(Ecosystem.Type packageManager)
@ParameterizedTest(name = "StackAnalysis HTML for: {0} with manifest: {1}")
@MethodSource("scenarios")
void Integration_Test_End_To_End_Stack_Analysis_Html(String useCase, String manifestFileName)
throws IOException, ExecutionException, InterruptedException {
String manifestFileName = ecoSystemsManifestNames.get(packageManager.getType());
var provider = Ecosystem.getProvider(manifestFileName);
var packageManager = provider.ecosystem;
String pathToManifest =
getFileFromResource(
manifestFileName, "tst_manifests", "it", packageManager.getType(), manifestFileName);
getFileFromResource(manifestFileName, "tst_manifests", "it", useCase, manifestFileName);
preparePythonEnvironment(packageManager);
// Github action runner with all maven and java versions seems to enter infinite loop in
// integration tests of
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright © 2023 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.redhat.exhort.providers;

import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(HelperExtension.class)
@ExtendWith(MockitoExtension.class)
class Gradle_Groovy_Provider_Test extends Gradle_Provider_Test {

@Override
String getManifestName() {
return "build.gradle";
}

@Override
String getProviderFolder() {
return "gradle-groovy";
}

@Override
String getSettingsName() {
return "settings.gradle";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright © 2023 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.redhat.exhort.providers;

import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(HelperExtension.class)
@ExtendWith(MockitoExtension.class)
class Gradle_Kotlin_Provider_Test extends Gradle_Provider_Test {

@Override
String getManifestName() {
return "build.gradle.kts";
}

@Override
String getProviderFolder() {
return "gradle-kotlin";
}

@Override
String getSettingsName() {
return "settings.gradle.kts";
}
}
Loading
Loading