|
@@ -120,13 +120,58 @@ |
120 |
120 |
|
Paths newPaths = new Paths(); |
121 |
121 |
|
for ( FilePath path : getPaths() ) { |
122 |
122 |
|
String zSubPath = path.getFileSubPath(); |
123 |
|
- |
FileUtil.copyFile( path.file(), new File( destDir, zSubPath ) ); |
|
123 |
+ |
FileUtils.copyFile( path.file(), new File( destDir, zSubPath ) ); |
124 |
124 |
|
newPaths.mPaths.add( new FilePath( zDest, zSubPath ) ); |
125 |
125 |
|
} |
126 |
126 |
|
return newPaths; |
127 |
127 |
|
} |
128 |
128 |
|
|
129 |
129 |
|
/** |
|
130 |
+ |
* Updates the files and directories of the specified directory to match 'this' paths. |
|
131 |
+ |
* |
|
132 |
+ |
* @return A paths object containing the paths of the new files. |
|
133 |
+ |
*/ |
|
134 |
+ |
@SuppressWarnings({"ResultOfMethodCallIgnored"}) |
|
135 |
+ |
public Paths update( String destDir ) { |
|
136 |
+ |
File zDest = new File( destDir ); |
|
137 |
+ |
if ( !zDest.isDirectory() ) { |
|
138 |
+ |
return copyTo( destDir ); |
|
139 |
+ |
} |
|
140 |
+ |
Paths zExistingPaths = new Paths(); |
|
141 |
+ |
zExistingPaths.glob( destDir, "**" ); |
|
142 |
+ |
if ( zExistingPaths.isEmpty() ) { |
|
143 |
+ |
return copyTo( destDir ); |
|
144 |
+ |
} |
|
145 |
+ |
Paths newPaths = new Paths(); |
|
146 |
+ |
|
|
147 |
+ |
Map<String, File> zDesired = toMap( this ); |
|
148 |
+ |
Map<String, File> zExisting = toMap( zExistingPaths ); |
|
149 |
+ |
for ( Map.Entry<String, File> zEntry : zDesired.entrySet() ) { |
|
150 |
+ |
String zSubPath = zEntry.getKey(); |
|
151 |
+ |
File zDesiredFile = zEntry.getValue(); |
|
152 |
+ |
File zExistingFile = zExisting.remove( zSubPath ); |
|
153 |
+ |
if ( zExistingFile == null ) { |
|
154 |
+ |
FileUtils.copyFile( zDesiredFile, new File( destDir, zSubPath ) ); |
|
155 |
+ |
} else { |
|
156 |
+ |
FileUtils.updateFile( zDesiredFile, zExistingFile ); |
|
157 |
+ |
} |
|
158 |
+ |
newPaths.mPaths.add( new FilePath( zDest, zSubPath ) ); |
|
159 |
+ |
} |
|
160 |
+ |
for ( File zFile : zExisting.values() ) { |
|
161 |
+ |
FileUtils.delete( zFile ); |
|
162 |
+ |
} |
|
163 |
+ |
return newPaths; |
|
164 |
+ |
} |
|
165 |
+ |
|
|
166 |
+ |
private static Map<String, File> toMap( Paths pPaths ) { |
|
167 |
+ |
HashMap<String, File> zMap = new HashMap<String, File>(); |
|
168 |
+ |
for ( FilePath path : pPaths.getPaths() ) { |
|
169 |
+ |
zMap.put( path.getFileSubPath(), path.file() ); |
|
170 |
+ |
} |
|
171 |
+ |
return zMap; |
|
172 |
+ |
} |
|
173 |
+ |
|
|
174 |
+ |
/** |
130 |
175 |
|
* Compresses the files and directories specified by the paths into a new zip file at the specified location. If there are no |
131 |
176 |
|
* paths or all the paths are directories, no zip file will be created. |
132 |
177 |
|
* |
|
@@ -146,23 +191,23 @@ |
146 |
191 |
|
out.putNextEntry( pFactory.createZE( path.getFileSubPath().replace( '\\', '/' ) ) ); |
147 |
192 |
|
} |
148 |
193 |
|
catch ( IOException e ) { |
149 |
|
- |
throw new WrappedIOException( e ); |
|
194 |
+ |
throw new FileSystemException( e ); |
150 |
195 |
|
} |
151 |
|
- |
FileInputStream in = FileUtil.createFileInputStream( path.file() ); |
|
196 |
+ |
FileInputStream in = FileUtils.createFileInputStream( path.file() ); |
152 |
197 |
|
try { |
153 |
|
- |
FileUtil.append( in, out ); |
|
198 |
+ |
FileUtils.append( in, out ); |
154 |
199 |
|
out.closeEntry(); |
155 |
200 |
|
} |
156 |
201 |
|
catch ( IOException e ) { |
157 |
|
- |
throw new WrappedIOException( e ); |
|
202 |
+ |
throw new FileSystemException( e ); |
158 |
203 |
|
} |
159 |
204 |
|
finally { |
160 |
|
- |
FileUtil.close( in ); |
|
205 |
+ |
FileUtils.close( in ); |
161 |
206 |
|
} |
162 |
207 |
|
} |
163 |
208 |
|
} |
164 |
209 |
|
finally { |
165 |
|
- |
FileUtil.close( out ); |
|
210 |
+ |
FileUtils.close( out ); |
166 |
211 |
|
} |
167 |
212 |
|
} |
168 |
213 |
|
return zPaths.size(); |
|
@@ -288,14 +333,14 @@ |
288 |
333 |
|
throw new IllegalArgumentException( "Files (e.g. " + zPath + ") may NOT have patterns: " + Arrays.asList( pPatterns ) ); |
289 |
334 |
|
} |
290 |
335 |
|
mIsFile = true; |
291 |
|
- |
mPath = FileUtil.getCanonicalFile( zPath ); |
|
336 |
+ |
mPath = FileUtils.getCanonicalFile( zPath ); |
292 |
337 |
|
return; |
293 |
338 |
|
} |
294 |
339 |
|
if ( !zPath.isDirectory() ) { |
295 |
340 |
|
throw new IllegalArgumentException( "Path Reference not a File or Directory: " + zPath ); |
296 |
341 |
|
} |
297 |
342 |
|
mIsFile = false; |
298 |
|
- |
mPath = FileUtil.getCanonicalFile( zPath ); |
|
343 |
+ |
mPath = FileUtils.getCanonicalFile( zPath ); |
299 |
344 |
|
List<String> zIncludes = new ArrayList<String>(); |
300 |
345 |
|
List<String> zExcludes = new ArrayList<String>(); |
301 |
346 |
|
for ( String zPattern : pPatterns ) { |
|
@@ -361,7 +406,7 @@ |
361 |
406 |
|
} else { |
362 |
407 |
|
if ( !excludedFile( zPath ) && acceptableFile( zPath ) ) { |
363 |
408 |
|
|
364 |
|
- |
String zFullCanonicalPath = FileUtil.getCanonicalPath( zFile ); |
|
409 |
+ |
String zFullCanonicalPath = FileUtils.getCanonicalPath( zFile ); |
365 |
410 |
|
String zRelativeCanonicalPath = zFullCanonicalPath.substring( mPath.getPath().length() + 1 ); |
366 |
411 |
|
pPaths.addCanonicalRelativePath( zRelativeCanonicalPath ); |
367 |
412 |
|
} |