feat: [deps] support for gradle

上级 fe8d3cdd
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.springframework.cloud:spring-cloud-contract-gradle-plugin:2.2.1.RELEASE'
}
}
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
apply plugin: 'spring-cloud-contract'
group = 'com.phodal.coco'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "Hoxton.SR1")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jersey'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.flywaydb:flyway-core'
implementation 'org.springframework.cloud:spring-cloud-starter-zipkin'
implementation 'org.springframework.cloud:spring-cloud-starter-zookeeper-config'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-stub-runner'
testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-verifier'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
contracts {
targetFramework = org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT5
testMode = 'WebTestClient'
}
test {
useJUnitPlatform()
}
package com.phodal.coco.gradledemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class GradledemoApplication {
public static void main(String[] args) {
SpringApplication.run(GradledemoApplication.class, args);
}
}
package com.phodal.coco.gradledemo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class GradledemoApplicationTests {
@Test
void contextLoads() {
}
}
......@@ -4,11 +4,20 @@ import (
"testing"
)
func TestDepFindUnused(t *testing.T) {
func Test_Dep_MavenFindUnused(t *testing.T) {
tests := []cmdTestCase{{
name: "dep",
cmd: "deps -p ../_fixtures/deps/maven_sample",
golden: "testdata/deps_maven.txt",
}}
runTestCmd(t, tests)
}
func Test_Dep_GradleFindUnused(t *testing.T) {
tests := []cmdTestCase{{
name: "dep",
cmd: "deps -p ../_fixtures/deps/gradle_sample",
golden: "testdata/deps_gradle.txt",
}}
runTestCmd(t, tests)
}
\ No newline at end of file
unused
+---------------------------+-------------------------------------------+--------------------+
| GROUPID | ARTIFACTID | SCOPE |
+---------------------------+-------------------------------------------+--------------------+
| org.flywaydb | flyway-core | implementation |
| org.springframework.cloud | spring-cloud-starter-zipkin | implementation |
| org.springframework.cloud | spring-cloud-starter-zookeeper-config | implementation |
| io.projectreactor | reactor-test | testImplementation |
| org.springframework.cloud | spring-cloud-starter-contract-stub-runner | testImplementation |
| org.springframework.cloud | spring-cloud-starter-contract-verifier | testImplementation |
+---------------------------+-------------------------------------------+--------------------+
......@@ -17,3 +17,7 @@ var JavaFileFilter = func(path string) bool {
var PomXmlFilter = func(path string) bool {
return strings.HasSuffix(path, "pom.xml")
}
var BuildGradleFilter = func(path string) bool {
return strings.HasSuffix(path, "build.gradle")
}
......@@ -28,12 +28,17 @@ func (d *DepApp) BuildImportMap(deps []domain.JClassNode) map[string]domain.JImp
func (d *DepApp) AnalysisPath(path string, nodes []domain.JClassNode) []domain.JDependency {
path, _ = filepath.Abs(path)
pomXmls := cocafile.GetFilesWithFilter(path, cocafile.PomXmlFilter)
gradleFiles := cocafile.GetFilesWithFilter(path, cocafile.BuildGradleFilter)
var mavenDeps []domain.JDependency = nil
for _, pomFile := range pomXmls {
currentMavenDeps := AnalysisMaven(pomFile)
mavenDeps = append(mavenDeps, currentMavenDeps...)
}
for _, gradleFile := range gradleFiles {
dependencies := AnalysisGradleFile(gradleFile)
mavenDeps = append(mavenDeps, dependencies...)
}
importMap := d.BuildImportMap(nodes)
......
......@@ -15,7 +15,7 @@ func Test_ShouldReturnGradleDep(t *testing.T) {
developmentOnly 'org.springframework.boot:spring-boot-devtools'
}`
results := AnalysisGradle(pluginsStr)
results := AnalysisGradleString(pluginsStr)
g.Expect(len(results)).To(Equal(2))
g.Expect(results[0].ArtifactId).To(Equal("spring-boot-starter-web"))
......@@ -27,7 +27,7 @@ func Test_ShouldReturnCorrectGradleDepsFroFile(t *testing.T) {
codePath := "../../../_fixtures/deps/gradle/build.gradle"
bytes := cmd_util.ReadFile(codePath)
mavenDeps := AnalysisGradle(string(bytes))
mavenDeps := AnalysisGradleString(string(bytes))
g.Expect(len(mavenDeps)).To(Equal(14))
}
......@@ -42,7 +42,7 @@ func Test_ShouldHandleExclude(t *testing.T) {
}
}`
results := AnalysisGradle(pluginsStr)
results := AnalysisGradleString(pluginsStr)
g.Expect(len(results)).To(Equal(1))
g.Expect(results[0].ArtifactId).To(Equal("spring-boot-starter-test"))
......
......@@ -2,12 +2,18 @@ package deps
import (
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/phodal/coca/cmd/cmd_util"
"github.com/phodal/coca/core/domain"
"github.com/phodal/coca/core/infrastructure/ast/groovy"
"github.com/phodal/coca/languages/groovy"
)
func AnalysisGradle(str string) []domain.JDependency {
func AnalysisGradleFile(path string) []domain.JDependency {
bytes := cmd_util.ReadFile(path)
return AnalysisGradleString(string(bytes))
}
func AnalysisGradleString(str string) []domain.JDependency {
parser := ProcessGroovyString(str)
context := parser.CompilationUnit()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册