Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Issue #8 - alternate /tests/ setup for 100% maven #45

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions jetty9/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>copy-resources</id>
Expand Down Expand Up @@ -146,6 +148,41 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>tag-and-deploy-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<exec executable="gcloud" logError="true" outputproperty="app.deploy.project">
<arg value="--quiet"/>
<arg value="config"/>
<arg value="list"/>
<arg value="--format=value(core.project)"/>
</exec>
<echo>app.deploy.project=${app.deploy.project}</echo>
<exec executable="docker">
<arg value="tag"/>
<arg value="jetty9:${docker.label.prefix}${jetty.version}"/>
<arg value="gcr.io/${app.deploy.project}/jetty9:testing"/>
</exec>
<exec executable="gcloud">
<arg value="docker"/>
<arg value="push"/>
Copy link
Member

@meltsufin meltsufin Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this push to GCR should be moved to a different profile or deploy phase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is important for the jetty9:testing tag, as used by the various docker images int he test webapps.

<arg value="gcr.io/${app.deploy.project}/jetty9:testing"/>
</exec>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Expand Down
64 changes: 61 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<docker.tag.long>${docker.tag.prefix}9.${jetty9.minor.version}-${maven.build.timestamp}</docker.tag.long>

<docker.openjdk.image>openjdk:8</docker.openjdk.image>
<gcloud-projectId-file>${project.build.directory}/gcloud-projectid.properties</gcloud-projectId-file>
</properties>

<developers>
Expand Down Expand Up @@ -85,6 +86,7 @@
<modules>
<module>jetty9-base</module>
<module>jetty9</module>
<module>tests</module>
</modules>

<dependencyManagement>
Expand Down Expand Up @@ -257,9 +259,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -305,5 +307,61 @@
</plugins>
</build>
</profile>
<profile>
<id>get-gcloud-project-id</id>
<activation>
<property>
<name>!app.deploy.project</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>find-app-deploy-project</id>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool how you inject the current project into Maven properties! 👍
The whole block needs a comment though to make it clear what's going on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo file="${gcloud-projectId-file}" append="false">app.deploy.project=</echo>
<exec executable="gcloud" logError="true" append="true" output="${gcloud-projectId-file}">
<arg value="--quiet"/>
<arg value="config"/>
<arg value="list"/>
<arg value="--format=value(core.project)"/>
</exec>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>read-gcloud-properties</id>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${gcloud-projectId-file}</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
49 changes: 49 additions & 0 deletions tests/gcloud-testing-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.google.cloud.runtimes.jetty.tests</groupId>
<artifactId>tests-parent</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<artifactId>gcloud-testing-core</artifactId>
<name>Jetty-Runtime :: Testing Core Lib</name>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.17</version>
</dependency>
<!--
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-logging</artifactId>
<version>0.3.0</version>
</dependency>
-->
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<version>4.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.google.cloud.runtime.jetty.testing;

import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.yaml.snakeyaml.Yaml;

import java.io.BufferedReader;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.Objects;

public final class AppDeployment {
Copy link
Member

@meltsufin meltsufin Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some javadoc comments please on what this class is doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public static final String PROJECT_ID;
public static final String VERSION_ID;
public static final String MODULE_ID;
public static final URI SERVER_URI;

static {
String projectId = System.getProperty("app.deploy.project");
String version = System.getProperty("app.deploy.version");

Objects.requireNonNull(projectId, "app.deploy.project");
Objects.requireNonNull(version, "app.deploy.version");

PROJECT_ID = projectId;
VERSION_ID = version;

String moduleId = null;

Path appYamlPath = MavenTestingUtils.getProjectFilePath("src/main/appengine/app.yaml");
if (Files.exists(appYamlPath)) {
try (BufferedReader reader = Files.newBufferedReader(appYamlPath, StandardCharsets.UTF_8)) {
Yaml yaml = new Yaml();
Map map = (Map) yaml.load(reader);
moduleId = (String) map.get("module");
} catch (IOException e) {
throw new RuntimeException("Unable to parse app.yaml", e);
}
}

MODULE_ID = moduleId;

StringBuilder uri = new StringBuilder();
uri.append("https://");
uri.append(version).append("-dot-");
if (moduleId != null) {
uri.append(moduleId).append("-dot-");
}
uri.append(projectId);
uri.append(".appspot.com/");

SERVER_URI = URI.create(uri.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.google.cloud.runtime.jetty.testing;

import org.eclipse.jetty.toolchain.test.IO;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.URI;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

public final class HttpURLUtil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: HttpUrlUtil

Copy link
Contributor Author

@joakime joakime Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its specifically designed for the HttpURLConnection from the JDK, so it make sense (and conforms to the Google checkstyle rules)

However, I filed it as Issue #49

/**
* Open a new {@link HttpURLConnection} to the provided URI.
*
* <p>
* Note: will also set the 'User-Agent' to {@code jetty-runtime/gcloud-testing-core}
* </p>
*
* @param uri the URI to open to
* @return the open HttpURLConnection
* @throws IOException if unable to open the connection
*/
public static HttpURLConnection openTo(URI uri) throws IOException {
HttpURLConnection http = (HttpURLConnection) uri.toURL().openConnection();
http.setRequestProperty("User-Agent", "jetty-runtime/gcloud-testing-core");
return http;
}

/**
* Obtain the text (non-binary) response body from an {@link HttpURLConnection},
* using the response provided charset.
*
* <p>
* Note: Normal HttpURLConnection doesn't use the provided charset properly.
* </p>
*
* @param http the {@link HttpURLConnection} to obtain the response body from
* @return the text of the response body
* @throws IOException if unable to get the text of the response body
*/
public static String getResponseBody(HttpURLConnection http) throws IOException {
Charset responseEncoding = StandardCharsets.UTF_8;
if (http.getContentEncoding() != null) {
responseEncoding = Charset.forName(http.getContentEncoding());
}

try (InputStream in = http.getInputStream();
InputStreamReader reader = new InputStreamReader(in, responseEncoding);
StringWriter writer = new StringWriter()) {
IO.copy(reader, writer);
return writer.toString();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.google.cloud.runtime.jetty.testing;

import org.eclipse.jetty.toolchain.test.IO;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
* Utilities for executing and collecting output from command line processes.
*/
public final class ProcessUtil {
private static final ExecutorService executor = Executors.newFixedThreadPool(5);

/**
* Execute a command line.
* <p>
* Report output from command line to Writer
* </p>
*
* @param output where to put the output from the execution of the command line
* @param args the command line arguments
* @return the exit code from the execution
*/
public static int exec(OutputStream output, String... args)
throws IOException, InterruptedException, ExecutionException {
System.out.printf("exec(%s)%n", Arrays.toString(args));
Process process = Runtime.getRuntime().exec(args);

InputStream in = process.getInputStream();

Future<Void> fut = executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
IO.copy(in, output);
return null;
}
});

fut.get();

return process.waitFor();
}
}
Loading