1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
package org.eclipse.wst.ws.tests.utils;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
public class FindDuplicateKeys
{
public static void main( String[] args )
{
File startPath = new File( args[0] );
String[] pluginFiles = Utils.readLines( args[1] );
Vector propertyFiles = new Vector();
Hashtable keys = new Hashtable();
PrintWriter writer = null;
Hashtable srcKeys = new Hashtable();
Vector srcFiles = new Vector();
Vector propNames = new Vector();
Vector pluginNames = new Vector();
String[] pluginArray = null;
Hashtable srcPluginMap = new Hashtable();
try
{
writer = new PrintWriter( new FileWriter( args[2] ));
}
catch( Exception exc )
{
exc.printStackTrace();
}
for( int index = 0; index < pluginFiles.length; index++ )
{
File pluginDir = Utils.getFile( startPath, pluginFiles[index] );
Utils.getFiles( pluginDir, propertyFiles, "properties", new String[]{ "bin", "build.properties",
"wsexplorer.properties",
"uddi.properties",
"wsdl.properties",
"wsil.properties",
"favorites.properties"
} );
Utils.getFiles( pluginDir, srcFiles, "java", new String[0] );
}
// Loop through each property file
for( int index = 0; index < propertyFiles.size(); index++ )
{
File propFile = (File)propertyFiles.elementAt(index);
File parent = new File( propFile.getParent() );
// Skip properties files that are in the plugin directory.
if( Utils.stringInArray( parent.getName(), pluginFiles ) )
{
continue;
}
String propName = propFile.getAbsolutePath();
int srcStart = propName.indexOf( "src" );
if( srcStart != -1 )
{
int lastSlash = propName.lastIndexOf( '\\' );
int lastDot = propName.lastIndexOf( '.' );
String name = propName.substring( srcStart + 4, lastSlash );
String name2 = propName.substring( srcStart + 4, lastDot );
name = name.replace( '\\', '.' );
name2 = name2.replace( '\\', '.' );
pluginNames.add( name );
pluginNames.add( name2 );
//System.out.println( propName + ">>" + name + ">>" + name2 );
}
}
pluginArray = (String[])pluginNames.toArray( new String[0] );
// Find all the java strings.
for( int index = 0; index < srcFiles.size(); index++ )
{
File srcFile = (File)srcFiles.elementAt(index);
Vector fileSrcKeys = new Vector();
String[] lines = Utils.readLines(srcFile );
for( int srcIndex = 0; srcIndex < lines.length; srcIndex++ )
{
Utils.findJavaStrings( lines[srcIndex], fileSrcKeys );
}
for( int keysIndex = 0; keysIndex < fileSrcKeys.size(); keysIndex++ )
{
String key = (String)fileSrcKeys.elementAt( keysIndex );
HashSet fileSet = (HashSet)srcKeys.get( key );
if( fileSet == null )
{
fileSet = new HashSet();
srcKeys.put( key, fileSet );
}
if( Utils.stringInArray( key, pluginArray ) )
{
HashSet names = (HashSet)srcPluginMap.get( srcFile );
if( names == null )
{
names = new HashSet();
srcPluginMap.put( srcFile, names );
}
names.add( key );
}
fileSet.add( srcFile );
}
}
int count = 1;
// Loop through each property file
for( int index = 0; index < propertyFiles.size(); index++ )
{
File propFile = (File)propertyFiles.elementAt(index);
Vector propKeys = Utils.getPropertyKeys( propFile );
File parent = new File( propFile.getParent() );
// Skip properties files that are in the plugin directory.
if( Utils.stringInArray( parent.getName(), pluginFiles ) )
{
continue;
}
System.out.println( propFile.getAbsolutePath() );
for( int propIndex = 0; propIndex < propKeys.size(); propIndex++ )
{
String propKey = (String)propKeys.elementAt( propIndex );
if( keys.containsKey(propKey) && !propKey.startsWith( "PLUGIN" ))
{
File origFile = (File)keys.get( propKey );
String origName = origFile.getAbsolutePath();
String propName = propFile.getAbsolutePath();
origName = origName.substring( args[0].length(), origName.length() );
propName = propName.substring( args[0].length(), propName.length() );
HashSet fileSet = (HashSet)srcKeys.get( propKey );
if( fileSet != null )
{
writer.println( count + " Property: " + propKey + " is in both " +
origName + " and " +
propName );
Iterator iter = fileSet.iterator();
while( iter.hasNext() )
{
File file = (File)iter.next();
writer.println( " >" + file.getAbsolutePath() );
HashSet names = (HashSet)srcPluginMap.get( file );
Iterator nameIter = names.iterator();
while( nameIter.hasNext() )
{
writer.println( " >" + nameIter.next() );
}
}
count++;
}
}
else
{
keys.put( propKey, propFile );
}
}
}
try
{
if( writer != null ) writer.close();
}
catch( Exception exc )
{
exc.printStackTrace();
}
}
}
|