1 package org.apache.archiva.common.utils;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
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.
36 public BaseFile( File pathFile )
38 this( pathFile.getAbsolutePath() );
41 public BaseFile( File repoDir, File pathFile )
43 this( repoDir, PathUtil.getRelative( repoDir.getAbsolutePath(), pathFile ) );
46 public BaseFile( File parent, String child )
48 super( parent, child );
49 this.baseDir = parent;
52 public BaseFile( String pathname )
56 // Calculate the top level directory.
59 while ( parent.getParentFile() != null )
61 parent = parent.getParentFile();
64 this.baseDir = parent;
67 public BaseFile( String repoDir, File pathFile )
69 this( new File( repoDir ), pathFile );
72 public BaseFile( String parent, String child )
74 super( parent, child );
75 this.baseDir = new File( parent );
78 public BaseFile( URI uri )
80 super( uri ); // only to satisfy java compiler.
81 throw new IllegalStateException( "The " + BaseFile.class.getName()
82 + " object does not support URI construction." );
85 public File getBaseDir()
90 public String getRelativePath()
92 return PathUtil.getRelative( this.baseDir.getAbsolutePath(), this );
95 public void setBaseDir( File baseDir )
97 this.baseDir = baseDir;
100 public void setBaseDir( String repoDir )
102 setBaseDir( new File( repoDir ) );