Skip to content

Commit

Permalink
-Solve issue with Sling Starter (use bundle location as fallback)
Browse files Browse the repository at this point in the history
  • Loading branch information
Imad ELALI committed Mar 5, 2021
1 parent 913025b commit 0c64059
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.neva.felix.webconsole.plugins.search.core;

import com.google.common.collect.ImmutableMap;
import com.neva.felix.webconsole.plugins.search.rest.BundleClassesServlet;
import com.neva.felix.webconsole.plugins.search.rest.BundleDownloadServlet;
import com.neva.felix.webconsole.plugins.search.utils.BundleUtils;
import com.google.common.collect.ImmutableMap;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
Expand All @@ -13,38 +13,44 @@

public class BundleInfo implements Serializable {

private final String symbolicName;
private final String symbolicName;

private final String name;
private final String name;
private final String location;

private final long id;
private final long id;

private final Map<String, String> context;
private final Map<String, String> context;

public BundleInfo(Bundle bundle, BundleContext context) {
this.symbolicName = bundle.getSymbolicName();
this.name = (String) bundle.getHeaders().get(Constants.BUNDLE_NAME);
this.id = bundle.getBundleId();
this.context = ImmutableMap.of(
"consoleUrl", BundleUtils.consolePath(context, bundle),
"bundleDownloadUrl", BundleDownloadServlet.url(context, bundle),
"bundleClassesUrl", BundleClassesServlet.url(context, bundle)
);
}
public BundleInfo(Bundle bundle, BundleContext context) {
this.symbolicName = bundle.getSymbolicName();
this.name = (String) bundle.getHeaders().get(Constants.BUNDLE_NAME);
this.id = bundle.getBundleId();
this.location = bundle.getLocation();
this.context = ImmutableMap.of(
"consoleUrl", BundleUtils.consolePath(context, bundle),
"bundleDownloadUrl", BundleDownloadServlet.url(context, bundle),
"bundleClassesUrl", BundleClassesServlet.url(context, bundle)
);
}

public String getSymbolicName() {
return symbolicName;
}
public String getSymbolicName() {
return symbolicName;
}

public String getName() {
return name;
}
public String getName() {
return name;
}

public long getId() {
return id;
}

public long getId() {
return id;
public String getLocation() {
return location;
}

public Map<String, String> getContext() {
return context;
}
return context;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -70,22 +69,20 @@ public File findJar(String bundleId) {
}

public File findJar(Long bundleId) {
return findJar(findDir(bundleId));
File jar = findJar(findDir(bundleId));
if (jar == null) {
//If jat not found through storage dir, try to resolve bundle location (Sling starter sources jars from maven repository)

This comment has been minimized.

Copy link
@pun-ky

pun-ky Mar 5, 2021

Contributor

Typo..

Nice 🙂

Bundle bundle = findBundle(bundleId);
return new File(StringUtils.replace(bundle.getLocation(), "reference:file:", ""));
}
return jar;
}

public File findJar(File bundleDir) {
if (bundleDir.exists()) {
List<File> files = FluentIterable.from(FileUtils.listFiles(bundleDir, new String[]{JAR_EXT}, true)).filter(new Predicate<File>() {
@Override
public boolean apply(File file) {
return file.getName().equalsIgnoreCase(BUNDLE_JAR_FILE);
}
}).toSortedList(new Comparator<File>() {
@Override
public int compare(File f1, File f2) {
return f2.getAbsolutePath().compareTo(f1.getAbsolutePath());
}
});
List<File> files = FluentIterable.from(FileUtils.listFiles(bundleDir, new String[]{JAR_EXT}, true))
.filter(file -> file.getName().equalsIgnoreCase(BUNDLE_JAR_FILE))
.toSortedList((f1, f2) -> f2.getAbsolutePath().compareTo(f1.getAbsolutePath()));

return Iterables.getFirst(files, null);
}
Expand Down Expand Up @@ -147,7 +144,7 @@ public String decompileClass(Decompilers type, Long bundleId, String className)
return decompileClass(type, findJar(bundleId), className);
}

public String decompileClass(Decompilers type,File jar, String className) {
public String decompileClass(Decompilers type, File jar, String className) {
String source = StringUtils.EMPTY;
try {
source = DecompilerFactory.get(type).decompile(jar, className, false);
Expand Down Expand Up @@ -259,9 +256,11 @@ private BundleClass obtainClassMetadata(BundleClass clazz, String classPid) {
}

public Bundle findBundle(String id) {
final Long longId = Longs.tryParse(id);
return findBundle(Longs.tryParse(id));
}

return longId != null ? context.getBundle(longId) : null;
public Bundle findBundle(Long id) {
return id != null ? context.getBundle(id) : null;
}

public Iterable<Bundle> findBundles(List<String> ids) {
Expand Down

0 comments on commit 0c64059

Please sign in to comment.