├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── settings.gradle ├── src ├── main │ ├── groovy │ │ └── com │ │ │ └── bmuschko │ │ │ └── gradle │ │ │ └── vagrant │ │ │ ├── validation │ │ │ ├── BackendProviderAware.groovy │ │ │ ├── PrerequisitesValidator.groovy │ │ │ ├── PrerequisitesValidationResult.groovy │ │ │ ├── VagrantInstallationValidator.groovy │ │ │ ├── VirtualBoxInstallationValidator.groovy │ │ │ ├── AggregatingPrerequisitesValidator.groovy │ │ │ └── AbstractInstallationValidator.groovy │ │ │ ├── tasks │ │ │ ├── VagrantHalt.groovy │ │ │ ├── VagrantReload.groovy │ │ │ ├── VagrantResume.groovy │ │ │ ├── VagrantStatus.groovy │ │ │ ├── VagrantSuspend.groovy │ │ │ ├── VagrantSshConfig.groovy │ │ │ ├── VagrantDestroy.groovy │ │ │ ├── VagrantSsh.groovy │ │ │ ├── VagrantUp.groovy │ │ │ └── Vagrant.groovy │ │ │ ├── Installation.groovy │ │ │ ├── EnvironmentVariables.groovy │ │ │ ├── Provider.groovy │ │ │ ├── process │ │ │ ├── ExternalProcessExecutionResult.groovy │ │ │ ├── ExternalProcessExecutor.groovy │ │ │ ├── ExternalProgram.groovy │ │ │ └── GDKExternalProcessExecutor.groovy │ │ │ ├── utils │ │ │ └── OsUtils.groovy │ │ │ ├── VagrantExtension.groovy │ │ │ ├── VagrantPlugin.groovy │ │ │ └── VagrantBasePlugin.groovy │ └── resources │ │ └── META-INF │ │ └── gradle-plugins │ │ ├── com.bmuschko.vagrant.properties │ │ └── com.bmuschko.vagrant-base.properties └── test │ └── groovy │ └── com │ └── bmuschko │ └── gradle │ └── vagrant │ ├── process │ └── ExternalProgramSpec.groovy │ ├── VagrantPluginSpec.groovy │ ├── validation │ ├── VagrantInstallationValidatorSpec.groovy │ └── VirtualBoxInstallationValidatorSpec.groovy │ ├── tasks │ ├── VagrantSpec.groovy │ ├── VagrantSshSpec.groovy │ └── VagrantUpSpec.groovy │ └── VagrantBasePluginSpec.groovy ├── .github └── workflows │ └── linux-build-release.yml ├── RELEASE_NOTES.md ├── gradlew.bat ├── gradlew ├── README.asciidoc └── LICENSE.txt /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | out 3 | *.iml 4 | *.ipr 5 | *.iws 6 | .idea 7 | .gradle -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmuschko/gradle-vagrant-plugin/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.gradle.enterprise' version '3.6' 3 | } 4 | 5 | rootProject.name = 'gradle-vagrant-plugin' -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/validation/BackendProviderAware.groovy: -------------------------------------------------------------------------------- 1 | package com.bmuschko.gradle.vagrant.validation 2 | 3 | interface BackendProviderAware { 4 | void setProvider(String provider) 5 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/gradle-plugins/com.bmuschko.vagrant.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2013 the original author or authors. 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 | implementation-class=com.bmuschko.gradle.vagrant.VagrantPlugin -------------------------------------------------------------------------------- /src/main/resources/META-INF/gradle-plugins/com.bmuschko.vagrant-base.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2014 the original author or authors. 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 | implementation-class=com.bmuschko.gradle.vagrant.VagrantBasePlugin -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/validation/PrerequisitesValidator.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.validation 17 | 18 | interface PrerequisitesValidator { 19 | PrerequisitesValidationResult validate() 20 | } -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/tasks/VagrantHalt.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 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 com.bmuschko.gradle.vagrant.tasks 17 | 18 | abstract class VagrantHalt extends Vagrant { 19 | VagrantHalt() { 20 | commands.add('halt') 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/validation/PrerequisitesValidationResult.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.validation 17 | 18 | class PrerequisitesValidationResult { 19 | boolean success 20 | String message 21 | } 22 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/tasks/VagrantReload.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 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 com.bmuschko.gradle.vagrant.tasks 17 | 18 | abstract class VagrantReload extends Vagrant { 19 | VagrantReload() { 20 | commands.add('reload') 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/tasks/VagrantResume.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 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 com.bmuschko.gradle.vagrant.tasks 17 | 18 | abstract class VagrantResume extends Vagrant { 19 | VagrantResume() { 20 | commands.add('resume') 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/tasks/VagrantStatus.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 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 com.bmuschko.gradle.vagrant.tasks 17 | 18 | abstract class VagrantStatus extends Vagrant { 19 | VagrantStatus() { 20 | commands.add('status') 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/tasks/VagrantSuspend.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 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 com.bmuschko.gradle.vagrant.tasks 17 | 18 | abstract class VagrantSuspend extends Vagrant { 19 | VagrantSuspend() { 20 | commands.add('suspend') 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/Installation.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 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 com.bmuschko.gradle.vagrant 17 | 18 | class Installation { 19 | Boolean validate = Boolean.TRUE 20 | 21 | void validate(Boolean value) { 22 | validate = value 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/tasks/VagrantSshConfig.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 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 com.bmuschko.gradle.vagrant.tasks 17 | 18 | abstract class VagrantSshConfig extends Vagrant { 19 | VagrantSshConfig() { 20 | commands.add('ssh-config') 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/tasks/VagrantDestroy.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 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 com.bmuschko.gradle.vagrant.tasks 17 | 18 | abstract class VagrantDestroy extends Vagrant { 19 | VagrantDestroy() { 20 | commands.set(['destroy', '--force']) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.github/workflows/linux-build-release.yml: -------------------------------------------------------------------------------- 1 | name: Build and Release [Linux] 2 | on: [push, pull_request] 3 | 4 | jobs: 5 | build: 6 | name: Build 7 | runs-on: ubuntu-18.04 8 | steps: 9 | - name: Checkout 10 | uses: actions/checkout@v1 11 | - name: Set up Java 12 | uses: actions/setup-java@v1 13 | with: 14 | java-version: 11 15 | - name: Compilation 16 | uses: eskatos/gradle-command-action@v1 17 | with: 18 | arguments: classes 19 | - name: Unit tests 20 | uses: eskatos/gradle-command-action@v1 21 | with: 22 | arguments: test 23 | - name: Assemble artifact 24 | uses: eskatos/gradle-command-action@v1 25 | with: 26 | arguments: assemble 27 | - name: Store artifact 28 | uses: actions/upload-artifact@v2 29 | with: 30 | name: gradle-vagrant-plugin.jar 31 | path: build/libs/*.jar -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/EnvironmentVariables.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 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 com.bmuschko.gradle.vagrant 17 | 18 | class EnvironmentVariables { 19 | Map variables = [:] 20 | 21 | void variable(String key, String value) { 22 | variables[key] = value 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/Provider.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 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 com.bmuschko.gradle.vagrant 17 | 18 | enum Provider { 19 | VIRTUALBOX('virtualbox') 20 | 21 | private final String name 22 | 23 | Provider(String name) { 24 | this.name = name 25 | } 26 | 27 | String getName() { 28 | name 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/process/ExternalProcessExecutionResult.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.process 17 | 18 | class ExternalProcessExecutionResult { 19 | static final int OK_EXIT_VALUE = 0 20 | 21 | Integer exitValue 22 | String text 23 | 24 | boolean isOK() { 25 | exitValue == OK_EXIT_VALUE 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/process/ExternalProcessExecutor.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.process 17 | 18 | interface ExternalProcessExecutor { 19 | ExternalProcessExecutionResult execute(List commands) throws IOException 20 | ExternalProcessExecutionResult execute(List commands, List envp, File dir) throws IOException 21 | } -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/tasks/VagrantSsh.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.tasks 17 | 18 | import org.gradle.api.provider.Property 19 | import org.gradle.api.tasks.Input 20 | 21 | abstract class VagrantSsh extends Vagrant { 22 | 23 | VagrantSsh() { 24 | commands.add("ssh") 25 | options.add("-c") 26 | options.add(sshCommand) 27 | } 28 | 29 | /** 30 | * The remote SSH to execute. 31 | */ 32 | @Input 33 | abstract Property getSshCommand() 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/tasks/VagrantUp.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.tasks 17 | 18 | import org.gradle.api.provider.Property 19 | import org.gradle.api.tasks.Input 20 | import org.gradle.api.tasks.Optional 21 | 22 | abstract class VagrantUp extends Vagrant { 23 | 24 | VagrantUp() { 25 | commands.add('up') 26 | options.addAll(provider.map { ["--provider=$it"] }.orElse(project.provider { [] })) 27 | } 28 | 29 | /** 30 | * The backend provider. Defaults to VirtualBox. 31 | */ 32 | @Input 33 | @Optional 34 | abstract Property getProvider() 35 | } 36 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/validation/VagrantInstallationValidator.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.validation 17 | 18 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutionResult 19 | import com.bmuschko.gradle.vagrant.process.ExternalProgram 20 | import groovy.util.logging.Slf4j 21 | 22 | @Slf4j 23 | class VagrantInstallationValidator extends AbstractInstallationValidator { 24 | @Override 25 | ExternalProgram getExternalProgram() { 26 | ExternalProgram.VAGRANT 27 | } 28 | 29 | @Override 30 | List getExecutableOptions() { 31 | ['-v'] 32 | } 33 | 34 | @Override 35 | void handleResult(ExternalProcessExecutionResult result) { 36 | if(result.isOK()) { 37 | log.info "Using ${result.text.trim()}." 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/utils/OsUtils.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 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 com.bmuschko.gradle.vagrant.utils 17 | 18 | final class OsUtils { 19 | private OsUtils() {} 20 | 21 | static boolean isOSWindows() { 22 | System.properties['os.name'].toLowerCase().contains('windows') 23 | } 24 | 25 | static List prepareEnvVars(Map providedEnvVars) { 26 | def allEnvVars = [:] 27 | // Get all of the inherited environment variables. 28 | allEnvVars.putAll(System.getenv()) 29 | // Apply the overrides and additions. 30 | allEnvVars.putAll(providedEnvVars) 31 | flattenEnvVars(allEnvVars) 32 | } 33 | 34 | private static List flattenEnvVars(Map providedEnvVars) { 35 | providedEnvVars.collect { key, value -> "$key=$value" } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/validation/VirtualBoxInstallationValidator.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.validation 17 | 18 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutionResult 19 | import com.bmuschko.gradle.vagrant.process.ExternalProgram 20 | import groovy.util.logging.Slf4j 21 | 22 | @Slf4j 23 | class VirtualBoxInstallationValidator extends AbstractInstallationValidator { 24 | @Override 25 | ExternalProgram getExternalProgram() { 26 | ExternalProgram.VIRTUALBOX 27 | } 28 | 29 | @Override 30 | List getExecutableOptions() { 31 | ['-v'] 32 | } 33 | 34 | @Override 35 | void handleResult(ExternalProcessExecutionResult result) { 36 | if(result.isOK()) { 37 | log.info "Using VirtualBox ${result.text.trim()}." 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/VagrantExtension.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant 17 | 18 | import org.gradle.util.ConfigureUtil 19 | 20 | class VagrantExtension { 21 | /** 22 | * The directory of the Vagrant box. 23 | */ 24 | File boxDir 25 | 26 | /** 27 | * The backend provider. 28 | */ 29 | String provider 30 | 31 | /** 32 | * The environment variables passed to Vagrant. 33 | */ 34 | EnvironmentVariables environmentVariables = new EnvironmentVariables() 35 | 36 | /** 37 | * Installation variables. 38 | */ 39 | Installation installation = new Installation() 40 | 41 | void environmentVariables(Closure closure) { 42 | ConfigureUtil.configure(closure, environmentVariables) 43 | } 44 | 45 | void installation(Closure closure) { 46 | ConfigureUtil.configure(closure, installation) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/process/ExternalProgram.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.process 17 | 18 | import com.bmuschko.gradle.vagrant.utils.OsUtils 19 | 20 | enum ExternalProgram { 21 | VIRTUALBOX('VirtualBox', 'vboxmanage'), VAGRANT('Vagrant', 'vagrant') 22 | 23 | private final String name 24 | private final String executable 25 | 26 | ExternalProgram(String name, String executable) { 27 | this.name = name 28 | this.executable = executable 29 | } 30 | 31 | String getName() { 32 | name 33 | } 34 | 35 | String getExecutable() { 36 | executable 37 | } 38 | 39 | List getCommandLineArgs() { 40 | def commandLineArgs = [] 41 | 42 | if(OsUtils.isOSWindows()) { 43 | commandLineArgs << 'cmd' 44 | commandLineArgs << '/c' 45 | } 46 | 47 | commandLineArgs << executable 48 | commandLineArgs 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/validation/AggregatingPrerequisitesValidator.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.validation 17 | 18 | class AggregatingPrerequisitesValidator implements PrerequisitesValidator, BackendProviderAware { 19 | PrerequisitesValidator vagrantInstallationValidator 20 | String provider 21 | def installationValidators 22 | 23 | AggregatingPrerequisitesValidator() { 24 | vagrantInstallationValidator = new VagrantInstallationValidator() 25 | installationValidators = [vagrantInstallationValidator] 26 | } 27 | 28 | @Override 29 | PrerequisitesValidationResult validate() { 30 | if(provider && provider == 'virtualbox') { 31 | installationValidators << new VirtualBoxInstallationValidator() 32 | } 33 | 34 | for(PrerequisitesValidator validator : installationValidators) { 35 | PrerequisitesValidationResult result = validator.validate() 36 | 37 | if(!result.success) { 38 | return result 39 | } 40 | } 41 | 42 | new PrerequisitesValidationResult(success: true, message: 'Prerequisites are correctly installed.') 43 | } 44 | 45 | @Override 46 | void setProvider(String provider) { 47 | this.provider = provider 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/groovy/com/bmuschko/gradle/vagrant/process/ExternalProgramSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 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 com.bmuschko.gradle.vagrant.process 17 | 18 | import spock.lang.Specification 19 | 20 | class ExternalProgramSpec extends Specification { 21 | static final String OS_NAME_SYSTEM_PROPERTY = 'os.name' 22 | String osName 23 | 24 | def setup() { 25 | osName = System.properties[OS_NAME_SYSTEM_PROPERTY] 26 | } 27 | 28 | def cleanup() { 29 | System.properties[OS_NAME_SYSTEM_PROPERTY] = osName 30 | } 31 | 32 | def "Get name for external program"() { 33 | expect: 34 | ExternalProgram.VAGRANT.name == 'Vagrant' 35 | ExternalProgram.VIRTUALBOX.name == 'VirtualBox' 36 | } 37 | 38 | def "Get executable for external program"() { 39 | expect: 40 | ExternalProgram.VAGRANT.executable == 'vagrant' 41 | ExternalProgram.VIRTUALBOX.executable == 'vboxmanage' 42 | } 43 | 44 | def "Get executable and command line args for Linux"() { 45 | when: 46 | System.properties[OS_NAME_SYSTEM_PROPERTY] = 'Linux' 47 | 48 | then: 49 | ExternalProgram.VAGRANT.commandLineArgs == [ExternalProgram.VAGRANT.executable] 50 | ExternalProgram.VIRTUALBOX.commandLineArgs == [ExternalProgram.VIRTUALBOX.executable] 51 | } 52 | 53 | def "Get executable and command line args for Windows"() { 54 | when: 55 | System.properties[OS_NAME_SYSTEM_PROPERTY] = 'Windows' 56 | 57 | then: 58 | ExternalProgram.VAGRANT.commandLineArgs == ['cmd', '/c', ExternalProgram.VAGRANT.executable] 59 | ExternalProgram.VIRTUALBOX.commandLineArgs == ['cmd', '/c', ExternalProgram.VIRTUALBOX.executable] 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/validation/AbstractInstallationValidator.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.validation 17 | 18 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutionResult 19 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutor 20 | import com.bmuschko.gradle.vagrant.process.ExternalProgram 21 | import com.bmuschko.gradle.vagrant.process.GDKExternalProcessExecutor 22 | import org.gradle.api.GradleException 23 | 24 | abstract class AbstractInstallationValidator implements PrerequisitesValidator { 25 | ExternalProcessExecutor externalProcessExecutor 26 | 27 | AbstractInstallationValidator() { 28 | externalProcessExecutor = new GDKExternalProcessExecutor(false) 29 | } 30 | 31 | @Override 32 | PrerequisitesValidationResult validate() { 33 | ExternalProgram externalProgram = getExternalProgram() 34 | List commands = externalProgram.commandLineArgs 35 | commands.addAll(getExecutableOptions()) 36 | 37 | try { 38 | ExternalProcessExecutionResult result = externalProcessExecutor.execute(commands) 39 | String message = result.isOK() ? result.text.trim() : "$externalProgram.name is not functional. Please check!" 40 | handleResult(result) 41 | return new PrerequisitesValidationResult(success: result.isOK(), message: message) 42 | } 43 | catch(IOException e) { 44 | throw new GradleException("$externalProgram.name could not be detected. Please install!") 45 | } 46 | } 47 | 48 | abstract ExternalProgram getExternalProgram() 49 | abstract List getExecutableOptions() 50 | abstract void handleResult(ExternalProcessExecutionResult result) 51 | } 52 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/process/GDKExternalProcessExecutor.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.process 17 | 18 | import groovy.util.logging.Slf4j 19 | 20 | @Slf4j 21 | class GDKExternalProcessExecutor implements ExternalProcessExecutor { 22 | boolean printToConsole 23 | 24 | GDKExternalProcessExecutor(boolean printToConsole = true) { 25 | this.printToConsole = printToConsole 26 | } 27 | 28 | @Override 29 | ExternalProcessExecutionResult execute(List commands) throws IOException { 30 | printCommandLineArgs(commands) 31 | Process process = commands.execute() 32 | handleProcess(process) 33 | } 34 | 35 | @Override 36 | ExternalProcessExecutionResult execute(List commands, List envp, File dir) throws IOException { 37 | printCommandLineArgs(commands) 38 | Process process = commands.execute(envp, dir) 39 | handleProcess(process) 40 | } 41 | 42 | private static void printCommandLineArgs(List commands) { 43 | log.info "Executing external command: '${commands.join(' ')}'" 44 | } 45 | 46 | private ExternalProcessExecutionResult handleProcess(Process process) { 47 | def out = new StringBuilder() 48 | def err = new StringBuilder() 49 | 50 | if(printToConsole) { 51 | // Process.consumeProcessOutput(System.out, System.err) didn't seem to flush the output to the console on Windows 52 | process.in.eachLine { line -> 53 | out <<= line 54 | println line 55 | } 56 | 57 | process.err.eachLine { line -> 58 | err <<= line 59 | println line 60 | } 61 | } 62 | 63 | process.waitFor() 64 | String text = printToConsole ? (out <<= err).toString() : process.text 65 | new ExternalProcessExecutionResult(exitValue: process.exitValue(), text: text) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /RELEASE_NOTES.md: -------------------------------------------------------------------------------- 1 | ### Version 3.0.0 (February 16, 2021) 2 | 3 | * Use provider API to configure tasks - [Pull Request 18](https://github.com/bmuschko/gradle-vagrant-plugin/pull/18). 4 | * Don't print environment - [Pull Request 20](https://github.com/bmuschko/gradle-vagrant-plugin/pull/20). 5 | 6 | ### Version 2.2.1 (February 9, 2021) 7 | 8 | * Mark options as internal - [Pull Request 17](https://github.com/bmuschko/gradle-vagrant-plugin/pull/17). 9 | 10 | ### Version 2.2 (February 4, 2021) 11 | 12 | * Update plugin for Gradle 7.0 - [Pull Request 16](https://github.com/bmuschko/gradle-vagrant-plugin/pull/16). 13 | * Upgrade to Gradle Wrapper 6.0.1. 14 | 15 | ### Version 2.1 (November 1, 2016) 16 | 17 | * Built with 3.x to fix issue with binary backward compatibility - [Issue 10](https://github.com/bmuschko/gradle-vagrant-plugin/issues/10). 18 | * Upgrade to Gradle Wrapper 3.1. 19 | 20 | ### Version 2.0 (October 11, 2014) 21 | 22 | * Upgrade to Gradle Wrapper 2.1. 23 | * Changed package name to `com.bmuschko.gradle.vagrant`. 24 | * Changed group ID to `com.bmuschko`. 25 | * Adapted plugin IDs to be compatible with Gradle's plugin portal. 26 | 27 | ### Version 0.7 (June 5, 2014) 28 | 29 | * Allow for configuring installation validation - [Pull Request 6](https://github.com/bmuschko/gradle-vagrant-plugin/pull/6). 30 | 31 | ### Version 0.6 (April 6, 2014) 32 | 33 | * Pass environment variables when invoking Vagrant - [Issue 3](https://github.com/bmuschko/gradle-vagrant-plugin/issues/3). 34 | 35 | ### Version 0.5 (February 28, 2014) 36 | 37 | * Capture errors from external program output and render it in console. 38 | * Each Vagrant operation now has a custom task type. 39 | * Split up code into two plugins: 40 | * `vagrant-base`: Provides custom tasks and preconfigures them. 41 | * `vagrant`: Creates tasks of all custom types with default values. 42 | 43 | ### Version 0.4 (February 27, 2014) 44 | 45 | * Correctly capture command line output for external programs on Windows. 46 | 47 | ### Version 0.3 (February 26, 2014) 48 | 49 | * Fix how the Vagrant executable is run on Windows - [Issue 1](https://github.com/bmuschko/gradle-vagrant-plugin/issues/1). 50 | * Default to `projectDir` for `boxDir` property - [Issue 2](https://github.com/bmuschko/gradle-vagrant-plugin/issues/2). 51 | * Upgrade to Gradle Wrapper 1.11. 52 | 53 | ### Version 0.2 (September 28, 2013) 54 | 55 | * Upgrade to Gradle Wrapper 1.8. 56 | * Wrote some unit tests. 57 | * Validating if Vagrant and VirtualBox are installed correctly. 58 | * Support for configuring backend provider. 59 | * Internal refactorings. 60 | 61 | ### Version 0.1 (September 15, 2013) 62 | 63 | * Initial release. -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/VagrantPlugin.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant 17 | 18 | import com.bmuschko.gradle.vagrant.tasks.* 19 | import org.gradle.api.Plugin 20 | import org.gradle.api.Project 21 | 22 | class VagrantPlugin implements Plugin { 23 | @Override 24 | void apply(Project project) { 25 | project.plugins.apply(VagrantBasePlugin) 26 | addTasks(project) 27 | } 28 | 29 | private void addTasks(Project project) { 30 | VagrantTaskDefinition.values().each { taskDef -> 31 | project.task(taskDef.name, type: taskDef.taskClass, description: taskDef.description) 32 | } 33 | } 34 | 35 | private enum VagrantTaskDefinition { 36 | DESTROY(VagrantDestroy, 'destroy', 'Stops the running machine Vagrant is managing and destroys all resources.'), 37 | HALT(VagrantHalt, 'halt', 'Shuts down the running machine Vagrant is managing.'), 38 | RELOAD(VagrantReload, 'reload', 'The equivalent of running a halt followed by an up.'), 39 | RESUME(VagrantResume, 'resume', 'Resumes a Vagrant managed machine that was previously suspended.'), 40 | SSH_CONFIG(VagrantSshConfig, 'sshConfig', 'Outputs the valid configuration for an SSH config file to SSH.'), 41 | STATUS(VagrantStatus, 'status', 'Outputs the state of the machines Vagrant is managing.'), 42 | SUSPEND(VagrantSuspend, 'suspend', 'Suspends the guest machine Vagrant is managing.'), 43 | UP(VagrantUp, 'up', 'Creates and configures guest machines according to your Vagrantfile.') 44 | 45 | private final Class taskClass 46 | private final String name 47 | private final String description 48 | 49 | private VagrantTaskDefinition(Class taskClass, String name, String description) { 50 | this.taskClass = taskClass 51 | this.name = name 52 | this.description = description 53 | } 54 | 55 | String getName() { 56 | "vagrant${name.capitalize()}" 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /src/test/groovy/com/bmuschko/gradle/vagrant/VagrantPluginSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant 17 | 18 | import com.bmuschko.gradle.vagrant.tasks.Vagrant 19 | import com.bmuschko.gradle.vagrant.tasks.VagrantUp 20 | import org.gradle.api.Project 21 | import org.gradle.testfixtures.ProjectBuilder 22 | import spock.lang.Specification 23 | 24 | class VagrantPluginSpec extends Specification { 25 | Project project 26 | 27 | def setup() { 28 | project = ProjectBuilder.builder().build() 29 | } 30 | 31 | def "Creates Vagrant default tasks"() { 32 | when: 33 | project.apply plugin: 'com.bmuschko.vagrant' 34 | then: 35 | project.tasks.findByName('vagrantDestroy') != null 36 | project.tasks.findByName('vagrantDestroy').commands.get() == ['destroy', '--force'] 37 | project.tasks.findByName('vagrantHalt') != null 38 | project.tasks.findByName('vagrantHalt').commands.get() == ['halt'] 39 | project.tasks.findByName('vagrantReload') != null 40 | project.tasks.findByName('vagrantReload').commands.get() == ['reload'] 41 | project.tasks.findByName('vagrantResume') != null 42 | project.tasks.findByName('vagrantResume').commands.get() == ['resume'] 43 | project.tasks.findByName('vagrantSshConfig') != null 44 | project.tasks.findByName('vagrantSshConfig').commands.get() == ['ssh-config'] 45 | project.tasks.findByName('vagrantStatus') != null 46 | project.tasks.findByName('vagrantStatus').commands.get() == ['status'] 47 | project.tasks.findByName('vagrantSuspend') != null 48 | project.tasks.findByName('vagrantSuspend').commands.get() == ['suspend'] 49 | project.tasks.findByName('vagrantUp') != null 50 | project.tasks.findByName('vagrantUp').commands.get() == ['up'] 51 | 52 | project.tasks.withType(Vagrant) { task -> 53 | assert task.boxDir.get().asFile == project.file("vagrant") 54 | } 55 | 56 | project.tasks.withType(VagrantUp) { task -> 57 | assert task.provider.get() == Provider.VIRTUALBOX.name 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/groovy/com/bmuschko/gradle/vagrant/validation/VagrantInstallationValidatorSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.validation 17 | 18 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutionResult 19 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutor 20 | import com.bmuschko.gradle.vagrant.process.ExternalProgram 21 | import org.gradle.api.GradleException 22 | import spock.lang.Specification 23 | 24 | class VagrantInstallationValidatorSpec extends Specification { 25 | PrerequisitesValidator vagrantInstallationValidator 26 | ExternalProcessExecutor mockExternalProcessExecutor 27 | 28 | def setup() { 29 | vagrantInstallationValidator = new VagrantInstallationValidator() 30 | mockExternalProcessExecutor = Mock() 31 | vagrantInstallationValidator.externalProcessExecutor = mockExternalProcessExecutor 32 | } 33 | 34 | def "Validate for thrown exception"() { 35 | when: 36 | vagrantInstallationValidator.validate() 37 | then: 38 | 1 * mockExternalProcessExecutor.execute([ExternalProgram.VAGRANT.executable, '-v']) >> { throw new IOException("something is wrong") } 39 | Throwable t = thrown(GradleException) 40 | t.message == 'Vagrant could not be detected. Please install!' 41 | } 42 | 43 | def "Validate for incorrect Vagrant installation"() { 44 | expect: 45 | ExternalProcessExecutionResult executionResult = new ExternalProcessExecutionResult(exitValue: 1, text: 'failure') 46 | when: 47 | PrerequisitesValidationResult validationResult = vagrantInstallationValidator.validate() 48 | then: 49 | 1 * mockExternalProcessExecutor.execute([ExternalProgram.VAGRANT.executable, '-v']) >> executionResult 50 | !validationResult.success 51 | validationResult.message == 'Vagrant is not functional. Please check!' 52 | } 53 | 54 | def "Validate for correct Vagrant installation"() { 55 | expect: 56 | ExternalProcessExecutionResult executionResult = new ExternalProcessExecutionResult(exitValue: 0, text: 'Vagrant version 1.5.5') 57 | when: 58 | PrerequisitesValidationResult validationResult = vagrantInstallationValidator.validate() 59 | then: 60 | 1 * mockExternalProcessExecutor.execute([ExternalProgram.VAGRANT.executable, '-v']) >> executionResult 61 | validationResult.success 62 | validationResult.message == 'Vagrant version 1.5.5' 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/groovy/com/bmuschko/gradle/vagrant/validation/VirtualBoxInstallationValidatorSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.validation 17 | 18 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutionResult 19 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutor 20 | import com.bmuschko.gradle.vagrant.process.ExternalProgram 21 | import org.gradle.api.GradleException 22 | import spock.lang.Specification 23 | 24 | class VirtualBoxInstallationValidatorSpec extends Specification { 25 | PrerequisitesValidator virtualBoxInstallationValidator 26 | ExternalProcessExecutor mockExternalProcessExecutor 27 | 28 | def setup() { 29 | virtualBoxInstallationValidator = new VirtualBoxInstallationValidator() 30 | mockExternalProcessExecutor = Mock() 31 | virtualBoxInstallationValidator.externalProcessExecutor = mockExternalProcessExecutor 32 | } 33 | 34 | def "Validate for thrown exception"() { 35 | when: 36 | virtualBoxInstallationValidator.validate() 37 | then: 38 | 1 * mockExternalProcessExecutor.execute([ExternalProgram.VIRTUALBOX.executable, '-v']) >> { throw new IOException("something is wrong") } 39 | Throwable t = thrown(GradleException) 40 | t.message == 'VirtualBox could not be detected. Please install!' 41 | } 42 | 43 | def "Validate for incorrect VirtualBox installation"() { 44 | expect: 45 | ExternalProcessExecutionResult executionResult = new ExternalProcessExecutionResult(exitValue: 1, text: 'failure') 46 | when: 47 | PrerequisitesValidationResult validationResult = virtualBoxInstallationValidator.validate() 48 | then: 49 | 1 * mockExternalProcessExecutor.execute([ExternalProgram.VIRTUALBOX.executable, '-v']) >> executionResult 50 | !validationResult.success 51 | validationResult.message == 'VirtualBox is not functional. Please check!' 52 | } 53 | 54 | def "Validate for correct VirtualBox installation"() { 55 | expect: 56 | ExternalProcessExecutionResult executionResult = new ExternalProcessExecutionResult(exitValue: 0, text: 'VirtualBox version 1.5.5') 57 | when: 58 | PrerequisitesValidationResult validationResult = virtualBoxInstallationValidator.validate() 59 | then: 60 | 1 * mockExternalProcessExecutor.execute([ExternalProgram.VIRTUALBOX.executable, '-v']) >> executionResult 61 | validationResult.success 62 | validationResult.message == 'VirtualBox version 1.5.5' 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/groovy/com/bmuschko/gradle/vagrant/tasks/VagrantSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.tasks 17 | 18 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutionResult 19 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutor 20 | import org.gradle.api.GradleException 21 | import org.gradle.api.Project 22 | import org.gradle.api.Task 23 | import org.gradle.testfixtures.ProjectBuilder 24 | import spock.lang.Specification 25 | 26 | class VagrantSpec extends Specification { 27 | static final TASK_NAME = 'someVagrantTask' 28 | Project project 29 | ExternalProcessExecutor mockExternalProcessExecutor 30 | 31 | def setup() { 32 | project = ProjectBuilder.builder().build() 33 | mockExternalProcessExecutor = Mock() 34 | } 35 | 36 | def "Executes task for thrown exception"() { 37 | expect: 38 | ExternalProcessExecutionResult result = new ExternalProcessExecutionResult(exitValue: 1, text: 'failure') 39 | when: 40 | Task task = project.task(TASK_NAME, type: Vagrant) { 41 | commands.set(['box', 'list']) 42 | boxDir.set(project.layout.projectDirectory.dir('mybox')) 43 | } 44 | 45 | task.processExecutor = mockExternalProcessExecutor 46 | task.runCommand() 47 | then: 48 | project.tasks.findByName(TASK_NAME) != null 49 | project.tasks.findByName(TASK_NAME).group == Vagrant.TASK_GROUP 50 | 1 * mockExternalProcessExecutor.execute(['vagrant', 'box', 'list'], null, project.file('mybox')) >> result 51 | !result.isOK() 52 | Throwable t = thrown(GradleException) 53 | t.message == 'Failed to execute the Vagrant command.' 54 | } 55 | 56 | def "Executes task for success"() { 57 | expect: 58 | ExternalProcessExecutionResult result = new ExternalProcessExecutionResult(exitValue: 0, text: 'success') 59 | when: 60 | Task task = project.task(TASK_NAME, type: Vagrant) { 61 | commands.set(['box', 'list']) 62 | boxDir.set(project.layout.projectDirectory.dir('mybox')) 63 | } 64 | 65 | task.processExecutor = mockExternalProcessExecutor 66 | task.runCommand() 67 | then: 68 | project.tasks.findByName(TASK_NAME) != null 69 | project.tasks.findByName(TASK_NAME).group == Vagrant.TASK_GROUP 70 | 1 * mockExternalProcessExecutor.execute(['vagrant', 'box', 'list'], null, project.file('mybox')) >> result 71 | result.isOK() 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/tasks/Vagrant.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.tasks 17 | 18 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutionResult 19 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutor 20 | import com.bmuschko.gradle.vagrant.process.ExternalProgram 21 | import com.bmuschko.gradle.vagrant.process.GDKExternalProcessExecutor 22 | import com.bmuschko.gradle.vagrant.utils.OsUtils 23 | import groovy.transform.PackageScope 24 | import org.gradle.api.DefaultTask 25 | import org.gradle.api.GradleException 26 | import org.gradle.api.file.DirectoryProperty 27 | import org.gradle.api.provider.ListProperty 28 | import org.gradle.api.provider.MapProperty 29 | import org.gradle.api.tasks.Input 30 | import org.gradle.api.tasks.InputDirectory 31 | import org.gradle.api.tasks.PathSensitive 32 | import org.gradle.api.tasks.PathSensitivity 33 | import org.gradle.api.tasks.TaskAction 34 | 35 | abstract class Vagrant extends DefaultTask { 36 | static final String TASK_GROUP = 'Vagrant' 37 | 38 | /** 39 | * The Vagrant command to run. 40 | */ 41 | @Input 42 | abstract ListProperty getCommands() 43 | 44 | @Input 45 | abstract ListProperty getOptions() 46 | 47 | /** 48 | * The directory the targeted Vagrant box resides in. 49 | */ 50 | @PathSensitive(PathSensitivity.RELATIVE) 51 | @InputDirectory 52 | abstract DirectoryProperty getBoxDir() 53 | 54 | /** 55 | * The environment variables passed to Vagrant command. 56 | */ 57 | @Input 58 | abstract MapProperty getEnvironmentVariables() 59 | 60 | // visible for testing 61 | @PackageScope 62 | ExternalProcessExecutor processExecutor 63 | 64 | Vagrant() { 65 | group = TASK_GROUP 66 | processExecutor = new GDKExternalProcessExecutor() 67 | } 68 | 69 | @TaskAction 70 | void runCommand() { 71 | List vagrantCommands = [] 72 | vagrantCommands.addAll(commands.get()) 73 | vagrantCommands.addAll(0, ExternalProgram.VAGRANT.commandLineArgs) 74 | vagrantCommands.addAll(options.get()) 75 | 76 | ExternalProcessExecutionResult result = processExecutor.execute(vagrantCommands, getEnvVars(), boxDir.get().asFile) 77 | 78 | if (!result.isOK()) { 79 | throw new GradleException('Failed to execute the Vagrant command.') 80 | } 81 | } 82 | 83 | private List getEnvVars() { 84 | def userSuppliedEnv = environmentVariables.get() 85 | return userSuppliedEnv.size() > 0 ? OsUtils.prepareEnvVars(userSuppliedEnv) : null 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/test/groovy/com/bmuschko/gradle/vagrant/tasks/VagrantSshSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.tasks 17 | 18 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutionResult 19 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutor 20 | import org.gradle.api.GradleException 21 | import org.gradle.api.Project 22 | import org.gradle.api.Task 23 | import org.gradle.testfixtures.ProjectBuilder 24 | import spock.lang.Specification 25 | 26 | class VagrantSshSpec extends Specification { 27 | static final TASK_NAME = 'someVagrantTask' 28 | Project project 29 | ExternalProcessExecutor mockExternalProcessExecutor 30 | 31 | def setup() { 32 | project = ProjectBuilder.builder().build() 33 | mockExternalProcessExecutor = Mock() 34 | } 35 | 36 | def "Executes task for thrown exception"() { 37 | expect: 38 | ExternalProcessExecutionResult result = new ExternalProcessExecutionResult(exitValue: 1, text: 'failure') 39 | when: 40 | Task task = project.task(TASK_NAME, type: VagrantSsh) { 41 | sshCommand.set("echo 'hello world'") 42 | boxDir.set(project.layout.projectDirectory.dir('mybox')) 43 | } 44 | 45 | task.processExecutor = mockExternalProcessExecutor 46 | task.runCommand() 47 | then: 48 | project.tasks.findByName(TASK_NAME) != null 49 | project.tasks.findByName(TASK_NAME).group == Vagrant.TASK_GROUP 50 | 1 * mockExternalProcessExecutor.execute(['vagrant', 'ssh', '-c', "echo 'hello world'"], null, project.file('mybox')) >> result 51 | !result.isOK() 52 | Throwable t = thrown(GradleException) 53 | t.message == 'Failed to execute the Vagrant command.' 54 | } 55 | 56 | def "Executes task for success"() { 57 | expect: 58 | ExternalProcessExecutionResult result = new ExternalProcessExecutionResult(exitValue: 0, text: 'success') 59 | when: 60 | Task task = project.task(TASK_NAME, type: VagrantSsh) { 61 | sshCommand.set("echo 'hello world'") 62 | boxDir.set(project.layout.projectDirectory.dir('mybox')) 63 | } 64 | 65 | task.processExecutor = mockExternalProcessExecutor 66 | task.runCommand() 67 | then: 68 | project.tasks.findByName(TASK_NAME) != null 69 | project.tasks.findByName(TASK_NAME).group == Vagrant.TASK_GROUP 70 | 1 * mockExternalProcessExecutor.execute(['vagrant', 'ssh', '-c', "echo 'hello world'"], null, project.file('mybox')) >> result 71 | result.isOK() 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /src/main/groovy/com/bmuschko/gradle/vagrant/VagrantBasePlugin.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 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 com.bmuschko.gradle.vagrant 17 | 18 | import com.bmuschko.gradle.vagrant.tasks.Vagrant 19 | import com.bmuschko.gradle.vagrant.tasks.VagrantUp 20 | import com.bmuschko.gradle.vagrant.validation.AggregatingPrerequisitesValidator 21 | import com.bmuschko.gradle.vagrant.validation.PrerequisitesValidationResult 22 | import org.gradle.api.GradleException 23 | import org.gradle.api.Plugin 24 | import org.gradle.api.Project 25 | import org.gradle.api.execution.TaskExecutionGraph 26 | 27 | class VagrantBasePlugin implements Plugin { 28 | static final String EXTENSION_NAME = 'vagrant' 29 | 30 | AggregatingPrerequisitesValidator prerequisitesValidator 31 | 32 | VagrantBasePlugin() { 33 | prerequisitesValidator = new AggregatingPrerequisitesValidator() 34 | } 35 | 36 | @Override 37 | void apply(Project project) { 38 | project.extensions.create(EXTENSION_NAME, VagrantExtension) 39 | configureVagrantTasks(project) 40 | validateVagrantInstallation(project) 41 | } 42 | 43 | private void configureVagrantTasks(Project project) { 44 | project.tasks.withType(Vagrant).configureEach { 45 | it.boxDir.convention(project.objects.directoryProperty().fileValue(getBoxDir(project))) 46 | it.environmentVariables.convention(project.extensions.findByName(EXTENSION_NAME).environmentVariables.variables) 47 | } 48 | 49 | project.tasks.withType(VagrantUp).configureEach { 50 | it.provider.convention(getProvider(project)) 51 | } 52 | } 53 | 54 | private File getBoxDir(Project project) { 55 | File boxDir = project.hasProperty('boxDir') ? project.file(project.boxDir) : project.extensions.findByName(EXTENSION_NAME).boxDir 56 | boxDir ?: project.file("vagrant") 57 | } 58 | 59 | private String getProvider(Project project) { 60 | String provider = project.hasProperty('provider') ? project.provider : project.extensions.findByName(EXTENSION_NAME).provider 61 | provider ?: Provider.VIRTUALBOX.name 62 | } 63 | 64 | private void validateVagrantInstallation(Project project) { 65 | project.gradle.taskGraph.whenReady { TaskExecutionGraph taskGraph -> 66 | if(isInstallationValidationEnabled(project) && containsVagrantTask(taskGraph)) { 67 | String requestedProvider = getProvider(project) 68 | 69 | if(requestedProvider) { 70 | prerequisitesValidator.setProvider(requestedProvider) 71 | } 72 | 73 | PrerequisitesValidationResult result = prerequisitesValidator.validate() 74 | 75 | if(!result.success) { 76 | throw new GradleException(result.message) 77 | } 78 | } 79 | } 80 | } 81 | 82 | private Boolean isInstallationValidationEnabled(Project project) { 83 | Boolean enabledValidation = project.extensions.findByName(EXTENSION_NAME).installation.validate 84 | project.logger.info "Installation validation enabled: $enabledValidation" 85 | enabledValidation 86 | } 87 | 88 | private boolean containsVagrantTask(TaskExecutionGraph taskGraph) { 89 | taskGraph.allTasks.findAll { task -> task instanceof Vagrant }.size() > 0 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/test/groovy/com/bmuschko/gradle/vagrant/tasks/VagrantUpSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 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 com.bmuschko.gradle.vagrant.tasks 17 | 18 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutionResult 19 | import com.bmuschko.gradle.vagrant.process.ExternalProcessExecutor 20 | import org.gradle.api.GradleException 21 | import org.gradle.api.Project 22 | import org.gradle.api.Task 23 | import org.gradle.testfixtures.ProjectBuilder 24 | import spock.lang.Specification 25 | 26 | class VagrantUpSpec extends Specification { 27 | static final TASK_NAME = 'someVagrantTask' 28 | Project project 29 | ExternalProcessExecutor mockExternalProcessExecutor 30 | 31 | def setup() { 32 | project = ProjectBuilder.builder().build() 33 | mockExternalProcessExecutor = Mock() 34 | } 35 | 36 | def "Executes task for thrown exception"() { 37 | expect: 38 | ExternalProcessExecutionResult result = new ExternalProcessExecutionResult(exitValue: 1, text: 'failure') 39 | when: 40 | Task task = project.task(TASK_NAME, type: VagrantUp) { 41 | boxDir.set(project.layout.projectDirectory.dir('mybox')) 42 | provider.set('vmware_fusion') 43 | } 44 | 45 | task.processExecutor = mockExternalProcessExecutor 46 | task.runCommand() 47 | then: 48 | project.tasks.findByName(TASK_NAME) != null 49 | project.tasks.findByName(TASK_NAME).group == Vagrant.TASK_GROUP 50 | 1 * mockExternalProcessExecutor.execute(['vagrant', 'up', '--provider=vmware_fusion'], null, project.file('mybox')) >> result 51 | !result.isOK() 52 | Throwable t = thrown(GradleException) 53 | t.message == 'Failed to execute the Vagrant command.' 54 | } 55 | 56 | def "Executes task for success with declared provider"() { 57 | expect: 58 | ExternalProcessExecutionResult result = new ExternalProcessExecutionResult(exitValue: 0, text: 'success') 59 | when: 60 | Task task = project.task(TASK_NAME, type: VagrantUp) { 61 | boxDir.set(project.layout.projectDirectory.dir('mybox')) 62 | provider.set('vmware_fusion') 63 | } 64 | 65 | task.processExecutor = mockExternalProcessExecutor 66 | task.runCommand() 67 | then: 68 | project.tasks.findByName(TASK_NAME) != null 69 | project.tasks.findByName(TASK_NAME).group == Vagrant.TASK_GROUP 70 | 1 * mockExternalProcessExecutor.execute(['vagrant', 'up', '--provider=vmware_fusion'], null, project.file('mybox')) >> result 71 | result.isOK() 72 | } 73 | 74 | def "Executes task for success without declared provider"() { 75 | expect: 76 | ExternalProcessExecutionResult result = new ExternalProcessExecutionResult(exitValue: 0, text: 'success') 77 | when: 78 | Task task = project.task(TASK_NAME, type: VagrantUp) { 79 | boxDir.set(project.layout.projectDirectory.dir('mybox')) 80 | } 81 | 82 | task.processExecutor = mockExternalProcessExecutor 83 | task.runCommand() 84 | then: 85 | project.tasks.findByName(TASK_NAME) != null 86 | project.tasks.findByName(TASK_NAME).group == Vagrant.TASK_GROUP 87 | 1 * mockExternalProcessExecutor.execute(['vagrant', 'up'], null, project.file('mybox')) >> result 88 | result.isOK() 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=`expr $i + 1` 158 | done 159 | case $i in 160 | 0) set -- ;; 161 | 1) set -- "$args0" ;; 162 | 2) set -- "$args0" "$args1" ;; 163 | 3) set -- "$args0" "$args1" "$args2" ;; 164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=`save "$@"` 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | exec "$JAVACMD" "$@" 184 | -------------------------------------------------------------------------------- /src/test/groovy/com/bmuschko/gradle/vagrant/VagrantBasePluginSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 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 com.bmuschko.gradle.vagrant 17 | 18 | import com.bmuschko.gradle.vagrant.tasks.Vagrant 19 | import com.bmuschko.gradle.vagrant.tasks.VagrantDestroy 20 | import com.bmuschko.gradle.vagrant.tasks.VagrantUp 21 | import org.gradle.api.Project 22 | import org.gradle.testfixtures.ProjectBuilder 23 | import spock.lang.Specification 24 | import spock.lang.Unroll 25 | 26 | class VagrantBasePluginSpec extends Specification { 27 | Project project 28 | 29 | def setup() { 30 | project = ProjectBuilder.builder().build() 31 | project.apply plugin: 'com.bmuschko.vagrant-base' 32 | } 33 | 34 | def "Box directory defaults to vagrant directory if not set"() { 35 | when: 36 | def task = project.task('myCustomVagrantUp', type: VagrantUp) 37 | then: 38 | task.boxDir.get().asFile == project.file("vagrant") 39 | } 40 | 41 | def "Box directory is set to value from extension"() { 42 | when: 43 | project.vagrant { 44 | boxDir = project.file('someDir') 45 | } 46 | 47 | def task = project.task('myCustomVagrantUp', type: VagrantUp) 48 | then: 49 | task.boxDir.get().asFile == project.file('someDir') 50 | } 51 | 52 | def "Box directory is set as property value"() { 53 | when: 54 | project.ext.boxDir = project.file('other') 55 | def task = project.task('myCustomVagrantUp', type: VagrantUp) 56 | then: 57 | task.boxDir.get().asFile == project.file('other') 58 | } 59 | 60 | def "Provider defaults to VirtualBox if not set"() { 61 | when: 62 | def task = project.task('myCustomVagrantUp', type: VagrantUp) 63 | then: 64 | task.provider.get() == Provider.VIRTUALBOX.name 65 | } 66 | 67 | def "Provider is set to value from extension"() { 68 | when: 69 | project.vagrant { 70 | provider = 'vmware_fusion' 71 | } 72 | 73 | def task = project.task('myCustomVagrantUp', type: VagrantUp) 74 | then: 75 | task.provider.get() == 'vmware_fusion' 76 | } 77 | 78 | def "Provider is set as property value"() { 79 | when: 80 | project.ext.provider = 'vmware_fusion' 81 | def task = project.task('myCustomVagrantUp', type: VagrantUp) 82 | then: 83 | task.provider.get() == 'vmware_fusion' 84 | } 85 | 86 | @Unroll 87 | def "Installation validation is set to #enabledValidation value from extension via exposed method"() { 88 | when: 89 | project.vagrant { 90 | installation { 91 | validate enabledValidation 92 | } 93 | } 94 | then: 95 | project.extensions.findByName('vagrant').installation.validate == enabledValidation 96 | 97 | where: 98 | enabledValidation << [true, false] 99 | } 100 | 101 | @Unroll 102 | def "Installation validation is set to #enabledValidation value from extension via setter method"() { 103 | when: 104 | project.vagrant { 105 | installation { 106 | validate = enabledValidation 107 | } 108 | } 109 | then: 110 | project.extensions.findByName('vagrant').installation.validate == enabledValidation 111 | 112 | where: 113 | enabledValidation << [true, false] 114 | } 115 | 116 | def "Installation validation defaults to enabled if not set"() { 117 | expect: 118 | project.extensions.findByName('vagrant').installation.validate 119 | } 120 | 121 | def "Can create task of type Vagrant with default values"() { 122 | when: 123 | def task = project.task('vagrantListsBoxes', type: Vagrant) { 124 | description = 'Outputs a list of available Vagrant boxes.' 125 | commands.set(['box', 'list']) 126 | } 127 | then: 128 | project.tasks.findByName('vagrantListsBoxes') 129 | task.description == 'Outputs a list of available Vagrant boxes.' 130 | task.commands.get() == ['box', 'list'] 131 | task.boxDir.get().asFile == project.file("vagrant") 132 | } 133 | 134 | def "Can create task of type Vagrant with custom values"() { 135 | when: 136 | def task = project.task('myCustomVagrantUp', type: VagrantUp) { 137 | description = 'Brings up Vagrant box.' 138 | boxDir.set(project.layout.projectDirectory.dir('custom')) 139 | provider.set('vmware_fusion') 140 | } 141 | then: 142 | project.tasks.findByName('myCustomVagrantUp') 143 | task.description == 'Brings up Vagrant box.' 144 | task.commands.get() == ['up'] 145 | task.boxDir.get().asFile == project.file('custom') 146 | task.provider.get() == 'vmware_fusion' 147 | } 148 | 149 | def "Can create multiple tasks of type Vagrant with custom values"() { 150 | when: 151 | project.ext.customBoxDir = project.file('custom') 152 | project.ext.fusionProvider = 'vmware_fusion' 153 | 154 | def upTask = project.task('fusionBoxUp', type: VagrantUp) { 155 | description = 'Brings up Fusion Vagrant box.' 156 | boxDir.set(project.customBoxDir) 157 | provider.set(project.fusionProvider) 158 | } 159 | 160 | def destroyTask = project.task('fusionBoxDestroy', type: VagrantDestroy) { 161 | description = 'Destroys Fusion Vagrant box.' 162 | boxDir.set(project.customBoxDir) 163 | } 164 | then: 165 | project.tasks.findByName('fusionBoxUp') 166 | upTask.description == 'Brings up Fusion Vagrant box.' 167 | upTask.commands.get() == ['up'] 168 | upTask.boxDir.get().asFile == project.file('custom') 169 | upTask.provider.get() == 'vmware_fusion' 170 | project.tasks.findByName('fusionBoxDestroy') 171 | destroyTask.description == 'Destroys Fusion Vagrant box.' 172 | destroyTask.commands.get() == ['destroy', '--force'] 173 | destroyTask.boxDir.get().asFile == project.file('custom') 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /README.asciidoc: -------------------------------------------------------------------------------- 1 | = Gradle Vagrant plugin image:https://github.com/bmuschko/gradle-vagrant-plugin/workflows/Build%20and%20Release%20%5BLinux%5D/badge.svg["Build Status", link="https://github.com/bmuschko/gradle-vagrant-plugin/actions?query=workflow%3A%22Build+and+Release+%5BLinux%5D%22"] 2 | 3 | image:https://hyzxph.media.zestyio.com/blog-vagrant.svg[Vagrant Logo, scaledwidth="5%"] 4 | 5 | Gradle plugin for managing link:http://www.vagrantup.com/[Vagrant] boxes. 6 | 7 | == Usage 8 | 9 | To use the plugin, include in your build script: 10 | 11 | [source,groovy] 12 | ---- 13 | buildscript { 14 | repositories { 15 | mavenCentral() 16 | } 17 | 18 | dependencies { 19 | classpath 'com.bmuschko:gradle-vagrant-plugin:3.0.0' 20 | } 21 | } 22 | ---- 23 | 24 | 25 | == Base plugin 26 | 27 | If you want to create your own task for managing Vagrant, you should go with the base plugin. This option is usually helpful 28 | if you are dealing with multiple VMs in parallel. The base plugin provides all custom task types and preconfigures them with 29 | sensible defaults. To use the base plugin, add the following `apply` notation to your build script. 30 | 31 | [source,groovy] 32 | ---- 33 | apply plugin: 'com.bmuschko.vagrant-base' 34 | ---- 35 | 36 | 37 | === Custom task types 38 | 39 | The base plugin provides the following custom task types: 40 | 41 | [options="header"] 42 | |======= 43 | |Type |Description 44 | |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantDestroy.html[VagrantDestroy] |Stops the running machine Vagrant is managing and destroys all resources. 45 | |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantHalt.html[VagrantHalt] |Shuts down the running machine Vagrant is managing. 46 | |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantReload.html[VagrantReload] |The equivalent of running a halt followed by an up. 47 | |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantSsh.html[VagrantSsh] |Executes a SSH command on the Vagrant machine. 48 | |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantSshConfig.html[VagrantSshConfig] |Outputs the valid configuration for an SSH config file to SSH. 49 | |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantStatus.html[VagrantStatus] |Outputs the state of the machines Vagrant is managing. 50 | |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantSuspend.html[VagrantSuspend] |Suspends the guest machine Vagrant is managing. 51 | |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantUp.html[VagrantUp] |Creates and configures guest machines according to your Vagrantfile. 52 | |======= 53 | 54 | 55 | === Extension properties 56 | 57 | The base plugin defines the following extension properties in the `vagrant` closure: 58 | 59 | [options="header"] 60 | |======= 61 | |Property name |Type |Default value |Description 62 | |`boxDir` |File |`project.file("vagrant")` |The directory the targeted Vagrant box resides in. 63 | |`provider` |String |virtualbox |The link:http://docs.vagrantup.com/v2/providers/index.html[backend provider] to be used. 64 | |======= 65 | 66 | The recommended way for providing values to the `Vagrantfile` from the outside is to use environment variables. This is made 67 | possible through the nested configuration element `environmentVariables`. This element exposes the method `variable` that 68 | takes two parameters: the key and value for a environment variable. For each invocation of this method a new key/value pair 69 | is added to internal property named `variables`. 70 | 71 | [options="header"] 72 | |======= 73 | |Property name |Type |Default value |Description 74 | |`variables` |Map |[:] |Provided environment variables as key/value pairs. 75 | |======= 76 | 77 | By default the plugin validates the installation of the Vagrant runtime and the selected provider. This validation logic 78 | can be disabled from your buildscript. This is made possible through the nested configuration element `installation`. 79 | This element exposes the method `validate` that take a single parameter. 80 | 81 | [options="header"] 82 | |======= 83 | |Property name |Type |Default value |Description 84 | |`validate` |Boolean |true |Installation validation 85 | |======= 86 | 87 | === Example 88 | 89 | [source,groovy] 90 | ---- 91 | import com.bmuschko.gradle.vagrant.tasks.VagrantUp 92 | import com.bmuschko.gradle.vagrant.tasks.VagrantDestroy 93 | 94 | ext { 95 | virtualBoxDir = file('virtualbox-box') 96 | fusionBoxDir = file('fusion-box') 97 | fusionProvider = 'vmware_fusion' 98 | } 99 | 100 | task startVirtualBoxVm(type: VagrantUp) { 101 | description = 'Starts VM machine running on VirtualBox.' 102 | group = 'VirtualBox VM' 103 | boxDir = virtualBoxDir 104 | } 105 | 106 | task stopVirtualBoxVm(type: VagrantDestroy) { 107 | description = 'Stops VM machine running on VirtualBox.' 108 | group = 'VirtualBox VM' 109 | boxDir = virtualBoxDir 110 | } 111 | 112 | task startFusionVm(type: VagrantUp) { 113 | description = 'Starts VM machine running on VMware Fusion.' 114 | group = 'Fusion VM' 115 | boxDir = fusionBoxDir 116 | provider = fusionProvider 117 | } 118 | 119 | task stopFusionVm(type: VagrantDestroy) { 120 | description = 'Stops VM machine running on VMware Fusion.' 121 | group = 'Fusion VM' 122 | boxDir = fusionBoxDir 123 | provider = fusionProvider 124 | } 125 | ---- 126 | 127 | 128 | == Convention plugin 129 | 130 | If you want the plugin to preconfigure commonly-used tasks for you, you should go with the full-fledged convention plugin. 131 | This plugin is a viable option if you only have to deal with a single VM. To use the convention plugin, add the following `apply` 132 | notation to your build script. 133 | 134 | [source,groovy] 135 | ---- 136 | apply plugin: 'com.bmuschko.vagrant' 137 | ---- 138 | 139 | 140 | === Default tasks 141 | 142 | The plugin defines the following tasks: 143 | 144 | [options="header"] 145 | |======= 146 | |Task name |Depends on |Type 147 | |`vagrantDestroy` |- |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantDestroy.html[VagrantDestroy] 148 | |`vagrantHalt` |- |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantHalt.html[VagrantHalt] 149 | |`vagrantReload` |- |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantReload.html[VagrantReload] 150 | |`vagrantResume` |- |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantResume.html[VagrantResume] 151 | |`vagrantSshConfig` |- |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantSshConfig.html[VagrantSshConfig] 152 | |`vagrantStatus` |- |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantStatus.html[VagrantStatus] 153 | |`vagrantSuspend` |- |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantSuspend.html[VagrantSuspend] 154 | |`vagrantUp` |- |link:http://bmuschko.github.io/gradle-vagrant-plugin/docs/groovydoc/com/bmuschko/gradle/vagrant/tasks/VagrantUp.html[VagrantUp] 155 | |======= 156 | 157 | 158 | === Example 159 | 160 | [source,groovy] 161 | ---- 162 | vagrant { 163 | boxDir = file('~/dev/my-vagrant-box') 164 | 165 | environmentVariables { 166 | variable 'IP', '192.168.1.33' 167 | variable 'OPERATINGSYSTEM', 'redhat' 168 | } 169 | 170 | installation { 171 | validate = false 172 | } 173 | } 174 | 175 | import com.bmuschko.gradle.vagrant.tasks.Vagrant 176 | import com.bmuschko.gradle.vagrant.tasks.VagrantSsh 177 | 178 | task vagrantListsBoxes(type: Vagrant) { 179 | description = 'Outputs a list of available Vagrant boxes.' 180 | commands = ['box', 'list'] 181 | } 182 | 183 | task vagrantEcho(type: VagrantSsh) { 184 | description = 'Runs remote SSH command in Vagrant box.' 185 | sshCommand = "echo 'hello'" 186 | 187 | dependsOn vagrantUp 188 | finalizedBy vagrantDestroy 189 | } 190 | ---- -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------