krysalis-version/src/java/org/krysalis/version/util/classpath/walker FileListener.java,NONE,1.1 PathWalker.java,1.3,1.4

[email protected]
Newsgroups gmane.comp.krysalis.sandbox
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/util/classpath/walker
In directory sc8-pr-cvs1:/tmp/cvs-serv10753/src/java/org/krysalis/version/util/classpath/walker

Modified Files:
	PathWalker.java 
Added Files:
	FileListener.java 
Log Message:
1) Collecting constraints [first efforts]
2) Added 'publish cent' to Gump [hopefully]
3) Tweaked cent

--- NEW FILE: FileListener.java ---
/*
The Krysalis Patchy Software License, Version 1.1_01

Copyright (c) 2003 Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in
   the documentation and/or other materials provided with the
   distribution.

3. The end-user documentation included with the redistribution,
   if any, must include the following acknowledgment:
	  "This product includes software developed for project 
	   Krysalis (http://www.krysalis.org/)."
   Alternately, this acknowledgment may appear in the software itself,
   if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
   "Krysalis Centipede" must not be used to endorse or promote products
   derived from this software without prior written permission. For
   written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
   "Krysalis Centipede", nor may "Krysalis" appear in their name, without
	prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
   individuals, who decided to donate the code to this project in respect 
   of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================
*/
package org.krysalis.version.util.classpath.walker;

import java.io.InputStream;

/**
 * @author ajack
 */
public interface FileListener
{
	void processFile(Object context, InputStream file, String location)
		throws Exception;
}

Index: PathWalker.java
===================================================================
RCS file: /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/util/classpath/walker/PathWalker.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** PathWalker.java	18 Feb 2003 22:17:06 -0000	1.3
--- PathWalker.java	5 Mar 2003 00:36:42 -0000	1.4
***************
*** 58,61 ****
--- 58,63 ----
  
  import java.io.File;
+ import java.io.FileInputStream;
+ import java.io.InputStream;
  import java.util.ArrayList;
  import java.util.Enumeration;
***************
*** 67,71 ****
  
  import org.krysalis.version.util.Tuple;
! import org.krysalis.version.util.classpath.*;
  import org.krysalis.version.util.logging.VersionLogger;
  
--- 69,74 ----
  
  import org.krysalis.version.util.Tuple;
! import org.krysalis.version.util.classpath.PathPart;
! import org.krysalis.version.util.classpath.PathSet;
  import org.krysalis.version.util.logging.VersionLogger;
  
***************
*** 83,90 ****
--- 86,96 ----
      private PathSet m_pathSet = null;
  
+     private ArrayList m_fileListeners = null;
      private ArrayList m_classListeners = null;
      private ArrayList m_jarListeners = null;
      private ArrayList m_manifestListeners = null;
  
+     private String m_fileName = null;
+ 
      private String m_classEnding = null;
      private String m_classPart1 = null;
***************
*** 107,111 ****
      }
  
!    
      public PathWalker(
          Object listener,
--- 113,125 ----
      }
  
!     public PathWalker(Object listener, Object context, String fileName) {
! 
!         m_fileName = fileName;
! 
!         initialize();
! 
!         addListener(listener, context);
!     }
! 
      public PathWalker(
          Object listener,
***************
*** 119,123 ****
          m_classPart1 = classPart1;
          m_classPart2 = classPart2;
!         
          m_pathSet = pathSet;
  
--- 133,137 ----
          m_classPart1 = classPart1;
          m_classPart2 = classPart2;
! 
          m_pathSet = pathSet;
  
***************
*** 138,141 ****
--- 152,166 ----
      }
  
+     public PathWalker(JarListener listener, Object context) {
+ 
+         m_classEnding = null;
+         m_classPart1 = null;
+         m_classPart2 = null;
+ 
+         initialize();
+ 
+         addJarListener(listener, context);
+     }
+ 
      public PathWalker(String classEnding, String classPart1) {
          m_classEnding = classEnding;
***************
*** 167,170 ****
--- 192,198 ----
          if (listener instanceof JarListener)
              addJarListener((JarListener) listener, context);
+ 
+         if (listener instanceof FileListener)
+             addFileListener((FileListener) listener, context);
      }
  
***************
*** 176,179 ****
--- 204,214 ----
      }
  
