This repository has been archived by the owner on Aug 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from spotify/shading-tolerant-version-reading
Shading tolerant version reading
- Loading branch information
Showing
10 changed files
with
287 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
flo-runner/src/main/java/com/spotify/flo/context/Version.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
flo-runner/src/main/resources/com/spotify/flo/flo-runner.version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
${project.version} |
42 changes: 42 additions & 0 deletions
42
flo-runner/src/test/java/com/spotify/flo/context/VersionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
41 changes: 41 additions & 0 deletions
41
flo-tests/shading-user/src/test/java/shaded/com/spotify/flo/context/VersionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |