| 1 |
package org.apache.maven.shared.io.location; |
| 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.maven.shared.utils.io.FileUtils; |
| 27 |
|
| 28 |
/** |
| 29 |
* The URL Location. |
| 30 |
* |
| 31 |
*/ |
| 32 |
public 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 |
public 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 |
/** {@inheritDoc} */ |
| 63 |
protected void initFile() |
| 64 |
throws IOException |
| 65 |
{ |
| 66 |
// TODO: Log this in the debug log-level... |
| 67 |
if ( unsafeGetFile() == null ) |
| 68 |
{ |
| 69 |
File tempFile = File.createTempFile( tempFilePrefix, tempFileSuffix ); |
| 70 |
|
| 71 |
if ( tempFileDeleteOnExit ) |
| 72 |
{ |
| 73 |
tempFile.deleteOnExit(); |
| 74 |
} |
| 75 |
|
| 76 |
FileUtils.copyURLToFile( url, tempFile ); |
| 77 |
|
| 78 |
setFile( tempFile ); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
} |