Skip to content

Commit

Permalink
JPPM update, jphp-runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
dim-s committed May 2, 2018
1 parent 44af2d2 commit b7474b1
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 36 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ build/
secret.asc

package.github.yml
package.hub.yml
package.hub.yml

*.hprof
1 change: 0 additions & 1 deletion docs
Submodule docs deleted from 846fb9
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 32 additions & 5 deletions jphp-runtime/api-docs/classes/php/lang/System.md
Original file line number Diff line number Diff line change
Expand Up @@ -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._

---

Expand Down Expand Up @@ -171,6 +173,7 @@ Set stderr stream.
```php
System::tempDirectory(): string
```
Returns temp directory that has write access.

---

Expand All @@ -189,6 +192,7 @@ System::userDirectory(): string
```php
System::userHome(): string
```
Returns user.home directory.

---

Expand All @@ -198,6 +202,7 @@ System::userHome(): string
```php
System::userName(): string
```
Returns os user name which logged.

---

Expand All @@ -207,6 +212,7 @@ System::userName(): string
```php
System::osName(): string
```
Returns Operation System Name, eg: `Windows`.

---

Expand All @@ -216,6 +222,27 @@ System::osName(): string
```php
System::osVersion(): string
```
Returns Operation System Version.

---

<a name="method-addruntimejarfile"></a>

### addRuntimeJarFile()
```php
System::addRuntimeJarFile(mixed $file): void
```
Add jar from file at runtime to runtime.

---

<a name="method-addruntimejarresource"></a>

### addRuntimeJarResource()
```php
System::addRuntimeJarResource(string $path): void
```
Add jar from classpath at runtime to runtime.

---
# Methods
Expand Down
37 changes: 32 additions & 5 deletions jphp-runtime/api-docs/classes/php/lang/System.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 из ресурсов во время выполнения._

---

Expand Down Expand Up @@ -171,6 +173,7 @@ Set stderr stream.
```php
System::tempDirectory(): string
```
Returns temp directory that has write access.

---

Expand All @@ -189,6 +192,7 @@ System::userDirectory(): string
```php
System::userHome(): string
```
Returns user.home directory.

---

Expand All @@ -198,6 +202,7 @@ System::userHome(): string
```php
System::userName(): string
```
Returns os user name which logged.

---

Expand All @@ -207,6 +212,7 @@ System::userName(): string
```php
System::osName(): string
```
Returns Operation System Name, eg: `Windows`.

---

Expand All @@ -216,6 +222,27 @@ System::osName(): string
```php
System::osVersion(): string
```
Returns Operation System Version.

---

<a name="method-addruntimejarfile"></a>

### addRuntimeJarFile()
```php
System::addRuntimeJarFile(mixed $file): void
```
Добавить jar файл во время выполнения.

---

<a name="method-addruntimejarresource"></a>

### addRuntimeJarResource()
```php
System::addRuntimeJarResource(string $path): void
```
Добавить jar из ресурсов во время выполнения.

---
# Методы
Expand Down
27 changes: 27 additions & 0 deletions jphp-runtime/src/main/resources/JPHP-INF/sdk/php/lang/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -123,30 +124,56 @@ public static function userDirectory(): string
}

/**
* Returns user.home directory.
* @return string
*/
public static function userHome(): string
{
}

/**
* Returns os user name which logged.
* @return string
*/
public static function userName(): string
{
}

/**
* Returns Operation System Name, eg: `Windows`.
* @return string
*/
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)
{
}
}
32 changes: 28 additions & 4 deletions jphp-runtime/src/php/runtime/ext/core/classes/WrapSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
}
}
24 changes: 21 additions & 3 deletions packager/buildSrc/GradlePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'";
}
}
}

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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, '.', '/');
Expand Down
28 changes: 13 additions & 15 deletions packager/example/simple/package.php.yml
Original file line number Diff line number Diff line change
@@ -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/**'
- /vendor/**
Loading

0 comments on commit b7474b1

Please sign in to comment.