1 package org.codehaus.plexus.maven.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
27
28 import org.apache.maven.plugin.AbstractMojo;
29 import org.apache.maven.plugin.MojoExecutionException;
30 import org.apache.maven.plugins.annotations.Component;
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.codehaus.plexus.metadata.merge.Merger;
35
36
37
38
39
40
41
42 @Mojo(name = "merge-metadata", defaultPhase = LifecyclePhase.PROCESS_CLASSES)
43 public class PlexusMergeMojo extends AbstractMojo {
44
45
46
47 @Parameter(defaultValue = "${project.build.outputDirectory}/META-INF/plexus/components.xml", required = true)
48 private File output;
49
50
51
52
53 @Parameter
54 private File[] descriptors;
55
56 @Component(hint = "componentsXml")
57 private Merger merger;
58
59 public void execute() throws MojoExecutionException {
60 List<File> files = new ArrayList<File>();
61
62 if (descriptors != null) {
63 files.addAll(Arrays.asList(descriptors));
64 }
65
66 if (files.isEmpty()) {
67 return;
68 }
69
70 try {
71 merger.mergeDescriptors(output, files);
72 } catch (IOException e) {
73 throw new MojoExecutionException("Error while executing component descriptor creator.", e);
74 }
75 }
76 }