1package org.apache.archiva.common.utils;
23/*4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */2122import java.io.File;
23import java.net.URI;
2425/**26 * BaseFile - convenient File object that tracks the Base Directory and can provide relative path values27 * for the file object based on that Base Directory value.28 *29 *30 */31publicclassBaseFile32extends File
33 {
34private File baseDir;
3536publicBaseFile( File pathFile )
37 {
38this( pathFile.getAbsolutePath() );
39 }
4041publicBaseFile( File repoDir, File pathFile )
42 {
43this( repoDir, PathUtil.getRelative(repoDir.getAbsolutePath(), pathFile.toPath() ) );
44 }
4546publicBaseFile( File parent, String child )
47 {
48super( parent, child );
49this.baseDir = parent;
50 }
5152publicBaseFile( String pathname )
53 {
54super( pathname );
5556// Calculate the top level directory.5758 File parent = this;
59while ( parent.getParentFile() != null )
60 {
61 parent = parent.getParentFile();
62 }
6364this.baseDir = parent;
65 }
6667publicBaseFile( String repoDir, File pathFile )
68 {
69this( new File( repoDir ), pathFile );
70 }
7172publicBaseFile( String parent, String child )
73 {
74super( parent, child );
75this.baseDir = new File( parent );
76 }
7778publicBaseFile( URI uri )
79 {
80super( uri ); // only to satisfy java compiler.81thrownew IllegalStateException(
82"The " + BaseFile.class.getName() + " object does not support URI construction." );
83 }
8485public File getBaseDir()
86 {
87return baseDir;
88 }
8990public String getRelativePath()
91 {
92return PathUtil.getRelative( this.baseDir.getAbsolutePath(), this.toPath() );
93 }
9495publicvoid setBaseDir( File baseDir )
96 {
97this.baseDir = baseDir;
98 }
99100publicvoid setBaseDir( String repoDir )
101 {
102 setBaseDir( new File( repoDir ) );
103 }
104 }