-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix endless loop with floating relocation pattern
Fixes #4. Thank you @jkebinger for reporting!
- Loading branch information
Showing
3 changed files
with
129 additions
and
39 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
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
62 changes: 62 additions & 0 deletions
62
src/test/java/org/basepom/maven/shade/CollectingManifestResourceTransformerTest.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,62 @@ | ||
/* | ||
* 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 org.basepom.maven.shade; | ||
|
||
import java.util.Collections; | ||
|
||
import org.apache.maven.plugins.shade.relocation.Relocator; | ||
import org.apache.maven.plugins.shade.relocation.SimpleRelocator; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class CollectingManifestResourceTransformerTest { | ||
|
||
@Test | ||
void testPatternRelocation() { | ||
Relocator relocator = new SimpleRelocator("^com\\.google\\.common", "prefab.shaded.com.google.common", null, null); | ||
|
||
Assertions.assertEquals("prefab.shaded.com.google.common.SomeClass", | ||
CollectingManifestResourceTransformer.relocate("com.google.common.SomeClass", Collections.singletonList(relocator))); | ||
} | ||
|
||
@Test | ||
void testAnchoredRelocation() { | ||
Relocator relocator = new SimpleRelocator("^com.google.common", "prefab.shaded.com.google.common", null, null); | ||
|
||
Assertions.assertEquals("prefab.shaded.com.google.common.SomeClass", | ||
CollectingManifestResourceTransformer.relocate("com.google.common.SomeClass", Collections.singletonList(relocator))); | ||
} | ||
|
||
@Test | ||
void testFloatingNonMatchingRelocation() { | ||
Relocator relocator = new SimpleRelocator("com.google.common", "prefab.shaded.cgm", null, null); | ||
|
||
Assertions.assertEquals("prefab.shaded.cgm.SomeClass", | ||
CollectingManifestResourceTransformer.relocate("com.google.common.SomeClass", Collections.singletonList(relocator))); | ||
} | ||
|
||
@Test | ||
void testFloatingMatchingRelocation() { | ||
Relocator relocator = new SimpleRelocator("com.google.common", "prefab.shaded.com.google.common", null, null); | ||
|
||
IllegalStateException exception = Assertions.assertThrows(IllegalStateException.class, | ||
() -> CollectingManifestResourceTransformer.relocate("com.google.common.SomeClass", Collections.singletonList(relocator))); | ||
|
||
Assertions.assertEquals( | ||
"Detected loop when relocating prefab.shaded.com.google.common.SomeClass to prefab.shaded.prefab.shaded.com.google.common.SomeClass, " | ||
+ "prefix prefab.shaded. already applied!\nRelocation pattern (<pattern>) may be unanchored (not starting with '^')!", | ||
exception.getMessage()); | ||
} | ||
} |