Skip to content

Commit

Permalink
reduce loadBundles methods and use a list to hold packages
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Oct 31, 2023
1 parent 3ded759 commit a89c3f9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 33 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/lucee/commons/lang/ClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static Class<?> loadClassByBundle(String className, BundleDefinition bund
try {
if (relatedBundles != null) {
for (BundleDefinition rb: relatedBundles) {
rb.getBundle(id, addional, true);
rb.getBundle(id, addional, true, false);
}
}
return bundle.getBundle(id, addional, true, versionOnlyMattersForDownload).loadClass(className);
Expand All @@ -183,7 +183,7 @@ public static Class<?> loadClassByBundle(String className, BundleDefinition bund
if (OSGiUtil.resolveBundleLoadingIssues(ThreadLocalPageContext.getConfig(), outer)) {
if (relatedBundles != null) {
for (BundleDefinition rb: relatedBundles) {
rb.getBundle(id, addional, true);
rb.getBundle(id, addional, true, false);
}
}
return bundle.getBundle(id, addional, true, versionOnlyMattersForDownload).loadClass(className);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2404,7 +2404,7 @@ public static JDBCDriver[] _loadJDBCDrivers(ConfigServerImpl configServer, Confi
cd = getClassDefinition(driver, "", config.getIdentification());
if (StringUtil.isEmpty(cd.getClassName()) && !StringUtil.isEmpty(cd.getName())) {
try {
Bundle bundle = OSGiUtil.loadBundle(cd.getName(), cd.getVersion(), config.getIdentification(), null, false);
Bundle bundle = OSGiUtil.loadBundle(cd.getName(), cd.getVersion(), config.getIdentification(), null, false, false, true, null);
String cn = JDBCDriver.extractClassName(bundle);
cd = new ClassDefinitionImpl(config.getIdentification(), cn, cd.getName(), cd.getVersion());
}
Expand Down
12 changes: 10 additions & 2 deletions core/src/main/java/lucee/runtime/osgi/BundleInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class BundleInfo implements Serializable {
private Map<String, Object> headers;

private Map<String, PackageDefinition> exportPackageAsMap;
private List<PackageDefinition> exportPackageAsList;
private static Map<String, BundleInfo> bundles = new HashMap<String, BundleInfo>();

public static BundleInfo getInstance(String id, InputStream is, boolean closeStream) throws IOException, BundleException {
Expand Down Expand Up @@ -161,9 +162,13 @@ public Collection<PackageDefinition> getExportPackageAsCollection() {
if (exportPackageAsMap == null) {
synchronized (this) {
if (exportPackageAsMap == null) {
if (StringUtil.isEmpty(exportPackage, true)) return (exportPackageAsMap = new HashMap<>()).values();
if (StringUtil.isEmpty(exportPackage, true)) {
exportPackageAsList = new ArrayList<>();
return (exportPackageAsMap = new HashMap<>()).values();
}

exportPackageAsMap = new HashMap<>();
exportPackageAsList = new ArrayList<>();
int len = exportPackage.length();
char c;
boolean inline = false;
Expand All @@ -177,17 +182,20 @@ public Collection<PackageDefinition> getExportPackageAsCollection() {
}
else if (!inline && c == ',') {
pd = toPackageDefinition(sb.toString());
exportPackageAsList.add(pd);
exportPackageAsMap.put(pd.getName(), pd);

sb = new StringBuilder();
}
else sb.append(c);
}
pd = toPackageDefinition(sb.toString());
exportPackageAsList.add(pd);
exportPackageAsMap.put(pd.getName(), pd);
}
}
}
return exportPackageAsMap.values();
return exportPackageAsList; // exportPackageAsMap.values();
}

public boolean hasMatchingExportPackage(PackageQuery pq) {
Expand Down
32 changes: 4 additions & 28 deletions core/src/main/java/lucee/runtime/osgi/OSGiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -621,37 +621,17 @@ public static Bundle loadBundle(final BundleRange bundleRange, Identification id
}
}

public static Bundle loadBundle(String name, Version version, Identification id, List<Resource> addional, boolean startIfNecessary) throws BundleException {
return loadBundle(name, version, id, addional, startIfNecessary, false, true, null);
}

public static Bundle loadBundle(String name, Version version, Identification id, List<Resource> addional, boolean startIfNecessary, boolean versionOnlyMattersForDownload)
throws BundleException {
return loadBundle(name, version, id, addional, startIfNecessary, versionOnlyMattersForDownload, true, null);
}

public static Bundle loadBundle(String name, Version version, Identification id, List<Resource> addional, boolean startIfNecessary, boolean versionOnlyMattersForDownload,
boolean downloadIfNecessary) throws BundleException {
return loadBundle(name, version, id, addional, startIfNecessary, versionOnlyMattersForDownload, versionOnlyMattersForDownload, null);
}

public static Bundle loadBundle(String name, Version version, Identification id, List<Resource> addional, boolean startIfNecessary, boolean versionOnlyMattersForDownload,
boolean downloadIfNecessary, Boolean printExceptions) throws BundleException {
try {
return _loadBundle(name, version, id, addional, startIfNecessary, null, versionOnlyMattersForDownload, downloadIfNecessary, printExceptions);
return _loadBundle(new BundleRange(name.trim()).setVersionRange(new BundleRange.VersionRange().add(version, VersionDefinition.EQ)), id, addional, startIfNecessary,
null, versionOnlyMattersForDownload, downloadIfNecessary, printExceptions);
}
catch (StartFailedException sfe) {
throw sfe.bundleException;
}
}

public static Bundle _loadBundle(String name, final Version version, Identification id, List<Resource> addional, boolean startIfNecessary, Set<String> parents,
boolean versionOnlyMattersForDownload, boolean downloadIfNecessary, Boolean printExceptions) throws BundleException, StartFailedException {
name = name.trim();
return _loadBundle(new BundleRange(name).setVersionRange(new BundleRange.VersionRange().add(version, VersionDefinition.EQ)), id, addional, startIfNecessary, parents,
versionOnlyMattersForDownload, downloadIfNecessary, printExceptions);
}

public static Bundle _loadBundle(final BundleRange bundleRange, Identification id, List<Resource> addional, boolean startIfNecessary, Set<String> parents,
boolean versionOnlyMattersForDownload, boolean downloadIfNecessary, Boolean printExceptions) throws BundleException, StartFailedException {
CFMLEngine engine = CFMLEngineFactory.getInstance();
Expand Down Expand Up @@ -2006,13 +1986,9 @@ public Bundle getLoadedBundle() {
return bundle;
}

public Bundle getBundle(Identification id, List<Resource> addional, boolean startIfNecessary) throws BundleException {
return getBundle(id, addional, startIfNecessary, false);
}

public Bundle getBundle(Identification id, List<Resource> addional, boolean startIfNecessary, boolean versionOnlyMattersForDownload) throws BundleException {
if (bundle == null) {
bundle = OSGiUtil.loadBundle(name, getVersion(), id, addional, startIfNecessary, versionOnlyMattersForDownload);
bundle = OSGiUtil.loadBundle(name, getVersion(), id, addional, startIfNecessary, versionOnlyMattersForDownload, true, null);
}
return bundle;
}
Expand All @@ -2031,7 +2007,7 @@ public Bundle getBundle(Config config, List<Resource> addional) throws BundleExc
public Bundle getBundle(Config config, List<Resource> addional, boolean versionOnlyMattersForDownload) throws BundleException {
if (bundle == null) {
config = ThreadLocalPageContext.getConfig(config);
bundle = OSGiUtil.loadBundle(name, getVersion(), config == null ? null : config.getIdentification(), addional, false, versionOnlyMattersForDownload);
bundle = OSGiUtil.loadBundle(name, getVersion(), config == null ? null : config.getIdentification(), addional, false, versionOnlyMattersForDownload, true, null);
}
return bundle;
}
Expand Down

0 comments on commit a89c3f9

Please sign in to comment.