updated client

This commit is contained in:
2024-02-22 08:50:19 +08:00
parent b1a7bcc9a8
commit ae0e4de23e
8 changed files with 171 additions and 66 deletions

View File

@@ -119,7 +119,6 @@ dependencies {
Provider<War> warTaskProvider = tasks.named('war', War) { War it -> Provider<War> warTaskProvider = tasks.named('war', War) { War it ->
from(configurations.frontend) from(configurations.frontend)
archiveVersion = ''
} }
tasks.named('deploy2Wildfly', Deploy2WildflyTask) { d2w -> tasks.named('deploy2Wildfly', Deploy2WildflyTask) { d2w ->

View File

@@ -1,3 +1,3 @@
jpacrepo.version=2024.02.12 jpacrepo.version=2024.02.22
lys.version=2024.02.12 lys.version=2024.02.22

View File

@@ -1,6 +1,7 @@
plugins { plugins {
id 'java-library' id 'java-library'
alias(catalog.plugins.envelope) alias(catalog.plugins.envelope)
alias(catalog.plugins.sambal)
} }
import net.woggioni.gradle.envelope.EnvelopeJarTask import net.woggioni.gradle.envelope.EnvelopeJarTask
@@ -10,6 +11,7 @@ dependencies {
implementation project(':jpacrepo-api') implementation project(':jpacrepo-api')
implementation catalog.slf4j.api implementation catalog.slf4j.api
implementation catalog.log4j.slf4j.impl implementation catalog.log4j.slf4j.impl
implementation catalog.picocli
runtimeOnly catalog.jboss.ejb.client runtimeOnly catalog.jboss.ejb.client
@@ -20,21 +22,21 @@ java {
} }
tasks.named(JavaPlugin.COMPILE_JAVA_TASK_NAME, JavaCompile) { tasks.named(JavaPlugin.COMPILE_JAVA_TASK_NAME, JavaCompile) {
options.javaModuleMainClass = 'net.woggioni.jpacrepo.client.Main' options.javaModuleMainClass = 'net.woggioni.jpacrepo.client.JpacrepoCli'
// options.compilerArgs += [ // options.compilerArgs += [
// '--add-reads', 'javax.ejb=ALL-UNNAMED' // '--add-reads', 'javax.ejb=ALL-UNNAMED'
// ] // ]
} }
Provider<EnvelopeJarTask> envelopeJarTaskProvider = tasks.named('envelopeJar', EnvelopeJarTask.class) { Provider<EnvelopeJarTask> envelopeJarTaskProvider = tasks.named('envelopeJar', EnvelopeJarTask.class) {
mainClass = 'net.woggioni.jpacrepo.client.Main' mainClass = 'net.woggioni.jpacrepo.client.JpacrepoCli'
} }
tasks.register('run', JavaExec) { JavaExec t -> tasks.register('run', JavaExec) { JavaExec t ->
classpath(project.sourceSets.main.output.dirs) classpath(project.sourceSets.main.output.dirs)
classpath(project.sourceSets.main.runtimeClasspath) classpath(project.sourceSets.main.runtimeClasspath)
mainModule = 'net.woggioni.jpacrepo.client' mainModule = 'net.woggioni.jpacrepo.client'
mainClass = 'net.woggioni.jpacrepo.client.Main' mainClass = 'net.woggioni.jpacrepo.client.JpacrepoCli'
// String modulePath = project.sourceSets.main.runtimeClasspath.files.stream() // String modulePath = project.sourceSets.main.runtimeClasspath.files.stream()
// .map(File::toString) // .map(File::toString)
// .collect(Collectors.joining(System.getProperty('path.separator'))) // .collect(Collectors.joining(System.getProperty('path.separator')))

View File

@@ -5,4 +5,5 @@ module net.woggioni.jpacrepo.client {
requires org.slf4j; requires org.slf4j;
requires org.apache.logging.log4j; requires org.apache.logging.log4j;
requires net.woggioni.jpacrepo.api; requires net.woggioni.jpacrepo.api;
requires info.picocli;
} }

View File

@@ -0,0 +1,51 @@
package net.woggioni.jpacrepo.client;
import lombok.SneakyThrows;
import picocli.CommandLine;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Objects;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
abstract class AbstractVersionProvider implements CommandLine.IVersionProvider {
private final String version;
private final String vcsHash;
@SneakyThrows
protected AbstractVersionProvider(String specificationTitle) {
String version = null;
String vcsHash = null;
Enumeration<URL> it = getClass().getClassLoader().getResources(JarFile.MANIFEST_NAME);
while (it.hasMoreElements()) {
URL manifestURL = it.nextElement();
Manifest mf = new Manifest();
try (InputStream is = manifestURL.openStream()) {
mf.read(is);
}
Attributes mainAttributes = mf.getMainAttributes();
if (Objects.equals(specificationTitle, mainAttributes.getValue(Attributes.Name.SPECIFICATION_TITLE))) {
version = mainAttributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
vcsHash = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
}
}
if (version == null || vcsHash == null) {
throw new RuntimeException("Version information not found in manifest");
}
this.version = version;
this.vcsHash = vcsHash;
}
@Override
public String[] getVersion() {
if (version.endsWith("-SNAPSHOT")) {
return new String[] { version, vcsHash };
} else {
return new String[] { version };
}
}
}

View File

@@ -0,0 +1,111 @@
package net.woggioni.jpacrepo.client;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import net.woggioni.jpacrepo.api.service.FileSystemSynchronizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import java.util.Properties;
class VersionProvider extends AbstractVersionProvider {
protected VersionProvider() {
super(("jpacrepo-client"));
}
}
@Slf4j
@CommandLine.Command(
name = "jpacrepo-cli",
versionProvider = VersionProvider.class)
public class JpacrepoCli implements Runnable {
@CommandLine.Option(
names = {"-ssl", "--tls"},
description = "Connect using SSL/TLS"
)
private boolean ssl = false;
@CommandLine.Option(
names = {"-H", "--host"},
description = "Wildfly server hostname"
)
private String host = "localhost";
@CommandLine.Option(
names = {"-P", "--port"},
description = "Wildfly server RPC port"
)
private int port = 8080;
@CommandLine.Option(
required = true,
names = {"-u", "--user"},
description = "Wildfly RPC username"
)
private String rpcUsername;
@CommandLine.Option(
required = true,
names = {"-p", "--password"},
description = "Wildfly RPC password"
)
private String rpcPassword;
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
private Context createContext() {
Properties prop = new Properties();
prop.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
if(ssl) {
prop.put(Context.PROVIDER_URL, String.format("remote+https://%s:%d", host, port));
} else {
prop.put(Context.PROVIDER_URL, String.format("http-remoting://%s:%d", host, port));
}
prop.put(Context.SECURITY_PRINCIPAL, rpcUsername);
prop.put(Context.SECURITY_CREDENTIALS, rpcPassword);
prop.put("jboss.naming.client.ejb.context", true);
return new InitialContext(prop);
}
@SneakyThrows
@Override
public void run() {
Context ctx = createContext();
// traverseJndiNode("/", context);
final FileSystemSynchronizer service = (FileSystemSynchronizer) ctx.lookup(
"/jpacrepo/PackageSynchronizerEJB!net.woggioni.jpacrepo.api.service.FileSystemSynchronizer"
);
service.syncDb();
}
public static void main(String[] args) {
Logger log = LoggerFactory.getLogger("jpacrepo-cli");
CommandLine commandLine = new CommandLine(new JpacrepoCli());
commandLine.setExecutionExceptionHandler((ex, cl, parseResult) -> {
log.error(ex.getLocalizedMessage(), ex);
return CommandLine.ExitCode.SOFTWARE;
});
System.exit(commandLine.execute(args));
}
}

View File

@@ -1,60 +0,0 @@
package net.woggioni.jpacrepo.client;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import net.woggioni.jpacrepo.api.service.FileSystemSynchronizer;
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 FileSystemSynchronizer service = (FileSystemSynchronizer) ctx.lookup(
"/jpacrepo/PackageSynchronizerEJB!net.woggioni.jpacrepo.api.service.FileSystemSynchronizer"
);
// List<PkgData> pkgs = service.searchPackage("google-earth", null, null, 1, 10);
// System.out.println(new XStream().toXML(pkgs));
service.syncDb();
}
}

View File

@@ -7,6 +7,7 @@ pluginManagement {
includeGroup 'net.woggioni.gradle.lombok' includeGroup 'net.woggioni.gradle.lombok'
includeGroup 'net.woggioni.gradle.wildfly' includeGroup 'net.woggioni.gradle.wildfly'
includeGroup 'net.woggioni.gradle.envelope' includeGroup 'net.woggioni.gradle.envelope'
includeGroup 'net.woggioni.gradle.sambal'
} }
} }
gradlePluginPortal() gradlePluginPortal()