mirror of
https://github.com/jlengrand/my-good-first-issues.git
synced 2026-03-10 08:31:23 +00:00
First build.gradle parsin
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -8,7 +8,7 @@
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_14" project-jdk-name="16" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11 (2)" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -14,6 +14,7 @@ version = "1.0-SNAPSHOT"
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://dl.bintray.com/kotlin/kotlin-eap")
|
||||
// maven { url = uri("https://repo.gradle.org/gradle/libs-releases") }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -28,6 +29,10 @@ dependencies {
|
||||
implementation("org.eclipse.aether:aether-transport-http:1.1.0")
|
||||
implementation("org.eclipse.aether:aether-transport-wagon:1.1.0")
|
||||
|
||||
// val toolingApiVersion = "5.2.1"
|
||||
// implementation("org.gradle:gradle-tooling-api:$toolingApiVersion")
|
||||
implementation("org.codehaus.groovy:groovy-astbuilder:3.0.4")
|
||||
|
||||
implementation("org.slf4j:slf4j-simple:2.0.0-alpha1")
|
||||
|
||||
val ktorVersion = "1.5.2"
|
||||
|
||||
@@ -33,8 +33,10 @@ class CliFirstGoodIssues : Callable<Int> {
|
||||
is GithubIssuesFailure ->
|
||||
println(result.throwable.message)
|
||||
is GithubIssuesSuccess -> {
|
||||
if (result.githubIssues.isEmpty()) println(CommandLine.Help.Ansi.AUTO.string("@|yellow,bold Found no issues for you to work on! Try again later! |@"))
|
||||
else prettyPrintIssues(result.githubIssues)
|
||||
if (result.githubIssues.isEmpty())
|
||||
println(CommandLine.Help.Ansi.AUTO.string("@|yellow,bold Found no issues for you to work on! Try again later! |@"))
|
||||
else
|
||||
prettyPrintIssues(result.githubIssues)
|
||||
}
|
||||
}
|
||||
return@runBlocking 0
|
||||
@@ -93,7 +95,7 @@ class PicoCliLogger : AppLogger {
|
||||
// println(CommandLine.Help.Ansi.AUTO.string("@|red Error while fetching and parsing input POM |@"))
|
||||
}
|
||||
|
||||
override fun logPomDependencyFailure(pomDependency: Dependency) {
|
||||
override fun logPomDependencyFailure(url: String) {
|
||||
// println(CommandLine.Help.Ansi.AUTO.string("@|red Error while fetching : $pomDependency! |@"))
|
||||
}
|
||||
|
||||
|
||||
@@ -39,13 +39,13 @@ class MyGoodFirstIssuesService(
|
||||
|
||||
dependencies.forEach { logger.logNewDependency(it) }
|
||||
|
||||
val (dependencyPoms, dependencyFailures) = dependencies.map { Pair(it, mavenService.getDependencyPom(it)) }
|
||||
.partition { it.second is MavenClientSuccess }
|
||||
val (dependencyPoms, dependencyFailures) = dependencies.map { mavenService.getDependencyPom(it) }
|
||||
.partition { it is MavenClientSuccess }
|
||||
|
||||
dependencyFailures.forEach { logger.logPomDependencyFailure(it.first) }
|
||||
dependencyFailures.forEach { logger.logPomDependencyFailure((it as MavenClientFailure).url) }
|
||||
|
||||
val (githubNames, githubFailures) = dependencyPoms
|
||||
.map{(it.second as MavenClientSuccess).pomProject}
|
||||
.map{(it as MavenClientSuccess).pomProject}
|
||||
.map { githubNameExtractor.getGithubNameFromProject(it) }
|
||||
.partition { it is GithubNameSuccess }
|
||||
|
||||
|
||||
@@ -4,13 +4,12 @@ import me.lengrand.mygoodfirstissues.github.GitHubServiceResult
|
||||
import me.lengrand.mygoodfirstissues.parsers.maven.GithubNameResult
|
||||
import me.lengrand.mygoodfirstissues.parsers.maven.MavenClientFailure
|
||||
import org.apache.maven.model.Dependency
|
||||
import org.apache.maven.model.Model
|
||||
|
||||
interface AppLogger{
|
||||
fun logNewRepoName(repoName : String)
|
||||
fun logNewDependency(pomDependency: Dependency)
|
||||
fun logPomFailure(urlOrPath: String, pomResult: MavenClientFailure)
|
||||
fun logPomDependencyFailure(pomDependency: Dependency)
|
||||
fun logPomDependencyFailure(url: String)
|
||||
fun logGithubFailure(pomProject: GithubNameResult)
|
||||
fun logGithubIssueFailure(githubName : String)
|
||||
fun logDependencies(dependencies: List<Dependency>)
|
||||
@@ -21,7 +20,7 @@ class SilentAppLogger : AppLogger {
|
||||
override fun logNewRepoName(repoName: String) = Unit
|
||||
override fun logNewDependency(pomDependency: Dependency) = Unit
|
||||
override fun logPomFailure(urlOrPath: String, pomResult: MavenClientFailure) = Unit
|
||||
override fun logPomDependencyFailure(pomDependency: Dependency) = Unit
|
||||
override fun logPomDependencyFailure(pomDependency: String) = Unit
|
||||
override fun logGithubFailure(pomProject: GithubNameResult) = Unit
|
||||
override fun logGithubIssueFailure(githubName: String) = Unit
|
||||
override fun logDependencies(dependencies: List<Dependency>) {
|
||||
@@ -44,7 +43,7 @@ class DefaultAppLogger : AppLogger {
|
||||
println("Error while fetching and parsing input POM")
|
||||
}
|
||||
|
||||
override fun logPomDependencyFailure(pomDependency: Dependency) {
|
||||
override fun logPomDependencyFailure(pomDependency: String) {
|
||||
println("Error while fetching : $pomDependency!")
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
package me.lengrand.mygoodfirstissues.parsers.gradle
|
||||
|
||||
import org.apache.commons.io.IOUtils
|
||||
import org.codehaus.groovy.ast.ASTNode
|
||||
import org.codehaus.groovy.ast.CodeVisitorSupport
|
||||
import org.codehaus.groovy.ast.builder.AstBuilder
|
||||
import org.codehaus.groovy.ast.expr.*
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.ArrayList
|
||||
import java.util.HashMap
|
||||
import kotlin.io.path.ExperimentalPathApi
|
||||
|
||||
|
||||
// Largely inspired from https://github.com/lovettli/liferay-ide/tree/master/tools/plugins/com.liferay.ide.gradle.core/src/com/liferay/ide/gradle/core/parser
|
||||
class GradleFetcher() {
|
||||
|
||||
companion object{
|
||||
@ExperimentalPathApi
|
||||
@JvmStatic
|
||||
fun main(args : Array<String>){
|
||||
println("test")
|
||||
|
||||
val buildLocation = "/Users/jlengrand/IdeaProjects/my-good-first-issues/src/test/resources/gradleBuilds/swacli-gradle.build"
|
||||
val buildLocationFolder = "/Users/jlengrand/IdeaProjects/swacli"
|
||||
|
||||
val file = File(buildLocation)
|
||||
val gradleDependencyUpdater =
|
||||
GradleDependencyUpdater(file)
|
||||
println(gradleDependencyUpdater.allDependencies)
|
||||
println("done")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class FindDependenciesVisitor : CodeVisitorSupport() {
|
||||
private var dependenceLineNum = -1
|
||||
|
||||
val dependencies: MutableList<GradleDependency> = ArrayList()
|
||||
override fun visitMethodCallExpression(call: MethodCallExpression) {
|
||||
if (call.methodAsString != "buildscript") {
|
||||
if (call.methodAsString == "dependencies") {
|
||||
if (dependenceLineNum == -1) {
|
||||
dependenceLineNum = call.lastLineNumber
|
||||
}
|
||||
}
|
||||
super.visitMethodCallExpression(call)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitArgumentlistExpression(ale: ArgumentListExpression) {
|
||||
val expressions = ale.expressions
|
||||
if (expressions.size == 1 && expressions[0] is ConstantExpression) {
|
||||
val depStr = expressions[0].text
|
||||
val deps = depStr.split(":").toTypedArray()
|
||||
if (deps.size == 3) {
|
||||
dependencies.add(
|
||||
GradleDependency(
|
||||
deps[0],
|
||||
deps[1],
|
||||
deps[2]
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
super.visitArgumentlistExpression(ale)
|
||||
}
|
||||
|
||||
override fun visitClosureExpression(expression: ClosureExpression) {
|
||||
super.visitClosureExpression(expression)
|
||||
}
|
||||
|
||||
override fun visitMapExpression(expression: MapExpression) {
|
||||
val mapEntryExpressions = expression.mapEntryExpressions
|
||||
val dependenceMap: MutableMap<String, String> = HashMap()
|
||||
for (mapEntryExpression in mapEntryExpressions) {
|
||||
val key = mapEntryExpression.keyExpression.text
|
||||
val value = mapEntryExpression.valueExpression.text
|
||||
dependenceMap[key] = value
|
||||
}
|
||||
dependencies.add(GradleDependency(dependenceMap))
|
||||
super.visitMapExpression(expression)
|
||||
}
|
||||
}
|
||||
|
||||
class GradleDependencyUpdater(scriptContents: String?) {
|
||||
private val nodes: List<ASTNode>
|
||||
|
||||
constructor(inputFile: File) : this(IOUtils.toString(FileInputStream(inputFile), StandardCharsets.UTF_8)) {}
|
||||
|
||||
val allDependencies: List<GradleDependency>
|
||||
get() {
|
||||
val visitor = FindDependenciesVisitor()
|
||||
for (node in nodes) {
|
||||
node.visit(visitor)
|
||||
}
|
||||
return visitor.dependencies
|
||||
}
|
||||
|
||||
init {
|
||||
val builder = AstBuilder()
|
||||
nodes = builder.buildFromString(scriptContents)
|
||||
}
|
||||
}
|
||||
|
||||
class GradleDependency {
|
||||
private val group: String
|
||||
private val name: String
|
||||
private val version: String
|
||||
|
||||
constructor(dep: Map<String, String>) {
|
||||
group = if(dep["group"] != null) dep["group"]!! else ""
|
||||
name = if(dep["name"] != null) dep["name"]!! else ""
|
||||
version = if(dep["version"] != null) dep["version"]!! else ""
|
||||
}
|
||||
|
||||
constructor(group: String, name: String, version: String) {
|
||||
this.group = group
|
||||
this.name = name
|
||||
this.version = version
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "$group:$name:$version"
|
||||
}
|
||||
}
|
||||
57
src/test/resources/gradleBuilds/swacli-gradle.build
Normal file
57
src/test/resources/gradleBuilds/swacli-gradle.build
Normal file
@@ -0,0 +1,57 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.4.10'
|
||||
id 'org.jetbrains.kotlin.plugin.serialization' version '1.4.10'
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin-kapt' // required
|
||||
|
||||
|
||||
group 'nl.lengrand'
|
||||
version '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib"
|
||||
|
||||
implementation 'info.picocli:picocli:4.5.2'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0'
|
||||
|
||||
implementation 'com.github.kittinunf.fuel:fuel:2.3.0'
|
||||
implementation 'com.github.kittinunf.fuel:fuel-kotlinx-serialization:2.3.0'
|
||||
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.0"
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.7.0"
|
||||
|
||||
kapt 'info.picocli:picocli-codegen:4.5.0'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions.jvmTarget = "11"
|
||||
}
|
||||
compileTestKotlin {
|
||||
kotlinOptions.jvmTarget = "11"
|
||||
}
|
||||
|
||||
kapt {
|
||||
arguments {
|
||||
arg("project", "${project.group}/${project.name}")
|
||||
}
|
||||
}
|
||||
|
||||
task customFatJar(type: Jar) {
|
||||
manifest {
|
||||
attributes 'Main-Class': 'nl.lengrand.swacli.SwaCLIPaginate'
|
||||
}
|
||||
baseName = 'all-in-one-jar'
|
||||
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
|
||||
with jar
|
||||
}
|
||||
Reference in New Issue
Block a user