1 package org.codehaus.mojo.natives.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import java.io.File;
28 import java.util.ArrayList;
29 import java.util.List;
30
31 import org.apache.maven.plugin.AbstractMojo;
32 import org.apache.maven.plugin.MojoExecutionException;
33 import org.apache.maven.plugins.annotations.Component;
34 import org.apache.maven.plugins.annotations.Parameter;
35 import org.apache.maven.project.MavenProject;
36 import org.codehaus.mojo.natives.EnvFactory;
37 import org.codehaus.mojo.natives.NativeBuildException;
38 import org.codehaus.mojo.natives.manager.EnvFactoryManager;
39
40 public abstract class AbstractNativeMojo
41 extends AbstractMojo
42 {
43 public static final String LINKER_INPUT_LIST_NAME = "NativeLinkerInputListName";
44
45 public static final String LINKER_OUTPUT_PATH = "NativeLinkerOutputPath";
46
47 public static final String INCZIP_FOUND = "IncZipFound";
48
49 public static final String INCZIP_TYPE = "inczip";
50
51 protected static final List EMPTY_FILE_LIST = new ArrayList();
52
53 @Parameter(defaultValue = "${project}", readonly = true, required = true)
54 protected MavenProject project;
55
56
57
58
59 @Parameter(defaultValue = "${basedir}", required = true)
60 protected File workingDirectory;
61
62
63
64
65
66 @Parameter
67 private String envFactoryName;
68
69 @Component
70 protected EnvFactoryManager envFactoryManager;
71
72
73
74
75 @Parameter(defaultValue = "${project.build.directory}/native/include")
76 protected File dependencyIncludeDirectory;
77
78 protected static String[] removeEmptyOptions( List args )
79 {
80 return NativeMojoUtils.trimParams( args );
81 }
82
83 protected List getAllCompilersOutputFileList()
84 {
85 List list = (List) this.getPluginContext().get( AbstractNativeMojo.LINKER_INPUT_LIST_NAME );
86
87 if ( list == null )
88 {
89 list = new ArrayList();
90
91 this.getPluginContext().put( AbstractNativeMojo.LINKER_INPUT_LIST_NAME, list );
92 }
93
94 return list;
95
96 }
97
98 protected void saveCompilerOutputFilePaths( List filePaths )
99 throws MojoExecutionException
100 {
101 List allCompilerOutputFileList = getAllCompilersOutputFileList();
102
103 for ( int i = 0; i < filePaths.size(); ++i )
104 {
105 File file = (File) filePaths.get( i );
106 allCompilerOutputFileList.add( file );
107 }
108 }
109
110
111
112
113
114 protected MavenProject getProject()
115 {
116 return this.project;
117 }
118
119 private EnvFactory envFactory = null;
120
121 protected EnvFactory getEnvFactory()
122 throws MojoExecutionException
123 {
124 if ( envFactory == null && envFactoryName != null )
125 {
126 try
127 {
128 envFactory = this.envFactoryManager.getEnvFactory( this.envFactoryName );
129 }
130 catch ( NativeBuildException e )
131 {
132 throw new MojoExecutionException( e.getMessage(), e );
133 }
134 }
135
136 return envFactory;
137 }
138
139 }