Skip to content

Commit e07f385

Browse files
committed
fixed ForgeGradle for Gradle 1.12
1 parent 2a65ee4 commit e07f385

File tree

1 file changed

+90
-2
lines changed

1 file changed

+90
-2
lines changed

src/main/java/net/minecraftforge/gradle/ZipFileTree.java

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
package net.minecraftforge.gradle;
1818

1919
import java.io.File;
20+
import java.io.FileOutputStream;
2021
import java.io.IOException;
2122
import java.io.InputStream;
23+
import java.io.OutputStream;
2224
import java.util.Enumeration;
2325
import java.util.Iterator;
2426
import java.util.Map;
@@ -27,15 +29,16 @@
2729
import java.util.zip.ZipEntry;
2830
import java.util.zip.ZipFile;
2931

32+
import org.apache.commons.io.IOUtils;
3033
import org.gradle.api.GradleException;
3134
import org.gradle.api.InvalidUserDataException;
3235
import org.gradle.api.UncheckedIOException;
3336
import org.gradle.api.file.FileVisitDetails;
3437
import org.gradle.api.file.FileVisitor;
3538
import org.gradle.api.file.RelativePath;
36-
import org.gradle.api.internal.file.AbstractFileTreeElement;
3739
import org.gradle.api.internal.file.collections.MinimalFileTree;
3840
import org.gradle.util.DeprecationLogger;
41+
import org.gradle.util.GFileUtils;
3942

4043
public class ZipFileTree implements MinimalFileTree
4144
{
@@ -106,7 +109,7 @@ public void visit(FileVisitor visitor)
106109
}
107110
}
108111

109-
private class DetailsImpl extends AbstractFileTreeElement implements FileVisitDetails
112+
private class DetailsImpl implements FileVisitDetails
110113
{
111114
private final ZipEntry entry;
112115
private final ZipFile zip;
@@ -175,5 +178,90 @@ public RelativePath getRelativePath()
175178
{
176179
return new RelativePath(!entry.isDirectory(), entry.getName().split("/"));
177180
}
181+
182+
// Stuff below this line was --------------------------------------------------
183+
// Stolen from Gradle's org.gradle.api.internal.file.AbstractFileTreeElement
184+
185+
public String toString()
186+
{
187+
return getDisplayName();
188+
}
189+
190+
public String getName()
191+
{
192+
return getRelativePath().getLastName();
193+
}
194+
195+
public String getPath()
196+
{
197+
return getRelativePath().getPathString();
198+
}
199+
200+
public void copyTo(OutputStream outstr)
201+
{
202+
try
203+
{
204+
InputStream inputStream = open();
205+
try
206+
{
207+
IOUtils.copyLarge(inputStream, outstr);
208+
}
209+
finally
210+
{
211+
inputStream.close();
212+
}
213+
}
214+
catch (IOException e)
215+
{
216+
throw new UncheckedIOException(e);
217+
}
218+
}
219+
220+
public boolean copyTo(File target)
221+
{
222+
validateTimeStamps();
223+
try
224+
{
225+
if (isDirectory())
226+
{
227+
GFileUtils.mkdirs(target);
228+
}
229+
else
230+
{
231+
GFileUtils.mkdirs(target.getParentFile());
232+
copyFile(target);
233+
}
234+
return true;
235+
}
236+
catch (Exception e)
237+
{
238+
throw new GradleException(String.format("Could not copy %s to '%s'.", new Object[] { getDisplayName(), target }), e);
239+
}
240+
}
241+
242+
private void validateTimeStamps()
243+
{
244+
long lastModified = getLastModified();
245+
if (lastModified < 0L)
246+
throw new GradleException(String.format("Invalid Timestamp %s for '%s'.", new Object[] { Long.valueOf(lastModified), getDisplayName() }));
247+
}
248+
249+
private void copyFile(File target) throws IOException
250+
{
251+
FileOutputStream outputStream = new FileOutputStream(target);
252+
try
253+
{
254+
copyTo(outputStream);
255+
}
256+
finally
257+
{
258+
outputStream.close();
259+
}
260+
}
261+
262+
public int getMode()
263+
{
264+
return ((isDirectory()) ? 493 : 420);
265+
}
178266
}
179267
}

0 commit comments

Comments
 (0)