-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·191 lines (160 loc) · 5.48 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
# Use the 'Project/data' folder for initial data.
# Use the './data' folder for development data (or initial data).
# Use the './Project/assets' folder to add data into the JAR file.
reset
folderDevelopment="Project"
folderRelease="Release"
# Get into the development directory
cd $folderDevelopment
# Check if is JavaFX
isJavaFX=false
if ls lib/javafx* 1> /dev/null 2>&1; then
isJavaFX=true
if [[ $OSTYPE == 'linux-gnu' ]]; then
MODULEPATH=./lib/javafx-linux/lib
fi
if [[ $OSTYPE == 'darwin'* ]] && [[ $(arch) == 'i386' ]]; then
MODULEPATH=./lib/javafx-osx-intel/lib
fi
if [[ $OSTYPE == 'darwin'* ]] && [[ $(arch) == 'arm64' ]]; then
MODULEPATH=./lib/javafx-osx-arm/lib
fi
MODULEPATH="--module-path $MODULEPATH --add-modules javafx.controls,javafx.fxml"
fi
# Check if is Hibernate
HIBERNATEX=""
HIBERNATEW=""
if [ -n "$(find . -maxdepth 1 -type f -name 'hibernate.properties' -print -quit)" ]; then
HIBERNATEX="--add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED"
HIBERNATEW="--add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --enable-preview -XX:+ShowCodeDetailsInExceptionMessages"
fi
# Remove any existing .class files from the bin directory
rm -rf ./bin
# Create the bin directory if it doesn't exist
mkdir -p ./bin
# Copy the assets directory to the bin directory
if [ -d ./assets ]; then
cp -r ./assets ./bin
fi
if [ -d ./icons ]; then
cp -r ./icons ./bin
fi
# Generate the CLASSPATH by iterating over JAR files in the lib directory and its subdirectories
lib_dir="lib"
jar_files=()
# Find all JAR files in the lib directory and its subdirectories
if [ -d ./lib ]; then
while IFS= read -r -d '' jar_file; do
if [[ "$jar_file" != *"javafx"* ]]; then
jar_files+=("$jar_file")
fi
done < <(find "$lib_dir" -name "*.jar" -type f -print0)
fi
# Join the JAR files into the class_path
class_path=$(IFS=:; echo "${jar_files[*]}")
# Remove the leading ':' from the class_path
CLASSPATHX=${class_path#:}
if [ -n "$CLASSPATHX" ]; then
CLASSPATHX="-cp \"$CLASSPATHX\""
fi
# Unir els fitxers JAR en el class_path
class_path_win=$(IFS=";"; printf "%s" "${jar_files[*]}")
class_path_win=$(echo "$class_path_win" | sed 's|lib/|.\\lib\\|g')
# Eliminar el ':' inicial del class_path
CLASSPATHW=${class_path_win#:}
if [ -n "$CLASSPATHW" ]; then
CLASSPATHW="-cp \"$CLASSPATHW\""
fi
# Compile the Java source files and place the .class files in the bin directory
eval "javac -d ./bin/ ./src/*.java $CLASSPATHX $MODULEPATH"
# Create the Project.jar file with the specified manifest file and the contents of the bin directory
jar cfm ./Project.jar ./Manifest.txt -C bin .
# Remove any .class files from the bin directory
rm -rf ./bin
# Get out of the development directory
cd ..
# Move 'data' temporally
if [ -d "./$folderRelease/data" ]; then
mv "./$folderRelease/data" ./
fi
# Erase and create $folderRelease
rm -rf ./$folderRelease
mkdir -p ./$folderRelease
# Move 'data' to $folderRelease
if [ -d "./data" ]; then
mv ./data "./$folderRelease/"
elif [ -d "./$folderDevelopment/data" ]; then
cp -r ./$folderDevelopment/data "./$folderRelease/"
fi
# Move the Project.jar file to the release directory
mv ./$folderDevelopment/Project.jar ./$folderRelease/Project.jar
# Copy lib if it exists
if [ -d ./$folderDevelopment/lib ]; then
cp -r ./$folderDevelopment/lib ./$folderRelease/lib
fi
# Copy icons if they exist
if [ -d ./$folderDevelopment/icons ] && [ "$isJavaFX" = true ]; then
cp -r ./$folderDevelopment/icons ./$folderRelease/icons
fi
# Copy .properties if they exist
if [ -n "$(find ./$folderDevelopment -maxdepth 1 -type f -name '*.properties' -print -quit)" ]; then
cp -r ./$folderDevelopment/*.properties ./$folderRelease/
fi
# Copy .xml if they exist (for Hibernate)
if [ -n "$(find ./$folderDevelopment -maxdepth 1 -type f -name '*.xml' -print -quit)" ]; then
cp -r ./$folderDevelopment/*.xml ./$folderRelease/
fi
# Add Project.jar to classpath
CLASSPATHX=${CLASSPATHX/#"-cp \""/}
if [ -n "$CLASSPATHX" ]; then
CLASSPATHX="-cp \"Project.jar:$CLASSPATHX"
else
CLASSPATHX="-cp \"Project.jar\""
fi
CLASSPATHW=${CLASSPATHW/#"-cp \""/}
if [ -n "$CLASSPATHW" ]; then
CLASSPATHW="-cp \"Project.jar;$CLASSPATHW"
else
CLASSPATHW="-cp \"Project.jar\""
fi
# Create the 'run.sh' and 'run.ps1' files
if [ "$isJavaFX" != true ]; then
cat > ./$folderRelease/run.sh << EOF
#!/bin/bash
java $HIBERNATEX $CLASSPATHX Main
EOF
cat > ./$folderRelease/run.ps1 << EOF
java $HIBERNATEW $CLASSPATHW Main
EOF
else
cat > ./$folderRelease/run.sh << EOF
#!/bin/bash
MODULEPATH=""
ICON=""
if ls lib/javafx* 1> /dev/null 2>&1; then
if [[ \$OSTYPE == 'linux-gnu' ]]; then
MODULEPATH=./lib/javafx-linux/lib
fi
if [[ \$OSTYPE == 'darwin'* ]] && [[ \$(arch) == 'i386' ]]; then
MODULEPATH=./lib/javafx-osx-intel/lib
ICON=-Xdock:icon=icons/iconOSX.png
fi
if [[ \$OSTYPE == 'darwin'* ]] && [[ \$(arch) == 'arm64' ]]; then
MODULEPATH=./lib/javafx-osx-arm/lib
ICON=-Xdock:icon=icons/iconOSX.png
fi
MODULEPATH="--module-path \$MODULEPATH --add-modules javafx.controls,javafx.fxml"
fi
java $HIBERNATEX \$ICON \$MODULEPATH $CLASSPATHX Main
EOF
cat > ./$folderRelease/run.ps1 << EOF
java $HIBERNATEW --module-path "./lib/javafx-windows/lib" --add-modules javafx.controls,javafx.fxml $CLASSPATHW Main
EOF
fi
# Fem l'arxiu executable
chmod +x ./$folderRelease/run.sh
# Run the Project.jar file
cd ./$folderRelease
./run.sh
cd