c2816dbfbfb420e077d8885d8b9d3b6ebbc58a83
[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.SKIP_TESTS;
20 import static org.openecomp.sdc.onboarding.Constants.SKIP_TEST_RUN;
21 import static org.openecomp.sdc.onboarding.Constants.UNICORN;
22
23 import org.apache.maven.plugin.AbstractMojo;
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugin.MojoFailureException;
26 import org.apache.maven.plugins.annotations.LifecyclePhase;
27 import org.apache.maven.plugins.annotations.Mojo;
28 import org.apache.maven.plugins.annotations.Parameter;
29 import org.apache.maven.plugins.annotations.ResolutionScope;
30 import org.apache.maven.project.MavenProject;
31
32 @Mojo(name = "post-test-run-helper", threadSafe = true, defaultPhase = LifecyclePhase.TEST,
33         requiresDependencyResolution = ResolutionScope.NONE)
34 public class PostTestRunHelperMojo extends AbstractMojo {
35
36     @Parameter
37     private BuildState buildState;
38     @Parameter(defaultValue = "${project.artifact.groupId}:${project.artifact.artifactId}")
39     private String moduleCoordinates;
40     @Parameter(defaultValue = "${project}", readonly = true)
41     private MavenProject project;
42     @Parameter
43     private String excludePackaging;
44
45
46     public void execute() throws MojoExecutionException, MojoFailureException {
47         if (!System.getProperties().containsKey(UNICORN)) {
48             return;
49         }
50         if (project.getPackaging().equals(excludePackaging)) {
51             return;
52         }
53
54         if (project.getProperties().containsKey(SKIP_TEST_RUN) && !Boolean.valueOf(
55                 project.getProperties().getProperty(SKIP_TEST_RUN))) {
56             if (!System.getProperties().containsKey(SKIP_TESTS)) {
57                 buildState.saveResourceBuildData(moduleCoordinates);
58                 buildState.addResourceBuildTime(moduleCoordinates, System.currentTimeMillis());
59
60             }
61         }
62
63     }
64 }