diff --git a/gradle.properties b/gradle.properties deleted file mode 100755 index 55dfbf7..0000000 --- a/gradle.properties +++ /dev/null @@ -1,2 +0,0 @@ -ng.name=unify4j -ng.version=v1.0.0 diff --git a/plugin/build.gradle b/plugin/build.gradle index e6111a2..766035b 100755 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -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 @@ -24,10 +33,49 @@ 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 config) { + enabled = config['enabled'] ?: false + source = config['source'] ?: '' + } +} + +class NgConfig { + String name + String version + boolean enabledLink + List jars + + @SuppressWarnings('GroovyAssignabilityCheck') + NgConfig(Map 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 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) + } else { + println '⚠️ gradle.yml not found, using default configuration' + return new NgConfig(new HashMap()) + } +} // Define a task to build the Groovy library into a JAR tasks.register('buildGroovyJar', Jar) { @@ -35,8 +83,8 @@ tasks.register('buildGroovyJar', Jar) { 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' } @@ -46,12 +94,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, diff --git a/plugin/gradle.yml b/plugin/gradle.yml new file mode 100644 index 0000000..2566371 --- /dev/null +++ b/plugin/gradle.yml @@ -0,0 +1,9 @@ +ng: + name: unify4j + version: v1.0.0 + enabled_link: false # enable compression and attachment of the external libraries + jars: + - enabled: false # enable compression and attachment of the external libraries + source: "" # lib Jar + - enabled: false + source: ""