From b7474b1c96bef88805b355769d23ee885efe532b Mon Sep 17 00:00:00 2001 From: Dmitriy Zayceff Date: Wed, 2 May 2018 17:34:12 +0300 Subject: [PATCH] JPPM update, jphp-runtime. --- .gitignore | 4 +- docs | 1 - .../jphp/ext/image/classes/PColor.java | 5 +++ .../api-docs/classes/php/lang/System.md | 37 ++++++++++++++++--- .../api-docs/classes/php/lang/System.ru.md | 37 ++++++++++++++++--- .../JPHP-INF/sdk/php/lang/System.php | 27 ++++++++++++++ .../runtime/ext/core/classes/WrapSystem.java | 32 ++++++++++++++-- packager/buildSrc/GradlePlugin.php | 24 ++++++++++-- packager/example/simple/package.php.yml | 28 +++++++------- packager/package.php.yml | 4 +- 10 files changed, 163 insertions(+), 36 deletions(-) delete mode 160000 docs diff --git a/.gitignore b/.gitignore index f73f4744b..e765ea56e 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,6 @@ build/ secret.asc package.github.yml -package.hub.yml \ No newline at end of file +package.hub.yml + +*.hprof \ No newline at end of file diff --git a/docs b/docs deleted file mode 160000 index 846fb9011..000000000 --- a/docs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 846fb90112617462f9004578195cbe32b4ed1a2f diff --git a/exts/jphp-graphic-ext/src/main/java/org/develnext/jphp/ext/image/classes/PColor.java b/exts/jphp-graphic-ext/src/main/java/org/develnext/jphp/ext/image/classes/PColor.java index 8f2e0e105..c8612e23f 100644 --- a/exts/jphp-graphic-ext/src/main/java/org/develnext/jphp/ext/image/classes/PColor.java +++ b/exts/jphp-graphic-ext/src/main/java/org/develnext/jphp/ext/image/classes/PColor.java @@ -17,6 +17,11 @@ public class PColor extends BaseObject { private Color color; + public PColor(Environment env, String color) { + super(env); + this.color = Color.decode(color); + } + public PColor(Environment env, Color color) { super(env); this.color = color; diff --git a/jphp-runtime/api-docs/classes/php/lang/System.md b/jphp-runtime/api-docs/classes/php/lang/System.md index 76e496309..46763c061 100644 --- a/jphp-runtime/api-docs/classes/php/lang/System.md +++ b/jphp-runtime/api-docs/classes/php/lang/System.md @@ -25,12 +25,14 @@ Class System - `System ::`[`setIn()`](#method-setin) - _Set stdin stream._ - `System ::`[`setOut()`](#method-setout) - _Set stdout stream._ - `System ::`[`setErr()`](#method-seterr) - _Set stderr stream._ -- `System ::`[`tempDirectory()`](#method-tempdirectory) +- `System ::`[`tempDirectory()`](#method-tempdirectory) - _Returns temp directory that has write access._ - `System ::`[`userDirectory()`](#method-userdirectory) -- `System ::`[`userHome()`](#method-userhome) -- `System ::`[`userName()`](#method-username) -- `System ::`[`osName()`](#method-osname) -- `System ::`[`osVersion()`](#method-osversion) +- `System ::`[`userHome()`](#method-userhome) - _Returns user.home directory._ +- `System ::`[`userName()`](#method-username) - _Returns os user name which logged._ +- `System ::`[`osName()`](#method-osname) - _Returns Operation System Name, eg: `Windows`._ +- `System ::`[`osVersion()`](#method-osversion) - _Returns Operation System Version._ +- `System ::`[`addRuntimeJarFile()`](#method-addruntimejarfile) - _Add jar from file at runtime to runtime._ +- `System ::`[`addRuntimeJarResource()`](#method-addruntimejarresource) - _Add jar from classpath at runtime to runtime._ --- @@ -171,6 +173,7 @@ Set stderr stream. ```php System::tempDirectory(): string ``` +Returns temp directory that has write access. --- @@ -189,6 +192,7 @@ System::userDirectory(): string ```php System::userHome(): string ``` +Returns user.home directory. --- @@ -198,6 +202,7 @@ System::userHome(): string ```php System::userName(): string ``` +Returns os user name which logged. --- @@ -207,6 +212,7 @@ System::userName(): string ```php System::osName(): string ``` +Returns Operation System Name, eg: `Windows`. --- @@ -216,6 +222,27 @@ System::osName(): string ```php System::osVersion(): string ``` +Returns Operation System Version. + +--- + + + +### addRuntimeJarFile() +```php +System::addRuntimeJarFile(mixed $file): void +``` +Add jar from file at runtime to runtime. + +--- + + + +### addRuntimeJarResource() +```php +System::addRuntimeJarResource(string $path): void +``` +Add jar from classpath at runtime to runtime. --- # Methods diff --git a/jphp-runtime/api-docs/classes/php/lang/System.ru.md b/jphp-runtime/api-docs/classes/php/lang/System.ru.md index fe49fadd7..aa0fc2d4f 100644 --- a/jphp-runtime/api-docs/classes/php/lang/System.ru.md +++ b/jphp-runtime/api-docs/classes/php/lang/System.ru.md @@ -25,12 +25,14 @@ Class System - `System ::`[`setIn()`](#method-setin) - _Set stdin stream._ - `System ::`[`setOut()`](#method-setout) - _Set stdout stream._ - `System ::`[`setErr()`](#method-seterr) - _Set stderr stream._ -- `System ::`[`tempDirectory()`](#method-tempdirectory) +- `System ::`[`tempDirectory()`](#method-tempdirectory) - _Returns temp directory that has write access._ - `System ::`[`userDirectory()`](#method-userdirectory) -- `System ::`[`userHome()`](#method-userhome) -- `System ::`[`userName()`](#method-username) -- `System ::`[`osName()`](#method-osname) -- `System ::`[`osVersion()`](#method-osversion) +- `System ::`[`userHome()`](#method-userhome) - _Returns user.home directory._ +- `System ::`[`userName()`](#method-username) - _Returns os user name which logged._ +- `System ::`[`osName()`](#method-osname) - _Returns Operation System Name, eg: `Windows`._ +- `System ::`[`osVersion()`](#method-osversion) - _Returns Operation System Version._ +- `System ::`[`addRuntimeJarFile()`](#method-addruntimejarfile) - _Добавить jar файл во время выполнения._ +- `System ::`[`addRuntimeJarResource()`](#method-addruntimejarresource) - _Добавить jar из ресурсов во время выполнения._ --- @@ -171,6 +173,7 @@ Set stderr stream. ```php System::tempDirectory(): string ``` +Returns temp directory that has write access. --- @@ -189,6 +192,7 @@ System::userDirectory(): string ```php System::userHome(): string ``` +Returns user.home directory. --- @@ -198,6 +202,7 @@ System::userHome(): string ```php System::userName(): string ``` +Returns os user name which logged. --- @@ -207,6 +212,7 @@ System::userName(): string ```php System::osName(): string ``` +Returns Operation System Name, eg: `Windows`. --- @@ -216,6 +222,27 @@ System::osName(): string ```php System::osVersion(): string ``` +Returns Operation System Version. + +--- + + + +### addRuntimeJarFile() +```php +System::addRuntimeJarFile(mixed $file): void +``` +Добавить jar файл во время выполнения. + +--- + + + +### addRuntimeJarResource() +```php +System::addRuntimeJarResource(string $path): void +``` +Добавить jar из ресурсов во время выполнения. --- # Методы diff --git a/jphp-runtime/src/main/resources/JPHP-INF/sdk/php/lang/System.php b/jphp-runtime/src/main/resources/JPHP-INF/sdk/php/lang/System.php index 88797771a..845d61f1f 100644 --- a/jphp-runtime/src/main/resources/JPHP-INF/sdk/php/lang/System.php +++ b/jphp-runtime/src/main/resources/JPHP-INF/sdk/php/lang/System.php @@ -109,6 +109,7 @@ public static function setErr(?Stream $err, string $encoding = null) } /** + * Returns temp directory that has write access. * @return string */ public static function tempDirectory(): string @@ -123,6 +124,7 @@ public static function userDirectory(): string } /** + * Returns user.home directory. * @return string */ public static function userHome(): string @@ -130,6 +132,7 @@ public static function userHome(): string } /** + * Returns os user name which logged. * @return string */ public static function userName(): string @@ -137,6 +140,7 @@ public static function userName(): string } /** + * Returns Operation System Name, eg: `Windows`. * @return string */ public static function osName(): string @@ -144,9 +148,32 @@ public static function osName(): string } /** + * Returns Operation System Version. * @return string */ public static function osVersion(): string { } + + /** + * Add jar from file at runtime to runtime. + * --RU-- + * Добавить jar файл во время выполнения. + * + * @param $file + */ + public static function addRuntimeJarFile($file) + { + } + + /** + * Add jar from classpath at runtime to runtime. + * --RU-- + * Добавить jar из ресурсов во время выполнения. + * + * @param string $path + */ + public static function addRuntimeJarResource(string $path) + { + } } diff --git a/jphp-runtime/src/php/runtime/ext/core/classes/WrapSystem.java b/jphp-runtime/src/php/runtime/ext/core/classes/WrapSystem.java index 84268f9e5..be2068591 100644 --- a/jphp-runtime/src/php/runtime/ext/core/classes/WrapSystem.java +++ b/jphp-runtime/src/php/runtime/ext/core/classes/WrapSystem.java @@ -4,13 +4,12 @@ import php.runtime.env.Environment; import php.runtime.ext.core.classes.stream.Stream; import php.runtime.lang.BaseObject; +import php.runtime.loader.RuntimeClassLoader; import php.runtime.memory.StringMemory; import php.runtime.reflection.ClassEntity; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.io.UnsupportedEncodingException; +import java.io.*; +import java.net.URL; import java.util.Map; import java.util.Properties; @@ -161,4 +160,29 @@ public static String osName() { public static String osVersion() { return System.getProperty("os.name"); } + + @Signature + public static void addRuntimeJarFile(Environment env, File file) throws IOException { + try { + env.getScope().getClassLoader().addLibrary(file.toURI().toURL()); + } catch (Throwable t) { + throw new IOException("Error, could not add URL to system classloader, " + t.getMessage()); + } + } + + @Signature + public static void addRuntimeJarResource(Environment env, String file) throws IOException { + try { + RuntimeClassLoader classLoader = env.getScope().getClassLoader(); + URL resource = classLoader.getResource(file); + + if (resource == null) { + throw new IOException("Resource not found"); + } + + classLoader.addLibrary(resource); + } catch (Throwable t) { + throw new IOException("Error, could not add URL to system classloader, " + t.getMessage()); + } + } } diff --git a/packager/buildSrc/GradlePlugin.php b/packager/buildSrc/GradlePlugin.php index cce8dd1d9..21c99a6bf 100644 --- a/packager/buildSrc/GradlePlugin.php +++ b/packager/buildSrc/GradlePlugin.php @@ -56,7 +56,23 @@ protected function makeGradleBuild(Package $pkg) foreach ((array) $this->config['deps'] as $dep) { if (str::trim($dep)) { - $compile[] = " compile '$dep'"; + if (str::startsWith($dep, 'file:')) { + $dep = str::sub($dep, 5); + $compile[] = " compile files('$dep')"; + } else { + $compile[] = " compile '$dep'"; + } + } + } + + foreach ((array) $this->config['providedDeps'] as $dep) { + if (str::trim($dep)) { + if (str::startsWith($dep, 'file:')) { + $dep = str::sub($dep, 5); + $provided[] = " provided files('$dep')"; + } else { + $provided[] = " provided '$dep'"; + } } } @@ -155,6 +171,7 @@ public function install(Event $event) /** * @jppm-need-package * @jppm-depends-on gradle:install + * @jppm-dependency-of publish * @jppm-dependency-of build * @param Event $event */ @@ -186,8 +203,9 @@ public function init(Event $event) $name = $event->package()->getName(); $name = (new TextWord($name))->capitalizeFully('-_ '); - $name = str::replace($name, '-', ' '); - $name = str::replace($name, '_', ' '); + $name = str::replace($name, '-', ''); + $name = str::replace($name, '_', ''); + $name = str::replace($name, ' ', ''); $package = Console::read('Enter package name of java sources:', 'php.pkg.' . str::lower($name)); $packageDir = str::replace($package, '.', '/'); diff --git a/packager/example/simple/package.php.yml b/packager/example/simple/package.php.yml index 8ebc01fe2..5226fbdae 100644 --- a/packager/example/simple/package.php.yml +++ b/packager/example/simple/package.php.yml @@ -1,30 +1,28 @@ name: simple version: 1.0.0 - deps: jphp-core: '*' jppm-helloworld: github.com/jphp-compiler/jppm-helloworld#dev - -plugins: [Doc, Hub] - + jphp-mysql-ext: '*' +plugins: +- Doc +- Hub app: - disable-launcher: true + disable-launcher: '1' bootstrap: index.php encoding: UTF-8 - metrics: false - trace: false - + metrics: '' + trace: '' sources: - src - doc: - langs: {en: English, ru: Русский} - + langs: + en: English + ru: Русский config: - build-dir: ./build-new - vendor-dir: ./vendor-jppm + build-dir: ./build + vendor-dir: ./vendor archive-dir: ./../ archive-format: zip - ignore: - - '/vendor/**' \ No newline at end of file + - /vendor/** diff --git a/packager/package.php.yml b/packager/package.php.yml index 48941326a..3f3058f0e 100644 --- a/packager/package.php.yml +++ b/packager/package.php.yml @@ -1,5 +1,5 @@ name: jppm -version: 0.2.1 +version: 0.2.3 plugins: [GitHub, Hub, Doc] @@ -14,7 +14,7 @@ github: > JPHP Package Manager v%version% **What's new** - + Add Gradle plugin for java sources. + + Fix bugs in the Gradle plugin. **Downloads** + For Windows: [JPPM Windows Installer](%github.address%/releases/download/jppm-%version%/jppm-setup-%version%.exe)