View Javadoc
1   package org.codehaus.mojo.appassembler.daemon.booter;
2   
3   /*
4    * The MIT License
5    *
6    * Copyright (c) 2006-2012, The Codehaus
7    *
8    * Permission is hereby granted, free of charge, to any person obtaining a copy of
9    * this software and associated documentation files (the "Software"), to deal in
10   * the Software without restriction, including without limitation the rights to
11   * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12   * of the Software, and to permit persons to whom the Software is furnished to do
13   * so, subject to the following conditions:
14   *
15   * The above copyright notice and this permission notice shall be included in all
16   * copies or substantial portions of the Software.
17   *
18   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24   * SOFTWARE.
25   */
26  
27  import java.io.File;
28  
29  import org.apache.maven.project.MavenProject;
30  import org.codehaus.mojo.appassembler.daemon.DaemonGenerationRequest;
31  import org.codehaus.mojo.appassembler.daemon.DaemonGenerator;
32  import org.codehaus.mojo.appassembler.daemon.DaemonGeneratorException;
33  import org.codehaus.mojo.appassembler.daemon.script.AbstactScriptDaemonGenerator;
34  import org.codehaus.mojo.appassembler.model.Classpath;
35  import org.codehaus.mojo.appassembler.model.Daemon;
36  import org.codehaus.mojo.appassembler.model.Directory;
37  import org.codehaus.mojo.appassembler.model.JvmSettings;
38  import org.codehaus.mojo.appassembler.util.DependencyFactory;
39  
40  /**
41   * This contains all common code which is used in the {@link UnixBooterDaemonGenerator} and in the
42   * {@link WindowsBooterDaemonGenerator}.
43   *
44   * @author <a href="mailto:trygve.laugstol@objectware.no">Trygve Laugst&oslash;l</a>
45   * @version $Id$
46   */
47  public abstract class AbstractBooterDaemonGenerator
48      extends AbstactScriptDaemonGenerator
49  {
50      /**
51       * @plexus.requirement role-hint="generic"
52       */
53      private DaemonGenerator genericDaemonGenerator;
54  
55      protected AbstractBooterDaemonGenerator( String platformName )
56      {
57          super( platformName );
58      }
59  
60      // -----------------------------------------------------------------------
61      // DaemonGenerator Implementation
62      // -----------------------------------------------------------------------
63  
64      public void generate( DaemonGenerationRequest request )
65          throws DaemonGeneratorException
66      {
67          Daemon daemon = request.getDaemon();
68          JvmSettings jvmSettings = daemon.getJvmSettings();
69  
70          File outputDirectory = request.getOutputDirectory();
71  
72          // -----------------------------------------------------------------------
73          // Generate the generic XML file
74          // -----------------------------------------------------------------------
75  
76          request.setOutputDirectory( new File( outputDirectory, "etc" ) );
77  
78          // TODO: we're assuming state for things that don't really appear stateful
79          /*
80           * The JVM settings are written to the script, and do not need to go into the manifest.
81           */
82          daemon.setJvmSettings( null );
83  
84          genericDaemonGenerator.generate( request );
85  
86          // set back
87          daemon.setJvmSettings( jvmSettings );
88  
89          // -----------------------------------------------------------------------
90          // Generate the shell script
91          // -----------------------------------------------------------------------
92  
93          Daemon booterDaemon = new Daemon();
94          booterDaemon.setId( daemon.getId() );
95          booterDaemon.setEnvironmentSetupFileName( daemon.getEnvironmentSetupFileName() );
96          booterDaemon.setLicenseHeaderFile( daemon.getLicenseHeaderFile() );
97          booterDaemon.setModelEncoding( daemon.getModelEncoding() );
98          // TODO: replace with org.codehaus.mojo.appassembler.booter.AppassemblerBooter.class.getName() and test - trygve
99          booterDaemon.setMainClass( "org.codehaus.mojo.appassembler.booter.AppassemblerBooter" );
100         booterDaemon.setShowConsoleWindow( daemon.isShowConsoleWindow() );
101 
102         booterDaemon.setJvmSettings( jvmSettings );
103         booterDaemon.setEndorsedDir( daemon.getEndorsedDir() );
104 
105         MavenProject project = request.getMavenProject();
106 
107         Classpath classpath = new Classpath();
108         booterDaemon.setClasspath( classpath );
109         classpath.addDirectory( createDirectory( "etc" ) );
110         classpath.addDependency( DependencyFactory.create( project,
111                                                            "org.codehaus.mojo.appassembler:appassembler-booter",
112                                                            request.getRepositoryLayout(),
113                                                            request.getOutputFileNameMapping() ) );
114 
115         // TODO: Transitively resolve the dependencies of the booter - for now we're just hardcoding them in
116         classpath.addDependency( DependencyFactory.create( project,
117                                                            "org.codehaus.mojo.appassembler:appassembler-model",
118                                                            request.getRepositoryLayout(),
119                                                            request.getOutputFileNameMapping() ) );
120         classpath.addDependency( DependencyFactory.create( project, "org.codehaus.plexus:plexus-utils",
121                                                            request.getRepositoryLayout(),
122                                                            request.getOutputFileNameMapping() ) );
123         classpath.addDependency( DependencyFactory.create( project, "stax:stax-api", request.getRepositoryLayout(),
124                                                            request.getOutputFileNameMapping() ) );
125         classpath.addDependency( DependencyFactory.create( project, "stax:stax", request.getRepositoryLayout(),
126                                                            request.getOutputFileNameMapping() ) );
127 
128         // FIXME: Check if this is correct new File("bin") ?
129         scriptGenerator.createBinScript( getPlatformName(), booterDaemon, outputDirectory, "bin" );
130     }
131 
132     // -----------------------------------------------------------------------
133     // Private
134     // -----------------------------------------------------------------------
135 
136     private static Directory createDirectory( String relativePath )
137     {
138         Directory directory = new Directory();
139         directory.setRelativePath( relativePath );
140         return directory;
141     }
142 }