Search in sources :

Example 11 with WriteAction

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

the class MavenProjectReaderTest method testDefaults.

public void testDefaults() throws Exception {
    VirtualFile file = new WriteAction<VirtualFile>() {

        @Override
        protected void run(@NotNull Result<VirtualFile> result) throws Throwable {
            VirtualFile res = myProjectRoot.createChildData(this, "pom.xml");
            result.setResult(res);
            VfsUtil.saveText(res, "<project>" + "  <groupId>test</groupId>" + "  <artifactId>project</artifactId>" + "  <version>1</version>" + "</project>");
        }
    }.execute().getResultObject();
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    MavenModel p = readProject(file);
    assertEquals("jar", p.getPackaging());
    assertNull(p.getName());
    assertNull(p.getParent());
    assertEquals("project-1", p.getBuild().getFinalName());
    assertEquals(null, p.getBuild().getDefaultGoal());
    assertSize(1, p.getBuild().getSources());
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("src/main/java"), p.getBuild().getSources().get(0));
    assertSize(1, p.getBuild().getTestSources());
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("src/test/java"), p.getBuild().getTestSources().get(0));
    assertEquals(1, p.getBuild().getResources().size());
    assertResource(p.getBuild().getResources().get(0), pathFromBasedir("src/main/resources"), false, null, Collections.<String>emptyList(), Collections.<String>emptyList());
    assertEquals(1, p.getBuild().getTestResources().size());
    assertResource(p.getBuild().getTestResources().get(0), pathFromBasedir("src/test/resources"), false, null, Collections.<String>emptyList(), Collections.<String>emptyList());
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("target"), p.getBuild().getDirectory());
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("target/classes"), p.getBuild().getOutputDirectory());
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("target/test-classes"), p.getBuild().getTestOutputDirectory());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 12 with WriteAction

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

the class MavenProjectReaderTest method testCustomSettings.

public void testCustomSettings() throws Exception {
    VirtualFile file = new WriteAction<VirtualFile>() {

        @Override
        protected void run(@NotNull Result<VirtualFile> result) throws Throwable {
            VirtualFile res = myProjectRoot.createChildData(this, "pom.xml");
            result.setResult(res);
            VfsUtil.saveText(res, "<project>" + "  <modelVersion>1.2.3</modelVersion>" + "  <groupId>test</groupId>" + "  <artifactId>project</artifactId>" + "  <version>1</version>" + "  <name>foo</name>" + "  <packaging>pom</packaging>" + "  <parent>" + "    <groupId>testParent</groupId>" + "    <artifactId>projectParent</artifactId>" + "    <version>2</version>" + "    <relativePath>../parent/pom.xml</relativePath>" + "  </parent>" + "  <build>" + "    <finalName>xxx</finalName>" + "    <defaultGoal>someGoal</defaultGoal>" + "    <sourceDirectory>mySrc</sourceDirectory>" + "    <testSourceDirectory>myTestSrc</testSourceDirectory>" + "    <scriptSourceDirectory>myScriptSrc</scriptSourceDirectory>" + "    <resources>" + "      <resource>" + "        <directory>myRes</directory>" + "        <filtering>true</filtering>" + "        <targetPath>dir</targetPath>" + "        <includes><include>**.properties</include></includes>" + "        <excludes><exclude>**.xml</exclude></excludes>" + "      </resource>" + "    </resources>" + "    <testResources>" + "      <testResource>" + "        <directory>myTestRes</directory>" + "        <includes><include>**.properties</include></includes>" + "      </testResource>" + "    </testResources>" + "    <directory>myOutput</directory>" + "    <outputDirectory>myClasses</outputDirectory>" + "    <testOutputDirectory>myTestClasses</testOutputDirectory>" + "  </build>" + "</project>");
        }
    }.execute().getResultObject();
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    MavenModel p = readProject(file);
    assertEquals("pom", p.getPackaging());
    assertEquals("foo", p.getName());
    assertParent(p, "testParent", "projectParent", "2");
    assertEquals("xxx", p.getBuild().getFinalName());
    assertEquals("someGoal", p.getBuild().getDefaultGoal());
    assertSize(1, p.getBuild().getSources());
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("mySrc"), p.getBuild().getSources().get(0));
    assertSize(1, p.getBuild().getTestSources());
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("myTestSrc"), p.getBuild().getTestSources().get(0));
    assertEquals(1, p.getBuild().getResources().size());
    assertResource(p.getBuild().getResources().get(0), pathFromBasedir("myRes"), true, "dir", Collections.singletonList("**.properties"), Collections.singletonList("**.xml"));
    assertEquals(1, p.getBuild().getTestResources().size());
    assertResource(p.getBuild().getTestResources().get(0), pathFromBasedir("myTestRes"), false, null, Collections.singletonList("**.properties"), Collections.<String>emptyList());
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("myOutput"), p.getBuild().getDirectory());
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("myClasses"), p.getBuild().getOutputDirectory());
    PlatformTestUtil.assertPathsEqual(pathFromBasedir("myTestClasses"), p.getBuild().getTestOutputDirectory());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 13 with WriteAction

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

