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