Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BaseFile |
|
| 1.1818181818181819;1.182 |
1 | package org.apache.maven.archiva.common.utils; | |
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.net.URI; | |
24 | ||
25 | /** | |
26 | * BaseFile - convenient File object that tracks the Base Directory and can provide relative path values | |
27 | * for the file object based on that Base Directory value. | |
28 | * | |
29 | * @version $Id: BaseFile.java 718864 2008-11-19 06:33:35Z brett $ | |
30 | */ | |
31 | public class BaseFile | |
32 | extends File | |
33 | { | |
34 | private File baseDir; | |
35 | ||
36 | public BaseFile( File pathFile ) | |
37 | { | |
38 | 0 | this( pathFile.getAbsolutePath() ); |
39 | 0 | } |
40 | ||
41 | public BaseFile( File repoDir, File pathFile ) | |
42 | { | |
43 | 0 | this( repoDir, PathUtil.getRelative( repoDir.getAbsolutePath(), pathFile ) ); |
44 | 0 | } |
45 | ||
46 | public BaseFile( File parent, String child ) | |
47 | { | |
48 | 0 | super( parent, child ); |
49 | 0 | this.baseDir = parent; |
50 | 0 | } |
51 | ||
52 | public BaseFile( String pathname ) | |
53 | { | |
54 | 0 | super( pathname ); |
55 | ||
56 | // Calculate the top level directory. | |
57 | ||
58 | 0 | File parent = this; |
59 | 0 | while ( parent.getParentFile() != null ) |
60 | { | |
61 | 0 | parent = parent.getParentFile(); |
62 | } | |
63 | ||
64 | 0 | this.baseDir = parent; |
65 | 0 | } |
66 | ||
67 | public BaseFile( String repoDir, File pathFile ) | |
68 | { | |
69 | 0 | this( new File( repoDir ), pathFile ); |
70 | 0 | } |
71 | ||
72 | public BaseFile( String parent, String child ) | |
73 | { | |
74 | 0 | super( parent, child ); |
75 | 0 | this.baseDir = new File( parent ); |
76 | 0 | } |
77 | ||
78 | public BaseFile( URI uri ) | |
79 | { | |
80 | 0 | super( uri ); // only to satisfy java compiler. |
81 | 0 | throw new IllegalStateException( "The " + BaseFile.class.getName() |
82 | + " object does not support URI construction." ); | |
83 | } | |
84 | ||
85 | public File getBaseDir() | |
86 | { | |
87 | 0 | return baseDir; |
88 | } | |
89 | ||
90 | public String getRelativePath() | |
91 | { | |
92 | 0 | return PathUtil.getRelative( this.baseDir.getAbsolutePath(), this ); |
93 | } | |
94 | ||
95 | public void setBaseDir( File baseDir ) | |
96 | { | |
97 | 0 | this.baseDir = baseDir; |
98 | 0 | } |
99 | ||
100 | public void setBaseDir( String repoDir ) | |
101 | { | |
102 | 0 | setBaseDir( new File( repoDir ) ); |
103 | 0 | } |
104 | } |