Skip to content

Commit

Permalink
do not throw an exception if packages are optional
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed May 31, 2023
1 parent 10ef760 commit 3c43c13
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 41 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ Require-Extension: 7E673D15-D87C-41A6-8B5F1956528C605F;name=MySQL;label=MySQL;ve
17AB52DE-B300-A94B-E058BD978511E39E;name=S3;label=S3;version=2.0.0.107,
87FE44E5-179C-43A3-A87B3D38BEF4652E;name=EHCache;label=EHCache;version=2.10.0.36,
D46B46A9-A0E3-44E1-D972A04AC3A8DC10;name=Chart;label=CFChart;version=1.0.19.24,
FAD1E8CB-4F45-4184-86359145767C29DE;name=Hibernate;label=Hibernate;version=3.5.5.87,
FAD1E8CB-4F45-4184-86359145767C29DE;name=Hibernate;label=Hibernate;version=3.5.5.89,
66E312DD-D083-27C0-64189D16753FD6F0;name=PDF;label=PDF;version=1.1.0.19,
FAD67145-E3AE-30F8-1C11A6CCF544F0B7;name=Form;label=Form tags;version=1.0.0.10;since=5.1.0.21,
B737ABC4-D43F-4D91-8E8E973E37C40D1B;name=Image;label=Image;version=2.0.0.25;since=5.3.0.35-ALPHA,
Expand Down
112 changes: 74 additions & 38 deletions core/src/main/java/lucee/runtime/osgi/OSGiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ private boolean accept(String name) {
// this is needed in case old version of extensions are used, because lucee no longer bundles this
packageBundleMapping.put("org.bouncycastle", "bcprov");
packageBundleMapping.put("org.apache.log4j", "log4j");
packageBundleMapping.put("com.fasterxml.jackson.annotation", "com.fasterxml.jackson.core.jackson-annotations");
packageBundleMapping.put("org.apache.lucene.analysis", "apache.lucene");
}

