1 package org.apache.maven.plugins.assembly.io;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.net.URL;
25
26 import org.apache.commons.io.IOUtils;
27
28 /**
29 * The URL Location.
30 *
31 */
32 class URLLocation
33 extends FileLocation
34 {
35
36 private final URL url;
37
38 private final String tempFilePrefix;
39
40 private final String tempFileSuffix;
41
42 private final boolean tempFileDeleteOnExit;
43
44 /**
45 * @param url the URL
46 * @param specification the spec
47 * @param tempFilePrefix the prefix
48 * @param tempFileSuffix the suffix
49 * @param tempFileDeleteOnExit delete on exit
50 */
51 URLLocation( URL url, String specification, String tempFilePrefix, String tempFileSuffix,
52 boolean tempFileDeleteOnExit )
53 {
54 super( specification );
55
56 this.url = url;
57 this.tempFilePrefix = tempFilePrefix;
58 this.tempFileSuffix = tempFileSuffix;
59 this.tempFileDeleteOnExit = tempFileDeleteOnExit;
60 }
61
62 @Override
63 protected void initFile()
64 throws IOException
65 {
66 if ( unsafeGetFile() == null )
67 {
68 File tempFile = File.createTempFile( tempFilePrefix, tempFileSuffix );
69
70 if ( tempFileDeleteOnExit )
71 {
72 tempFile.deleteOnExit();
73 }
74
75 IOUtils.copy( url, tempFile );
76
77 setFile( tempFile );
78 }
79 }
80
81 }