Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.esotericsoftware.filesystem;

import com.esotericsoftware.scar.*;

import java.io.*;

public final class FilePath
{
    private final File mSomeParentDir;
    private final String mFileSubPath;
    private final File mCanonicalPath;

    private FilePath( File pSomeParentDir, String pFileSubPath, File pCanonicalPath )
    {
        mSomeParentDir = pSomeParentDir;
        mFileSubPath = pFileSubPath;
        mCanonicalPath = pCanonicalPath;
    }

    public FilePath( File pSomeParentDir, String pFileSubPath )
    {
        this( pSomeParentDir, pFileSubPath, Utils.canonical( new File( pSomeParentDir, pFileSubPath ) ) );
    }

    public static FilePath canonical( File pSomeParentDir, String pFileSubPath )
    {
        return new FilePath( pSomeParentDir, pFileSubPath, new File( pSomeParentDir, pFileSubPath ) );
    }

    private static FilePath innerAlreadyCanonical( File pFilePath )
    {
        return new FilePath( pFilePath.getParentFile(), pFilePath.getName(), pFilePath );
    }

    public static FilePath canonicalize( File pFilePath )
    {
        return innerAlreadyCanonical( Utils.canonical( pFilePath ) );
    }

    public File getSomeParentDir()
    {
        return mSomeParentDir;
    }

    public String getFileSubPath()
    {
        return mFileSubPath;
    }

    public String canonical()
    {
        return mCanonicalPath.getPath();
    }

    public File file()
    {
        return mCanonicalPath;
    }

    public String relativeFromDir(File pCanonicalJarDir)
    {
        File zCommonDirPath = Utils.findCommonDirPathFromCanonicalDirPaths(pCanonicalJarDir, mCanonicalPath.getParentFile());
        if ( zCommonDirPath == null )
        {
            throw new IllegalStateException( "Unable to create Relative path from '" + pCanonicalJarDir + "' to: " + this );
        }
        String zJarDir = normalize(pCanonicalJarDir, zCommonDirPath);
        String zFilePath = normalize(mCanonicalPath, zCommonDirPath);
        while ( zJarDir.length() != 0 )
        {
            zFilePath = "../" + zFilePath;
            int zAt = zJarDir.lastIndexOf("/");
            if ( zAt == -1 )
            {
                zJarDir = "";
            }
            else
            {
                zJarDir = zJarDir.substring(0,zAt);
            }
        }
        return zFilePath;
    }

    private String normalize(File pPath, File pCommonDirPath) {
        String zPath = pPath.getPath().substring(pCommonDirPath.getPath().length()).replace('\\', '/');
        return zPath.startsWith("/") ? zPath.substring(1) : zPath;
    }

    public boolean equals( FilePath them )
    {
        return this == them || ((them != null) && this.canonical().equals( them.canonical() ));
    }

    @Override
    public boolean equals( Object obj )
    {
        return (this == obj) || ((obj instanceof FilePath) && equals( (FilePath) obj ));
    }

    @Override
    public int hashCode()
    {
        return canonical().hashCode();
    }

    @Override
    public String toString()
    {
        return canonical();
    }
}

Commits for litesoft/trunk/Java/ScarPlus/src/com/esotericsoftware/filesystem/FilePath.java

Diff revisions: vs.
Revision Author Commited Message
943 Diff Diff GeorgeS picture GeorgeS Tue 03 Jun, 2014 04:25:50 +0000

Extracting commonfoundation

889 Diff Diff GeorgeS picture GeorgeS Tue 18 Dec, 2012 00:21:56 +0000

Correct Relative Path for JARing

361 Diff Diff GeorgeS picture GeorgeS Mon 08 Aug, 2011 01:34:17 +0000
313 Diff Diff GeorgeS picture GeorgeS Wed 13 Jul, 2011 20:17:30 +0000
302 GeorgeS picture GeorgeS Fri 08 Jul, 2011 14:08:10 +0000