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 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;
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;
39 @Mojo(name = "post-compile-helper", threadSafe = true, defaultPhase = LifecyclePhase.TEST_COMPILE,
40 requiresDependencyResolution = ResolutionScope.TEST)
41 public class PostCompileHelperMojo extends AbstractMojo {
43 @Parameter(defaultValue = "${project}", readonly = true)
44 private MavenProject project;
45 @Parameter(defaultValue = "${project.artifact.groupId}:${project.artifact.artifactId}")
46 private String moduleCoordinates;
48 private String excludePackaging;
50 private BuildState buildState;
52 private File mainResourceLocation;
54 private File testResourceLocation;
57 public void execute() throws MojoExecutionException {
58 if (!System.getProperties().containsKey(UNICORN)) {
61 if (project.getPackaging().equals(excludePackaging)) {
64 if (project.getProperties().containsKey(TEST_ONLY)) {
65 project.getProperties().setProperty(SKIP_MAIN_SOURCE_COMPILE, Boolean.TRUE.toString());
66 project.getProperties().remove(TEST_ONLY);
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);
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);
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);
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);
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);
91 if (!project.getProperties().containsKey(SKIP_MAIN_SOURCE_COMPILE)) {
92 buildState.addModuleBuildTime(moduleCoordinates, System.currentTimeMillis());
93 project.getProperties().setProperty(SKIP_PMD, Boolean.FALSE.toString());
95 if (!project.getProperties().containsKey(SKIP_TEST_SOURCE_COMPILE)) {
96 project.getProperties().setProperty(SKIP_PMD, Boolean.FALSE.toString());
98 buildState.saveModuleBuildData(moduleCoordinates);