Skip to content

Commit 0388a23

Browse files
committed
♻️ refactor: refactor codebase #2
1 parent ed2243e commit 0388a23

File tree

3 files changed

+95
-33
lines changed

3 files changed

+95
-33
lines changed

Diff for: README.md

+14-18
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,20 @@ make jar
5555

5656
### Upgrading version
5757

58-
- file `gradle.properties`
59-
60-
```sh
61-
ng.name=bot4j
62-
ng.version=v1.0.0
58+
- file `gradle.yml`
59+
60+
```yaml
61+
ng:
62+
name: bot4j
63+
version: v1.0.0
64+
enabled_link: false # enable compression and attachment of the external libraries
65+
jars:
66+
# unify4J: Java 1.8 skeleton library offering a rich toolkit of utility functions
67+
# for collections, strings, date/time, JSON, maps, and more.
68+
- "./../libs/unify4j-v1.0.0.jar"
69+
# alpha4J: is a Java 8 library featuring common data structures and algorithms.
70+
# Enhance your projects with efficient and easy-to-use implementations designed for performance and clarity.
71+
- "./../libs/alpha4j-v1.0.0.jar"
6372
```
6473
6574
## Integration
@@ -69,16 +78,3 @@ ng.version=v1.0.0
6978
```gradle
7079
implementation files('libs/bot4j-v1.0.0.jar') // filename based on ng.name and ng.version
7180
```
72-
73-
2. Edit file `main Spring Boot application` (optional)
74-
75-
```java
76-
77-
@SpringBootApplication
78-
@ComponentScan(basePackages = {"org.bot4j"}) // root name of package bot4j
79-
public class ApiApplication {
80-
public static void main(String[] args) {
81-
SpringApplication.run(ApiApplication.class, args);
82-
}
83-
}
84-
```

Diff for: plugin/build.gradle

+70-15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
*/
55
//file:noinspection VulnerableLibrariesLocal
66
//file:noinspection SpellCheckingInspection
7+
buildscript {
8+
repositories {
9+
// Use Maven Central for resolving dependencies.
10+
mavenCentral()
11+
}
12+
dependencies {
13+
classpath 'org.yaml:snakeyaml:2.0'
14+
}
15+
}
716

817
plugins {
918
// Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins
@@ -24,19 +33,47 @@ repositories {
2433
mavenCentral()
2534
}
2635

27-
def props = new Properties()
28-
props.load(new FileInputStream(rootProject.file("gradle.properties")))
29-
def _name = props.getProperty("ng.name")
30-
def _version = props.getProperty("ng.version")
36+
import org.yaml.snakeyaml.Yaml
37+
38+
class NgConfig {
39+
String name
40+
String version
41+
boolean enabledLink
42+
List<String> jars
43+
44+
@SuppressWarnings('GroovyAssignabilityCheck')
45+
NgConfig(Map<String, Object> configs) {
46+
name = configs.containsKey('name') ? configs['name'] : 'bot4j'
47+
version = configs.containsKey('version') ? configs['version'] : 'v1.0.0'
48+
enabledLink = configs.containsKey('enabled_link') ? configs['enabled_link'] : false
49+
jars = configs.containsKey('jars') ? configs['jars'] : []
50+
}
51+
}
52+
53+
// Define ngConfig as a static global variable
54+
NgConfig ngConfig = loadNgConfig()
55+
56+
NgConfig loadNgConfig() {
57+
def configs = file('gradle.yml')
58+
if (configs.exists()) {
59+
def yaml = new Yaml()
60+
def config = yaml.load(new FileInputStream(configs))
61+
println '⌛ Loading NgConfigs configuration via gradle.yml'
62+
return new NgConfig(config['ng'] as Map<String, Object>)
63+
} else {
64+
println '⚠️ gradle.yml not found, using default configuration'
65+
return new NgConfig(new HashMap<String, Object>())
66+
}
67+
}
3168

3269
// Define a task to build the Groovy library into a JAR
3370
tasks.register('buildGroovyJar', Jar) {
3471
// Set the base directory for the source files
3572
from 'src/main/groovy'
3673
// Set the destination directory for the compiled classes
3774
into('')
38-
archiveFileName = "${_name}" + ".jar"
39-
version("${_version}")
75+
archiveFileName = "${ngConfig.getName()}" + ".jar"
76+
version("${ngConfig.getVersion()}")
4077
include '**/*.groovy'
4178
}
4279

@@ -46,12 +83,37 @@ tasks.named('build') {
4683
}
4784

4885
tasks.jar {
49-
archivesBaseName = "${_name}"
50-
version = "${_version}"
86+
archivesBaseName = "${ngConfig.getName()}"
87+
version = "${ngConfig.getVersion()}"
88+
89+
// Handle duplicates
90+
// <code>
91+
// duplicatesStrategy = DuplicatesStrategy.EXCLUDE
92+
// </code>
93+
// Compressing the external JAR files listed in gradle.yml using zipTree if enabled_link is true
94+
if (ngConfig.isEnabledLink() && !ngConfig.getJars().isEmpty()) {
95+
ngConfig.getJars().each { jar ->
96+
println("📦 Jar compressing... [${jar}]")
97+
from {
98+
zipTree(file(jar))
99+
}
100+
}
101+
} else {
102+
println '⚠️ Skipping compression of dependency JAR files...'
103+
}
51104
}
52105

53106
// Add dependencies
54107
dependencies {
108+
// Add the dependencies listed in the gradle.yml file
109+
if (!ngConfig.getJars().isEmpty()) {
110+
ngConfig.getJars().each { jar ->
111+
println("🔄 Jar mounting... [${jar}]")
112+
implementation files(jar)
113+
}
114+
} else {
115+
println '⚠️ No JAR files specified in gradle.yml for dependencies.'
116+
}
55117
// Use the awesome Spock testing and specification framework
56118
testImplementation libs.spock.core
57119
// Incorporate JUnit Jupiter API version 4.13.2 for unit testing,
@@ -88,11 +150,4 @@ dependencies {
88150
implementation group: 'com.jayway.jsonpath', name: 'json-path', version: '2.9.0'
89151
// The "validation-api" library, version 2.0.1.Final, provides tools for validating Java objects according to defined constraints.
90152
implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
91-
92-
// unify4J: Java 1.8 skeleton library offering a rich toolkit of utility functions
93-
// for collections, strings, date/time, JSON, maps, and more.
94-
implementation files('./../libs/unify4j-v1.0.0.jar')
95-
// alpha4j: is a Java 8 library featuring common data structures and algorithms.
96-
// Enhance your projects with efficient and easy-to-use implementations designed for performance and clarity.
97-
implementation files('./../libs/alpha4j-v1.0.0.jar')
98153
}

Diff for: plugin/gradle.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ng:
2+
name: bot4j
3+
version: v1.0.0
4+
enabled_link: false # enable compression and attachment of the external libraries
5+
jars:
6+
# unify4J: Java 1.8 skeleton library offering a rich toolkit of utility functions
7+
# for collections, strings, date/time, JSON, maps, and more.
8+
- "./../libs/unify4j-v1.0.0.jar"
9+
# alpha4J: is a Java 8 library featuring common data structures and algorithms.
10+
# Enhance your projects with efficient and easy-to-use implementations designed for performance and clarity.
11+
- "./../libs/alpha4j-v1.0.0.jar"

0 commit comments

Comments
 (0)