Skip to content

Commit d116bb5

Browse files
authored
feat: add support for local builder properties for local builds. (#3824)
You can add a properties file at ~/.codenameone/local.properties in which you can define the java17.home property to point to your Java17 home. Also added android34 build tools target support
1 parent 56d2119 commit d116bb5

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

maven/codenameone-maven-plugin/src/main/java/com/codename1/builders/AndroidGradleBuilder.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,19 @@ private String getGradleVersion(String gradleExe) throws Exception {
436436
private String getGradleJavaHome() throws BuildException {
437437
if (useGradle8) {
438438
String home = System.getenv("JAVA17_HOME");
439+
if (home == null && (home = getLocalBuilderProperties().getProperty("java17.home", null)) != null) {
440+
if (!(new File(home)).isDirectory()) {
441+
throw new BuildException("The java17.home property is not set to a valid directory. " +
442+
"You have defined it in your ~/.codenameone/local.properties file, " +
443+
"but it is not a valid directory."
444+
);
445+
}
446+
}
439447
if (home == null) {
440-
throw new BuildException("When using gradle 8, you must set the JAVA17_HOME environment variable to the location of a Java 17 JDK");
448+
throw new BuildException(
449+
"When using gradle 8, " +
450+
"you must set the JAVA17_HOME environment variable to the location of a Java 17 JDK"
451+
);
441452
}
442453

443454
if (!(new File(home).isDirectory())) {
@@ -448,7 +459,6 @@ private String getGradleJavaHome() throws BuildException {
448459
}
449460
return System.getProperty("java.home");
450461
}
451-
452462
private int parseVersionStringAsInt(String versionString) {
453463
if (versionString.indexOf(".") > 0) {
454464
try {
@@ -3528,6 +3538,10 @@ public void usesClassMethod(String cls, String method) {
35283538
compileSdkVersion = "33";
35293539
supportLibVersion = "28";
35303540
}
3541+
if (buildToolsVersion.startsWith("34")) {
3542+
compileSdkVersion = "34";
3543+
supportLibVersion = "28";
3544+
}
35313545
jcenter =
35323546
" google()\n" +
35333547
" jcenter()\n" +

maven/codenameone-maven-plugin/src/main/java/com/codename1/builders/Executor.java

+31-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public abstract class Executor {
9999
static boolean IS_MAC;
100100
protected final Map<String,String> defaultEnvironment = new HashMap<String,String>();
101101

102-
102+
private Properties localBuilderProperties;
103103

104104

105105
protected File codenameOneJar;
@@ -2077,15 +2077,42 @@ public String xorEncode(String s) {
20772077
}
20782078
}
20792079

2080-
2081-
2082-
20832080
private ClassLoader getCodenameOneJarClassLoader() throws IOException {
20842081
if (codenameOneJar == null) {
20852082
throw new IllegalStateException("Must set codenameOneJar in Executor");
20862083
}
20872084
return new URLClassLoader(new URL[]{codenameOneJar.toURI().toURL()});
20882085
}
20892086

2087+
/**
2088+
* Loads global local builder properties from user's home directory.
2089+
* @return
2090+
* @throws IOException
2091+
*/
2092+
protected Properties getLocalBuilderProperties() {
2093+
if (localBuilderProperties == null) {
2094+
String sep = File.separator;
2095+
File propertiesFile = new File(
2096+
System.getProperty("user.home") + sep + ".codenameone" + sep + "local.properties"
2097+
);
2098+
localBuilderProperties = new Properties();
2099+
if (!propertiesFile.exists()) {
2100+
return localBuilderProperties;
20902101

2102+
}
2103+
try {
2104+
FileInputStream fis = new FileInputStream(propertiesFile);
2105+
try {
2106+
localBuilderProperties.load(fis);
2107+
} finally {
2108+
fis.close();
2109+
}
2110+
} catch (IOException ex) {
2111+
throw new RuntimeException("Failed to load local properties", ex);
2112+
}
2113+
}
2114+
2115+
return localBuilderProperties;
2116+
2117+
}
20912118
}

0 commit comments

Comments
 (0)