Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/scripts-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
steps:
- uses: actions/checkout@v4


- name: Ensure CocoaPods tooling
run: |
mkdir -p ~/.codenameone
Expand Down
42 changes: 42 additions & 0 deletions Ports/CLDC11/src/java/lang/invoke/StringConcatFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores
* CA 94065 USA or visit www.oracle.com if you need additional information or
* have any questions.
*/
package java.lang.invoke;

/**
* @deprecated this class is used internally for String concatenation compatibility
*/
public final class StringConcatFactory {
private StringConcatFactory() {
}

public static CallSite makeConcat(MethodHandles.Lookup lookup, String name,
MethodType concatType) {
return null;
}

public static CallSite makeConcatWithConstants(MethodHandles.Lookup lookup, String name,
MethodType concatType, String recipe, Object... constants) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,6 @@ private void doIOSLocalBuild(File tmpProjectDir, Properties props, File distJar)
String incSources = request.getArg("build.incSources", null);
request.setIncludeSource(true);



String testBuild = request.getArg("build.unitTest", null);
if(testBuild != null && testBuild.equals("1")) {
e.setUnitTestMode(true);
Expand Down Expand Up @@ -1075,17 +1073,41 @@ private static class PropertyConflictException extends LibraryPropertiesExceptio




private static int parseJavaVersion(String version, int defaultValue) {
if (version == null) {
return defaultValue;
}
String normalized = version.trim();
if (normalized.isEmpty()) {
return defaultValue;
}
if (normalized.startsWith("1.")) {
normalized = normalized.substring(2);
}
int dotPos = normalized.indexOf('.');
if (dotPos > 0) {
normalized = normalized.substring(0, dotPos);
}
int dashPos = normalized.indexOf('-');
if (dashPos > 0) {
normalized = normalized.substring(0, dashPos);
}
try {
return Integer.parseInt(normalized);
} catch (NumberFormatException ex) {
return defaultValue;
}
}

private SortedProperties mergeRequiredProperties(String libraryName, Properties libProps, Properties projectProps) throws LibraryPropertiesException {


String javaVersion = (String)projectProps.getProperty("codename1.arg.java.version", "8");
String javaVersionLib = (String)libProps.get("codename1.arg.java.version");
if(javaVersionLib != null){
int v1 = 5;
if(javaVersion != null){
v1 = Integer.parseInt(javaVersion);
}
int v2 = Integer.parseInt(javaVersionLib);
int v1 = parseJavaVersion(javaVersion, 5);
int v2 = parseJavaVersion(javaVersionLib, 5);
//if the lib java version is bigger, this library cannot be used
if(v1 < v2){
throw new VersionMismatchException(libraryName, "Cannot use a cn1lib with java version "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
*/
@Mojo(name = "compliance-check", defaultPhase = LifecyclePhase.PROCESS_CLASSES, requiresDependencyResolution = ResolutionScope.TEST)
public class ComplianceCheckMojo extends AbstractCN1Mojo {
private static final String[] DEFAULT_DONTWARN_CLASSES = {
// RMI isn't part of Codename One supported runtime API.
"java.rmi.Remote",
// JDK implementation detail that can leak into analysis in newer JDK toolchains.
"java.util.Arrays$ArrayList"
};

private File complianceOutputFile;
@Override
Expand Down Expand Up @@ -234,6 +240,11 @@ private void runProguard(int passNum) throws MojoExecutionException{
java.createArg().setValue(keep);
}
}
for (String dontWarnClass : DEFAULT_DONTWARN_CLASSES) {
java.createArg().setValue("-dontwarn");
java.createArg().setValue(dontWarnClass);
}

if (passNum == 0) {
getLog().debug("Compliance check pass 0");
// In the first pass we don't want any warnings or errors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,33 @@ private boolean mergeProjectAppendedProperties(Artifact artifact) throws IOExcep
return changed;
}


private static int parseJavaVersion(String version, int defaultValue) {
if (version == null) {
return defaultValue;
}
String normalized = version.trim();
if (normalized.isEmpty()) {
return defaultValue;
}
if (normalized.startsWith("1.")) {
normalized = normalized.substring(2);
}
int dotPos = normalized.indexOf('.');
if (dotPos > 0) {
normalized = normalized.substring(0, dotPos);
}
int dashPos = normalized.indexOf('-');
if (dashPos > 0) {
normalized = normalized.substring(0, dashPos);
}
try {
return Integer.parseInt(normalized);
} catch (NumberFormatException ex) {
return defaultValue;
}
}

/**
* Merges the lib's required properties with the project properties. Does not persist.
* @param artifact
Expand All @@ -244,11 +271,8 @@ private boolean mergeProjectRequiredProperties(Artifact artifact) throws IOExcep
String javaVersion = (String)projectProps.getProperty("codename1.arg.java.version", "8");
String javaVersionLib = (String)libProps.get("codename1.arg.java.version");
if(javaVersionLib != null){
int v1 = 5;
if(javaVersion != null){
v1 = Integer.parseInt(javaVersion);
}
int v2 = Integer.parseInt(javaVersionLib);
int v1 = parseJavaVersion(javaVersion, 5);
int v2 = parseJavaVersion(javaVersionLib, 5);
//if the lib java version is bigger, this library cannot be used
if(v1 < v2){
throw new BuildException("Cannot use a cn1lib with java version "
Expand Down
5 changes: 5 additions & 0 deletions scripts/build-ios-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ if ! command -v pod >/dev/null 2>&1; then
exit 1
fi

ORIGINAL_JAVA_HOME="$JAVA_HOME"
export JAVA_HOME="$JAVA17_HOME"
export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH"

bia_log "Using JAVA_HOME at $JAVA_HOME"
bia_log "Original JAVA_HOME was $ORIGINAL_JAVA_HOME"
bia_log "Using JAVA17_HOME at $JAVA17_HOME"
bia_log "Using Maven installation at $MAVEN_HOME"
bia_log "Using CocoaPods version $(pod --version 2>/dev/null || echo '<unknown>')"
bia_log "Java version for Maven invocations:"
"$JAVA_HOME/bin/java" -version
IOS_UISCENE="${IOS_UISCENE:-false}"
bia_log "Building sample app with ios.uiscene=${IOS_UISCENE}"

Expand Down
4 changes: 4 additions & 0 deletions scripts/hellocodenameone/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This is a multi-module maven project for building a Codename One application. Co

If you plan to use Java as your primary language, https://shannah.github.io/cn1-maven-archetypes/cn1app-archetype-tutorial/getting-started.html[start here].

=== Java Version

Use Java 17 to build and run this project (e.g. `JAVA_HOME` should point to a JDK 17 installation).

=== Kotlin

If you plan to use Kotlin as your primary language, https://shannah.github.io/cn1app-archetype-kotlin-template/getting-started.html[start here].
Expand Down
4 changes: 2 additions & 2 deletions scripts/hellocodenameone/android/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<codename1.platform>android</codename1.platform>
<codename1.projectPlatform>android</codename1.projectPlatform>
<codename1.defaultBuildTarget>android-device</codename1.defaultBuildTarget>
Expand Down
5 changes: 5 additions & 0 deletions scripts/hellocodenameone/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ setlocal EnableExtensions

set MVNW=mvnw.cmd

java -version 2>&1 | findstr /c:"17" >nul
if errorlevel 1 if exist "C:\Program Files\Java\jdk-17" set "JAVA_HOME=C:\Program Files\Java\jdk-17"
if errorlevel 1 if exist "C:\Program Files\Eclipse Adoptium\jdk-17" set "JAVA_HOME=C:\Program Files\Eclipse Adoptium\jdk-17"
if not "%JAVA_HOME%"=="" set "PATH=%JAVA_HOME%\bin;%PATH%"

SET CMD=%1
if "%CMD%"=="" (
set CMD=jar
Expand Down
19 changes: 18 additions & 1 deletion scripts/hellocodenameone/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
set -e
MVNW="./mvnw"

JAVA17_HOME=""
if [ -n "$JAVA_HOME" ] && [ -x "$JAVA_HOME/bin/java" ] && "$JAVA_HOME/bin/java" -version 2>&1 | head -n 1 | grep -q "\"17"; then
JAVA17_HOME="$JAVA_HOME"
else
for candidate in /usr/lib/jvm/java-17-openjdk-amd64 /usr/lib/jvm/java-17-openjdk /usr/lib/jvm/jdk-17 /usr/lib/jvm/*17*; do
if [ -x "$candidate/bin/java" ] && "$candidate/bin/java" -version 2>&1 | head -n 1 | grep -q "\"17"; then
JAVA17_HOME="$candidate"
break
fi
done
fi

if [ -n "$JAVA17_HOME" ]; then
export JAVA_HOME="$JAVA17_HOME"
export PATH="$JAVA_HOME/bin:$PATH"
fi

function mac_desktop {

"$MVNW" "package" "-DskipTests" "-Dcodename1.platform=javase" "-Dcodename1.buildTarget=mac-os-x-desktop" "-U" "-e"
Expand Down Expand Up @@ -96,4 +113,4 @@ CMD="$1"
if [ "$CMD" == "" ]; then
CMD="jar"
fi
"$CMD"
"$CMD"
6 changes: 3 additions & 3 deletions scripts/hellocodenameone/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,16 @@
<codename1.targetPlatform>javase</codename1.targetPlatform>
</properties>
</profile>
</profiles>
</profiles>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.codenameone.examples.hellocodenameone;

import com.codename1.testing.AbstractTest;

public class Java17LanguageFeaturesTest extends AbstractTest {

@Override
public boolean runTest() throws Exception {
var greeting = "Hello";
var target = "Codename One";

var message = switch (greeting.length()) {
case 5 -> greeting + " " + target;
default -> "unexpected";
};

var textBlock = """
Java 17 language features
should compile in tests.
""";

assertEqual("Hello Codename One", message);
assertEqual("Java 17 language features\nshould compile in tests.\n", textBlock);

return true;
}
}
4 changes: 2 additions & 2 deletions scripts/hellocodenameone/ios/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<codename1.platform>ios</codename1.platform>
<codename1.projectPlatform>ios</codename1.projectPlatform>
<codename1.defaultBuildTarget>ios-device</codename1.defaultBuildTarget>
Expand Down
4 changes: 2 additions & 2 deletions scripts/hellocodenameone/javascript/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<codename1.platform>javascript</codename1.platform>
<codename1.projectPlatform>javascript</codename1.projectPlatform>
<codename1.defaultBuildTarget>javascript</codename1.defaultBuildTarget>
Expand Down
4 changes: 2 additions & 2 deletions scripts/hellocodenameone/javase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<codename1.platform>javase</codename1.platform>
<codename1.projectPlatform>javase</codename1.projectPlatform>
</properties>
Expand Down
17 changes: 17 additions & 0 deletions scripts/hellocodenameone/mvnw

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions scripts/hellocodenameone/mvnw.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading