View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2008 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // utgb-shell Project
18  //
19  // Deploy.java
20  // Since: Jan 14, 2008
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.shell;
26  
27  import java.io.File;
28  
29  import org.utgenome.config.UTGBConfig;
30  import org.xerial.util.FileUtil;
31  import org.xerial.util.opt.Option;
32  
33  public class Deploy extends UTGBShellCommand {
34  
35  	@Option(symbol = "p", longName = "path", varName = "CONTEXT_PATH", description = "web application's context path. e.g., myapp")
36  	private String contextPath = null;
37  
38  	@Option(symbol = "n", description = "do not generate context.xml")
39  	boolean noContextXML = false;
40  
41  	@Option(symbol = "c", longName = "clean", description = "force recompilation of the project (utgb clean, utgb compile), then deploy")
42  	boolean forceClean = false;
43  
44  	public Deploy() {
45  	}
46  
47  	@Override
48  	public void execute(String[] args) throws Exception {
49  		if (!isInProjectRoot())
50  			throw new UTGBShellException("not in the project root");
51  
52  		// create war/utgb folder
53  		FileUtil.mkdirs(new File(getProjectRoot(), "war/utgb"));
54  
55  		if (forceClean) {
56  			UTGBShell.runCommand(globalOption, "clean");
57  			UTGBShell.runCommand(globalOption, "compile");
58  		}
59  
60  		UTGBConfig config = loadUTGBConfig();
61  		// generate context.xml file
62  		if (!noContextXML)
63  			createContextXML(contextPath != null ? contextPath : config.projectName, new File("").getAbsolutePath(), false);
64  		maven("tomcat:deploy -U" + (contextPath != null ? " -Dpath=/" + contextPath : ""));
65  	}
66  
67  	@Override
68  	public String name() {
69  		return "deploy";
70  	}
71  
72  	@Override
73  	public String getOneLinerDescription() {
74  		return "deploy the project (war file) to the remote Tomcat server";
75  	}
76  
77  }