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