+     public void addFileListener(FileListener fileListener, Object context) {
+         if (null == m_fileListeners)
+             m_fileListeners = new ArrayList();
+ 
+         m_fileListeners.add(new Tuple(fileListener, context));
+     }
+ 
      public void addManifestListener(
          ManifestListener manifestListener,
***************
*** 259,263 ****
                      //OSystem.g_out.println("Directory: " + dirName);        
  
!                     if (null != m_classListeners)
                          searchDirectory(file, null);
                  }
--- 294,299 ----
                      //OSystem.g_out.println("Directory: " + dirName);        
  
!                     if ((null != m_classListeners)
!                         || (null != m_fileListeners))
                          searchDirectory(file, null);
                  }
***************
*** 284,287 ****
--- 320,337 ----
              }
  
+             if (null != m_fileListeners) {
+                 for (Enumeration e = jf.entries(); e.hasMoreElements();) {
+                     JarEntry entry = (JarEntry) e.nextElement();
+                     String fileName = entry.getName();
+ 
+                     if (fileName.equals(m_fileName)) {
+ 
+                         processFile(
+                             jf.getInputStream(entry),
+                             "JAR:" + jar.getName());
+                     }
+                 }
+             }
+ 
              if (null != m_classListeners) {
                  for (Enumeration e = jf.entries(); e.hasMoreElements();) {
***************
*** 305,315 ****
              }
          }
-         catch (Exception e) {
-             System.err.println("Unable to open JAR:" + jar.toString());
-             e.printStackTrace(System.err);
-         }
          catch (Throwable t) {
!             System.err.println("Unable to open JAR:" + jar.toString());
!             t.printStackTrace(System.err);
          }
      }
--- 355,360 ----
              }
          }
          catch (Throwable t) {
!             VersionLogger.g_log.error("Throwable:" + jar + ")", t);
          }
      }
***************
*** 328,348 ****
                  if (file.exists()) {
                      if (file.isFile()) {
!                         String clazzName = file.getName();
  
!                         if (clazzName.endsWith(m_classEnding)) {
!                             String fullClazzName =
!                                 (path
!                                     + "."
!                                     + clazzName.substring(
!                                         0,
!                                         clazzName.length() - 6));
  
!                             //System.out.println("Class FileName: " + fullClazzName);
  
!                             searchForClass(
!                                 fullClazzName,
!                                 false,
!                                 "Directory:" + directoryName);
!                         }
                      }
                      else {
--- 373,399 ----
                  if (file.exists()) {
                      if (file.isFile()) {
!                         
!                         //System.out.println("Search File: " + fileName);
  
!                         if (null != m_fileName)
!                             if (fileName.equals(m_fileName))
!                                 processFile(fileName, file.getAbsolutePath());
  
!                         if (null != m_classEnding)
!                             if (fileName.endsWith(m_classEnding)) {
!                                 String fullClazzName =
!                                     (path
!                                         + "."
!                                         + fileName.substring(
!                                             0,
!                                 fileName.length() - 6));
  
!                                 System.out.println("Class FileName: " + fullClazzName);
! 
!                                 searchForClass(
!                                     fullClazzName,
!                                     false,
!                                     "Directory:" + directoryName);
!                             }
                      }
                      else {
***************
*** 401,404 ****
--- 452,483 ----
                  file,
                  manifest);
+         }
+     }
+ 
+     private void processFile(String fileName, String location) {
+         try {
+             processFile(new FileInputStream(fileName), location);
+         }
+         catch (Throwable t) {
+ 
+             VersionLogger.g_log.error("Throwable:" + fileName + ")", t);
+         }
+     }
+ 
+     private void processFile(InputStream file, String location)
+         throws Exception {
+             
+         VersionLogger.g_log.debug("Process File:" + file + "[" + location + "]");
+       
+             
+         for (Iterator listeners = m_fileListeners.iterator();
+             listeners.hasNext();
+             ) {
+             Tuple tuple = (Tuple) listeners.next();
+ 
+             ((FileListener) (tuple.getFirst())).processFile(
+                 tuple.getSecond(),
+                 file,
+                 location);
          }
      }




-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger 
for complex code. Debugging C/C++ programs can leave you feeling lost and 
disoriented. TotalView can help you find your way. Available on major UNIX 
and Linux platforms. Try it free. www.etnus.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.