11<?php
22namespace PHPJava \Core ;
33
4+ use PHPJava \Exceptions \UndefinedEntrypointException ;
45use PHPJava \Imitation \java \io \FileNotFoundException ;
56use PHPJava \Imitation \java \lang \ClassNotFoundException ;
67use 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}
0 commit comments