Skip to content

Commit fa89aa3

Browse files
committed
Upgrade JPPM 0.5.7
1 parent 3ed66c1 commit fa89aa3

File tree

6 files changed

+91
-31
lines changed

6 files changed

+91
-31
lines changed

jphp-core/src/org/develnext/jphp/core/compiler/jvm/statement/ExpressionStmtCompiler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3123,6 +3123,9 @@ public Memory writeExpression(ExprStmtToken expression, boolean returnValue, boo
31233123
int initStackSize = method.getStackCount();
31243124
exprStackInit.push(initStackSize);
31253125

3126+
if (expression == null) {
3127+
throw new CriticalException("Invalid expression token expr, on line unknown, expr = null");
3128+
}
31263129
if (!expression.isStmtList()) {
31273130
if (expression.getAsmExpr() == null) {
31283131
throw new CriticalException("Invalid expression token without asm expr, on line " + expression.getMeta().getStartLine() + ", expr = " + expression.getWord());

packager/buildSrc/AppPlugin.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function build(Event $event)
9090
$buildFileName = $build['file-name'];
9191
}
9292

93-
$buildType = $build['type'] ?? 'one-jar';
93+
$buildType = $build['type'] ?? 'multi-jar';
9494

9595
$buildDir = $event->package()->getConfigBuildPath();
9696

@@ -104,6 +104,7 @@ function build(Event $event)
104104

105105
$metaInfServices = [];
106106
$jars = [];
107+
$vendorJars = [];
107108

108109
foreach ($exec->getClassPaths() as $classPath) {
109110
if (fs::isDir($classPath)) {
@@ -130,10 +131,14 @@ function build(Event $event)
130131
});
131132
} else if (fs::ext($classPath) === 'jar') {
132133
Console::log("-> add jar: $classPath");
134+
$vendorJars[] = $classPath;
133135

134136
switch ($buildType) {
135137
case 'one-jar': {
136-
$jar = new ZipArchive($classPath);
138+
Console::error("app.build.type as 'one-jar' no longer supported, use 'multi-jar'");
139+
exit(-1);
140+
141+
/*$jar = new ZipArchive($classPath);
137142
$jar->readAll(function (ZipArchiveEntry $stat, ?Stream $stream) use (&$metaInfServices, $buildDir) {
138143
$name = $stat->name;
139144
@@ -151,7 +156,7 @@ function build(Event $event)
151156
fs::ensureParent($file);
152157
fs::copy($stream, $file);
153158
}
154-
});
159+
});*/
155160

156161
break;
157162
}
@@ -307,7 +312,15 @@ function build(Event $event)
307312
Console::log("-> Build portable Java Runtime for App (via 'jlink')");
308313
$javaRuntimeBuilder = new AppPluginJavaRuntimeBuilder();
309314

310-
foreach (flow($jars, $libJars) as $jar) {
315+
if ($launcherConf['java']['jdk']) {
316+
if (is_string($launcherConf['java']['jdk'])) {
317+
$javaRuntimeBuilder->setJavaHomeEmbedded($launcherConf['java']['jdk']);
318+
} else if (is_array($launcherConf['java']['jdk'])) {
319+
$javaRuntimeBuilder->setJavaHomeEmbedded($launcherConf['java']['jdk'][Package::getOS()]);
320+
}
321+
}
322+
323+
foreach ($vendorJars as $jar) {
311324
$javaRuntimeBuilder->addJar($jar);
312325
}
313326

@@ -360,7 +373,19 @@ function build(Event $event)
360373

361374
default:
362375
if (!$launcher['disable-launcher'] && !$launcherConf['disabled']) {
363-
Console::log("\n Use 'java -jar \"$buildDir/$buildFileName.jar\"' to run the result app.");
376+
if (str::posIgnoreCase(System::osName(), 'win') === -1) {
377+
if (arr::has($launcherConf['types'], 'sh')) {
378+
Console::log("\n Use '{0}' to run the result app.", fs::normalize("./$buildDir/$buildFileName"));
379+
} else {
380+
Console::warn("\n Launcher script is not available, app.launcher.types hasn't 'sh' value");
381+
}
382+
} else {
383+
if (arr::has($launcherConf['types'], 'bat')) {
384+
Console::log("\n Use '{0}.bat' to run the result app.", fs::normalize($buildDir . "\\" . $buildFileName));
385+
} else {
386+
Console::warn("\n Launcher script is not available, app.launcher.types hasn't 'bat' value");
387+
}
388+
}
364389
}
365390
}
366391

packager/buildSrc/app/AppPluginJavaRuntimeBuilder.php

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use php\lib\fs;
1010
use php\lib\str;
1111
use php\util\Flow;
12+
use Tasks;
13+
use function var_dump;
1214

1315
class AppPluginJavaRuntimeBuilder
1416
{
@@ -19,13 +21,34 @@ class AppPluginJavaRuntimeBuilder
1921

2022
public $jvmModules = [];
2123

24+
protected $javaHome;
25+
protected $javaHomeEmbedded;
26+
2227
public function __construct()
2328
{
29+
$this->javaHome = fs::parent(fs::parent((new JavaExec())->getJavaBin()));
30+
$this->javaHomeEmbedded = $this->javaHome;
31+
}
32+
33+
/**
34+
* @param string $javaHomeEmbedded
35+
*/
36+
public function setJavaHomeEmbedded(string $javaHomeEmbedded): void
37+
{
38+
$this->javaHomeEmbedded = $javaHomeEmbedded;
39+
}
40+
41+
/**
42+
* @param string $javaHome
43+
*/
44+
public function setJavaHome(string $javaHome): void
45+
{
46+
$this->javaHome = $javaHome;
2447
}
2548

2649
public function addJar($jar)
2750
{
28-
$this->jars[$jar] = $jar;
51+
$this->jars[$jar] = fs::abs($jar);
2952
}
3053

3154
public function addJvmModules(...$modules)
@@ -41,7 +64,7 @@ public function addJvmModules(...$modules)
4164
public function fetchModules($workingDir)
4265
{
4366
$javaExec = new JavaExec();
44-
$jdepsBin = fs::parent($javaExec->getJavaBin()) . "/jdeps";
67+
$jdepsBin = $this->javaHome . "/bin/jdeps";
4568

4669
$modules = [];
4770

@@ -69,20 +92,18 @@ public function fetchModules($workingDir)
6992
return $modules;
7093
}
7194

72-
public function build($workingDir)
95+
public function buildForJDK11($workingDir)
7396
{
7497
$modules = flow(
7598
$this->fetchModules($workingDir),
7699
$this->jvmModules
77100
)->toMap();
78101

79-
$javaExec = new JavaExec();
80-
$javaHome = fs::parent($javaExec->getJavaBin());
81-
$jlinkBin = $javaHome . "/jlink";
102+
$jlinkBin = $this->javaHome . "/bin/jlink";
82103

83104
$proc = new Process([
84105
$jlinkBin,
85-
"--module-path", "$javaHome/jmods;out",
106+
"--module-path", "$this->javaHomeEmbedded/jmods;out",
86107
"--add-modules", str::join($modules, ","),
87108
"--output", "jre"
88109
], $workingDir, System::getEnv());
@@ -92,4 +113,28 @@ public function build($workingDir)
92113
exit(-1);
93114
}
94115
}
116+
117+
public function buildForJDK8($workingDir)
118+
{
119+
Tasks::copy("$this->javaHomeEmbedded/jre", "$workingDir/jre");
120+
}
121+
122+
public function build($workingDir)
123+
{
124+
if (fs::exists("$this->javaHomeEmbedded/jmods")) {
125+
if (!fs::exists("$this->javaHome/jmods")) {
126+
Console::error("Failed to build jre, it's requires JDK 11+ with 'jlink' tool, JAVA_HOME = {0}", $this->javaHome);
127+
exit(-1);
128+
}
129+
130+
$this->buildForJDK11($workingDir);
131+
} else {
132+
if (fs::exists("$this->javaHomeEmbedded/jre")) {
133+
$this->buildForJDK8($workingDir);
134+
} else {
135+
Console::error("Failed to build jre, cannot find {0}", $this->javaHomeEmbedded);
136+
exit(-1);
137+
}
138+
}
139+
}
95140
}

packager/example/hello-world/package.php.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ app:
1717
enabled: true # enable launcher scripts
1818
types: [sh, bat]
1919
java:
20-
embedded: true # add jvm via jlink + jdeps
20+
# jdk: 'path-to-embedded-jdk' # path to jdk with JRE or jmods
21+
#embedded: true # add jvm via jlink + jdeps
2122

2223
sources:
2324
- src

packager/example/hello-world/src/index.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,4 @@
22
use std;
33

44
$hello = new \helloworld\HelloWorld("Hello? World");
5-
//$hello->print();
6-
7-
function test($a, $b, $c) {
8-
return $a + $b + $c;
9-
}
10-
11-
function foo() {
12-
for ($i = 0; $i < 10000000; $i++) {
13-
$r = test($i, $i, $i);
14-
}
15-
}
16-
17-
$t = Time::millis();
18-
foo();
19-
echo (Time::millis() - $t) . "ms\n";
5+
$hello->print();

packager/package.php.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: jppm
2-
version: 0.5.6
2+
version: 0.5.7
33

44
plugins: [GitHub, Hub, Doc]
55

@@ -14,8 +14,8 @@ github:
1414
> JPHP Package Manager v%version%
1515
1616
**What's new**
17-
+ Fix Tasks::run() up-to-date status when using flags.
18-
+ Colorized output for Xterm console (Linux, Mac, Cygwin).
17+
+ Improve build jre (`java.launcher.jdk` option).
18+
+ Remove `one-jar` build type (`app.build.type` option), use only `multi-jar`
1919
2020
**Downloads**
2121
+ For Windows: [JPPM Windows Installer](%github.address%/releases/download/jppm-%version%/jppm-setup-%version%.exe)

0 commit comments

Comments
 (0)