Search in sources :

Example 16 with Result

use of com.intellij.openapi.application.Result 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 17 with Result

use of com.intellij.openapi.application.Result 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 18 with Result

use of com.intellij.openapi.application.Result 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 19 with Result

use of com.intellij.openapi.application.Result 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 20 with Result

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

the class XmlChooseColorIntentionAction method chooseColor.

public static void chooseColor(JComponent editorComponent, PsiElement element) {
    String caption = CodeInsightBundle.message("intention.color.chooser.dialog");
    final XmlAttributeValue literal = PsiTreeUtil.getParentOfType(element, XmlAttributeValue.class, false);
    if (literal == null)
        return;
    final String text = StringUtil.unquoteString(literal.getValue());
    Color oldColor;
    try {
        oldColor = Color.decode(text);
    } catch (NumberFormatException e) {
        oldColor = JBColor.GRAY;
    }
    Color color = ColorChooser.chooseColor(editorComponent, caption, oldColor, true);
    if (color == null)
        return;
    if (!Comparing.equal(color, oldColor)) {
        if (!FileModificationService.getInstance().preparePsiElementForWrite(element))
            return;
        final String newText = "#" + ColorUtil.toHex(color);
        final PsiManager manager = literal.getManager();
        final XmlAttribute newAttribute = XmlElementFactory.getInstance(manager.getProject()).createAttribute("name", newText, element);
        final Runnable replaceRunnable = () -> {
            final XmlAttributeValue valueElement = newAttribute.getValueElement();
            assert valueElement != null;
            literal.replace(valueElement);
        };
        new WriteCommandAction(element.getProject(), caption) {

            @Override
            protected void run(@NotNull Result result) throws Throwable {
                replaceRunnable.run();
            }
        }.execute();
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlAttribute(com.intellij.psi.xml.XmlAttribute) JBColor(com.intellij.ui.JBColor) PsiManager(com.intellij.psi.PsiManager) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) Result(com.intellij.openapi.application.Result)

Aggregations

Result (com.intellij.openapi.application.Result)278 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)177 NotNull (org.jetbrains.annotations.NotNull)111 WriteAction (com.intellij.openapi.application.WriteAction)87 VirtualFile (com.intellij.openapi.vfs.VirtualFile)76 Project (com.intellij.openapi.project.Project)55 File (java.io.File)30 Document (com.intellij.openapi.editor.Document)28 Module (com.intellij.openapi.module.Module)28 XmlFile (com.intellij.psi.xml.XmlFile)28 IOException (java.io.IOException)26 PsiFile (com.intellij.psi.PsiFile)25 XmlTag (com.intellij.psi.xml.XmlTag)24 Nullable (org.jetbrains.annotations.Nullable)16 ArrayList (java.util.ArrayList)15 ReadAction (com.intellij.openapi.application.ReadAction)14 Editor (com.intellij.openapi.editor.Editor)12 NlModel (com.android.tools.idea.uibuilder.model.NlModel)11 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)10 TextRange (com.intellij.openapi.util.TextRange)10