X - Fixes for API changes
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.r35157.nenjim.hubd.impl.ref;
|
||||
|
||||
import com.r35157.nenjim.hubd.ctx.Context;
|
||||
import com.r35157.nenjim.hubd.ctx.ContextManager;
|
||||
import com.r35157.nenjim.valuetypes.ctx.ContextId;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class ContextManagerImpl implements ContextManager {
|
||||
public ContextManagerImpl() {
|
||||
this.defaultContext = new Context();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context getDefault() {
|
||||
return defaultContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context get(ContextId contextId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ContextId> getList() {
|
||||
return Set.of();
|
||||
}
|
||||
|
||||
private Context defaultContext;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.r35157.nenjim.hubd.impl.ref;
|
||||
|
||||
import com.r35157.nenjim.hubd.journal.Journal;
|
||||
import com.r35157.nenjim.hubd.journal.JournalManager;
|
||||
|
||||
public class JournalManagerImpl implements JournalManager {
|
||||
@Override
|
||||
public Journal getJournal(String s) {
|
||||
return new Journal(null, null, null);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,55 @@
|
||||
package com.r35157.nenjim.hubd.impl.ref;
|
||||
|
||||
import com.r35157.nenjim.hubd.ctx.Context;
|
||||
import com.r35157.nenjim.hubd.NenjimHub;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
//import org.apache.logging.log4j.LogManager;
|
||||
//import org.apache.logging.log4j.Logger;
|
||||
import java.lang.management.ClassLoadingMXBean;
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
import com.r35157.nenjim.hubd.ctx.ContextManager;
|
||||
import com.r35157.nenjim.hubd.journal.JournalManager;
|
||||
import com.r35157.nenjim.hubd.impl.ref.JournalManagerImpl;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class Main {
|
||||
static void main(String[] args) throws Exception {
|
||||
try {
|
||||
new Main(args).service();
|
||||
} catch(Throwable t) {
|
||||
log.error("Error initializing NenjimHub - " + t.getMessage());
|
||||
}
|
||||
new Main(args).start();
|
||||
}
|
||||
|
||||
public Main(String[] args) throws Exception {
|
||||
hub = new NenjimHubImpl();
|
||||
/*hub = new NenjimHubImpl();
|
||||
log.info("Initializing NenjimHub...");
|
||||
log.info("Ready!");
|
||||
|
||||
hub.noop();
|
||||
Thread.sleep(Long.MAX_VALUE);
|
||||
String classesCacheDirRaw = "~/.config/nenjim/cache/classes";
|
||||
String classesCacheDir = (classesCacheDirRaw.startsWith("~/"))
|
||||
? System.getProperty("user.home") + classesCacheDirRaw.substring(1)
|
||||
: classesCacheDirRaw;
|
||||
Path pathToClassesCache = Path.of(classesCacheDir);
|
||||
|
||||
if(Files.exists(pathToClassesCache) == false) {
|
||||
System.err.println("Cannot find '" + classesCacheDirRaw + "'");
|
||||
System.exit(-1);
|
||||
}*/
|
||||
|
||||
//System.out.println("Initializing initial NenjimClassLoader with default context...");
|
||||
JournalManager journalManager = new JournalManagerImpl();
|
||||
ContextManager contextManager = new ContextManagerImpl();
|
||||
Context defaultContext = contextManager.getDefault();
|
||||
|
||||
NenjimClassLoader nenjimClassLoader = new NenjimClassLoader(journalManager, defaultContext);
|
||||
Class<?> clazz = nenjimClassLoader.findClass("com.r35157.nenjim.hubd.impl.ref.NenjimHubImpl");
|
||||
|
||||
/*NenjimHub nenjimHub = null;
|
||||
Context defaultContext = new Context();
|
||||
|
||||
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||
NenjimKicker kicker = (NenjimKicker)instance;
|
||||
*/
|
||||
int a = 0;
|
||||
}
|
||||
|
||||
private void service() throws Exception {
|
||||
private void start() {
|
||||
}
|
||||
|
||||
private static final Logger log = LogManager.getLogger(Main.class);
|
||||
|
||||
private final NenjimHub hub;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.r35157.nenjim.hubd.impl.ref;
|
||||
|
||||
import com.r35157.libs.valuetypes.basic.SemanticVersion;
|
||||
import com.r35157.nenjim.hubd.ctx.Context;
|
||||
import com.r35157.nenjim.hubd.journal.Journal;
|
||||
import com.r35157.nenjim.hubd.journal.JournalManager;
|
||||
import com.r35157.nenjim.hubd.module.Release;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class NenjimClassLoader extends ClassLoader {
|
||||
// TODO: Check protection - it is only main that can create a 'half' initialized classloader (and set the rest with setters afterwards)
|
||||
NenjimClassLoader(JournalManager journalManager, Context context) {
|
||||
this.journalManager = journalManager;
|
||||
this.context = context;
|
||||
//moduleVersion = new SemanticVersion(0, 1, 0);
|
||||
}
|
||||
|
||||
private String getModuleName(String className) {
|
||||
return className.substring(0, className.lastIndexOf("."));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> findClass(String className) throws ClassNotFoundException {
|
||||
System.out.println("NenjimClassLoader asked to load '" + className + "'...");
|
||||
|
||||
// Check if we have any local version preferences configured for the associated Context.
|
||||
SemanticVersion version = context.getVersion(className);
|
||||
|
||||
if(version == null) {
|
||||
// No local configurations for a specific version has been configured for this package
|
||||
// in this Context. Use the version the developer do recommend in the Journal.
|
||||
String moduleName = getModuleName(className);
|
||||
System.out.println(" Context (" + context.getName() + ") does NOT have any special version requirements for the module '" + moduleName + "' - use vendor recommendation from journal...");
|
||||
Journal journal = journalManager.getJournal(moduleName);
|
||||
Release release = journal.getRelease(version);
|
||||
System.out.println(" Journal did recommend version '" + version + "' for the module '" + moduleName + "'");
|
||||
}
|
||||
System.out.println("Searching for class '" + className + "' in local Nenjim class cache...");
|
||||
String relativePath = className.replace('.', '/') + ".class";
|
||||
int a = 0;
|
||||
/*
|
||||
Path classFile = classCacheRoot.resolve(relativePath);
|
||||
|
||||
if (!Files.exists(classFile)) {
|
||||
throw new ClassNotFoundException("Class not found: " + className + " at " + classFile);
|
||||
}
|
||||
|
||||
try {
|
||||
byte[] classBytes = Files.readAllBytes(classFile);
|
||||
return defineClass(className, classBytes, 0, classBytes.length);
|
||||
} catch (IOException e) {
|
||||
throw new ClassNotFoundException("Failed to load class: " + className, e);
|
||||
}
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
private JournalManager journalManager;
|
||||
private Context context;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.r35157.nenjim.hubd.impl.ref;
|
||||
|
||||
import com.r35157.nenjim.hubd.NenjimHub;
|
||||
import com.r35157.nenjim.hubd.NenjimJournal;
|
||||
import com.r35157.nenjim.hubd.journal.Journal;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -13,7 +13,7 @@ public class NenjimHubImpl implements NenjimHub {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void monitorJournal(@NotNull NenjimJournal nenjimJournal) {
|
||||
public void monitorJournal(@NotNull Journal journal) {
|
||||
log.warn("monitorJournal IS NOT IMPLEMENTED!");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user