public String getPerUserPluginDirectoryName() { String name; if (pluginDir == null) { name = getPluginID(); } else { name = new File(pluginDir).getName(); } String str = new File(new File(SystemProperties.getUserPath(), "plugins"), name).getAbsolutePath(); if (pluginDir == null) { return (str); } try { if (new File(pluginDir).getCanonicalPath().equals(new File(str).getCanonicalPath())) { return (pluginDir); } } catch (Throwable e) { } return (str); }
public String getReportText() { final Element rootElement = new Element("root"); rootElement.setAttribute("isBackward", String.valueOf(!myForward)); final List<PsiFile> files = new ArrayList<PsiFile>(myDependencies.keySet()); Collections.sort( files, new Comparator<PsiFile>() { @Override public int compare(PsiFile f1, PsiFile f2) { final VirtualFile virtualFile1 = f1.getVirtualFile(); final VirtualFile virtualFile2 = f2.getVirtualFile(); if (virtualFile1 != null && virtualFile2 != null) { return virtualFile1.getPath().compareToIgnoreCase(virtualFile2.getPath()); } return 0; } }); for (PsiFile file : files) { final Element fileElement = new Element("file"); fileElement.setAttribute("path", file.getVirtualFile().getPath()); for (PsiFile dep : myDependencies.get(file)) { Element depElement = new Element("dependency"); depElement.setAttribute("path", dep.getVirtualFile().getPath()); fileElement.addContent(depElement); } rootElement.addContent(fileElement); } PathMacroManager.getInstance(myProject).collapsePaths(rootElement); return JDOMUtil.writeDocument(new Document(rootElement), SystemProperties.getLineSeparator()); }
@NotNull public static String expandUserHome(@NotNull String path) { if (path.startsWith("~/") || path.startsWith("~\\")) { path = SystemProperties.getUserHome() + path.substring(1); } return path; }
/** Return a checksum that changes when something in the properties changes. */ public long getChecksum() { if (defaultProps == null) { return lastModified(); } return lastModified() + defaultProps.lastModified(); }
private void exportParameters() { synchronized (exported_parameters) { if (!exported_parameters_dirty) { return; } exported_parameters_dirty = false; try { TreeMap<String, String> tm = new TreeMap<String, String>(); Set<String> exported_keys = new HashSet<String>(); for (String[] entry : exported_parameters.values()) { String key = entry[0]; String value = entry[1]; exported_keys.add(key); if (value != null) { tm.put(key, value); } } for (Map.Entry<String, String> entry : imported_parameters.entrySet()) { String key = entry.getKey(); if (!exported_keys.contains(key)) { tm.put(key, entry.getValue()); } } File parent_dir = new File(SystemProperties.getUserPath()); File props = new File(parent_dir, "exported_params.properties"); PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(props), "UTF-8")); try { for (Map.Entry<String, String> entry : tm.entrySet()) { pw.println(entry.getKey() + "=" + entry.getValue()); } } finally { pw.close(); } } catch (Throwable e) { e.printStackTrace(); } } }
// null means we were unable to get roots, so do not check access @Nullable @TestOnly private static Set<String> allowedRoots() { if (insideGettingRoots) return null; Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); if (openProjects.length == 0) return null; final Set<String> allowed = new THashSet<String>(); allowed.add(FileUtil.toSystemIndependentName(PathManager.getHomePath())); try { URL outUrl = Application.class.getResource("/"); String output = new File(outUrl.toURI()).getParentFile().getParentFile().getPath(); allowed.add(FileUtil.toSystemIndependentName(output)); } catch (URISyntaxException ignored) { } allowed.add(FileUtil.toSystemIndependentName(SystemProperties.getJavaHome())); allowed.add( FileUtil.toSystemIndependentName(new File(FileUtil.getTempDirectory()).getParent())); allowed.add(FileUtil.toSystemIndependentName(System.getProperty("java.io.tmpdir"))); allowed.add(FileUtil.toSystemIndependentName(SystemProperties.getUserHome())); for (Project project : openProjects) { if (!project.isInitialized()) { return null; // all is allowed } for (VirtualFile root : ProjectRootManager.getInstance(project).getContentRoots()) { allowed.add(root.getPath()); } for (VirtualFile root : getAllRoots(project)) { allowed.add(StringUtil.trimEnd(root.getPath(), JarFileSystem.JAR_SEPARATOR)); } String location = project.getBasePath(); assert location != null : project; allowed.add(FileUtil.toSystemIndependentName(location)); } allowed.addAll(ourAdditionalRoots); return allowed; }
@Contract("null -> null") public static String getLocationRelativeToUserHome(@Nullable final String path) { if (path == null) return null; if (SystemInfo.isUnix) { final File projectDir = new File(path); final File userHomeDir = new File(SystemProperties.getUserHome()); if (isAncestor(userHomeDir, projectDir, true)) { return "~/" + getRelativePath(userHomeDir, projectDir); } } return path; }
private void loadExportedParameters() { synchronized (exported_parameters) { try { File parent_dir = new File(SystemProperties.getUserPath()); File props = new File(parent_dir, "exported_params.properties"); if (props.exists()) { LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(props), "UTF-8")); try { while (true) { String line = lnr.readLine(); if (line == null) { break; } String[] bits = line.split("="); if (bits.length == 2) { String key = bits[0].trim(); String value = bits[1].trim(); if (key.length() > 0 && value.length() > 0) { imported_parameters.put(key, value); } } } } finally { lnr.close(); } } } catch (Throwable e) { e.printStackTrace(); } } COConfigurationManager.setIntDefault("instance.port", Constants.INSTANCE_PORT); registerExportedParameter("instance.port", "instance.port"); }
protected File getDevicesDir() throws IOException { File dir = new File(SystemProperties.getUserPath()); dir = new File(dir, "devices"); if (!dir.exists()) { if (!dir.mkdirs()) { throw (new IOException("Failed to create '" + dir + "'")); } } return (dir); }
@Override public void documentChanged(DocumentEvent event) { if (myStopTrackingDocuments) return; final Document document = event.getDocument(); VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document); boolean isRelevant = virtualFile != null && isRelevant(virtualFile); final FileViewProvider viewProvider = getCachedViewProvider(document); if (viewProvider == null) { handleCommitWithoutPsi(document); return; } boolean inMyProject = viewProvider.getManager() == myPsiManager; if (!isRelevant || !inMyProject) { myLastCommittedTexts.remove(document); return; } ApplicationManager.getApplication().assertWriteAccessAllowed(); final List<PsiFile> files = viewProvider.getAllFiles(); boolean commitNecessary = true; for (PsiFile file : files) { if (mySynchronizer.isInsideAtomicChange(file)) { commitNecessary = false; continue; } assert file instanceof PsiFileImpl || "mock.file".equals(file.getName()) && ApplicationManager.getApplication().isUnitTestMode() : event + "; file=" + file + "; allFiles=" + files + "; viewProvider=" + viewProvider; } boolean forceCommit = ApplicationManager.getApplication().hasWriteAction(ExternalChangeAction.class) && (SystemProperties.getBooleanProperty("idea.force.commit.on.external.change", false) || ApplicationManager.getApplication().isHeadlessEnvironment() && !ApplicationManager.getApplication().isUnitTestMode()); // Consider that it's worth to perform complete re-parse instead of merge if the whole document // text is replaced and // current document lines number is roughly above 5000. This makes sense in situations when // external change is performed // for the huge file (that causes the whole document to be reloaded and 'merge' way takes a // while to complete). if (event.isWholeTextReplaced() && document.getTextLength() > 100000) { document.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, Boolean.TRUE); } if (commitNecessary) { assert !(document instanceof DocumentWindow); myUncommittedDocuments.add(document); myDocumentCommitProcessor.log( "added uncommitted doc", null, false, myProject, document, ((DocumentEx) document).isInBulkUpdate()); if (forceCommit) { commitDocument(document); } else if (!((DocumentEx) document).isInBulkUpdate() && myPerformBackgroundCommit) { myDocumentCommitProcessor.commitAsynchronously(myProject, document, event); } } else { myLastCommittedTexts.remove(document); } }
@Nullable public static VirtualFile getUserHomeDir() { final String path = SystemProperties.getUserHome(); return LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(path)); }
/** * Construct the default version check message. * * @return message to send */ public static Map constructVersionCheckMessage(String reason) { // only send if anonymous-check flag is not set boolean send_info = COConfigurationManager.getBooleanParameter("Send Version Info"); Map message = new HashMap(); // always send message.put("appid", SystemProperties.getApplicationIdentifier()); message.put("appname", SystemProperties.getApplicationName()); message.put("version", Constants.AZUREUS_VERSION); String sub_ver = Constants.AZUREUS_SUBVER; if (sub_ver.length() > 0) { message.put("subver", sub_ver); } if (COConfigurationManager.getBooleanParameter("Beta Programme Enabled")) { message.put("beta_prog", "true"); } message.put("ui", COConfigurationManager.getStringParameter("ui", "unknown")); message.put("os", Constants.OSName); message.put("os_version", System.getProperty("os.version")); message.put( "os_arch", System.getProperty("os.arch")); // see http://lopica.sourceforge.net/os.html boolean using_phe = COConfigurationManager.getBooleanParameter("network.transport.encrypted.require"); message.put("using_phe", using_phe ? new Long(1) : new Long(0)); // swt stuff try { Class c = Class.forName("org.eclipse.swt.SWT"); String swt_platform = (String) c.getMethod("getPlatform", new Class[] {}).invoke(null, new Object[] {}); message.put("swt_platform", swt_platform); Integer swt_version = (Integer) c.getMethod("getVersion", new Class[] {}).invoke(null, new Object[] {}); message.put("swt_version", new Long(swt_version.longValue())); if (send_info) { c = Class.forName("org.gudy.azureus2.ui.swt.mainwindow.MainWindow"); if (c != null) { c.getMethod("addToVersionCheckMessage", new Class[] {Map.class}) .invoke(null, new Object[] {message}); } } } catch (ClassNotFoundException e) { /* ignore */ } catch (NoClassDefFoundError er) { /* ignore */ } catch (InvocationTargetException err) { /* ignore */ } catch (Throwable t) { t.printStackTrace(); } int last_send_time = COConfigurationManager.getIntParameter("Send Version Info Last Time", -1); int current_send_time = (int) (SystemTime.getCurrentTime() / 1000); COConfigurationManager.setParameter("Send Version Info Last Time", current_send_time); String id = COConfigurationManager.getStringParameter("ID", null); if (id != null && send_info) { message.put("id", id); try { byte[] id2 = CryptoManagerFactory.getSingleton().getSecureID(); message.put("id2", id2); } catch (Throwable e) { } if (last_send_time != -1 && last_send_time < current_send_time) { // time since last message.put("tsl", new Long(current_send_time - last_send_time)); } message.put("reason", reason); String java_version = System.getProperty("java.version"); if (java_version == null) { java_version = "unknown"; } message.put("java", java_version); String java_vendor = System.getProperty("java.vm.vendor"); if (java_vendor == null) { java_vendor = "unknown"; } message.put("javavendor", java_vendor); long max_mem = Runtime.getRuntime().maxMemory() / (1024 * 1024); message.put("javamx", new Long(max_mem)); String java_rt_name = System.getProperty("java.runtime.name"); if (java_rt_name != null) { message.put("java_rt_name", java_rt_name); } String java_rt_version = System.getProperty("java.runtime.version"); if (java_rt_version != null) { message.put("java_rt_version", java_rt_version); } OverallStats stats = StatsFactory.getStats(); if (stats != null) { // long total_bytes_downloaded = stats.getDownloadedBytes(); // long total_bytes_uploaded = stats.getUploadedBytes(); long total_uptime = stats.getTotalUpTime(); // removed due to complaints about anonymous stats collection // message.put( "total_bytes_downloaded", new Long( total_bytes_downloaded ) ); // message.put( "total_bytes_uploaded", new Long( total_bytes_uploaded ) ); message.put("total_uptime", new Long(total_uptime)); // message.put( "dlstats", stats.getDownloadStats()); } try { NetworkAdminASN current_asn = NetworkAdmin.getSingleton().getCurrentASN(); String as = current_asn.getAS(); message.put("ip_as", current_asn.getAS()); String asn = current_asn.getASName(); if (asn.length() > 64) { asn = asn.substring(0, 64); } message.put("ip_asn", asn); } catch (Throwable e) { Debug.out(e); } // send locale, so we can determine which languages need attention message.put("locale", Locale.getDefault().toString()); String originalLocale = System.getProperty("user.language") + "_" + System.getProperty("user.country"); String variant = System.getProperty("user.variant"); if (variant != null && variant.length() > 0) { originalLocale += "_" + variant; } message.put("orig_locale", originalLocale); // We may want to reply differently if the user is in Beginner mode vs Advanced message.put("user_mode", COConfigurationManager.getIntParameter("User Mode", -1)); Set<String> features = UtilitiesImpl.getFeaturesInstalled(); if (features.size() > 0) { String str = ""; for (String f : features) { str += (str.length() == 0 ? "" : ",") + f; } message.put("vzfeatures", str); } try { if (AzureusCoreFactory.isCoreAvailable()) { // installed plugin IDs PluginInterface[] plugins = AzureusCoreFactory.getSingleton().getPluginManager().getPluginInterfaces(); List pids = new ArrayList(); List vs_data = new ArrayList(); for (int i = 0; i < plugins.length; i++) { PluginInterface plugin = plugins[i]; String pid = plugin.getPluginID(); String info = plugin.getPluginconfig().getPluginStringParameter("plugin.info"); // filter out built-in and core ones if ((info != null && info.length() > 0) || (!pid.startsWith("<") && !pid.startsWith("azbp") && !pid.startsWith("azupdater") && !pid.startsWith("azplatform") && !pids.contains(pid))) { if (info != null && info.length() > 0) { if (info.length() < 256) { pid += ":" + info; } else { Debug.out("Plugin '" + pid + "' reported excessive info string '" + info + "'"); } } pids.add(pid); } Map data = plugin.getPluginconfig().getPluginMapParameter("plugin.versionserver.data", null); if (data != null) { Map payload = new HashMap(); byte[] data_bytes = BEncoder.encode(data); if (data_bytes.length > 16 * 1024) { Debug.out( "Plugin '" + pid + "' reported excessive version server data (length=" + data_bytes.length + ")"); payload.put("error", "data too long: " + data_bytes.length); } else { payload.put("data", data_bytes); } payload.put("id", pid); payload.put("version", plugin.getPluginVersion()); vs_data.add(payload); } } message.put("plugins", pids); if (vs_data.size() > 0) { message.put("plugin_data", vs_data); } } } catch (Throwable e) { Debug.out(e); } } return message; }