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.JACOCO_SKIP;
20 import static org.openecomp.sdc.onboarding.Constants.SKIP_TEST_RUN;
21 import static org.openecomp.sdc.onboarding.Constants.RESOURCES_CHANGED;
22 import static org.openecomp.sdc.onboarding.Constants.UNICORN;
25 import java.io.IOException;
26 import java.io.UncheckedIOException;
27 import java.util.stream.Collectors;
28 import org.apache.maven.plugin.AbstractMojo;
29 import org.apache.maven.plugin.MojoExecutionException;
30 import org.apache.maven.plugin.MojoFailureException;
31 import org.apache.maven.plugins.annotations.LifecyclePhase;
32 import org.apache.maven.plugins.annotations.Mojo;
33 import org.apache.maven.plugins.annotations.Parameter;
34 import org.apache.maven.plugins.annotations.ResolutionScope;
35 import org.apache.maven.project.MavenProject;
37 @Mojo(name = "pre-test-compile-helper", threadSafe = true, defaultPhase = LifecyclePhase.GENERATE_TEST_RESOURCES,
38 requiresDependencyResolution = ResolutionScope.TEST)
39 public class PreTestCompileHelperMojo extends AbstractMojo {
42 private File compiledFilesList;
44 private Long staleThreshold;
46 private File inputTestFilesList;
48 private BuildState buildState;
49 @Parameter(defaultValue = "${project}", readonly = true)
50 private MavenProject project;
51 @Parameter(defaultValue = "${project.artifact.groupId}:${project.artifact.artifactId}")
52 private String moduleCoordinates;
54 private String excludePackaging;
57 public void execute() throws MojoExecutionException, MojoFailureException {
58 if (!System.getProperties().containsKey(UNICORN)) {
61 if (project.getPackaging().equals(excludePackaging)) {
64 if (compiledFilesList.exists()
65 && compiledFilesList.lastModified() > System.currentTimeMillis() - staleThreshold) {
67 buildState.markModuleDirty(inputTestFilesList);
68 project.getProperties().setProperty(SKIP_TEST_RUN, Boolean.FALSE.toString());
69 } catch (IOException e) {
70 throw new UncheckedIOException(e);
73 boolean isTestMust = buildState.isTestMust(moduleCoordinates,
74 project.getDependencies().stream().map(d -> d.getGroupId() + ":" + d.getArtifactId())
75 .collect(Collectors.toList()));
77 project.getProperties().setProperty(RESOURCES_CHANGED, Boolean.TRUE.toString());
78 if (!project.getProperties().containsKey(SKIP_TEST_RUN)) {
79 project.getProperties().setProperty(SKIP_TEST_RUN, Boolean.FALSE.toString());
82 if (!project.getProperties().containsKey(SKIP_TEST_RUN)) {
83 project.getProperties().setProperty(SKIP_TEST_RUN, Boolean.TRUE.toString());
85 if (System.getProperties().containsKey(JACOCO_SKIP) && Boolean.FALSE.equals(Boolean.valueOf(
86 System.getProperties().getProperty(JACOCO_SKIP)))) {
87 project.getProperties().setProperty(SKIP_TEST_RUN, Boolean.FALSE.toString());