@NotNull public static Set<String> getMacroNames(Element root, @Nullable PathMacroFilter filter, @NotNull PathMacros pathMacros) { final PathMacrosCollector collector = new PathMacrosCollector(); collector.substitute(root, true, false, filter); Set<String> preResult = collector.myMacroMap.keySet(); if (preResult.isEmpty()) { return Collections.emptySet(); } Set<String> result = new SmartHashSet<String>(preResult); result.removeAll(pathMacros.getSystemMacroNames()); result.removeAll(pathMacros.getLegacyMacroNames()); result.removeAll(PathMacrosImpl.getToolMacroNames()); result.removeAll(pathMacros.getIgnoredMacroNames()); return result; }
private void setUpMocks(final String projectPath) { myModule = context.mock(Module.class); myPathMacros = context.mock(PathMacrosImpl.class); myProject = context.mock(ProjectEx.class); final VirtualFile projectFile = context.mock(VirtualFile.class, "projectFile"); context.checking(new Expectations() {{ allowing(myModule).isDisposed(); will(returnValue(false)); allowing(myProject).isDisposed(); will(returnValue(false)); allowing(projectFile).getPath(); will(returnValue(projectPath)); final String moduleFilePath = projectPath + "/module/module.iml"; allowing(myApplication).getComponent(with(equal(PathMacros.class))); will(returnValue(myPathMacros)); allowing(myPathMacros).addMacroReplacements(with(any(ReplacePathToMacroMap.class))); allowing(myProject).getBaseDir(); will(returnValue(projectFile)); allowing(myModule).getModuleFilePath(); will(returnValue(moduleFilePath)); allowing(myModule).getProject(); will(returnValue(myProject)); }}); }
@Override protected void setUp() throws Exception { super.setUp(); final File testRoot = new File(PluginPathManager.getPluginHomePath("eclipse") + "/testData", getRelativeTestPath()); assertTrue(testRoot.getAbsolutePath(), testRoot.isDirectory()); final File currentTestRoot = new File(testRoot, getTestName(true)); assertTrue(currentTestRoot.getAbsolutePath(), currentTestRoot.isDirectory()); final String tempPath = getProject().getBaseDir().getPath(); final File tempDir = new File(tempPath); VirtualFile vTestRoot = LocalFileSystem.getInstance().findFileByIoFile(currentTestRoot); copyDirContentsTo(vTestRoot, getProject().getBaseDir()); final VirtualFile virtualTestDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir); assertNotNull(tempDir.getAbsolutePath(), virtualTestDir); virtualTestDir.refresh(false, true); PathMacros.getInstance().setMacro(VARIABLE, new File(tempPath, VARIABLE + "idea").getPath()); PathMacros.getInstance().setMacro(SRCVARIABLE, new File(tempPath, SRCVARIABLE + "idea").getPath()); }
@Override protected void setUp() throws Exception { super.setUp(); final File testRoot = new File(PluginPathManager.getPluginHomePath("eclipse") + "/testData", getRelativeTestPath()); assertTrue(testRoot.getAbsolutePath(), testRoot.isDirectory()); final File currentTestRoot = new File(testRoot, getTestName(true)); assertTrue(currentTestRoot.getAbsolutePath(), currentTestRoot.isDirectory()); final String tempPath = getProject().getBaseDir().getPath(); final File tempDir = new File(tempPath); FileUtil.copyDir(currentTestRoot, tempDir); final VirtualFile virtualTestDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir); assertNotNull(tempDir.getAbsolutePath(), virtualTestDir); virtualTestDir.refresh(false, true); PathMacros.getInstance().setMacro(VARIABLE, new File(tempPath, VARIABLE + "idea").getPath()); PathMacros.getInstance().setMacro(SRCVARIABLE, new File(tempPath, SRCVARIABLE + "idea").getPath()); }
private void setUpMocks(final String projectPath) { myModule = context.mock(Module.class); myPathMacros = context.mock(PathMacrosImpl.class); myProject = context.mock(ProjectEx.class); final VirtualFile projectFile = context.mock(VirtualFile.class, "projectFile"); context.checking(new Expectations() {{ allowing(myModule).isDisposed(); will(returnValue(false)); allowing(myProject).isDisposed(); will(returnValue(false)); allowing(projectFile).getPath(); will(returnValue(projectPath)); final String moduleFilePath = projectPath + "/module/module.iml"; allowing(myApplication).getComponent(with(equal(PathMacros.class))); will(returnValue(myPathMacros)); allowing(myPathMacros).addMacroReplacements(with(any(ReplacePathToMacroMap.class))); allowing(myProject).getBaseDir(); will(returnValue(projectFile)); allowing(myModule).getModuleDir(); will(returnValue(moduleFilePath)); allowing(myModule).getProject(); will(returnValue(myProject)); }}); }
/** * A constctor that extracts all neeed properties for ant build from the project. * * @param project a project to examine * @param genOptions generation options */ public PropertyFileGeneratorImpl(Project project, GenerationOptions genOptions) { // path variables final PathMacros pathMacros = PathMacros.getInstance(); final Set<String> macroNamesSet = pathMacros.getUserMacroNames(); if (macroNamesSet.size() > 0) { final String[] macroNames = ArrayUtil.toStringArray(macroNamesSet); Arrays.sort(macroNames); for (final String macroName : macroNames) { addProperty(BuildProperties.getPathMacroProperty(macroName), pathMacros.getValue(macroName)); } } // jdk homes if (genOptions.forceTargetJdk) { final Sdk[] usedJdks = BuildProperties.getUsedJdks(project); for (Sdk jdk : usedJdks) { if (jdk.getHomeDirectory() == null) { continue; } final File homeDir = BuildProperties.toCanonicalFile(VfsUtil.virtualToIoFile(jdk.getHomeDirectory())); addProperty(BuildProperties.getJdkHomeProperty(jdk.getName()), homeDir.getPath().replace(File.separatorChar, '/')); } } // generate idea.home property if (genOptions.isIdeaHomeGenerated()) { addProperty(BuildProperties.PROPERTY_IDEA_HOME, PathManager.getHomePath()); } if (genOptions.enableFormCompiler) { addProperty(BuildProperties.PROPERTY_INCLUDE_JAVA_RUNTIME_FOR_INSTRUMENTATION, genOptions.forceTargetJdk? "false" : "true"); } ChunkBuildExtension.generateAllProperties(this, project, genOptions); }
private static ReplacePathToMacroMap createReplacementMap() { final PathMacros pathMacros = PathMacros.getInstance(); final Set<String> macroNames = pathMacros.getUserMacroNames(); final ReplacePathToMacroMap map = new ReplacePathToMacroMap(); for (final String macroName : macroNames) { map.put(GenerationUtils.normalizePath(pathMacros.getValue(macroName)), BuildProperties.propertyRef(BuildProperties.getPathMacroProperty(macroName))); } map.put(GenerationUtils.normalizePath(PathManager.getHomePath()), BuildProperties.propertyRef(BuildProperties.PROPERTY_IDEA_HOME)); return map; }
private boolean hasMacroWithName(String name) { if (PathMacros.getInstance().getSystemMacroNames().contains(name)) { return true; } for (Couple<String> macro : myMacros) { if (name.equals(macro.getFirst())) { return true; } } return false; }
public void commit() throws ConfigurationException { ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { myPathMacroTable.commit(); final Collection<String> ignored = parseIgnoredVariables(); final PathMacros instance = PathMacros.getInstance(); instance.setIgnoredMacroNames(ignored); } }); }
public static Map<String, String> getMacroMap() { final PathMacros macros = PathMacros.getInstance(); final Set<String> allNames = macros.getAllMacroNames(); final HashMap<String, String> map = new HashMap<String, String>(); for (String eachMacroName : allNames) { map.put("$" + eachMacroName + "$", macros.getValue(eachMacroName)); } return map; }
protected JComponent createComponentWithMacroBrowse(@NotNull final TextFieldWithBrowseButton textAccessor) { final FixedSizeButton button = new FixedSizeButton(textAccessor); button.setIcon(AllIcons.RunConfigurations.Variables); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<String> macros = new SmartList<String>(PathMacros.getInstance().getUserMacroNames()); if (myModuleContext != null || myHasModuleMacro) { macros.add(PathMacroUtil.MODULE_DIR_MACRO_NAME); } final JList list = new JBList(ArrayUtil.toStringArray(macros)); JBPopupFactory.getInstance().createListPopupBuilder(list).setItemChoosenCallback(new Runnable() { @Override public void run() { final Object value = list.getSelectedValue(); if (value instanceof String) { textAccessor.setText('$' + ((String)value) + '$'); } } }).setMovable(false).setResizable(false).createPopup().showUnderneathOf(button); } }); JPanel panel = new JPanel(new BorderLayout()); panel.add(textAccessor, BorderLayout.CENTER); panel.add(button, BorderLayout.EAST); return panel; }
public ApplicationEnvironment(CoreApplicationEnvironment appEnvironment) { appEnvironment.registerFileType(HtmlFileType.INSTANCE, "html;htm;sht;shtm;shtml"); appEnvironment.registerFileType(XHtmlFileType.INSTANCE, "xhtml"); appEnvironment.registerFileType(DTDFileType.INSTANCE, "dtd;ent;mod;elt"); appEnvironment.registerFileType(XmlFileType.INSTANCE, "xml;xsd;tld;xsl;jnlp;wsdl;jhm;ant;xul;xslt;rng;fxml"); SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(XMLLanguage.INSTANCE, new XmlSyntaxHighlighterFactory()); SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(DTDLanguage.INSTANCE, new DtdSyntaxHighlighterFactory()); SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(HTMLLanguage.INSTANCE, new HtmlSyntaxHighlighterFactory()); SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(XHTMLLanguage.INSTANCE, new XhtmlSyntaxHighlighterFactory()); appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, XMLLanguage.INSTANCE, new XMLParserDefinition()); appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, DTDLanguage.INSTANCE, new DTDParserDefinition()); appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, HTMLLanguage.INSTANCE, new HTMLParserDefinition()); appEnvironment.addExplicitExtension(LanguageParserDefinitions.INSTANCE, XHTMLLanguage.INSTANCE, new XHTMLParserDefinition()); appEnvironment.addExplicitExtension(IdIndexers.INSTANCE, XmlFileType.INSTANCE, new XmlIdIndexer()); appEnvironment.addExplicitExtension(IdIndexers.INSTANCE, DTDFileType.INSTANCE, new XmlIdIndexer()); appEnvironment.addExplicitExtension(TodoIndexers.INSTANCE, XmlFileType.INSTANCE, new XmlTodoIndexer()); appEnvironment.addExplicitExtension(TodoIndexers.INSTANCE, DTDFileType.INSTANCE, new XmlTodoIndexer()); appEnvironment.addExplicitExtension(TodoIndexers.INSTANCE, XHtmlFileType.INSTANCE, new XHtmlTodoIndexer()); appEnvironment.addExtension(MetaDataContributor.EP_NAME, new XmlApplicationComponent()); appEnvironment.addExtension(FileBasedIndexExtension.EXTENSION_POINT_NAME, new XmlNamespaceIndex()); appEnvironment.addExtension(FileBasedIndexExtension.EXTENSION_POINT_NAME, new SchemaTypeInheritanceIndex()); appEnvironment.addExtension(FileBasedIndexExtension.EXTENSION_POINT_NAME, new XmlTagNamesIndex()); appEnvironment.addExtension(StandardResourceProvider.EP_NAME, new InternalResourceProvider()); appEnvironment.registerApplicationComponent(PathMacros.class, new PathMacrosImpl()); appEnvironment.registerApplicationService(ExternalResourceManager.class, new ExternalResourceManagerExImpl()); appEnvironment.registerApplicationService(XmlFoldingSettings.class, new XmlFoldingSettings()); Language[] myLanguages = new Language[]{XMLLanguage.INSTANCE, HTMLLanguage.INSTANCE, XHTMLLanguage.INSTANCE, DTDLanguage.INSTANCE}; for (Language myLanguage : myLanguages) { appEnvironment.addExplicitExtension(LanguageFolding.INSTANCE, myLanguage, new XmlFoldingBuilder()); appEnvironment.addExplicitExtension(LanguageFindUsages.INSTANCE, myLanguage, new XmlFindUsagesProvider()); appEnvironment.addExplicitExtension(LanguageASTFactory.INSTANCE, myLanguage, new XmlASTFactory()); } }
private static void registerPathVariable() { String repository = MavenUtil.resolveLocalRepository(null, null, null).getAbsolutePath(); PathMacros macros = PathMacros.getInstance(); for (String each : macros.getAllMacroNames()) { String path = macros.getValue(each); if (path != null && FileUtil.pathsEqual(repository, path)) { return; } } macros.setMacro(MAVEN_REPOSITORY, repository); }
public MvcPathMacros() { Set<String> macroNames = PathMacros.getInstance().getUserMacroNames(); for (String framework : ContainerUtil.ar("grails", "griffon")) { String name = "USER_HOME_" + framework.toUpperCase(); if (!macroNames.contains(name)) { // OK, it may appear/disappear during the application lifetime, but we ignore that for now. Restart will help anyway PathMacros.getInstance().addLegacyMacro(name, StringUtil.trimEnd(getSdkWorkDirParent(framework), "/")); } } }
public static Set<String> getMacroNames(Element root, @Nullable PathMacroFilter filter, @NotNull final PathMacros pathMacros) { final PathMacrosCollector collector = new PathMacrosCollector(); collector.substitute(root, true, false, filter); final HashSet<String> result = new HashSet<String>(collector.myMacroMap.keySet()); result.removeAll(pathMacros.getSystemMacroNames()); result.removeAll(pathMacros.getLegacyMacroNames()); result.removeAll(PathMacrosImpl.getToolMacroNames()); result.removeAll(pathMacros.getIgnoredMacroNames()); return result; }
public CoreModule(@NotNull Disposable parentDisposable, @NotNull Project project, String moduleFilePath) { super(project.getPicoContainer(), parentDisposable); myLifetime = parentDisposable; myProject = project; myPath = moduleFilePath; Extensions.instantiateArea(ExtensionAreas.IDEA_MODULE, this, null); CoreApplicationEnvironment.registerExtensionPoint(Extensions.getArea(this), ModuleExtension.EP_NAME, ModuleExtension.class); Disposer.register(parentDisposable, new Disposable() { @Override public void dispose() { Extensions.disposeArea(CoreModule.this); } }); initModuleExtensions(); final ModuleRootManagerImpl moduleRootManager = new ModuleRootManagerImpl(this, DirectoryIndex.getInstance(project), ProjectRootManagerImpl.getInstanceImpl(project), VirtualFilePointerManager.getInstance()) { @Override public void loadState(ModuleRootManagerState object) { loadState(object, false); } }; Disposer.register(parentDisposable, new Disposable() { @Override public void dispose() { moduleRootManager.disposeComponent(); } }); getPicoContainer().registerComponentInstance(ModuleRootManager.class, moduleRootManager); getPicoContainer().registerComponentInstance(PathMacroManager.class, new ModulePathMacroManager(PathMacros.getInstance(), this)); myModuleScopeProvider = createModuleScopeProvider(); }
private boolean hasMacroWithName(String name) { if (PathMacros.getInstance().getSystemMacroNames().contains(name)) { return true; } for (Pair<String, String> macro : myMacros) { if (name.equals(macro.getFirst())) { return true; } } return false; }
public static boolean checkNonIgnoredMacros(final Project project, final Set<String> usedMacros){ final PathMacros pathMacros = PathMacros.getInstance(); for (Iterator<String> iterator = usedMacros.iterator(); iterator.hasNext();) { if (pathMacros.isIgnoredMacroName(iterator.next())) { iterator.remove(); } } return checkMacros(project, usedMacros); }
public static boolean checkMacros(final Project project, final Set<String> usedMacros) { final Set<String> defined = getDefinedMacros(); usedMacros.removeAll(defined); // try to lookup values in System properties @NonNls final String pathMacroSystemPrefix = "path.macro."; for (Iterator it = usedMacros.iterator(); it.hasNext();) { final String macro = (String)it.next(); final String value = System.getProperty(pathMacroSystemPrefix + macro, null); if (value != null) { ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { PathMacros.getInstance().setMacro(macro, value); } }); it.remove(); } } if (usedMacros.isEmpty()) { return true; // all macros in configuration files are defined } // there are undefined macros, need to define them before loading components final boolean[] result = new boolean[1]; final Runnable r = new Runnable() { public void run() { result[0] = showMacrosConfigurationDialog(project, usedMacros); } }; WaitForProgressToShow.runOrInvokeAndWaitAboveProgress(r, ModalityState.NON_MODAL); return result[0]; }
public static Set<String> getDefinedMacros() { final PathMacros pathMacros = PathMacros.getInstance(); Set<String> definedMacros = new HashSet<String>(pathMacros.getUserMacroNames()); definedMacros.addAll(pathMacros.getSystemMacroNames()); definedMacros = Collections.unmodifiableSet(definedMacros); return definedMacros; }
private void registerPathVariable() { File repository = MavenUtil.resolveLocalRepository(null, null, null); PathMacros macros = PathMacros.getInstance(); for (String each : macros.getAllMacroNames()) { String path = macros.getValue(each); if (path == null) continue; if (new File(path).equals(repository)) return; } macros.setMacro(MAVEN_REPOSITORY, repository.getPath()); }
@Nonnull public static Set<String> getMacroNames(Element root, @Nullable PathMacroFilter filter, @Nonnull final PathMacros pathMacros) { final PathMacrosCollectorImpl collector = new PathMacrosCollectorImpl(); collector.substitute(root, true, false, filter); final HashSet<String> result = new HashSet<String>(collector.myMacroMap.keySet()); result.removeAll(pathMacros.getSystemMacroNames()); result.removeAll(pathMacros.getLegacyMacroNames()); for (Macro macro : MacroManager.getInstance().getMacros()) { result.remove(macro.getName()); } result.removeAll(MacroManager.getInstance().getMacros()); result.removeAll(pathMacros.getIgnoredMacroNames()); return result; }
private List<String> createMacros() { List<String> list = new SmartList<>(); for (String name : PathMacros.getInstance().getUserMacroNames()) { list.add("$" + name + "$"); } if (withModuleDir) { list.add("$" + PathMacroUtil.MODULE_DIR_MACRO_NAME + "$"); list.add(ProgramParametersConfigurator.MODULE_WORKING_DIR); } return list; }
public static Map<String, String> getMacroMap() { final PathMacros macros = PathMacros.getInstance(); final Set<String> allNames = macros.getAllMacroNames(); final Map<String, String> map = new THashMap<>(allNames.size()); for (String eachMacroName : allNames) { map.put("$" + eachMacroName + "$", macros.getValue(eachMacroName)); } return map; }
@NotNull public static Set<String> getMacroNames(@NotNull final Element e) { return getMacroNames(e, new CompositePathMacroFilter(Extensions.getExtensions(MACRO_FILTER_EXTENSION_POINT_NAME)), PathMacros.getInstance()); }
public ProjectPathMacroManager(PathMacros pathMacros, Project project) { super(pathMacros); myProject = project; }
public BasePathMacroManager(@Nullable PathMacros pathMacros) { myPathMacros = (PathMacrosImpl)pathMacros; }
public ModulePathMacroManager(PathMacros pathMacros, Module module) { super(pathMacros); myModule = module; }