java rewrite

This commit is contained in:
2022-06-03 23:59:59 +08:00
parent 76608d5713
commit b59dcfd93c
68 changed files with 2218 additions and 1769 deletions

View File

@@ -0,0 +1,50 @@
plugins {
id 'java-library'
id "net.woggioni.gradle.envelope"
}
import net.woggioni.gradle.envelope.EnvelopeJarTask
dependencies {
implementation group: 'org.slf4j', name: 'slf4j-api', version: getProperty('slf4j.version')
implementation group: 'org.apache.logging.log4j',
name: 'log4j-slf4j-impl',
version: getProperty('log4j.version')
implementation project(':jpacrepo-api')
runtimeOnly group: 'org.jboss',
name: 'jboss-ejb-client', version: getProperty('jboss.ejb.client.version')
}
java {
modularity.inferModulePath = true
}
tasks.named(JavaPlugin.COMPILE_JAVA_TASK_NAME, JavaCompile) { JavaCompile j ->
options.javaModuleMainClass = 'net.woggioni.jpacrepo.client.Main'
// options.compilerArgs += [
// '--add-reads', 'javax.ejb=ALL-UNNAMED'
// ]
}
Provider<EnvelopeJarTask> envelopeJarTaskProvider = tasks.named('envelopeJar', EnvelopeJarTask.class) {
mainClass = 'net.woggioni.jpacrepo.client.Main'
}
tasks.register('run', JavaExec) { JavaExec t ->
classpath(project.sourceSets.main.output.dirs)
classpath(project.sourceSets.main.runtimeClasspath)
mainModule = 'net.woggioni.jpacrepo.client'
mainClass = 'net.woggioni.jpacrepo.client.Main'
// String modulePath = project.sourceSets.main.runtimeClasspath.files.stream()
// .map(File::toString)
// .collect(Collectors.joining(System.getProperty('path.separator')))
// jvmArgs = [
// '--add-reads', 'net.woggioni.jpacrepo.client=ALL-UNNAMED',
// '--module-path', modulePath
// ]
modularity.inferModulePath = true
}

View File

@@ -0,0 +1,8 @@
module net.woggioni.jpacrepo.client {
requires static lombok;
requires jdk.unsupported;
requires java.naming;
requires org.slf4j;
requires org.apache.logging.log4j;
requires net.woggioni.jpacrepo.api;
}

View File

@@ -0,0 +1,58 @@
package net.woggioni.jpacrepo.client;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import net.woggioni.jpacrepo.api.service.PacmanServiceRemote;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import java.util.Properties;
@Slf4j
public class Main {
private static void traverseJndiNode(String nodeName, Context context) {
try {
NamingEnumeration<NameClassPair> list = context.list(nodeName);
while (list.hasMore()) {
String childName = nodeName + "" + list.next().getName();
System.out.println(childName);
traverseJndiNode(childName, context);
}
} catch (NamingException ex) {
// We reached a leaf
}
}
@SneakyThrows
public static void main(String[] args) {
Properties prop = new Properties();
// InputStream in = Main.class.getClassLoader().getResourceAsStream("jboss-ejb-client.properties");
// prop.load(in);
prop.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
prop.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
// prop.put(Context.PROVIDER_URL, "http-remoting://nuc:8080");
// prop.put(Context.PROVIDER_URL, "remote://odroid-u3:4447");
prop.put(Context.SECURITY_PRINCIPAL, "walter");
prop.put(Context.SECURITY_CREDENTIALS, "27ff5990757d1d");
// prop.put(Context.SECURITY_PRINCIPAL, "luser");
// prop.put(Context.SECURITY_CREDENTIALS, "123456");
prop.put("jboss.naming.client.ejb.context", true);
Context context = new InitialContext(prop);
Context ctx = new InitialContext(prop);
traverseJndiNode("/", context);
// final PacmanService stateService = (PacmanService) ctx.lookup("/jpacrepo-1.0/remote/PacmanServiceEJB!service.PacmanService");
final PacmanServiceRemote service = (PacmanServiceRemote) ctx.lookup(
"/jpacrepo-2.0-SNAPSHOT/PacmanServiceEJB!net.woggioni.jpacrepo.api.service.PacmanServiceRemote"
);
// List<PkgData> pkgs = service.searchPackage("google-earth", null, null, 1, 10);
// System.out.println(new XStream().toXML(pkgs));
service.syncDB();
}
}

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss,SSS} %highlight{[%p]} (%t) %c: %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>