Skip to content
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

Fix build on Windows OS #3882

Merged
merged 2 commits into from
Feb 14, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.URI;
Expand Down Expand Up @@ -131,61 +132,55 @@ public class JakartaTransformer {
* Extracts Jar into temp directory
*
*/
private static void extract(String inPath, String outPath) throws Exception {

Path target = Paths.get(outPath);
Path source = Paths.get(inPath);

try (ZipInputStream zis = new ZipInputStream(new FileInputStream(source.toFile()))) {

// list files in zip
ZipEntry zipEntry = zis.getNextEntry();

while (zipEntry != null) {

boolean isDirectory = false;

if (zipEntry.getName().endsWith(File.separator)) {
isDirectory = true;
}

Path targetDirResolved = target.resolve(zipEntry.getName());

Path normalizePath = targetDirResolved.normalize();
if (!normalizePath.startsWith(target)) {
throw new IOException("Bad zip entry: " + zipEntry.getName());
}

Path newPath = normalizePath;

if (isDirectory) {
Files.createDirectories(newPath);
} else {
if (newPath.getParent() != null) {
if (Files.notExists(newPath.getParent())) {
Files.createDirectories(newPath.getParent());
}
}
Files.copy(zis, newPath, StandardCopyOption.REPLACE_EXISTING);
}

zipEntry = zis.getNextEntry();

}
zis.closeEntry();

}
}
private static void extract(String inPath, String outPath) throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would use spaces instead of tabs..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, fixed it. In my defense the formatters in the Coding-Standards give me 404s.


Path target = Paths.get(outPath);
Path source = Paths.get(inPath);

try (ZipInputStream zis = new ZipInputStream(new FileInputStream(source.toFile()))) {
ZipEntry zipEntry = zis.getNextEntry();

while (zipEntry != null) {
Path path = target.resolve(zipEntry.getName()).normalize();

if (!path.startsWith(target + File.separator)) {
throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
}

if (zipEntry.isDirectory()) {
if (!Files.isDirectory(path)) {
Files.createDirectories(path);
}
} else {
// fix for Windows-created archives
Path parent = path.getParent();
if (!Files.isDirectory(parent)) {
Files.createDirectories(parent);
}

// write file content
try (OutputStream os = Files.newOutputStream(path)) {
byte[] buffer = new byte[1024];
int len;
while ((len = zis.read(buffer)) > 0) {
os.write(buffer, 0, len);
}
}
}
zipEntry = zis.getNextEntry();
}
zis.closeEntry();
}
}

/**
*
* Compress temp directory back into Jar after transformed
*
*/

public static void jar(Path sourcePath, String outJarPath) throws IOException {

URI uri = URI.create("jar:file:" + outJarPath);
URI uri = URI.create("jar:" + Paths.get(outJarPath).normalize().toUri());

Files.walkFileTree(sourcePath, new SimpleFileVisitor<Path>() {
@Override
Expand Down