Skip to content

Commit eb1b9d4

Browse files
committed
Support jar class
1 parent 8b95075 commit eb1b9d4

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

src/Core/JavaArchive.php

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace PHPJava\Core;
33

4+
use PHPJava\Exceptions\UndefinedEntrypointException;
45
use PHPJava\Imitation\java\io\FileNotFoundException;
56
use PHPJava\Imitation\java\lang\ClassNotFoundException;
67
use PHPJava\Utilities\ClassResolver;
@@ -76,6 +77,24 @@ function ($fileName) {
7677
);
7778
}
7879

80+
/**
81+
* Execute jar file.
82+
*
83+
* @return mixed
84+
* @throws ClassNotFoundException
85+
*/
86+
public function execute()
87+
{
88+
return $this->getClassByName($this->getEntryPointName())
89+
->getInvoker()
90+
->getStatic()
91+
->getMethods()
92+
->call(
93+
static::DEFAULT_ENTRYPOINT_NAME,
94+
[]
95+
);
96+
}
97+
7998
public function __debugInfo()
8099
{
81100
return [
@@ -84,6 +103,7 @@ public function __debugInfo()
84103
'entryPointName' => $this->getEntryPointName(),
85104
'file' => $this->jarFile,
86105
'classes' => $this->getClasses(),
106+
'classPaths' => $this->getClassPaths(),
87107
];
88108
}
89109

@@ -102,6 +122,18 @@ public function getEntryPointName(): ?string
102122
return $this->manifestData['main-class'] ?? null;
103123
}
104124

125+
public function getClassPaths(): array
126+
{
127+
$classPaths = [];
128+
foreach (explode(' ', $this->manifestData['class-path'] ?? []) as $path) {
129+
if (empty($path)) {
130+
continue;
131+
}
132+
$classPaths[] = $path;
133+
}
134+
return $classPaths;
135+
}
136+
105137
public function getClasses(): array
106138
{
107139
return $this->classes;
@@ -114,19 +146,4 @@ public function getClassByName(string $name): JavaClass
114146
}
115147
return $this->classes[$name];
116148
}
117-
118-
private function getEntryPointFinderPath(): array
119-
{
120-
if (strpos('.', $this->getEntryPointName()) === false) {
121-
return [
122-
[$this->getEntryPointName(), static::DEFAULT_ENTRYPOINT_NAME],
123-
];
124-
}
125-
$splitEntryPoint = explode('.', $this->getEntryPointName());
126-
$methodOrClassName = array_pop($splitEntryPoint);
127-
return [
128-
[implode('.', $splitEntryPoint), $methodOrClassName],
129-
[$this->getEntryPointName(), static::DEFAULT_ENTRYPOINT_NAME],
130-
];
131-
}
132149
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace PHPJava\Exceptions;
3+
4+
class UndefinedEntrypointException extends \Exception
5+
{
6+
}

0 commit comments

Comments
 (0)