Skip to content

Commit

Permalink
Fixes based on self-review
Browse files Browse the repository at this point in the history
Signed-off-by: David Matějček <david.matejcek@omnifish.ee>

# Conflicts:
#	appserver/jms/jms-core/src/main/java/com/sun/enterprise/connectors/jms/system/JmsProviderLifecycle.java
  • Loading branch information
dmatej committed Feb 20, 2024
1 parent 50d9e62 commit 8663099
Show file tree
Hide file tree
Showing 50 changed files with 308 additions and 324 deletions.
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, 2023 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
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, 2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2023 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
Expand All @@ -16,40 +17,41 @@

package org.glassfish.appclient.server.core;

import com.sun.enterprise.config.serverbeans.Config;
import com.sun.enterprise.config.serverbeans.Applications;
import com.sun.enterprise.module.HK2Module;
import java.io.IOException;
import com.sun.enterprise.config.serverbeans.Config;
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.deployment.Application;
import com.sun.enterprise.deployment.ApplicationClientDescriptor;
import com.sun.enterprise.deployment.archivist.AppClientArchivist;
import com.sun.enterprise.module.HK2Module;
import com.sun.enterprise.module.ModulesRegistry;
import com.sun.logging.LogDomains;

import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.inject.Singleton;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.logging.Logger;
import jakarta.inject.Inject;
import jakarta.inject.Named;

import org.glassfish.api.admin.ServerEnvironment;
import org.glassfish.api.deployment.DeploymentContext;
import org.glassfish.api.deployment.MetaData;
import org.glassfish.api.deployment.UndeployCommandParameters;
import org.glassfish.appclient.server.core.jws.servedcontent.ASJarSigner;
import org.glassfish.deployment.common.DeploymentException;
import org.glassfish.javaee.core.deployment.JavaEEDeployer;

import org.jvnet.hk2.annotations.Service;
import org.glassfish.hk2.api.PostConstruct;
import jakarta.inject.Singleton;
import org.glassfish.api.admin.ServerEnvironment;
import org.glassfish.appclient.server.core.jws.JWSAdapterManager;
import org.glassfish.appclient.server.core.jws.JavaWebStartInfo;
import org.glassfish.appclient.server.core.jws.servedcontent.ASJarSigner;
import org.glassfish.deployment.common.Artifacts;
import org.glassfish.deployment.common.DeploymentException;
import org.glassfish.deployment.common.DeploymentUtils;
import org.glassfish.hk2.api.PostConstruct;
import org.glassfish.javaee.core.deployment.JavaEEDeployer;
import org.jvnet.hk2.annotations.Service;

/**
* AppClient module deployer.
* <p>
Expand Down Expand Up @@ -160,14 +162,14 @@ public class AppClientDeployer
* Maps the app name to the user-friendly context root for that app.
*/
private final Map<String,String> appAndClientNameToUserFriendlyContextRoot =
new HashMap<String,String>();
new HashMap<>();



/** the class loader which knows about the org.glassfish.main.appclient.gf-client-module */
private ClassLoader gfClientModuleClassLoader;

/*
/**
* Each app client server application will listen for config change
* events - for creation, deletion, or change of java-web-start-enabled
* property settings. Because they are not handled as services hk2 will
Expand All @@ -177,8 +179,7 @@ public class AppClientDeployer
* all app client server applications so the deployer can forward
* notifications to each app client server app.
*/
final private Set<AppClientServerApplication> appClientApps =
new HashSet<AppClientServerApplication>();
private final Set<AppClientServerApplication> appClientApps = new HashSet<>();

