1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.github.maven_nar;
21
22 import java.io.File;
23 import java.util.List;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugin.MojoFailureException;
28 import org.apache.maven.plugins.annotations.Parameter;
29 import org.apache.tools.ant.Project;
30
31 import com.github.maven_nar.cpptasks.CUtil;
32 import com.github.maven_nar.cpptasks.LinkerDef;
33 import com.github.maven_nar.cpptasks.types.LibrarySet;
34 import com.github.maven_nar.cpptasks.types.LibraryTypeEnum;
35
36
37
38
39
40
41 public class Lib {
42
43
44
45
46
47 @Parameter(required = true)
48 private String name;
49
50
51
52
53 @Parameter(defaultValue = "shared", required = true)
54 private String type = Library.SHARED;
55
56
57
58
59 @Parameter(required = true)
60 private File directory;
61
62
63
64
65 @Parameter
66 private List
67
68 public final void addLibSet(final AbstractDependencyMojo mojo, final LinkerDef linker, final Project antProject)
69 throws MojoFailureException, MojoExecutionException {
70 if (this.name == null) {
71 throw new MojoFailureException("NAR: Please specify <Name> as part of <Lib> for library \"" + this.name + "\"");
72 }
73 addLibSet(mojo, linker, antProject, this.name, this.directory);
74 }
75
76 private void addLibSet(final AbstractDependencyMojo mojo, final LinkerDef linker, final Project antProject,
77 final String name, final File dir) throws MojoFailureException, MojoExecutionException {
78 if (this.libs == null) {
79 addSingleLibSet(linker, antProject, name, dir);
80 } else {
81 addMultipleLibSets(mojo, linker, antProject, name);
82 }
83 }
84
85 private void addMultipleLibSets(final AbstractDependencyMojo mojo, final LinkerDef linker, final Project antProject,
86 final String name) throws MojoFailureException, MojoExecutionException {
87 final List dependencies = mojo.getNarArtifacts();
88 for (final Object lib1 : this.libs) {
89 final Lib lib = (Lib) lib1;
90 final String[] ids = name.split(":", 2);
91 if (ids.length != 2) {
92 throw new MojoFailureException("NAR: Please specify <Name> as part of <Lib> in format 'groupId:artifactId'");
93 }
94 for (final Object dependency1 : dependencies) {
95 final Artifact dependency = (Artifact) dependency1;
96 if (dependency.getGroupId().equals(ids[0]) && dependency.getArtifactId().equals(ids[1])) {
97
98 final File narDir = new File(dependency.getFile().getParentFile(),
99 "nar/lib/" + mojo.getAOL() + "/" + lib.type);
100 final String narName = dependency.getArtifactId() + "-" + lib.name + "-" + dependency.getBaseVersion();
101 lib.addLibSet(mojo, linker, antProject, narName, narDir);
102 }
103 }
104 }
105 }
106
107 private void addSingleLibSet(final LinkerDef linker, final Project antProject, final String name, final File dir)
108 throws MojoFailureException, MojoExecutionException {
109 if (!this.type.equals("framework") && dir == null) {
110 throw new MojoFailureException("NAR: Please specify <Directory> as part of <Lib> for library \"" + name + "\"");
111 }
112 final LibrarySet libSet = new LibrarySet();
113 libSet.setProject(antProject);
114 libSet.setLibs(new CUtil.StringArrayBuilder(name));
115 final LibraryTypeEnum libType = new LibraryTypeEnum();
116 libType.setValue(this.type);
117 libSet.setType(libType);
118 libSet.setDir(dir);
119 linker.addLibset(libSet);
120 }
121 }