04e0ca8e23328127be21f088df0c38af250635b8
[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.INSTRUMENT_ONLY;
20 import static org.openecomp.sdc.onboarding.Constants.INSTRUMENT_WITH_TEST_ONLY;
21 import static org.openecomp.sdc.onboarding.Constants.RESOURCE_ONLY;
22 import static org.openecomp.sdc.onboarding.Constants.RESOURCE_WITH_TEST_ONLY;
23 import static org.openecomp.sdc.onboarding.Constants.SKIP_MAIN_SOURCE_COMPILE;
24 import static org.openecomp.sdc.onboarding.Constants.SKIP_PMD;
25 import static org.openecomp.sdc.onboarding.Constants.SKIP_TEST_SOURCE_COMPILE;
26 import static org.openecomp.sdc.onboarding.Constants.TEST_ONLY;
27 import static org.openecomp.sdc.onboarding.Constants.TEST_RESOURCE_ONLY;
28 import static org.openecomp.sdc.onboarding.Constants.UNICORN;
29
30 import java.io.File;
31 import org.apache.maven.plugin.AbstractMojo;
32 import org.apache.maven.plugin.MojoExecutionException;
33 import org.apache.maven.plugins.annotations.LifecyclePhase;
34 import org.apache.maven.plugins.annotations.Mojo;
35 import org.apache.maven.plugins.annotations.Parameter;
36 import org.apache.maven.plugins.annotations.ResolutionScope;
37 import org.apache.maven.project.MavenProject;
38
39 @Mojo(name = "post-compile-helper", threadSafe = true, defaultPhase = LifecyclePhase.TEST_COMPILE,
40         requiresDependencyResolution = ResolutionScope.TEST)
41 public class PostCompileHelperMojo extends AbstractMojo {
42
43     @Parameter(defaultValue = "${project}", readonly = true)
44     private MavenProject project;
45     @Parameter(defaultValue = "${project.artifact.groupId}:${project.artifact.artifactId}")
46     private String moduleCoordinates;
47     @Parameter
48     private String excludePackaging;
49     @Parameter
50     private BuildState buildState;
51     @Parameter
52     private File mainResourceLocation;
53     @Parameter
54     private File testResourceLocation;
55
56
57     public void execute() throws MojoExecutionException {
58         if (!System.getProperties().containsKey(UNICORN)) {
59             return;
60         }
61         if (project.getPackaging().equals(excludePackaging)) {
62             return;
63         }
64         if (project.getProperties().containsKey(TEST_ONLY)) {
65             project.getProperties().setProperty(SKIP_MAIN_SOURCE_COMPILE, Boolean.TRUE.toString());
66             project.getProperties().remove(TEST_ONLY);
67         }
68         if (project.getProperties().containsKey(INSTRUMENT_ONLY)) {
69             project.getProperties().setProperty(SKIP_MAIN_SOURCE_COMPILE, Boolean.TRUE.toString());
70             project.getProperties().setProperty(SKIP_TEST_SOURCE_COMPILE, Boolean.TRUE.toString());
71             project.getProperties().remove(INSTRUMENT_ONLY);
72         }
73         if (project.getProperties().containsKey(INSTRUMENT_WITH_TEST_ONLY)) {
74             project.getProperties().setProperty(SKIP_MAIN_SOURCE_COMPILE, Boolean.TRUE.toString());
75             project.getProperties().remove(INSTRUMENT_WITH_TEST_ONLY);
76         }
77         if (project.getProperties().containsKey(RESOURCE_WITH_TEST_ONLY)) {
78             project.getProperties().setProperty(SKIP_MAIN_SOURCE_COMPILE, Boolean.TRUE.toString());
79             project.getProperties().remove(RESOURCE_WITH_TEST_ONLY);
80         }
81         if (project.getProperties().containsKey(RESOURCE_ONLY)) {
82             project.getProperties().setProperty(SKIP_MAIN_SOURCE_COMPILE, Boolean.TRUE.toString());
83             project.getProperties().setProperty(SKIP_TEST_SOURCE_COMPILE, Boolean.TRUE.toString());
84             project.getProperties().remove(RESOURCE_ONLY);
85         }
86         if (project.getProperties().containsKey(TEST_RESOURCE_ONLY)) {
87             project.getProperties().setProperty(SKIP_MAIN_SOURCE_COMPILE, Boolean.TRUE.toString());
88             project.getProperties().setProperty(SKIP_TEST_SOURCE_COMPILE, Boolean.TRUE.toString());
89             project.getProperties().remove(TEST_RESOURCE_ONLY);
90         }
91         if (!project.getProperties().containsKey(SKIP_MAIN_SOURCE_COMPILE)) {
92             buildState.addModuleBuildTime(moduleCoordinates, System.currentTimeMillis());
93             project.getProperties().setProperty(SKIP_PMD, Boolean.FALSE.toString());
94         }
95         if (!project.getProperties().containsKey(SKIP_TEST_SOURCE_COMPILE)) {
96             project.getProperties().setProperty(SKIP_PMD, Boolean.FALSE.toString());
97         }
98         buildState.saveModuleBuildData(moduleCoordinates);
99     }
100 }