8b0ff0eba23d9e9efdae212bdbb351576479751b
[sdc.git] /
1 /*
2  * Copyright © 2018 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdc.onboarding;
18
19 import static org.openecomp.sdc.onboarding.Constants.FORK_COUNT;
20 import static org.openecomp.sdc.onboarding.Constants.FORK_MODE;
21 import static org.openecomp.sdc.onboarding.Constants.JACOCO_SKIP;
22 import static org.openecomp.sdc.onboarding.Constants.SKIP_PMD;
23 import static org.openecomp.sdc.onboarding.Constants.UNICORN;
24
25 import org.apache.maven.plugin.AbstractMojo;
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugin.MojoFailureException;
28 import org.apache.maven.plugins.annotations.LifecyclePhase;
29 import org.apache.maven.plugins.annotations.Mojo;
30 import org.apache.maven.plugins.annotations.Parameter;
31 import org.apache.maven.plugins.annotations.ResolutionScope;
32 import org.apache.maven.project.MavenProject;
33
34 @Mojo(name = "init-helper", threadSafe = true, defaultPhase = LifecyclePhase.GENERATE_RESOURCES,
35         requiresDependencyResolution = ResolutionScope.TEST)
36 public class InitializationHelperMojo extends AbstractMojo {
37
38     @Parameter(defaultValue = "${project}", readonly = true)
39     private MavenProject project;
40     @Parameter
41     private BuildState buildState;
42     @Parameter
43     private String excludePackaging;
44
45     public void execute() throws MojoExecutionException, MojoFailureException {
46
47         if (project.getPackaging().equals(excludePackaging)) {
48             return;
49         }
50         project.getProperties().setProperty("skipGet", "false");
51         if (System.getProperties().containsKey(JACOCO_SKIP) && Boolean.FALSE.equals(Boolean.valueOf(
52                 System.getProperties().getProperty(JACOCO_SKIP)))) {
53             project.getProperties().setProperty(FORK_COUNT, "1");
54             project.getProperties().setProperty(FORK_MODE, "once");
55         } else {
56             project.getProperties().setProperty(FORK_COUNT, "0");
57             project.getProperties().setProperty(FORK_MODE, "never");
58         }
59
60         project.getProperties().setProperty(SKIP_PMD, Boolean.TRUE.toString());
61
62         if (System.getProperties().containsKey(UNICORN)) {
63             buildState.init();
64         } else {
65             project.getProperties().setProperty("skipMainSourceCompile", "false");
66             project.getProperties().setProperty("skipTestSourceCompile", "false");
67         }
68
69     }
70
71 }