Skip to content

Commit

Permalink
Support source code lookup for classes not on the project classpath
Browse files Browse the repository at this point in the history
  • Loading branch information
guw committed Oct 21, 2023
1 parent 3ea0c15 commit e4be25a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bundles/com.salesforce.bazel.eclipse.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@
id="com.salesforce.bazel.eclipse.core.classpath.launching.runtimeResolver">
</runtimeClasspathEntryResolver>
</extension>
<extension
point="org.eclipse.jdt.launching.sourceContainerResolvers">
<resolver
class="com.salesforce.bazel.eclipse.core.classpath.BazelSourceContainerResolver">
</resolver>
</extension>

<extension
point="org.eclipse.core.contenttype.contentTypes">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*-
* Copyright (c) 2023 Salesforce and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Salesforce - adapted from M2E, JDT or other Eclipse project
*/
package com.salesforce.bazel.eclipse.core.classpath;

import java.io.File;
import java.util.Collection;
import java.util.Set;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.containers.ExternalArchiveSourceContainer;
import org.eclipse.jdt.launching.sourcelookup.advanced.ISourceContainerResolver;

import com.salesforce.bazel.eclipse.core.util.jar.SourceJarFinder;

/**
* A resolver to find source code for Bazel classpath container entries
*/
public class BazelSourceContainerResolver implements ISourceContainerResolver {

@Override
public Collection<ISourceContainer> resolveSourceContainers(File classesLocation, IProgressMonitor monitor)
throws CoreException {

var sourceJar = SourceJarFinder.findSourceJar(classesLocation.toPath());
if (sourceJar != null) {
return Set.of(new ExternalArchiveSourceContainer(sourceJar.toOSString(), true));
}

return null;
}

}

0 comments on commit e4be25a

Please sign in to comment.