diff --git a/appserver/admin/backup/src/main/java/com/sun/enterprise/backup/ListManager.java b/appserver/admin/backup/src/main/java/com/sun/enterprise/backup/ListManager.java index 155f9832bf1..c2d98a38579 100644 --- a/appserver/admin/backup/src/main/java/com/sun/enterprise/backup/ListManager.java +++ b/appserver/admin/backup/src/main/java/com/sun/enterprise/backup/ListManager.java @@ -22,7 +22,6 @@ package com.sun.enterprise.backup; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.util.ColumnFormatter; import com.sun.enterprise.util.io.FileUtils; @@ -33,6 +32,8 @@ import java.util.List; import java.util.TreeSet; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; + /** * diff --git a/appserver/admin/cli-optional/pom.xml b/appserver/admin/cli-optional/pom.xml index f3a7f29d1ff..66dc0f79af1 100755 --- a/appserver/admin/cli-optional/pom.xml +++ b/appserver/admin/cli-optional/pom.xml @@ -80,7 +80,8 @@ org.glassfish.main.admin admin-cli ${project.version} - + + org.glassfish.main.core glassfish ${project.version} @@ -138,18 +139,5 @@ - - - maven-jar-plugin - - - - true -+ ../../modules - - - - - diff --git a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/BackupCommands.java b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/BackupCommands.java index 93db55a57cf..39022d5c23c 100644 --- a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/BackupCommands.java +++ b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/BackupCommands.java @@ -19,7 +19,6 @@ import com.sun.enterprise.admin.servermgmt.cli.LocalDomainCommand; import com.sun.enterprise.backup.BackupRequest; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.util.ObjectAnalyzer; import java.io.File; @@ -28,6 +27,7 @@ import org.glassfish.api.Param; import org.glassfish.api.admin.CommandException; import org.glassfish.api.admin.CommandValidationException; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import static com.sun.enterprise.util.Utility.isEmpty; import static com.sun.enterprise.util.io.DomainDirs.getDefaultDomainsDir; diff --git a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/BackupDomainCommand.java b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/BackupDomainCommand.java index 07758abaa21..8b3901e62ee 100644 --- a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/BackupDomainCommand.java +++ b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/BackupDomainCommand.java @@ -21,7 +21,6 @@ import com.sun.enterprise.backup.BackupException; import com.sun.enterprise.backup.BackupManager; import com.sun.enterprise.backup.BackupWarningException; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.universal.process.ProcessUtils; import com.sun.enterprise.util.ObjectAnalyzer; @@ -30,6 +29,7 @@ import org.glassfish.api.Param; import org.glassfish.api.admin.CommandException; import org.glassfish.hk2.api.PerLookup; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import org.jvnet.hk2.annotations.Service; /** diff --git a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DatabaseCommand.java b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DatabaseCommand.java index 1e705e0e588..7d9614edc29 100644 --- a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DatabaseCommand.java +++ b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DatabaseCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Contributors to the Eclipse Foundation + * Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -19,7 +19,6 @@ import com.sun.enterprise.admin.cli.CLICommand; import com.sun.enterprise.admin.cli.ClassPathBuilder; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.util.OS; import java.io.File; @@ -27,8 +26,9 @@ import org.glassfish.api.Param; import org.glassfish.api.admin.CommandException; import org.glassfish.api.admin.CommandValidationException; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; -import static com.sun.enterprise.util.SystemPropertyConstants.DERBY_ROOT_PROPERTY; +import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.DERBY_ROOT_PROP_NAME; import static com.sun.enterprise.util.SystemPropertyConstants.INSTALL_ROOT_PROPERTY; import static com.sun.enterprise.util.SystemPropertyConstants.JAVA_ROOT_PROPERTY; @@ -55,6 +55,7 @@ public abstract class DatabaseCommand extends CLICommand { @Param(name = "dbport", optional = true, defaultValue = DB_PORT_DEFAULT) protected String dbPort; + protected final ClassPathBuilder modulepath = new ClassPathBuilder(); protected final ClassPathBuilder sClasspath = new ClassPathBuilder(); protected final ClassPathBuilder sDatabaseClasspath = new ClassPathBuilder(); @@ -77,10 +78,11 @@ protected void prepareProcessExecutor() throws Exception { } javaHome = new File(getSystemProperty(JAVA_ROOT_PROPERTY)); - dbLocation = new File(getSystemProperty(DERBY_ROOT_PROPERTY)); + dbLocation = new File(getSystemProperty(DERBY_ROOT_PROP_NAME)); checkIfDbInstalled(dbLocation); - sClasspath.add(new File(installRoot, "lib/asadmin/cli-optional.jar")); + modulepath.addAll(new File(installRoot, "lib/bootstrap"), f -> f.isFile()); + sClasspath.add(new File(installRoot, System.getProperty("java.class.path"))); sDatabaseClasspath.add(dbLocation, "lib", "derby.jar") .add(dbLocation, "lib", "derbyshared.jar") .add(dbLocation, "lib", "derbytools.jar") @@ -133,22 +135,28 @@ protected String[] pingDatabaseCmd(boolean bRedirect) throws Exception { getJavaExe().toString(), "-Djava.library.path=" + installRoot + File.separator + "lib", "-Dderby.storage.fileSyncTransactionLog=True", + "--module-path", + modulepath.toString(), + "--add-modules", + "ALL-MODULE-PATH", "-cp", sClasspath + File.pathSeparator + sDatabaseClasspath, - "com.sun.enterprise.admin.cli.optional.DerbyControl", "ping", - dbHost, dbPort, Boolean.valueOf(bRedirect).toString() }; + dbHost, dbPort, Boolean.toString(bRedirect) }; } return new String[] { getJavaExe().toString(), "-Djava.library.path=" + installRoot + File.separator + "lib", + "--module-path", + modulepath.toString(), + "--add-modules", + "ALL-MODULE-PATH", "-cp", sClasspath + File.pathSeparator + sDatabaseClasspath, - "com.sun.enterprise.admin.cli.optional.DerbyControl", "ping", - dbHost, dbPort, Boolean.valueOf(bRedirect).toString() }; + dbHost, dbPort, Boolean.toString(bRedirect) }; } /** diff --git a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/ListBackupsCommand.java b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/ListBackupsCommand.java index 461ced23840..882243e5037 100644 --- a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/ListBackupsCommand.java +++ b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/ListBackupsCommand.java @@ -20,13 +20,13 @@ import com.sun.enterprise.backup.BackupException; import com.sun.enterprise.backup.BackupWarningException; import com.sun.enterprise.backup.ListManager; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.util.ObjectAnalyzer; import java.io.File; import org.glassfish.api.admin.CommandException; import org.glassfish.hk2.api.PerLookup; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import org.jvnet.hk2.annotations.Service; /** diff --git a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/RestoreDomainCommand.java b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/RestoreDomainCommand.java index cc81a25f2a9..febc08953cc 100644 --- a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/RestoreDomainCommand.java +++ b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/RestoreDomainCommand.java @@ -21,7 +21,6 @@ import com.sun.enterprise.backup.BackupRequest; import com.sun.enterprise.backup.BackupWarningException; import com.sun.enterprise.backup.RestoreManager; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.universal.process.ProcessUtils; import com.sun.enterprise.util.ObjectAnalyzer; @@ -32,6 +31,7 @@ import org.glassfish.api.admin.CommandException; import org.glassfish.api.admin.CommandValidationException; import org.glassfish.hk2.api.PerLookup; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import org.jvnet.hk2.annotations.Service; import static com.sun.enterprise.util.Utility.isAllNull; diff --git a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/StartDatabaseCommand.java b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/StartDatabaseCommand.java index e89eb92fda3..d9910d30a87 100644 --- a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/StartDatabaseCommand.java +++ b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/StartDatabaseCommand.java @@ -18,7 +18,6 @@ import com.sun.enterprise.admin.cli.CLIProcessExecutor; import com.sun.enterprise.universal.glassfish.GFLauncherUtils; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.util.OS; import java.io.File; @@ -30,6 +29,7 @@ import org.glassfish.api.admin.CommandException; import org.glassfish.api.admin.CommandValidationException; import org.glassfish.hk2.api.PerLookup; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import org.jvnet.hk2.annotations.Service; import static com.sun.enterprise.admin.cli.optional.DerbyControl.DB_LOG_FILENAME; @@ -92,6 +92,11 @@ public String[] startDatabaseCmd() { cmd.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:9011"); } + cmd.add("--module-path"); + cmd.add(modulepath.toString()); + cmd.add("--add-modules"); + cmd.add("ALL-MODULE-PATH"); + cmd.add("-cp"); cmd.add(sClasspath + pathSeparator + sDatabaseClasspath); if (jvmoptions != null) { @@ -117,8 +122,11 @@ public String[] sysinfoCmd() throws Exception { javaHome + separator + "bin" + separator + "java", "-Djava.library.path=" + installRoot + separator + "lib", "-Dderby.storage.fileSyncTransactionLog=True", + "--module-path", + modulepath.toString(), + "--add-modules", + "ALL-MODULE-PATH", "-cp", sClasspath + pathSeparator + sDatabaseClasspath, - "com.sun.enterprise.admin.cli.optional.DerbyControl", "sysinfo", dbHost, dbPort, "false" }; @@ -127,8 +135,11 @@ public String[] sysinfoCmd() throws Exception { return new String[] { javaHome + separator + "bin" + separator + "java", "-Djava.library.path=" + installRoot + separator + "lib", + "--module-path", + modulepath.toString(), + "--add-modules", + "ALL-MODULE-PATH", "-cp", sClasspath + pathSeparator + sDatabaseClasspath, - "com.sun.enterprise.admin.cli.optional.DerbyControl", "sysinfo", dbHost, dbPort, "false" }; @@ -144,6 +155,11 @@ public String[] executeSQLCmd() throws Exception { cmd.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:9012"); } + cmd.add("--module-path"); + cmd.add(modulepath.toString()); + cmd.add("--add-modules"); + cmd.add("ALL-MODULE-PATH"); + cmd.add("-cp"); cmd.add(sClasspath + pathSeparator + sDatabaseClasspath); @@ -158,7 +174,7 @@ public String[] executeSQLCmd() throws Exception { cmd.add(dbPassword); } - return cmd.toArray(new String[cmd.size()]); + return cmd.toArray(String[]::new); } /** diff --git a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/StopDatabaseCommand.java b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/StopDatabaseCommand.java index b25765cb0ab..ae05ed152e7 100644 --- a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/StopDatabaseCommand.java +++ b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/StopDatabaseCommand.java @@ -19,7 +19,6 @@ import com.sun.enterprise.admin.cli.CLIProcessExecutor; import com.sun.enterprise.admin.cli.Environment; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.util.OS; import java.io.File; @@ -29,6 +28,7 @@ import org.glassfish.api.admin.CommandException; import org.glassfish.api.admin.CommandValidationException; import org.glassfish.hk2.api.PerLookup; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import org.jvnet.hk2.annotations.Service; import static com.sun.enterprise.admin.cli.CLIUtil.readPasswordFileOptions; @@ -81,8 +81,11 @@ public String[] stopDatabaseCmd() throws Exception { javaHome + separator + "bin" + separator + "java", "-Djava.library.path=" + installRoot + separator + "lib", "-Dderby.storage.fileSyncTransactionLog=True", + "--module-path", + modulepath.toString(), + "--add-modules", + "ALL-MODULE-PATH", "-cp", sClasspath + pathSeparator + sDatabaseClasspath, - "com.sun.enterprise.admin.cli.optional.DerbyControl", "shutdown", dbHost, dbPort, "false" }; @@ -91,8 +94,11 @@ public String[] stopDatabaseCmd() throws Exception { return new String[] { javaHome + separator + "bin" + separator + "java", "-Djava.library.path=" + installRoot + separator + "lib", + "--module-path", + modulepath.toString(), + "--add-modules", + "ALL-MODULE-PATH", "-cp", sClasspath + pathSeparator + sDatabaseClasspath, - "com.sun.enterprise.admin.cli.optional.DerbyControl", "shutdown", dbHost, dbPort, "false" }; @@ -100,10 +106,13 @@ public String[] stopDatabaseCmd() throws Exception { if (OS.isDarwin()) { return new String[] { javaHome + separator + "bin" + separator + "java", - "-Djava.library.path=" + installRoot + separator + - "lib", "-Dderby.storage.fileSyncTransactionLog=True", + "-Djava.library.path=" + installRoot + separator + "lib", + "-Dderby.storage.fileSyncTransactionLog=True", + "--module-path", + modulepath.toString(), + "--add-modules", + "ALL-MODULE-PATH", "-cp", sClasspath + pathSeparator + sDatabaseClasspath, - "com.sun.enterprise.admin.cli.optional.DerbyControl", "shutdown", dbHost, dbPort, "false", dbUser, dbPassword }; @@ -112,8 +121,11 @@ public String[] stopDatabaseCmd() throws Exception { return new String[] { javaHome + separator + "bin" + separator + "java", "-Djava.library.path=" + installRoot + separator + "lib", + "--module-path", + modulepath.toString(), + "--add-modules", + "ALL-MODULE-PATH", "-cp", sClasspath + pathSeparator + sDatabaseClasspath, - "com.sun.enterprise.admin.cli.optional.DerbyControl", "shutdown", dbHost, dbPort, "false", dbUser, dbPassword }; diff --git a/appserver/admin/cli/pom.xml b/appserver/admin/cli/pom.xml index 6a1157fea28..6d7c86494fe 100755 --- a/appserver/admin/cli/pom.xml +++ b/appserver/admin/cli/pom.xml @@ -47,7 +47,7 @@ org.glassfish.main.admin admin-cli - ${project.parent.version} + ${project.version} @@ -59,12 +59,7 @@ org.glassfish.admin.cli.AsadminMain - true - ../../modules - - ../../lib/bootstrap/glassfish-jul-extension.jar - diff --git a/appserver/admin/cli/src/main/java/org/glassfish/admin/cli/AsadminMain.java b/appserver/admin/cli/src/main/java/org/glassfish/admin/cli/AsadminMain.java index d38d2572875..f200e8d50b2 100644 --- a/appserver/admin/cli/src/main/java/org/glassfish/admin/cli/AsadminMain.java +++ b/appserver/admin/cli/src/main/java/org/glassfish/admin/cli/AsadminMain.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation. * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -29,13 +30,17 @@ public static void main(String[] args) { // Metrix.event("START"); Environment.setPrefix("AS_ADMIN_"); Environment.setShortPrefix("AS_"); - int code = new AsadminMain().doMain(args); + + AsadminMain main = new AsadminMain(); + int code = main.doMain(args); // Metrix.event("DONE"); // System.out.println("METRIX:"); // System.out.println(Metrix.getInstance().toString()); System.exit(code); } + + @Override protected String getCommandName() { return "asadmin"; } diff --git a/appserver/admin/template/src/main/resources/config/domain.xml b/appserver/admin/template/src/main/resources/config/domain.xml index b29c5e4500e..05fa87e7db3 100644 --- a/appserver/admin/template/src/main/resources/config/domain.xml +++ b/appserver/admin/template/src/main/resources/config/domain.xml @@ -157,6 +157,8 @@ + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -Djdk.corba.allowOutputStreamSubclass=true -Djdk.tls.rejectClientInitiatedRenegotiation=true @@ -220,7 +222,7 @@ --add-exports=java.naming/com.sun.jndi.ldap=ALL-UNNAMED --add-exports=java.base/jdk.internal.vm.annotation=ALL-UNNAMED --add-opens=java.base/jdk.internal.vm.annotation=ALL-UNNAMED - + -Djdk.attach.allowAttachSelf=true @@ -358,7 +360,8 @@ - -server + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -Djdk.corba.allowOutputStreamSubclass=true -Djdk.tls.rejectClientInitiatedRenegotiation=true diff --git a/appserver/appclient/client/acc-standalone/pom.xml b/appserver/appclient/client/acc-standalone/pom.xml index 0218caad3ce..04cc28900c8 100755 --- a/appserver/appclient/client/acc-standalone/pom.xml +++ b/appserver/appclient/client/acc-standalone/pom.xml @@ -17,14 +17,15 @@ --> - + 4.0.0 org.glassfish.main.appclient client 7.0.21-SNAPSHOT - ../pom.xml gf-client @@ -35,9 +36,9 @@ This module builds the free-standing JAR file for the app client container which can be run without using an OSGi implementation. - This module contains little source of its own but mostly packages a JAR - with a manifest Class-Path that specifies all the OSGi JARs on which - it directly or indirectly depends. + However it still depends on many of jars in the modules directory. + The class loader hierarchy tries to reduce efforts required to run + the Application Client especially related to the classpath. @@ -53,63 +54,16 @@ - - ../lib - ${path.lib}/install/applications - ${path.lib}/appclient - ../../javadb/lib - ../../mq/lib - - ${path.derby}/derby.jar ${path.derby}/derbyclient.jar ${path.derby}/derbynet.jar ${path.derby}/derbytools.jar ${path.derby}/derbyrun.jar - ${path.apps}/jaxr-ra/jaxr-ra.jar - ${path.apps}/__ds_jdbc_ra/jdbc-ra-ds.jar ${path.apps}/__cp_jdbc_ra/jdbc-ra-cp.jar ${path.apps}/__xa_jdbc_ra/jdbc-ra-xa.jar ${path.apps}/__dm_jdbc_ra/jdbc-ra-dm.jar - ${path.mq}/imq.jar ${path.mq}/imqadmin.jar ${path.mq}/imqutil.jar ${path.mq}/fscontext.jar ${path.apps}/jmsra/imqjmsra.jar - ${path.appclient}/weld-se-shaded.jar - - ${path.lib}/bootstrap/glassfish-jul-extension.jar ${classpath.mq} ${classpath.derby} ${classpath.jaxrra} ${classpath.jdbcra} ${classpath.weld} - - - - - org.glassfish.main.appclient - gf-client-module - ${project.version} - - - org.jboss.weld.se - weld-se-shaded - - - - org.glassfish.main.jdbc - jdbc-runtime - ${project.version} - true - - - org.glassfish.main.resources - resources-runtime - ${project.version} - true + org.junit.jupiter + junit-jupiter-engine - org.glassfish.main.persistence - entitybean-container + org.glassfish.main.common + simple-glassfish-api ${project.version} - true - - - org.jboss.weld - weld-osgi-bundle - - - * - * - - - true + provided @@ -133,16 +87,11 @@ org.glassfish.appclient.client.AppClientFacade org.glassfish.appclient.client.acc - true - ../modules/ - custom - ${artifact.artifactId}${dashClassifier?}.${artifact.extension} ${project.build.outputDirectory}/META-INF/MANIFEST.MF org.glassfish.appclient.client.acc.agent.AppClientContainerAgent true - ${classpath.additions} diff --git a/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/ACCAgentClassLoader.java b/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/ACCAgentClassLoader.java index 921f73eb144..124441e70c7 100644 --- a/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/ACCAgentClassLoader.java +++ b/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/ACCAgentClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -18,17 +18,10 @@ package org.glassfish.appclient.client.acc.agent; import java.io.File; -import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.net.URLStreamHandlerFactory; -import java.security.PrivilegedAction; -import java.util.Enumeration; - -import org.glassfish.appclient.common.ClassPathUtils; - -import static java.security.AccessController.doPrivileged; +import java.util.Arrays; /** * Used as the system class loader during app client launch. @@ -40,75 +33,51 @@ *

* This class and it's dependencies must not use logging, which could cause recursion in class * loading. So don't extend GlassfishUrlClassLoader. Reproducer: TCK tests use this classloader. + *

+ * The name of this class must not be changed - it is explicitly used in the TCK Platform Test + * package. * * @author tjquinn + * @author David Matejcek */ public class ACCAgentClassLoader extends URLClassLoader { - private boolean isActive = true; + static { + registerAsParallelCapable(); + } /** - * This constructor is used by the VM to create a system class loader (as specified by -Djava.system.class.loader on the - * java command created from the appclient script). + * This constructor is used by the VM to create a system class loader (as specified by + * -Djava.system.class.loader on the java command created from the appclient script). + *

+ * This class loader ignores the parent and uses {@link GFDependenciesClassLoader} + * with the {@link ClassLoader#getPlatformClassLoader()} as its parent instead. */ public ACCAgentClassLoader(ClassLoader parent) { - super(new URL[] {}, prepareLoader(parent)); - } - - - private static URLClassLoader prepareLoader(ClassLoader parent) { - PrivilegedAction action = () -> new URLClassLoader( - new URL[] {ClassPathUtils.getGFClientJarURL()}, new ClassLoaderWrapper(parent)); - return doPrivileged(action); - } - - - public ACCAgentClassLoader(URL[] urls) { - super(urls); - } - - public ACCAgentClassLoader(URL[] urls, ClassLoader parent) { - super(urls, new ClassLoaderWrapper(parent)); - } - - public ACCAgentClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) { - super(urls, parent, factory); + super("Agent", new URL[0], new UserClassLoader()); } - // a custom system class loader need to define this method in order to load the java agent. + /** + * A custom system class loader need to define this method in order to load the java agent. + * + * @param path + * @throws MalformedURLException + */ public void appendToClassPathForInstrumentation(String path) throws MalformedURLException { addURL(new File(path).toURI().toURL()); } + /** + * Returns class name, hash code and list of managed urls and info about parent. + */ @Override - public synchronized Class loadClass(String name) throws ClassNotFoundException { - if (isActive && isStillActive()) { - return super.loadClass(name); - } - return getParent().loadClass(name); - } - - @Override - public URL getResource(String name) { - if (isActive && isStillActive()) { - return super.getResource(name); - } - return getParent().getResource(name); - } - - @Override - public Enumeration getResources(String name) throws IOException { - if (isActive && isStillActive()) { - return super.getResources(name); - } - return getParent().getResources(name); - } - - private boolean isStillActive() { - if (isActive) { - String propValue = System.getProperty("org.glassfish.appclient.acc.agentLoaderDone"); - isActive = (propValue != null); - } - return isActive; + public String toString() { + final StringBuilder text = new StringBuilder(1024); + text.append(getClass().getName()).append('@').append(Integer.toHexString(hashCode())); + text.append("[name=").append(getName()).append("], urls=[\n"); + Arrays.stream(getURLs()).forEach(u -> text.append(u).append('\n')); + text.append(']'); + text.append(", parent=").append(getParent()); + return text.toString(); } } diff --git a/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/AppClientContainerAgent.java b/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/AppClientContainerAgent.java index 4259952c059..330040430c6 100644 --- a/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/AppClientContainerAgent.java +++ b/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/AppClientContainerAgent.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -18,17 +19,16 @@ import java.io.File; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; -import java.io.LineNumberReader; import java.lang.instrument.Instrumentation; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.logging.Logger; -import org.glassfish.appclient.client.AppClientFacade; -import org.glassfish.appclient.client.acc.UserError; - import static java.util.logging.Level.FINE; -import static org.glassfish.appclient.client.CLIBootstrap.FILE_OPTIONS_INTRODUCER; +import static org.glassfish.appclient.client.acc.agent.CLIBootstrap.FILE_OPTIONS_INTRODUCER; /** * Agent which prepares the ACC before the VM launches the selected main program. @@ -48,26 +48,29 @@ */ public class AppClientContainerAgent { - private static Logger logger = Logger.getLogger(AppClientContainerAgent.class.getName()); + private static final Logger LOG = Logger.getLogger(AppClientContainerAgent.class.getName()); public static void premain(String agentArgsText, Instrumentation instrumentation) { + ClassLoader loader = ClassLoader.getSystemClassLoader().getParent(); try { long now = System.currentTimeMillis(); - /* - * The agent prepares the ACC but does not launch the client. - */ - AppClientFacade.prepareACC(optionsValue(agentArgsText), instrumentation); - - logger.fine("AppClientContainerAgent finished after " + (System.currentTimeMillis() - now) + " ms"); - - } catch (UserError ue) { - ue.displayAndExit(); - } catch (Exception e) { + // The agent prepares the ACC but does not launch the client. + // The thread class loader is used in init method. + Thread.currentThread().setContextClassLoader(loader); + Class containerInitClass = loader.loadClass("org.glassfish.appclient.client.AppClientContainerHolder"); + Method initContainer = containerInitClass.getMethod("init", String.class, Instrumentation.class); + try { + initContainer.invoke(null, optionsValue(agentArgsText), instrumentation); + } catch (InvocationTargetException e) { + throw e.getCause(); + } + + LOG.fine("AppClientContainerAgent finished after " + (System.currentTimeMillis() - now) + " ms"); + } catch (Throwable e) { e.printStackTrace(); System.exit(1); } - } private static String optionsValue(final String agentArgsText) throws FileNotFoundException, IOException { @@ -79,19 +82,14 @@ private static String optionsValue(final String agentArgsText) throws FileNotFou return agentArgsText; } - File argsFile = new File(agentArgsText.substring(FILE_OPTIONS_INTRODUCER.length())); - String result; - - try (LineNumberReader reader = new LineNumberReader(new FileReader(argsFile))) { - result = reader.readLine(); - } + final Path argsFile = new File(agentArgsText.substring(FILE_OPTIONS_INTRODUCER.length())).toPath(); + final String result = Files.readString(argsFile).trim(); if (Boolean.getBoolean("keep.argsfile")) { - System.err.println("Agent arguments file retained: " + argsFile.getAbsolutePath()); - } else if (!argsFile.delete()) { - logger.log(FINE, "Unable to delete temporary args file {0}; continuing", argsFile.getAbsolutePath()); + System.err.println("Agent arguments file retained: " + argsFile); + } else if (!Files.deleteIfExists(argsFile)) { + LOG.log(FINE, "Unable to delete temporary args file {0}; continuing", argsFile); } - return result; } } diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/CLIBootstrap.java b/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/CLIBootstrap.java similarity index 86% rename from appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/CLIBootstrap.java rename to appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/CLIBootstrap.java index 2b4a0e15978..932c68cbc6f 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/CLIBootstrap.java +++ b/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/CLIBootstrap.java @@ -1,6 +1,6 @@ /* + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2022 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -15,23 +15,19 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package org.glassfish.appclient.client; - -import com.sun.enterprise.util.OS; +package org.glassfish.appclient.client.acc.agent; import java.io.File; import java.io.IOException; import java.io.PrintStream; -import java.net.URL; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.glassfish.appclient.client.acc.UserError; -import org.glassfish.appclient.common.ClassPathUtils; +import org.glassfish.embeddable.client.ApplicationClientCLIEncoding; +import org.glassfish.embeddable.client.UserError; import static java.lang.System.arraycopy; @@ -69,9 +65,9 @@ */ public class CLIBootstrap { + private static final boolean IS_WINDOWS = System.getProperty("os.name", "generic").startsWith("Win"); public final static String FILE_OPTIONS_INTRODUCER = "argsfile="; - private final static String COMMA_IN_ARG_PLACEHOLDER = "+-+-+-+"; private final static boolean isDebug = System.getenv("AS_DEBUG") != null; private final static String INPUT_ARGS = System.getenv("inputArgs"); @@ -81,9 +77,9 @@ public class CLIBootstrap { private final static String INSTALL_ROOT_PROPERTY_EXPR = "-Dcom.sun.aas.installRoot="; private final static String SECURITY_POLICY_PROPERTY_EXPR = "-Djava.security.policy="; private final static String SECURITY_AUTH_LOGIN_CONFIG_PROPERTY_EXPR = "-Djava.security.auth.login.config="; - private final static String SYSTEM_CLASS_LOADER_PROPERTY_EXPR = "-Djava.system.class.loader=org.glassfish.appclient.client.acc.agent.ACCAgentClassLoader"; + private final static String SYSPROP_SYSTEM_CLASS_LOADER = "-Djava.system.class.loader="; - private final static String[] ENV_VARS = { "_AS_INSTALL", "APPCPATH", "VMARGS" }; + private final static String[] ENV_VARS = { "AS_INSTALL", "APPCPATH", "VMARGS" }; private JavaInfo java = new JavaInfo(); private GlassFishInfo gfInfo = new GlassFishInfo(); @@ -170,8 +166,6 @@ public static void main(String[] args) { } catch (Exception ex) { ex.printStackTrace(); System.exit(1); - } catch (UserError ue) { - ue.displayAndExit(); } } @@ -216,7 +210,7 @@ private static String[] convertInputArgsVariable(String inputArgs) { // #### Instance methods - CLIBootstrap() throws UserError { + CLIBootstrap() throws Error { } @@ -231,7 +225,7 @@ JavaInfo initJava() { * @param args * @throws UserError */ - private String run(String[] args) throws UserError { + private String run(String[] args) throws Error { java = new JavaInfo(); gfInfo = new GlassFishInfo(); @@ -252,7 +246,7 @@ private String run(String[] args) throws UserError { } } if (!isMatched) { - throw new UserError("arg " + i + " = " + augmentedArgs[i] + " not recognized"); + throw new Error("arg " + i + " = " + augmentedArgs[i] + " not recognized"); } } @@ -287,21 +281,22 @@ private String run(String[] args) throws UserError { * @param command */ private void addProperties(final StringBuilder command) { - command.append(' ').append("-Dorg.glassfish.gmbal.no.multipleUpperBoundsException=true"); + final Path gfBootstrapLibs = gfInfo.lib.toPath().resolve("bootstrap").normalize(); + command.append(' ').append("--module-path ").append(quote(gfBootstrapLibs.toString())); + command.append(' ').append("--add-modules ALL-MODULE-PATH"); command.append(' ').append("--add-opens=java.base/java.lang=ALL-UNNAMED"); + command.append(' ').append("-Xshare:off"); + command.append(' ').append(SYSPROP_SYSTEM_CLASS_LOADER).append("org.glassfish.appclient.client.acc.agent.ACCAgentClassLoader"); command.append(' ').append(INSTALL_ROOT_PROPERTY_EXPR).append(quote(gfInfo.home().getAbsolutePath())); + command.append(' ').append("-Dorg.glassfish.gmbal.no.multipleUpperBoundsException=true"); command.append(' ').append(SECURITY_POLICY_PROPERTY_EXPR).append(quote(gfInfo.securityPolicy().getAbsolutePath())); - command.append(' ').append("-classpath").append(' ').append(gfInfo.agentJarPath()).append(File.pathSeparatorChar).append('.'); - command.append(' ').append(SYSTEM_CLASS_LOADER_PROPERTY_EXPR); - command.append(' ').append("-Xshare:off"); command.append(' ').append(SECURITY_AUTH_LOGIN_CONFIG_PROPERTY_EXPR).append(quote(gfInfo.loginConfig().getAbsolutePath())); } /** * Adds the -javaagent option to the command line. - * */ - private void addAgentOption() throws UserError { + private void addAgentOption() throws Error { otherJVMOptions.processValue(new String[] { "-javaagent:" + quote(gfInfo.agentJarPath()) + agentOptionsFromFile() }, 0); } @@ -340,7 +335,7 @@ private static String quote(String string) { * @return */ private static String quoteSuppressTokenSubst(String string) { - return (OS.isWindows() ? quote(string) : quote(string.replace("$", "\\$"))); + return IS_WINDOWS ? quote(string) : quote(string.replace("$", "\\$")); } /** @@ -350,33 +345,12 @@ private static String quoteSuppressTokenSubst(String string) { * @return */ static String quoteEscapedArgument(String string) { - if (!OS.isWindows()) { + if (!IS_WINDOWS) { string = string.replace("\\", "\\\\").replace("\"", "\\\"").replace("$", "\\$").replace("`", "\\`"); } return "\"" + string + "\""; } - /** - * Replaces commas in an argument value (which can confuse the ACC agent argument parsing because shells strip out - * double-quotes) with a special sequence. - * - * @param string string to encode - * @return encoded string - */ - public static String encodeArg(String string) { - return string.replace(",", COMMA_IN_ARG_PLACEHOLDER); - } - - /** - * Replaces occurrences of comma encoding with commas. - * - * @param string possibly encoded string - * @return decoded string - */ - public static String decodeArg(String string) { - return string.replace(COMMA_IN_ARG_PLACEHOLDER, ","); - } - /** * Manages the arguments which will be passed to the ACC Java agent. @@ -407,7 +381,7 @@ final void add(String item) { * @param accArg */ final void addACCArg(String accArg) { - add("arg=" + encodeArg(accArg)); + add("arg=" + ApplicationClientCLIEncoding.encodeArg(accArg)); } @Override @@ -427,7 +401,6 @@ public String toString() { private class CommandLineElement { private final Pattern pattern; - Matcher matcher; private final Pattern whiteSpacePattern = Pattern.compile("[\\r\\n]"); @@ -443,7 +416,7 @@ private class CommandLineElement { } final boolean matchesPattern(String element) { - matcher = pattern.matcher(element); + Matcher matcher = pattern.matcher(element); return matcher.matches(); } @@ -462,7 +435,7 @@ boolean matches(String element) { * @throws UserError if the user specified an option that requires a value but provided no value (either the next * command line element is another option or there is no next element) */ - int processValue(String[] args, int slot) throws UserError { + int processValue(String[] args, int slot) throws Error { // Ignore an argument that is just unquoted white space. Matcher matcher = whiteSpacePattern.matcher(args[slot]); if (!matcher.matches()) { @@ -493,9 +466,9 @@ boolean isNextArg(String[] args, int currentSlot) { * @param currentSlot * @throws UserError */ - void ensureNonOptionNextArg(final String[] args, final int currentSlot) throws UserError { + void ensureNonOptionNextArg(final String[] args, final int currentSlot) throws Error { if ((currentSlot >= args.length - 1) || (args[currentSlot + 1].charAt(0) == '-')) { - throw new UserError("Command line element " + args[currentSlot] + " requires non-option value"); + throw new Error("Command line element " + args[currentSlot] + " requires non-option value"); } } @@ -602,7 +575,7 @@ class OptionValue { } @Override - int processValue(String[] args, int slot) throws UserError { + int processValue(String[] args, int slot) throws Error { ensureNonOptionNextArg(args, slot); optValues.add(new OptionValue(args[slot++], args[slot++])); @@ -639,7 +612,7 @@ boolean matches(final String element) { } @Override - int processValue(String[] args, int slot) throws UserError { + int processValue(String[] args, int slot) throws Error { final int result = super.processValue(args, slot); final OptionValue newOptionValue = optValues.get(optValues.size() - 1); agentArgs.addACCArg(newOptionValue.option); @@ -676,7 +649,7 @@ boolean matches(final String element) { } @Override - int processValue(String[] args, int slot) throws UserError { + int processValue(String[] args, int slot) throws Error { final int result = super.processValue(args, slot); agentArgs.addACCArg(values.get(values.size() - 1)); return result; @@ -741,7 +714,7 @@ boolean matches(String element) { private class JVMMainOption extends CommandLineElement { private static final String JVM_MAIN_PATTERN = "-jar|-client|[^-][^\\s]*"; - private String introducer = null; + private String introducer; JVMMainOption() { super(JVM_MAIN_PATTERN); @@ -769,69 +742,66 @@ boolean matches(String element) { } @Override - int processValue(String[] args, int slot) throws UserError { + int processValue(String[] args, int slot) throws Error { // We only care about the most recent setting. values.clear(); - // If arg[slot] is -jar or -client we expect the next value to be the file. Make sure there is a next item and that it + // If arg[slot] is -jar or -client we expect the next value to be the file. + // Make sure there is a next item and that it if (args[slot].charAt(0) != '-') { - // This must be a main class specified on the command line. + values.add("-classpath"); + values.add(gfInfo.agentJarPath() + File.pathSeparatorChar + + ClassPathUtils.getClassPathForGfClient(".")); final int result = super.processValue(args, slot); - agentArgs.add("client=class=" + values.get(values.size() - 1)); + String className = values.get(values.size() - 1); + agentArgs.add("client=class=" + className); return result; } if (!nextLooksOK(args, slot)) { - throw new UserError("-jar or -client requires value but missing"); + throw new Error("-jar or -client requires value but missing"); } introducer = args[slot++]; final int result = super.processValue(args, slot); - final String clientJarPath = values.get(values.size() - 1); + final String clientJarPath = values.remove(values.size() - 1); final File clientJarFile = new File(clientJarPath); if (clientJarFile.isDirectory()) { - // Record in the agent args that the user is launching a directory. Set the main class launch info to launch the ACC JAR. + // Record in the agent args that the user is launching a directory. + // Set the main class launch info to launch the ACC JAR. agentArgs.add("client=dir=" + quote(clientJarFile.getAbsolutePath())); introducer = "-jar"; - values.set(values.size() - 1, gfInfo.agentJarPath()); + values.add(gfInfo.agentJarPath()); } else { agentArgs.add("client=jar=" + quote(clientJarPath)); - // The client path is not a directory. It should be a .jar or a .ear file. If an EAR, then we want Java to launch - // our ACC jar. If a JAR, then we will launch that JAR. + // The client path is not a directory. It should be a .jar or a .ear file. + // If an EAR, then we want Java to launch our ACC jar. + // If a JAR, then we will launch that JAR. if (clientJarPath.endsWith(".ear")) { introducer = "-jar"; - values.set(values.size() - 1, gfInfo.agentJarPath()); + values.add(gfInfo.agentJarPath()); } else if (clientJarPath.endsWith(".jar")) { introducer = null; - values.set(values.size() - 1, "-classpath"); - values.add(gfInfo.agentJarPath() + File.pathSeparatorChar + getClassPathForGfClient(clientJarPath)); + values.add("-classpath"); + values.add(gfInfo.agentJarPath() + File.pathSeparatorChar + + ClassPathUtils.getClassPathForGfClient(clientJarPath)); String mainClass = ClassPathUtils.getMainClass(clientJarFile); values.add(mainClass == null ? "" : mainClass); + } else { + throw new Error("Unexpected client: " + clientJarPath); } } return result; } - private String getClassPathForGfClient(String clientJarPath) { - URL[] classpath = ClassPathUtils.getJavaClassPathForAppClient(); - if (classpath.length == 0) { - return clientJarPath; - } - return clientJarPath + File.pathSeparator + Stream.of(classpath).map(ClassPathUtils::convertToString) - .collect(Collectors.joining(File.pathSeparator)); - } - - @Override boolean format(final StringBuilder commandLine) { - if (introducer != null) { - /* - * In the generated command we always use "-jar" to indicate the JAR to be launched, even if the user specified - * "-client" on the appclient command line. - */ - super.format(commandLine, false /* useQuotes */, "-jar"); - return super.format(commandLine, true /* useQuotes */); + if (introducer == null) { + return super.format(commandLine, false /* useQuotes */); } - return super.format(commandLine, false /* useQuotes */); + // In the generated command we always use "-jar" to indicate the JAR to be launched, + // even if the user specified "-client" on the appclient command line. + super.format(commandLine, false /* useQuotes */, introducer); + return super.format(commandLine, true /* useQuotes */); } private boolean nextLooksOK(final String[] args, final int slot) { @@ -857,17 +827,16 @@ private String agentOptionsFromFile() { private File fileContainingAgentArgs() throws IOException { File argsFile = File.createTempFile("acc", ".dat"); - PrintStream ps = new PrintStream(argsFile); - ps.println(agentArgs.toString()); - ps.close(); - + try (PrintStream ps = new PrintStream(argsFile)) { + ps.println(agentArgs.toString()); + } return argsFile; } /** * Encapsulates information about the GlassFish installation, mostly useful directories within the installation. *

- * Note that we use the property acc._AS_INSTALL to find the installation. + * Note that we use the property acc.AS_INSTALL to find the installation. */ static class GlassFishInfo { @@ -878,14 +847,14 @@ static class GlassFishInfo { private static final String ACC_CONFIG_PREFIX = "domains/domain1/config"; GlassFishInfo() { - String asInstallPath = System.getProperty(ENV_VAR_PROP_PREFIX + "_AS_INSTALL"); - if (asInstallPath == null || asInstallPath.length() == 0) { - throw new IllegalArgumentException("_AS_INSTALL == null"); + String asInstallPath = System.getProperty(ENV_VAR_PROP_PREFIX + "AS_INSTALL"); + if (asInstallPath == null || asInstallPath.isEmpty()) { + throw new IllegalArgumentException("AS_INSTALL == null"); } - this.home = new File(asInstallPath); - modules = new File(home, "modules"); - lib = new File(home, "lib"); - libAppclient = new File(lib, "appclient"); + this.home = new File(asInstallPath).toPath().normalize().toFile(); + this.modules = new File(home, "modules"); + this.lib = new File(home, "lib"); + this.libAppclient = new File(lib, "appclient"); } File home() { @@ -900,6 +869,10 @@ File lib() { return lib; } + File libAppclient() { + return libAppclient; + } + File configxml() { /* * Try using glassfish-acc.xml. If that does not exist then the user might have done an in-place upgrade from an earlier @@ -1017,7 +990,7 @@ class UserVMArgs { private final List evElements = new ArrayList<>(); - UserVMArgs(String vmargs) throws UserError { + UserVMArgs(String vmargs) throws Error { if (isDebug) { System.err.println("VMARGS = " + (vmargs == null ? "null" : vmargs)); @@ -1042,7 +1015,7 @@ private void initEVCommandLineElements() { evElements.add(evOtherJVMOptions); } - private void processEVCommandLineElements(final String[] envVarJVMArgs) throws UserError { + private void processEVCommandLineElements(final String[] envVarJVMArgs) throws Error { /* * Process each command-line argument by the first CommandLineElement which matches the argument. */ @@ -1056,7 +1029,7 @@ private void processEVCommandLineElements(final String[] envVarJVMArgs) throws U } } if (!isMatched) { - throw new UserError("arg " + i + " = " + envVarJVMArgs[i] + " not recognized"); + throw new Error("arg " + i + " = " + envVarJVMArgs[i] + " not recognized"); } } } diff --git a/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/ClassLoaderWrapper.java b/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/ClassLoaderWrapper.java deleted file mode 100644 index cb3622453ab..00000000000 --- a/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/ClassLoaderWrapper.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2021 Contributors to the Eclipse Foundation. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.glassfish.appclient.client.acc.agent; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Enumeration; -import java.util.function.Consumer; -import java.util.function.Supplier; -import java.util.stream.Stream; - -public class ClassLoaderWrapper extends ClassLoader implements Supplier, Consumer { - - private ClassLoader wrapped; - - public ClassLoaderWrapper(ClassLoader wrapped) { - super(wrapped.getName(), wrapped); - this.wrapped = wrapped; - } - - public ClassLoader getWrapped() { - return this.wrapped; - } - - public void setWrapped(ClassLoader wrapped) { - this.wrapped = wrapped; - } - - public void accept(ClassLoader t) { - setWrapped(t); - } - - public ClassLoader get() { - return getWrapped(); - } - - public int hashCode() { - return this.wrapped.hashCode(); - } - - public boolean equals(Object obj) { - return this.wrapped.equals(obj); - } - - public String toString() { - return this.wrapped.toString(); - } - - public String getName() { - if (this.wrapped == null) { - return super.getName(); - } - - return this.wrapped.getName(); - } - - public Class loadClass(String name) throws ClassNotFoundException { - return this.wrapped.loadClass(name); - } - - public URL getResource(String name) { - return this.wrapped.getResource(name); - } - - public Enumeration getResources(String name) throws IOException { - return this.wrapped.getResources(name); - } - - public Stream resources(String name) { - return this.wrapped.resources(name); - } - - public InputStream getResourceAsStream(String name) { - return this.wrapped.getResourceAsStream(name); - } - - public void setDefaultAssertionStatus(boolean enabled) { - this.wrapped.setDefaultAssertionStatus(enabled); - } - - public void setPackageAssertionStatus(String packageName, boolean enabled) { - this.wrapped.setPackageAssertionStatus(packageName, enabled); - } - - public void setClassAssertionStatus(String className, boolean enabled) { - this.wrapped.setClassAssertionStatus(className, enabled); - } - - public void clearAssertionStatus() { - this.wrapped.clearAssertionStatus(); - } -} diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/common/ClassPathUtils.java b/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/ClassPathUtils.java similarity index 51% rename from appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/common/ClassPathUtils.java rename to appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/ClassPathUtils.java index f2249d20fc7..ea57abf412e 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/common/ClassPathUtils.java +++ b/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/ClassPathUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Eclipse Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -14,7 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package org.glassfish.appclient.common; +package org.glassfish.appclient.client.acc.agent; import java.io.File; import java.io.IOException; @@ -22,7 +22,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Path; -import java.security.CodeSource; import java.util.ArrayList; import java.util.List; import java.util.function.Function; @@ -30,6 +29,7 @@ import java.util.jar.JarFile; import java.util.jar.Manifest; import java.util.stream.Collectors; +import java.util.stream.Stream; import static java.util.Collections.emptyList; @@ -38,7 +38,7 @@ * * @author David Matejcek */ -public class ClassPathUtils { +final class ClassPathUtils { private static final Function TO_URL = p -> { try { @@ -48,20 +48,12 @@ public class ClassPathUtils { } }; - private static final Function TO_REAL_PATH = p -> { - try { - return p.toRealPath(); - } catch (IOException e) { - throw new IllegalStateException("Could not resolve real path of: " + p, e); - } - }; - /** * @param clientJarFile * @return Main-Class attributer of the manifest file. */ - public static String getMainClass(File clientJarFile) { + static String getMainClass(File clientJarFile) { try (JarFile jarFile = new JarFile(clientJarFile)) { Manifest manifest = jarFile.getManifest(); if (manifest == null) { @@ -75,71 +67,41 @@ public static String getMainClass(File clientJarFile) { } - /** - * @return java.class.path without gf-client.jar extended by env.APPCPATH. Never null. - */ - public static URL[] getJavaClassPathForAppClient() { - final Path gfClientJar = TO_REAL_PATH.apply(getGFClientJarPath()); - final List paths = convertClassPathToPaths(System.getProperty("java.class.path")); - final List result = new ArrayList<>(); - for (Path path : paths) { - if (!TO_REAL_PATH.apply(path).equals(gfClientJar)) { - result.add(TO_URL.apply(path)); - } + static String getClassPathForGfClient(String clientJarPath) { + URL[] classpath = getJavaClassPathForAppClient(); + if (classpath.length == 0) { + return clientJarPath; } - result.addAll(convertClassPathToURLs(System.getenv("APPCPATH"))); - return result.toArray(new URL[result.size()]); - } - - /** - * @return {@link URL} to the gf-client.jar - */ - public static URL getGFClientJarURL() { - return TO_URL.apply(getGFClientJarPath()); + return clientJarPath + File.pathSeparator + Stream.of(classpath).map(ClassPathUtils::convertToString) + .distinct().collect(Collectors.joining(File.pathSeparator)); } - /** - * @return {@link Path} to the gf-client.jar - */ - public static Path getGFClientJarPath() { - try { - Class clazz = Class.forName("org.glassfish.appclient.client.acc.agent.AppClientContainerAgent"); - CodeSource codeSource = clazz.getProtectionDomain().getCodeSource(); - if (codeSource == null || codeSource.getLocation() == null) { - throw new IllegalStateException("Unable to detect the gf-client.jar location," - + " because the getCodeSource() or getLocation() method returned null." - + " That can happen ie. when you use the boot classloader" - + " or a classloader which doesn't use locations."); - } - return Path.of(codeSource.getLocation().toURI()); - } catch (ClassNotFoundException | URISyntaxException e) { - throw new IllegalStateException("Could not detect the GlassFish lib directory.", e); + private static URL[] getJavaClassPathForAppClient() { + final List paths = convertClassPathToPaths(System.getProperty("java.class.path")); + final List result = new ArrayList<>(); + for (Path path : paths) { + result.add(TO_URL.apply(path)); } + result.addAll(convertClassPathToURLs(System.getenv("APPCPATH"))); + return result.toArray(URL[]::new); } - /** - * @param classPath files separated by {@link File#pathSeparator} - * @return classPath as a list of {@link URL} - */ - public static List convertClassPathToURLs(final String classPath) { + private static List convertClassPathToURLs(final String classPath) { return convertClassPathToPaths(classPath).stream().map(TO_URL).collect(Collectors.toList()); } - /** - * @param classPath files separated by {@link File#pathSeparator} - * @return classPath as a list of {@link Path} - */ - public static List convertClassPathToPaths(final String classPath) { + private static List convertClassPathToPaths(final String classPath) { if (classPath == null || classPath.isBlank()) { return emptyList(); } - final List result = new ArrayList<>(); try { - for (String classPathElement : classPath.split(File.pathSeparator)) { - result.add(new File(classPathElement.trim()).toPath()); + String[] paths = classPath.split(File.pathSeparator); + final List result = new ArrayList<>(paths.length); + for (String classPathElement : paths) { + result.add(new File(classPathElement.trim()).toPath().normalize()); } return result; } catch (Exception e) { @@ -148,13 +110,9 @@ public static List convertClassPathToPaths(final String classPath) { } - /** - * @param url url describing a {@link Path} - * @return string path - */ - public static String convertToString(URL url) { + private static String convertToString(URL url) { try { - return Path.of(url.toURI()).toString(); + return new File(url.toURI()).toPath().toAbsolutePath().normalize().toFile().getAbsolutePath(); } catch (URISyntaxException e) { throw new IllegalArgumentException("Cannot convert to URI string: " + url, e); } diff --git a/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/GFDependenciesClassLoader.java b/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/GFDependenciesClassLoader.java new file mode 100644 index 00000000000..4970db370be --- /dev/null +++ b/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/GFDependenciesClassLoader.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.appclient.client.acc.agent; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.CodeSource; +import java.util.Arrays; +import java.util.Set; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Stream; + +/** + * This class loader was created to minimize GlassFish dependencies on the command line. + * It can be used as a system class loader too. + * It should not depend on other classes except JDK. + */ +public final class GFDependenciesClassLoader extends URLClassLoader { + + static { + registerAsParallelCapable(); + } + + private static final Function TO_URL = file -> { + try { + return file.toURI().toURL(); + } catch (IOException e) { + throw new Error("Could not resolve url: " + file, e); + } + }; + + private static final boolean AS_TRACE = Boolean.parseBoolean(System.getenv("AS_TRACE")); + + /** + * This constructor is used when you instantiate this class loader in your code. + */ + GFDependenciesClassLoader() { + super("GlassFish", findGlassFishJars(), ClassLoader.getPlatformClassLoader()); + } + + + /** + * Returns class name, hash code and list of managed urls and info about parent. + */ + @Override + public String toString() { + final StringBuilder text = new StringBuilder(1024); + text.append(getClass().getName()).append('@').append(Integer.toHexString(hashCode())); + text.append("[name=").append(getName()).append(']'); + if (AS_TRACE) { + text.append(", urls=[\n"); + Arrays.stream(getURLs()).forEach(u -> text.append(u).append('\n')); + text.append(']'); + text.append(", parent=").append(getParent()); + } + return text.toString(); + } + + private static URL[] findGlassFishJars() { + Path gfHome = getGlassFishHome(); + Path gfModules = gfHome.resolve("modules"); + Set ignoredFiles = Set.of( + // TODO: Which should be here? + ); + Predicate moduleFilter = path -> { + String fileName = path.getFileName().toString(); + if (!fileName.endsWith(".jar") || ignoredFiles.contains(fileName)) { + return false; + } + String relativePath = gfModules.relativize(path).toString(); + return !relativePath.contains("autostart/"); + }; + Path appInstall = gfHome.resolve(Path.of("lib", "install", "applications")); + Predicate libFilter = filePath -> { + String path = appInstall.relativize(filePath).toString(); + return path.endsWith(".jar") && (path.contains("jmsra/") || path.contains("_jdbc_ra/")); + }; + Path derbyLibDir = gfHome.resolve(Path.of("..", "javadb", "lib")).normalize(); + Predicate derbyFilter = filePath -> { + Set files = Set.of("derby.jar", "derbyclient.jar", "derbynet.jar"); + return files.contains(filePath.getFileName().toString()); + }; + Stream modules = findFiles(gfModules, moduleFilter); + Stream libs = findFiles(appInstall, libFilter); + Stream derbyLibs = findFiles(derbyLibDir, derbyFilter); + return Stream.of(modules, libs, derbyLibs).reduce(Stream::concat).orElseGet(Stream::empty).map(TO_URL) + .toArray(URL[]::new); + } + + + private static Stream findFiles(Path root, Predicate filter) { + try { + return Files.walk(root, 5).filter(filter).map(Path::toFile); + } catch (IOException e) { + throw new Error(e); + } + } + + + private static Path getGlassFishHome() { + return new File(getMyJar()).getParentFile().getParentFile().toPath(); + } + + + private static URI getMyJar() { + try { + CodeSource codeSource = GFDependenciesClassLoader.class.getProtectionDomain().getCodeSource(); + if (codeSource == null || codeSource.getLocation() == null) { + throw new Error("Unable to detect the current jar file location," + + " because the getCodeSource() or getLocation() method returned null." + + " That can happen ie. when you use the boot classloader" + + " or a classloader which doesn't use locations."); + } + return codeSource.getLocation().toURI(); + } catch (URISyntaxException e) { + throw new Error("Could not detect the GlassFish lib directory.", e); + } + } +} diff --git a/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/UserClassLoader.java b/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/UserClassLoader.java new file mode 100644 index 00000000000..7cd7e55a6da --- /dev/null +++ b/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/acc/agent/UserClassLoader.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.appclient.client.acc.agent; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.glassfish.embeddable.client.ApplicationClientClassLoader; +import org.glassfish.embeddable.client.ApplicationClientContainer; + +/** + * Dependencies from -classpath argument, APPCPATH environment option, current directory + */ +public class UserClassLoader extends URLClassLoader implements ApplicationClientClassLoader { + + private static final Function PATH_TO_URL = p -> { + try { + return p.toUri().toURL(); + } catch (MalformedURLException e) { + throw new IllegalStateException("Could not convert path to url: " + p, e); + } + }; + + + UserClassLoader() { + super("User", createClassPath(), new GFDependenciesClassLoader()); + } + + private volatile ApplicationClientContainer container; + + @Override + public ApplicationClientContainer getApplicationClientContainer() { + return container; + } + + + @Override + public void setApplicationClientContainer(ApplicationClientContainer container) { + this.container = container; + } + + + /** + * Returns class name, hash code and list of managed urls and info about parent. + */ + @Override + public String toString() { + final StringBuilder text = new StringBuilder(1024); + text.append(getClass().getName()).append('@').append(Integer.toHexString(hashCode())); + text.append("[name=").append(getName()).append(']'); + text.append("[container=").append(container).append(']'); + text.append(", urls=[\n"); + Arrays.stream(getURLs()).forEach(u -> text.append(u).append('\n')); + text.append(']'); + text.append(", parent=").append(getParent()); + return text.toString(); + } + + + private static URL[] createClassPath() { + final Stream hardCodedPaths = convertClassPathToPaths("."); + final Stream cpPaths = convertClassPathToPaths(System.getProperty("java.class.path")); + final Stream envPaths = convertClassPathToPaths(System.getenv("APPCPATH")); + final Predicate filterOutGfClient = f -> !f.endsWith(Path.of("gf-client.jar")); + return Stream.of(hardCodedPaths, cpPaths, envPaths).reduce(Stream::concat).orElseGet(Stream::empty) + .map(Path::toAbsolutePath).map(Path::normalize).distinct().filter(filterOutGfClient).map(PATH_TO_URL) + .toArray(URL[]::new); + } + + private static Stream convertClassPathToPaths(final String classPath) { + if (classPath == null || classPath.isBlank()) { + return Stream.empty(); + } + try { + return Stream.of(classPath.split(File.pathSeparator)).map(File::new).map(File::toPath); + } catch (Exception e) { + throw new IllegalArgumentException("Could not parse the classpath: " + classPath, e); + } + } +} diff --git a/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/packageappclient/PackageAppClient.java b/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/packageappclient/PackageAppClient.java index cac07567328..50eb8008ffe 100644 --- a/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/packageappclient/PackageAppClient.java +++ b/appserver/appclient/client/acc-standalone/src/main/java/org/glassfish/appclient/client/packageappclient/PackageAppClient.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -16,8 +17,6 @@ package org.glassfish.appclient.client.packageappclient; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; - import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; @@ -68,7 +67,6 @@ public class PackageAppClient { private final static String GLASSFISH_LIB = "glassfish/lib"; private final static String GLASSFISH_BIN = "glassfish/bin"; private final static String GLASSFISH_CONFIG = "glassfish/config"; - private final static String MODULES_ENDORSED_DIR = "glassfish/modules/endorsed"; private final static String MQ_LIB = "mq/lib"; private final static String DOMAIN_1_CONFIG = "glassfish/domains/domain1/config"; private final static String INDENT = " "; @@ -79,15 +77,9 @@ public class PackageAppClient { private final static String[] DIRS_TO_COPY = new String[] { GLASSFISH_LIB + "/dtds", GLASSFISH_LIB + "/schemas", - GLASSFISH_LIB + "/appclient" }; - - /* - * relative path to the endorsed directory of the app server. Handled separately from other directorys because we do not - * include all files from the endorsed directory. - */ - private final static String LIB_ENDORSED_DIR = GLASSFISH_LIB + "/endorsed"; - - private final static String[] ENDORSED_DIRS_TO_COPY = new String[] { LIB_ENDORSED_DIR, MODULES_ENDORSED_DIR }; + GLASSFISH_LIB + "/appclient", + GLASSFISH_LIB + "/bootstrap", + }; /* default sun-acc.xml is relative to the installation directory */ private final static String DEFAULT_ACC_XML = DOMAIN_1_CONFIG + ACC_CONFIG_FILE_DEFAULT; @@ -124,8 +116,6 @@ public class PackageAppClient { /* default output file */ private final static String DEFAULT_OUTPUT_PATH = GLASSFISH_LIB + "/appclient.jar"; - private final static LocalStringsImpl strings = new LocalStringsImpl(PackageAppClient.class); - private boolean isVerbose; /** @@ -146,74 +136,62 @@ private void run(String[] args) throws URISyntaxException, IOException { File installDir = findInstallDir(thisJarFile); File modulesDir = new File(installDir.toURI().resolve("glassfish/modules/")); - /* - * Write the new JAR to a temp file in the install directory. Then we can simply rename the file to the correct name. - * (Rename does not work on Windows systems across volumes.) - */ + // Write the new JAR to a temp file in the install directory. Then we can simply rename + // the file to the correct name. + // (Rename does not work on Windows systems across volumes.) File tempFile = File.createTempFile("appc", ".tmp", installDir); File outputFile = chooseOutputFile(installDir, args); File[] configFiles = chooseConfigFiles(installDir, args); String[] classPathElements = getJarClassPath(thisJarFile).split(" "); - JarOutputStream os = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempFile))); - - /* - * Add this JAR file to the output. - */ - addFile(os, installDir.toURI(), thisJarFile.toURI(), tempFile, ""); - - /* - * JARs listed in the Class-Path are all relative to the modules directory so resolve each Class-Path entry against the - * modules directory. - */ - for (String classPathElement : classPathElements) { - File classPathJAR = new File(modulesDir, classPathElement); - addFile(os, installDir.toURI(), modulesDir.toURI().resolve(classPathJAR.toURI()), tempFile, ""); - } + try (JarOutputStream os = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempFile)))) { + // Add this JAR file to the output. + addFile(os, installDir.toURI(), thisJarFile.toURI(), tempFile, ""); - /* - * The directories to copy are all relative to the installation directory, so resolve them against the installDir file. - */ - for (String dirToCopy : DIRS_TO_COPY) { - addDir(os, installDir.toURI(), installDir.toURI().resolve(dirToCopy), tempFile, ""); - } + // JARs listed in the Class-Path are all relative to the modules directory so resolve + // each Class-Path entry against the modules directory. + for (String classPathElement : classPathElements) { + File classPathJAR = new File(modulesDir, classPathElement); + addFile(os, installDir.toURI(), modulesDir.toURI().resolve(classPathJAR.toURI()), tempFile, ""); + } - for (String endorsedDirToCopy : ENDORSED_DIRS_TO_COPY) { - addEndorsedFiles(os, installDir.toURI(), installDir.toURI().resolve(endorsedDirToCopy), tempFile); - } + // The directories to copy are all relative to the installation directory, so resolve + // them against the installDir file. + for (String dirToCopy : DIRS_TO_COPY) { + addDir(os, installDir.toURI(), installDir.toURI().resolve(dirToCopy), tempFile, ""); + } - for (String singleFileToCopy : SINGLE_FILES_TO_COPY) { - addFile(os, installDir.toURI(), installDir.toURI().resolve(singleFileToCopy), tempFile, ""); - } + for (String singleFileToCopy : SINGLE_FILES_TO_COPY) { + addFile(os, installDir.toURI(), installDir.toURI().resolve(singleFileToCopy), tempFile, ""); + } - /* - * The glassfish-acc.xml file and sun-acc.xml files. - */ - for (File configFile : configFiles) { - addFile(os, installDir.toURI(), configFile.toURI(), tempFile, ""); + // The glassfish-acc.xml file and sun-acc.xml files. + for (File configFile : configFiles) { + addFile(os, installDir.toURI(), configFile.toURI(), tempFile, ""); + } } - - os.close(); placeFile(tempFile, outputFile); } private void placeFile(final File tempFile, final File outputFile) { if (outputFile.exists()) { if (!outputFile.delete()) { - throw new RuntimeException(strings.get("errDel", outputFile.getAbsolutePath())); + throw new RuntimeException("Stopping; could not delete the existing output file " + outputFile.getAbsolutePath()); } - System.out.println(strings.get("replacingFile", outputFile.getAbsolutePath())); + System.out.println("Replacing " + outputFile.getAbsolutePath()); } else { - System.out.println(strings.get("creatingFile", outputFile.getAbsolutePath())); + System.out.println("Creating" + outputFile.getAbsolutePath()); } if (isVerbose) { - System.out.println(strings.get("moving", tempFile.getAbsolutePath(), outputFile.getAbsolutePath())); + System.out + .println("Moving temp file " + tempFile.getAbsolutePath() + " to " + outputFile.getAbsolutePath()); } if (!tempFile.renameTo(outputFile)) { - throw new RuntimeException(strings.get("errRenaming", tempFile.getAbsolutePath(), outputFile.getAbsolutePath())); + throw new RuntimeException( + "Error renaming temp file " + tempFile.getAbsolutePath() + " to " + outputFile.getAbsolutePath()); } } @@ -243,7 +221,7 @@ private void addEndorsedFiles(JarOutputStream os, URI installDirURI, URI endorse private void addFile(JarOutputStream os, URI installDirURI, URI absoluteURIToAdd, File outputFile, String indent) throws IOException { try { if (isVerbose) { - System.err.println(indent + strings.get("addingFile", absoluteURIToAdd)); + System.err.println(indent + "Adding directory " + absoluteURIToAdd); } File fileToCopy = new File(absoluteURIToAdd); @@ -261,7 +239,8 @@ private void addFile(JarOutputStream os, URI installDirURI, URI absoluteURIToAdd */ if (!new File(absoluteURIToAdd).exists()) { if (isVerbose) { - System.err.println(indent + strings.get("noFile", new File(absoluteURIToAdd).getAbsolutePath())); + System.err.println(indent + "Error locating file " + + new File(absoluteURIToAdd).getAbsolutePath() + "; continuing"); } return; } @@ -276,7 +255,8 @@ private void addFile(JarOutputStream os, URI installDirURI, URI absoluteURIToAdd * Probably duplicate entry. Keep going after logging the error. */ if (isVerbose) { - System.err.println(indent + strings.get("zipExc", e.getLocalizedMessage())); + System.err.println( + indent + "Continuing after ZipException when adding a file: " + e.getLocalizedMessage()); } } catch (FileNotFoundException ignore) { } @@ -323,7 +303,7 @@ private void addDir(JarOutputStream os, URI installDirURI, URI absoluteDirURIToA } if (isVerbose) { - System.err.println(indent + strings.get("addingDir", dirFile.getAbsolutePath())); + System.err.println(indent + "Adding dir " + dirFile.getAbsolutePath()); } for (File fileToAdd : matchingFiles) { @@ -406,7 +386,8 @@ private File[] chooseConfigFiles(final File installDir, final String[] args) { File userSpecifiedFile = new File(xmlArg); files = new File[] { userSpecifiedFile }; if (!userSpecifiedFile.exists()) { - System.err.println(strings.get("xmlNotFound", userSpecifiedFile.getAbsolutePath())); + System.err.println("The XML configuration file " + userSpecifiedFile.getAbsolutePath() + + " does not exist; continuing but output is incomplete"); } } @@ -414,7 +395,7 @@ private File[] chooseConfigFiles(final File installDir, final String[] args) { } - private File findInstallDir(File currentJarFile) throws URISyntaxException { + private File findInstallDir(File currentJarFile) { return currentJarFile.getParentFile().getParentFile().getParentFile(); } diff --git a/appserver/appclient/client/acc-standalone/src/main/resources/org/glassfish/appclient/client/acc/agent/LocalStrings.properties b/appserver/appclient/client/acc-standalone/src/main/resources/org/glassfish/appclient/client/acc/agent/LocalStrings.properties deleted file mode 100644 index 9694989c26b..00000000000 --- a/appserver/appclient/client/acc-standalone/src/main/resources/org/glassfish/appclient/client/acc/agent/LocalStrings.properties +++ /dev/null @@ -1,20 +0,0 @@ -# -# Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. -# -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v. 2.0, which is available at -# http://www.eclipse.org/legal/epl-2.0. -# -# This Source Code may also be made available under the following Secondary -# Licenses when the conditions for such availability set forth in the -# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, -# version 2 with the GNU Classpath Exception, which is available at -# https://www.gnu.org/software/classpath/license.html. -# -# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 -# - - -main.usage=Usage :\n\tappclient [ | -client ] \n\t\t[-mainclass |-name ] \n\t\t[-xml ] \n\t\t[-textauth] [-user ] [-password |-passwordfile ] \n\t\t[-targetserver host[:port][,host[:port]...] \n\t\t[app-args] -main.usage.1=or :\n\tappclient [ ]\n\t\t[ | -jar ] \n\t\t[app args] -main.badVersion=Current Java version {0} is too low; {1} or later required diff --git a/appserver/appclient/client/acc-standalone/src/main/resources/org/glassfish/appclient/client/packageappclient/LocalStrings.properties b/appserver/appclient/client/acc-standalone/src/main/resources/org/glassfish/appclient/client/packageappclient/LocalStrings.properties deleted file mode 100644 index a4655a0bf0c..00000000000 --- a/appserver/appclient/client/acc-standalone/src/main/resources/org/glassfish/appclient/client/packageappclient/LocalStrings.properties +++ /dev/null @@ -1,26 +0,0 @@ -# -# Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. -# -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v. 2.0, which is available at -# http://www.eclipse.org/legal/epl-2.0. -# -# This Source Code may also be made available under the following Secondary -# Licenses when the conditions for such availability set forth in the -# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, -# version 2 with the GNU Classpath Exception, which is available at -# https://www.gnu.org/software/classpath/license.html. -# -# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 -# - -errDel=Stopping; could not delete the existing output file {0} -replacingFile=Replacing {0} -creatingFile=Creating {0} -zipExc=Continuing after ZipException when adding a file: {0} -xmlNotFound=The XML configuration file {0} does not exist; continuing but output is incomplete -addingFile=Adding file {0} -addingDir=Adding directory {0} -noFile=Error locating file {0}; continuing -errRenaming=Error renaming temp file {0} to {1} -moving=Moving temp file {0} to {1} diff --git a/appserver/appclient/client/acc/src/test/java/org/glassfish/appclient/client/CLIBootstrapTest.java b/appserver/appclient/client/acc-standalone/src/test/java/org/glassfish/appclient/client/acc/agent/CLIBootstrapTest.java similarity index 96% rename from appserver/appclient/client/acc/src/test/java/org/glassfish/appclient/client/CLIBootstrapTest.java rename to appserver/appclient/client/acc-standalone/src/test/java/org/glassfish/appclient/client/acc/agent/CLIBootstrapTest.java index 09324219171..3ce0894c0e5 100644 --- a/appserver/appclient/client/acc/src/test/java/org/glassfish/appclient/client/CLIBootstrapTest.java +++ b/appserver/appclient/client/acc-standalone/src/test/java/org/glassfish/appclient/client/acc/agent/CLIBootstrapTest.java @@ -1,6 +1,6 @@ /* + * Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2021 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -15,7 +15,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package org.glassfish.appclient.client; +package org.glassfish.appclient.client.acc.agent; import java.lang.reflect.Method; import java.util.regex.Pattern; @@ -43,7 +43,7 @@ public void setUp() { System.setProperty(CLIBootstrap.ENV_VAR_PROP_PREFIX + "AS_JAVA", ""); System.setProperty(CLIBootstrap.ENV_VAR_PROP_PREFIX + "JAVA_HOME", ""); System.setProperty(CLIBootstrap.ENV_VAR_PROP_PREFIX + "PATH", System.getenv("PATH")); - System.setProperty(CLIBootstrap.ENV_VAR_PROP_PREFIX + "_AS_INSTALL", + System.setProperty(CLIBootstrap.ENV_VAR_PROP_PREFIX + "AS_INSTALL", "/Users/Tim/asgroup/v3/H/publish/glassfish7/glassfish"); } diff --git a/appserver/appclient/client/acc/pom.xml b/appserver/appclient/client/acc/pom.xml index f29aa1976b9..607f07ce87b 100755 --- a/appserver/appclient/client/acc/pom.xml +++ b/appserver/appclient/client/acc/pom.xml @@ -77,6 +77,16 @@ glassfish-jul-extension compile + + org.glassfish.main.common + glassfish-jdk-extensions + ${project.version} + + + org.glassfish.main.common + simple-glassfish-api + ${project.version} + org.glassfish.hk2 hk2-core diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/AppClientContainerHolder.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/AppClientContainerHolder.java new file mode 100644 index 00000000000..6595c735dc2 --- /dev/null +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/AppClientContainerHolder.java @@ -0,0 +1,500 @@ +/* + * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.appclient.client; + +import com.sun.enterprise.deployment.node.SaxParserHandlerBundled; +import com.sun.enterprise.universal.glassfish.TokenResolver; + +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.Unmarshaller; +import jakarta.xml.bind.ValidationEvent; +import jakarta.xml.bind.util.ValidationEventCollector; + +import java.io.BufferedReader; +import java.io.CharArrayWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; +import java.lang.instrument.Instrumentation; +import java.net.MalformedURLException; +import java.net.URI; +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.sax.SAXSource; + +import org.glassfish.appclient.client.acc.ACCLogger; +import org.glassfish.appclient.client.acc.AgentArguments; +import org.glassfish.appclient.client.acc.AppClientContainer; +import org.glassfish.appclient.client.acc.AppClientContainer.Builder; +import org.glassfish.appclient.client.acc.AppclientCommandArguments; +import org.glassfish.appclient.client.acc.CommandLaunchInfo; +import org.glassfish.appclient.client.acc.CommandLaunchInfo.ClientLaunchType; +import org.glassfish.appclient.client.acc.TargetServerHelper; +import org.glassfish.appclient.client.acc.TransformingClassLoader; +import org.glassfish.appclient.client.acc.Util; +import org.glassfish.appclient.client.acc.config.AuthRealm; +import org.glassfish.appclient.client.acc.config.ClientContainer; +import org.glassfish.appclient.client.acc.config.ClientCredential; +import org.glassfish.appclient.client.acc.config.MessageSecurityConfig; +import org.glassfish.appclient.client.acc.config.Property; +import org.glassfish.appclient.client.acc.config.TargetServer; +import org.glassfish.embeddable.client.ApplicationClientClassLoader; +import org.glassfish.embeddable.client.ApplicationClientContainer; +import org.glassfish.embeddable.client.UserError; +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; + +import static org.glassfish.appclient.client.acc.CommandLaunchInfo.ClientLaunchType.UNKNOWN; + +/** + * @author tjquinn + * @author David Matejcek + */ +public class AppClientContainerHolder implements ApplicationClientContainer { + + private static final String ACC_CONFIG_CONTENT_PROPERTY_NAME = "glassfish-acc.xml.content"; + private static final String MAN_PAGE_PATH = "/org/glassfish/appclient/client/acc/appclient.1m"; + + private static volatile AppClientContainerHolder instance; + + private CommandLaunchInfo launchInfo; + private AppclientCommandArguments appClientCommandArgs; + + private ApplicationClientContainer appClientContainer; + + + @Override + public void launch(String[] args) throws UserError { + appClientContainer.launch(args); + } + + public ApplicationClientContainer getAppClientContainer() { + return appClientContainer; + } + + public static synchronized AppClientContainerHolder getInstance() { + if (instance == null) { + // The container was not initialized by the instrumentation executed + // by the AppClientContainerAgent. We will try to make it. + try { + init(null, null); + } catch (UserError ue) { + ue.displayAndExit(); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(1); + } + } + return instance; + } + + /** + * Initializes the {@link ApplicationClientContainer} singleton. + * + * @param agentArgsText + * @param inst + * @throws UserError + * @throws Exception + */ + public static synchronized void init(String agentArgsText, Instrumentation inst) throws UserError, Exception { + int version = Runtime.version().feature(); + if (version < 11) { + throw new UserError(MessageFormat.format("Current Java version {0} is too low; {1} or later required", + System.getProperty("java.version"), "11")); + } + + // Analyze the agent argument string. + AgentArguments agentArgs = AgentArguments.newInstance(agentArgsText); + + + // The agent arguments that correspond to the ones that we want to pass to the ACC are + // the ones with the "arg=" keyword prefix. + // These will include arguments with meaning to the ACC (-textauth for example) as well + // as arguments to be passed on to the client's main method. + AppClientContainerHolder holder = new AppClientContainerHolder(); + holder.appClientCommandArgs = AppclientCommandArguments.newInstance(agentArgs.namedValues("arg")); + + if (holder.appClientCommandArgs.isUsage()) { + usage(0); + } else if (holder.appClientCommandArgs.isHelp()) { + help(); + } + + // Examine the agent arguments for settings about how to launch the client. + holder.launchInfo = CommandLaunchInfo.newInstance(agentArgs); + if (holder.launchInfo.getClientLaunchType() == UNKNOWN) { + usage(1); + } + + // Load the ACC configuration XML file. + ClientContainer clientContainer = readConfig(holder.appClientCommandArgs); + + // Decide what target servers to use. This combines any specified on the command line with + // any in the config file's target-server elements as well as any set in the properties of + // the config file. + final TargetServer[] targetServers = TargetServerHelper.targetServers(clientContainer, + holder.appClientCommandArgs.getTargetServer()); + + ClassLoader dependenciesCL = Thread.currentThread().getContextClassLoader(); + try { + // This class loader does transformations and is saved inside the container. + TransformingClassLoader loader = initClassLoader(dependenciesCL, inst == null); + Thread.currentThread().setContextClassLoader(loader); + + // Get the builder. Doing so correctly involves merging the configuration file data with + // some of the command line and agent arguments. + final AppClientContainer.Builder builder = createBuilder(targetServers, clientContainer, holder.appClientCommandArgs); + + // Create the ACC. Again, precisely how we create it depends on some of the command line + // arguments and agent arguments. + final AppClientContainer newACC = createContainer(builder, holder.launchInfo, holder.appClientCommandArgs); + + // Because the JMV might invoke the client's main class, the agent needs to prepare the container. + // (This is done as part of the AppClientContainer.start() processing in the public API. + newACC.prepare(inst); + holder.appClientContainer = newACC; + ((ApplicationClientClassLoader) dependenciesCL).setApplicationClientContainer(holder.appClientContainer); + AppClientContainerHolder.instance = holder; + } finally { + // Reset for possible usage in the AppClientGroupFacade + Thread.currentThread().setContextClassLoader(dependenciesCL); + } + } + + private static void usage(final int exitStatus) { + System.err.println(getUsage()); + System.exit(exitStatus); + } + + private static void help() throws IOException { + final InputStream is = AppClientContainerHolder.class.getResourceAsStream(MAN_PAGE_PATH); + if (is == null) { + usage(0); + } + + try (BufferedReader helpReader = new BufferedReader(new InputStreamReader(is))) { + String line; + while ((line = helpReader.readLine()) != null) { + System.err.println(line); + } + } finally { + System.exit(0); + } + } + + private static String getUsage() { + return "appclient [ | -client ] [-mainclass |-name ]" + + " [-xml ] [-textauth] [-user ] [-password |-passwordfile ]" + + " [-targetserver host[:port][,host[:port]...] [app-args]" + System.lineSeparator() + + " or :\n\tappclient [ ] [ | -jar ]" + + " [app args]"; + } + + + private static TransformingClassLoader initClassLoader(final ClassLoader parent, final boolean loaderShouldTransform) { + final TransformingClassLoader loader = TransformingClassLoader.instance(); + if (loader == null) { + return TransformingClassLoader.newInstance(parent, loaderShouldTransform); + } + return loader; + } + + private static Builder createBuilder(TargetServer[] targetServers, ClientContainer clientContainer, + AppclientCommandArguments appClientCommandArgs) throws IOException { + Builder builder = AppClientContainer.newBuilder(targetServers); + + /* + * Augment the builder with settings from the app client options that can affect the builder itself. (This is distinct + * from options that affect what client to launch which are handled in creating the ACC itself. + */ + updateClientCredentials(builder, appClientCommandArgs); + List msc = clientContainer.getMessageSecurityConfig(); + if (msc != null) { + builder.getMessageSecurityConfig().addAll(clientContainer.getMessageSecurityConfig()); + } + + builder.logger(new ACCLogger(clientContainer.getLogService())); + + AuthRealm authRealm = clientContainer.getAuthRealm(); + if (authRealm != null) { + builder.authRealm(authRealm.getClassname()); + } + + List property = clientContainer.getProperty(); + if (property != null) { + builder.containerProperties(property); + } + + return builder; + } + + private static void updateClientCredentials(final Builder builder, final AppclientCommandArguments appClientCommandArgs) { + ClientCredential clientCredential = builder.getClientCredential(); + String user = clientCredential == null ? null : clientCredential.getUserName(); + char[] pw = clientCredential != null && clientCredential.getPassword() != null ? clientCredential.getPassword().get() : null; + + /* + * user on command line? + */ + String commandLineUser = appClientCommandArgs.getUser(); + if (commandLineUser != null) { + user = commandLineUser; + } + + /* + * password or passwordfile on command line? (theAppClientCommandArgs class takes care of reading the password from the + * file and/or handling the -password option. + */ + char[] commandLinePW = appClientCommandArgs.getPassword(); + if (commandLinePW != null) { + pw = commandLinePW; + } + + builder.clientCredentials(user, pw); + } + + private static AppClientContainer createContainer(Builder builder, CommandLaunchInfo launchInfo, + AppclientCommandArguments appClientArgs) throws Exception, UserError { + + /* + * The launchInfo already knows something about how to conduct the launch. + */ + ClientLaunchType launchType = launchInfo.getClientLaunchType(); + AppClientContainer container; + + switch (launchType) { + case JAR: + case DIR: + // The client name in the launch info is a file path for the directory or JAR to launch. + container = createContainerForAppClientArchiveOrDir(builder, launchInfo.getClientName(), appClientArgs); + break; + + case URL: + container = createContainerForJWSLaunch(builder, launchInfo.getClientName(), appClientArgs); + break; + + case CLASS: + container = createContainerForClassName(builder, launchInfo.getClientName()); + break; + + case CLASSFILE: + container = createContainerForClassFile(builder, launchInfo.getClientName()); + break; + + default: + container = null; + } + + if (container == null) { + throw new IllegalArgumentException("cannot choose app client launch type"); + } + + return container; + } + + + private static AppClientContainer createContainerForAppClientArchiveOrDir(Builder builder, String appClientPath, + AppclientCommandArguments appClientArgs) throws Exception, UserError { + return builder.newContainer(Util.getURI(new File(appClientPath)), null, + appClientArgs.getMainclass(), appClientArgs.getName(), appClientArgs.isTextauth()); + } + + + private static AppClientContainer createContainerForJWSLaunch(Builder builder, String appClientPath, + AppclientCommandArguments appClientArgs) throws Exception, UserError { + return builder.newContainer(URI.create(appClientPath), null /* callbackHandler */, appClientArgs.getMainclass(), + appClientArgs.getName()); + } + + + /** + * Place "." on the class path so that when we convert the class file path + * to a fully-qualified class name and try to load it, we'll find it. + */ + private static AppClientContainer createContainerForClassName(Builder builder, String className) throws Exception, UserError { + return builder.newContainer(Class.forName(className, true, Thread.currentThread().getContextClassLoader())); + } + + private static AppClientContainer createContainerForClassFile(Builder builder, String classFilePath) + throws MalformedURLException, ClassNotFoundException, FileNotFoundException, IOException, Exception, UserError { + + Util.verifyFilePath(classFilePath); + + /* + * Strip off the trailing .class from the path and convert separator characters to dots to build a fully-qualified class + * name. + */ + String className = classFilePath.substring(0, classFilePath.lastIndexOf(".class")).replace(File.separatorChar, '.'); + + return createContainerForClassName(builder, className); + } + + private static ClientContainer readConfig(AppclientCommandArguments appClientCommandArgs) throws UserError, Exception { + final String configPath = appClientCommandArgs.getConfigFilePath(); + ClientContainer result = null; + Reader configReader = null; + try { + /* + * During a Java Web Start launch, the config is passed as a property value. + */ + final String configInProperty = System.getProperty(ACC_CONFIG_CONTENT_PROPERTY_NAME); + final String configFileLocationForErrorMessage; + if (configInProperty == null) { + /* + * This is not a Java Web Start launch, so read the configuration from a disk file. + */ + File configFile = checkXMLFile(configPath); + checkXMLFile(appClientCommandArgs.getConfigFilePath()); + configReader = new FileReader(configFile); + configFileLocationForErrorMessage = configFile.getAbsolutePath(); + } else { + /* + * Awkwardly, the glassfish-acc.xml content refers to a config file. We work around this for Java Web Start launch by + * capturing the content of that config file into a property setting in the generated JNLP document. We need to write + * that content into a temporary file here on the client and then replace a placeholder in the glassfish-acc.xml content + * with the path to that temp file. + */ + final File securityConfigTempFile = Util.writeTextToTempFile(configInProperty, "wss-client-config", ".xml", false); + final Properties p = new Properties(); + p.setProperty("security.config.path", securityConfigTempFile.getAbsolutePath()); + configReader = new StringReader(Util.replaceTokens(configInProperty, p)); + configFileLocationForErrorMessage = null; + } + + /* + * Although JAXB makes it very simple to parse the XML into Java objects, we have to do several things explicitly to use + * our local copies of DTDs and XSDs. + */ + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setValidating(true); + spf.setNamespaceAware(true); + SAXParser parser = spf.newSAXParser(); + XMLReader reader = parser.getXMLReader(); + + /* + * Get the local entity resolver that knows about the bundled .dtd and .xsd files. + */ + reader.setEntityResolver(new SaxParserHandlerBundled()); + + /* + * To support installation-directory independence the default glassfish-acc.xml refers to the wss-config file using + * ${com.sun.aas.installRoot}... So preprocess the glassfish-acc.xml file to replace any tokens with the corresponding + * values, then submit that result to JAXB. + */ + InputSource inputSource = replaceTokensForParsing(configReader); + SAXSource saxSource = new SAXSource(reader, inputSource); + + JAXBContext jc = JAXBContext.newInstance(ClientContainer.class); + Unmarshaller u = jc.createUnmarshaller(); + final ValidationEventCollector vec = new ValidationEventCollector(); + u.setEventHandler(vec); + result = (ClientContainer) u.unmarshal(saxSource); + if (vec.hasEvents()) { + printValidationEvents(configFileLocationForErrorMessage, vec.getEvents()); + } + return result; + } finally { + if (configReader != null) { + configReader.close(); + } + } + } + + private static void printValidationEvents(String file, ValidationEvent[] events) { + /* + * The parser reported at least one warning or error. If all events were warnings, display them as a message and + * continue. Otherwise there was at least one error or fatal, so say so and try to continue but say that such errors + * might be fatal in future releases. + */ + boolean isError = false; + final StringBuilder sb = new StringBuilder(); + for (ValidationEvent ve : events) { + sb.append(ve.getMessage()).append(System.lineSeparator()); + isError |= (ve.getSeverity() != ValidationEvent.WARNING); + } + + String messageIntroduction = MessageFormat.format(isError + ? "Error parsing app client container configuration{0}." + + " Attempting to continue." + + " In future releases such parsing errors might become fatal." + + " Please correct your configuration file." + : "Warning(s) parsing app client container configuration{0}." + + " Continuing.", + file == null ? "" : " file " + file); + System.err.println(messageIntroduction + System.lineSeparator() + sb); + } + + private static InputSource replaceTokensForParsing(final Reader reader) throws FileNotFoundException, IOException { + CharArrayWriter writer = new CharArrayWriter(); + try { + char[] buffer = new char[4096]; + int charsRead; + while ((charsRead = reader.read(buffer)) != -1) { + writer.write(buffer, 0, charsRead); + } + } finally { + writer.close(); + } + reader.close(); + + Map mapping = new HashMap<>(); + Properties props = System.getProperties(); + for (String propName : props.stringPropertyNames()) { + mapping.put(propName, props.getProperty(propName)); + } + + TokenResolver resolver = new TokenResolver(mapping); + String configWithTokensReplaced = resolver.resolve(writer.toString()); + return new InputSource(new StringReader(configWithTokensReplaced)); + } + + private static File checkXMLFile(String xmlFullName) throws UserError { + try { + File f = new File(xmlFullName); + if (f.exists() && f.isFile() && f.canRead()) { + return f; + } + // If given file does not exists + xmlMessage(xmlFullName); + return null; + } catch (Exception ex) { + xmlMessage(xmlFullName); + return null; + } + } + + private static void xmlMessage(String xmlFullName) throws UserError { + UserError ue = new UserError(MessageFormat.format( + "Client Container xml: {0} not found or unable to read.\nYou may want to use the -xml option to locate your configuration xml.", + xmlFullName)); + ue.setUsage(getUsage()); + throw ue; + + } +} diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/AppClientFacade.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/AppClientFacade.java index b7c556eff58..214765beb7a 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/AppClientFacade.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/AppClientFacade.java @@ -17,85 +17,14 @@ package org.glassfish.appclient.client; -import com.sun.enterprise.container.common.spi.util.InjectionException; -import com.sun.enterprise.deployment.node.SaxParserHandlerBundled; -import com.sun.enterprise.universal.glassfish.TokenResolver; -import com.sun.enterprise.util.LocalStringManager; -import com.sun.enterprise.util.LocalStringManagerImpl; - -import jakarta.xml.bind.JAXBContext; -import jakarta.xml.bind.JAXBException; -import jakarta.xml.bind.Unmarshaller; -import jakarta.xml.bind.ValidationEvent; -import jakarta.xml.bind.util.ValidationEventCollector; - -import java.io.BufferedReader; -import java.io.CharArrayWriter; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; -import java.lang.instrument.Instrumentation; -import java.lang.reflect.InvocationTargetException; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.transform.sax.SAXSource; - -import org.glassfish.appclient.client.acc.ACCClassLoader; -import org.glassfish.appclient.client.acc.ACCLogger; -import org.glassfish.appclient.client.acc.AgentArguments; -import org.glassfish.appclient.client.acc.AppClientContainer; -import org.glassfish.appclient.client.acc.AppClientContainer.Builder; -import org.glassfish.appclient.client.acc.AppclientCommandArguments; -import org.glassfish.appclient.client.acc.CommandLaunchInfo; -import org.glassfish.appclient.client.acc.CommandLaunchInfo.ClientLaunchType; -import org.glassfish.appclient.client.acc.TargetServerHelper; -import org.glassfish.appclient.client.acc.UserError; -import org.glassfish.appclient.client.acc.Util; -import org.glassfish.appclient.client.acc.config.AuthRealm; -import org.glassfish.appclient.client.acc.config.ClientContainer; -import org.glassfish.appclient.client.acc.config.ClientCredential; -import org.glassfish.appclient.client.acc.config.MessageSecurityConfig; -import org.glassfish.appclient.client.acc.config.Property; -import org.glassfish.appclient.client.acc.config.TargetServer; -import org.glassfish.common.util.GlassfishUrlClassLoader; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; - -import static org.glassfish.appclient.client.acc.CommandLaunchInfo.ClientLaunchType.UNKNOWN; +import org.glassfish.embeddable.client.ApplicationClientClassLoader; +import org.glassfish.embeddable.client.UserError; /** * @author tjquinn */ public class AppClientFacade { - private static final String ACC_CONFIG_CONTENT_PROPERTY_NAME = "glassfish-acc.xml.content"; - private static final String MAN_PAGE_PATH = "/org/glassfish/appclient/client/acc/appclient.1m"; - private static final String LINE_SEP = System.lineSeparator(); - - private static final Class stringsAnchor = ACCClassLoader.class; - private static LocalStringManager localStrings = new LocalStringManagerImpl(stringsAnchor); - - private static CommandLaunchInfo launchInfo; - private static AppclientCommandArguments appClientCommandArgs; - private static AppClientContainer appClientContainer; - /** * Prepares the ACC (if not already done by the agent) and then transfers control to the ACC. *

@@ -114,425 +43,14 @@ public class AppClientFacade { */ public static void main(String[] args) { try { - if (appClientContainer == null) { - /* - * The facade JAR has been run directly, not via the appclient script and not via Java Web Start. So we have no agent - * arguments and no instrumentation for registering transformations. - * - * Because the agent has not run, we prepare the ACC here. (The agent would have done so itself had it run.) - */ - prepareACC(null, null); - } - - /* - * In any case, the ACC is now prepared. Launch the app client in the prepared ACC. - */ - appClientContainer.launch(args); - } catch (Exception ex) { - ex.printStackTrace(); - System.exit(1); + ApplicationClientClassLoader loader = (ApplicationClientClassLoader) Thread.currentThread() + .getContextClassLoader(); + loader.getApplicationClientContainer().launch(args); } catch (UserError ue) { ue.displayAndExit(); - } - } - - public static AppClientContainer acc() { - return appClientContainer; - } - - public static void launch(String[] args) throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, - IllegalArgumentException, InvocationTargetException, IOException, SAXException, InjectionException, UserError { - appClientContainer.launch(args); - } - - public static void prepareACC(String agentArgsText, Instrumentation inst) throws UserError, MalformedURLException, URISyntaxException, - JAXBException, FileNotFoundException, ParserConfigurationException, SAXException, IOException, Exception { - int version = Runtime.version().feature(); - if (version < 11) { - throw new UserError(localStrings.getLocalString(stringsAnchor, "main.badVersion", - "Current Java version {0} is too low; {1} or later required", - new Object[] {System.getProperty("java.version"), "11"})); - } - - /* - * Analyze the agent argument string. - */ - AgentArguments agentArgs = AgentArguments.newInstance(agentArgsText); - - /* - * The agent arguments that correspond to the ones that we want to pass to the ACC are the ones with the "arg=" keyword - * prefix. These will include arguments with meaning to the ACC (-textauth for example) as well as arguments to be - * passed on to the client's main method. - */ - appClientCommandArgs = AppclientCommandArguments.newInstance(agentArgs.namedValues("arg")); - - if (appClientCommandArgs.isUsage()) { - usage(0); - } else if (appClientCommandArgs.isHelp()) { - help(); - } - - /* - * Examine the agent arguments for settings about how to launch the client. - */ - launchInfo = CommandLaunchInfo.newInstance(agentArgs); - if (launchInfo.getClientLaunchType() == UNKNOWN) { - usage(1); - } - - /* - * Handle the legacy env. variable APPCPATH. - */ - ACCClassLoader loader = initClassLoader((inst == null)); - Thread.currentThread().setContextClassLoader(loader); - - /* - * The installRoot property will be set by the ServerEnvironment initialization using the ACC start-up context. That - * happens during the ACCModulesManager warm-up. - */ - - /* - * Load the ACC configuration XML file. - */ - ClientContainer clientContainer = readConfig(appClientCommandArgs.getConfigFilePath(), loader); - - /* - * Decide what target servers to use. This combines any specified on the command line with any in the config file's - * target-server elements as well as any set in the properties of the config file. - */ - final TargetServer[] targetServers = TargetServerHelper.targetServers(clientContainer, appClientCommandArgs.getTargetServer()); - - /* - * Get the builder. Doing so correctly involves merging the configuration file data with some of the command line and - * agent arguments. - */ - final AppClientContainer.Builder builder = createBuilder(targetServers, clientContainer, appClientCommandArgs); - - /* - * Create the ACC. Again, precisely how we create it depends on some of the command line arguments and agent arguments. - */ - final AppClientContainer newACC = createContainer(builder, launchInfo, appClientCommandArgs); - - /* - * Because the JMV might invoke the client's main class, the agent needs to prepare the container. (This is done as part - * of the AppClientContainer.start() processing in the public API. - */ - newACC.prepare(inst); - - appClientContainer = newACC; - } - - private static void usage(final int exitStatus) { - System.err.println(getUsage()); - System.exit(exitStatus); - } - - private static void help() throws IOException { - final InputStream is = AppClientFacade.class.getResourceAsStream(MAN_PAGE_PATH); - if (is == null) { - usage(0); - } - - try (BufferedReader helpReader = new BufferedReader(new InputStreamReader(is))) { - String line; - while ((line = helpReader.readLine()) != null) { - System.err.println(line); - } - } finally { - System.exit(0); - } - } - - private static String getUsage() { - return localStrings.getLocalString(stringsAnchor, "main.usage", - "appclient [ | -client ] [-mainclass |-name ] [-xml ] [-textauth] [-user ] [-password |-passwordfile ] [-targetserver host[:port][,host[:port]...] [app-args]") - + System.lineSeparator() + localStrings.getLocalString(stringsAnchor, "main.usage.1", - " or :\n\tappclient [ ] [ | -jar ] [app args]"); - } - - private static ACCClassLoader initClassLoader(final boolean loaderShouldTransform) throws MalformedURLException { - ACCClassLoader loader = ACCClassLoader.instance(); - if (loader == null) { - loader = ACCClassLoader.newInstance(Thread.currentThread().getContextClassLoader(), loaderShouldTransform); - } - - return loader; - } - - private static Builder createBuilder(TargetServer[] targetServers, ClientContainer clientContainer, - AppclientCommandArguments appClientCommandArgs) throws IOException { - Builder builder = AppClientContainer.newBuilder(targetServers); - - /* - * Augment the builder with settings from the app client options that can affect the builder itself. (This is distinct - * from options that affect what client to launch which are handled in creating the ACC itself. - */ - updateClientCredentials(builder, appClientCommandArgs); - List msc = clientContainer.getMessageSecurityConfig(); - if (msc != null) { - builder.getMessageSecurityConfig().addAll(clientContainer.getMessageSecurityConfig()); - } - - builder.logger(new ACCLogger(clientContainer.getLogService())); - - AuthRealm authRealm = clientContainer.getAuthRealm(); - if (authRealm != null) { - builder.authRealm(authRealm.getClassname()); - } - - List property = clientContainer.getProperty(); - if (property != null) { - builder.containerProperties(property); - } - - return builder; - } - - private static void updateClientCredentials(final Builder builder, final AppclientCommandArguments appClientCommandArgs) { - ClientCredential clientCredential = builder.getClientCredential(); - String user = (clientCredential != null ? clientCredential.getUserName() : null); - char[] pw = (clientCredential != null && clientCredential.getPassword() != null ? clientCredential.getPassword().get() : null); - - /* - * user on command line? - */ - String commandLineUser; - if ((commandLineUser = appClientCommandArgs.getUser()) != null) { - user = commandLineUser; - } - - /* - * password or passwordfile on command line? (theAppClientCommandArgs class takes care of reading the password from the - * file and/or handling the -password option. - */ - char[] commandLinePW; - if ((commandLinePW = appClientCommandArgs.getPassword()) != null) { - pw = commandLinePW; - } - - builder.clientCredentials(user, pw); - } - - private static AppClientContainer createContainer(Builder builder, CommandLaunchInfo launchInfo, - AppclientCommandArguments appClientArgs) throws Exception, UserError { - - /* - * The launchInfo already knows something about how to conduct the launch. - */ - ClientLaunchType launchType = launchInfo.getClientLaunchType(); - AppClientContainer container; - - switch (launchType) { - case JAR: - case DIR: - /* - * The client name in the launch info is a file path for the directory or JAR to launch. - */ - container = createContainerForAppClientArchiveOrDir(builder, launchInfo.getClientName(), appClientArgs.getMainclass(), - appClientArgs.getName()); - break; - - case URL: - container = createContainerForJWSLaunch(builder, launchInfo.getClientName(), appClientArgs.getMainclass(), - appClientArgs.getName()); - break; - - case CLASS: - container = createContainerForClassName(builder, launchInfo.getClientName()); - break; - - case CLASSFILE: - container = createContainerForClassFile(builder, launchInfo.getClientName()); - break; - - default: - container = null; - } - - if (container == null) { - throw new IllegalArgumentException("cannot choose app client launch type"); - } - - return container; - } - - private static AppClientContainer createContainerForAppClientArchiveOrDir(Builder builder, String appClientPath, String mainClassName, String clientName) throws Exception, UserError { - return builder.newContainer(Util.getURI(new File(appClientPath)), null /* callbackHandler */, mainClassName, clientName, appClientCommandArgs.isTextauth()); - } - - private static AppClientContainer createContainerForJWSLaunch(Builder builder, String appClientPath, String mainClassName, String clientName) throws Exception, UserError { - return builder.newContainer(URI.create(appClientPath), null /* callbackHandler */, mainClassName, clientName); - } - - private static AppClientContainer createContainerForClassName(Builder builder, String className) throws Exception, UserError { - - /* - * Place "." on the class path so that when we convert the class file path to a fully-qualified class name and try to - * load it, we'll find it. - */ - - ClassLoader loader = prepareLoaderToFindClassFile(Thread.currentThread().getContextClassLoader()); - Thread.currentThread().setContextClassLoader(loader); - - return builder.newContainer(Class.forName(className, true, loader)); - } - - private static ClassLoader prepareLoaderToFindClassFile(final ClassLoader currentLoader) throws MalformedURLException { - File currentDirPath = new File(System.getProperty("user.dir")); - ClassLoader newLoader = new GlassfishUrlClassLoader(new URL[] { currentDirPath.toURI().toURL() }, currentLoader); - return newLoader; - } - - private static AppClientContainer createContainerForClassFile(Builder builder, String classFilePath) - throws MalformedURLException, ClassNotFoundException, FileNotFoundException, IOException, Exception, UserError { - - Util.verifyFilePath(classFilePath); - - /* - * Strip off the trailing .class from the path and convert separator characters to dots to build a fully-qualified class - * name. - */ - String className = classFilePath.substring(0, classFilePath.lastIndexOf(".class")).replace(File.separatorChar, '.'); - - return createContainerForClassName(builder, className); - } - - private static ClientContainer readConfig(final String configPath, final ClassLoader loader) throws UserError, JAXBException, - FileNotFoundException, ParserConfigurationException, SAXException, URISyntaxException, IOException { - ClientContainer result = null; - Reader configReader = null; - String configFileLocationForErrorMessage = ""; - try { - /* - * During a Java Web Start launch, the config is passed as a property value. - */ - String configInProperty = System.getProperty(ACC_CONFIG_CONTENT_PROPERTY_NAME); - if (configInProperty != null) { - /* - * Awkwardly, the glassfish-acc.xml content refers to a config file. We work around this for Java Web Start launch by - * capturing the content of that config file into a property setting in the generated JNLP document. We need to write - * that content into a temporary file here on the client and then replace a placeholder in the glassfish-acc.xml content - * with the path to that temp file. - */ - final File securityConfigTempFile = Util.writeTextToTempFile(configInProperty, "wss-client-config", ".xml", false); - final Properties p = new Properties(); - p.setProperty("security.config.path", securityConfigTempFile.getAbsolutePath()); - configInProperty = Util.replaceTokens(configInProperty, p); - configReader = new StringReader(configInProperty); - } else { - /* - * This is not a Java Web Start launch, so read the configuration from a disk file. - */ - File configFile = checkXMLFile(configPath); - checkXMLFile(appClientCommandArgs.getConfigFilePath()); - configReader = new FileReader(configFile); - configFileLocationForErrorMessage = configFile.getAbsolutePath(); - } - - /* - * Although JAXB makes it very simple to parse the XML into Java objects, we have to do several things explicitly to use - * our local copies of DTDs and XSDs. - */ - SAXParserFactory spf = SAXParserFactory.newInstance(); - spf.setValidating(true); - spf.setNamespaceAware(true); - SAXParser parser = spf.newSAXParser(); - XMLReader reader = parser.getXMLReader(); - - /* - * Get the local entity resolver that knows about the bundled .dtd and .xsd files. - */ - reader.setEntityResolver(new SaxParserHandlerBundled()); - - /* - * To support installation-directory independence the default glassfish-acc.xml refers to the wss-config file using - * ${com.sun.aas.installRoot}... So preprocess the glassfish-acc.xml file to replace any tokens with the corresponding - * values, then submit that result to JAXB. - */ - InputSource inputSource = replaceTokensForParsing(configReader); - - SAXSource saxSource = new SAXSource(reader, inputSource); - JAXBContext jc = JAXBContext.newInstance(ClientContainer.class); - final ValidationEventCollector vec = new ValidationEventCollector(); - - Unmarshaller u = jc.createUnmarshaller(); - u.setEventHandler(vec); - result = (ClientContainer) u.unmarshal(saxSource); - if (vec.hasEvents()) { - /* - * The parser reported at least one warning or error. If all events were warnings, display them as a message and - * continue. Otherwise there was at least one error or fatal, so say so and try to continue but say that such errors - * might be fatal in future releases. - */ - boolean isError = false; - final StringBuilder sb = new StringBuilder(); - for (ValidationEvent ve : vec.getEvents()) { - sb.append(ve.getMessage()).append(LINE_SEP); - isError |= (ve.getSeverity() != ValidationEvent.WARNING); - } - - String messageIntroduction = localStrings.getLocalString(AppClientFacade.class, - isError ? "appclient.errParsingConfig" : "appclient.warnParsingConfig", - isError ? "Error parsing app client container configuration {0}. Attempting to continue. In future releases such parsing errors might become fatal. Please correct your configuration file." - : "Warning(s) parsing app client container configuration {0}. Continuing.", - new Object[] { configFileLocationForErrorMessage }); - - System.err.println(messageIntroduction + LINE_SEP + sb.toString()); - } - - return result; - } finally { - if (configReader != null) { - configReader.close(); - } - } - } - - private static InputSource replaceTokensForParsing(final Reader reader) throws FileNotFoundException, IOException, URISyntaxException { - char[] buffer = new char[1024]; - - CharArrayWriter writer = new CharArrayWriter(); - int charsRead; - while ((charsRead = reader.read(buffer)) != -1) { - writer.write(buffer, 0, charsRead); - } - writer.close(); - reader.close(); - - Map mapping = new HashMap<>(); - Properties props = System.getProperties(); - for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { - String propName = (String) e.nextElement(); - mapping.put(propName, props.getProperty(propName)); - } - - TokenResolver resolver = new TokenResolver(mapping); - String configWithTokensReplaced = resolver.resolve(writer.toString()); - InputSource inputSource = new InputSource(new StringReader(configWithTokensReplaced)); - return inputSource; - } - - private static File checkXMLFile(String xmlFullName) throws UserError { - try { - File f = new File(xmlFullName); - if (f.exists() && f.isFile() && f.canRead()) { - return f; - } else {// If given file does not exists - xmlMessage(xmlFullName); - return null; - } } catch (Exception ex) { - xmlMessage(xmlFullName); - return null; + ex.printStackTrace(); + System.exit(1); } } - - private static void xmlMessage(String xmlFullName) throws UserError { - UserError ue = new UserError(localStrings.getLocalString(stringsAnchor, "main.cannot_read_clientContainer_xml", - "Client Container xml: {0} not found or unable to read.\nYou may want to use the -xml option to locate your configuration xml.", - new String[] { xmlFullName })); - ue.setUsage(getUsage()); - throw ue; - - } } diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/AppClientGroupFacade.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/AppClientGroupFacade.java index f1038d151d8..3e6556028c3 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/AppClientGroupFacade.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/AppClientGroupFacade.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -16,11 +17,23 @@ package org.glassfish.appclient.client; -import org.glassfish.appclient.client.acc.UserError; +import org.glassfish.appclient.client.acc.AppClientContainer; +import org.glassfish.embeddable.client.ApplicationClientClassLoader; +import org.glassfish.embeddable.client.UserError; /** + * The AppClientContainerAgent initializes instrumentation, class loaders and also + * the {@link AppClientContainer} instance, which must be reachable for this class then + * - and that was a problem. The solution is to "smuggle" the container using + * the class loader, which is the only thing which can be shared with the agent. + *

+ * With the usage of JPMS it got yet bit more complicated as we had to keep some order + * between classes and class loaders and we also noticed an issue with Windows which limit + * the length of the command line; therefore we introduced another layer which automatically + * detects some GlassFish's jar files and we don't need to add them to the -classpath argument. * * @author tjquinn + * @author David Matejcek */ public class AppClientGroupFacade { @@ -29,19 +42,14 @@ public class AppClientGroupFacade { */ public static void main(String[] args) { try { - if (AppClientFacade.acc() == null) { - /* - * The facade JAR has been run directly, not via the appclient script and not via Java Web Start. So we have no agent - * arguments and no instrumentation for registering transformations. - */ - AppClientFacade.prepareACC(null, null); - } - AppClientFacade.launch(args); + ApplicationClientClassLoader loader = (ApplicationClientClassLoader) Thread.currentThread() + .getContextClassLoader(); + loader.getApplicationClientContainer().launch(args); + } catch (UserError ue) { + ue.displayAndExit(); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); - } catch (UserError ue) { - ue.displayAndExit(); } } } diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/JWSACCMaskingClassLoader.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/JWSACCMaskingClassLoader.java index b2b9e521c97..5e4368c827a 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/JWSACCMaskingClassLoader.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/JWSACCMaskingClassLoader.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation * Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -42,7 +43,7 @@ class JWSACCMaskingClassLoader extends MaskingClassLoader { private final Collection endorsedPackagesToMask; JWSACCMaskingClassLoader(ClassLoader parent, Collection endorsedPackagesToMask) { - super(parent, Collections.EMPTY_SET /* punchins */, Collections.EMPTY_SET /* multiples */, + super(parent, Collections.emptySet() /* punchins */, Collections.emptySet() /* multiples */, false /* useExplicitCallsToFindSystemClass */); this.endorsedPackagesToMask = endorsedPackagesToMask; } diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/JWSAppClientContainerMain.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/JWSAppClientContainerMain.java index 2cbfa87b1dc..8845e183568 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/JWSAppClientContainerMain.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/JWSAppClientContainerMain.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -33,9 +34,9 @@ import javax.swing.SwingUtilities; -import org.glassfish.appclient.client.acc.UserError; import org.glassfish.appclient.client.jws.boot.ErrorDisplayDialog; import org.glassfish.appclient.client.jws.boot.LaunchSecurityHelper; +import org.glassfish.embeddable.client.UserError; /** * @@ -88,18 +89,14 @@ public static void main(String[] args) { try { now = System.currentTimeMillis(); - /* - * Process any arguments (conveyed as properties in the JNLP) intended for the JWS-aware ACC. - */ + // Process any arguments (conveyed as properties in the JNLP) intended for the JWS-aware ACC. processJWSArgs(); final String agentArgsText = System.getProperty("agent.args"); LaunchSecurityHelper.setPermissions(); - /* - * Prevent the Java Web Start class loader from delegating to its parent when resolving classes and resources that - * should come from the GlassFish-provided endorsed JARs. - */ + // Prevent the Java Web Start class loader from delegating to its parent when resolving + // classes and resources that should come from the GlassFish-provided endorsed JARs. insertMaskingLoader(); final ClientRunner runner = new ClientRunner(agentArgsText, args); @@ -133,8 +130,8 @@ private ClientRunner(final String agentArgsText, final String[] args) { @Override public void run() { try { - AppClientFacade.prepareACC(agentArgsText, null); - AppClientFacade.launch(args); + AppClientContainerHolder.init(agentArgsText, null); + AppClientContainerHolder.getInstance().launch(args); logger.log(Level.FINE, "JWSAppClientContainer finished after {0} ms", (System.currentTimeMillis() - now)); } catch (UserError ue) { if (!isTestMode()) { @@ -155,9 +152,7 @@ private static void insertMaskingLoader() throws IOException, NoSuchFieldExcepti props.load(sr); final ClassLoader jwsLoader = Thread.currentThread().getContextClassLoader(); - final ClassLoader mcl = getMaskingClassLoader(jwsLoader.getParent(), props); - final Field jwsLoaderParentField = ClassLoader.class.getDeclaredField("parent"); jwsLoaderParentField.setAccessible(true); jwsLoaderParentField.set(jwsLoader, mcl); diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/ACCStartupContext.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/ACCStartupContext.java index e6e4e6e77a1..b9b4cf304b4 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/ACCStartupContext.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/ACCStartupContext.java @@ -17,7 +17,6 @@ package org.glassfish.appclient.client.acc; -import com.sun.enterprise.glassfish.bootstrap.cfg.AsenvConf; import com.sun.enterprise.module.bootstrap.StartupContext; import com.sun.enterprise.util.io.FileUtils; @@ -26,10 +25,20 @@ import java.io.File; import java.net.URI; import java.net.URISyntaxException; +import java.util.Map; import java.util.Properties; +import org.glassfish.main.jdke.props.EnvToPropsConverter; import org.jvnet.hk2.annotations.Service; +import static com.sun.enterprise.util.SystemPropertyConstants.AGENT_ROOT_PROPERTY; +import static com.sun.enterprise.util.SystemPropertyConstants.CONFIG_ROOT_PROPERTY; +import static com.sun.enterprise.util.SystemPropertyConstants.DERBY_ROOT_PROPERTY; +import static com.sun.enterprise.util.SystemPropertyConstants.DOMAINS_ROOT_PROPERTY; +import static com.sun.enterprise.util.SystemPropertyConstants.IMQ_BIN_PROPERTY; +import static com.sun.enterprise.util.SystemPropertyConstants.IMQ_LIB_PROPERTY; +import static com.sun.enterprise.util.SystemPropertyConstants.INSTALL_ROOT_PROPERTY; +import static com.sun.enterprise.util.SystemPropertyConstants.JAVA_ROOT_PROPERTY_ASENV; /** * Start-up context for the ACC. Note that this context is used also for * Java Web Start launches. @@ -40,8 +49,6 @@ @Singleton public class ACCStartupContext extends StartupContext { - private static final String DERBY_ROOT_PROPERTY = "AS_DERBY_INSTALL"; - public ACCStartupContext() { super(accEnvironment()); } @@ -53,13 +60,20 @@ public ACCStartupContext() { * @return */ private static Properties accEnvironment() { - final Properties environment = AsenvConf.parseAsEnv(getRootDirectory()).toProperties(); - environment.setProperty("com.sun.aas.installRoot", getRootDirectory().getAbsolutePath()); - final File javadbDir = new File(getRootDirectory().getParentFile(), "javadb"); - if (javadbDir.isDirectory()) { - environment.setProperty(DERBY_ROOT_PROPERTY, javadbDir.getAbsolutePath()); - } - return environment; + final File rootDirectory = getRootDirectory(); + final Map pairs = Map.of( + "AS_DERBY_INSTALL", DERBY_ROOT_PROPERTY, + "AS_IMQ_LIB", IMQ_LIB_PROPERTY, + "AS_IMQ_BIN", IMQ_BIN_PROPERTY, + "AS_CONFIG", CONFIG_ROOT_PROPERTY, + "AS_INSTALL", INSTALL_ROOT_PROPERTY, + "AS_JAVA", JAVA_ROOT_PROPERTY_ASENV, + "AS_DEF_DOMAINS_PATH", DOMAINS_ROOT_PROPERTY, + "AS_DEF_NODES_PATH", AGENT_ROOT_PROPERTY); + Map files = new EnvToPropsConverter(rootDirectory.toPath()).convert(pairs); + Properties env = new Properties(); + files.entrySet().forEach(e -> env.put(e.getKey(), e.getValue().getPath())); + return env; } private static File getRootDirectory() { @@ -69,7 +83,7 @@ private static File getRootDirectory() { */ URI jarURI = null; try { - jarURI = ACCClassLoader.class.getProtectionDomain().getCodeSource().getLocation().toURI(); + jarURI = ACCStartupContext.class.getProtectionDomain().getCodeSource().getLocation().toURI(); } catch (URISyntaxException ex) { throw new RuntimeException(ex); } diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AgentArguments.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AgentArguments.java index a49e078f102..d9fc18e50d8 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AgentArguments.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AgentArguments.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -23,7 +24,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.glassfish.appclient.client.CLIBootstrap; +import org.glassfish.embeddable.client.ApplicationClientCLIEncoding; import static java.util.Collections.emptyList; import static java.util.regex.Pattern.DOTALL; @@ -103,10 +104,10 @@ private void scan(String args) { Matcher agentArgMatcher = agentArgPattern.matcher(args); while (agentArgMatcher.find()) { String keyword = agentArgMatcher.group(KEYWORD); - /* - * Either the quoted string group or the unquoted string group from the matcher will be valid. - */ - String value = CLIBootstrap.decodeArg(agentArgMatcher.group(QUOTED) != null ? agentArgMatcher.group(QUOTED) : agentArgMatcher.group(UNQUOTED)); + // Either the quoted string group or the unquoted string group from the matcher will be valid. + String value = ApplicationClientCLIEncoding.decodeArg(agentArgMatcher.group(QUOTED) == null + ? agentArgMatcher.group(UNQUOTED) + : agentArgMatcher.group(QUOTED)); values.computeIfAbsent(keyword, e -> new ArrayList<>()).add(value); } diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainer.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainer.java index b7f416f5efd..071b4ff6645 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainer.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation. + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation. * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -40,7 +40,8 @@ import java.lang.reflect.Modifier; import java.net.URI; import java.net.URL; -import java.net.URLClassLoader; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.text.MessageFormat; import java.util.Collection; import java.util.List; @@ -63,6 +64,8 @@ import org.glassfish.appclient.client.acc.config.Property; import org.glassfish.appclient.client.acc.config.Security; import org.glassfish.appclient.client.acc.config.TargetServer; +import org.glassfish.embeddable.client.ApplicationClientContainer; +import org.glassfish.embeddable.client.UserError; import org.glassfish.hk2.api.PerLookup; import org.glassfish.hk2.api.ServiceHandle; import org.glassfish.hk2.api.ServiceLocator; @@ -79,7 +82,7 @@ *

  • create a new builder for an ACC (see {@link #newBuilder} and {@link AppClientContainerBuilder}), *
  • optionally modify the configuration by invoking various builder methods, *
  • create an embedded instance of the ACC from the builder using {@link AppClientContainerBuilder#newContainer() }, - *
  • startClient the client using {@link #startClient(String[])}, and + *
  • startClient the client using {@link #launch(String[])}, and *
  • stop the container using {@link #stop()}. * * @@ -166,7 +169,7 @@ */ @Service @PerLookup -public class AppClientContainer { +public class AppClientContainer implements ApplicationClientContainer { // XXX move this /** Prop name for keeping temporary files */ @@ -194,20 +197,16 @@ public class AppClientContainer { @Inject private ServiceLocator habitat; - private Builder builder; - private Cleanup cleanup; - private State state = State.INSTANTIATED; // HK2 will create the instance + private volatile State state; private ClientMainClassSetting clientMainClassSetting; - private URLClassLoader classLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader(); + private TransformingClassLoader classLoader; private Launchable client; - private CallbackHandler callerSuppliedCallbackHandler; - /** returned from binding the app client to naming; used in preparing component invocation */ private String componentId; @@ -221,54 +220,32 @@ public static AppClientContainer.Builder newBuilder(final TargetServer[] targetS return new AppClientContainerBuilder(targetServers); } - /* - * ********************* ABOUT INITIALIZATION ******************** - * - * Note that, internally, the AppClientContainerBuilder's newContainer methods use HK2 to instantiate the - * AppClientContainer object (so we can inject references to various other services). - * - * The newContainer method then invokes one of the ACC's prepare methods to initialize the ACC fully. All - * that is left at that point is for the client's main method to be invoked. - * - */ - public void startClient(String[] args) throws Exception, UserError { - prepare(null); - launch(args); + private AppClientContainer() { + this.classLoader = (TransformingClassLoader) Thread.currentThread().getContextClassLoader(); + this.state = State.INSTANTIATED; } void prepareSecurity(final TargetServer[] targetServers, final List msgSecConfigs, final Properties containerProperties, final ClientCredential clientCredential, - final CallbackHandler callerSuppliedCallbackHandler, final URLClassLoader classLoader, final boolean isTextAuth) + final CallbackHandler callerSuppliedCallbackHandler, final boolean isTextAuth) throws ReflectiveOperationException, InjectionException, IOException, SAXException { - appClientContainerSecurityHelper.init(targetServers, msgSecConfigs, containerProperties, clientCredential, callerSuppliedCallbackHandler, classLoader, - client.getDescriptor(classLoader), isTextAuth); - } - - void setCallbackHandler(final CallbackHandler callerSuppliedCallbackHandler) { - this.callerSuppliedCallbackHandler = callerSuppliedCallbackHandler; - } - - void setBuilder(final Builder builder) { - this.builder = builder; + appClientContainerSecurityHelper.init(targetServers, msgSecConfigs, containerProperties, clientCredential, + callerSuppliedCallbackHandler, classLoader, client.getDescriptor(classLoader), isTextAuth); } - public void prepare(final Instrumentation inst) throws NamingException, IOException, InstantiationException, IllegalAccessException, - InjectionException, ClassNotFoundException, SAXException, NoSuchMethodException, UserError { + public void prepare(final Instrumentation inst) throws Exception, UserError { completePreparation(inst); } void setClient(final Launchable client) throws ClassNotFoundException { this.client = client; clientMainClassSetting = ClientMainClassSetting.set(client.getMainClass()); - } void processPermissions() throws IOException { // need to process the permissions files - if (classLoader instanceof ACCClassLoader) { - ((ACCClassLoader) classLoader).processDeclaredPermissions(); - } + classLoader.processDeclaredPermissions(); } protected Class loadClass(final String className) throws ClassNotFoundException { @@ -281,44 +258,37 @@ protected ClassLoader getClassLoader() { /** * Gets the ACC ready so the main class can run. This can be followed, immediately or after some time, by either an - * invocation of {@link #launch(java.lang.String[]) or by the JVM invoking the client's main method (as would happen + * invocation of {@link #launch(java.lang.String[])} + * @throws Exception or by the JVM invoking the client's main method (as would happen * during a java -jar theClient.jar launch. - * - * @throws java.lang.Exception + * @throws UserError */ - private void completePreparation(final Instrumentation inst) throws NamingException, IOException, InstantiationException, - IllegalAccessException, InjectionException, ClassNotFoundException, SAXException, NoSuchMethodException, UserError { + private void completePreparation(final Instrumentation inst) throws Exception, UserError { if (state != State.INSTANTIATED) { - throw new IllegalStateException(); + throw new IllegalStateException( + "Expected state was " + State.INSTANTIATED + ", but current state was " + state); } - /* - * Attach any names defined in the app client. Validate the descriptor first, then use it to bind names in the app - * client. This order is important - for example, to set up message destination refs correctly. - */ + // Attach any names defined in the app client. Validate the descriptor first, then use it to + // bind names in the app client. This order is important - for example, to set up message + // destination refs correctly. client.validateDescriptor(); final ApplicationClientDescriptor desc = client.getDescriptor(classLoader); componentId = componentEnvManager.bindToComponentNamespace(desc); - /* - * Arrange for cleanup now instead of during launch() because in some use cases the JVM will invoke the client's main - * method itself and launch will be skipped. - */ + // Arrange for cleanup now instead of during launch() because in some use cases the JVM will + // invoke the client's main method itself and launch will be skipped. cleanup = Cleanup.arrangeForShutdownCleanup(logger, habitat, desc); - /* - * Allow pre-destroy handling to work on the main class during clean-up. - */ + // Allow pre-destroy handling to work on the main class during clean-up. cleanup.setInjectionManager(injectionManager, ClientMainClassSetting.clientMainClass); - /* - * If this app client contains persistence unit refs, then initialize the PU handling. - */ + // If this app client contains persistence unit refs, then initialize the PU handling. Collection referencedPUs = desc.findReferencedPUs(); if (referencedPUs != null && !referencedPUs.isEmpty()) { - ProviderContainerContractInfoImpl pcci = new ProviderContainerContractInfoImpl((ACCClassLoader) getClassLoader(), inst, - client.getAnchorDir(), connectorRuntime); + ProviderContainerContractInfoImpl pcci = new ProviderContainerContractInfoImpl( + (TransformingClassLoader) getClassLoader(), inst, client.getAnchorDir(), connectorRuntime); for (PersistenceUnitDescriptor puDesc : referencedPUs) { PersistenceUnitLoader pul = new PersistenceUnitLoader(puDesc, pcci); desc.addEntityManagerFactory(puDesc.getName(), pul.getEMF()); @@ -340,47 +310,45 @@ private void completePreparation(final Instrumentation inst) throws NamingExcept managedBeanManager.loadManagedBeans(desc.getApplication()); cleanup.setManagedBeanManager(managedBeanManager); - /** - * We don't really need the main method here but we do need the side-effects. - */ + // We don't really need the main method here but we do need the side-effects. getMainMethod(); state = State.PREPARED; } - public void launch(String[] args) throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, - IllegalArgumentException, InvocationTargetException, IOException, SAXException, InjectionException, UserError { + public void launch(String[] args) throws UserError { if (state != State.PREPARED) { - throw new IllegalStateException(); - } - Method mainMethod = getMainMethod(); - // build args to the main and call it - Object params[] = new Object[1]; - params[0] = args; - - if (logger.isLoggable(Level.FINE)) { - dumpLoaderURLs(); + throw new IllegalStateException("Unexpected state. Expected " + State.PREPARED + ", actual is " + state); + } + Thread.currentThread().setContextClassLoader(classLoader); + try { + Method mainMethod = getMainMethod(); + // build args to the main and call it + if (logger.isLoggable(Level.FINE)) { + logger.log(Level.FINE, + "Current thread's classloader: " + Thread.currentThread().getContextClassLoader()); + } + mainMethod.invoke(null, new Object[] {args}); + state = State.STARTED; + } catch (InvocationTargetException e) { + if (e.getCause() instanceof UserError) { + throw (UserError) e.getCause(); + } + throw new IllegalStateException("Launch failed.", e.getCause()); + } catch (Exception e) { + throw new IllegalStateException("Launch failed.", e); + } finally { + // We need to clean up when the EDT ends or, if there is no EDT, right away. + // In particular, JMS/MQ-related non-daemon threads might still be running due to open + // queueing connections. + cleanupWhenSafe(); } - mainMethod.invoke(null, params); - state = State.STARTED; - - /* - * We need to clean up when the EDT ends or, if there is no EDT, right away. In particular, JMS/MQ-related non-daemon - * threads might still be running due to open queueing connections. - */ - cleanupWhenSafe(); } private boolean isEDTRunning() { - Map threads = java.security.AccessController - .doPrivileged(new java.security.PrivilegedAction>() { - - @Override - public Map run() { - return Thread.getAllStackTraces(); - } - }); + Map threads = AccessController + .doPrivileged((PrivilegedAction>) Thread::getAllStackTraces); logger.fine("Checking for EDT thread..."); for (Map.Entry entry : threads.entrySet()) { @@ -402,38 +370,18 @@ private void cleanupWhenSafe() { if (isEDTRunning()) { final AtomicReference edt = new AtomicReference<>(); try { - SwingUtilities.invokeAndWait(new Runnable() { - @Override - public void run() { - edt.set(Thread.currentThread()); - } - }); + SwingUtilities.invokeAndWait(() -> edt.set(Thread.currentThread())); edt.get().join(); } catch (Exception e) { - + logger.log(Level.WARNING, "Waiting for Swing thread failed.", e); } } stop(); } - private void dumpLoaderURLs() { - final String sep = System.lineSeparator(); - final ClassLoader ldr = Thread.currentThread().getContextClassLoader(); - if (ldr instanceof ACCClassLoader) { - final ACCClassLoader loader = (ACCClassLoader) ldr; - final URL[] urls = loader.getURLs(); - - final StringBuilder sb = new StringBuilder("Class loader URLs:"); - for (URL url : urls) { - sb.append(" ").append(url.toExternalForm()).append(sep); - } - sb.append(sep); - logger.fine(sb.toString()); - } - } private Method getMainMethod() - throws NoSuchMethodException, ClassNotFoundException, IOException, SAXException, InjectionException, UserError { + throws UserError, ReflectiveOperationException, InjectionException, IOException, SAXException { // determine the main method using reflection // verify that it is public static void and takes // String[] as the only argument @@ -459,28 +407,25 @@ private Method getMainMethod() return result; } + /** * Stops the app client container. *

    - * Note that the calling program should not stop the ACC if there might be other threads running, such as the Swing - * event dispatcher thread. Stopping the ACC can shut down various services that those continuing threads might try to - * use. + * Note that the calling program should not stop the ACC if there might be other threads + * running, such as the Swing event dispatcher thread. Stopping the ACC can shut down various + * services that those continuing threads might try to use. *

    - * Also note that stopping the ACC will have no effect on any thread that the app client itself might have created. If - * the calling program needs to control such threads it and the client code running in the threads should agree on how - * they will communicate with each other. The ACC cannot help with this. + * Also note that stopping the ACC will have no effect on any thread that the app client itself + * might have created. If the calling program needs to control such threads it and the client + * code running in the threads should agree on how they will communicate with each other. + * The ACC cannot help with this. */ public void stop() { - /* - * Because stop can be invoked automatically at the end of launch, allow the developer's driver program to invoke stop - * again without penalty. - */ + // Because stop can be invoked automatically at the end of launch, allow the developer's + // driver program to invoke stop again without penalty. if (state == State.STOPPED) { return; } - if (state != State.STARTED) { - throw new IllegalStateException(); - } cleanup.start(); state = State.STOPPED; } @@ -493,7 +438,7 @@ enum ClientMainClassSetting { static String clientMainClassName; static volatile Class clientMainClass; - static boolean isInjected = false; + static boolean isInjected; static ClientMainClassSetting set(final String name) { clientMainClassName = name; @@ -515,12 +460,11 @@ static Class getClientMainClass(final ClassLoader loader, InjectionManager injec throw new IllegalStateException("neither client main class nor its class name has been set"); } clientMainClass = Class.forName(clientMainClassName, true, loader); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "Loaded client main class {0}", clientMainClassName); - } + logger.log(Level.FINE, "Loaded client main class {0}", clientMainClassName); } - ComponentInvocation ci = new ComponentInvocation(componentId, ComponentInvocation.ComponentInvocationType.APP_CLIENT_INVOCATION, - container, acDesc.getApplication().getAppName(), acDesc.getModuleName()); + ComponentInvocation ci = new ComponentInvocation(componentId, + ComponentInvocation.ComponentInvocationType.APP_CLIENT_INVOCATION, container, + acDesc.getApplication().getAppName(), acDesc.getModuleName()); invocationManager.preInvoke(ci); InjectionException injExc = null; @@ -603,7 +547,7 @@ enum State { * EAR that contains multiple app clients as submodules within it; the ACC needs the calling program to specify which of * the possibly several app client modules is the one to execute. * - * @param mainClassName + * @param clientMainClassName * @return */ public void setClientMainClassName(final String clientMainClassName) throws ClassNotFoundException { @@ -621,22 +565,17 @@ void setClientMainClass(final Class clientMainClass) { */ private static void prepareURLStreamHandling() { // Set the HTTPS URL stream handler. - java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() { - @Override - public Object run() { - URL.setURLStreamHandlerFactory(new DirContextURLStreamHandlerFactory()); - return null; - } - }); + PrivilegedAction action = () -> { + URL.setURLStreamHandlerFactory(new DirContextURLStreamHandlerFactory()); + return null; + }; + AccessController.doPrivileged(action); } - void setClassLoader(ACCClassLoader classLoader) { - this.classLoader = classLoader; - } /** - * Prescribes the exposed behavior of ACC configuration that can be set up further, and can be used to newContainer an - * ACC. + * Prescribes the exposed behavior of ACC configuration that can be set up further, and can be + * used to newContainer an ACC. */ public interface Builder { diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerBuilder.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerBuilder.java index d65a66c207c..725fce7617b 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerBuilder.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -18,11 +18,11 @@ package org.glassfish.appclient.client.acc; import com.sun.enterprise.container.common.spi.util.InjectionException; -import com.sun.enterprise.module.bootstrap.BootException; import com.sun.enterprise.util.LocalStringManager; import com.sun.enterprise.util.LocalStringManagerImpl; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.net.URISyntaxException; import java.net.URLClassLoader; @@ -39,6 +39,7 @@ import org.glassfish.appclient.client.acc.config.Property; import org.glassfish.appclient.client.acc.config.TargetServer; import org.glassfish.appclient.client.acc.config.util.XML; +import org.glassfish.embeddable.client.UserError; import org.glassfish.enterprise.iiop.api.GlassFishORBHelper; import org.xml.sax.SAXException; @@ -69,12 +70,13 @@ public class AppClientContainerBuilder implements AppClientContainer.Builder { private static final LocalStringManager localStrings = new LocalStringManagerImpl(AppClientContainerBuilder.class); + private final URLClassLoader classLoader; + /** caller-specified target servers */ private TargetServer[] targetServers; private AuthRealm authRealm; - private final URLClassLoader classLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader(); /** * The caller can pre-set the client credentials using the clientCredentials method. The ACC will use the @@ -95,10 +97,6 @@ public class AppClientContainerBuilder implements AppClientContainer.Builder { */ private Properties containerProperties; - AppClientContainerBuilder() { - - } - /** * Creates a new builder with the specified target servers and client URI. * @@ -107,6 +105,7 @@ public class AppClientContainerBuilder implements AppClientContainer.Builder { */ AppClientContainerBuilder(final TargetServer[] targetServers) { this.targetServers = targetServers; + this.classLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader(); } public AppClientContainer newContainer(final Class mainClass, final CallbackHandler callerSpecifiedCallbackHandler) throws Exception { @@ -155,27 +154,27 @@ public AppClientContainer newContainer(final URI clientURI) throws Exception, Us private AppClientContainer createContainer(final Launchable client, final CallbackHandler callerSuppliedCallbackHandler, final boolean isTextAuth) - throws BootException, URISyntaxException, ReflectiveOperationException, InjectionException, IOException, SAXException { + throws ReflectiveOperationException, InjectionException, IOException, SAXException { AppClientContainer container = ACCModulesManager.getService(AppClientContainer.class); // process the packaged permissions.xml container.processPermissions(); container.setClient(client); - container.setBuilder(this); - CallbackHandler callbackHandler = (callerSuppliedCallbackHandler != null ? callerSuppliedCallbackHandler - : getCallbackHandlerFromDescriptor(client.getDescriptor(classLoader).getCallbackHandler())); - container.prepareSecurity(targetServers, messageSecurityConfigs, containerProperties, clientCredential, callbackHandler, - classLoader, isTextAuth); + CallbackHandler callbackHandler = callerSuppliedCallbackHandler == null + ? getCallbackHandlerFromDescriptor(client.getDescriptor(classLoader).getCallbackHandler()) + : callerSuppliedCallbackHandler; + container.prepareSecurity(targetServers, messageSecurityConfigs, containerProperties, clientCredential, + callbackHandler, isTextAuth); return container; } private CallbackHandler getCallbackHandlerFromDescriptor(final String callbackHandlerName) - throws ClassNotFoundException, InstantiationException, IllegalAccessException { + throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException { if (callbackHandlerName != null && !callbackHandlerName.equals("")) { Class callbackHandlerClass = (Class) Class.forName(callbackHandlerName, true, classLoader); - return callbackHandlerClass.newInstance(); + return callbackHandlerClass.getDeclaredConstructor().newInstance(); } return null; diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerSecurityHelper.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerSecurityHelper.java index 1720cab8de1..03f967dd75f 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerSecurityHelper.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerSecurityHelper.java @@ -66,7 +66,7 @@ void init(final TargetServer[] targetServers, final List final ApplicationClientDescriptor acDesc, final boolean isTextAuth) throws ReflectiveOperationException, InjectionException, IOException { - this.classLoader = (classLoader == null) ? Thread.currentThread().getContextClassLoader() : classLoader; + this.classLoader = classLoader; initLoginConfig(); CallbackHandler callbackHandler = initSecurity(callerSuppliedCallbackHandler, acDesc); @@ -105,7 +105,7 @@ private void initLoginConfig() throws IOException { * config file contains a blank then ConfigFile class expects the URL to contain a blank, not %20 for example. So, we * need to use the deprecated File.toURL() method to create such a URL. */ - System.setProperty("java.security.auth.login.config", configFile.toURL().toString()); + System.setProperty("java.security.auth.login.config", configFile.toURI().toURL().toString()); } /** diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppclientCommandArguments.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppclientCommandArguments.java index 62a74159860..84c2e77b997 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppclientCommandArguments.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppclientCommandArguments.java @@ -35,6 +35,8 @@ import java.util.logging.Level; import java.util.logging.Logger; +import org.glassfish.embeddable.client.UserError; + /** * Encapsulates handling of appclient script command arguments and options. *

    diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/CommandLaunchInfo.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/CommandLaunchInfo.java index 5f036684141..16815de9a9e 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/CommandLaunchInfo.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/CommandLaunchInfo.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -48,29 +49,16 @@ public class CommandLaunchInfo { /* records the client JAR file path, directory path, class name, or class file path */ private String clientName; - private String appcPath = null; - -// /** -// * Creates and returns a new CommandLaunchInfo instance. -// *

    -// * Typically the caller is the agent which will pass the agent arguments -// * it received when the VM invoked its premain method. -// * -// * @param agentArgs string of agent arguments -// * @return new CommandLaunchInfo object -// */ -// public static CommandLaunchInfo newInstance(final String agentArgs) throws UserError { -// CommandLaunchInfo result = new CommandLaunchInfo(agentArgs); -// return result; -// } - - public static CommandLaunchInfo newInstance(final AgentArguments agentArgs) throws UserError { + private String appcPath; + + + public static CommandLaunchInfo newInstance(final AgentArguments agentArgs) { final CommandLaunchInfo result = new CommandLaunchInfo(agentArgs); return result; } - private CommandLaunchInfo(final AgentArguments agentArgs) throws UserError { + private CommandLaunchInfo(final AgentArguments agentArgs) { clientLaunchType = saveArgInfo(agentArgs); } @@ -98,8 +86,7 @@ public String getAppcPath() { return appcPath; } - private ClientLaunchType saveArgInfo( - final AgentArguments agentArgs) throws UserError { + private ClientLaunchType saveArgInfo(final AgentArguments agentArgs) { if (agentArgs == null){ return ClientLaunchType.UNKNOWN; } @@ -117,7 +104,7 @@ private ClientLaunchType saveArgInfo( } private String lastFromList(final List list) { - return (list.isEmpty() ? null : list.get(list.size() - 1)); + return list.isEmpty() ? null : list.get(list.size() - 1); } private ClientLaunchType processClientArg(final String clientSpec) { @@ -132,9 +119,7 @@ private ClientLaunchType processClientArg(final String clientSpec) { if (clientName.startsWith("\"") && clientName.endsWith("\"")) { clientName = clientName.substring(1, clientName.length() - 1); } - ClientLaunchType type = ClientLaunchType.byType(clientType); - - return type; + return ClientLaunchType.byType(clientType); } private void processAppcPath(final String appcPath) { diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/FacadeLaunchable.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/FacadeLaunchable.java index e6a6bb66da6..f3818b51ed8 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/FacadeLaunchable.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/FacadeLaunchable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -46,6 +46,7 @@ import org.glassfish.api.deployment.archive.ReadableArchive; import org.glassfish.appclient.common.ACCAppClientArchivist; +import org.glassfish.embeddable.client.UserError; import org.glassfish.hk2.api.ServiceLocator; import org.xml.sax.SAXException; @@ -267,15 +268,8 @@ public ApplicationClientDescriptor getDescriptor(final URLClassLoader loader) th */ archivist.setAnnotationProcessingRequested( ! isJWSLaunch); - final ACCClassLoader tempLoader = AccessController.doPrivileged(new PrivilegedAction() { - - @Override - public ACCClassLoader run() { - return new ACCClassLoader(loader.getURLs(), loader.getParent()); - } - - }); - + PrivilegedAction action = () -> new TransformingClassLoader(loader.getURLs(), loader.getParent()); + final TransformingClassLoader tempLoader = AccessController.doPrivileged(action); archivist.setClassLoader(tempLoader); diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/JWSACCClassLoader.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/JWSACCClassLoader.java index ff5f2f07e2e..b058a506a94 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/JWSACCClassLoader.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/JWSACCClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -22,15 +22,18 @@ import java.security.PermissionCollection; import org.glassfish.appclient.common.ClientClassLoaderDelegate; -import org.glassfish.common.util.GlassfishUrlClassLoader; +import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; public class JWSACCClassLoader extends GlassfishUrlClassLoader { + static { + registerAsParallelCapable(); + } + private final ClientClassLoaderDelegate clientCLDelegate; public JWSACCClassLoader(URL[] urls, ClassLoader parent) { - super(urls, parent); - + super("JWS-ACC", urls, parent); clientCLDelegate = new ClientClassLoaderDelegate(this); } diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/Launchable.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/Launchable.java index 6632b10c2db..4eafbfdad61 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/Launchable.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/Launchable.java @@ -34,6 +34,7 @@ import javax.xml.stream.XMLStreamException; import org.glassfish.api.deployment.archive.ReadableArchive; +import org.glassfish.embeddable.client.UserError; import org.glassfish.hk2.api.ServiceLocator; import org.xml.sax.SAXException; @@ -104,9 +105,9 @@ static Launchable newLaunchable(final URI uri, * ACCClassLoader instance yet. Create one if needed * before proceeding. */ - ACCClassLoader cl = ACCClassLoader.instance(); + TransformingClassLoader cl = TransformingClassLoader.instance(); if (cl == null) { - cl = ACCClassLoader.newInstance(Thread.currentThread().getContextClassLoader(), false); + cl = TransformingClassLoader.newInstance(Thread.currentThread().getContextClassLoader(), false); } cl.appendURL(clientOrFacadeURL); } @@ -122,15 +123,8 @@ static ApplicationClientDescriptor openWithAnnoProcessingAndTempLoader( final ReadableArchive facadeRA, final ReadableArchive clientRA) throws IOException, SAXException { archivist.setAnnotationProcessingRequested(true); - final ACCClassLoader tempLoader = AccessController.doPrivileged( - new PrivilegedAction() { - - @Override - public ACCClassLoader run() { - return new ACCClassLoader(loader.getURLs(), loader.getParent()); - } - } - ); + PrivilegedAction action = () -> new TransformingClassLoader(loader.getURLs(), loader.getParent()); + final TransformingClassLoader tempLoader = AccessController.doPrivileged(action); archivist.setClassLoader(tempLoader); final ApplicationClientDescriptor acDesc = archivist.open(facadeRA, clientRA); diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/LocalStrings.properties b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/LocalStrings.properties index 21ec1154e4e..537af995688 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/LocalStrings.properties +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/LocalStrings.properties @@ -75,7 +75,3 @@ appclient.cannotOpenModuleManifest=Error opening manifest for module {0} appclient.cannotCloseModuleManifest=Error closing manifest for module {0} appclient.multClientsNoChoice=The application contains multiple app clients; please choose one using -mainclass {0} or -name {1} appclient.missingValue=Value for {0} expected but was not configured or assigned - -main.usage=Usage :\n\tappclient [ | -client ] \n\t\t[-mainclass |-name ] \n\t\t[-xml ] \n\t\t[-textauth] [-user ] [-password |-passwordfile ] \n\t\t[-targetserver host[:port][,host[:port]...] \n\t\t[app-args] -main.usage.1=or :\n\tappclient [ ]\n\t\t[ | -jar ] \n\t\t[app args] -main.badVersion=Current Java version {0} is too low; {1} or later required diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/MainClassLaunchable.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/MainClassLaunchable.java index 9ae37b1ceed..a65bf0f7f0e 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/MainClassLaunchable.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/MainClassLaunchable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -33,6 +33,7 @@ import java.net.URLClassLoader; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.Objects; import java.util.jar.Attributes; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; @@ -71,8 +72,8 @@ public ApplicationClientDescriptor getDescriptor(final URLClassLoader loader) th // There is no developer-provided descriptor possible so just use a default one. if (acDesc == null) { ReadableArchive tempArchive = null; - PrivilegedAction action = () -> new ACCClassLoader(loader.getURLs(), loader.getParent()); - final ACCClassLoader tempLoader = AccessController.doPrivileged(action); + PrivilegedAction action = () -> new TransformingClassLoader(loader.getURLs(), loader.getParent()); + final TransformingClassLoader tempLoader = AccessController.doPrivileged(action); tempArchive = createArchive(tempLoader, mainClass); final AppClientArchivist acArchivist = getArchivist(tempArchive, tempLoader); archivist.setClassLoader(tempLoader); @@ -109,9 +110,10 @@ private ReadableArchive createArchive(final ClassLoader loader, final Class m final ZipEntry mainClassEntry = new ZipEntry(mainClassResourceName); jos.putNextEntry(mainClassEntry); InputStream is = loader.getResourceAsStream(mainClassResourceName); + Objects.requireNonNull(is, "Resource not found " + mainClassResourceName + " by class loader " + loader); int bytesRead; - byte[] buffer = new byte[1024]; - while ( (bytesRead = is.read(buffer)) != -1) { + byte[] buffer = new byte[4096]; + while ((bytesRead = is.read(buffer)) != -1) { jos.write(buffer, 0, bytesRead); } is.close(); @@ -119,12 +121,9 @@ private ReadableArchive createArchive(final ClassLoader loader, final Class m jos.close(); MemoryMappedArchive mma = new MemoryMappedArchive(baos.toByteArray()); - /* - * Some archive-related processing looks for the file type from the URI, so set it - * to something. - */ + // Some archive-related processing looks for the file type from the URI, + // so set it to something. mma.setURI(URI.create("file:///tempClient.jar")); - return mma; } diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/ProviderContainerContractInfoImpl.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/ProviderContainerContractInfoImpl.java index edcec40f09e..2649b8a97d7 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/ProviderContainerContractInfoImpl.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/ProviderContainerContractInfoImpl.java @@ -36,8 +36,8 @@ import org.glassfish.api.deployment.DeploymentContext; import org.glassfish.api.naming.SimpleJndiName; -import org.glassfish.common.util.GlassfishUrlClassLoader; import org.glassfish.deployment.common.RootDeploymentDescriptor; +import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; import org.glassfish.persistence.jpa.ProviderContainerContractInfoBase; /** @@ -48,7 +48,7 @@ */ public class ProviderContainerContractInfoImpl extends ProviderContainerContractInfoBase { - private final ACCClassLoader classLoader; + private final TransformingClassLoader classLoader; private final Instrumentation inst; private final String applicationLocation; @@ -63,7 +63,7 @@ public class ProviderContainerContractInfoImpl extends ProviderContainerContract * @param inst VM's instrumentation object */ public ProviderContainerContractInfoImpl( - final ACCClassLoader classLoader, + final TransformingClassLoader classLoader, final Instrumentation inst, final String applicationLocation, final ConnectorRuntime connectorRuntime) { @@ -80,7 +80,8 @@ public ClassLoader getClassLoader() { @Override public ClassLoader getTempClassloader() { - PrivilegedAction action = () -> new GlassfishUrlClassLoader(classLoader.getURLs()); + PrivilegedAction action = () -> new GlassfishUrlClassLoader("PersistenceTmp", + classLoader.getURLs()); return AccessController.doPrivileged(action); } diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/TargetServerHelper.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/TargetServerHelper.java index 4d005ff89b3..0eb9b55cb00 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/TargetServerHelper.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/TargetServerHelper.java @@ -23,6 +23,7 @@ import org.glassfish.appclient.client.acc.config.Property; import org.glassfish.appclient.client.acc.config.Security; import org.glassfish.appclient.client.acc.config.TargetServer; +import org.glassfish.embeddable.client.UserError; import org.glassfish.enterprise.iiop.api.GlassFishORBHelper; /** diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/TestMain.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/TestMain.java index 05aa7820b9f..f78fba3b5aa 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/TestMain.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/TestMain.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to Eclipse Foundation. * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -17,27 +18,19 @@ package org.glassfish.appclient.client.acc; /** - * * @author tjquinn */ public class TestMain { private static final String JAR_CLIENT_NAME = "there/myClient.jar"; - private static final String DIR_CLIENT_NAME = "here/myClient"; private static final String USER_VALUE = "joe-the-user"; - private static final String PASSWORDFILE_NAME = "topSecret.stuff"; /** * @param args the command line arguments */ public static void main(String[] args) { - try { - final AgentArguments agentArgs = AgentArguments.newInstance( - "mode=acscript" + ",client=jar=" + JAR_CLIENT_NAME + ",arg=-textauth" + ",arg=-user,arg=" + USER_VALUE); - CommandLaunchInfo.newInstance(agentArgs); - } catch (UserError ex) { - System.err.println(ex.getLocalizedMessage()); - - } + final AgentArguments agentArgs = AgentArguments.newInstance( + "mode=acscript" + ",client=jar=" + JAR_CLIENT_NAME + ",arg=-textauth" + ",arg=-user,arg=" + USER_VALUE); + CommandLaunchInfo.newInstance(agentArgs); } } diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/ACCClassLoader.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/TransformingClassLoader.java similarity index 57% rename from appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/ACCClassLoader.java rename to appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/TransformingClassLoader.java index 72031f4f5c7..c2013ef1f27 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/ACCClassLoader.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/TransformingClassLoader.java @@ -1,7 +1,6 @@ /* - * Copyright (c) 2021, 2023 Contributors to Eclipse Foundation. + * Copyright (c) 2021, 2024 Contributors to Eclipse Foundation. * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2022 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -22,11 +21,14 @@ import com.sun.enterprise.util.io.FileUtils; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.IllegalClassFormatException; +import java.net.MalformedURLException; import java.net.URL; +import java.nio.file.Path; import java.security.CodeSource; import java.security.PermissionCollection; import java.security.PrivilegedAction; @@ -35,11 +37,13 @@ import java.util.Collections; import java.util.Enumeration; import java.util.List; -import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Stream; -import org.glassfish.appclient.common.ClassPathUtils; import org.glassfish.appclient.common.ClientClassLoaderDelegate; -import org.glassfish.common.util.GlassfishUrlClassLoader; +import org.glassfish.embeddable.client.ApplicationClientClassLoader; +import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; import static java.security.AccessController.doPrivileged; @@ -48,79 +52,64 @@ * * @author tjquinn */ -public class ACCClassLoader extends GlassfishUrlClassLoader { +public class TransformingClassLoader extends GlassfishUrlClassLoader { - private static final String AGENT_LOADER_CLASS_NAME = "org.glassfish.appclient.client.acc.agent.ACCAgentClassLoader"; - private static ACCClassLoader instance; + static { + registerAsParallelCapable(); + } + + private static final Function PATH_TO_URL = p -> { + try { + return p.toUri().toURL(); + } catch (MalformedURLException e) { + throw new IllegalStateException("Could not convert path to url: " + p, e); + } + }; - private ACCClassLoader shadow; - private boolean shouldTransform; + private static TransformingClassLoader instance; - private final List transformers = Collections.synchronizedList(new ArrayList()); + private TransformingClassLoader shadow; + private final boolean shouldTransform; + private final List transformers = Collections.synchronizedList(new ArrayList<>()); private ClientClassLoaderDelegate clientCLDelegate; - public static synchronized ACCClassLoader newInstance(ClassLoader parent, boolean shouldTransform) { + /** + * @param parent + * @param shouldTransform + * @return new class loader + * @throws IllegalStateException + * @throws IllegalArgumentException + */ + public static synchronized TransformingClassLoader newInstance(ClassLoader parent, boolean shouldTransform) { if (instance != null) { - throw new IllegalStateException("already set"); + throw new IllegalStateException("Already set"); } - - ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); - boolean currentCLWasAgentCL = currentClassLoader.getClass().getName().equals(AGENT_LOADER_CLASS_NAME); - ClassLoader parentForACCCL = currentCLWasAgentCL ? currentClassLoader.getParent() : currentClassLoader; - - PrivilegedAction action = () -> { - URL[] classpath = ClassPathUtils.getJavaClassPathForAppClient(); - return new ACCClassLoader(classpath, parentForACCCL, shouldTransform); + PrivilegedAction action = () -> { + return parent instanceof ApplicationClientClassLoader + // Parent already comes with user dependencies + ? new TransformingClassLoader(new URL[0], parent, shouldTransform) + // Otherwise adopt system class path, environment options, whatever. + : new TransformingClassLoader(createClassPath(), parent, shouldTransform); }; instance = doPrivileged(action); - - if (currentCLWasAgentCL) { - try { - adjustACCAgentClassLoaderParent(instance); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - return instance; } - public static ACCClassLoader instance() { + public static TransformingClassLoader instance() { return instance; } - private static void adjustACCAgentClassLoaderParent(ACCClassLoader instance) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { - ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); - - if (systemClassLoader.getClass().getName().equals(AGENT_LOADER_CLASS_NAME)) { - if (systemClassLoader instanceof Consumer) { - - @SuppressWarnings("unchecked") - Consumer consumerOfClassLoader = (Consumer) systemClassLoader; - - consumerOfClassLoader.accept(instance); - - System.setProperty("org.glassfish.appclient.acc.agentLoaderDone", "true"); - } - } - } - - - public ACCClassLoader(ClassLoader parent, final boolean shouldTransform) { - super(new URL[0], parent); + private TransformingClassLoader(URL[] classpath, ClassLoader parent, boolean shouldTransform) { + super("Transformer", classpath, parent); this.shouldTransform = shouldTransform; - clientCLDelegate = new ClientClassLoaderDelegate(this); - } - - public ACCClassLoader(URL[] urls, ClassLoader parent) { - super(urls, parent); - clientCLDelegate = new ClientClassLoaderDelegate(this); + this.clientCLDelegate = new ClientClassLoaderDelegate(this); } - private ACCClassLoader(URL[] urls, ClassLoader parent, boolean shouldTransform) { - this(urls, parent); - this.shouldTransform = shouldTransform; + public TransformingClassLoader(URL[] urls, ClassLoader parent) { + super("Transformer", urls, parent); + this.shouldTransform = false; + this.clientCLDelegate = new ClientClassLoaderDelegate(this); } public synchronized void appendURL(final URL url) { @@ -134,21 +123,11 @@ public void addTransformer(final ClassFileTransformer xf) { transformers.add(xf); } - public void setShouldTransform(final boolean shouldTransform) { - this.shouldTransform = shouldTransform; - } - - synchronized ACCClassLoader shadow() { + synchronized TransformingClassLoader shadow() { if (shadow == null) { - shadow = doPrivileged(new PrivilegedAction() { - @Override - public ACCClassLoader run() { - return new ACCClassLoader(getURLs(), getParent()); - } - - }); + PrivilegedAction action = () -> new TransformingClassLoader(getURLs(), getParent()); + shadow = doPrivileged(action); } - return shadow; } @@ -215,15 +194,27 @@ public void processDeclaredPermissions() throws IOException { @Override public Enumeration getResources(String name) throws IOException { - final ResourceLocator locator = new ResourceLocator(this, getParentClassLoader(), true); + final ResourceLocator locator = new ResourceLocator(this, getParent(), true); return locator.getResources(name); } - private ClassLoader getParentClassLoader() { - final ClassLoader parent = getParent(); - if (parent == null) { - return getSystemClassLoader(); + private static URL[] createClassPath() { + final Stream cpPaths = convertClassPathToPaths(System.getProperty("java.class.path")); + final Stream envPaths = convertClassPathToPaths(System.getenv("APPCPATH")); + final Predicate filterOutGfClient = f -> !f.endsWith(Path.of("gf-client.jar")); + return Stream.concat(cpPaths, envPaths).map(Path::toAbsolutePath).map(Path::normalize).distinct() + .filter(filterOutGfClient).map(PATH_TO_URL).toArray(URL[]::new); + } + + private static Stream convertClassPathToPaths(final String classPath) { + if (classPath == null || classPath.isBlank()) { + return Stream.empty(); + } + try { + return Stream.of(classPath.split(File.pathSeparator)).map(File::new).map(File::toPath); + } catch (Exception e) { + throw new IllegalArgumentException("Could not parse the classpath: " + classPath, e); } - return parent; } + } diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/UndeployedLaunchable.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/UndeployedLaunchable.java index 1ba734d65d0..d945b3aa510 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/UndeployedLaunchable.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/UndeployedLaunchable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -25,7 +25,6 @@ import com.sun.enterprise.deployment.archivist.Archivist; import com.sun.enterprise.deployment.archivist.ArchivistFactory; import com.sun.enterprise.deployment.util.DOLUtils; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import java.io.IOException; import java.net.URI; @@ -39,7 +38,9 @@ import org.glassfish.api.deployment.archive.ReadableArchive; import org.glassfish.deployment.common.ModuleDescriptor; import org.glassfish.deployment.common.RootDeploymentDescriptor; +import org.glassfish.embeddable.client.UserError; import org.glassfish.hk2.api.ServiceLocator; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import org.xml.sax.SAXException; @@ -77,8 +78,7 @@ static UndeployedLaunchable newUndeployedLaunchable( */ Archivist archivist = af.getArchivist("car", classLoader); if (archivist == null) { - throw new UserError(localStrings.get("appclient.invalidArchive", - ra.getURI().toASCIIString())); + throw new UserError(localStrings.get("appclient.invalidArchive", ra.getURI().toASCIIString())); } final ArchiveType moduleType = archivist.getModuleType(); @@ -227,14 +227,8 @@ private String extractMainClassFromArchive(final ReadableArchive clientRA) throw public ApplicationClientDescriptor getDescriptor(final URLClassLoader loader) throws IOException, SAXException { this.classLoader = loader; if (acDesc == null) { - final AppClientArchivist _archivist = getArchivist( - AccessController.doPrivileged(new PrivilegedAction() { - - @Override - public ACCClassLoader run() { - return new ACCClassLoader(loader.getURLs(), loader.getParent()); - } - })); + PrivilegedAction action = () -> new TransformingClassLoader(loader.getURLs(), loader.getParent()); + final AppClientArchivist _archivist = getArchivist(AccessController.doPrivileged(action)); _archivist.setAnnotationProcessingRequested(true); acDesc = _archivist.open(clientRA); diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/callbackhandler/DefaultGUICallbackHandler.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/callbackhandler/DefaultGUICallbackHandler.java index 7127d412357..2f6756ede62 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/callbackhandler/DefaultGUICallbackHandler.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/callbackhandler/DefaultGUICallbackHandler.java @@ -17,7 +17,6 @@ package org.glassfish.appclient.client.acc.callbackhandler; import com.sun.enterprise.security.GUILoginDialog; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import java.io.IOException; @@ -25,6 +24,7 @@ import javax.security.auth.callback.UnsupportedCallbackException; import org.glassfish.appclient.client.acc.callbackhandler.CallbackGUIBindings.MessageType; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Example callback handler for displaying and gathering information from the diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/jws/boot/ErrorDisplayDialog.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/jws/boot/ErrorDisplayDialog.java index 677cdeb5d41..9f590a41b2f 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/jws/boot/ErrorDisplayDialog.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/jws/boot/ErrorDisplayDialog.java @@ -29,7 +29,7 @@ import javax.swing.JScrollPane; import javax.swing.JTextArea; -import org.glassfish.appclient.client.acc.UserError; +import org.glassfish.embeddable.client.UserError; /** * Displays errors detected after Java Web Start has launched the diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/jws/boot/JWSACCMain.java b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/jws/boot/JWSACCMain.java index 9a73e1c9a56..858fc519c34 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/jws/boot/JWSACCMain.java +++ b/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/jws/boot/JWSACCMain.java @@ -1,6 +1,6 @@ /* + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2022 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -60,21 +60,12 @@ */ public class JWSACCMain implements Runnable { -// /** path to a class in one of the app server lib jars downloaded by Java Web Start */ -// private static final String APPSERVER_LIB_CLASS_NAME = "com.sun.enterprise.server.ApplicationServer"; - /** name of the permissions template */ private static final String PERMISSIONS_TEMPLATE_NAME = "jwsclient.policy"; /** placeholder used in the policy template to substitute dynamically-generated grant clauses */ private static final String GRANT_CLAUSES_PROPERTY_EXPR = "${grant.clauses}"; - /** line separator */ - private static final String lineSep = System.getProperty("line.separator"); - - /** the user-specified security policy template to use */ - private static String jwsPolicyTemplateURL = null; - /** unpublished command-line argument conveying jwsacc information */ private static final String JWSACC_ARGUMENT_PREFIX = "-jwsacc"; @@ -167,7 +158,8 @@ public static void main(String[] args) { *components or the JVM will never exit. */ } catch (Throwable thr) { - System.exit(1); + thr.printStackTrace(); + System.exit(1); } } @@ -191,14 +183,14 @@ public void run() { System.setProperty("com.sun.aas.downloaded.appclient.jar", downloadedAppclientJarFile.getAbsolutePath()); Thread.currentThread().setContextClassLoader(loader); - + System.err.println("XXXX: JWSACCMain.run set CL to thread: " + loader); /* *Use the prepared class loader to load the ACC main method, prepare *the arguments to the constructor, and invoke the static main method. */ - Class mainClass = Class.forName("com.sun.enterprise.appclient.MainWithModuleSupport", + Class mainClass = Class.forName("com.sun.enterprise.appclient.MainWithModuleSupport", true /* initialize */, loader); - Constructor constr = mainClass.getConstructor(new Class[] {String[].class, URL[].class}); + Constructor constr = mainClass.getDeclaredConstructor(String[].class, URL[].class); constr.newInstance(args, persistenceJarURLs); } catch(Throwable thr) { exitValue = 1; diff --git a/appserver/appclient/client/acc/src/main/resources/org/glassfish/appclient/client/acc/LocalStrings.properties b/appserver/appclient/client/acc/src/main/resources/org/glassfish/appclient/client/acc/LocalStrings.properties index 16dbdaeeaae..7710227c618 100644 --- a/appserver/appclient/client/acc/src/main/resources/org/glassfish/appclient/client/acc/LocalStrings.properties +++ b/appserver/appclient/client/acc/src/main/resources/org/glassfish/appclient/client/acc/LocalStrings.properties @@ -62,7 +62,3 @@ appclient.serverWithoutValue=The -targetserver option must be followed by host[: appclient.portNotValid=The server expression {0} contains an invalid port number {1} appclient.cannotOpenModuleManifest=Error opening manifest for module {0} appclient.cannotCloseModuleManifest=Error closing manifest for module {0} - -main.usage=Usage 1:\n\tappclient [ | -client ] \n\t\t[-mainclass |-name ] \n\t\t[-xml ] \n\t\t[-textauth] [-user ] [-password |-passwordfile ] \n\t\t[-targetserver host[:port][,host[:port]]...] \n\t\t[app-args] -main.usage.1=Usage 2:\n\tappclient [ ]\n\t\t[ | -jar ] \n\t\t[app args] -main.badVersion=Current Java version {0} is too low; {1} or later required diff --git a/appserver/appclient/client/acc/src/test/java/org/glassfish/appclient/client/acc/AppclientCommandArgumentsTest.java b/appserver/appclient/client/acc/src/test/java/org/glassfish/appclient/client/acc/AppclientCommandArgumentsTest.java index fec1252ff62..18fe3e57fc7 100644 --- a/appserver/appclient/client/acc/src/test/java/org/glassfish/appclient/client/acc/AppclientCommandArgumentsTest.java +++ b/appserver/appclient/client/acc/src/test/java/org/glassfish/appclient/client/acc/AppclientCommandArgumentsTest.java @@ -27,6 +27,7 @@ import java.util.Properties; import java.util.logging.Logger; +import org.glassfish.embeddable.client.UserError; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; diff --git a/appserver/appclient/client/acc/src/test/java/org/glassfish/appclient/client/acc/CommandLaunchInfoTest.java b/appserver/appclient/client/acc/src/test/java/org/glassfish/appclient/client/acc/CommandLaunchInfoTest.java index 1bd9fb45ffc..3a94f23759f 100644 --- a/appserver/appclient/client/acc/src/test/java/org/glassfish/appclient/client/acc/CommandLaunchInfoTest.java +++ b/appserver/appclient/client/acc/src/test/java/org/glassfish/appclient/client/acc/CommandLaunchInfoTest.java @@ -24,6 +24,7 @@ import java.util.List; import org.glassfish.appclient.client.acc.CommandLaunchInfo.ClientLaunchType; +import org.glassfish.embeddable.client.UserError; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/appclient b/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/appclient index aa240dac3a6..41521673128 100644 --- a/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/appclient +++ b/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/appclient @@ -1,5 +1,6 @@ -#!/bin/sh +#!/bin/bash # +# Copyright (c) 2024 Contributors to the Eclipse Foundation # Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. # # This program and the accompanying materials are made available under the @@ -15,10 +16,6 @@ # SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 # -# - -# set -x - chooseJava() { # # Looks for Java at AS_JAVA, JAVA_HOME or in the path. @@ -65,14 +62,12 @@ seekJavaOnPath() { } -_AS_INSTALL=`dirname "$0"`/.. -export _AS_INSTALL +export AS_INSTALL="$(dirname $(realpath -s $0))/.." case "`uname`" in - CYGWIN*) _AS_INSTALL=`cygpath --windows $_AS_INSTALL` + CYGWIN*) AS_INSTALL=`cygpath --windows $AS_INSTALL` cygwinProp=-Dorg.glassfish.isCygwin=true esac -. "${_AS_INSTALL}/config/asenv.conf" +. "${AS_INSTALL}/config/asenv.conf" chooseJava - -eval "`"${ACCJava}" -Dorg.glassfish.appclient.shell $cygwinProp -classpath "${_AS_INSTALL}/lib/gf-client.jar" org.glassfish.appclient.client.CLIBootstrap "$@"`" +eval "`"${ACCJava}" -Dorg.glassfish.appclient.shell $cygwinProp --module-path "${AS_INSTALL}/lib/bootstrap" --add-modules ALL-MODULE-PATH -classpath "${AS_INSTALL}/lib/gf-client.jar" org.glassfish.appclient.client.acc.agent.CLIBootstrap "$@"`" diff --git a/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/appclient.bat b/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/appclient.bat index 60b86637f90..81d430c0fc5 100644 --- a/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/appclient.bat +++ b/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/appclient.bat @@ -1,5 +1,6 @@ @echo off REM +REM Copyright (c) 2024 Contributors to the Eclipse Foundation REM Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. REM REM This program and the accompanying materials are made available under the @@ -65,18 +66,10 @@ rem issue the error so we don't have to do i18n of our own message from the scri goto :EOF :main -set _AS_INSTALL=%~dp0.. -call "%_AS_INSTALL%\config\asenv.bat" +set ARGS=%* +set AS_INSTALL=%~dp0.. +call "%AS_INSTALL%\config\asenv.bat" call :chooseJava -set inputArgs=%* -rem -rem Convert the java.exe path and the classpath path to -rem Windows "short" versions - with no spaces - so the -rem for /F statement below will work correctly. Spaces cause -rem it great troubles. -rem -for %%a in ("%JAVA%") do set ACCJava=%%~sa% -for %%a in ("%_AS_INSTALL%/lib/gf-client.jar") do set XCLASSPATH=%%~sa -for /F "usebackq tokens=*" %%a in (`%ACCJava% -classpath %XCLASSPATH% org.glassfish.appclient.client.CLIBootstrap`) do set javaCmd=%%a -%javaCmd% +FOR /F "delims=" %i IN (%JAVA% --module-path "%AS_INSTALL%\lib\bootstrap" --add-modules ALL-MODULE-PATH -classpath "%AS_INSTALL%\lib\gf-client.jar" org.glassfish.appclient.client.acc.agent.CLIBootstrap %*) DO set CMD=%i +%CMD% %ARGS% diff --git a/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/appclient.js b/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/appclient.js index e4c2b8aeb17..eec2950ab6e 100644 --- a/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/appclient.js +++ b/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/appclient.js @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -32,7 +33,7 @@ var builtinEndorsedDirSetting = quoteMultiStringIfNeeded( AS_INSTALL + "\\lib\\endorsed" + pathSep + - AS_INSTALL_MOD + + AS_INSTALL_MOD + "\\endorsed", pathSep); var mainClassIdentRequired = 1; @@ -123,13 +124,13 @@ function processArgs() { var accNonvaluedOptions = ["-textauth", "-noappinvoke", "-usage", "-help"]; //var re = new RegExp("\"([^\"]+)\"|[^\"\\s]+)","g"); var re = /"([^"]+)"|([^"\s]+)/g; - + // var tokens = inputArgs.split(" "); // var tokens = re.exec(inputArgs); var tokens = inputArgs.match(re); for (tokenIndex = 0; tokenIndex < tokens.length; tokenIndex++) { var token = tokens[tokenIndex]; - + var matched=null; matched = matchToWithType(token, jvmValuedOptions, "JVM"); if (matched == null) { @@ -152,7 +153,7 @@ function processArgs() { expecting = null; } } - + if (matched == null) { if (expecting != null) { recordArg(expectingArgType, expecting, token); diff --git a/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/package-appclient b/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/package-appclient index 341491e5831..e707a7dea16 100755 --- a/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/package-appclient +++ b/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/package-appclient @@ -1,5 +1,6 @@ -#!/bin/sh +#!/bin/bash # +# Copyright (c) 2024 Contributors to the Eclipse Foundation # Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. # # This program and the accompanying materials are made available under the @@ -17,19 +18,20 @@ # set -x -_AS_INSTALL=`dirname "$0"`/.. +export AS_INSTALL="$(dirname $(realpath -s $0))/.." + # # Run with the user-specified Java, if any. # case "`uname`" in - CYGWIN*) _AS_INSTALL=`cygpath --windows $_AS_INSTALL` + CYGWIN*) AS_INSTALL=`cygpath --windows $AS_INSTALL` esac -. "${_AS_INSTALL}/config/asenv.conf" +. "${AS_INSTALL}/config/asenv.conf" JAVA=java # Depends upon Java from ../config/asenv.conf if [ ${AS_JAVA} ]; then JAVA=${AS_JAVA}/bin/java fi -_AS_INSTALL_LIB=$_AS_INSTALL/lib -$JAVA -classpath "$_AS_INSTALL_LIB/gf-client.jar" org.glassfish.appclient.client.packageappclient.PackageAppClient "$@" +AS_INSTALL_LIB="$AS_INSTALL/lib" +$JAVA -classpath "$AS_INSTALL_LIB/gf-client.jar" org.glassfish.appclient.client.packageappclient.PackageAppClient "$@" diff --git a/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/package-appclient.bat b/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/package-appclient.bat index 286f2baf2fa..4aed19d3c80 100755 --- a/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/package-appclient.bat +++ b/appserver/appclient/client/appclient-scripts/src/main/resources/glassfish/bin/package-appclient.bat @@ -1,5 +1,6 @@ @echo off REM +REM Copyright (c) 2024 Contributors to the Eclipse Foundation REM Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. REM REM This program and the accompanying materials are made available under the @@ -16,16 +17,18 @@ REM SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 REM setlocal -set _AS_INSTALL=%~dp0.. -call "%_AS_INSTALL%\config\asenv.bat" +set AS_INSTALL=%~dp0.. +call "%AS_INSTALL%\config\asenv.bat" REM REM Run with the user-specified Java, if any. REM if "%AS_JAVA%x" == "x" goto UsePath set JAVA="%AS_JAVA%\bin\java" goto run + :UsePath set JAVA=java + :run -set _AS_INSTALL_LIB=%_AS_INSTALL%\lib -%JAVA% -classpath "%_AS_INSTALL_LIB%\gf-client.jar" org.glassfish.appclient.client.packageappclient.PackageAppClient %* +set AS_INSTALL_LIB=%AS_INSTALL%\lib +%JAVA% -classpath "%AS_INSTALL_LIB%\gf-client.jar" org.glassfish.appclient.client.packageappclient.PackageAppClient %* diff --git a/appserver/appclient/server/core/pom.xml b/appserver/appclient/server/core/pom.xml index 1b55cd99a2c..394a26983e6 100644 --- a/appserver/appclient/server/core/pom.xml +++ b/appserver/appclient/server/core/pom.xml @@ -50,7 +50,7 @@ org.glassfish.main.common - common-util + glassfish-jdk-extensions ${project.version} diff --git a/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/AppClientServerApplication.java b/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/AppClientServerApplication.java index 7aa1db330af..5552193e5b0 100644 --- a/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/AppClientServerApplication.java +++ b/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/AppClientServerApplication.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -33,9 +33,9 @@ import org.glassfish.api.deployment.DeployCommandParameters; import org.glassfish.api.deployment.DeploymentContext; import org.glassfish.appclient.server.core.jws.JavaWebStartInfo; -import org.glassfish.common.util.GlassfishUrlClassLoader; import org.glassfish.hk2.api.PerLookup; import org.glassfish.hk2.api.ServiceLocator; +import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; import org.jvnet.hk2.annotations.Service; /** @@ -157,11 +157,10 @@ public boolean resume() throws Exception { @Override public ClassLoader getClassLoader() { - /* - * This cannot be null or it prevents the framework from invoking unload - * on the deployer for this app. - */ - PrivilegedAction action = () -> new GlassfishUrlClassLoader(new URL[0]); + // This cannot be null or it prevents the framework from invoking unload + // on the deployer for this app. + PrivilegedAction action = () -> new GlassfishUrlClassLoader( + "AppClientServer(" + deployedAppName + ")", new URL[0]); return AccessController.doPrivileged(action); } diff --git a/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/CarHandler.java b/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/CarHandler.java index 1138835bf87..6d2c138a6ab 100644 --- a/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/CarHandler.java +++ b/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/CarHandler.java @@ -89,7 +89,7 @@ public boolean handles(ReadableArchive archive) throws IOException { @Override public ClassLoader getClassLoader(final ClassLoader parent, DeploymentContext context) { - PrivilegedAction action = () -> new ASURLClassLoader(parent); + PrivilegedAction action = () -> new ASURLClassLoader("CarHandler", parent); ASURLClassLoader cloader = AccessController.doPrivileged(action); try { cloader.addURL(context.getSource().getURI().toURL()); @@ -99,12 +99,8 @@ public ClassLoader getClassLoader(final ClassLoader parent, DeploymentContext co } try { - final DeploymentContext dc = context; - final ClassLoader cl = cloader; - - AccessController.doPrivileged( - new PermsArchiveDelegate.SetPermissionsAction( - SMGlobalPolicyUtil.CommponentType.car, dc, cl)); + AccessController.doPrivileged(new PermsArchiveDelegate.SetPermissionsAction( + SMGlobalPolicyUtil.CommponentType.car, context, cloader)); } catch (PrivilegedActionException e) { throw new SecurityException(e.getException()); } diff --git a/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/jws/JavaWebStartInfo.java b/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/jws/JavaWebStartInfo.java index 565862ee6d3..e6991d59762 100644 --- a/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/jws/JavaWebStartInfo.java +++ b/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/jws/JavaWebStartInfo.java @@ -18,7 +18,6 @@ package org.glassfish.appclient.server.core.jws; import com.sun.enterprise.deployment.ApplicationClientDescriptor; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import jakarta.inject.Inject; @@ -59,6 +58,7 @@ import org.glassfish.logging.annotation.LogMessageInfo; import org.glassfish.logging.annotation.LogMessagesResourceBundle; import org.glassfish.logging.annotation.LoggerInfo; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import org.jvnet.hk2.annotations.Service; import org.jvnet.hk2.config.ConfigListener; import org.jvnet.hk2.config.UnprocessedChangeEvent; diff --git a/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/jws/servedcontent/TokenHelper.java b/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/jws/servedcontent/TokenHelper.java index 6a7119b3896..7387d7994df 100644 --- a/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/jws/servedcontent/TokenHelper.java +++ b/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/jws/servedcontent/TokenHelper.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation. * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -17,7 +18,6 @@ package org.glassfish.appclient.server.core.jws.servedcontent; import com.sun.enterprise.deployment.ApplicationClientDescriptor; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import java.net.URI; import java.util.Properties; @@ -29,6 +29,7 @@ import org.glassfish.appclient.server.core.jws.JavaWebStartInfo; import org.glassfish.appclient.server.core.jws.JavaWebStartInfo.VendorInfo; import org.glassfish.appclient.server.core.jws.NamingConventions; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * diff --git a/appserver/common/container-common/src/main/java/org/glassfish/ha/commands/Strings.java b/appserver/common/container-common/src/main/java/org/glassfish/ha/commands/Strings.java index 625ec6702be..ccc8936ad2a 100644 --- a/appserver/common/container-common/src/main/java/org/glassfish/ha/commands/Strings.java +++ b/appserver/common/container-common/src/main/java/org/glassfish/ha/commands/Strings.java @@ -16,7 +16,7 @@ package org.glassfish.ha.commands; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Strings -- Get your Strings here. diff --git a/appserver/connectors/connectors-internal-api/src/main/java/com/sun/appserv/connectors/internal/api/ConnectorClassFinder.java b/appserver/connectors/connectors-internal-api/src/main/java/com/sun/appserv/connectors/internal/api/ConnectorClassFinder.java index 78fc7b32abf..b2d00cf9d9f 100644 --- a/appserver/connectors/connectors-internal-api/src/main/java/com/sun/appserv/connectors/internal/api/ConnectorClassFinder.java +++ b/appserver/connectors/connectors-internal-api/src/main/java/com/sun/appserv/connectors/internal/api/ConnectorClassFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -28,11 +28,15 @@ */ public class ConnectorClassFinder extends ASURLClassLoader implements DelegatingClassLoader.ClassFinder { + static { + registerAsParallelCapable(); + } + private final DelegatingClassLoader.ClassFinder librariesClassFinder; private volatile String raName; public ConnectorClassFinder(ClassLoader parent, String raName, DelegatingClassLoader.ClassFinder finder) { - super(parent); + super("Connector(" + raName + ')', parent); this.raName = raName; // There should be better approach to skip libraries Classloader when none specified. diff --git a/appserver/connectors/connectors-runtime/pom.xml b/appserver/connectors/connectors-runtime/pom.xml index 48f97dca425..916084f04dc 100644 --- a/appserver/connectors/connectors-runtime/pom.xml +++ b/appserver/connectors/connectors-runtime/pom.xml @@ -66,6 +66,11 @@ common-util ${project.version} + + org.glassfish.main.common + glassfish-jdk-extensions + ${project.version} + org.glassfish.main.deployment deployment-common diff --git a/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/ConnectorClassLoader.java b/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/ConnectorClassLoader.java index dd510a96f73..47f4ab729aa 100644 --- a/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/ConnectorClassLoader.java +++ b/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/ConnectorClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -42,6 +42,10 @@ */ public class ConnectorClassLoader extends ASURLClassLoader { + static { + registerAsParallelCapable(); + } + private static final Logger _logger = LogDomains.getLogger(ConnectorClassLoader.class, LogDomains.RSR_LOGGER); private volatile static ConnectorClassLoader classLoader; @@ -73,10 +77,11 @@ public static synchronized ConnectorClassLoader getInstance() { } private ConnectorClassLoader() { + super("Connector", ClassLoader.getSystemClassLoader()); } private ConnectorClassLoader(ClassLoader parent) { - super(parent); + super("Connector", parent); this.parent = parent; } @@ -111,7 +116,7 @@ public void addResourceAdapter(String rarName, String moduleDir) { try { File file = new File(moduleDir); - PrivilegedAction action = () -> new ASURLClassLoader(parent); + PrivilegedAction action = () -> new ASURLClassLoader("ResourceAdapter(" + rarName + ")", parent); ASURLClassLoader cl = AccessController.doPrivileged(action); cl.appendURL(file.toURI().toURL()); diff --git a/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/ConnectorRARClassLoader.java b/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/ConnectorRARClassLoader.java index 9cff65dadd6..97d03e633e4 100644 --- a/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/ConnectorRARClassLoader.java +++ b/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/ConnectorRARClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -30,10 +30,15 @@ * @author Sivakumar Thyagarajan */ public class ConnectorRARClassLoader extends SecureClassLoader{ - private JarResourceExtractor jarResources; + + static { + registerAsParallelCapable(); + } + + private final JarResourceExtractor jarResources; public ConnectorRARClassLoader(String jarName, ClassLoader parent) { - super(parent); + super(jarName, parent); // Create the JarResource and suck in the .jar file. jarResources = new JarResourceExtractor(jarName); } diff --git a/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/DriverLoader.java b/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/DriverLoader.java index 4de401edcf7..5ae19193200 100644 --- a/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/DriverLoader.java +++ b/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/DriverLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -48,6 +48,8 @@ import org.jvnet.hk2.annotations.Service; +import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.DERBY_ROOT_PROP_NAME; + /** * Driver Loader to load the jdbc drivers and get driver/datasource classnames * by introspection. @@ -492,7 +494,7 @@ private boolean isVendorSpecific(File f, String dbVendor, String className, private List getJdbcDriverLocations() { List jarFileLocations = new ArrayList<>(); - jarFileLocations.add(getLocation(SystemPropertyConstants.DERBY_ROOT_PROPERTY)); + jarFileLocations.add(getLocation(DERBY_ROOT_PROP_NAME)); jarFileLocations.add(getLocation(SystemPropertyConstants.INSTALL_ROOT_PROPERTY)); jarFileLocations.add(getLocation(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY)); return jarFileLocations; diff --git a/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/RARUtils.java b/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/RARUtils.java index 5a74c54864e..6501ad8ad00 100644 --- a/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/RARUtils.java +++ b/appserver/connectors/connectors-runtime/src/main/java/com/sun/enterprise/connectors/util/RARUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -37,7 +37,7 @@ import java.util.logging.Level; import java.util.logging.Logger; -import org.glassfish.common.util.GlassfishUrlClassLoader; +import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; /** * This is a utility class to obtain the properties of a @@ -168,15 +168,14 @@ private static ClassLoader getClassLoader(String file) throws ConnectorRuntimeEx File f = new File(file); validateRARLocation(f); try { - ClassLoader commonClassLoader = - ConnectorRuntime.getRuntime().getClassLoaderHierarchy().getCommonClassLoader(); + ClassLoader commonCL = ConnectorRuntime.getRuntime().getClassLoaderHierarchy().getCommonClassLoader(); if (f.isDirectory()) { List urls = new ArrayList<>(); urls.add(f.toURI().toURL()); appendURLs(urls, f); - return new GlassfishUrlClassLoader(urls.toArray(URL[]::new), commonClassLoader); + return new GlassfishUrlClassLoader("ResourceAdapterDir(" + f.getName() + ")", urls.toArray(URL[]::new), commonCL); } - return new ConnectorRARClassLoader(file, commonClassLoader); + return new ConnectorRARClassLoader(file, commonCL); } catch (IOException ioe) { throw new ConnectorRuntimeException("unable to read connector descriptor from " + file, ioe); } diff --git a/appserver/deployment/jakartaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarClassLoader.java b/appserver/deployment/jakartaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarClassLoader.java index 0b3041aa2b4..3659bfeb781 100644 --- a/appserver/deployment/jakartaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarClassLoader.java +++ b/appserver/deployment/jakartaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2022 Contributors to the Eclipse Foundation. + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation. * Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -32,11 +32,15 @@ */ public class EarClassLoader extends ASURLClassLoader { + static { + registerAsParallelCapable(); + } + private List moduleClassLoaders = new LinkedList<>(); - boolean isPreDestroyCalled = false; + boolean isPreDestroyCalled; public EarClassLoader(ClassLoader classLoader) { - super(classLoader); + super("Ear", classLoader); } public void addModuleClassLoader(String moduleName, ClassLoader cl) { @@ -114,9 +118,4 @@ private ClassLoaderHolder(String moduleName, ClassLoader loader) { this.moduleName = moduleName; } } - - @Override - protected String getClassLoaderName() { - return "EarClassLoader"; - } } diff --git a/appserver/deployment/jakartaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarHandler.java b/appserver/deployment/jakartaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarHandler.java index cfb1150b8ed..0d15051d591 100644 --- a/appserver/deployment/jakartaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarHandler.java +++ b/appserver/deployment/jakartaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarHandler.java @@ -32,7 +32,6 @@ import com.sun.enterprise.security.ee.perms.PermsArchiveDelegate; import com.sun.enterprise.security.ee.perms.SMGlobalPolicyUtil; import com.sun.enterprise.security.integration.DDPermissionsLoader; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.util.LocalStringManagerImpl; import com.sun.enterprise.util.io.FileUtils; @@ -84,6 +83,7 @@ import org.glassfish.internal.deployment.ExtendedDeploymentContext; import org.glassfish.javaee.core.deployment.ApplicationHolder; import org.glassfish.loader.util.ASClassLoaderUtil; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import org.jvnet.hk2.annotations.Service; import org.xml.sax.SAXException; diff --git a/appserver/deployment/jakartaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarLibClassLoader.java b/appserver/deployment/jakartaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarLibClassLoader.java index 9a192ebef63..7835d2b254c 100644 --- a/appserver/deployment/jakartaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarLibClassLoader.java +++ b/appserver/deployment/jakartaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarLibClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2022 Contributors to the Eclipse Foundation. + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation. * Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -26,16 +26,15 @@ */ public class EarLibClassLoader extends ASURLClassLoader { + static { + registerAsParallelCapable(); + } + public EarLibClassLoader(URL[] urls, ClassLoader classLoader) { - super(classLoader); + super("EarLib", classLoader); for (URL url : urls) { addURL(url); } } - - @Override - protected String getClassLoaderName() { - return "EarLibClassLoader"; - } } diff --git a/appserver/distributions/glassfish-common/src/main/resources/bin/asadmin b/appserver/distributions/glassfish-common/src/main/resources/bin/asadmin index 6aefb78d505..2c3f0427217 100644 --- a/appserver/distributions/glassfish-common/src/main/resources/bin/asadmin +++ b/appserver/distributions/glassfish-common/src/main/resources/bin/asadmin @@ -1,5 +1,6 @@ #!/bin/sh # +# Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation # Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. # # This program and the accompanying materials are made available under the @@ -15,17 +16,16 @@ # SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 # -AS_INSTALL=`dirname "$0"`/../glassfish +export AS_INSTALL="$(dirname $(realpath -s $0))/../glassfish" case "`uname`" in CYGWIN*) AS_INSTALL=`cygpath --windows $AS_INSTALL` esac -AS_INSTALL_LIB="$AS_INSTALL/lib" . "${AS_INSTALL}/config/asenv.conf" + JAVA=java -#Depends upon Java from ../config/asenv.conf if [ ${AS_JAVA} ]; then JAVA=${AS_JAVA}/bin/java fi -exec "$JAVA" -jar "$AS_INSTALL_LIB/client/appserver-cli.jar" "$@" - +export ASADMIN_CLASSPATH="$AS_INSTALL/appserver-cli.jar:${ASADMIN_CLASSPATH}" +exec "$JAVA" ${ASADMIN_JVM_OPTIONS} --module-path "${ASADMIN_MODULEPATH}" --add-modules ALL-MODULE-PATH -cp "$ASADMIN_CLASSPATH" org.glassfish.admin.cli.AsadminMain "$@" diff --git a/appserver/distributions/glassfish-common/src/main/resources/bin/asadmin.bat b/appserver/distributions/glassfish-common/src/main/resources/bin/asadmin.bat index 49a8e4e2149..aba24752bed 100644 --- a/appserver/distributions/glassfish-common/src/main/resources/bin/asadmin.bat +++ b/appserver/distributions/glassfish-common/src/main/resources/bin/asadmin.bat @@ -1,5 +1,6 @@ @echo off REM +REM Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation REM Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. REM REM This program and the accompanying materials are made available under the @@ -15,20 +16,22 @@ REM REM SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 REM - -REM Always use JDK 1.6 or higher -REM Depends on Java from ..\glassfish\config\asenv.bat VERIFY OTHER 2>nul setlocal ENABLEEXTENSIONS if ERRORLEVEL 0 goto ok echo "Unable to enable extensions" exit /B 1 + :ok -call "%~dp0..\glassfish\config\asenv.bat" +set AS_INSTALL=%~dp0..\glassfish +call "%AS_INSTALL%\config\asenv.bat" if "%AS_JAVA%x" == "x" goto UsePath -set JAVA="%AS_JAVA%\bin\java" +set JAVA=%AS_JAVA%\bin\java goto run + :UsePath set JAVA=java + :run -%JAVA% -jar "%~dp0..\glassfish\lib\client\appserver-cli.jar" %* +set ASADMIN_CLASSPATH=%AS_INSTALL%\appserver-cli.jar;%ASADMIN_CLASSPATH% +%JAVA% %ASADMIN_JVM_OPTIONS% --module-path "%ASADMIN_MODULEPATH%" --add-modules ALL-MODULE-PATH -cp "%ASADMIN_CLASSPATH%" org.glassfish.admin.cli.AsadminMain %* diff --git a/appserver/distributions/glassfish-common/src/main/resources/bin/debug-asadmin b/appserver/distributions/glassfish-common/src/main/resources/bin/debug-asadmin index 6af531803fa..8511a1ea203 100644 --- a/appserver/distributions/glassfish-common/src/main/resources/bin/debug-asadmin +++ b/appserver/distributions/glassfish-common/src/main/resources/bin/debug-asadmin @@ -1,5 +1,6 @@ #!/bin/sh # +# Copyright (c) 2024 Contributors to the Eclipse Foundation # Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. # # This program and the accompanying materials are made available under the @@ -15,15 +16,13 @@ # SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 # -# Always use JDK 1.6 or higher -AS_INSTALL=`dirname "$0"`/../glassfish -AS_INSTALL_LIB="$AS_INSTALL/lib" +export AS_INSTALL="$(dirname $(realpath -s $0))/../glassfish" . "${AS_INSTALL}/config/asenv.conf" + JAVA=java -#Depends upon Java from ../config/asenv.conf if [ ${AS_JAVA} ]; then JAVA=${AS_JAVA}/bin/java fi -exec "$JAVA" -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=9008 -jar "$AS_INSTALL_LIB/client/appserver-cli.jar" "$@" - +export ASADMIN_CLASSPATH="$AS_INSTALL/appserver-cli.jar:$ASADMIN_CLASSPATH" +exec "$JAVA" ${ASADMIN_JVM_OPTIONS} -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=9008 --module-path "${ASADMIN_MODULEPATH}" --add-modules ALL-MODULE-PATH -cp "$ASADMIN_CLASSPATH" org.glassfish.admin.cli.AsadminMain "$@" diff --git a/appserver/distributions/glassfish-common/src/main/resources/bin/debug-asadmin.bat b/appserver/distributions/glassfish-common/src/main/resources/bin/debug-asadmin.bat index 965e548d37c..8034a959e7a 100755 --- a/appserver/distributions/glassfish-common/src/main/resources/bin/debug-asadmin.bat +++ b/appserver/distributions/glassfish-common/src/main/resources/bin/debug-asadmin.bat @@ -1,5 +1,6 @@ @echo off REM +REM Copyright (c) 2024 Contributors to the Eclipse Foundation REM Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. REM REM This program and the accompanying materials are made available under the @@ -15,20 +16,22 @@ REM REM SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 REM - -REM Always use JDK 1.6 or higher -REM Depends on Java from ..\glassfish\config\asenv.bat VERIFY OTHER 2>nul setlocal ENABLEEXTENSIONS if ERRORLEVEL 0 goto ok echo "Unable to enable extensions" exit /B 1 + :ok -call "%~dp0..\glassfish\config\asenv.bat" +set AS_INSTALL="%~dp0..\glassfish" +call "%AS_INSTALL%\config\asenv.bat" if "%AS_JAVA%x" == "x" goto UsePath -set JAVA="%AS_JAVA%\bin\java" +set JAVA=%AS_JAVA%\bin\java goto run + :UsePath set JAVA=java + :run -%JAVA% -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=9008 -jar "%~dp0..\glassfish\lib\client\appserver-cli.jar" %* +set ASADMIN_CLASSPATH=%AS_INSTALL%\appserver-cli.jar:%ASADMIN_CLASSPATH% +%JAVA% %ASADMIN_JVM_OPTIONS% -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=9008 --module-path "%ASADMIN_MODULEPATH%" --add-modules ALL-MODULE-PATH -cp "%ASADMIN_CLASSPATH%" org.glassfish.admin.cli.AsadminMain %* diff --git a/appserver/distributions/glassfish-common/src/main/resources/bin/startserv b/appserver/distributions/glassfish-common/src/main/resources/bin/startserv index 493bb63ee77..d0899b0b287 100755 --- a/appserver/distributions/glassfish-common/src/main/resources/bin/startserv +++ b/appserver/distributions/glassfish-common/src/main/resources/bin/startserv @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright (c) 2023,2024 Contributors to the Eclipse Foundation +# Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation # Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. # # This program and the accompanying materials are made available under the @@ -16,21 +16,22 @@ # SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 # -AS_INSTALL=`dirname "$0"`/../glassfish +export AS_INSTALL="$(dirname $(realpath -s $0))/../glassfish" case "`uname`" in CYGWIN*) AS_INSTALL=`cygpath --windows $AS_INSTALL` esac -AS_INSTALL_LIB="$AS_INSTALL/modules" . "${AS_INSTALL}/config/asenv.conf" + JAVA=java -#Depends upon Java from ../config/asenv.conf if [ ${AS_JAVA} ]; then JAVA=${AS_JAVA}/bin/java fi +export ASADMIN_CLASSPATH="$AS_INSTALL/appserver-cli.jar:${ASADMIN_CLASSPATH}" + start_as_main_process () { if [[ "$@" == "--help" ]] || [[ "$@" == "--help=true" ]] || [[ "$@" == "-?" ]]; then - exec java -jar "$ASADMIN_JAR" start-domain --help + exec "$JAVA" ${ASADMIN_JVM_OPTIONS} --module-path "${ASADMIN_MODULEPATH}" --add-modules ALL-MODULE-PATH -cp "$ASADMIN_CLASSPATH" org.glassfish.admin.cli.AsadminMain start-domain --help fi # Execute start-domain --dry-run and store the output line by line into an array. @@ -50,7 +51,7 @@ start_as_main_process () { else DRY_RUN_OUTPUT+=("$COM"); fi - done < <(java -jar "$ASADMIN_JAR" start-domain --dry-run "$@" || echo "FAILED" ) + done < <("$JAVA" ${ASADMIN_JVM_OPTIONS} --module-path "${ASADMIN_MODULEPATH}" --add-modules ALL-MODULE-PATH -cp "$ASADMIN_CLASSPATH" org.glassfish.admin.cli.AsadminMain start-domain --dry-run "$@" || echo "FAILED") if [[ x"$DRY_RUN_OUTPUT" == x ]] then echo -n -e "${DRY_RUN_OUTPUT_BEFORE_DUMP}" >&2 @@ -65,8 +66,7 @@ start_as_main_process () { } -ASADMIN_JAR="$AS_INSTALL_LIB/admin-cli.jar" start_as_main_process "$@" # Alternatively, run the following: -# exec "$JAVA" -jar "$ASADMIN_JAR" start-domain --verbose "$@" \ No newline at end of file +# exec "$JAVA" -jar "$ASADMIN_JAR" start-domain --verbose "$@" diff --git a/appserver/distributions/glassfish-common/src/main/resources/bin/startserv.bat b/appserver/distributions/glassfish-common/src/main/resources/bin/startserv.bat index 60829dac652..f0d9028034d 100755 --- a/appserver/distributions/glassfish-common/src/main/resources/bin/startserv.bat +++ b/appserver/distributions/glassfish-common/src/main/resources/bin/startserv.bat @@ -1,5 +1,6 @@ @echo off REM +REM Copyright (c) 2024 Contributors to the Eclipse Foundation REM Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. REM REM This program and the accompanying materials are made available under the @@ -15,5 +16,22 @@ REM REM SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 REM +VERIFY OTHER 2>nul +setlocal ENABLEEXTENSIONS +if ERRORLEVEL 0 goto ok +echo "Unable to enable extensions" +exit /B 1 -java -jar "%~dp0..\glassfish\modules\admin-cli.jar" start-domain --verbose %* +:ok +set AS_INSTALL=%~dp0..\glassfish +call "%AS_INSTALL%\config\asenv.bat" +if "%AS_JAVA%x" == "x" goto UsePath +set JAVA=%AS_JAVA%\bin\java +goto run + +:UsePath +set JAVA=java + +:run +set ASADMIN_CLASSPATH=%AS_INSTALL%\appserver-cli.jar;%ASADMIN_CLASSPATH% +%JAVA% %ASADMIN_JVM_OPTIONS% --module-path "%ASADMIN_MODULEPATH%" --add-modules ALL-MODULE-PATH -cp "%ASADMIN_CLASSPATH%" org.glassfish.admin.cli.AsadminMain start-domain --verbose %* diff --git a/appserver/distributions/glassfish-common/src/main/resources/bin/stopserv b/appserver/distributions/glassfish-common/src/main/resources/bin/stopserv index 6fe959af7bb..45b8c4bb85c 100755 --- a/appserver/distributions/glassfish-common/src/main/resources/bin/stopserv +++ b/appserver/distributions/glassfish-common/src/main/resources/bin/stopserv @@ -1,5 +1,6 @@ -#!/bin/sh +#!/bin/bash # +# Copyright (c) 2024 Contributors to the Eclipse Foundation # Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. # # This program and the accompanying materials are made available under the @@ -15,7 +16,17 @@ # SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 # -AS_INSTALL=`dirname "$0"`/../glassfish -AS_INSTALL_LIB="$AS_INSTALL/modules" +export AS_INSTALL="$(dirname $(realpath -s $0))/../glassfish" +case "`uname`" in + CYGWIN*) AS_INSTALL=`cygpath --windows $AS_INSTALL` +esac +. "${AS_INSTALL}/config/asenv.conf" -exec java -jar "$AS_INSTALL_LIB/admin-cli.jar" stop-domain "$@" +JAVA=java +if [ ${AS_JAVA} ]; then + JAVA=${AS_JAVA}/bin/java +fi + +export ASADMIN_CLASSPATH="$AS_INSTALL/appserver-cli.jar:${ASADMIN_CLASSPATH}" + +"$JAVA" ${ASADMIN_JVM_OPTIONS} --module-path "${ASADMIN_MODULEPATH}" --add-modules ALL-MODULE-PATH -cp "$ASADMIN_CLASSPATH" org.glassfish.admin.cli.AsadminMain stop-domain "$@" diff --git a/appserver/distributions/glassfish-common/src/main/resources/bin/stopserv.bat b/appserver/distributions/glassfish-common/src/main/resources/bin/stopserv.bat index 575474fa500..7823302ee35 100755 --- a/appserver/distributions/glassfish-common/src/main/resources/bin/stopserv.bat +++ b/appserver/distributions/glassfish-common/src/main/resources/bin/stopserv.bat @@ -1,5 +1,6 @@ @echo off REM +REM Copyright (c) 2024 Contributors to the Eclipse Foundation REM Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. REM REM This program and the accompanying materials are made available under the @@ -16,4 +17,22 @@ REM SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 REM -java -jar "%~dp0..\glassfish\modules\admin-cli.jar" stop-domain %* +VERIFY OTHER 2>nul +setlocal ENABLEEXTENSIONS +if ERRORLEVEL 0 goto ok +echo "Unable to enable extensions" +exit /B 1 + +:ok +set AS_INSTALL=%~dp0.. +call "%AS_INSTALL%\config\asenv.bat" +if "%AS_JAVA%x" == "x" goto UsePath +set JAVA=%AS_JAVA%\bin\java +goto run + +:UsePath +set JAVA=java + +:run +set ASADMIN_CLASSPATH=%AS_INSTALL%\appserver-cli.jar;%ASADMIN_CLASSPATH% +%JAVA% %ASADMIN_JVM_OPTIONS% --module-path "%ASADMIN_MODULEPATH%" --add-modules ALL-MODULE-PATH -cp "%ASADMIN_CLASSPATH%" org.glassfish.admin.cli.AsadminMain stop-domain %* diff --git a/appserver/distributions/glassfish-common/src/main/resources/glassfish/bin/asadmin b/appserver/distributions/glassfish-common/src/main/resources/glassfish/bin/asadmin index 43cb5d22dc3..ac9a0cf2c37 100644 --- a/appserver/distributions/glassfish-common/src/main/resources/glassfish/bin/asadmin +++ b/appserver/distributions/glassfish-common/src/main/resources/glassfish/bin/asadmin @@ -1,5 +1,6 @@ #!/bin/sh # +# Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation # Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. # # This program and the accompanying materials are made available under the @@ -15,15 +16,16 @@ # SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 # -AS_INSTALL=`dirname "$0"`/.. +export AS_INSTALL="$(dirname $(realpath -s $0))/.." case "`uname`" in CYGWIN*) AS_INSTALL=`cygpath --windows $AS_INSTALL` esac -AS_INSTALL_LIB="$AS_INSTALL/lib" . "${AS_INSTALL}/config/asenv.conf" + JAVA=java -#Depends upon Java from ../config/asenv.conf if [ ${AS_JAVA} ]; then JAVA=${AS_JAVA}/bin/java fi -exec "$JAVA" -jar "$AS_INSTALL_LIB/client/appserver-cli.jar" "$@" + +export ASADMIN_CLASSPATH="$AS_INSTALL/appserver-cli.jar:${ASADMIN_CLASSPATH}" +exec "$JAVA" ${ASADMIN_JVM_OPTIONS} --module-path "${ASADMIN_MODULEPATH}" --add-modules ALL-MODULE-PATH -cp "$ASADMIN_CLASSPATH" org.glassfish.admin.cli.AsadminMain "$@" diff --git a/appserver/distributions/glassfish-common/src/main/resources/glassfish/bin/asadmin.bat b/appserver/distributions/glassfish-common/src/main/resources/glassfish/bin/asadmin.bat index ea6f018fa97..4b326a849fb 100644 --- a/appserver/distributions/glassfish-common/src/main/resources/glassfish/bin/asadmin.bat +++ b/appserver/distributions/glassfish-common/src/main/resources/glassfish/bin/asadmin.bat @@ -1,5 +1,6 @@ @echo off REM +REM Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation REM Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. REM REM This program and the accompanying materials are made available under the @@ -15,20 +16,22 @@ REM REM SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 REM - -REM Always use JDK 1.6 or higher -REM Depends on Java from ..\config\asenv.bat VERIFY OTHER 2>nul setlocal ENABLEEXTENSIONS if ERRORLEVEL 0 goto ok echo "Unable to enable extensions" exit /B 1 + :ok -call "%~dp0..\config\asenv.bat" +set AS_INSTALL=%~dp0.. +call "%AS_INSTALL%\config\asenv.bat" if "%AS_JAVA%x" == "x" goto UsePath -set JAVA="%AS_JAVA%\bin\java" +set JAVA=%AS_JAVA%\bin\java goto run + :UsePath set JAVA=java + :run -%JAVA% -jar "%~dp0..\lib\client\appserver-cli.jar" %* +set ASADMIN_CLASSPATH=%AS_INSTALL%\appserver-cli.jar;%ASADMIN_CLASSPATH% +%JAVA% %ASADMIN_JVM_OPTIONS% --module-path "%ASADMIN_MODULEPATH%" --add-modules ALL-MODULE-PATH -cp "%ASADMIN_CLASSPATH%" org.glassfish.admin.cli.AsadminMain %* diff --git a/appserver/distributions/glassfish/src/main/assembly/glassfish.xml b/appserver/distributions/glassfish/src/main/assembly/glassfish.xml index 743a0f2ae89..d71bf761ee1 100644 --- a/appserver/distributions/glassfish/src/main/assembly/glassfish.xml +++ b/appserver/distributions/glassfish/src/main/assembly/glassfish.xml @@ -1,7 +1,7 @@ + ${temp.dir} 640 + admin-cli.jar appserver-cli.jar - ${install.dir.name}/glassfish/lib/client + ${install.dir.name}/glassfish @@ -326,7 +327,10 @@ ${temp.dir} 640 + glassfish.jar + glassfish-jdk-extensions.jar glassfish-jul-extension.jar + simple-glassfish-api.jar ${install.dir.name}/glassfish/lib/bootstrap @@ -362,8 +366,12 @@ *.jar - server-mgmt.jar + admin-cli.jar + appserver-cli.jar + cli-optional.jar + cluster-cli.jar osgi-cli-interactive.jar + server-mgmt.jar flashlight-agent.jar org.apache.felix.configadmin.jar org.apache.felix.fileinstall.jar @@ -377,10 +385,10 @@ felix.jar nucleus-domain.jar appserver-domain.jar + glassfish.jar + glassfish-jdk-extensions.jar glassfish-jul-extension.jar - cli-optional.jar - appserver-cli.jar - cluster-cli.jar + simple-glassfish-api.jar glassfish-embedded-shell.jar glassfish-embedded-static-shell.jar jakartaee.jar diff --git a/appserver/distributions/web/src/main/assembly/web.xml b/appserver/distributions/web/src/main/assembly/web.xml index f89863ccecb..a30fa39c3e9 100644 --- a/appserver/distributions/web/src/main/assembly/web.xml +++ b/appserver/distributions/web/src/main/assembly/web.xml @@ -1,7 +1,7 @@ + ${temp.dir} 640 + admin-cli.jar appserver-cli.jar - ${install.dir.name}/glassfish/lib/client + ${install.dir.name}/glassfish @@ -200,7 +201,10 @@ ${temp.dir} 640 + glassfish.jar + glassfish-jdk-extensions.jar glassfish-jul-extension.jar + simple-glassfish-api.jar ${install.dir.name}/glassfish/lib/bootstrap @@ -236,8 +240,12 @@ *.jar - server-mgmt.jar + admin-cli.jar + appserver-cli.jar + cli-optional.jar + cluster-cli.jar osgi-cli-interactive.jar + server-mgmt.jar flashlight-agent.jar org.apache.felix.configadmin.jar org.apache.felix.fileinstall.jar @@ -251,10 +259,10 @@ felix.jar nucleus-domain.jar appserver-domain.jar + glassfish.jar + glassfish-jdk-extensions.jar glassfish-jul-extension.jar - cli-optional.jar - appserver-cli.jar - cluster-cli.jar + simple-glassfish-api.jar glassfish-embedded-shell.jar glassfish-embedded-static-shell.jar jakartaee.jar diff --git a/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/deployment/EjbJarHandler.java b/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/deployment/EjbJarHandler.java index 1365a43ae98..9c1cdf084b6 100644 --- a/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/deployment/EjbJarHandler.java +++ b/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/deployment/EjbJarHandler.java @@ -101,7 +101,7 @@ public String getVersionIdentifier(ReadableArchive archive) { @Override public ClassLoader getClassLoader(final ClassLoader parent, DeploymentContext context) { - PrivilegedAction action = () -> new ASURLClassLoader(parent); + PrivilegedAction action = () -> new ASURLClassLoader("EjbJarHandler", parent); ASURLClassLoader cloader = AccessController.doPrivileged(action); try { diff --git a/appserver/extras/embedded/all/pom.xml b/appserver/extras/embedded/all/pom.xml index c8e925caf03..4fc6c7cd69a 100644 --- a/appserver/extras/embedded/all/pom.xml +++ b/appserver/extras/embedded/all/pom.xml @@ -868,6 +868,12 @@ ${project.version} true + + org.glassfish.main.common + glassfish-jdk-extensions + ${project.version} + true + org.glassfish.main.admin config-api @@ -980,6 +986,12 @@ ${project.version} true + + org.glassfish.main.core + glassfish-osgi-bootstrap + ${project.version} + true + org.glassfish.main.core api-exporter diff --git a/appserver/extras/embedded/common/bootstrap/pom.xml b/appserver/extras/embedded/common/bootstrap/pom.xml index ac488ad1fe3..4cd38362ad2 100644 --- a/appserver/extras/embedded/common/bootstrap/pom.xml +++ b/appserver/extras/embedded/common/bootstrap/pom.xml @@ -39,6 +39,12 @@ osgi.core provided + + org.glassfish.main.core + glassfish-osgi-bootstrap + ${project.version} + provided + org.glassfish.main.core glassfish @@ -72,11 +78,11 @@ jar false ${project.build.directory}/classes - META-INF/** + META-INF/**,module-info.class org.glassfish.main.core - glassfish + glassfish-osgi-bootstrap ${project.version} jar false diff --git a/appserver/extras/embedded/common/bootstrap/src/main/java/org/glassfish/uberjar/bootstrap/UberJarOSGiGlassFishRuntimeBuilder.java b/appserver/extras/embedded/common/bootstrap/src/main/java/org/glassfish/uberjar/bootstrap/UberJarOSGiGlassFishRuntimeBuilder.java index fbfe11066f2..680499f4c4c 100644 --- a/appserver/extras/embedded/common/bootstrap/src/main/java/org/glassfish/uberjar/bootstrap/UberJarOSGiGlassFishRuntimeBuilder.java +++ b/appserver/extras/embedded/common/bootstrap/src/main/java/org/glassfish/uberjar/bootstrap/UberJarOSGiGlassFishRuntimeBuilder.java @@ -18,7 +18,6 @@ package org.glassfish.uberjar.bootstrap; import com.sun.enterprise.glassfish.bootstrap.cfg.OsgiPlatform; -import com.sun.enterprise.glassfish.bootstrap.osgi.OSGiFrameworkLauncher; import com.sun.enterprise.util.io.FileUtils; import java.io.File; @@ -37,6 +36,7 @@ import org.glassfish.embeddable.GlassFishException; import org.glassfish.embeddable.GlassFishRuntime; import org.glassfish.embeddable.spi.RuntimeBuilder; +import org.glassfish.main.boot.osgi.OSGiFrameworkLauncher; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; @@ -103,7 +103,7 @@ public void destroy() throws GlassFishException { } @Override - public GlassFishRuntime build(BootstrapProperties bsOptions) throws GlassFishException { + public GlassFishRuntime build(BootstrapProperties bsOptions, ClassLoader classloader) throws GlassFishException { String uberJarURI = bsOptions.getProperty(UBER_JAR_URI); logger.log(Level.FINER, "UberJarOSGiGlassFishRuntimeBuilder.build, uberJarUri={0}", uberJarURI); @@ -154,7 +154,7 @@ public GlassFishRuntime build(BootstrapProperties bsOptions) throws GlassFishExc "jar:" + jar.toString() + "!/modules/instanceroot-builder_jar/," + "jar:" + jar.toString() + "!/modules/kernel_jar/"; - if (isOSGiEnv()) { + if (isOSGiEnv(classloader)) { autoStartBundleLocation = autoStartBundleLocation + ",jar:" + jar.toString() + "!/modules/osgi-modules-uninstaller_jar/"; } @@ -173,8 +173,8 @@ public GlassFishRuntime build(BootstrapProperties bsOptions) throws GlassFishExc logger.logp(Level.FINER, "UberJarOSGiGlassFishRuntimeBuilder", "build", "Building file system {0}", bsOptions); try { - if (!isOSGiEnv()) { - final OSGiFrameworkLauncher fwLauncher = new OSGiFrameworkLauncher(bsOptions.getProperties()); + if (!isOSGiEnv(classloader)) { + final OSGiFrameworkLauncher fwLauncher = new OSGiFrameworkLauncher(bsOptions.getProperties(), classloader); framework = fwLauncher.launchOSGiFrameWork(); return fwLauncher.getService(GlassFishRuntime.class); } @@ -197,8 +197,8 @@ private String getDefaultInstanceRoot() { .getAbsolutePath(); } - private boolean isOSGiEnv() { - return (getClass().getClassLoader() instanceof BundleReference); + private boolean isOSGiEnv(ClassLoader classloader) { + return classloader instanceof BundleReference; } public T getService(Class type, BundleContext context) throws Exception { diff --git a/appserver/extras/embedded/nucleus/pom.xml b/appserver/extras/embedded/nucleus/pom.xml index c330e39893e..ea154852756 100644 --- a/appserver/extras/embedded/nucleus/pom.xml +++ b/appserver/extras/embedded/nucleus/pom.xml @@ -166,6 +166,12 @@ ${project.version} true + + org.glassfish.main.common + glassfish-jdk-extensions + ${project.version} + true + org.glassfish.main.admin config-api @@ -278,6 +284,12 @@ ${project.version} true + + org.glassfish.main.core + glassfish-osgi-bootstrap + ${project.version} + true + org.glassfish.main.core api-exporter diff --git a/appserver/extras/embedded/shell/glassfish-embedded-static-shell/pom.xml b/appserver/extras/embedded/shell/glassfish-embedded-static-shell/pom.xml index 68a3c733b8e..7788ab3a23e 100755 --- a/appserver/extras/embedded/shell/glassfish-embedded-static-shell/pom.xml +++ b/appserver/extras/embedded/shell/glassfish-embedded-static-shell/pom.xml @@ -25,7 +25,7 @@ org.glassfish.main.extras extras 7.0.21-SNAPSHOT - ../../../pom.xml + ../../.. glassfish-embedded-static-shell @@ -35,8 +35,6 @@ ../../../javadb/lib ${path.derby}/derby.jar ${path.derby}/derbyclient.jar ${path.derby}/derbynet.jar ${path.derby}/derbytools.jar ${path.derby}/derbyrun.jar - ../bootstrap - ${path.bootstrap}/glassfish-jul-extension.jar @@ -835,12 +833,6 @@ ${project.version} true - - org.glassfish.main.common - simple-glassfish-api - ${project.version} - true - org.glassfish.external management-api @@ -876,12 +868,6 @@ ${project.version} true - - org.glassfish.main.core - glassfish - ${project.version} - true - org.glassfish.main.core api-exporter @@ -1363,6 +1349,31 @@ woodstox-core true + + + + org.glassfish.main.common + glassfish-jdk-extensions + ${project.version} + provided + + + org.glassfish.main + glassfish-jul-extension + provided + + + org.glassfish.main.common + simple-glassfish-api + ${project.version} + provided + + + org.glassfish.main.core + glassfish + ${project.version} + provided + @@ -1379,7 +1390,7 @@ org.glassfish.embedded.static-shell - ${classpath.derby} ${classpath.bootstrap} + ${classpath.derby} ../asadmin/server-mgmt.jar ../../admin-cli.jar org.glassfish.runnablejar.UberMain diff --git a/appserver/extras/embedded/web/pom.xml b/appserver/extras/embedded/web/pom.xml index 0ecce5cfa20..f4b7ddf39a2 100644 --- a/appserver/extras/embedded/web/pom.xml +++ b/appserver/extras/embedded/web/pom.xml @@ -183,6 +183,12 @@ ${project.version} true + + org.glassfish.main.common + glassfish-jdk-extensions + ${project.version} + true + org.glassfish.main.admin config-api @@ -295,6 +301,12 @@ ${project.version} true + + org.glassfish.main.core + glassfish-osgi-bootstrap + ${project.version} + true + org.glassfish.main.core api-exporter diff --git a/appserver/itest-tools/src/main/java/org/glassfish/main/itest/tools/asadmin/StartServ.java b/appserver/itest-tools/src/main/java/org/glassfish/main/itest/tools/asadmin/StartServ.java index 601af11a230..8148a1defea 100644 --- a/appserver/itest-tools/src/main/java/org/glassfish/main/itest/tools/asadmin/StartServ.java +++ b/appserver/itest-tools/src/main/java/org/glassfish/main/itest/tools/asadmin/StartServ.java @@ -160,4 +160,10 @@ public AsadminResult exec(final int timeout, final String... args) { return result; } + + @Override + public String toString() { + return this.startServ.toString(); + } + } diff --git a/appserver/jms/jms-core/src/main/java/com/sun/enterprise/connectors/jms/JMSLoggerInfo.java b/appserver/jms/jms-core/src/main/java/com/sun/enterprise/connectors/jms/JMSLoggerInfo.java index 92fa2efbdf3..5e91a44d14f 100644 --- a/appserver/jms/jms-core/src/main/java/com/sun/enterprise/connectors/jms/JMSLoggerInfo.java +++ b/appserver/jms/jms-core/src/main/java/com/sun/enterprise/connectors/jms/JMSLoggerInfo.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -183,25 +184,10 @@ public static Logger getLogger() { ) public static final String MDB_CONFIG_EXCEPTION = LOGMSG_PREFIX + "-00023"; - @LogMessageInfo(message = "MQ Resource adapter upgrade started.") + @LogMessageInfo(message = "MQ Resource adapter upgrade from {0} to {1} started.") public static final String JMSRA_UPGRADE_STARTED = LOGMSG_PREFIX + "-00024"; @LogMessageInfo(message = "MQ Resource adapter upgrade completed.") public static final String JMSRA_UPGRADE_COMPLETED = LOGMSG_PREFIX + "-00025"; - @LogMessageInfo( - message = "Upgrading a MQ resource adapter failed : {0}", - level = "WARNING", - cause = "unknown", - action = "unknown" - ) - public static final String JMSRA_UPGRADE_FAILED = LOGMSG_PREFIX + "-00026"; - - @LogMessageInfo( - message = "Check for a new version of MQ installation failed : {0}", - level = "WARNING", - cause = "unknown", - action = "unknown" - ) - public static final String JMSRA_UPGRADE_CHECK_FAILED = LOGMSG_PREFIX + "-00027"; } diff --git a/appserver/jms/jms-core/src/main/java/com/sun/enterprise/connectors/jms/util/JmsRaUtil.java b/appserver/jms/jms-core/src/main/java/com/sun/enterprise/connectors/jms/util/JmsRaUtil.java index 7fe55f88a23..7a9f0603ba0 100755 --- a/appserver/jms/jms-core/src/main/java/com/sun/enterprise/connectors/jms/util/JmsRaUtil.java +++ b/appserver/jms/jms-core/src/main/java/com/sun/enterprise/connectors/jms/util/JmsRaUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -17,7 +17,6 @@ package com.sun.enterprise.connectors.jms.util; -import com.sun.appserv.connectors.internal.api.ConnectorConstants; import com.sun.appserv.connectors.internal.api.ConnectorRuntimeException; import com.sun.enterprise.config.serverbeans.Cluster; import com.sun.enterprise.config.serverbeans.Config; @@ -29,13 +28,15 @@ import com.sun.enterprise.connectors.jms.system.MQAddressList; import com.sun.enterprise.deployment.ConnectorConfigProperty; import com.sun.enterprise.deployment.ConnectorDescriptor; -import com.sun.enterprise.util.SystemPropertyConstants; +import com.sun.enterprise.util.io.FileUtils; import com.sun.enterprise.util.zip.ZipFile; import com.sun.enterprise.util.zip.ZipFileException; import java.io.File; import java.io.FileInputStream; +import java.nio.file.Path; import java.util.List; +import java.util.Objects; import java.util.jar.JarFile; import java.util.jar.Manifest; import java.util.logging.Level; @@ -46,16 +47,23 @@ import org.glassfish.internal.api.RelativePathResolver; import org.jvnet.hk2.config.types.Property; +import static com.sun.appserv.connectors.internal.api.ConnectorConstants.DEFAULT_JMS_ADAPTER; +import static com.sun.enterprise.util.SystemPropertyConstants.IMQ_LIB_PROPERTY; +import static com.sun.enterprise.util.SystemPropertyConstants.INSTALL_ROOT_PROPERTY; +import static java.util.logging.Level.FINE; +import static java.util.logging.Level.FINEST; +import static java.util.logging.Level.INFO; +import static java.util.logging.Level.WARNING; + public class JmsRaUtil { private final static String MQ_RAR = "imqjmsra.rar"; - private final String SYSTEM_APP_DIR = - "lib" + File.separator + "install" + File.separator + "applications"; + /** lib/install/applications */ + private static final Path SYSTEM_APP_DIR = Path.of("lib", "install", "applications"); - private final String MQ_RAR_MANIFEST = - ConnectorConstants.DEFAULT_JMS_ADAPTER + File.separator + "META-INF" - + File.separator + "MANIFEST.MF"; + /** jmsra/META-INF/MANIFEST.MF */ + private static final Path MQ_RAR_MANIFEST = Path.of("META-INF", "MANIFEST.MF"); // Manifest version tag. private final static String MANIFEST_TAG = "Implementation-Version"; @@ -79,10 +87,10 @@ public class JmsRaUtil { private int reconnectDelayInSeconds = DEFAULT_RECONNECT_DELAY; private int reconnectMaxRetries = DEFAULT_RECONNECT_RETRIES; - private boolean reconnectEnabled = false; + private boolean reconnectEnabled; - JmsService js = null; - MQAddressList list = null; + JmsService js; + MQAddressList list; private static final Logger _logger = JMSLoggerInfo.getLogger(); @@ -90,12 +98,13 @@ public JmsRaUtil() throws ConnectorRuntimeException { this(null); } + public JmsRaUtil(JmsService js) throws ConnectorRuntimeException { try { if (js != null) { - this.js = js; + this.js = js; } else { - this.js = Globals.get(JmsService.class); + this.js = Globals.get(JmsService.class); } list = new MQAddressList(this.js); // if (isClustered() && ! this.js.getType().equals( @@ -109,34 +118,39 @@ public JmsRaUtil(JmsService js) throws ConnectorRuntimeException { } } - public void setupAddressList() throws ConnectorRuntimeException{ - try { - list.setup(); - } catch (Exception e) { - throw handleException(e); - } + + public void setupAddressList() throws ConnectorRuntimeException { + try { + list.setup(); + } catch (Exception e) { + throw handleException(e); + } } + public String getUrl() { - try { + try { return list.toString(); - } catch (Exception e) { - return null; - } + } catch (Exception e) { + return null; + } } + public static boolean isClustered(List clusters, String instanceName) { - return (enableClustering() && isServerClustered(clusters, - instanceName)); - } - /** + return (enableClustering() && isServerClustered(clusters, instanceName)); + } + + + /** * Return true if the given server instance is part of a cluster. */ - public static boolean isServerClustered(List clusters, String instanceName) - { + public static boolean isServerClustered(List clusters, String instanceName) { return (getClusterForServer(clusters, instanceName) != null); } - public static Cluster getClusterForServer(List clusters, String instanceName){ + + + public static Cluster getClusterForServer(List clusters, String instanceName) { //Return the server only if it is part of a cluster (i.e. only if a cluster //has a reference to it). for (Object cluster : clusters) { @@ -159,15 +173,15 @@ private static boolean enableClustering() { * this flag is set to false. Default is true. */ String enablecluster = System.getProperty(ENABLE_AUTO_CLUSTERING); - _logger.log(Level.FINE, "Sun MQ Auto cluster system property " + enablecluster); + _logger.log(FINE, "Sun MQ Auto cluster system property " + enablecluster); if ((enablecluster != null) && (enablecluster.trim().equals("false"))){ - _logger.log(Level.FINE, "Disabling Sun MQ Auto Clustering"); + _logger.log(FINE, "Disabling Sun MQ Auto Clustering"); return false; } } catch (Exception e) { } - _logger.log(Level.FINE, "Enabling Sun MQ Auto Clustering"); + _logger.log(FINE, "Enabling Sun MQ Auto Clustering"); return true; } @@ -202,14 +216,11 @@ public String getAddressListBehaviour() { public void setMdbContainerProperties(){ MdbContainer mdbc = null; try { - mdbc = Globals.get(MdbContainer.class); - - } - catch (Exception e) { - _logger.log(Level.WARNING, JMSLoggerInfo.MDB_CONFIG_EXCEPTION, new Object[]{e.getMessage()}); - if (_logger.isLoggable(Level.FINE)) { - _logger.log(Level.FINE, e.getClass().getName(), e); + } catch (Exception e) { + _logger.log(WARNING, JMSLoggerInfo.MDB_CONFIG_EXCEPTION, new Object[] {e.getMessage()}); + if (_logger.isLoggable(FINE)) { + _logger.log(FINE, e.getClass().getName(), e); } } @@ -239,7 +250,7 @@ else if (name.equals reconnectDelayInSeconds = Integer.parseInt(p.getValue()); } catch (Exception e) { - _logger.log(Level.WARNING, JMSLoggerInfo.MDB_CONFIG_EXCEPTION, + _logger.log(WARNING, JMSLoggerInfo.MDB_CONFIG_EXCEPTION, new Object[]{e.getMessage()}); } } @@ -248,7 +259,7 @@ else if (name.equals(propName_reconnect_max_retries)) { reconnectMaxRetries = Integer.parseInt(p.getValue()); } catch (Exception e) { - _logger.log(Level.WARNING, JMSLoggerInfo.MDB_CONFIG_EXCEPTION, + _logger.log(WARNING, JMSLoggerInfo.MDB_CONFIG_EXCEPTION, new Object[]{e.getMessage()}); } } @@ -258,15 +269,15 @@ else if (name.equals cmtMaxRuntimeExceptions = Integer.parseInt(p.getValue()); } catch (Exception e) { - _logger.log(Level.WARNING, JMSLoggerInfo.MDB_CONFIG_EXCEPTION, + _logger.log(WARNING, JMSLoggerInfo.MDB_CONFIG_EXCEPTION, new Object[]{e.getMessage()}); } } } catch (Exception e) { - _logger.log(Level.WARNING, JMSLoggerInfo.MDB_CONFIG_EXCEPTION, + _logger.log(WARNING, JMSLoggerInfo.MDB_CONFIG_EXCEPTION, new Object[]{e.getMessage()}); - if (_logger.isLoggable(Level.FINE)) { - _logger.log(Level.FINE, e.getClass().getName(), e); + if (_logger.isLoggable(FINE)) { + _logger.log(FINE, e.getClass().getName(), e); } } } @@ -278,8 +289,8 @@ else if (name.equals if (reconnectMaxRetries < 0) { reconnectMaxRetries = DEFAULT_RECONNECT_RETRIES; } - if (_logger.isLoggable(Level.FINE)) { - _logger.log(Level.FINE, + if (_logger.isLoggable(FINE)) { + _logger.log(FINE, propName_reconnect_delay_in_seconds+"="+ reconnectDelayInSeconds +", "+ propName_reconnect_max_retries+ "="+reconnectMaxRetries + ", "+ @@ -295,20 +306,18 @@ else if (name.equals } public void configureDescriptor(ConnectorDescriptor cd) { - Object[] envProps = cd.getConfigProperties().toArray(); for (Object envProp2 : envProps) { - ConnectorConfigProperty envProp = (ConnectorConfigProperty ) envProp2; + ConnectorConfigProperty envProp = (ConnectorConfigProperty) envProp2; String name = envProp.getName(); - if (!name.equals("ConnectionURL")) { - continue; - } + if (!name.equals("ConnectionURL")) { + continue; + } String userValue = getUrl(); if (userValue != null) { cd.removeConfigProperty(envProp); - cd.addConfigProperty(new ConnectorConfigProperty ( - name, userValue, userValue, envProp.getType())); + cd.addConfigProperty(new ConnectorConfigProperty(name, userValue, userValue, envProp.getType())); } } @@ -321,107 +330,90 @@ public void configureDescriptor(ConnectorDescriptor cd) { * directory. */ public void upgradeIfNecessary() { + String imqLibPath = System.getProperty(IMQ_LIB_PROPERTY); + if (imqLibPath == null) { + _logger.log(Level.SEVERE, "IMQ lib root system property not set: " + IMQ_LIB_PROPERTY); + return; + } - String installedMqVersion = null; - String deployedMqVersion = null; + String installRoot = System.getProperty(INSTALL_ROOT_PROPERTY); + if (installRoot == null) { + _logger.log(Level.SEVERE, "Install root system property not set: " + INSTALL_ROOT_PROPERTY); + return; + } + final Path imqLib = new File(imqLibPath).toPath(); + final Path deployedDir = new File(installRoot).toPath().resolve(SYSTEM_APP_DIR).resolve(DEFAULT_JMS_ADAPTER); + final File imqLibRar = imqLib.resolve(MQ_RAR).toFile(); + final String installedMqVersion; + final String deployedMqVersion; try { - installedMqVersion = getInstalledMqVersion(); - _logger.log(Level.FINE,"installedMQVersion :: " + installedMqVersion); - deployedMqVersion = getDeployedMqVersion(); - _logger.log(Level.FINE,"deployedMQVersion :: " + deployedMqVersion); - }catch (Exception e) { - return; + installedMqVersion = getInstalledMqVersion(imqLibRar); + _logger.log(FINE, "installedMQVersion: {0}", installedMqVersion); + deployedMqVersion = getDeployedMqVersion(deployedDir); + _logger.log(FINE, "deployedMQVersion: {0}", deployedMqVersion); + } catch (Exception e) { + throw new IllegalStateException("Upgrade failed - could not resolve deployed and installed version.", e); } - String deployed_dir = - java.lang. System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY) - + File.separator + SYSTEM_APP_DIR + File.separator - + ConnectorConstants.DEFAULT_JMS_ADAPTER; + if (installedMqVersion == null) { + _logger.log(INFO, "No JMS RA installation RAR found on path {0}. Nothing for upgrade.", imqLibRar); + return; + } // If the Manifest entry has different versions, then attempt to // explode the MQ resource adapter. - if (!installedMqVersion.equals(deployedMqVersion)) { - try { - _logger.log(Level.INFO, JMSLoggerInfo.JMSRA_UPGRADE_STARTED); - ZipFile rarFile = new ZipFile(System.getProperty - (SystemPropertyConstants.IMQ_LIB_PROPERTY) + - File.separator + MQ_RAR, deployed_dir); - rarFile.explode(); - _logger.log(Level.INFO, JMSLoggerInfo.JMSRA_UPGRADE_COMPLETED); - } catch(ZipFileException ze) { - _logger.log(Level.SEVERE, JMSLoggerInfo.JMSRA_UPGRADE_FAILED, - new Object[]{ze.getMessage()}); - } + if (!Objects.equals(installedMqVersion, deployedMqVersion)) { + try { + _logger.log(INFO, JMSLoggerInfo.JMSRA_UPGRADE_STARTED, + new Object[] {deployedMqVersion, installedMqVersion}); + FileUtils.whack(deployedDir.toFile()); + ZipFile rarFile = new ZipFile(imqLibRar, deployedDir.toFile()); + rarFile.explode(); + _logger.log(INFO, JMSLoggerInfo.JMSRA_UPGRADE_COMPLETED); + } catch (ZipFileException e) { + _logger.log(Level.SEVERE, "Upgrading a MQ resource adapter failed", e); + } } + } + + /** Full path of installed Mq Client library */ + private String getInstalledMqVersion(final File imqLibRar) throws Exception { + // This is for a file based install RAR has to be present in this location + // AS_INSTALL/../imq/lib, but ca be set also to another place. + if (!imqLibRar.exists()) { + return null; + } + _logger.log(FINEST, "Found installation JMS RAR: {0}", imqLibRar); + try (JarFile jFile = new JarFile(imqLibRar)) { + Manifest mf = jFile.getManifest(); + return mf.getMainAttributes().getValue(MANIFEST_TAG); + } } - private String getInstalledMqVersion() throws Exception { - String ver = null; - // Full path of installed Mq Client library - String installed_dir = - System.getProperty(SystemPropertyConstants.IMQ_LIB_PROPERTY); - String jarFile = installed_dir + File.separator + MQ_RAR; - _logger.log(Level.FINE,"Installed MQ JAR " + jarFile); - JarFile jFile = null; - try { - if ((new File(jarFile)).exists()) { - /* This is for a file based install - * RAR has to be present in this location - * ASHOME/imq/lib - */ - jFile = new JarFile(jarFile); - } else { - /* This is for a package based install - * RAR has to be present in this location - * /usr/lib - */ - jFile = new JarFile(installed_dir + File.separator + ".." + File.separator + MQ_RAR); - } - Manifest mf = jFile.getManifest(); - ver = mf.getMainAttributes().getValue(MANIFEST_TAG); - return ver; - } catch (Exception e) { - _logger.log(Level.WARNING, JMSLoggerInfo.JMSRA_UPGRADE_CHECK_FAILED, - new Object[]{e.getMessage() + ":" + jarFile}); - throw e; - } finally { - if (jFile != null) { - jFile.close(); - } - } + /** Full path of Mq client library that is deployed in appserver. */ + private String getDeployedMqVersion(Path deployedDir) throws Exception { + File manifestFile = deployedDir.resolve(MQ_RAR_MANIFEST).toFile(); + if (!manifestFile.exists()) { + return null; + } + _logger.log(FINEST, "Found deployed JMS RA Manifest file {0}", manifestFile); + try (FileInputStream fis = new FileInputStream(manifestFile)) { + Manifest mf = new Manifest(fis); + return mf.getMainAttributes().getValue(MANIFEST_TAG); + } } - private String getDeployedMqVersion() throws Exception { - String ver = null; - // Full path of Mq client library that is deployed in appserver. - String deployed_dir = - System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY) - + File.separator + SYSTEM_APP_DIR; - String manifestFile = deployed_dir + File.separator + - MQ_RAR_MANIFEST; - _logger.log(Level.FINE,"Deployed MQ version Manifest file" + manifestFile); - try (FileInputStream fis = new FileInputStream(manifestFile)) { - Manifest mf = new Manifest(fis); - ver = mf.getMainAttributes().getValue(MANIFEST_TAG); - return ver; - } catch (Exception e) { - _logger.log(Level.WARNING, JMSLoggerInfo.JMSRA_UPGRADE_CHECK_FAILED, - new Object[]{e.getMessage() + ":" + manifestFile}); - throw e; - } - } - - private static ConnectorRuntimeException handleException(Exception e) { - ConnectorRuntimeException cre = - new ConnectorRuntimeException(e.getMessage()); + + private static ConnectorRuntimeException handleException(Exception e) { + ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage()); cre.initCause(e); return cre; } - public static String getJMSPropertyValue(Server as){ + public static String getJMSPropertyValue(Server as) { SystemProperty sp = as.getSystemProperty("JMS_PROVIDER_PORT"); if (sp != null) { return sp.getValue(); @@ -447,16 +439,17 @@ public static String getJMSPropertyValue(Server as){ return null; } - public static String getUnAliasedPwd(String alias){ - try{ + + public static String getUnAliasedPwd(String alias) { + try { String unalisedPwd = RelativePathResolver.getRealPasswordFromAlias(alias); if (unalisedPwd != null && "".equals(unalisedPwd)) { return unalisedPwd; } - }catch(Exception e){ + } catch (Exception e) { } - return alias; + return alias; } } diff --git a/appserver/resources/resources-connector/src/test/resources/DomainTest.xml b/appserver/resources/resources-connector/src/test/resources/DomainTest.xml index 2812bd81297..57034937e42 100644 --- a/appserver/resources/resources-connector/src/test/resources/DomainTest.xml +++ b/appserver/resources/resources-connector/src/test/resources/DomainTest.xml @@ -117,6 +117,8 @@ + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -Djdk.corba.allowOutputStreamSubclass=true -Djdk.tls.rejectClientInitiatedRenegotiation=true diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/AsadminLoggingITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/AsadminLoggingITest.java index 12682968db3..d5cb64c8fd9 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/AsadminLoggingITest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/AsadminLoggingITest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Eclipse Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024 Eclipse Foundation and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/AsadminVerifyDomainXmlITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/AsadminVerifyDomainXmlITest.java new file mode 100644 index 00000000000..dc589033f82 --- /dev/null +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/AsadminVerifyDomainXmlITest.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.main.admin.test; + +import org.glassfish.main.itest.tools.GlassFishTestEnvironment; +import org.glassfish.main.itest.tools.asadmin.Asadmin; +import org.junit.jupiter.api.Test; + +import static org.glassfish.main.itest.tools.asadmin.AsadminResultMatcher.asadminOK; +import static org.hamcrest.MatcherAssert.assertThat; + + +/** + * @author David Matejcek + */ +public class AsadminVerifyDomainXmlITest { + + private static final Asadmin ASADMIN = GlassFishTestEnvironment.getAsadmin(); + + + @Test + public void verifyDomainXml() { + assertThat(ASADMIN.exec("verify-domain-xml"), asadminOK()); + } +} diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/GJULEvsJDKLogManagerIT.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/GJULEvsJDKLogManagerIT.java new file mode 100644 index 00000000000..5ac0e8c6039 --- /dev/null +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/GJULEvsJDKLogManagerIT.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.main.admin.test; + +import java.nio.file.Path; + +import org.glassfish.main.itest.tools.GlassFishTestEnvironment; +import org.glassfish.main.itest.tools.asadmin.Asadmin; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.glassfish.main.itest.tools.asadmin.AsadminResultMatcher.asadminOK; +import static org.hamcrest.MatcherAssert.assertThat; + +public class GJULEvsJDKLogManagerIT { + + private static final Asadmin ASADMIN = GlassFishTestEnvironment.getAsadmin(false); + private static final Path LOGDIR = GlassFishTestEnvironment.getDomain1Directory().resolve("logs").toAbsolutePath(); + private static final String SYSOPT_ERR_LOG = "'-XX:ErrorFile=" + LOGDIR + "/java_error%p.log'"; + private static final String SYSOPT_GC_LOG = "'-Xlog:gc*:file=" + LOGDIR + "/gc-%t.log:time:filecount=10'"; + + @BeforeAll + static void setAndBackup() { + assertThat(ASADMIN.exec(60000, "stop-domain"), asadminOK()); + assertThat(ASADMIN.exec(60000, "backup-domain"), asadminOK()); + assertThat(ASADMIN.exec(60000, "start-domain"), asadminOK()); + } + + + @Test + void testConfigureAndRestart() { + assertThat(ASADMIN.exec(10000, "create-jvm-options", SYSOPT_ERR_LOG), asadminOK()); + assertThat(ASADMIN.exec(10000, "create-jvm-options", SYSOPT_GC_LOG), asadminOK()); + assertThat(ASADMIN.exec(60000, "restart-domain"), asadminOK()); + } + + @AfterAll + static void revert() { + assertThat(ASADMIN.exec(60000, "stop-domain"), asadminOK()); + assertThat(ASADMIN.exec(60000, "restore-domain", "domain1"), asadminOK()); + assertThat(ASADMIN.exec(60000, "start-domain"), asadminOK()); + } +} diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/StartServITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/StartServITest.java index 0f6ce9b95ea..5d3d56b18c0 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/StartServITest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/StartServITest.java @@ -99,7 +99,9 @@ static class StartServArgumentsProvider implements ArgumentsProvider { @Override public Stream provideArguments(ExtensionContext context) { return Stream.of( + // Will be as [1] Arguments.of(STARTSERV), + // Will be as [2] Arguments.of(STARTSERV_IN_TOPLEVEL_BIN) ); } diff --git a/appserver/tests/appserv-tests/config/common.xml b/appserver/tests/appserv-tests/config/common.xml index 710bf2420e2..81fdc22e475 100644 --- a/appserver/tests/appserv-tests/config/common.xml +++ b/appserver/tests/appserv-tests/config/common.xml @@ -61,17 +61,26 @@ Variables used: - + + + + - - + + + + @@ -1399,8 +1408,14 @@ AS_ADMIN_MASTERPASSWORD=${master.password} - + + + + + @@ -1409,6 +1424,28 @@ AS_ADMIN_MASTERPASSWORD=${master.password} + + + + + + + + + + + + + + + + + + + + + + diff --git a/appserver/tests/appserv-tests/config/jws-appclient b/appserver/tests/appserv-tests/config/jws-appclient index 94ba854f71b..9d45bdfbe37 100644 --- a/appserver/tests/appserv-tests/config/jws-appclient +++ b/appserver/tests/appserv-tests/config/jws-appclient @@ -66,14 +66,14 @@ seekJavaOnPath() { } -_AS_INSTALL=$S1AS_HOME -echo "_AS_INSTALL now defined as $_AS_INSTALL" -export _AS_INSTALL +AS_INSTALL=$S1AS_HOME +echo "AS_INSTALL now defined as $AS_INSTALL" +export AS_INSTALL case "`uname`" in - CYGWIN*) _AS_INSTALL=`cygpath --windows $_AS_INSTALL` + CYGWIN*) AS_INSTALL=`cygpath --windows $AS_INSTALL` cygwinProp=-Dorg.glassfish.isCygwin=true esac -. "${_AS_INSTALL}/config/asenv.conf" +. "${AS_INSTALL}/config/asenv.conf" chooseJava diff --git a/appserver/tests/appserv-tests/config/properties.xml b/appserver/tests/appserv-tests/config/properties.xml index 96a131e3c93..745af652514 100644 --- a/appserver/tests/appserv-tests/config/properties.xml +++ b/appserver/tests/appserv-tests/config/properties.xml @@ -105,6 +105,25 @@ AS_ADMIN_MASTERPASSWORD=${master.password} + + + + + + + + + + + + + + + + + @@ -136,7 +155,8 @@ AS_ADMIN_MASTERPASSWORD=${master.password} We use the test script (not appclient) if the user wants to launch app clients using Java Web Start. --> - @@ -162,7 +182,8 @@ AS_ADMIN_MASTERPASSWORD=${master.password} - diff --git a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/build.xml b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/build.xml index 69e2cd12d2a..176972fb941 100644 --- a/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/build.xml +++ b/appserver/tests/appserv-tests/devtests/cdi/javaee-integration/normal-bean-injection-ear/build.xml @@ -46,7 +46,7 @@ - + - - - - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/connector/v3/administered-object-definition/build.xml b/appserver/tests/appserv-tests/devtests/connector/v3/administered-object-definition/build.xml index 7935d7069af..d81b6cb761d 100644 --- a/appserver/tests/appserv-tests/devtests/connector/v3/administered-object-definition/build.xml +++ b/appserver/tests/appserv-tests/devtests/connector/v3/administered-object-definition/build.xml @@ -44,10 +44,12 @@ + modulepath="${env.S1AS_HOME}/lib/bootstrap" + classpath="${mvn.lib.dir}/junit.jar:${s1astest.classpath}" + debug="on" includeantruntime="false" failonerror="true"> + + + @@ -79,6 +81,11 @@ + + + + + diff --git a/appserver/tests/appserv-tests/devtests/connector/v3/administered-object-definition/ut/ArchiveTest.java b/appserver/tests/appserv-tests/devtests/connector/v3/administered-object-definition/ut/ArchiveTest.java index a2138a8a7b2..fef3d80697c 100644 --- a/appserver/tests/appserv-tests/devtests/connector/v3/administered-object-definition/ut/ArchiveTest.java +++ b/appserver/tests/appserv-tests/devtests/connector/v3/administered-object-definition/ut/ArchiveTest.java @@ -67,7 +67,7 @@ private void doTestApplicationArchive() throws Exception{ ApplicationArchivist reader = (ApplicationArchivist) TestUtil.getByType(ApplicationArchivist.class); reader.setAnnotationProcessingRequested(true); - ASURLClassLoader classLoader = new ASURLClassLoader(this.getClass().getClassLoader()); + ASURLClassLoader classLoader = new ASURLClassLoader(appArchiveName, this.getClass().getClassLoader()); classLoader.addURL(archive.toURL()); reader.setClassLoader(classLoader); @@ -122,7 +122,7 @@ private void doTestWebArchive() throws Exception{ File archive = new File(archiveDir, appArchiveName); assertTrue("Do not fing the archive "+archive.getAbsolutePath(), archive.exists()); - ASURLClassLoader classLoader = new ASURLClassLoader(this.getClass().getClassLoader()); + ASURLClassLoader classLoader = new ASURLClassLoader(appArchiveName, this.getClass().getClassLoader()); classLoader.addURL(archive.toURL()); WebArchivist reader = (WebArchivist) TestUtil.getByType(WebArchivist.class); @@ -233,7 +233,7 @@ private void doTestEJBArchive() throws Exception{ File archive = new File(archiveDir, appArchiveName); assertTrue("Do not fing the archive "+archive.getAbsolutePath(), archive.exists()); - ASURLClassLoader classLoader = new ASURLClassLoader(this.getClass().getClassLoader()); + ASURLClassLoader classLoader = new ASURLClassLoader(appArchiveName, this.getClass().getClassLoader()); classLoader.addURL(archive.toURL()); EjbArchivist reader = (EjbArchivist) TestUtil.getByType(EjbArchivist.class); diff --git a/appserver/tests/appserv-tests/devtests/connector/v3/connection-factory-definition/build.xml b/appserver/tests/appserv-tests/devtests/connector/v3/connection-factory-definition/build.xml index 6175f553644..c15bfec6632 100644 --- a/appserver/tests/appserv-tests/devtests/connector/v3/connection-factory-definition/build.xml +++ b/appserver/tests/appserv-tests/devtests/connector/v3/connection-factory-definition/build.xml @@ -18,10 +18,10 @@ --> - - - - ]> + + + +]> @@ -32,60 +32,68 @@ - - + + - - + + - - + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -95,7 +103,7 @@ - + diff --git a/appserver/tests/appserv-tests/devtests/connector/v3/connection-factory-definition/ut/ArchiveTest.java b/appserver/tests/appserv-tests/devtests/connector/v3/connection-factory-definition/ut/ArchiveTest.java index 55171d11b2f..5ea30dfa897 100644 --- a/appserver/tests/appserv-tests/devtests/connector/v3/connection-factory-definition/ut/ArchiveTest.java +++ b/appserver/tests/appserv-tests/devtests/connector/v3/connection-factory-definition/ut/ArchiveTest.java @@ -68,7 +68,7 @@ private void doTestApplicationArchive() throws Exception{ ApplicationArchivist reader = (ApplicationArchivist) TestUtil.getByType(ApplicationArchivist.class); reader.setAnnotationProcessingRequested(true); - ASURLClassLoader classLoader = new ASURLClassLoader(this.getClass().getClassLoader()); + ASURLClassLoader classLoader = new ASURLClassLoader(appArchiveName, this.getClass().getClassLoader()); classLoader.addURL(archive.toURL()); reader.setClassLoader(classLoader); @@ -127,7 +127,7 @@ private void doTestWebArchive() throws Exception{ File archive = new File(archiveDir, appArchiveName); assertTrue("Do not fing the archive "+archive.getAbsolutePath(), archive.exists()); - ASURLClassLoader classLoader = new ASURLClassLoader(this.getClass().getClassLoader()); + ASURLClassLoader classLoader = new ASURLClassLoader(appArchiveName, this.getClass().getClassLoader()); classLoader.addURL(archive.toURL()); WebArchivist reader = (WebArchivist) TestUtil.getByType(WebArchivist.class); @@ -236,7 +236,7 @@ private void doTestEJBArchive() throws Exception{ File archive = new File(archiveDir, appArchiveName); assertTrue("Do not fing the archive "+archive.getAbsolutePath(), archive.exists()); - ASURLClassLoader classLoader = new ASURLClassLoader(this.getClass().getClassLoader()); + ASURLClassLoader classLoader = new ASURLClassLoader(appArchiveName, this.getClass().getClassLoader()); classLoader.addURL(archive.toURL()); EjbArchivist reader = (EjbArchivist) TestUtil.getByType(EjbArchivist.class); diff --git a/appserver/tests/appserv-tests/devtests/connector/v3/ejb32-mdb/build.xml b/appserver/tests/appserv-tests/devtests/connector/v3/ejb32-mdb/build.xml index 3207e79bcc7..18d6653ecf5 100644 --- a/appserver/tests/appserv-tests/devtests/connector/v3/ejb32-mdb/build.xml +++ b/appserver/tests/appserv-tests/devtests/connector/v3/ejb32-mdb/build.xml @@ -83,14 +83,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/connector/v3/jms-destination-definition/ut/ArchiveTest.java b/appserver/tests/appserv-tests/devtests/connector/v3/jms-destination-definition/ut/ArchiveTest.java index a34da4f5521..fbca68cbe6a 100644 --- a/appserver/tests/appserv-tests/devtests/connector/v3/jms-destination-definition/ut/ArchiveTest.java +++ b/appserver/tests/appserv-tests/devtests/connector/v3/jms-destination-definition/ut/ArchiveTest.java @@ -70,7 +70,7 @@ private void doTestApplicationArchive() throws IOException, SAXParseException { ApplicationArchivist reader = (ApplicationArchivist) TestUtil.getByType(ApplicationArchivist.class); reader.setAnnotationProcessingRequested(true); - ASURLClassLoader classLoader = new ASURLClassLoader(this.getClass().getClassLoader()); + ASURLClassLoader classLoader = new ASURLClassLoader(appArchiveName, this.getClass().getClassLoader()); classLoader.addURL(archive.toURL()); reader.setClassLoader(classLoader); Application applicationDesc = reader.open(archive); @@ -115,7 +115,7 @@ private void doTestApplicationClientArchive() throws IOException, SAXParseExcept File archive = new File(archiveDir, appArchiveName); assertTrue("Do not find the archive: " + archive.getAbsolutePath(), archive.exists()); - ASURLClassLoader classLoader = new ASURLClassLoader(this.getClass().getClassLoader()); + ASURLClassLoader classLoader = new ASURLClassLoader(appArchiveName, this.getClass().getClassLoader()); classLoader.addURL(archive.toURL()); AppClientArchivist reader = (AppClientArchivist)TestUtil.getByType(AppClientArchivist.class); @@ -221,7 +221,7 @@ private void doTestWebArchive() throws IOException, SAXParseException { File archive = new File(archiveDir, appArchiveName); assertTrue("Do not find the archive: " + archive.getAbsolutePath(), archive.exists()); - ASURLClassLoader classLoader = new ASURLClassLoader(this.getClass().getClassLoader()); + ASURLClassLoader classLoader = new ASURLClassLoader(appArchiveName, this.getClass().getClassLoader()); classLoader.addURL(archive.toURL()); WebArchivist reader = (WebArchivist) TestUtil.getByType(WebArchivist.class); @@ -327,7 +327,7 @@ private void doTestEJBArchive() throws IOException, SAXParseException { File archive = new File(archiveDir, appArchiveName); assertTrue("Do not find the archive: " + archive.getAbsolutePath(), archive.exists()); - ASURLClassLoader classLoader = new ASURLClassLoader(this.getClass().getClassLoader()); + ASURLClassLoader classLoader = new ASURLClassLoader(appArchiveName, this.getClass().getClassLoader()); classLoader.addURL(archive.toURL()); EjbArchivist reader = (EjbArchivist) TestUtil.getByType(EjbArchivist.class); diff --git a/appserver/tests/appserv-tests/devtests/deployment/config/common.xml b/appserver/tests/appserv-tests/devtests/deployment/config/common.xml index b3cb31ba5b9..bfed63cc0f9 100644 --- a/appserver/tests/appserv-tests/devtests/deployment/config/common.xml +++ b/appserver/tests/appserv-tests/devtests/deployment/config/common.xml @@ -133,6 +133,7 @@ + diff --git a/appserver/tests/appserv-tests/devtests/deployment/directorydeploy/ear/build.xml b/appserver/tests/appserv-tests/devtests/deployment/directorydeploy/ear/build.xml index 0a57ca6a8e5..e5ba39cb66f 100644 --- a/appserver/tests/appserv-tests/devtests/deployment/directorydeploy/ear/build.xml +++ b/appserver/tests/appserv-tests/devtests/deployment/directorydeploy/ear/build.xml @@ -144,7 +144,6 @@ resultproperty="result"> - diff --git a/appserver/tests/appserv-tests/devtests/deployment/directorydeploy/ejb/build.xml b/appserver/tests/appserv-tests/devtests/deployment/directorydeploy/ejb/build.xml index 96d09a39122..a600ce80235 100644 --- a/appserver/tests/appserv-tests/devtests/deployment/directorydeploy/ejb/build.xml +++ b/appserver/tests/appserv-tests/devtests/deployment/directorydeploy/ejb/build.xml @@ -114,6 +114,11 @@ + + + + + diff --git a/appserver/tests/appserv-tests/devtests/deployment/directorydeploy/ejbwithsuffix/build.xml b/appserver/tests/appserv-tests/devtests/deployment/directorydeploy/ejbwithsuffix/build.xml index 6cd74e797a8..6b21522c596 100644 --- a/appserver/tests/appserv-tests/devtests/deployment/directorydeploy/ejbwithsuffix/build.xml +++ b/appserver/tests/appserv-tests/devtests/deployment/directorydeploy/ejbwithsuffix/build.xml @@ -115,7 +115,11 @@ - + + + + + diff --git a/appserver/tests/appserv-tests/devtests/deployment/dol/override/build.xml b/appserver/tests/appserv-tests/devtests/deployment/dol/override/build.xml index 5f53e7e6ee7..58b18f05bfa 100644 --- a/appserver/tests/appserv-tests/devtests/deployment/dol/override/build.xml +++ b/appserver/tests/appserv-tests/devtests/deployment/dol/override/build.xml @@ -56,7 +56,7 @@ -${inst} + ${inst} - + + + + + diff --git a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/build.xml b/appserver/tests/appserv-tests/devtests/deployment/dol/validation/build.xml index 9af8e54a1f3..77556763caf 100644 --- a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/build.xml +++ b/appserver/tests/appserv-tests/devtests/deployment/dol/validation/build.xml @@ -37,9 +37,6 @@ - - @@ -52,30 +49,11 @@ - - - - - - - - - - - - - - @@ -97,8 +75,6 @@ - - @@ -115,42 +91,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -${inst} + ${inst} - + + + + + @@ -222,28 +170,6 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar/META-INF/application.xml b/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar/META-INF/application.xml deleted file mode 100644 index 166e0cd0ea4..00000000000 --- a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar/META-INF/application.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - -Application description -ValidationApp - -employee-service-icon16x16.jpg - - -validation.rar - - -emp app role -employee_app - - -admin app role -administrator_app - - diff --git a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar/META-INF/weblogic-application.xml b/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar/META-INF/weblogic-application.xml deleted file mode 100644 index 1f3247be50e..00000000000 --- a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar/META-INF/weblogic-application.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - param1 - val1 - - diff --git a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar/wlsRar/META-INF/ra.xml b/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar/wlsRar/META-INF/ra.xml deleted file mode 100644 index 83995a076ee..00000000000 --- a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar/wlsRar/META-INF/ra.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - SimpleVersionableRA - deploymentTestCo - StartupClassRA - 0.1 - - - connector.ResourceAdapterImpl - - - - diff --git a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar/wlsRar/META-INF/weblogic-ra.xml b/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar/wlsRar/META-INF/weblogic-ra.xml deleted file mode 100644 index 4f2edd1111d..00000000000 --- a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar/wlsRar/META-INF/weblogic-ra.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - ResourceAdapter - diff --git a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar2/META-INF/application.xml b/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar2/META-INF/application.xml deleted file mode 100644 index 166e0cd0ea4..00000000000 --- a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar2/META-INF/application.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - -Application description -ValidationApp - -employee-service-icon16x16.jpg - - -validation.rar - - -emp app role -employee_app - - -admin app role -administrator_app - - diff --git a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar2/META-INF/weblogic-application.xml b/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar2/META-INF/weblogic-application.xml deleted file mode 100644 index 38d63832b20..00000000000 --- a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar2/META-INF/weblogic-application.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - param1 - val1 - - diff --git a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar3/META-INF/application.xml b/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar3/META-INF/application.xml deleted file mode 100644 index 166e0cd0ea4..00000000000 --- a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar3/META-INF/application.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - -Application description -ValidationApp - -employee-service-icon16x16.jpg - - -validation.rar - - -emp app role -employee_app - - -admin app role -administrator_app - - diff --git a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar3/META-INF/weblogic-application.xml b/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar3/META-INF/weblogic-application.xml deleted file mode 100644 index e44c3f1140d..00000000000 --- a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsEar3/META-INF/weblogic-application.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - true - - - dictionary - - - - diff --git a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsRar/META-INF/ra.xml b/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsRar/META-INF/ra.xml deleted file mode 100644 index 18280631ce8..00000000000 --- a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsRar/META-INF/ra.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - SimpleVersionableRA - deploymentTestCo - StartupClassRA - 0.1 - - - connector.ResourceAdapterImpl - - - - - diff --git a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsRar/META-INF/weblogic-ra.xml b/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsRar/META-INF/weblogic-ra.xml deleted file mode 100644 index 4f2edd1111d..00000000000 --- a/appserver/tests/appserv-tests/devtests/deployment/dol/validation/wlsRar/META-INF/weblogic-ra.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - ResourceAdapter - diff --git a/appserver/tests/appserv-tests/devtests/deployment/versioning/versioning-common.xml b/appserver/tests/appserv-tests/devtests/deployment/versioning/versioning-common.xml index 7488e71c539..1c2b8daac52 100644 --- a/appserver/tests/appserv-tests/devtests/deployment/versioning/versioning-common.xml +++ b/appserver/tests/appserv-tests/devtests/deployment/versioning/versioning-common.xml @@ -35,8 +35,8 @@ @param ${force} (optional) --> - - + + - - - + + + @@ -64,9 +64,9 @@ @param ${versionExpression} (optional) --> - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - + @@ -125,7 +125,7 @@ - + - + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - + + + + + - - - + + + + + - - - + + + + + - - - + + - - - + + + + + - - - + + + + + - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + - + - - - + + + - - - + + + + + - + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - + + - - + + - - - - + + + + - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - + + + + + + + + - + - + - + - - + + - - + + - + - + - + - + - + @@ -500,7 +530,7 @@ @param ${xmlVersionIdentifier} (optional) --> - + @@ -522,36 +552,38 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - + - + - - + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + - - + + + + + + + + + + + + + - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - + - + - @@ -640,9 +678,9 @@ - - + - - - - - - - - - - - - - - - - - - + + - - - - + + + + - - - - + + + + - - - + + - - - + + - - - - + + + + + + + + - - - - - - - + + + + + + + - + @@ -777,31 +822,31 @@ - + - - - + + + - + - + - + - + - + - - - + + + diff --git a/appserver/tests/appserv-tests/devtests/deployment/webservices/annotations-common.xml b/appserver/tests/appserv-tests/devtests/deployment/webservices/annotations-common.xml index 71c9efd0b09..18e86707e8e 100644 --- a/appserver/tests/appserv-tests/devtests/deployment/webservices/annotations-common.xml +++ b/appserver/tests/appserv-tests/devtests/deployment/webservices/annotations-common.xml @@ -70,7 +70,7 @@ diff --git a/appserver/tests/appserv-tests/devtests/deployment/webservices/noinf/build.xml b/appserver/tests/appserv-tests/devtests/deployment/webservices/noinf/build.xml index 1c5021e4c76..e4b9a7a85af 100644 --- a/appserver/tests/appserv-tests/devtests/deployment/webservices/noinf/build.xml +++ b/appserver/tests/appserv-tests/devtests/deployment/webservices/noinf/build.xml @@ -18,7 +18,7 @@ --> - + ]> diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb30/clientview/adapted/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb30/clientview/adapted/build.xml index e257621f29b..aecba6bd67f 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb30/clientview/adapted/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb30/clientview/adapted/build.xml @@ -32,7 +32,7 @@ - + @@ -63,13 +63,10 @@ - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb30/clientview/core/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb30/clientview/core/build.xml index ccadb697582..3bc0964e91b 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb30/clientview/core/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb30/clientview/core/build.xml @@ -32,7 +32,7 @@ - + @@ -63,13 +63,10 @@ - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb30/clientview/exceptions/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb30/clientview/exceptions/build.xml index c8920160ce3..858fc9b8470 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb30/clientview/exceptions/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb30/clientview/exceptions/build.xml @@ -63,13 +63,10 @@ - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb30/hello/session/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb30/hello/session/build.xml index 0bae76fae6c..d2e57df0e3d 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb30/hello/session/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb30/hello/session/build.xml @@ -31,73 +31,67 @@ - - - - - - - - + + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb30/hello/session5/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb30/hello/session5/build.xml index 20be0d6aca8..35c6d758324 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb30/hello/session5/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb30/hello/session5/build.xml @@ -66,6 +66,7 @@ + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb30/persistence/tx_propagation/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb30/persistence/tx_propagation/build.xml index f674fc1d055..675f1158fa6 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb30/persistence/tx_propagation/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb30/persistence/tx_propagation/build.xml @@ -120,13 +120,10 @@ - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/asynchronous/localandremote/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/asynchronous/localandremote/build.xml index 1d571d1b77c..393ed43546f 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/asynchronous/localandremote/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/asynchronous/localandremote/build.xml @@ -61,15 +61,10 @@ - - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/asynchronous/remote/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/asynchronous/remote/build.xml index 4e78e11e25b..c09503c6084 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/asynchronous/remote/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/asynchronous/remote/build.xml @@ -61,15 +61,10 @@ - - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/asynchronous/threadpoolconfig/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/asynchronous/threadpoolconfig/build.xml index f05fe8c448b..9c3cd430d3c 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/asynchronous/threadpoolconfig/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/asynchronous/threadpoolconfig/build.xml @@ -64,14 +64,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/generics/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/generics/build.xml index 8cce1ef2b57..48c21f863b2 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/generics/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/generics/build.xml @@ -60,15 +60,10 @@ - - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/javamodule/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/javamodule/build.xml index 9e7c657373b..aa502258367 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/javamodule/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/javamodule/build.xml @@ -60,15 +60,10 @@ - - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/jaxrs/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/jaxrs/build.xml index c83a5586f35..ea1d027622b 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/jaxrs/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/jaxrs/build.xml @@ -2,7 +2,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/managedbean/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/managedbean/build.xml index d511bfb09cc..8b3701424b3 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/managedbean/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/managedbean/build.xml @@ -60,15 +60,10 @@ - - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/sinitcallejb/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/sinitcallejb/build.xml index bbd697beae5..a4f99ef2f67 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/sinitcallejb/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/ejblite/sinitcallejb/build.xml @@ -60,15 +60,10 @@ - - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/basic/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/basic/build.xml index aa5a6c4b50c..2d8071804aa 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/basic/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/basic/build.xml @@ -66,13 +66,17 @@ - + + + - + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/build.xml index a065ef7c6f3..4c978f78731 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/build.xml @@ -195,32 +195,31 @@ ant all (Executes all the ejb-ejb31-embedded tests) - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/datasourcedef/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/datasourcedef/build.xml index 9ac34f4d87d..5b8b21406f4 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/datasourcedef/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/datasourcedef/build.xml @@ -68,8 +68,11 @@ + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/ejbandwar/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/ejbandwar/build.xml index f83a71cff30..0f9ed89bdef 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/ejbandwar/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/ejbandwar/build.xml @@ -94,8 +94,11 @@ + + @@ -107,8 +110,11 @@ + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/ejbinwar/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/ejbinwar/build.xml index 0a621f85993..3348442eb91 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/ejbinwar/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/ejbinwar/build.xml @@ -85,8 +85,11 @@ + + @@ -97,8 +100,11 @@ + + @@ -110,8 +116,11 @@ + + @@ -122,8 +131,11 @@ + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/embedasync/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/embedasync/build.xml index 511682c8615..48cd652d3b5 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/embedasync/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/embedasync/build.xml @@ -68,8 +68,11 @@ + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/jaxrs/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/jaxrs/build.xml index 41a99673762..84be1017f65 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/jaxrs/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/jaxrs/build.xml @@ -79,9 +79,7 @@ - @@ -91,7 +89,9 @@ + @@ -129,12 +129,15 @@ + + - + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/manifestonly/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/manifestonly/build.xml index c344c7ecad7..34327f93c10 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/manifestonly/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/manifestonly/build.xml @@ -85,8 +85,11 @@ + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/mdb/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/mdb/build.xml index 582eb3cd711..4f0e20d8904 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/mdb/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/mdb/build.xml @@ -133,11 +133,16 @@ + + + + - + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/twomodules/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/twomodules/build.xml index 7e92846f116..0e42cd5da81 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/twomodules/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/twomodules/build.xml @@ -72,10 +72,13 @@ - + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/twomoduleswithlibs/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/twomoduleswithlibs/build.xml index 68599e6ea38..99cdd313d23 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/twomoduleswithlibs/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/embedded/twomoduleswithlibs/build.xml @@ -108,14 +108,13 @@ + + - @@ -124,8 +123,11 @@ + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/disable_nonportable_jndi/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/disable_nonportable_jndi/build.xml index 6f1651d3094..83797da4037 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/disable_nonportable_jndi/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/disable_nonportable_jndi/build.xml @@ -64,14 +64,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/ear/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/ear/build.xml index 1c13adebe55..67d6a03008d 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/ear/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/ear/build.xml @@ -70,15 +70,10 @@ - - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/jcdifull/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/jcdifull/build.xml index 6a4ce1153f4..ed211807681 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/jcdifull/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/jcdifull/build.xml @@ -32,12 +32,18 @@ - + - - + + + + + @@ -49,9 +55,9 @@ - - - + + + @@ -69,15 +75,10 @@ - - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/passact/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/passact/build.xml index 830df673186..117d9e5daf7 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/passact/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/passact/build.xml @@ -64,14 +64,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/remote1/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/remote1/build.xml index bc32871bbbe..9c709454bb5 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/remote1/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/remote1/build.xml @@ -64,14 +64,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/remote2/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/remote2/build.xml index ac3db23b0c3..a1f9e79ab86 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/remote2/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/remote2/build.xml @@ -61,15 +61,10 @@ - - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/schema/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/schema/build.xml index d4b406dc5d8..94e8b682107 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/schema/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/schema/build.xml @@ -61,14 +61,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/sfsbscnc/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/sfsbscnc/build.xml index d19618fb6aa..64ed9cef075 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/sfsbscnc/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/sfsbscnc/build.xml @@ -61,15 +61,10 @@ - - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/webandejb/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/webandejb/build.xml index c4c777bffce..213aaeeff0a 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/webandejb/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/full/webandejb/build.xml @@ -60,15 +60,10 @@ - - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/security/simple/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/security/simple/build.xml index 8c27fee2dfc..55f4e6abf17 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/security/simple/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/security/simple/build.xml @@ -40,8 +40,7 @@ - - + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/cache/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/cache/build.xml index 4843f0be76f..df657149382 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/cache/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/cache/build.xml @@ -61,14 +61,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/hello/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/hello/build.xml index ee9fb7ee6cb..639f5fa5a9f 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/hello/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/hello/build.xml @@ -63,14 +63,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/multi-module/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/multi-module/build.xml index f43c1ad8919..7b88f9ab28f 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/multi-module/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/multi-module/build.xml @@ -120,15 +120,13 @@ - - - - - - + + + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/threemodules/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/threemodules/build.xml index 9a42369fc85..b127b47f76b 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/threemodules/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/singleton/threemodules/build.xml @@ -120,15 +120,13 @@ - - - - - - + + + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/timer31/mdb/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/timer31/mdb/build.xml index 1cb6ec25fe6..bd357bd5f1d 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/timer31/mdb/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/timer31/mdb/build.xml @@ -74,15 +74,10 @@ - - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb31/timer31/methodintf/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb31/timer31/methodintf/build.xml index 59c1e88a1b7..c372cfc679a 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb31/timer31/methodintf/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb31/timer31/methodintf/build.xml @@ -57,15 +57,10 @@ - - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/embedded/autoclose/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/embedded/autoclose/build.xml index 266ef591620..35320707ef4 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/embedded/autoclose/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/embedded/autoclose/build.xml @@ -63,16 +63,11 @@ - - - - - - - + + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/aroundconstruct/annotation/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/aroundconstruct/annotation/build.xml index b27f71b6817..6cd67847cfd 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/aroundconstruct/annotation/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/aroundconstruct/annotation/build.xml @@ -57,14 +57,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/aroundconstruct/descriptor/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/aroundconstruct/descriptor/build.xml index 990413f00e2..9d5f32dbb3f 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/aroundconstruct/descriptor/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/aroundconstruct/descriptor/build.xml @@ -58,14 +58,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/constructor-level/annotation/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/constructor-level/annotation/build.xml index e505cb6f98d..c0bbc289a08 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/constructor-level/annotation/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/constructor-level/annotation/build.xml @@ -57,14 +57,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/constructor-level/descriptor/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/constructor-level/descriptor/build.xml index f8c413b3580..3bbdf208fab 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/constructor-level/descriptor/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/constructor-level/descriptor/build.xml @@ -58,14 +58,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/get_method_lc/annotation/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/get_method_lc/annotation/build.xml index d5a4011366c..9171bf6cd76 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/get_method_lc/annotation/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/get_method_lc/annotation/build.xml @@ -57,14 +57,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/get_method_lc/descriptor/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/get_method_lc/descriptor/build.xml index 3ae0f442dd6..3d4a9ced23d 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/get_method_lc/descriptor/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/get_method_lc/descriptor/build.xml @@ -58,14 +58,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/interceptors-inheritance/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/interceptors-inheritance/build.xml index 393200f6961..67b025c481f 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/interceptors-inheritance/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/interceptors-inheritance/build.xml @@ -57,14 +57,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/lc-method-constructor-level/annotation/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/lc-method-constructor-level/annotation/build.xml index a5e63b73d56..e47dea9910c 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/lc-method-constructor-level/annotation/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/lc-method-constructor-level/annotation/build.xml @@ -57,14 +57,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/lc-method-constructor-level/descriptor/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/lc-method-constructor-level/descriptor/build.xml index 23f6a43bcaf..158bbb7ee4e 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/lc-method-constructor-level/descriptor/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/interceptors/lc-method-constructor-level/descriptor/build.xml @@ -58,14 +58,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/intfces/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/intfces/build.xml index 9d158671427..d1cdfacb38d 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/intfces/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/intfces/build.xml @@ -32,7 +32,7 @@ - + @@ -49,27 +49,24 @@ - + - + - + - + @@ -80,36 +77,30 @@ - + - + - + - + - - - - - - - + + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/mdb/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/mdb/build.xml index 3207e79bcc7..18d6653ecf5 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/mdb/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/mdb/build.xml @@ -83,14 +83,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/methodintf/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/methodintf/build.xml index 5a9ce770a20..24f5c347459 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/methodintf/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/methodintf/build.xml @@ -57,14 +57,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/sfsb/basic/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/sfsb/basic/build.xml index 6e7cb99c935..7c331af1fee 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/sfsb/basic/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/sfsb/basic/build.xml @@ -61,14 +61,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/sfsb/descriptor/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/sfsb/descriptor/build.xml index b7441aefc02..e498455a73e 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/sfsb/descriptor/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/sfsb/descriptor/build.xml @@ -61,14 +61,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/sfsb/lifecycle_cb_txattr/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/sfsb/lifecycle_cb_txattr/build.xml index 5276631d350..a9a0b4ed58f 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/sfsb/lifecycle_cb_txattr/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/sfsb/lifecycle_cb_txattr/build.xml @@ -61,14 +61,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/ejb32/timer/opallowed/build.xml b/appserver/tests/appserv-tests/devtests/ejb/ejb32/timer/opallowed/build.xml index 5fd83c67a72..86c8c81616d 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/ejb32/timer/opallowed/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/ejb32/timer/opallowed/build.xml @@ -31,99 +31,96 @@ - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/appserver/tests/appserv-tests/devtests/ejb/stubs/standaloneclient/build.xml b/appserver/tests/appserv-tests/devtests/ejb/stubs/standaloneclient/build.xml index cc024134b01..0fc9918b262 100644 --- a/appserver/tests/appserv-tests/devtests/ejb/stubs/standaloneclient/build.xml +++ b/appserver/tests/appserv-tests/devtests/ejb/stubs/standaloneclient/build.xml @@ -32,42 +32,39 @@ - + - - - + + - - - - - - + + + + + - - - + @@ -94,17 +91,12 @@ - - - - - - - + + + + + + diff --git a/appserver/tests/appserv-tests/devtests/jdbc/flushconnectionpool/build.xml b/appserver/tests/appserv-tests/devtests/jdbc/flushconnectionpool/build.xml index f63f3cb5d05..97acbc8cb14 100755 --- a/appserver/tests/appserv-tests/devtests/jdbc/flushconnectionpool/build.xml +++ b/appserver/tests/appserv-tests/devtests/jdbc/flushconnectionpool/build.xml @@ -49,10 +49,9 @@ - + + value="**/SimpleBMP.class, **/SimpleBMPHome.class,**/*Client*.class"/> @@ -60,7 +59,6 @@ - @@ -72,8 +70,7 @@ - + @@ -82,7 +79,6 @@ - @@ -92,29 +88,22 @@ - - - - - - - - - - + + + ]> @@ -37,50 +37,39 @@ - - - + + + - - - - + + + + - - - - + + + + - - - - - - - - - - - - - - - - + + + + + - - - + + + diff --git a/appserver/tests/appserv-tests/devtests/naming/injection/build.xml b/appserver/tests/appserv-tests/devtests/naming/injection/build.xml index 625a71baf4b..e6d7642e2fe 100644 --- a/appserver/tests/appserv-tests/devtests/naming/injection/build.xml +++ b/appserver/tests/appserv-tests/devtests/naming/injection/build.xml @@ -73,14 +73,10 @@ - - - - - + + + + diff --git a/appserver/tests/appserv-tests/devtests/security/ejb-mutual-ssl/build.xml b/appserver/tests/appserv-tests/devtests/security/ejb-mutual-ssl/build.xml index 6ca67c20743..ed786c60143 100644 --- a/appserver/tests/appserv-tests/devtests/security/ejb-mutual-ssl/build.xml +++ b/appserver/tests/appserv-tests/devtests/security/ejb-mutual-ssl/build.xml @@ -39,7 +39,7 @@ - + @@ -70,43 +70,46 @@ - + - - - - - + + + + + - + - + - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -114,6 +117,6 @@ - + diff --git a/appserver/tests/appserv-tests/devtests/security/ejb-oneway-ssl/build.xml b/appserver/tests/appserv-tests/devtests/security/ejb-oneway-ssl/build.xml index 561375d6fac..98e180ca32a 100644 --- a/appserver/tests/appserv-tests/devtests/security/ejb-oneway-ssl/build.xml +++ b/appserver/tests/appserv-tests/devtests/security/ejb-oneway-ssl/build.xml @@ -37,7 +37,7 @@ - + @@ -58,22 +58,22 @@ - - + + - - - - - + + + + + - + @@ -82,17 +82,21 @@ - - - - - - - - - + + + + + + + + + + + + + + diff --git a/appserver/tests/appserv-tests/devtests/security/simple-perf/build.xml b/appserver/tests/appserv-tests/devtests/security/simple-perf/build.xml index 3e0613676f4..148d4984527 100644 --- a/appserver/tests/appserv-tests/devtests/security/simple-perf/build.xml +++ b/appserver/tests/appserv-tests/devtests/security/simple-perf/build.xml @@ -35,7 +35,7 @@ - + @@ -56,28 +56,28 @@ - + - - - - - - - - - - - + + + + + + + + + + + - + @@ -86,18 +86,22 @@ - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/appserver/tests/appserv-tests/devtests/security/standalone/loginctxdriver/build.xml b/appserver/tests/appserv-tests/devtests/security/standalone/loginctxdriver/build.xml index 6e9533c0898..93f3ebd87ca 100644 --- a/appserver/tests/appserv-tests/devtests/security/standalone/loginctxdriver/build.xml +++ b/appserver/tests/appserv-tests/devtests/security/standalone/loginctxdriver/build.xml @@ -45,7 +45,7 @@ - + @@ -74,7 +74,7 @@ - + @@ -82,7 +82,7 @@ - + @@ -100,18 +100,21 @@ - - - - - - - - - - + + + + + + + + + + + + + - - diff --git a/appserver/tests/appserv-tests/devtests/transaction/ee/cli/build.xml b/appserver/tests/appserv-tests/devtests/transaction/ee/cli/build.xml index a33174188a7..5e496a7cb32 100644 --- a/appserver/tests/appserv-tests/devtests/transaction/ee/cli/build.xml +++ b/appserver/tests/appserv-tests/devtests/transaction/ee/cli/build.xml @@ -228,7 +228,7 @@ @@ -290,7 +290,7 @@ diff --git a/appserver/tests/community/gfproject/build-impl.xml b/appserver/tests/community/gfproject/build-impl.xml index 8daa55edef3..af3a0e41d0a 100644 --- a/appserver/tests/community/gfproject/build-impl.xml +++ b/appserver/tests/community/gfproject/build-impl.xml @@ -52,8 +52,8 @@ - - + + diff --git a/appserver/tests/quicklook/amx/pom.xml b/appserver/tests/quicklook/amx/pom.xml index b05c3b5e615..10854aef91f 100644 --- a/appserver/tests/quicklook/amx/pom.xml +++ b/appserver/tests/quicklook/amx/pom.xml @@ -17,34 +17,34 @@ --> - + 4.0.0 org.glassfish.quicklook admin Admin Quicklook Tests jar - org.glassfish.quicklook - quicklook + org.glassfish.quicklook + quicklook 7.0.21-SNAPSHOT - ../pom.xml Runs the tests on admin/asadmin code - src - - - maven-compiler-plugin - - iso-8859-1 - 1.5 - 1.5 - - - + src + + + maven-compiler-plugin + + iso-8859-1 + 11 + + + - + org.testng testng diff --git a/appserver/tests/quicklook/build.xml b/appserver/tests/quicklook/build.xml index 516fe978e00..0684c07c850 100644 --- a/appserver/tests/quicklook/build.xml +++ b/appserver/tests/quicklook/build.xml @@ -44,14 +44,16 @@ - - - - - + + + + + + + - + @@ -451,7 +453,7 @@ - + @@ -491,10 +493,10 @@ - + - + @@ -510,7 +512,7 @@ - + diff --git a/appserver/tests/quicklook/ejb/remoteview/pom.xml b/appserver/tests/quicklook/ejb/remoteview/pom.xml index 379831bcf89..674c32d4d60 100644 --- a/appserver/tests/quicklook/ejb/remoteview/pom.xml +++ b/appserver/tests/quicklook/ejb/remoteview/pom.xml @@ -60,7 +60,7 @@ org.testng testng - 6.11 + 7.10.2 diff --git a/appserver/tests/quicklook/ejb/remoteview/src/test/RemoteViewTestNG.java b/appserver/tests/quicklook/ejb/remoteview/src/test/RemoteViewTestNG.java index 13d0344ddfe..e217766cdc1 100644 --- a/appserver/tests/quicklook/ejb/remoteview/src/test/RemoteViewTestNG.java +++ b/appserver/tests/quicklook/ejb/remoteview/src/test/RemoteViewTestNG.java @@ -46,9 +46,8 @@ public void helloRemote() throws Exception{ test_result = true; } catch(ExecutionException e) { test_result = false; - System.out.println("Got async ExecutionException. Cause is " + - e.getCause().getMessage()); - e.getCause().printStackTrace(); + System.out.println("Got async ExecutionException."); + e.printStackTrace(); } Assert.assertEquals(test_result, true,"Unexpected Results"); } @@ -66,7 +65,8 @@ public void portableGlobal() throws Exception{ test_result = true; } catch(Exception e) { test_result = false; - System.out.println("Exception from portableGlobal:"+e); + System.err.println("Exception from portableGlobal"); + e.printStackTrace(); } Assert.assertEquals(test_result, true,"Unexpected Results"); } @@ -84,17 +84,18 @@ public void nonPortableGlobal() throws Exception{ test_result = true; } catch(Exception e) { test_result = false; - System.out.println("Exception from portableGlobal:"+e); + System.err.println("Exception from portableGlobal:"); + e.printStackTrace(); } Assert.assertEquals(test_result, true,"Unexpected Results"); } private static void callHome(HelloHome home) throws Exception { HelloRemote hr = home.create(); - //System.out.println("2.x HelloRemote.hello() says " + hr.hello()); + System.out.println("2.x HelloRemote.hello() says " + hr.hello()); } private static void callBusHome(Hello h) { - String hret = h.hello(); - //System.out.println("Hello.hello() says " + h.hello()); + String hret = h.hello(); + System.out.println("Hello.hello() says " + h.hello()); } } diff --git a/appserver/tests/quicklook/gfproject/build-impl.xml b/appserver/tests/quicklook/gfproject/build-impl.xml index 8d994e0a4ec..48b3b3b3172 100644 --- a/appserver/tests/quicklook/gfproject/build-impl.xml +++ b/appserver/tests/quicklook/gfproject/build-impl.xml @@ -45,11 +45,22 @@ - - - - - + + + + + + + + + + + + + + + + @@ -61,7 +72,7 @@ - + @@ -72,9 +83,7 @@ - - - + @@ -104,14 +113,14 @@ - + - + @@ -154,7 +163,7 @@ - + @@ -168,7 +177,7 @@ - + @@ -204,7 +213,7 @@ - + @@ -215,7 +224,7 @@ - + @@ -243,7 +252,7 @@ - + @@ -357,7 +366,9 @@ - + @@ -368,7 +379,9 @@ - + diff --git a/appserver/tests/quicklook/pom.xml b/appserver/tests/quicklook/pom.xml index ca0bcccb7cd..4e8de5fb4cc 100644 --- a/appserver/tests/quicklook/pom.xml +++ b/appserver/tests/quicklook/pom.xml @@ -1,7 +1,7 @@ - + 4.0.0 org.eclipse.ee4j project 1.0.9 - + org.glassfish.quicklook quicklook 7.0.21-SNAPSHOT - jar + pom Glassfish Quicklook Bundle This pom describes how to run QuickLook tests on the Glassfish Bundle @@ -40,45 +42,47 @@ maven-antrun-plugin - 3.0.0 + 3.1.0 default-test test - - - + + + + + + - - - - + - - + + - + - + - + @@ -86,15 +90,16 @@ - + - + - + @@ -102,40 +107,40 @@ - + - + - + - + - + - + - + @@ -199,12 +204,11 @@ - - - com.beust - jcommander - 1.72 - + + com.beust + jcommander + 1.72 + @@ -217,7 +221,7 @@ true - + true @@ -227,7 +231,7 @@ true - + test_wd @@ -253,7 +257,7 @@ true - + test_em @@ -267,7 +271,7 @@ true - + dev_debug diff --git a/appserver/tests/quicklook/testng/testng_cluster.xml b/appserver/tests/quicklook/testng/testng_cluster.xml index 217eea97ae8..b405faa8b79 100644 --- a/appserver/tests/quicklook/testng/testng_cluster.xml +++ b/appserver/tests/quicklook/testng/testng_cluster.xml @@ -18,7 +18,7 @@ - + diff --git a/appserver/tests/quicklook/testng/testng_debug.xml b/appserver/tests/quicklook/testng/testng_debug.xml index 68a900f55c1..55b82433d93 100644 --- a/appserver/tests/quicklook/testng/testng_debug.xml +++ b/appserver/tests/quicklook/testng/testng_debug.xml @@ -18,7 +18,7 @@ - + diff --git a/appserver/tests/quicklook/testng/testng_em.xml b/appserver/tests/quicklook/testng/testng_em.xml index 722ad4fa061..94645548ba8 100644 --- a/appserver/tests/quicklook/testng/testng_em.xml +++ b/appserver/tests/quicklook/testng/testng_em.xml @@ -18,7 +18,7 @@ - + diff --git a/appserver/tests/quicklook/testng/testng_full_profile.xml b/appserver/tests/quicklook/testng/testng_full_profile.xml index 9f690d69146..398b5a4d0ed 100644 --- a/appserver/tests/quicklook/testng/testng_full_profile.xml +++ b/appserver/tests/quicklook/testng/testng_full_profile.xml @@ -19,7 +19,7 @@ - + @@ -49,7 +49,7 @@ - - + @@ -53,7 +53,7 @@ - -Djdk.attach.allowAttachSelf=true @@ -285,7 +287,8 @@ - -server + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -Djdk.tls.rejectClientInitiatedRenegotiation=true -XX:+UnlockDiagnosticVMOptions diff --git a/nucleus/admin/template/src/main/resources/config/logging.properties b/nucleus/admin/template/src/main/resources/config/logging.properties index fbc3d7fe202..994b4210752 100644 --- a/nucleus/admin/template/src/main/resources/config/logging.properties +++ b/nucleus/admin/template/src/main/resources/config/logging.properties @@ -207,6 +207,7 @@ org.glassfish.hk2.classmodel.level=INFO org.glassfish.jersey.level=INFO org.glassfish.jersey.message.internal.TracingLogger.level=INFO org.glassfish.main.level=INFO +org.glassfish.main.jdke=INFO org.glassfish.naming.level=INFO org.glassfish.persistence.level=INFO org.glassfish.resourcebase.level=INFO diff --git a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/progress/ProgressStatusClient.java b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/progress/ProgressStatusClient.java index 912c384a26b..3951ad07c23 100644 --- a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/progress/ProgressStatusClient.java +++ b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/progress/ProgressStatusClient.java @@ -16,7 +16,6 @@ package com.sun.enterprise.admin.progress; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.util.StringUtils; import java.util.HashMap; @@ -28,6 +27,7 @@ import org.glassfish.api.admin.progress.ProgressStatusDTO; import org.glassfish.api.admin.progress.ProgressStatusEvent; import org.glassfish.api.admin.progress.ProgressStatusEventCreateChild; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Provides mirroring of events into given ProgressStatus substructure. Never rewrites name in base ProgressStatus (i.e. diff --git a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/PlainTextManager.java b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/PlainTextManager.java index 5e3ee81e491..61cb7155a1f 100644 --- a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/PlainTextManager.java +++ b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/PlainTextManager.java @@ -17,7 +17,8 @@ package com.sun.enterprise.admin.remote; import com.sun.enterprise.universal.collections.ManifestUtils; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; + +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * diff --git a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteAdminCommand.java b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteAdminCommand.java index c5499e77cda..d9b837b6944 100644 --- a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteAdminCommand.java +++ b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteAdminCommand.java @@ -24,7 +24,6 @@ import com.sun.enterprise.admin.util.HttpConnectorAddress; import com.sun.enterprise.admin.util.cache.AdminCacheUtils; import com.sun.enterprise.config.serverbeans.SecureAdmin; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.universal.io.SmartFile; import com.sun.enterprise.util.io.FileUtils; import com.sun.enterprise.util.net.NetUtils; @@ -76,6 +75,7 @@ import org.glassfish.api.admin.Payload; import org.glassfish.common.util.HttpParser; import org.glassfish.common.util.admin.AuthTokenManager; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; diff --git a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteResponseManager.java b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteResponseManager.java index bd7c397a497..d7ea5a1ab77 100644 --- a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteResponseManager.java +++ b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteResponseManager.java @@ -17,7 +17,6 @@ package com.sun.enterprise.admin.remote; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.util.io.FileUtils; import java.io.ByteArrayInputStream; @@ -29,6 +28,8 @@ import java.util.Map; import java.util.logging.Logger; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; + import static com.sun.enterprise.util.StringUtils.ok; /** diff --git a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteRestAdminCommand.java b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteRestAdminCommand.java index 0b27f8d1b76..c15807eccd5 100644 --- a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteRestAdminCommand.java +++ b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteRestAdminCommand.java @@ -33,7 +33,6 @@ import com.sun.enterprise.admin.util.HttpConnectorAddress; import com.sun.enterprise.admin.util.cache.AdminCacheUtils; import com.sun.enterprise.config.serverbeans.SecureAdmin; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.universal.io.SmartFile; import com.sun.enterprise.util.StringUtils; import com.sun.enterprise.util.net.NetUtils; @@ -79,6 +78,7 @@ import org.glassfish.api.admin.ParameterMap; import org.glassfish.api.admin.Payload; import org.glassfish.common.util.admin.AuthTokenManager; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import static java.util.logging.Level.FINER; import static java.util.logging.Level.FINEST; @@ -1110,30 +1110,30 @@ private void doHttpCommand(String uriString, String httpMethod, HttpCommand cmd, continue; } catch (ConnectException ce) { - logger.log(FINER, "doHttpCommand: connect exception {0}", ce); + logger.log(FINER, "doHttpCommand: connect exception", ce); // this really means nobody was listening on the remote server // note: ConnectException extends IOException and tells us more! String msg = strings.get("ConnectException", host, port + ""); throw new CommandException(msg, ce); } catch (UnknownHostException he) { - logger.log(FINER, "doHttpCommand: host exception {0}", he); + logger.log(FINER, "doHttpCommand: host exception", he); // bad host name String msg = strings.get("UnknownHostException", host); throw new CommandException(msg, he); } catch (SocketException se) { - logger.log(FINER, "doHttpCommand: socket exception {0}", se); + logger.log(FINER, "doHttpCommand: socket exception", se); throw new CommandException(se); } catch (SSLException se) { - logger.log(FINER, "doHttpCommand: SSL exception {0}", se); + logger.log(FINER, "doHttpCommand: SSL exception", se); if (secure) { logger.log(SEVERE, AdminLoggerInfo.mServerIsNotSecure, new Object[] { host, port }); } throw new CommandException(se); } catch (SocketTimeoutException e) { - logger.log(FINER, "doHttpCommand: read timeout {0}", e); + logger.log(FINER, "doHttpCommand: read timeout", e); throw new CommandException(strings.get("ReadTimeout", (float) readTimeout / 1000), e); } catch (IOException e) { - logger.log(FINER, "doHttpCommand: IO exception {0}", e); + logger.log(FINER, "doHttpCommand: IO exception", e); throw new CommandException(strings.get("IOError", e.getMessage()), e); } catch (CommandException e) { throw e; diff --git a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/util/AsadminTrustManager.java b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/util/AsadminTrustManager.java index 1d9bb96ae27..771f4de6821 100644 --- a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/util/AsadminTrustManager.java +++ b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/util/AsadminTrustManager.java @@ -17,7 +17,6 @@ package com.sun.enterprise.admin.util; import com.sun.enterprise.security.store.AsadminTruststore; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import java.io.Console; import java.io.IOException; @@ -29,6 +28,8 @@ import javax.net.ssl.X509TrustManager; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; + /** * An implementation of {@link X509TrustManager} that provides basic support for Trust Management. It checks if the * server is trusted and displays the certificate that was received from the server. The user is then prompted to diff --git a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/util/Strings.java b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/util/Strings.java index 3276e9b680d..1812b2550a4 100644 --- a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/util/Strings.java +++ b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/util/Strings.java @@ -16,7 +16,7 @@ package com.sun.enterprise.admin.util; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Strings -- Get your Strings here. One file with Strings So one class for messing with them! Nothing in here is public diff --git a/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/NodeUtils.java b/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/NodeUtils.java index cbaf592102f..1192347a477 100644 --- a/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/NodeUtils.java +++ b/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/NodeUtils.java @@ -71,7 +71,7 @@ public class NodeUtils { static final String PARAM_TYPE = "type"; static final String PARAM_INSTALL = "install"; public static final String PARAM_WINDOWS_DOMAIN = "windowsdomain"; - static final String LANDMARK_FILE = "glassfish/modules/admin-cli.jar"; + static final String LANDMARK_FILE = "glassfish/admin-cli.jar"; private static final String NL = System.lineSeparator(); private TokenResolver resolver = null; private Logger logger = null; diff --git a/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/Strings.java b/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/Strings.java index fea82e30a4a..e58f56396fa 100644 --- a/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/Strings.java +++ b/nucleus/cluster/admin/src/main/java/com/sun/enterprise/v3/admin/cluster/Strings.java @@ -16,7 +16,7 @@ package com.sun.enterprise.v3.admin.cluster; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Strings -- Get your Strings here. diff --git a/nucleus/cluster/cli/pom.xml b/nucleus/cluster/cli/pom.xml index 9c492ad597f..a155cf0a0de 100755 --- a/nucleus/cluster/cli/pom.xml +++ b/nucleus/cluster/cli/pom.xml @@ -124,23 +124,5 @@ - - - maven-jar-plugin - - - - - ../../modules/cluster-common.jar - ../../modules/cluster-ssh.jar - ../../modules/config-api.jar - ../../modules/internal-api.jar - ../../modules/config-types.jar - ../../modules/shoal-gms-impl.jar - - - - - diff --git a/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/ChangeNodeMasterPasswordCommand.java b/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/ChangeNodeMasterPasswordCommand.java index be1fa1fa453..88bbf9cfd0e 100644 --- a/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/ChangeNodeMasterPasswordCommand.java +++ b/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/ChangeNodeMasterPasswordCommand.java @@ -21,7 +21,6 @@ import com.sun.enterprise.admin.servermgmt.RepositoryConfig; import com.sun.enterprise.admin.util.CommandModelData.ParamModelData; import com.sun.enterprise.security.store.PasswordAdapter; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.universal.process.ProcessUtils; import com.sun.enterprise.universal.xml.MiniXmlParser; import com.sun.enterprise.universal.xml.MiniXmlParserException; @@ -34,6 +33,7 @@ import org.glassfish.api.Param; import org.glassfish.api.admin.CommandException; import org.glassfish.hk2.api.PerLookup; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import org.jvnet.hk2.annotations.Service; /** diff --git a/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/StartLocalInstanceCommand.java b/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/StartLocalInstanceCommand.java index 1e1cad3d65a..3d609a394ca 100644 --- a/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/StartLocalInstanceCommand.java +++ b/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/StartLocalInstanceCommand.java @@ -195,20 +195,18 @@ protected int executeCommand() throws CommandException { * Sets the launcher and info fields. */ @Override - public void createLauncher() - throws GFLauncherException, MiniXmlParserException { - setLauncher(GFLauncherFactory.getInstance(getType())); - setInfo(getLauncher().getInfo()); - getInfo().setInstanceName(instanceName); - getInfo().setInstanceRootDir(instanceDir); - getInfo().setVerbose(verbose); - getInfo().setWatchdog(watchdog); - getInfo().setDebug(debug); - getInfo().setRespawnInfo(programOpts.getClassName(), - programOpts.getClassPath(), - respawnArgs()); - - getLauncher().setup(); + public void createLauncher() throws GFLauncherException, MiniXmlParserException { + setLauncher(GFLauncherFactory.getInstance(getType())); + setInfo(getLauncher().getInfo()); + getInfo().setInstanceName(instanceName); + getInfo().setInstanceRootDir(instanceDir); + getInfo().setVerbose(verbose); + getInfo().setWatchdog(watchdog); + getInfo().setDebug(debug); + getInfo().setRespawnInfo(programOpts.getClassName(), programOpts.getModulePath(), programOpts.getClassPath(), + respawnArgs()); + + getLauncher().setup(); } /** diff --git a/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/Strings.java b/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/Strings.java index d4406a2d5dd..e84dd79aab0 100644 --- a/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/Strings.java +++ b/nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/Strings.java @@ -17,7 +17,7 @@ package com.sun.enterprise.admin.cli.cluster; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Strings -- Get your Strings here. diff --git a/nucleus/cluster/common/src/main/java/com/sun/enterprise/util/cluster/Strings.java b/nucleus/cluster/common/src/main/java/com/sun/enterprise/util/cluster/Strings.java index 71d503b6c11..68a3f2364a2 100644 --- a/nucleus/cluster/common/src/main/java/com/sun/enterprise/util/cluster/Strings.java +++ b/nucleus/cluster/common/src/main/java/com/sun/enterprise/util/cluster/Strings.java @@ -16,7 +16,7 @@ package com.sun.enterprise.util.cluster; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Strings -- Get your Strings here. diff --git a/nucleus/cluster/gms-adapter/pom.xml b/nucleus/cluster/gms-adapter/pom.xml index 4d5682a121a..e01ae687394 100644 --- a/nucleus/cluster/gms-adapter/pom.xml +++ b/nucleus/cluster/gms-adapter/pom.xml @@ -93,16 +93,6 @@ - - maven-jar-plugin - - - - shoal-gms-impl.jar - - - - diff --git a/nucleus/cluster/ssh/src/main/java/org/glassfish/cluster/ssh/connect/Strings.java b/nucleus/cluster/ssh/src/main/java/org/glassfish/cluster/ssh/connect/Strings.java index 3ab558f840e..7dc731122ae 100644 --- a/nucleus/cluster/ssh/src/main/java/org/glassfish/cluster/ssh/connect/Strings.java +++ b/nucleus/cluster/ssh/src/main/java/org/glassfish/cluster/ssh/connect/Strings.java @@ -15,7 +15,7 @@ */ package org.glassfish.cluster.ssh.connect; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Strings -- Get your Strings here. diff --git a/nucleus/cluster/ssh/src/main/java/org/glassfish/cluster/ssh/util/Strings.java b/nucleus/cluster/ssh/src/main/java/org/glassfish/cluster/ssh/util/Strings.java index 44665db5ef7..a7b94716b6e 100644 --- a/nucleus/cluster/ssh/src/main/java/org/glassfish/cluster/ssh/util/Strings.java +++ b/nucleus/cluster/ssh/src/main/java/org/glassfish/cluster/ssh/util/Strings.java @@ -16,7 +16,7 @@ package org.glassfish.cluster.ssh.util; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Strings -- Get your Strings here. diff --git a/nucleus/common/common-util/pom.xml b/nucleus/common/common-util/pom.xml index 361ff771e86..22a2f8decc9 100755 --- a/nucleus/common/common-util/pom.xml +++ b/nucleus/common/common-util/pom.xml @@ -51,6 +51,11 @@ compile + + org.glassfish.main.common + glassfish-jdk-extensions + ${project.version} + org.glassfish.hk2 hk2-core diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java index 3630f39725a..f354583c143 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java @@ -68,8 +68,8 @@ import java.util.zip.ZipEntry; import org.glassfish.api.deployment.InstrumentableClassLoader; -import org.glassfish.common.util.GlassfishUrlClassLoader; import org.glassfish.hk2.api.PreDestroy; +import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; import static java.util.logging.Level.INFO; @@ -86,6 +86,10 @@ public class ASURLClassLoader extends GlassfishUrlClassLoader implements JasperAdapter, InstrumentableClassLoader, PreDestroy, DDPermissionsLoader { + static { + registerAsParallelCapable(); + } + /** logger for this class */ private static final Logger _logger = CULoggerInfo.getLogger(); @@ -122,24 +126,16 @@ public class ASURLClassLoader extends GlassfishUrlClassLoader //holder for declared and ee permissions private final PermsHolder permissionsHolder; - /** - * Constructor. - */ - public ASURLClassLoader() { - super(new URL[0]); - permissionsHolder = new PermsHolder(); - _logger.log(Level.FINE, "ClassLoader: {0} is getting created.", this); - } - - /** * Constructor. * + * @param name * @param parent parent class loader */ - public ASURLClassLoader(ClassLoader parent) { - super(new URL[0], parent); + public ASURLClassLoader(String name, ClassLoader parent) { + super(name, new URL[0], parent); permissionsHolder = new PermsHolder(); + _logger.log(Level.FINE, "ClassLoader: {0} is getting created.", this); } @@ -791,18 +787,13 @@ private byte[] getClassData(InputStream istream) throws IOException { } - protected String getClassLoaderName() { - return "ASURLClassLoader"; - } - - /** * Returns a string representation of this class loader */ @Override public String toString() { StringBuilder buffer = new StringBuilder(); - buffer.append(getClassLoaderName()).append(" :\n"); + buffer.append(getName()).append(" :\n"); if (doneCalled) { buffer.append("doneCalled = true").append('\n'); buffer.append("doneSnapshot = ").append(doneSnapshot); diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/security/store/AsadminSecurityUtil.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/security/store/AsadminSecurityUtil.java index 064f7a8372e..4e4b23e6a31 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/security/store/AsadminSecurityUtil.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/security/store/AsadminSecurityUtil.java @@ -17,7 +17,6 @@ package com.sun.enterprise.security.store; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.util.CULoggerInfo; import com.sun.enterprise.util.io.FileUtils; @@ -36,6 +35,8 @@ import java.security.cert.CertificateException; import java.util.logging.Logger; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; + import static com.sun.enterprise.util.SystemPropertyConstants.CLIENT_TRUSTSTORE_PASSWORD_PROPERTY; import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PROPERTY; diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/Duration.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/Duration.java index 21f2cfcffa2..64230ba4285 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/Duration.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/Duration.java @@ -16,7 +16,7 @@ package com.sun.enterprise.universal; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Convert a msec duration into weeks, hours, minutes, seconds diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/ASenvPropertyReader.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/ASenvPropertyReader.java index 58f0b13af9f..ba881c25445 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/ASenvPropertyReader.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/ASenvPropertyReader.java @@ -20,14 +20,13 @@ import com.sun.enterprise.universal.io.SmartFile; import com.sun.enterprise.util.net.NetUtils; -import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; -import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; +import org.glassfish.main.jdke.props.EnvToPropsConverter; + import static com.sun.enterprise.util.SystemPropertyConstants.AGENT_ROOT_PROPERTY; import static com.sun.enterprise.util.SystemPropertyConstants.CONFIG_ROOT_PROPERTY; import static com.sun.enterprise.util.SystemPropertyConstants.DERBY_ROOT_PROPERTY; @@ -39,9 +38,6 @@ import static com.sun.enterprise.util.SystemPropertyConstants.JAVA_ROOT_PROPERTY; import static com.sun.enterprise.util.SystemPropertyConstants.JAVA_ROOT_PROPERTY_ASENV; import static com.sun.enterprise.util.SystemPropertyConstants.PRODUCT_ROOT_PROPERTY; -import static com.sun.enterprise.util.SystemPropertyConstants.UNIX_ASENV_FILENAME; -import static com.sun.enterprise.util.SystemPropertyConstants.WINDOWS_ASENV_FILENAME; -import static java.nio.charset.StandardCharsets.UTF_8; /** * Class ASenvPropertyReader @@ -59,7 +55,6 @@ public class ASenvPropertyReader { "AS_IMQ_LIB", IMQ_LIB_PROPERTY, "AS_IMQ_BIN", IMQ_BIN_PROPERTY, "AS_CONFIG", CONFIG_ROOT_PROPERTY, - "AS_INSTALL", INSTALL_ROOT_PROPERTY, "AS_JAVA", JAVA_ROOT_PROPERTY_ASENV, "AS_DEF_DOMAINS_PATH", DOMAINS_ROOT_PROPERTY, "AS_DEF_NODES_PATH", AGENT_ROOT_PROPERTY); @@ -130,180 +125,16 @@ public String toString() { } - /** - * ASenvMap is a "lazy-evaluation" map, i.e., for values that are - * expensive to calculate, the value is not calculated until it is actually - * used. - */ static class ASenvMap extends HashMap { - // If we find a token in a set property, this is set to true. - boolean foundToken; - ASenvMap(File installDir) { - put(INSTALL_ROOT_PROPERTY, installDir.getPath()); - File configDir = SmartFile.sanitize(new File(installDir, "config")); - put(CONFIG_ROOT_PROPERTY, configDir.getPath()); - setProperties(configDir); - postProcess(configDir); - // Product root is defined to be the parent of the install root. - // While tempting to just use installDir.getParent() we go through - // these gyrations just in case setProperties() changed the value - // of the INSTALL_ROOT_PROPERTY property. - File installRoot = new File(super.get(INSTALL_ROOT_PROPERTY)); - put(PRODUCT_ROOT_PROPERTY, installRoot.getParent()); - } - - @Override - public String get(Object k) { - String v = super.get(k); - if (v != null) { - return v; - } - if (k.equals(HOST_NAME_PROPERTY)) { - v = getHostname(); - put(HOST_NAME_PROPERTY, v); - } - else if (k.equals(JAVA_ROOT_PROPERTY)) { - v = getJavaRoot(super.get(JAVA_ROOT_PROPERTY_ASENV)); - put(JAVA_ROOT_PROPERTY, v); - } - return v; - } - - @Override - public Set keySet() { - completeMap(); - return super.keySet(); - } - - @Override - public Set> entrySet() { - completeMap(); - return super.entrySet(); - } - - @Override - public boolean containsKey(Object k) { - completeMap(); - return super.containsKey(k); - } - - @Override - public Collection values() { - completeMap(); - return super.values(); - } - - /** - * Add the "lazy" items to the map so that the map is complete. - */ - private void completeMap() { - get(HOST_NAME_PROPERTY); - get(JAVA_ROOT_PROPERTY); - } - - - /** - *

      - *
    1. change relative paths to absolute - *
    2. change env. variables to either the actual values in the environment -` * or to another prop in asenv - *
    - */ - private void postProcess(File configDir) { - if (foundToken) { - final Map env = System.getenv(); - //put env props in first - Map all = new HashMap<>(env); - // now override with our props - all.putAll(this); - TokenResolver tr = new TokenResolver(all); - tr.resolve(this); - } - - // props have all tokens replaced now (if they exist) - // now make the paths absolute. - // Call super.keySet here so that the lazy values are not added - // to the map at this point. - Set keys = super.keySet(); - - for (String key : keys) { - String value = super.get(key); - if (GFLauncherUtils.isRelativePath(value)) { - // we have to handle both of these: - // /x/y/../z - // ../x/y/../z - - File f; - if (value.startsWith(".")) { - f = SmartFile.sanitize(new File(configDir, value)); - } - else { - f = SmartFile.sanitize(new File(value)); - } - - put(key, f.getPath()); - } - } - } - - private void setProperties(File configDir) { - //Read in asenv.conf/bat and set system properties accordingly - File asenv = new File(configDir, - GFLauncherUtils.isWindows() ? WINDOWS_ASENV_FILENAME : UNIX_ASENV_FILENAME); - if (!asenv.exists()) { - return; - } - try (BufferedReader reader = new BufferedReader(new FileReader(asenv, UTF_8))) { - String line; - while ((line = reader.readLine()) != null) { - setProperty(line); - } - } catch (Exception e) { - throw new IllegalStateException("Could not parse " + asenv, e); - } - } - - /** - * Method setProperty - * Parses a single line of asenv.conf or asenv.bat and attempt to - * set the corresponding property. Note that if the system - * property is already set (e.g. via -D on the command line), then - * we will not clobber its existing value. - * - * @param line - * - */ - private void setProperty(String line) { - int pos = line.indexOf('='); - if (pos > 0) { - String lhs = (line.substring(0, pos)).trim(); - String rhs = (line.substring(pos + 1)).trim(); - - if (GFLauncherUtils.isWindows()) { - // trim off the "set " - lhs = (lhs.substring(3)).trim(); - } else { - // take the quotes out - pos = rhs.indexOf('"'); - if (pos != -1) { - rhs = (rhs.substring(pos + 1)).trim(); - pos = rhs.indexOf('"'); - if (pos != -1) { - rhs = (rhs.substring(0, pos)).trim(); - } - } - } - - String systemPropertyName = ENV_TO_SYS_PROPERTY.get(lhs); - - if (systemPropertyName != null) { - if (TokenResolver.hasToken(rhs)) { - foundToken = true; - } - put(systemPropertyName, rhs); - } - } + new EnvToPropsConverter(installDir.toPath()).convert(ENV_TO_SYS_PROPERTY).entrySet() + .forEach(e -> this.put(e.getKey(), e.getValue().getPath())); + String javaHome = new File(System.getProperty("java.home")).toPath().toString(); + put(JAVA_ROOT_PROPERTY, javaHome); + put(JAVA_ROOT_PROPERTY_ASENV, javaHome); + put(INSTALL_ROOT_PROPERTY, installDir.toPath().toString()); + put(PRODUCT_ROOT_PROPERTY, installDir.getParentFile().toPath().toString()); + put(HOST_NAME_PROPERTY, getHostname()); } private static String getHostname() { @@ -316,68 +147,5 @@ private static String getHostname() { } return hostname; } - - /** - * Get a value for the Java installation directory. The value that is - * passed in should be the value from the ASenv config file. If it is valid - * it is returned. Otherwise, this method checks the following: - * - JAVA_HOME environment variable - * - java.home system property - */ - private static String getJavaRoot(String fileValue) { - // make sure we have a folder with java in it! - // note that we are not in a position to set it from domain.xml yet - - // first choice -- whatever is in asenv - String javaRootName = fileValue; - - if (isValidJavaRoot(javaRootName)) { - return javaRootName; // we are already done! - } - - // try JAVA_HOME - javaRootName = System.getenv("JAVA_HOME"); - - if (isValidJavaRoot(javaRootName)) { - javaRootName = SmartFile.sanitize(new File(javaRootName)).getPath(); - return javaRootName; - } - // try java.home with ../ - // usually java.home is pointing at jre and ".." goes to the jdk - javaRootName = System.getProperty("java.home") + "/.."; - - if (isValidJavaRoot(javaRootName)) { - javaRootName = SmartFile.sanitize(new File(javaRootName)).getPath(); - return javaRootName; - } - - // try java.home as-is - javaRootName = System.getProperty("java.home"); - - if (isValidJavaRoot(javaRootName)) { - javaRootName = SmartFile.sanitize(new File(javaRootName)).getPath(); - return javaRootName; - } - // TODO - should this be an Exception? A log message? - return null; - } - - private static boolean isValidJavaRoot(String javaRootName) { - if (!GFLauncherUtils.ok(javaRootName)) { - return false; - } - - // look for ${javaRootName}/bin/java[.exe] - File f = new File(javaRootName); - - if (GFLauncherUtils.isWindows()) { - f = new File(f, "bin/java.exe"); - } else { - f = new File(f, "bin/java"); - } - - return f.exists(); - } - } } diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/GFLauncherUtils.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/GFLauncherUtils.java index 91b7a4b8541..9d0cacc417b 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/GFLauncherUtils.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/GFLauncherUtils.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation * Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -17,30 +18,29 @@ package com.sun.enterprise.universal.glassfish; import com.sun.enterprise.universal.io.SmartFile; +import com.sun.enterprise.util.SystemPropertyConstants; import com.sun.enterprise.util.net.NetUtils; import java.io.File; -import java.net.JarURLConnection; -import java.net.URL; +import java.io.IOException; +import java.net.URISyntaxException; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; import java.util.Locale; -import static com.sun.enterprise.util.SystemPropertyConstants.INSTALL_ROOT_PROPERTY; - /** * Package private static utility methods * @author bnevins */ -public class GFLauncherUtils { +public final class GFLauncherUtils { private GFLauncherUtils() { - // all static methods + // all static methods } public static boolean ok(String s) { - return s != null && s.length() > 0; + return s != null && !s.isEmpty(); } public static boolean safeExists(File f) { @@ -51,54 +51,12 @@ public static boolean safeIsDirectory(File f) { return f != null && f.isDirectory(); } - public static synchronized File getInstallDir() { - // if it is already set as a System Property -- skip the huge block below - setInstallDirFromSystemProp(); - - if(installDir == null) - { - String resourceName = GFLauncherUtils.class.getName().replace('.', '/') + ".class"; - URL resource = GFLauncherUtils.class.getClassLoader().getResource(resourceName); - - if (resource == null) { - return null; - } - - if (!resource.getProtocol().equals("jar")) { - return null; - } - - try { - JarURLConnection c = (JarURLConnection) resource.openConnection(); - URL jarFile = c.getJarFileURL(); - - // important to sanitize it! - // unreported bug: - // JDK does this: - // the parent of "/foo/." is "/foo", not "/" ! - - - File f = SmartFile.sanitize(new File(jarFile.toURI())); - - f = f.getParentFile(); // /modules - - if (f == null) { - return null; - } - - f = f.getParentFile(); // / - - if (f == null) { - return null; - } - - installDir = SmartFile.sanitize(f); - } - catch (Exception e) { - installDir = null; - } + public static File getInstallDir() { + try { + return resolveInstallDir(); + } catch (IOException | URISyntaxException e) { + throw new Error("Cannot resolve install root!", e); } - return installDir; } public static boolean isWindows() { @@ -133,7 +91,7 @@ public static String getCanonicalHostName() throws UnknownHostException { } public static String replace(String s, String token, String replace) { - if (s == null || s.length() <= 0 || token == null || token.length() <= 0) { + if (s == null || s.isEmpty() || token == null || token.isEmpty()) { return s; } @@ -162,17 +120,13 @@ public static String replace(String s, String token, String replace) { public static boolean isRelativePath(String path) { if (!ok(path)) { return false; - } - else if (path.startsWith(".")) { + } else if (path.startsWith(".")) { return true; - } - else if (path.indexOf("/.") >= 0) { + } else if (path.indexOf("/.") >= 0) { return true; - } - else if (path.indexOf("\\.") >= 0) { + } else if (path.indexOf("\\.") >= 0) { return true; - } - else { + } else { return false; } } @@ -182,16 +136,16 @@ else if (path.indexOf("\\.") >= 0) { * @param cp The classpath-like string * @return the list of File */ - public static List stringToFiles(String cp) - { - List list = new ArrayList(); + public static List stringToFiles(String cp) { + List list = new ArrayList<>(); - if(ok(cp)) { + if (ok(cp)) { cp = SmartFile.sanitizePaths(cp); String[] ss = cp.split(File.pathSeparator); - for(String s : ss) + for (String s : ss) { list.add(new File(s)); + } } return list; @@ -214,27 +168,37 @@ public static String fileListToPathString(List files) { return sb.toString(); } - private static void setInstallDirFromSystemProp() { - // https://embedded-glassfish.dev.java.net/issues/show_bug.cgi?id=54 - // - // For instance if we are called from an Embedded Server then InstallRoot - // may already be set as a System Prop -- and the jar we are running from has - // nothing whatever to do with the concept of an "install root". - // In that case we certainly do not want to wipe out the already set install root. - - // if anything is not kosher simply return w/o setting installDir to anything. - String installRootDirName = System.getProperty(INSTALL_ROOT_PROPERTY); - - if(!ok(installRootDirName)) - return; - - File f = SmartFile.sanitize(new File(installRootDirName)); - - if(f.isDirectory()) { - installDir = f; + /** + * @return + * @throws IOException + * @throws URISyntaxException + */ + private static File resolveInstallDir() throws IOException, URISyntaxException { + // Property first, because it could be already set by this JVM and we respect it. + String sys = System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY); + if (sys != null) { + return toValidDirectory(sys); } + String env = System.getenv("AS_INSTALL"); + if (env != null) { + return toValidDirectory(env); + } + // Expectation: we are running the program using usual directory design of GlassFish. + // That means that the common-util jar is in modules directory. + return new File(GFLauncherUtils.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getCanonicalFile().getParentFile().getParentFile(); } - private static File installDir; + private static File toValidDirectory(String value) throws IOException { + File file = new File(value).toPath().normalize().toFile(); + if (!file.isAbsolute()) { + throw new IOException("The path to install root is not an absolute path: " + file); + } + File canonical = file.getCanonicalFile(); + if (!canonical.isDirectory()) { + throw new IOException("The path to install root is not a directory: " + canonical); + } + return canonical; + } } diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/i18n/LocalStrings.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/i18n/LocalStrings.java deleted file mode 100644 index 40140b99b30..00000000000 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/i18n/LocalStrings.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package com.sun.enterprise.universal.i18n; - -/** - * This class makes getting localized strings super-simple. All methods are static. - * The reason is that that makes it much simpler to use -- you never need to create an - * instance and store it. You simply call one of the 2 methods directly. However, - * there is a performance penalty for this convenience. This class has to figure out - * what package your calling code is in (every time). My reasoning is that the emitting - * of log messages tends to be much less frequent than other normal processing steps. - * If performance is an issue -- use an instance of LocalStringsImpl. - *

    Specifics: - *

      - *
    • Your calling code should have a file named LocalStrings.properties in its - * package directory. - *
    • If your localized string has no arguments call get(String) to get the localized - * String value. - *
    • If you have a parameterized string, call get(String, Object...) - *
    - *

    Note: You can not get an Exception out of calling this code! If the String - * or the properties file does not exist, it will return the String that you gave - * in the first place as the argument. - *

    Examples: - *

      - *
    • String s = LocalStrings.get("xyz"); - *
    • String s = LocalStrings.get("xyz", new Date(), 500, "something", 2.00003); - *
    • String s = LocalStrings.get("xyz", "something", "foo", "whatever"); - *
    - * - * - * - * @author bnevins - */ -public class LocalStrings { - - private LocalStrings() { - } - - /** - * Get a String from the caller's package's LocalStrings.properties - * @param indexString The string index into the localized string file - * @return the String from LocalStrings or the supplied String if it doesn't exist - */ - public static String get(String indexString) { - return new LocalStringsImpl().get(indexString); - } - - /** - * Get and format a String from the caller's package's LocalStrings.properties - * @param indexString The string index into the localized string file - * @param objects The arguments to give to MessageFormat - * @return the String from LocalStrings or the supplied String if it doesn't exist -- - * using the array of supplied Object arguments - */ - public static String get(String indexString, Object... objects) { - return new LocalStringsImpl().get(indexString, objects); - } - - /** - * Get a String from the caller's package's LocalStrings.properties - * @param indexString The string index into the localized string file - * @return the String from LocalStrings or the supplied default value if it doesn't exist - */ - public String getString(String indexString, String defaultValue) { - return new LocalStringsImpl().get(indexString, defaultValue); - } - - /** - * Get an integer from the caller's package's LocalStrings.properties - * @param indexString The string index into the localized string file - * @return the integer value from LocalStrings or the supplied default if - * it doesn't exist or is bad. - */ - public static int getInt(String indexString, int defaultValue) { - return new LocalStringsImpl().getInt(indexString, defaultValue); - } - - /** - * Get a boolean from the caller's package's LocalStrings.properties - * @param indexString The string index into the localized string file - * @return the integer value from LocalStrings or the supplied default if - * it doesn't exist or is bad. - */ - public boolean getBoolean(String indexString, boolean defaultValue) { - return new LocalStringsImpl().getBoolean(indexString, defaultValue); - } -} diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/i18n/LocalStringsImpl.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/i18n/LocalStringsImpl.java deleted file mode 100644 index c837d3e0e0a..00000000000 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/i18n/LocalStringsImpl.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package com.sun.enterprise.universal.i18n; - -import java.text.MessageFormat; -import java.util.Locale; -import java.util.ResourceBundle; - -/** - * This class makes getting localized strings super-simple. This is the companion - * class to Strings. Use this class when performance may be an issue. I.e. Strings - * is all-static and creates a ResourceBundle on every call. This class is instantiated - * once and can be used over and over from the same package. - *

    Specifics: - *

      - *
    • Your calling code should have a file named LocalStrings.properties in its - * package directory. - *
    • If your localized string has no arguments call get(String) to get the localized - * String value. - *
    • If you have a parameterized string, call get(String, Object...) - *
    - *

    Note: You can not get an Exception out of calling this code! If the String - * or the properties file does not exist, it will return the String that you gave - * in the first place as the argument. - *

    Example: - *

      - *
    • LocalStringsImpl sh = new LocalStringsImpl(); - *
    • String s = sh.get("xyz"); - *
    • String s = sh.get("xyz", new Date(), 500, "something", 2.00003); - *
    • String s = sh.get("xyz", "something", "foo", "whatever"); - *
    - * - * @author bnevins 2005 - */ -public class LocalStringsImpl { - private ResourceBundle bundle; - private String propsName = "LocalStrings"; - private static final String thisPackage = "com.elf.util"; - private static final ResourceBundle.Control rbcontrol = ResourceBundle.Control - .getControl(ResourceBundle.Control.FORMAT_PROPERTIES); - - /** - * Create a LocalStringsImpl instance. - * Automatically discover the caller's LocalStrings.properties file - */ - public LocalStringsImpl() { - setBundle(); - } - - /** - * Create a LocalStringsImpl instance. - * use the proffered class object to find LocalStrings.properties. - * This is the constructor to use if you are concerned about getting - * the fastest performance. - */ - public LocalStringsImpl(Class clazz) { - setBundle(clazz); - } - - /** - * Create a LocalStringsImpl instance. - * use the proffered String. The String is the FQN of the properties file, - * without the '.properties'. E.g. 'com.elf.something.LogStrings' - */ - public LocalStringsImpl(String packageName, String propsName) { - this.propsName = propsName; - int len = packageName.length(); - - // side-effect -- make sure it ends in '.' - if (packageName.charAt(len - 1) != '.') { - packageName += '.'; - } - - setBundle(packageName); - } - - /** - * Get a String from the caller's package's LocalStrings.properties - * @param indexString The string index into the localized string file - * @return the String from LocalStrings or the supplied String if it doesn't exist - */ - public String get(String indexString) { - try { - return getBundle().getString(indexString); - } - catch (Exception e) { - // it is not an error to have no key... - return indexString; - } - } - - /** - * Get and format a String from the caller's package's LocalStrings.properties - * @param indexString The string index into the localized string file - * @param objects The arguments to give to MessageFormat - * @return the String from LocalStrings or the supplied String if it doesn't exist -- - * using the array of supplied Object arguments - */ - public String get(String indexString, Object... objects) { - indexString = get(indexString); - - try { - MessageFormat mf = new MessageFormat(indexString); - return mf.format(objects); - } - catch (Exception e) { - return indexString; - } - } - - /** - * Get a String from the caller's package's LocalStrings.properties - * @param indexString The string index into the localized string file - * @return the String from LocalStrings or the supplied default value if it doesn't exist - */ - public String getString(String indexString, String defaultValue) { - try { - return getBundle().getString(indexString); - } - catch (Exception e) { - // it is not an error to have no key... - return defaultValue; - } - } - - /** - * Get an integer from the caller's package's LocalStrings.properties - * @param indexString The string index into the localized string file - * @return the integer value from LocalStrings or the supplied default if - * it doesn't exist or is bad. - */ - public int getInt(String indexString, int defaultValue) { - try { - String s = getBundle().getString(indexString); - return Integer.parseInt(s); - } - catch (Exception e) { - // it is not an error to have no key... - return defaultValue; - } - } - - /** - * Get a boolean from the caller's package's LocalStrings.properties - * @param indexString The string index into the localized string file - * @return the integer value from LocalStrings or the supplied default if - * it doesn't exist or is bad. - */ - public boolean getBoolean(String indexString, boolean defaultValue) { - try { - return Boolean.parseBoolean(getBundle().getString(indexString)); - } - catch (Exception e) { - // it is not an error to have no key... - return defaultValue; - } - } - - public ResourceBundle getBundle() { - return bundle; - } - - /////////////////////////////////////////////////////////////////////////// - private void setBundle() { - // go through the stack, top to bottom. The item that is below the LAST - // method that is in the util framework is where the logfile is. - // note that there may be more than one method from util in the stack - // because they may be calling us indirectly from LoggerHelper. Also - // note that this class won't work from any class in the util hierarchy itself. - - try { - StackTraceElement[] items = Thread.currentThread().getStackTrace(); - int lastMeOnStack = -1; - - for (int i = 0; i < items.length; i++) { - StackTraceElement item = items[i]; - if (item.getClassName().startsWith(thisPackage)) { - lastMeOnStack = i; - } - } - - String className = items[lastMeOnStack + 1].getClassName(); - setBundle(className); - } - catch (Exception e) { - bundle = null; - } - } - - private void setBundle(Class clazz) { - - try { - String className = clazz.getName(); - setBundle(className); - - // April 25, 2009 -- if OSGi is in charge then we might not have got the - // bundle! Fix: send in the class's Classloader... - if(bundle == null) { - String props = className.substring(0, className.lastIndexOf('.')) + "." + propsName; - bundle = ResourceBundle.getBundle(props, Locale.getDefault(), clazz.getClassLoader(), - rbcontrol); - } - } - catch (Exception e) { - bundle = null; - } - } - - private void setBundle(String className) { - try { - String props = className.substring(0, className.lastIndexOf('.')) + "." + propsName; - bundle = ResourceBundle.getBundle(props, rbcontrol); - } - catch (Exception e) { - bundle = null; - } - } -} diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/JavaClassRunner.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/JavaClassRunner.java index 4a48cf172ee..76d47217789 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/JavaClassRunner.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/JavaClassRunner.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -48,14 +48,14 @@ public class JavaClassRunner { } final Path javaroot = Path.of(System.getProperty("java.home")); javaExecutable = javaroot.resolve("bin").resolve(javaName); - } - - public JavaClassRunner(String classpath, String[] sysprops, String classname, String[] args) throws IOException { - if (javaExecutable == null) { - throw new IOException("Can not find a jvm"); + if (!javaExecutable.toFile().canExecute()) { + throw new Error(javaExecutable + " is not an existing executable file."); } + } - if (!isEmpty(classname)) { + public JavaClassRunner(String modulepath, String classpath, String[] sysprops, String classname, String[] args) + throws IOException { + if (!isSet(classname)) { throw new IllegalArgumentException("classname was null"); } @@ -64,7 +64,13 @@ public JavaClassRunner(String classpath, String[] sysprops, String classname, St cmdline.add("nohup"); } cmdline.add(javaExecutable.toString()); - if (isEmpty(classpath)) { + if (isSet(modulepath)) { + cmdline.add("--module-path"); + cmdline.add(modulepath); + cmdline.add("--add-modules"); + cmdline.add("ALL-MODULE-PATH"); + } + if (isSet(classpath)) { cmdline.add("-cp"); cmdline.add(classpath); } @@ -97,7 +103,7 @@ public void run() throws IOException { } } - private boolean isEmpty(String s) { + private boolean isSet(String s) { return s != null && !s.isEmpty(); } } diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/xml/MiniXmlParser.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/xml/MiniXmlParser.java index ea2c1510adb..f0d62a62045 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/xml/MiniXmlParser.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/xml/MiniXmlParser.java @@ -19,7 +19,6 @@ import com.sun.common.util.logging.LoggingConfigImpl; import com.sun.enterprise.universal.glassfish.GFLauncherUtils; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.util.HostAndPort; import com.sun.enterprise.util.StringUtils; @@ -42,6 +41,7 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import org.glassfish.main.jul.handler.GlassFishLogHandlerProperty; import static java.nio.charset.StandardCharsets.UTF_8; diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/FelixPrettyPrinter.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/FelixPrettyPrinter.java index e388941891a..3619b998136 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/FelixPrettyPrinter.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/FelixPrettyPrinter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2008, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -25,10 +25,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.osgi.framework.BundleException; - /** - * Tools for obtaining readable information from the {@link BundleException} + * Tools for obtaining readable information from the {@link org.osgi.framework.BundleException} */ public class FelixPrettyPrinter { diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/Strings.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/Strings.java index a9b82595974..65c2f0c6b13 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/Strings.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/Strings.java @@ -16,7 +16,7 @@ package com.sun.enterprise.util; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Strings -- Get your Strings here. diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/SystemPropertyConstants.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/SystemPropertyConstants.java index 7fc7dee7df7..efd073d8721 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/SystemPropertyConstants.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/SystemPropertyConstants.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation. * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -20,6 +21,7 @@ import java.io.File; +// FIXME: Visit BootstrapKeys and remove duplicit constants here public class SystemPropertyConstants { /** @@ -177,6 +179,7 @@ public class SystemPropertyConstants { public static final String JDMK_HOME_PROPERTY = "com.sun.aas.jdmkHome"; + @Deprecated public static final String DERBY_ROOT_PROPERTY = "com.sun.aas.derbyRoot"; /** Java ES Monitoring Framework install directory */ diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/DomainDirs.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/DomainDirs.java index be1ba3c6452..df1ea203d85 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/DomainDirs.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/DomainDirs.java @@ -17,7 +17,6 @@ package com.sun.enterprise.util.io; import com.sun.enterprise.universal.glassfish.ASenvPropertyReader; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.util.SystemPropertyConstants; import java.io.File; @@ -25,6 +24,8 @@ import java.io.IOException; import java.util.Map; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; + /** * A class for keeping track of the directories that a domain lives in and under. * diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/ServerDirs.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/ServerDirs.java index e8d9ebaa232..2698bc493dd 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/ServerDirs.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/ServerDirs.java @@ -17,7 +17,6 @@ package com.sun.enterprise.util.io; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.universal.io.SmartFile; import com.sun.enterprise.util.ObjectAnalyzer; @@ -26,6 +25,8 @@ import java.io.FileReader; import java.io.IOException; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; + import static java.nio.charset.StandardCharsets.UTF_8; /** diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/Strings.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/Strings.java index 300ee6699fb..acbc05aa8a7 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/Strings.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/Strings.java @@ -16,7 +16,7 @@ package com.sun.enterprise.util.io; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Strings -- Get your Strings here. diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/reflect/Strings.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/reflect/Strings.java index 7b4e0015f4d..a7129aea5fa 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/reflect/Strings.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/reflect/Strings.java @@ -16,7 +16,7 @@ package com.sun.enterprise.util.reflect; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Strings -- Get your Strings here. diff --git a/nucleus/common/common-util/src/test/java/com/sun/enterprise/universal/glassfish/ASenvPropertyReaderTest.java b/nucleus/common/common-util/src/test/java/com/sun/enterprise/universal/glassfish/ASenvPropertyReaderTest.java index bf9914d2415..5fb1c00c722 100644 --- a/nucleus/common/common-util/src/test/java/com/sun/enterprise/universal/glassfish/ASenvPropertyReaderTest.java +++ b/nucleus/common/common-util/src/test/java/com/sun/enterprise/universal/glassfish/ASenvPropertyReaderTest.java @@ -1,6 +1,6 @@ /* + * Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2021 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -46,6 +46,6 @@ public static void setUpClass() throws Exception { public void test() { ASenvPropertyReader reader = new ASenvPropertyReader(installDir); Map props = reader.getProps(); - assertThat(props.toString(), props.entrySet(), hasSize(10)); + assertThat(props.toString(), props.entrySet(), hasSize(5)); } } diff --git a/nucleus/common/common-util/src/test/resources/clusters1.xml b/nucleus/common/common-util/src/test/resources/clusters1.xml index 50728ddf616..2278b75f41d 100644 --- a/nucleus/common/common-util/src/test/resources/clusters1.xml +++ b/nucleus/common/common-util/src/test/resources/clusters1.xml @@ -171,8 +171,8 @@ - -XX:MaxPermSize=192m - -client + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -Djavax.management.builder.initial=com.sun.enterprise.v3.admin.AppServerMBeanServerBuilder -XX:+UnlockDiagnosticVMOptions @@ -322,8 +322,8 @@ - -XX:MaxPermSize=192m - -server + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -XX:+UnlockDiagnosticVMOptions -Djava.security.policy=${com.sun.aas.instanceRoot}/config/server.policy @@ -488,8 +488,8 @@ - -XX:MaxPermSize=192m - -server + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -XX:+UnlockDiagnosticVMOptions -Djava.security.policy=${com.sun.aas.instanceRoot}/config/server.policy @@ -654,8 +654,8 @@ - -XX:MaxPermSize=192m - -server + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -XX:+UnlockDiagnosticVMOptions -Djava.security.policy=${com.sun.aas.instanceRoot}/config/server.policy @@ -820,8 +820,8 @@ - -XX:MaxPermSize=192m - -server + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -XX:+UnlockDiagnosticVMOptions -Djava.security.policy=${com.sun.aas.instanceRoot}/config/server.policy @@ -986,8 +986,8 @@ - -XX:MaxPermSize=192m - -server + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -XX:+UnlockDiagnosticVMOptions -Djava.security.policy=${com.sun.aas.instanceRoot}/config/server.policy diff --git a/nucleus/common/common-util/src/test/resources/manysysprops.xml b/nucleus/common/common-util/src/test/resources/manysysprops.xml index f63d23ed193..5e4f3a3f908 100644 --- a/nucleus/common/common-util/src/test/resources/manysysprops.xml +++ b/nucleus/common/common-util/src/test/resources/manysysprops.xml @@ -176,8 +176,8 @@ - -XX:MaxPermSize=192m - -client + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -Djavax.management.builder.initial=com.sun.enterprise.v3.admin.AppServerMBeanServerBuilder -XX:+UnlockDiagnosticVMOptions @@ -327,8 +327,8 @@ - -XX:MaxPermSize=192m - -server + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -XX:+UnlockDiagnosticVMOptions -Djava.security.policy=${com.sun.aas.instanceRoot}/config/server.policy @@ -496,8 +496,8 @@ - -XX:MaxPermSize=192m - -server + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -XX:+UnlockDiagnosticVMOptions -Djava.security.policy=${com.sun.aas.instanceRoot}/config/server.policy @@ -662,8 +662,8 @@ - -XX:MaxPermSize=192m - -server + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -XX:+UnlockDiagnosticVMOptions -Djava.security.policy=${com.sun.aas.instanceRoot}/config/server.policy @@ -828,8 +828,8 @@ - -XX:MaxPermSize=192m - -server + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -XX:+UnlockDiagnosticVMOptions -Djava.security.policy=${com.sun.aas.instanceRoot}/config/server.policy @@ -994,8 +994,8 @@ - -XX:MaxPermSize=192m - -server + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -XX:+UnlockDiagnosticVMOptions -Djava.security.policy=${com.sun.aas.instanceRoot}/config/server.policy diff --git a/nucleus/common/glassfish-api/src/main/java/org/glassfish/api/admin/ServerEnvironment.java b/nucleus/common/glassfish-api/src/main/java/org/glassfish/api/admin/ServerEnvironment.java index c9c2ea36f4f..3368aa1d5a9 100644 --- a/nucleus/common/glassfish-api/src/main/java/org/glassfish/api/admin/ServerEnvironment.java +++ b/nucleus/common/glassfish-api/src/main/java/org/glassfish/api/admin/ServerEnvironment.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -32,7 +32,7 @@ */ @Contract public interface ServerEnvironment { - public enum Status { + enum Status { starting, started, stopping, stopped } diff --git a/nucleus/common/glassfish-jdk-extensions/pom.xml b/nucleus/common/glassfish-jdk-extensions/pom.xml new file mode 100755 index 00000000000..f33a9cca458 --- /dev/null +++ b/nucleus/common/glassfish-jdk-extensions/pom.xml @@ -0,0 +1,44 @@ + + + + + 4.0.0 + + + org.glassfish.main.common + nucleus-common + 7.0.21-SNAPSHOT + + + glassfish-jdk-extensions + glassfish-jar + + GlassFish JDK Extensions + Things we would like to see in JDK + + + + org.junit.jupiter + junit-jupiter-engine + + + org.hamcrest + hamcrest + + + diff --git a/nucleus/common/glassfish-jdk-extensions/src/main/java/module-info.java b/nucleus/common/glassfish-jdk-extensions/src/main/java/module-info.java new file mode 100644 index 00000000000..e19edb8e156 --- /dev/null +++ b/nucleus/common/glassfish-jdk-extensions/src/main/java/module-info.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/** + * @author David Matejcek + */ +module org.glassfish.main.jdke { + + requires java.base; + + exports org.glassfish.main.jdke.cl; + exports org.glassfish.main.jdke.i18n; + exports org.glassfish.main.jdke.props; +} diff --git a/nucleus/common/common-util/src/main/java/org/glassfish/common/util/GlassfishUrlClassLoader.java b/nucleus/common/glassfish-jdk-extensions/src/main/java/org/glassfish/main/jdke/cl/GlassfishUrlClassLoader.java similarity index 88% rename from nucleus/common/common-util/src/main/java/org/glassfish/common/util/GlassfishUrlClassLoader.java rename to nucleus/common/glassfish-jdk-extensions/src/main/java/org/glassfish/main/jdke/cl/GlassfishUrlClassLoader.java index 0024da32ac2..9e3a9997a74 100644 --- a/nucleus/common/common-util/src/main/java/org/glassfish/common/util/GlassfishUrlClassLoader.java +++ b/nucleus/common/glassfish-jdk-extensions/src/main/java/org/glassfish/main/jdke/cl/GlassfishUrlClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -14,7 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package org.glassfish.common.util; +package org.glassfish.main.jdke.cl; import java.io.Closeable; import java.io.IOException; @@ -51,33 +51,36 @@ public class GlassfishUrlClassLoader extends URLClassLoader { /** * Initializes the internal classpath. * + * @param name * @param urls */ - public GlassfishUrlClassLoader(URL[] urls) { - super(urls); + public GlassfishUrlClassLoader(String name, URL[] urls) { + super(name, urls, ClassLoader.getSystemClassLoader()); } /** * Initializes the internal classpath. * + * @param name * @param urls * @param parent */ - public GlassfishUrlClassLoader(URL[] urls, ClassLoader parent) { - super(urls, parent); + public GlassfishUrlClassLoader(String name, URL[] urls, ClassLoader parent) { + super(name, urls, parent); } /** * Initializes the internal classpath. * + * @param name * @param urls * @param parent * @param factory */ - public GlassfishUrlClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) { - super(urls, parent, factory); + public GlassfishUrlClassLoader(String name, URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) { + super(name, urls, parent, factory); } // turn protected to public diff --git a/nucleus/common/glassfish-jdk-extensions/src/main/java/org/glassfish/main/jdke/i18n/LocalStringsImpl.java b/nucleus/common/glassfish-jdk-extensions/src/main/java/org/glassfish/main/jdke/i18n/LocalStringsImpl.java new file mode 100644 index 00000000000..ca15c89ddb9 --- /dev/null +++ b/nucleus/common/glassfish-jdk-extensions/src/main/java/org/glassfish/main/jdke/i18n/LocalStringsImpl.java @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation + * Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.main.jdke.i18n; + +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.Locale; +import java.util.ResourceBundle; + +import static java.util.ResourceBundle.Control.FORMAT_PROPERTIES; + +/** + * This class makes getting localized strings super-simple. This is the companion + * class to Strings. Use this class when performance may be an issue. I.e. Strings + * is all-static and creates a ResourceBundle on every call. This class is instantiated + * once and can be used over and over from the same package. + *

    Specifics: + *

      + *
    • Your calling code should have a file named LocalStrings.properties in its + * package directory. + *
    • If your localized string has no arguments call get(String) to get the localized + * String value. + *
    • If you have a parameterized string, call get(String, Object...) + *
    + *

    Note: You can not get an Exception out of calling this code! If the String + * or the properties file does not exist, it will return the String that you gave + * in the first place as the argument. + *

    Example: + *

      + *
    • LocalStringsImpl sh = new LocalStringsImpl(); + *
    • String s = sh.get("xyz"); + *
    • String s = sh.get("xyz", new Date(), 500, "something", 2.00003); + *
    • String s = sh.get("xyz", "something", "foo", "whatever"); + *
    + * + * @author bnevins 2005 + */ +public class LocalStringsImpl { + + private static final boolean LOG_ERRORS = Boolean.parseBoolean(System.getenv("AS_LOG_I18N_ERRORS")); + private static final String LOG_TARGET_FILE = System.getenv("AS_LOG_I18N_LOG_FILE"); + private static final PrintStream LOG_TARGET; + private static final String thisPackage = "com.elf.util"; + private static final ResourceBundle.Control rbcontrol = ResourceBundle.Control.getControl(FORMAT_PROPERTIES); + static { + if (LOG_ERRORS) { + if (LOG_TARGET_FILE == null) { + LOG_TARGET = System.err; + } else { + try { + LOG_TARGET = new PrintStream(LOG_TARGET_FILE); + Runtime.getRuntime().addShutdownHook(new Thread(() -> LOG_TARGET.close())); + } catch (FileNotFoundException e) { + throw new Error(e); + } + } + } else { + LOG_TARGET = null; + } + } + + private final ResourceBundle bundle; + + /** + * Create a LocalStringsImpl instance. + * use the proffered class object to find LocalStrings.properties. + * This is the constructor to use if you are concerned about getting + * the fastest performance. + */ + public LocalStringsImpl(Class clazz) { + bundle = load(clazz); + } + + + private static ResourceBundle load(Class clazz) { + String className = clazz.getName(); + String props = className.substring(0, className.lastIndexOf('.')) + "." + "LocalStrings"; + try { + return ResourceBundle.getBundle(props, Locale.getDefault(), clazz.getModule()); + } catch (Exception e) { + if (LOG_ERRORS) { + LOG_TARGET.println("Could not find resource bundle: " + props); + e.printStackTrace(LOG_TARGET); + } + return null; + } + } + + + /** + * Get a String from the caller's package's LocalStrings.properties + * + * @param key The string index into the localized string file + * @return the String from LocalStrings or the supplied String if it doesn't exist + */ + public String get(String key) { + try { + return getBundle().getString(key); + } catch (Exception e) { + if (LOG_ERRORS) { + LOG_TARGET.println("Could not resolve: " + key); + e.printStackTrace(LOG_TARGET); + } + // it is not an error to have no key... + return key; + } + } + + + /** + * Get and format a String from the caller's package's LocalStrings.properties + * + * @param key The string index into the localized string file + * @param objects The arguments to give to MessageFormat + * @return the String from LocalStrings or the supplied String if it doesn't exist -- + * using the array of supplied Object arguments + */ + public String get(String key, Object... objects) { + final String template = get(key); + if (template == key) { + return key + ": " + Arrays.toString(objects); + } + try { + MessageFormat mf = new MessageFormat(template); + return mf.format(objects); + } catch (Exception e) { + if (LOG_ERRORS) { + e.printStackTrace(LOG_TARGET); + } + return template; + } + } + + + /** + * Get a String from the caller's package's LocalStrings.properties + * + * @param key The string index into the localized string file + * @return the String from LocalStrings or the supplied default value if it doesn't exist + */ + public String getString(String key, String defaultValue) { + try { + return getBundle().getString(key); + } catch (Exception e) { + if (LOG_ERRORS) { + LOG_TARGET.println("Could not resolve: " + key); + e.printStackTrace(LOG_TARGET); + } + // it is not an error to have no key... + return defaultValue; + } + } + + + /** + * Get an integer from the caller's package's LocalStrings.properties + * + * @param key The string index into the localized string file + * @return the integer value from LocalStrings or the supplied default if + * it doesn't exist or is bad. + */ + public int getInt(String key, int defaultValue) { + try { + String s = getBundle().getString(key); + return Integer.parseInt(s); + } catch (Exception e) { + if (LOG_ERRORS) { + LOG_TARGET.println("Could not resolve: " + key); + e.printStackTrace(LOG_TARGET); + } + // it is not an error to have no key... + return defaultValue; + } + } + + + /** + * Get a boolean from the caller's package's LocalStrings.properties + * + * @param key The string index into the localized string file + * @return the integer value from LocalStrings or the supplied default if + * it doesn't exist or is bad. + */ + public boolean getBoolean(String key, boolean defaultValue) { + try { + return Boolean.parseBoolean(getBundle().getString(key)); + } catch (Exception e) { + if (LOG_ERRORS) { + LOG_TARGET.println("Could not resolve: " + key); + e.printStackTrace(LOG_TARGET); + } + // it is not an error to have no key... + return defaultValue; + } + } + + + public ResourceBundle getBundle() { + return bundle; + } +} diff --git a/nucleus/common/glassfish-jdk-extensions/src/main/java/org/glassfish/main/jdke/props/EnvToPropsConverter.java b/nucleus/common/glassfish-jdk-extensions/src/main/java/org/glassfish/main/jdke/props/EnvToPropsConverter.java new file mode 100644 index 00000000000..267ea2556eb --- /dev/null +++ b/nucleus/common/glassfish-jdk-extensions/src/main/java/org/glassfish/main/jdke/props/EnvToPropsConverter.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2024 Eclipse Foundation and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.main.jdke.props; + +import java.io.File; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; + +/** + * Given a file, tries to resolve given keys to absolute paths. + * + * @author David Matejcek + */ +public final class EnvToPropsConverter { + + private final Path anchor; + + /** + * @param relativePathAnchor absolute path; will be normalized. + */ + public EnvToPropsConverter(final Path relativePathAnchor) { + if (relativePathAnchor == null || !relativePathAnchor.isAbsolute()) { + throw new IllegalArgumentException("The path is not absolute: " + relativePathAnchor); + } + anchor = relativePathAnchor.normalize(); + } + + + /** + * Tries to resolve given keys. + *
      + *
    • First tries {@link System#getProperty(String)} using map value. + *
    • Then tries {@link System#getenv(String)} using map key. + *
    + * Then if the retrieved value is relative, it is resolved against the anchor path from + * constructor. + * The resolved file is added to the resulting map using the input map's value as a key. + * There is no guarantee the file does exist. + * + * @param envToSys - key is env name, value is system property name. + * @return map of system property names and absolute files. + */ + public Map convert(final Map envToSys) { + final Map files = new HashMap<>(envToSys.size()); + for (final String envPropertyName : envToSys.keySet()) { + final String systemPropertyName = envToSys.get(envPropertyName); + if (systemPropertyName == null) { + continue; + } + final File file = convert(envPropertyName, systemPropertyName); + if (file != null) { + files.put(systemPropertyName, file); + } + } + return files; + } + + + /** + * Tries to resolve given keys. + *
      + *
    • First tries {@link System#getProperty(String)} using the second parameter. + *
    • Then tries {@link System#getenv(String)} using the first parameter. + *
    + * Then if the retrieved value is relative, it is resolved against the anchor path from + * constructor. + * + * @param envPropertyName + * @param systemPropertyName + * @return file - there is no guarantee the file does exist. + */ + public File convert(final String envPropertyName, final String systemPropertyName) { + final String value = evaluate(envPropertyName, systemPropertyName); + return value == null ? null : toAbsoluteFile(new File(value)); + } + + + private String evaluate(final String envPropertyName, final String systemPropertyName) { + final String sysValue = System.getProperty(systemPropertyName); + if (sysValue != null) { + return sysValue; + } + final String envValue = System.getenv(envPropertyName); + if (envValue != null) { + return envValue; + } +// System.err.println("Missing env " + envPropertyName + " or system property " + systemPropertyName); + return null; + } + + + private File toAbsoluteFile(final File file) { + if (file.isAbsolute()) { + return file.toPath().normalize().toFile(); + } + return anchor.resolve(file.toPath()).toAbsolutePath().normalize().toFile(); + } +} diff --git a/nucleus/common/common-util/src/test/java/org/glassfish/common/util/GlassfishUrlClassLoaderTest.java b/nucleus/common/glassfish-jdk-extensions/src/test/java/org/glassfish/main/jdke/cl/GlassfishUrlClassLoaderTest.java similarity index 80% rename from nucleus/common/common-util/src/test/java/org/glassfish/common/util/GlassfishUrlClassLoaderTest.java rename to nucleus/common/glassfish-jdk-extensions/src/test/java/org/glassfish/main/jdke/cl/GlassfishUrlClassLoaderTest.java index 9b879fe6962..ee87e481f43 100644 --- a/nucleus/common/common-util/src/test/java/org/glassfish/common/util/GlassfishUrlClassLoaderTest.java +++ b/nucleus/common/glassfish-jdk-extensions/src/test/java/org/glassfish/main/jdke/cl/GlassfishUrlClassLoaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Eclipse Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024 Eclipse Foundation and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -14,7 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package org.glassfish.common.util; +package org.glassfish.main.jdke.cl; import java.net.URL; import java.net.URLClassLoader; @@ -33,7 +33,7 @@ public class GlassfishUrlClassLoaderTest { public void isParallel() { assertAll( () -> assertTrue(new URLClassLoader(new URL[0]).isRegisteredAsParallelCapable()), - () -> assertTrue(new GlassfishUrlClassLoader(new URL[0]).isRegisteredAsParallelCapable()) + () -> assertTrue(new GlassfishUrlClassLoader("GlassfishUrlClassLoaderTest", new URL[0]).isRegisteredAsParallelCapable()) ); } } diff --git a/nucleus/common/internal-api/src/main/java/org/glassfish/internal/api/DelegatingClassLoader.java b/nucleus/common/internal-api/src/main/java/org/glassfish/internal/api/DelegatingClassLoader.java index 2b0de80a8ac..0e050a20ca6 100644 --- a/nucleus/common/internal-api/src/main/java/org/glassfish/internal/api/DelegatingClassLoader.java +++ b/nucleus/common/internal-api/src/main/java/org/glassfish/internal/api/DelegatingClassLoader.java @@ -45,6 +45,10 @@ */ public class DelegatingClassLoader extends ClassLoader { + static { + registerAsParallelCapable(); + } + /** * This interface is an optimization. *

    @@ -215,6 +219,7 @@ protected Enumeration findResources(String name) throws IOException { return new CompositeEnumeration(enumerators); } + @Override public String getName() { return name; } diff --git a/nucleus/common/pom.xml b/nucleus/common/pom.xml index 3d26271ee8a..c56252eeb32 100755 --- a/nucleus/common/pom.xml +++ b/nucleus/common/pom.xml @@ -33,6 +33,7 @@ GlassFish Nucleus Common modules + glassfish-jdk-extensions simple-glassfish-api internal-api common-util diff --git a/nucleus/common/simple-glassfish-api/README b/nucleus/common/simple-glassfish-api/README deleted file mode 100644 index 324394082ff..00000000000 --- a/nucleus/common/simple-glassfish-api/README +++ /dev/null @@ -1 +0,0 @@ -The contents of this module is bundled by core/bootstrap module viz., glassfish.jar diff --git a/nucleus/common/simple-glassfish-api/src/main/java/module-info.java b/nucleus/common/simple-glassfish-api/src/main/java/module-info.java new file mode 100644 index 00000000000..26c5d973624 --- /dev/null +++ b/nucleus/common/simple-glassfish-api/src/main/java/module-info.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/** + * Basic GlassFish interfaces and classes used by all implementations. + * + * @uses org.glassfish.embeddable.spi.RuntimeBuilder + * + * @author David Matejcek + */ +module org.glassfish.main.api.simple { + + requires java.base; + requires java.logging; + + uses org.glassfish.embeddable.spi.RuntimeBuilder; + + exports org.glassfish.embeddable; + exports org.glassfish.embeddable.client; + exports org.glassfish.embeddable.spi; +} diff --git a/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/GlassFishRuntime.java b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/GlassFishRuntime.java index 3ceca71df50..a418c7a52e9 100644 --- a/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/GlassFishRuntime.java +++ b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/GlassFishRuntime.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -17,7 +17,6 @@ package org.glassfish.embeddable; -import java.util.Iterator; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; import java.util.logging.Level; @@ -130,7 +129,7 @@ private synchronized static GlassFishRuntime _bootstrap(BootstrapProperties boot } ClassLoader classLoader = cl == null ? GlassFishRuntime.class.getClassLoader() : cl; RuntimeBuilder runtimeBuilder = getRuntimeBuilder(bootstrapProperties, classLoader); - me = runtimeBuilder.build(bootstrapProperties); + me = runtimeBuilder.build(bootstrapProperties, classLoader); return me; } @@ -146,10 +145,8 @@ protected synchronized static void shutdownInternal() throws GlassFishException private static RuntimeBuilder getRuntimeBuilder(BootstrapProperties bootstrapProperties, ClassLoader classLoader) throws GlassFishException { logger.logp(Level.FINE, "GlassFishRuntime", "getRuntimeBuilder", "classloader={0}", classLoader); - Iterator runtimeBuilders = ServiceLoader.load(RuntimeBuilder.class, classLoader).iterator(); - while (runtimeBuilders.hasNext()) { + for (RuntimeBuilder builder : ServiceLoader.load(RuntimeBuilder.class, classLoader)) { try { - RuntimeBuilder builder = runtimeBuilders.next(); logger.logp(Level.FINE, "GlassFishRuntime", "getRuntimeBuilder", "builder = {0}", builder); if (builder.handles(bootstrapProperties)) { return builder; diff --git a/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/client/ApplicationClientCLIEncoding.java b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/client/ApplicationClientCLIEncoding.java new file mode 100644 index 00000000000..14ae72cdfcb --- /dev/null +++ b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/client/ApplicationClientCLIEncoding.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.embeddable.client; + + +/** + * This class is used to share arguments as a string property between Java Agent + * and Java Main class. + */ +public final class ApplicationClientCLIEncoding { + + private final static String COMMA_IN_ARG_PLACEHOLDER = "+-+-+-+"; + + private ApplicationClientCLIEncoding() { + // utility class + } + + /** + * Replaces commas in an argument value (which can confuse the ACC agent argument parsing because shells strip out + * double-quotes) with a special sequence. + * + * @param string string to encode + * @return encoded string + */ + public static String encodeArg(String string) { + return string.replace(",", COMMA_IN_ARG_PLACEHOLDER); + } + + /** + * Replaces occurrences of comma encoding with commas. + * + * @param string possibly encoded string + * @return decoded string + */ + public static String decodeArg(String string) { + return string.replace(COMMA_IN_ARG_PLACEHOLDER, ","); + } + +} diff --git a/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/client/ApplicationClientClassLoader.java b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/client/ApplicationClientClassLoader.java new file mode 100644 index 00000000000..7291c7b43cd --- /dev/null +++ b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/client/ApplicationClientClassLoader.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Contributors to Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.embeddable.client; + + +/** + * Marks class loaders in gf-client and gf-client-module which can provide a container + * initialized by the Java agent. + *

    + * It is the only way to send an object from the agent to the main class. + *

    + * {@link ClassLoader} is an abstract class and we don't want to introduce + * multiple inheritance, so this interface is added to chosen class loaders. + * The hierarchy in the appclient is strictly defined, so this is enough. + * Older implementations used principially same "trick", but this is bit more + * readable as you can always search usages of this interface. + */ +public interface ApplicationClientClassLoader { + + /** + * Sets the container. Default implementation doesn't do anything. + * + * @param container + */ + default void setApplicationClientContainer(ApplicationClientContainer container) { + // does nothing by default. + } + + /** + * @return {@link ApplicationClientContainer} + */ + ApplicationClientContainer getApplicationClientContainer(); +} diff --git a/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/client/ApplicationClientContainer.java b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/client/ApplicationClientContainer.java new file mode 100644 index 00000000000..7033cad650f --- /dev/null +++ b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/client/ApplicationClientContainer.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.embeddable.client; + + +/** + * Shared interface required to avoid circular dependency of gf-client.jar and gf-client-module.jar + */ +public interface ApplicationClientContainer { + + /** + * Executes the client. The implementation of this interface might require some preparation. + * + * @param args + * @throws UserError When user provided incorrect arguments or some requirements were not met. + */ + void launch(String[] args) throws UserError; +} diff --git a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/UserError.java b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/client/UserError.java similarity index 63% rename from appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/UserError.java rename to nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/client/UserError.java index 7110d8dbdb8..2dabd757c1a 100644 --- a/appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/UserError.java +++ b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/client/UserError.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -14,33 +15,36 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package org.glassfish.appclient.client.acc; +package org.glassfish.embeddable.client; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.text.MessageFormat; /** - *Represents any user error, such as an invalid combination of command options, - *or specifying a non-existent JAR file. - *

    - *Such errors should be user-correctable, provided the message is clear. - *So no stack traces should be displayed when UserErrors are thrown. + * Represents any user error, such as an invalid combination of command options, + * or specifying a non-existent JAR file. + *

    + * Such errors should be user-correctable, provided the message is clear. + * So no stack traces should be displayed when UserErrors are thrown. * * @author tjquinn */ public class UserError extends Throwable { + private static final long serialVersionUID = 4171944609382558583L; + /** Allows user to turn on stack traces for user errors - normally off */ - private static final String SHOW_STACK_TRACES_PROPERTY_NAME = - UserError.class.getPackage().getName() + ".showUserErrorStackTraces"; + private static final String SHOW_STACK_TRACES_PROPERTY_NAME = UserError.class.getPackage().getName() + + ".showUserErrorStackTraces"; /** * Creates a new UserError instance having formatted the message with the * arguments provided. - *@param message the message string, presumably containing argument placeholders - *@param args 0 or more arguments for substitution for the placeholders in the message string - *@return new UserError with message formatted as requested + * + * @param message the message string, presumably containing argument placeholders + * @param args 0 or more arguments for substitution for the placeholders in the message string + * @return new UserError with message formatted as requested */ public static UserError formatUserError(String message, String... args) { String formattedMessage = MessageFormat.format(message, (Object[]) args); @@ -49,7 +53,7 @@ public static UserError formatUserError(String message, String... args) { } /** xmlMessage implementation showed the usage message after the error */ - private String usage = null; + private String usage; public UserError(String message) { super(message); @@ -63,24 +67,27 @@ public UserError(Throwable cause) { super(cause); } + /** - *Sets whether or not the usage message should be displayed after the - *error message is displayed to the user. - *@param showUsage the new setting + * Sets whether or not the usage message should be displayed after the + * error message is displayed to the user. + * + * @param usage the new setting */ public void setUsage(String usage) { this.usage = usage; } + /** - *Displays the user error message, and any messages along the exception - *chain, if any, and then exits. If showUsage has been set to true, then - *the usage message is displayed before exiting. - *

    - *Only the messages, and not the stack traces, are shown because these are - *user errors that should be user-correctable. Stack traces are too - *alarming and of minimal use to the user as he or she tries to understand - *and fix the error. + * Displays the user error message, and any messages along the exception + * chain, if any, and then exits. If showUsage has been set to true, then + * the usage message is displayed before exiting. + *

    + * Only the messages, and not the stack traces, are shown because these are + * user errors that should be user-correctable. Stack traces are too + * alarming and of minimal use to the user as he or she tries to understand + * and fix the error. */ public void displayAndExit() { display(System.err); diff --git a/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/spi/RuntimeBuilder.java b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/spi/RuntimeBuilder.java index 41386c97726..9604e67f4c1 100644 --- a/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/spi/RuntimeBuilder.java +++ b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/spi/RuntimeBuilder.java @@ -36,7 +36,13 @@ public interface RuntimeBuilder { * @return * @throws GlassFishException */ - GlassFishRuntime build(BootstrapProperties options) throws GlassFishException; + default GlassFishRuntime build(BootstrapProperties options) throws GlassFishException { + return build(options, getClass().getClassLoader()); + } + + + GlassFishRuntime build(BootstrapProperties options, ClassLoader classloader) throws GlassFishException; + /** * Returns true if this RuntimeBuilder is capable of creating a GlassFishRuntime diff --git a/nucleus/core/bootstrap-osgi/pom.xml b/nucleus/core/bootstrap-osgi/pom.xml new file mode 100755 index 00000000000..0654a9cf289 --- /dev/null +++ b/nucleus/core/bootstrap-osgi/pom.xml @@ -0,0 +1,112 @@ + + + + + 4.0.0 + + + org.glassfish.main.core + nucleus-core + 7.0.21-SNAPSHOT + + + glassfish-osgi-bootstrap + glassfish-jar + + Appserver Core OSGI Bootstraping + + + + org.glassfish.main.core + glassfish + ${project.version} + provided + + + org.glassfish.hk2 + hk2-core + + + org.glassfish.hk2 + hk2-extras + provided + + + org.osgi + osgi.core + provided + + + + org.glassfish.main.common + simple-glassfish-api + ${project.version} + + + org.glassfish.main.common + common-util + ${project.version} + + + org.glassfish.main.common + glassfish-api + + + + + org.glassfish.main.common + glassfish-jdk-extensions + ${project.version} + provided + + + org.glassfish.annotations + logging-annotation-processor + true + + + + org.junit.jupiter + junit-jupiter-engine + + + org.hamcrest + hamcrest + + + org.apache.felix + org.apache.felix.main + test + + + + + + + org.apache.felix + maven-bundle-plugin + + + org.glassfish.main.boot.osgi.GlassFishMainActivator + + + + + + diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/AutoDisposableGlassFish.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/AutoDisposableGlassFish.java similarity index 96% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/AutoDisposableGlassFish.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/AutoDisposableGlassFish.java index f9eb3420c1a..3daebd3bab0 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/AutoDisposableGlassFish.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/AutoDisposableGlassFish.java @@ -14,9 +14,8 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.embedded; +package org.glassfish.main.boot.embedded; -import com.sun.enterprise.glassfish.bootstrap.GlassFishImpl; import com.sun.enterprise.module.bootstrap.ModuleStartup; import java.io.File; @@ -33,6 +32,7 @@ import org.glassfish.embeddable.GlassFishException; import org.glassfish.embeddable.GlassFishProperties; import org.glassfish.hk2.api.ServiceLocator; +import org.glassfish.main.boot.impl.GlassFishImpl; import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.AUTO_DELETE; diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/EmbeddedGlassFishRuntime.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedGlassFishRuntime.java similarity index 98% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/EmbeddedGlassFishRuntime.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedGlassFishRuntime.java index 68c3b46af53..2cc08e7c267 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/EmbeddedGlassFishRuntime.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedGlassFishRuntime.java @@ -15,10 +15,9 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.embedded; +package org.glassfish.main.boot.embedded; import com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys; -import com.sun.enterprise.glassfish.bootstrap.log.LogFacade; import com.sun.enterprise.module.ModulesRegistry; import com.sun.enterprise.module.bootstrap.Main; import com.sun.enterprise.module.bootstrap.ModuleStartup; @@ -46,6 +45,7 @@ import org.glassfish.embeddable.GlassFishRuntime; import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.hk2.utilities.DuplicatePostProcessor; +import org.glassfish.main.boot.log.LogFacade; import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.AUTO_DELETE; import static java.util.logging.Level.FINER; @@ -64,7 +64,7 @@ class EmbeddedGlassFishRuntime extends GlassFishRuntime { private final Map glassFishInstances = new ConcurrentHashMap<>(); private final Main main; - public EmbeddedGlassFishRuntime(Main main) { + EmbeddedGlassFishRuntime(Main main) { this.main = main; } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/EmbeddedGlassFishRuntimeBuilder.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedGlassFishRuntimeBuilder.java similarity index 82% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/EmbeddedGlassFishRuntimeBuilder.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedGlassFishRuntimeBuilder.java index 63681e82857..17f42159f07 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/EmbeddedGlassFishRuntimeBuilder.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedGlassFishRuntimeBuilder.java @@ -15,14 +15,12 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.embedded; +package org.glassfish.main.boot.embedded; import com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys; import com.sun.enterprise.glassfish.bootstrap.cfg.OsgiPlatform; -import com.sun.enterprise.glassfish.bootstrap.cfg.StartupContextUtil; -import com.sun.enterprise.glassfish.bootstrap.log.LogFacade; +import com.sun.enterprise.glassfish.bootstrap.cfg.ServerFiles; import com.sun.enterprise.module.ModulesRegistry; -import com.sun.enterprise.module.bootstrap.Main; import com.sun.enterprise.module.common_impl.AbstractFactory; import java.io.File; @@ -34,11 +32,12 @@ import java.util.logging.Level; import java.util.logging.Logger; -import org.glassfish.common.util.GlassfishUrlClassLoader; import org.glassfish.embeddable.BootstrapProperties; import org.glassfish.embeddable.GlassFishException; import org.glassfish.embeddable.GlassFishRuntime; import org.glassfish.embeddable.spi.RuntimeBuilder; +import org.glassfish.main.boot.log.LogFacade; +import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; /** * @author bhavanishankar@dev.java.net @@ -53,13 +52,8 @@ public class EmbeddedGlassFishRuntimeBuilder implements RuntimeBuilder { @Override public GlassFishRuntime build(BootstrapProperties bsProps) throws GlassFishException { - /* Step 1. Build the classloader. */ - // The classloader should contain installRoot/modules/**/*.jar files. String installRoot = getInstallRoot(bsProps); - if (installRoot != null) { - System.setProperty("org.glassfish.embeddable.installRoot", installRoot); - } - // Required to add moduleJarURLs to support 'java -jar modules/glassfish.jar case' + // Required to add moduleJarURLs to support 'java -jar glassfish.jar case' List moduleJarURLs = getModuleJarURLs(installRoot); final ClassLoader cl; if (moduleJarURLs.isEmpty()) { @@ -67,21 +61,30 @@ public GlassFishRuntime build(BootstrapProperties bsProps) throws GlassFishExcep } else { cl = new EmbeddedClassLoader(getClass().getClassLoader(), moduleJarURLs); } + return build(bsProps, cl, installRoot); + } + + @Override + public GlassFishRuntime build(BootstrapProperties bsProps, ClassLoader cl) throws GlassFishException { + String installRoot = getInstallRoot(bsProps); + return build(bsProps, cl, installRoot); + } + + private GlassFishRuntime build(BootstrapProperties bsProps, ClassLoader cl, String installRoot) { + if (installRoot != null) { + System.setProperty("org.glassfish.embeddable.installRoot", installRoot); + } // Step 2. Setup the module subsystem. - Main main = new EmbeddedMain(); SingleHK2Factory.initialize(cl); ModulesRegistry modulesRegistry = AbstractFactory.getInstance().createModulesRegistry(); modulesRegistry.setParentClassLoader(cl); // Step 3. Create NonOSGIGlassFishRuntime - GlassFishRuntime glassFishRuntime = new EmbeddedGlassFishRuntime(main); - LOG.logp(Level.FINER, getClass().getName(), "build", - "Created GlassFishRuntime {0} with InstallRoot {1}, Bootstrap Options {2}", - new Object[]{glassFishRuntime, installRoot, bsProps}); - return glassFishRuntime; + return new EmbeddedGlassFishRuntime(new EmbeddedMain()); } + @Override public boolean handles(BootstrapProperties bsProps) { // See GLASSFISH-16743 for the reason behind additional check @@ -97,7 +100,7 @@ public boolean handles(BootstrapProperties bsProps) { private String getInstallRoot(BootstrapProperties props) { String installRootProp = props.getInstallRoot(); if (installRootProp == null) { - File installRoot = StartupContextUtil.detectInstallRoot(); + File installRoot = ServerFiles.detectInstallRoot(); if (isValidInstallRoot(installRoot)) { installRootProp = installRoot.getAbsolutePath(); } @@ -144,9 +147,12 @@ private boolean isValidInstallRoot(File installRoot) { } private static class EmbeddedClassLoader extends GlassfishUrlClassLoader { + static { + registerAsParallelCapable(); + } - EmbeddedClassLoader(ClassLoader parent, List moduleJarURLs) { - super(moduleJarURLs.toArray(URL[]::new), parent); + private EmbeddedClassLoader(ClassLoader parent, List moduleJarURLs) { + super("EmbeddedCL", moduleJarURLs.toArray(URL[]::new), parent); } } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/EmbeddedInhabitantsParser.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedInhabitantsParser.java similarity index 96% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/EmbeddedInhabitantsParser.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedInhabitantsParser.java index c44dc4b7bee..405da792bc8 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/EmbeddedInhabitantsParser.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedInhabitantsParser.java @@ -15,9 +15,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.embedded; - -import com.sun.enterprise.glassfish.bootstrap.log.LogFacade; +package org.glassfish.main.boot.embedded; import java.util.logging.Level; import java.util.logging.Logger; @@ -26,6 +24,7 @@ import org.glassfish.hk2.api.PopulatorPostProcessor; import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.hk2.utilities.DescriptorImpl; +import org.glassfish.main.boot.log.LogFacade; /** * Kernel's decoration for embedded environment. diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/EmbeddedMain.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedMain.java similarity index 96% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/EmbeddedMain.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedMain.java index 867f24dfe26..628263ad4d7 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/EmbeddedMain.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/EmbeddedMain.java @@ -15,7 +15,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.embedded; +package org.glassfish.main.boot.embedded; import com.sun.enterprise.module.bootstrap.BootException; import com.sun.enterprise.module.bootstrap.Main; diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/JarUtil.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/JarUtil.java similarity index 97% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/JarUtil.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/JarUtil.java index 10bd0dc6fd4..0952aa639ba 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/JarUtil.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/JarUtil.java @@ -15,9 +15,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.embedded; - -import com.sun.enterprise.glassfish.bootstrap.log.LogFacade; +package org.glassfish.main.boot.embedded; import java.io.File; import java.io.FileOutputStream; @@ -29,6 +27,8 @@ import java.util.logging.Level; import java.util.logging.Logger; +import org.glassfish.main.boot.log.LogFacade; + /** * Most part is copied from com.sun.appserv.connectors.internal.api.ConnectorsUtil *

    diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/SingleHK2Factory.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/SingleHK2Factory.java similarity index 95% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/SingleHK2Factory.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/SingleHK2Factory.java index 69b57f035d8..11467f95490 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/embedded/SingleHK2Factory.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/SingleHK2Factory.java @@ -15,15 +15,16 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.embedded; +package org.glassfish.main.boot.embedded; -import com.sun.enterprise.glassfish.bootstrap.log.LogFacade; import com.sun.enterprise.module.ModuleDefinition; import com.sun.enterprise.module.ModulesRegistry; import com.sun.enterprise.module.common_impl.AbstractFactory; import com.sun.enterprise.module.common_impl.ModuleId; import com.sun.enterprise.module.single.SingleModulesRegistry; +import org.glassfish.main.boot.log.LogFacade; + /** * Factory which provides SingleModulesRegistry * This should actually be in HK2 workspace. diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/impl/GlassFishImpl.java similarity index 99% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/impl/GlassFishImpl.java index 0587528d6fe..fbf2b930325 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishImpl.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/impl/GlassFishImpl.java @@ -15,7 +15,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap; +package org.glassfish.main.boot.impl; import com.sun.enterprise.module.bootstrap.ModuleStartup; diff --git a/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/log/LogFacade.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/log/LogFacade.java new file mode 100644 index 00000000000..c462735f160 --- /dev/null +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/log/LogFacade.java @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation + * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.main.boot.log; + +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; + +import org.glassfish.logging.annotation.LogMessageInfo; +import org.glassfish.logging.annotation.LogMessagesResourceBundle; +import org.glassfish.logging.annotation.LoggerInfo; + +public class LogFacade { + + @LoggerInfo(subsystem = "BOOTSTRAP", description="Main bootstrap logger.") + public static final String BOOTSTRAP_LOGGER_NAME = "jakarta.enterprise.bootstrap"; + + @LogMessagesResourceBundle + public static final String RB_NAME = "org.glassfish.main.boot.log.LogMessages"; + + public static final Logger BOOTSTRAP_LOGGER = Logger.getLogger(BOOTSTRAP_LOGGER_NAME, RB_NAME); + + @LogMessageInfo( + message = "Can not start bundle {0} because it is not contained in the list of installed bundles.", + level = "WARNING") + public static final String CANT_START_BUNDLE = "NCLS-BOOTSTRAP-00005"; + + @LogMessageInfo( + message = "Failed to start {0}.", + level = "WARNING") + public static final String BUNDLE_START_FAILED = "NCLS-BOOTSTRAP-00006"; + + @LogMessageInfo( + message = "Can't uninstall bundle = {0} as it's already uninstalled.", + level = "WARNING") + public static final String BUNDLE_ALREADY_UNINSTALED = "NCLS-BOOTSTRAP-00007"; + + @LogMessageInfo( + message = "Uninstalled bundle {0} installed from {1}.", + level = "INFO") + public static final String UNINSTALLED_BUNDLE = "NCLS-BOOTSTRAP-00008"; + + @LogMessageInfo( + message = "Can't update bundle = {0} as it's already uninstalled.", + level = "WARNING") + public static final String CANT_UPDATE_ALREADY_INSTALLED = "NCLS-BOOTSTRAP-00009"; + + @LogMessageInfo( + message = "Updated bundle {0} from {1}.", + level = "INFO") + public static final String BUNDLE_UPDATED = "NCLS-BOOTSTRAP-00010"; + + @LogMessageInfo( + message = "Failed to uninstall bundle {0}.", + level = "WARNING") + public static final String BUNDLE_UNINSTALL_FAILED = "NCLS-BOOTSTRAP-00011"; + + @LogMessageInfo( + message = "Failed to update {0}.", + level = "WARNING") + public static final String UPDATE_FAILED = "NCLS-BOOTSTRAP-00012"; + + @LogMessageInfo( + message = "Failed to install {0}.", + level = "WARNING") + public static final String INSTALL_FAILED = "NCLS-BOOTSTRAP-00013"; + + @LogMessageInfo( + message = "Can not set the start level for {0} to {2} as it is already set to {1}.", + level = "WARNING") + public static final String CANT_SET_START_LEVEL = "NCLS-BOOTSTRAP-00014"; + + @LogMessageInfo( + message = "Skipping entry {0} because it is not an absolute URI.", + level = "WARNING") + public static final String ENTRY_SKIPPED = "NCLS-BOOTSTRAP-00015"; + + @LogMessageInfo( + message = "Skipping entry {0} due to exception: ", + level = "WARNING") + public static final String ENTRY_SKIPPED_DUE_TO = "NCLS-BOOTSTRAP-00016"; + + @LogMessageInfo( + message = "Create bundle provisioner {0}.", + level = "CONFIG") + public static final String CREATE_BUNDLE_PROVISIONER = "NCLS-BOOTSTRAP-00026"; + + @LogMessageInfo( + message = "Registered {0} as OSGi service registration: {1}.", + level = "CONFIG") + public static final String SERVICE_REGISTERED = "NCLS-BOOTSTRAP-00027"; + + @LogMessageInfo( + message = "Unregistered {0} from service registry.", + level = "CONFIG") + public static final String SERVICE_UNREGISTERED = "NCLS-BOOTSTRAP-00028"; + + @LogMessageInfo( + message = "Exception while unregistering: ", + level = "WARNING") + public static final String SERVICE_UNREGISTRATION_EXCEPTION = "NCLS-BOOTSTRAP-00029"; + + @LogMessageInfo( + message = "installLocations = {0}.", + level = "INFO") + public static final String SHOW_INSTALL_LOCATIONS = "NCLS-BOOTSTRAP-00030"; + + @LogMessageInfo( + message = "Unable to determine if {0} is a fragment or not due to ", + level = "INFO") + public static final String CANT_TELL_IF_FRAGMENT = "NCLS-BOOTSTRAP-00031"; + + @LogMessageInfo( + message = "Skipping starting of bundles bundles have been provisioned already.", + level = "INFO") + public static final String SKIP_STARTING_ALREADY_PROVISIONED_BUNDLES = "NCLS-BOOTSTRAP-00032"; + + @LogMessageInfo( + message = "{0} : latest file in installation location = {1} and latest installed bundle = {2} ", + level = "INFO") + public static final String LATEST_FILE_IN_INSTALL_LOCATION = "NCLS-BOOTSTRAP-00033"; + + @LogMessageInfo( + message = "Updating system bundle.", + level = "INFO") + public static final String UPDATING_SYSTEM_BUNDLE = "NCLS-BOOTSTRAP-00034"; + + @LogMessageInfo( + message = "Provisioning options have changed, recreating the framework with a clean OSGi storage(aka cache).", + level = "INFO") + public static final String PROVISIONING_OPTIONS_CHANGED = "NCLS-BOOTSTRAP-00035"; + + @LogMessageInfo( + message = "Storage support not available in framework bundle, so can't store bundle ids. This may lead to slower start up time.", + level = "WARNING") + public static final String CANT_STORE_BUNDLEIDS = "NCLS-BOOTSTRAP-00037"; + + @LogMessageInfo( + message = "Storage support not available in framework bundle, so can't store provisioning options. This may lead to slower start up time.", + level = "WARNING") + public static final String CANT_STORE_PROVISIONING_OPTIONS = "NCLS-BOOTSTRAP-00038"; + + @LogMessageInfo( + message = "Got an unexpected exception.", + level = "WARNING") + public static final String CAUGHT_EXCEPTION = "NCLS-BOOTSTRAP-00039"; + + /** + * This helper method is duplicated from org.glassfish.api.logging.LogHelper to avoid adding + * dependency on the glassfish-api bundle. + * Logs a message with the given level, message, parameters and Throwable. + * + * @param logger the Logger object to be used for logging the message. + * @param level the Level of the message to be logged. + * @param messageId the key in the resource bundle of the Logger containing the localized text. + * @param thrown the Throwable associated with the message to be logged. + * @param params the parameters to the localized text. + */ + public static void log(Logger logger, Level level, String messageId, Throwable thrown, Object... params) { + LogRecord rec = new LogRecord(level, messageId); + rec.setLoggerName(logger.getName()); + rec.setResourceBundleName(logger.getResourceBundleName()); + rec.setResourceBundle(logger.getResourceBundle()); + rec.setParameters(params); + rec.setThrown(thrown); + logger.log(rec); + } +} diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/BundleProvisioner.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/BundleProvisioner.java similarity index 99% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/BundleProvisioner.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/BundleProvisioner.java index 9509601a45e..2100bd22149 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/BundleProvisioner.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/BundleProvisioner.java @@ -15,9 +15,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; - -import com.sun.enterprise.glassfish.bootstrap.log.LogFacade; +package org.glassfish.main.boot.osgi; import java.io.InputStream; import java.net.URI; @@ -31,6 +29,7 @@ import java.util.logging.Level; import java.util.logging.Logger; +import org.glassfish.main.boot.log.LogFacade; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/BundleProvisionerCustomizer.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/BundleProvisionerCustomizer.java similarity index 97% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/BundleProvisionerCustomizer.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/BundleProvisionerCustomizer.java index 4d8e20bc477..984f14dfbcb 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/BundleProvisionerCustomizer.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/BundleProvisionerCustomizer.java @@ -14,7 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; +package org.glassfish.main.boot.osgi; import java.net.URI; import java.util.List; @@ -66,4 +66,4 @@ interface BundleProvisionerCustomizer { * @return start level of this bundle. -1 if not known */ Integer getStartLevel(Jar jar); -} \ No newline at end of file +} diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/DefaultBundleProvisionerCustomizer.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/DefaultBundleProvisionerCustomizer.java similarity index 96% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/DefaultBundleProvisionerCustomizer.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/DefaultBundleProvisionerCustomizer.java index 8e0c69401e6..dd013789f71 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/DefaultBundleProvisionerCustomizer.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/DefaultBundleProvisionerCustomizer.java @@ -14,9 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; - -import com.sun.enterprise.glassfish.bootstrap.log.LogFacade; +package org.glassfish.main.boot.osgi; import java.io.File; import java.io.FileFilter; @@ -33,6 +31,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import org.glassfish.main.boot.log.LogFacade; import org.osgi.framework.Bundle; import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.AUTO_INSTALL_PROP; @@ -85,8 +84,11 @@ class DefaultBundleProvisionerCustomizer implements BundleProvisionerCustomizer this.config = config; // for optimization reasons, process these properties once and store their values processAutoInstallLocations(); + LOG.log(Level.CONFIG, () -> "autoInstallLocations:\n" + autoInstallLocations); processAutoStartLocations(); + LOG.log(Level.CONFIG, () -> "autoStartLocations:\n" + autoStartLocations); processStartLevels(); + LOG.log(Level.CONFIG, () -> "configuredAutoInstallLocations:\n" + configuredAutoInstallLocations); } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/EmbeddedOSGiGlassFishImpl.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishImpl.java similarity index 95% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/EmbeddedOSGiGlassFishImpl.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishImpl.java index ce1a19b2592..02fcc67eb13 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/EmbeddedOSGiGlassFishImpl.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishImpl.java @@ -15,15 +15,14 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; - -import com.sun.enterprise.glassfish.bootstrap.log.LogFacade; +package org.glassfish.main.boot.osgi; import java.util.logging.Level; import java.util.logging.Logger; import org.glassfish.embeddable.GlassFish; import org.glassfish.embeddable.GlassFishException; +import org.glassfish.main.boot.log.LogFacade; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/EmbeddedOSGiGlassFishRuntime.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishRuntime.java similarity index 87% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/EmbeddedOSGiGlassFishRuntime.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishRuntime.java index 3e3631c49ec..2f092f215fb 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/EmbeddedOSGiGlassFishRuntime.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishRuntime.java @@ -15,11 +15,8 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; +package org.glassfish.main.boot.osgi; -import com.sun.enterprise.glassfish.bootstrap.GlassFishImpl; -import com.sun.enterprise.glassfish.bootstrap.cfg.AsenvConf; -import com.sun.enterprise.glassfish.bootstrap.cp.GlassfishBootstrapClassLoader; import com.sun.enterprise.module.ModulesRegistry; import com.sun.enterprise.module.bootstrap.BootException; import com.sun.enterprise.module.bootstrap.Main; @@ -37,17 +34,20 @@ import java.util.Arrays; import java.util.Enumeration; import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.logging.Logger; import java.util.stream.Collectors; -import org.glassfish.common.util.GlassfishUrlClassLoader; import org.glassfish.embeddable.GlassFish; import org.glassfish.embeddable.GlassFishException; import org.glassfish.embeddable.GlassFishProperties; import org.glassfish.embeddable.GlassFishRuntime; import org.glassfish.hk2.api.MultiException; import org.glassfish.hk2.api.ServiceLocator; +import org.glassfish.main.boot.impl.GlassFishImpl; +import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; +import org.glassfish.main.jdke.props.EnvToPropsConverter; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; @@ -58,6 +58,13 @@ import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.INSTALL_ROOT_URI_PROP_NAME; import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.INSTANCE_ROOT_PROP_NAME; import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.INSTANCE_ROOT_URI_PROP_NAME; +import static com.sun.enterprise.util.SystemPropertyConstants.AGENT_ROOT_PROPERTY; +import static com.sun.enterprise.util.SystemPropertyConstants.CONFIG_ROOT_PROPERTY; +import static com.sun.enterprise.util.SystemPropertyConstants.DERBY_ROOT_PROPERTY; +import static com.sun.enterprise.util.SystemPropertyConstants.DOMAINS_ROOT_PROPERTY; +import static com.sun.enterprise.util.SystemPropertyConstants.IMQ_BIN_PROPERTY; +import static com.sun.enterprise.util.SystemPropertyConstants.IMQ_LIB_PROPERTY; +import static com.sun.enterprise.util.SystemPropertyConstants.JAVA_ROOT_PROPERTY_ASENV; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.logging.Level.FINEST; import static org.glassfish.embeddable.GlassFish.Status.DISPOSED; @@ -226,16 +233,25 @@ private void tryAddPomProperties(Bundle bundle, StringBuilder bundleBuilder) thr private void setEnv(Properties bootstrapProperties) { final String installRootValue = bootstrapProperties.getProperty(INSTALL_ROOT_PROP_NAME); if (installRootValue != null && !installRootValue.isEmpty()) { + final Map pairs = Map.of( + "AS_DERBY_INSTALL", DERBY_ROOT_PROPERTY, + "AS_IMQ_LIB", IMQ_LIB_PROPERTY, + "AS_IMQ_BIN", IMQ_BIN_PROPERTY, + "AS_CONFIG", CONFIG_ROOT_PROPERTY, + "AS_JAVA", JAVA_ROOT_PROPERTY_ASENV, + "AS_DEF_DOMAINS_PATH", DOMAINS_ROOT_PROPERTY, + "AS_DEF_NODES_PATH", AGENT_ROOT_PROPERTY); + File installRoot = new File(installRootValue); - System.setProperty(INSTALL_ROOT_PROP_NAME, installRoot.getAbsolutePath()); - final AsenvConf asenv = AsenvConf.parseAsEnv(installRoot); - asenv.mirrorToSystemProperties(); + new EnvToPropsConverter(installRoot.toPath()).convert(pairs).entrySet() + .forEach(e -> System.setProperty(e.getKey(), e.getValue().getPath())); + System.setProperty(INSTALL_ROOT_PROP_NAME, installRootValue); System.setProperty(INSTALL_ROOT_URI_PROP_NAME, installRoot.toURI().toString()); } final String instanceRootValue = bootstrapProperties.getProperty(INSTANCE_ROOT_PROP_NAME); if (instanceRootValue != null && !instanceRootValue.isEmpty()) { - File instanceRoot = new File(instanceRootValue); + File instanceRoot = new File(instanceRootValue).toPath().normalize().toFile(); System.setProperty(INSTANCE_ROOT_PROP_NAME, instanceRoot.getAbsolutePath()); System.setProperty(INSTANCE_ROOT_URI_PROP_NAME, instanceRoot.toURI().toString()); } @@ -269,7 +285,7 @@ private void logCL(final Logger logger, final String label, final ClassLoader cl private String toString(final ClassLoader classLoader) { - if (classLoader instanceof GlassfishBootstrapClassLoader || classLoader instanceof GlassfishUrlClassLoader) { + if (classLoader instanceof GlassfishUrlClassLoader) { return classLoader.toString(); } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/EmbeddedOSGiGlassFishRuntimeBuilder.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishRuntimeBuilder.java similarity index 79% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/EmbeddedOSGiGlassFishRuntimeBuilder.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishRuntimeBuilder.java index 94f5785ea3e..2a829c97d61 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/EmbeddedOSGiGlassFishRuntimeBuilder.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/EmbeddedOSGiGlassFishRuntimeBuilder.java @@ -15,7 +15,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; +package org.glassfish.main.boot.osgi; import com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys; import com.sun.enterprise.glassfish.bootstrap.cfg.OsgiPlatform; @@ -54,11 +54,12 @@ public boolean handles(BootstrapProperties bsProps) { } @Override - public GlassFishRuntime build(BootstrapProperties bsProps) throws GlassFishException { + public GlassFishRuntime build(BootstrapProperties bsProps, ClassLoader classloader) throws GlassFishException { configureBundles(bsProps); - provisionBundles(bsProps); - GlassFishRuntime gfr = new EmbeddedOSGiGlassFishRuntime(getBundleContext()); - getBundleContext().registerService(GlassFishRuntime.class.getName(), gfr, (Hashtable) bsProps.getProperties()); + provisionBundles(bsProps, classloader); + BundleContext bundleContext = getBundleContext(classloader); + GlassFishRuntime gfr = new EmbeddedOSGiGlassFishRuntime(bundleContext); + bundleContext.registerService(GlassFishRuntime.class.getName(), gfr, (Hashtable) bsProps.getProperties()); return gfr; } @@ -68,14 +69,13 @@ private void configureBundles(BootstrapProperties bsProps) { } } - private BundleContext getBundleContext() { - return BundleReference.class.cast(getClass().getClassLoader()).getBundle().getBundleContext(); - } - - private void provisionBundles(BootstrapProperties bsProps) { - BundleProvisioner bundleProvisioner = new BundleProvisioner(getBundleContext(), bsProps.getProperties()); + private void provisionBundles(BootstrapProperties bsProps, ClassLoader classloader) { + BundleProvisioner bundleProvisioner = new BundleProvisioner(getBundleContext(classloader), bsProps.getProperties()); bundleProvisioner.installBundles(); bundleProvisioner.startBundles(); } + private BundleContext getBundleContext(ClassLoader classloader) { + return BundleReference.class.cast(classloader).getBundle().getBundleContext(); + } } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/GlassFishBundleContext.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/GlassFishBundleContext.java similarity index 98% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/GlassFishBundleContext.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/GlassFishBundleContext.java index a04ca78fdbb..0db2f95753d 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/GlassFishBundleContext.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/GlassFishBundleContext.java @@ -14,7 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; +package org.glassfish.main.boot.osgi; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/GlassFishDecorator.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/GlassFishDecorator.java similarity index 97% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/GlassFishDecorator.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/GlassFishDecorator.java index 2020a637641..12069c5d860 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/GlassFishDecorator.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/GlassFishDecorator.java @@ -15,7 +15,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; +package org.glassfish.main.boot.osgi; import org.glassfish.embeddable.CommandRunner; import org.glassfish.embeddable.Deployer; diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/GlassFishMainActivator.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/GlassFishMainActivator.java similarity index 82% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/GlassFishMainActivator.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/GlassFishMainActivator.java index 4ba09919104..d8ddbb32f1d 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/GlassFishMainActivator.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/GlassFishMainActivator.java @@ -15,14 +15,13 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; +package org.glassfish.main.boot.osgi; import com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys; import java.io.File; import java.lang.System.Logger; import java.net.URI; -import java.nio.file.Path; import java.util.Properties; import org.glassfish.embeddable.BootstrapProperties; @@ -30,7 +29,6 @@ import org.glassfish.embeddable.GlassFishException; import org.glassfish.embeddable.GlassFishProperties; import org.glassfish.embeddable.GlassFishRuntime; -import org.glassfish.main.jul.JULHelperFactory; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -61,7 +59,7 @@ */ public class GlassFishMainActivator implements BundleActivator { - private static final Logger LOG = JULHelperFactory.getHelper().getSystemLogger(GlassFishMainActivator.class); + private static final Logger LOG = System.getLogger(GlassFishMainActivator.class.getName()); private static final String[] DEFAULT_INSTALLATION_LOCATIONS_RELATIVE = new String[]{ // Order is important. @@ -175,8 +173,8 @@ private GlassFishRuntime lookupGfr(BundleContext context) { if (context == null) { return null; } - final ServiceReference serviceReference = context.getServiceReference(GlassFishRuntime.class.getName()); - return serviceReference == null ? null : (GlassFishRuntime) context.getService(serviceReference); + final ServiceReference serviceReference = context.getServiceReference(GlassFishRuntime.class); + return serviceReference == null ? null : context.getService(serviceReference); } @@ -193,24 +191,8 @@ private Properties prepareStartupContext(final BundleContext context) { } installRoot = context.getProperty(BootstrapKeys.INSTALL_ROOT_PROP_NAME); - - if (installRoot == null) { - installRoot = guessInstallRoot(context); - if (installRoot == null) { - throw new RuntimeException("Property named " + BootstrapKeys.INSTALL_ROOT_PROP_NAME + " is not set."); - } - LOG.log(DEBUG, "Deduced install root as: {0} from location of bundle. " - + "If this is not correct, set correct value in a property called " + BootstrapKeys.INSTALL_ROOT_PROP_NAME, - installRoot); - } - if (!new File(installRoot).exists()) { - throw new RuntimeException("No such directory: [" + installRoot + "]"); - } properties.setProperty(BootstrapKeys.INSTALL_ROOT_PROP_NAME, installRoot); String instanceRoot = context.getProperty(BootstrapKeys.INSTANCE_ROOT_PROP_NAME); - if (instanceRoot == null) { - instanceRoot = new File(installRoot, "domains/domain1/").getAbsolutePath(); - } properties.setProperty(BootstrapKeys.INSTANCE_ROOT_PROP_NAME, instanceRoot); properties.putAll(makeProvisioningOptions(context)); @@ -219,28 +201,6 @@ private Properties prepareStartupContext(final BundleContext context) { return properties; } - /** - * This method tries to guess install root based on location of the bundle. Please note, because location of a - * bundle is free form string, this method can come to very wrong conclusion if user wants to fool us. - * - * @param context - * @return - */ - private String guessInstallRoot(BundleContext context) { - String location = context.getBundle().getLocation(); - try { - final URI uri = URI.create(location); - File f = new File(uri); - // We can't assume it is glassfish/modules/glassfish.jar. - // Bare nucleus is installed as nucleus/modules/glassfish.jar. - if (f.exists() && f.isFile() && f.getParentFile().toPath().endsWith(Path.of("modules"))) { - return f.getParentFile().getParentFile().getAbsolutePath(); - } - } catch (Exception e) { - } - return null; - } - private Properties makeProvisioningOptions(BundleContext context) { Properties provisioningOptions = new Properties(); URI installURI = new File(installRoot).toURI(); diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/Launcher.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/GlassFishOsgiLauncher.java similarity index 91% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/Launcher.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/GlassFishOsgiLauncher.java index f60b11b10e0..77b69874ef3 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/Launcher.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/GlassFishOsgiLauncher.java @@ -14,7 +14,9 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap; +package org.glassfish.main.boot.osgi; + +import com.sun.enterprise.glassfish.bootstrap.launch.Launcher; import java.io.BufferedReader; import java.io.IOException; @@ -30,12 +32,11 @@ import org.glassfish.embeddable.CommandRunner; import org.glassfish.embeddable.Deployer; import org.glassfish.embeddable.GlassFish; -import org.glassfish.embeddable.GlassFishException; import org.glassfish.embeddable.GlassFishProperties; import org.glassfish.embeddable.GlassFishRuntime; // must be public to be accessible for reflection -public class Launcher { +public class GlassFishOsgiLauncher implements Launcher { // logging system may override original output streams. private static final PrintStream STDOUT = System.out; @@ -44,6 +45,17 @@ public class Launcher { private volatile GlassFish gf; private volatile GlassFishRuntime gfr; + public GlassFishOsgiLauncher(ClassLoader classloader) { + // Why this - it is too easy to load this class by wrong classloader. + // That has consequences (CNFE for other required classes) and here it is + // quite easy to check. + if (getClass().getClassLoader() != classloader) { + throw new IllegalStateException( + "The class " + getClass() + " was not loaded by the same classloader as given in constructor!"); + } + } + + @Override public void launch(final Properties properties) throws Exception { addShutdownHook(); gfr = GlassFishRuntime.bootstrap(new BootstrapProperties(properties), getClass().getClassLoader()); @@ -147,7 +159,7 @@ public void run() { } - private void runCommand(final CommandRunner cmdRunner, final String command) throws GlassFishException { + private void runCommand(final CommandRunner cmdRunner, final String command) { String[] tokens = command.split("\\s"); CommandResult result = cmdRunner.run(tokens[0], Arrays.copyOfRange(tokens, 1, tokens.length)); System.out.println(result.getExitStatus()); diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/Jar.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/Jar.java similarity index 98% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/Jar.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/Jar.java index 96870c3d981..dc0d4f5b11a 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/Jar.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/Jar.java @@ -15,7 +15,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; +package org.glassfish.main.boot.osgi; import java.io.File; import java.net.URI; diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/MinimalBundleProvisioner.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/MinimalBundleProvisioner.java similarity index 97% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/MinimalBundleProvisioner.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/MinimalBundleProvisioner.java index 4c241559425..79c6fc9d139 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/MinimalBundleProvisioner.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/MinimalBundleProvisioner.java @@ -15,9 +15,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; - -import com.sun.enterprise.glassfish.bootstrap.log.LogFacade; +package org.glassfish.main.boot.osgi; import java.util.Collections; import java.util.List; @@ -25,6 +23,7 @@ import java.util.logging.Level; import java.util.logging.Logger; +import org.glassfish.main.boot.log.LogFacade; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/MinimalBundleProvisionerCustomizer.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/MinimalBundleProvisionerCustomizer.java similarity index 97% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/MinimalBundleProvisionerCustomizer.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/MinimalBundleProvisionerCustomizer.java index 27fb4542c7b..cb6eb114a76 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/MinimalBundleProvisionerCustomizer.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/MinimalBundleProvisionerCustomizer.java @@ -14,9 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; - -import com.sun.enterprise.glassfish.bootstrap.log.LogFacade; +package org.glassfish.main.boot.osgi; import java.io.File; import java.io.IOException; @@ -30,6 +28,7 @@ import java.util.logging.Level; import java.util.logging.Logger; +import org.glassfish.main.boot.log.LogFacade; import org.osgi.framework.Constants; class MinimalBundleProvisionerCustomizer extends DefaultBundleProvisionerCustomizer { diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiFrameworkLauncher.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/OSGiFrameworkLauncher.java similarity index 85% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiFrameworkLauncher.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/OSGiFrameworkLauncher.java index e62d634f6a5..377654031e8 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiFrameworkLauncher.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/OSGiFrameworkLauncher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -15,7 +15,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; +package org.glassfish.main.boot.osgi; import java.util.HashMap; import java.util.Map; @@ -41,10 +41,17 @@ public class OSGiFrameworkLauncher { private final Properties properties; + private final ClassLoader classloader; private Framework framework; - public OSGiFrameworkLauncher(Properties properties) { + public OSGiFrameworkLauncher(Properties properties, ClassLoader classloader) { this.properties = properties; + this.classloader = classloader; + } + + + public ClassLoader getClassLoader() { + return classloader; } @@ -53,8 +60,7 @@ public Framework launchOSGiFrameWork() throws Exception { throw new IllegalStateException("An OSGi framework is already running..."); } // Locate an OSGi framework and initialize it - ServiceLoader frameworkFactories = ServiceLoader.load(FrameworkFactory.class, - getClass().getClassLoader()); + ServiceLoader frameworkFactories = ServiceLoader.load(FrameworkFactory.class, classloader); Map mm = new HashMap<>(); for (Map.Entry e : properties.entrySet()) { mm.put((String) e.getKey(), (String) e.getValue()); @@ -91,10 +97,10 @@ public T getService(Class type) throws Exception { throw new IllegalStateException("OSGi framework has not yet been launched."); } final BundleContext context = framework.getBundleContext(); - ServiceTracker tracker = new ServiceTracker(context, type.getName(), null); + ServiceTracker tracker = new ServiceTracker<>(context, type.getName(), null); try { tracker.open(true); - return type.cast(tracker.waitForService(0)); + return tracker.waitForService(0); } finally { tracker.close(); } @@ -108,6 +114,6 @@ public T getService(Class type) throws Exception { * @return false if we are already called in the context of OSGi framework, else true. */ private boolean isOSGiEnv() { - return getClass().getClassLoader() instanceof BundleReference; + return classloader instanceof BundleReference; } } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiGlassFishImpl.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/OSGiGlassFishImpl.java similarity index 97% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiGlassFishImpl.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/OSGiGlassFishImpl.java index 7bfad830c15..35075efbfc1 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiGlassFishImpl.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/OSGiGlassFishImpl.java @@ -14,7 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; +package org.glassfish.main.boot.osgi; import org.glassfish.embeddable.GlassFish; import org.glassfish.embeddable.GlassFishException; diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiGlassFishRuntime.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/OSGiGlassFishRuntime.java similarity index 98% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiGlassFishRuntime.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/OSGiGlassFishRuntime.java index 8b992e3adb9..081994f8c43 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiGlassFishRuntime.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/OSGiGlassFishRuntime.java @@ -15,7 +15,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; +package org.glassfish.main.boot.osgi; import org.glassfish.embeddable.GlassFish; import org.glassfish.embeddable.GlassFishException; diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiGlassFishRuntimeBuilder.java b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/OSGiGlassFishRuntimeBuilder.java similarity index 91% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiGlassFishRuntimeBuilder.java rename to nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/OSGiGlassFishRuntimeBuilder.java index 42a313e3ec9..4f109b60a07 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiGlassFishRuntimeBuilder.java +++ b/nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/osgi/OSGiGlassFishRuntimeBuilder.java @@ -15,11 +15,10 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; +package org.glassfish.main.boot.osgi; import com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys; import com.sun.enterprise.glassfish.bootstrap.cfg.OsgiPlatform; -import com.sun.enterprise.glassfish.bootstrap.log.LogFacade; import java.io.File; import java.io.FileInputStream; @@ -35,6 +34,7 @@ import org.glassfish.embeddable.GlassFishException; import org.glassfish.embeddable.GlassFishRuntime; import org.glassfish.embeddable.spi.RuntimeBuilder; +import org.glassfish.main.boot.log.LogFacade; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.framework.launch.Framework; @@ -82,22 +82,15 @@ public final class OSGiGlassFishRuntimeBuilder implements RuntimeBuilder { private static final Logger LOG = LogFacade.BOOTSTRAP_LOGGER; - private Framework framework; - - private Properties oldProvisioningOptions; private Properties newProvisioningOptions; // These two should be a part of an external interface of HK2, but they are not, so we have to duplicate them here. private OSGiFrameworkLauncher fwLauncher; - - /** - * Default constructor needed for meta-inf/service lookup to work - */ - public OSGiGlassFishRuntimeBuilder() {} + private Framework framework; @Override - public GlassFishRuntime build(BootstrapProperties bsProps) throws GlassFishException { + public GlassFishRuntime build(BootstrapProperties bsProps, ClassLoader classloader) throws GlassFishException { try { Properties properties = bsProps.getProperties(); @@ -106,7 +99,7 @@ public GlassFishRuntime build(BootstrapProperties bsProps) throws GlassFishExcep properties.setProperty(BootstrapKeys.BUILDER_NAME_PROPERTY, getClass().getName()); // Step 0: Locate and launch a framework long t0 = System.currentTimeMillis(); - fwLauncher = new OSGiFrameworkLauncher(properties); + fwLauncher = new OSGiFrameworkLauncher(properties, classloader); framework = fwLauncher.launchOSGiFrameWork(); long t1 = System.currentTimeMillis(); LOG.logp(Level.FINE, "OSGiGlassFishRuntimeBuilder", "build", "Launched {0}", framework); @@ -116,7 +109,7 @@ public GlassFishRuntime build(BootstrapProperties bsProps) throws GlassFishExcep storeProvisioningOptions(properties); } else { // this will reconfigure if any provisioning options have changed. - reconfigure(properties); + reconfigure(properties, classloader); } BundleProvisioner bundleProvisioner = createBundleProvisioner(framework.getBundleContext(), properties); LOG.log(Level.CONFIG, LogFacade.CREATE_BUNDLE_PROVISIONER, bundleProvisioner); @@ -228,28 +221,28 @@ private boolean newFramework() { * This method helps in situations where glassfish installation directory has been moved or * certain initial provisoning options have changed, etc. If such thing has happened, it uninstalls * all the bundles that were installed from GlassFish installation location. + * @param classloader */ - private void reconfigure(Properties properties) throws Exception { + private void reconfigure(Properties properties, ClassLoader classloader) throws Exception { if (hasBeenReconfigured(properties)) { LOG.log(Level.INFO, LogFacade.PROVISIONING_OPTIONS_CHANGED); framework.stop(); framework.waitForStop(0); - properties.setProperty(FRAMEWORK_STORAGE_CLEAN, - FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); - fwLauncher = new OSGiFrameworkLauncher(properties); + properties.setProperty(FRAMEWORK_STORAGE_CLEAN, FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); + fwLauncher = new OSGiFrameworkLauncher(properties, classloader); framework = fwLauncher.launchOSGiFrameWork(); - LOG.logp(Level.FINE, "OSGiGlassFishRuntimeBuilder", "reconfigure", "Launched {0}", - new Object[]{framework}); + LOG.logp(Level.FINE, "OSGiGlassFishRuntimeBuilder", "reconfigure", "Launched {0}", framework); storeProvisioningOptions(properties); } } private boolean hasBeenReconfigured(Properties properties) { LOG.logp(Level.FINE, "OSGiGlassFishRuntimeBuilder", "hasBeenReconfigured", "oldProvisioningOptions = {0}", - new Object[]{getOldProvisioningOptions()}); + getOldProvisioningOptions()); + Properties newOptions = getNewProvisioningOptions(properties); LOG.logp(Level.FINE, "OSGiGlassFishRuntimeBuilder", "hasBeenReconfigured", "newProvisioningOptions = {0}", - new Object[]{getNewProvisioningOptions(properties)}); - return !getNewProvisioningOptions(properties).equals(getOldProvisioningOptions()); + newOptions); + return !newOptions.equals(getOldProvisioningOptions()); } /** @@ -298,7 +291,7 @@ private void storeProvisioningOptions(Properties properties) { getNewProvisioningOptions(properties).store(os, ""); os.flush(); LOG.logp(Level.CONFIG, "OSGiGlassFishRuntimeBuilder", "storeProvisioningOptions", - "Stored provisioning options in {0}", new Object[] {f.getAbsolutePath()}); + "Stored provisioning options in {0}", f); } catch (IOException e) { LOG.log(Level.WARNING, "Storing provisioning options failed.", e); } @@ -312,7 +305,7 @@ private Properties getOldProvisioningOptions() { if (f != null && f.exists()) { options.load(new FileInputStream(f)); LOG.logp(Level.FINE, "OSGiGlassFishRuntimeBuilder", "getOldProvisioningOptions", - "Read provisioning options from {0}", new Object[]{f.getAbsolutePath()}); + "Read provisioning options from {0}", f); oldProvisioningOptions = options; } } catch (Exception e) { @@ -324,8 +317,7 @@ private Properties getOldProvisioningOptions() { private static BundleProvisioner createBundleProvisioner(BundleContext bctx, Properties props) { - final boolean ondemandProvisioning = Boolean - .parseBoolean(props.getProperty(ONDEMAND_BUNDLE_PROVISIONING)); + final boolean ondemandProvisioning = Boolean.parseBoolean(props.getProperty(ONDEMAND_BUNDLE_PROVISIONING)); if (ondemandProvisioning) { return new MinimalBundleProvisioner(bctx, props); } diff --git a/nucleus/core/bootstrap-osgi/src/main/resources/META-INF/services/org.glassfish.embeddable.spi.RuntimeBuilder b/nucleus/core/bootstrap-osgi/src/main/resources/META-INF/services/org.glassfish.embeddable.spi.RuntimeBuilder new file mode 100644 index 00000000000..ac251a4959a --- /dev/null +++ b/nucleus/core/bootstrap-osgi/src/main/resources/META-INF/services/org.glassfish.embeddable.spi.RuntimeBuilder @@ -0,0 +1,3 @@ +org.glassfish.main.boot.osgi.OSGiGlassFishRuntimeBuilder +org.glassfish.main.boot.osgi.EmbeddedOSGiGlassFishRuntimeBuilder +org.glassfish.main.boot.embedded.EmbeddedGlassFishRuntimeBuilder diff --git a/nucleus/core/bootstrap-osgi/src/main/resources/META-INF/services/org.glassfish.hk2.api.PopulatorPostProcessor b/nucleus/core/bootstrap-osgi/src/main/resources/META-INF/services/org.glassfish.hk2.api.PopulatorPostProcessor new file mode 100644 index 00000000000..6c473f9b2ba --- /dev/null +++ b/nucleus/core/bootstrap-osgi/src/main/resources/META-INF/services/org.glassfish.hk2.api.PopulatorPostProcessor @@ -0,0 +1 @@ +org.glassfish.main.boot.embedded.EmbeddedInhabitantsParser diff --git a/nucleus/core/bootstrap-osgi/src/main/resources/logging.properties b/nucleus/core/bootstrap-osgi/src/main/resources/logging.properties new file mode 100644 index 00000000000..987ee7d5e47 --- /dev/null +++ b/nucleus/core/bootstrap-osgi/src/main/resources/logging.properties @@ -0,0 +1,8 @@ +handlers=org.glassfish.main.jul.handler.SimpleLogHandler +org.glassfish.main.jul.handler.SimpleLogHandler.level=ALL +org.glassfish.main.jul.handler.SimpleLogHandler.formatter=org.glassfish.main.jul.formatter.UniformLogFormatter + +systemRootLogger.level=FINEST +.level=FINEST + +org.glassfish.main.jul.record.resolveLevelWithIncompleteConfiguration=true diff --git a/nucleus/core/bootstrap/src/test/java/com/sun/enterprise/glassfish/bootstrap/osgi/BundleProvisionerTest.java b/nucleus/core/bootstrap-osgi/src/test/java/org/glassfish/main/boot/osgi/BundleProvisionerTest.java similarity index 83% rename from nucleus/core/bootstrap/src/test/java/com/sun/enterprise/glassfish/bootstrap/osgi/BundleProvisionerTest.java rename to nucleus/core/bootstrap-osgi/src/test/java/org/glassfish/main/boot/osgi/BundleProvisionerTest.java index 3d6a4d81041..a22f85c2815 100644 --- a/nucleus/core/bootstrap/src/test/java/com/sun/enterprise/glassfish/bootstrap/osgi/BundleProvisionerTest.java +++ b/nucleus/core/bootstrap-osgi/src/test/java/org/glassfish/main/boot/osgi/BundleProvisionerTest.java @@ -14,9 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.osgi; - -import com.sun.enterprise.glassfish.bootstrap.log.LogFacade; +package org.glassfish.main.boot.osgi; import java.lang.System.Logger; import java.lang.System.Logger.Level; @@ -44,7 +42,7 @@ class BundleProvisionerTest { @Test void noBundles() throws Exception { - LOG.log(Level.INFO, LogFacade.STARTING_BUNDLEPROVISIONER); + LOG.log(Level.INFO, "Starting BundleProvisioner"); // TODO: add some properties, create more tests Properties props = new Properties(); Path cacheDir = Files.createTempDirectory("FelixCache"); @@ -60,14 +58,14 @@ void noBundles() throws Exception { } assertNotNull(osgiFramework, "No OSGi framwework found!"); long t1 = System.currentTimeMillis(); - LOG.log(Level.INFO, LogFacade.OSGI_LOCATE_TIME, (t1-t0)); + LOG.log(Level.INFO, "Time taken to locate OSGi framework = {0} ms.", t1 - t0); osgiFramework.init(); long t2 = System.currentTimeMillis(); - LOG.log(Level.INFO, LogFacade.OSGI_INIT_TIME, (t2-t1)); + LOG.log(Level.INFO, "Time taken to initialize OSGi framework = {0} ms.", t2 - t1); BundleProvisioner bundleProvisioner = new BundleProvisioner(osgiFramework.getBundleContext(), props); bundleProvisioner.installBundles(); long t3 = System.currentTimeMillis(); - LOG.log(Level.INFO, LogFacade.BUNDLE_INSTALLATION_TIME, (t3-t2)); + LOG.log(Level.INFO, "Time taken to finish installation of bundles = {0} ms.", t3 - t2); assertEquals(0, bundleProvisioner.getNoOfInstalledBundles()); assertEquals(0, bundleProvisioner.getNoOfUpdatedBundles()); assertEquals(0, bundleProvisioner.getNoOfUninstalledBundles()); @@ -77,13 +75,13 @@ void noBundles() throws Exception { assertEquals(Bundle.ACTIVE, osgiFramework.getState()); long t4 = System.currentTimeMillis(); - LOG.log(Level.INFO, LogFacade.BUNDLE_STARTING_TIME, (t4-t3)); - LOG.log(Level.INFO, LogFacade.TOTAL_START_TIME, (t4-t0)); + LOG.log(Level.INFO, "Time taken to finish starting bundles = {0} ms.", t4 - t3); + LOG.log(Level.INFO, "Total time taken to start = {0} ms.", t4 - t0); osgiFramework.stop(); osgiFramework.waitForStop(0); long t5 = System.currentTimeMillis(); - LOG.log(Level.INFO, LogFacade.BUNDLE_STOP_TIME, (t5 - t4)); - LOG.log(Level.INFO, LogFacade.TOTAL_TIME, (t5-t0)); + LOG.log(Level.INFO, "Time taken to stop = {0} ms.", t5 - t4); + LOG.log(Level.INFO, "Total time taken = {0}.", t5 - t0); assertEquals(Bundle.RESOLVED, osgiFramework.getState()); } } diff --git a/nucleus/core/bootstrap/pom.xml b/nucleus/core/bootstrap/pom.xml index 7bb611c1042..ae38deb29cf 100755 --- a/nucleus/core/bootstrap/pom.xml +++ b/nucleus/core/bootstrap/pom.xml @@ -60,12 +60,9 @@ provided - org.glassfish.hk2 - hk2-core - - - org.glassfish.hk2 - hk2-extras + org.glassfish.main.common + glassfish-jdk-extensions + ${project.version} provided @@ -74,25 +71,11 @@ provided - org.glassfish.main.common simple-glassfish-api ${project.version} - - org.glassfish.main.common - common-util - ${project.version} - - - org.glassfish.main.common - glassfish-api - - - org.glassfish.annotations logging-annotation-processor @@ -121,24 +104,11 @@ - true - custom - ${artifact.artifactId}.${artifact.extension} - com.sun.enterprise.glassfish.bootstrap.ASMain + com.sun.enterprise.glassfish.bootstrap.GlassFishMain - - org.apache.felix - maven-bundle-plugin - - - com.sun.enterprise.glassfish.bootstrap.osgi.GlassFishMainActivator - - - - maven-dependency-plugin @@ -149,7 +119,7 @@ pre-integration-test - org.apache.felix.main,simple-glassfish-api,glassfish-jul-extension + org.apache.felix.main,simple-glassfish-api,glassfish-jul-extension,glassfish-jdk-extensions ${project.build.directory}/test-osgi true diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java index 0ea5ef8835b..58dd79f2852 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java @@ -17,29 +17,26 @@ package com.sun.enterprise.glassfish.bootstrap; -import com.sun.enterprise.glassfish.bootstrap.cfg.AsenvConf; +import com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys; import com.sun.enterprise.glassfish.bootstrap.cfg.OsgiPlatform; import com.sun.enterprise.glassfish.bootstrap.cfg.ServerFiles; import com.sun.enterprise.glassfish.bootstrap.cfg.StartupContextCfg; -import com.sun.enterprise.glassfish.bootstrap.cfg.StartupContextUtil; -import com.sun.enterprise.glassfish.bootstrap.cp.ClassLoaderBuilder; -import com.sun.enterprise.glassfish.bootstrap.cp.GlassfishBootstrapClassLoader; +import com.sun.enterprise.glassfish.bootstrap.cfg.StartupContextCfgFactory; +import com.sun.enterprise.glassfish.bootstrap.launch.GlassfishOsgiBootstrapClassLoader; import com.sun.enterprise.glassfish.bootstrap.log.LogFacade; import java.io.File; import java.io.PrintStream; -import java.lang.reflect.Method; import java.nio.file.Path; import java.util.Properties; -import java.util.logging.Level; -import static com.sun.enterprise.glassfish.bootstrap.StartupContextCfgFactory.createStartupContextCfg; +import org.glassfish.main.jdke.props.EnvToPropsConverter; + import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.PLATFORM_PROPERTY_KEY; +import static com.sun.enterprise.glassfish.bootstrap.cp.ClassLoaderBuilder.createOSGiFrameworkLauncherCL; import static com.sun.enterprise.glassfish.bootstrap.log.LogFacade.BOOTSTRAP_LOGGER; -import static com.sun.enterprise.module.bootstrap.ArgumentManager.argsToMap; +import static java.lang.ClassLoader.getSystemClassLoader; import static java.util.logging.Level.SEVERE; -import static org.glassfish.main.jul.cfg.GlassFishLoggingConstants.CLASS_INITIALIZER; -import static org.glassfish.main.jul.cfg.GlassFishLoggingConstants.KEY_TRACING_ENABLED; /** * @author Sanjeeb.Sahoo@Sun.COM @@ -47,76 +44,40 @@ */ public class GlassFishMain { - /** - * true enable 'logging of logging' so you can watch the order of actions in standard outputs. - */ - private static final String ENV_AS_TRACE_LOGGING = "AS_TRACE_LOGGING"; - /** - *

      - *
    • true defers log record resolution to a moment when logging configuration is loaded from - * logging.properties. - *
    • false means that log record's level is compared with default logger settings which is - * usually INFO/WARNING. Records with FINE, FINER, FINEST will be lost. - *
    - */ - private static final String ENV_AS_TRACE_BOOTSTRAP = "AS_TRACE_BOOTSTRAP"; - - private static final String DEFAULT_DOMAINS_DIR_PROPNAME = "AS_DEF_DOMAINS_PATH"; - // logging system may override original output streams. private static final PrintStream STDOUT = System.out; public static void main(final String[] args) { try { - final File installRoot = StartupContextUtil.detectInstallRoot(); - final ClassLoader jdkExtensionCL = ClassLoader.getSystemClassLoader().getParent(); - final GlassfishBootstrapClassLoader gfBootCL = new GlassfishBootstrapClassLoader(installRoot, - jdkExtensionCL); - initializeLogManager(gfBootCL); - checkJdkVersion(); - final Properties argsAsProps = argsToMap(args); final String platformName = whichPlatform(); + // Set the system property to allow downstream code to know the platform on which GlassFish runs. + System.setProperty(PLATFORM_PROPERTY_KEY, platformName); final OsgiPlatform platform = OsgiPlatform.valueOf(platformName); STDOUT.println("Launching GlassFish on " + platform + " platform"); - // Set the system property to allow downstream code to know the platform on which GlassFish runs. - System.setProperty(PLATFORM_PROPERTY_KEY, platformName); + // FIXME: move to serverfiles + final File installRoot = ServerFiles.detectInstallRoot(); + STDOUT.println("Resolved GlassFish install root: " + installRoot); - final Path instanceRoot = findInstanceRoot(installRoot, argsAsProps); + final Properties properties = initProperties(args); + STDOUT.println("Resolved properties: " + properties); + final Path instanceRoot = findInstanceRoot(installRoot, properties); final ServerFiles files = new ServerFiles(installRoot.toPath(), instanceRoot); - final StartupContextCfg startupContextCfg = createStartupContextCfg(platform, files, args); - final ClassLoader launcherCL = ClassLoaderBuilder.createLauncherCL(startupContextCfg, gfBootCL); - - final Class launcherClass = launcherCL.loadClass(Launcher.class.getName()); - final Object launcher = launcherClass.getDeclaredConstructor().newInstance(); - final Method method = launcherClass.getMethod("launch", Properties.class); + final StartupContextCfg cfg = StartupContextCfgFactory.createStartupContextCfg(platform, files, properties); + final ClassLoader osgiCL = createOSGiFrameworkLauncherCL(cfg, getSystemClassLoader()); + try (GlassfishOsgiBootstrapClassLoader launcherCL = new GlassfishOsgiBootstrapClassLoader(installRoot, osgiCL)) { + launcherCL.launchGlassFishServer(cfg.toProperties()); + } - // launcherCL is used only to load the RuntimeBuilder service. - // on all other places is used classloader which loaded the GlassfishRuntime class - // -> it must not be loaded by any parent classloader, it's children would be ignored. - method.invoke(launcher, startupContextCfg.toProperties()); - - // also note that debugging is not possible until the debug port is open. + // Note: debugging is not possible until the debug port is open. } catch (Throwable t) { - t.printStackTrace(); throw new Error("Could not start the server!", t); } } - /** - * The GlassFishLogManager must be set before the first usage of any JUL component, - * it would be replaced by another implementation otherwise. - */ - private static void initializeLogManager(final GlassfishBootstrapClassLoader gfMainCL) throws Exception { - final Class loggingInitializer = gfMainCL.loadClass(CLASS_INITIALIZER); - final Properties loggingCfg = createDefaultLoggingProperties(); - loggingInitializer.getMethod("tryToSetAsDefault", Properties.class).invoke(loggingInitializer, loggingCfg); - } - - private static void checkJdkVersion() { int version = Runtime.version().feature(); if (version < 11) { @@ -125,6 +86,48 @@ private static void checkJdkVersion() { } } + private static Properties initProperties(String[] args) { + Properties map = new Properties(); + if (args.length == 0) { + return map; + } + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < args.length; i++) { + String name = args[i]; + if (name.startsWith("-")) { + // throw it away if there is no value left + if (i + 1 < args.length) { + map.put(name, args[++i]); + } + } else { + // default --> last one wins! + map.put("default", args[i]); + } + } + // no sense doing this if we were started by CLI... + if (!wasStartedByCLI(map)) { + for (int i = 0; i < args.length; i++) { + if (i > 0) { + sb.append(BootstrapKeys.ARG_SEP); + } + sb.append(args[i]); + } + map.setProperty(BootstrapKeys.ORIGINAL_ARGS, sb.toString()); + map.setProperty(BootstrapKeys.ORIGINAL_CP, System.getProperty("java.class.path")); + map.setProperty(BootstrapKeys.ORIGINAL_CN, GlassFishMain.class.getName()); + map.setProperty(BootstrapKeys.ORIGINAL_MP, System.getProperty("jdk.module.path")); + } + return map; + } + + + private static boolean wasStartedByCLI(final Properties properties) { + // if we were started by CLI there will be some special args set... + return properties.getProperty("-asadmin-classpath") != null + && properties.getProperty("-asadmin-classname") != null + && properties.getProperty("-asadmin-args") != null; + } + private static String whichPlatform() { final String platformSysOption = System.getProperty(PLATFORM_PROPERTY_KEY); @@ -143,19 +146,19 @@ private static String whichPlatform() { * IMPORTANT - check for instance BEFORE domain. We will always come up * with a default domain but there is no such thing as a default instance. */ - private static Path findInstanceRoot(File installRoot, Properties args) { - File instanceDir = getInstanceRoot(args); + private static Path findInstanceRoot(File installRoot, Properties argsAsProps) { + File instanceDir = getInstanceRoot(argsAsProps); if (instanceDir == null) { // that means that this is a DAS. - instanceDir = getDomainRoot(args, installRoot); + instanceDir = getDomainRoot(argsAsProps, installRoot); } verifyDomainRoot(instanceDir); return instanceDir.toPath(); } - private static File getInstanceRoot(Properties args) { - String instanceDir = getParam(args, "instancedir"); + private static File getInstanceRoot(Properties argsAsProps) { + String instanceDir = getParam(argsAsProps, "instancedir"); if (isSet(instanceDir)) { return new File(instanceDir); } @@ -168,16 +171,16 @@ private static File getInstanceRoot(Properties args) { * * @param installRoot */ - private static File getDomainRoot(Properties args, File installRoot) { + private static File getDomainRoot(Properties argsAsProps, File installRoot) { // first see if it is specified directly - String domainDir = getParam(args, "domaindir"); + String domainDir = getParam(argsAsProps, "domaindir"); if (isSet(domainDir)) { return new File(domainDir); } // now see if they specified the domain name -- we will look in the default domains-dir File defDomainsRoot = getDefaultDomainsDir(installRoot); - String domainName = getParam(args, "domain"); + String domainName = getParam(argsAsProps, "domain"); if (isSet(domainName)) { return new File(defDomainsRoot, domainName); @@ -189,16 +192,18 @@ private static File getDomainRoot(Properties args, File installRoot) { private static File getDefaultDomainsDir(File installRoot) { - AsenvConf asEnv = AsenvConf.parseAsEnv(installRoot); - String dirname = asEnv.getProperty(DEFAULT_DOMAINS_DIR_PROPNAME); - if (!isSet(dirname)) { - throw new RuntimeException(DEFAULT_DOMAINS_DIR_PROPNAME + " is not set."); + String domainsRootSys = "com.sun.aas.domainsRoot"; + String domainsRootEnv = "AS_DEF_DOMAINS_PATH"; + // Can be a just a link + File domainsDirFile = new EnvToPropsConverter(installRoot.toPath()).convert(domainsRootEnv, domainsRootSys); + if (domainsDirFile == null) { + throw new RuntimeException( + "Neither " + domainsRootEnv + " env property nor " + domainsRootSys + " system property is set."); } - File domainsDir = absolutize(new File(dirname)); + File domainsDir = absolutize(domainsDirFile); if (!domainsDir.isDirectory()) { - throw new RuntimeException(DEFAULT_DOMAINS_DIR_PROPNAME + "[" + dirname + "]" - + " is specifying a file that is NOT a directory."); + throw new RuntimeException(domainsDir + " is specifying a file that is NOT a directory."); } return domainsDir; } @@ -243,34 +248,11 @@ private static void verifyDomainRoot(File domainRoot) { } - private static Properties createDefaultLoggingProperties() { - final Properties cfg = new Properties(); - cfg.setProperty("handlers", - "org.glassfish.main.jul.handler.SimpleLogHandler,org.glassfish.main.jul.handler.GlassFishLogHandler"); - cfg.setProperty("org.glassfish.main.jul.handler.SimpleLogHandler.formatter", - "org.glassfish.main.jul.formatter.UniformLogFormatter"); - // useful to track any startup race conditions etc. Logging is always in game. - if ("true".equals(System.getenv(ENV_AS_TRACE_LOGGING))) { - cfg.setProperty(KEY_TRACING_ENABLED, "true"); - } - cfg.setProperty("systemRootLogger.level", Level.INFO.getName()); - cfg.setProperty(".level", Level.INFO.getName()); - // better startup performance vs. losing log records. - if ("true".equals(System.getenv(ENV_AS_TRACE_BOOTSTRAP))) { - cfg.setProperty("org.glassfish.main.jul.record.resolveLevelWithIncompleteConfiguration", "false"); - } else { - cfg.setProperty("org.glassfish.main.jul.record.resolveLevelWithIncompleteConfiguration", "true"); - } - - return cfg; - } - - - private static String getParam(Properties map, String name) { + private static String getParam(Properties argsAsProps, String name) { // allow both "-" and "--" - String val = map.getProperty("-" + name); + String val = argsAsProps.getProperty("-" + name); if (val == null) { - val = map.getProperty("--" + name); + val = argsAsProps.getProperty("--" + name); } return val; } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/AsenvConf.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/AsenvConf.java deleted file mode 100644 index f93e5c405fc..00000000000 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/AsenvConf.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2024 Contributors to the Eclipse Foundation. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package com.sun.enterprise.glassfish.bootstrap.cfg; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.LineNumberReader; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static com.sun.enterprise.glassfish.bootstrap.log.LogFacade.BOOTSTRAP_LOGGER; -import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.logging.Level.FINE; - -/** - * The asenv.conf file content. - */ -public class AsenvConf { - - private static final Pattern LINE = Pattern.compile("(?i)(set +)?([^=]*)=\"?([^\"]*)\"?"); - - private final Properties properties; - - private AsenvConf(File asenv, File configDir) { - this.properties = new Properties(); - if (!asenv.exists()) { - BOOTSTRAP_LOGGER.log(FINE, "{0} not found, ignoring", asenv.getAbsolutePath()); - return; - } - try (LineNumberReader lnReader = new LineNumberReader(new FileReader(asenv, UTF_8))) { - String line = lnReader.readLine(); - // most of the asenv.conf values have surrounding "", remove them - // and on Windows, they start with SET XXX=YYY - while (line != null) { - Matcher m = LINE.matcher(line); - if (m.matches()) { - File configFile = new File(m.group(3)); - if (!configFile.isAbsolute()) { - configFile = new File(configDir, m.group(3)); - if (configFile.exists()) { - properties.put(m.group(2), configFile.getAbsolutePath()); - } else { - properties.put(m.group(2), m.group(3)); - } - } else { - properties.put(m.group(2), m.group(3)); - } - } - line = lnReader.readLine(); - } - } catch (IOException ioe) { - throw new RuntimeException("Error opening asenv.conf file.", ioe); - } - } - - public String getProperty(String key) { - return properties.getProperty(key); - } - - - public void mirrorToSystemProperties() { - for (String name : properties.stringPropertyNames()) { - System.setProperty(name, properties.getProperty(name)); - } - } - - - public Properties toProperties() { - return (Properties) properties.clone(); - } - - - public static AsenvConf parseAsEnv(File installRoot) { - File configDir = new File(installRoot, "config"); - File asenv = getAsEnvConf(configDir); - return new AsenvConf(asenv, configDir); - } - - - /** - * Figures out the asenv.conf file to load. - */ - private static File getAsEnvConf(File configDir) { - String osName = System.getProperty("os.name"); - if (osName.contains("Windows")) { - return new File(configDir, "asenv.bat"); - } - return new File(configDir, "asenv.conf"); - } -} diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/BootstrapKeys.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/BootstrapKeys.java index 0cba7944e22..1eb2182de0a 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/BootstrapKeys.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/BootstrapKeys.java @@ -25,6 +25,13 @@ public final class BootstrapKeys { public static final String PLATFORM_PROPERTY_KEY = "GlassFish_Platform"; /** bundle containing module startup */ public static final String GF_KERNEL = "org.glassfish.core.kernel"; + + public static final String ASADMIN_MP = "-asadmin-modulepath"; + public static final String ASADMIN_CP = "-asadmin-classpath"; + public static final String ASADMIN_CN = "-asadmin-classname"; + public static final String ASADMIN_ARGS = "-asadmin-args"; + + public static final String ORIGINAL_MP = "-startup-modulepath"; public static final String ORIGINAL_CP = "-startup-classpath"; public static final String ORIGINAL_CN = "-startup-classname"; public static final String ORIGINAL_ARGS = "-startup-args"; @@ -72,6 +79,15 @@ public final class BootstrapKeys { public static final String AUTO_DELETE = "org.glassfish.embeddable.autoDelete"; + // Following constants were copy-pasted from com.sun.enterprise.module.bootstrap.StartupContext + // to avoid dependency on HK2 jar files. + public final static String TIME_ZERO_NAME = "__time_zero"; + public final static String STARTUP_MODULE_NAME = "hk2.startup.context.mainModule"; + public final static String STARTUP_MODULESTARTUP_NAME = "hk2.startup.context.moduleStartup"; + + public static final String DERBY_ROOT_PROP_NAME = "com.sun.aas.derbyRoot"; + + private BootstrapKeys() { } } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/FelixUtil.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/FelixUtil.java similarity index 99% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/FelixUtil.java rename to nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/FelixUtil.java index 24eff6f183b..6ae9eedcd93 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/FelixUtil.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/FelixUtil.java @@ -17,7 +17,7 @@ * under the License. */ -package com.sun.enterprise.glassfish.bootstrap; +package com.sun.enterprise.glassfish.bootstrap.cfg; import java.util.HashMap; import java.util.Map; diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/ServerFiles.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/ServerFiles.java index 23a831688fd..ee80eefdc6b 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/ServerFiles.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/ServerFiles.java @@ -18,6 +18,8 @@ import java.io.File; import java.io.IOException; +import java.net.URI; +import java.net.URL; import java.nio.file.Path; public class ServerFiles { @@ -85,4 +87,23 @@ private static File toExistingFile(String path) throws IllegalArgumentException throw new IllegalArgumentException("Invalid path: " + path, e); } } + + /** + * @return autodetected glassfish directory based on where usually is this class. + */ + public static File detectInstallRoot() { + // glassfish/lib/bootstrap/glassfish.jar + File bootstrapFile = findBootstrapFile(); + // glassfish/ + return bootstrapFile.getParentFile().getParentFile().getParentFile(); + } + + + /** + * @return uses this class to locate its jar file. + */ + private static File findBootstrapFile() { + URL jarUrl = ServerFiles.class.getProtectionDomain().getCodeSource().getLocation(); + return new File(URI.create(jarUrl.toExternalForm().replaceFirst("jar:", "file:"))); + } } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/StartupContextCfgFactory.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/StartupContextCfgFactory.java similarity index 71% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/StartupContextCfgFactory.java rename to nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/StartupContextCfgFactory.java index bab6baa43a9..ebda3fd47db 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/StartupContextCfgFactory.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/StartupContextCfgFactory.java @@ -14,13 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap; - -import com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys; -import com.sun.enterprise.glassfish.bootstrap.cfg.OsgiPlatform; -import com.sun.enterprise.glassfish.bootstrap.cfg.ServerFiles; -import com.sun.enterprise.glassfish.bootstrap.cfg.StartupContextCfg; -import com.sun.enterprise.module.bootstrap.StartupContext; +package com.sun.enterprise.glassfish.bootstrap.cfg; import java.io.File; import java.io.FileInputStream; @@ -36,11 +30,11 @@ import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.INSTALL_ROOT_URI_PROP_NAME; import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.INSTANCE_ROOT_PROP_NAME; import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.INSTANCE_ROOT_URI_PROP_NAME; +import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.STARTUP_MODULESTARTUP_NAME; +import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.STARTUP_MODULE_NAME; +import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.TIME_ZERO_NAME; import static com.sun.enterprise.glassfish.bootstrap.log.LogFacade.BOOTSTRAP_FMWCONF; import static com.sun.enterprise.glassfish.bootstrap.log.LogFacade.BOOTSTRAP_LOGGER; -import static com.sun.enterprise.module.bootstrap.ArgumentManager.argsToMap; -import static com.sun.enterprise.module.bootstrap.StartupContext.STARTUP_MODULE_NAME; -import static com.sun.enterprise.module.bootstrap.StartupContext.TIME_ZERO_NAME; import static java.util.logging.Level.INFO; import static org.osgi.framework.Constants.FRAMEWORK_STORAGE; @@ -54,8 +48,9 @@ private StartupContextCfgFactory() { } - public static StartupContextCfg createStartupContextCfg(OsgiPlatform platform, ServerFiles files, String[] args) { - Properties properties = argsToMap(args); + public static StartupContextCfg createStartupContextCfg(OsgiPlatform platform, ServerFiles files, Properties args) { + Properties properties = new Properties(); + properties.putAll(args); properties.setProperty(TIME_ZERO_NAME, Long.toString(System.currentTimeMillis())); File installRoot = files.getInstallRoot().toFile(); @@ -66,57 +61,17 @@ public static StartupContextCfg createStartupContextCfg(OsgiPlatform platform, S properties.setProperty(INSTANCE_ROOT_PROP_NAME, instanceRoot.getAbsolutePath()); properties.setProperty(INSTANCE_ROOT_URI_PROP_NAME, instanceRoot.toURI().toString()); - if (properties.getProperty(STARTUP_MODULE_NAME) == null) { - properties.setProperty(STARTUP_MODULE_NAME, BootstrapKeys.GF_KERNEL); - } + properties.setProperty(STARTUP_MODULE_NAME, BootstrapKeys.GF_KERNEL); // temporary hack until CLI does that for us. - for (int i = 0; i < args.length; i++) { - if (args[i].equals("-upgrade")) { - if (i + 1 < args.length && !args[i + 1].equals("false")) { - properties.setProperty(StartupContext.STARTUP_MODULESTARTUP_NAME, "upgrade"); - } - } + String upgrade = properties.getProperty("-upgrade"); + if (upgrade != null && !upgrade.equals("false")) { + properties.setProperty(STARTUP_MODULESTARTUP_NAME, "upgrade"); } - - addRawStartupInfo(args, properties); - return mergePlatformConfiguration(platform, files, properties); } - /** - * Need the raw unprocessed args for RestartDomainCommand in case we were NOT started by CLI - * - * @param args raw args to this main() - * @param cfg the properties to save as a system property - */ - private static void addRawStartupInfo(final String[] args, final Properties properties) { - if (wasStartedByCLI(properties)) { - return; - } - // no sense doing this if we were started by CLI... - properties.setProperty(BootstrapKeys.ORIGINAL_CP, System.getProperty("java.class.path")); - properties.setProperty(BootstrapKeys.ORIGINAL_CN, ASMain.class.getName()); - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < args.length; i++) { - if (i > 0) { - sb.append(BootstrapKeys.ARG_SEP); - } - sb.append(args[i]); - } - properties.setProperty(BootstrapKeys.ORIGINAL_ARGS, sb.toString()); - } - - - private static boolean wasStartedByCLI(final Properties properties) { - // if we were started by CLI there will be some special args set... - return properties.getProperty("-asadmin-classpath") != null - && properties.getProperty("-asadmin-classname") != null - && properties.getProperty("-asadmin-args") != null; - } - - private static StartupContextCfg mergePlatformConfiguration(OsgiPlatform platform, ServerFiles files, Properties properties) { final Properties platformCfg; @@ -193,5 +148,4 @@ private static void overrideBySystemProps(Properties osgiCfg, Collection } } } - } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/StartupContextUtil.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/StartupContextUtil.java deleted file mode 100644 index 10d0acd4b6b..00000000000 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cfg/StartupContextUtil.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2024 Contributors to the Eclipse Foundation. - * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package com.sun.enterprise.glassfish.bootstrap.cfg; - -import com.sun.enterprise.module.bootstrap.StartupContext; -import com.sun.enterprise.module.bootstrap.Which; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import java.util.StringTokenizer; - -import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.ARG_SEP; -import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.INSTALL_ROOT_PROP_NAME; -import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.INSTANCE_ROOT_PROP_NAME; -import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.ORIGINAL_ARGS; - -/** - * This encapsulates the behavior of the properties object that's part of - * {@link com.sun.enterprise.module.bootstrap.StartupContext}. - * - * @author Sanjeeb.Sahoo@Sun.COM - */ -public final class StartupContextUtil { - - // this contains utility methods only - private StartupContextUtil() { - } - - - /** - * @return autodetected glassfish directory based on where usually is this class. - */ - public static File detectInstallRoot() { - // glassfish/modules/glassfish.jar - File bootstrapFile = findBootstrapFile(); - // glassfish/ - return bootstrapFile.getParentFile().getParentFile(); - } - - - /** - * @return uses this class to locate its jar file. - */ - private static File findBootstrapFile() { - try { - return Which.jarFile(StartupContextUtil.class); - } catch (IOException e) { - throw new Error("Cannot get bootstrap path from " + StartupContextUtil.class + " class location, aborting", - e); - } - } - - - /** - * @param context - * @return absolute glassfish directory aka install root. - */ - public static File getInstallRoot(StartupContext context) { - return getInstallRoot(context.getArguments()); - } - - - /** - * @param properties - * @return absolute glassfish directory aka install root. - */ - public static File getInstallRoot(Properties properties) { - return absolutize(new File(properties.getProperty(INSTALL_ROOT_PROP_NAME))); - - } - - - /** - * @param context - * @return absolute domain or instance directory aka instance root. - */ - public static File getInstanceRoot(StartupContext context) { - return getInstanceRoot(context.getArguments()); - } - - - /** - * @param properties - * @return absolute domain or instance directory aka instance root. - */ - public static File getInstanceRoot(Properties properties) { - return absolutize(new File(properties.getProperty(INSTANCE_ROOT_PROP_NAME))); - } - - - /** - * @param context - * @return parsed array of arguments saved as {@link #ORIGINAL_ARGS} - */ - public static String[] getOriginalArguments(StartupContext context) { - Properties args = context.getArguments(); - // See how ASMain packages the arguments - String s = args.getProperty(ORIGINAL_ARGS); - if (s == null) { - return new String[0]; - } - StringTokenizer st = new StringTokenizer(s, ARG_SEP, false); - List result = new ArrayList<>(); - while (st.hasMoreTokens()) { - result.add(st.nextToken()); - } - return result.toArray(new String[result.size()]); - } - - - private static File absolutize(File f) { - try { - return f.getCanonicalFile(); - } catch (IOException e) { - return f.getAbsoluteFile(); - } - } -} diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/ClassLoaderBuilder.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/ClassLoaderBuilder.java index a304025fbe8..20c45e55c37 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/ClassLoaderBuilder.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/ClassLoaderBuilder.java @@ -17,12 +17,10 @@ package com.sun.enterprise.glassfish.bootstrap.cp; import com.sun.enterprise.glassfish.bootstrap.cfg.StartupContextCfg; -import com.sun.enterprise.glassfish.bootstrap.osgi.OSGiGlassFishRuntimeBuilder; import java.io.IOException; import java.io.InputStream; import java.net.URL; -import java.nio.file.Path; import java.util.HashSet; import java.util.Set; import java.util.jar.Attributes; @@ -34,67 +32,6 @@ public class ClassLoaderBuilder { - private final ClassPathBuilder cpBuilder; - private final StartupContextCfg cfg; - - private ClassLoaderBuilder(StartupContextCfg cfg) { - this.cfg = cfg; - this.cpBuilder = new ClassPathBuilder(); - } - - private void addPlatformDependencies() throws IOException { - getOsgiPlatformAdapter(cfg).addFrameworkJars(cpBuilder); - } - - private ClassLoader build(ClassLoader delegate) { - return cpBuilder.build(delegate); - } - - private void addLauncherDependencies() throws IOException { - cpBuilder.addJar(cfg.getFileUnderInstallRoot(Path.of("modules", "glassfish.jar"))); - } - - private void addServerBootstrapDependencies() throws IOException { - cpBuilder.addJar(cfg.getFileUnderInstallRoot(Path.of("modules", "simple-glassfish-api.jar"))); - cpBuilder.addJar(cfg.getFileUnderInstallRoot(Path.of("lib", "bootstrap", "glassfish-jul-extension.jar"))); - } - - - /** - * This method is responsible setting up launcher class loader which is then used while calling - * {@link org.glassfish.embeddable.GlassFishRuntime#bootstrap(org.glassfish.embeddable.BootstrapProperties, ClassLoader)}. - * - * This launcher class loader's delegation hierarchy looks like this: - * launcher class loader - * -> OSGi framework launcher class loader - * -> extension class loader - * -> null (bootstrap loader) - * We first create what we call "OSGi framework launcher class loader," that has - * classes that we want to be visible via system bundle. - * Then we create launcher class loader which has {@link OSGiGlassFishRuntimeBuilder} and its dependencies in - * its search path. We set the former one as the parent of this, there by sharing the same copy of - * GlassFish API classes and also making OSGi classes visible to OSGiGlassFishRuntimeBuilder. - * - * We could have merged all the jars into one class loader and called it the launcher class loader, but - * then such a loader, when set as the bundle parent loader for all OSGi classloading delegations, would make - * more things visible than desired. Please note, glassfish.jar has a very long dependency chain. See - * glassfish issue 13287 for the kinds of problems it can create. - * - * @see #createOSGiFrameworkLauncherCL(StartupContextCfg, ClassLoader) - * @param delegate Parent class loader for the launcher class loader. - */ - public static ClassLoader createLauncherCL(StartupContextCfg cfg, ClassLoader delegate) { - try { - ClassLoader osgiFWLauncherCL = createOSGiFrameworkLauncherCL(cfg, delegate); - ClassLoaderBuilder clb = new ClassLoaderBuilder(cfg); - clb.addLauncherDependencies(); - return clb.build(osgiFWLauncherCL); - } catch (IOException e) { - throw new Error(e); - } - } - - /** * This method is responsible for setting up the what we call "OSGi framework launcher class loader." It has * the following classes/jars in its search path: @@ -103,7 +40,7 @@ public static ClassLoader createLauncherCL(StartupContextCfg cfg, ClassLoader de * - jdk tools.jar classpath. * OSGi framework classes are there because we want to launch the framework. * simple-glassfish-api.jar is needed, because we need those classes higher up in the class loader chain otherwise - * {@link com.sun.enterprise.glassfish.bootstrap.Launcher} won't be able to see the same copy that's + * {@link com.sun.enterprise.glassfish.bootstrap.launch.Launcher} won't be able to see the same copy that's * used by rest of the system. * tools.jar is needed because its packages, which are exported via system bundle, are consumed by EJBC. * This class loader is configured to be the delegate for all bundle class loaders by setting @@ -111,49 +48,38 @@ public static ClassLoader createLauncherCL(StartupContextCfg cfg, ClassLoader de * class loaders, one should be very careful about adding stuff here, as it not only affects performance, it also * affects functionality as explained in GlassFish issue 13287. * - * @param delegate Parent class loader for this class loader. + * @param parent Parent class loader for this class loader. + * @throws IOException */ - private static ClassLoader createOSGiFrameworkLauncherCL(StartupContextCfg cfg, ClassLoader delegate) { - try { - ClassLoaderBuilder clb = new ClassLoaderBuilder(cfg); - clb.addPlatformDependencies(); - clb.addServerBootstrapDependencies(); - ClassLoader classLoader = clb.build(delegate); - String osgiPackages = classLoader.resources("META-INF/MANIFEST.MF").map(ClassLoaderBuilder::loadExports) - .collect(Collectors.joining(", ")); - // FIXME: This will not be printed anywhere after failure, because logging could not be configured. -// BOOTSTRAP_LOGGER.log(INFO, "OSGI framework packages:\n{0}", osgiPackages); - System.err.println("OSGI framework packages:\n" + osgiPackages); - String javaPackages = detectJavaPackages(); - System.err.println("JDK provided packages:\n" + javaPackages); - cfg.setProperty(FRAMEWORK_SYSTEMPACKAGES, osgiPackages + ", " + javaPackages); - return classLoader; - } catch (IOException e) { - throw new Error(e); - } + public static ClassLoader createOSGiFrameworkLauncherCL(StartupContextCfg cfg, ClassLoader parent) + throws IOException { + ClassLoader classLoader = getOsgiPlatformAdapter(cfg).addFrameworkJars(new ClassPathBuilder()).build(parent); + String osgiPackages = classLoader.resources("META-INF/MANIFEST.MF").map(ClassLoaderBuilder::loadExports) + .collect(Collectors.joining(", ")); + // FIXME: This will not be printed anywhere after failure, because logging could not be configured. + // BOOTSTRAP_LOGGER.log(INFO, "OSGI framework packages:\n{0}", osgiPackages); + System.err.println("OSGI framework packages:\n" + osgiPackages); + String javaPackages = detectJavaPackages(); + System.err.println("JDK provided packages:\n" + javaPackages); + cfg.setProperty(FRAMEWORK_SYSTEMPACKAGES, osgiPackages + ", " + javaPackages); + return classLoader; } private static OsgiPlatformAdapter getOsgiPlatformAdapter(StartupContextCfg cfg) { - OsgiPlatformAdapter osgiPlatformAdapter; switch (cfg.getPlatform()) { case Felix: - osgiPlatformAdapter = new FelixAdapter(cfg); - break; + return new FelixAdapter(cfg); case Knopflerfish: - osgiPlatformAdapter = new KnopflerfishAdapter(cfg); - break; + return new KnopflerfishAdapter(cfg); case Equinox: - osgiPlatformAdapter = new EquinoxAdapter(cfg); - break; + return new EquinoxAdapter(cfg); case Embedded: case Static: - osgiPlatformAdapter = new EmbeddedAdapter(); - break; + return new EmbeddedAdapter(); default: throw new RuntimeException("Unsupported platform " + cfg.getPlatform()); } - return osgiPlatformAdapter; } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/ClassPathBuilder.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/ClassPathBuilder.java index ea4cd407e99..7178c05b19b 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/ClassPathBuilder.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/ClassPathBuilder.java @@ -26,40 +26,44 @@ import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.List; -import java.util.regex.Pattern; -import org.glassfish.common.util.GlassfishUrlClassLoader; +import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; /** * Builds up a {@link ClassLoader}. * * @author Kohsuke Kawaguchi */ -public final class ClassPathBuilder { +final class ClassPathBuilder { private final List files = new ArrayList<>(); /** * Adds a single jar. * * @param jar + * @return this * @throws IOException if the file doesn't exist. */ - public void addJar(File jar) throws IOException { + ClassPathBuilder addJar(File jar) throws IOException { if (!jar.exists()) { throw new IOException("No such file: " + jar); } files.add(jar); + return this; } + /** * Adds all jars in the given folder. * * @param folder - * A directory that contains a bunch of jar files. + * A directory that contains a bunch of jar files. * @param excludes - * List of jars to be excluded + * List of jars to be excluded + * @return this + * @throws IOException */ - public void addJarFolder(File folder, final String... excludes) throws IOException { + ClassPathBuilder addJarFolder(File folder, final String... excludes) throws IOException { if (!folder.isDirectory()) { throw new IOException("Not a directory " + folder); } @@ -77,45 +81,20 @@ public void addJarFolder(File folder, final String... excludes) throws IOExcepti if (children == null) { // in a very rare race condition, the directory can disappear after we checked. - return; + return this; } for (File child : children) { addJar(child); } + return this; } - /** - * Looks for the child files/directories in the given folder that matches the specified GLOB patterns - * (like "foo-*.jar") and adds them to the classpath. - */ - public void addGlob(File folder, String... masks) throws IOException { - StringBuilder regexp = new StringBuilder(); - for (String mask : masks) { - if (regexp.length() > 0) { - regexp.append('|'); - } - regexp.append("(\\Q"); - regexp.append(mask.replace("?","\\E.\\Q").replace("*","\\E.*\\Q")); - regexp.append("\\E)"); - } - Pattern p = Pattern.compile(regexp.toString()); - File[] children = folder.listFiles(); - if (children == null) { - return; - } - for (File child : children) { - if (p.matcher(child.getName()).matches()) { - addJar(child); - } - } - } - - public ClassLoader build(final ClassLoader parent) { + ClassLoader build(final ClassLoader parent) { PrivilegedAction action = () -> { URL[] urls = files.stream().map(ClassPathBuilder::toURL).toArray(URL[]::new); - return new GlassfishUrlClassLoader(urls, parent); + return new GlassfishUrlClassLoader("OSGi", urls, parent); }; return AccessController.doPrivileged(action); } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/EmbeddedAdapter.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/EmbeddedAdapter.java index 629a6ac9765..360f94bd536 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/EmbeddedAdapter.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/EmbeddedAdapter.java @@ -26,7 +26,8 @@ public class EmbeddedAdapter implements OsgiPlatformAdapter { * Noop. */ @Override - public void addFrameworkJars(ClassPathBuilder cpb) { + public ClassPathBuilder addFrameworkJars(ClassPathBuilder builder) { // nothing to do + return builder; } } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/EquinoxAdapter.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/EquinoxAdapter.java index e395963827b..5a99bad5225 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/EquinoxAdapter.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/EquinoxAdapter.java @@ -33,7 +33,7 @@ public EquinoxAdapter(StartupContextCfg cfg) { } @Override - public void addFrameworkJars(ClassPathBuilder builder) throws IOException { - builder.addJarFolder(equinoxHome); + public ClassPathBuilder addFrameworkJars(ClassPathBuilder builder) throws IOException { + return builder.addJarFolder(equinoxHome); } } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/FelixAdapter.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/FelixAdapter.java index a23bf3466e0..028eef451ec 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/FelixAdapter.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/FelixAdapter.java @@ -33,7 +33,7 @@ public FelixAdapter(StartupContextCfg cfg) { @Override - public void addFrameworkJars(ClassPathBuilder cpb) throws IOException { - cpb.addJar(new File(felixHome, "bin/felix.jar")); + public ClassPathBuilder addFrameworkJars(ClassPathBuilder builder) throws IOException { + return builder.addJar(new File(felixHome, "bin/felix.jar")); } } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/KnopflerfishAdapter.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/KnopflerfishAdapter.java index 9498aa606dd..f0a860d19ce 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/KnopflerfishAdapter.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/KnopflerfishAdapter.java @@ -33,7 +33,7 @@ public KnopflerfishAdapter(StartupContextCfg cfg) { @Override - public void addFrameworkJars(ClassPathBuilder cpb) throws IOException { - cpb.addJar(new File(kfHome, "framework.jar")); + public ClassPathBuilder addFrameworkJars(ClassPathBuilder cpb) throws IOException { + return cpb.addJar(new File(kfHome, "framework.jar")); } } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/OsgiPlatformAdapter.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/OsgiPlatformAdapter.java index 03ae296a16f..cc4fddeefb9 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/OsgiPlatformAdapter.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/OsgiPlatformAdapter.java @@ -22,7 +22,9 @@ interface OsgiPlatformAdapter { /** * Adds the jar files of the OSGi platform to the given {@link ClassPathBuilder} + * + * @return the parameter to allow fluent api call */ - void addFrameworkJars(ClassPathBuilder builder) throws IOException; + ClassPathBuilder addFrameworkJars(ClassPathBuilder builder) throws IOException; } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/GlassfishBootstrapClassLoader.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/launch/GlassfishOsgiBootstrapClassLoader.java similarity index 62% rename from nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/GlassfishBootstrapClassLoader.java rename to nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/launch/GlassfishOsgiBootstrapClassLoader.java index 480594306f9..756eea487bc 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/cp/GlassfishBootstrapClassLoader.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/launch/GlassfishOsgiBootstrapClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -14,18 +14,17 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package com.sun.enterprise.glassfish.bootstrap.cp; +package com.sun.enterprise.glassfish.bootstrap.launch; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; -import java.net.URLClassLoader; -import java.nio.file.Paths; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; +import java.util.Properties; + +import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; /** @@ -34,13 +33,12 @@ *

    * List: *

      - *
    • GlassFish Java Util Logging Extension - *
    • Grizzly NPN API + *
    • GlassFish OSGI Bootstrap *
    * * @author David Matejcek */ -public class GlassfishBootstrapClassLoader extends URLClassLoader { +public class GlassfishOsgiBootstrapClassLoader extends GlassfishUrlClassLoader { static { registerAsParallelCapable(); @@ -53,26 +51,29 @@ public class GlassfishBootstrapClassLoader extends URLClassLoader { * @param parent - parent classloader * @throws IOException - if required libraries (internally listed) could not be read */ - public GlassfishBootstrapClassLoader(final File glassfishDir, final ClassLoader parent) throws IOException { - super(createUrls(glassfishDir), parent); + public GlassfishOsgiBootstrapClassLoader(final File glassfishDir, final ClassLoader parent) throws IOException { + super("GlassFishOsgiBootstrap", createUrls(glassfishDir), parent); } - /** - * Returns class name, hash code and list of managed urls. - */ - @Override - public String toString() { - return getClass().getName() + "@" + Integer.toHexString(hashCode()) + ": " - + Arrays.stream(getURLs()).collect(Collectors.toList()); + public void launchGlassFishServer(final Properties properties) { + try { + @SuppressWarnings("unchecked") + final Class launcherClass = (Class) loadClass( + "org.glassfish.main.boot.osgi.GlassFishOsgiLauncher"); + final Launcher launcher = launcherClass.getDeclaredConstructor(ClassLoader.class).newInstance(this); + launcher.launch(properties); + } catch (Exception e) { + throw new Error("Failed to launch GlassFish Server!", e); + } } private static URL[] createUrls(final File glassfishDir) throws IOException { final List urls = new ArrayList<>(); - final File libDir = glassfishDir.toPath().resolve(Paths.get("lib", "bootstrap")).toFile(); - urls.add(getURL(libDir, "glassfish-jul-extension")); - return urls.toArray(new URL[urls.size()]); + final File moduleDir = new File(glassfishDir, "modules"); + urls.add(getURL(moduleDir, "glassfish-osgi-bootstrap")); + return urls.toArray(URL[]::new); } diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/launch/Launcher.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/launch/Launcher.java new file mode 100644 index 00000000000..f43b5a05d06 --- /dev/null +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/launch/Launcher.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package com.sun.enterprise.glassfish.bootstrap.launch; + +import java.util.Properties; + +public interface Launcher { + + void launch(Properties properties) throws Exception; +} diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/log/LogFacade.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/log/LogFacade.java index 29c8475eecd..356dfbd4fbf 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/log/LogFacade.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/log/LogFacade.java @@ -17,8 +17,6 @@ package com.sun.enterprise.glassfish.bootstrap.log; -import java.util.logging.Level; -import java.util.logging.LogRecord; import java.util.logging.Logger; import org.glassfish.logging.annotation.LogMessageInfo; @@ -30,8 +28,8 @@ public class LogFacade { @LoggerInfo(subsystem = "BOOTSTRAP", description="Main bootstrap logger.") public static final String BOOTSTRAP_LOGGER_NAME = "jakarta.enterprise.bootstrap"; - @LogMessagesResourceBundle() - public static final String RB_NAME = "com.sun.enterprise.glassfish.bootstrap.LogMessages"; + @LogMessagesResourceBundle + public static final String RB_NAME = "com.sun.enterprise.glassfish.bootstrap.log.LogMessages"; public static final Logger BOOTSTRAP_LOGGER = Logger.getLogger(BOOTSTRAP_LOGGER_NAME, RB_NAME); @@ -47,189 +45,4 @@ public class LogFacade { level = "INFO") public static final String BOOTSTRAP_FMWCONF = "NCLS-BOOTSTRAP-00002"; - @LogMessageInfo( - message = "Can not start bundle {0} because it is not contained in the list of installed bundles.", - level = "WARNING") - public static final String CANT_START_BUNDLE = "NCLS-BOOTSTRAP-00005"; - - @LogMessageInfo( - message = "Failed to start {0}.", - level = "WARNING") - public static final String BUNDLE_START_FAILED = "NCLS-BOOTSTRAP-00006"; - - @LogMessageInfo( - message = "Can't uninstall bundle = {0} as it's already uninstalled.", - level = "WARNING") - public static final String BUNDLE_ALREADY_UNINSTALED = "NCLS-BOOTSTRAP-00007"; - - @LogMessageInfo( - message = "Uninstalled bundle {0} installed from {1}.", - level = "INFO") - public static final String UNINSTALLED_BUNDLE = "NCLS-BOOTSTRAP-00008"; - - @LogMessageInfo( - message = "Can't update bundle = {0} as it's already uninstalled.", - level = "WARNING") - public static final String CANT_UPDATE_ALREADY_INSTALLED = "NCLS-BOOTSTRAP-00009"; - - @LogMessageInfo( - message = "Updated bundle {0} from {1}.", - level = "INFO") - public static final String BUNDLE_UPDATED = "NCLS-BOOTSTRAP-00010"; - - @LogMessageInfo( - message = "Failed to uninstall bundle {0}.", - level = "WARNING") - public static final String BUNDLE_UNINSTALL_FAILED = "NCLS-BOOTSTRAP-00011"; - - @LogMessageInfo( - message = "Failed to update {0}.", - level = "WARNING") - public static final String UPDATE_FAILED = "NCLS-BOOTSTRAP-00012"; - - @LogMessageInfo( - message = "Failed to install {0}.", - level = "WARNING") - public static final String INSTALL_FAILED = "NCLS-BOOTSTRAP-00013"; - - @LogMessageInfo( - message = "Can not set the start level for {0} to {2} as it is already set to {1}.", - level = "WARNING") - public static final String CANT_SET_START_LEVEL = "NCLS-BOOTSTRAP-00014"; - - @LogMessageInfo( - message = "Skipping entry {0} because it is not an absolute URI.", - level = "WARNING") - public static final String ENTRY_SKIPPED = "NCLS-BOOTSTRAP-00015"; - - @LogMessageInfo( - message = "Skipping entry {0} due to exception: ", - level = "WARNING") - public static final String ENTRY_SKIPPED_DUE_TO = "NCLS-BOOTSTRAP-00016"; - - @LogMessageInfo( - message = "Starting BundleProvisioner.", - level = "INFO") - public static final String STARTING_BUNDLEPROVISIONER = "NCLS-BOOTSTRAP-00017"; - - @LogMessageInfo( - message = "Time taken to locate OSGi framework = {0} ms.", - level = "INFO") - public static final String OSGI_LOCATE_TIME = "NCLS-BOOTSTRAP-00018"; - - @LogMessageInfo( - message = "Time taken to initialize OSGi framework = {0} ms.", - level = "INFO") - public static final String OSGI_INIT_TIME = "NCLS-BOOTSTRAP-00020"; - - @LogMessageInfo( - message = "Time taken to finish installation of bundles = {0} ms.", - level = "INFO") - public static final String BUNDLE_INSTALLATION_TIME = "NCLS-BOOTSTRAP-00021"; - - @LogMessageInfo( - message = "Time taken to finish starting bundles = {0} ms.", - level = "INFO") - public static final String BUNDLE_STARTING_TIME = "NCLS-BOOTSTRAP-00022"; - - @LogMessageInfo( - message = "Total time taken to start = {0} ms.", - level = "INFO") - public static final String TOTAL_START_TIME = "NCLS-BOOTSTRAP-00023"; - - @LogMessageInfo( - message = "Time taken to stop = {0} ms.", - level = "INFO") - public static final String BUNDLE_STOP_TIME = "NCLS-BOOTSTRAP-00024"; - - @LogMessageInfo( - message = "Total time taken = {0}.", - level = "INFO") - public static final String TOTAL_TIME = "NCLS-BOOTSTRAP-00025"; - - @LogMessageInfo( - message = "Create bundle provisioner {0}.", - level = "CONFIG") - public static final String CREATE_BUNDLE_PROVISIONER = "NCLS-BOOTSTRAP-00026"; - - @LogMessageInfo( - message = "Registered {0} as OSGi service registration: {1}.", - level = "CONFIG") - public static final String SERVICE_REGISTERED = "NCLS-BOOTSTRAP-00027"; - - @LogMessageInfo( - message = "Unregistered {0} from service registry.", - level = "CONFIG") - public static final String SERVICE_UNREGISTERED = "NCLS-BOOTSTRAP-00028"; - - @LogMessageInfo( - message = "Exception while unregistering: ", - level = "WARNING") - public static final String SERVICE_UNREGISTRATION_EXCEPTION = "NCLS-BOOTSTRAP-00029"; - - @LogMessageInfo( - message = "installLocations = {0}.", - level = "INFO") - public static final String SHOW_INSTALL_LOCATIONS = "NCLS-BOOTSTRAP-00030"; - - @LogMessageInfo( - message = "Unable to determine if {0} is a fragment or not due to ", - level = "INFO") - public static final String CANT_TELL_IF_FRAGMENT = "NCLS-BOOTSTRAP-00031"; - - @LogMessageInfo( - message = "Skipping starting of bundles bundles have been provisioned already.", - level = "INFO") - public static final String SKIP_STARTING_ALREADY_PROVISIONED_BUNDLES = "NCLS-BOOTSTRAP-00032"; - - @LogMessageInfo( - message = "{0} : latest file in installation location = {1} and latest installed bundle = {2} ", - level = "INFO") - public static final String LATEST_FILE_IN_INSTALL_LOCATION = "NCLS-BOOTSTRAP-00033"; - - @LogMessageInfo( - message = "Updating system bundle.", - level = "INFO") - public static final String UPDATING_SYSTEM_BUNDLE = "NCLS-BOOTSTRAP-00034"; - - @LogMessageInfo( - message = "Provisioning options have changed, recreating the framework with a clean OSGi storage(aka cache).", - level = "INFO") - public static final String PROVISIONING_OPTIONS_CHANGED = "NCLS-BOOTSTRAP-00035"; - - @LogMessageInfo( - message = "Storage support not available in framework bundle, so can't store bundle ids. This may lead to slower start up time.", - level = "WARNING") - public static final String CANT_STORE_BUNDLEIDS = "NCLS-BOOTSTRAP-00037"; - - @LogMessageInfo( - message = "Storage support not available in framework bundle, so can't store provisioning options. This may lead to slower start up time.", - level = "WARNING") - public static final String CANT_STORE_PROVISIONING_OPTIONS = "NCLS-BOOTSTRAP-00038"; - - @LogMessageInfo( - message = "Got an unexpected exception.", - level = "WARNING") - public static final String CAUGHT_EXCEPTION = "NCLS-BOOTSTRAP-00039"; - - /** - * This helper method is duplicated from org.glassfish.api.logging.LogHelper to avoid adding - * dependency on the glassfish-api bundle. - * Logs a message with the given level, message, parameters and Throwable. - * - * @param logger the Logger object to be used for logging the message. - * @param level the Level of the message to be logged. - * @param messageId the key in the resource bundle of the Logger containing the localized text. - * @param thrown the Throwable associated with the message to be logged. - * @param params the parameters to the localized text. - */ - public static void log(Logger logger, Level level, String messageId, Throwable thrown, Object... params) { - LogRecord rec = new LogRecord(level, messageId); - rec.setLoggerName(logger.getName()); - rec.setResourceBundleName(logger.getResourceBundleName()); - rec.setResourceBundle(logger.getResourceBundle()); - rec.setParameters(params); - rec.setThrown(thrown); - logger.log(rec); - } } diff --git a/nucleus/core/bootstrap/src/main/java/module-info.java b/nucleus/core/bootstrap/src/main/java/module-info.java new file mode 100644 index 00000000000..6afb9821b50 --- /dev/null +++ b/nucleus/core/bootstrap/src/main/java/module-info.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +/** + * @author David Matejcek + */ +module org.glassfish.main.bootstrap { + + requires java.base; + requires java.logging; + + requires org.glassfish.main.api.simple; + requires org.glassfish.main.jdke; + + requires static org.apache.felix.framework; + requires static org.glassfish.annotation.processing.logging; + + exports com.sun.enterprise.glassfish.bootstrap.cfg; + exports com.sun.enterprise.glassfish.bootstrap.launch; +} diff --git a/nucleus/core/bootstrap/src/main/resources/META-INF/services/org.glassfish.embeddable.spi.RuntimeBuilder b/nucleus/core/bootstrap/src/main/resources/META-INF/services/org.glassfish.embeddable.spi.RuntimeBuilder deleted file mode 100644 index 99bcf4338ed..00000000000 --- a/nucleus/core/bootstrap/src/main/resources/META-INF/services/org.glassfish.embeddable.spi.RuntimeBuilder +++ /dev/null @@ -1,3 +0,0 @@ -com.sun.enterprise.glassfish.bootstrap.osgi.OSGiGlassFishRuntimeBuilder -com.sun.enterprise.glassfish.bootstrap.embedded.EmbeddedGlassFishRuntimeBuilder -com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishRuntimeBuilder diff --git a/nucleus/core/bootstrap/src/main/resources/META-INF/services/org.glassfish.hk2.api.PopulatorPostProcessor b/nucleus/core/bootstrap/src/main/resources/META-INF/services/org.glassfish.hk2.api.PopulatorPostProcessor deleted file mode 100644 index f1caf75c33c..00000000000 --- a/nucleus/core/bootstrap/src/main/resources/META-INF/services/org.glassfish.hk2.api.PopulatorPostProcessor +++ /dev/null @@ -1 +0,0 @@ -com.sun.enterprise.glassfish.bootstrap.embedded.EmbeddedInhabitantsParser diff --git a/nucleus/core/bootstrap/src/test/java/com/sun/enterprise/glassfish/bootstrap/cfg/AsenvConfTest.java b/nucleus/core/bootstrap/src/test/java/com/sun/enterprise/glassfish/bootstrap/cfg/AsenvConfTest.java deleted file mode 100644 index 5fd6d4bf0e3..00000000000 --- a/nucleus/core/bootstrap/src/test/java/com/sun/enterprise/glassfish/bootstrap/cfg/AsenvConfTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2024 Contributors to the Eclipse Foundation. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package com.sun.enterprise.glassfish.bootstrap.cfg; - -import java.io.File; -import java.io.PrintWriter; - -import org.junit.jupiter.api.Test; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class AsenvConfTest { - - /** - * This test is used to test the regex pattern of "parseAsEnv" method of "MainHelper.java". - *
    - * It creates two temporary files (asenv.conf and asenv.bat) for testing purpose. - * The "parseAsEnv()" method of "MainHelper.java" reads the "asenv.*" file line by line to - * generate the Properties "asenvProps" whose assertion has been done in this unit test. - */ - @Test - void parseAsEnvTest() throws Exception { - File resources = File.createTempFile("helperTestResources", "config"); - resources.delete(); // delete the temp file - resources.mkdir(); // reuse the name for a directory - resources.deleteOnExit(); - File config = new File(resources, "config"); - config.mkdir(); - config.deleteOnExit(); - File asenv_bat = new File(config, "asenv.bat"); // test resource for windows - File asenv_conf = new File(config, "asenv.conf");// test resource for linux - asenv_bat.deleteOnExit(); - asenv_conf.deleteOnExit(); - - PrintWriter pw1 = new PrintWriter(asenv_bat, UTF_8); - pw1.println("set AbcVar=value1"); - pw1.println("SET Avar=\"value2\""); - pw1.println("Set Bvar=\"value3\""); - pw1.println("set setVar=\"value4\""); - pw1.println("set SetVar=value5"); - pw1.println("set seVar=\"value6\""); - pw1.println("set sVar=\"value7\""); - pw1.close(); - PrintWriter pw2 = new PrintWriter(asenv_conf, UTF_8); - pw2.println("AbcVar=value1"); - pw2.println("Avar=\"value2\""); - pw2.println("Bvar=\"value3\""); - pw2.println("setVar=\"value4\""); - pw2.println("SetVar=value5"); - pw2.println("seVar=\"value6\""); - pw2.println("sVar=\"value7\""); - pw2.close(); - - File installRoot = new File(resources.toString()); - AsenvConf asenvProps = AsenvConf.parseAsEnv(installRoot); - assertEquals("value1", asenvProps.getProperty("AbcVar")); - assertEquals("value2", asenvProps.getProperty("Avar")); - assertEquals("value3", asenvProps.getProperty("Bvar")); - assertEquals("value4", asenvProps.getProperty("setVar")); - assertEquals("value5", asenvProps.getProperty("SetVar")); - assertEquals("value6", asenvProps.getProperty("seVar")); - assertEquals("value7", asenvProps.getProperty("sVar")); - } -} diff --git a/nucleus/core/bootstrap/src/test/java/com/sun/enterprise/glassfish/bootstrap/cp/ClassLoaderBuilderIT.java b/nucleus/core/bootstrap/src/test/java/com/sun/enterprise/glassfish/bootstrap/cp/ClassLoaderBuilderIT.java index 691855555ea..346e06eca90 100644 --- a/nucleus/core/bootstrap/src/test/java/com/sun/enterprise/glassfish/bootstrap/cp/ClassLoaderBuilderIT.java +++ b/nucleus/core/bootstrap/src/test/java/com/sun/enterprise/glassfish/bootstrap/cp/ClassLoaderBuilderIT.java @@ -17,10 +17,10 @@ package com.sun.enterprise.glassfish.bootstrap.cp; -import com.sun.enterprise.glassfish.bootstrap.StartupContextCfgFactory; import com.sun.enterprise.glassfish.bootstrap.cfg.OsgiPlatform; import com.sun.enterprise.glassfish.bootstrap.cfg.ServerFiles; import com.sun.enterprise.glassfish.bootstrap.cfg.StartupContextCfg; +import com.sun.enterprise.glassfish.bootstrap.cfg.StartupContextCfgFactory; import java.io.File; import java.io.IOException; @@ -30,6 +30,7 @@ import org.junit.jupiter.api.Test; +import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.ASADMIN_ARGS; import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.INSTALL_ROOT_PROP_NAME; import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.INSTANCE_ROOT_PROP_NAME; import static org.hamcrest.CoreMatchers.anyOf; @@ -37,6 +38,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.stringContainsInOrder; import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.osgi.framework.Constants.FRAMEWORK_SYSTEMPACKAGES; @@ -48,9 +50,11 @@ class ClassLoaderBuilderIT { @Test void createLauncher_Felix() throws Exception { StartupContextCfg cfg = createStartupContextCfg(); - ClassLoader loader = ClassLoaderBuilder.createLauncherCL(cfg, ClassLoader.getPlatformClassLoader()); + assertEquals("-something", cfg.getProperty(ASADMIN_ARGS), + ASADMIN_ARGS + " wasn't written through to startup context cfg."); + ClassLoader loader = ClassLoaderBuilder.createOSGiFrameworkLauncherCL(cfg, ClassLoader.getPlatformClassLoader()); assertNotNull(loader); - Class osgiClass = loader.loadClass("org.osgi.framework.Bundle"); + Class osgiClass = loader.loadClass("org.osgi.framework.BundleReference"); assertNotNull(osgiClass); Class clazz = loader.loadClass("org.apache.felix.framework.Felix"); assertNotNull(clazz); @@ -81,17 +85,17 @@ private StartupContextCfg createStartupContextCfg() throws IOException { Path jarFilesDir = detectBasedir().toPath().resolve(Path.of("target", "test-osgi")); Files.copy(jarFilesDir.resolve("glassfish-jul-extension.jar"), bootstrapDir.resolve("glassfish-jul-extension.jar")); Files.copy(jarFilesDir.resolve("org.apache.felix.main.jar"), felixBin.resolve("felix.jar")); - Files.copy(jarFilesDir.resolve("simple-glassfish-api.jar"), modulesDir.resolve("simple-glassfish-api.jar")); - Files.copy(jarFilesDir.resolve(Path.of("..", "glassfish.jar")), modulesDir.resolve("glassfish.jar")); + Files.copy(jarFilesDir.resolve("simple-glassfish-api.jar"), bootstrapDir.resolve("simple-glassfish-api.jar")); + Files.copy(jarFilesDir.resolve(Path.of("..", "glassfish.jar")), bootstrapDir.resolve("glassfish.jar")); - Properties properties = new Properties(); + Properties args = new Properties(); Path cfgDir = Files.createDirectories(installRoot.resolve(Path.of("config"))); Files.createFile(cfgDir.resolve("osgi.properties")); - properties.setProperty(INSTALL_ROOT_PROP_NAME, installRoot.toFile().getAbsolutePath()); + args.setProperty(INSTALL_ROOT_PROP_NAME, installRoot.toFile().getAbsolutePath()); + args.setProperty(INSTANCE_ROOT_PROP_NAME, instanceRoot.toFile().getAbsolutePath()); + args.setProperty(ASADMIN_ARGS, "-something"); - properties.setProperty(INSTANCE_ROOT_PROP_NAME, instanceRoot.toFile().getAbsolutePath()); - - return StartupContextCfgFactory.createStartupContextCfg(OsgiPlatform.Felix, files, new String[0]); + return StartupContextCfgFactory.createStartupContextCfg(OsgiPlatform.Felix, files, args); } diff --git a/nucleus/core/kernel/pom.xml b/nucleus/core/kernel/pom.xml index 0087ca35369..b5a701507e6 100755 --- a/nucleus/core/kernel/pom.xml +++ b/nucleus/core/kernel/pom.xml @@ -31,9 +31,10 @@ glassfish-jar Kernel Classes - + false + org.glassfish.main.jul.GlassFishLogManager @@ -105,6 +106,11 @@ common-util ${project.version} + + org.glassfish.main.common + glassfish-jdk-extensions + ${project.version} + org.glassfish.main.common simple-glassfish-api @@ -116,6 +122,11 @@ glassfish ${project.version} + + org.glassfish.main.core + glassfish-osgi-bootstrap + ${project.version} + org.glassfish.main.core logging @@ -188,6 +199,11 @@ org.hamcrest hamcrest + + org.glassfish.main + glassfish-jul-extension + test + org.glassfish.expressly @@ -266,7 +282,6 @@ maven-assembly-plugin - 3.7.1 commonClassLoader tests @@ -317,7 +332,7 @@ - + fastest diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/IdmService.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/IdmService.java index 707d1a9d09f..45686919b3d 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/IdmService.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/IdmService.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation. * Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -16,7 +17,6 @@ package com.sun.enterprise.v3.admin; -import com.sun.enterprise.glassfish.bootstrap.cfg.StartupContextUtil; import com.sun.enterprise.module.bootstrap.StartupContext; import com.sun.enterprise.security.store.IdentityManagement; @@ -27,8 +27,11 @@ import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.Properties; +import java.util.StringTokenizer; import java.util.logging.Logger; import org.glassfish.api.admin.PasswordAliasStore; @@ -38,6 +41,9 @@ import org.glassfish.server.ServerEnvironmentImpl; import org.jvnet.hk2.annotations.Service; +import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.ARG_SEP; +import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.ORIGINAL_ARGS; + /** * An implementation of the @link {IdentityManagement} that manages the password needs of the server. This * implementation consults the Java KeyStore and assumes that the stores are available in server's configuration area. @@ -47,22 +53,22 @@ @Service(name = "jks-based") public class IdmService implements PostConstruct, IdentityManagement { + private static final String FIXED_KEY = "master-password"; // the fixed key for master-password file + private static final String PASSWORDFILE_OPTION_TO_ASMAIN = "-passwordfile"; // note single hyphen, in line with other args to ASMain! + private static final String STDIN_OPTION_TO_ASMAIN = "-read-stdin"; // note single hyphen, in line with other args to ASMain! + + private static final String MP_PROPERTY = "AS_ADMIN_MASTERPASSWORD"; + private final Logger logger = Logger.getAnonymousLogger(); @Inject - private volatile StartupContext sc = null; + private volatile StartupContext sc; @Inject - private volatile ServerEnvironmentImpl env = null; + private volatile ServerEnvironmentImpl env; private char[] masterPassword; - private static final String FIXED_KEY = "master-password"; // the fixed key for master-password file - private static final String PASSWORDFILE_OPTION_TO_ASMAIN = "-passwordfile"; // note single hyphen, in line with other args to ASMain! - private static final String STDIN_OPTION_TO_ASMAIN = "-read-stdin"; // note single hyphen, in line with other args to ASMain! - - private static final String MP_PROPERTY = "AS_ADMIN_MASTERPASSWORD"; - @Override public void postConstruct() { boolean success; @@ -113,7 +119,7 @@ private boolean setFromMasterPasswordFile() { private boolean setFromAsMainArguments() { File pwf = null; try { - String[] args = StartupContextUtil.getOriginalArguments(sc); + String[] args = getOriginalArguments(sc); int index = 0; for (String arg : args) { if (PASSWORDFILE_OPTION_TO_ASMAIN.equals(arg)) { @@ -187,4 +193,21 @@ private boolean setFromStdin() { } } + /** + * @param context + * @return parsed array of arguments saved as {@link #ORIGINAL_ARGS} + */ + private static String[] getOriginalArguments(StartupContext context) { + Properties args = context.getArguments(); + String s = args.getProperty(ORIGINAL_ARGS); + if (s == null) { + return new String[0]; + } + StringTokenizer st = new StringTokenizer(s, ARG_SEP, false); + List result = new ArrayList<>(); + while (st.hasMoreTokens()) { + result.add(st.nextToken()); + } + return result.toArray(new String[result.size()]); + } } diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/LocationsCommand.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/LocationsCommand.java index 22687ce801e..94919c81ffd 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/LocationsCommand.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/LocationsCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -18,7 +18,6 @@ package com.sun.enterprise.v3.admin; import com.sun.enterprise.config.serverbeans.Domain; -import com.sun.enterprise.glassfish.bootstrap.cfg.StartupContextUtil; import jakarta.inject.Inject; import jakarta.inject.Singleton; @@ -34,8 +33,9 @@ import org.glassfish.api.admin.CommandLock; import org.glassfish.api.admin.RestEndpoint; import org.glassfish.api.admin.RestEndpoints; +import org.glassfish.api.admin.ServerEnvironment; +import org.glassfish.internal.api.ServerContext; import org.glassfish.internal.config.UnprocessedConfigListener; -import org.glassfish.server.ServerEnvironmentImpl; import org.jvnet.hk2.annotations.Service; import static org.glassfish.api.ActionReport.ExitCode.SUCCESS; @@ -58,7 +58,10 @@ public class LocationsCommand implements AdminCommand { @Inject - ServerEnvironmentImpl serverEnvironment; + private ServerEnvironment serverEnvironment; + + @Inject + private ServerContext server; @Inject private UnprocessedConfigListener ucl; @@ -70,13 +73,13 @@ public void execute(AdminCommandContext context) { report.setMessage(serverEnvironment.getInstanceRoot().getAbsolutePath().replace('\\', '/')); MessagePart messagePart = report.getTopMessagePart(); - messagePart.addProperty("Base-Root", StartupContextUtil.getInstallRoot(serverEnvironment.getStartupContext()).getAbsolutePath()); + messagePart.addProperty("Base-Root", server.getInstallRoot().getAbsolutePath()); messagePart.addProperty("Domain-Root", serverEnvironment.getInstanceRoot().getAbsolutePath()); messagePart.addProperty("Instance-Root", serverEnvironment.getInstanceRoot().getAbsolutePath()); messagePart.addProperty("Config-Dir", serverEnvironment.getConfigDirPath().getAbsolutePath()); - messagePart.addProperty("Uptime", "" + getUptime()); + messagePart.addProperty("Uptime", Long.toString(getUptime())); messagePart.addProperty("Pid", Long.toString(ProcessHandle.current().pid())); - messagePart.addProperty("Restart-Required", "" + ucl.serverRequiresRestart()); + messagePart.addProperty("Restart-Required", Boolean.toString(ucl.serverRequiresRestart())); } private long getUptime() { diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/RestartServer.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/RestartServer.java index 1dbedaea7d2..90c9f317e17 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/RestartServer.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/RestartServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -17,9 +17,9 @@ package com.sun.enterprise.v3.admin; +import com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys; import com.sun.enterprise.module.ModulesRegistry; import com.sun.enterprise.module.bootstrap.StartupContext; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.universal.process.JavaClassRunner; import com.sun.enterprise.util.StringUtils; @@ -32,6 +32,7 @@ import org.glassfish.api.admin.AdminCommandContext; import org.glassfish.embeddable.GlassFish; import org.glassfish.internal.api.Globals; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * For non-verbose mode: Stop this server, spawn a new JVM that will wait for this JVM to die. The new JVM then starts @@ -51,11 +52,13 @@ public class RestartServer { private Properties props; private Logger logger; private boolean verbose; + private String modulepath; private String classpath; private String classname; private String argsString; private String[] args; private String serverName = ""; + private static final LocalStringsImpl strings = new LocalStringsImpl(RestartServer.class); private static final String magicProperty = "-DAS_RESTART=" + ProcessHandle.current().pid(); private static final String[] normalProps = { magicProperty }; @@ -150,7 +153,7 @@ private void doReincarnation() throws RDCException { sysProps = normalProps; } - JavaClassRunner runner = new JavaClassRunner(classpath, sysProps, classname, args); + JavaClassRunner runner = new JavaClassRunner(modulepath, classpath, sysProps, classname, args); runner.run(); } catch (Exception e) { throw new RDCException(e); @@ -158,18 +161,19 @@ private void doReincarnation() throws RDCException { } private boolean setupReincarnationWithAsadmin() throws RDCException { - classpath = props.getProperty("-asadmin-classpath"); - classname = props.getProperty("-asadmin-classname"); - argsString = props.getProperty("-asadmin-args"); + modulepath = props.getProperty(BootstrapKeys.ASADMIN_MP); + classpath = props.getProperty(BootstrapKeys.ASADMIN_CP); + classname = props.getProperty(BootstrapKeys.ASADMIN_CN); + argsString = props.getProperty(BootstrapKeys.ASADMIN_ARGS); return verify("restart.server.asadminError"); } private boolean setupReincarnationWithOther() throws RDCException { - - classpath = props.getProperty("-startup-classpath"); - classname = props.getProperty("-startup-classname"); - argsString = props.getProperty("-startup-args"); + modulepath = props.getProperty(BootstrapKeys.ORIGINAL_MP); + classpath = props.getProperty(BootstrapKeys.ORIGINAL_CP); + classname = props.getProperty(BootstrapKeys.ORIGINAL_CN); + argsString = props.getProperty(BootstrapKeys.ORIGINAL_ARGS); return verify("restart.server.nonAsadminError"); } @@ -282,7 +286,7 @@ private void stripOperandFromArgs() { } private boolean ok(String s) { - return s != null && s.length() > 0; + return s != null && !s.isEmpty(); } // We use this simply to tell the difference between fatal errors and other diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/Strings.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/Strings.java index aaf287d6c64..d876d2c2876 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/Strings.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/admin/Strings.java @@ -16,7 +16,7 @@ package com.sun.enterprise.v3.admin; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Strings -- Get your Strings here. One file with Strings So one class for messing with them! Nothing in here is public diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/AppLibClassLoaderServiceImpl.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/AppLibClassLoaderServiceImpl.java index a5ca84c32a5..140c7cd5d25 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/AppLibClassLoaderServiceImpl.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/AppLibClassLoaderServiceImpl.java @@ -59,11 +59,11 @@ import org.glassfish.api.event.EventListener; import org.glassfish.api.event.Events; import org.glassfish.api.event.RestrictTo; -import org.glassfish.common.util.GlassfishUrlClassLoader; import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.internal.api.ClassLoaderHierarchy; import org.glassfish.internal.api.DelegatingClassLoader; import org.glassfish.internal.api.DelegatingClassLoader.ClassFinder; +import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; import org.jvnet.hk2.annotations.Service; import static java.lang.System.Logger.Level.DEBUG; @@ -219,12 +219,16 @@ private void addDelegates(Collection libURIs, DelegatingClassLoader holder) */ private static class URLClassFinder extends GlassfishUrlClassLoader implements ClassFinder { + static { + registerAsParallelCapable(); + } + private static final URLStreamHandler urlStreamHandler = new NonCachingURLStreamHandler(); private final Set notFoundResources = ConcurrentHashMap.newKeySet(); URLClassFinder(URL url, ClassLoader parent) { - super(new URL[] {url}, parent); + super("AppLib(" + url.getFile() + ")", new URL[] {url}, parent); } /** @@ -316,7 +320,7 @@ private static class NonCachedURLConnection extends JarURLConnection { private JarURLConnection jarURLConnection; - public NonCachedURLConnection(URL url) throws MalformedURLException { + private NonCachedURLConnection(URL url) throws MalformedURLException { super(url); } @@ -353,6 +357,10 @@ public void setUseCaches(boolean useCaches) { */ private static class DelegatingClassFinder extends DelegatingClassLoader implements ClassFinder { + static { + registerAsParallelCapable(); + } + DelegatingClassFinder(ClassLoader parent) { super(parent); } diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/AppServerStartup.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/AppServerStartup.java index eb9e2149719..7c3be3683d3 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/AppServerStartup.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/AppServerStartup.java @@ -148,7 +148,7 @@ public void setStartupContext(StartupContext context) { * A keep alive thread that keeps the server JVM from going down as long as GlassFish kernel is up. */ private Thread serverThread; - private boolean shutdownSignal = false; + private boolean shutdownSignal; private final static String THREAD_POLICY_PROPERTY = "org.glassfish.startupThreadPolicy"; private final static String MAX_STARTUP_THREAD_PROPERTY = "org.glassfish.maxStartupThreads"; diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/CommonClassLoaderServiceImpl.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/CommonClassLoaderServiceImpl.java index 54b4bd5485e..ccfbb57df8b 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/CommonClassLoaderServiceImpl.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/CommonClassLoaderServiceImpl.java @@ -17,21 +17,19 @@ package com.sun.enterprise.v3.server; -import com.sun.enterprise.module.bootstrap.StartupContext; -import com.sun.enterprise.util.SystemPropertyConstants; - +import jakarta.annotation.PostConstruct; import jakarta.inject.Inject; import java.io.File; import java.io.FilenameFilter; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URL; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Properties; +import java.util.Objects; import java.util.function.Predicate; import java.util.jar.JarFile; import java.util.jar.Manifest; @@ -41,11 +39,15 @@ import java.util.stream.Stream; import org.glassfish.api.admin.ServerEnvironment; -import org.glassfish.common.util.GlassfishUrlClassLoader; -import org.glassfish.hk2.api.PostConstruct; import org.glassfish.kernel.KernelLoggerInfo; +import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; import org.jvnet.hk2.annotations.Service; +import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.DERBY_ROOT_PROP_NAME; +import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.INSTALL_ROOT_PROP_NAME; +import static java.util.logging.Level.CONFIG; +import static java.util.logging.Level.INFO; + /** * This class is responsible for setting up Common Class Loader. As the * name suggests, Common Class Loader is common to all deployed applications. @@ -69,88 +71,72 @@ * @author Sanjeeb.Sahoo@Sun.COM */ @Service -public class CommonClassLoaderServiceImpl implements PostConstruct { - /** - * The common classloader. - */ - private GlassfishUrlClassLoader commonClassLoader; +public class CommonClassLoaderServiceImpl { + + private static final Logger LOG = KernelLoggerInfo.getLogger(); @Inject - APIClassLoaderServiceImpl acls; + private APIClassLoaderServiceImpl acls; @Inject - ServerEnvironment env; + private ServerEnvironment env; - final static Logger logger = KernelLoggerInfo.getLogger(); - private ClassLoader APIClassLoader; + /** + * The common classloader. + */ + private GlassfishUrlClassLoader commonClassLoader; + private ClassLoader apiClassLoader; private String commonClassPath = ""; private static final String SERVER_EXCLUDED_ATTR_NAME = "GlassFish-ServerExcluded"; - @Override - public void postConstruct() { - APIClassLoader = acls.getAPIClassLoader(); - assert (APIClassLoader != null); + @PostConstruct + private void postConstruct() { + apiClassLoader = Objects.requireNonNull(acls.getAPIClassLoader(), "API ClassLoader is null!"); createCommonClassLoader(); } private void createCommonClassLoader() { List cpElements = new ArrayList<>(); File domainDir = env.getInstanceRoot(); - // I am forced to use System.getProperty, as there is no API that makes - // the installRoot available. Sad, but true. Check dev forum on this. - final String installRoot = System.getProperty( - SystemPropertyConstants.INSTALL_ROOT_PROPERTY); - - // See https://glassfish.dev.java.net/issues/show_bug.cgi?id=5872 - // In case of embedded GF, we may not have an installRoot. - if (installRoot!=null) { - File installDir = new File(installRoot); - File installLibPath = new File(installDir, "lib"); - if (installLibPath.isDirectory()) { - Collections.addAll(cpElements, - installLibPath.listFiles(new CompiletimeJarFileFilter())); - } - } else { - logger.logp(Level.WARNING, "CommonClassLoaderServiceImpl", - "createCommonClassLoader", - KernelLoggerInfo.systemPropertyNull, - SystemPropertyConstants.INSTALL_ROOT_PROPERTY); + final String installRoot = System.getProperty(INSTALL_ROOT_PROP_NAME); + if (installRoot == null) { + throw new IllegalStateException("The system property is not set: " + INSTALL_ROOT_PROP_NAME); } - File domainClassesDir = new File(domainDir, "lib/classes/"); // NOI18N + File installDir = new File(installRoot); + File installLibDir = new File(installDir, "lib"); + if (installLibDir.isDirectory()) { + Collections.addAll(cpElements, installLibDir.listFiles(new CompiletimeJarFileFilter())); + } + final File domainLibDir = new File(domainDir, "lib"); + final File domainClassesDir = new File(domainLibDir, "classes"); if (domainClassesDir.exists()) { cpElements.add(domainClassesDir); } - final File domainLib = new File(domainDir, "lib/"); // NOI18N - if (domainLib.isDirectory()) { - Collections.addAll(cpElements, - domainLib.listFiles(new JarFileFilter())); + if (domainLibDir.isDirectory()) { + Collections.addAll(cpElements, domainLibDir.listFiles(new JarFileFilter())); } - // See issue https://glassfish.dev.java.net/issues/show_bug.cgi?id=13612 - // We no longer add derby jars to launcher class loader, we add them to common class loader instead. - cpElements.addAll(findDerbyClient()); + cpElements.addAll(findDerbyJars(installDir)); List urls = new ArrayList<>(); - for (File f : cpElements) { + for (File file : cpElements) { try { - urls.add(f.toURI().toURL()); - } catch (MalformedURLException e) { - logger.log(Level.WARNING, KernelLoggerInfo.invalidClassPathEntry, - new Object[] {f, e}); + urls.add(file.toURI().toURL()); + } catch (IOException e) { + LOG.log(Level.WARNING, KernelLoggerInfo.invalidClassPathEntry, new Object[] {file, e}); } } commonClassPath = urlsToClassPath(urls.stream()); if (urls.isEmpty()) { - logger.logp(Level.FINE, "CommonClassLoaderManager", + LOG.logp(Level.FINE, "CommonClassLoaderManager", "Skipping creation of CommonClassLoader as there are no libraries available", "urls = {0}", urls); } else { - // Skip creation of an unnecessary classloader in the hierarchy, - // when all it would have done was to delegate up. - commonClassLoader = new GlassfishUrlClassLoader(urls.toArray(URL[]::new), APIClassLoader); + commonClassLoader = new GlassfishUrlClassLoader("CommonLibs", urls.toArray(URL[]::new), apiClassLoader); + LOG.log(Level.FINE, "Created common classloader: {0}", commonClassLoader); } } public ClassLoader getCommonClassLoader() { - return commonClassLoader != null ? commonClassLoader : APIClassLoader; + return commonClassLoader == null ? apiClassLoader : commonClassLoader; } /** @@ -160,7 +146,7 @@ public ClassLoader getCommonClassLoader() { */ public void addToClassPath(URL url) { if (commonClassLoader == null) { - commonClassLoader = new GlassfishUrlClassLoader(new URL[] {url}, APIClassLoader); + commonClassLoader = new GlassfishUrlClassLoader("CommonLibs", new URL[] {url}, apiClassLoader); } else { commonClassLoader.addURL(url); } @@ -180,87 +166,57 @@ private static String urlsToClassPath(Stream urls) { .collect(Collectors.joining(File.pathSeparator)); } - private List findDerbyClient() { - final String DERBY_HOME_PROP = "AS_DERBY_INSTALL"; - StartupContext startupContext = env.getStartupContext(); - Properties arguments = null; + private List findDerbyJars(File installDir) { + Path derbyHome = getDerbyDir(installDir); + LOG.log(CONFIG, "Using derby home: {0}", derbyHome); - if (startupContext != null) { - arguments = startupContext.getArguments(); + final File derbyLib = derbyHome.resolve("lib").toFile(); + if (!derbyLib.exists()) { + LOG.log(INFO, KernelLoggerInfo.cantFindDerby, derbyLib); + return Collections.emptyList(); } - String derbyHome = null; - - if (arguments != null) { - derbyHome = arguments.getProperty(DERBY_HOME_PROP, - System.getProperty(DERBY_HOME_PROP)); - } + return Arrays + .asList(derbyLib.listFiles((dir, name) -> name.endsWith(".jar") && !name.startsWith("derbyLocale_"))); + } - File derbyLib = null; - if (derbyHome != null) { - derbyLib = new File(derbyHome, "lib"); + private static Path getDerbyDir(File installDir) { + String derbyHomeProperty = System.getProperty(DERBY_ROOT_PROP_NAME); + if (derbyHomeProperty == null) { + return installDir.toPath().resolve(Path.of("..", "javadb")); } - if (derbyLib == null || !derbyLib.exists()) { - logger.info(KernelLoggerInfo.cantFindDerby); - return Collections.emptyList(); + Path derbyHome = new File(derbyHomeProperty).toPath(); + if (derbyHome.isAbsolute()) { + return derbyHome; } - - return Arrays.asList(derbyLib.listFiles(new FilenameFilter(){ - @Override - public boolean accept(File dir, String name) { - // Include only files having .jar extn and exclude all localisation jars, because they are - // already mentioned in the Class-Path header of the main jars - return (name.endsWith(".jar") && !name.startsWith("derbyLocale_")); - } - })); + return new File(installDir, "config").toPath().resolve(derbyHome); } private static class JarFileFilter implements FilenameFilter { - private final String JAR_EXT = ".jar"; // NOI18N @Override public boolean accept(File dir, String name) { - return name.endsWith(JAR_EXT); + return name.endsWith(".jar"); } } private static class CompiletimeJarFileFilter extends JarFileFilter { - /* - * See https://glassfish.dev.java.net/issues/show_bug.cgi?id=9526 - */ + @Override - public boolean accept(File dir, String name) - { + public boolean accept(File dir, String name) { if (super.accept(dir, name)) { File file = new File(dir, name); - JarFile jar = null; - try - { - jar = new JarFile(file); + try (JarFile jar = new JarFile(file)) { Manifest manifest = jar.getManifest(); if (manifest != null) { - String exclude = manifest.getMainAttributes(). - getValue(SERVER_EXCLUDED_ATTR_NAME); - if (exclude != null && exclude.equalsIgnoreCase("true")) { + String exclude = manifest.getMainAttributes().getValue(SERVER_EXCLUDED_ATTR_NAME); + if ("true".equalsIgnoreCase(exclude)) { return false; } } - } - catch (IOException e) - { - logger.log(Level.WARNING, KernelLoggerInfo.exceptionProcessingJAR, + } catch (IOException e) { + LOG.log(Level.WARNING, KernelLoggerInfo.exceptionProcessingJAR, new Object[] {file.getAbsolutePath(), e}); - } finally { - try - { - if (jar != null) { - jar.close(); - } - } - catch (IOException e) - { - // ignore - } } return true; } diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/ServerContextImpl.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/ServerContextImpl.java index 73c564b60e2..c07e82dc034 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/ServerContextImpl.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/ServerContextImpl.java @@ -17,7 +17,7 @@ package com.sun.enterprise.v3.server; -import com.sun.enterprise.glassfish.bootstrap.cfg.StartupContextUtil; +import com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys; import com.sun.enterprise.module.bootstrap.StartupContext; import jakarta.inject.Inject; @@ -81,7 +81,7 @@ public String[] getCmdLineArgs() { @Override public File getInstallRoot() { - return StartupContextUtil.getInstallRoot(startupContext); + return new File(startupContext.getArguments().getProperty(BootstrapKeys.INSTALL_ROOT_PROP_NAME)); } @Override diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/ServerLifecycleModule.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/ServerLifecycleModule.java index 4e4d38f9885..47ff261299b 100755 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/ServerLifecycleModule.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/ServerLifecycleModule.java @@ -33,10 +33,10 @@ import java.util.logging.Logger; import org.glassfish.api.logging.LogHelper; -import org.glassfish.common.util.GlassfishUrlClassLoader; import org.glassfish.internal.api.ServerContext; import org.glassfish.kernel.KernelLoggerInfo; import org.glassfish.loader.util.ASClassLoaderUtil; +import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; /** * @author Sridatta Viswanath @@ -114,7 +114,7 @@ LifecycleListener loadServerLifecycle() throws ServerLifecycleException { } else { URL[] urls = getURLs(); _logger.log(Level.FINE, "Lifecycle module = {0} has classpath URLs = {1}", new Object[] { getName(), urls }); - this.urlClassLoader = new GlassfishUrlClassLoader(urls, ctx.getLifecycleParentClassLoader()); + this.urlClassLoader = new GlassfishUrlClassLoader(getName(), urls, ctx.getLifecycleParentClassLoader()); classLoader = this.urlClassLoader; } @SuppressWarnings("unchecked") diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SystemTasksImpl.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SystemTasksImpl.java index 3f73c85ecd5..df0d175f35e 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SystemTasksImpl.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SystemTasksImpl.java @@ -25,7 +25,6 @@ import com.sun.enterprise.config.serverbeans.JavaConfig; import com.sun.enterprise.config.serverbeans.Server; import com.sun.enterprise.config.serverbeans.SystemProperty; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.universal.process.ProcessUtils; import com.sun.enterprise.util.SystemPropertyConstants; import com.sun.enterprise.util.io.ServerDirs; @@ -48,6 +47,7 @@ import org.glassfish.hk2.runlevel.RunLevel; import org.glassfish.internal.api.InitRunLevel; import org.glassfish.kernel.KernelLoggerInfo; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import org.jvnet.hk2.annotations.Optional; import org.jvnet.hk2.annotations.Service; diff --git a/nucleus/core/kernel/src/main/java/org/glassfish/kernel/KernelLoggerInfo.java b/nucleus/core/kernel/src/main/java/org/glassfish/kernel/KernelLoggerInfo.java index 27a9e073568..e9d759f39e2 100644 --- a/nucleus/core/kernel/src/main/java/org/glassfish/kernel/KernelLoggerInfo.java +++ b/nucleus/core/kernel/src/main/java/org/glassfish/kernel/KernelLoggerInfo.java @@ -319,7 +319,7 @@ public static Logger getLogger() { public static final String invalidClassPathEntry = LOGMSG_PREFIX + "-00045"; @LogMessageInfo( - message = "Cannot find javadb client jar file, derby jdbc driver will not be available by default.", + message = "Cannot find javadb client jar file, derby jdbc driver will not be available by default: {0}.", level = "INFO") public static final String cantFindDerby = LOGMSG_PREFIX + "-00046"; diff --git a/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/UberMain.java b/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/UberMain.java index 45f0df07b9c..2b23e8985aa 100644 --- a/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/UberMain.java +++ b/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/UberMain.java @@ -18,7 +18,6 @@ import com.sun.enterprise.config.serverbeans.Application; import com.sun.enterprise.config.serverbeans.Domain; -import com.sun.enterprise.glassfish.bootstrap.embedded.EmbeddedGlassFishRuntimeBuilder; import java.io.BufferedReader; import java.io.IOException; @@ -36,6 +35,7 @@ import org.glassfish.embeddable.GlassFishProperties; import org.glassfish.embeddable.GlassFishRuntime; import org.glassfish.grizzly.config.dom.NetworkListener; +import org.glassfish.main.boot.embedded.EmbeddedGlassFishRuntimeBuilder; import org.glassfish.runnablejar.commandline.Arguments; import org.glassfish.runnablejar.commandline.CommandLineParser; @@ -43,7 +43,6 @@ import static java.util.logging.Level.FINE; import static java.util.logging.Level.INFO; import static java.util.logging.Level.SEVERE; -import static org.glassfish.embeddable.CommandResult.ExitStatus.SUCCESS; /** * This is main class for the uber jars viz., glassfish-embedded-all.jar and diff --git a/nucleus/core/kernel/src/test/java/com/sun/enterprise/v3/server/CommonClassLoaderServiceImplTest.java b/nucleus/core/kernel/src/test/java/com/sun/enterprise/v3/server/CommonClassLoaderServiceImplTest.java index d72fd6f10a6..e424c480e49 100644 --- a/nucleus/core/kernel/src/test/java/com/sun/enterprise/v3/server/CommonClassLoaderServiceImplTest.java +++ b/nucleus/core/kernel/src/test/java/com/sun/enterprise/v3/server/CommonClassLoaderServiceImplTest.java @@ -15,52 +15,35 @@ */ package com.sun.enterprise.v3.server; -import com.sun.enterprise.module.bootstrap.StartupContext; +import jakarta.inject.Inject; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; import java.nio.file.Path; -import org.glassfish.api.admin.RuntimeType; import org.glassfish.api.admin.ServerEnvironment; -import org.junit.jupiter.api.BeforeEach; +import org.glassfish.main.core.kernel.test.KernelJUnitExtension; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.stringContainsInOrder; +@ExtendWith(KernelJUnitExtension.class) public class CommonClassLoaderServiceImplTest { - private int loadClassCalls; - private int getResourceCalls; + @Inject + private CommonClassLoaderServiceImpl commonCLService; - CommonClassLoaderServiceImpl commonCLService; - MockServerEnvironment serverEnv; - - @BeforeEach - public void setUp() { - commonCLService = new CommonClassLoaderServiceImpl(); - commonCLService.acls = new APIClassLoaderServiceImpl() { - @Override - public ClassLoader getAPIClassLoader() { - return new URLClassLoader(new URL[0], null); - } - - }; - serverEnv = new MockServerEnvironment(); - commonCLService.env = serverEnv; - } + @Inject + private ServerEnvironment env; @Test - public void testAddingUrlWithNoInitialUrls() throws MalformedURLException, ClassNotFoundException { - commonCLService.postConstruct(); - + public void testAddingUrlWithNoInitialUrls() throws Exception { final String classesPath = "target/test-additional-classes/"; commonCLService.addToClassPath(new File(classesPath).toURI().toURL()); -// we need to retrieve the classloader after adding URLs, otherwise we + // we need to retrieve the classloader after adding URLs, otherwise we // would get its parent because of an optimization in the service final ClassLoader commonClassLoader = commonCLService.getCommonClassLoader(); commonClassLoader.loadClass(CommonClassLoaderServiceImplTestAdditionalClass.class.getName()); @@ -68,10 +51,7 @@ public void testAddingUrlWithNoInitialUrls() throws MalformedURLException, Class } @Test - public void testAddingUrlWithInitialUrl() throws MalformedURLException, ClassNotFoundException { - final String domainDir = "target/test-domain"; - serverEnv.setInstanceRoot(new File(domainDir)); - commonCLService.postConstruct(); + public void testAddingUrlWithInitialUrl() throws Exception { // the classloader should already be the one we want, initialized with classes in domain/lib/classes final ClassLoader commonClassLoader = commonCLService.getCommonClassLoader(); @@ -80,112 +60,9 @@ public void testAddingUrlWithInitialUrl() throws MalformedURLException, ClassNot commonClassLoader.loadClass(CommonClassLoaderServiceImplTestAdditionalClass.class.getName()); commonClassLoader.loadClass(CommonClassLoaderServiceImplTestDomainClass.class.getName()); - assertThat(commonCLService.getCommonClassPath(), containsString(new File(classesPath).getAbsolutePath())); - assertThat(commonCLService.getCommonClassPath(), containsString(Path.of(domainDir,"lib","classes").toAbsolutePath().toString())); - } - - static class MockServerEnvironment implements ServerEnvironment { - - File instanceRoot; - - @Override - public File getInstanceRoot() { - return instanceRoot; - } - - public void setInstanceRoot(File instanceRoot) { - this.instanceRoot = instanceRoot; - } - - @Override - public StartupContext getStartupContext() { - return null; - } - - @Override - public File getConfigDirPath() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public File getLibPath() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public File getApplicationRepositoryPath() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public File getApplicationStubPath() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public File getApplicationCompileJspPath() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public File getApplicationGeneratedXMLPath() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public File getApplicationEJBStubPath() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public File getApplicationPolicyFilePath() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public File getApplicationAltDDPath() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public File getMasterPasswordFile() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public File getJKS() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public File getTrustStore() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public Status getStatus() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public RuntimeType getRuntimeType() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public String getInstanceName() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean isInstance() { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean isDas() { - throw new UnsupportedOperationException("Not supported yet."); - } - + assertThat(commonCLService.getCommonClassPath(), + stringContainsInOrder( + env.getInstanceRoot().toPath().resolve(Path.of("lib", "classes")).toString(), + new File(classesPath).getAbsolutePath())); } } diff --git a/nucleus/core/kernel/src/test/java/com/sun/enterprise/v3/services/impl/GrizzlyProxyTest.java b/nucleus/core/kernel/src/test/java/com/sun/enterprise/v3/services/impl/GrizzlyProxyTest.java index 8c19131cb23..6013939b50a 100644 --- a/nucleus/core/kernel/src/test/java/com/sun/enterprise/v3/services/impl/GrizzlyProxyTest.java +++ b/nucleus/core/kernel/src/test/java/com/sun/enterprise/v3/services/impl/GrizzlyProxyTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Contributors to the Eclipse Foundation + * Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -149,7 +149,7 @@ public void testInitAddressWithInvalidVal() throws IOException { private static void validateLogContents(String[] messages) throws IOException { try (BufferedReader reader = new BufferedReader(new FileReader(TEST_LOG))) { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { buf.append(line); diff --git a/nucleus/core/kernel/src/test/java/org/glassfish/main/core/kernel/test/KernelJUnitExtension.java b/nucleus/core/kernel/src/test/java/org/glassfish/main/core/kernel/test/KernelJUnitExtension.java index b99dd6420f5..8e78a2b4605 100644 --- a/nucleus/core/kernel/src/test/java/org/glassfish/main/core/kernel/test/KernelJUnitExtension.java +++ b/nucleus/core/kernel/src/test/java/org/glassfish/main/core/kernel/test/KernelJUnitExtension.java @@ -1,6 +1,5 @@ /* - * Copyright (c) 2021 Eclipse Foundation and/or its affiliates. All rights reserved. - * Copyright (c) 2021 Contributors to the Eclipse Foundation + * Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -18,11 +17,15 @@ package org.glassfish.main.core.kernel.test; import com.sun.enterprise.admin.util.InstanceStateService; +import com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys; +import com.sun.enterprise.util.io.FileUtils; import com.sun.enterprise.v3.admin.ObjectInputStreamWithServiceLocator; +import java.nio.file.Path; import java.util.Set; import org.glassfish.tests.utils.junit.HK2JUnit5Extension; +import org.glassfish.tests.utils.junit.JUnitSystem; import org.junit.jupiter.api.extension.ExtensionContext; @@ -33,6 +36,14 @@ */ public class KernelJUnitExtension extends HK2JUnit5Extension { + static { + Path installRoot = JUnitSystem.detectBasedir(); + Path instanceRoot = installRoot.resolve(Path.of("target", "test-domain")); + FileUtils.mkdirsMaybe(instanceRoot.toFile()); + System.setProperty(BootstrapKeys.INSTALL_ROOT_PROP_NAME, installRoot.toString()); + System.setProperty(BootstrapKeys.INSTANCE_ROOT_PROP_NAME, instanceRoot.toString()); + } + @Override protected String getDomainXml(final Class testClass) { return "DomainTest.xml"; diff --git a/nucleus/core/kernel/src/test/java/org/glassfish/runnablejar/UberMainTest.java b/nucleus/core/kernel/src/test/java/org/glassfish/runnablejar/UberMainTest.java index 4fa56c05527..c740a8eb212 100644 --- a/nucleus/core/kernel/src/test/java/org/glassfish/runnablejar/UberMainTest.java +++ b/nucleus/core/kernel/src/test/java/org/glassfish/runnablejar/UberMainTest.java @@ -42,21 +42,21 @@ */ public class UberMainTest { - @Test - public void getInfoAfterStartup() throws GlassFishException { + @Test + public void getInfoAfterStartup() throws GlassFishException { + String info = new InfoPrinter().getInfoAfterStartup(List.of(app("/app1"), app("application")), + List.of(listener(8080, false), listener(8181, true))); + System.out.println(info); + } - String info = new InfoPrinter().getInfoAfterStartup(List.of(app("/app1"), app("application")), - List.of(listener(8080, false), listener(8181, true))); - System.out.println(info); - } - @Test - public void getInfoAfterStartup_noApps() throws GlassFishException { + @Test + public void getInfoAfterStartup_noApps() throws GlassFishException { + String info = new InfoPrinter().getInfoAfterStartup(List.of(), + List.of(listener(8080, false), listener(8181, true))); + System.out.println(info); + } - String info = new InfoPrinter().getInfoAfterStartup(List.of(), - List.of(listener(8080, false), listener(8181, true))); - System.out.println(info); - } private MockListener listener(int port, boolean secure) { return new MockListener(port, secure); @@ -68,7 +68,7 @@ private MockApplication app(String app) { private class MockApplication implements Application { - private String name; + private final String name; public MockApplication(String name) { this.name = name; @@ -91,157 +91,157 @@ public String getEnabled() { @Override public void setContextRoot(String contextRoot) throws PropertyVetoException { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getLocation() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setLocation(String location) throws PropertyVetoException { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getObjectType() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setObjectType(String objectType) throws PropertyVetoException { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setEnabled(String enabled) throws PropertyVetoException { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getLibraries() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setLibraries(String libraries) throws PropertyVetoException { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getAvailabilityEnabled() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setAvailabilityEnabled(String availabilityEnabled) throws PropertyVetoException { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getAsyncReplication() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setAsyncReplication(String asyncReplication) throws PropertyVetoException { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getDirectoryDeployed() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setDirectoryDeployed(String directoryDeployed) throws PropertyVetoException { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getDescription() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setDescription(String description) throws PropertyVetoException { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getDeploymentOrder() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setDeploymentOrder(String deploymentOrder) throws PropertyVetoException { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public List getModule() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public List getEngine() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public Resources getResources() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setResources(Resources resources) throws PropertyVetoException { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public AppTenants getAppTenants() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setAppTenants(AppTenants appTenants) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public List getExtensions() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public List getProperty() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setName(String name) throws PropertyVetoException { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public Property addProperty(Property property) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public Property lookupProperty(String name) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public Property removeProperty(String name) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public Property removeProperty(Property property) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } } @@ -275,209 +275,209 @@ public String getSecurityEnabled() { @Override public Http getHttp() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setHttp(Http http) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getName() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setName(String name) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public PortUnification getPortUnification() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setPortUnification(PortUnification portUnification) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public HttpRedirect getHttpRedirect() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setHttpRedirect(HttpRedirect httpRedirect) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public ProtocolChainInstanceHandler getProtocolChainInstanceHandler() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setProtocolChainInstanceHandler(ProtocolChainInstanceHandler protocolChainHandler) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setSecurityEnabled(String securityEnabled) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public Ssl getSsl() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setSsl(Ssl ssl) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public List getProperty() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public Property addProperty(Property property) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public Property lookupProperty(String name) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public Property removeProperty(String name) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public Property removeProperty(Property property) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } }; } @Override public String getAddress() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setAddress(String address) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setEnabled(String enabled) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getJkConfigurationFile() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setJkConfigurationFile(String configFile) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getJkEnabled() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setJkEnabled(String jkEnabled) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getName() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setName(String name) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getType() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setType(String type) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setPort(String port) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getProtocol() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setProtocol(String protocol) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getThreadPool() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setThreadPool(String threadPool) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public String getTransport() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public void setTransport(String transport) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public List getProperty() { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public Property addProperty(Property property) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public Property lookupProperty(String name) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public Property removeProperty(String name) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } @Override public Property removeProperty(Property property) { - throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + throw new UnsupportedOperationException("Not supported yet."); } } } diff --git a/nucleus/core/kernel/src/test/java/org/glassfish/tests/kernel/deployment/EventsTest.java b/nucleus/core/kernel/src/test/java/org/glassfish/tests/kernel/deployment/EventsTest.java index e7354030591..95343fd3769 100644 --- a/nucleus/core/kernel/src/test/java/org/glassfish/tests/kernel/deployment/EventsTest.java +++ b/nucleus/core/kernel/src/test/java/org/glassfish/tests/kernel/deployment/EventsTest.java @@ -84,11 +84,12 @@ public void setup() throws Exception { events.register(listener); } + @AfterEach public void deleteApplications() { - if (application != null) { - application.delete(); - } + if (application != null) { + application.delete(); + } } diff --git a/nucleus/core/kernel/src/test/resources/DomainTest.xml b/nucleus/core/kernel/src/test/resources/DomainTest.xml index 3c1ab6f7bad..d6d938780a3 100644 --- a/nucleus/core/kernel/src/test/resources/DomainTest.xml +++ b/nucleus/core/kernel/src/test/resources/DomainTest.xml @@ -113,6 +113,8 @@ + -Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager + -Djava.util.logging.config.block=true -Djava.awt.headless=true -Djdk.corba.allowOutputStreamSubclass=true -Djdk.tls.rejectClientInitiatedRenegotiation=true diff --git a/nucleus/core/logging/pom.xml b/nucleus/core/logging/pom.xml index b48049e8637..17d3ff5c065 100755 --- a/nucleus/core/logging/pom.xml +++ b/nucleus/core/logging/pom.xml @@ -43,6 +43,11 @@ glassfish-jul-extension compile + + org.glassfish.main.common + glassfish-jdk-extensions + ${project.version} + org.glassfish.main.common glassfish-api diff --git a/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogManagerService.java b/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogManagerService.java index 1f2fb7c5937..07fc8e0e4f1 100644 --- a/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogManagerService.java +++ b/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogManagerService.java @@ -64,7 +64,6 @@ import org.glassfish.main.jul.handler.GlassFishLogHandler; import org.glassfish.main.jul.handler.GlassFishLogHandlerConfiguration; import org.glassfish.main.jul.handler.GlassFishLogHandlerProperty; -import org.glassfish.main.jul.tracing.GlassFishLoggingTracer; import org.glassfish.server.ServerEnvironmentImpl; import org.jvnet.hk2.annotations.Service; @@ -323,7 +322,6 @@ private Map getResolvedLoggingProperties() throws IOException { private void reconfigure(final File configFile) { - GlassFishLoggingTracer.trace(getClass(), () -> "reconfigure(" + configFile + ")"); LOG.info(() -> "Using property file: " + configFile); if (!GlassFishLogManager.isGlassFishLogManager()) { try (FileInputStream configuration = new FileInputStream(configFile)) { @@ -337,7 +335,6 @@ private void reconfigure(final File configFile) { try { final GlassFishLogManagerConfiguration cfg = getRuntimeConfiguration(); if (cfg == null) { - GlassFishLoggingTracer.error(getClass(), "Logging configuration is not available!"); return; } final ReconfigurationAction reconfig = new ReconfigurationAction(cfg); diff --git a/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LoggerInfoMetadataService.java b/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LoggerInfoMetadataService.java index 795e9d8187f..0d931e53057 100644 --- a/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LoggerInfoMetadataService.java +++ b/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LoggerInfoMetadataService.java @@ -39,7 +39,7 @@ import java.util.ResourceBundle; import java.util.Set; -import org.glassfish.common.util.GlassfishUrlClassLoader; +import org.glassfish.main.jdke.cl.GlassfishUrlClassLoader; import org.jvnet.hk2.annotations.Service; @Service @@ -182,7 +182,8 @@ private void initialize() { urls[i] = uris[i].toURL(); } ResourceBundle rb; - try (GlassfishUrlClassLoader loader = new GlassfishUrlClassLoader(urls, new NullClassLoader())) { + try (GlassfishUrlClassLoader loader = new GlassfishUrlClassLoader("LoggerInfoMetadata", urls, + new NullClassLoader())) { rb = ResourceBundle.getBundle(RBNAME, locale, loader); } for (String key : rb.keySet()) { diff --git a/nucleus/core/pom.xml b/nucleus/core/pom.xml index 8053254c20b..16c00abd7a5 100644 --- a/nucleus/core/pom.xml +++ b/nucleus/core/pom.xml @@ -34,6 +34,7 @@ bootstrap + bootstrap-osgi kernel api-exporter extra-jre-packages diff --git a/nucleus/deployment/admin/src/main/java/org/glassfish/deployment/admin/InstanceValidateRemoteDirDeploymentCommand.java b/nucleus/deployment/admin/src/main/java/org/glassfish/deployment/admin/InstanceValidateRemoteDirDeploymentCommand.java index 89fd152a004..cd27b8b3774 100644 --- a/nucleus/deployment/admin/src/main/java/org/glassfish/deployment/admin/InstanceValidateRemoteDirDeploymentCommand.java +++ b/nucleus/deployment/admin/src/main/java/org/glassfish/deployment/admin/InstanceValidateRemoteDirDeploymentCommand.java @@ -17,7 +17,6 @@ package org.glassfish.deployment.admin; import com.sun.enterprise.config.serverbeans.Domain; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import java.io.File; import java.util.logging.Level; @@ -33,6 +32,7 @@ import org.glassfish.api.admin.RuntimeType; import org.glassfish.deployment.common.DeploymentUtils; import org.glassfish.hk2.api.PerLookup; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import org.jvnet.hk2.annotations.Service; /** diff --git a/nucleus/distributions/atomic/src/main/assembly/atomic.xml b/nucleus/distributions/atomic/src/main/assembly/atomic.xml index 54e0c73b433..572461982c9 100644 --- a/nucleus/distributions/atomic/src/main/assembly/atomic.xml +++ b/nucleus/distributions/atomic/src/main/assembly/atomic.xml @@ -74,11 +74,23 @@ ${temp.dir} + glassfish.jar + glassfish-jdk-extensions.jar glassfish-jul-extension.jar + simple-glassfish-api.jar ${install.dir.name}/lib/bootstrap + + + ${temp.dir} + + admin-cli.jar + + ${install.dir.name} + + ${temp.dir} @@ -127,6 +139,7 @@ *.jar + admin-cli.jar server-mgmt.jar osgi-cli-interactive.jar flashlight-agent.jar @@ -140,7 +153,10 @@ org.osgi.util.promise.jar felix.jar nucleus-domain.jar + glassfish.jar + glassfish-jdk-extensions.jar glassfish-jul-extension.jar + simple-glassfish-api.jar ${install.dir.name}/modules diff --git a/nucleus/distributions/nucleus-common/src/main/resources/bin/nadmin b/nucleus/distributions/nucleus-common/src/main/resources/bin/nadmin index 6df8760eeed..1a184116519 100644 --- a/nucleus/distributions/nucleus-common/src/main/resources/bin/nadmin +++ b/nucleus/distributions/nucleus-common/src/main/resources/bin/nadmin @@ -1,5 +1,6 @@ #!/bin/sh # +# Copyright (c) 2024 Contributors to the Eclipse Foundation # Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. # # This program and the accompanying materials are made available under the @@ -15,15 +16,15 @@ # SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 # -AS_INSTALL=`dirname "$0"`/.. +export AS_INSTALL="$(dirname $(realpath -s $0))/.." case "`uname`" in CYGWIN*) AS_INSTALL=`cygpath --windows $AS_INSTALL` esac -AS_INSTALL_LIB="$AS_INSTALL/modules" . "${AS_INSTALL}/config/asenv.conf" + JAVA=java -#Depends upon Java from ../config/asenv.conf if [ ${AS_JAVA} ]; then JAVA=${AS_JAVA}/bin/java fi -exec "$JAVA" -jar "$AS_INSTALL_LIB/admin-cli.jar" "$@" + +exec "$JAVA" ${ASADMIN_JVM_OPTIONS} --module-path "${ASADMIN_MODULEPATH}" --add-modules ALL-MODULE-PATH -cp "$ASADMIN_CLASSPATH" com.sun.enterprise.admin.cli.AdminMain "$@" diff --git a/nucleus/distributions/nucleus-common/src/main/resources/bin/nadmin.bat b/nucleus/distributions/nucleus-common/src/main/resources/bin/nadmin.bat index f0a95a21c8c..c8300b1325d 100644 --- a/nucleus/distributions/nucleus-common/src/main/resources/bin/nadmin.bat +++ b/nucleus/distributions/nucleus-common/src/main/resources/bin/nadmin.bat @@ -1,34 +1,36 @@ -@echo off -REM -REM Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. -REM -REM This program and the accompanying materials are made available under the -REM terms of the Eclipse Public License v. 2.0, which is available at -REM http://www.eclipse.org/legal/epl-2.0. -REM -REM This Source Code may also be made available under the following Secondary -REM Licenses when the conditions for such availability set forth in the -REM Eclipse Public License v. 2.0 are satisfied: GNU General Public License, -REM version 2 with the GNU Classpath Exception, which is available at -REM https://www.gnu.org/software/classpath/license.html. -REM -REM SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 -REM - - -REM Always use JDK 1.6 or higher -REM Depends on Java from ..\config\asenv.bat -VERIFY OTHER 2>nul -setlocal ENABLEEXTENSIONS -if ERRORLEVEL 0 goto ok -echo "Unable to enable extensions" -exit /B 1 -:ok -call "%~dp0..\config\asenv.bat" -if "%AS_JAVA%x" == "x" goto UsePath -set JAVA="%AS_JAVA%\bin\java" -goto run -:UsePath -set JAVA=java -:run -%JAVA% -jar "%~dp0..\modules\admin-cli.jar" %* +@echo off +REM +REM Copyright (c) 2024 Contributors to the Eclipse Foundation +REM Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. +REM +REM This program and the accompanying materials are made available under the +REM terms of the Eclipse Public License v. 2.0, which is available at +REM http://www.eclipse.org/legal/epl-2.0. +REM +REM This Source Code may also be made available under the following Secondary +REM Licenses when the conditions for such availability set forth in the +REM Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +REM version 2 with the GNU Classpath Exception, which is available at +REM https://www.gnu.org/software/classpath/license.html. +REM +REM SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +REM + +VERIFY OTHER 2>nul +setlocal ENABLEEXTENSIONS +if ERRORLEVEL 0 goto ok +echo "Unable to enable extensions" +exit /B 1 + +:ok +set AS_INSTALL=%~dp0.. +call "%AS_INSTALL%\config\asenv.bat" +if "%AS_JAVA%x" == "x" goto UsePath +set JAVA=%AS_JAVA%\bin\java +goto run + +:UsePath +set JAVA=java + +:run +%JAVA% %ASADMIN_JVM_OPTIONS% --module-path "%ASADMIN_MODULEPATH%" --add-modules ALL-MODULE-PATH -cp "%ASADMIN_CLASSPATH%" com.sun.enterprise.admin.cli.AdminMain %* diff --git a/nucleus/distributions/nucleus-common/src/main/resources/bin/startserv b/nucleus/distributions/nucleus-common/src/main/resources/bin/startserv index 3537bf557b7..782668c7356 100644 --- a/nucleus/distributions/nucleus-common/src/main/resources/bin/startserv +++ b/nucleus/distributions/nucleus-common/src/main/resources/bin/startserv @@ -16,21 +16,20 @@ # SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 # -AS_INSTALL=`dirname "$0"`/.. +export AS_INSTALL="$(dirname $(realpath -s $0))/.." case "`uname`" in CYGWIN*) AS_INSTALL=`cygpath --windows $AS_INSTALL` esac -AS_INSTALL_LIB="$AS_INSTALL/modules" . "${AS_INSTALL}/config/asenv.conf" + JAVA=java -#Depends upon Java from ../config/asenv.conf if [ ${AS_JAVA} ]; then JAVA=${AS_JAVA}/bin/java fi start_as_main_process () { if [[ "$@" == "--help" ]] || [[ "$@" == "--help=true" ]] || [[ "$@" == "-?" ]]; then - exec java -jar "$ASADMIN_JAR" start-domain --help + exec "$JAVA" ${ASADMIN_JVM_OPTIONS} --module-path "${ASADMIN_MODULEPATH}" --add-modules ALL-MODULE-PATH -cp "$ASADMIN_CLASSPATH" com.sun.enterprise.admin.cli.AdminMain start-domain --help fi # Execute start-domain --dry-run and store the output line by line into an array. @@ -50,7 +49,7 @@ start_as_main_process () { else DRY_RUN_OUTPUT+=("$COM"); fi - done < <(java -jar "$ASADMIN_JAR" start-domain --dry-run "$@" || echo "FAILED" ) + done < <("$JAVA" ${ASADMIN_JVM_OPTIONS} --module-path "${ASADMIN_MODULEPATH}" --add-modules ALL-MODULE-PATH -cp "$ASADMIN_CLASSPATH" com.sun.enterprise.admin.cli.AdminMain start-domain --dry-run "$@" || echo "FAILED") if [[ x"$DRY_RUN_OUTPUT" == x ]] then echo -n -e "${DRY_RUN_OUTPUT_BEFORE_DUMP}" >&2 @@ -65,8 +64,7 @@ start_as_main_process () { } -ASADMIN_JAR="$AS_INSTALL_LIB/admin-cli.jar" start_as_main_process "$@" # Alternatively, run the following: -# exec "$JAVA" -jar "$ASADMIN_JAR" start-domain --verbose "$@" \ No newline at end of file +# exec "$JAVA" -jar "$ASADMIN_JAR" start-domain --verbose "$@" diff --git a/nucleus/distributions/nucleus-common/src/main/resources/bin/startserv.bat b/nucleus/distributions/nucleus-common/src/main/resources/bin/startserv.bat index 57196df6fa3..55d7b12b106 100644 --- a/nucleus/distributions/nucleus-common/src/main/resources/bin/startserv.bat +++ b/nucleus/distributions/nucleus-common/src/main/resources/bin/startserv.bat @@ -1,5 +1,6 @@ @echo off REM +REM Copyright (c) 2024 Contributors to the Eclipse Foundation REM Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. REM REM This program and the accompanying materials are made available under the @@ -15,5 +16,21 @@ REM REM SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 REM +VERIFY OTHER 2>nul +setlocal ENABLEEXTENSIONS +if ERRORLEVEL 0 goto ok +echo "Unable to enable extensions" +exit /B 1 -java -jar "%~dp0..\modules\admin-cli.jar" start-domain --verbose %* +:ok +set AS_INSTALL=%~dp0.. +call "%AS_INSTALL%\config\asenv.bat" +if "%AS_JAVA%x" == "x" goto UsePath +set JAVA=%AS_JAVA%\bin\java +goto run + +:UsePath +set JAVA=java + +:run +%JAVA% %ASADMIN_JVM_OPTIONS% --module-path "%ASADMIN_MODULEPATH%" --add-modules ALL-MODULE-PATH -cp "%ASADMIN_CLASSPATH%" com.sun.enterprise.admin.cli.AdminMain start-domain --verbose %* diff --git a/nucleus/distributions/nucleus-common/src/main/resources/bin/stopserv b/nucleus/distributions/nucleus-common/src/main/resources/bin/stopserv index 47d70c90945..02014ede1e0 100644 --- a/nucleus/distributions/nucleus-common/src/main/resources/bin/stopserv +++ b/nucleus/distributions/nucleus-common/src/main/resources/bin/stopserv @@ -1,5 +1,6 @@ #!/bin/sh # +# Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation # Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. # # This program and the accompanying materials are made available under the @@ -16,6 +17,5 @@ # AS_INSTALL=`dirname "$0"`/.. -AS_INSTALL_LIB="$AS_INSTALL/modules" -exec java -jar "$AS_INSTALL_LIB/admin-cli.jar" stop-domain "$@" +exec java "-Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager" -jar "$AS_INSTALL/admin-cli.jar" stop-domain "$@" diff --git a/nucleus/distributions/nucleus-common/src/main/resources/bin/stopserv.bat b/nucleus/distributions/nucleus-common/src/main/resources/bin/stopserv.bat index aca534159c8..0f10d2bfad9 100644 --- a/nucleus/distributions/nucleus-common/src/main/resources/bin/stopserv.bat +++ b/nucleus/distributions/nucleus-common/src/main/resources/bin/stopserv.bat @@ -1,19 +1,20 @@ -@echo off -REM -REM Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. -REM -REM This program and the accompanying materials are made available under the -REM terms of the Eclipse Public License v. 2.0, which is available at -REM http://www.eclipse.org/legal/epl-2.0. -REM -REM This Source Code may also be made available under the following Secondary -REM Licenses when the conditions for such availability set forth in the -REM Eclipse Public License v. 2.0 are satisfied: GNU General Public License, -REM version 2 with the GNU Classpath Exception, which is available at -REM https://www.gnu.org/software/classpath/license.html. -REM -REM SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 -REM - - -java -jar "%~dp0..\modules\admin-cli.jar" stop-domain %* +@echo off +REM +REM Copyright (c) 2024 Contributors to the Eclipse Foundation +REM Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. +REM +REM This program and the accompanying materials are made available under the +REM terms of the Eclipse Public License v. 2.0, which is available at +REM http://www.eclipse.org/legal/epl-2.0. +REM +REM This Source Code may also be made available under the following Secondary +REM Licenses when the conditions for such availability set forth in the +REM Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +REM version 2 with the GNU Classpath Exception, which is available at +REM https://www.gnu.org/software/classpath/license.html. +REM +REM SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +REM + + +java "-Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager" -jar "%~dp0..\admin-cli.jar" stop-domain %* diff --git a/nucleus/distributions/nucleus-common/src/main/resources/config/asenv.bat b/nucleus/distributions/nucleus-common/src/main/resources/config/asenv.bat index 20642050f73..cda98e747a9 100644 --- a/nucleus/distributions/nucleus-common/src/main/resources/config/asenv.bat +++ b/nucleus/distributions/nucleus-common/src/main/resources/config/asenv.bat @@ -38,10 +38,14 @@ REM directory. REM REM This file uses UTF-8 character encoding. -set AS_IMQ_LIB=..\..\mq\lib -set AS_IMQ_BIN=..\..\mq\bin -set AS_CONFIG=..\config -set AS_INSTALL=.. -set AS_DEF_DOMAINS_PATH=..\domains -set AS_DEF_NODES_PATH=..\nodes -set AS_DERBY_INSTALL=..\..\javadb +set AS_DERBY_INSTALL=%AS_INSTALL%\..\javadb +set AS_IMQ_LIB=%AS_INSTALL%\..\mq\lib +set AS_IMQ_BIN=%AS_INSTALL%\..\mq\bin + +set AS_CONFIG=%AS_INSTALL%\config +set AS_DEF_DOMAINS_PATH=%AS_INSTALL%\domains +set AS_DEF_NODES_PATH=%AS_INSTALL%\nodes + +set ASADMIN_MODULEPATH=%AS_INSTALL%\lib\bootstrap +set ASADMIN_JVM_OPTIONS=-Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager +set ASADMIN_CLASSPATH=%AS_INSTALL%\admin-cli.jar;%AS_INSTALL%\lib\asadmin\*;%AS_INSTALL%\modules\admin-util.jar;%AS_INSTALL%\modules\backup.jar;%AS_INSTALL%\modules\cluster-common.jar;%AS_INSTALL%\modules\config-api.jar;%AS_INSTALL%\modules\config-types.jar;%AS_INSTALL%\modules\common-util.jar;%AS_INSTALL%\modules\glassfish-api.jar;%AS_INSTALL%\modules\hk2.jar;%AS_INSTALL%\modules\hk2-config-generator.jar;%AS_INSTALL%\modules\jackson-core.jar;%AS_INSTALL%\modules\jakarta.activation-api.jar;%AS_INSTALL%\modules\jakarta.validation-api.jar;%AS_INSTALL%\modules\jakarta.xml.bind-api.jar;%AS_INSTALL%\modules\jaxb-osgi.jar;%AS_INSTALL%\modules\jettison.jar;%AS_INSTALL%\modules\launcher.jar;%AS_INSTALL%\modules\mimepull.jar diff --git a/nucleus/distributions/nucleus-common/src/main/resources/config/asenv.conf b/nucleus/distributions/nucleus-common/src/main/resources/config/asenv.conf index 2f6bffd19df..f263030a0d2 100644 --- a/nucleus/distributions/nucleus-common/src/main/resources/config/asenv.conf +++ b/nucleus/distributions/nucleus-common/src/main/resources/config/asenv.conf @@ -37,10 +37,14 @@ # # This file uses UTF-8 character encoding. -AS_IMQ_LIB="../../mq/lib" -AS_IMQ_BIN="../../mq/bin" -AS_CONFIG="../config" -AS_INSTALL=".." -AS_DEF_DOMAINS_PATH="../domains" -AS_DEF_NODES_PATH="../nodes" -AS_DERBY_INSTALL="../../javadb" +export AS_DERBY_INSTALL="${AS_DERBY_INSTALL:-$AS_INSTALL/../javadb}" +export AS_IMQ_LIB="${AS_IMQ_LIB:-$AS_INSTALL/../mq/lib}" +export AS_IMQ_BIN="${AS_IMQ_BIN:-$AS_INSTALL/../mq/bin}" + +export AS_CONFIG="${AS_CONFIG:-$AS_INSTALL/config}" +export AS_DEF_DOMAINS_PATH="${AS_DEF_DOMAINS_PATH:-$AS_INSTALL/domains}" +export AS_DEF_NODES_PATH="${AS_DEF_NODES_PATH:-$AS_INSTALL/nodes}" + +export ASADMIN_MODULEPATH="${AS_INSTALL}/lib/bootstrap" +export ASADMIN_JVM_OPTIONS="-Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager" +export ASADMIN_CLASSPATH="$AS_INSTALL/admin-cli.jar:$AS_INSTALL/lib/asadmin/*:$AS_INSTALL/modules/admin-util.jar:$AS_INSTALL/modules/backup.jar:$AS_INSTALL/modules/cluster-common.jar:$AS_INSTALL/modules/config-api.jar:$AS_INSTALL/modules/config-types.jar:$AS_INSTALL/modules/common-util.jar:$AS_INSTALL/modules/glassfish-api.jar:$AS_INSTALL/modules/hk2.jar:$AS_INSTALL/modules/hk2-config-generator.jar:$AS_INSTALL/modules/jackson-core.jar:$AS_INSTALL/modules/jakarta.activation-api.jar:$AS_INSTALL/modules/jakarta.validation-api.jar:$AS_INSTALL/modules/jakarta.xml.bind-api.jar:$AS_INSTALL/modules/jaxb-osgi.jar:$AS_INSTALL/modules/jettison.jar:$AS_INSTALL/modules/launcher.jar:$AS_INSTALL/modules/mimepull.jar" diff --git a/nucleus/distributions/nucleus-common/src/main/resources/config/osgi.properties b/nucleus/distributions/nucleus-common/src/main/resources/config/osgi.properties index 0cb1c791cdc..066351e8182 100755 --- a/nucleus/distributions/nucleus-common/src/main/resources/config/osgi.properties +++ b/nucleus/distributions/nucleus-common/src/main/resources/config/osgi.properties @@ -93,6 +93,9 @@ com.sun.enterprise.hk2.cacheDir=${org.osgi.framework.storage} # Since Felix starts bundles with same start level in the order in which bundles are installed, # and osgi-adapter and osgi-resource-locator both have same start level of 1, to make sure # osgi-resource-locator starts ahead of osgi-adapter, we install it ahead of osgi-adapter as well. + +# The admin-cli.jar is meant to be used with asadmin commands. At this moment it is also required +# by the web application in Ant based tests: jdbc/flushconnectionpool. # # TODO: We should fix it by using different start levels, but at this point we can't change # the start levels, as we have already documented the start levels shell bundles in public documents. @@ -100,8 +103,8 @@ com.sun.enterprise.hk2.cacheDir=${org.osgi.framework.storage} # Then we autostart GlassFish core bundles followed by optional services. # The reason for using installRootURI is to make sure any char like white space is properly encoded. glassfish.osgi.auto.install=\ - ${com.sun.aas.installRootURI}modules/osgi-resource-locator.jar \ ${com.sun.aas.installRootURI}modules/ \ + ${com.sun.aas.installRootURI}admin-cli.jar \ ${com.sun.aas.installRootURI}modules/autostart/ # This bundle is only needed to be activated if we want to use ondemqand mode. @@ -126,11 +129,12 @@ hk2.bundles=\ ${com.sun.aas.installRootURI}modules/asm-commons.jar \ ${com.sun.aas.installRootURI}modules/asm-tree.jar \ ${com.sun.aas.installRootURI}modules/asm-util.jar \ - ${com.sun.aas.installRootURI}modules/osgi-adapter.jar + ${com.sun.aas.installRootURI}modules/osgi-adapter.jar \ + ${com.sun.aas.installRootURI}admin-cli.jar core.bundles=\ ${hk2.bundles} \ - ${com.sun.aas.installRootURI}modules/glassfish.jar + ${com.sun.aas.installRootURI}modules/glassfish-osgi-bootstrap.jar autostart.bundles=${com.sun.aas.installRootURI}modules/autostart/ diff --git a/nucleus/distributions/nucleus/src/main/assembly/nucleus-new.xml b/nucleus/distributions/nucleus/src/main/assembly/nucleus-new.xml index 6dfda6eb9bb..b689e216c5d 100644 --- a/nucleus/distributions/nucleus/src/main/assembly/nucleus-new.xml +++ b/nucleus/distributions/nucleus/src/main/assembly/nucleus-new.xml @@ -65,8 +65,16 @@ ${install.dir.name}/lib/schemas - + + + ${temp.dir} + + admin-cli.jar + + ${install.dir.name} + + ${temp.dir} @@ -99,7 +107,10 @@ ${temp.dir} + glassfish.jar + glassfish-jdk-extensions.jar glassfish-jul-extension.jar + simple-glassfish-api.jar ${install.dir.name}/lib/bootstrap @@ -132,6 +143,7 @@ *.jar + admin-cli.jar server-mgmt.jar osgi-cli-interactive.jar flashlight-agent.jar @@ -143,7 +155,10 @@ org.apache.felix.scr.jar org.osgi.util.function.jar org.osgi.util.promise.jar + glassfish.jar + glassfish-jdk-extensions.jar glassfish-jul-extension.jar + simple-glassfish-api.jar felix.jar nucleus-domain.jar cluster-cli.jar diff --git a/nucleus/distributions/pom.xml b/nucleus/distributions/pom.xml index f673f0db5ca..7f6493578ec 100644 --- a/nucleus/distributions/pom.xml +++ b/nucleus/distributions/pom.xml @@ -135,6 +135,9 @@ ${nadmin.executable} ${create-domain.args} + true + + true diff --git a/nucleus/featuresets/atomic/pom.xml b/nucleus/featuresets/atomic/pom.xml index d4e882130c2..eef18eef943 100644 --- a/nucleus/featuresets/atomic/pom.xml +++ b/nucleus/featuresets/atomic/pom.xml @@ -464,6 +464,17 @@ + + org.glassfish.main.core + glassfish-osgi-bootstrap + ${project.version} + + + * + * + + + org.glassfish.main.core kernel @@ -508,6 +519,11 @@ + + org.glassfish.main.common + glassfish-jdk-extensions + ${project.version} + org.glassfish.main.admin config-api diff --git a/nucleus/flashlight/framework/src/main/java/org/glassfish/flashlight/impl/client/Strings.java b/nucleus/flashlight/framework/src/main/java/org/glassfish/flashlight/impl/client/Strings.java index 1825e14eb5a..b5ed12e50bc 100644 --- a/nucleus/flashlight/framework/src/main/java/org/glassfish/flashlight/impl/client/Strings.java +++ b/nucleus/flashlight/framework/src/main/java/org/glassfish/flashlight/impl/client/Strings.java @@ -16,7 +16,7 @@ package org.glassfish.flashlight.impl.client; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Strings -- Get your Strings here. diff --git a/nucleus/glassfish-jul-extension/src/main/java/module-info.java b/nucleus/glassfish-jul-extension/src/main/java/module-info.java index 3be019be94d..47055a1c3b4 100644 --- a/nucleus/glassfish-jul-extension/src/main/java/module-info.java +++ b/nucleus/glassfish-jul-extension/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Eclipse Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2022 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at diff --git a/nucleus/osgi-platforms/felix/src/main/resources/config/osgi.properties b/nucleus/osgi-platforms/felix/src/main/resources/config/osgi.properties index 0cb1c791cdc..066351e8182 100755 --- a/nucleus/osgi-platforms/felix/src/main/resources/config/osgi.properties +++ b/nucleus/osgi-platforms/felix/src/main/resources/config/osgi.properties @@ -93,6 +93,9 @@ com.sun.enterprise.hk2.cacheDir=${org.osgi.framework.storage} # Since Felix starts bundles with same start level in the order in which bundles are installed, # and osgi-adapter and osgi-resource-locator both have same start level of 1, to make sure # osgi-resource-locator starts ahead of osgi-adapter, we install it ahead of osgi-adapter as well. + +# The admin-cli.jar is meant to be used with asadmin commands. At this moment it is also required +# by the web application in Ant based tests: jdbc/flushconnectionpool. # # TODO: We should fix it by using different start levels, but at this point we can't change # the start levels, as we have already documented the start levels shell bundles in public documents. @@ -100,8 +103,8 @@ com.sun.enterprise.hk2.cacheDir=${org.osgi.framework.storage} # Then we autostart GlassFish core bundles followed by optional services. # The reason for using installRootURI is to make sure any char like white space is properly encoded. glassfish.osgi.auto.install=\ - ${com.sun.aas.installRootURI}modules/osgi-resource-locator.jar \ ${com.sun.aas.installRootURI}modules/ \ + ${com.sun.aas.installRootURI}admin-cli.jar \ ${com.sun.aas.installRootURI}modules/autostart/ # This bundle is only needed to be activated if we want to use ondemqand mode. @@ -126,11 +129,12 @@ hk2.bundles=\ ${com.sun.aas.installRootURI}modules/asm-commons.jar \ ${com.sun.aas.installRootURI}modules/asm-tree.jar \ ${com.sun.aas.installRootURI}modules/asm-util.jar \ - ${com.sun.aas.installRootURI}modules/osgi-adapter.jar + ${com.sun.aas.installRootURI}modules/osgi-adapter.jar \ + ${com.sun.aas.installRootURI}admin-cli.jar core.bundles=\ ${hk2.bundles} \ - ${com.sun.aas.installRootURI}modules/glassfish.jar + ${com.sun.aas.installRootURI}modules/glassfish-osgi-bootstrap.jar autostart.bundles=${com.sun.aas.installRootURI}modules/autostart/ diff --git a/nucleus/osgi-platforms/osgi-cli-interactive/pom.xml b/nucleus/osgi-platforms/osgi-cli-interactive/pom.xml index 9bfd3ae67df..4ca5b933553 100644 --- a/nucleus/osgi-platforms/osgi-cli-interactive/pom.xml +++ b/nucleus/osgi-platforms/osgi-cli-interactive/pom.xml @@ -39,6 +39,12 @@ + + org.glassfish.main.common + glassfish-jdk-extensions + ${project.version} + provided + org.glassfish.main.admin admin-cli @@ -48,7 +54,6 @@ org.jline jline provided - true diff --git a/nucleus/osgi-platforms/osgi-cli-interactive/src/main/java/org/glassfish/osgi/cli/interactive/LocalOSGiShellCommand.java b/nucleus/osgi-platforms/osgi-cli-interactive/src/main/java/org/glassfish/osgi/cli/interactive/LocalOSGiShellCommand.java index 20c8338e187..24029925027 100644 --- a/nucleus/osgi-platforms/osgi-cli-interactive/src/main/java/org/glassfish/osgi/cli/interactive/LocalOSGiShellCommand.java +++ b/nucleus/osgi-platforms/osgi-cli-interactive/src/main/java/org/glassfish/osgi/cli/interactive/LocalOSGiShellCommand.java @@ -26,7 +26,6 @@ import com.sun.enterprise.admin.cli.ProgramOptions; import com.sun.enterprise.admin.cli.remote.RemoteCLICommand; import com.sun.enterprise.admin.util.CommandModelData.ParamModelData; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import jakarta.inject.Inject; @@ -54,6 +53,7 @@ import org.glassfish.hk2.api.MultiException; import org.glassfish.hk2.api.PerLookup; import org.glassfish.hk2.api.ServiceLocator; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; import org.jline.reader.Completer; import org.jline.reader.EndOfFileException; import org.jline.reader.LineReader; @@ -357,6 +357,7 @@ private int executeCommands(LineReader reader) throws CommandException { */ final ProgramOptions programOptions = new ProgramOptions(env); // copy over AsadminMain info + programOptions.setModulePath(programOpts.getModulePath()); programOptions.setClassPath(programOpts.getClassPath()); programOptions.setClassName(programOpts.getClassName()); // remove the old one and replace it diff --git a/nucleus/parent/pom.xml b/nucleus/parent/pom.xml index 30c6e3f2213..1864b8e8514 100644 --- a/nucleus/parent/pom.xml +++ b/nucleus/parent/pom.xml @@ -401,10 +401,10 @@ pom import + org.glassfish.grizzly grizzly-npn-api - ${grizzly.npn.version} @@ -2020,9 +2020,7 @@ - true - custom - ${artifact.artifactId}.${artifact.extension} + false ${project.build.outputDirectory}/META-INF/MANIFEST.MF diff --git a/nucleus/security/core/src/main/java/com/sun/enterprise/security/admin/cli/Strings.java b/nucleus/security/core/src/main/java/com/sun/enterprise/security/admin/cli/Strings.java index df84b178d0d..6326f4135fd 100644 --- a/nucleus/security/core/src/main/java/com/sun/enterprise/security/admin/cli/Strings.java +++ b/nucleus/security/core/src/main/java/com/sun/enterprise/security/admin/cli/Strings.java @@ -16,7 +16,7 @@ package com.sun.enterprise.security.admin.cli; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; +import org.glassfish.main.jdke.i18n.LocalStringsImpl; /** * Strings -- Get your Strings here. One file with Strings So one class for messing with them! Nothing in here is public diff --git a/nucleus/test-utils/src/main/java/org/glassfish/tests/utils/junit/ExcludeClasses.java b/nucleus/test-utils/src/main/java/org/glassfish/tests/utils/junit/ExcludeClasses.java index fa7415326c0..0a0e49e3a00 100644 --- a/nucleus/test-utils/src/main/java/org/glassfish/tests/utils/junit/ExcludeClasses.java +++ b/nucleus/test-utils/src/main/java/org/glassfish/tests/utils/junit/ExcludeClasses.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Eclipse Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -43,5 +43,5 @@ * * @return array iof ignored classes */ - public Class[] value(); + Class[] value(); } diff --git a/nucleus/test-utils/src/main/java/org/glassfish/tests/utils/junit/HK2ClasssVisitor.java b/nucleus/test-utils/src/main/java/org/glassfish/tests/utils/junit/HK2ClasssVisitor.java index ee09b870346..dff527ab80e 100644 --- a/nucleus/test-utils/src/main/java/org/glassfish/tests/utils/junit/HK2ClasssVisitor.java +++ b/nucleus/test-utils/src/main/java/org/glassfish/tests/utils/junit/HK2ClasssVisitor.java @@ -1,6 +1,6 @@ /* + * Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation. * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2021, 2023 Eclipse Foundation and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -50,7 +50,7 @@ class HK2ClasssVisitor extends ClassVisitor { * @param locator * @param excludedClasses */ - public HK2ClasssVisitor(final ServiceLocator locator, final Set> excludedClasses) { + HK2ClasssVisitor(final ServiceLocator locator, final Set> excludedClasses) { super(ASM9); this.locator = locator; this.excludedClasses = excludedClasses.stream().map(Class::getName).collect(Collectors.toSet()); diff --git a/nucleus/test-utils/src/main/java/org/glassfish/tests/utils/junit/JUnitSystem.java b/nucleus/test-utils/src/main/java/org/glassfish/tests/utils/junit/JUnitSystem.java new file mode 100644 index 00000000000..4243d63c58b --- /dev/null +++ b/nucleus/test-utils/src/main/java/org/glassfish/tests/utils/junit/JUnitSystem.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.tests.utils.junit; + +import java.io.File; +import java.nio.file.Path; + +/** + * Helper class to make possible running tests the same way in Maven as in Eclipse IDE, probably + * also other environments. + */ +public final class JUnitSystem { + + private JUnitSystem() { + // utility class + } + + /** + * Useful for a heuristic inside Eclipse and other environments. + * + * @return Absolute path to the glassfish directory. + */ + public static Path detectBasedir() { + // Maven would set this property. + final String basedir = System.getProperty("basedir"); + if (basedir != null) { + return new File(basedir).toPath().toAbsolutePath(); + } + // Maybe we are standing in the basedir. + final File target = new File("target"); + if (target.exists()) { + return target.toPath().toAbsolutePath().getParent(); + } + // Eclipse IDE sometimes uses target as the current dir. + return new File(".").toPath().toAbsolutePath().getParent(); + } +}