Skip to content

Commit d6acf9e

Browse files
authored
Add Playground project export Download Button
Part of the work on #4638
1 parent a5d0ad5 commit d6acf9e

11 files changed

Lines changed: 1202 additions & 2 deletions

File tree

maven/integration-tests/all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ bash migrate-googlemapsdemo-test.sh
77
bash migrate-coderad-lib.sh
88
bash cssfonts.sh
99
bash native-interfaces.sh
10+
bash initializr-roundtrip-test.sh
1011
bash cn1app-archetype-test.sh
1112
bash bare-bones-kotlin-test.sh
1213
bash migrate-kitchensink-test.sh
1314
bash googlemaps-demo.sh
14-
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
3+
set -e
4+
source "$SCRIPTPATH/inc/env.sh"
5+
6+
WORKDIR="$SCRIPTPATH/build/initializr-roundtrip"
7+
SOURCE_WORKDIR="$WORKDIR/source-work"
8+
GENERATED_WORKDIR="$WORKDIR/generated-work"
9+
ARTIFACT_ID="initializr-roundtrip"
10+
SOURCE_PROJECT="$SOURCE_WORKDIR/$ARTIFACT_ID"
11+
GENERATED_PROJECT="$GENERATED_WORKDIR/$ARTIFACT_ID"
12+
APP_NAME="RoundTripInitializrApp"
13+
PACKAGE_NAME="com.acme.initializr.roundtrip"
14+
15+
rm -rf "$WORKDIR"
16+
mkdir -p "$WORKDIR"
17+
18+
mkdir -p "$SOURCE_WORKDIR" "$GENERATED_WORKDIR"
19+
20+
cd "$SOURCE_WORKDIR"
21+
22+
mvn archetype:generate \
23+
-DarchetypeArtifactId=cn1app-archetype \
24+
-DarchetypeGroupId=com.codenameone \
25+
-DarchetypeVersion="$CN1_VERSION" \
26+
-DartifactId="$ARTIFACT_ID" \
27+
-DgroupId="$PACKAGE_NAME" \
28+
-Dversion=1.0-SNAPSHOT \
29+
-DmainName="$APP_NAME" \
30+
-DinteractiveMode=false
31+
32+
cat > "$SOURCE_PROJECT/generate-app-project.rpf" <<EOF
33+
template.type=maven
34+
template.mainName=$APP_NAME
35+
template.packageName=$PACKAGE_NAME
36+
EOF
37+
38+
cd "$GENERATED_WORKDIR"
39+
mvn "com.codenameone:codenameone-maven-plugin:${CN1_VERSION}:generate-app-project" \
40+
-DarchetypeGroupId=com.codenameone \
41+
-DarchetypeArtifactId=cn1app-archetype \
42+
-DarchetypeVersion="${CN1_VERSION}" \
43+
-DartifactId="${ARTIFACT_ID}" \
44+
-DgroupId="${PACKAGE_NAME}" \
45+
-Dversion=1.0-SNAPSHOT \
46+
-DmainName="${APP_NAME}" \
47+
-DpackageName="${PACKAGE_NAME}" \
48+
-DinteractiveMode=false \
49+
-DsourceProject="$SOURCE_PROJECT"
50+
51+
if [ ! -d "$GENERATED_PROJECT" ]; then
52+
echo "Generated project missing at $GENERATED_PROJECT"
53+
exit 1
54+
fi
55+
56+
normalize_project() {
57+
PROJECT_DIR="$1"
58+
while read -r SETTINGS_FILE; do
59+
NORMALIZED_FILE="$SETTINGS_FILE.normalized"
60+
grep -v '^[[:space:]]*#' "$SETTINGS_FILE" | sort > "$NORMALIZED_FILE"
61+
if [ ! -s "$NORMALIZED_FILE" ]; then
62+
echo "Normalization produced an empty codenameone_settings.properties file: $SETTINGS_FILE (expected non-comment property entries)."
63+
rm -f "$NORMALIZED_FILE"
64+
exit 1
65+
fi
66+
mv "$NORMALIZED_FILE" "$SETTINGS_FILE"
67+
done < <(find "$PROJECT_DIR" -type f -name "codenameone_settings.properties")
68+
}
69+
70+
normalize_project "$SOURCE_PROJECT"
71+
normalize_project "$GENERATED_PROJECT"
72+
73+
IGNORES_FILE="$WORKDIR/roundtrip.ignores"
74+
cat > "$IGNORES_FILE" <<EOF
75+
generate-app-project.rpf
76+
EOF
77+
78+
DIFF_OUT="$WORKDIR/roundtrip.diff"
79+
set +e
80+
diff -ruN -x target -X "$IGNORES_FILE" "$SOURCE_PROJECT" "$GENERATED_PROJECT" > "$DIFF_OUT"
81+
DIFF_STATUS=$?
82+
set -e
83+
84+
if [ "$DIFF_STATUS" -ne 0 ]; then
85+
echo "Initializr round-trip comparison failed. Unexpected differences found:"
86+
cat "$DIFF_OUT"
87+
exit 1
88+
fi
89+
90+
echo "Initializr round-trip comparison passed."
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<artifactId>cn1playground-cn1libs</artifactId>
6+
<groupId>com.codenameone.playground</groupId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<groupId>com.codenameone.playground</groupId>
11+
<artifactId>cn1playground-ZipSupport</artifactId>
12+
<version>1.0-SNAPSHOT</version>
13+
<packaging>pom</packaging>
14+
<name>ZipSupport</name>
15+
<build>
16+
<plugins>
17+
<plugin>
18+
<groupId>org.codehaus.mojo</groupId>
19+
<artifactId>build-helper-maven-plugin</artifactId>
20+
<version>1.7</version>
21+
<executions>
22+
<execution>
23+
<id>attach-artifacts</id>
24+
<phase>validate</phase>
25+
<goals>
26+
<goal>attach-artifact</goal>
27+
</goals>
28+
<configuration>
29+
<artifacts>
30+
<artifact>
31+
<file>${basedir}/jars/main.zip</file>
32+
<type>jar</type>
33+
<classifier>common</classifier>
34+
</artifact>
35+
</artifacts>
36+
</configuration>
37+
</execution>
38+
</executions>
39+
</plugin>
40+
</plugins>
41+
</build>
42+
</project>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<artifactId>cn1playground</artifactId>
6+
<groupId>com.codenameone.playground</groupId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<groupId>com.codenameone.playground</groupId>
11+
<artifactId>cn1playground-cn1libs</artifactId>
12+
<version>1.0-SNAPSHOT</version>
13+
<packaging>pom</packaging>
14+
<name>cn1playground-cn1libs</name>
15+
<profiles>
16+
<profile>
17+
<id>ZipSupport.cn1lib-cn1lib</id>
18+
<activation>
19+
<file><exists>${basedir}/ZipSupport/pom.xml</exists></file>
20+
</activation>
21+
<modules><module>ZipSupport</module></modules>
22+
</profile>
23+
<profile>
24+
<id>ZipSupport.cn1lib-cn1lib-fromroot</id>
25+
<activation>
26+
<file><exists>${basedir}/cn1libs/ZipSupport/pom.xml</exists></file>
27+
</activation>
28+
<modules><module>ZipSupport</module></modules>
29+
</profile>
30+
</profiles>
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<inherited>false</inherited>
35+
<groupId>org.codehaus.mojo</groupId>
36+
<artifactId>exec-maven-plugin</artifactId>
37+
<executions>
38+
<execution>
39+
<id>sync-zipsupport-assets</id>
40+
<phase>validate</phase>
41+
<goals>
42+
<goal>exec</goal>
43+
</goals>
44+
<configuration>
45+
<executable>sh</executable>
46+
<workingDirectory>${project.parent.basedir}</workingDirectory>
47+
<arguments>
48+
<argument>${project.parent.basedir}/tools/sync-zipsupport-from-initializr.sh</argument>
49+
</arguments>
50+
</configuration>
51+
</execution>
52+
</executions>
53+
</plugin>
54+
</plugins>
55+
</build>
56+
57+
</project>

