private void validateModule(@NotNull Module module) throws Exception { final String importedModulePath = getProject().getBaseDir().getPath(); final Element actualImlElement = new Element("root"); ((ModuleRootManagerImpl) ModuleRootManager.getInstance(module)) .getState() .writeExternal(actualImlElement); PathMacros.getInstance().setMacro(MODULE_DIR, importedModulePath); PathMacroManager.getInstance(module).collapsePaths(actualImlElement); PathMacroManager.getInstance(getProject()).collapsePaths(actualImlElement); PathMacros.getInstance().removeMacro(MODULE_DIR); final String projectPath = getProject().getBaseDir().getPath(); final File expectedImlFile = new File(projectPath + "/expected/" + module.getName() + ".iml"); final Document expectedIml = JDOMUtil.loadDocument(expectedImlFile); final Element expectedImlElement = expectedIml.getRootElement(); final String errorMsg = "Configuration of module " + module.getName() + " does not meet expectations.\nExpected:\n" + new String(JDOMUtil.printDocument(expectedIml, "\n")) + "\nBut got:\n" + new String(JDOMUtil.printDocument(new Document(actualImlElement), "\n")); Assert.assertTrue(errorMsg, JDOMUtil.areElementsEqual(expectedImlElement, actualImlElement)); validateFacet(module); }
protected String expandPath(String path, Module module, Project project) { path = PathMacroManager.getInstance(project).expandPath(path); if (module != null) { path = PathMacroManager.getInstance(module).expandPath(path); } return path; }
public void writeExternal(final Element element) throws WriteExternalException { super.writeExternal(element); JavaRunConfigurationExtensionManager.getInstance().writeExternal(this, element); writeModule(element); DefaultJDOMExternalizer.writeExternal(this, element); final Data persistentData = getPersistentData(); DefaultJDOMExternalizer.writeExternal(persistentData, element); EnvironmentVariablesComponent.writeExternal(element, persistentData.getEnvs()); final String dirName = persistentData.getDirName(); if (!dirName.isEmpty()) { final Element dirNameElement = new Element("dir"); dirNameElement.setAttribute("value", FileUtil.toSystemIndependentName(dirName)); element.addContent(dirNameElement); } final Element patternsElement = new Element(PATTERNS_EL_NAME); for (String o : persistentData.getPatterns()) { final Element patternElement = new Element(PATTERN_EL_NAME); patternElement.setAttribute(TEST_CLASS_ATT_NAME, o); patternsElement.addContent(patternElement); } final String forkMode = getForkMode(); if (!forkMode.equals("none")) { final Element forkModeElement = new Element("fork_mode"); forkModeElement.setAttribute("value", forkMode); element.addContent(forkModeElement); } element.addContent(patternsElement); PathMacroManager.getInstance(getProject()).collapsePathsRecursively(element); }
public void readExternal(final Element element) throws InvalidDataException { PathMacroManager.getInstance(getProject()).expandPaths(element); super.readExternal(element); JavaRunConfigurationExtensionManager.getInstance().readExternal(this, element); readModule(element); DefaultJDOMExternalizer.readExternal(this, element); DefaultJDOMExternalizer.readExternal(getPersistentData(), element); EnvironmentVariablesComponent.readExternal(element, getPersistentData().getEnvs()); final Element patternsElement = element.getChild(PATTERNS_EL_NAME); if (patternsElement != null) { final Set<String> tests = new LinkedHashSet<String>(); for (Object o : patternsElement.getChildren(PATTERN_EL_NAME)) { Element patternElement = (Element) o; tests.add(patternElement.getAttributeValue(TEST_CLASS_ATT_NAME)); } myData.setPatterns(tests); } final Element forkModeElement = element.getChild("fork_mode"); if (forkModeElement != null) { final String mode = forkModeElement.getAttributeValue("value"); if (mode != null) { setForkMode(mode); } } final Element dirNameElement = element.getChild("dir"); if (dirNameElement != null) { final String dirName = dirNameElement.getAttributeValue("value"); getPersistentData().setDirName(FileUtil.toSystemDependentName(dirName)); } }
@Nullable @Override public RefEntity getReference(final String type, final String fqName) { for (RefManagerExtension extension : myExtensions.values()) { final RefEntity refEntity = extension.getReference(type, fqName); if (refEntity != null) return refEntity; } if (SmartRefElementPointer.FILE.equals(type)) { return RefFileImpl.fileFromExternalName(this, fqName); } if (SmartRefElementPointer.MODULE.equals(type)) { return RefModuleImpl.moduleFromName(this, fqName); } if (SmartRefElementPointer.PROJECT.equals(type)) { return getRefProject(); } if (SmartRefElementPointer.DIR.equals(type)) { String url = VfsUtilCore.pathToUrl(PathMacroManager.getInstance(getProject()).expandPath(fqName)); VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(url); if (vFile != null) { final PsiDirectory dir = PsiManager.getInstance(getProject()).findDirectory(vFile); return getReference(dir); } } return null; }
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()); }
public DefaultProjectStorage( @NotNull File file, @NotNull String fileSpec, PathMacroManager pathMacroManager) { super( file, fileSpec, RoamingType.DISABLED, pathMacroManager.createTrackingSubstitutor(), "defaultProject", null); }
private synchronized void writeOutput( @NotNull final CommonProblemDescriptor[] descriptions, @NotNull RefEntity refElement) { final Element parentNode = new Element(InspectionsBundle.message("inspection.problems")); exportResults(descriptions, refElement, parentNode); final List list = parentNode.getChildren(); @NonNls final String ext = ".xml"; final String fileName = ourOutputPath + File.separator + myToolWrapper.getShortName() + ext; final PathMacroManager pathMacroManager = PathMacroManager.getInstance(getContext().getProject()); PrintWriter printWriter = null; try { new File(ourOutputPath).mkdirs(); final File file = new File(fileName); final CharArrayWriter writer = new CharArrayWriter(); if (!file.exists()) { writer .append("<") .append(InspectionsBundle.message("inspection.problems")) .append(" " + GlobalInspectionContextBase.LOCAL_TOOL_ATTRIBUTE + "=\"") .append(Boolean.toString(myToolWrapper instanceof LocalInspectionToolWrapper)) .append("\">\n"); } for (Object o : list) { final Element element = (Element) o; pathMacroManager.collapsePaths(element); JDOMUtil.writeElement(element, writer, "\n"); } printWriter = new PrintWriter( new BufferedWriter( new OutputStreamWriter( new FileOutputStream(fileName, true), CharsetToolkit.UTF8_CHARSET))); printWriter.append("\n"); printWriter.append(writer.toString()); } catch (IOException e) { LOG.error(e); } finally { if (printWriter != null) { printWriter.close(); } } }
public void writeExternal(Element element) throws WriteExternalException { super.writeExternal(element); writeModule(element); JDOMExternalizer.write(element, "path", scriptPath); JDOMExternalizer.write(element, "vmparams", vmParams); JDOMExternalizer.write(element, "params", scriptParams); JDOMExternalizer.write(element, "workDir", workDir); JDOMExternalizer.write(element, "debug", isDebugEnabled); JDOMExternalizer.writeMap(element, envs, null, "env"); PathMacroManager.getInstance(getProject()).collapsePathsRecursively(element); }
public void readExternal(Element element) throws InvalidDataException { PathMacroManager.getInstance(getProject()).expandPaths(element); super.readExternal(element); readModule(element); scriptPath = JDOMExternalizer.readString(element, "path"); vmParams = JDOMExternalizer.readString(element, "vmparams"); scriptParams = JDOMExternalizer.readString(element, "params"); final String wrk = JDOMExternalizer.readString(element, "workDir"); if (!".".equals(wrk)) { workDir = wrk; } isDebugEnabled = Boolean.parseBoolean(JDOMExternalizer.readString(element, "debug")); envs.clear(); JDOMExternalizer.readMap(element, envs, null, "env"); }
@Override public void readExternal(Element element) throws InvalidDataException { PathMacroManager.getInstance(getProject()).expandPaths(element); super.readExternal(element); JavaRunConfigurationExtensionManager.getInstance().readExternal(this, element); readModule(element); DefaultJDOMExternalizer.readExternal(this, element); DefaultJDOMExternalizer.readExternal(getPersistantData(), element); EnvironmentVariablesComponent.readExternal(element, getPersistantData().getEnvs()); Map<String, String> properties = getPersistantData().TEST_PROPERTIES; properties.clear(); Element propertiesElement = element.getChild("properties"); if (propertiesElement != null) { List<Element> children = propertiesElement.getChildren("property"); for (Element property : children) { properties.put(property.getAttributeValue("name"), property.getAttributeValue("value")); } } List<String> listeners = getPersistantData().TEST_LISTENERS; listeners.clear(); Element listenersElement = element.getChild("listeners"); if (listenersElement != null) { List<Element> children = listenersElement.getChildren("listener"); for (Element listenerClassName : children) { listeners.add(listenerClassName.getAttributeValue("class")); } } final Element patternsElement = element.getChild(PATTERNS_EL_NAME); if (patternsElement != null) { final LinkedHashSet<String> tests = new LinkedHashSet<String>(); for (Object o : patternsElement.getChildren(PATTERN_EL_NAME)) { Element patternElement = (Element) o; tests.add(patternElement.getAttributeValue(TEST_CLASS_ATT_NAME)); } getPersistantData().setPatterns(tests); } }
public void readClasspath( ModifiableRootModel model, final Collection<String> unknownLibraries, Collection<String> unknownJdks, final Set<String> usedVariables, Set<String> refsToModules, final String testPattern, Element classpathElement) throws IOException, ConversionException { for (OrderEntry orderEntry : model.getOrderEntries()) { if (!(orderEntry instanceof ModuleSourceOrderEntry)) { model.removeOrderEntry(orderEntry); } } int idx = 0; for (Object o : classpathElement.getChildren(EclipseXml.CLASSPATHENTRY_TAG)) { try { readClasspathEntry( model, unknownLibraries, unknownJdks, usedVariables, refsToModules, testPattern, (Element) o, idx++, EclipseModuleManagerImpl.getInstance(model.getModule()), ((BasePathMacroManager) PathMacroManager.getInstance(model.getModule())) .getExpandMacroMap()); } catch (ConversionException e) { ErrorLog.rethrow(ErrorLog.Level.Warning, null, EclipseXml.CLASSPATH_FILE, e); } } if (!model.isSdkInherited() && model.getSdkName() == null) { EclipseModuleManagerImpl.getInstance(model.getModule()).setForceConfigureJDK(); model.inheritSdk(); } }
public static void assertElementEquals(final Element element, String value, Module module) { PathMacroManager.getInstance(module).collapsePaths(element); assertEquals(value, new XMLOutputter().outputString(element)); }
protected BaseFileConfigurableStoreImpl(@NotNull ComponentManager componentManager) { myComponentManager = componentManager; myDefaultsStateStorage = new DefaultsStateStorage(PathMacroManager.getInstance(myComponentManager)); }