public AppClientDeployer() {
}
Expand Down Expand Up @@ -282,8 +283,7 @@ protected void generateArtifacts(DeploymentContext dc) throws DeploymentExceptio
* @param helper
* @param dc
*/
private void recordUserFriendlyContextRoot(final AppClientDeployerHelper helper,
final DeploymentContext dc) {
private void recordUserFriendlyContextRoot(final AppClientDeployerHelper helper, final DeploymentContext dc) {
final String path = JWSAdapterManager.userFriendlyContextRoot(helper.appClientDesc(), dc.getAppProps());
dc.getModuleProps().put("jws.user.friendly.path", path);
}
Expand Down Expand Up @@ -322,23 +322,17 @@ private AppClientDeployerHelper getSavedHelperOrCreateHelper(final DeploymentCon
final String key = HELPER_KEY_NAME + moduleURI(dc);
AppClientDeployerHelper h = null;

final AppClientDeployerHelper.Proxy p = dc.getTransientAppMetaData(key,
AppClientDeployerHelper.Proxy.class);
final AppClientDeployerHelper.Proxy p = dc.getTransientAppMetaData(key, AppClientDeployerHelper.Proxy.class);
if (p != null) {
h = p.helper();
}

if (h == null) {
h = dc.getTransientAppMetaData(key,
StandaloneAppClientDeployerHelper.class);
h = dc.getTransientAppMetaData(key, StandaloneAppClientDeployerHelper.class);
}
if (h == null) {
/*
* We are probably loading a previously-deployed app client, so
* the helper has not be created yet. Create it.
*/
h = createAndSaveHelper(dc,
gfClientModuleClassLoader);
// We are probably loading a previously-deployed app client, so
// the helper has not be created yet. Create it.
h = createAndSaveHelper(dc, gfClientModuleClassLoader);
}
return h;
}
Expand All @@ -348,20 +342,20 @@ private String moduleURI(final DeploymentContext dc) {
return acd.getModuleDescriptor().getArchiveUri();
}

public void recordContextRoot(final String appName,
final String clientURIWithinEAR,
final String userFriendlyContextRoot) {
appAndClientNameToUserFriendlyContextRoot.put(
keyToAppAndClientNameMap(appName, clientURIWithinEAR),
userFriendlyContextRoot);

public void recordContextRoot(final String appName, final String clientURIWithinEAR,
final String userFriendlyContextRoot) {
String key = keyToAppAndClientNameMap(appName, clientURIWithinEAR);
appAndClientNameToUserFriendlyContextRoot.put(key, userFriendlyContextRoot);
}

public void removeContextRoot(final String appName,
final String clientURIWithinEAR) {
appAndClientNameToUserFriendlyContextRoot.remove(
keyToAppAndClientNameMap(appName, clientURIWithinEAR));

public void removeContextRoot(final String appName, final String clientURIWithinEAR) {
String key = keyToAppAndClientNameMap(appName, clientURIWithinEAR);
appAndClientNameToUserFriendlyContextRoot.remove(key);
}


/**
* Returns the user-friendly context root for the specified app client.
* <p>
Expand All @@ -371,19 +365,13 @@ public void removeContextRoot(final String appName,
* @param clientModuleURI
* @return
*/
public String userFriendlyContextRoot(final String appName,
final String clientModuleURI) {
return appAndClientNameToUserFriendlyContextRoot.get(
keyToAppAndClientNameMap(appName, clientModuleURI));
public String userFriendlyContextRoot(final String appName, final String clientModuleURI) {
String key = keyToAppAndClientNameMap(appName, clientModuleURI);
return appAndClientNameToUserFriendlyContextRoot.get(key);
}



private String keyToAppAndClientNameMap(final String appName,
final String moduleURIText) {
private String keyToAppAndClientNameMap(final String appName, final String moduleURIText) {
return appName + "/" + (moduleURIText == null ? appName : moduleURIText);
}



}
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, 2023 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
Expand Down Expand Up @@ -290,7 +290,7 @@ public abstract void createAndAddLibraryJNLPs(final AppClientDeployerHelper help
throws IOException;

public Map<String,Map<URI,StaticContent>> signingAliasToJar() {
return Collections.EMPTY_MAP;
return Collections.emptyMap();
}

public final DeploymentContext dc() {
Expand Down Expand Up @@ -480,7 +480,17 @@ protected void addClientPolicyFiles(final OutputJarArchive clientFacadeArchive)
}
}

protected abstract void copyFileToTopLevelJAR(final OutputJarArchive clientFacadeArchive, final File f, final String path) throws IOException;
/**
* Copies a file's contents to the top-level JAR generated by this deployment.
*
* @param clientFacadeArchive
* @param inputFile
* @param pathInJar
* @throws IOException
*/
protected abstract void copyFileToTopLevelJAR(final OutputJarArchive clientFacadeArchive, final File inputFile,
final String pathInJar) throws IOException;


protected final void generateAppClientFacade() throws IOException, URISyntaxException {
try (OutputJarArchive facadeArchive = new OutputJarArchive()) {
Expand Down Expand Up @@ -568,7 +578,7 @@ static void copy(ReadableArchive source, WritableArchive target, String entryNam
FileUtils.copy(is, os);
} catch (ZipException ze) {
// this is a duplicate...
return;
logger.log(Level.WARNING, "Putting of the entry failed for " + entryName, ze);
}
}
}
Expand All @@ -585,6 +595,7 @@ static void copyArchive(ReadableArchive source, WritableArchive target, Set<Stri
copy(source, target, entryName);
} catch (IOException ioe) {
// duplicate, we ignore
logger.log(Level.WARNING, "Putting of the entry failed for " + entryName, ioe);
}
}
}
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, 2023 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
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, 2023 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
Expand All @@ -24,9 +24,7 @@
import com.sun.enterprise.util.io.FileUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -125,29 +123,16 @@ protected void addTopLevelContentToClientFacade(OutputJarArchive facadeArchive)
public void createAndAddLibraryJNLPs(AppClientDeployerHelper helper, TokenHelper tHelper, Map<String, DynamicContent> dynamicContent) {
}

/**
* Copies a file's contents to the top-level JAR generated by this
* deployment.
*
* @param clientFacadeArchive
* @param f
* @param path
* @throws IOException
*/
@Override
protected void copyFileToTopLevelJAR(final OutputJarArchive clientFacadeArchive, final File f, final String path) throws IOException {
copyToArchive(f, clientFacadeArchive, path);
}

private void copyToArchive(final File inputFile, final OutputJarArchive outputArchive, final String pathInJar) throws IOException {
try (WritableArchiveEntry os = outputArchive.putNextEntry(pathInJar);
InputStream is = new FileInputStream(inputFile)) {
FileUtils.copy(is, os);
@Override
protected void copyFileToTopLevelJAR(final OutputJarArchive clientFacadeArchive, final File inputFile,
final String pathInJar) throws IOException {
try (WritableArchiveEntry os = clientFacadeArchive.putNextEntry(pathInJar)) {
FileUtils.copy(inputFile, os);
}
}



@Override
public FixedContent fixedContentWithinEAR(String uriString) {
/*
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, 2023 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
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, 2023 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
Expand Down Expand Up @@ -1297,12 +1297,12 @@ protected static File getTempFile(File fileOrDir) throws IOException {
* @param archive abstraction to use when adding the file
* @param filePath to the file to add
* @param entryName the entry name in the archive
* @throws IOException
*/
protected static void addFileToArchive(WritableArchive archive, String filePath, String entryName)
throws IOException {
try (FileInputStream is = new FileInputStream(new File(filePath));
WritableArchiveEntry os = archive.putNextEntry(entryName)) {
FileUtils.copy(is, os);
try (WritableArchiveEntry os = archive.putNextEntry(entryName)) {
FileUtils.copy(new File(filePath), os);
}
}

Expand All @@ -1313,6 +1313,7 @@ protected static void addFileToArchive(WritableArchive archive, String filePath,
* @param in jar file
* @param out jar file
* @param ignored entry names to not copy from to source jar file
* @throws IOException
*/
protected void copyJarElements(ReadableArchive in, WritableArchive out, Set<String> ignored) throws IOException {
Enumeration<String> entries = in.entries();
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, 2023 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
Expand Down Expand Up @@ -39,7 +39,7 @@
@Service
public class DescriptorArchivist {
@Inject
protected ArchivistFactory archivistFactory;
private ArchivistFactory archivistFactory;

@Inject
private Provider<ApplicationArchivist> archivistProvider;
Expand All @@ -53,13 +53,13 @@ public class DescriptorArchivist {
public void write(Application application, ReadableArchive in, WritableArchive out) throws IOException {
if (application.isVirtual()) {
ModuleDescriptor<BundleDescriptor> aModule = application.getModules().iterator().next();
Archivist<?> moduleArchivist = archivistFactory.getArchivist(aModule.getModuleType());
Archivist<BundleDescriptor> moduleArchivist = archivistFactory.getArchivist(aModule.getModuleType());
write(aModule.getDescriptor(), moduleArchivist, in, out);
} else {
// this is a real application.
// let's start by writing out all submodules deployment descriptors
for (ModuleDescriptor<BundleDescriptor> aModule : application.getModules()) {
Archivist<?> moduleArchivist = archivistFactory.getArchivist(aModule.getModuleType());
Archivist<BundleDescriptor> moduleArchivist = archivistFactory.getArchivist(aModule.getModuleType());
try (WritableArchive moduleArchive = out.createSubArchive(aModule.getArchiveUri());
ReadableArchive moduleArchive2 = in.getSubArchive(aModule.getArchiveUri())) {
write(aModule.getDescriptor(), moduleArchivist, moduleArchive2, moduleArchive);
Expand All @@ -80,9 +80,10 @@ public void write(Application application, ReadableArchive in, WritableArchive o
* @param archivist responsible for writing such bundle type
* @param in archive to read from
* @param out archive to write to
* @throws IOException
*/
protected void write(BundleDescriptor bundle, Archivist archivist, ReadableArchive in, WritableArchive out)
throws IOException {
protected void write(BundleDescriptor bundle, Archivist<BundleDescriptor> archivist, ReadableArchive in,
WritableArchive out) throws IOException {
archivist.setDescriptor(bundle);
archivist.writeDeploymentDescriptors(in, out);
}
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, 2023 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
Expand Down

0 comments on commit 8663099

Please sign in to comment.