Skip to content

Commit

Permalink
Downgrade to java 8
Browse files Browse the repository at this point in the history
  • Loading branch information
LexManos committed Jul 27, 2023
1 parent 3a4a6ba commit d0ba2a2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repositories {
}

group = 'net.minecraftforge'
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
java.toolchain.languageVersion = JavaLanguageVersion.of(8)
java.withSourcesJar()
jarSigner.fromEnvironmentVariables()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void fill(SignTask task) {
}

private void set(String key, Consumer<String> prop) {
var data = System.getenv(key);
String data = System.getenv(key);
if (data != null)
prop.accept(data);
else
Expand Down
37 changes: 25 additions & 12 deletions src/main/java/net/minecraftforge/gradlejarsigner/SignTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package net.minecraftforge.gradlejarsigner;

import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -23,10 +24,12 @@
import java.util.zip.ZipFile;

import org.gradle.api.Task;
import org.gradle.api.tasks.TaskInputs;
import org.gradle.api.file.FileTreeElement;
import org.gradle.api.file.FileVisitDetails;
import org.gradle.api.file.FileVisitor;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.Internal;
Expand Down Expand Up @@ -56,7 +59,7 @@ public class SignTask implements PatternFilterable {
if (this.config != null)
this.config.setDelegate(this);

var objs = this.parent.getProject().getObjects();
ObjectFactory objs = this.parent.getProject().getObjects();

this.alias = objs.property(String.class);
this.storePass = objs.property(String.class);
Expand All @@ -77,7 +80,7 @@ public Object doCall() {
}

private Object addProperties() {
var in = this.parent.getInputs();
TaskInputs in = this.parent.getInputs();
if (!patternSet.isEmpty()) {
in.property("signJar.patternSet.excludes", patternSet.getExcludes());
in.property("signJar.patternSet.includes", patternSet.getIncludes());
Expand Down Expand Up @@ -110,12 +113,12 @@ private boolean hasEnoughInfo() {
private <T extends Task> void sign(T task) throws IOException {
final Map<String, Entry<byte[], Long>> ignoredStuff = new HashMap<>();

var tmp = this.parent.getTemporaryDir();
var output = this.parent.getArchiveFile().get().getAsFile();
var original = new File(tmp, output.getName() + ".original");
File tmp = this.parent.getTemporaryDir();
File output = this.parent.getArchiveFile().get().getAsFile();
File original = new File(tmp, output.getName() + ".original");
Files.move(output.toPath(), original.toPath(), StandardCopyOption.REPLACE_EXISTING);

var input = original;
File input = original;
if (!patternSet.isEmpty()) {
input = new File(tmp, input.getName() + ".unsigned");
processInputJar(original, input, ignoredStuff);
Expand All @@ -129,14 +132,14 @@ private <T extends Task> void sign(T task) throws IOException {
throw new IllegalStateException("Both KeyStoreFile and KeyStoreData can not be set at the same time");
keyStore = this.keyStoreFile.get().getAsFile();
} else if (this.keyStoreData.isPresent()) {
var data = Base64.getDecoder().decode(this.keyStoreData.get().getBytes(StandardCharsets.UTF_8));
byte[] data = Base64.getDecoder().decode(this.keyStoreData.get().getBytes(StandardCharsets.UTF_8));
keyStore = new File(tmp, "keystore");
Files.write(keyStore.toPath(), data);
} else {
throw new IllegalArgumentException("SignJar needs either a Base64 encoded KeyStore file, or a path to a KeyStore file");
}

var map = new HashMap<String, String>();
Map<String, String> map = new HashMap<>();
map.put("alias", this.alias.get());
map.put("storePass", this.storePass.get());
map.put("jar", input.getAbsolutePath());
Expand All @@ -157,10 +160,10 @@ private <T extends Task> void sign(T task) throws IOException {
}

private void processInputJar(File input, File output, final Map<String, Entry<byte[], Long>> unsigned) throws IOException {
var spec = patternSet.getAsSpec();
final Spec<FileTreeElement> spec = patternSet.getAsSpec();

output.getParentFile().mkdirs();
try (var outs = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(output)))){
try (JarOutputStream outs = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(output)))){
this.parent.getProject().zipTree(input).visit(new FileVisitor() {
@Override
public void visitDir(FileVisitDetails details) {
Expand All @@ -185,7 +188,13 @@ public void visitFile(FileVisitDetails details) {
outs.closeEntry();
} else {
InputStream stream = details.open();
var data = stream.readAllBytes();
ByteArrayOutputStream tmp = new ByteArrayOutputStream(stream.available());
byte[] buf = new byte[0x100];
int len;
while ((len = stream.read(buf)) != -1)
tmp.write(buf, 0, len);

byte[] data = tmp.toByteArray();
unsigned.put(details.getPath(), new MapEntry(data, details.getLastModified()));
stream.close();
}
Expand All @@ -202,6 +211,7 @@ private void writeOutputJar(File signedJar, File outputJar, Map<String, Entry<by

JarOutputStream outs = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(outputJar)));

byte[] buf = new byte[0x100];
ZipFile base = new ZipFile(signedJar);
for (ZipEntry e : Collections.list(base.entries())) {
if (e.isDirectory()) {
Expand All @@ -210,7 +220,10 @@ private void writeOutputJar(File signedJar, File outputJar, Map<String, Entry<by
ZipEntry n = new ZipEntry(e.getName());
n.setTime(e.getTime());
outs.putNextEntry(n);
base.getInputStream(e).transferTo(outs);
InputStream in = base.getInputStream(e);
int len;
while ((len = in.read(buf)) != -1)
outs.write(buf, 0, len);
outs.closeEntry();
}
}
Expand Down

0 comments on commit d0ba2a2

Please sign in to comment.