1 package org.apache.archiva.common.utils;
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.net.URI;
24
25
26
27
28
29
30
31 public class BaseFile
32 extends File
33 {
34 private File baseDir;
35
36 public BaseFile( File pathFile )
37 {
38 this( pathFile.getAbsolutePath() );
39 }
40
41 public BaseFile( File repoDir, File pathFile )
42 {
43 this( repoDir, PathUtil.getRelative( repoDir.getAbsolutePath(), pathFile ) );
44 }
45
46 public BaseFile( File parent, String child )
47 {
48 super( parent, child );
49 this.baseDir = parent;
50 }
51
52 public BaseFile( String pathname )
53 {
54 super( pathname );
55
56
57
58 File parent = this;
59 while ( parent.getParentFile() != null )
60 {
61 parent = parent.getParentFile();
62 }
63
64 this.baseDir = parent;
65 }
66
67 public BaseFile( String repoDir, File pathFile )
68 {
69 this( new File( repoDir ), pathFile );
70 }
71
72 public BaseFile( String parent, String child )
73 {
74 super( parent, child );
75 this.baseDir = new File( parent );
76 }
77
78 public BaseFile( URI uri )
79 {
80 super( uri );
81 throw new IllegalStateException(
82 "The " + BaseFile.class.getName() + " object does not support URI construction." );
83 }
84
85 public File getBaseDir()
86 {
87 return baseDir;
88 }
89
90 public String getRelativePath()
91 {
92 return PathUtil.getRelative( this.baseDir.getAbsolutePath(), this );
93 }
94
95 public void setBaseDir( File baseDir )
96 {
97 this.baseDir = baseDir;
98 }
99
100 public void setBaseDir( String repoDir )
101 {
102 setBaseDir( new File( repoDir ) );
103 }
104 }