1 package org.apache.maven.plugins.assembly.utils;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.codehaus.plexus.components.io.fileselectors.FileInfo;
23
24 import java.io.File;
25 import java.util.Locale;
26
27
28
29
30 public final class AssemblyFileUtils
31 {
32
33 private AssemblyFileUtils()
34 {
35
36 }
37
38 public static String makePathRelativeTo( String path, final File basedir )
39 {
40 if ( basedir == null )
41 {
42 return path;
43 }
44
45 if ( path == null )
46 {
47 return null;
48 }
49
50 path = path.trim();
51
52 String base = basedir.getAbsolutePath();
53 if ( path.startsWith( base ) )
54 {
55 path = path.substring( base.length() );
56 if ( path.length() > 0 )
57 {
58 if ( path.startsWith( "/" ) || path.startsWith( "\\" ) )
59 {
60 path = path.substring( 1 );
61 }
62 }
63
64 if ( path.length() == 0 )
65 {
66 path = ".";
67 }
68 }
69
70 if ( !new File( path ).isAbsolute() )
71 {
72 path = path.replace( '\\', '/' );
73 }
74
75 return path;
76 }
77
78 @SuppressWarnings( "ResultOfMethodCallIgnored" )
79 public static void verifyTempDirectoryAvailability( final File tempDir )
80 {
81 if ( !tempDir.exists() )
82 {
83 tempDir.mkdirs();
84 }
85 }
86
87 private static String normalizePath( String path )
88 {
89 return path.replace( '\\', '/' );
90 }
91
92 public static String normalizeFileInfo( FileInfo fileInfo )
93 {
94 String name = fileInfo.getName();
95 name = normalizePath( name );
96 return name.replace( File.separatorChar, '/' );
97 }
98
99 public static boolean isPropertyFile( String sourceName )
100 {
101 return sourceName.toLowerCase( Locale.ENGLISH ).endsWith( ".properties" );
102 }
103
104 public static boolean isPropertyFile( File file )
105 {
106 return isPropertyFile( file.getName() );
107 }
108
109
110
111
112
113
114
115
116 public static boolean isAbsolutePath( File dir )
117 {
118 return dir != null
119 && ( dir.isAbsolute()
120 || dir.getPath().startsWith( "\\" ) );
121 }
122 }