View Javadoc
1   package org.codehaus.mojo.natives.linker;
2   
3   /*
4    * The MIT License
5    *
6    * Copyright (c) 2004, The Codehaus
7    *
8    * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
9    * associated documentation files (the "Software"), to deal in the Software without restriction,
10   * including without limitation the rights to use, copy, modify, merge, publish, distribute,
11   * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
12   * furnished to do so, subject to the following conditions:
13   *
14   * The above copyright notice and this permission notice shall be included in all copies or
15   * substantial portions of the Software.
16   *
17   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
18   * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19   * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20   * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22   */
23  
24  import org.codehaus.plexus.util.StringUtils;
25  import org.codehaus.plexus.util.cli.Commandline;
26  
27  import java.io.File;
28  import java.util.List;
29  
30  public class ArchiveLinker
31      extends AbstractLinker
32  {
33  
34      public static final String EXECUTABLE = "ar";
35  
36      public ArchiveLinker()
37      {
38      }
39  
40      protected Commandline createLinkerCommandLine( List objectFiles, LinkerConfiguration config )
41      {
42          Commandline cl = new Commandline();
43  
44          cl.setWorkingDirectory( config.getWorkingDirectory().getPath() );
45  
46          String executable = EXECUTABLE;
47  
48          if ( !StringUtils.isBlank( config.getExecutable() ) )
49          {
50              executable = config.getExecutable();
51          }
52  
53          cl.setExecutable( executable );
54  
55          for ( int i = 0; i < config.getStartOptions().length; ++i )
56          {
57              cl.createArg().setValue( config.getStartOptions()[i] );
58          }
59  
60          // the next 2 are for completeness, the start options should be good enough
61          for ( int i = 0; i < config.getMiddleOptions().length; ++i )
62          {
63              cl.createArg().setValue( config.getMiddleOptions()[i] );
64          }
65  
66          for ( int i = 0; i < config.getEndOptions().length; ++i )
67          {
68              cl.createArg().setValue( config.getEndOptions()[i] );
69          }
70  
71          cl.createArg().setFile( config.getOutputFile() );
72  
73          for ( int i = 0; i < objectFiles.size(); ++i )
74          {
75              File objFile = (File) objectFiles.get( i );
76  
77              cl.createArg().setValue( objFile.getPath() );
78          }
79  
80          return cl;
81  
82      }
83  }