1 package org.apache.maven.plugins.assembly.io;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.net.URL;
25 import java.nio.file.Files;
26
27 import org.apache.commons.io.IOUtils;
28
29
30
31
32
33 class URLLocation
34 extends FileLocation
35 {
36
37 private final URL url;
38
39 private final String tempFilePrefix;
40
41 private final String tempFileSuffix;
42
43 private final boolean tempFileDeleteOnExit;
44
45
46
47
48
49
50
51
52 URLLocation( URL url, String specification, String tempFilePrefix, String tempFileSuffix,
53 boolean tempFileDeleteOnExit )
54 {
55 super( specification );
56
57 this.url = url;
58 this.tempFilePrefix = tempFilePrefix;
59 this.tempFileSuffix = tempFileSuffix;
60 this.tempFileDeleteOnExit = tempFileDeleteOnExit;
61 }
62
63 @Override
64 protected void initFile()
65 throws IOException
66 {
67 if ( unsafeGetFile() == null )
68 {
69 File tempFile = Files.createTempFile( tempFilePrefix, tempFileSuffix ).toFile();
70
71 if ( tempFileDeleteOnExit )
72 {
73 tempFile.deleteOnExit();
74 }
75
76 IOUtils.copy( url, tempFile );
77
78 setFile( tempFile );
79 }
80 }
81
82 }