-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix shading issues and add shading tests (#61)
As seen in netty/netty#9687, due to GradleUp/shadow#519, we have `reactor/shaded/META-INF/versions/9/module-info.class` file in the final JAR, although we thought that we excluded it. This PR fixes a few related shading issues and adds the missing tests for the shadowed jar, so that we will never miss such issues again. It also changes the shading package to `reactor.blockhound.shaded` for better package alignment.
- Loading branch information
Showing
3 changed files
with
131 additions
and
2 deletions.
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
46 changes: 46 additions & 0 deletions
46
agent/src/jarFileTest/java/reactor/blockhoud/AbstractJarFileTest.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,46 @@ | ||
/* | ||
* Copyright (c) 2019-Present Pivotal Software Inc, All Rights Reserved. | ||
* | ||
* 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 | ||
* | ||
* https://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 reactor.blockhoud; | ||
|
||
import java.net.URI; | ||
import java.nio.file.FileSystem; | ||
import java.nio.file.FileSystems; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static java.util.Collections.emptyMap; | ||
|
||
/** | ||
* A helper class to access the content of a shaded JAR | ||
*/ | ||
class AbstractJarFileTest { | ||
|
||
static Path root; | ||
|
||
static { | ||
try { | ||
Path jarFilePath = Paths.get(System.getProperty("jarFile")); | ||
URI jarFileUri = new URI("jar", jarFilePath.toUri().toString(), null); | ||
FileSystem fileSystem = FileSystems.newFileSystem(jarFileUri, emptyMap()); | ||
root = fileSystem.getPath("/"); | ||
} | ||
catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
agent/src/jarFileTest/java/reactor/blockhoud/JarFileShadingTest.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,63 @@ | ||
/* | ||
* Copyright (c) 2019-Present Pivotal Software Inc, All Rights Reserved. | ||
* | ||
* 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 | ||
* | ||
* https://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 reactor.blockhoud; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import org.assertj.core.api.ListAssert; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* This test must be executed with Gradle because it requires a shadow JAR | ||
*/ | ||
public class JarFileShadingTest extends AbstractJarFileTest { | ||
|
||
@Test | ||
public void testPackages() throws Exception { | ||
assertThatFileList(root).containsOnly( | ||
"reactor", | ||
"META-INF" | ||
); | ||
|
||
assertThatFileList(root.resolve("reactor")).containsOnly( | ||
"blockhound" | ||
); | ||
} | ||
|
||
@Test | ||
public void testMetaInf() throws Exception { | ||
assertThatFileList(root.resolve("META-INF")).containsOnly( | ||
"MANIFEST.MF", | ||
"services" | ||
); | ||
assertThatFileList(root.resolve("META-INF").resolve("services")).containsOnly( | ||
"reactor.blockhound.integration.BlockHoundIntegration" | ||
); | ||
} | ||
|
||
private ListAssert<String> assertThatFileList(Path path) throws IOException { | ||
return (ListAssert) assertThat(Files.list(path)) | ||
.extracting(Path::getFileName) | ||
.extracting(Path::toString) | ||
.extracting(it -> it.endsWith("/") ? it.substring(0, it.length() - 1) : it); | ||
} | ||
|
||
} |