axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hemap...@apache.org
Subject cvs commit: ws-axis/contrib/ews/src/org/apache/geronimo/ews/ws4j2ee/utils/packager JARFileEntry.java JARFile.java Packager.java
Date Thu, 10 Jun 2004 11:33:12 GMT
hemapani    2004/06/10 04:33:12

  Modified:    contrib/ews/src/org/apache/geronimo/ews/ws4j2ee/utils/packager
                        JARFileEntry.java JARFile.java Packager.java
  Log:
  update the packager to able to add jar files and create new jar file having all files in
the both jarfiles
  
  Revision  Changes    Path
  1.3       +4 -3      ws-axis/contrib/ews/src/org/apache/geronimo/ews/ws4j2ee/utils/packager/JARFileEntry.java
  
  Index: JARFileEntry.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/contrib/ews/src/org/apache/geronimo/ews/ws4j2ee/utils/packager/JARFileEntry.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JARFileEntry.java	4 Feb 2004 04:29:56 -0000	1.2
  +++ JARFileEntry.java	10 Jun 2004 11:33:12 -0000	1.3
  @@ -55,6 +55,7 @@
   
   package org.apache.geronimo.ews.ws4j2ee.utils.packager;
   
  +import java.io.InputStream;
   import java.util.jar.JarEntry;
   
   /**
  @@ -66,9 +67,9 @@
    */
   public class JARFileEntry {
       private JarEntry jarEntry;
  -    private String source;
  +    private InputStream source;
   
  -    public JARFileEntry(String jarfilePath, String source) {
  +    public JARFileEntry(String jarfilePath, InputStream source) {
           this.jarEntry = new JarEntry(jarfilePath);
           this.source = source;
           if (this.source == null || this.jarEntry == null)
  @@ -85,7 +86,7 @@
       /**
        * @return 
        */
  -    public String getSource() {
  +    public InputStream getSource() {
           return source;
       }
   
  
  
  
  1.3       +38 -17    ws-axis/contrib/ews/src/org/apache/geronimo/ews/ws4j2ee/utils/packager/JARFile.java
  
  Index: JARFile.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/contrib/ews/src/org/apache/geronimo/ews/ws4j2ee/utils/packager/JARFile.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JARFile.java	4 Feb 2004 04:29:55 -0000	1.2
  +++ JARFile.java	10 Jun 2004 11:33:12 -0000	1.3
  @@ -58,13 +58,18 @@
   import java.io.BufferedInputStream;
   import java.io.BufferedOutputStream;
   import java.io.File;
  -import java.io.FileInputStream;
   import java.io.FileOutputStream;
   import java.io.IOException;
   import java.io.InputStream;
  -import java.util.Vector;
  +import java.util.Enumeration;
  +import java.util.HashMap;
  +import java.util.Iterator;
   import java.util.jar.JarEntry;
  +import java.util.jar.JarFile;
   import java.util.jar.JarOutputStream;
  +import java.util.zip.ZipEntry;
  +
  +import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
   
   /**
    * create a jar file with given set of jar entries.
  @@ -79,21 +84,36 @@
    * @author Srinath Perera(hemapani@opensource.lk)
    */
   public class JARFile {
  -    private Vector jarEntries;
  +    private HashMap jarEntries;
       private File path;
   
  -    public JARFile(String path, Vector entries) {
  +    public JARFile(String path, HashMap entries) {
           jarEntries = entries;
           this.path = new File(path);
       }
   
       public JARFile(File path) {
           this.path = path;
  -        jarEntries = new Vector();
  +        jarEntries = new HashMap();
  +    }
  +    
  +    public void addJarFile(String jarFile) throws GenerationFault{
  +        try {
  +    		JarFile file = new JarFile(jarFile);
  +    		Enumeration e = file.entries();
  +    		while(e.hasMoreElements()){
  +    			ZipEntry entry = (ZipEntry)e.nextElement();
  +    			JARFileEntry newEntry = new JARFileEntry(entry.getName(),file.getInputStream(entry));
  +				this.jarEntries.put(entry.getName(),newEntry);
  +    		}
  +        } catch (IOException e) {
  +            e.printStackTrace();
  +            throw new GenerationFault(e);
  +        }
       }
   
       public void addJarEntry(JARFileEntry entry) {
  -        this.jarEntries.add(entry);
  +        this.jarEntries.put(entry.getJarEntry().getName(),entry);
       }
   
       public void createNewJarFile() throws IOException {
  @@ -104,20 +124,21 @@
   
           BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream(path));
           JarOutputStream jo = new JarOutputStream(bo);
  +		Iterator it = jarEntries.values().iterator();
  +        for (; it.hasNext();) {
   
  -        for (int i = 0; i < jarEntries.size(); i++) {
  -
  -            JARFileEntry jarentry = (JARFileEntry) jarEntries.get(i);
  +            JARFileEntry jarentry = (JARFileEntry) it.next();
               System.out.println(jarentry.getSource() + " adding ..");
  +			InputStream instream = null;
  +//            File input = new File(jarentry.getSource());
   
  -            File input = new File(jarentry.getSource());
  -            InputStream instream = null;
  -
  -            if (input.exists())
  -                instream = new FileInputStream(input);
  -            else
  -                instream = JARFile.class.getClassLoader()
  -                        .getResourceAsStream(jarentry.getSource());
  +//
  +//            if (input.exists())
  +//                instream = new FileInputStream(input);
  +//            else
  +//                instream = JARFile.class.getClassLoader()
  +//                        .getResourceAsStream(jarentry.getSource());
  +			instream = jarentry.getSource();           
   
               BufferedInputStream source = new BufferedInputStream(instream);
   
  
  
  
  1.3       +175 -163  ws-axis/contrib/ews/src/org/apache/geronimo/ews/ws4j2ee/utils/packager/Packager.java
  
  Index: Packager.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/contrib/ews/src/org/apache/geronimo/ews/ws4j2ee/utils/packager/Packager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Packager.java	4 Feb 2004 04:29:56 -0000	1.2
  +++ Packager.java	10 Jun 2004 11:33:12 -0000	1.3
  @@ -55,16 +55,11 @@
   
   package org.apache.geronimo.ews.ws4j2ee.utils.packager;
   
  -import org.apache.geronimo.ews.ws4j2ee.toWs.UnrecoverableGenarationFault;
  -
  -import java.io.BufferedReader;
   import java.io.File;
  -import java.io.FileInputStream;
  -import java.io.FileNotFoundException;
  -import java.io.FileReader;
   import java.io.IOException;
   import java.io.InputStream;
  -import java.util.ArrayList;
  +
  +import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
   
   /**
    * <p>Package the ws4j2ee genarated classes. For the time been a file
  @@ -81,176 +76,193 @@
       public Packager() {
           ejbjar = new JARFile(new File("x-ejb.jar"));
           jaxrpcjar = new JARFile(new File("x-jaxrpc.jar"));
  -
  -        JARFileEntry jentry1 = new JARFileEntry("META-INF/services/org.apache.axis.deployment.wsdd.Provider",
  -                "org.apache.axis.deployment.wsdd.Provider");
  -        JARFileEntry jentry2 = new JARFileEntry("org.apache.axis.deployment.wsdd.WSDDJavaJ2EEProvider.class",
  -                "org/apache/axis/deployment/wsdd/WSDDJavaJ2EEProvider.class");
  -
  -        JARFileEntry jentry3 = new JARFileEntry("org.apache.axis.J2EEProvider.class",
  -                "org/apache/axis/J2EEProvider.class");
  +		InputStream in = Packager.class.getClassLoader()
  +					.getResourceAsStream("org.apache.axis.deployment.wsdd.Provider");
  +        JARFileEntry jentry1 
  +        	= new JARFileEntry("META-INF/services/org.apache.axis.deployment.wsdd.Provider",in);
  +		in = Packager.class.getClassLoader()
  +					.getResourceAsStream("org/apache/axis/deployment/wsdd/WSDDJavaJ2EEProvider.class");
  +        JARFileEntry jentry2 = new JARFileEntry("org.apache.axis.deployment.wsdd.WSDDJavaJ2EEProvider.class",in);
  +		in = Packager.class.getClassLoader()
  +					.getResourceAsStream("org/apache/axis/J2EEProvider.class");
  +        JARFileEntry jentry3 = new JARFileEntry("org.apache.axis.J2EEProvider.class",in);
   
           jaxrpcjar.addJarEntry(jentry1);
           jaxrpcjar.addJarEntry(jentry2);
           jaxrpcjar.addJarEntry(jentry3);
       }
   
  -    public void loadFromDir(String ejbDir,
  -                            String jaxrpcDir) {
  -        //get EJBClass files							
  -        FileSerachAgent searcher = new FileSerachAgent(ejbDir);
  -        searcher.addAcceptedFile(".class");
  -        ArrayList ejbClassFiles = searcher.serach();
  -
  -        for (int i = 0; i < ejbClassFiles.size(); i++) {
  -            String filename = (String) ejbClassFiles.get(i);
  -            JARFileEntry jentry =
  -                    new JARFileEntry(filename, getOutClassFileName(filename, ejbDir));
  -            ejbjar.addJarEntry(jentry);
  -            jaxrpcjar.addJarEntry(jentry);
  -        }
  -
  -        searcher = new FileSerachAgent(ejbDir);
  -        searcher.addRejectedFile(".class");
  -        searcher.setDefaultForUnspsecified(true);
  -        ArrayList ejbDDFiles = searcher.serach();
  -
  -        for (int i = 0; i < ejbDDFiles.size(); i++) {
  -            String filename = (String) ejbDDFiles.get(i);
  -            JARFileEntry jentry =
  -                    new JARFileEntry(filename, getOutDDName(filename));
  -            ejbjar.addJarEntry(jentry);
  -        }
  -
  -        searcher = new FileSerachAgent(jaxrpcDir);
  -        searcher.addAcceptedFile(".class");
  -        ArrayList jaxrpcClassFiles = searcher.serach();
  -
  -        for (int i = 0; i < jaxrpcClassFiles.size(); i++) {
  -            String filename = (String) jaxrpcClassFiles.get(i);
  -            JARFileEntry jentry =
  -                    new JARFileEntry(filename, getOutClassFileName(filename, jaxrpcDir));
  -            jaxrpcjar.addJarEntry(jentry);
  -            ejbjar.addJarEntry(jentry);
  -        }
  -
  -        searcher = new FileSerachAgent(jaxrpcDir);
  -        searcher.addRejectedFile(".class");
  -        searcher.setDefaultForUnspsecified(true);
  -        ArrayList jaxrpcDDFiles = searcher.serach();
  -
  -        for (int i = 0; i < jaxrpcDDFiles.size(); i++) {
  -            String filename = (String) jaxrpcDDFiles.get(i);
  -            JARFileEntry jentry =
  -                    new JARFileEntry(filename, getOutDDName(filename));
  -            jaxrpcjar.addJarEntry(jentry);
  -        }
  -    }
  -
  -    public void loadFromCL(String[] args) {
  -        try {
  -            BufferedReader reader = new BufferedReader(new FileReader(JARCONF_FILE));
  -            String line = null;
  -            String inputfilename = null;
  -            String outfilename = null;
  -            InputStream inputStream = null;
  -
  -            for (int i = 0; i < args.length; i++) {
  -                line = args[i];
  -                if (line.length() < 2)
  -                    continue;
  -                if (!(line.endsWith(".xml") || line.endsWith(".wsdl") || line.endsWith(".class")))
{
  -                    inputfilename = (line.substring(line.indexOf(':') + 1)).replace('.',
'/') + ".class";
  -                    outfilename = (line.substring(line.indexOf(':') + 1)).replace('.',
'/') + ".class";
  -                } else {
  -                    inputfilename = (line.substring(line.indexOf(':') + 1));
  -                    outfilename = "META-INF/" + (line.substring(line.indexOf(':') + 1));
  -                }
  -
  -                JARFileEntry jentry = new JARFileEntry(outfilename, inputfilename);
  -
  -                if (line.startsWith("ejb:")) {
  -                    ejbjar.addJarEntry(jentry);
  -                } else if (line.startsWith("jaxrpc:")) {
  -                    jaxrpcjar.addJarEntry(jentry);
  -                }
  -            }
  -        } catch (FileNotFoundException e) {
  -            throw new UnrecoverableGenarationFault(e.getMessage());
  -        }
  -    }
  -
  -    private void loadFromFile() {
  -        try {
  -            BufferedReader reader = new BufferedReader(new FileReader(JARCONF_FILE));
  -            String line = null;
  -            String inputfilename = null;
  -            String outfilename = null;
  -            InputStream inputStream = null;
  -
  -            while ((line = reader.readLine()) != null) {
  -                if (line.length() < 2)
  -                    continue;
  -                if (!(line.endsWith(".xml") || line.endsWith(".wsdl") || line.endsWith(".class")))
{
  -                    inputfilename = (line.substring(line.indexOf(':') + 1)).replace('.',
'/') + ".class";
  -                    outfilename = (line.substring(line.indexOf(':') + 1)).replace('.',
'/') + ".class";
  -                } else {
  -                    inputfilename = (line.substring(line.indexOf(':') + 1));
  -                    outfilename = "META-INF/" + (line.substring(line.indexOf(':') + 1));
  -                }
  -
  -                File file = new File(inputfilename);
  -                if (file.exists())
  -                    inputStream = new FileInputStream(file);
  -                else
  -                    inputStream = Packager.class.getClassLoader().getResourceAsStream(inputfilename);
  -
  -                JARFileEntry jentry = new JARFileEntry(outfilename, inputfilename);
  -
  -                if (line.startsWith("ejb:")) {
  -                    ejbjar.addJarEntry(jentry);
  -                } else if (line.startsWith("jaxrpc:")) {
  -                    jaxrpcjar.addJarEntry(jentry);
  -                }
  -            }
  -
  -        } catch (FileNotFoundException e) {
  -            throw new UnrecoverableGenarationFault(e.getMessage());
  -        } catch (IOException e) {
  -            throw new UnrecoverableGenarationFault(e.getMessage());
  -        }
  -
  -    }
  -
  -    public void createNewJarFile() throws IOException {
  -        ejbjar.createNewJarFile();
  -        jaxrpcjar.createNewJarFile();
  -    }
  -
  -    private String getOutClassFileName(String filename, String dir) {
  -        String out = filename.substring(dir.length());
  -        if (out.startsWith("/"))
  -            out = out.substring(1);
  -        return out;
  -    }
  -
  -    private String getOutDDName(String filename) {
  -        String out = "META-INF/" + filename.substring(filename.lastIndexOf("/"));
  -        return out;
  -    }
  -
  -    public static void main(String[] args) throws Exception {
  -        Packager packager = new Packager();
  +//    public void loadFromDir(String ejbDir,
  +//                            String jaxrpcDir) {
  +//        //get EJBClass files							
  +//        FileSerachAgent searcher = new FileSerachAgent(ejbDir);
  +//        searcher.addAcceptedFile(".class");
  +//        ArrayList ejbClassFiles = searcher.serach();
  +//
  +//        for (int i = 0; i < ejbClassFiles.size(); i++) {
  +//            String filename = (String) ejbClassFiles.get(i);
  +//            JARFileEntry jentry =
  +//                    new JARFileEntry(filename, getOutClassFileName(filename, ejbDir));
  +//            ejbjar.addJarEntry(jentry);
  +//            jaxrpcjar.addJarEntry(jentry);
  +//        }
  +//
  +//        searcher = new FileSerachAgent(ejbDir);
  +//        searcher.addRejectedFile(".class");
  +//        searcher.setDefaultForUnspsecified(true);
  +//        ArrayList ejbDDFiles = searcher.serach();
  +//
  +//        for (int i = 0; i < ejbDDFiles.size(); i++) {
  +//            String filename = (String) ejbDDFiles.get(i);
  +//            JARFileEntry jentry =
  +//                    new JARFileEntry(filename, getOutDDName(filename));
  +//            ejbjar.addJarEntry(jentry);
  +//        }
  +//
  +//        searcher = new FileSerachAgent(jaxrpcDir);
  +//        searcher.addAcceptedFile(".class");
  +//        ArrayList jaxrpcClassFiles = searcher.serach();
  +//
  +//        for (int i = 0; i < jaxrpcClassFiles.size(); i++) {
  +//            String filename = (String) jaxrpcClassFiles.get(i);
  +//            JARFileEntry jentry =
  +//                    new JARFileEntry(filename, getOutClassFileName(filename, jaxrpcDir));
  +//            jaxrpcjar.addJarEntry(jentry);
  +//            ejbjar.addJarEntry(jentry);
  +//        }
  +//
  +//        searcher = new FileSerachAgent(jaxrpcDir);
  +//        searcher.addRejectedFile(".class");
  +//        searcher.setDefaultForUnspsecified(true);
  +//        ArrayList jaxrpcDDFiles = searcher.serach();
  +//
  +//        for (int i = 0; i < jaxrpcDDFiles.size(); i++) {
  +//            String filename = (String) jaxrpcDDFiles.get(i);
  +//            JARFileEntry jentry =
  +//                    new JARFileEntry(filename, getOutDDName(filename));
  +//            jaxrpcjar.addJarEntry(jentry);
  +//        }
  +//    }
  +
  +//    public void loadFromCL(String[] args) {
  +//        try {
  +//            BufferedReader reader = new BufferedReader(new FileReader(JARCONF_FILE));
  +//            String line = null;
  +//            String inputfilename = null;
  +//            String outfilename = null;
  +//            InputStream inputStream = null;
  +//
  +//            for (int i = 0; i < args.length; i++) {
  +//                line = args[i];
  +//                if (line.length() < 2)
  +//                    continue;
  +//                if (!(line.endsWith(".xml") || line.endsWith(".wsdl") || line.endsWith(".class")))
{
  +//                    inputfilename = (line.substring(line.indexOf(':') + 1)).replace('.',
'/') + ".class";
  +//                    outfilename = (line.substring(line.indexOf(':') + 1)).replace('.',
'/') + ".class";
  +//                } else {
  +//                    inputfilename = (line.substring(line.indexOf(':') + 1));
  +//                    outfilename = "META-INF/" + (line.substring(line.indexOf(':') + 1));
  +//                }
  +//
  +//                JARFileEntry jentry = new JARFileEntry(outfilename, inputfilename);
  +//
  +//                if (line.startsWith("ejb:")) {
  +//                    ejbjar.addJarEntry(jentry);
  +//                } else if (line.startsWith("jaxrpc:")) {
  +//                    jaxrpcjar.addJarEntry(jentry);
  +//                }
  +//            }
  +//        } catch (FileNotFoundException e) {
  +//            throw new UnrecoverableGenarationFault(e.getMessage());
  +//        }
  +//    }
  +//
  +//    private void loadFromFile() {
  +//        try {
  +//            BufferedReader reader = new BufferedReader(new FileReader(JARCONF_FILE));
  +//            String line = null;
  +//            String inputfilename = null;
  +//            String outfilename = null;
  +//            InputStream inputStream = null;
  +//
  +//            while ((line = reader.readLine()) != null) {
  +//                if (line.length() < 2)
  +//                    continue;
  +//                if (!(line.endsWith(".xml") || line.endsWith(".wsdl") || line.endsWith(".class")))
{
  +//                    inputfilename = (line.substring(line.indexOf(':') + 1)).replace('.',
'/') + ".class";
  +//                    outfilename = (line.substring(line.indexOf(':') + 1)).replace('.',
'/') + ".class";
  +//                } else {
  +//                    inputfilename = (line.substring(line.indexOf(':') + 1));
  +//                    outfilename = "META-INF/" + (line.substring(line.indexOf(':') + 1));
  +//                }
  +//
  +//                File file = new File(inputfilename);
  +//                if (file.exists())
  +//                    inputStream = new FileInputStream(file);
  +//                else
  +//                    inputStream = Packager.class.getClassLoader().getResourceAsStream(inputfilename);
  +//
  +//                JARFileEntry jentry = new JARFileEntry(outfilename, inputfilename);
  +//
  +//                if (line.startsWith("ejb:")) {
  +//                    ejbjar.addJarEntry(jentry);
  +//                } else if (line.startsWith("jaxrpc:")) {
  +//                    jaxrpcjar.addJarEntry(jentry);
  +//                }
  +//            }
  +//
  +//        } catch (FileNotFoundException e) {
  +//            throw new UnrecoverableGenarationFault(e.getMessage());
  +//        } catch (IOException e) {
  +//            throw new UnrecoverableGenarationFault(e.getMessage());
  +//        }
  +//
  +//    }
  +//
  +//    public void createNewJarFile() throws IOException {
  +//        ejbjar.createNewJarFile();
  +//        jaxrpcjar.createNewJarFile();
  +//    }
  +//
  +//    private String getOutClassFileName(String filename, String dir) {
  +//        String out = filename.substring(dir.length());
  +//        if (out.startsWith("/"))
  +//            out = out.substring(1);
  +//        return out;
  +//    }
  +//
  +//    private String getOutDDName(String filename) {
  +//        String out = "META-INF/" + filename.substring(filename.lastIndexOf("/"));
  +//        return out;
  +//    }
  +//
  +    public static void main(String[] args) {
  +//        Packager packager = new Packager();
   //		if(args.length > 0)
   //			packager.loadFromCL(args);
   //		else
   //			packager.loadFromFile();
   //		packager.createNewJarFile();
  -        //packager.loadFromDir();	
  -		
  +//        packager.loadFromDir();	
  +//		
   //		File file = new File(JARCONF_FILE);
   //		if(file.exists()){
   //			file.delete();
   //		}
  +        try {
  +            JARFile jfile = new JARFile(new File(args[0]));
  +            for(int i = 1;i<args.length;i++){
  +            	jfile.addJarFile(args[i]);
  +            	System.out.println(args[i]);
  +            }
  +            jfile.createNewJarFile();
  +            
  +        } catch (GenerationFault e) {
  +            // TODO Auto-generated catch block
  +            e.printStackTrace();
  +        } catch (IOException e) {
  +            // TODO Auto-generated catch block
  +            e.printStackTrace();
  +        }
       }
   }
  
  
  

Mime
View raw message