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

Support scanning applibs #23957

Merged
merged 2 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -17,6 +17,11 @@

package com.sun.enterprise.deployment.util;

import static com.sun.enterprise.deployment.deploy.shared.Util.toURI;
import static java.util.Collections.emptyList;
import static org.glassfish.deployment.common.DeploymentUtils.getManifestLibraries;
import static org.glassfish.loader.util.ASClassLoaderUtil.getAppLibDirLibrariesAsList;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -25,7 +30,6 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
import java.util.Properties;
Expand All @@ -42,7 +46,6 @@
import org.glassfish.api.deployment.archive.ReadableArchive;
import org.glassfish.deployment.common.DeploymentContextImpl;
import org.glassfish.deployment.common.DeploymentProperties;
import org.glassfish.deployment.common.DeploymentUtils;
import org.glassfish.deployment.common.Descriptor;
import org.glassfish.deployment.common.ModuleDescriptor;
import org.glassfish.deployment.common.RootDeploymentDescriptor;
Expand All @@ -55,7 +58,9 @@
import org.glassfish.internal.data.ApplicationRegistry;
import org.glassfish.internal.deployment.ExtendedDeploymentContext;
import org.glassfish.internal.deployment.SnifferManager;
import org.glassfish.loader.util.ASClassLoaderUtil;
import org.glassfish.logging.annotation.LogMessageInfo;
import org.glassfish.logging.annotation.LogMessagesResourceBundle;
import org.glassfish.logging.annotation.LoggerInfo;
import org.xml.sax.SAXException;

import com.sun.enterprise.config.serverbeans.Applications;
Expand All @@ -70,18 +75,13 @@
import com.sun.enterprise.deployment.WebBundleDescriptor;
import com.sun.enterprise.deployment.archivist.Archivist;
import com.sun.enterprise.deployment.archivist.ArchivistFactory;
import com.sun.enterprise.deployment.deploy.shared.Util;
import com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile;
import com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFileFor;
import com.sun.enterprise.deployment.io.DescriptorConstants;
import com.sun.enterprise.deployment.node.XMLElement;
import com.sun.enterprise.deployment.xml.TagNames;
import com.sun.enterprise.util.LocalStringManagerImpl;

import org.glassfish.logging.annotation.LogMessageInfo;
import org.glassfish.logging.annotation.LoggerInfo;
import org.glassfish.logging.annotation.LogMessagesResourceBundle;

/**
* Utility class for convenience methods
*
Expand Down Expand Up @@ -151,46 +151,47 @@ public static synchronized Logger getDefaultLogger() {
}

public static boolean equals(Object a, Object b) {
return ((a == null && b == null) ||
(a != null && a.equals(b)));
return ((a == null && b == null) || (a != null && a.equals(b)));
}

public static List<URI> getLibraryJarURIs(BundleDescriptor bundleDesc, ReadableArchive archive) throws Exception {
if (bundleDesc == null) {
return Collections.emptyList();
return emptyList();
}

ModuleDescriptor moduleDesc = bundleDesc.getModuleDescriptor();
Application app = ((BundleDescriptor)moduleDesc.getDescriptor()).getApplication();
return getLibraryJarURIs(app, archive);
}

public static List<URI> getLibraryJarURIs(Application app, ReadableArchive archive) throws Exception {
List<URL> libraryURLs = new ArrayList<>();
List<URI> libraryURIs = new ArrayList<>();

// add libraries referenced through manifest
libraryURLs.addAll(DeploymentUtils.getManifestLibraries(archive));
// Add libraries referenced through manifest
List<URL> libraryURLs = new ArrayList<>(getManifestLibraries(archive));
ReadableArchive parentArchive = archive.getParentArchive();
if (parentArchive == null) {
return Collections.emptyList();
return emptyList();
}

File appRoot = new File(parentArchive.getURI());
// add libraries jars inside application lib directory
libraryURLs.addAll(ASClassLoaderUtil.getAppLibDirLibrariesAsList(appRoot, app.getLibraryDirectory(), null));
// Add libraries jars inside application lib directory
libraryURLs.addAll(getAppLibDirLibrariesAsList(appRoot, app.getLibraryDirectory(), null));
for (URL url : libraryURLs) {
libraryURIs.add(Util.toURI(url));
libraryURIs.add(toURI(url));
}

return libraryURIs;
}

public static BundleDescriptor getCurrentBundleForContext(DeploymentContext context) {
ExtendedDeploymentContext ctx = (ExtendedDeploymentContext)context;
Application application = context.getModuleMetaData(Application.class);
if (application == null) {
// this can happen for non-JavaEE type deployment. e.g., issue 15869
// This can happen for non-JavaEE type deployment. e.g., issue 15869
return null;
}

if (ctx.getParentContext() == null) {
if (application.isVirtual()) {
// standalone module
Expand All @@ -199,6 +200,7 @@ public static BundleDescriptor getCurrentBundleForContext(DeploymentContext cont
// top level
return application;
}

// a sub module of ear
return application.getModuleByUri(ctx.getModuleUri());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022, 2022 Contributors to the Eclipse Foundation.
* Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -748,16 +749,24 @@ private void processBdasForAppLibs(ReadableArchive archive, DeploymentContext co
try {
// Each appLib in context.getAppLibs is a URI of the form
// "file:/glassfish/runtime/trunk/glassfish7/glassfish/domains/domain1/lib/applibs/mylib.jar"
List<URI> appLibs = context.getAppLibs();
Set<String> installedLibraries = getInstalledLibraries(archive);

if (!isAnyEmpty(appLibs, installedLibraries)) {
for (URI appLib : appLibs) {
for (String installedLibrary : installedLibraries) {
if (appLib.getPath().endsWith(installedLibrary)) {
// parentArchiveAppLibs are the app libs in the manifest of the root archive and any embedded
// archives.
List<URI> rootArchiveAppLibs = context.getAppLibs();

// Each appLib in getInstalledLibraries(archive) is a String of the form
// "mylib.jar"
// currentArchiveAppLibNames are the app libs from the manifest of only the current archive.
// This may therefor be a subset of the rootArchiveAppLibs when the root archive has multiple
// embedded libs with their own app lib references in their manifest.
Set<String> currentArchiveAppLibNames = getInstalledLibraries(archive);

if (!isAnyEmpty(rootArchiveAppLibs, currentArchiveAppLibNames)) {
for (URI rootArchiveAppLib : rootArchiveAppLibs) {
for (String currentArchiveAppLibName : currentArchiveAppLibNames) {
if (rootArchiveAppLib.getPath().endsWith(currentArchiveAppLibName)) {
ReadableArchive libArchive = null;
try {
libArchive = archiveFactory.openArchive(appLib);
libArchive = archiveFactory.openArchive(rootArchiveAppLib);
if (libArchive.exists(META_INF_BEANS_XML)) {
libBdas.add(new RootBeanDeploymentArchive(
libArchive,
Expand Down
Loading