Skip to content

Commit

Permalink
feat: add support for local builder properties for local builds. (#3824)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shannah authored Aug 3, 2024
1 parent 56d2119 commit d116bb5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,19 @@ private String getGradleVersion(String gradleExe) throws Exception {
private String getGradleJavaHome() throws BuildException {
if (useGradle8) {
String home = System.getenv("JAVA17_HOME");
if (home == null && (home = getLocalBuilderProperties().getProperty("java17.home", null)) != null) {
if (!(new File(home)).isDirectory()) {
throw new BuildException("The java17.home property is not set to a valid directory. " +
"You have defined it in your ~/.codenameone/local.properties file, " +
"but it is not a valid directory."
);
}
}
if (home == null) {
throw new BuildException("When using gradle 8, you must set the JAVA17_HOME environment variable to the location of a Java 17 JDK");
throw new BuildException(
"When using gradle 8, " +
"you must set the JAVA17_HOME environment variable to the location of a Java 17 JDK"
);
}

if (!(new File(home).isDirectory())) {
Expand All @@ -448,7 +459,6 @@ private String getGradleJavaHome() throws BuildException {
}
return System.getProperty("java.home");
}

private int parseVersionStringAsInt(String versionString) {
if (versionString.indexOf(".") > 0) {
try {
Expand Down Expand Up @@ -3528,6 +3538,10 @@ public void usesClassMethod(String cls, String method) {
compileSdkVersion = "33";
supportLibVersion = "28";
}
if (buildToolsVersion.startsWith("34")) {
compileSdkVersion = "34";
supportLibVersion = "28";
}
jcenter =
" google()\n" +
" jcenter()\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public abstract class Executor {
static boolean IS_MAC;
protected final Map<String,String> defaultEnvironment = new HashMap<String,String>();


private Properties localBuilderProperties;


protected File codenameOneJar;
Expand Down Expand Up @@ -2077,15 +2077,42 @@ public String xorEncode(String s) {
}
}




private ClassLoader getCodenameOneJarClassLoader() throws IOException {
if (codenameOneJar == null) {
throw new IllegalStateException("Must set codenameOneJar in Executor");
}
return new URLClassLoader(new URL[]{codenameOneJar.toURI().toURL()});
}

/**
* Loads global local builder properties from user's home directory.
* @return
* @throws IOException
*/
protected Properties getLocalBuilderProperties() {
if (localBuilderProperties == null) {
String sep = File.separator;
File propertiesFile = new File(
System.getProperty("user.home") + sep + ".codenameone" + sep + "local.properties"
);
localBuilderProperties = new Properties();
if (!propertiesFile.exists()) {
return localBuilderProperties;

}
try {
FileInputStream fis = new FileInputStream(propertiesFile);
try {
localBuilderProperties.load(fis);
} finally {
fis.close();
}
} catch (IOException ex) {
throw new RuntimeException("Failed to load local properties", ex);
}
}

return localBuilderProperties;

}
}

0 comments on commit d116bb5

Please sign in to comment.