-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actually unbundle the server jar. Oops
- Loading branch information
Showing
5 changed files
with
90 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package agency.highlysuspect.minivan; | ||
|
||
import java.io.BufferedOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
public class Util { | ||
public static void cpy(InputStream in, OutputStream out) throws IOException { | ||
byte[] shuttle = new byte[4096]; | ||
int read; | ||
while((read = in.read(shuttle)) != -1) out.write(shuttle, 0, read); | ||
} | ||
|
||
public static void cpy(InputStream in, Path out) throws IOException { | ||
try(OutputStream outS = new BufferedOutputStream(Files.newOutputStream(out))) { | ||
cpy(in, outS); | ||
} | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
src/main/java/agency/highlysuspect/minivan/prov/Unbundler.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,53 @@ | ||
package agency.highlysuspect.minivan.prov; | ||
|
||
|
||
import agency.highlysuspect.minivan.Util; | ||
import org.gradle.api.Project; | ||
|
||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipFile; | ||
|
||
public class Unbundler extends MiniProvider { | ||
public Unbundler(Project project, Path bundledJar, String unbundledJarName) { | ||
super(project); | ||
this.bundledJar = bundledJar; | ||
this.unbundledJarName = unbundledJarName; | ||
|
||
//cachebusting from before the unbundler existed | ||
props.set("unbundlerInPipeline", "true"); | ||
} | ||
|
||
final Path bundledJar; | ||
final String unbundledJarName; | ||
|
||
public Path unbundle() throws Exception { | ||
Path unbundled = getOrCreate(subst(unbundledJarName), unbundledJar -> { | ||
log.lifecycle("Unbundling {} to {}...", bundledJar, unbundledJar); | ||
|
||
try(ZipFile zf = new ZipFile(bundledJar.toFile())) { | ||
Optional<? extends ZipEntry> innerJar = zf.stream() | ||
.filter(e -> e.getName().startsWith("META-INF/versions/") && e.getName().endsWith(".jar")) | ||
.findFirst(); | ||
|
||
if(innerJar.isPresent()) { | ||
log.lifecycle("\\-> Found inner jar: {}", innerJar.get()); | ||
InputStream in = zf.getInputStream(innerJar.get()); | ||
Util.cpy(in, unbundledJar); | ||
} else { | ||
log.lifecycle("\\-> Did not find any inner jar to unbundle."); | ||
//No bundling | ||
//TODO dont copuy the jar if it doesn't need to be unbundled | ||
Files.copy(bundledJar, unbundledJar); | ||
} | ||
} | ||
}); | ||
|
||
log.info("unbundled: {}", unbundled); | ||
|
||
return unbundled; | ||
} | ||
} |