@NotNull public static String getProjectRepresentationName( @NotNull String targetProjectPath, @Nullable String rootProjectPath) { if (rootProjectPath == null) { File rootProjectDir = new File(targetProjectPath); if (rootProjectDir.isFile()) { rootProjectDir = rootProjectDir.getParentFile(); } return rootProjectDir.getName(); } File rootProjectDir = new File(rootProjectPath); if (rootProjectDir.isFile()) { rootProjectDir = rootProjectDir.getParentFile(); } File targetProjectDir = new File(targetProjectPath); if (targetProjectDir.isFile()) { targetProjectDir = targetProjectDir.getParentFile(); } StringBuilder buffer = new StringBuilder(); for (File f = targetProjectDir; f != null && !FileUtil.filesEqual(f, rootProjectDir); f = f.getParentFile()) { buffer.insert(0, f.getName()).insert(0, ":"); } buffer.insert(0, rootProjectDir.getName()); return buffer.toString(); }
@Test public void testCreateBoot() throws Exception { File homeJDK = new File(System.getProperty("java.home")).getParentFile(); if (!new File(homeJDK, "lib/tools.jar").exists()) return; // Skip pure jre File bootJDK = SystemInfo.isMac ? homeJDK.getParentFile().getParentFile() : homeJDK; String verStr = System.getProperty("java.version"); boolean macNonStandardJDK = SystemInfo.isMac && !new File(bootJDK, "Contents/Home").exists(); JdkBundle bundle = macNonStandardJDK ? JdkBundle.createBoot(false) : // the test is run under jdk with non-standard layout JdkBundle.createBoot(); assertNotNull(bundle); assertTrue(bundle.isBoot()); assertFalse(bundle.isBundled()); assertTrue( FileUtil.filesEqual(bundle.getAbsoluteLocation(), macNonStandardJDK ? homeJDK : bootJDK)); Pair<Version, Integer> verUpdate = bundle.getVersionUpdate(); assertNotNull(verUpdate); final String evalVerStr = verUpdate.first.toString() + "_" + verUpdate.second.toString(); assertTrue(evalVerStr + " is not the same with " + verStr, verStr.contains(evalVerStr)); }
private void cleanupBrokenData() { close(true); //noinspection TestOnlyProblems final File currentDataDir = getCurrentDataDir(); final File currentDataContextDir = getCurrentDataContextDir(); final File[] files = currentDataDir.listFiles(); if (files != null) { for (File file : files) { if (!FileUtil.filesEqual(file, currentDataContextDir)) { FileUtil.delete(file); } } } else { FileUtil.delete(currentDataDir); } }
@Test public void testJdk6OnMac() throws Exception { if (!SystemInfo.isMac) return; boolean testPassed; File[] jdk6Files = null; File standardJdk6LocationDirectory = new File(STANDARD_JDK_6_LOCATION_ON_MAC_OS_X); if (standardJdk6LocationDirectory.exists()) { jdk6Files = findJdkInDirectory(standardJdk6LocationDirectory, "1.6.0"); } if (jdk6Files == null || jdk6Files.length == 0) { File standardJdkLocationDirectory = new File(STANDARD_JDK_LOCATION_ON_MAC_OS_X); jdk6Files = findJdkInDirectory(standardJdkLocationDirectory, "1.6.0"); } if (jdk6Files == null || jdk6Files.length == 0) { // We have not found any jdk6 installation. Nothing to test. return; } JdkBundleList jdkBundleList = new JdkBundleList(); jdkBundleList.addBundlesFromLocation( STANDARD_JDK_6_LOCATION_ON_MAC_OS_X, JDK6_VERSION, JDK6_VERSION); jdkBundleList.addBundlesFromLocation( STANDARD_JDK_LOCATION_ON_MAC_OS_X, JDK6_VERSION, JDK6_VERSION); ArrayList<JdkBundle> bundles = jdkBundleList.toArrayList(); for (File file : jdk6Files) { testPassed = false; for (JdkBundle bundle : bundles) { if (FileUtil.filesEqual(bundle.getAbsoluteLocation(), file)) { testPassed = true; break; } } assertTrue(file.getAbsolutePath() + " has not been found among jdk bundles.", testPassed); } }
private static void copy( @NotNull File src, @NotNull File dest, ConfigImportSettings settings, File oldInstallationHome) throws IOException { src = src.getCanonicalFile(); dest = dest.getCanonicalFile(); if (!src.isDirectory()) { throw new IOException( ApplicationBundle.message( "config.import.invalid.directory.error", src.getAbsolutePath())); } if (!dest.isDirectory()) { throw new IOException( ApplicationBundle.message( "config.import.invalid.directory.error", dest.getAbsolutePath())); } if (FileUtil.filesEqual(src, dest)) { return; } FileUtil.ensureExists(dest); File[] childFiles = src.listFiles( new FilenameFilter() { @Override public boolean accept(@NotNull File dir, @NotNull String name) { // Don't copy plugins just imported. They're most probably incompatible with newer // idea version. return !StringUtil.startsWithChar(name, '.') && !name.equals(PLUGINS_PATH); } }); if (childFiles == null || childFiles.length == 0) { return; } for (File from : childFiles) { File to = new File(dest, from.getName()); if (from.isDirectory()) { FileUtil.copyDir(from, to, false); } else { FileUtil.copy(from, to); } } File plugins = new File(src, PLUGINS_PATH); if (!loadOldPlugins(plugins, dest) && SystemInfo.isMac) { File oldPluginsDir = getOldPath( oldInstallationHome, settings, PathManager.PROPERTY_PLUGINS_PATH, new Function<String, String>() { @Override public String fun(String pathSelector) { return PathManager.getDefaultPluginPathFor(pathSelector); } }); if (oldPluginsDir == null) { // e.g. installation home referred to config home. Try with default selector, same as config // name oldPluginsDir = new File(PathManager.getDefaultPluginPathFor(src.getName())); } loadOldPlugins(oldPluginsDir, dest); } }