the class InvalidProjectImportingTest method testUnknownProblemWithEmptyFile.

public void testUnknownProblemWithEmptyFile() throws Exception {
    createProjectPom("");
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            myProjectPom.setBinaryContent(new byte[0]);
        }
    }.execute().throwException();
    importProject();
    assertModules("project");
    MavenProject root = getRootProjects().get(0);
    assertProblems(root, "'pom.xml' has syntax errors");
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject) WriteAction(com.intellij.openapi.application.WriteAction) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 14 with WriteAction

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

the class BuildoutFacetConfigurator method setupFacet.

static void setupFacet(Module module, @NotNull BuildoutFacetConfiguration config) {
    //TODO: refactor, see other python facets
    FacetManager facetManager = FacetManager.getInstance(module);
    final ModifiableFacetModel model = facetManager.createModifiableModel();
    BuildoutFacetType facetType = BuildoutFacetType.getInstance();
    BuildoutFacet facet = facetManager.createFacet(facetType, facetType.getDefaultFacetName(), config, null);
    model.addFacet(facet);
    new WriteAction() {

        protected void run(@NotNull final Result result) throws Throwable {
            model.commit();
        }
    }.execute();
    facet.updatePaths();
    BuildoutFacet.attachLibrary(module);
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) FacetManager(com.intellij.facet.FacetManager) ProjectFacetManager(com.intellij.facet.ProjectFacetManager) Result(com.intellij.openapi.application.Result)

Example 15 with WriteAction

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

the class ArtifactsTestCase method addModule.

protected Module addModule(final String moduleName, @Nullable final VirtualFile sourceRoot) {
    return new WriteAction<Module>() {

        @Override
        protected void run(@NotNull final Result<Module> result) {
            final Module module = createModule(moduleName);
            if (sourceRoot != null) {
                PsiTestUtil.addSourceContentToRoots(module, sourceRoot);
            }
            ModuleRootModificationUtil.setModuleSdk(module, getTestProjectJdk());
            result.setResult(module);
        }
    }.execute().getResultObject();
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Aggregations

Result (com.intellij.openapi.application.Result)85 WriteAction (com.intellij.openapi.application.WriteAction)85 NotNull (org.jetbrains.annotations.NotNull)38 VirtualFile (com.intellij.openapi.vfs.VirtualFile)37 File (java.io.File)20 IOException (java.io.IOException)16 Module (com.intellij.openapi.module.Module)10 PsiFile (com.intellij.psi.PsiFile)7 Sdk (com.intellij.openapi.projectRoots.Sdk)5 RunResult (com.intellij.openapi.application.RunResult)4 Document (com.intellij.openapi.editor.Document)4 Project (com.intellij.openapi.project.Project)4 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)4 Library (com.intellij.openapi.roots.libraries.Library)4 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)4 ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 FacetManager (com.intellij.facet.FacetManager)2 ProjectFacetManager (com.intellij.facet.ProjectFacetManager)2