Skip to content

Commit 0475893

Browse files
committed
build.gradle: added new launchers
1 parent 5731305 commit 0475893

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

snaploader-examples/build.gradle

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ plugins {
33
id 'application'
44
}
55

6+
/** get system specific separated directories for the source and the destination of the dependencies */
7+
String dependenciesDir = "${rootDir.getPath()}/snaploader-examples/build/libs/dependencies/"
8+
String libsDir = "${rootDir.getPath()}/snaploader/build/libs/"
9+
final String dependencyName = "snaploader-${version}.jar"
10+
11+
/** replace unix '/' with windows escaped '\' */
12+
if (System.getProperty("os.name").contains("Windows")) {
13+
dependenciesDir = dependenciesDir.replaceAll("/", "\\\\")
14+
libsDir = libsDir.replaceAll("/", "\\\\")
15+
}
16+
617
application {
718
mainClass = 'electrostatic.snaploader.examples.TestBasicFeatures'
819
}
@@ -15,6 +26,14 @@ tasks.register("TestBasicFeatures2") {
1526
application.mainClass = 'electrostatic.snaploader.examples.TestBasicFeatures2'
1627
}
1728

29+
tasks.register("MonitorableExample") {
30+
application.mainClass = 'electrostatic.snaploader.examples.MonitorableExample'
31+
}
32+
33+
tasks.register("ReflectiveLauncher") {
34+
application.mainClass = 'electrostatic.snaploader.examples.ReflectiveLauncher'
35+
}
36+
1837
tasks.register("TestMultipleLoads") {
1938
application.mainClass = 'electrostatic.snaploader.examples.TestMultipleLoads'
2039
}
@@ -27,6 +46,44 @@ tasks.register("TestMultiThreading") {
2746
application.mainClass = 'electrostatic.snaploader.examples.TestMultiThreading'
2847
}
2948

49+
task copyLibs(type: Copy) {
50+
from (libsDir) {
51+
include '**/*.jar'
52+
}
53+
into(dependenciesDir)
54+
includeEmptyDirs = false
55+
setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE)
56+
}
57+
58+
/** Assembles a jar file with a class-path loading the dependencies and a main-class */
59+
task createJar(type : Jar, dependsOn : copyLibs){
60+
//get the copied jars
61+
String dependenciesString = ""
62+
final File dependencies = new File(dependenciesDir)
63+
if(dependencies.exists()) {
64+
if (dependencies.listFiles().length > 0) {
65+
final File[] files = dependencies.listFiles()
66+
for (int i = 0; i < files.length; i++) {
67+
final String fileName = files[i].getName()
68+
if (fileName.contains(".jar")) {
69+
/** All zip paths are unix paths; so no need to the file system specific separator */
70+
dependenciesString += "dependencies/" + fileName + " "
71+
}
72+
}
73+
}
74+
}
75+
76+
manifest {
77+
attributes 'Project': 'snaploader-examples',
78+
'Automatic-Module-Name': "${project.name.replace("-", ".")}",
79+
'Compiled-by': JavaVersion.current(),
80+
'Class-Path': dependenciesString,
81+
'Main-Class': application.mainClass
82+
}
83+
with jar
84+
}
85+
86+
3087
dependencies {
3188
implementation project(path: ':snaploader')
32-
}
89+
}

0 commit comments

Comments
 (0)