re base code
[sdc.git] / openecomp-be / tools / compile-helper-plugin / src / main / java / org / openecomp / sdc / onboarding / InitializationHelperMojo.java
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 org.apache.maven.plugin.AbstractMojo;
20 import org.apache.maven.plugin.MojoExecutionException;
21 import org.apache.maven.plugin.MojoFailureException;
22 import org.apache.maven.plugins.annotations.LifecyclePhase;
23 import org.apache.maven.plugins.annotations.Mojo;
24 import org.apache.maven.plugins.annotations.Parameter;
25 import org.apache.maven.plugins.annotations.ResolutionScope;
26 import org.apache.maven.project.MavenProject;
27
28 import static org.openecomp.sdc.onboarding.Constants.*;
29
30 @Mojo(name = "init-helper", threadSafe = true, defaultPhase = LifecyclePhase.GENERATE_RESOURCES,
31         requiresDependencyResolution = ResolutionScope.TEST)
32 public class InitializationHelperMojo extends AbstractMojo {
33
34     @Parameter(defaultValue = "${project}", readonly = true)
35     private MavenProject project;
36     @Parameter
37     private BuildState buildState;
38     @Parameter
39     private String excludePackaging;
40
41     @Override
42     public void execute() throws MojoExecutionException, MojoFailureException {
43         if (PREFIX == UNICORN || JACOCO == UNICORN) {
44             System.getProperties().setProperty(UNICORN, Boolean.TRUE.toString());
45         }
46         if (project.getPackaging().equals(excludePackaging)) {
47             return;
48         }
49         if (Boolean.valueOf(JACOCO_BUILD)) {
50             project.getProperties().setProperty(FORK_COUNT, "1");
51             project.getProperties().setProperty(FORK_MODE, "once");
52         } else {
53             project.getProperties().setProperty(FORK_COUNT, "0");
54             project.getProperties().setProperty(FORK_MODE, "never");
55         }
56
57         project.getProperties().setProperty(SKIP_PMD, Boolean.TRUE.toString());
58
59         if (System.getProperties().containsKey(UNICORN)) {
60             buildState.init();
61         } else {
62             project.getProperties().setProperty("skipMainSourceCompile", Boolean.FALSE.toString());
63             project.getProperties().setProperty("skipTestSourceCompile", Boolean.FALSE.toString());
64         }
65
66
67     }
68
69
70 }