1 package org.apache.maven.plugin.ejb.utils;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Enumeration;
24 import java.util.HashMap;
25 import java.util.Iterator;
26 import java.util.Map;
27 import java.util.jar.JarEntry;
28 import java.util.jar.JarFile;
29
30
31
32
33 public class JarContentChecker
34 {
35 private final static Boolean FOUND = Boolean.TRUE;
36
37 private final static Boolean NOT_FOUND = Boolean.FALSE;
38
39 private Map<File, Boolean> fileMap;
40
41 private Map<File, Boolean> directoryMap;
42
43
44 public JarContentChecker()
45 {
46 fileMap = new HashMap<File, Boolean>();
47 directoryMap = new HashMap<File, Boolean>();
48 }
49
50 public void addDirectory( File dir )
51 {
52 directoryMap.put( dir, NOT_FOUND );
53 }
54
55 public void addFile( File file )
56 {
57 fileMap.put( file, NOT_FOUND );
58 }
59
60
61
62
63
64
65
66
67
68 public boolean isOK( JarFile jarFile )
69 {
70 boolean bRetVal;
71 Enumeration<JarEntry> zipentries = jarFile.entries();
72 JarEntry entry;
73 File entryFile;
74
75 resetList();
76
77 while ( zipentries.hasMoreElements() )
78 {
79 entry = zipentries.nextElement();
80 entryFile = new File( entry.getName() );
81
82 if ( entry.isDirectory() )
83 {
84
85
86
87 if ( directoryMap.containsKey( entryFile ) )
88 {
89 directoryMap.put( entryFile, FOUND );
90 }
91 }
92 else if ( fileMap.containsKey( entryFile ) )
93 {
94 fileMap.put( entryFile, FOUND );
95 }
96 }
97
98 bRetVal = checkFinalResult();
99
100 return bRetVal;
101 }
102
103 private boolean checkFinalResult()
104 {
105 boolean bRetVal = true;
106
107 Iterator<File> keys = fileMap.keySet().iterator();
108
109 while ( keys.hasNext() && bRetVal )
110 {
111 if ( fileMap.get( keys.next() ).equals( NOT_FOUND ) )
112 {
113 bRetVal = false;
114 }
115 }
116
117 keys = directoryMap.keySet().iterator();
118
119 while ( keys.hasNext() && bRetVal )
120 {
121 if ( directoryMap.get( keys.next() ).equals( NOT_FOUND ) )
122 {
123 bRetVal = false;
124 }
125 }
126
127 return bRetVal;
128 }
129
130 private void resetList()
131 {
132 Iterator<File> keys = fileMap.keySet().iterator();
133
134 while ( keys.hasNext() )
135 {
136 fileMap.put( keys.next(), NOT_FOUND );
137 }
138
139 keys = directoryMap.keySet().iterator();
140
141 while ( keys.hasNext() )
142 {
143 directoryMap.put( keys.next(), NOT_FOUND );
144 }
145 }
146 }