-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rubentxu
committed
Oct 26, 2023
1 parent
c31f0e4
commit 706d4c8
Showing
57 changed files
with
1,373 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
### Comandos | ||
|
||
|
||
```bash | ||
# Construir e instalar dependencias | ||
$ gradle clean :pipeline-cli:shadowJar | ||
``` | ||
|
||
|
||
|
||
```bash | ||
# Ejecutar | ||
$ java -jar pipeline-cli/build/libs/pipeline-cli-1.0-SNAPSHOT.jar -c pipeline-cli/src/test/resources/config.yaml -s pipeline-cli/src/test/resources/HelloWorld.pipeline.kts | ||
|
||
``` | ||
|
||
```bash | ||
# Ejecutar con print classpath | ||
gradle clean :pipeline-cli:printClasspath | ||
`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,15 @@ | ||
plugins { | ||
kotlin("jvm") version "1.9.10" | ||
application | ||
id("io.kotest") version "0.4.10" | ||
|
||
} | ||
|
||
group = "dev.rubentxu.pipeline" | ||
version = "1.0-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
|
||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3") | ||
val kotlinVersion: String by extra("1.9.10") | ||
val kotlinCoroutinesVersion: String by extra("1.7.3") | ||
|
||
testImplementation(kotlin("test")) | ||
|
||
testImplementation("io.kotest:kotest-runner-junit5-jvm:5.7.2") | ||
testImplementation("io.kotest:kotest-assertions-core-jvm:5.7.2") | ||
implementation("io.kotest:kotest-property-jvm:5.7.2") | ||
allprojects { | ||
|
||
repositories { | ||
mavenCentral() | ||
maven { url = uri("https://repo.gradle.org/gradle/libs-releases") } | ||
} | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(17) | ||
} | ||
|
||
application { | ||
mainClass.set("MainKt") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
plugins { | ||
kotlin("jvm") | ||
id("io.kotest") version "0.4.10" | ||
id("com.github.johnrengelman.shadow") version "7.1.2" | ||
|
||
} | ||
|
||
group = "dev.rubentxu.pipeline.core" | ||
version = "1.0-SNAPSHOT" | ||
|
||
val kotlinVersion: String by rootProject.extra | ||
val kotlinCoroutinesVersion: String by rootProject.extra | ||
|
||
dependencies { | ||
|
||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinCoroutinesVersion") | ||
implementation("org.gradle:gradle-tooling-api:8.4") | ||
implementation("org.eclipse.jgit:org.eclipse.jgit:6.7.0.202309050840-r") | ||
|
||
|
||
testImplementation(kotlin("test")) | ||
|
||
testImplementation("io.kotest:kotest-runner-junit5-jvm:5.7.2") | ||
testImplementation("io.kotest:kotest-assertions-core-jvm:5.7.2") | ||
testImplementation("org.mockito.kotlin:mockito-kotlin:5.1.0") | ||
testImplementation("io.kotest:kotest-property-jvm:5.7.2") | ||
|
||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(17) | ||
} | ||
|
||
tasks { | ||
shadowJar { | ||
archiveClassifier.set("") | ||
archiveBaseName.set("core") | ||
|
||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
core/src/main/kotlin/dev/rubentxu/pipeline/compiler/GradleCompiler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package dev.rubentxu.pipeline.compiler | ||
|
||
import dev.rubentxu.pipeline.library.JarFileNotFoundException | ||
import dev.rubentxu.pipeline.library.LibraryConfiguration | ||
import dev.rubentxu.pipeline.library.LibraryNotFoundException | ||
import dev.rubentxu.pipeline.library.SourceNotFoundException | ||
import org.gradle.tooling.GradleConnector | ||
import org.gradle.tooling.ProjectConnection | ||
import org.gradle.tooling.model.GradleProject | ||
import java.io.File | ||
import java.nio.file.Path | ||
|
||
class GradleCompiler { | ||
fun compileAndJar(sourcePath: String, libraryConfiguration: LibraryConfiguration): File { | ||
val file = File(resolveAndNormalizeAbsolutePath(sourcePath)) | ||
if(!file.exists()) { | ||
throw SourceNotFoundException("File ${file.path} not found") | ||
} | ||
|
||
val connection: ProjectConnection = GradleConnector.newConnector() | ||
.forProjectDirectory(file) | ||
.connect() | ||
|
||
val project: GradleProject = connection.getModel(GradleProject::class.java) | ||
project.name | ||
|
||
try { | ||
connection.newBuild() | ||
.withArguments("clean", "build", "-ParchiveBaseName${libraryConfiguration.name}") | ||
.run() | ||
|
||
val jarFile = findJarFile(File(resolveAndNormalizeAbsolutePath(sourcePath), "build/libs/")) | ||
|
||
if (jarFile?.exists() == false) { | ||
throw JarFileNotFoundException(jarFile.path) | ||
} | ||
|
||
return jarFile!! | ||
} finally { | ||
connection.close() | ||
} | ||
} | ||
|
||
fun getProjectName(projectDir: String): String { | ||
val connection: ProjectConnection = GradleConnector.newConnector() | ||
.forProjectDirectory(File(projectDir)) | ||
.connect() | ||
|
||
try { | ||
val project: GradleProject = connection.getModel(GradleProject::class.java) | ||
return project.name | ||
} finally { | ||
connection.close() | ||
} | ||
} | ||
|
||
fun findJarFile(directory: File): File? { | ||
return directory.walk() | ||
.filter { it.isFile && it.extension == "jar" } | ||
.firstOrNull() // Devuelve el primer archivo JAR encontrado o null si no se encontró ninguno | ||
} | ||
|
||
fun resolveAndNormalizeAbsolutePath(relativePath: String): String { | ||
val path = Path.of(relativePath) | ||
return path.toAbsolutePath().normalize().toString() | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion
1
...ipeline/extensions/StepBlockExtensions.kt → ...ipeline/extensions/StepBlockExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
core/src/main/kotlin/dev/rubentxu/pipeline/library/GitSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package dev.rubentxu.pipeline.library | ||
|
||
import dev.rubentxu.pipeline.compiler.GradleCompiler | ||
import org.eclipse.jgit.api.Git | ||
import java.io.File | ||
|
||
class GitSource(private val gradleCompiler: GradleCompiler) : SourceRetriever { | ||
override fun retrieve(libraryConfiguration: LibraryConfiguration): File { | ||
val gitRepoPath = "build/to/local/git/repo" | ||
Git.cloneRepository() | ||
.setURI(libraryConfiguration.sourcePath) | ||
.setDirectory(File(gitRepoPath)) | ||
.call() | ||
|
||
return gradleCompiler.compileAndJar(gitRepoPath, libraryConfiguration) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
core/src/main/kotlin/dev/rubentxu/pipeline/library/LibraryConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package dev.rubentxu.pipeline.library | ||
|
||
data class LibraryConfiguration( | ||
val name: String, | ||
val sourcePath: String, | ||
val version: String, | ||
val retriever: SourceRetriever, | ||
val credentialsId: String? | ||
|
||
|
||
) |
7 changes: 7 additions & 0 deletions
7
core/src/main/kotlin/dev/rubentxu/pipeline/library/LibraryExceptions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.rubentxu.pipeline.library | ||
|
||
class LibraryNotFoundException(id: LibraryId) : Exception("Librería ${id.name} con ${id.version} no encontrada") | ||
|
||
class SourceNotFoundException(message:String) : Exception(message) | ||
|
||
class JarFileNotFoundException(path: String) : Exception("No se encontró el archivo JAR en la ruta especificada: $path") |
6 changes: 6 additions & 0 deletions
6
core/src/main/kotlin/dev/rubentxu/pipeline/library/LibraryId.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package dev.rubentxu.pipeline.library | ||
|
||
data class LibraryId ( | ||
val name: String, | ||
val version: String | ||
) |
33 changes: 33 additions & 0 deletions
33
core/src/main/kotlin/dev/rubentxu/pipeline/library/LibraryLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package dev.rubentxu.pipeline.library | ||
|
||
|
||
|
||
import java.io.File | ||
import java.net.URLClassLoader | ||
import java.nio.file.Path | ||
|
||
class LibraryLoader { | ||
val libraries = mutableMapOf<LibraryId, LibraryConfiguration>() | ||
|
||
fun loadLibrary(id: LibraryId): File { | ||
val libraryConfiguration = libraries[id] ?: throw LibraryNotFoundException(id) | ||
return doLoadLibrary(libraryConfiguration) | ||
} | ||
|
||
private fun doLoadLibrary(libraryConfiguration: LibraryConfiguration): File { | ||
val retriever = libraryConfiguration.retriever | ||
val jarFile = retriever.retrieve(libraryConfiguration) | ||
val url = jarFile.toURI().toURL() | ||
|
||
// Crear un nuevo URLClassLoader con la nueva URL | ||
URLClassLoader.newInstance(arrayOf(url)) | ||
return jarFile | ||
} | ||
|
||
fun resolveAndNormalizeAbsolutePath(relativePath: String): String { | ||
val path = Path.of(relativePath) | ||
return path.toAbsolutePath().normalize().toString() | ||
|
||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
core/src/main/kotlin/dev/rubentxu/pipeline/library/LocalJar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dev.rubentxu.pipeline.library | ||
|
||
import java.io.File | ||
|
||
class LocalJar : SourceRetriever { | ||
override fun retrieve(libraryConfiguration: LibraryConfiguration): File { | ||
val jarPath = libraryConfiguration.sourcePath | ||
val jarFile = File(jarPath) | ||
|
||
if (!jarFile.exists()) { | ||
throw JarFileNotFoundException(jarPath) | ||
} | ||
|
||
return jarFile | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
core/src/main/kotlin/dev/rubentxu/pipeline/library/LocalSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package dev.rubentxu.pipeline.library | ||
|
||
import dev.rubentxu.pipeline.compiler.GradleCompiler | ||
import java.io.File | ||
|
||
class LocalSource(private val gradleCompiler: GradleCompiler) : SourceRetriever { | ||
override fun retrieve(libraryConfiguration: LibraryConfiguration): File { | ||
val sourcePath = libraryConfiguration.sourcePath | ||
return gradleCompiler.compileAndJar(sourcePath, libraryConfiguration) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
core/src/main/kotlin/dev/rubentxu/pipeline/library/SourceRetriever.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.rubentxu.pipeline.library | ||
|
||
import java.io.File | ||
|
||
interface SourceRetriever { | ||
fun retrieve(libraryConfiguration: LibraryConfiguration): File | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.