Skip to content

Commit f9d7288

Browse files
committed
Upgrade JPPM 0.5.4 & 0.5.5
1 parent 2835db3 commit f9d7288

File tree

5 files changed

+56
-16
lines changed

5 files changed

+56
-16
lines changed

packager/buildSrc/AppPlugin.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ function build(Event $event)
311311
$javaRuntimeBuilder->addJar($jar);
312312
}
313313

314+
$tree = $event->packager()->fetchDependencyTree($event->package(), '');
315+
$tree->eachDep(function (Package $pkg) use ($javaRuntimeBuilder) {
316+
$javaRuntimeBuilder->addJvmModules(...$pkg->getAny('jvm-modules', []));
317+
});
318+
314319
$javaRuntimeBuilder->build($buildDir);
315320
Console::log("-> Java Runtime is build successfully, the app will use the 'jre' dir as JAVA_HOME");
316321
}

packager/buildSrc/app/AppPluginJavaRuntimeBuilder.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use php\lang\System;
99
use php\lib\fs;
1010
use php\lib\str;
11+
use php\util\Flow;
1112

1213
class AppPluginJavaRuntimeBuilder
1314
{
@@ -16,6 +17,8 @@ class AppPluginJavaRuntimeBuilder
1617
*/
1718
public $jars = [];
1819

20+
public $jvmModules = [];
21+
1922
public function __construct()
2023
{
2124
}
@@ -25,6 +28,16 @@ public function addJar($jar)
2528
$this->jars[$jar] = $jar;
2629
}
2730

31+
public function addJvmModules(...$modules)
32+
{
33+
foreach ($modules as $module) {
34+
if (!$this->jvmModules[$module]) {
35+
$this->jvmModules[$module] = $module;
36+
Console::log("-- add jvm module '{0}'", $module);
37+
}
38+
}
39+
}
40+
2841
public function fetchModules($workingDir)
2942
{
3043
$javaExec = new JavaExec();
@@ -41,8 +54,14 @@ public function fetchModules($workingDir)
4154
foreach (str::lines($string, true) as $line) {
4255
[, $module] = str::split($line, "->");
4356
$module = str::trim($module);
44-
if ($module === "not found") continue;
45-
$modules[$module] = $module;
57+
if ($module === "not found") {
58+
continue;
59+
}
60+
61+
if (!$modules[$module]) {
62+
Console::log("-- add jvm module '{0}'", $module);
63+
$modules[$module] = $module;
64+
}
4665
}
4766
}
4867
}
@@ -52,11 +71,10 @@ public function fetchModules($workingDir)
5271

5372
public function build($workingDir)
5473
{
55-
$modules = $this->fetchModules($workingDir);
56-
57-
foreach ($modules as $module) {
58-
Console::log("-- add jvm module '{0}'", $module);
59-
}
74+
$modules = flow(
75+
$this->fetchModules($workingDir),
76+
$this->jvmModules
77+
)->toMap();
6078

6179
$javaExec = new JavaExec();
6280
$javaHome = fs::parent($javaExec->getJavaBin());

packager/buildSrc/app/__compile-app-bytecode.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use php\lang\Environment;
66
use php\lang\Module;
77
use php\lib\fs;
8+
use php\lib\str;
89

910
function ____makePackage($fileOrStream)
1011
{
@@ -84,20 +85,23 @@ function ____compile($sourceDir)
8485
spl_autoload_register(function ($name) use ($sourceDir, &$includedFiles) {
8586
echo("Try class '$name' auto load\n");
8687

87-
$filename = "$sourceDir/$name.php";
88-
$includedFiles[fs::normalize($filename)] = true;
88+
$filename = "$sourceDir/" . str::replace($name, "\\", "/") . ".php";
8989

90-
if (fs::exists($filename)) {
90+
if (fs::isFile($filename)) {
9191
echo "Find class '$name' in ", $filename, "\n";
92+
$includedFiles[fs::normalize($filename)] = true;
9293

93-
$compiled = new File($sourceDir, $name . ".phb");
94+
$compiled = new File($sourceDir, str::replace($name, "\\", "/") . ".phb");
9495
fs::ensureParent($compiled);
9596

9697
$fileStream = new FileStream($filename);
9798
$module = new Module($fileStream, false, true);
9899
$module->dump($compiled, true);
99100
$fileStream->close();
101+
$includedFiles[fs::normalize($filename)] = true;
100102
return;
103+
} else {
104+
echo "[WARN] Unable to load '$name' class, '$filename' is not found";
101105
}
102106
});
103107

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?php
2+
use std;
23

34
$hello = new \helloworld\HelloWorld("Hello? World");
4-
$hello->print();
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";

packager/package.php.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: jppm
2-
version: 0.5.3
2+
version: 0.5.5
33

44
plugins: [GitHub, Hub, Doc]
55

@@ -14,9 +14,7 @@ github:
1414
> JPHP Package Manager v%version%
1515
1616
**What's new**
17-
+ Add jlink support for build Java Runtime portable (in App plugin)
18-
+ Add launch scripts (sh & bat) in App Plugin
19-
+ Improve internal SDK.
17+
+ Fix bytecode compilation for Linux & Mac.
2018
2119
**Downloads**
2220
+ For Windows: [JPPM Windows Installer](%github.address%/releases/download/jppm-%version%/jppm-setup-%version%.exe)

0 commit comments

Comments
 (0)