From 3141e1255fa421458050e9ab7343d55ce9701905 Mon Sep 17 00:00:00 2001 From: kchan Date: Tue, 30 Oct 2007 20:18:52 +0000 Subject: Move utility class from wst.ws.env.tests to wst.ws.tests. --- .../org.eclipse.wst.ws.tests/META-INF/MANIFEST.MF | 8 +- .../eclipse/wst/ws/tests/utils/BuildClasspath.java | 74 +++++ .../wst/ws/tests/utils/CopyPropertyFiles.java | 81 ++++++ .../eclipse/wst/ws/tests/utils/FindContextIds.java | 90 ++++++ .../wst/ws/tests/utils/FindDuplicateKeys.java | 196 +++++++++++++ .../wst/ws/tests/utils/FindPercentString.java | 68 +++++ .../wst/ws/tests/utils/FindPropertyMovement.java | 116 ++++++++ .../utils/GenPluginPropertiesFromPluginXml.java | 76 +++++ .../wst/ws/tests/utils/ListPropertyFiles.java | 39 +++ .../eclipse/wst/ws/tests/utils/RemoveBrackets.java | 80 ++++++ .../wst/ws/tests/utils/RemoveUnusedKeys.java | 182 ++++++++++++ .../wst/ws/tests/utils/UpdateFeatureXMLFiles.java | 93 +++++++ .../org/eclipse/wst/ws/tests/utils/Utils.java | 305 +++++++++++++++++++++ 13 files changed, 1405 insertions(+), 3 deletions(-) create mode 100644 tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/BuildClasspath.java create mode 100644 tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/CopyPropertyFiles.java create mode 100644 tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindContextIds.java create mode 100644 tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindDuplicateKeys.java create mode 100644 tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindPercentString.java create mode 100644 tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindPropertyMovement.java create mode 100644 tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/GenPluginPropertiesFromPluginXml.java create mode 100644 tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/ListPropertyFiles.java create mode 100644 tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/RemoveBrackets.java create mode 100644 tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/RemoveUnusedKeys.java create mode 100644 tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/UpdateFeatureXMLFiles.java create mode 100644 tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/Utils.java diff --git a/tests/org.eclipse.wst.ws.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.wst.ws.tests/META-INF/MANIFEST.MF index 67205fca7..401dd7afa 100644 --- a/tests/org.eclipse.wst.ws.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.wst.ws.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %PLUGIN_NAME Bundle-SymbolicName: org.eclipse.wst.ws.tests; singleton:=true -Bundle-Version: 1.0.201.qualifier +Bundle-Version: 1.0.301.qualifier Bundle-Activator: org.eclipse.wst.ws.tests.plugin.TestsPlugin Bundle-Vendor: %PLUGIN_PROVIDER Bundle-Localization: plugin @@ -24,9 +24,11 @@ Require-Bundle: org.eclipse.wst.ws, org.eclipse.emf.ecore, org.eclipse.emf.ecore.xmi Eclipse-LazyStart: true -Export-Package: org.eclipse.wst.ws.tests.data, +Export-Package: org.eclipse.wst.ws.test.popup, + org.eclipse.wst.ws.tests.data, org.eclipse.wst.ws.tests.plugin, - org.eclipse.wst.ws.tests.unittest + org.eclipse.wst.ws.tests.unittest, + org.eclipse.wst.ws.tests.utils Bundle-ClassPath: tests.jar Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/BuildClasspath.java b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/BuildClasspath.java new file mode 100644 index 000000000..3d9623dc5 --- /dev/null +++ b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/BuildClasspath.java @@ -0,0 +1,74 @@ +package org.eclipse.wst.ws.tests.utils; + +import java.util.Enumeration; +import java.util.ResourceBundle; + +import org.eclipse.core.runtime.IPlatformRunnable; +import org.eclipse.core.runtime.Platform; +import org.eclipse.osgi.util.ManifestElement; +import org.osgi.framework.Bundle; +import org.osgi.framework.Constants; + +/** + * This program will generate a classpath that can be used to build the wsexplorer.war file. + * + */ +public class BuildClasspath implements IPlatformRunnable +{ + public Object run(Object args) throws Exception + { + ResourceBundle pluginRequires = ResourceBundle.getBundle( "org.eclipse.wst.command.env.property.tools.ExplorerRequires" ); + Enumeration requireKeys = pluginRequires.getKeys(); + + while( requireKeys.hasMoreElements() ) + { + String key = (String)requireKeys.nextElement(); + buildClasspath( pluginRequires.getString(key) ); + } + + return IPlatformRunnable.EXIT_OK; + } + + private void buildClasspath( String pluginId ) throws Exception + { + Bundle bundle = Platform.getBundle( pluginId ); + String classpath = (String)bundle.getHeaders().get( Constants.BUNDLE_CLASSPATH ); + String location = bundle.getLocation(); + + // Add classpath to list + ManifestElement[] classpaths = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, classpath); + + if( classpaths != null ) + { + for( int index = 0; index < classpaths.length; index++ ) + { + String newPath = null; + + // We have a special case for the SWT plugin since it + if( location.indexOf( "org.eclipse.swt" ) != -1 ) + { + Bundle[] bundles = Platform.getFragments( bundle ); + String newLocation = bundles[0].getLocation().substring(8); + String path = classpaths[index].getValue().replaceFirst( "\\$ws\\$", "ws/win32"); + + newPath = newLocation + path; + } + else if( location.startsWith( "update" ) ) + { + newPath = location.substring(8) + classpaths[index].getValue(); + } + else if( location.startsWith( "initial" )) + { + newPath = location.substring(23) + classpaths[index].getValue(); + } + else if( location.startsWith( "System" )) + { + String platformLocation = Platform.getInstallLocation().getURL().toString().substring(6); + newPath = platformLocation + "plugins/org.eclipse.osgi_3.0.1/" + classpaths[index].getValue(); + } + + System.out.print( newPath + ';'); + } + } + } +} diff --git a/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/CopyPropertyFiles.java b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/CopyPropertyFiles.java new file mode 100644 index 000000000..c0ee50fa1 --- /dev/null +++ b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/CopyPropertyFiles.java @@ -0,0 +1,81 @@ +package org.eclipse.wst.ws.tests.utils; + +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Vector; + +public class CopyPropertyFiles +{ + public static void main( String[] args ) + { + File startPath = new File( args[0] ); + String[] pluginFiles = Utils.readLines( args[1] ); + String newPath = args[2]; + String pathRelativeTo= args[3]; + Vector propertyFiles = new Vector(); + + for( int index = 0; index < pluginFiles.length; index++ ) + { + File pluginDir = Utils.getFile( startPath, pluginFiles[index] ); + + if( pluginDir != null ) + { + Utils.getFiles( pluginDir, propertyFiles, "properties", new String[]{ "bin", "build.properties", + } ); + } + } + + // Loop through each property file + for( int index = 0; index < propertyFiles.size(); index++ ) + { + File propFile = (File)propertyFiles.elementAt(index); + String propName = propFile.getAbsolutePath(); + int pluginIndex = propName.indexOf( pathRelativeTo ); + int firstSlash = propName.indexOf( "\\", pluginIndex ); + int nextSlash = propName.indexOf( "\\", firstSlash+1 ); + String pluginName = propName.substring( firstSlash + 1, nextSlash ); + int underIndex = pluginName.indexOf( '_' ); + + if( underIndex != -1 ) + { + pluginName = pluginName.substring( 0, underIndex ); + } + + String newName = newPath + File.separator + "plugins" + + File.separator + pluginName + + File.separator + propName.substring( nextSlash+1, propName.length() ); + + File newFile = new File( newName ); + File parent = new File( newFile.getParent() ); + PrintWriter writer = null; + + try + { + parent.mkdirs(); + + writer = new PrintWriter( new FileWriter( newFile )); + String[] lines = Utils.readLines( propFile ); + + for( int lineIndex = 0; lineIndex < lines.length; lineIndex++ ) + { + writer.println( lines[lineIndex] ); + } + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + finally + { + try + { + if( writer != null ) writer.close(); + } + catch( Exception exc ) + { + } + } + } + } +} diff --git a/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindContextIds.java b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindContextIds.java new file mode 100644 index 000000000..0fb63031e --- /dev/null +++ b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindContextIds.java @@ -0,0 +1,90 @@ +package org.eclipse.wst.ws.tests.utils; + +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Vector; + +/* + * This class is used to find Context IDs in source files. + * args[0] = The root directory where plugins source directories will be searched. + * args[1] = A file containing plugin source directories. Each line should contain + * a path to a source directory relative to the args[0] parameter. + * args[2] = The output file name. + */ +public class FindContextIds +{ + public void findIds( String rootDirectory, String sourceDirectoryName, String outputFileName ) + { + File sourceDirectoryFile = new File( sourceDirectoryName ); + String[] srcDirLines = Utils.readLines( sourceDirectoryFile ); + PrintWriter outputFile = null; + + try + { + outputFile = new PrintWriter( new FileWriter( outputFileName ) ); + + for( int index = 0; index < srcDirLines.length; index++ ) + { + String sourceDirName = srcDirLines[index]; + File sourceDirectory = new File( rootDirectory, sourceDirName ); + + outputFile.println( "======>Context IDs for plugin directory: " + sourceDirName ); + + findIdsForaDirectory( sourceDirectory, outputFile ); + } + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + finally + { + if( outputFile != null ) + { + outputFile.close(); + } + } + } + + static public void main( String[] args ) + { + FindContextIds findIds = new FindContextIds(); + + if( args.length != 3 ) + { + System.out.println( "Error: expecting a root directory, the source directory file name, and an output file as parameters." ); + return; + } + + findIds.findIds( args[0], args[1], args[2] ); + } + + private boolean findIdsForaDirectory( File sourceDirectory, PrintWriter outputFile ) + { + Vector files = new Vector(); + boolean found = false; + + Utils.getFiles( sourceDirectory, files, "java", new String[0] ); + + // Loop through each file. + for( int fileIndex = 0; fileIndex < files.size(); fileIndex++ ) + { + String[] lines = Utils.readLines( (File)files.elementAt(fileIndex) ); + + // Loop through each line in the file. + for( int lineIndex = 0; lineIndex < lines.length; lineIndex++ ) + { + String line = lines[lineIndex]; + + if( line.indexOf("CONTEXT_ID") != -1 ) + { + outputFile.println( line ); + found = true; + } + } + } + + return found; + } +} diff --git a/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindDuplicateKeys.java b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindDuplicateKeys.java new file mode 100644 index 000000000..502ffd89f --- /dev/null +++ b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindDuplicateKeys.java @@ -0,0 +1,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(); + } + } +} diff --git a/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindPercentString.java b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindPercentString.java new file mode 100644 index 000000000..1cdef9fa0 --- /dev/null +++ b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindPercentString.java @@ -0,0 +1,68 @@ +package org.eclipse.wst.ws.tests.utils; + +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Vector; + +public class FindPercentString +{ + public static void main( String[] args ) + { + File startPath = new File( args[0] ); + String[] pluginFiles = Utils.readLines( args[1] ); + PrintWriter writer = null; + Vector srcFiles = new Vector(); + + 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] ); + + if( pluginDir != null ) + { + Utils.getFiles( pluginDir, srcFiles, "java", 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 ); + + if( key.startsWith("%" ) ) + { + writer.println( key + " >> " + srcFile.getName() ); + } + } + } + + try + { + if( writer != null ) writer.close(); + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + } +} diff --git a/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindPropertyMovement.java b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindPropertyMovement.java new file mode 100644 index 000000000..ba663699c --- /dev/null +++ b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/FindPropertyMovement.java @@ -0,0 +1,116 @@ +package org.eclipse.wst.ws.tests.utils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStream; +import java.io.PrintWriter; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; +import java.util.PropertyResourceBundle; +import java.util.Set; +import java.util.Vector; + +public class FindPropertyMovement +{ + public static void main( String[] args ) + { + File oldPath = new File( args[0] ); + File newPath = new File( args[1] ); + File outputFile = new File( args[2] ); + + Vector oldPropertyFiles = new Vector(); + Vector newPropertyFiles = new Vector(); + + Hashtable oldKeyMap = new Hashtable(); + Hashtable newKeyMap = new Hashtable(); + + Utils.getFiles( oldPath, oldPropertyFiles, "properties", new String[0] ); + Utils.getFiles( newPath, newPropertyFiles, "properties", new String[0] ); + + buildMap( oldPropertyFiles, oldKeyMap ); + buildMap( newPropertyFiles, newKeyMap ); + + Set newKeySet = newKeyMap.entrySet(); + Iterator iter = newKeySet.iterator(); + PrintWriter writer = null; + + try + { + writer = new PrintWriter( new FileWriter( outputFile )); + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + + while( iter.hasNext() && writer != null ) + { + Map.Entry entry = (Map.Entry)iter.next(); + String property = (String)entry.getKey(); + String newFileName = (String)entry.getValue(); + String oldFileName = (String)oldKeyMap.get( property ); + + if( oldFileName == null || newFileName.equals( oldFileName ) ) + { + // Do nothing. Either this key didn't exist in the old property + // files or this key is still in the same property file. + } + else + { + writer.println( property + " " + oldFileName + " " + newFileName ); + } + } + + try + { + if( writer != null ) writer.close(); + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + } + + private static void buildMap( Vector inputFiles, Hashtable keyMap ) + { + for( int index = 0; index < inputFiles.size(); index++ ) + { + File propFile = (File)inputFiles.elementAt(index); + String propName = propFile.getAbsolutePath(); + int pluginIndex = propName.indexOf( "plugins" ); + String propString = propName.substring( pluginIndex, propName.length() ); + InputStream stream = null; + + try + { + stream = new FileInputStream( propFile ); + PropertyResourceBundle bundle = new PropertyResourceBundle( stream ); + + Enumeration keys = bundle.getKeys(); + + while( keys.hasMoreElements() ) + { + keyMap.put( keys.nextElement(), propString ); + } + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + finally + { + try + { + if( stream != null ) stream.close(); + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + } + } + } +} diff --git a/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/GenPluginPropertiesFromPluginXml.java b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/GenPluginPropertiesFromPluginXml.java new file mode 100644 index 000000000..e66ddf006 --- /dev/null +++ b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/GenPluginPropertiesFromPluginXml.java @@ -0,0 +1,76 @@ +package org.eclipse.wst.ws.tests.utils; + +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.HashSet; + +public class GenPluginPropertiesFromPluginXml +{ + public static void main( String[] args ) + { + File startPath = new File( args[0] ); + String[] pluginFiles = Utils.readLines( args[1] ); + + for( int index = 0; index < pluginFiles.length; index++ ) + { + String filename = pluginFiles[index]; + + HashSet keys = new HashSet(); + File dir = Utils.getFile( startPath, filename ); + File file = Utils.getFile( dir, "plugin.xml" ); + + if( file == null ) continue; + + Utils.getPluginXMLKeys( file, keys ); + + File propfile = Utils.getFile( dir, "plugin.properties" ); + + if( keys.size() > 0 && propfile == null ) + { + try + { + System.out.println( "No plugin.properties file for:" + file ); + propfile = File.createTempFile( "prefix", "suffix" ); + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + } + else if( keys.size() == 0 ) + { + continue; + } + + File outputFile = new File( dir.getAbsolutePath() + File.separator + "plugin.properties.new" ); + File delFile = new File( dir.getAbsolutePath() + File.separator + "plugin.properties.del" ); + PrintWriter writer = null; + PrintWriter delWriter = null; + + try + { + writer = new PrintWriter( new FileWriter( outputFile ) ); + delWriter = new PrintWriter( new FileWriter( delFile )); + System.out.println( "Generating output to:" + outputFile ); + Utils.createOutputFile( keys, propfile, writer, delWriter ); + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + finally + { + try + { + if( writer != null ) writer.close(); + if( delWriter != null ) delWriter.close(); + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + } + } + } +} diff --git a/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/ListPropertyFiles.java b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/ListPropertyFiles.java new file mode 100644 index 000000000..2a0a6c2ca --- /dev/null +++ b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/ListPropertyFiles.java @@ -0,0 +1,39 @@ +package org.eclipse.wst.ws.tests.utils; + +import java.io.File; +import java.util.Vector; + +public class ListPropertyFiles +{ + public static void main( String[] args ) + { + File startPath = new File( args[0] ); + Vector propertyFiles = new Vector(); + + Utils.getFiles( startPath, propertyFiles, "backup", new String[]{ "bin", "build.properties", + } ); + + // Loop through each property file + for( int index = 0; index < propertyFiles.size(); index++ ) + { + File propFile = (File)propertyFiles.elementAt(index); + String propName = propFile.getAbsolutePath(); + int pluginIndex = propName.indexOf( "plugins" ); + int firstSlash = propName.indexOf( "\\", pluginIndex ); + int nextSlash = propName.indexOf( "\\", firstSlash+1 ); + String pluginName = propName.substring( firstSlash + 1, nextSlash ); + int underIndex = pluginName.indexOf( '_' ); + + if( underIndex != -1 ) + { + pluginName = pluginName.substring( 0, underIndex ); + } + + String newName = "del plugins" + + File.separator + pluginName + + File.separator + propName.substring( nextSlash+1, propName.length() ); + + System.out.println( newName ); + } + } +} diff --git a/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/RemoveBrackets.java b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/RemoveBrackets.java new file mode 100644 index 000000000..b35682b43 --- /dev/null +++ b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/RemoveBrackets.java @@ -0,0 +1,80 @@ +package org.eclipse.wst.ws.tests.utils; + +import java.awt.Button; +import java.awt.Event; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.TextArea; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class RemoveBrackets extends Frame +{ + /** + * Comment for serialVersionUID + */ + private static final long serialVersionUID = 3617292320299824176L; + private TextArea inputArea_; + private TextArea outputArea_; + private Button button_; + + public RemoveBrackets() + { + super( "Convert HTML brackets" ); + } + + public static void main(String[] args) + { + RemoveBrackets convert = new RemoveBrackets(); + + convert.buildUI(); + } + + private void buildUI() + { + GridLayout layout = new GridLayout(3,1); + //layout.setColumns(1); + setLayout( layout ); + + inputArea_ = new TextArea( 10, 50 ); + outputArea_ = new TextArea( 10, 50 ); + button_ = new Button( "Press here to convert to HTML" ); + + inputArea_.setEditable( true ); + outputArea_.setEditable( true ); + button_.addActionListener( new ActionListener() + { + public void actionPerformed( ActionEvent evt ) + { + convertText(); + } + }); + + add( inputArea_ ); + add( button_ ); + add( outputArea_ ); + //setSize( 100, 100 ); + pack(); + show(); + } + + public boolean handleEvent( Event evt ) + { + if( evt.id == Event.WINDOW_DESTROY ) + { + System.exit(0); + } + + return true; + } + + private void convertText() + { + String inputString = inputArea_.getText(); + String outputString = inputString.replaceAll( "<", "<"); + + outputString = outputString.replaceAll( ">", ">" ); + + outputArea_.setText( outputString ); + } +} diff --git a/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/RemoveUnusedKeys.java b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/RemoveUnusedKeys.java new file mode 100644 index 000000000..f2ea86a48 --- /dev/null +++ b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/RemoveUnusedKeys.java @@ -0,0 +1,182 @@ +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.Vector; + +public class RemoveUnusedKeys +{ + 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(); + Hashtable srcKeys = new Hashtable(); + Vector srcFiles = new Vector(); + Vector propNames = new Vector(); + Vector pluginNames = new Vector(); + String[] pluginArray = null; + Hashtable srcPluginMap = new Hashtable(); + + + // Find all the property files. + for( int index = 0; index < pluginFiles.length; index++ ) + { + File pluginDir = Utils.getFile( startPath, pluginFiles[index] ); + + if( pluginDir == null ) + { + System.out.println( "Plugin: " + pluginFiles[index] + " not found!" ); + continue; + } + + Utils.getFiles( pluginDir, propertyFiles, "properties", new String[]{ "bin", "build.properties", + "wsexplorer.properties", + "uddi.properties", + "wsdl.properties", + "wsil.properties", + "favorites.properties", + "newprops.properties", + "delprops.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; + } + + String propName = propFile.getAbsolutePath(); + int srcStart = propName.indexOf( "src" ); + String folderName = ""; + String pkgName = ""; + + if( srcStart != -1 ) + { + int lastSlash = propName.lastIndexOf( '\\' ); + String name = propName.substring( srcStart + 4, lastSlash ); + name = name.replace( '\\', '.' ); + + pkgName = name; + folderName = propName.substring( 0, lastSlash + 1 ); + } + else + { + continue; + } + + System.out.println( propFile.getAbsolutePath() ); + + String newPropName = folderName + "newprops.properties"; + String delPropName = folderName + "delprops.properties"; + + PrintWriter newPropertyFile = null; + PrintWriter delPropertyFile = null; + + try + { + newPropertyFile = new PrintWriter( new FileWriter( newPropName )); + delPropertyFile = new PrintWriter( new FileWriter( delPropName )); + + Utils.createOutputFile( srcKeys.keySet(), propFile, newPropertyFile, delPropertyFile ); + + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + finally + { + if( newPropertyFile != null ) newPropertyFile.close(); + if( delPropertyFile != null ) delPropertyFile.close(); + } + } + } +} diff --git a/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/UpdateFeatureXMLFiles.java b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/UpdateFeatureXMLFiles.java new file mode 100644 index 000000000..bcfaeecf6 --- /dev/null +++ b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/UpdateFeatureXMLFiles.java @@ -0,0 +1,93 @@ +package org.eclipse.wst.ws.tests.utils; + +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Vector; + +public class UpdateFeatureXMLFiles +{ + public static void main( String[] args ) + { + String rootPath = args[0]; + File rootFile = new File( rootPath ); + Vector featureFiles = new Vector(); + + getFiles( featureFiles, rootFile ); + + int size = featureFiles.size(); + + for( int index = 0; index < size; index++ ) + { + File file = (File)featureFiles.elementAt( index ); + String fileName = file.getName(); + int langIndex = fileName.indexOf( "feature_" ); + int dotIndex = fileName.indexOf( '.', langIndex ); + String lang = fileName.substring( langIndex + 8, dotIndex ); + String[] lines = Utils.readLines( file ); + + PrintWriter writer = null; + FileWriter fileWriter = null; + + try + { + fileWriter = new FileWriter( file ); + writer = new PrintWriter( fileWriter ); + + for( int lineIndex = 0; lineIndex < lines.length; lineIndex++ ) + { + String line = lines[lineIndex]; + + if( line.indexOf( "licenseURL" ) != -1 ) + { + writer.println( "licenseURL=license_" + lang + ".html" ); + } + else + { + writer.println( line ); + } + } + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + finally + { + try + { + writer.close(); + fileWriter.close(); + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + } + } + } + + static private void getFiles( Vector files, File path ) + { + if( path.isDirectory() ) + { + File[] children = path.listFiles(); + + for( int index = 0; index < children.length; index++ ) + { + getFiles( files, children[index] ); + } + } + else + { + String pathName = path.getName(); + + int index = pathName.indexOf( "feature_" ); + + if( index != -1 ) + { + files.add( path ); + } + } + } +} diff --git a/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/Utils.java b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/Utils.java new file mode 100644 index 000000000..aa20dbc4e --- /dev/null +++ b/tests/org.eclipse.wst.ws.tests/tests/org/eclipse/wst/ws/tests/utils/Utils.java @@ -0,0 +1,305 @@ +package org.eclipse.wst.ws.tests.utils; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.FilenameFilter; +import java.io.InputStream; +import java.io.PrintWriter; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Iterator; +import java.util.PropertyResourceBundle; +import java.util.Vector; + +public class Utils +{ + public static void createOutputFile( Collection keys, File propsFile, PrintWriter outputFile, PrintWriter deleteFile ) + { + String[] lines = readLines( propsFile ); + boolean continueLine = false; + boolean deleteKey = false; + + for( int index = 0; index < lines.length; index++ ) + { + String line = lines[index].trim(); + + if( continueLine ) + { + continueLine = line.endsWith( "\\" ); + + if( !deleteKey ) + { + outputFile.println( line ); + } + else + { + deleteFile.println( line ); + } + + continue; + } + + continueLine = line.endsWith( "\\" ); + + boolean validKey = isLineKey( keys, line ); + boolean hasKey = line.indexOf( '=' ) != -1; + + if( validKey ) + { + outputFile.println( line ); + deleteKey = false; + } + else if( hasKey ) + { + deleteKey = true; + deleteFile.println( line ); + } + else + { + outputFile.println( line ); + } + } + } + + public static boolean isLineKey( Collection keys, String line ) + { + boolean result = false; + Iterator iter = keys.iterator(); + int equalIndex = line.indexOf( '=' ); + String key = null; + + if( equalIndex != -1 && !line.startsWith( "#" )) + { + key = line.substring( 0, equalIndex ); + } + + while( iter.hasNext() && key != null ) + { + String collectionKey = (String)iter.next(); + if( key.equals( collectionKey ) || collectionKey.equals( '%' + key ) ) + { + result = true; + break; + } + } + + return result; + } + + public static void getPluginXMLKeys( File file, HashSet keys ) + { + BufferedReader reader = null; + + try + { + reader = new BufferedReader( new FileReader( file ) ); + + String line = reader.readLine(); + + while( line != null ) + { + Vector linekeys = findKeys( line ); + keys.addAll( linekeys ); + line = reader.readLine(); + } + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + finally + { + try + { + if( reader != null ) reader.close(); + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + } + } + + public static File getFile( File base, final String child ) + { + File[] file = base.listFiles( new FilenameFilter() + { + public boolean accept( File file, String name ) + { + int index = name.indexOf( '_' ); + + if( index != -1 ) + { + name = name.substring( 0, index ); + } + + return name.endsWith( child ); + } + } ); + return file.length == 0 ? null : file[0]; + } + + public static Vector findKeys( String line ) + { + Vector keys = new Vector(); + int quotestart = line.indexOf( '"' ); + int quoteend = line.indexOf( '"', quotestart + 1 ); + + while( quotestart != -1 && quoteend != -1 && quotestart < quoteend ) + { + String key = line.substring( quotestart+1, quoteend ); + + if( key.startsWith( "%") ) + { + keys.add( key.substring(1, key.length() ) ); + } + + quotestart = line.indexOf( '"', quoteend+1 ); + quoteend = line.indexOf( '"', quotestart+1 ); + } + + return keys; + } + + public static void findJavaStrings( String line, Vector keys ) + { + int quotestart = line.indexOf( '"' ); + int quoteend = line.indexOf( '"', quotestart + 1 ); + + while( quotestart != -1 && quoteend != -1 && quotestart < quoteend ) + { + // Find last real ending quote. + while( quotestart != -1 && quoteend != -1 && line.charAt( quoteend-1 ) == '\\' ) + { + quoteend = line.indexOf( '"', quoteend + 1 ); + } + + if( quotestart == -1 || quoteend == -1 || quotestart > quoteend ) break; + + String key = line.substring( quotestart+1, quoteend ); + + keys.add( key ); + + quotestart = line.indexOf( '"', quoteend+1 ); + quoteend = line.indexOf( '"', quotestart+1 ); + } + } + + public static String[] readLines( File file ) + { + Vector files = new Vector(); + BufferedReader reader = null; + + try + { + reader = new BufferedReader( new FileReader( file ) ); + + String line = reader.readLine(); + + while( line != null ) + { + files.add( line ); + line = reader.readLine(); + } + } + catch( Exception exc ) + { + System.out.println( "Problem opening file:" + file ); + exc.printStackTrace(); + } + finally + { + try + { + if( reader != null ) reader.close(); + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + } + + return (String[])files.toArray( new String[0] ); + + } + + public static String[] readLines( String file ) + { + return readLines( new File( file ) ); + } + + public static void getFiles( File file, Vector files, String fileSuffix, String[] excludeFiles ) + { + if( stringInArray( file.getName(), excludeFiles ) ) + { + // do nothing + } + else if( file.isDirectory() ) + { + File[] dirfiles = file.listFiles(); + + for( int index = 0; index < dirfiles.length; index++ ) + { + getFiles( dirfiles[index], files, fileSuffix, excludeFiles ); + } + } + else if( file.getName().endsWith( fileSuffix ) ) + { + files.add( file ); + } + } + + public static boolean stringInArray( String name, String[] names ) + { + boolean found = false; + + for( int index = 0; index < names.length; index++ ) + { + if( name.equals( names[index] )) + { + found = true; + break; + } + } + + return found; + } + public static Vector getPropertyKeys( File file ) + { + Vector keys = new Vector(); + InputStream stream = null; + + try + { + stream = new FileInputStream( file ); + + PropertyResourceBundle bundle = new PropertyResourceBundle( stream ); + Enumeration keyEnum = bundle.getKeys(); + + while( keyEnum.hasMoreElements() ) + { + keys.add( keyEnum.nextElement() ); + } + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + finally + { + try + { + if( stream != null ) stream.close(); + } + catch( Exception exc ) + { + exc.printStackTrace(); + } + } + + return keys; + } +} -- cgit v1.2.3