1
2
3
4
5
6
7 package net.alchim31.maven.yuicompressor;
8
9 import java.io.File;
10
11
12
13
14 public class SourceFile {
15
16
17 private File srcRoot;
18
19
20 private File destRoot;
21
22
23 private boolean destAsSource;
24
25
26 private String rpath;
27
28
29 private String extension;
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public SourceFile(File srcRoot, File destRoot, String name, boolean destAsSource) {
44 this.srcRoot = srcRoot;
45 this.destRoot = destRoot;
46 this.destAsSource = destAsSource;
47 this.rpath = name;
48 int sep = this.rpath.lastIndexOf('.');
49 if (sep > 0) {
50 this.extension = this.rpath.substring(sep);
51 this.rpath = rpath.substring(0, sep);
52 } else {
53 this.extension = "";
54 }
55 }
56
57
58
59
60
61
62 public File toFile() {
63 String frpath = rpath + extension;
64 if (destAsSource) {
65 File defaultDest = destRoot.toPath().resolve(frpath).toFile();
66 if (defaultDest.exists() && defaultDest.canRead()) {
67 return defaultDest;
68 }
69 }
70 return srcRoot.toPath().resolve(frpath).toFile();
71 }
72
73
74
75
76
77
78
79
80
81 public File toDestFile(String suffix) {
82 return destRoot.toPath().resolve(rpath + suffix + extension).toFile();
83 }
84
85
86
87
88
89
90 public String getExtension() {
91 return extension;
92 }
93 }