001package org.apache.maven.scm.provider.svn.svnexe.command.info; 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 022import java.util.ArrayList; 023import java.util.List; 024 025import org.apache.maven.scm.command.info.InfoItem; 026import org.codehaus.plexus.util.cli.StreamConsumer; 027 028/** 029 * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a> 030 * 031 */ 032public class SvnInfoConsumer 033 implements StreamConsumer 034{ 035 private List<InfoItem> infoItems = new ArrayList<InfoItem>(); 036 037 private InfoItem currentItem = new InfoItem(); 038 039 /** {@inheritDoc} */ 040 public void consumeLine( String s ) 041 { 042 if ( s.equals( "" ) ) 043 { 044 if ( currentItem != null ) 045 { 046 infoItems.add( currentItem ); 047 } 048 049 currentItem = new InfoItem(); 050 } 051 else if ( s.startsWith( "Path: " ) ) 052 { 053 currentItem.setPath( getValue( s ) ); 054 } 055 else if ( s.startsWith( "URL: " ) ) 056 { 057 currentItem.setURL( getValue( s ) ); 058 } 059 else if ( s.startsWith( "Repository Root: " ) ) 060 { 061 currentItem.setRepositoryRoot( getValue( s ) ); 062 } 063 else if ( s.startsWith( "Repository UUID: " ) ) 064 { 065 currentItem.setRepositoryUUID( getValue( s ) ); 066 } 067 else if ( s.startsWith( "Revision: " ) ) 068 { 069 currentItem.setRevision( getValue( s ) ); 070 } 071 else if ( s.startsWith( "Node Kind: " ) ) 072 { 073 currentItem.setNodeKind( getValue( s ) ); 074 } 075 else if ( s.startsWith( "Schedule: " ) ) 076 { 077 currentItem.setSchedule( getValue( s ) ); 078 } 079 else if ( s.startsWith( "Last Changed Author: " ) ) 080 { 081 currentItem.setLastChangedAuthor( getValue( s ) ); 082 } 083 else if ( s.startsWith( "Last Changed Rev: " ) ) 084 { 085 currentItem.setLastChangedRevision( getValue( s ) ); 086 } 087 else if ( s.startsWith( "Last Changed Date: " ) ) 088 { 089 currentItem.setLastChangedDate( getValue( s ) ); 090 } 091 } 092 093 private static String getValue( String s ) 094 { 095 int idx = s.indexOf( ": " ); 096 097 if ( idx < 0 ) 098 { 099 // FIXME: Can't throw any exceptions in consumeLine.. 100 return null; 101 } 102 else 103 { 104 return s.substring( idx + 2 ); 105 } 106 } 107 108 public List<InfoItem> getInfoItems() 109 { 110 return infoItems; 111 } 112}