diff --git a/appserver/featuresets/debug/pom.xml b/appserver/featuresets/debug/pom.xml index a09addf980f..fe69dc7e91a 100644 --- a/appserver/featuresets/debug/pom.xml +++ b/appserver/featuresets/debug/pom.xml @@ -40,16 +40,16 @@ In the IDE, for instance, Eclipse, go to run - debug configurations - remote java application - project And add this project there. - + Debug - + jakarta.el jakarta.el-api - + org.osgi osgi.core @@ -65,9 +65,9 @@ org.apache.felix - org.apache.felix.framework + org.apache.felix.main - + org.glassfish.grizzly grizzly-framework 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 ff97d812ad9..ab6f6acdf09 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 @@ -101,9 +101,11 @@ private void startConsole() throws IOException { try { System.out.println("command = " + command); if ("start".equalsIgnoreCase(command)) { - if (gf.getStatus() != GlassFish.Status.STARTED || gf.getStatus() == GlassFish.Status.STOPPING || gf.getStatus() == GlassFish.Status.STARTING) + if (gf.getStatus() != GlassFish.Status.STARTED || gf.getStatus() == GlassFish.Status.STOPPING || gf.getStatus() == GlassFish.Status.STARTING) { gf.start(); - else System.out.println("Already started or stopping or starting"); + } else { + System.out.println("Already started or stopping or starting"); + } } else if ("stop".equalsIgnoreCase(command)) { if (gf.getStatus() != GlassFish.Status.STARTED) { System.out.println("GlassFish is not started yet. Please execute start first."); @@ -174,9 +176,12 @@ private void prompt() { private void addShutdownHook() { Runtime.getRuntime().addShutdownHook(new Thread("GlassFish Shutdown Hook") { + @Override public void run() { try { - gfr.shutdown(); + if (gfr != null) { + gfr.shutdown(); + } } catch (Exception ex) { System.err.println("Error stopping framework: " + ex); diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiGlassFishRuntimeBuilder.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiGlassFishRuntimeBuilder.java index c829ef22899..32e940c4960 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiGlassFishRuntimeBuilder.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/osgi/OSGiGlassFishRuntimeBuilder.java @@ -22,8 +22,7 @@ import org.glassfish.embeddable.GlassFishException; import org.glassfish.embeddable.GlassFishRuntime; import org.glassfish.embeddable.spi.RuntimeBuilder; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleException; +import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.framework.launch.Framework; @@ -79,7 +78,7 @@ public final class OSGiGlassFishRuntimeBuilder implements RuntimeBuilder { private Framework framework; - private Logger logger = LogFacade.BOOTSTRAP_LOGGER; + private final Logger logger = LogFacade.BOOTSTRAP_LOGGER; private Properties oldProvisioningOptions; private Properties newProvisioningOptions; @@ -92,6 +91,7 @@ public final class OSGiGlassFishRuntimeBuilder implements RuntimeBuilder { */ public OSGiGlassFishRuntimeBuilder() {} + @Override public GlassFishRuntime build(BootstrapProperties bsProps) throws GlassFishException { try { MainHelper.buildStartupContext(bsProps.getProperties()); @@ -147,6 +147,7 @@ public GlassFishRuntime build(BootstrapProperties bsProps) throws GlassFishExcep } } + @Override public boolean handles(BootstrapProperties bsProps) { // See GLASSFISH-16743 for the reason behind additional check final String builderName = bsProps.getProperty(Constants.BUILDER_NAME_PROPERTY); @@ -214,7 +215,8 @@ private void printStats(BundleProvisioner bundleProvisioner, long t0, long t1, l } private boolean newFramework() { - return framework.getBundleContext().getBundles().length == 1; + BundleContext context = framework.getBundleContext(); + return context == null || context.getBundles().length == 1; } /** @@ -238,16 +240,11 @@ private void reconfigure(Properties properties) throws Exception { } private boolean hasBeenReconfigured(Properties properties) { - try { - logger.logp(Level.FINE, "OSGiGlassFishRuntimeBuilder", "hasBeenReconfigured", "oldProvisioningOptions = {0}", - new Object[]{getOldProvisioningOptions()}); - logger.logp(Level.FINE, "OSGiGlassFishRuntimeBuilder", "hasBeenReconfigured", "newProvisioningOptions = {0}", - new Object[]{getNewProvisioningOptions(properties)}); - return !getNewProvisioningOptions(properties).equals(getOldProvisioningOptions()); - } catch (IOException e) { - e.printStackTrace(); - return true; - } + logger.logp(Level.FINE, "OSGiGlassFishRuntimeBuilder", "hasBeenReconfigured", "oldProvisioningOptions = {0}", + new Object[]{getOldProvisioningOptions()}); + logger.logp(Level.FINE, "OSGiGlassFishRuntimeBuilder", "hasBeenReconfigured", "newProvisioningOptions = {0}", + new Object[]{getNewProvisioningOptions(properties)}); + return !getNewProvisioningOptions(properties).equals(getOldProvisioningOptions()); } /** @@ -294,45 +291,39 @@ private void storeBundleIds(Long[] bundleIds) { } private void storeProvisioningOptions(Properties properties) { - FileOutputStream os = null; - try { - File f = framework.getBundleContext().getDataFile(PROVISIONING_OPTIONS_FILENAME); - // GLASSFISH-19623: f can be null - if (f == null) { - logger.log(Level.WARNING, LogFacade.CANT_STORE_PROVISIONING_OPTIONS); - return; - } - os = new FileOutputStream(f); + BundleContext context = framework.getBundleContext(); + if (context == null) { + throw new IllegalStateException("No bundle context available!"); + } + File f = context.getDataFile(PROVISIONING_OPTIONS_FILENAME); + // GLASSFISH-19623: f can be null + if (f == null) { + logger.log(Level.WARNING, LogFacade.CANT_STORE_PROVISIONING_OPTIONS); + return; + } + try (FileOutputStream os = new FileOutputStream(f)) { getNewProvisioningOptions(properties).store(os, ""); os.flush(); - logger.logp(Level.FINE, "OSGiGlassFishRuntimeBuilder", "storeProvisioningOptions", "Stored provisioning options in {0}", - new Object[]{f.getAbsolutePath()}); + logger.logp(Level.CONFIG, "OSGiGlassFishRuntimeBuilder", "storeProvisioningOptions", + "Stored provisioning options in {0}", new Object[] {f.getAbsolutePath()}); } catch (IOException e) { - e.printStackTrace(); - } finally { - if (os != null) { - try { - os.close(); - } catch (IOException e) { - // ignored - } - } + logger.log(Level.WARNING, "Storing provisioning options failed.", e); } } - private Properties getOldProvisioningOptions() throws IOException { + private Properties getOldProvisioningOptions() { if (oldProvisioningOptions == null) { Properties options = new Properties(); try { File f = framework.getBundleContext().getDataFile(PROVISIONING_OPTIONS_FILENAME); - if (f != null && f.exists()) { // GLASSFISH-19623: f can be null + if (f != null && f.exists()) { options.load(new FileInputStream(f)); logger.logp(Level.FINE, "OSGiGlassFishRuntimeBuilder", "getOldProvisioningOptions", "Read provisioning options from {0}", new Object[]{f.getAbsolutePath()}); oldProvisioningOptions = options; } } catch (Exception e) { - e.printStackTrace(); + logger.log(Level.WARNING, "Loading provisioning options failed.", e); } } return oldProvisioningOptions; diff --git a/nucleus/parent/pom.xml b/nucleus/parent/pom.xml index 819fbd544a0..c5c8eb1ab66 100644 --- a/nucleus/parent/pom.xml +++ b/nucleus/parent/pom.xml @@ -462,10 +462,17 @@ provided + org.apache.felix org.apache.felix.main - 7.0.3 + 7.1.0-SNAPSHOT + + + org.apache.felix + org.apache.felix.framework + 7.1.0-SNAPSHOT + provided org.apache.felix @@ -524,12 +531,6 @@ - - org.apache.felix - org.apache.felix.framework - 7.0.3 - provided - org.jline diff --git a/snapshots/felix-framework/pom.xml b/snapshots/felix-framework/pom.xml new file mode 100644 index 00000000000..ef3c8183425 --- /dev/null +++ b/snapshots/felix-framework/pom.xml @@ -0,0 +1,49 @@ + + + + 4.0.0 + + org.glassfish.main.snapshots + snapshotsmodule + 0.0.0-SNAPSHOT + + + felix-framework + pom + + + https://github.com/dmatej/felix-dev/archive/refs/heads/FELIX-6522-JDK17.zip + ${project.build.directory}/felix-dev-FELIX-6522-JDK17/framework + + + + + + com.googlecode.maven-download-plugin + download-maven-plugin + + + maven-invoker-plugin + + + + diff --git a/snapshots/felix-main/pom.xml b/snapshots/felix-main/pom.xml new file mode 100644 index 00000000000..c0dc0071636 --- /dev/null +++ b/snapshots/felix-main/pom.xml @@ -0,0 +1,58 @@ + + + + 4.0.0 + + org.glassfish.main.snapshots + snapshotsmodule + 0.0.0-SNAPSHOT + + + felix-main + pom + + + https://github.com/dmatej/felix-dev/archive/refs/heads/FELIX-6522-JDK17.zip + ${project.build.directory}/felix-dev-FELIX-6522-JDK17/main + + + + + org.glassfish.main.snapshots + felix-framework + pom + 0.0.0-SNAPSHOT + + + + + + + com.googlecode.maven-download-plugin + download-maven-plugin + + + maven-invoker-plugin + + + + diff --git a/snapshots/pom.xml b/snapshots/pom.xml index 3fff435fec5..4746e20522d 100644 --- a/snapshots/pom.xml +++ b/snapshots/pom.xml @@ -39,6 +39,11 @@ GlassFish Snapshots Parent Temporary snapshot modules + + felix-framework + felix-main + + @@ -89,6 +94,8 @@ clean source:jar install + + --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED ${basedir}/../settings.xml staging,default 4