Skip to content

Commit d77d4b9

Browse files
committed
use gradle application plugin to generate zip file
1 parent 4d754c2 commit d77d4b9

File tree

4 files changed

+347
-26
lines changed

4 files changed

+347
-26
lines changed

build.gradle

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
allprojects {
2-
apply plugin: "java"
3-
}
4-
51
subprojects {
2+
apply plugin: "java"
63
apply plugin: "jacoco"
74
apply plugin: "maven"
85
apply plugin: "maven-publish"
@@ -23,7 +20,7 @@ subprojects {
2320
}
2421
dependencies {
2522
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
26-
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
23+
// classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
2724
}
2825
}
2926

@@ -61,12 +58,3 @@ subprojects {
6158
archives sourcesJar
6259
}
6360
}
64-
65-
task copyToParent(type: Copy) {
66-
into "$buildDir/libs"
67-
subprojects {
68-
from tasks.withType(Jar)
69-
}
70-
}
71-
72-
build.finalizedBy(copyToParent)

framework/build.gradle

+54-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
apply plugin: 'application'
66
apply plugin: 'checkstyle'
7-
apply plugin: 'com.github.johnrengelman.shadow'
7+
//apply plugin: 'com.github.johnrengelman.shadow'
88

99
mainClassName = 'org.tron.program.FullNode'
1010

@@ -133,12 +133,6 @@ run {
133133
}
134134
}
135135

136-
shadowJar {
137-
baseName = 'java-tron'
138-
classifier = null
139-
version = null
140-
}
141-
142136
test {
143137
testLogging {
144138
exceptionFormat = 'full'
@@ -214,10 +208,58 @@ def binaryRelease(taskName, jarName, mainClass) {
214208
}
215209
}
216210
}
211+
startScripts {
212+
doLast {
213+
delete unixScript
214+
}
215+
}
216+
def createScript(project, mainClass, name) {
217+
project.tasks.create(name: name, type: CreateStartScripts) {
218+
unixStartScriptGenerator.template = resources.text.fromFile('../gradle/unixStartScript.txt')
219+
windowsStartScriptGenerator.template = resources.text.fromFile('../gradle/windowsStartScript.txt')
220+
outputDir = new File(project.buildDir, 'scripts')
221+
mainClassName = mainClass
222+
applicationName = name
223+
classpath = project.tasks[JavaPlugin.JAR_TASK_NAME].outputs.files + project.configurations.runtime
224+
defaultJvmOpts = ['-XX:+UseConcMarkSweepGC',
225+
'-XX:+PrintGCDetails',
226+
'-Xloggc:./gc.log',
227+
'-XX:+PrintGCDateStamps',
228+
'-XX:+CMSParallelRemarkEnabled',
229+
'-XX:ReservedCodeCacheSize=256m',
230+
'-XX:+CMSScavengeBeforeRemark'
231+
]
232+
}
233+
project.tasks[name].dependsOn(project.jar)
234+
project.applicationDistribution.with {
235+
into("bin") {
236+
from(project.tasks[name])
237+
fileMode = 0755
238+
}
239+
}
240+
}
217241

