001    package org.apache.maven.scm.provider.synergy.consumer;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     * http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.maven.scm.log.ScmLogger;
023    import org.codehaus.plexus.util.cli.StreamConsumer;
024    
025    import java.io.File;
026    
027    /**
028     * Parse output of
029     * <p/>
030     * <pre>
031     * ccm wa -show -p &lt;project_spec&gt;
032     * </pre>
033     *
034     * @author <a href="mailto:julien.henry@capgemini.com">Julien Henry</a>
035     *
036     */
037    public class SynergyWorkareaConsumer
038        implements StreamConsumer
039    {
040        private ScmLogger logger;
041    
042        private File workarea;
043    
044        public SynergyWorkareaConsumer( ScmLogger logger )
045        {
046            this.logger = logger;
047        }
048    
049        /**
050         * We are expecting the following output:
051         * <p/>
052         * <pre>
053         *            Project Maintain Copies Relative Time Translate Modify Path
054         *            -------------------------------------------------------------------
055         *            BGZBFZH&tilde;1 TRUE TRUE FALSE FALSE TRUE FALSE 'D:\cmsynergy\ccm_wa\LAPOSTE\BGZBFZH&tilde;1'
056         * </pre>
057         * <p/>
058         * And we want to extract:
059         * <p/>
060         * <pre>
061         *            D:\cmsynergy\ccm_wa\LAPOSTE\BGZBFZH&tilde;1
062         *            &lt;pre&gt;
063         *
064         * {@inheritDoc}
065         */
066        public void consumeLine( String line )
067        {
068            if ( logger.isDebugEnabled() )
069            {
070                logger.debug( line );
071            }
072            if ( line.indexOf( " '" ) > -1 )
073            {
074                int beginIndex = line.indexOf( " '" );
075                String fileName = line.substring( beginIndex + 2, line.indexOf( "'", beginIndex + 2 ) );
076                workarea = new File( fileName );
077            }
078        }
079    
080        public File getWorkAreaPath()
081        {
082            return workarea;
083        }
084    }