-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·139 lines (119 loc) · 4.09 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/sh
USAGE="
usage: $0 action [-all]
valid actions:
clean
compile
jar
test-valid run tests expected to compile with no errors
test-errors run tests expected to show errors
test run all tests
install install locally with maven
bundle bundle for release to central
use -all to test against all JDKs in \$HOME/tools
"
# project configuration
GROUP="io.github.rogerkeays"
ARTIFACT="fluent"
VERSION="0.3.1"
DESCRIPTION="Static extension methods for Java"
LICENSE="MIT License"
DEVELOPER="Roger Keays"
GITHUB_NAME="rogerkeays"
EMAIL="realguybrush@vivaldi.net"
# build configuration
TARGET=9
PACKAGE="com.sun.tools.javac.comp"
CLASSNAME="Fluent"
JAR="$ARTIFACT.jar"
PLUGIN="-Xplugin:fluent"
TEST_OPTS="-J--add-opens=java.base/java.lang=ALL-UNNAMED "
TEST_CLASSPATH="$JAR"
# location of jdk for building
[ ! "$JAVA_HOME" ] && JAVA_HOME="$(dirname $(dirname $(readlink -f $(which javac))))"
# directories containing jdks to test against, separated by spaces
JDKS="$JAVA_HOME"
[ "$2" = "-all" ] && JDKS="$HOME/tools/jdk-*"
# build code starts here
[ ! $1 ] && echo "$USAGE" && exit 1;
echo ">>> clean"
[ -d target ] && rm -r target
[ $1 = "clean" ] && exit 0
# note: -source 8 is required to import com.sun.tools.javac.*
echo ">>> compile ($JAVA_HOME)"
$JAVA_HOME/bin/javac -Xlint:unchecked -nowarn -source 8 -target $TARGET -d target $CLASSNAME.java
[ $? -eq 0 ] || exit 1
[ $1 = "compile" ] && exit 0
echo ">>> jar"
mkdir -p target/META-INF/services
echo "$PACKAGE.$CLASSNAME" > target/META-INF/services/com.sun.source.util.Plugin
cd target; $JAVA_HOME/bin/jar -cf ../$JAR *; cd ..
[ $1 = "jar" ] && exit 0
for JDK in $JDKS; do
echo ">>> test-valid ($JDK)"
"$JDK"/bin/javac -cp $TEST_CLASSPATH -d target "$PLUGIN" $TEST_OPTS TestValid.java
[ $? -eq 0 ] || exit 1
"$JDK"/bin/java -cp target -enableassertions TestValid
[ $? -eq 0 ] || exit 1
done
[ $1 = "test-valid" ] && exit 0
for JDK in $JDKS; do
echo ">>> test-errors ($JDK)"
"$JDK"/bin/javac -cp $TEST_CLASSPATH -d target "$PLUGIN" $TEST_OPTS TestErrors.java
done
[ $1 = "test-errors" ] && exit 0
[ $1 = "test" ] && exit 0
echo ">>> install"
mvn install:install-file -DgroupId=$GROUP -DartifactId=$ARTIFACT -Dversion=$VERSION -Dpackaging=jar -Dfile=$JAR
[ $? -eq 0 ] || exit 1
[ $1 = "install" ] && exit 0
echo ">>> bundle"
mkdir target/bundle
echo "<?xml version='1.0' encoding='UTF-8'?>
<project xmlns='http://maven.apache.org/POM/4.0.0'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd'>
<modelVersion>4.0.0</modelVersion>
<groupId>$GROUP</groupId>
<artifactId>$ARTIFACT</artifactId>
<packaging>jar</packaging>
<version>$VERSION</version>
<name>$CLASSNAME</name>
<description>$DESCRIPTION</description>
<url>https://github.com/$GITHUB_NAME/$ARTIFACT</url>
<licenses>
<license>
<name>$LICENSE</name>
<url>https://github.com/$GITHUB_NAME/$ARTIFACT/LICENSE</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<name>$DEVELOPER</name>
<email>$EMAIL</email>
<organization>Individual</organization>
<organizationUrl>https://github.com/$GITHUB_NAME</organizationUrl>
</developer>
</developers>
<scm>
<connection>scm:git:git://github.com/$GITHUB_NAME/$ARTIFACT.git</connection>
<developerConnection>scm:git:ssh://github.com:$GITHUB_NAME/$ARTIFACT.git</developerConnection>
<url>https://github.com/$GITHUB_NAME/$ARTIFACT/tree/master</url>
</scm>
</project>
" >> target/bundle/$ARTIFACT-$VERSION.pom
cp $JAR target/bundle/$ARTIFACT-$VERSION.jar
$JAVA_HOME/bin/jar -cf target/bundle/$ARTIFACT-$VERSION-sources.jar *.java
$JAVA_HOME/bin/javadoc --source 8 -d target/javadoc $CLASSNAME.java
cd target/javadoc
$JAVA_HOME/bin/jar -cf ../bundle/$ARTIFACT-$VERSION-javadoc.jar *
cd ../bundle
for i in *; do gpg -ab $i; done
for i in *; do
md5sum $i > $i.md5
sha1sum $i > $i.sha1
sha256sum $i > $i.sha256
sha512sum $i > $i.sha512
done
$JAVA_HOME/bin/jar -cf ../$ARTIFACT-$VERSION.bundle.jar *