下面列出了怎么用com.intellij.openapi.application.PathManager的API类实例代码及写法,或者点击链接到github查看源代码。
private static String findTestDataPath() {
if (new File(PathManager.getHomePath() + "/contrib").isDirectory()) {
// started from IntelliJ IDEA Ultimate project
return FileUtil.toSystemIndependentName(PathManager.getHomePath() + "/contrib/flutter-intellij/testData");
}
final File f = new File("testData");
if (f.isDirectory()) {
// started from flutter plugin project
return FileUtil.toSystemIndependentName(f.getAbsolutePath());
}
final String parentPath = PathUtil.getParentPath(PathManager.getHomePath());
if (new File(parentPath + "/intellij-plugins").isDirectory()) {
// started from IntelliJ IDEA Community Edition + flutter plugin project
return FileUtil.toSystemIndependentName(parentPath + "/intellij-plugins/flutter-intellij/testData");
}
if (new File(parentPath + "/contrib").isDirectory()) {
// started from IntelliJ IDEA Community + flutter plugin project
return FileUtil.toSystemIndependentName(parentPath + "/contrib/flutter-intellij/testData");
}
return "";
}
private static String findTestDataPath() {
if (new File(PathManager.getHomePath() + "/contrib").isDirectory()) {
// started from IntelliJ IDEA Ultimate project
return FileUtil.toSystemIndependentName(PathManager.getHomePath() + "/contrib/flutter-intellij/testData");
}
final File f = new File("testData");
if (f.isDirectory()) {
// started from flutter plugin project
return FileUtil.toSystemIndependentName(f.getAbsolutePath());
}
final String parentPath = PathUtil.getParentPath(PathManager.getHomePath());
if (new File(parentPath + "/intellij-plugins").isDirectory()) {
// started from IntelliJ IDEA Community Edition + flutter plugin project
return FileUtil.toSystemIndependentName(parentPath + "/intellij-plugins/flutter-intellij/testData");
}
if (new File(parentPath + "/contrib").isDirectory()) {
// started from IntelliJ IDEA Community + flutter plugin project
return FileUtil.toSystemIndependentName(parentPath + "/contrib/flutter-intellij/testData");
}
return "";
}
private static void showSetupIssues(ImmutableList<String> issues, BlazeContext context) {
logger.warn(
String.format(
"Issues collecting info from C++ compiler. Showing first few out of %d:\n%s",
issues.size(), Iterables.limit(issues, 25)));
IssueOutput.warn("Issues collecting info from C++ compiler (click to see logs)")
.navigatable(
new Navigatable() {
@Override
public void navigate(boolean b) {
ShowFilePathAction.openFile(new File(PathManager.getLogPath(), "idea.log"));
}
@Override
public boolean canNavigate() {
return true;
}
@Override
public boolean canNavigateToSource() {
return false;
}
})
.submit(context);
}
public static ReactiveTfvcClientHost create(Project project, Path clientPath) throws ExecutionException {
SingleThreadScheduler scheduler = new SingleThreadScheduler(defineNestedLifetime(project), "ReactiveTfClient Scheduler");
ReactiveClientConnection connection = new ReactiveClientConnection(scheduler);
try {
Path logDirectory = Paths.get(PathManager.getLogPath(), "ReactiveTfsClient");
Path clientHomeDir = clientPath.getParent().getParent();
GeneralCommandLine commandLine = ProcessHelper.patchPathEnvironmentVariable(
getClientCommandLine(clientPath, connection.getPort(), logDirectory, clientHomeDir));
ProcessHandler processHandler = new OSProcessHandler(commandLine);
connection.getLifetime().onTerminationIfAlive(processHandler::destroyProcess);
processHandler.addProcessListener(createProcessListener(connection));
processHandler.startNotify();
return new ReactiveTfvcClientHost(connection);
} catch (Throwable t) {
connection.terminate();
throw t;
}
}
/**
* Filter out all jars imported to the project with the exception of
* jars on the JDK path, IntelliJ installation paths, and plugin installation path,
* because Pants is already exporting all the runtime classpath in manifest.jar.
*
* Exception applies during unit test of this plugin because "JUnit" and "com.intellij"
* plugin lives under somewhere under ivy, whereas during normal usage, they are covered
* by `homePath`.
*
*
* @param params JavaParameters
* @return a set of paths that should be allowed to passed to the test runner.
*/
@NotNull
private Set<String> calculatePathsAllowed(JavaParameters params) {
String homePath = PathManager.getHomePath();
String pluginPath = PathManager.getPluginsPath();
Set<String> pathsAllowed = Sets.newHashSet(homePath, pluginPath);
if (ApplicationManager.getApplication().isUnitTestMode()) {
// /Users/yic/.ivy2/pants/com.intellij.sdk.community/idea_rt/jars/idea_rt-latest.jar ->
// /Users/yic/.ivy2/pants/com.intellij.sdk.community/
Optional.ofNullable(PluginManagerCore.getPlugin(PluginId.getId("com.intellij")))
.map(s -> s.getPath().getParentFile().getParentFile().getParentFile().getAbsolutePath())
.ifPresent(pathsAllowed::add);
// At this point we know junit plugin is already enabled.
// //Users/yic/.ivy2/pants/com.intellij.junit-plugin/junit-rt/jars/junit-rt-latest.jar ->
// /Users/yic/.ivy2/pants/com.intellij.junit-plugin/
Optional.ofNullable(PluginManagerCore.getPlugin(PluginId.getId("JUnit")))
.map(s -> s.getPath().getParentFile().getParentFile().getParentFile().getAbsolutePath())
.ifPresent(pathsAllowed::add);
}
return pathsAllowed;
}
@Override
protected void setUp() throws Exception {
VfsRootAccess.allowRootAccess(getTestRootDisposable(), PathManager.getConfigPath());
super.setUp();
File settingsFile = MavenWorkspaceSettingsComponent.getInstance(myProject).getSettings().generalSettings.getEffectiveGlobalSettingsIoFile();
if (settingsFile != null) {
VfsRootAccess.allowRootAccess(getTestRootDisposable(), settingsFile.getAbsolutePath());
}
}
private boolean classLoader() {
synchronized (this) {
String path = PathManager.getPluginsPath() + File.separator + "leetcode-editor" + File.separator + "natives" + File.separator;
if (!new File(path, "icudtl.dat").exists()
&& !new File(path, "jcef_app.app").exists()) {
return Boolean.FALSE;
} else {
JourneyLoader.getJourneyClassLoader(path);
return Boolean.TRUE;
}
}
}
@NotNull
private static File getTestProjectsRootDirPath() {
// It is important that the testData directory be marked as a test resource so its content is copied to out/test dir
String testDataPath = PathManager.getHomePathFor(ProjectWrangler.class);
// "out/test" is defined by IntelliJ but we may want to change the module or root dir of the test projects.
testDataPath = Paths.get(testDataPath, "out", "test", MODULE_NAME).toString();
testDataPath = toCanonicalPath(toSystemDependentName(testDataPath));
return new File(testDataPath, PROJECT_DIR);
}
@SuppressWarnings("Duplicates")
private static String findTestDataPath() {
if (new File(PathManager.getHomePath() + "/contrib").isDirectory()) {
// started from IntelliJ IDEA Ultimate project
return FileUtil.toSystemIndependentName(PathManager.getHomePath() + "/contrib/Dart/testData");
}
final File f = new File("testData");
if (f.isDirectory()) {
// started from 'Dart-plugin' project
return FileUtil.toSystemIndependentName(f.getAbsolutePath());
}
final String parentPath = PathUtil.getParentPath(PathManager.getHomePath());
if (new File(parentPath + "/intellij-plugins").isDirectory()) {
// started from IntelliJ IDEA Community Edition + Dart Plugin project
return FileUtil.toSystemIndependentName(parentPath + "/intellij-plugins/Dart/testData");
}
if (new File(parentPath + "/contrib").isDirectory()) {
// started from IntelliJ IDEA Community + Dart Plugin project
return FileUtil.toSystemIndependentName(parentPath + "/contrib/Dart/testData");
}
return "";
}
@SuppressWarnings("Duplicates")
private static String findTestDataPath() {
if (new File(PathManager.getHomePath() + "/contrib").isDirectory()) {
// started from IntelliJ IDEA Ultimate project
return FileUtil.toSystemIndependentName(PathManager.getHomePath() + "/contrib/Dart/testData");
}
final File f = new File("testData");
if (f.isDirectory()) {
// started from 'Dart-plugin' project
return FileUtil.toSystemIndependentName(f.getAbsolutePath());
}
final String parentPath = PathUtil.getParentPath(PathManager.getHomePath());
if (new File(parentPath + "/intellij-plugins").isDirectory()) {
// started from IntelliJ IDEA Community Edition + Dart Plugin project
return FileUtil.toSystemIndependentName(parentPath + "/intellij-plugins/Dart/testData");
}
if (new File(parentPath + "/contrib").isDirectory()) {
// started from IntelliJ IDEA Community + Dart Plugin project
return FileUtil.toSystemIndependentName(parentPath + "/contrib/Dart/testData");
}
return "";
}
public void setLog4jProperties() {
File file =
new File(
PathManager.getPluginsPath()
+ "/tmc-plugin-intellij/lib/tmc-plugin-intellij.jar");
if (file.exists()) {
setPluginLog();
} else {
setDevLog();
}
}
private void setPluginLog() {
String jarPath =
PathManager.getPluginsPath() + "/tmc-plugin-intellij/lib/tmc-plugin-intellij.jar";
try {
JarFile jar = new JarFile(jarPath);
JarEntry entry = jar.getJarEntry("log4j.properties");
InputStream is = jar.getInputStream(entry);
PropertyConfigurator.configure(is);
} catch (IOException e) {
e.printStackTrace();
}
}
@Nullable
private static String getPlatformApiPath() {
String platformJar = PathManager.getJarPathForClass(Application.class);
if (platformJar == null) {
return null;
}
File jarFile = new File(platformJar).getAbsoluteFile();
File jarDir = jarFile.getParentFile();
if (jarDir == null) {
return null;
}
if (jarDir.getName().equals("lib")) {
// Building against IDE distribution.
// root/ <- we want this
// |-lib/
// | `-openapi.jar (jarFile)
// `-plugins/
return jarDir.getParent();
} else if (jarDir.getName().equals("core-api")) {
// Building against source.
// tools/idea/ <- we want this
// |-platform/
// | `-core-api/
// | `-libcore-api.jar (jarFile)
// `-plugins/
File platformDir = jarDir.getParentFile();
if (platformDir != null && platformDir.getName().equals("platform")) {
return platformDir.getParent();
}
}
return null;
}
@Override
protected void before() throws Throwable {
if (!isRunThroughBlaze()) {
// If running directly through the IDE, don't try to load plugins from the sandbox environment
// Instead we'll rely on the slightly more hermetic module classpath
oldPluginPathProperty = System.getProperty(PathManager.PROPERTY_PLUGINS_PATH);
System.setProperty(PathManager.PROPERTY_PLUGINS_PATH, "/dev/null");
}
testRootDisposable = Disposer.newDisposable();
}
@Override
protected void after() {
if (oldPluginPathProperty != null) {
System.setProperty(PathManager.PROPERTY_PLUGINS_PATH, oldPluginPathProperty);
} else {
System.clearProperty(PathManager.PROPERTY_PLUGINS_PATH);
}
try {
Disposer.dispose(testRootDisposable);
cleanupSwingDataStructures();
cleanupDeleteOnExitHookList();
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
@Nullable
private static String getPlatformApiPath() {
String platformJar = PathManager.getJarPathForClass(Application.class);
if (platformJar == null) {
return null;
}
File jarFile = new File(platformJar).getAbsoluteFile();
File jarDir = jarFile.getParentFile();
if (jarDir == null) {
return null;
}
if (jarDir.getName().equals("lib")) {
// Building against IDE distribution.
// root/ <- we want this
// |-lib/
// | `-openapi.jar (jarFile)
// `-plugins/
return jarDir.getParent();
} else if (jarDir.getName().equals("core-api")) {
// Building against source.
// tools/idea/ <- we want this
// |-platform/
// | `-core-api/
// | `-libcore-api.jar (jarFile)
// `-plugins/
File platformDir = jarDir.getParentFile();
if (platformDir != null && platformDir.getName().equals("platform")) {
return platformDir.getParent();
}
}
return null;
}
public static File findTestPath(String folderName) {
final File f = new File(folderName);
if (f.exists()) {
return f.getAbsoluteFile();
}
return new File(PathManager.getHomePath() + "/plugins/pants/" + folderName);
}
private static String findTestDataPath() {
File f = new File("testData");
if (f.exists()) {
return f.getAbsolutePath();
}
return PathManager.getHomePath() + "/plugins/haxe/testData";
}
private static String findTestDataPath() {
File f = new File("src/test/resources");
if (f.exists()) {
return f.getAbsolutePath();
}
return PathManager.getHomePath() + "/plugins/thrift/testData";
}
private String getBasePath() {
if (myBasePath == null) {
String s = PathManager.getPluginsPath() + File.separatorChar + CPP_TOOLS;
if (!new File(s).exists()) {
s = PathManager.getPreinstalledPluginsPath() + File.separatorChar + CPP_TOOLS;
if (!new File(s).exists()) {
throw new RuntimeException("Plugin home is not found");
}
}
myBasePath = s;
}
return myBasePath;
}
@Override
protected void collectAllowedRoots(final List<String> roots) {
roots.add(myJdkHome);
roots.addAll(collectRootsInside(myJdkHome));
roots.add(PathManager.getConfigPath());
}
public static String getBinaryFileDirPath() {
return Paths.get(PathManager.getConfigPath()).toString() + File.separator + Const.BINARY_FILES_DIR_NAME + File.separator;
}
@NotNull
public static String getRootDirPath() {
return Paths.get(PathManager.getConfigPath()).toString() + File.separator + Const.PACKAGE_TEMPLATES_DIR_NAME + File.separator;
}
public static String getBinaryFilesCacheDefaultDir() {
return PathManager.getSystemPath()
+ File.separator + Const.CACHE_DIR_NAME
+ File.separator + Const.BINARY_FILES_CACHE_DIR_NAME;
}
@NotNull
private String getLibrariesPath() {
return Paths.get(PathManager.getConfigPath()).toString() + File.separator + Const.LIBRARIES_DIR_NAME + File.separator;
}
private static File getProjectConfigurationDir() {
return new File(PathManager.getSystemPath(), "blaze/projects").getAbsoluteFile();
}
WebExperimentSyncer(String pluginName) {
this.pluginName = pluginName;
cacheFile =
Paths.get(PathManager.getSystemPath(), "blaze", pluginName + ".experiments.cache.dat")
.toFile();
}
@Override
public File[] getExportFiles() {
return new File[]{new File(PathManager.getOptionsPath() + File.separatorChar + "buck.xml")};
}
@NotNull
public static String getApplicationFolder() {
return PathManager.getConfigPath() + "/php-toolbox";
}
private String getOptionsFilePath() {
String optionsPath = PathManager.getOptionsPath();
return optionsPath + File.separator + "pluginErrorReportSubmitter.xml";
}