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
30 changes: 20 additions & 10 deletions .github/scripts/build_javadocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ else
JAVADOC_CMD="javadoc"
fi

TMP_SNIPPETS_JSONL="$(mktemp)"
cleanup() {
rm -f "$TMP_SNIPPETS_JSONL"
run_with_timeout() {
local seconds="$1"
shift
if command -v timeout >/dev/null 2>&1; then
timeout "${seconds}" "$@"
return $?
fi
"$@"
}
trap cleanup EXIT

echo "Extracting JavaDoc snippets prior to JavaDoc generation..."
"$ROOT_DIR/scripts/extract-javadoc-java-snippets.sh" "$CN1_DIR/src" > "$TMP_SNIPPETS_JSONL"

echo "Validating JavaDoc snippets prior to JavaDoc generation..."
"$ROOT_DIR/scripts/validate-extracted-javadoc-snippets.sh" "$TMP_SNIPPETS_JSONL"

rm -rf "$CN1_DIR/dist/javadoc"
rm -rf "$CN1_DIR/build/tempJavaSources"
Expand All @@ -33,6 +31,18 @@ mkdir -p "$CN1_DIR/dist/javadoc"

cp -r "$CN1_DIR/src/"* "$CN1_DIR/build/tempJavaSources/"

VALIDATE_SNIPPETS_SCRIPT="${SCRIPT_DIR}/validate-extracted-javadoc-snippets.sh"
if [ -x "${VALIDATE_SNIPPETS_SCRIPT}" ]; then
echo "Validating JavaDoc snippets prior to JavaDoc generation..." >&2
if ! run_with_timeout 300 "${VALIDATE_SNIPPETS_SCRIPT}"; then
status=$?
if [ "${status}" -eq 124 ]; then
echo "JavaDoc snippet validation timed out after 300 seconds." >&2
fi
exit "${status}"
fi
fi

cat > "$CN1_DIR/build/tempJavaSources/com/codename1/impl/ImplementationFactory.java" <<'EOF'
package com.codename1.impl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ private void bindGlobals(Interpreter interpreter, PlaygroundContext context) thr
interpreter.set("theme", context.getTheme());
interpreter.set("hostForm", context.getHostForm());
interpreter.set("previewRoot", context.getPreviewRoot());
interpreter.set("Display", resolveDisplayBinding());
interpreter.set("UIManager", resolveUiManagerBinding());
interpreter.set("Display", Display.getInstance());
interpreter.set("UIManager", UIManager.getInstance());
interpreter.set("FontImage", FontImage.class);
interpreter.set("CN", com.codename1.ui.CN.class);
interpreter.set("BoxLayout", BoxLayout.class);
Expand All @@ -134,29 +134,15 @@ private void bindGlobals(Interpreter interpreter, PlaygroundContext context) thr
interpreter.set("GridLayout", GridLayout.class);
interpreter.set("LayeredLayout", LayeredLayout.class);
interpreter.set("Style", Style.class);
interpreter.set("Component", Component.class);
namespace.importPackage("com.codename1.ui");
namespace.importPackage("com.codename1.ui.layouts");
namespace.importPackage("com.codename1.components");
namespace.importPackage("com.codename1.ui.geom");
namespace.importClass("com.codename1.ui.Component");
namespace.importClass("com.codenameone.playground.PlaygroundContext");
}

private Object resolveDisplayBinding() {
try {
return Display.getInstance();
} catch (Throwable ex) {
return Display.class;
}
}

private Object resolveUiManagerBinding() {
try {
return UIManager.getInstance();
} catch (Throwable ex) {
return UIManager.class;
}
}

private String adaptScript(String script) {
String adapted = unwrapSingleTopLevelClass(script);
String normalized = adapted == null ? script : adapted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@
import com.codename1.ui.Container;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Button;
import com.codename1.ui.Label;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.ui.plaf.Style;
import com.codename1.ui.css.CSSThemeCompiler;
import com.codename1.ui.util.MutableResource;
import java.util.Hashtable;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -27,36 +22,10 @@ public static void main(String[] args) throws Exception {
smokeLifecycleDemo();
smokeRestScriptWithLambda();
smokeStringMethods();
smokeCssUiidCollectionUsesPreviewOnly();
smokeCssCompilerAcceptsBasicButtonRule();
smokeComponentTypeResolvesWithoutExplicitImport();
System.out.println("Playground smoke tests passed.");
}

private static void smokeCssUiidCollectionUsesPreviewOnly() {
Container preview = new Container(BoxLayout.y());
Button button = new Button("Hello");
Label label = new Label("World");
preview.addAll(button, label);

List<String> uiids = PlaygroundCssSupport.collectVisibleUiids(preview);
require(uiids.contains("Button"), "Expected Button UIID completion from preview");
require(uiids.contains("Label"), "Expected Label UIID completion from preview");
require(!uiids.contains("BrowserComponent"), "Preview UIID collection must not include app shell/editor UIIDs");
for (int i = 0; i < uiids.size(); i++) {
require(!uiids.get(i).startsWith("."), "UIID completions should be plain selector names, not dot-prefixed");
}
}

private static void smokeCssCompilerAcceptsBasicButtonRule() {
String normalized = PlaygroundCssSupport.normalizeCustomCss("Button {\n color: white;\n}");
require("Button {\n color: white;\n}".equals(normalized), "Basic Button CSS should remain unchanged");
CSSThemeCompiler compiler = new CSSThemeCompiler();
MutableResource resource = new MutableResource();
compiler.compile(normalized, resource, "PlaygroundCssSmokeTheme");
Hashtable theme = resource.getTheme("PlaygroundCssSmokeTheme");
require(theme != null && !theme.isEmpty(), "Compiled CSS theme should produce theme properties");
}

private static void smokeGeneratedRegistry() throws Exception {
GeneratedCN1Access access = GeneratedCN1Access.INSTANCE;
require(access.findClass("com.codename1.ui.layouts.BoxLayout") == BoxLayout.class,
Expand Down Expand Up @@ -218,6 +187,30 @@ public void log(String message) {
"Loose script list snippet should log its completion");
}

private static void smokeComponentTypeResolvesWithoutExplicitImport() {
Display.init(null);

Form host = new Form("Host", new BorderLayout());
Container preview = new Container(new BorderLayout());
host.add(BorderLayout.CENTER, preview);
host.show();

PlaygroundContext context = new PlaygroundContext(host, preview, null,
new PlaygroundContext.Logger() {
public void log(String message) {
}
});

PlaygroundRunner runner = new PlaygroundRunner();
PlaygroundRunner.RunResult result = runner.run(
"Component c = new Label(\"Implicit import works\");\n"
+ "c;\n",
context);

require(result.getComponent() instanceof Label,
"Component type should resolve without explicit import: " + summarizeMessages(result));
}

private static void require(boolean condition, String message) {
if (!condition) {
throw new IllegalStateException(message);
Expand Down
Loading