001 package org.apache.maven.scm.provider.accurev.util;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.io.File;
023 import java.io.IOException;
024
025 public class WorkspaceUtils
026 {
027 public static boolean isSameFile( File file1, String filename2)
028 {
029 return isSameFile( file1, filename2 == null ? null : new File( filename2 ) );
030
031 }
032
033 //We need to canonicalise the files (if we can) before we compare them..
034 public static boolean isSameFile( File file1, File file2 )
035 {
036
037 if ( file1 == file2 || ( file1 == null && file2 == null ) )
038 {
039 return true;
040 }
041
042 if ( file1 == null || file2 == null )
043 {
044 return false;
045 }
046
047 try
048 {
049 file1 = file1.getCanonicalFile();
050 }
051 catch ( IOException ioEx )
052 {
053 //Oh well, we'll compare the non-canonicalised file then.
054 }
055
056 try
057 {
058 file2 = file2.getCanonicalFile();
059 }
060 catch ( IOException ioEx )
061 {
062 //Oh well, we'll compare the non-canonicalised file then.
063 }
064 return file1.equals( file2 );
065 }
066
067 private WorkspaceUtils()
068 {
069 // no op only to prevents class creation
070 }
071 }