|
| 1 | +import java.util.regex.Matcher |
| 2 | + |
| 3 | +buildscript { |
| 4 | + repositories { |
| 5 | + maven { url 'https://plugins.gradle.org/m2/' } |
| 6 | + } |
| 7 | + dependencies { |
| 8 | + classpath 'com.netflix.nebula:gradle-ospackage-plugin:6.1.1' |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +apply plugin: 'java' |
| 13 | +apply plugin: 'java-library' |
| 14 | +apply plugin: 'application' |
| 15 | +apply plugin: 'nebula.ospackage-application' |
| 16 | + |
| 17 | +group = 'ai.swim' |
| 18 | +description = 'tutorial Web Agents' |
| 19 | +ext.moduleName = 'swim.tutorial' |
| 20 | +sourceCompatibility = 1.9 |
| 21 | +version = project.property('application.version') |
| 22 | +mainClassName = 'swim.tutorial.TutorialPlane' |
| 23 | + |
| 24 | +//def moduleName = 'swim.tutorial' |
| 25 | +def jvmVersion = System.getProperty('java.version').split('\\.')[0] as Integer |
| 26 | +def useModules = jvmVersion >= 9 && !project.hasProperty('no-modules') |
| 27 | + |
| 28 | +repositories { |
| 29 | + jcenter() |
| 30 | + maven { |
| 31 | + url "https://oss.sonatype.org/content/repositories/snapshots/" |
| 32 | + } |
| 33 | + |
| 34 | +} |
| 35 | + |
| 36 | +dependencies { |
| 37 | + compile 'ai.swim:swim-loader:3.9.1-SNAPSHOT' |
| 38 | + compile 'ai.swim:swim-server:3.9.1-SNAPSHOT' |
| 39 | + compile 'ai.swim:swim-client:3.9.1-SNAPSHOT' |
| 40 | +} |
| 41 | + |
| 42 | +afterEvaluate { |
| 43 | + compileJava { |
| 44 | + if (useModules) { |
| 45 | + doFirst { |
| 46 | + options.compilerArgs += [ |
| 47 | + '--module-path', classpath.asPath, |
| 48 | + ] |
| 49 | + classpath = files() |
| 50 | + } |
| 51 | + } |
| 52 | + options.compilerArgs += ['-Xlint'] |
| 53 | + options.encoding = 'UTF-8' |
| 54 | + } |
| 55 | + |
| 56 | + jar { |
| 57 | + inputs.property('moduleName', moduleName) |
| 58 | + manifest { |
| 59 | + attributes( |
| 60 | + 'Implementation-Title': moduleName, |
| 61 | + 'Implementation-Version': version, |
| 62 | + 'Main-Class': mainClassName) |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + tasks.withType(JavaCompile) { |
| 67 | + options.encoding = 'UTF-8' |
| 68 | + if (!useModules) { |
| 69 | + exclude '*module-info*' |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + run { |
| 74 | + dependsOn jar |
| 75 | + doFirst { |
| 76 | + jvmArgs += [ |
| 77 | + '--module-path', files(configurations.runtimeClasspath, jar.archivePath).asPath, |
| 78 | + '--module', "${moduleName}/${mainClassName}" |
| 79 | + ] |
| 80 | + classpath = files() |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + startScripts { |
| 85 | + inputs.property("moduleName", moduleName) |
| 86 | + doFirst { |
| 87 | + classpath = files() |
| 88 | + defaultJvmOpts = [ |
| 89 | + '-Dswim.config=/etc/swim-tutorial/server.recon', |
| 90 | + '-Xms3g', |
| 91 | + '-Xmx3g', |
| 92 | + '--module-path', 'APP_HOME_LIBS', |
| 93 | + '--module', "${moduleName}/${mainClassName}" |
| 94 | + ] |
| 95 | + } |
| 96 | + doLast { |
| 97 | + def bashFile = new File(outputDir, applicationName) |
| 98 | + String bashContent = bashFile.text |
| 99 | + bashFile.text = bashContent.replaceFirst('APP_HOME_LIBS', Matcher.quoteReplacement('$APP_HOME/lib')) |
| 100 | + |
| 101 | + def batFile = new File(outputDir, applicationName + ".bat") |
| 102 | + String batContent = batFile.text |
| 103 | + batFile.text = batContent.replaceFirst('APP_HOME_LIBS', Matcher.quoteReplacement('%APP_HOME%\\lib')) |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + ospackage { |
| 108 | + release '1' |
| 109 | + prefix '/opt/swim-tutorial' |
| 110 | + } |
| 111 | + |
| 112 | + task packageDeb(type: Deb) { |
| 113 | + maintainer = 'developer@swim.ai' |
| 114 | + |
| 115 | + configurationFile("/etc/sysconfig/${project.name}") |
| 116 | + preInstall "addgroup --quiet --system ${project.name}" |
| 117 | + preInstall "adduser --quiet --system --ingroup ${project.name} --no-create-home --disabled-password ${project.name}" |
| 118 | + postInstall "systemctl preset ${project.name} > /dev/null 2>&1" |
| 119 | + postInstall "systemctl start ${project.name} > /dev/null 2>&1" |
| 120 | + preUninstall "systemctl disable ${project.name} > /dev/null 2>&1" |
| 121 | + preUninstall "systemctl stop ${project.name} > /dev/null 2>&1" |
| 122 | + postUninstall "systemctl daemon-reload > /dev/null 2>&1" |
| 123 | + |
| 124 | + from('pkg') { |
| 125 | + into '/etc/systemd/system' |
| 126 | + include '*.service' |
| 127 | + addParentDirs false |
| 128 | + expand project.properties |
| 129 | + user 'root' |
| 130 | + permissionGroup 'root' |
| 131 | + fileMode = 0644 |
| 132 | + } |
| 133 | + |
| 134 | + from('pkg') { |
| 135 | + into '/etc/sysconfig' |
| 136 | + include "${project.name}" |
| 137 | + user 'root' |
| 138 | + permissionGroup 'root' |
| 139 | + fileMode = 0644 |
| 140 | + fileType CONFIG | NOREPLACE |
| 141 | + } |
| 142 | + } |
| 143 | +} |
0 commit comments