|
| 1 | +package org.codehaus.plexus.archiver.diags; |
| 2 | + |
| 3 | +/* |
| 4 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 5 | + * or more contributor license agreements. See the NOTICE file |
| 6 | + * distributed with this work for additional information |
| 7 | + * regarding copyright ownership. The ASF licenses this file |
| 8 | + * to you under the Apache License, Version 2.0 (the |
| 9 | + * "License"); you may not use this file except in compliance |
| 10 | + * with the License. You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, |
| 15 | + * software distributed under the License is distributed on an |
| 16 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | + * KIND, either express or implied. See the License for the |
| 18 | + * specific language governing permissions and limitations |
| 19 | + * under the License. |
| 20 | + */ |
| 21 | + |
| 22 | +import org.codehaus.plexus.archiver.*; |
| 23 | +import org.codehaus.plexus.components.io.resources.PlexusIoResource; |
| 24 | +import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection; |
| 25 | +import org.codehaus.plexus.util.StringUtils; |
| 26 | +import sun.reflect.generics.reflectiveObjects.NotImplementedException; |
| 27 | + |
| 28 | +import javax.annotation.Nonnull; |
| 29 | +import java.io.File; |
| 30 | +import java.io.IOException; |
| 31 | +import java.util.ArrayList; |
| 32 | +import java.util.HashMap; |
| 33 | +import java.util.List; |
| 34 | +import java.util.Map; |
| 35 | + |
| 36 | +/** |
| 37 | + * A diagnostic archiver that keeps track of stuff that has been added. |
| 38 | + */ |
| 39 | +public class TrackingArchiver |
| 40 | + implements Archiver |
| 41 | +{ |
| 42 | + private File destFile; |
| 43 | + |
| 44 | + public final List<Addition> added = new ArrayList<Addition>(); |
| 45 | + |
| 46 | + private boolean useJvmChmod; |
| 47 | + |
| 48 | + private boolean ignorePermissions; |
| 49 | + |
| 50 | + public void createArchive() |
| 51 | + throws ArchiverException, IOException |
| 52 | + { |
| 53 | + } |
| 54 | + |
| 55 | + public void addDirectory( final @Nonnull File directory ) |
| 56 | + throws ArchiverException |
| 57 | + { |
| 58 | + added.add( new Addition( directory, null, null, null, -1 ) ); |
| 59 | + } |
| 60 | + |
| 61 | + public void addDirectory( final @Nonnull File directory, final String prefix ) |
| 62 | + throws ArchiverException |
| 63 | + { |
| 64 | + added.add( new Addition( directory, prefix, null, null, -1 ) ); |
| 65 | + } |
| 66 | + |
| 67 | + public void addDirectory( final @Nonnull File directory, final String[] includes, final String[] excludes ) |
| 68 | + throws ArchiverException |
| 69 | + { |
| 70 | + added.add( new Addition( directory, null, includes, excludes, -1 ) ); |
| 71 | + } |
| 72 | + |
| 73 | + public void addDirectory( final @Nonnull File directory, final String prefix, final String[] includes, |
| 74 | + final String[] excludes ) |
| 75 | + throws ArchiverException |
| 76 | + { |
| 77 | + added.add( new Addition( directory, prefix, includes, excludes, -1 ) ); |
| 78 | + } |
| 79 | + |
| 80 | + public void addFileSet( final @Nonnull FileSet fileSet ) |
| 81 | + throws ArchiverException |
| 82 | + { |
| 83 | + added.add( new Addition( fileSet, null, null, null, -1 ) ); |
| 84 | + } |
| 85 | + |
| 86 | + public void addFile( final @Nonnull File inputFile, final @Nonnull String destFileName ) |
| 87 | + throws ArchiverException |
| 88 | + { |
| 89 | + added.add( new Addition( inputFile, destFileName, null, null, -1 ) ); |
| 90 | + } |
| 91 | + |
| 92 | + public void addFile( final @Nonnull File inputFile, final @Nonnull String destFileName, final int permissions ) |
| 93 | + throws ArchiverException |
| 94 | + { |
| 95 | + added.add( new Addition( inputFile, destFileName, null, null, permissions ) ); |
| 96 | + } |
| 97 | + |
| 98 | + public void addArchivedFileSet( final @Nonnull File archiveFile ) |
| 99 | + throws ArchiverException |
| 100 | + { |
| 101 | + added.add( new Addition( archiveFile, null, null, null, -1 ) ); |
| 102 | + } |
| 103 | + |
| 104 | + public void addArchivedFileSet( final @Nonnull File archiveFile, final String prefix ) |
| 105 | + throws ArchiverException |
| 106 | + { |
| 107 | + added.add( new Addition( archiveFile, prefix, null, null, -1 ) ); |
| 108 | + } |
| 109 | + |
| 110 | + public void addSymlink( String s, String s2 ) |
| 111 | + throws ArchiverException |
| 112 | + { |
| 113 | + added.add( new Addition( s, null, null, null, -1 ) ); |
| 114 | + } |
| 115 | + |
| 116 | + public void addSymlink( String s, int i, String s2 ) |
| 117 | + throws ArchiverException |
| 118 | + { |
| 119 | + added.add( new Addition( s, null, null, null, -1 ) ); |
| 120 | + |
| 121 | + } |
| 122 | + |
| 123 | + public void addArchivedFileSet( final File archiveFile, final String[] includes, final String[] excludes ) |
| 124 | + throws ArchiverException |
| 125 | + { |
| 126 | + added.add( new Addition( archiveFile, null, includes, excludes, -1 ) ); |
| 127 | + } |
| 128 | + |
| 129 | + public void addArchivedFileSet( final @Nonnull File archiveFile, final String prefix, final String[] includes, |
| 130 | + final String[] excludes ) |
| 131 | + throws ArchiverException |
| 132 | + { |
| 133 | + added.add( new Addition( archiveFile, prefix, includes, excludes, -1 ) ); |
| 134 | + } |
| 135 | + |
| 136 | + public void addArchivedFileSet( final ArchivedFileSet fileSet ) |
| 137 | + throws ArchiverException |
| 138 | + { |
| 139 | + added.add( new Addition( fileSet, null, null, null, -1 ) ); |
| 140 | + } |
| 141 | + |
| 142 | + public void addResource( final PlexusIoResource resource, final String destFileName, final int permissions ) |
| 143 | + throws ArchiverException |
| 144 | + { |
| 145 | + added.add( new Addition( resource, destFileName, null, null, permissions ) ); |
| 146 | + } |
| 147 | + |
| 148 | + public void addResources( final PlexusIoResourceCollection resources ) |
| 149 | + throws ArchiverException |
| 150 | + { |
| 151 | + added.add( new Addition( resources, null, null, null, -1 ) ); |
| 152 | + } |
| 153 | + |
| 154 | + public File getDestFile() |
| 155 | + { |
| 156 | + return destFile; |
| 157 | + } |
| 158 | + |
| 159 | + public void setDestFile( final File destFile ) |
| 160 | + { |
| 161 | + this.destFile = destFile; |
| 162 | + } |
| 163 | + |
| 164 | + public void setFileMode( final int mode ) |
| 165 | + { |
| 166 | + } |
| 167 | + |
| 168 | + public int getFileMode() |
| 169 | + { |
| 170 | + return Integer.parseInt( "0644", 8 ); |
| 171 | + } |
| 172 | + |
| 173 | + public int getOverrideFileMode() |
| 174 | + { |
| 175 | + return Integer.parseInt( "0644", 8 ); |
| 176 | + } |
| 177 | + |
| 178 | + public void setDefaultFileMode( final int mode ) |
| 179 | + { |
| 180 | + } |
| 181 | + |
| 182 | + public int getDefaultFileMode() |
| 183 | + { |
| 184 | + return Integer.parseInt( "0644", 8 ); |
| 185 | + } |
| 186 | + |
| 187 | + public void setDirectoryMode( final int mode ) |
| 188 | + { |
| 189 | + } |
| 190 | + |
| 191 | + public int getDirectoryMode() |
| 192 | + { |
| 193 | + return Integer.parseInt( "0755", 8 ); |
| 194 | + } |
| 195 | + |
| 196 | + public int getOverrideDirectoryMode() |
| 197 | + { |
| 198 | + return Integer.parseInt( "0755", 8 ); |
| 199 | + } |
| 200 | + |
| 201 | + public void setDefaultDirectoryMode( final int mode ) |
| 202 | + { |
| 203 | + } |
| 204 | + |
| 205 | + public int getDefaultDirectoryMode() |
| 206 | + { |
| 207 | + return Integer.parseInt( "0755", 8 ); |
| 208 | + } |
| 209 | + |
| 210 | + public boolean getIncludeEmptyDirs() |
| 211 | + { |
| 212 | + return false; |
| 213 | + } |
| 214 | + |
| 215 | + public void setIncludeEmptyDirs( final boolean includeEmptyDirs ) |
| 216 | + { |
| 217 | + } |
| 218 | + |
| 219 | + public void setDotFileDirectory( final File dotFileDirectory ) |
| 220 | + { |
| 221 | + } |
| 222 | + |
| 223 | + public |
| 224 | + @Nonnull |
| 225 | + ResourceIterator getResources() |
| 226 | + throws ArchiverException |
| 227 | + { |
| 228 | + throw new NotImplementedException(); |
| 229 | + } |
| 230 | + |
| 231 | + @SuppressWarnings( "rawtypes" ) |
| 232 | + public Map<String, ArchiveEntry> getFiles() |
| 233 | + { |
| 234 | + return new HashMap<String, ArchiveEntry>(); |
| 235 | + } |
| 236 | + |
| 237 | + public boolean isForced() |
| 238 | + { |
| 239 | + return false; |
| 240 | + } |
| 241 | + |
| 242 | + public void setForced( final boolean forced ) |
| 243 | + { |
| 244 | + } |
| 245 | + |
| 246 | + public boolean isSupportingForced() |
| 247 | + { |
| 248 | + return true; |
| 249 | + } |
| 250 | + |
| 251 | + public String getDuplicateBehavior() |
| 252 | + { |
| 253 | + return null; |
| 254 | + } |
| 255 | + |
| 256 | + public void setDuplicateBehavior( final String duplicate ) |
| 257 | + { |
| 258 | + } |
| 259 | + |
| 260 | + public class Addition |
| 261 | + { |
| 262 | + /** |
| 263 | + * {@inheritDoc} |
| 264 | + * |
| 265 | + * @see Object#toString() |
| 266 | + */ |
| 267 | + @Override |
| 268 | + public String toString() |
| 269 | + { |
| 270 | + return "Addition (\n resource= " + resource + "\n directory= " + directory + "\n destination= " |
| 271 | + + destination + "\n permissions= " + permissions + "\n includes= " + ( includes == null |
| 272 | + ? "-none-" |
| 273 | + : StringUtils.join( includes, ", " ) ) + "\n excludes= " + ( excludes == null |
| 274 | + ? "-none-" |
| 275 | + : StringUtils.join( excludes, ", " ) ) + "\n)"; |
| 276 | + } |
| 277 | + |
| 278 | + public final Object resource; |
| 279 | + |
| 280 | + public final File directory; |
| 281 | + |
| 282 | + public final String destination; |
| 283 | + |
| 284 | + public final int permissions; |
| 285 | + |
| 286 | + public final String[] includes; |
| 287 | + |
| 288 | + public final String[] excludes; |
| 289 | + |
| 290 | + public Addition( final Object resource, final String destination, final String[] includes, |
| 291 | + final String[] excludes, final int permissions ) |
| 292 | + { |
| 293 | + this.resource = resource; |
| 294 | + if ( resource instanceof FileSet) |
| 295 | + { |
| 296 | + final FileSet fs = (FileSet) resource; |
| 297 | + directory = fs.getDirectory(); |
| 298 | + this.destination = fs.getPrefix(); |
| 299 | + this.includes = fs.getIncludes(); |
| 300 | + this.excludes = fs.getExcludes(); |
| 301 | + this.permissions = permissions; |
| 302 | + } |
| 303 | + else |
| 304 | + { |
| 305 | + if ( resource instanceof File && ( (File) resource ).isDirectory() ) |
| 306 | + { |
| 307 | + directory = (File) resource; |
| 308 | + } |
| 309 | + else |
| 310 | + { |
| 311 | + directory = null; |
| 312 | + } |
| 313 | + |
| 314 | + this.destination = destination; |
| 315 | + this.includes = includes; |
| 316 | + this.excludes = excludes; |
| 317 | + this.permissions = permissions; |
| 318 | + } |
| 319 | + } |
| 320 | + } |
| 321 | + |
| 322 | + public boolean isUseJvmChmod() |
| 323 | + { |
| 324 | + return useJvmChmod; |
| 325 | + } |
| 326 | + |
| 327 | + public void setUseJvmChmod( final boolean useJvmChmod ) |
| 328 | + { |
| 329 | + this.useJvmChmod = useJvmChmod; |
| 330 | + } |
| 331 | + |
| 332 | + public boolean isIgnorePermissions() |
| 333 | + { |
| 334 | + return ignorePermissions; |
| 335 | + } |
| 336 | + |
| 337 | + public void setIgnorePermissions( final boolean ignorePermissions ) |
| 338 | + { |
| 339 | + this.ignorePermissions = ignorePermissions; |
| 340 | + } |
| 341 | +} |
0 commit comments