55package net .minecraftforge .gradlejarsigner ;
66
77import java .io .BufferedOutputStream ;
8+ import java .io .ByteArrayOutputStream ;
89import java .io .File ;
910import java .io .FileOutputStream ;
1011import java .io .IOException ;
2324import java .util .zip .ZipFile ;
2425
2526import org .gradle .api .Task ;
27+ import org .gradle .api .tasks .TaskInputs ;
2628import org .gradle .api .file .FileTreeElement ;
2729import org .gradle .api .file .FileVisitDetails ;
2830import org .gradle .api .file .FileVisitor ;
2931import org .gradle .api .file .RegularFileProperty ;
32+ import org .gradle .api .model .ObjectFactory ;
3033import org .gradle .api .provider .Property ;
3134import org .gradle .api .specs .Spec ;
3235import org .gradle .api .tasks .Internal ;
@@ -56,7 +59,7 @@ public class SignTask implements PatternFilterable {
5659 if (this .config != null )
5760 this .config .setDelegate (this );
5861
59- var objs = this .parent .getProject ().getObjects ();
62+ ObjectFactory objs = this .parent .getProject ().getObjects ();
6063
6164 this .alias = objs .property (String .class );
6265 this .storePass = objs .property (String .class );
@@ -77,7 +80,7 @@ public Object doCall() {
7780 }
7881
7982 private Object addProperties () {
80- var in = this .parent .getInputs ();
83+ TaskInputs in = this .parent .getInputs ();
8184 if (!patternSet .isEmpty ()) {
8285 in .property ("signJar.patternSet.excludes" , patternSet .getExcludes ());
8386 in .property ("signJar.patternSet.includes" , patternSet .getIncludes ());
@@ -110,12 +113,12 @@ private boolean hasEnoughInfo() {
110113 private <T extends Task > void sign (T task ) throws IOException {
111114 final Map <String , Entry <byte [], Long >> ignoredStuff = new HashMap <>();
112115
113- var tmp = this .parent .getTemporaryDir ();
114- var output = this .parent .getArchiveFile ().get ().getAsFile ();
115- var original = new File (tmp , output .getName () + ".original" );
116+ File tmp = this .parent .getTemporaryDir ();
117+ File output = this .parent .getArchiveFile ().get ().getAsFile ();
118+ File original = new File (tmp , output .getName () + ".original" );
116119 Files .move (output .toPath (), original .toPath (), StandardCopyOption .REPLACE_EXISTING );
117120
118- var input = original ;
121+ File input = original ;
119122 if (!patternSet .isEmpty ()) {
120123 input = new File (tmp , input .getName () + ".unsigned" );
121124 processInputJar (original , input , ignoredStuff );
@@ -129,14 +132,14 @@ private <T extends Task> void sign(T task) throws IOException {
129132 throw new IllegalStateException ("Both KeyStoreFile and KeyStoreData can not be set at the same time" );
130133 keyStore = this .keyStoreFile .get ().getAsFile ();
131134 } else if (this .keyStoreData .isPresent ()) {
132- var data = Base64 .getDecoder ().decode (this .keyStoreData .get ().getBytes (StandardCharsets .UTF_8 ));
135+ byte [] data = Base64 .getDecoder ().decode (this .keyStoreData .get ().getBytes (StandardCharsets .UTF_8 ));
133136 keyStore = new File (tmp , "keystore" );
134137 Files .write (keyStore .toPath (), data );
135138 } else {
136139 throw new IllegalArgumentException ("SignJar needs either a Base64 encoded KeyStore file, or a path to a KeyStore file" );
137140 }
138141
139- var map = new HashMap <String , String >();
142+ Map < String , String > map = new HashMap <>();
140143 map .put ("alias" , this .alias .get ());
141144 map .put ("storePass" , this .storePass .get ());
142145 map .put ("jar" , input .getAbsolutePath ());
@@ -157,10 +160,10 @@ private <T extends Task> void sign(T task) throws IOException {
157160 }
158161
159162 private void processInputJar (File input , File output , final Map <String , Entry <byte [], Long >> unsigned ) throws IOException {
160- var spec = patternSet .getAsSpec ();
163+ final Spec < FileTreeElement > spec = patternSet .getAsSpec ();
161164
162165 output .getParentFile ().mkdirs ();
163- try (var outs = new JarOutputStream (new BufferedOutputStream (new FileOutputStream (output )))){
166+ try (JarOutputStream outs = new JarOutputStream (new BufferedOutputStream (new FileOutputStream (output )))){
164167 this .parent .getProject ().zipTree (input ).visit (new FileVisitor () {
165168 @ Override
166169 public void visitDir (FileVisitDetails details ) {
@@ -185,7 +188,13 @@ public void visitFile(FileVisitDetails details) {
185188 outs .closeEntry ();
186189 } else {
187190 InputStream stream = details .open ();
188- var data = stream .readAllBytes ();
191+ ByteArrayOutputStream tmp = new ByteArrayOutputStream (stream .available ());
192+ byte [] buf = new byte [0x100 ];
193+ int len ;
194+ while ((len = stream .read (buf )) != -1 )
195+ tmp .write (buf , 0 , len );
196+
197+ byte [] data = tmp .toByteArray ();
189198 unsigned .put (details .getPath (), new MapEntry (data , details .getLastModified ()));
190199 stream .close ();
191200 }
@@ -202,6 +211,7 @@ private void writeOutputJar(File signedJar, File outputJar, Map<String, Entry<by
202211
203212 JarOutputStream outs = new JarOutputStream (new BufferedOutputStream (new FileOutputStream (outputJar )));
204213
214+ byte [] buf = new byte [0x100 ];
205215 ZipFile base = new ZipFile (signedJar );
206216 for (ZipEntry e : Collections .list (base .entries ())) {
207217 if (e .isDirectory ()) {
@@ -210,7 +220,10 @@ private void writeOutputJar(File signedJar, File outputJar, Map<String, Entry<by
210220 ZipEntry n = new ZipEntry (e .getName ());
211221 n .setTime (e .getTime ());
212222 outs .putNextEntry (n );
213- base .getInputStream (e ).transferTo (outs );
223+ InputStream in = base .getInputStream (e );
224+ int len ;
225+ while ((len = in .read (buf )) != -1 )
226+ outs .write (buf , 0 , len );
214227 outs .closeEntry ();
215228 }
216229 }
0 commit comments