public static IdeaPluginDescriptorImpl[] loadDescriptors(@Nullable StartupProgress progress) { if (ClassUtilCore.isLoadingOfExternalPluginsDisabled()) { return IdeaPluginDescriptorImpl.EMPTY_ARRAY; } final List<IdeaPluginDescriptorImpl> result = new ArrayList<IdeaPluginDescriptorImpl>(); int pluginsCount = countPlugins(PathManager.getPluginsPath()) + countPlugins(PathManager.getPreinstalledPluginsPath()); loadDescriptors(PathManager.getPluginsPath(), result, progress, pluginsCount); Application application = ApplicationManager.getApplication(); boolean fromSources = false; if (application == null || !application.isUnitTestMode()) { int size = result.size(); loadDescriptors(PathManager.getPreinstalledPluginsPath(), result, progress, pluginsCount); fromSources = size == result.size(); } loadDescriptorsFromProperty(result); loadDescriptorsFromClassPath(result, fromSources ? progress : null); IdeaPluginDescriptorImpl[] pluginDescriptors = result.toArray(new IdeaPluginDescriptorImpl[result.size()]); try { Arrays.sort(pluginDescriptors, new PluginDescriptorComparator(pluginDescriptors)); } catch (Exception e) { prepareLoadingPluginsErrorMessage( IdeBundle.message("error.plugins.were.not.loaded", e.getMessage())); getLogger().info(e); return findCorePlugin(pluginDescriptors); } return pluginDescriptors; }
private static synchronized boolean checkSystemFolders() { final String configPath = PathManager.getConfigPath(); if (configPath == null || !new File(configPath).isDirectory()) { showError( "Invalid config path", "Config path '" + configPath + "' is invalid.\n" + "If you have modified the 'idea.config.path' property please make sure it is correct,\n" + "otherwise please re-install the IDE."); return false; } final String systemPath = PathManager.getSystemPath(); if (systemPath == null || !new File(systemPath).isDirectory()) { showError( "Invalid system path", "System path '" + systemPath + "' is invalid.\n" + "If you have modified the 'idea.system.path' property please make sure it is correct,\n" + "otherwise please re-install the IDE."); return false; } return true; }
@Override public boolean isBundled() { if (PluginManagerCore.CORE_PLUGIN_ID.equals(myId.getIdString())) { return true; } String path; try { // to avoid paths like this /home/kb/IDEA/bin/../config/plugins/APlugin path = getPath().getCanonicalPath(); } catch (IOException e) { path = getPath().getAbsolutePath(); } Application app = ApplicationManager.getApplication(); if (app != null && app.isInternal()) { if (path.startsWith( PathManager.getHomePath() + File.separator + "out" + File.separator + "classes")) { return true; } if (app.isUnitTestMode() && !path.startsWith(PathManager.getPluginsPath() + File.separatorChar)) { return true; } } return path.startsWith(PathManager.getPreInstalledPluginsPath()); }
private static void attachJdkAnnotations(Sdk jdk) { LocalFileSystem lfs = LocalFileSystem.getInstance(); VirtualFile root = null; if (root == null) { // community idea under idea root = lfs.findFileByPath( FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/java/jdkAnnotations"); } if (root == null) { // idea under idea root = lfs.findFileByPath( FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/community/java/jdkAnnotations"); } if (root == null) { // build root = VirtualFileManager.getInstance() .findFileByUrl( "jar://" + FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/lib/jdkAnnotations.jar!/"); } if (root == null) { LOG.error( "jdk annotations not found in: " + FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/lib/jdkAnnotations.jar!/"); return; } SdkModificator modificator = jdk.getSdkModificator(); modificator.removeRoot(root, AnnotationOrderRootType.getInstance()); modificator.addRoot(root, AnnotationOrderRootType.getInstance()); modificator.commitChanges(); }
private static void invalidateIndex() { LOG.info("Marking VFS as corrupted"); final File indexRoot = PathManager.getIndexRoot(); if (indexRoot.exists()) { final String[] children = indexRoot.list(); if (children != null && children.length > 0) { // create index corruption marker only if index directory exists and is non-empty // It is incorrect to consider non-existing indices "corrupted" FileUtil.createIfDoesntExist(new File(PathManager.getIndexRoot(), "corruption.marker")); } } }
@Override protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) throws Exception { moduleBuilder.setLanguageLevel(LanguageLevel.JDK_1_8); moduleBuilder.addLibraryJars( "guava-17.0.jar", PathManager.getHomePath().replace(File.separatorChar, '/') + "/community/lib/", "guava-17.0.jar"); moduleBuilder.addLibraryJars( "guava-17.0.jar-2", PathManager.getHomePath().replace(File.separatorChar, '/') + "/lib/", "guava-17.0.jar"); moduleBuilder.addJdk(IdeaTestUtil.getMockJdk18Path().getPath()); }
@Nullable private static File getExecutable() { String execPath = System.getProperty(PROPERTY_WATCHER_EXECUTABLE_PATH); if (execPath != null) return new File(execPath); String execName = getExecutableName(false); if (execName == null) return null; return FileUtil.findFirstThatExist( FileUtil.join(PathManager.getBinPath(), execName), FileUtil.join(PathManager.getHomePath(), "community", "bin", getExecutableName(true)), FileUtil.join(PathManager.getBinPath(), getExecutableName(true))); }
public static void configureMPS(String... plugins) { String mpsInternal = System.getProperty("mps.internal"); System.setProperty("idea.is.internal", mpsInternal == null ? "false" : mpsInternal); System.setProperty("idea.no.jre.check", "true"); // Not necessary to set this property for loading listed plugins - see // PluginManager.loadDescriptors() System.setProperty("idea.load.plugins", "false"); System.setProperty("idea.platform.prefix", "Idea"); StringBuffer pluginPath = new StringBuffer(); File pluginDir = new File(com.intellij.openapi.application.PathManager.getPreinstalledPluginsPath()); for (File pluginFolder : pluginDir.listFiles()) { if (pluginPath.length() > 0) { pluginPath.append(File.pathSeparator); } pluginPath.append(pluginFolder.getPath()); } System.setProperty("plugin.path", pluginPath.toString()); // Value of this property is comma-separated list of plugin IDs intended to load by platform System.setProperty("idea.load.plugins.id", StringUtils.join(plugins, ",")); if (!cachesInvalidated) { FSRecords.invalidateCaches(); cachesInvalidated = true; } try { IdeaTestApplication.getInstance(null); } catch (Exception e) { throw new RuntimeException(e); } }
public static String getCommunityPath() { final String homePath = PathManager.getHomePath(); if (new File(homePath, "community").exists()) { return homePath + File.separatorChar + "community"; } return homePath; }
private void checkFsSanity() { try { String path = myProject.getProjectFilePath(); if (path == null || FileUtil.isAncestor(PathManager.getConfigPath(), path, true)) { return; } boolean actual = FileUtil.isFileSystemCaseSensitive(path); LOG.info(path + " case-sensitivity: " + actual); if (actual != SystemInfo.isFileSystemCaseSensitive) { int prefix = SystemInfo.isFileSystemCaseSensitive ? 1 : 0; // IDE=true -> FS=false -> prefix='in' String title = ApplicationBundle.message("fs.case.sensitivity.mismatch.title"); String text = ApplicationBundle.message("fs.case.sensitivity.mismatch.message", prefix); Notifications.Bus.notify( new Notification( Notifications.SYSTEM_MESSAGES_GROUP_ID, title, text, NotificationType.WARNING, NotificationListener.URL_OPENING_LISTENER), myProject); } } catch (FileNotFoundException e) { LOG.warn(e); } }
@Nullable private ClassLoader createGreclipseLoader(@Nullable String jar) { if (StringUtil.isEmpty(jar)) return null; if (jar.equals(myGreclipseJar)) { return myGreclipseLoader; } try { URL[] urls = { new File(jar).toURI().toURL(), new File(ObjectUtils.assertNotNull(PathManager.getJarPathForClass(GreclipseMain.class))) .toURI() .toURL() }; ClassLoader loader = new URLClassLoader(urls, null); Class.forName("org.eclipse.jdt.internal.compiler.batch.Main", false, loader); myGreclipseJar = jar; myGreclipseLoader = loader; return loader; } catch (Exception e) { LOG.error(e); return null; } }
public void removeCoverageSuite(final CoverageSuite suite) { final String fileName = suite.getCoverageDataFileName(); boolean deleteTraces = suite.isTracingEnabled(); if (!FileUtil.isAncestor(PathManager.getSystemPath(), fileName, false)) { String message = "Would you like to delete file \'" + fileName + "\' "; if (deleteTraces) { message += "and traces directory \'" + FileUtil.getNameWithoutExtension(new File(fileName)) + "\' "; } message += "on disk?"; if (Messages.showYesNoDialog( myProject, message, CommonBundle.getWarningTitle(), Messages.getWarningIcon()) == Messages.YES) { deleteCachedCoverage(fileName, deleteTraces); } } else { deleteCachedCoverage(fileName, deleteTraces); } myCoverageSuites.remove(suite); if (myCurrentSuitesBundle != null && myCurrentSuitesBundle.contains(suite)) { CoverageSuite[] suites = myCurrentSuitesBundle.getSuites(); suites = ArrayUtil.remove(suites, suite); chooseSuitesBundle(suites.length > 0 ? new CoverageSuitesBundle(suites) : null); } }
public static void attachJdkAnnotations(@NotNull SdkModificator modificator) { LocalFileSystem lfs = LocalFileSystem.getInstance(); List<String> pathsChecked = new ArrayList<>(); // community idea under idea String path = FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/java/jdkAnnotations"; VirtualFile root = lfs.findFileByPath(path); pathsChecked.add(path); if (root == null) { // idea under idea path = FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/community/java/jdkAnnotations"; root = lfs.findFileByPath(path); pathsChecked.add(path); } if (root == null) { // build String url = "jar://" + FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/lib/jdkAnnotations.jar!/"; root = VirtualFileManager.getInstance().findFileByUrl(url); pathsChecked.add( FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/lib/jdkAnnotations.jar"); } if (root == null) { String msg = "Paths checked:\n"; for (String p : pathsChecked) { File file = new File(p); msg += "Path: '" + p + "' " + (file.exists() ? "Found" : "Not found") + "; directory children: " + Arrays.toString(file.getParentFile().listFiles()) + "\n"; } LOG.error("JDK annotations not found", msg); return; } OrderRootType annoType = AnnotationOrderRootType.getInstance(); modificator.removeRoot(root, annoType); modificator.addRoot(root, annoType); }
private static String getHomeDirectory() { return new File( PathManager.getResourceRoot( JetParsingTest.class, "/org/jetbrains/jet/parsing/JetParsingTest.class")) .getParentFile() .getParentFile() .getParent(); }
public static File getCompilerSystemDirectory() { //noinspection HardCodedStringLiteral final String systemPath = ourSystemPath != null ? ourSystemPath : (ourSystemPath = PathUtil.getCanonicalPath(PathManager.getSystemPath())); return new File(systemPath, "compiler"); }
@NotNull private File getStorageDirectory() { String dirName = myProject.getName() + "." + Integer.toHexString(myProject.getPresentableUrl().hashCode()); File dir = new File(PathManager.getSystemPath(), "refs/" + dirName); FileUtil.createDirectory(dir); return dir; }
public static String getTestDataRoot() { String homePath = PathManager.getHomePath(); File candidate = new File(homePath, "community/RegExpSupport"); if (candidate.isDirectory()) { return new File(candidate, "testData").getPath(); } return new File(homePath, "RegExpSupport/testData").getPath(); }
private static VirtualFile findJar(String name) { String path = PathManager.getHomePath() + '/' + name; VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path); assert file != null : "not found: " + path; VirtualFile jar = JarFileSystem.getInstance().getJarRootForLocalFile(file); assert jar != null : "no .jar for: " + path; return jar; }
private static File getJettyLauncherFile() { final String binDir = PathManager.getPluginsPath() + File.separator + JettyManager.PLUGIN_NAME + File.separator + BIN_DIR; return new File(binDir, getDefaultJettyLauncherFileName()); }
protected void createLibrary(ModifiableRootModel model, final String name, final String path) { final Library.ModifiableModel modifiableModel = model.getModuleLibraryTable().createLibrary(name).getModifiableModel(); final VirtualFile home = LocalFileSystem.getInstance().refreshAndFindFileByPath(PathManager.getHomePath() + path); modifiableModel.addRoot(home, OrderRootType.CLASSES); modifiableModel.commit(); }
@NotNull public static List<String> getDisabledPlugins() { if (ourDisabledPlugins == null) { ourDisabledPlugins = new ArrayList<String>(); if (System.getProperty("idea.ignore.disabled.plugins") == null && !isUnitTestMode()) { loadDisabledPlugins(PathManager.getConfigPath(), ourDisabledPlugins); } } return ourDisabledPlugins; }
private JBZipFile getTasksArchive(String postfix) throws IOException { String configPath = PathManager.getConfigPath(true); File tasksFolder = new File(configPath, TASKS_FOLDER); if (!tasksFolder.exists()) { //noinspection ResultOfMethodCallIgnored tasksFolder.mkdir(); } String projectName = myProject.getName(); return new JBZipFile(new File(tasksFolder, projectName + postfix)); }
@NotNull public static String baseTestDiscoveryPathForProject(Project project) { return PathManager.getSystemPath() + File.separator + "testDiscovery" + File.separator + project.getName() + "." + project.getLocationHash(); }
protected void doTest(@NonNls String text, @Nullable String expected) { String result = printTokens(text, 0); if (expected != null) { assertSameLines(expected, result); } else { assertSameLinesWithFile( PathManager.getHomePath() + "/" + getDirPath() + "/" + getTestName(true) + ".txt", result); } }
@Nullable public static String locateAnnotationsJar(@NotNull Module module) { String jarName; String libPath; if (EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(module) .isAtLeast(LanguageLevel.JDK_1_8)) { jarName = "annotations-java8.jar"; libPath = new File(PathManager.getHomePath(), "redist").getAbsolutePath(); } else { jarName = "annotations.jar"; libPath = PathManager.getLibPath(); } final LocateLibraryDialog dialog = new LocateLibraryDialog( module, libPath, jarName, QuickFixBundle.message("add.library.annotations.description")); return dialog.showAndGet() ? dialog.getResultingLibraryPath() : null; }
public ShelveChangesManager(final Project project, final MessageBus bus) { myProject = project; myBus = bus; if (!project.isDefault()) { myFileProcessor = new CompoundShelfFileProcessor("shelf"); } else { myFileProcessor = new CompoundShelfFileProcessor( new StreamProvider[] {}, PathManager.getConfigPath() + File.separator + "shelf"); } }
protected void doFileTest(@NonNls String fileExt) { String fileName = PathManager.getHomePath() + "/" + getDirPath() + "/" + getTestName(true) + "." + fileExt; String text = ""; try { String fileText = FileUtil.loadFile(new File(fileName)); text = StringUtil.convertLineSeparators(shouldTrim() ? fileText.trim() : fileText); } catch (IOException e) { fail("can't load file " + fileName + ": " + e.getMessage()); } doTest(text); }
@Override protected void setUp() throws Exception { super.setUp(); myNestedFormLoader = new MyNestedFormLoader(); final String swingPath = PathUtil.getJarPathForClass(AbstractButton.class); java.util.List<URL> cp = new ArrayList<URL>(); appendPath(cp, JBTabbedPane.class); appendPath(cp, TIntObjectHashMap.class); appendPath(cp, UIUtil.class); appendPath(cp, SystemInfoRt.class); appendPath(cp, ApplicationManager.class); appendPath(cp, PathManager.getResourceRoot(this.getClass(), "/messages/UIBundle.properties")); appendPath(cp, PathManager.getResourceRoot(this.getClass(), "/RuntimeBundle.properties")); appendPath(cp, GridLayoutManager.class); // forms_rt appendPath(cp, DataProvider.class); myClassFinder = new MyClassFinder( new URL[] {new File(swingPath).toURI().toURL()}, cp.toArray(new URL[cp.size()])); }
@SuppressWarnings("UseOfSystemOutOrSystemErr") private static synchronized void printOrder(Loader loader, String url, Resource resource) { if (!ourDumpOrder) return; if (!ourOrderedUrls.add(url)) return; String home = FileUtil.toSystemIndependentName(PathManager.getHomePath()); try { ourOrderSize += resource.getContentLength(); } catch (IOException e) { e.printStackTrace(System.out); } if (ourOrder == null) { final File orderFile = new File(PathManager.getBinPath() + File.separator + "order.txt"); try { if (!FileUtil.ensureCanCreateFile(orderFile)) return; ourOrder = new PrintStream(new FileOutputStream(orderFile, true)); ShutDownTracker.getInstance() .registerShutdownTask( new Runnable() { public void run() { ourOrder.close(); System.out.println(ourOrderSize); } }); } catch (IOException e) { return; } } if (ourOrder != null) { String jarURL = FileUtil.toSystemIndependentName(loader.getBaseURL().getFile()); jarURL = StringUtil.trimStart(jarURL, "file:/"); if (jarURL.startsWith(home)) { jarURL = jarURL.replaceFirst(home, ""); jarURL = StringUtil.trimEnd(jarURL, "!/"); ourOrder.println(url + ":" + jarURL); } } }
public class JUnitMembersSearcherTest extends AbstractSearcherTest { private static final LightProjectDescriptor junitProjectDescriptor = new JetJdkAndLibraryProjectDescriptor( new File( PathManager.getHomePath().replace(File.separatorChar, '/') + "/lib/junit-4.10.jar")); public void testJunit3() throws IOException { doJUnit3test(); } public void testJunit4() throws IOException { doJUnit4test(); } public void testJunit4Alias() throws IOException { doJUnit4test(); } private void doJUnit3test() throws IOException { myFixture.configureByFile(getFileName()); List<String> directives = InTextDirectivesUtils.findListWithPrefix( "// CLASS: ", FileUtil.loadFile(new File(getPathToFile()))); assertFalse("Specify CLASS directive in test file", directives.isEmpty()); String superClassName = directives.get(0); PsiClass psiClass = getPsiClass(superClassName); checkResult(ClassInheritorsSearch.search(psiClass, getProjectScope(), false)); } private void doJUnit4test() throws IOException { myFixture.configureByFile(getFileName()); List<String> directives = InTextDirectivesUtils.findListWithPrefix( "// ANNOTATION: ", FileUtil.loadFile(new File(getPathToFile()))); assertFalse("Specify ANNOTATION directive in test file", directives.isEmpty()); String annotationClassName = directives.get(0); PsiClass psiClass = getPsiClass(annotationClassName); checkResult(AnnotatedMembersSearch.search(psiClass, getProjectScope())); } @Override protected String getTestDataPath() { return new File(PluginTestCaseBase.getTestDataPathBase(), "/search/junit").getPath() + File.separator; } @NotNull @Override protected LightProjectDescriptor getProjectDescriptor() { return junitProjectDescriptor; } }