mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 02:09:44 +02:00
Merge remote-tracking branch
'origin/GP-1338_ryanmkurtz_PR-3454_zZeck_pydevLocateFix' (Closes #3453, Closes #3454)
This commit is contained in:
commit
45cd8dc795
4 changed files with 28 additions and 29 deletions
|
@ -16,24 +16,21 @@
|
|||
package ghidradev.ghidraprojectcreator.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.naming.OperationNotSupportedException;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.*;
|
||||
import org.eclipse.jdt.core.IClasspathEntry;
|
||||
import org.eclipse.jdt.core.IJavaProject;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
|
||||
import ghidradev.Activator;
|
||||
|
||||
|
@ -158,30 +155,30 @@ public class PyDevUtils {
|
|||
* @throws CoreException if there was a problem searching for the PyDev source directory.
|
||||
*/
|
||||
public static File getPyDevSrcDir() throws CoreException {
|
||||
String eclipsePath = Platform.getInstallLocation().getURL().getFile();
|
||||
|
||||
List<File> searchDirs = new ArrayList<>();
|
||||
searchDirs.add(new File(eclipsePath, "plugins"));
|
||||
searchDirs.add(new File(eclipsePath, "dropins"));
|
||||
|
||||
for (File searchRoot : searchDirs) {
|
||||
try (Stream<Path> paths = Files.walk(Paths.get(searchRoot.toURI()))) {
|
||||
Optional<File> pysrcDir = paths.filter(
|
||||
Files::isDirectory)
|
||||
.filter(p -> p.endsWith("pysrc"))
|
||||
.map(p -> p.toFile())
|
||||
.filter(f -> f.getParentFile().getName().startsWith("org.python.pydev"))
|
||||
.findFirst();
|
||||
if (pysrcDir.isPresent()) {
|
||||
return pysrcDir.get();
|
||||
Bundle[] bundles =
|
||||
FrameworkUtil.getBundle(PyDevUtilsInternal.class).getBundleContext().getBundles();
|
||||
|
||||
Bundle pydevCoreBundle = Stream.of(bundles)
|
||||
.filter(bundle -> bundle.getSymbolicName().contains("org.python.pydev.core"))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (pydevCoreBundle != null) {
|
||||
try {
|
||||
URL pydevDirUrl = FileLocator.toFileURL(pydevCoreBundle.getEntry("/"));
|
||||
URI pydevDirUri =
|
||||
new URI(pydevDirUrl.getProtocol(), pydevDirUrl.getPath(), null).normalize();
|
||||
Path pysrcDir = Paths.get(pydevDirUri).resolve("pysrc");
|
||||
if (Files.exists(pysrcDir)) {
|
||||
return pysrcDir.toFile();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (Exception e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
|
||||
IStatus.ERROR, "Problem searching for PyDev source directory", e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue