@@ -144,7 +144,69 @@ if [ -f "$APP_DIR/build.sh" ]; then
144144 chmod +x " $APP_DIR /build.sh"
145145fi
146146
147- MAIN_FILE=$( find " $APP_DIR " -path " */common/src/main/java/*Application.java" | head -n 1 || true)
147+ SETTINGS_FILE=" $APP_DIR /common/codenameone_settings.properties"
148+ if [ ! -f " $SETTINGS_FILE " ]; then
149+ ba_log " codenameone_settings.properties not found at $SETTINGS_FILE " >&2
150+ exit 1
151+ fi
152+
153+ CN1_SETTINGS_TMP=$( mktemp)
154+ trap ' rm -f "$CN1_SETTINGS_TMP"' EXIT
155+
156+ SETTINGS_FILE=" $SETTINGS_FILE " python3 << 'PY ' >"$CN1_SETTINGS_TMP"
157+ import os
158+ import pathlib
159+ import shlex
160+
161+ path = pathlib.Path(os.environ['SETTINGS_FILE'])
162+ package = ""
163+ main_name = ""
164+ if path.exists():
165+ for line in path.read_text().splitlines():
166+ stripped = line.strip()
167+ if not stripped or stripped.startswith('#'):
168+ continue
169+ if stripped.startswith('codename1.packageName=') and not package:
170+ package = stripped.split('=', 1)[1].strip()
171+ elif stripped.startswith('codename1.mainName=') and not main_name:
172+ main_name = stripped.split('=', 1)[1].strip()
173+
174+ print(f"CN1_PACKAGE_NAME={shlex.quote(package)}")
175+ print(f"CN1_CURRENT_MAIN_NAME={shlex.quote(main_name)}")
176+ PY
177+
178+ # shellcheck disable=SC1090
179+ source " $CN1_SETTINGS_TMP "
180+ rm -f " $CN1_SETTINGS_TMP "
181+ trap - EXIT
182+
183+ PACKAGE_NAME=" ${CN1_PACKAGE_NAME:- } "
184+ CURRENT_MAIN_NAME=" ${CN1_CURRENT_MAIN_NAME:- } "
185+
186+ if [ -z " $PACKAGE_NAME " ]; then
187+ PACKAGE_NAME=" $GROUP_ID "
188+ ba_log " Package name not found in settings. Falling back to groupId $PACKAGE_NAME "
189+ fi
190+
191+ if [ -z " $CURRENT_MAIN_NAME " ]; then
192+ CURRENT_MAIN_NAME=" $MAIN_NAME "
193+ ba_log " Main class name not found in settings. Falling back to target $CURRENT_MAIN_NAME "
194+ fi
195+
196+ PACKAGE_PATH=" ${PACKAGE_NAME// .// } "
197+ if [ -n " $PACKAGE_PATH " ]; then
198+ EXPECTED_MAIN_PATH=" $APP_DIR /common/src/main/java/$PACKAGE_PATH /$CURRENT_MAIN_NAME .java"
199+ else
200+ EXPECTED_MAIN_PATH=" $APP_DIR /common/src/main/java/$CURRENT_MAIN_NAME .java"
201+ fi
202+
203+ if [ -f " $EXPECTED_MAIN_PATH " ]; then
204+ MAIN_FILE=" $EXPECTED_MAIN_PATH "
205+ else
206+ ba_log " Expected main source $EXPECTED_MAIN_PATH not found. Scanning project tree for $CURRENT_MAIN_NAME .java"
207+ MAIN_FILE=$( find " $APP_DIR /common/src/main/java" -name " $CURRENT_MAIN_NAME .java" | head -n 1 || true)
208+ fi
209+
148210if [ -z " $MAIN_FILE " ]; then
149211 ba_log " Could not locate the generated application source file" >&2
150212 exit 1
@@ -198,11 +260,9 @@ public class ${MAIN_NAME} {
198260}
199261HELLOEOF
200262
201- SETTINGS_FILE=" $APP_DIR /common/codenameone_settings.properties"
202263ba_log " Setting codename1.mainName to $MAIN_NAME "
203- if [ -f " $SETTINGS_FILE " ]; then
204- if grep -q ' ^codename1.mainName=' " $SETTINGS_FILE " ; then
205- python3 - " $SETTINGS_FILE " " $MAIN_NAME " << 'PY '
264+ if grep -q ' ^codename1.mainName=' " $SETTINGS_FILE " ; then
265+ python3 - " $SETTINGS_FILE " " $MAIN_NAME " << 'PY '
206266import pathlib
207267import re
208268import sys
@@ -217,17 +277,13 @@ else:
217277 text = text + ('\n' if not text.endswith('\n') else '') + replacement + '\n'
218278path.write_text(text if text.endswith('\n') else text + '\n')
219279PY
220- else
221- printf ' \ncodename1.mainName=%s\n' " $MAIN_NAME " >> " $SETTINGS_FILE "
222- fi
223280else
224- printf ' codename1 .mainName=%s\n' " $MAIN_NAME " > " $SETTINGS_FILE "
281+ printf ' \ncodename1 .mainName=%s\n' " $MAIN_NAME " > > " $SETTINGS_FILE "
225282fi
226283
227284ba_log " Disabling Codename One CSS compilation to avoid headless failures"
228- if [ -f " $SETTINGS_FILE " ]; then
229- if grep -q ' ^codename1.cssTheme=' " $SETTINGS_FILE " ; then
230- python3 - " $SETTINGS_FILE " << 'PY '
285+ if grep -q ' ^codename1.cssTheme=' " $SETTINGS_FILE " ; then
286+ python3 - " $SETTINGS_FILE " << 'PY '
231287import pathlib
232288import re
233289import sys
@@ -241,11 +297,8 @@ else:
241297 text = text + ('\n' if not text.endswith('\n') else '') + replacement + '\n'
242298path.write_text(text if text.endswith('\n') else text + '\n')
243299PY
244- else
245- printf ' \ncodename1.cssTheme=false\n' >> " $SETTINGS_FILE "
246- fi
247300else
248- printf ' codename1 .cssTheme=false\n' > " $SETTINGS_FILE "
301+ printf ' \ncodename1 .cssTheme=false\n' > > " $SETTINGS_FILE "
249302fi
250303
251304ba_log " Building Android gradle project using Codename One port"
0 commit comments