96f29d00542e980e69db7b72d709737f2988d4ee
[sdc.git] /
1 package org.openecomp.sdc.onboarding.util;
2
3 import java.io.File;
4 import java.io.IOException;
5 import org.apache.maven.execution.MavenSession;
6 import org.apache.maven.plugin.AbstractMojo;
7 import org.apache.maven.plugin.MojoExecutionException;
8 import org.apache.maven.plugin.MojoFailureException;
9 import org.apache.maven.plugins.annotations.Component;
10 import org.apache.maven.plugins.annotations.LifecyclePhase;
11 import org.apache.maven.plugins.annotations.Mojo;
12 import org.apache.maven.plugins.annotations.Parameter;
13 import org.apache.maven.plugins.annotations.ResolutionScope;
14 import org.apache.maven.project.MavenProject;
15 import org.apache.maven.project.MavenProjectHelper;
16
17 @Mojo(name = "calibrate-artifact-helper", threadSafe = true, defaultPhase = LifecyclePhase.INSTALL,
18         requiresDependencyResolution = ResolutionScope.TEST)
19 public class CalibrateArtifactPlugin extends AbstractMojo {
20
21     private static final String ARTIFACT_COPY_PATH = "artifactPathToCopy";
22
23     @Parameter(defaultValue = "${session}")
24     private MavenSession session;
25     @Parameter(defaultValue = "${project}", readonly = true)
26     private MavenProject project;
27     @Component
28     private MavenProjectHelper projectHelper;
29     @Parameter
30     private String groupId;
31     @Parameter
32     private String artifactId;
33     @Parameter
34     private String version;
35     @Parameter
36     private String excludePackaging;
37     @Parameter
38     private ArtifactHelper artifactHelper;
39
40     @Override
41     public void execute() throws MojoExecutionException, MojoFailureException {
42         if (project.getPackaging().equals(excludePackaging)) {
43             return;
44         }
45         if (project.getProperties().containsKey(ARTIFACT_COPY_PATH)
46                     && project.getProperties().getProperty(ARTIFACT_COPY_PATH) != null) {
47             File f = new File(project.getProperties().getProperty(ARTIFACT_COPY_PATH));
48             if (f.exists()) {
49                 project.getArtifact().setFile(f);
50             }
51         }
52         try {
53             artifactHelper.shutDown(project);
54         } catch (IOException | ClassNotFoundException e) {
55             throw new MojoExecutionException("Unexpected Error Occured during shutdown activities", e);
56         }
57     }
58 }