218-
artifacts {
219-
archives(binaryRelease('buildSolidityNodeJar', 'SolidityNode', 'org.tron.program.SolidityNode'),
220-
binaryRelease('buildFullNodeJar', 'FullNode', 'org.tron.program.FullNode'),
221-
binaryRelease('buildKeystoreFactoryJar', 'KeystoreFactory', 'org.tron.program.KeystoreFactory'),
222-
binaryRelease('buildDBConvertJar', 'DBConvert', 'org.tron.program.DBConvert'))
242+
distZip {
243+
doLast {
244+
file("$destinationDir/$archiveName").renameTo("$destinationDir/"+'java-tron-'+version+'-bin.zip')
245+
}
223246
}
247+
248+
applicationName = 'java-tron'
249+
startScripts.enabled = false
250+
run.enabled = false
251+
tasks.distTar.enabled = false
252+
253+
createScript(project, 'org.tron.program.SolidityNode', 'SolidityNode')
254+
createScript(project, 'org.tron.program.FullNode', 'FullNode')
255+
createScript(project, 'org.tron.program.KeystoreFactory', 'KeystoreFactory')
256+
createScript(project, 'org.tron.program.DBConvert', 'DBConvert')
257+
258+
259+
task copyToParent(type: Copy) {
260+
into "../build/distributions"
261+
from "$buildDir/distributions"
262+
include "*.zip"
263+
}
264+
265+
build.finalizedBy(copyToParent)

gradle/unixStartScript.txt

+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
#!/usr/bin/env sh
2+
3+
#
4+
# Copyright 2015 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
##############################################################################
20+
##
21+
## ${applicationName} start up script for UN*X
22+
##
23+
##############################################################################
24+
25+
# Attempt to set APP_HOME
26+
# Resolve links: \$0 may be a link
27+
PRG="\$0"
28+
# Need this for relative symlinks.
29+
while [ -h "\$PRG" ] ; do
30+
ls=`ls -ld "\$PRG"`
31+
link=`expr "\$ls" : '.*-> \\(.*\\)\$'`
32+
if expr "\$link" : '/.*' > /dev/null; then
33+
PRG="\$link"
34+
else
35+
PRG=`dirname "\$PRG"`"/\$link"
36+
fi
37+
done
38+
SAVED="`pwd`"
39+
cd "`dirname \"\$PRG\"`/${appHomeRelativePath}" >/dev/null
40+
APP_HOME="`pwd -P`"
41+
cd "\$SAVED" >/dev/null
42+
43+
APP_NAME="${applicationName}"
44+
APP_BASE_NAME=`basename "\$0"`
45+
46+
UNAME=\$(uname -s)
47+
if [ x"\$UNAME" == x"Linux" ];then
48+
TOTAL=\$(cat /proc/meminfo |grep MemTotal |awk -F ' ' '{print \$2}')
49+
MEM=\$(echo "\$TOTAL/1024/1024*0.8" | bc |awk -F. '{print \$1"g"}')
50+
JAVA_OPTS='"-Xmx\$MEM" "-Xms\$MEM"'
51+
fi
52+
53+
# Add default JVM options here. You can also use JAVA_OPTS and ${optsEnvironmentVar} to pass JVM options to this script.
54+
DEFAULT_JVM_OPTS=${defaultJvmOpts}
55+
56+
# Use the maximum available, or set MAX_FD != -1 to use that value.
57+
MAX_FD="maximum"
58+
59+
warn () {
60+
echo "\$*"
61+
}
62+
63+
die () {
64+
echo
65+
echo "\$*"
66+
echo
67+
exit 1
68+
}
69+
70+
# OS specific support (must be 'true' or 'false').
71+
cygwin=false
72+
msys=false
73+
darwin=false
74+
nonstop=false
75+
case "`uname`" in
76+
CYGWIN* )
77+
cygwin=true
78+
;;
79+
Darwin* )
80+
darwin=true
81+
;;
82+
MINGW* )
83+
msys=true
84+
;;
85+
NONSTOP* )
86+
nonstop=true
87+
;;
88+
esac
89+
90+
CLASSPATH=$classpath
91+
92+
# Determine the Java command to use to start the JVM.
93+
if [ -n "\$JAVA_HOME" ] ; then
94+
if [ -x "\$JAVA_HOME/jre/sh/java" ] ; then
95+
# IBM's JDK on AIX uses strange locations for the executables
96+
JAVACMD="\$JAVA_HOME/jre/sh/java"
97+
else
98+
JAVACMD="\$JAVA_HOME/bin/java"
99+
fi
100+
if [ ! -x "\$JAVACMD" ] ; then
101+
die "ERROR: JAVA_HOME is set to an invalid directory: \$JAVA_HOME
102+
103+
Please set the JAVA_HOME variable in your environment to match the
104+
location of your Java installation."
105+
fi
106+
else
107+
JAVACMD="java"
108+
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
109+
110+
Please set the JAVA_HOME variable in your environment to match the
111+
location of your Java installation."
112+
fi
113+
114+
# Increase the maximum file descriptors if we can.
115+
if [ "\$cygwin" = "false" -a "\$darwin" = "false" -a "\$nonstop" = "false" ] ; then
116+
MAX_FD_LIMIT=`ulimit -H -n`
117+
if [ \$? -eq 0 ] ; then
118+
if [ "\$MAX_FD" = "maximum" -o "\$MAX_FD" = "max" ] ; then
119+
MAX_FD="\$MAX_FD_LIMIT"
120+
fi
121+
ulimit -n \$MAX_FD
122+
if [ \$? -ne 0 ] ; then
123+
warn "Could not set maximum file descriptor limit: \$MAX_FD"
124+
fi
125+
else
126+
warn "Could not query maximum file descriptor limit: \$MAX_FD_LIMIT"
127+
fi
128+
fi
129+
130+
# For Darwin, add options to specify how the application appears in the dock
131+
if \$darwin; then
132+
GRADLE_OPTS="\$GRADLE_OPTS \\"-Xdock:name=\$APP_NAME\\" \\"-Xdock:icon=\$APP_HOME/media/gradle.icns\\""
133+
fi
134+
135+
# For Cygwin or MSYS, switch paths to Windows format before running java
136+
if [ "\$cygwin" = "true" -o "\$msys" = "true" ] ; then
137+
APP_HOME=`cygpath --path --mixed "\$APP_HOME"`
138+
CLASSPATH=`cygpath --path --mixed "\$CLASSPATH"`
139+
JAVACMD=`cygpath --unix "\$JAVACMD"`
140+
141+
# We build the pattern for arguments to be converted via cygpath
142+
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
143+
SEP=""
144+
for dir in \$ROOTDIRSRAW ; do
145+
ROOTDIRS="\$ROOTDIRS\$SEP\$dir"
146+
SEP="|"
147+
done
148+
OURCYGPATTERN="(^(\$ROOTDIRS))"
149+
# Add a user-defined pattern to the cygpath arguments
150+
if [ "\$GRADLE_CYGPATTERN" != "" ] ; then
151+
OURCYGPATTERN="\$OURCYGPATTERN|(\$GRADLE_CYGPATTERN)"
152+
fi
153+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
154+
i=0
155+
for arg in "\$@" ; do
156+
CHECK=`echo "\$arg"|egrep -c "\$OURCYGPATTERN" -`
157+
CHECK2=`echo "\$arg"|egrep -c "^-"` ### Determine if an option
158+
159+
if [ \$CHECK -ne 0 ] && [ \$CHECK2 -eq 0 ] ; then ### Added a condition
160+
eval `echo args\$i`=`cygpath --path --ignore --mixed "\$arg"`
161+
else
162+
eval `echo args\$i`="\"\$arg\""
163+
fi
164+
i=`expr \$i + 1`
165+
done
166+
case \$i in
167+
0) set -- ;;
168+
1) set -- "\$args0" ;;
169+
2) set -- "\$args0" "\$args1" ;;
170+
3) set -- "\$args0" "\$args1" "\$args2" ;;
171+
4) set -- "\$args0" "\$args1" "\$args2" "\$args3" ;;
172+
5) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" ;;
173+
6) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" ;;
174+
7) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" "\$args6" ;;
175+
8) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" "\$args6" "\$args7" ;;
176+
9) set -- "\$args0" "\$args1" "\$args2" "\$args3" "\$args4" "\$args5" "\$args6" "\$args7" "\$args8" ;;
177+
esac
178+
fi
179+
180+
# Escape application args
181+
save () {
182+
for i do printf %s\\\\n "\$i" | sed "s/'/'\\\\\\\\''/g;1s/^/'/;\\\$s/\\\$/' \\\\\\\\/" ; done
183+
echo " "
184+
}
185+
APP_ARGS=`save "\$@"`
186+
187+
# Collect all arguments for the java command, following the shell quoting and substitution rules
188+
eval set -- \$DEFAULT_JVM_OPTS \$JAVA_OPTS \$${optsEnvironmentVar} <% if ( appNameSystemProperty ) { %>"\"-D${appNameSystemProperty}=\$APP_BASE_NAME\"" <% } %>-classpath "\"\$CLASSPATH\"" ${mainClassName} "\$APP_ARGS"
189+
190+
exec "\$JAVACMD" "\$@"

0 commit comments

Comments
 (0)