scripts/cn1playground/common/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
<scope>test</scope>
2525
</dependency>
2626

27+
28+
<dependency>
29+
<artifactId>cn1playground-ZipSupport</artifactId>
30+
<groupId>com.codenameone.playground</groupId>
31+
<version>1.0-SNAPSHOT</version>
32+
<classifier>common</classifier>
33+
<type>jar</type>
34+
</dependency>
35+
2736
<!-- INJECT DEPENDENCIES -->
2837
</dependencies>
2938

scripts/cn1playground/common/src/main/java/com/codenameone/playground/CN1Playground.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public class CN1Playground extends Lifecycle {
3737
private static final String ROLE_EMBEDDED_FORM = "embeddedForm";
3838
private static final String ROLE_EMBEDDED_TITLE_AREA = "embeddedTitleArea";
3939
private static final String SHARE_BUTTON_LABEL = "Copy Shareable Playground URL";
40-
4140
private final PlaygroundRunner runner = new PlaygroundRunner();
41+
private final PlaygroundProjectExporter projectExporter = new PlaygroundProjectExporter();
4242

4343
private Form appForm;
4444
private PlaygroundBrowserEditor editor;
@@ -76,6 +76,8 @@ public void runApp() {
7676
toolbar.getTitleComponent().setUIID("PlaygroundTitle");
7777
}
7878

79+
toolbar.addMaterialCommandToRightBar("Download", com.codename1.ui.FontImage.MATERIAL_DOWNLOAD, e -> projectExporter.export(currentScript, currentCss));
80+
7981
editor = new PlaygroundBrowserEditor(PlaygroundBrowserEditor.Mode.JAVA, currentScript, websiteDarkMode, this::handleSourceChanged);
8082
cssEditor = new PlaygroundBrowserEditor(PlaygroundBrowserEditor.Mode.CSS, currentCss, websiteDarkMode, this::handleCssChanged);
8183
inspector = new PlaygroundInspector(websiteDarkMode, (component, property, value) -> handlePropertyChanged(component));

0 commit comments

Comments
 (0)