//$HeadURL$
/*----------------------------------------------------------------------------
 This file is part of deegree, http://deegree.org/
 Copyright (C) 2001-2009 by:
 - Department of Geography, University of Bonn -
 and
 - lat/lon GmbH -

 This library is free software; you can redistribute it and/or modify it under
 the terms of the GNU Lesser General Public License as published by the Free
 Software Foundation; either version 2.1 of the License, or (at your option)
 any later version.
 This library is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 details.
 You should have received a copy of the GNU Lesser General Public License
 along with this library; if not, write to the Free Software Foundation, Inc.,
 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

 Contact information:

 lat/lon GmbH
 Aennchenstr. 19, 53177 Bonn
 Germany
 http://lat-lon.de/

 Department of Geography, University of Bonn
 Prof. Dr. Klaus Greve
 Postfach 1147, 53001 Bonn
 Germany
 http://www.geographie.uni-bonn.de/deegree/

 e-mail: info@deegree.org
 ----------------------------------------------------------------------------*/
package org.deegree.commons.processors;

import static org.slf4j.LoggerFactory.getLogger;

import java.io.File;
import java.io.IOException;
import java.util.Set;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedOptions;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;

import org.apache.commons.io.FileUtils;
import org.deegree.commons.annotations.ConsoleManaged;
import org.slf4j.Logger;

/**
 * <code>LoggingAnnotationProcessor</code>
 * 
 * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
 * @author last edited by: $Author$
 * 
 * @version $Revision$, $Date$
 */

@SupportedAnnotationTypes(value = { "org.deegree.commons.annotations.ConsoleManaged" })
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedOptions( { "basedir" })
public class ConsoleManagedProcessor extends AbstractProcessor {

    private static final Logger LOG = getLogger( ConsoleManagedProcessor.class );

    private String basedir;

    @Override
    public void init( ProcessingEnvironment env ) {
        super.init( env );
        basedir = env.getOptions().get( "basedir" );
        if ( basedir == null ) {
            LOG.info( "No basedir set - skipping processing of console managed annotations." );
            return;
        }
        File parentFile = new File( basedir );
        if ( !parentFile.exists() && !parentFile.mkdirs() ) {
            LOG.warn( "Target directory could not be created: {}", parentFile );
        }
    }

    private void find( Element e )
                            throws IOException {
        ConsoleManaged managed = e.getAnnotation( ConsoleManaged.class );

        if ( managed != null ) {
            FileUtils.copyDirectory( new File( basedir, managed.directory() ),
                                     new File( "target/classes/META-INF/deegree/console" ) );
        }

        for ( Element e2 : e.getEnclosedElements() ) {
            find( e2 );
        }
    }

    @Override
    public boolean process( Set<? extends TypeElement> annotations, RoundEnvironment roundEnv ) {
        if ( basedir == null ) {
            return false;
        }

        for ( Element e : roundEnv.getRootElements() ) {
            try {
                find( e );
            } catch ( IOException e1 ) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }

        return false;
    }

}

@@ -1335,16 +1335,72 @@
 ssors;%0A%0A
+import static org.apache.commons.io.IOCase.INSENSITIVE;%0A
 import s
@@ -2017,16 +2017,181 @@
 eUtils;%0A
+import org.apache.commons.io.filefilter.IOFileFilter;%0Aimport org.apache.commons.io.filefilter.NameFileFilter;%0Aimport org.apache.commons.io.filefilter.NotFileFilter;%0A
 import o
@@ -3502,32 +3502,183 @@
 ged != null ) %7B%0A
+            IOFileFilter filter = new NameFileFilter( new String%5B%5D %7B %22CVS%22, %22.svn%22 %7D, INSENSITIVE );%0A            filter = new NotFileFilter( filter );%0A
             File
@@ -3830,16 +3830,24 @@
 nsole%22 )
+, filter
  );%0A    
@@ -4294,78 +4294,86 @@
     
-// TODO Auto-generated catch block%0A                e1.printStackTrace(
+LOG.warn( %22IO error when copying console files: %7B%7D%22, e1.getLocalizedMessage() 
 );%0A 

exclude .svn and CVS directories when packing the console files