Skip to content

Commit

Permalink
Merge pull request #23911 from dmatej/felix-jdk17-fix
Browse files Browse the repository at this point in the history
Felix jdk17 fix - able to start with the Security Manager enabled
  • Loading branch information
arjantijms authored Apr 22, 2022
2 parents ff47235 + d50d9b6 commit 8205400
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 52 deletions.
10 changes: 5 additions & 5 deletions appserver/featuresets/debug/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@

In the IDE, for instance, Eclipse, go to run - debug configurations - remote java application - project
And add this project there.
</description>
</description>

<name>Debug</name>

<dependencies>
<dependency>
<dependency>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
</dependency>

<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
Expand All @@ -65,9 +65,9 @@
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<artifactId>org.apache.felix.main</artifactId>
</dependency>

<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-framework</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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());
}

/**
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions nucleus/parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,17 @@
<scope>provided</scope>
</dependency>

<!-- framework is transitive dependency of others, but it is aggregated in main too -->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.main</artifactId>
<version>7.0.3</version>
<version>7.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>7.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
Expand Down Expand Up @@ -524,12 +531,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>7.0.3</version>
<scope>provided</scope>
</dependency>
<!-- This is currently used by osgi-shell cmd -->
<dependency>
<groupId>org.jline</groupId>
Expand Down
49 changes: 49 additions & 0 deletions snapshots/felix-framework/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2022 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
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.glassfish.main.snapshots</groupId>
<artifactId>snapshotsmodule</artifactId>
<version>0.0.0-SNAPSHOT</version>
</parent>

<artifactId>felix-framework</artifactId>
<packaging>pom</packaging>

<properties>
<snapshots.sources.url>https://github.com/dmatej/felix-dev/archive/refs/heads/FELIX-6522-JDK17.zip</snapshots.sources.url>
<snapshots.sources.directory>${project.build.directory}/felix-dev-FELIX-6522-JDK17/framework</snapshots.sources.directory>
</properties>

<build>
<plugins>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
58 changes: 58 additions & 0 deletions snapshots/felix-main/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2022 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
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.glassfish.main.snapshots</groupId>
<artifactId>snapshotsmodule</artifactId>
<version>0.0.0-SNAPSHOT</version>
</parent>

<artifactId>felix-main</artifactId>
<packaging>pom</packaging>

<properties>
<snapshots.sources.url>https://github.com/dmatej/felix-dev/archive/refs/heads/FELIX-6522-JDK17.zip</snapshots.sources.url>
<snapshots.sources.directory>${project.build.directory}/felix-dev-FELIX-6522-JDK17/main</snapshots.sources.directory>
</properties>

<dependencies>
<dependency>
<groupId>org.glassfish.main.snapshots</groupId>
<artifactId>felix-framework</artifactId>
<type>pom</type>
<version>0.0.0-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
7 changes: 7 additions & 0 deletions snapshots/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<name>GlassFish Snapshots Parent</name>
<description>Temporary snapshot modules</description>

<modules>
<module>felix-framework</module>
<module>felix-main</module>
</modules>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -89,6 +94,8 @@
</pomIncludes>
<!-- source:jar - ie. metro uses sources of other modules -->
<goals>clean source:jar install</goals>
<!-- Felix uses ianal plugin made in 2008 which requires this -->
<mavenOpts>--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED</mavenOpts>
<settingsFile>${basedir}/../settings.xml</settingsFile>
<profiles>staging,default</profiles>
<parallelThreads>4</parallelThreads>
Expand Down

0 comments on commit 8205400

Please sign in to comment.