Search in sources :

Example 6 with PathMacros

use of com.intellij.openapi.application.PathMacros in project intellij-plugins by JetBrains.

the class FlashBuilderImportTest method testPathVariables.

public void testPathVariables() throws Exception {
    final PathMacros pathMacros = PathMacros.getInstance();
    if (pathMacros.getValue("FLASH_BUILDER_PATH_VARIABLE") != null) {
        pathMacros.removeMacro("FLASH_BUILDER_PATH_VARIABLE");
    }
    final VirtualFile settingsDir = VfsUtil.createDirectories(myFlashBuilderProjectDir.getPath() + "/Flash_Builder_workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings");
    final String someAbsoluteFolderPath = getSomeAbsoluteFolderPath();
    final String content = "#Fri Sep 10 19:11:24 MSD 2010\n" + "eclipse.preferences.version=1\n" + "pathvariable.FLASH_BUILDER_PATH_VARIABLE=" + someAbsoluteFolderPath.replace(":", "\\:") + "\n";
    addFileWithContent("org.eclipse.core.resources.prefs", content, settingsDir);
    addFileWithContent("com.adobe.flexbuilder.project.prefs", content, settingsDir);
    importProject(getStandardDotProjectFileContent(), "<actionScriptProperties>\n" + "  <compiler additionalCompilerArguments='-some -locale  en_US  ja_JP  -other '>\n" + "    <compilerSourcePath>\n" + "      <compilerSourcePathEntry kind=\"1\" path=\"${FLASH_BUILDER_PATH_VARIABLE}/src5\"/>\n" + "      <compilerSourcePathEntry kind=\"1\" path=\"locales\\{locale}\"/>\n" + "    </compilerSourcePath>" + "    <libraryPath defaultLinkType=\"0\">\n" + "      <libraryPathEntry kind=\"3\" linkType=\"1\" path=\"${FLASH_BUILDER_PATH_VARIABLE}/somelib/somelib.swc\" useDefaultLinkType=\"false\"/>\n" + "    </libraryPath>" + "  </compiler>\n" + "</actionScriptProperties>", new ArrayList<>(), myFlashBuilderProjectDir.getPath() + "/Flash_Builder_workspace");
    final String contentRootUrl = myFlashBuilderProjectDir.getUrl();
    checkContentRoots(contentRootUrl, VfsUtilCore.pathToUrl(someAbsoluteFolderPath + "/src5"));
    checkSourceRoots(VfsUtilCore.pathToUrl(someAbsoluteFolderPath + "/src5"), contentRootUrl + "/locales/en_US", contentRootUrl + "/locales/ja_JP");
    checkLibraries(new LibraryInfo[] { new LibraryInfo("somelib", null, someAbsoluteFolderPath + "/somelib/somelib.swc") });
    final FlexBuildConfiguration bc = getBC();
    assertEquals("-some -other ", bc.getCompilerOptions().getAdditionalOptions());
    assertEquals(1, bc.getCompilerOptions().getAllOptions().size());
    assertEquals("en_US\nja_JP", bc.getCompilerOptions().getOption("compiler.locale"));
    assertEquals(someAbsoluteFolderPath, pathMacros.getValue("FLASH_BUILDER_PATH_VARIABLE"));
    pathMacros.removeMacro("FLASH_BUILDER_PATH_VARIABLE");
}
Also used : PathMacros(com.intellij.openapi.application.PathMacros)

Example 7 with PathMacros

use of com.intellij.openapi.application.PathMacros in project intellij-community by JetBrains.

the class PathMacroListEditor method commit.

public void commit() throws ConfigurationException {
    ApplicationManager.getApplication().runWriteAction(() -> {
        myPathMacroTable.commit();
        final Collection<String> ignored = parseIgnoredVariables();
        final PathMacros instance = PathMacros.getInstance();
        instance.setIgnoredMacroNames(ignored);
    });
}
Also used : PathMacros(com.intellij.openapi.application.PathMacros)

Example 8 with PathMacros

use of com.intellij.openapi.application.PathMacros in project intellij-community by JetBrains.

the class ParametersList method getMacroMap.

