IDEA-133754 Maven: resources builder: support outputDirectory parameters of maven...
[idea/community.git] / plugins / maven / src / main / java / org / jetbrains / idea / maven / project / MavenResourceCompilerConfigurationGenerator.java
index 86f73e9721fa391bd8ea1ddafd01578a20a79283..a245114ad5e6cc10335b4258c8c990ef34c4bc27 100644 (file)
@@ -23,6 +23,7 @@ import com.intellij.util.xmlb.XmlSerializer;
 import org.jdom.Document;
 import org.jdom.Element;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.jetbrains.idea.maven.dom.references.MavenFilteredPropertyPsiReferenceProvider;
 import org.jetbrains.idea.maven.model.MavenId;
 import org.jetbrains.idea.maven.model.MavenResource;
@@ -124,7 +125,9 @@ public class MavenResourceCompilerConfigurationGenerator {
       }
 
       Element pluginConfiguration = mavenProject.getPluginConfiguration("org.apache.maven.plugins", "maven-resources-plugin");
-      resourceConfig.outputDirectory = MavenJDOMUtil.findChildValueByPath(pluginConfiguration, "outputDirectory", null);
+
+      resourceConfig.outputDirectory = getResourcesPluginGoalOutputDirectory(mavenProject, pluginConfiguration, "resources");
+      resourceConfig.testOutputDirectory = getResourcesPluginGoalOutputDirectory(mavenProject, pluginConfiguration, "testResources");
 
       addResources(resourceConfig.resources, mavenProject.getResources());
       addResources(resourceConfig.testResources, mavenProject.getTestResources());
@@ -182,6 +185,20 @@ public class MavenResourceCompilerConfigurationGenerator {
     });
   }
 
+  @Nullable
+  private static String getResourcesPluginGoalOutputDirectory(@NotNull MavenProject mavenProject,
+                                                              @Nullable Element pluginConfiguration,
+                                                              @NotNull String goal) {
+    final Element goalConfiguration = mavenProject.getPluginGoalConfiguration("org.apache.maven.plugins", "maven-resources-plugin", goal);
+    String outputDirectory = MavenJDOMUtil.findChildValueByPath(goalConfiguration, "outputDirectory", null);
+    if (outputDirectory == null) {
+      outputDirectory = MavenJDOMUtil.findChildValueByPath(pluginConfiguration, "outputDirectory", null);
+    }
+    return outputDirectory == null || FileUtil.isAbsolute(outputDirectory)
+           ? outputDirectory
+           : mavenProject.getDirectory() + '/' + outputDirectory;
+  }
+
   private static void generateManifest(@NotNull MavenProject mavenProject, @NotNull Module module) {
     try {
       String jdkVersion = null;