Skip to content

Commit 06ca15d

Browse files
committed
new version
1 parent 2659b2e commit 06ca15d

File tree

2 files changed

+60
-8
lines changed

2 files changed

+60
-8
lines changed

build.gradle

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,31 @@ plugins {
33
}
44

55
group 'com.github.kayjamlang'
6-
version '0.1'
6+
version '0.1.1'
77

88
repositories {
99
mavenCentral()
10+
maven {
11+
url "https://oss.sonatype.org/service/local/repositories/releases/content/"
12+
}
13+
}
14+
15+
jar {
16+
manifest {
17+
attributes(
18+
'Main-Class': 'com.github.kayjamlang.executor.cli.Main'
19+
)
20+
}
21+
from {
22+
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
23+
}
24+
1025
}
1126

1227
dependencies {
1328
implementation group: 'commons-cli', name: 'commons-cli', version: '1.4'
14-
implementation group: 'com.github.kayjamlang', name: 'core', version: '0.1.2.1'
15-
implementation group: 'com.github.kayjamlang', name: 'executor', version: '0.1.2'
29+
//implementation group: 'com.github.kayjamlang', name: 'core', version: '0.1.2.1'
30+
implementation group: 'com.github.kayjamlang', name: 'executor', version: '0.1.3'
1631
implementation group: 'com.github.albfernandez', name: 'juniversalchardet', version: '2.4.0'
1732
testCompile group: 'junit', name: 'junit', version: '4.13'
1833
}

src/main/java/com/github/kayjamlang/executor/cli/Main.java

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
package com.github.kayjamlang.executor.cli;
22

33
import com.github.kayjamlang.executor.Executor;
4-
import com.github.kayjamlang.executor.MainLibrary;
4+
import com.github.kayjamlang.executor.libs.main.MainLibrary;
5+
import com.github.kayjamlang.executor.libs.Library;
56
import org.apache.commons.cli.*;
67
import org.mozilla.universalchardet.UniversalDetector;
78

89
import java.io.File;
910
import java.io.IOException;
11+
import java.net.URL;
12+
import java.net.URLClassLoader;
1013
import java.nio.file.Paths;
14+
import java.util.Enumeration;
1115
import java.util.Scanner;
16+
import java.util.jar.JarEntry;
17+
import java.util.jar.JarFile;
1218

1319
public class Main {
1420

@@ -27,20 +33,51 @@ public static void main(String[] args) throws Exception {
2733
cmd = parser.parse(options, args);
2834
} catch (ParseException e) {
2935
System.out.println(e.getMessage());
30-
formatter.printHelp("kayjam", options);
36+
formatter.printHelp("kayjam-cli", options);
3137

3238
System.exit(1);
3339
return;
3440
}
3541

36-
File executeFile = new File(Paths.get(System.getProperty("user.dir"),
37-
cmd.getOptionValue("file")).normalize().toString());
38-
3942
Executor executor = new Executor();
4043
executor.addLibrary(new MainLibrary());
44+
File libDir = new File(Paths.get(System.getProperty("user.dir"),
45+
"./libs/").normalize().toString());
46+
if(libDir.exists()){
47+
File[] files = libDir.listFiles();
48+
if(files!=null)
49+
for(File libJar: files){
50+
if(libDir.getName().endsWith(".jar"))
51+
loadJarLibrary(executor, libJar);
52+
}
53+
}
54+
55+
File executeFile = new File(Paths.get(System.getProperty("pathFile"),
56+
cmd.getOptionValue("file")).normalize().toString());
4157
executor.execute("{"+read(executeFile)+"}");
4258
}
4359

60+
private static void loadJarLibrary(Executor executor, File file) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
61+
JarFile jarFile = new JarFile(file);
62+
Enumeration<JarEntry> e = jarFile.entries();
63+
64+
URL[] urls = { new URL("jar:file:" + file.getPath()+"!/") };
65+
URLClassLoader cl = URLClassLoader.newInstance(urls);
66+
67+
while (e.hasMoreElements()) {
68+
JarEntry je = e.nextElement();
69+
if(je.isDirectory() || !je.getName().endsWith(".class")){
70+
continue;
71+
}
72+
73+
String className = je.getName().substring(0,je.getName().length()-6);
74+
className = className.replace('/', '.');
75+
Class<?> c = cl.loadClass(className);
76+
if(c.isAssignableFrom(Library.class))
77+
executor.addLibrary((Library) c.newInstance());
78+
}
79+
}
80+
4481
private static String read(File file) throws IOException {
4582
Scanner reader = new Scanner(file, UniversalDetector.detectCharset(file));
4683

0 commit comments

Comments
 (0)