Search in sources :

Example 16 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project freeline by alibaba.

the class FreelineUtil method installFreeline.

private static void installFreeline(final Project project, final FreelineStatus status, final PsiFile psiFile, final GradleDependencyEntity dependencyEntity) {
    needReformatCode = false;
    CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {

        @Override
        public void run() {
            ApplicationManager.getApplication().runWriteAction(new Runnable() {

                @Override
                public void run() {
                    if (!status.isExistClasspath()) {
                        Collection<VirtualFile> collection = status.getGradleBuildFiles();
                        if (dependencyEntity != null) {
                            for (VirtualFile file : collection) {
                                GradleBuildModel model = GradleBuildModel.parseBuildFile(file, project);
                                List<ArtifactDependencyModel> artifactDependencyModels = model.buildscript().dependencies().artifacts();
                                for (ArtifactDependencyModel model1 : artifactDependencyModels) {
                                    ArtifactDependencyModelWrapper wrapper = new ArtifactDependencyModelWrapper(model1);
                                    if (wrapper.group().equals(Constant.ANDROID_GRADLE_TOOL_GROUP_NAME)) {
                                        ArtifactDependencySpec spec = new ArtifactDependencySpec(dependencyEntity.getArtifactId(), dependencyEntity.getGroupId(), dependencyEntity.getNewestReleaseVersion());
                                        model.buildscript().dependencies().addArtifact("classpath", spec);
                                        model.applyChanges();
                                        needReformatCode = true;
                                        status.setClasspathFile(file);
                                        break;
                                    }
                                }
                                if (status.isExistClasspath()) {
                                    break;
                                }
                            }
                        }
                    }
                    if (!status.isExistPlugin()) {
                        if (psiFile != null && psiFile instanceof GroovyFile) {
                            GradleUtil.applyPlugin(project, (GroovyFile) psiFile, Constant.FREELINE_PLUGIN_ID);
                        }
                    }
                }
            });
        }
    });
    if (needReformatCode && status.getClasspathFile() != null) {
        DocumentUtil.reformatCode(project, status.getClasspathFile());
    }
    LogUtil.d("Sync Project Finish, start download freeline.zip.");
    initFreeline(project);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) ArtifactDependencySpec(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencySpec)

Example 17 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project plugins by kiteco.

the class KiteProjectComponent method sendEvent.

// -----sendEvent-----
private void sendEvent(String action, Editor editor) {
    try {
        if (editor == null) {
            return;
        }
        VirtualFile file = FileDocumentManager.getInstance().getFile(editor.getDocument());
        if (file == null) {
            log("  -> null file, skipping event");
            return;
        }
        if (!file.isInLocalFileSystem()) {
            log("  -> non-local file, skipping event");
            return;
        }
        m_kiteConnection.sendEvent(action, file.getCanonicalPath(), editor.getDocument().getText(), editor.getSelectionModel().getSelectionStart(), editor.getSelectionModel().getSelectionEnd());
    } catch (Exception e) {
        logException("Exception sending event", e);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 18 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoPathLibraryTest method testExcludeChildContentRootFromLibrary.

/**
   * src <content root>
   * goPath <gopath>
   * - src
   * -- contentRoot <content root>
   * -- notContentRoot
   */
public void testExcludeChildContentRootFromLibrary() throws IOException {
    VirtualFile goPath = createGoPath();
    VirtualFile src = goPath.createChildDirectory(this, "src");
    VirtualFile contentRoot = src.createChildDirectory(this, "contentRoot");
    VirtualFile notContentRoot = src.createChildDirectory(this, "notContentRoot");
    addContentRoot(contentRoot);
    GoApplicationLibrariesService.getInstance().setLibraryRootUrls(goPath.getUrl());
    assertLibrary(Collections.singletonList(notContentRoot.getUrl()), "temp:///src", contentRoot.getUrl());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 19 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoRunConfigurationTestCase method doTestProducedConfigurations.

protected void doTestProducedConfigurations() {
    VirtualFile file = myFixture.copyFileToProject(getTestName(true) + ".go", "import/path/" + getTestName(true) + ".go");
    myFixture.configureFromExistingVirtualFile(file);
    doTestProducedConfigurations(myFixture.getFile().findElementAt(myFixture.getCaretOffset()));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 20 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoPathLibraryTest method testAddGoPathAsLibrary.

/**
   * src <content root>
   * goPath <gopath>
   * - src
   * -- test
   */
public void testAddGoPathAsLibrary() throws IOException {
    VirtualFile goPath = createGoPath();
    VirtualFile goPathContent = goPath.createChildDirectory(this, "src").createChildDirectory(this, "test");
    GoApplicationLibrariesService.getInstance().setLibraryRootUrls(goPath.getUrl());
    assertLibrary(Collections.singletonList(goPathContent.getUrl()), "temp:///src");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)5443 File (java.io.File)757 Nullable (org.jetbrains.annotations.Nullable)719 Project (com.intellij.openapi.project.Project)718 NotNull (org.jetbrains.annotations.NotNull)703 PsiFile (com.intellij.psi.PsiFile)564 Module (com.intellij.openapi.module.Module)495 IOException (java.io.IOException)327 ArrayList (java.util.ArrayList)258 Document (com.intellij.openapi.editor.Document)241 PsiElement (com.intellij.psi.PsiElement)205 Test (org.junit.Test)193 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)114 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)100 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)91 List (java.util.List)90