Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smaller cleanups #25172

Merged
merged 19 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -74,9 +74,9 @@ public String getVersionIdentifier(ReadableArchive archive) {
GFCarXMLParser gfXMLParser = new GFCarXMLParser();
versionIdentifier = gfXMLParser.extractVersionIdentifierValue(archive);
} catch (IOException e) {
LOG.log(Level.SEVERE, e.getMessage());
LOG.log(Level.SEVERE, e.getMessage(), e);
} catch (XMLStreamException e) {
LOG.log(Level.SEVERE, e.getMessage());
LOG.log(Level.SEVERE, e.getMessage(), e);
}
return versionIdentifier;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2008, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -137,21 +137,21 @@ protected String getModuleClassPath(DeploymentContext ctx) {
* @return The instance classpath
*/
protected String getCommonClassPath() {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();

File libDir = env.getLibPath();
String libDirPath = libDir.getAbsolutePath();

// Append domain_root/lib/classes
sb.append(libDirPath + File.separator + "classes");
sb.append(libDirPath).append(File.separator).append("classes");
sb.append(File.pathSeparator);

// Append domain_root/lib/[*.jar|*.zip]
String[] files = libDir.list();
if (files != null) {
for (String file : files) {
if (file.endsWith(".jar") || file.endsWith(".zip")) {
sb.append(libDirPath + File.separator + file);
sb.append(libDirPath).append(File.separator).append(file);
sb.append(File.pathSeparator);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -91,9 +91,9 @@ public String getVersionIdentifier(ReadableArchive archive) {
GFEjbJarXMLParser gfXMLParser = new GFEjbJarXMLParser(archive);
versionIdentifier = gfXMLParser.extractVersionIdentifierValue(archive);
} catch (XMLStreamException e) {
LOG.log(Level.SEVERE, e.getMessage());
LOG.log(Level.SEVERE, e.getMessage(), e);
} catch (IOException e) {
LOG.log(Level.SEVERE, e.getMessage());
LOG.log(Level.SEVERE, e.getMessage(), e);
}
return versionIdentifier;
}
Expand Down Expand Up @@ -145,17 +145,13 @@ public ClassLoader getClassLoader(final ClassLoader parent, DeploymentContext co
}

try {
final DeploymentContext dc = context;
final ClassLoader cl = cloader;

AccessController.doPrivileged(
new PermsArchiveDelegate.SetPermissionsAction(SMGlobalPolicyUtil.CommponentType.ejb, dc, cl));
AccessController.doPrivileged(new PermsArchiveDelegate.SetPermissionsAction(
SMGlobalPolicyUtil.CommponentType.ejb, context, cloader));
} catch (PrivilegedActionException e) {
throw new SecurityException(e.getException());
}

} catch (Exception e) {
LOG.log(Level.SEVERE, e.getMessage());
throw new RuntimeException(e);
}
return cloader;
Expand Down
3 changes: 1 addition & 2 deletions appserver/extras/embedded/common/bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<includes>**/OSGiFrameworkLauncher**,**/AutoProcessor**</includes>
<excludes>META-INF/**</excludes>
<includes>**/OSGiFrameworkLauncher**</includes>
</artifactItem>
</artifactItems>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.PLATFORM_PROPERTY_KEY;
import static com.sun.enterprise.util.io.FileUtils.USER_HOME;
import static org.glassfish.embeddable.GlassFishProperties.CONFIG_FILE_URI_PROP_NAME;
import static org.osgi.framework.Constants.BUNDLE_VERSION;
import static org.osgi.framework.Constants.FRAMEWORK_STORAGE;
import static org.osgi.framework.Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA;

Expand Down Expand Up @@ -109,8 +110,8 @@ public GlassFishRuntime build(BootstrapProperties bsOptions) throws GlassFishExc
URI jar = null;
try {
jar = uberJarURI != null ? new URI(uberJarURI) : Util.whichJar(GlassFishRuntime.class);
} catch (URISyntaxException ex) {
logger.log(Level.SEVERE, null, ex);
} catch (URISyntaxException e) {
throw new IllegalStateException(e);
}

// XXX : Commented out by Prasad , we are again looking for instance root here. Why ?
Expand Down Expand Up @@ -151,7 +152,7 @@ public GlassFishRuntime build(BootstrapProperties bsOptions) throws GlassFishExc

String autoStartBundleLocation = "jar:" + jar.toString() + "!/modules/installroot-builder_jar/," +
"jar:" + jar.toString() + "!/modules/instanceroot-builder_jar/," +
"jar:" + jar.toString() + "!/modules/kernel_jar/"; // TODO :: was modules/glassfish_jar
"jar:" + jar.toString() + "!/modules/kernel_jar/";

if (isOSGiEnv()) {
autoStartBundleLocation = autoStartBundleLocation +
Expand Down Expand Up @@ -182,8 +183,8 @@ public GlassFishRuntime build(BootstrapProperties bsOptions) throws GlassFishExc
autostartBundle.start(Bundle.START_TRANSIENT);
logger.log(Level.FINER, "Started autostartBundle {0}", autostartBundle);
return getService(GlassFishRuntime.class, context);
} catch (Throwable t) {
throw new GlassFishException(new Exception(t));
} catch (Exception e) {
throw new GlassFishException(e);
}
}

Expand All @@ -201,10 +202,10 @@ private boolean isOSGiEnv() {
}

public <T> T getService(Class<T> type, BundleContext context) throws Exception {
ServiceTracker tracker = new ServiceTracker(context, type.getName(), null);
ServiceTracker<?, T> tracker = new ServiceTracker<>(context, type.getName(), null);
try {
tracker.open(true);
return type.cast(tracker.waitForService(0));
return tracker.waitForService(0);
} finally {
// no need to track further
tracker.close();
Expand Down Expand Up @@ -233,7 +234,7 @@ private String loadVersion() {
URL manifestURL = UberJarOSGiGlassFishRuntimeBuilder.class.getResource("/META-INF/MANIFEST.MF");
try (InputStream manifestStream = manifestURL.openStream()) {
Manifest manifest = new Manifest(manifestStream);
return manifest.getMainAttributes().getValue(org.osgi.framework.Constants.BUNDLE_VERSION);
return manifest.getMainAttributes().getValue(BUNDLE_VERSION);
} catch (IOException e) {
throw new IllegalStateException("Could not load version from the manifest file.", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation.
* Copyright (c) 2021, 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
Expand Down Expand Up @@ -46,7 +46,6 @@
import java.io.PrintWriter;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -323,7 +322,7 @@ void isValid(ManagedConnectionImpl managedConnectionImpl) throws ResourceExcepti

boolean connectionValidationRequired = (conVal == null) ?
false :
Boolean.valueOf(conVal.toLowerCase(Locale.getDefault()));
Boolean.parseBoolean(conVal.toLowerCase(Locale.getDefault()));
if (!connectionValidationRequired) {
return;
}
Expand Down Expand Up @@ -529,7 +528,7 @@ void resetIsolation(ManagedConnectionImpl managedConnectionImpl, int tranIsol) t
if (transactionIsolation != null && !transactionIsolation.isEmpty()) {
String guaranteeIsolationLevel = spec.getDetail(GUARANTEEISOLATIONLEVEL);
if (guaranteeIsolationLevel != null && !guaranteeIsolationLevel.isEmpty()) {
boolean guarantee = Boolean.valueOf(guaranteeIsolationLevel);
boolean guarantee = Boolean.parseBoolean(guaranteeIsolationLevel);
if (guarantee) {
int tranIsolationInt = getTransactionIsolationInt(transactionIsolation);
try {
Expand Down Expand Up @@ -572,8 +571,8 @@ private void detectSqlTraceListeners() {
// Load the listener class
try {
listenerClass = Thread.currentThread().getContextClassLoader().loadClass(sqlTraceListener);
} catch (ClassNotFoundException ex) {
_logger.log(SEVERE, "jdbc.sql_trace_listener_cnfe", sqlTraceListener);
} catch (ClassNotFoundException e) {
_logger.log(SEVERE, "Failed to load class: " + sqlTraceListener, e);
}
Class intf[] = listenerClass.getInterfaces();
for (Class interfaceName : intf) {
Expand All @@ -590,16 +589,8 @@ private void detectSqlTraceListeners() {
listener = (SQLTraceListener) constructor.newInstance(initargs);
}
}
} catch (InstantiationException ex) {
_logger.log(SEVERE, "jdbc.sql_trace_listener_exception", ex.getMessage());
} catch (IllegalAccessException ex) {
_logger.log(SEVERE, "jdbc.sql_trace_listener_exception", ex.getMessage());
} catch (IllegalArgumentException ex) {
_logger.log(SEVERE, "jdbc.sql_trace_listener_exception", ex.getMessage());
} catch (InvocationTargetException ex) {
_logger.log(SEVERE, "jdbc.sql_trace_listener_exception", ex.getMessage());
} catch (SecurityException ex) {
_logger.log(SEVERE, "jdbc.sql_trace_listener_exception", ex.getMessage());
} catch (ReflectiveOperationException | IllegalArgumentException | SecurityException ex) {
_logger.log(SEVERE, "jdbc.sql_trace_listener_exception", ex);
}
sqlTraceDelegator.registerSQLTraceListener(listener);
}
Expand Down Expand Up @@ -1338,7 +1329,7 @@ protected void computeStatementWrappingStatus() {
boolean poolProperty = false;
String statementWrappingString = getStatementWrapping();
if (statementWrappingString != null) {
poolProperty = Boolean.valueOf(statementWrappingString);
poolProperty = Boolean.parseBoolean(statementWrappingString);
}

if (wrapStatement == JVM_OPTION_STATEMENT_WRAPPING_ON
Expand Down Expand Up @@ -1436,7 +1427,7 @@ private void detectStatementLeakSupport() {
String stmtLeakReclaim = getStatementLeakReclaim();
if (stmtLeakTimeout != null) {
statementLeakTimeout = Integer.parseInt(stmtLeakTimeout) * 1000L;
statementLeakReclaim = Boolean.valueOf(stmtLeakReclaim);
statementLeakReclaim = Boolean.parseBoolean(stmtLeakReclaim);
if (_logger.isLoggable(FINE)) {
_logger.log(FINE, "StatementLeakTimeout in seconds: " + statementLeakTimeout
+ " & StatementLeakReclaim: " + statementLeakReclaim + " for pool : " + getPoolInfo());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#
# Copyright (c) 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
Expand Down Expand Up @@ -178,9 +179,7 @@ jdbc.jdbc_factory_class_load_exception=RAR9002 : Exception while getting Proxied
RAR9002.diag.cause.1=Connection object could be null
RAR9002.diag.cause.2=Initialization provoked by method could have failed.
RAR9002.diag.cause.3=Underlying method inaccessible.
jdbc.sql_trace_listener_cnfe=RAR9003 : Sql tracing : ClassNotFoundException while trying to load class : {0}
RAR9003.diag.cause.1=Sql trace listener class name is not in the classpath.
jdbc.sql_trace_listener_exception=RAR9004 : Exception while introspecting SQL trace listeners : {0}
jdbc.sql_trace_listener_exception=RAR9004 : Exception while introspecting SQL trace listeners
RAR9004.diag.cause.1=Constructor of the sql trace listener provided does not have enough access.
RAR9004.diag.cause.2=Sql trace listener does not implement org.glassfish.api.jdbc.SQLTraceListener.
RAR9004.diag.cause.3=Error while instantiating sql trace listener class provided.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.glassfish.main.admin.test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -79,15 +78,11 @@ public void createClusterTest() {
@Test
@Order(2)
public void deployAppToClusterTest() {
String warFile = getWar().getAbsolutePath();
String warFile = TestResources.createSimpleWarDeployment(TEST_APP_NAME).getAbsolutePath();
assertThat(ASADMIN.exec("deploy", "--target", CLUSTER_NAME, "--name", TEST_APP_NAME, "--contextroot", TEST_APP_NAME,
warFile), asadminOK());
}

private static File getWar() {
return TestResources.createSimpleWarDeployment(TEST_APP_NAME);
}

@Test
@Order(3)
public void createInstancesTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public static void waitOsgiReady() throws Exception {
if (!result.isError()) {
return;
}
Thread.sleep(1000);
}
}

Expand Down Expand Up @@ -127,7 +126,7 @@ public void osgiShell() throws IOException {
private String newCmdSession() throws Exception {
List<String> value = runCmd("osgi", "--session", "new");
if (value.size() != 1) {
throw new Exception("Unexpected output: \n " + value);
throw new AssertionError("Unexpected output: \n " + value);
}
return value.get(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.main.admin.test.webapp;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.concurrent.atomic.AtomicBoolean;

Expand All @@ -24,7 +24,6 @@
import org.glassfish.main.itest.tools.asadmin.Asadmin;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
Expand All @@ -33,6 +32,7 @@
import static org.glassfish.main.itest.tools.asadmin.AsadminResultMatcher.asadminOK;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

public class HttpServerNameITest {

Expand All @@ -43,7 +43,6 @@ public class HttpServerNameITest {

private static final AtomicBoolean APP_DEPLOYED = new AtomicBoolean();

@ParameterizedTest(name = "[{index}] testServerName: {0}")
@CsvSource({
"'Plain host name', hostname1, http://hostname1:8080/",
"'Plain domain name', my.domain.com, http://my.domain.com:8080/",
Expand All @@ -53,7 +52,8 @@ public class HttpServerNameITest {
"'Secure domain name and port', https://my.domain.com:123, https://my.domain.com:123/",
"'Secure domain name and standard port', https://my.domain.com:443, https://my.domain.com/"
})
public void testHostName(String description, String serverName, String expectedUrlPrefix) throws IOException, InterruptedException {
@ParameterizedTest(name = "[{index}] testServerName: {0}")
public void testHostName(String description, String serverName, String expectedUrlPrefix) throws Exception {
assertThat(ASADMIN.exec("set", SERVER_NAME_PROPERTY + "=" + serverName), asadminOK());

final HttpURLConnection conn = GlassFishTestEnvironment.openConnection(HTTP_PORT, "/" + TEST_APP_NAME);
Expand All @@ -73,13 +73,12 @@ static void deploy() {

@AfterAll
static void undeploy() {
Assumptions.assumeTrue(APP_DEPLOYED.get());
assumeTrue(APP_DEPLOYED.get());
assertThat(ASADMIN.exec("undeploy", TEST_APP_NAME), asadminOK());
}

@AfterEach
void cleanup() {
ASADMIN.exec("set", SERVER_NAME_PROPERTY + "=");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,10 @@ public class SQLTraceListenerTest {

private static final System.Logger LOG = System.getLogger(SQLTraceListenerTest.class.getName());

private static final String RESOURCE_ROOT = "src/main/resources/" + SqlListenerApplication.class.getPackageName().replace(".", "/");

private static final String LIB_FILE_NAME = "lib.jar";

private static final String WEBAPP_FILE_NAME = "webapp.war";

private static final String WEBAPP_NAME = "webapp";

private static final String POOL_NAME = "DerbyPool";

private static final Asadmin ASADMIN = GlassFishTestEnvironment.getAsadmin();
Expand Down Expand Up @@ -136,13 +132,13 @@ private static File createSqlTraceListenerLib() throws IOException {
return appLib;
}

private static File createWebApp() throws IOException {
private static File createWebApp() {
WebArchive webArchive = ShrinkWrap.create(WebArchive.class)
.addClass(SqlListenerApplication.class)
.addClass(SqlListenerEndpoint.class)
.addClass(Employee.class)
.addAsResource(new File(RESOURCE_ROOT, "/META-INF/persistence.xml"), "/META-INF/persistence.xml")
.addAsResource(new File(RESOURCE_ROOT, "/META-INF/load.sql"), "/META-INF/load.sql");
.addAsResource(SqlListenerApplication.class.getPackage(), "/META-INF/persistence.xml", "/META-INF/persistence.xml")
.addAsResource(SqlListenerApplication.class.getPackage(), "/META-INF/load.sql", "/META-INF/load.sql");

LOG.log(INFO, webArchive.toString(true));

Expand Down
Loading