Skip to content

Commit 8a602c5

Browse files
authored
Add 'args' parameter to Maven plugin (GoogleContainerTools#361)
1 parent 91e297d commit 8a602c5

10 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎jib-maven-plugin/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
1616
- `jib:buildDocker` maven goal to build straight to Docker daemon ([#266](https://github.com/GoogleContainerTools/jib/pull/266))
1717
- `mainClass` is inferred by searching through class files if configuration is missing ([#278](https://github.com/GoogleContainerTools/jib/pull/278))
1818
- Can now specify target image with `-Dimage` ([#328](https://github.com/GoogleContainerTools/jib/issues/328))
19+
- `args` parameter to define default main args ([#346](https://github.com/GoogleContainerTools/jib/issues/346))
1920

2021
### Changed
2122
- Removed `enableReproducibleBuilds` parameter - application layers will always be reproducible ([#245](https://github.com/GoogleContainerTools/jib/pull/245))

‎jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/BuildDockerMojo.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public void execute() throws MojoExecutionException {
6868
.setKnownBaseRegistryCredentials(knownBaseRegistryCredentials)
6969
.setTargetImage(targetImage)
7070
.setMainClass(mainClass)
71+
.setJavaArguments(getArgs())
7172
.setJvmFlags(getJvmFlags())
7273
.setEnvironment(getEnvironment())
7374
.build();

‎jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/BuildImageMojo.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
100100
.setTargetImageCredentialHelperName(getTargetImageCredentialHelperName())
101101
.setKnownTargetRegistryCredentials(knownTargetRegistryCredentials)
102102
.setMainClass(mainClass)
103+
.setJavaArguments(getArgs())
103104
.setJvmFlags(getJvmFlags())
104105
.setEnvironment(getEnvironment())
105106
.setTargetFormat(ImageFormat.valueOf(getFormat()).getManifestTemplateClass())

‎jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/DockerContextMojo.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
5454
.setBaseImage(getBaseImage())
5555
.setJvmFlags(getJvmFlags())
5656
.setMainClass(mainClass)
57+
.setJavaArguments(getArgs())
5758
.generate(Paths.get(targetDir));
5859

5960
mavenBuildLogger.info("Created Docker context at " + targetDir);

‎jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/JibPluginConfiguration.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ static ImageReference parseTargetImageReference(String to) {
9797

9898
@Nullable @Parameter private String mainClass;
9999

100+
@Parameter private List<String> args = Collections.emptyList();
101+
100102
@Nullable
101103
@Parameter(defaultValue = "Docker", required = true)
102104
private String format;
@@ -140,6 +142,10 @@ String getMainClass() {
140142
return mainClass;
141143
}
142144

145+
List<String> getArgs() {
146+
return args;
147+
}
148+
143149
String getFormat() {
144150
return Preconditions.checkNotNull(format);
145151
}

‎jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/BuildDockerMojoIntegrationTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private static String buildToDockerDaemonAndRun(Path projectRoot, String imageRe
5656
@Test
5757
public void testExecute_simple() throws VerificationException, IOException, InterruptedException {
5858
Assert.assertEquals(
59-
"Hello, world\n",
59+
"Hello, world. An argument.\n",
6060
buildToDockerDaemonAndRun(
6161
simpleTestProject.getProjectRoot(),
6262
"gcr.io/jib-integration-testing/simpleimage:maven"));

‎jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/BuildImageMojoIntegrationTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void testExecute_simple() throws VerificationException, IOException, Inte
8989
}
9090

9191
Assert.assertEquals(
92-
"Hello, world\n",
92+
"Hello, world. An argument.\n",
9393
buildAndRun(
9494
simpleTestProject.getProjectRoot(),
9595
"gcr.io/jib-integration-testing/simpleimage:maven"));

‎jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/DockerContextMojoIntegrationTest.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public void testExecute() throws VerificationException, IOException, Interrupted
5050

5151
String imageName = "jib/integration-test";
5252
new Command("docker", "build", "-t", imageName, dockerContextDirectory.toString()).run();
53-
Assert.assertEquals("Hello, world\n", new Command("docker", "run", imageName).run());
53+
Assert.assertEquals(
54+
"Hello, world. An argument.\n", new Command("docker", "run", imageName).run());
5455
}
5556
}

‎jib-maven-plugin/src/test/resources/projects/simple/pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<to>
4242
<image>gcr.io/jib-integration-testing/simpleimage:maven</image>
4343
</to>
44+
<args>An argument.</args>
4445
<!-- Does not have tests use user-level cache for base image layers. -->
4546
<useOnlyProjectCache>true</useOnlyProjectCache>
4647
</configuration>

‎jib-maven-plugin/src/test/resources/projects/simple/src/main/java/com/test/HelloWorld.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public static void main(String[] args) throws IOException, URISyntaxException {
3636
Path worldFile = Paths.get(classLoader.getResource("world").toURI());
3737
String world = new String(Files.readAllBytes(worldFile), StandardCharsets.UTF_8);
3838

39-
System.out.println(greeting + ", " + world);
39+
System.out.println(greeting + ", " + world + ". " + (args.length > 0 ? args[0] : ""));
4040
}
4141
}

0 commit comments

Comments
 (0)