Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #194 from spotify/shading-tolerant-version-reading
Browse files Browse the repository at this point in the history
Shading tolerant version reading
  • Loading branch information
danielnorberg authored Dec 11, 2018
2 parents fe062a3 + c30194a commit 09fe382
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 1 deletion.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
# Maven heap size
MAVEN_OPTS: -Xmx1024m -Xms1024m
command: mvn -B verify scala:doc-jar -Pcoverage -Pmissinglink
- run: flo-tests/run_shading_tests.sh
- run: bash <(curl -s https://codecov.io/bash)

test_jdk10:
Expand Down
21 changes: 21 additions & 0 deletions flo-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,25 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>conf</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static Logging create(Logger logger) {
}

void header() {
LOG.info("FloRunner v{}", getClass().getPackage().getImplementationVersion());
LOG.info("FloRunner v{}", Version.floRunnerVersion());
LOG.info("");
}

Expand Down
48 changes: 48 additions & 0 deletions flo-runner/src/main/java/com/spotify/flo/context/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*-
* -\-\-
* Flo Runner
* --
* Copyright (C) 2016 - 2018 Spotify AB
* --
* 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 com.spotify.flo.context;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Version {

private static final String VERSION_RESOURCE = "/com/spotify/flo/flo-runner.version";

private static class Lazy {

private static String RUNNER_VERSION = readFloRunnerVersion();
}

static synchronized String floRunnerVersion() {
return Lazy.RUNNER_VERSION;
}

private static String readFloRunnerVersion() {
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(
Version.class.getResourceAsStream(VERSION_RESOURCE)))) {
return reader.readLine().trim();
} catch (IOException e) {
throw new RuntimeException(String.format("Failed to read flo runner version from %s", VERSION_RESOURCE), e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${project.version}
42 changes: 42 additions & 0 deletions flo-runner/src/test/java/com/spotify/flo/context/VersionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*-
* -\-\-
* Flo Runner
* --
* Copyright (C) 2016 - 2018 Spotify AB
* --
* 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 com.spotify.flo.context;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.junit.Test;

public class VersionTest {

@Test
public void shouldReadFloVersion() throws IOException {
final String expectedVersion;
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(
Version.class.getResourceAsStream("/com/spotify/flo/flo-runner.version")))) {
expectedVersion = reader.readLine().trim();
}
assertThat(Version.floRunnerVersion(), is(expectedVersion));
}
}
14 changes: 14 additions & 0 deletions flo-tests/run_shading_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -e
cd "$(dirname "$0")/.."
FLO_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
mvn -B install -DskipTests
cd flo-tests

pushd shading
mvn -B clean install -DskipTests -Dflo.version=$FLO_VERSION
popd

pushd shading-user
mvn -B clean test
popd
47 changes: 47 additions & 0 deletions flo-tests/shading-user/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.spotify</groupId>
<artifactId>foss-root</artifactId>
<version>8</version>
</parent>

<name>Flo Tests - Shading User</name>
<artifactId>flo-tests-shading-user</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>
Tests using shaded flo
</description>

<dependencies>
<dependency>
<groupId>com.spotify</groupId>
<artifactId>flo-tests-shading</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<!-- TODO: remove -Djdk.net.URLClassPath.disableClassPathURLCheck=true after debian fixes
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=911925 -->
<argLine>-Xmx256m -Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*-
* -\-\-
* Flo Tests - Shading User
* --
* Copyright (C) 2016 - 2018 Spotify AB
* --
* 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 shaded.com.spotify.flo.context;

import static org.junit.Assert.assertEquals;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.junit.Test;

public class VersionTest {

@Test
public void shouldReadRelocatedFloVersion() throws IOException {
final String expectedVersion;
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(
Version.class.getResourceAsStream("/shaded/com/spotify/flo/flo-runner.version")))) {
expectedVersion = reader.readLine().trim();
}
assertEquals(expectedVersion, Version.floRunnerVersion());
}
}
71 changes: 71 additions & 0 deletions flo-tests/shading/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.spotify</groupId>
<artifactId>foss-root</artifactId>
<version>8</version>
</parent>

<name>Flo Tests - Shading</name>
<artifactId>flo-tests-shading</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>
Shaded Flo for testing
</description>

<dependencies>
<dependency>
<groupId>com.spotify</groupId>
<artifactId>flo-runner</artifactId>
<version>${flo.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.spotify.flo.context.FloRunner</Main-Class>
</manifestEntries>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>reference.conf</resource>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>com.spotify.flo</pattern>
<shadedPattern>shaded.com.spotify.flo</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

0 comments on commit 09fe382

Please sign in to comment.