2 * Copyright © 2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on a "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.onboarding;
19 import org.apache.maven.model.Plugin;
20 import org.apache.maven.plugin.AbstractMojo;
21 import org.apache.maven.plugin.MojoExecutionException;
22 import org.apache.maven.plugin.MojoFailureException;
23 import org.apache.maven.plugins.annotations.LifecyclePhase;
24 import org.apache.maven.plugins.annotations.Mojo;
25 import org.apache.maven.plugins.annotations.Parameter;
26 import org.apache.maven.plugins.annotations.ResolutionScope;
27 import org.apache.maven.project.MavenProject;
28 import org.codehaus.plexus.util.xml.Xpp3Dom;
30 import java.util.List;
32 import static org.openecomp.sdc.onboarding.Constants.*;
34 @Mojo(name = "pre-test-compile-helper", threadSafe = true, defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES,
35 requiresDependencyResolution = ResolutionScope.TEST)
36 public class PreTestCompileHelperMojo extends AbstractMojo {
39 private BuildState buildState;
40 @Parameter(defaultValue = "${project}", readonly = true)
41 private MavenProject project;
42 @Parameter(defaultValue = "${project.artifact.groupId}:${project.artifact.artifactId}")
43 private String moduleCoordinates;
44 @Parameter(defaultValue = "${project.buildPlugins}", readonly = true)
45 private List<Plugin> plugins;
47 private String excludePackaging;
50 public void execute() throws MojoExecutionException, MojoFailureException {
51 if (!System.getProperties().containsKey(UNICORN)) {
54 if (project.getPackaging().equals(excludePackaging)) {
57 if (buildState.isTestExecutionMandatory()) {
58 project.getProperties().setProperty(SKIP_TEST_RUN, Boolean.FALSE.toString());
60 boolean isTestMust = buildState.isTestMust(moduleCoordinates);
62 project.getProperties().setProperty(RESOURCES_CHANGED, Boolean.TRUE.toString());
63 if (!project.getProperties().containsKey(SKIP_TEST_RUN)) {
64 project.getProperties().setProperty(SKIP_TEST_RUN, Boolean.FALSE.toString());
67 if (!project.getProperties().containsKey(SKIP_TEST_RUN) || isTestSkippedExplicitly()) {
68 project.getProperties().setProperty(SKIP_TEST_RUN, Boolean.TRUE.toString());
70 if (System.getProperties().containsKey(JACOCO_SKIP) && Boolean.FALSE.equals(Boolean.valueOf(
71 System.getProperties().getProperty(JACOCO_SKIP)))) {
72 project.getProperties().setProperty(SKIP_TEST_RUN, Boolean.FALSE.toString());
77 private boolean isTestSkippedExplicitly() {
78 for (Plugin p : plugins) {
79 if ("org.apache.maven.plugins:maven-surefire-plugin".equals(p.getKey())) {
80 Xpp3Dom dom = Xpp3Dom.class.cast(p.getConfiguration());
81 if (dom.getChild(SKIP_TESTS) != null) {
82 return Boolean.TRUE.equals(Boolean.valueOf(dom.getValue()));