// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.gradle.importing;

import com.intellij.compiler.CompilerConfiguration;
import com.intellij.compiler.CompilerConfigurationImpl;
import com.intellij.compiler.CompilerWorkspaceConfiguration;
import com.intellij.compiler.impl.javaCompiler.javac.JavacConfiguration;
import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions;
import org.junit.Test;

/**
 * @author Vladislav.Soroka
 */
public class GradleJavaSettingsImportingTest extends GradleSettingsImportingTest {
  @Test
  public void testCompilerConfigurationSettingsImport() throws Exception {

    importProject(
      withGradleIdeaExtPlugin(
        "idea {\n" +
        "  project.settings {\n" +
        "    compiler {\n" +
        "      resourcePatterns '!*.java;!*.class'\n" +
        "      clearOutputDirectory false\n" +
        "      addNotNullAssertions false\n" +
        "      autoShowFirstErrorInEditor false\n" +
        "      displayNotificationPopup false\n" +
        "      enableAutomake false\n" +
        "      parallelCompilation true\n" +
        "      rebuildModuleOnDependencyChange false\n" +
        "      javac {\n" +
        "        preferTargetJDKCompiler false\n" +
        "        javacAdditionalOptions '-Dkey=val'\n" +
        "        generateNoWarnings true\n" +
        "      }\n" +
        "    }\n" +
        "  }\n" +
        "}")
    );

    final CompilerConfigurationImpl compilerConfiguration = (CompilerConfigurationImpl)CompilerConfiguration.getInstance(myProject);
    final CompilerWorkspaceConfiguration workspaceConfiguration = CompilerWorkspaceConfiguration.getInstance(myProject);

    assertSameElements(compilerConfiguration.getResourceFilePatterns(), "!*.class", "!*.java");
    assertFalse(workspaceConfiguration.CLEAR_OUTPUT_DIRECTORY);
    assertFalse(compilerConfiguration.isAddNotNullAssertions());
    assertFalse(workspaceConfiguration.AUTO_SHOW_ERRORS_IN_EDITOR);
    assertFalse(workspaceConfiguration.DISPLAY_NOTIFICATION_POPUP);
    assertFalse(workspaceConfiguration.MAKE_PROJECT_ON_SAVE);
    assertTrue(workspaceConfiguration.PARALLEL_COMPILATION);
    assertFalse(workspaceConfiguration.REBUILD_ON_DEPENDENCY_CHANGE);

    final JpsJavaCompilerOptions javacOpts = JavacConfiguration.getOptions(myProject, JavacConfiguration.class);
    assertFalse(javacOpts.PREFER_TARGET_JDK_COMPILER);
    assertEquals("-Dkey=val", javacOpts.ADDITIONAL_OPTIONS_STRING);
    assertTrue(javacOpts.GENERATE_NO_WARNINGS);
  }
}

@@ -421,24 +421,131 @@
 figuration;%0A
+import com.intellij.packaging.artifacts.Artifact;%0Aimport com.intellij.packaging.artifacts.ArtifactManager;%0A
 import org.j
@@ -2722,11 +2722,642 @@
 GS);%0A  %7D
+%0A%0A  @Test%0A  public void testArtifactsSettingsImport() throws Exception %7B%0A    importProject(%0A      withGradleIdeaExtPlugin(%0A        %22import org.jetbrains.gradle.ext.*%5Cn%22 +%0A        %22idea %7B%5Cn%22 +%0A        %22  project.settings %7B%5Cn%22 +%0A        %22    ideArtifacts %7B%5Cn%22 +%0A        %22      ideArtifact(%5C%22myArt%5C%22) %7B%5Cn%22 +%0A        %22         file(%5C%22build.gradle%5C%22)%5Cn%22 +%0A        %22      %7D%5Cn%22 +%0A        %22    %7D%5Cn%22 +%0A        %22  %7D%5Cn%22 +%0A        %22%7D%22)%0A    );%0A    final ArtifactManager artifactManager = ArtifactManager.getInstance(myProject);%0A%0A    final Artifact artifact = artifactManager.getArtifacts()%5B0%5D;%0A    assertEquals(%22myArt%22, artifact.getName());%0A  %7D
 %0A%7D%0A

test import IDEA artifacts from gradle