Skip to content

Commit

Permalink
♻️ refactor: update CI.CD dependencies injection #3
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jun 30, 2024
1 parent 35306ad commit 14d9527
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 21 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,19 @@ make jar

### Upgrading version

- file `gradle.properties`

```sh
ng.name=botwrap4j
ng.version=v1.0.0
- file `gradle.yml`

```yaml
#file: noinspection SpellCheckingInspection
ng:
name: botwrap4j
version: v1.0.0
enabled_link: true # enable compression and attachment of the external libraries
jars:
- enabled: false # enable compression and attachment of the external libraries
source: "./../libs/unify4j-v1.0.0.jar" # lib Jar
- enabled: true
source: "./../libs/bot4j-v1.0.0.jar"
```
## Integration
Expand Down
2 changes: 0 additions & 2 deletions gradle.properties

This file was deleted.

97 changes: 83 additions & 14 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
*/
//file:noinspection VulnerableLibrariesLocal
//file:noinspection SpellCheckingInspection
buildscript {
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
classpath 'org.yaml:snakeyaml:2.0'
}
}

plugins {
// Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins
Expand All @@ -27,19 +36,58 @@ repositories {
mavenCentral()
}

def props = new Properties()
props.load(new FileInputStream(rootProject.file("gradle.properties")))
def _name = props.getProperty("ng.name")
def _version = props.getProperty("ng.version")
import org.yaml.snakeyaml.Yaml

class JarConfig {
boolean enabled
String source

JarConfig(Map<String, Object> config) {
enabled = config['enabled'] ?: false
source = config['source'] ?: ''
}
}

class NgConfig {
String name
String version
boolean enabledLink
List<JarConfig> jars

@SuppressWarnings('GroovyAssignabilityCheck')
NgConfig(Map<String, Object> configs) {
name = configs.containsKey('name') ? configs['name'] : 'bot4j'
version = configs.containsKey('version') ? configs['version'] : 'v0.0.0'
enabledLink = configs.containsKey('enabled_link') ? configs['enabled_link'] : false
// jars = configs.containsKey('jars') ? configs['jars'] : [] // List<String> jars
jars = configs.containsKey('jars') ? configs['jars'].collect { new JarConfig(it) } : []
}
}

// Define ngConfig as a static global variable
NgConfig ngConfig = loadNgConfig()

NgConfig loadNgConfig() {
def configs = file('gradle.yml')
if (configs.exists()) {
def yaml = new Yaml()
def config = yaml.load(new FileInputStream(configs))
println '⌛ Loading NgConfigs configuration via gradle.yml'
return new NgConfig(config['ng'] as Map<String, Object>)
} else {
println '⚠️ gradle.yml not found, using default configuration'
return new NgConfig(new HashMap<String, Object>())
}
}

// Define a task to build the Groovy library into a JAR
tasks.register('buildGroovyJar', Jar) {
// Set the base directory for the source files
from 'src/main/groovy'
// Set the destination directory for the compiled classes
into('')
archiveFileName = "${_name}" + ".jar"
version("${_version}")
archiveFileName = "${ngConfig.getName()}" + ".jar"
version("${ngConfig.getVersion()}")
include '**/*.groovy'
}

Expand All @@ -49,12 +97,39 @@ tasks.named('build') {
}

tasks.jar {
archivesBaseName = "${_name}"
version = "${_version}"
archivesBaseName = "${ngConfig.getName()}"
version = "${ngConfig.getVersion()}"

// Handle duplicates
// duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// Compressing the external JAR files listed in gradle.yml using zipTree if enabled_link is true
if (ngConfig.isEnabledLink() && !ngConfig.getJars().isEmpty()) {
ngConfig.getJars().each { jar ->
if (jar.isEnabled() && !jar.getSource().isEmpty()) {
println("📦 Jar compressing... [${jar.getSource()}]")
from {
zipTree(file(jar.getSource()))
}
}
}
} else {
println '⚠️ Skipping compression of dependency JAR files...'
}
}

// Add dependencies
dependencies {
// Add the dependencies listed in the gradle.yml file
if (!ngConfig.getJars().isEmpty()) {
ngConfig.getJars().each { jar ->
if (!jar.getSource().isEmpty()) {
println("🔄 Jar mounting... [${jar.getSource()}]")
implementation files(jar.getSource())
}
}
} else {
println '⚠️ No JAR files specified in gradle.yml for dependencies.'
}
// Use the awesome Spock testing and specification framework
testImplementation libs.spock.core
// Incorporate JUnit Jupiter API version 4.13.2 for unit testing,
Expand Down Expand Up @@ -97,10 +172,4 @@ dependencies {
// The "spring-boot-configuration-processor" library, version 2.7.18,
// is a Spring Boot module that processes configuration metadata annotations to generate metadata files and aid in auto-configuration of Spring applications.
implementation group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: '2.7.18'

// unify4J: Java 1.8 skeleton library offering a rich toolkit of utility functions
// for collections, strings, date/time, JSON, maps, and more.
implementation files('./../libs/unify4j-v1.0.0.jar')
// bot4j: a robust designed for sending notifications to various messaging platforms such as Telegram, Discord, and Slack.
implementation files('./../libs/bot4j-v1.0.0.jar')
}
10 changes: 10 additions & 0 deletions plugin/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#file: noinspection SpellCheckingInspection
ng:
name: botwrap4j
version: v1.0.0
enabled_link: true # enable compression and attachment of the external libraries
jars:
- enabled: false # enable compression and attachment of the external libraries
source: "./../libs/unify4j-v1.0.0.jar" # lib Jar
- enabled: true
source: "./../libs/bot4j-v1.0.0.jar"

0 comments on commit 14d9527

Please sign in to comment.