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

Don't extract referenced bundles for Maven runtime classpath #926

Merged
merged 1 commit into from
Oct 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
6 changes: 3 additions & 3 deletions m2e-maven-runtime/org.eclipse.m2e.maven.runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@
com.google.inject.*;provider=m2e;mandatory:=provider,\
io.takari.*;provider=m2e;mandatory:=provider
Import-Package: \
org.slf4j;resolution:=optional;version="[1.7.0,3.0.0)",\
org.slf4j.spi;resolution:=optional;version="[1.7.0,3.0.0)",\
org.slf4j.helpers;resolution:=optional;version="[1.7.0,3.0.0)",\
org.slf4j;version="[1.7.31,3.0.0)",\
org.slf4j.spi;version="[1.7.31,3.0.0)",\
org.slf4j.helpers;version="[1.7.31,3.0.0)",\
javax.inject;version="1.0.0",\
javax.annotation;version="[1.2.0,2.0.0)",\
javax.annotation.sql;version="[1.2.0,2.0.0)",\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.stream.Collectors;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
Expand All @@ -38,19 +39,27 @@
* @since 1.5
*/
public class Bundles {
private Bundles() {
}

private static final Logger log = LoggerFactory.getLogger(Bundles.class);

public static List<String> getClasspathEntries(Bundle bundle) {
log.debug("getClasspathEntries(Bundle={})", bundle);
Set<String> cp = new LinkedHashSet<>();
if(inDevelopmentMode()) {
cp.addAll(getDevClassPath(bundle.getSymbolicName()));
Collections.addAll(cp, getDevClassPath(bundle.getSymbolicName()));
}
cp.addAll(parseBundleClasspath(bundle));
List<String> entries = new ArrayList<>();
for(String cpe : cp) {
String entry = getClasspathEntryPath(bundle, ".".equals(cpe) ? "/" : cpe);
String entry;
if(".".equals(cpe)) {
entry = FileLocator.getBundleFileLocation(bundle)
.orElseThrow(() -> new NoSuchElementException("Unable to locate bundle:" + bundle)).toString();
} else {
entry = getClasspathEntryPath(bundle, cpe);
}
if(entry != null) {
log.debug("\tEntry:{}", entry);
entries.add(entry);
Expand All @@ -64,7 +73,7 @@ private static List<String> parseBundleClasspath(Bundle bundle) {
try {
ManifestElement[] cpEntries = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, header);
if(cpEntries != null) {
return Arrays.stream(cpEntries).map(ManifestElement::getValue).collect(Collectors.toList());
return Arrays.stream(cpEntries).map(ManifestElement::getValue).toList();
}
} catch(BundleException ex) {
log.warn("Could not parse bundle classpath of {}", bundle, ex);
Expand Down Expand Up @@ -97,12 +106,12 @@ public static String getClasspathEntryPath(Bundle bundle, String cp) {
}

@SuppressWarnings("restriction")
public static List<String> getDevClassPath(String bundleSymbolicName) {
return Arrays.asList(org.eclipse.core.internal.runtime.DevClassPathHelper.getDevClassPath(bundleSymbolicName));
private static String[] getDevClassPath(String bundleSymbolicName) {
return org.eclipse.core.internal.runtime.DevClassPathHelper.getDevClassPath(bundleSymbolicName);
}

@SuppressWarnings("restriction")
public static boolean inDevelopmentMode() {
private static boolean inDevelopmentMode() {
return org.eclipse.core.internal.runtime.DevClassPathHelper.inDevelopmentMode();
}
}