/*
 * Copyright 2000-2015 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jetbrains.idea.maven.importing.configurers;

import com.intellij.compiler.CompilerConfiguration;
import com.intellij.openapi.compiler.options.ExcludeEntryDescription;
import com.intellij.openapi.compiler.options.ExcludesConfiguration;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.project.MavenProject;

/**
 * @author Sergey Evdokimov
 */
public class MavenCompilerConfigurer extends MavenModuleConfigurer {
  @Override
  public void configure(@NotNull MavenProject mavenProject, @NotNull Project project, @Nullable Module module) {
    if (module == null) return;

    CompilerConfiguration configuration = CompilerConfiguration.getInstance(project);

    if (configuration.getBytecodeTargetLevel(module) == null) {
      String targetLevel = mavenProject.getTargetLevel();
      if (targetLevel == null) {
        // default source and target settings of maven-compiler-plugin is 1.5, see details at http://maven.apache.org/plugins/maven-compiler-plugin
        targetLevel = "1.5";
      }
      configuration.setBytecodeTargetLevel(module, targetLevel);
    }

    // Exclude src/main/archetype-resources
    VirtualFile dir = VfsUtil.findRelativeFile(mavenProject.getDirectoryFile(), "src", "main", "resources", "archetype-resources");
    if (dir != null && !configuration.isExcludedFromCompilation(dir)) {
      ExcludesConfiguration cfg = configuration.getExcludedEntriesConfiguration();
      cfg.addExcludeEntryDescription(new ExcludeEntryDescription(dir, true, false, project));
    }
  }
}

@@ -1011,24 +1011,62 @@
 irtualFile;%0A
+import com.intellij.util.ObjectUtils;%0A
 import org.j
@@ -1546,75 +1546,8 @@
 t);%0A
-%0A    if (configuration.getBytecodeTargetLevel(module) == null) %7B%0A  
     
@@ -1602,18 +1602,16 @@
 ();%0A    
-  
 if (targ
@@ -1617,16 +1617,72 @@
 getLevel
+ != null %7C%7C configuration.getBytecodeTargetLevel(module)
  == null
@@ -1681,26 +1681,24 @@
  == null) %7B%0A
-  
       // def
@@ -1835,45 +1835,8 @@
 gin%0A
-        targetLevel = %221.5%22;%0A      %7D%0A
     
@@ -1882,16 +1882,36 @@
 module, 
+ObjectUtils.notNull(
 targetLe
@@ -1913,16 +1913,24 @@
 getLevel
+, %221.5%22)
 );%0A    %7D

use maven-compiler-plugin configuration with higher priority than target level set by other importers; related issue: IDEA-138419 Maven: target bytecode version for a module seems to be always 1.5 (cherry picked from commit db4e1d6)