@Nullable public static PyRemotePathMapper getPathMapper(@NotNull Project project, Sdk sdk) { if (PySdkUtil.isRemote(sdk)) { PythonRemoteInterpreterManager instance = PythonRemoteInterpreterManager.getInstance(); if (instance != null) { //noinspection ConstantConditions PyRemotePathMapper remotePathMapper = instance.setupMappings(project, (PyRemoteSdkAdditionalDataBase)sdk.getSdkAdditionalData(), null); PathMappingSettings mappingSettings = PyConsoleOptions.getInstance(project).getPythonConsoleSettings().getMappingSettings(); remotePathMapper.addAll(mappingSettings.getPathMappings(), PyRemotePathMapper.PyPathMappingType.USER_DEFINED); return remotePathMapper; } } return null; }
public void readExternal(Element element) throws InvalidDataException { super.readExternal(element); myInterpreterOptions = JDOMExternalizerUtil.readField(element, "INTERPRETER_OPTIONS"); readEnvs(element); mySdkHome = JDOMExternalizerUtil.readField(element, "SDK_HOME"); myWorkingDirectory = JDOMExternalizerUtil.readField(element, "WORKING_DIRECTORY"); myUseModuleSdk = Boolean.parseBoolean(JDOMExternalizerUtil.readField(element, "IS_MODULE_SDK")); final String addContentRoots = JDOMExternalizerUtil.readField(element, "ADD_CONTENT_ROOTS"); myAddContentRoots = addContentRoots == null || Boolean.parseBoolean(addContentRoots); final String addSourceRoots = JDOMExternalizerUtil.readField(element, "ADD_SOURCE_ROOTS"); myAddSourceRoots = addSourceRoots == null || Boolean.parseBoolean(addSourceRoots); getConfigurationModule().readExternal(element); setMappingSettings(PathMappingSettings.readExternal(element)); // extension settings: PythonRunConfigurationExtensionsManager.getInstance().readExternal(this, element); }
public void writeExternal(Element element) throws WriteExternalException { super.writeExternal(element); JDOMExternalizerUtil.writeField(element, "INTERPRETER_OPTIONS", myInterpreterOptions); writeEnvs(element); JDOMExternalizerUtil.writeField(element, "SDK_HOME", mySdkHome); JDOMExternalizerUtil.writeField(element, "WORKING_DIRECTORY", myWorkingDirectory); JDOMExternalizerUtil.writeField(element, "IS_MODULE_SDK", Boolean.toString(myUseModuleSdk)); JDOMExternalizerUtil.writeField(element, "ADD_CONTENT_ROOTS", Boolean.toString(myAddContentRoots)); JDOMExternalizerUtil.writeField(element, "ADD_SOURCE_ROOTS", Boolean.toString(myAddSourceRoots)); getConfigurationModule().writeExternal(element); // extension settings: PythonRunConfigurationExtensionsManager.getInstance().writeExternal(this, element); PathMappingSettings.writeExternal(element, getMappingSettings()); }
@Test public void testFromSettings() throws Exception { PathMappingSettings settings = new PathMappingSettings(); PyRemotePathMapper emptyMapper = PyRemotePathMapper.fromSettings(settings, PyPathMappingType.USER_DEFINED); assertTrue(emptyMapper.isEmpty()); settings.add(new PathMappingSettings.PathMapping("C:\\local\\folder", "/remote/folder")); settings.add(new PathMappingSettings.PathMapping("C:\\local\\folder\\child", "/remote/child-from-local")); settings.add(new PathMappingSettings.PathMapping("C:\\local\\child-from-remote", "/remote/folder/child")); PyRemotePathMapper mapper = PyRemotePathMapper.fromSettings(settings, PyPathMappingType.HELPERS); assertFalse(mapper.isEmpty()); assertConvertsOneToAnother(mapper, "C:\\local\\folder\\src\\main.py", "/remote/folder/src/main.py"); assertConvertsOneToAnother(mapper, "C:\\local\\folder\\child\\test\\all.py", "/remote/child-from-local/test/all.py"); assertConvertsOneToAnother(mapper, "C:/local/child-from-remote/README", "/remote/folder/child/README"); assertEquals("/unmapped/list.txt", mapper.convertToLocal("/unmapped/list.txt")); assertEquals("C:\\unmapped\\list.txt", mapper.convertToRemote("C:\\unmapped\\list.txt")); }
@Override public void setPathMappings(@Nullable PathMappingSettings pathMappings) { myPathMappings = new PathMappingSettings(); if (pathMappings != null) { myPathMappings.addAll(pathMappings); } }
public void save(Element rootElement) { rootElement.setAttribute(INTERPRETER_PATH, StringUtil.notNullize(getInterpreterPath())); rootElement.setAttribute(HELPERS_PATH, StringUtil.notNullize(getHelpersPath())); rootElement.setAttribute(INITIALIZED, Boolean.toString(isInitialized())); rootElement.setAttribute(VALID, Boolean.toString(isValid())); PathMappingSettings.writeExternal(rootElement, myPathMappings); for (String remoteRoot : getRemoteRoots()) { final Element child = new Element(REMOTE_ROOTS); child.setAttribute(REMOTE_PATH, remoteRoot); rootElement.addContent(child); } }
public void setMappingSettings(@Nullable final PathMappingSettings mappingSettings) { if (mappingSettings == null) { myMappingSettings = new PathMappingSettings(); } else { myMappingSettings = mappingSettings; } setTextRepresentation(myMappingSettings); fireStateChanged(); }
private void setTextRepresentation(@NotNull PathMappingSettings mappingSettings) { final StringBuilder sb = new StringBuilder(); for (PathMappingSettings.PathMapping mapping : mappingSettings.getPathMappings()) { sb.append(mapping.getLocalRoot()).append("=").append(mapping.getRemoteRoot()).append(";"); } if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); //trim last ; } getComponent().setText(sb.toString()); }
public void apply(AbstractPythonRunConfigurationParams form) { mySdkHome = form.getSdkHome(); myInterpreterOptions = form.getInterpreterOptions(); myEnvs = form.getEnvs(); myUseModuleSdk = form.isUseModuleSdk(); myModuleName = form.getModule() == null ? null : form.getModule().getName(); myWorkingDirectory = form.getWorkingDirectory(); myAddContentRoots = form.shouldAddContentRoots(); myAddSourceRoots = form.shouldAddSourceRoots(); myMappings = form.getMappingSettings() == null ? new PathMappingSettings() : form.getMappingSettings(); }
@NotNull public static PyRemotePathMapper cloneMapper(@Nullable PyRemotePathMapper mapper) { PyRemotePathMapper pathMapper = new PyRemotePathMapper(); if (mapper != null) { for (Map.Entry<PyPathMappingType, Collection<PathMappingSettings.PathMapping>> entry : mapper.myPathMappings.entrySet()) { for (PathMappingSettings.PathMapping pathMapping : entry.getValue()) { pathMapper.addMapping(pathMapping.getLocalRoot(), pathMapping.getRemoteRoot(), entry.getKey()); } } } return pathMapper; }
@Override protected VirtualFile[] doAddItems() { Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myPanel)); try { String[] files = PythonRemoteInterpreterManager .getInstance().chooseRemoteFiles(project, (PyRemoteSdkAdditionalDataBase)mySdk.getSdkAdditionalData(), false); final String sourcesLocalPath = PySdkUtil.getRemoteSourcesLocalPath(mySdk.getHomePath()); VirtualFile[] vFiles = new VirtualFile[files.length]; int i = 0; for (String file : files) { String localRoot = PyRemoteSourceItem.localPathForRemoteRoot(sourcesLocalPath, file); myNewMappings.add(new PathMappingSettings.PathMapping(localRoot, file)); myRemoteSdkData.getPathMappings().addMappingCheckUnique(localRoot, file); if (!new File(localRoot).exists()) { new File(localRoot).mkdirs(); } vFiles[i++] = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(localRoot)); } vFiles = adjustAddedFileSet(myPanel, vFiles); List<VirtualFile> added = new ArrayList<VirtualFile>(vFiles.length); for (VirtualFile vFile : vFiles) { if (addElement(vFile)) { added.add(vFile); } } return VfsUtilCore.toVirtualFileArray(added); } catch (Exception e) { LOG.error(e); } return new VirtualFile[0]; }
@Override public void apply(SdkModificator sdkModificator) { if (sdkModificator.getSdkAdditionalData() instanceof PyRemoteSdkAdditionalDataBase) { for (PathMappingSettings.PathMapping mapping : myNewMappings) { ((PyRemoteSdkAdditionalDataBase)sdkModificator.getSdkAdditionalData()).getPathMappings() .addMappingCheckUnique(mapping.getLocalRoot(), mapping.getRemoteRoot()); } } super.apply(sdkModificator); }
@Override @Nullable public PathMappingSettings getMappingSettings() { if (myInterpreterRemote) { return myPathMappingsComponent.getMappingSettings(); } else { return new PathMappingSettings(); } }
private void setTextRepresentation(@Nonnull PathMappingSettings mappingSettings) { final StringBuilder sb = new StringBuilder(); for (PathMappingSettings.PathMapping mapping : mappingSettings.getPathMappings()) { sb.append(mapping.getLocalRoot()).append("=").append(mapping.getRemoteRoot()).append(";"); } if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); //trim last ; } getComponent().setText(sb.toString()); }
@NotNull @Override public PathMappingSettings getPathMappings() { return myPathMappings; }
@NotNull @Override public PathMappingSettings getPathMappings() { return myRemoteSdkProperties.getPathMappings(); }
@Override public void setPathMappings(@Nullable PathMappingSettings pathMappings) { myRemoteSdkProperties.setPathMappings(pathMappings); }
@NotNull PathMappingSettings getPathMappings();
@NotNull public abstract PathMappingSettings getPathMappingSettings(@NotNull Project project, @NotNull RemoteSdkAdditionalData data);
public PathMappingSettings getPathMappingSettings() { return new PathMappingSettings(getElements()); }
@Override protected PathMappingSettings.PathMapping createElement() { return new PathMappingSettings.PathMapping(); }
@Override protected boolean isEmpty(PathMappingSettings.PathMapping element) { return element.getLocalRoot().isEmpty() && element.getRemoteRoot().isEmpty(); }
@Override protected PathMappingSettings.PathMapping cloneElement(PathMappingSettings.PathMapping envVariable) { return envVariable.clone(); }
@Override protected boolean canDeleteElement(PathMappingSettings.PathMapping selection) { return true; }
@NotNull public PathMappingSettings getMappingSettings() { return myMappingSettings; }
@Override public PathMappingSettings getMappingSettings() { return myPathMappingsComponent.getMappingSettings(); }
@Override public void setMappingSettings(@Nullable PathMappingSettings mappingSettings) { myPathMappingsComponent.setMappingSettings(mappingSettings); }
@Nullable PathMappingSettings getMappingSettings();
@AbstractCollection(surroundWithTag = false) public PathMappingSettings getMappings() { return myMappings; }
@Nullable @Override public PathMappingSettings getMappingSettings() { return getMappings(); }
public void setMappings(@Nullable PathMappingSettings mappings) { myMappings = mappings != null ? mappings : new PathMappingSettings(); }
@Nullable @Override public PathMappingSettings getMappingSettings() { throw new UnsupportedOperationException(); }
@Override public void setMappingSettings(@Nullable PathMappingSettings mappingSettings) { throw new UnsupportedOperationException(); }
@NotNull public static PyRemotePathMapper fromSettings(@NotNull PathMappingSettings settings, @NotNull PyPathMappingType mappingType) { PyRemotePathMapper mapper = new PyRemotePathMapper(); mapper.addAll(settings.getPathMappings(), mappingType); return mapper; }
public void addMapping(String local, String remote, @NotNull PyPathMappingType type) { myPathMappings.putValue(type, new PathMappingSettings.PathMapping(local, remote)); }