-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement support for service providers #22
Changes from 5 commits
40fbd22
c5b8c64
418e69d
87e4576
23c9fd4
9025913
13ea4d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.eed3si9n.jarjar; | ||
|
||
import com.eed3si9n.jarjar.util.EntryStruct; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class ResourceProcessorTest { | ||
|
||
private ResourceProcessor processor; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
String rules = "rule org.example.** something.shaded.@0"; | ||
List<Rule> parsed = (List<Rule>)(List<?>) RulesFileParser.parse(rules); | ||
processor = new ResourceProcessor(new PackageRemapper(parsed, true)); | ||
} | ||
|
||
@Test | ||
public void testClassFile() throws IOException { | ||
EntryStruct entryStruct = new EntryStruct(); | ||
entryStruct.name = "org/example/Object.class"; | ||
entryStruct.data = new byte[]{0x10}; | ||
|
||
assertTrue(processor.process(entryStruct)); | ||
assertEquals(entryStruct.name, "org/example/Object.class"); | ||
assertArrayEquals(entryStruct.data, new byte[]{0x10}); | ||
} | ||
|
||
@Test | ||
public void testServiceProviderConfig() throws IOException { | ||
String original = "org.example.Impl # comment" + System.lineSeparator() | ||
+ "org.example.AnotherImpl" + System.lineSeparator() | ||
+ System.lineSeparator() | ||
+ " org.another.Impl"; | ||
String expected = "something.shaded.org.example.Impl" + System.lineSeparator() | ||
+ "something.shaded.org.example.AnotherImpl" + System.lineSeparator() | ||
+ System.lineSeparator() | ||
+ "org.another.Impl"; | ||
EntryStruct entryStruct = new EntryStruct(); | ||
entryStruct.name = "META-INF/services/org.example.Service"; | ||
entryStruct.data = original.getBytes(StandardCharsets.UTF_8); | ||
|
||
assertTrue(processor.process(entryStruct)); | ||
assertEquals(entryStruct.name, "META-INF/services/something.shaded.org.example.Service"); | ||
assertArrayEquals(entryStruct.data, expected.getBytes(StandardCharsets.UTF_8)); | ||
} | ||
|
||
@Test | ||
public void testOtherResource() throws IOException { | ||
EntryStruct entryStruct = new EntryStruct(); | ||
entryStruct.name = "org/example/file.txt"; | ||
entryStruct.data = new byte[]{0x10}; | ||
|
||
assertTrue(processor.process(entryStruct)); | ||
assertEquals(entryStruct.name, "something/shaded/org/example/file.txt"); | ||
assertArrayEquals(entryStruct.data, new byte[]{0x10}); | ||
|
||
EntryStruct entryStruct2 = new EntryStruct(); | ||
entryStruct2.name = "another_org/example/file.txt"; | ||
entryStruct2.data = new byte[]{0x10}; | ||
|
||
assertTrue(processor.process(entryStruct2)); | ||
assertEquals(entryStruct2.name, "another_org/example/file.txt"); | ||
assertArrayEquals(entryStruct.data, new byte[]{0x10}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ addSbtPlugin("com.eed3si9n" % "sbt-nocomma" % "0.1.0") | |
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3") | ||
addSbtPlugin("org.scala-sbt" % "sbt-contraband" % "0.4.6") | ||
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1") | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure about this line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @er1c thanks for fixing the java8 issue I added this line because we are not (yet) using jarjar-abrams but only the jarjar cli. To give a bit more context, we build our code with Bazel and we have a jarjar rule that basically invokes I'm not very familiar with sbt, is there another way to get an uber jar? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I tried to run
sbt jarjar/assembly
I got:These
module-info.class
all clash when being packed into the uber jar and ignoring them seemed reasonable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been discussed here: sbt/sbt-assembly#391