├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── kokoro
├── continuous.bat
└── continuous.sh
├── minikube-gradle-plugin
├── CHANGELOG.md
├── README.md
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── scripts
│ └── prepare_release.sh
├── settings.gradle
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── google
│ │ │ └── cloud
│ │ │ └── tools
│ │ │ └── minikube
│ │ │ ├── MinikubeExtension.java
│ │ │ ├── MinikubePlugin.java
│ │ │ ├── MinikubeTask.java
│ │ │ └── util
│ │ │ ├── CommandExecutor.java
│ │ │ ├── CommandExecutorFactory.java
│ │ │ └── MinikubeDockerEnvParser.java
│ └── resources
│ │ └── META-INF
│ │ └── gradle-plugins
│ │ └── com.google.cloud.tools.minikube.properties
│ └── test
│ ├── java
│ └── com
│ │ └── google
│ │ └── cloud
│ │ └── tools
│ │ └── minikube
│ │ ├── MinikubeExtensionTest.java
│ │ ├── MinikubePluginTest.java
│ │ ├── MinikubeTaskTest.java
│ │ └── util
│ │ ├── CommandExecutorTest.java
│ │ └── MinikubeDockerEnvParserTest.java
│ └── resources
│ └── mockito-extensions
│ └── org.mockito.plugins.MockMaker
└── minikube-maven-plugin
├── .gitignore
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── CHANGELOG.md
├── README.md
├── config
├── checkstyle-header.xml
├── copyright.header
└── google-checks-no-indent.xml
├── kokoro
└── release_build.sh
├── mvnw
├── mvnw.cmd
├── pom.xml
├── scripts
└── prepare_release.sh
└── src
├── main
└── java
│ └── com
│ └── google
│ └── cloud
│ └── tools
│ └── minikube
│ ├── command
│ ├── BuildLogger.java
│ └── CommandExecutor.java
│ └── maven
│ ├── AbstractMinikubeMojo.java
│ ├── CommandConfiguration.java
│ ├── DeleteMojo.java
│ ├── MavenBuildLogger.java
│ ├── StartMojo.java
│ └── StopMojo.java
└── test
├── java
└── com
│ └── google
│ └── cloud
│ └── tools
│ └── minikube
│ ├── command
│ └── CommandExecutorTest.java
│ └── maven
│ ├── AbstractMinikubeMojoTest.java
│ ├── DeleteMojoTest.java
│ ├── FakeMinikube.java
│ ├── MinikubeVerifier.java
│ ├── StartMojoTest.java
│ ├── StopMojoTest.java
│ ├── TestPlugin.java
│ └── TestProject.java
└── resources
├── fakeminikube
├── mockito-extensions
└── org.mockito.plugins.MockMaker
└── projects
└── simple
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 | target
3 | out
4 | *.iml
5 | *.ipr
6 | *.iws
7 | .idea
8 | .gradle
9 | /.settings
10 | /.classpath
11 | /.project
12 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to Minikube build tools for java
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution,
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code Reviews
19 |
20 | 1. Set your git user.email property to the address used for step 1. E.g.
21 | ```
22 | git config --global user.email "janedoe@google.com"
23 | ```
24 | If you're a Googler or other corporate contributor,
25 | use your corporate email address here, not your personal address.
26 | 2. Fork the repository into your own Github account.
27 | 3. Please include unit tests for all new code.
28 | 4. Make sure all existing tests pass. (gradlew test)
29 | 5. Associate the change with an existing issue or file a [new issue](../../issues)
30 | 6. Create a pull request!
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | | ⛔⛔⛔ DEPRECATED ⛔⛔⛔ |
2 | | :----- |
3 | | These plugins are not maintained, no more updates or releases will be made. Users may fork and update this project on their own. |
4 |
5 | Minikube Gradle and Maven Plugins
6 | =================================
7 | - [minikube-gradle-plugin](https://github.com/GoogleCloudPlatform/minikube-build-tools-for-java/tree/master/minikube-gradle-plugin)
8 | - [minikube-maven-plugin](https://github.com/GoogleCloudPlatform/minikube-build-tools-for-java/tree/master/minikube-maven-plugin)
9 |
--------------------------------------------------------------------------------
/kokoro/continuous.bat:
--------------------------------------------------------------------------------
1 | @echo on
2 |
3 | cd github/minikube-build-tools-for-java
4 |
5 | rem there is no minikube installed on this system, so any integration test will probably not work
6 | rem we porbably also have to install VirtualBox or some other VM driver, it not even clear to me
7 | rem that kokoro will allow us to run a VM.
8 |
9 | cd minikube-gradle-plugin && call gradlew.bat --console=plain clean build && ^
10 | cd ../minikube-maven-plugin && call mvnw.bat -B -U clean verify
11 | exit /b %ERRORLEVEL%
12 |
--------------------------------------------------------------------------------
/kokoro/continuous.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 | set -x
5 |
6 | cd github/minikube-build-tools-for-java
7 |
8 | (cd minikube-gradle-plugin; ./gradlew --console=plain clean build)
9 | (cd minikube-maven-plugin; ./mvnw -B -U clean verify)
10 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 | All notable changes to this project will be documented in this file.
3 | ## [unreleased]
4 |
5 | ### Added
6 |
7 | ### Changed
8 |
9 | ### Fixed
10 |
11 | ## 1.0.0
12 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/README.md:
--------------------------------------------------------------------------------
1 | | ⛔⛔⛔ DEPRECATED ⛔⛔⛔ |
2 | | :----- |
3 | | These plugins are not maintained, no more updates or releases will be made. Users may fork and update this project on their own. |
4 |
5 |
6 | Minikube Gradle Plugin
7 | ======================
8 | This plugin provides tasks and configuration to manage a minikube lifecycle for gradle developers.
9 |
10 | Now available on [gradle plugin portal](https://plugins.gradle.org/plugin/com.google.cloud.tools.minikube).
11 |
12 | This plugin requires that you have Minikube [installed](https://kubernetes.io/docs/tasks/tools/install-minikube/).
13 |
14 | It exposes the following tasks
15 | - `minikubeStart`
16 | - `minikubeStop`
17 | - `minikubeDelete`
18 |
19 | It exposes the `minikube` configuration extension.
20 |
21 | ```groovy
22 | minikube {
23 | minikube = // path to minikube, default is "minikube"
24 | }
25 | ```
26 |
27 | Task specific flags are configured on the tasks themselves.
28 |
29 | All `minikube` tasks are of the type `MinikubeTask` and all share the same kind of configuration.
30 | - `flags` (`String[]`) : any minikube flags **this is the only one users should edit for the provided tasks**
31 | - `minikube` (`String`) : path to minikube executable which should be set by using the `minikube` extension
32 | - `command` (`String`) : start/stop/whatever (users probably shouldn't be editing this for default commands)
33 |
34 | ```groovy
35 | minikubeStart {
36 | flags = ["--vm-driver=none"]
37 | }
38 | ```
39 |
40 | This plugin also allows users to add in any custom `minikube` task.
41 |
42 | ```groovy
43 | task minikubeCustom(type: com.google.cloud.tools.minikube.MinikubeTask) {
44 | command = "custom"
45 | flags = ["--some-flag"]
46 | }
47 | ```
48 |
49 | The `minikube` extension also provides a method to obtain the environment variables necessary for working with minikube's docker daemon (See [`docker-machine env` reference](https://docs.docker.com/machine/reference/env/))
50 | :
51 | ```
52 | def minikubeDockerEnv = minikube.getDockerEnv()
53 | ```
54 |
55 | Optional parameter `` sets target minikube instance (`minikube --profile `).
56 |
57 | `minikubeDockerEnv` is a map containing these fields:
58 |
59 | ```
60 | minikubeDockerEnv.DOCKER_TLS_VERIFY
61 | minikubeDockerEnv.DOCKER_HOST
62 | minikubeDockerEnv.DOCKER_CERT_PATH
63 | minikubeDockerEnv.DOCKER_API_VERSION
64 | ```
65 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java-gradle-plugin'
3 | id 'checkstyle'
4 | id 'com.gradle.plugin-publish' version '0.9.7'
5 | id 'com.github.sherter.google-java-format' version '0.8'
6 | id 'net.researchgate.release' version '2.6.0'
7 | id 'maven'
8 | }
9 |
10 | sourceCompatibility = JavaVersion.VERSION_1_8
11 | targetCompatibility = JavaVersion.VERSION_1_8
12 |
13 | repositories {
14 | // use jcenter for gradle plugin portal releases.
15 | jcenter()
16 | }
17 |
18 | dependencies {
19 | compile gradleApi()
20 | testCompile 'junit:junit:4.11'
21 | testCompile 'org.apache.commons:commons-lang3:3.6'
22 | testCompile 'org.mockito:mockito-core:2.+'
23 | }
24 |
25 | group = 'com.google.cloud.tools'
26 |
27 | jar {
28 | manifest {
29 | attributes 'Implementation-Title': project.name,
30 | 'Implementation-Version': version,
31 | 'Built-By': System.getProperty('user.name'),
32 | 'Built-Date': new Date(),
33 | 'Built-JDK': System.getProperty('java.version'),
34 | 'Built-Gradle': gradle.gradleVersion
35 | }
36 | }
37 |
38 | test {
39 | testLogging {
40 | showStandardStreams = true
41 | exceptionFormat = 'full'
42 | }
43 | }
44 |
45 |
46 | /* GOOGLE JAVA FORMAT */
47 | check.dependsOn verifyGoogleJavaFormat
48 | /* GOOGLE JAVA FORMAT */
49 |
50 |
51 | /* CHECKSTYLE */
52 | checkstyle {
53 | toolVersion = "8.18"
54 |
55 | // get the google_checks.xml file from the checkstyle jar and take out the java checks
56 | def googleChecks = resources.text.fromArchiveEntry(configurations.checkstyle[0], 'google_checks.xml').asString()
57 | def fileExtensionsBefore = ''
58 | def fileExtensionsAfter = ''
59 | def googleChecksNoJava = googleChecks.replace(fileExtensionsBefore, fileExtensionsAfter)
60 | assert !googleChecks.equals(googleChecksNoJava)
61 |
62 | config = resources.text.fromString(googleChecksNoJava)
63 |
64 | maxErrors = 0
65 | maxWarnings = 0
66 | }
67 | /* CHECKSTYLE */
68 |
69 | /* RELEASE */
70 | // gradle plugin portal releases
71 | pluginBundle {
72 | website = 'https://github.com/GoogleCloudPlatform/minikube-build-tools-for-java/'
73 | vcsUrl = 'https://github.com/GoogleCloudPlatform/minikube-build-tools-for-java/'
74 |
75 | plugins {
76 | minikubePlugin {
77 | id = 'com.google.cloud.tools.minikube'
78 | displayName = 'Gradle Minikube plugin'
79 | description = 'A plugin to manage the minikube lifecycle in a gradle project'
80 | tags = ['google', 'minikube']
81 | }
82 | }
83 | }
84 |
85 | // Release plugin (git release commits and version updates)
86 | release {
87 | tagTemplate = 'v$version-gradle'
88 | git {
89 | requireBranch = /^gradle_release_v[0-9A-Za-z.-]+.*$/ //regex
90 | }
91 | }
92 | /* RELEASE */
93 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/gradle.properties:
--------------------------------------------------------------------------------
1 | version = 1.0.0-SNAPSHOT
2 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogleContainerTools/minikube-build-tools-for-java/120fe65eca3cb99219e3a099869f80e7848356ae/minikube-gradle-plugin/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/minikube-gradle-plugin/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/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 | # http://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, switch paths to Windows format before running java
129 | if $cygwin ; 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=$((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 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
185 | cd "$(dirname "$0")"
186 | fi
187 |
188 | exec "$JAVACMD" "$@"
189 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/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 http://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 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/scripts/prepare_release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -
2 | # Usage: ./scripts/prepare_release.sh []
3 |
4 | set -e
5 |
6 | EchoRed() {
7 | echo "$(tput setaf 1; tput bold)$1$(tput sgr0)"
8 | }
9 | EchoGreen() {
10 | echo "$(tput setaf 2; tput bold)$1$(tput sgr0)"
11 | }
12 |
13 | Die() {
14 | EchoRed "$1"
15 | exit 1
16 | }
17 |
18 | DieUsage() {
19 | Die "Usage: ./scripts/prepare_release.sh []"
20 | }
21 |
22 | # Usage: CheckVersion
23 | CheckVersion() {
24 | [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]] || Die "Version: $1 not in ###.###.###[-XXX] format."
25 | }
26 |
27 | [ $# -ne 1 ] && [ $# -ne 2 ] && DieUsage
28 |
29 | EchoGreen '===== RELEASE SETUP SCRIPT ====='
30 |
31 | VERSION=$1
32 | CheckVersion ${VERSION}
33 | if [ -n "$2" ]; then
34 | POST_RELEASE_VERSION=$2
35 | CheckVersion ${POST_RELEASE_VERSION}
36 | fi
37 |
38 | if [[ $(git status -uno --porcelain) ]]; then
39 | Die 'There are uncommitted changes.'
40 | fi
41 |
42 | # Runs integration tests. (ignored for now)
43 | # ./gradlew integrationTest --info --stacktrace
44 |
45 | # Checks out a new branch for this version release (eg. 1.5.7).
46 | BRANCH=gradle_release_v${VERSION}
47 | git checkout -b ${BRANCH}
48 |
49 | # Changes the version for release and creates the commits/tags.
50 | echo | ./gradlew release -Prelease.releaseVersion=${VERSION} ${POST_RELEASE_VERSION:+"-Prelease.newVersion=${POST_RELEASE_VERSION}"}
51 |
52 | # Pushes the release branch and tag to Github.
53 | git push origin ${BRANCH}
54 | git push origin v${VERSION}-gradle
55 |
56 | # File a PR on Github for the new branch. Have someone LGTM it, which gives you permission to continue.
57 | EchoGreen 'File a PR for the new release branch:'
58 | echo https://github.com/GoogleContainerTools/minikube-build-tools-for-java/compare/${BRANCH}
59 |
60 | EchoGreen "Once approved and merged, checkout the 'v${VERSION}-gradle' tag and run './gradlew publishPlugins'."
61 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'minikube-gradle-plugin'
2 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/src/main/java/com/google/cloud/tools/minikube/MinikubeExtension.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube;
18 |
19 | import com.google.cloud.tools.minikube.util.CommandExecutorFactory;
20 | import com.google.cloud.tools.minikube.util.MinikubeDockerEnvParser;
21 | import java.io.IOException;
22 | import java.util.Arrays;
23 | import java.util.List;
24 | import java.util.Map;
25 | import org.gradle.api.Project;
26 | import org.gradle.api.provider.Property;
27 |
28 | /** Minikube configuration extension. */
29 | public class MinikubeExtension {
30 |
31 | private final Property minikube;
32 |
33 | private final CommandExecutorFactory commandExecutorFactory;
34 |
35 | public MinikubeExtension(Project project, CommandExecutorFactory commandExecutorFactory) {
36 | minikube = project.getObjects().property(String.class);
37 | setMinikube("minikube");
38 |
39 | this.commandExecutorFactory = commandExecutorFactory;
40 | }
41 |
42 | public String getMinikube() {
43 | return minikube.get();
44 | }
45 |
46 | public void setMinikube(String minikube) {
47 | this.minikube.set(minikube);
48 | }
49 |
50 | public Property getMinikubeProvider() {
51 | return minikube;
52 | }
53 |
54 | /**
55 | * Gets the minikube docker environment variables by running the command 'minikube docker-env
56 | * --shell=none'.
57 | *
58 | * @return A map of docker environment variables and their values
59 | */
60 | public Map getDockerEnv() throws IOException, InterruptedException {
61 | return getDockerEnv("");
62 | }
63 |
64 | /**
65 | * Gets the minikube docker environment variables by running the command 'minikube docker-env
66 | * --shell=none'.
67 | *
68 | * @param profile target minikube profile
69 | * @return A map of docker environment variables and their values
70 | */
71 | public Map getDockerEnv(String profile) throws IOException, InterruptedException {
72 | if (profile == null) {
73 | throw new NullPointerException("Minikube profile must not be null");
74 | }
75 |
76 | List minikubeDockerEnvCommand =
77 | Arrays.asList(minikube.get(), "docker-env", "--shell=none", "--profile=" + profile);
78 |
79 | List dockerEnv =
80 | commandExecutorFactory.newCommandExecutor().run(minikubeDockerEnvCommand);
81 |
82 | return MinikubeDockerEnvParser.parse(dockerEnv);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/src/main/java/com/google/cloud/tools/minikube/MinikubePlugin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube;
18 |
19 | import com.google.cloud.tools.minikube.util.CommandExecutorFactory;
20 | import org.gradle.api.Plugin;
21 | import org.gradle.api.Project;
22 |
23 | /** An extremely basic minikube plugin to manage the minikube lifecycle from gradle. */
24 | public class MinikubePlugin implements Plugin {
25 | private static String MINIKUBE_GROUP = "Minikube";
26 | private Project project;
27 | private MinikubeExtension minikubeExtension;
28 |
29 | @Override
30 | public void apply(Project project) {
31 | this.project = project;
32 | CommandExecutorFactory commandExecutorFactory = new CommandExecutorFactory(project.getLogger());
33 |
34 | createMinikubeExtension(commandExecutorFactory);
35 |
36 | configureMinikubeTaskAdditionCallback(commandExecutorFactory);
37 | createMinikubeStartTask();
38 | createMinikubeStopTask();
39 | createMinikubeDeleteTask();
40 | }
41 |
42 | // Configure tasks as they are added. This allows us to configure our own AND any user configured
43 | // tasks.
44 | private void configureMinikubeTaskAdditionCallback(
45 | CommandExecutorFactory commandExecutorFactory) {
46 | project
47 | .getTasks()
48 | .withType(MinikubeTask.class)
49 | .whenTaskAdded(
50 | task -> {
51 | task.setMinikube(minikubeExtension.getMinikubeProvider());
52 | task.setGroup(MINIKUBE_GROUP);
53 | task.setCommandExecutorFactory(commandExecutorFactory);
54 | });
55 | }
56 |
57 | private void createMinikubeExtension(CommandExecutorFactory commandExecutorFactory) {
58 | minikubeExtension =
59 | project
60 | .getExtensions()
61 | .create("minikube", MinikubeExtension.class, project, commandExecutorFactory);
62 | }
63 |
64 | private void createMinikubeStartTask() {
65 | MinikubeTask task = project.getTasks().create("minikubeStart", MinikubeTask.class);
66 | task.setCommand("start");
67 | task.setDescription("Starts the minikube cluster.");
68 | }
69 |
70 | private void createMinikubeStopTask() {
71 | MinikubeTask task = project.getTasks().create("minikubeStop", MinikubeTask.class);
72 | task.setCommand("stop");
73 | task.setDescription("Stops the minikube cluster.");
74 | }
75 |
76 | private void createMinikubeDeleteTask() {
77 | MinikubeTask task = project.getTasks().create("minikubeDelete", MinikubeTask.class);
78 | task.setCommand("delete");
79 | task.setDescription("Deletes the minikube cluster.");
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/src/main/java/com/google/cloud/tools/minikube/MinikubeTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube;
18 |
19 | import com.google.cloud.tools.minikube.util.CommandExecutorFactory;
20 | import java.io.IOException;
21 | import java.util.ArrayList;
22 | import java.util.Arrays;
23 | import java.util.List;
24 | import org.gradle.api.DefaultTask;
25 | import org.gradle.api.provider.Property;
26 | import org.gradle.api.tasks.Input;
27 | import org.gradle.api.tasks.TaskAction;
28 |
29 | /** Generic Minikube task. */
30 | public class MinikubeTask extends DefaultTask {
31 |
32 | /** minikube executable : lazily evaluated from extension input */
33 | private Property minikube;
34 | /** The minikube command: start, stop, etc. */
35 | private String command;
36 | /** Flag passthrough */
37 | private String[] flags = {};
38 |
39 | private CommandExecutorFactory commandExecutorFactory;
40 |
41 | public MinikubeTask() {
42 | minikube = getProject().getObjects().property(String.class);
43 | }
44 |
45 | public MinikubeTask setCommandExecutorFactory(CommandExecutorFactory commandExecutorFactory) {
46 | this.commandExecutorFactory = commandExecutorFactory;
47 | return this;
48 | }
49 |
50 | @Input
51 | public String getMinikube() {
52 | return minikube.get();
53 | }
54 |
55 | public void setMinikube(String minikube) {
56 | this.minikube.set(minikube);
57 | }
58 |
59 | public void setMinikube(Property minikube) {
60 | this.minikube = minikube;
61 | }
62 |
63 | @Input
64 | public String getCommand() {
65 | return command;
66 | }
67 |
68 | public void setCommand(String command) {
69 | this.command = command;
70 | }
71 |
72 | @Input
73 | public String[] getFlags() {
74 | return flags;
75 | }
76 |
77 | public void setFlags(String[] flags) {
78 | this.flags = flags;
79 | }
80 |
81 | @TaskAction
82 | public void execMinikube() throws IOException, InterruptedException {
83 | List minikubeCommand = buildMinikubeCommand();
84 | commandExecutorFactory.newCommandExecutor().run(minikubeCommand);
85 | }
86 |
87 | // @VisibleForTesting
88 | List buildMinikubeCommand() {
89 | List execString = new ArrayList<>();
90 | execString.add(getMinikube());
91 | execString.add(command);
92 | execString.addAll(Arrays.asList(flags));
93 |
94 | return execString;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/src/main/java/com/google/cloud/tools/minikube/util/CommandExecutor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.util;
18 |
19 | import java.io.BufferedReader;
20 | import java.io.IOException;
21 | import java.io.InputStreamReader;
22 | import java.util.ArrayList;
23 | import java.util.List;
24 | import java.util.Map;
25 | import java.util.concurrent.ExecutorService;
26 | import java.util.concurrent.Executors;
27 | import java.util.concurrent.TimeUnit;
28 | import org.gradle.api.GradleException;
29 | import org.gradle.api.logging.Logger;
30 |
31 | /** Executes a shell command. */
32 | public class CommandExecutor {
33 |
34 | // @VisibleForTesting
35 | static final int TIMEOUT_SECONDS = 5;
36 |
37 | /** Sets the {@code Logger} to use to log messages during the command execution. */
38 | public CommandExecutor setLogger(Logger logger) {
39 | this.logger = logger;
40 | return this;
41 | }
42 |
43 | /** Sets the environment variables to run the command with. */
44 | public CommandExecutor setEnvironment(Map environmentMap) {
45 | this.environment = environmentMap;
46 | return this;
47 | }
48 |
49 | // @VisibleForTesting
50 | static class ProcessBuilderFactory {
51 | ProcessBuilder createProcessBuilder() {
52 | return new ProcessBuilder();
53 | }
54 | }
55 |
56 | // @VisibleForTesting
57 | CommandExecutor setProcessBuilderFactory(ProcessBuilderFactory processBuilderFactory) {
58 | this.processBuilderFactory = processBuilderFactory;
59 | return this;
60 | }
61 |
62 | // @VisibleForTesting
63 | static class ExecutorServiceFactory {
64 | ExecutorService createExecutorService() {
65 | return Executors.newSingleThreadExecutor();
66 | }
67 | }
68 |
69 | // @VisibleForTesting
70 | CommandExecutor setExecutorServiceFactory(ExecutorServiceFactory executorServiceFactory) {
71 | this.executorServiceFactory = executorServiceFactory;
72 | return this;
73 | }
74 |
75 | private ProcessBuilderFactory processBuilderFactory = new ProcessBuilderFactory();
76 | private ExecutorServiceFactory executorServiceFactory = new ExecutorServiceFactory();
77 | private Logger logger;
78 | private Map environment;
79 |
80 | /**
81 | * Runs the command.
82 | *
83 | * @param command the list of command line tokens
84 | * @return the output of the command as a list of lines
85 | * @throws GradleException if the command exited with non-zero exit code
86 | */
87 | public List run(List command) throws IOException, InterruptedException {
88 | if (logger != null) {
89 | logger.debug("Running command : " + String.join(" ", command));
90 | }
91 |
92 | ExecutorService executor = executorServiceFactory.createExecutorService();
93 |
94 | // Builds the command to execute.
95 | ProcessBuilder processBuilder = processBuilderFactory.createProcessBuilder();
96 | processBuilder.command(command);
97 | processBuilder.redirectErrorStream(true);
98 | if (environment != null) {
99 | processBuilder.environment().putAll(environment);
100 | }
101 | final Process process = processBuilder.start();
102 |
103 | // Runs the command and streams the output.
104 | List output = new ArrayList<>();
105 | executor.execute(outputConsumerRunnable(process, output));
106 | int exitCode = process.waitFor();
107 |
108 | // Shuts down the executor.
109 | executor.shutdown();
110 |
111 | try {
112 | executor.awaitTermination(TIMEOUT_SECONDS, TimeUnit.SECONDS);
113 | } catch (InterruptedException ex) {
114 | if (logger != null) {
115 | logger.debug("Task Executor interrupted waiting for output consumer thread");
116 | }
117 | }
118 |
119 | // Stops the build if the command fails to do something, we may want to make this configurable.
120 | if (exitCode != 0) {
121 | throw new GradleException("command exited with non-zero exit code : " + exitCode);
122 | }
123 |
124 | return output;
125 | }
126 |
127 | /**
128 | * Creates a Runnable to for the single thread {@code ExecutorService} to read the command output.
129 | *
130 | * @param process the process to read from
131 | * @param output a list to store the output lines to
132 | */
133 | private Runnable outputConsumerRunnable(Process process, List output) {
134 | return () -> {
135 | try (BufferedReader br =
136 | new BufferedReader(new InputStreamReader(process.getInputStream()))) {
137 | String line = br.readLine();
138 | while (line != null) {
139 | if (logger != null) {
140 | logger.info(line);
141 | }
142 | output.add(line);
143 | line = br.readLine();
144 | }
145 | } catch (IOException ex) {
146 | if (logger != null) {
147 | logger.warn("IO Exception reading process output");
148 | }
149 | }
150 | };
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/src/main/java/com/google/cloud/tools/minikube/util/CommandExecutorFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.util;
18 |
19 | import org.gradle.api.logging.Logger;
20 |
21 | /** {@link CommandExecutor} Factory. */
22 | public class CommandExecutorFactory {
23 | private final Logger logger;
24 |
25 | /**
26 | * Creates a new factory.
27 | *
28 | * @param logger for logging messages during the command execution
29 | */
30 | public CommandExecutorFactory(Logger logger) {
31 | this.logger = logger;
32 | }
33 |
34 | public CommandExecutor newCommandExecutor() {
35 | return new CommandExecutor().setLogger(logger);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/src/main/java/com/google/cloud/tools/minikube/util/MinikubeDockerEnvParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.util;
18 |
19 | import java.util.HashMap;
20 | import java.util.List;
21 | import java.util.Map;
22 |
23 | /** Utility class to parse a minikube's Docker environment variables list. */
24 | public class MinikubeDockerEnvParser {
25 |
26 | private MinikubeDockerEnvParser() {}
27 |
28 | /**
29 | * Parses a list of KEY=VALUE strings into a map from KEY to VALUE.
30 | *
31 | * @param keyValueStrings a list of "KEY=VALUE" strings, where KEY is the environment variable
32 | * name and VALUE is the value to set it to
33 | */
34 | public static Map parse(List keyValueStrings) {
35 | Map environmentMap = new HashMap<>();
36 |
37 | for (String keyValueString : keyValueStrings) {
38 | String[] keyValuePair = keyValueString.split("=", 2);
39 |
40 | if (keyValuePair.length < 2) {
41 | throw new IllegalArgumentException(
42 | "Error while parsing minikube's Docker environment: environment variable string not in KEY=VALUE format");
43 | }
44 | if (keyValuePair[0].length() == 0) {
45 | throw new IllegalArgumentException(
46 | "Error while parsing minikube's Docker environment: encountered empty environment variable name");
47 | }
48 |
49 | environmentMap.put(keyValuePair[0], keyValuePair[1]);
50 | }
51 |
52 | return environmentMap;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/src/main/resources/META-INF/gradle-plugins/com.google.cloud.tools.minikube.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2017 Google Inc.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | # use this file except in compliance with the License. You may obtain a copy of
6 | # 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, WITHOUT
12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | # License for the specific language governing permissions and limitations under
14 | # the License.
15 | #
16 |
17 | implementation-class=com.google.cloud.tools.minikube.MinikubePlugin
18 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/src/test/java/com/google/cloud/tools/minikube/MinikubeExtensionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube;
18 |
19 | import static org.mockito.Mockito.mock;
20 | import static org.mockito.Mockito.times;
21 | import static org.mockito.Mockito.verify;
22 | import static org.mockito.Mockito.when;
23 |
24 | import com.google.cloud.tools.minikube.util.CommandExecutor;
25 | import com.google.cloud.tools.minikube.util.CommandExecutorFactory;
26 | import java.io.IOException;
27 | import java.util.ArrayList;
28 | import java.util.Arrays;
29 | import java.util.Collections;
30 | import java.util.HashMap;
31 | import java.util.List;
32 | import java.util.Map;
33 | import org.gradle.api.Project;
34 | import org.gradle.testfixtures.ProjectBuilder;
35 | import org.junit.Assert;
36 | import org.junit.Before;
37 | import org.junit.Test;
38 |
39 | /** Tests for MinikubeExtension */
40 | public class MinikubeExtensionTest {
41 |
42 | private CommandExecutor commandExecutorMock;
43 | private CommandExecutorFactory commandExecutorFactoryMock;
44 | private MinikubeExtension minikube;
45 |
46 | private List expectedCommand;
47 | private static final List dockerEnvOutput =
48 | Arrays.asList("ENV_VAR1=VAL1", "ENV_VAR2=VAL2");
49 | private static final Map expectedMap;
50 |
51 | static {
52 | Map map = new HashMap<>(2);
53 | map.put("ENV_VAR1", "VAL1");
54 | map.put("ENV_VAR2", "VAL2");
55 | expectedMap = Collections.unmodifiableMap(map);
56 | }
57 |
58 | @Before
59 | public void setUp() {
60 | Project project = ProjectBuilder.builder().build();
61 |
62 | // Mocks the CommandExecutor.
63 | commandExecutorMock = mock(CommandExecutor.class);
64 | commandExecutorFactoryMock = mock(CommandExecutorFactory.class);
65 | when(commandExecutorFactoryMock.newCommandExecutor()).thenReturn(commandExecutorMock);
66 |
67 | // Creates an extension to test on.
68 | minikube = new MinikubeExtension(project, commandExecutorFactoryMock);
69 | minikube.setMinikube("/test/path/to/minikube");
70 |
71 | expectedCommand =
72 | new ArrayList<>(Arrays.asList("/test/path/to/minikube", "docker-env", "--shell=none"));
73 | }
74 |
75 | /*
76 | * Test with default minikube profile
77 | */
78 | @Test
79 | public void testGetDockerEnvWithDefaultProfile() throws IOException, InterruptedException {
80 | expectedCommand.add("--profile=");
81 | when(commandExecutorMock.run(expectedCommand)).thenReturn(dockerEnvOutput);
82 | Assert.assertEquals(expectedMap, minikube.getDockerEnv());
83 | verify(commandExecutorMock).run(expectedCommand);
84 | }
85 |
86 | /*
87 | * Test with 'testProfile'
88 | */
89 | @Test
90 | public void testGetDockerEnvWithTestProfile() throws IOException, InterruptedException {
91 | String profile = "testProfile";
92 | expectedCommand.add("--profile=".concat(profile));
93 | when(commandExecutorMock.run(expectedCommand)).thenReturn(dockerEnvOutput);
94 | Assert.assertEquals(expectedMap, minikube.getDockerEnv(profile));
95 | verify(commandExecutorMock).run(expectedCommand);
96 | }
97 |
98 | /*
99 | * Make sure both minikube.getDockerEnv() and minikube.getDockerEnv("") refer to the default minikube profile
100 | */
101 | @Test
102 | public void testGetSameDockerEnvWithTwoDefaultProfiles()
103 | throws IOException, InterruptedException {
104 | String profile = "";
105 | expectedCommand.add("--profile=".concat(profile));
106 | when(commandExecutorMock.run(expectedCommand)).thenReturn(dockerEnvOutput);
107 | Assert.assertEquals(minikube.getDockerEnv(), minikube.getDockerEnv(profile));
108 | verify(commandExecutorMock, times(2)).run(expectedCommand);
109 | }
110 |
111 | /*
112 | * getDockerEnv() should not permit null values
113 | */
114 | @Test
115 | public void testGetDockerEnvWithNullProfile() throws IOException, InterruptedException {
116 | try {
117 | minikube.getDockerEnv(null);
118 | Assert.fail("getDockerEnv() should not permit null values");
119 | } catch (NullPointerException ex) {
120 | Assert.assertNotNull(ex.getMessage());
121 | Assert.assertEquals("Minikube profile must not be null", ex.getMessage());
122 | }
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/src/test/java/com/google/cloud/tools/minikube/MinikubePluginTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube;
18 |
19 | import org.gradle.api.Project;
20 | import org.gradle.api.internal.project.ProjectInternal;
21 | import org.gradle.api.tasks.TaskCollection;
22 | import org.gradle.api.tasks.TaskContainer;
23 | import org.gradle.testfixtures.ProjectBuilder;
24 | import org.junit.Assert;
25 | import org.junit.Rule;
26 | import org.junit.Test;
27 | import org.junit.rules.TemporaryFolder;
28 |
29 | /** Tests for MinikubePlugin */
30 | public class MinikubePluginTest {
31 | @Rule public TemporaryFolder tmp = new TemporaryFolder();
32 |
33 | @Test
34 | public void testDefaultMinikubeTasks() {
35 | Project project = ProjectBuilder.builder().withProjectDir(tmp.getRoot()).build();
36 | project.getPluginManager().apply(MinikubePlugin.class);
37 | ((ProjectInternal) project).evaluate();
38 |
39 | TaskContainer t = project.getTasks();
40 | TaskCollection tc = t.withType(MinikubeTask.class);
41 |
42 | Assert.assertEquals(3, tc.size());
43 |
44 | AssertMinikubeTaskConfig(tc, "minikubeStart", "start");
45 | AssertMinikubeTaskConfig(tc, "minikubeStop", "stop");
46 | AssertMinikubeTaskConfig(tc, "minikubeDelete", "delete");
47 | }
48 |
49 | private void AssertMinikubeTaskConfig(
50 | TaskCollection tc, String taskName, String taskCommand) {
51 | MinikubeTask minikubeTask = tc.getByName(taskName);
52 | Assert.assertEquals(minikubeTask.getMinikube(), "minikube");
53 | Assert.assertEquals(minikubeTask.getCommand(), taskCommand);
54 | Assert.assertArrayEquals(minikubeTask.getFlags(), new String[] {});
55 | }
56 |
57 | @Test
58 | public void testMinikubeExtensionSetProperties() {
59 | Project project = ProjectBuilder.builder().withProjectDir(tmp.getRoot()).build();
60 | project.getPluginManager().apply(MinikubePlugin.class);
61 | MinikubeExtension ex = (MinikubeExtension) project.getExtensions().getByName("minikube");
62 | ex.setMinikube("/custom/minikube/path");
63 |
64 | TaskContainer t = project.getTasks();
65 | TaskCollection tc = t.withType(MinikubeTask.class);
66 |
67 | Assert.assertEquals(3, tc.size());
68 |
69 | tc.forEach(
70 | minikubeTask -> {
71 | Assert.assertEquals(minikubeTask.getMinikube(), "/custom/minikube/path");
72 | });
73 | }
74 |
75 | @Test
76 | public void testUserAddedMinikubeTaskConfigured() {
77 | Project project = ProjectBuilder.builder().withProjectDir(tmp.getRoot()).build();
78 | project.getPluginManager().apply(MinikubePlugin.class);
79 | MinikubeExtension ex = (MinikubeExtension) project.getExtensions().getByName("minikube");
80 | ex.setMinikube("/custom/minikube/path");
81 |
82 | MinikubeTask custom = project.getTasks().create("minikubeCustom", MinikubeTask.class);
83 | custom.setCommand("custom");
84 |
85 | Assert.assertEquals(custom.getMinikube(), "/custom/minikube/path");
86 | Assert.assertEquals(custom.getCommand(), "custom");
87 | Assert.assertArrayEquals(custom.getFlags(), new String[] {});
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/src/test/java/com/google/cloud/tools/minikube/MinikubeTaskTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube;
18 |
19 | import java.util.Arrays;
20 | import org.gradle.api.Project;
21 | import org.gradle.testfixtures.ProjectBuilder;
22 | import org.junit.Assert;
23 | import org.junit.Rule;
24 | import org.junit.Test;
25 | import org.junit.rules.TemporaryFolder;
26 |
27 | /** Tests for MinikubeTask */
28 | public class MinikubeTaskTest {
29 |
30 | @Rule public TemporaryFolder tmp = new TemporaryFolder();
31 |
32 | @Test
33 | public void testBuildCommand() {
34 | Project project = ProjectBuilder.builder().withProjectDir(tmp.getRoot()).build();
35 | MinikubeTask testTask =
36 | project
37 | .getTasks()
38 | .create(
39 | "minikubeTestTask",
40 | MinikubeTask.class,
41 | minikubeTask -> {
42 | minikubeTask.setMinikube("/test/path/to/minikube");
43 | minikubeTask.setCommand("testCommand");
44 | minikubeTask.setFlags(new String[] {"testFlag1", "testFlag2"});
45 | });
46 |
47 | Assert.assertEquals(
48 | Arrays.asList("/test/path/to/minikube", "testCommand", "testFlag1", "testFlag2"),
49 | testTask.buildMinikubeCommand());
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/src/test/java/com/google/cloud/tools/minikube/util/CommandExecutorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.util;
18 |
19 | import static org.mockito.Mockito.inOrder;
20 | import static org.mockito.Mockito.mock;
21 | import static org.mockito.Mockito.verify;
22 | import static org.mockito.Mockito.verifyZeroInteractions;
23 | import static org.mockito.Mockito.when;
24 |
25 | import java.io.IOException;
26 | import java.io.InputStream;
27 | import java.util.Arrays;
28 | import java.util.HashMap;
29 | import java.util.List;
30 | import java.util.Map;
31 | import java.util.concurrent.ExecutorService;
32 | import java.util.concurrent.TimeUnit;
33 | import org.apache.tools.ant.filters.StringInputStream;
34 | import org.gradle.api.GradleException;
35 | import org.gradle.api.logging.Logger;
36 | import org.junit.Assert;
37 | import org.junit.Before;
38 | import org.junit.Test;
39 | import org.mockito.InOrder;
40 | import org.mockito.Mock;
41 | import org.mockito.MockitoAnnotations;
42 |
43 | /** Tests for CommandExecutor */
44 | public class CommandExecutorTest {
45 | @Mock private CommandExecutor.ProcessBuilderFactory processBuilderFactoryMock;
46 |
47 | @Mock private ProcessBuilder processBuilderMock;
48 |
49 | @Mock private Process processMock;
50 |
51 | @Mock private Logger loggerMock;
52 |
53 | private InOrder loggerInOrder;
54 |
55 | @Before
56 | public void setup() throws IOException {
57 | MockitoAnnotations.initMocks(this);
58 |
59 | when(processBuilderFactoryMock.createProcessBuilder()).thenReturn(processBuilderMock);
60 | when(processBuilderMock.start()).thenReturn(processMock);
61 | loggerInOrder = inOrder(loggerMock);
62 | }
63 |
64 | @Test
65 | public void testRunCommand_success() throws IOException, InterruptedException {
66 | List command = Arrays.asList("someCommand", "someOption");
67 | List expectedOutput = Arrays.asList("some output line 1", "some output line 2");
68 |
69 | // Has the mocked process output the expected output.
70 | setProcessMockOutput(expectedOutput);
71 |
72 | // Executes the command.
73 | List output =
74 | new CommandExecutor().setProcessBuilderFactory(processBuilderFactoryMock).run(command);
75 |
76 | // Verifies the process building and output reading is correct.
77 | verifyProcessBuilding(command);
78 | Assert.assertEquals(expectedOutput, output);
79 |
80 | verifyZeroInteractions(loggerMock);
81 | }
82 |
83 | @Test
84 | public void testRunCommandWithEnvironmentVariables() throws IOException, InterruptedException {
85 | List environmentStrings =
86 | Arrays.asList("SOME_VARIABLE_1=SOME_VALUE_1", "SOME_VARIABLE_2=SOME_VALUE_2");
87 | List command = Arrays.asList("someCommand", "someOption");
88 | List expectedOutput = Arrays.asList("some output line 1", "some output line 2");
89 |
90 | // Converts the environment into key-value pairs.
91 | Map expectedEnvironment = MinikubeDockerEnvParser.parse(environmentStrings);
92 |
93 | // Mocks the environment for the processBuilderMock to put the environment map in.
94 | Map processEnvironment = new HashMap<>();
95 | when(processBuilderMock.environment()).thenReturn(processEnvironment);
96 |
97 | setProcessMockOutput(expectedOutput);
98 |
99 | List output =
100 | new CommandExecutor()
101 | .setEnvironment(expectedEnvironment)
102 | .setProcessBuilderFactory(processBuilderFactoryMock)
103 | .run(command);
104 |
105 | verifyProcessBuilding(command);
106 | verify(processBuilderMock).environment();
107 | Assert.assertEquals(expectedEnvironment, processEnvironment);
108 | Assert.assertEquals(expectedOutput, output);
109 |
110 | verifyZeroInteractions(loggerMock);
111 | }
112 |
113 | @Test
114 | public void testRunCommandWithLogging_success() throws IOException, InterruptedException {
115 | List command = Arrays.asList("someCommand", "someOption");
116 | List expectedOutput = Arrays.asList("some output line 1", "some output line 2");
117 |
118 | setProcessMockOutput(expectedOutput);
119 |
120 | List output =
121 | new CommandExecutor()
122 | .setLogger(loggerMock)
123 | .setProcessBuilderFactory(processBuilderFactoryMock)
124 | .run(command);
125 |
126 | verifyProcessBuilding(command);
127 | Assert.assertEquals(expectedOutput, output);
128 |
129 | // Verifies the logger messages were logged.
130 | loggerInOrder.verify(loggerMock).debug("Running command : someCommand someOption");
131 | loggerInOrder.verify(loggerMock).info("some output line 1");
132 | loggerInOrder.verify(loggerMock).info("some output line 2");
133 | }
134 |
135 | @Test
136 | public void testRunCommandWithLogging_badProcessOutput()
137 | throws IOException, InterruptedException {
138 | List command = Arrays.asList("someCommand", "someOption");
139 |
140 | InputStream processOutput = new StringInputStream("");
141 | processOutput.close();
142 | when(processMock.getInputStream()).thenReturn(processOutput);
143 |
144 | new CommandExecutor()
145 | .setLogger(loggerMock)
146 | .setProcessBuilderFactory(processBuilderFactoryMock)
147 | .run(command);
148 |
149 | loggerInOrder.verify(loggerMock).warn("IO Exception reading process output");
150 | }
151 |
152 | @Test
153 | public void testRunCommand_commandError() throws IOException, InterruptedException {
154 | List command = Arrays.asList("someCommand", "someOption");
155 | List expectedOutput = Arrays.asList("some output line 1", "some output line 2");
156 |
157 | setProcessMockOutput(expectedOutput);
158 | when(processMock.waitFor()).thenReturn(1);
159 |
160 | try {
161 | new CommandExecutor().setProcessBuilderFactory(processBuilderFactoryMock).run(command);
162 | Assert.fail("Expected a GradleException to be thrown");
163 | } catch (GradleException ex) {
164 | Assert.assertEquals("command exited with non-zero exit code : 1", ex.getMessage());
165 |
166 | verifyProcessBuilding(command);
167 | verifyZeroInteractions(loggerMock);
168 | }
169 | }
170 |
171 | @Test
172 | public void testRunCommandWithLogging_commandTimeout() throws IOException, InterruptedException {
173 | List command = Arrays.asList("someCommand", "someOption");
174 |
175 | // Mocks the ExecutorService to be interrupted when awaiting termination.
176 | CommandExecutor.ExecutorServiceFactory executorServiceFactoryMock =
177 | mock(CommandExecutor.ExecutorServiceFactory.class);
178 | ExecutorService executorServiceMock = mock(ExecutorService.class);
179 | when(executorServiceFactoryMock.createExecutorService()).thenReturn(executorServiceMock);
180 | when(executorServiceMock.awaitTermination(CommandExecutor.TIMEOUT_SECONDS, TimeUnit.SECONDS))
181 | .thenThrow(new InterruptedException());
182 |
183 | new CommandExecutor()
184 | .setLogger(loggerMock)
185 | .setProcessBuilderFactory(processBuilderFactoryMock)
186 | .setExecutorServiceFactory(executorServiceFactoryMock)
187 | .run(command);
188 |
189 | loggerInOrder.verify(loggerMock).debug("Running command : someCommand someOption");
190 | loggerInOrder
191 | .verify(loggerMock)
192 | .debug("Task Executor interrupted waiting for output consumer thread");
193 | }
194 |
195 | private void setProcessMockOutput(List expectedOutput) {
196 | when(processMock.getInputStream())
197 | .thenReturn(new StringInputStream(String.join("\n", expectedOutput)));
198 | }
199 |
200 | private void verifyProcessBuilding(List command) throws IOException {
201 | verify(processBuilderMock).command(command);
202 | verify(processBuilderMock).redirectErrorStream(true);
203 | verify(processBuilderMock).start();
204 |
205 | verify(processMock).getInputStream();
206 | }
207 | }
208 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/src/test/java/com/google/cloud/tools/minikube/util/MinikubeDockerEnvParserTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.util;
18 |
19 | import java.util.Arrays;
20 | import java.util.HashMap;
21 | import java.util.List;
22 | import java.util.Map;
23 | import org.junit.Assert;
24 | import org.junit.Test;
25 |
26 | /** Tests for {@code MinikubeDockerEnvParser} */
27 | public class MinikubeDockerEnvParserTest {
28 |
29 | @Test
30 | public void testParse_success() {
31 | List keyValueStrings =
32 | Arrays.asList(
33 | "SOME_VARIABLE_1=SOME_VALUE_1", "SOME_VARIABLE_2=SOME_VALUE_2", "SOME_VARIABLE_3=");
34 | Map expectedEnvironment = new HashMap<>();
35 | expectedEnvironment.put("SOME_VARIABLE_1", "SOME_VALUE_1");
36 | expectedEnvironment.put("SOME_VARIABLE_2", "SOME_VALUE_2");
37 | expectedEnvironment.put("SOME_VARIABLE_3", "");
38 |
39 | Map environment = MinikubeDockerEnvParser.parse(keyValueStrings);
40 |
41 | Assert.assertEquals(expectedEnvironment, environment);
42 | }
43 |
44 | @Test
45 | public void testParse_variableNameEmpty() {
46 | List keyValueStrings =
47 | Arrays.asList("SOME_VARIABLE_1=SOME_VALUE_1", "=SOME_VALUE_2", "SOME_VARIABLE_3=");
48 |
49 | try {
50 | MinikubeDockerEnvParser.parse(keyValueStrings);
51 | Assert.fail("Expected an IllegalArgumentException to be thrown");
52 | } catch (IllegalArgumentException ex) {
53 | Assert.assertEquals(
54 | "Error while parsing minikube's Docker environment: encountered empty environment variable name",
55 | ex.getMessage());
56 | }
57 | }
58 |
59 | @Test
60 | public void testParse_invalidFormat() {
61 | List keyValueStrings =
62 | Arrays.asList("SOME_VARIABLE_1=SOME_VALUE_1", "SOME_VARIABLE_2", "SOME_VARIABLE_3=");
63 |
64 | try {
65 | MinikubeDockerEnvParser.parse(keyValueStrings);
66 | Assert.fail("Expected an IllegalArgumentException to be thrown");
67 | } catch (IllegalArgumentException ex) {
68 | Assert.assertEquals(
69 | "Error while parsing minikube's Docker environment: environment variable string not in KEY=VALUE format",
70 | ex.getMessage());
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/minikube-gradle-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker:
--------------------------------------------------------------------------------
1 | mock-maker-inline
2 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 | target
3 | out
4 | *.iml
5 | *.ipr
6 | *.iws
7 | .idea
8 | .gradle
9 | /.settings
10 | /.classpath
11 | /.project
12 | log.txt
13 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogleContainerTools/minikube-build-tools-for-java/120fe65eca3cb99219e3a099869f80e7848356ae/minikube-maven-plugin/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/minikube-maven-plugin/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
--------------------------------------------------------------------------------
/minikube-maven-plugin/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 | All notable changes to this project will be documented in this file.
3 | ## [unreleased]
4 |
5 | ### Added
6 |
7 | ### Changed
8 |
9 | ### Fixed
10 |
11 | ## 1.0.0
12 | ### Added
13 | - Adds minikube `start`, `stop`, and `delete` goals.
14 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/README.md:
--------------------------------------------------------------------------------
1 | | ⛔⛔⛔ DEPRECATED ⛔⛔⛔ |
2 | | :----- |
3 | | These plugins are not maintained, no more updates or releases will be made. Users may fork and update this project on their own. |
4 |
5 | [](https://maven-badges.herokuapp.com/maven-central/com.google.cloud.tools/minikube-maven-plugin)
6 |
7 | Minikube Maven Plugin
8 | ======================
9 | This plugin provides tasks and configuration to manage a minikube lifecycle for Maven developers.
10 |
11 | Now available on the [Central repository](https://maven-badges.herokuapp.com/maven-central/com.google.cloud.tools/minikube-maven-plugin).
12 |
13 | This plugin requires that you have Minikube [installed](https://kubernetes.io/docs/tasks/tools/install-minikube/).
14 |
15 | In your Maven Java project, add the plugin to your `pom.xml`:
16 |
17 | ```xml
18 |
19 | com.google.cloud.tools
20 | minikube-maven-plugin
21 | 1.0.0-alpha.1
22 |
23 | ```
24 |
25 | It exposes the following goals:
26 |
27 | - `minikube:start` : Starts a local kubernetes cluster
28 | - `minikube:stop` : Stops a local kubernetes cluster
29 | - `minikube:delete` : Deletes a local kubernetes cluster
30 |
31 | Configure additional plugin options:
32 |
33 | Field | Default | Description
34 | --- | --- | ---
35 | `minikube`|`minikube`|Path to minikube executable
36 | `flags`|*None*|Flags to pass to minikube
37 | `start`|*None*|Configuration for `start` goal
38 | `stop`|*None*|Configuration for `start` goal
39 | `delete`|*None*|Configuration for `delete` goal
40 |
41 | Example configuration:
42 |
43 | ```xml
44 |
45 | ...
46 |
47 | /path/to/minikube
48 |
49 | flags to pass to minikube
50 |
51 |
52 |
53 | flags for the start task
54 |
55 |
56 |
57 |
58 | flags for the stop task
59 |
60 |
61 |
62 |
63 | flags for the delete task
64 |
65 |
66 |
67 |
68 | ```
69 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/config/checkstyle-header.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/config/copyright.header:
--------------------------------------------------------------------------------
1 | ^/\*$
2 | ^ \* Copyright 2018 Google Inc\.$
3 | ^ \*$
4 | ^ \* Licensed under the Apache License, Version 2\.0 \(the "License"\); you may not$
5 | ^ \* use this file except in compliance with the License\. You may obtain a copy of$
6 | ^ \* 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, WITHOUT$
12 | ^ \* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\. See the$
13 | ^ \* License for the specific language governing permissions and limitations under$
14 | ^ \* the License\.$
15 | ^ \*/$
16 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/config/google-checks-no-indent.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
71 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
115 |
116 |
117 |
119 |
120 |
121 |
122 |
124 |
125 |
126 |
127 |
129 |
130 |
131 |
132 |
134 |
135 |
136 |
137 |
138 |
140 |
141 |
142 |
143 |
145 |
146 |
147 |
148 |
150 |
151 |
152 |
153 |
155 |
156 |
157 |
158 |
160 |
162 |
164 |
166 |
167 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/kokoro/release_build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Fail on any error.
4 | set -e
5 | # Display commands to stderr.
6 | set -x
7 |
8 | cd github/minikube-build-tools-for-java/minikube-maven-plugin
9 | ./mvnw -Prelease -B -U verify
10 |
11 | # copy pom with the name expected in the Maven repository
12 | ARTIFACT_ID=$(mvn -B help:evaluate -Dexpression=project.artifactId 2>/dev/null | grep -v "^\[")
13 | PROJECT_VERSION=$(mvn -B help:evaluate -Dexpression=project.version 2>/dev/null| grep -v "^\[")
14 | cp pom.xml target/${ARTIFACT_ID}-${PROJECT_VERSION}.pom
15 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.google.cloud.tools
5 | minikube-maven-plugin
6 | 1.0.0-SNAPSHOT
7 | maven-plugin
8 |
9 | Minikube Maven Plugin
10 | Minikube lifecycle management
11 | https://github.com/GoogleCloudPlatform/minikube-build-tools-for-java/minikube-maven-plugin
12 |
13 |
14 |
15 | The Apache License, Version 2.0
16 | http://www.apache.org/licenses/LICENSE-2.0.txt
17 |
18 |
19 |
20 |
21 |
22 | coollog
23 | Qingyang Chen
24 | qingyangc@google.com
25 |
26 |
27 | loosebazooka
28 | Appu Goundan
29 | appu@google.com
30 |
31 |
32 |
33 |
34 | scm:git:https://github.com/GoogleCloudPlatform/minikube-build-tools-for-java.git
35 |
36 | scm:git:https://github.com/GoogleCloudPlatform/minikube-build-tools-for-java.git
37 |
38 | https://github.com/GoogleCloudPlatform/minikube-build-tools-for-java
39 |
40 |
41 |
42 | UTF-8
43 | 1.8
44 | 1.8
45 |
46 |
47 |
48 |
49 | org.apache.maven
50 | maven-plugin-api
51 | 3.5.2
52 |
53 |
54 |
55 | org.apache.maven
56 | maven-core
57 | 3.5.2
58 |
59 |
60 | org.apache.maven.shared
61 | maven-verifier
62 | 1.6
63 |
64 |
65 |
66 | com.google.guava
67 | guava
68 | 23.5-jre
69 | compile
70 |
71 |
72 |
73 |
74 | org.apache.maven.plugin-tools
75 | maven-plugin-annotations
76 | 3.5.1
77 | provided
78 |
79 |
80 |
81 | junit
82 | junit
83 | 4.13.1
84 | test
85 |
86 |
87 | org.mockito
88 | mockito-core
89 | 2.15.0
90 | test
91 |
92 |
93 |
94 |
95 |
96 |
97 | org.apache.maven.plugins
98 | maven-plugin-plugin
99 | 3.5.1
100 |
101 |
102 |
103 |
104 | org.apache.maven.plugins
105 | maven-surefire-plugin
106 | 2.20.1
107 |
108 |
109 |
110 |
111 | com.coveo
112 | fmt-maven-plugin
113 | 2.1.0
114 |
115 |
116 | com.google.googlejavaformat
117 | google-java-format
118 | 1.5
119 |
120 |
121 |
122 |
123 | default-cli
124 | validate
125 |
126 | format
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 | maven-checkstyle-plugin
135 | 2.17
136 |
137 |
138 | com.puppycrawl.tools
139 | checkstyle
140 | 8.18
141 |
142 |
143 |
144 | false
145 | true
146 | warning
147 | ${project.build.sourceDirectory}
148 |
149 |
150 |
151 | google-checks
152 | validate
153 |
154 | check
155 |
156 |
157 | config/google-checks-no-indent.xml
158 |
159 |
160 |
161 | header-check
162 | validate
163 |
164 | check
165 |
166 |
167 | config/checkstyle-header.xml
168 | config/header-java.txt
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/scripts/prepare_release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -
2 | # Usage: ./prepare_release.sh
3 |
4 | set -e
5 |
6 | Colorize() {
7 | echo "$(tput setff $2)$1$(tput sgr0)"
8 | }
9 |
10 | EchoRed() {
11 | echo "$(tput setaf 1; tput bold)$1$(tput sgr0)"
12 | }
13 | EchoGreen() {
14 | echo "$(tput setaf 2; tput bold)$1$(tput sgr0)"
15 | }
16 |
17 | Die() {
18 | EchoRed "$1"
19 | exit 1
20 | }
21 |
22 | DieUsage() {
23 | Die "Usage: ./prepare_release.sh "
24 | }
25 |
26 | # Usage: CheckVersion
27 | CheckVersion() {
28 | [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+)?$ ]] || Die "Version not in ###.###.###(-alpha.###) format."
29 | }
30 |
31 | # Usage: HasSuffix
32 | HasSuffix() {
33 | $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+-alpha\.[0-9]+$
34 | }
35 |
36 | # Usage: StripSuffix
37 | StripSuffix() {
38 | echo $1 | sed 's/\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/'
39 | }
40 |
41 | # Usage: IncrementVersion
42 | IncrementVersion() {
43 | local version=$1
44 | local minorVersion=$(echo $version | sed 's/[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\)/\1/')
45 | local nextMinorVersion=$((minorVersion+1))
46 | echo $version | sed "s/\([0-9][0-9]*\.[0-9][0-9]*\)\.[0-9][0-9]*/\1.$nextMinorVersion/"
47 | }
48 |
49 | [ $# -ne 2 ] || DieUsage
50 |
51 | EchoGreen '===== RELEASE SETUP SCRIPT ====='
52 |
53 | VERSION=$1
54 | CheckVersion ${VERSION}
55 |
56 | if [[ $(HasSuffix $VERSION) ]]; then
57 | NEXT_VERSION=$(IncrementVersion $VERSION)
58 | else
59 | NEXT_VERSION=$(StripSuffix $VERSION)
60 | fi
61 | CheckVersion ${NEXT_VERSION}
62 |
63 | if [[ $(git status -uno --porcelain) ]]; then
64 | Die 'There are uncommitted changes.'
65 | fi
66 |
67 | # Checks out a new branch for this version release (eg. 1.5.7).
68 | git checkout -b ${VERSION}
69 |
70 | # Updates the pom.xml with the version to release.
71 | mvn versions:set versions:commit -DnewVersion=${VERSION}
72 |
73 | # Tags a new commit for this release.
74 | git commit -am "preparing release ${VERSION}"
75 | git tag v${VERSION}-maven
76 |
77 | # Updates the pom.xml with the next snapshot version.
78 | # For example, when releasing 1.5.7, the next snapshot version would be 1.5.8-SNAPSHOT.
79 | NEXT_SNAPSHOT=${NEXT_VERSION}-SNAPSHOT
80 | mvn versions:set versions:commit -DnewVersion=${NEXT_SNAPSHOT}
81 |
82 | # Commits the next snapshot version.
83 | git commit -am "${NEXT_SNAPSHOT}"
84 |
85 | # Pushes the tag and release branch to Github.
86 | git push origin v${VERSION}-maven
87 | git push origin ${VERSION}
88 |
89 | # File a PR on Github for the new branch. Have someone LGTM it, which gives you permission to continue.
90 | EchoGreen 'File a PR for the new release branch:'
91 | echo https://github.com/GoogleCloudPlatform/minikube-build-tools-for-java/compare/${VERSION}
92 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/main/java/com/google/cloud/tools/minikube/command/BuildLogger.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.command;
18 |
19 | // TODO: Share this with minikube-gradle-plugin.
20 | /** Implementations should be use build system-specific logging mechanisms. */
21 | public interface BuildLogger {
22 |
23 | void lifecycle(CharSequence message);
24 |
25 | void info(CharSequence message);
26 |
27 | void debug(CharSequence message);
28 |
29 | void warn(CharSequence message);
30 |
31 | void error(CharSequence message);
32 | }
33 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/main/java/com/google/cloud/tools/minikube/command/CommandExecutor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.command;
18 |
19 | import com.google.common.annotations.VisibleForTesting;
20 | import java.io.BufferedReader;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import java.io.InputStreamReader;
24 | import java.nio.charset.StandardCharsets;
25 | import java.util.ArrayList;
26 | import java.util.Arrays;
27 | import java.util.List;
28 | import java.util.Map;
29 | import java.util.concurrent.ExecutorService;
30 | import java.util.concurrent.Executors;
31 | import java.util.concurrent.TimeUnit;
32 | import java.util.function.Supplier;
33 |
34 | // TODO: Share this with minikube-gradle-plugin.
35 | /** Executes a shell command. */
36 | public class CommandExecutor {
37 |
38 | @VisibleForTesting static final int TIMEOUT_SECONDS = 5;
39 |
40 | private Supplier processBuilderSupplier = ProcessBuilder::new;
41 | private Supplier executorServiceSupplier = Executors::newSingleThreadExecutor;
42 | private BuildLogger logger;
43 | private Map environment;
44 |
45 | /** Sets the {@code BuildLogger} to use to log messages during the command execution. */
46 | public CommandExecutor setLogger(BuildLogger logger) {
47 | this.logger = logger;
48 | return this;
49 | }
50 |
51 | /** Sets the environment variables to run the command with. */
52 | public CommandExecutor setEnvironment(Map environmentMap) {
53 | this.environment = environmentMap;
54 | return this;
55 | }
56 |
57 | @VisibleForTesting
58 | CommandExecutor setProcessBuilderSupplier(Supplier processBuilderSupplier) {
59 | this.processBuilderSupplier = processBuilderSupplier;
60 | return this;
61 | }
62 |
63 | @VisibleForTesting
64 | CommandExecutor setExecutorServiceSupplier(Supplier executorServiceSupplier) {
65 | this.executorServiceSupplier = executorServiceSupplier;
66 | return this;
67 | }
68 |
69 | /** Runs the command. Same as {@link #run(List)}. */
70 | public List run(String... command) throws IOException, InterruptedException {
71 | return run(Arrays.asList(command));
72 | }
73 |
74 | /**
75 | * Runs the command.
76 | *
77 | * @param command the list of command line tokens
78 | * @return the output of the command as a list of lines
79 | * @throws IOException if the command failed to run or exited with non-zero exit code
80 | */
81 | public List run(List command) throws IOException, InterruptedException {
82 | if (logger != null) {
83 | logger.debug("Running command : " + String.join(" ", command));
84 | }
85 |
86 | ExecutorService executor = executorServiceSupplier.get();
87 |
88 | // Builds the command to execute.
89 | ProcessBuilder processBuilder = processBuilderSupplier.get();
90 | processBuilder.command(command);
91 | processBuilder.redirectErrorStream(true);
92 | if (environment != null) {
93 | processBuilder.environment().putAll(environment);
94 | }
95 | Process process = processBuilder.start();
96 |
97 | // Runs the command and streams the output.
98 | List output = new ArrayList<>();
99 | executor.execute(makeOutputConsumerRunnable(process, output));
100 | int exitCode = process.waitFor();
101 |
102 | // Shuts down the executor.
103 | executor.shutdown();
104 |
105 | try {
106 | executor.awaitTermination(TIMEOUT_SECONDS, TimeUnit.SECONDS);
107 | } catch (InterruptedException ex) {
108 | if (logger != null) {
109 | logger.debug("Task Executor interrupted waiting for output consumer thread");
110 | }
111 | }
112 |
113 | // Checks the command exit code.
114 | if (exitCode != 0) {
115 | throw new IOException("command exited with non-zero exit code : " + exitCode);
116 | }
117 |
118 | return output;
119 | }
120 |
121 | /**
122 | * Creates a {@link Runnable} to read the command output.
123 | *
124 | * @param process the process to read from
125 | * @param output a list to store the output lines to
126 | */
127 | private Runnable makeOutputConsumerRunnable(Process process, List output) {
128 | return () -> {
129 | try (InputStream processInputStream = process.getInputStream();
130 | InputStreamReader inputStreamReader =
131 | new InputStreamReader(processInputStream, StandardCharsets.UTF_8);
132 | BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
133 | String line = bufferedReader.readLine();
134 | while (line != null) {
135 | if (logger != null) {
136 | logger.lifecycle(line);
137 | }
138 | output.add(line);
139 | line = bufferedReader.readLine();
140 | }
141 |
142 | } catch (IOException ex) {
143 | if (logger != null) {
144 | logger.warn("IO Exception reading process output");
145 | }
146 | }
147 | };
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/main/java/com/google/cloud/tools/minikube/maven/AbstractMinikubeMojo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.maven;
18 |
19 | import com.google.cloud.tools.minikube.command.CommandExecutor;
20 | import com.google.common.annotations.VisibleForTesting;
21 | import com.google.common.collect.ImmutableList;
22 | import java.io.IOException;
23 | import java.util.ArrayList;
24 | import java.util.List;
25 | import java.util.function.Supplier;
26 | import org.apache.maven.plugin.AbstractMojo;
27 | import org.apache.maven.plugin.MojoExecutionException;
28 | import org.apache.maven.plugins.annotations.Parameter;
29 |
30 | abstract class AbstractMinikubeMojo extends AbstractMojo {
31 |
32 | /** Path to minikube executable. */
33 | @Parameter(defaultValue = "minikube", required = true)
34 | private String minikube;
35 |
36 | /** Common flags to add when calling minikube. */
37 | @Parameter private List flags;
38 |
39 | private Supplier commandExecutorSupplier = CommandExecutor::new;
40 | private MavenBuildLogger mavenBuildLogger = new MavenBuildLogger(getLog());
41 |
42 | @Override
43 | public void execute() throws MojoExecutionException {
44 | List minikubeCommand = buildMinikubeCommand();
45 |
46 | try {
47 | commandExecutorSupplier.get().setLogger(mavenBuildLogger).run(minikubeCommand);
48 |
49 | } catch (InterruptedException | IOException ex) {
50 | throw new MojoExecutionException(getDescription() + " failed", ex);
51 | }
52 | }
53 |
54 | @VisibleForTesting
55 | void setMinikube(String minikube) {
56 | this.minikube = minikube;
57 | }
58 |
59 | @VisibleForTesting
60 | void setFlags(ImmutableList flags) {
61 | this.flags = flags;
62 | }
63 |
64 | @VisibleForTesting
65 | void setMavenBuildLogger(MavenBuildLogger mavenBuildLogger) {
66 | this.mavenBuildLogger = mavenBuildLogger;
67 | }
68 |
69 | @VisibleForTesting
70 | void setCommandExecutorSupplier(Supplier commandExecutorSupplier) {
71 | this.commandExecutorSupplier = commandExecutorSupplier;
72 | }
73 |
74 | /** @return what this goal does */
75 | abstract String getDescription();
76 |
77 | /** @return the minikube command this goal runs */
78 | abstract String getCommand();
79 |
80 | /** @return command-specific flags */
81 | abstract ImmutableList getMoreFlags();
82 |
83 | @VisibleForTesting
84 | List buildMinikubeCommand() {
85 | List execString = new ArrayList<>();
86 | execString.add(minikube);
87 | execString.add(getCommand());
88 | if (flags != null) {
89 | execString.addAll(flags);
90 | }
91 | execString.addAll(getMoreFlags());
92 |
93 | return execString;
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/main/java/com/google/cloud/tools/minikube/maven/CommandConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.maven;
18 |
19 | import com.google.common.collect.ImmutableList;
20 | import java.util.List;
21 | import javax.annotation.Nullable;
22 |
23 | /** Additional Maven configuration for commands. */
24 | public class CommandConfiguration {
25 |
26 | /** Additional flags to pass to the command. */
27 | @Nullable private List flags;
28 |
29 | ImmutableList getFlags() {
30 | if (flags == null) {
31 | return ImmutableList.of();
32 | }
33 | return ImmutableList.copyOf(flags);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/main/java/com/google/cloud/tools/minikube/maven/DeleteMojo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.maven;
18 |
19 | import com.google.common.collect.ImmutableList;
20 | import org.apache.maven.plugins.annotations.Mojo;
21 | import org.apache.maven.plugins.annotations.Parameter;
22 |
23 | @Mojo(name = "delete")
24 | class DeleteMojo extends AbstractMinikubeMojo {
25 |
26 | @Parameter private CommandConfiguration delete;
27 |
28 | @Override
29 | String getDescription() {
30 | return "Deleting minikube cluster";
31 | }
32 |
33 | @Override
34 | String getCommand() {
35 | return "delete";
36 | }
37 |
38 | @Override
39 | ImmutableList getMoreFlags() {
40 | if (delete == null) {
41 | return ImmutableList.of();
42 | }
43 | return delete.getFlags();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/main/java/com/google/cloud/tools/minikube/maven/MavenBuildLogger.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.maven;
18 |
19 | import com.google.cloud.tools.minikube.command.BuildLogger;
20 | import org.apache.maven.plugin.logging.Log;
21 |
22 | class MavenBuildLogger implements BuildLogger {
23 |
24 | private final Log log;
25 |
26 | MavenBuildLogger(Log log) {
27 | this.log = log;
28 | }
29 |
30 | @Override
31 | public void lifecycle(CharSequence message) {
32 | log.info("[LIFECYCLE] " + message);
33 | }
34 |
35 | @Override
36 | public void info(CharSequence message) {
37 | log.info(message);
38 | }
39 |
40 | @Override
41 | public void debug(CharSequence message) {
42 | log.debug(message);
43 | }
44 |
45 | @Override
46 | public void warn(CharSequence message) {
47 | log.warn(message);
48 | }
49 |
50 | @Override
51 | public void error(CharSequence message) {
52 | log.error(message);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/main/java/com/google/cloud/tools/minikube/maven/StartMojo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.maven;
18 |
19 | import com.google.common.collect.ImmutableList;
20 | import javax.annotation.Nullable;
21 | import org.apache.maven.plugins.annotations.Mojo;
22 | import org.apache.maven.plugins.annotations.Parameter;
23 |
24 | @Mojo(name = "start")
25 | class StartMojo extends AbstractMinikubeMojo {
26 |
27 | @Parameter @Nullable private CommandConfiguration start;
28 |
29 | @Override
30 | String getDescription() {
31 | return "Starting minikube cluster";
32 | }
33 |
34 | @Override
35 | String getCommand() {
36 | return "start";
37 | }
38 |
39 | @Override
40 | ImmutableList getMoreFlags() {
41 | if (start == null) {
42 | return ImmutableList.of();
43 | }
44 | return start.getFlags();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/main/java/com/google/cloud/tools/minikube/maven/StopMojo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.maven;
18 |
19 | import com.google.common.collect.ImmutableList;
20 | import org.apache.maven.plugins.annotations.Mojo;
21 | import org.apache.maven.plugins.annotations.Parameter;
22 |
23 | @Mojo(name = "stop")
24 | class StopMojo extends AbstractMinikubeMojo {
25 |
26 | @Parameter private CommandConfiguration stop;
27 |
28 | @Override
29 | String getDescription() {
30 | return "Stopping minikube cluster";
31 | }
32 |
33 | @Override
34 | String getCommand() {
35 | return "stop";
36 | }
37 |
38 | @Override
39 | ImmutableList getMoreFlags() {
40 | if (stop == null) {
41 | return ImmutableList.of();
42 | }
43 | return stop.getFlags();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/test/java/com/google/cloud/tools/minikube/command/CommandExecutorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.command;
18 |
19 | import com.google.common.collect.ImmutableMap;
20 | import java.io.ByteArrayInputStream;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import java.nio.charset.StandardCharsets;
24 | import java.util.Arrays;
25 | import java.util.HashMap;
26 | import java.util.List;
27 | import java.util.Map;
28 | import java.util.concurrent.ExecutorService;
29 | import java.util.concurrent.TimeUnit;
30 | import org.junit.Assert;
31 | import org.junit.Before;
32 | import org.junit.Test;
33 | import org.junit.runner.RunWith;
34 | import org.mockito.InOrder;
35 | import org.mockito.Mock;
36 | import org.mockito.Mockito;
37 | import org.mockito.junit.MockitoJUnitRunner;
38 |
39 | /** Tests for {@link CommandExecutor}. */
40 | @RunWith(MockitoJUnitRunner.class)
41 | public class CommandExecutorTest {
42 |
43 | private final List command = Arrays.asList("someCommand", "someOption");
44 | private final List expectedOutput =
45 | Arrays.asList("some output line 1", "some output line 2");
46 |
47 | @Mock private ProcessBuilder mockProcessBuilder;
48 | @Mock private Process mockProcess;
49 | @Mock private BuildLogger mockBuildLogger;
50 |
51 | private CommandExecutor testCommandExecutor;
52 | private InOrder loggerInOrder;
53 |
54 | @Before
55 | public void setUp() throws IOException {
56 | Mockito.when(mockProcessBuilder.start()).thenReturn(mockProcess);
57 |
58 | testCommandExecutor = new CommandExecutor().setProcessBuilderSupplier(() -> mockProcessBuilder);
59 |
60 | loggerInOrder = Mockito.inOrder(mockBuildLogger);
61 | }
62 |
63 | @Test
64 | public void testRun_success() throws IOException, InterruptedException {
65 | setMockProcessOutput(expectedOutput);
66 |
67 | // Executes the command.
68 | List output = testCommandExecutor.run(command);
69 |
70 | verifyProcessBuilding(command);
71 | Assert.assertEquals(expectedOutput, output);
72 |
73 | Mockito.verifyZeroInteractions(mockBuildLogger);
74 | }
75 |
76 | @Test
77 | public void testRun_withEnvironmentVariables() throws IOException, InterruptedException {
78 | Map expectedEnvironmentMap =
79 | ImmutableMap.of("SOME_VARIABLE_1", "SOME_VALUE_1", "SOME_VARIABLE_2", "SOME_VALUE_2");
80 |
81 | Map processBuilderEnvironmentMap = new HashMap<>();
82 | Mockito.when(mockProcessBuilder.environment()).thenReturn(processBuilderEnvironmentMap);
83 |
84 | setMockProcessOutput(expectedOutput);
85 |
86 | List output = testCommandExecutor.setEnvironment(expectedEnvironmentMap).run(command);
87 |
88 | verifyProcessBuilding(command);
89 | Assert.assertEquals(expectedEnvironmentMap, processBuilderEnvironmentMap);
90 | Assert.assertEquals(expectedOutput, output);
91 |
92 | Mockito.verifyZeroInteractions(mockBuildLogger);
93 | }
94 |
95 | @Test
96 | public void testRun_withLogging_success() throws IOException, InterruptedException {
97 | setMockProcessOutput(expectedOutput);
98 |
99 | List output = testCommandExecutor.setLogger(mockBuildLogger).run(command);
100 |
101 | verifyProcessBuilding(command);
102 | Assert.assertEquals(expectedOutput, output);
103 |
104 | // Verifies the logger messages were logged.
105 | loggerInOrder.verify(mockBuildLogger).debug("Running command : someCommand someOption");
106 | loggerInOrder.verify(mockBuildLogger).lifecycle("some output line 1");
107 | loggerInOrder.verify(mockBuildLogger).lifecycle("some output line 2");
108 | }
109 |
110 | @Test
111 | public void testRun_withLogging_badProcessOutput() throws IOException, InterruptedException {
112 | InputStream errorInputStream =
113 | new InputStream() {
114 |
115 | @Override
116 | public int read() throws IOException {
117 | throw new IOException();
118 | }
119 | };
120 | Mockito.when(mockProcess.getInputStream()).thenReturn(errorInputStream);
121 |
122 | testCommandExecutor.setLogger(mockBuildLogger).run(command);
123 |
124 | loggerInOrder.verify(mockBuildLogger).debug("Running command : someCommand someOption");
125 | loggerInOrder.verify(mockBuildLogger).warn("IO Exception reading process output");
126 | }
127 |
128 | @Test
129 | public void testRun_withLogging_commandTimeout() throws InterruptedException, IOException {
130 | // Mocks the ExecutorService to be interrupted when awaiting termination.
131 | ExecutorService mockExecutorService = Mockito.mock(ExecutorService.class);
132 | Mockito.when(
133 | mockExecutorService.awaitTermination(CommandExecutor.TIMEOUT_SECONDS, TimeUnit.SECONDS))
134 | .thenThrow(new InterruptedException());
135 |
136 | testCommandExecutor
137 | .setExecutorServiceSupplier(() -> mockExecutorService)
138 | .setLogger(mockBuildLogger)
139 | .run(command);
140 |
141 | loggerInOrder.verify(mockBuildLogger).debug("Running command : someCommand someOption");
142 | loggerInOrder
143 | .verify(mockBuildLogger)
144 | .debug("Task Executor interrupted waiting for output consumer thread");
145 | }
146 |
147 | @Test
148 | public void testRun_commandError() throws InterruptedException, IOException {
149 | setMockProcessOutput(expectedOutput);
150 |
151 | Mockito.when(mockProcess.waitFor()).thenReturn(1);
152 |
153 | try {
154 | testCommandExecutor.run(command);
155 | Assert.fail("Expected an IOException to be thrown");
156 |
157 | } catch (IOException ex) {
158 | Assert.assertEquals("command exited with non-zero exit code : 1", ex.getMessage());
159 |
160 | verifyProcessBuilding(command);
161 | Mockito.verifyZeroInteractions(mockBuildLogger);
162 | }
163 | }
164 |
165 | /** Has the mocked process output the expected output. */
166 | private void setMockProcessOutput(List expectedOutput) {
167 | Mockito.when(mockProcess.getInputStream())
168 | .thenReturn(
169 | new ByteArrayInputStream(
170 | String.join("\n", expectedOutput).getBytes(StandardCharsets.UTF_8)));
171 | }
172 |
173 | /** Verifies that the process building and output reading is correct. */
174 | private void verifyProcessBuilding(List command) throws IOException {
175 | Mockito.verify(mockProcessBuilder).command(command);
176 | Mockito.verify(mockProcessBuilder).redirectErrorStream(true);
177 | Mockito.verify(mockProcessBuilder).start();
178 |
179 | Mockito.verify(mockProcess).getInputStream();
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/test/java/com/google/cloud/tools/minikube/maven/AbstractMinikubeMojoTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.maven;
18 |
19 | import com.google.cloud.tools.minikube.command.CommandExecutor;
20 | import com.google.common.collect.ImmutableList;
21 | import java.io.IOException;
22 | import java.util.Arrays;
23 | import java.util.List;
24 | import org.apache.maven.plugin.MojoExecutionException;
25 | import org.junit.Assert;
26 | import org.junit.Before;
27 | import org.junit.Test;
28 | import org.junit.runner.RunWith;
29 | import org.mockito.Mock;
30 | import org.mockito.Mockito;
31 | import org.mockito.Spy;
32 | import org.mockito.junit.MockitoJUnitRunner;
33 |
34 | /** Tests for {@link AbstractMinikubeMojo}. */
35 | @RunWith(MockitoJUnitRunner.class)
36 | public class AbstractMinikubeMojoTest {
37 |
38 | @Spy private AbstractMinikubeMojo spyAbstractMinikubeMojo;
39 |
40 | @Mock private CommandExecutor mockCommandExecutor;
41 | @Mock private MavenBuildLogger mockMavenBuildLogger;
42 |
43 | @Before
44 | public void setUp() {
45 | Mockito.when(mockCommandExecutor.setLogger(Mockito.any(MavenBuildLogger.class)))
46 | .thenReturn(mockCommandExecutor);
47 | }
48 |
49 | @Test
50 | public void testBuildMinikubeCommand() {
51 | spyAbstractMinikubeMojo.setMinikube("path/to/minikube");
52 | spyAbstractMinikubeMojo.setFlags(ImmutableList.of("someFlag1", "someFlag2"));
53 |
54 | Mockito.when(spyAbstractMinikubeMojo.getCommand()).thenReturn("somecommand");
55 | Mockito.when(spyAbstractMinikubeMojo.getMoreFlags())
56 | .thenReturn(ImmutableList.of("moreFlag1", "moreFlag2"));
57 |
58 | Assert.assertEquals(
59 | Arrays.asList(
60 | "path/to/minikube", "somecommand", "someFlag1", "someFlag2", "moreFlag1", "moreFlag2"),
61 | spyAbstractMinikubeMojo.buildMinikubeCommand());
62 | }
63 |
64 | @Test
65 | public void testExecute() throws IOException, MojoExecutionException, InterruptedException {
66 | List minikubeCommand = Arrays.asList("some", "command");
67 | Mockito.doReturn(minikubeCommand).when(spyAbstractMinikubeMojo).buildMinikubeCommand();
68 |
69 | spyAbstractMinikubeMojo.setCommandExecutorSupplier(() -> mockCommandExecutor);
70 | spyAbstractMinikubeMojo.setMavenBuildLogger(mockMavenBuildLogger);
71 |
72 | spyAbstractMinikubeMojo.execute();
73 |
74 | Mockito.verify(mockCommandExecutor).setLogger(mockMavenBuildLogger);
75 | Mockito.verify(mockCommandExecutor).run(minikubeCommand);
76 | }
77 |
78 | @Test
79 | public void testExecute_fail() throws IOException, InterruptedException {
80 | List minikubeCommand = Arrays.asList("some", "command");
81 | Mockito.doReturn(minikubeCommand).when(spyAbstractMinikubeMojo).buildMinikubeCommand();
82 |
83 | String description = "some description";
84 | Mockito.when(spyAbstractMinikubeMojo.getDescription()).thenReturn(description);
85 |
86 | spyAbstractMinikubeMojo.setCommandExecutorSupplier(() -> mockCommandExecutor);
87 | IOException expectedIOException = new IOException();
88 | Mockito.doThrow(expectedIOException).when(mockCommandExecutor).run(minikubeCommand);
89 |
90 | try {
91 | spyAbstractMinikubeMojo.execute();
92 | Assert.fail("execute() should have failed");
93 |
94 | } catch (MojoExecutionException ex) {
95 | Assert.assertEquals(description + " failed", ex.getMessage());
96 | Assert.assertEquals(expectedIOException, ex.getCause());
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/test/java/com/google/cloud/tools/minikube/maven/DeleteMojoTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.maven;
18 |
19 | import java.io.IOException;
20 | import java.net.URISyntaxException;
21 | import org.apache.maven.it.VerificationException;
22 | import org.junit.Before;
23 | import org.junit.ClassRule;
24 | import org.junit.Rule;
25 | import org.junit.Test;
26 |
27 | /** Tests for {@link StartMojo}. */
28 | public class DeleteMojoTest {
29 |
30 | @ClassRule public static final TestPlugin testPlugin = new TestPlugin();
31 |
32 | @Rule public final TestProject testProject = new TestProject(testPlugin, "/projects/simple");
33 |
34 | private MinikubeVerifier minikubeVerifier;
35 |
36 | @Before
37 | public void setUp() throws VerificationException, IOException, URISyntaxException {
38 | minikubeVerifier = new MinikubeVerifier(testProject);
39 | }
40 |
41 | @Test
42 | public void testExecute_withProject() throws VerificationException, IOException {
43 | minikubeVerifier.verify("delete", "delete");
44 | }
45 |
46 | @Test
47 | public void testExecute_withProject_andFlags() throws VerificationException, IOException {
48 | minikubeVerifier
49 | .setProfile("deleteFlags")
50 | .verify("delete", "delete someCommonFlag someDeleteFlag1 someDeleteFlag2");
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/test/java/com/google/cloud/tools/minikube/maven/FakeMinikube.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.maven;
18 |
19 | import com.google.common.io.Resources;
20 | import java.io.IOException;
21 | import java.net.URISyntaxException;
22 | import java.nio.file.Files;
23 | import java.nio.file.Path;
24 | import java.nio.file.Paths;
25 | import java.nio.file.attribute.PosixFilePermissions;
26 |
27 | /** Gets a fake minikube executable. */
28 | class FakeMinikube {
29 |
30 | static Path getPath() throws IOException, URISyntaxException {
31 | // Makes the 'fakeminikube' executable.
32 | Path fakeMinikube = Paths.get(Resources.getResource("fakeminikube").toURI());
33 | // 755
34 | Files.setPosixFilePermissions(fakeMinikube, PosixFilePermissions.fromString("rwxr-xr-x"));
35 |
36 | return fakeMinikube.toAbsolutePath();
37 | }
38 |
39 | private FakeMinikube() {}
40 | }
41 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/test/java/com/google/cloud/tools/minikube/maven/MinikubeVerifier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.maven;
18 |
19 | import java.io.IOException;
20 | import java.net.URISyntaxException;
21 | import java.nio.charset.StandardCharsets;
22 | import java.nio.file.Files;
23 | import java.nio.file.Paths;
24 | import java.util.Collections;
25 | import org.apache.maven.it.VerificationException;
26 | import org.apache.maven.it.Verifier;
27 | import org.junit.Assert;
28 |
29 | /** Utilities for verifying minikube goals on a {@link TestProject}. */
30 | class MinikubeVerifier {
31 |
32 | private final Verifier verifier;
33 | private String profile;
34 |
35 | /** Sets up the a verifier on the {@link TestProject}. */
36 | MinikubeVerifier(TestProject testProject)
37 | throws VerificationException, IOException, URISyntaxException {
38 | // Sets the minikube executable to fakeminikube.
39 | testProject.replaceInPom("@@MinikubePath@@", FakeMinikube.getPath().toString());
40 |
41 | verifier = new Verifier(testProject.getProjectRoot().toString());
42 | verifier.setAutoclean(false);
43 | }
44 |
45 | /** Sets a profile to use. */
46 | MinikubeVerifier setProfile(String profile) {
47 | this.profile = profile;
48 | return this;
49 | }
50 |
51 | /** Verifies execution of the goal produces the correct fakeminikube output. */
52 | void verify(String goal, String expectedOutput) throws IOException, VerificationException {
53 | if (profile != null) {
54 | verifier.setCliOptions(Collections.singletonList("-P" + profile));
55 | }
56 | verifier.executeGoal("minikube:" + goal);
57 | verifier.verifyErrorFreeLog();
58 |
59 | String fakeMinikubeOutput =
60 | new String(
61 | Files.readAllBytes(Paths.get(verifier.getBasedir()).resolve("fakeminikube.log")),
62 | StandardCharsets.UTF_8);
63 | Assert.assertEquals(expectedOutput, fakeMinikubeOutput);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/test/java/com/google/cloud/tools/minikube/maven/StartMojoTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.maven;
18 |
19 | import java.io.IOException;
20 | import java.net.URISyntaxException;
21 | import org.apache.maven.it.VerificationException;
22 | import org.junit.Before;
23 | import org.junit.ClassRule;
24 | import org.junit.Rule;
25 | import org.junit.Test;
26 |
27 | /** Tests for {@link StartMojo}. */
28 | public class StartMojoTest {
29 |
30 | @ClassRule public static final TestPlugin testPlugin = new TestPlugin();
31 |
32 | @Rule public final TestProject testProject = new TestProject(testPlugin, "/projects/simple");
33 |
34 | private MinikubeVerifier minikubeVerifier;
35 |
36 | @Before
37 | public void setUp() throws VerificationException, IOException, URISyntaxException {
38 | minikubeVerifier = new MinikubeVerifier(testProject);
39 | }
40 |
41 | @Test
42 | public void testExecute_withProject() throws VerificationException, IOException {
43 | minikubeVerifier.verify("start", "start");
44 | }
45 |
46 | @Test
47 | public void testExecute_withProject_andFlags() throws VerificationException, IOException {
48 | minikubeVerifier
49 | .setProfile("startFlags")
50 | .verify("start", "start someCommonFlag someStartFlag1 someStartFlag2");
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/test/java/com/google/cloud/tools/minikube/maven/StopMojoTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.maven;
18 |
19 | import java.io.IOException;
20 | import java.net.URISyntaxException;
21 | import org.apache.maven.it.VerificationException;
22 | import org.junit.Before;
23 | import org.junit.ClassRule;
24 | import org.junit.Rule;
25 | import org.junit.Test;
26 |
27 | /** Tests for {@link StartMojo}. */
28 | public class StopMojoTest {
29 |
30 | @ClassRule public static final TestPlugin testPlugin = new TestPlugin();
31 |
32 | @Rule public final TestProject testProject = new TestProject(testPlugin, "/projects/simple");
33 |
34 | private MinikubeVerifier minikubeVerifier;
35 |
36 | @Before
37 | public void setUp() throws VerificationException, IOException, URISyntaxException {
38 | minikubeVerifier = new MinikubeVerifier(testProject);
39 | }
40 |
41 | @Test
42 | public void testExecute_withProject() throws VerificationException, IOException {
43 | minikubeVerifier.verify("stop", "stop");
44 | }
45 |
46 | @Test
47 | public void testExecute_withProject_andFlags() throws VerificationException, IOException {
48 | minikubeVerifier
49 | .setProfile("stopFlags")
50 | .verify("stop", "stop someCommonFlag someStopFlag1 someStopFlag2");
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/test/java/com/google/cloud/tools/minikube/maven/TestPlugin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.maven;
18 |
19 | import java.io.FileReader;
20 | import java.io.IOException;
21 | import org.apache.maven.it.VerificationException;
22 | import org.apache.maven.it.Verifier;
23 | import org.apache.maven.model.Model;
24 | import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
25 | import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
26 | import org.junit.rules.ExternalResource;
27 |
28 | /** Sets up the plugin for testing. */
29 | class TestPlugin extends ExternalResource {
30 |
31 | private String pluginVersion;
32 |
33 | String getVersion() {
34 | return pluginVersion;
35 | }
36 |
37 | @Override
38 | protected void before() throws IOException, XmlPullParserException, VerificationException {
39 | // Installs the plugin for use in tests.
40 | Verifier verifier = new Verifier(".", true);
41 | verifier.setAutoclean(false);
42 | verifier.addCliOption("-DskipTests");
43 | verifier.executeGoal("install");
44 |
45 | // Reads the project version.
46 | MavenXpp3Reader reader = new MavenXpp3Reader();
47 | Model model = reader.read(new FileReader("pom.xml"));
48 | pluginVersion = model.getVersion();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/test/java/com/google/cloud/tools/minikube/maven/TestProject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * 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, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 |
17 | package com.google.cloud.tools.minikube.maven;
18 |
19 | import java.io.IOException;
20 | import java.nio.charset.StandardCharsets;
21 | import java.nio.file.Files;
22 | import java.nio.file.Path;
23 | import org.apache.maven.it.util.ResourceExtractor;
24 | import org.junit.rules.TemporaryFolder;
25 |
26 | /** Works with the test Maven project in the {@code resources/project} directory. */
27 | public class TestProject extends TemporaryFolder {
28 |
29 | private final TestPlugin testPlugin;
30 | private final String projectPathInResources;
31 |
32 | private Path projectRoot;
33 |
34 | TestProject(TestPlugin testPlugin, String projectPathInResources) {
35 | this.testPlugin = testPlugin;
36 | this.projectPathInResources = projectPathInResources;
37 | }
38 |
39 | Path getProjectRoot() {
40 | return projectRoot;
41 | }
42 |
43 | /** Replaces a string in the project {@code pom.xml}. */
44 | void replaceInPom(String oldString, String newString) throws IOException {
45 | Path pomXml = projectRoot.resolve("pom.xml");
46 | Files.write(
47 | pomXml,
48 | new String(Files.readAllBytes(pomXml), StandardCharsets.UTF_8)
49 | .replace(oldString, newString)
50 | .getBytes(StandardCharsets.UTF_8));
51 | }
52 |
53 | @Override
54 | protected void before() throws Throwable {
55 | super.before();
56 |
57 | copyProject();
58 | }
59 |
60 | private void copyProject() throws IOException {
61 | projectRoot =
62 | ResourceExtractor.extractResourcePath(
63 | TestProject.class, projectPathInResources, newFolder(), true)
64 | .toPath();
65 |
66 | // Puts the correct plugin version into the test project pom.xml.
67 | replaceInPom("@@PluginVersion@@", testPlugin.getVersion());
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/test/resources/fakeminikube:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Simply outputs the arguments to the command to "fakeminikube.log".
4 | echo -n $@ >> fakeminikube.log
5 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker:
--------------------------------------------------------------------------------
1 | mock-maker-inline
2 |
--------------------------------------------------------------------------------
/minikube-maven-plugin/src/test/resources/projects/simple/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.test
5 | simple
6 | 1
7 |
8 |
9 | 1.8
10 | UTF-8
11 | UTF-8
12 | @@PluginVersion@@
13 |
14 |
15 |
16 |
17 | startFlags
18 |
19 |
20 |
21 | com.google.cloud.tools
22 | minikube-maven-plugin
23 | ${minikube-maven-plugin.version}
24 |
25 |
26 |
27 | someStartFlag1
28 | someStartFlag2
29 |
30 |
31 |
32 | someCommonFlag
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | stopFlags
41 |
42 |
43 |
44 | com.google.cloud.tools
45 | minikube-maven-plugin
46 | ${minikube-maven-plugin.version}
47 |
48 |
49 |
50 | someStopFlag1
51 | someStopFlag2
52 |
53 |
54 |
55 | someCommonFlag
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | deleteFlags
64 |
65 |
66 |
67 | com.google.cloud.tools
68 | minikube-maven-plugin
69 | ${minikube-maven-plugin.version}
70 |
71 |
72 |
73 | someDeleteFlag1
74 | someDeleteFlag2
75 |
76 |
77 |
78 | someCommonFlag
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 | org.apache.maven.plugins
91 | maven-compiler-plugin
92 |
93 | 1.8
94 | 1.8
95 |
96 |
97 |
98 |
99 | com.google.cloud.tools
100 | minikube-maven-plugin
101 | ${minikube-maven-plugin.version}
102 |
103 | @@MinikubePath@@
104 |
105 |
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------