Search in sources :

Example 86 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class SvnMergeProvider method conflictResolvedForFile.

public void conflictResolvedForFile(@NotNull VirtualFile file) {
    // TODO: Add possibility to resolve content conflicts separately from property conflicts.
    SvnVcs vcs = SvnVcs.getInstance(myProject);
    File path = virtualToIoFile(file);
    try {
        // TODO: Probably false should be passed to "resolveTree", but previous logic used true implicitly
        vcs.getFactory(path).createConflictClient().resolve(path, Depth.EMPTY, false, true, true);
    } catch (VcsException e) {
        LOG.warn(e);
    }
    // the .mine/.r## files have been deleted
    final VirtualFile parent = file.getParent();
    if (parent != null) {
        parent.refresh(true, false);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsException(com.intellij.openapi.vcs.VcsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) SvnVcs(org.jetbrains.idea.svn.SvnVcs)

Example 87 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class SvnMergeProvider method loadRevisions.

@NotNull
public MergeData loadRevisions(@NotNull final VirtualFile file) throws VcsException {
    final MergeData data = new MergeData();
    VcsRunnable runnable = () -> {
        File oldFile = null;
        File newFile = null;
        File workingFile = null;
        boolean mergeCase = false;
        SvnVcs vcs = SvnVcs.getInstance(myProject);
        Info info = vcs.getInfo(file);
        if (info != null) {
            oldFile = info.getConflictOldFile();
            newFile = info.getConflictNewFile();
            workingFile = info.getConflictWrkFile();
            mergeCase = workingFile == null || workingFile.getName().contains("working");
            // for debug
            if (workingFile == null) {
                LOG.info("Null working file when merging text conflict for " + file.getPath() + " old file: " + oldFile + " new file: " + newFile);
            }
            if (mergeCase) {
                // this is merge case
                oldFile = info.getConflictNewFile();
                newFile = info.getConflictOldFile();
                workingFile = info.getConflictWrkFile();
            }
            data.LAST_REVISION_NUMBER = new SvnRevisionNumber(info.getRevision());
        } else {
            throw new VcsException("Could not get info for " + file.getPath());
        }
        if (oldFile == null || newFile == null || workingFile == null) {
            ByteArrayOutputStream bos = getBaseRevisionContents(vcs, file);
            data.ORIGINAL = bos.toByteArray();
            data.LAST = bos.toByteArray();
            data.CURRENT = readFile(virtualToIoFile(file));
        } else {
            data.ORIGINAL = readFile(oldFile);
            data.LAST = readFile(newFile);
            data.CURRENT = readFile(workingFile);
        }
        if (mergeCase) {
            final ByteArrayOutputStream contents = getBaseRevisionContents(vcs, file);
            if (!Arrays.equals(contents.toByteArray(), data.ORIGINAL)) {
                // swap base and server: another order of merge arguments
                byte[] original = data.ORIGINAL;
                data.ORIGINAL = data.LAST;
                data.LAST = original;
            }
        }
    };
    VcsUtil.runVcsProcessWithProgress(runnable, VcsBundle.message("multiple.file.merge.loading.progress.title"), false, myProject);
    return data;
}
Also used : SvnRevisionNumber(org.jetbrains.idea.svn.SvnRevisionNumber) VcsRunnable(com.intellij.vcsUtil.VcsRunnable) MergeData(com.intellij.openapi.vcs.merge.MergeData) VcsException(com.intellij.openapi.vcs.VcsException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Info(org.jetbrains.idea.svn.info.Info) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) SvnVcs(org.jetbrains.idea.svn.SvnVcs) NotNull(org.jetbrains.annotations.NotNull)

Example 88 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class SuiteBrowser method showDialog.

@Override
public String showDialog() {
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) {

        @Override
        public boolean isFileVisible(VirtualFile virtualFile, boolean showHidden) {
            if (!showHidden && virtualFile.getName().charAt(0) == '.')
                return false;
            return virtualFile.isDirectory() || "xml".equals(virtualFile.getExtension());
        }
    };
    descriptor.setDescription("Please select the testng.xml suite file");
    descriptor.setTitle("Select Suite");
    VirtualFile file = FileChooser.chooseFile(descriptor, getProject(), null);
    return file != null ? file.getPath() : null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor)

Example 89 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class XsltDebuggerExtension method patchParameters.

public void patchParameters(final SimpleJavaParameters parameters, XsltRunConfiguration configuration, UserDataHolder extensionData) throws CantRunException {
    final XsltRunConfiguration.OutputType outputType = configuration.getOutputType();
    final Sdk jdk = configuration.getEffectiveJDK();
    assert jdk != null;
    final String ver = jdk.getVersionString();
    if (ver == null || (ver.contains("1.0") || ver.contains("1.1") || ver.contains("1.2") || ver.contains("1.3") || ver.contains("1.4"))) {
        throw new CantRunException("The XSLT Debugger can only be used with JDK 1.5+");
    }
    // TODO: fix and remove
    if (outputType != XsltRunConfiguration.OutputType.CONSOLE) {
        throw new CantRunException("XSLT Debugger requires Output Type == CONSOLE");
    }
    try {
        final int port = NetUtils.findAvailableSocketPort();
        parameters.getVMParametersList().defineProperty("xslt.debugger.port", String.valueOf(port));
        extensionData.putUserData(PORT, port);
    } catch (IOException e) {
        LOG.info(e);
        throw new CantRunException("Unable to find a free network port");
    }
    final char c = File.separatorChar;
    final PluginId pluginId = PluginManagerCore.getPluginByClassName(getClass().getName());
    assert pluginId != null || System.getProperty("xslt-debugger.plugin.path") != null;
    final File pluginPath;
    if (pluginId != null) {
        final IdeaPluginDescriptor descriptor = PluginManager.getPlugin(pluginId);
        assert descriptor != null;
        pluginPath = descriptor.getPath();
    } else {
        // -Dxslt-debugger.plugin.path=C:\work\java\intellij/ultimate\out\classes\production\xslt-debugger-engine
        pluginPath = new File(System.getProperty("xslt-debugger.plugin.path"));
    }
    File rtClasspath = new File(pluginPath, "lib" + c + "xslt-debugger-engine.jar");
    if (rtClasspath.exists()) {
        parameters.getClassPath().addTail(rtClasspath.getAbsolutePath());
        final File rmiStubs = new File(pluginPath, "lib" + c + "rmi-stubs.jar");
        assert rmiStubs.exists() : rmiStubs.getAbsolutePath();
        parameters.getClassPath().addTail(rmiStubs.getAbsolutePath());
        final File engineImpl = new File(pluginPath, "lib" + c + "rt" + c + "xslt-debugger-engine-impl.jar");
        assert engineImpl.exists() : engineImpl.getAbsolutePath();
        parameters.getClassPath().addTail(engineImpl.getAbsolutePath());
    } else {
        if (!(rtClasspath = new File(pluginPath, "classes")).exists()) {
            if (ApplicationManagerEx.getApplicationEx().isInternal() && new File(pluginPath, "org").exists()) {
                rtClasspath = pluginPath;
                final File engineImplInternal = new File(pluginPath, ".." + c + "xslt-debugger-engine-impl");
                assert engineImplInternal.exists() : engineImplInternal.getAbsolutePath();
                parameters.getClassPath().addTail(engineImplInternal.getAbsolutePath());
            } else {
                throw new CantRunException("Runtime classes not found");
            }
        }
        parameters.getClassPath().addTail(rtClasspath.getAbsolutePath());
        final File rmiStubs = new File(rtClasspath, "rmi-stubs.jar");
        assert rmiStubs.exists() : rmiStubs.getAbsolutePath();
        parameters.getClassPath().addTail(rmiStubs.getAbsolutePath());
    }
    File trove4j = new File(PathManager.getLibPath() + c + "trove4j.jar");
    if (!trove4j.exists()) {
        trove4j = new File(PathManager.getHomePath() + c + "community" + c + "lib" + c + "trove4j.jar");
        assert trove4j.exists() : trove4j.getAbsolutePath();
    }
    parameters.getClassPath().addTail(trove4j.getAbsolutePath());
    final String type = parameters.getVMParametersList().getPropertyValue("xslt.transformer.type");
    if ("saxon".equalsIgnoreCase(type)) {
        addSaxon(parameters, pluginPath, SAXON_6_JAR);
    } else if ("saxon9".equalsIgnoreCase(type)) {
        addSaxon(parameters, pluginPath, SAXON_9_JAR);
    } else if ("xalan".equalsIgnoreCase(type)) {
        final Boolean xalanPresent = isValidXalanPresent(parameters);
        if (xalanPresent == null) {
            addXalan(parameters, pluginPath);
        } else if (!xalanPresent) {
            throw new CantRunException("Unsupported Xalan version is present in classpath.");
        }
    } else if (type != null) {
        throw new CantRunException("Unsupported Transformer type '" + type + "'");
    } else if (parameters.getClassPath().getPathsString().toLowerCase().contains("xalan")) {
        if (isValidXalanPresent(parameters) == Boolean.TRUE) {
            parameters.getVMParametersList().defineProperty("xslt.transformer.type", "xalan");
        }
    }
    final VirtualFile xsltFile = configuration.findXsltFile();
    final PsiManager psiManager = PsiManager.getInstance(configuration.getProject());
    final XsltChecker.LanguageLevel level;
    if (xsltFile != null) {
        level = XsltSupport.getXsltLanguageLevel(psiManager.findFile(xsltFile));
    } else {
        level = XsltChecker.LanguageLevel.V1;
    }
    extensionData.putUserData(VERSION, level);
    if (!parameters.getVMParametersList().hasProperty("xslt.transformer.type")) {
        // add saxon for backward-compatibility
        if (level == XsltChecker.LanguageLevel.V2) {
            parameters.getVMParametersList().defineProperty("xslt.transformer.type", "saxon9");
            addSaxon(parameters, pluginPath, SAXON_9_JAR);
        } else {
            parameters.getVMParametersList().defineProperty("xslt.transformer.type", "saxon");
            addSaxon(parameters, pluginPath, SAXON_6_JAR);
        }
    }
    parameters.getVMParametersList().defineProperty("xslt.main", "org.intellij.plugins.xsltDebugger.rt.XSLTDebuggerMain");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XsltRunConfiguration(org.intellij.lang.xpath.xslt.run.XsltRunConfiguration) PsiManager(com.intellij.psi.PsiManager) IOException(java.io.IOException) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) XsltChecker(org.intellij.lang.xpath.xslt.impl.XsltChecker) PluginId(com.intellij.openapi.extensions.PluginId) CantRunException(com.intellij.execution.CantRunException) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 90 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class XsltDebuggerExtension method isValidXalanPresent.

@Nullable
private static Boolean isValidXalanPresent(SimpleJavaParameters parameters) {
    final List<VirtualFile> files = parameters.getClassPath().getVirtualFiles();
    for (VirtualFile file : files) {
        if (file.getName().matches(".*xalan.*\\.jar")) {
            final VirtualFile root = JarFileSystem.getInstance().getJarRootForLocalFile(file);
            final VirtualFile manifestFile = root != null ? root.findFileByRelativePath("META-INF/MANIFEST.MF") : null;
            if (manifestFile != null) {
                try {
                    Manifest manifest = manifestFile.getUserData(MANIFEST);
                    if (manifest == null) {
                        manifest = new Manifest(manifestFile.getInputStream());
                        manifestFile.putUserData(MANIFEST, manifest);
                    }
                    Attributes attributes = manifest.getAttributes("org/apache/xalan/");
                    if (attributes == null) {
                        attributes = manifest.getAttributes("org/apache/xalan");
                    }
                    if (attributes == null) {
                        LOG.info("No manifest attributes for 'org/apache/xalan/' in " + manifestFile.getPresentableUrl());
                        continue;
                    }
                    final String version = attributes.getValue("Implementation-Version");
                    if (version != null) {
                        final String[] parts = version.split("\\.");
                        if (parts.length >= 2) {
                            if (Integer.parseInt(parts[0]) >= 2 && Integer.parseInt(parts[1]) >= 6) {
                                return true;
                            }
                        }
                        LOG.info("Unsupported Xalan version: " + version);
                    } else {
                        LOG.info("No Xalan version information in " + file.getPath());
                    }
                } catch (IOException e) {
                    LOG.warn("Unable to read manifest from " + file.getName(), e);
                }
            } else {
                LOG.info("No manifest file in " + file.getPath());
            }
            return false;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Attributes(java.util.jar.Attributes) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)5465 File (java.io.File)762 Project (com.intellij.openapi.project.Project)720 Nullable (org.jetbrains.annotations.Nullable)720 NotNull (org.jetbrains.annotations.NotNull)703 PsiFile (com.intellij.psi.PsiFile)571 Module (com.intellij.openapi.module.Module)501 IOException (java.io.IOException)327 ArrayList (java.util.ArrayList)260 Document (com.intellij.openapi.editor.Document)244 PsiElement (com.intellij.psi.PsiElement)209 Test (org.junit.Test)196 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)124 PsiDirectory (com.intellij.psi.PsiDirectory)124 XmlFile (com.intellij.psi.xml.XmlFile)124 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)116 Editor (com.intellij.openapi.editor.Editor)115 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)101 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)91 List (java.util.List)90