krysalis-version/src/java/org/krysalis/version/constraint/collecting/collectors ClasspathConstraintCollector.java,NONE,1.1

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

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

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

Copyright (c) 2002-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.constraint.collecting.collectors;

import java.io.InputStream;

import org.krysalis.version.constraint.ConstraintSet;
import org.krysalis.version.constraint.collecting.ConstraintCollector;
import org.krysalis.version.constraint.collecting.ConstraintSetCollection;
import org.krysalis.version.constraint.loading.loaders.ConstraintTextLoader;
import org.krysalis.version.exception.VersionException;
import org.krysalis.version.loading.VersionLoaderLogger;
import org.krysalis.version.util.classpath.walker.FileListener;
import org.krysalis.version.util.classpath.walker.PathWalker;
import org.krysalis.version.util.note.AnnotationScratchpad;

//
// :TODO: Rework this to use the ClassLoader to load the JAR resource, since file system access may not match what a classloader provides.
//
/**
 * @author ajack. 
 */
public class ClasspathConstraintCollector
    extends ConstraintCollector
    implements FileListener {
        
    private ConstraintTextLoader m_loader = null;
    private PathWalker m_searcher = null;
    private ConstraintSetCollection m_collection = null;
    
    /**
    * Construct a VersionFinder class (a ClasspathSearcher specifialized for
    * Manifest)
    */
    public ClasspathConstraintCollector() {
        m_searcher = new PathWalker(this, null, "constraints.txt");
        m_loader = new ConstraintTextLoader();
    }

    public void collectInto(ConstraintSetCollection collection)
        throws VersionException {
        // :TODO: Not my favourite two lines of code, feels 'odd'
        // to hand off control, and be listening for event, and stashing
        // the values via a local member variable. Maybe need to pass the
        // collection via a search context.

        m_collection = collection;
        m_searcher.search();
    }

    public void processFile(
        Object walkContext,
        InputStream fileContents,
        String location)
        throws VersionException {
        VersionLoaderLogger.g_log.debug("*** File: " + location);

        AnnotationScratchpad pad = m_collection.getAnnotations();

        pad.addInfo("Loading from file: " + location);

        try
        {
            ConstraintSet set = m_loader.load(fileContents);
            
            m_collection.add(set);
        }
        catch (Exception e)
        {
            //:TODO:
        }
    }

    public static void main(String args[]) throws Exception {
        (new ClasspathConstraintCollector()).collect().dump(System.out);
    }
}




-------------------------------------------------------
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.