1
package org.apache.maven.wagon.providers.ssh;
4
* Licensed to the Apache Software Foundation (ASF) under one
5
* or more contributor license agreements. See the NOTICE file
6
* distributed with this work for additional information
7
* regarding copyright ownership. The ASF licenses this file
8
* to you under the Apache License, Version 2.0 (the
9
* "License"); you may not use this file except in compliance
10
* with the License. You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* Unless required by applicable law or agreed to in writing,
15
* software distributed under the License is distributed on an
16
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
* KIND, either express or implied. See the License for the
18
* specific language governing permissions and limitations
22
import org.apache.maven.wagon.TransferFailedException;
24
import java.io.BufferedReader;
25
import java.io.IOException;
26
import java.io.StringReader;
27
import java.util.ArrayList;
28
import java.util.List;
29
import java.util.regex.Matcher;
30
import java.util.regex.Pattern;
35
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
36
* @version $Id: LSParser.java 1174063 2011-09-22 11:22:43Z olamy $
41
* output samples see LSParserTest:
43
* <li>osx "-rw-r--r-- 1 joakim joakim 1194 Dec 11 09:25 pom.xml"</li>
44
* <li>osx fr : "-rw-r--r-- 1 olamy staff 19 21 sep 00:34 more-resources.dat"</li>
45
* <li>cygwin : "drwxr-xr-x+ 5 joakim None 0 Dec 11 10:30 pom.xml"</li>
46
* <li>linux : "-rw-r--r-- 1 joakim joakim 1194 2006-12-11 09:25 pom.xml"</li>
49
private static final Pattern PATTERN = Pattern.compile( ".+\\s+[0-9]+\\s+.+\\s+.+\\s+[0-9]+\\s+"
51
+ "([0-9]{4}-[0-9]{2}-[0-9]{2}"
57
+ "\\s+[0-9:]+\\s+(.+?)" );
60
* Parse a raw "ls -FlA", and obtain the list of files.
62
* @param rawLS the raw LS to parse.
63
* @return the list of files found.
64
* @throws TransferFailedException
65
* @todo use ls -1a and do away with the method all together
67
public List<String> parseFiles( String rawLS )
68
throws TransferFailedException
70
List<String> ret = new ArrayList<String>();
73
BufferedReader br = new BufferedReader( new StringReader( rawLS ) );
75
String line = br.readLine();
77
while ( line != null )
81
Matcher m = PATTERN.matcher( line );
84
ret.add( m.group( 2 ) );
89
catch ( IOException e )
91
throw new TransferFailedException( "Error parsing file listing.", e );