View Javadoc
1   /*
2    * Copyright 2013 vagrant-maven-plugin contributors.
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  package net.nicoulaj.maven.plugins.vagrant;
17  
18  import de.saumya.mojo.ruby.script.ScriptException;
19  import org.apache.maven.plugins.annotations.Mojo;
20  import org.apache.maven.plugins.annotations.Parameter;
21  
22  import java.io.IOException;
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import static org.codehaus.plexus.util.StringUtils.isEmpty;
27  import static org.codehaus.plexus.util.StringUtils.join;
28  
29  /**
30   * Invokes Vagrant {@code up} command.
31   *
32   * @author <a href="http://github.com/nicoulaj">Julien Nicoulaud</a>
33   * @since 1.0
34   */
35  @SuppressWarnings("unused")
36  @Mojo(name = "up")
37  public final class UpMojo extends AbstractVagrantMojo {
38  
39      /** Mojo/Vagrant command name. */
40      public static final String NAME = "up";
41  
42      /**
43       * VM name.
44       */
45      @Parameter
46      protected String vm;
47  
48      /**
49       * Enable or disable provisioning.
50       */
51      @Parameter(defaultValue = "true")
52      protected boolean provision;
53  
54      /**
55       * Enable only certain provisioners, by type.
56       */
57      @Parameter
58      protected List<String> provisioners;
59  
60      @Override
61      protected void doExecute() throws IOException, ScriptException {
62  
63          final List<String> args = new ArrayList<String>();
64  
65          args.add(NAME);
66  
67          if (!isEmpty(vm))
68              args.add(vm);
69  
70          if (!provision)
71              args.add("--no-provision");
72  
73          else if (provisioners != null && !provisioners.isEmpty()) {
74              args.add("--provision");
75              args.add("--provision-with");
76              args.add(join(provisioners.iterator(), ","));
77  
78          } else
79              args.add("--provision");
80  
81          cli(args);
82      }
83  }