private Map<String, String> getMacroMap() {
    if (myMacroMap == null) {
        // the insertion order is important for later iterations, so LinkedHashMap is used
        myMacroMap = new LinkedHashMap<>();
        // ApplicationManager.getApplication() will return null if executed in ParameterListTest
        final Application application = ApplicationManager.getApplication();
        if (application != null) {
            final PathMacros pathMacros = PathMacros.getInstance();
            if (pathMacros != null) {
                for (String name : pathMacros.getUserMacroNames()) {
                    final String value = pathMacros.getValue(name);
                    if (value != null) {
                        myMacroMap.put("${" + name + "}", value);
                    }
                }
            }
            final Map<String, String> env = EnvironmentUtil.getEnvironmentMap();
            for (String name : env.keySet()) {
                final String key = "${" + name + "}";
                if (!myMacroMap.containsKey(key)) {
                    myMacroMap.put(key, env.get(name));
                }
            }
        }
    }
    return myMacroMap;
}
Also used : PathMacros(com.intellij.openapi.application.PathMacros) Application(com.intellij.openapi.application.Application)

Example 9 with PathMacros

use of com.intellij.openapi.application.PathMacros in project intellij-community by JetBrains.

the class EPathUtil method collapse2EclipseVariabledPath.

@Nullable
static String collapse2EclipseVariabledPath(final LibraryOrderEntry libraryOrderEntry, OrderRootType type) {
    final VirtualFile[] virtualFiles = libraryOrderEntry.getRootFiles(type);
    if (virtualFiles.length > 0) {
        VirtualFile jarFile = virtualFiles[0];
        if (jarFile.getFileSystem() instanceof JarFileSystem) {
            jarFile = JarFileSystem.getInstance().getVirtualFileForJar(jarFile);
        }
        if (jarFile == null) {
            return null;
        }
        final Project project = libraryOrderEntry.getOwnerModule().getProject();
        final VirtualFile baseDir = project.getBaseDir();
        final String filePath = jarFile.getPath();
        if (baseDir != null && !VfsUtilCore.isAncestor(baseDir, jarFile, false)) {
            final String ideaCollapsed = PathMacroManager.getInstance(project).collapsePath(filePath);
            if (ideaCollapsed.contains(".."))
                return null;
            final int index = ideaCollapsed.indexOf('$');
            if (index < 0)
                return null;
            return ideaCollapsed.substring(index).replace("$", "");
        }
    }
    for (String url : libraryOrderEntry.getRootUrls(type)) {
        //check if existing eclipse variable points inside project or doesn't exist
        String filePath = VirtualFileManager.extractPath(url);
        final int jarSeparatorIdx = filePath.indexOf(JarFileSystem.JAR_SEPARATOR);
        if (jarSeparatorIdx > -1) {
            filePath = filePath.substring(0, jarSeparatorIdx);
        }
        final PathMacros pathMacros = PathMacros.getInstance();
        final Set<String> names = pathMacros.getUserMacroNames();
        for (String name : names) {
            final String path = FileUtil.toSystemIndependentName(pathMacros.getValue(name));
            if (filePath.startsWith(path + "/")) {
                final String substr = filePath.substring(path.length());
                return name + (substr.startsWith("/") || substr.length() == 0 ? substr : "/" + substr);
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PathMacros(com.intellij.openapi.application.PathMacros) Project(com.intellij.openapi.project.Project) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with PathMacros

use of com.intellij.openapi.application.PathMacros in project intellij-community by JetBrains.

the class FileChooserFactoryImpl method getMacroMap.

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;
}
Also used : PathMacros(com.intellij.openapi.application.PathMacros) THashMap(gnu.trove.THashMap)

Aggregations

PathMacros (com.intellij.openapi.application.PathMacros)12 Application (com.intellij.openapi.application.Application)2 ReplacePathToMacroMap (com.intellij.application.options.ReplacePathToMacroMap)1 Project (com.intellij.openapi.project.Project)1 JarFileSystem (com.intellij.openapi.vfs.JarFileSystem)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 THashMap (gnu.trove.THashMap)1 File (java.io.File)1 Nullable (org.jetbrains.annotations.Nullable)1