1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-04 23:55:26 +02:00

improved autodetection of FTPListingParser

This commit is contained in:
Javier Montalvo Orus 2007-05-14 17:36:48 +00:00
parent 0005a06a32
commit ddf02094dd
5 changed files with 189 additions and 75 deletions

View file

@ -39,6 +39,7 @@
* Javier Montalvo Orus (Symbian) - Fixing 174828 - [ftp] Folders are attempted to be removed as files
* Javier Montalvo Orus (Symbian) - Fixing 176216 - [api] FTP sould provide API to allow clients register their own FTPListingParser
* Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API
* Javier Montalvo Orus (Symbian) - improved autodetection of FTPListingParser
********************************************************************************/
package org.eclipse.rse.internal.services.files.ftp;
@ -83,7 +84,6 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
private Mutex _commandMutex = new Mutex();
private String _parser;
private String _userHome;
private transient String _hostName;
private transient String _userId;
@ -287,61 +287,24 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
//System parser
_parser = _ftpPropertySet.getPropertyValue("parser"); //$NON-NLS-1$
String systemName = _ftpClient.getSystemName();
if(!_parser.equalsIgnoreCase("AUTO")) //$NON-NLS-1$
_ftpClient.setParserFactory(_entryParserFactory);
FTPClientConfig config = _entryParserFactory.getFTPClientConfig(_ftpPropertySet.getPropertyValue("parser"),systemName); //$NON-NLS-1$
if(config!=null)
{
_ftpClient.setParserFactory(_entryParserFactory);
_ftpClient.configure(_entryParserFactory.getFTPClientConfig(_parser));
_ftpClient.configure(config);
}
else
{
//try to guess
String systemName = _ftpClient.getSystemName().toUpperCase();
if(systemName.indexOf(' ')!=-1)
{
systemName = systemName.substring(0,systemName.indexOf(' '));
}
//FTPClientConfig.SYST_NT = "WINDOWS"
if(systemName.startsWith(FTPClientConfig.SYST_NT))
{
_ftpClient.setParserFactory(_entryParserFactory);
_ftpClient.configure(_entryParserFactory.getFTPClientConfig("WinNT")); //$NON-NLS-1$
}else
//FTPClientConfig.SYST_MVS = "MVS"
if(systemName.startsWith(FTPClientConfig.SYST_MVS))
{
_ftpClient.configure(new FTPClientConfig(FTPClientConfig.SYST_MVS));
}else
//FTPClientConfig.SYST_OS2 = "OS/2"
if(systemName.startsWith(FTPClientConfig.SYST_OS2))
{
_ftpClient.configure(new FTPClientConfig(FTPClientConfig.SYST_OS2));
}else
//FTPClientConfig.SYST_OS400 = "OS/400"
if(systemName.startsWith(FTPClientConfig.SYST_OS400))
{
_ftpClient.configure(new FTPClientConfig(FTPClientConfig.SYST_OS400));
}else
//FTPClientConfig.SYST_VMS = "VMS"
if(systemName.startsWith(FTPClientConfig.SYST_VMS))
{
_ftpClient.setParserFactory(_entryParserFactory);
_ftpClient.configure(_entryParserFactory.getFTPClientConfig("VMS")); //$NON-NLS-1$
}else
//Default UNIX-like parsing
//FTPClientConfig.SYST_UNIX = "UNIX"
{
_ftpClient.configure(new FTPClientConfig(FTPClientConfig.SYST_UNIX));
}
//UNIX parsing by default if no suitable parser found
_ftpClient.configure(new FTPClientConfig(FTPClientConfig.SYST_UNIX));
}
// Initial active/passive mode. This action will be refreshed later using setDataConnectionMode()
if(_ftpPropertySet.getPropertyValue("passive").equalsIgnoreCase("true")) //$NON-NLS-1$ //$NON-NLS-2$
{
_ftpClient.enterLocalPassiveMode();

View file

@ -6,6 +6,7 @@
*
* Contributors:
* Javier Montalvo Orus (Symbian) - initial API and implementation
* Javier Montalvo Orus (Symbian) - improved autodetection of FTPListingParser
********************************************************************************/
package org.eclipse.rse.internal.services.files.ftp.parser;
@ -20,10 +21,11 @@ public interface IFTPClientConfigFactory extends FTPFileEntryParserFactory {
/**
*
* @param key name attribute of the extension point to be returned
* @param parser Parser selected from the FTP Settings. This setting is "AUTO" by default, performing a parser discovery
* @param systemName String returned by the host from the FTP SYST command, describing the host
* @return FTPClientConfig instance created from the attributes passed in the extension point
*/
public FTPClientConfig getFTPClientConfig(String key);
public FTPClientConfig getFTPClientConfig(String parser, String systemName);
/**
* Returns a Set of key names

View file

@ -17,6 +17,7 @@ Martin Oberhuber (Wind River) - add FTP Only system type
Javier Montalvo Orus (Symbian) - [plan] Improve Discovery and Autodetect in RSE
Javier Montalvo Orus (Symbian) - Fixing 176216 - [api] FTP sould provide API to allow clients register their own FTPListingParser
Martin Oberhuber (Wind River) - [186523] Move subsystemConfigurations from UI to core
Javier Montalvo Orus (Symbian) - improved autodetection of FTPListingParser
-->
<?eclipse version="3.1"?>
<plugin>
@ -49,34 +50,46 @@ Martin Oberhuber (Wind River) - [186523] Move subsystemConfigurations from UI to
<extension point="org.eclipse.rse.subsystems.files.ftp.ftpFileEntryParser">
<parser
id="org.eclipse.rse.ftp.parser.Unix"
class="org.apache.commons.net.ftp.parser.UnixFTPEntryParser"
label="%FTPParser.UNIX">
ftpSystemTypes=".*[Uu][Nn][Ii][Xx].*"
id="org.eclipse.rse.ftp.parser.Unix"
label="%FTPParser.UNIX"
priority="100">
</parser>
<parser
id="org.eclipse.rse.ftp.parser.MVS"
class="org.apache.commons.net.ftp.parser.MVSFTPEntryParser"
label="%FTPParser.MVS">
ftpSystemTypes=".*[Mm][Vv][Ss].*"
id="org.eclipse.rse.ftp.parser.MVS"
label="%FTPParser.MVS"
priority="100">
</parser>
<parser
id="org.eclipse.rse.ftp.parser.WinNT"
class="org.eclipse.rse.internal.subsystems.files.ftp.parser.RSENTFTPEntryParser"
label="%FTPParser.WinNT">
ftpSystemTypes=".*[Ww][Ii][Nn][Dd][Oo][Ww][Ss].*"
id="org.eclipse.rse.ftp.parser.WinNT"
label="%FTPParser.WinNT"
priority="100">
</parser>
<parser
id="org.eclipse.rse.ftp.parser.OS2"
class="org.apache.commons.net.ftp.parser.OS2FTPEntryParser"
label="%FTPParser.OS2">
ftpSystemTypes=".*[Oo][Ss]/2.*"
id="org.eclipse.rse.ftp.parser.OS2"
label="%FTPParser.OS2"
priority="100">
</parser>
<parser
id="org.eclipse.rse.ftp.parser.OS400"
class="org.apache.commons.net.ftp.parser.OS400FTPEntryParser"
label="%FTPParser.OS400">
ftpSystemTypes=".*[Oo][Ss]/400.*"
id="org.eclipse.rse.ftp.parser.OS400"
label="%FTPParser.OS400"
priority="100">
</parser>
<parser
id="org.eclipse.rse.ftp.parser.VMS"
class="org.eclipse.rse.internal.subsystems.files.ftp.parser.RSEVMSFTPEntryParser"
label="%FTPParser.VMS">
class="org.eclipse.rse.internal.subsystems.files.ftp.parser.RSEVMSFTPEntryParser"
ftpSystemTypes=".*[Vv][Mm][Ss].*"
id="org.eclipse.rse.ftp.parser.VMS"
label="%FTPParser.VMS"
priority="100">
</parser>
</extension>

View file

@ -51,7 +51,7 @@ The string attributes &lt;code&gt;defaultDateFormatStr&lt;/code&gt; &lt;code&gt;
<element name="parser">
<complexType>
<attribute name="id" type="string" use="required">
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
@ -61,7 +61,7 @@ The string attributes &lt;code&gt;defaultDateFormatStr&lt;/code&gt; &lt;code&gt;
<attribute name="label" type="string" use="required">
<annotation>
<documentation>
Name that will be displayed in the UI
Name that will be displayed in the FTP Settings dialog
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
@ -71,7 +71,7 @@ The string attributes &lt;code&gt;defaultDateFormatStr&lt;/code&gt; &lt;code&gt;
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
Extension of &lt;code&gt;org.apache.commons.net.ftp.Configurable,org.apache.commons.net.ftp.FTPFileEntryParser&lt;/code&gt; implementing the parser for the specific server
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn="org.apache.commons.net.ftp.Configurable,org.apache.commons.net.ftp.FTPFileEntryParser"/>
@ -81,35 +81,75 @@ The string attributes &lt;code&gt;defaultDateFormatStr&lt;/code&gt; &lt;code&gt;
<attribute name="defaultDateFormatStr" type="string">
<annotation>
<documentation>
This property specifies the main date format that will be used by a parser configured by this configuration to parse file timestamps. If this is not specified, such a parser will use as a default value, the most commonly used format which will be in as used in &lt;code&gt;en_US&lt;/code&gt; locales. This should be in the format described for &lt;code&gt;java.text.SimpleDateFormat&lt;/code&gt;. property.
</documentation>
</annotation>
</attribute>
<attribute name="recentDateFormatStr" type="string">
<annotation>
<documentation>
This property specifies a secondary date format that will be used by a parser configured by this configuration to parse file timestamps, typically those less than a year old. If this is not specified, such a parser will not attempt to parse using an alternate format.
This is used primarily in unix-based systems.
This should be in the format described for &lt;code&gt;java.text.SimpleDateFormat&lt;/code&gt;.
</documentation>
</annotation>
</attribute>
<attribute name="serverLanguageCode" type="string">
<annotation>
<documentation>
This property allows user to specify a &lt;a href=&quot;http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt&quot;&gt;
two-letter ISO-639 language code&lt;/a&gt; that will be used to configure the set of month names used by the file timestamp parser.
If neither this nor the shortMonthNames is specified, parsing will assume English month names, which may or may not be significant, depending on whether the date format(s) specified via defaultDateFormatStr and/or recentDateFormatStr are using
numeric or alphabetic month names.
If the code supplied is not supported here, &lt;code&gt;en_US&lt;/code&gt;
month names will be used. We are supporting here those language
codes which, when a &lt;code&gt; java.util.Locale&lt;/code&gt; is constucted
using it, and a &lt;code&gt;java.text.SimpleDateFormat&lt;/code&gt; is
constructed using that Locale, the array returned by the
SimpleDateFormat&apos;s &lt;code&gt;getShortMonths()&lt;/code&gt; method consists solely of three 8-bit ASCII character strings. Additionally,
languages which do not meet this requirement are included if a
common alternative set of short month names is known to be used.
This means that users who can tell us of additional such encodings
may get them added to the list of supported languages by contacting
the jakarta-commons-net team.
&lt;strong&gt; Please note that this attribute will NOT be used to determine a locale-based date format for the language. &lt;/strong&gt;
Experience has shown that many if not most FTP servers outside the
United States employ the standard &lt;code&gt;en_US&lt;/code&gt; date format
orderings of &lt;code&gt;MMM d yyyy&lt;/code&gt; and &lt;code&gt;MMM d HH:mm&lt;/code&gt;
and attempting to deduce this automatically here would cause more
problems than it would solve. The date format must be changed
via the defaultDateFormatStr and/or recentDateFormatStr parameters.
</documentation>
</annotation>
</attribute>
<attribute name="shortMonthNames" type="string">
<annotation>
<documentation>
This property allows the user to specify a set of month names used by the server that is different from those that may be specified using the setServerLanguageCode property.
This should be a string containing twelve strings each composed of
three characters, delimited by pipe (|) characters. Currently,
only 8-bit ASCII characters are known to be supported. For example, a set of month names used by a hypothetical Icelandic FTP server might conceivably be specified as &lt;code&gt;&quot;jan|feb|mar|apr|ma&amp;#xED;|j&amp;#xFA;n|j&amp;#xFA;l|&amp;#xE1;g&amp;#xFA;|sep|okt|n&amp;#xF3;v|des&quot;&lt;/code&gt;.
</documentation>
</annotation>
</attribute>
<attribute name="serverTimeZoneId" type="string">
<annotation>
<documentation>
This property allows a time zone to be specified corresponding to that known to be used by an FTP server in file listings. This might be particularly useful to clients such as Ant that try to use these timestamps for dependency checking. This should be one of the identifiers used by &lt;code&gt;java.util.TimeZone&lt;/code&gt; to refer to time zones, for example, &lt;code&gt;America/Chicago&lt;/code&gt; or &lt;code&gt;Asia/Rangoon&lt;/code&gt;.
</documentation>
</annotation>
</attribute>
<attribute name="ftpSystemTypes" type="string">
<annotation>
<documentation>
Regular expression used to match with the string returned by the FTP SYST command to autodetect the parser if not specified by the user
</documentation>
</annotation>
</attribute>
<attribute name="priority" type="string">
<annotation>
<documentation>
Priority used if more than one extension matches the regular expression given by ftpSystemTypes.
</documentation>
</annotation>
</attribute>
@ -193,6 +233,7 @@ available at http://www.eclipse.org/legal/epl-v10.html
Contributors:
Javier Montalvo Orus (Symbian) - initial API and implementation
Javier Montalvo Orus (Symbian) - added ftpSystemTypes and priority
</documentation>
</annotation>

View file

@ -6,6 +6,7 @@
*
* Contributors:
* Javier Montalvo Orus (Symbian) - initial API and implementation
* Javier Montalvo Orus (Symbian) - improved autodetection of FTPListingParser
********************************************************************************/
package org.eclipse.rse.internal.subsystems.files.ftp.parser;
@ -13,6 +14,7 @@ package org.eclipse.rse.internal.subsystems.files.ftp.parser;
import java.util.Hashtable;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPFileEntryParser;
@ -60,17 +62,104 @@ public class FTPClientConfigFactory implements IFTPClientConfigFactory {
* (non-Javadoc)
* @see org.eclipse.rse.internal.services.files.ftp.parser.IFTPClientConfigFactory#getFTPClientConfig(java.lang.String)
*/
public FTPClientConfig getFTPClientConfig(String key)
public FTPClientConfig getFTPClientConfig(String parser, String systemName)
{
if(!ftpConfig.containsKey(key))
FTPClientConfig ftpClientConfig = null;
if(parser.equals("AUTO")) //$NON-NLS-1$
{
int priorityInt = Integer.MAX_VALUE;
int previousPriorityInt = Integer.MAX_VALUE;
IConfigurationElement selectedCofiguration = null;
IConfigurationElement[] ce = ep.getConfigurationElements();
for (int i = 0; i < ce.length; i++)
{
String ftpSystemTypes = ce[i].getAttribute("ftpSystemTypes"); //$NON-NLS-1$
if(ftpSystemTypes!=null)
{
Pattern ftpSystemTypesRegex = Pattern.compile(ftpSystemTypes);
if(ftpSystemTypesRegex.matcher(systemName).matches())
{
//try to get priority otherwise assigning Integer.MAX_VALUE
String priority = ce[i].getAttribute("priority"); //$NON-NLS-1$
if(priority!=null)
{
priorityInt = Integer.parseInt(priority);
}
else
{
priorityInt = Integer.MAX_VALUE;
}
if(priorityInt < previousPriorityInt)
{
selectedCofiguration = ce[i];
previousPriorityInt = priorityInt;
}
}
}
}
//process the selected IConfigurationElement
if(selectedCofiguration != null)
{
FTPClientConfig config = null;
//populate tables
String clas = selectedCofiguration.getAttribute("class"); //$NON-NLS-1$
if(!ftpFileEntryParser.containsKey(clas))
{
FTPFileEntryParser entryParser=null;
try {
entryParser = (FTPFileEntryParser)selectedCofiguration.createExecutableExtension("class"); //$NON-NLS-1$
} catch (CoreException e) {
throw new ParserInitializationException(e.getMessage());
}
ftpFileEntryParser.put(clas, entryParser);
}
String defaultDateFormatStr = selectedCofiguration.getAttribute("defaultDateFormatStr"); //$NON-NLS-1$
String recentDateFormatStr = selectedCofiguration.getAttribute("recentDateFormatStr"); //$NON-NLS-1$
String serverLanguageCode = selectedCofiguration.getAttribute("serverLanguageCode"); //$NON-NLS-1$
String shortMonthNames = selectedCofiguration.getAttribute("shortMonthNames"); //$NON-NLS-1$
String serverTimeZoneId = selectedCofiguration.getAttribute("serverTimeZoneId"); //$NON-NLS-1$
config = new FTPClientConfig(clas);
//not necessary checking for null, as null is valid input
config.setDefaultDateFormatStr(defaultDateFormatStr);
config.setRecentDateFormatStr(recentDateFormatStr);
config.setServerLanguageCode(serverLanguageCode);
config.setShortMonthNames(shortMonthNames);
config.setServerTimeZoneId(serverTimeZoneId);
//not necessary storing in the hashtable, as discovered will not be reused
ftpClientConfig = config;
}
}
if(ftpClientConfig==null)
{
if(ftpConfig.containsKey(parser))
{
//restore parser from hashtable
ftpClientConfig = (FTPClientConfig)ftpConfig.get(parser);
}
else
{
IConfigurationElement[] ce = ep.getConfigurationElements();
for (int i = 0; i < ce.length; i++)
{
String label = ce[i].getAttribute("label"); //$NON-NLS-1$
if(label.equals(key))
if(label.equals(parser))
{
FTPClientConfig config = null;
@ -103,13 +192,19 @@ public class FTPClientConfigFactory implements IFTPClientConfigFactory {
config.setServerTimeZoneId(serverTimeZoneId);
ftpConfig.put(label, config);
ftpClientConfig = (FTPClientConfig)ftpConfig.get(parser);
break;
}
}
}
}
return (FTPClientConfig)ftpConfig.get(key);
return ftpClientConfig;
}
/*