|
17 | 17 | package net.minecraftforge.gradle; |
18 | 18 |
|
19 | 19 | import java.io.File; |
| 20 | +import java.io.FileOutputStream; |
20 | 21 | import java.io.IOException; |
21 | 22 | import java.io.InputStream; |
| 23 | +import java.io.OutputStream; |
22 | 24 | import java.util.Enumeration; |
23 | 25 | import java.util.Iterator; |
24 | 26 | import java.util.Map; |
|
27 | 29 | import java.util.zip.ZipEntry; |
28 | 30 | import java.util.zip.ZipFile; |
29 | 31 |
|
| 32 | +import org.apache.commons.io.IOUtils; |
30 | 33 | import org.gradle.api.GradleException; |
31 | 34 | import org.gradle.api.InvalidUserDataException; |
32 | 35 | import org.gradle.api.UncheckedIOException; |
33 | 36 | import org.gradle.api.file.FileVisitDetails; |
34 | 37 | import org.gradle.api.file.FileVisitor; |
35 | 38 | import org.gradle.api.file.RelativePath; |
36 | | -import org.gradle.api.internal.file.AbstractFileTreeElement; |
37 | 39 | import org.gradle.api.internal.file.collections.MinimalFileTree; |
38 | 40 | import org.gradle.util.DeprecationLogger; |
| 41 | +import org.gradle.util.GFileUtils; |
39 | 42 |
|
40 | 43 | public class ZipFileTree implements MinimalFileTree |
41 | 44 | { |
@@ -106,7 +109,7 @@ public void visit(FileVisitor visitor) |
106 | 109 | } |
107 | 110 | } |
108 | 111 |
|
109 | | - private class DetailsImpl extends AbstractFileTreeElement implements FileVisitDetails |
| 112 | + private class DetailsImpl implements FileVisitDetails |
110 | 113 | { |
111 | 114 | private final ZipEntry entry; |
112 | 115 | private final ZipFile zip; |
@@ -175,5 +178,90 @@ public RelativePath getRelativePath() |
175 | 178 | { |
176 | 179 | return new RelativePath(!entry.isDirectory(), entry.getName().split("/")); |
177 | 180 | } |
| 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 | + } |
178 | 266 | } |
179 | 267 | } |
0 commit comments