EMMA Coverage Report (generated Thu Nov 26 15:54:18 CST 2009)
[all classes][org.eclipse.pde.api.tools.internal.util]

COVERAGE SUMMARY FOR SOURCE FILE [FileManager.java]

nameclass, %method, %block, %line, %
FileManager.java100% (1/1)100% (5/5)61%  (36/59)75%  (15/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FileManager100% (1/1)100% (5/5)61%  (36/59)75%  (15/20)
deleteFiles (): boolean 100% (1/1)21%  (6/29)38%  (3/8)
<static initializer> 100% (1/1)100% (5/5)100% (3/3)
FileManager (): void 100% (1/1)100% (3/3)100% (1/1)
getManager (): FileManager 100% (1/1)100% (8/8)100% (3/3)
recordTempFileRoot (String): void 100% (1/1)100% (14/14)100% (5/5)

1/*******************************************************************************
2 * Copyright (c) 2009 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.pde.api.tools.internal.util;
12 
13import java.io.File;
14import java.util.HashSet;
15import java.util.Iterator;
16 
17/**
18 * Manager to handle temp files that have been created. Used as a fall-back to
19 * ensure we clean up after ourselves
20 * 
21 * @since 1.0.1
22 */
23public final class FileManager {
24 
25        private static FileManager fInstance = null;
26        
27        /**
28         * The set of recorded file paths
29         */
30        private static HashSet fFilePaths = null;
31        
32        /**
33         * Constructor
34         * private - no instantiation
35         */
36        private FileManager() {}
37        
38        /**
39         * Returns the singleton instance of the manager
40         * @return the manager instance
41         */
42        public synchronized static FileManager getManager() {
43                if(fInstance == null) {
44                        fInstance = new FileManager();
45                }
46                return fInstance;
47        }
48        
49        /**
50         * Records a file root path to be deleted on the next call to 
51         * {@link #deleteFiles()}.
52         * @param absolutepath the absolute path in the local file system of the file to delete
53         */
54        public void recordTempFileRoot(String absolutepath) {
55                if(absolutepath != null) {
56                        if(fFilePaths == null) {
57                                fFilePaths = new HashSet(10);
58                        }
59                        fFilePaths.add(absolutepath);
60                }
61        }
62        
63        /**
64         * Deletes all of the recorded file roots from the local filesystem (if still existing)
65         * and returns the success of the entire delete operation.
66         * @return true if all recorded files were deleted, false otherwise
67         */
68        public boolean deleteFiles() {
69                boolean success = true;
70                if(fFilePaths != null) {
71                        File file = null;
72                        for(Iterator iter = fFilePaths.iterator(); iter.hasNext();) {
73                                file = new File((String) iter.next());
74                                success &= Util.delete(file);
75                        }
76                        fFilePaths.clear();
77                }
78                return success;
79        }
80}

[all classes][org.eclipse.pde.api.tools.internal.util]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov