Skip to content

Commit

Permalink
add support for polyglot maven builds (no pom.xml)
Browse files Browse the repository at this point in the history
  • Loading branch information
briandealwis committed Oct 30, 2020
1 parent 4ee9012 commit a706c78
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 3 deletions.
13 changes: 13 additions & 0 deletions builders/gcp/base/acceptance/java_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,26 @@ func TestAcceptanceJava(t *testing.T) {
MustUse: []string{javaGradle, javaRuntime, entrypoint},
MustNotUse: []string{javaEntrypoint},
},
{
Name: "Java gradle",
App: "java/gradle_micronaut",
Env: []string{"GOOGLE_ENTRYPOINT=java -jar build/libs/helloworld-0.1-all.jar"},
MustUse: []string{javaGradle, javaRuntime, entrypoint},
MustNotUse: []string{javaEntrypoint},
},
{
Name: "Java gradle (Dev Mode)",
App: "java/gradle_micronaut",
Env: []string{"GOOGLE_DEVMODE=1"},
FilesMustExist: []string{"/layers/google.java.gradle/cache", "/layers/google.java.gradle/cache/bin/.devmode_rebuild.sh"},
MustRebuildOnChange: "/workspace/src/main/java/example/HelloController.java",
},
{
Name: "polyglot maven",
App: "java/polyglot-maven",
MustUse: []string{javaMaven, javaRuntime, javaEntrypoint},
MustNotUse: []string{entrypoint},
},
{
Name: "Maven build args",
App: "java/maven_testing_profile",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>io.takari.polyglot</groupId>
<artifactId>polyglot-yaml</artifactId>
<version>0.4.5</version>
</extension>
</extensions>
18 changes: 18 additions & 0 deletions builders/testdata/generic/java/polyglot-maven/pom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
modelVersion: 4.0.0
groupId: main
artifactId: polyglot-maven
version: 0.1

properties:
maven.compiler.target: 11
maven.compiler.source: 11

build:
plugins:
- groupId: org.apache.maven.plugins
artifactId: maven-jar-plugin
version: 3.2.0
configuration:
archive:
manifest:
mainClass: main.Main
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main;

import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;

public class Main {

public static void main(String[] args) throws IOException {
// Create an instance of HttpServer bound to port defined by the
// PORT environment variable when present, otherwise on 8080.
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);

// Set root URI path.
server.createContext(
"/",
(var t) -> {
byte[] response = "PASS".getBytes();
t.sendResponseHeaders(200, response.length);
try (OutputStream os = t.getResponseBody()) {
os.write(response);
}
});

server.start();
}
}
4 changes: 2 additions & 2 deletions cmd/java/maven/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func main() {
}

func detectFn(ctx *gcp.Context) error {
if !ctx.FileExists("pom.xml") {
ctx.OptOut("pom.xml not found.")
if !ctx.FileExists("pom.xml") && !ctx.FileExists(".mvn/extensions.xml") {
ctx.OptOut("None of the following found: pom.xml or .mvn/extensions.xml.")
}
return nil
}
Expand Down
7 changes: 7 additions & 0 deletions cmd/java/maven/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ func TestDetect(t *testing.T) {
},
want: 0,
},
{
name: ".mvn/extensions.xml",
files: map[string]string{
".mvn/extensions.xml": "",
},
want: 0,
},
{
name: "no pom.xml",
files: map[string]string{},
Expand Down
3 changes: 2 additions & 1 deletion cmd/java/runtime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ func detectFn(ctx *gcp.Context) error {
runtime.CheckOverride(ctx, "java")

if ctx.FileExists("pom.xml") ||
ctx.FileExists(".mvn/extensions.xml") ||
ctx.FileExists("build.gradle") ||
ctx.FileExists("build.gradle.kts") ||
ctx.FileExists("META-INF/MANIFEST.MF") ||
len(ctx.Glob("*.java")) > 0 ||
len(ctx.Glob("*.jar")) > 0 {
return nil
}
ctx.OptOut("None of the following found: pom.xml, build.gradle, build.gradle.kts, META-INF/MANIFEST.MF, *.java, *.jar.")
ctx.OptOut("None of the following found: pom.xml, .mvn/extensions.xml, build.gradle, build.gradle.kts, META-INF/MANIFEST.MF, *.java, *.jar.")
return nil
}

Expand Down
7 changes: 7 additions & 0 deletions cmd/java/runtime/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ func TestDetect(t *testing.T) {
},
want: 0,
},
{
name: ".mvn/extensions.xml",
files: map[string]string{
".mvn/extensions.xml": "",
},
want: 0,
},
{
name: "build.gradle",
files: map[string]string{
Expand Down

0 comments on commit a706c78

Please sign in to comment.