Skip to content

Commit 2edb0e9

Browse files
committed
fix path issue
1 parent 4c3be32 commit 2edb0e9

File tree

5 files changed

+53
-21
lines changed

5 files changed

+53
-21
lines changed

.env

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,70 @@ function s4j_workdir() {
99
}
1010
alias s4jwd="s4j_workdir"
1111

12+
function s4j_cp() {
13+
cp="$(s4j_workdir)/libs/*"
14+
cp="$cp:$(s4j_workdir)/libs/linux-amd64/*)"
15+
cp="$cp:$(s4j_workdir)/libs/windows-amd64/*)"
16+
cp="$cp:."
17+
echo $cp
18+
}
19+
20+
alias s4jcp="sj4_cp"
21+
1222
function s4j_build() {
1323
pushd $(s4jwd)
1424
ant -f resources/build.xml
1525
popd
1626
}
1727
alias s4jb="s4j_build"
1828

29+
function s4j_compile() {
30+
rm -rf $(s4j_workdir)/bin
31+
32+
# compile code
33+
javac -cp "$(s4j_cp)" $(find . -name '*.java') -d "$(s4j_workdir)/bin"
34+
35+
# extract natives
36+
for native_jar in $(find ./libs/*/* -name "*.jar")
37+
do
38+
unzip -o -q $native_jar "natives/*" -d $(s4j_workdir)/bin
39+
done
40+
41+
# copy data
42+
cp $(s4j_workdir)/data/* $(s4j_workdir)/bin
43+
44+
# copy other files
45+
pushd $(s4j_workdir)/examples/java
46+
find . ! -name '*.java' | cpio -pdm $(s4j_workdir)/bin
47+
popd
48+
pushd $(s4j_workdir)/examples/reference
49+
find . ! -name '*.java' | cpio -pdm $(s4j_workdir)/bin
50+
popd
51+
}
52+
alias s4jc="s4j_compile"
1953

2054
function s4j_examples_run() {
21-
java_file_path=$(find . -name "*.java" | fzf)
22-
java_file=${java_file_path##*/}
23-
java_dir=${java_file_path%/*}
24-
pushd $java_dir;
25-
java_filename="${java_file%.*}"
26-
lib=$(s4j_workdir)/distribution/scratch4j-linux-amd64.jar
27-
rm -rf **/*.class
28-
javac -cp "$lib:." $java_file
29-
echo $PWD
30-
echo $java_file
31-
java -cp "$lib:." $java_file
55+
s4j_compile
56+
pushd bin;
57+
java_file_path=$(find . -name "*.class" -type f -exec grep -lr "main" {} \; | fzf)
58+
java_file_path=$(echo $java_file_path | tr "/" ".")
59+
java_file_path=${java_file_path:2}
60+
java_file_path=${java_file_path%.class}
61+
echo $java_file_path
62+
java -cp $(s4j_cp) $java_file_path
3263
popd;
3364
}
3465
alias s4jer="s4j_examples_run"
3566

3667
function s4j_examples_run_all() {
37-
root=$(s4j_workdir)
38-
for f in $(find ./examples/reference -name "*.java")
68+
cp=$(s4j_cp)
69+
s4j_compile
70+
for f in $(find ./examples/reference -name "*.class")
3971
do
4072
java_file=${f##*/}
4173
java_dir=${f%/*}
4274
java_name="${java_file%.*}"
43-
pushd $java_dir
44-
rm -rf **/*.class
45-
javac -cp "$root/distribution/scratch4j-linux-amd64.jar:." $java_file
46-
java -cp "$root/distribution/scratch4j-linux-amd64.jar:." $java_name
47-
popd
75+
java -cp "$cp:bin" $java_name
4876
done
4977
}
5078
alias s4jera="s4j_examples_run_all"

examples/java/Cat/CatSketch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class CatSketch {
77

88
public CatSketch() {
99
Stage myStage = new Stage(800, 600);
10-
Sprite myCat = new Sprite();
10+
Sprite myCat = new CatSprite();
1111
myStage.add(myCat);
1212
}
1313

examples/java/StressTest/StressTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public class StressTest extends Stage {
1010

1111
public StressTest() {
1212
this.addBackdrop("outback", "StressTest/assets/outback.png");
13-
this.setDebug(true);
1413

1514
for (int i = 0; i < dinos; i++) {
1615
this.add(new Dino());

src/org/openpatch/scratch/Stage.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.openpatch.scratch.internal.Image;
2525
import org.openpatch.scratch.internal.Sound;
2626
import org.openpatch.scratch.internal.Stamp;
27+
import processing.core.PApplet;
2728
import processing.core.PConstants;
2829
import processing.core.PGraphics;
2930
import processing.event.KeyEvent;
@@ -955,6 +956,7 @@ public void draw() {
955956

956957
this.run();
957958
this.sprites.stream().forEach(s -> s.run());
959+
958960
this.sprites.stream().forEach(s -> s.draw());
959961
this.texts.stream().forEach(t -> t.draw());
960962

src/org/openpatch/scratch/extensions/fs/File.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ private static String getPath(String path) {
6565
return path;
6666
}
6767
var systemPath = ClassLoader.getSystemResource("").toURI().getPath();
68-
return Paths.get(systemPath, path).toString();
68+
if (systemPath != null) {
69+
return Paths.get(systemPath, path).toString();
70+
}
71+
return path;
6972
} catch (URISyntaxException e) {
7073
e.printStackTrace();
7174
return null;

0 commit comments

Comments
 (0)