Compare commits
3 Commits
664c6108a5
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc690f3350 | ||
|
|
8be9cf81d7 | ||
|
|
7df22a2d1f |
@@ -2,13 +2,25 @@
|
|||||||
set -uo pipefail
|
set -uo pipefail
|
||||||
|
|
||||||
# when executed as executable file in "git for windows" bash some things won't work, so always run with prefixed command
|
# when executed as executable file in "git for windows" bash some things won't work, so always run with prefixed command
|
||||||
originDir=$(pwd);
|
jarDir=/g/zeitlaeufer/dist/;
|
||||||
cd /g/zeitlaeufer/;
|
if [[ $# == 0 || ($1 != -quick && $1 != -class) ]]; then
|
||||||
tmpDir="/tmp/zeitlaeufer_$RANDOM";
|
tmpDir=/tmp/zeitlaeufer_$RANDOM;
|
||||||
mkdir $tmpDir;
|
mkdir $tmpDir;
|
||||||
cp dist/zeitlaeufer.jar $tmpDir;
|
cp ${jarDir}zeitlaeufer.jar $tmpDir;
|
||||||
cd $originDir;
|
jarDir=$tmpDir;
|
||||||
|
elif [[ $1 == -quick ]]; then
|
||||||
|
shift;
|
||||||
|
elif [[ $1 == -class ]]; then
|
||||||
|
originDir=$(pwd);
|
||||||
|
cd /g/zeitlaeufer/target/;
|
||||||
|
java de.szimnau.zeitlaeufer.$2;
|
||||||
|
exitCode=$?;
|
||||||
|
cd originDir;
|
||||||
|
return $exitCode;
|
||||||
|
fi
|
||||||
# java -jar $tmpDir/zeitlaeufer.jar $@;
|
# java -jar $tmpDir/zeitlaeufer.jar $@;
|
||||||
# -p <=> --module-path | -m <=> --module
|
# -p <=> --module-path | -m <=> --module
|
||||||
java --module-path $tmpDir/zeitlaeufer.jar --module zeitlaeufer $@;
|
java --module-path $jarDir/zeitlaeufer.jar --module zeitlaeufer $@;
|
||||||
rm -r $tmpDir;
|
if [[ -n $tmpDir && -d $tmpDir ]]; then
|
||||||
|
rm -r $tmpDir;
|
||||||
|
fi
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package de.szimnau.zeitlaeufer;
|
|||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -45,22 +46,15 @@ public class Main {
|
|||||||
|
|
||||||
private static SortedMap<Integer, Class<?>> getAllrelevantClasses() {
|
private static SortedMap<Integer, Class<?>> getAllrelevantClasses() {
|
||||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||||
List<String> fileNames = new ArrayList<>();
|
URL resourceUrl = classLoader.getResource("de/szimnau/zeitlaeufer");
|
||||||
URL jarUrl = classLoader.getResource("de/szimnau/zeitlaeufer");
|
if (resourceUrl == null) {
|
||||||
String path = jarUrl.getPath().split(":", 2)[1];
|
throw new RuntimeException("Kann ausführbare Klassen nicht eruieren, da keine Ressource \"de/szimnau/zeitlaeufer\" verfügbar.");
|
||||||
String cleanPath = path.substring(0, path.lastIndexOf('!'));
|
|
||||||
Enumeration<JarEntry> entries;
|
|
||||||
try (var jarFile = new JarFile(URLDecoder.decode(cleanPath, StandardCharsets.UTF_8))) {
|
|
||||||
entries = jarFile.entries();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
while (entries.hasMoreElements()) {
|
Set<String> fileNames;
|
||||||
JarEntry entry = entries.nextElement();
|
if (resourceUrl.getPath().contains(".jar")) {
|
||||||
if (entry.isDirectory()) {
|
fileNames = getFileNamesStreamFromJar(resourceUrl);
|
||||||
continue;
|
} else {
|
||||||
}
|
fileNames = getFileNamesStreamFromPackage(resourceUrl);
|
||||||
fileNames.add(entry.getName());
|
|
||||||
}
|
}
|
||||||
var increment = new AtomicInteger();
|
var increment = new AtomicInteger();
|
||||||
return Collections.unmodifiableSortedMap(new TreeMap<>(
|
return Collections.unmodifiableSortedMap(new TreeMap<>(
|
||||||
@@ -79,6 +73,39 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static Set<String> getFileNamesStreamFromJar(URL resourceUrl) {
|
||||||
|
Set<String> fileNames = new HashSet<>();
|
||||||
|
String path = resourceUrl.getPath().split(":", 2)[1];
|
||||||
|
String cleanPath = path.substring(0, path.lastIndexOf('!'));
|
||||||
|
Enumeration<JarEntry> entries;
|
||||||
|
try (var jarFile = new JarFile(URLDecoder.decode(cleanPath, StandardCharsets.UTF_8))) {
|
||||||
|
entries = jarFile.entries();
|
||||||
|
while (entries.hasMoreElements()) {
|
||||||
|
JarEntry entry = entries.nextElement();
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fileNames.add(entry.getName());
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Kann JAR-Datei zwecks Reflection nicht öffnen:", e);
|
||||||
|
}
|
||||||
|
return fileNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static Set<String> getFileNamesStreamFromPackage(URL resourceUrl) {
|
||||||
|
try (InputStream stream = resourceUrl.openStream();
|
||||||
|
var br = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
|
||||||
|
return br.lines()
|
||||||
|
.map(line -> "de/szimnau/zeitlaeufer." + line)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("ausführbare Klassen nicht eruieren, da Ressource " + resourceUrl + " nicht auslesbar.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static Class<?> getClass(String className) {
|
private static Class<?> getClass(String className) {
|
||||||
String classWithPath = className.replace("/", ".");
|
String classWithPath = className.replace("/", ".");
|
||||||
return getClassForName(classWithPath.substring(0, className.lastIndexOf('.')));
|
return getClassForName(classWithPath.substring(0, className.lastIndexOf('.')));
|
||||||
|
|||||||
Reference in New Issue
Block a user