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 javax.annotation.Nonnull;
25 import java.io.File;
26 import java.util.Locale;
27
28
29
30
31 public final class AssemblyFileUtils
32 {
33
34 private AssemblyFileUtils()
35 {
36
37 }
38
39 public static String makePathRelativeTo( String path, final File basedir )
40 {
41 if ( basedir == null )
42 {
43 return path;
44 }
45
46 if ( path == null )
47 {
48 return null;
49 }
50
51 path = path.trim();
52
53 String base = basedir.getAbsolutePath();
54 if ( path.startsWith( base ) )
55 {
56 path = path.substring( base.length() );
57 if ( path.length() > 0 )
58 {
59 if ( path.startsWith( "/" ) || path.startsWith( "\\" ) )
60 {
61 path = path.substring( 1 );
62 }
63 }
64
65 if ( path.length() == 0 )
66 {
67 path = ".";
68 }
69 }
70
71 if ( !new File( path ).isAbsolute() )
72 {
73 path = path.replace( '\\', '/' );
74 }
75
76 return path;
77 }
78
79 @SuppressWarnings( "ResultOfMethodCallIgnored" )
80 public static void verifyTempDirectoryAvailability( @Nonnull final File tempDir )
81 {
82 if ( !tempDir.exists() )
83 {
84 tempDir.mkdirs();
85 }
86 }
87
88 @Nonnull
89 private static String normalizePath( @Nonnull String path )
90 {
91 return path.replace( '\\', '/' );
92 }
93
94 @Nonnull
95 public static String normalizeFileInfo( @Nonnull FileInfo fileInfo )
96 {
97 String name = fileInfo.getName();
98 name = normalizePath( name );
99 return name.replace( File.separatorChar, '/' );
100 }
101
102 public static boolean isPropertyFile( String sourceName )
103 {
104 return sourceName.toLowerCase( Locale.ENGLISH ).endsWith( ".properties" );
105 }
106
107 public static boolean isPropertyFile( File file )
108 {
109 return isPropertyFile( file.getName() );
110 }
111
112
113
114
115
116
117
118
119 public static boolean isAbsolutePath( File dir )
120 {
121 return dir != null
122 && ( dir.isAbsolute()
123 || dir.getPath().startsWith( "\\" ) );
124 }
125 }