/**
Expand Down Expand Up @@ -426,47 +428,52 @@ public static Bundle loadBundle(BundleFile bf) throws IOException, BundleExcepti
return _loadBundle(bc, bf.getFile());
}

public static Bundle loadBundleByPackage(String packageName, List<VersionDefinition> versionDefinitions, Set<Bundle> loadedBundles, boolean startIfNecessary,
public static Bundle loadBundleByPackage(String packageName, List<VersionDefinition> versionDefinitions, short resolution, Set<Bundle> loadedBundles, boolean startIfNecessary,
Set<String> parents) throws BundleException, IOException {
CFMLEngine engine = CFMLEngineFactory.getInstance();
CFMLEngineFactory factory = engine.getCFMLEngineFactory();
try {
CFMLEngine engine = CFMLEngineFactory.getInstance();
CFMLEngineFactory factory = engine.getCFMLEngineFactory();

// if part of bootdelegation we ignore
if (OSGiUtil.isPackageInBootelegation(packageName)) {
return null;
}
// if part of bootdelegation we ignore
if (OSGiUtil.isPackageInBootelegation(packageName)) {
return null;
}

// is it in jar directory but not loaded
File dir = factory.getBundleDirectory();
File[] children = dir.listFiles(JAR_EXT_FILTER);
List<PackageDefinition> pds;
for (File child: children) {
BundleFile bf = BundleFile.getInstance(child);
if (bf.isBundle()) {
if (parents.contains(toString(bf))) continue;
pds = toPackageDefinitions(bf.getExportPackage(), packageName, versionDefinitions);
if (pds != null && !pds.isEmpty()) {
Bundle b = exists(loadedBundles, bf);
if (b != null) {

if (startIfNecessary) _startIfNecessary(b, parents);
return null;
}
b = loadBundle(bf);
if (b != null) {
loadedBundles.add(b);
if (startIfNecessary) _startIfNecessary(b, parents);
return b;
// is it in jar directory but not loaded
File dir = factory.getBundleDirectory();
File[] children = dir.listFiles(JAR_EXT_FILTER);
List<PackageDefinition> pds;
for (File child: children) {
BundleFile bf = BundleFile.getInstance(child);
if (bf.isBundle()) {
if (parents.contains(toString(bf))) continue;
pds = toPackageDefinitions(bf.getExportPackage(), packageName, versionDefinitions);
if (pds != null && !pds.isEmpty()) {
Bundle b = exists(loadedBundles, bf);
if (b != null) {

if (startIfNecessary) _startIfNecessary(b, parents);
return null;
}
b = loadBundle(bf);
if (b != null) {
loadedBundles.add(b);
if (startIfNecessary) _startIfNecessary(b, parents);
return b;
}
}
}
}
}

String bn = packageBundleMapping.get(packageName);
if (!StringUtil.isEmpty(bn)) return loadBundle(bn, null, null, null, startIfNecessary);
String bn = packageBundleMapping.get(packageName);
if (!StringUtil.isEmpty(bn)) return loadBundle(bn, null, null, null, startIfNecessary, false);

for (Entry<String, String> e: packageBundleMapping.entrySet()) {
if (packageName.startsWith(e.getKey() + ".")) return loadBundle(e.getValue(), null, null, null, startIfNecessary);
for (Entry<String, String> e: packageBundleMapping.entrySet()) {
if (packageName.startsWith(e.getKey() + ".")) return loadBundle(e.getValue(), null, null, null, startIfNecessary, false);
}
}
catch (IOException | BundleException e) {
if (resolution == PackageQuery.RESOLUTION_REQUIRED) throw e;
}
return null;
}
Expand Down Expand Up @@ -1304,7 +1311,7 @@ private static void loadPackages(final Set<String> parents, final Set<Bundle> lo
while (it.hasNext()) {
pq = it.next();
try {
loadBundleByPackage(pq.getName(), pq.getVersionDefinitons(), loadedBundles, true, parents);
loadBundleByPackage(pq.getName(), pq.getVersionDefinitons(), pq.getResolution(), loadedBundles, true, parents);
}
catch (Exception _be) {
boolean printExceptions = Caster.toBooleanValue(SystemUtil.getSystemPropOrEnvVar("lucee.cli.printExceptions", null), false);
Expand Down Expand Up @@ -1472,16 +1479,25 @@ public static List<PackageQuery> getRequiredPackages(Bundle bundle) throws Bundl
Entry<String, String> e;
String value;
PackageQuery pd;
short resolution = PackageQuery.RESOLUTION_REQUIRED;
while (it.hasNext()) {
r = it.next();
pd = null;
Iterator<Entry<String, String>> iit = r.getDirectives().entrySet().iterator();
inner: while (iit.hasNext()) {
e = iit.next();
if (!"filter".equals(e.getKey())) continue;
value = e.getValue();
pd = toPackageQuery(value);
if (pd != null) rtn.add(pd);

// resolution
if ("resolution".equals(e.getKey())) PackageQuery.toResolution(e.getValue(), PackageQuery.RESOLUTION_REQUIRED);

// filter
if (!"filter".equals(e.getKey())) {
value = e.getValue();
pd = toPackageQuery(value);
if (pd != null) rtn.add(pd);
}
}
if (pd != null && resolution != PackageQuery.RESOLUTION_REQUIRED) pd.setResolution(resolution);
}
return rtn;
}
Expand Down Expand Up @@ -1670,13 +1686,33 @@ public String getOpAsString() {
}

public static class PackageQuery {
public static final short RESOLUTION_REQUIRED = 1;
public static final short RESOLUTION_DYNAMIC = 2;
public static final short RESOLUTION_OPTIONAL = 4;
private final String name;
private List<VersionDefinition> versions = new ArrayList<OSGiUtil.VersionDefinition>();
private short resolution = RESOLUTION_REQUIRED;

public PackageQuery(String name) {
this.name = name;
}

public void setResolution(short resolution) {
this.resolution = resolution;
}

public short getResolution() {
return resolution;
}

public static int toResolution(String strResolution, int defaultValue) {
if (!StringUtil.isEmpty(strResolution, true)) {
if ("optional".equalsIgnoreCase(strResolution)) return RESOLUTION_OPTIONAL;
if ("dynamic".equalsIgnoreCase(strResolution)) return RESOLUTION_DYNAMIC;
}
return defaultValue;
}

public void addVersion(int op, String version, boolean not) throws BundleException {
versions.add(new VersionDefinition(OSGiUtil.toVersion(version), op, not));
}
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="5.4.0.64-SNAPSHOT"/>
<property name="version" value="5.4.0.65-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>5.4.0.64-SNAPSHOT</version>
<version>5.4.0.65-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 3c43c13

Please sign in to comment.