You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by mc...@apache.org on 2008/01/25 09:10:28 UTC

svn commit: r615140 [3/4] - /felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/

Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/PathFile.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/PathFile.java?rev=615140&r1=615139&r2=615140&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/PathFile.java (original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/PathFile.java Fri Jan 25 00:10:25 2008
@@ -1,739 +1,739 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.obr.plugin;
-
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.nio.channels.FileChannel;
-
-
-/**
- * this class provide some functions to simplify file manipulation.
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class PathFile
-{
-
-    /**
-     * full filename.
-     */
-    private String m_fullFilename;
-
-    /**
-     * store only the filename of the file.
-     */
-    private String m_fileName;
-
-    /**
-     * store only the path of this file.
-     */
-    private String m_pathFile;
-
-    /**
-     * store the base Directory in case of relative path.
-     */
-    private String m_baseDir;
-
-    /**
-     * store the protocol used (ie:file, http...).
-     */
-    private String m_protocol;
-
-    /**
-     * if the path is relative or absolute.
-     */
-    private boolean m_relative;
-
-    /**
-     * if this file is a folder.
-     */
-    private boolean m_folder;
-
-    /**
-     * if the file exist or not.
-     */
-    private boolean m_exist;
-
-    /**
-     * if this file is a file (not a folder).
-     */
-    private boolean m_file;
-
-    /**
-     * if this filename is valid or incomplete.
-     */
-    private boolean m_valid;
-
-
-    /**
-     * build all the attribute information.
-     * @param filename path to the file
-     */
-    public PathFile( String filename )
-    {
-
-        this.m_fullFilename = filename;
-        if ( filename == null )
-        {
-            this.m_valid = false;
-            return;
-        }
-        this.m_valid = true;
-        m_protocol = extractProtocol( filename );
-        m_pathFile = extractPathFile( filename );
-        if ( m_pathFile.startsWith( "//" ) )
-        {
-            // avoid problems on Unix like system
-            m_pathFile = m_pathFile.substring( 1 );
-        }
-        m_fileName = extractFileName( filename );
-        m_relative = extractRelative();
-        if ( !m_relative && ( getProtocol().compareTo( "file" ) == 0 || getProtocol().compareTo( "" ) == 0 ) )
-        {
-            File f = new File( getOnlyAbsoluteFilename() );
-            m_file = f.isFile();
-            m_folder = f.isDirectory();
-            m_exist = f.exists();
-            if ( m_folder )
-            {
-                m_pathFile = m_pathFile + m_fileName + File.separator;
-                m_fileName = "";
-            }
-        }
-        if ( m_exist )
-        {
-            m_protocol = "file";
-        }
-        else
-        {
-            if ( m_fileName.compareTo( "" ) == 0 )
-            {
-                m_folder = true;
-                m_file = false;
-            }
-            else
-            {
-                m_folder = false;
-                m_file = true;
-            }
-
-        }
-
-        // add the '/' before the complete path if it is absolute path
-        if ( !this.isRelative() && !m_pathFile.startsWith( "/" ) )
-        {
-            m_pathFile = "/".concat( m_pathFile );
-        }
-
-    }
-
-
-    /**
-     * get if the filename is relative or absolute.
-     * @return true if the path is relative, else false
-     */
-    private boolean extractRelative()
-    {
-        if ( m_pathFile.startsWith( "." + File.separator, 1 ) || m_pathFile.startsWith( ".." + File.separator, 1 ) )
-        {
-            m_pathFile = m_pathFile.substring( 1 );
-            m_valid = false;
-            return true;
-        }
-
-        return false;
-    }
-
-
-    /**
-     * get only the name from the filename.
-     * @param fullFilename full filename
-     * @return the name of the file or folder
-     */
-    private String extractFileName( String fullFilename )
-    {
-        int index = fullFilename.lastIndexOf( '/' ); // Given path 
-        return fullFilename.substring( index + 1, fullFilename.length() );
-    }
-
-
-    /**
-     * get the path from the filename.
-     * @param fullFilename full filename
-     * @return the path of the file
-     */
-    private String extractPathFile( String fullFilename )
-    {
-        String substring;
-        if ( extractFileName( fullFilename ).compareTo( "" ) == 0 )
-        {
-            // it is a folder
-            substring = fullFilename;
-        }
-        else
-        {
-            substring = fullFilename.substring( 0, fullFilename.indexOf( extractFileName( fullFilename ) ) );
-        }
-
-        if ( getProtocol().compareTo( "" ) != 0 )
-        {
-            substring = substring.substring( 5 );
-        }
-
-        return substring;
-    }
-
-
-    /**
-     * determine which protocol is used.
-     * @param filename the full fileneme
-     * @return "file" or "http" or ""
-     */
-    private String extractProtocol( String filename )
-    {
-        if ( filename.startsWith( "file:" ) )
-        {
-            return "file";
-        }
-        if ( filename.startsWith( "http:" ) )
-        {
-            return "http";
-        }
-        return "";
-    }
-
-
-    /**
-     * set the base directory.
-     * @param baseDir new value for the base directory
-     */
-    public void setBaseDir( String baseDir )
-    {
-        this.m_baseDir = baseDir;
-        if ( isRelative() && this.m_fullFilename != null )
-        {
-            this.m_valid = true;
-            if ( getProtocol().compareTo( "file" ) == 0 || getProtocol().compareTo( "" ) == 0 )
-            {
-                File f = new File( getOnlyAbsoluteFilename() );
-                m_file = f.isFile();
-                m_folder = f.isDirectory();
-                m_exist = f.exists();
-            }
-            if ( m_exist )
-            {
-                m_protocol = "file";
-            }
-        }
-
-    }
-
-
-    /**
-     * get the base directory.
-     * @return base directory
-     */
-    public String getBaseDir()
-    {
-        return this.m_baseDir;
-    }
-
-
-    public boolean isValid()
-    {
-        return m_valid;
-    }
-
-
-    public boolean isRelative()
-    {
-        return m_relative;
-    }
-
-
-    public boolean isExists()
-    {
-        return m_exist;
-    }
-
-
-    public boolean isFile()
-    {
-        return m_file;
-    }
-
-
-    public boolean isFolder()
-    {
-        return m_folder;
-    }
-
-
-    /**
-     * get a File which points on the same file.
-     * @return a File object
-     */
-    public File getFile()
-    {
-        if ( !this.isValid() )
-        {
-            return null;
-        }
-        String path = PathFile.uniformSeparator( this.getOnlyAbsoluteFilename() );
-        if ( File.separatorChar == '\\' )
-        {
-            path = path.replace( '\\', '/' );
-        }
-        File f = new File( path );
-        return f;
-    }
-
-
-    /**
-     * get an URI which points on the same file.
-     * @return an URI object
-     */
-    public URI getUri()
-    {
-        if ( !this.isValid() )
-        {
-            return null;
-        }
-        String path = PathFile.uniformSeparator( getAbsoluteFilename() );
-        if ( File.separatorChar == '\\' )
-        {
-            path = path.replace( '\\', '/' );
-        }
-
-        path = path.replaceAll( " ", "%20" );
-
-        URI uri = null;
-        try
-        {
-            uri = new URI( path );
-        }
-        catch ( URISyntaxException e )
-        {
-            System.err.println( "Malformed URI: " + path );
-            System.err.println( e.getMessage() );
-            return null;
-        }
-        return uri;
-    }
-
-
-    /**
-     * get protocol + relative path of this file.
-     * @return the relative path or null if it is not valid
-     */
-    public String getRelativePath()
-    {
-        if ( !this.isValid() )
-        {
-            return null;
-        }
-
-        return getProtocol() + ":/" + getOnlyRelativePath();
-    }
-
-
-    /**
-     * get only (without protocol) relative path of this file.
-     * @return the relative path or null if it is not valid
-     */
-    public String getOnlyRelativePath()
-    {
-        if ( !this.isValid() )
-        {
-            return null;
-        }
-        if ( this.isRelative() )
-        {
-            return m_pathFile;
-
-        }
-        else
-        {
-            if ( m_baseDir != null )
-            {
-                // System.err.println(m_pathFile);
-                // System.err.println(m_baseDir);
-                if ( m_pathFile.startsWith( m_baseDir ) )
-                {
-                    /*
-                     * String ch1 = m_pathFile; String ch2 = m_baseDir; System.err.println(ch1); System.err.println(ch2); System.err.println("."+File.separator+ch1.substring(ch2.length()));
-                     */
-                    return "." + File.separator + m_pathFile.substring( m_baseDir.length() );
-                }
-            }
-            return m_pathFile;
-        }
-    }
-
-
-    /**
-     * calcul absolute path from relative path.
-     * @param baseDir base directory
-     * @param path path to convert
-     * @return the absolute path or null
-     */
-    private String calculAbsolutePath( String baseDir, String path )
-    {
-        if ( path.startsWith( ".." + File.separatorChar ) )
-        {
-            String base = baseDir;
-            int lastIndex;
-            lastIndex = base.lastIndexOf( File.separator );
-            if ( lastIndex == base.length() )
-            {
-                base = base.substring( 0, base.length() - 1 );
-                lastIndex = base.lastIndexOf( File.separator );
-            }
-            if ( lastIndex < base.length() )
-            {
-                return calculAbsolutePath( base.substring( 0, lastIndex + 1 ), path.substring( 3 ) );
-            }
-            else
-            {
-                return null;
-            }
-        }
-        else if ( path.startsWith( "." + File.separatorChar ) )
-        {
-            String res;
-            if ( File.separatorChar == '\\' )
-            {
-                res = path.replaceFirst( ".", baseDir.replace( '\\', '/' ) );
-            }
-            else
-            {
-                res = path.replaceFirst( ".", baseDir );
-            }
-
-            return PathFile.uniformSeparator( res );
-        }
-        else
-        {
-            return PathFile.uniformSeparator( baseDir + path );
-        }
-    }
-
-
-    /**
-     * get only (without protocol) absolute path (without filename).
-     * @return absolute path
-     */
-    public String getOnlyAbsolutePath()
-    {
-        if ( !this.isValid() )
-        {
-            return null;
-        }
-        if ( isRelative() )
-        {
-            return calculAbsolutePath( m_baseDir, m_pathFile );
-        }
-        else
-        {
-            return m_pathFile;
-        }
-    }
-
-
-    /**
-     * get protocol + absolute path (without filename).
-     * @return absolute path
-     */
-    public String getAbsolutePath()
-    {
-
-        if ( isRelative() )
-        {
-            return getProtocol() + ":/" + calculAbsolutePath( m_baseDir, m_pathFile );
-        }
-        else
-        {
-            if ( getProtocol().compareTo( "" ) == 0 || m_pathFile == null )
-            {
-                return m_pathFile;
-            }
-            else
-            {
-                return getProtocol() + ":" + m_pathFile;
-            }
-        }
-    }
-
-
-    /**
-     * get only (without protocol) absolute path + filename.
-     * @return absolute filename
-     */
-    public String getOnlyAbsoluteFilename()
-    {
-        if ( getOnlyAbsolutePath() != null && getFilename() != null )
-        {
-            return getOnlyAbsolutePath() + getFilename();
-        }
-        else
-        {
-            return null;
-        }
-    }
-
-
-    /**
-     * get protocol + absolute path + filename.
-     * @return absolute filenama
-     */
-    public String getAbsoluteFilename()
-    {
-        if ( getAbsolutePath() != null && getFilename() != null )
-        {
-            return getAbsolutePath() + getFilename();
-        }
-        else
-        {
-            return null;
-        }
-    }
-
-
-    /**
-     * get only (without protocol) relative path + filename.
-     * @return relative filename
-     */
-    public String getOnlyRelativeFilename()
-    {
-        if ( !this.isValid() )
-        {
-            return "";
-        }
-
-        return getOnlyRelativePath() + getFilename();
-
-    }
-
-
-    /**
-     * get protocol + relative path + filename.
-     * @return relative filename
-     */
-    public String getRelativeFilename()
-    {
-        if ( !this.isValid() )
-        {
-            return "";
-        }
-
-        if ( this.isRelative() )
-        {
-            return getRelativePath() + getFilename();
-        }
-        else
-        {
-            return getAbsoluteFilename();
-        }
-    }
-
-
-    public String getFilename()
-    {
-        return m_fileName;
-    }
-
-
-    public String getProtocol()
-    {
-        return m_protocol;
-    }
-
-
-    /**
-     * create all the directories not also present in the current path.
-     * @return true if all directories was created, else false
-     */
-    public boolean createPath()
-    {
-        File path = new File( this.getOnlyAbsolutePath() );
-        if ( path.exists() )
-        {
-            return true;
-        }
-        return path.mkdirs();
-    }
-
-
-    /**
-     * create all the directories not also present in the current path and the file.
-     * @return true it was created, else false
-     */
-    public boolean createFile()
-    {
-        File path = new File( this.getOnlyAbsolutePath() );
-        if ( !path.exists() )
-        {
-            if ( !this.createPath() )
-            {
-                return false;
-            }
-        }
-        path = new File( this.getOnlyAbsoluteFilename() );
-        try
-        {
-            return path.createNewFile();
-        }
-        catch ( IOException e )
-        {
-            return false;
-        }
-
-    }
-
-
-    /**
-     * delete the current file.
-     * @return true if it was deleted, else false
-     */
-    public boolean delete()
-    {
-        File path = new File( this.getAbsoluteFilename() );
-        if ( path.exists() )
-        {
-            return path.delete();
-        }
-        else
-        {
-            return true;
-        }
-
-    }
-
-    private static final String REGEXP_BACKSLASH = "\\\\";
-
-
-    /**
-     * replace all '\' by '\\' in the given string.
-     * @param path string where replace the search pattern
-     * @return string replaced
-     */
-    public static String doubleSeparator( String path )
-    {
-        // double the '\' in the path
-        if ( path != null && File.separatorChar == '\\' )
-        {
-            return path.replaceAll( REGEXP_BACKSLASH, REGEXP_BACKSLASH + REGEXP_BACKSLASH );
-        }
-        else
-        {
-            return null;
-        }
-    }
-
-
-    /**
-     * file separator('\' or '/') by the one of the current system.
-     * @param path string where replace the search pattern
-     * @return string replaced
-     */
-    public static String uniformSeparator( String path )
-    {
-        if ( File.separatorChar == '\\' )
-        {
-            if ( path.startsWith( "/" ) )
-            {
-                return path.substring( 1 ).replace( '/', File.separatorChar );
-            }
-            else
-            {
-                return path.replace( '/', File.separatorChar );
-            }
-        }
-        else
-        {
-            return path.replace( '\\', File.separatorChar );
-        }
-    }
-
-
-    /**
-     * copy file from src to dest.
-     * @param src source file
-     * @param dest destination file
-     * @return true if the file was correctly copied, else false
-     */
-    public static boolean copyFile( PathFile src, PathFile dest )
-    {
-        FileChannel in = null;
-        FileChannel out = null;
-
-        if ( !src.isExists() )
-        {
-            System.err.println( "src file must exist: " + src.getAbsoluteFilename() );
-            return false;
-        }
-        if ( !dest.isExists() )
-        {
-            dest.createFile();
-        }
-        try
-        {
-            in = new FileInputStream( src.getOnlyAbsoluteFilename() ).getChannel();
-            out = new FileOutputStream( dest.getOnlyAbsoluteFilename() ).getChannel();
-
-            in.transferTo( 0, in.size(), out );
-        }
-        catch ( Exception e )
-        {
-            e.printStackTrace();
-        }
-        finally
-        {
-            if ( in != null )
-            {
-                try
-                {
-                    in.close();
-                }
-                catch ( IOException e )
-                {
-                    return false;
-                }
-            }
-            if ( out != null )
-            {
-                try
-                {
-                    out.close();
-                }
-                catch ( IOException e )
-                {
-                    return false;
-                }
-            }
-        }
-        return true;
-    }
-
-}
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.obr.plugin;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.channels.FileChannel;
+
+
+/**
+ * this class provide some functions to simplify file manipulation.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class PathFile
+{
+
+    /**
+     * full filename.
+     */
+    private String m_fullFilename;
+
+    /**
+     * store only the filename of the file.
+     */
+    private String m_fileName;
+
+    /**
+     * store only the path of this file.
+     */
+    private String m_pathFile;
+
+    /**
+     * store the base Directory in case of relative path.
+     */
+    private String m_baseDir;
+
+    /**
+     * store the protocol used (ie:file, http...).
+     */
+    private String m_protocol;
+
+    /**
+     * if the path is relative or absolute.
+     */
+    private boolean m_relative;
+
+    /**
+     * if this file is a folder.
+     */
+    private boolean m_folder;
+
+    /**
+     * if the file exist or not.
+     */
+    private boolean m_exist;
+
+    /**
+     * if this file is a file (not a folder).
+     */
+    private boolean m_file;
+
+    /**
+     * if this filename is valid or incomplete.
+     */
+    private boolean m_valid;
+
+
+    /**
+     * build all the attribute information.
+     * @param filename path to the file
+     */
+    public PathFile( String filename )
+    {
+
+        this.m_fullFilename = filename;
+        if ( filename == null )
+        {
+            this.m_valid = false;
+            return;
+        }
+        this.m_valid = true;
+        m_protocol = extractProtocol( filename );
+        m_pathFile = extractPathFile( filename );
+        if ( m_pathFile.startsWith( "//" ) )
+        {
+            // avoid problems on Unix like system
+            m_pathFile = m_pathFile.substring( 1 );
+        }
+        m_fileName = extractFileName( filename );
+        m_relative = extractRelative();
+        if ( !m_relative && ( getProtocol().compareTo( "file" ) == 0 || getProtocol().compareTo( "" ) == 0 ) )
+        {
+            File f = new File( getOnlyAbsoluteFilename() );
+            m_file = f.isFile();
+            m_folder = f.isDirectory();
+            m_exist = f.exists();
+            if ( m_folder )
+            {
+                m_pathFile = m_pathFile + m_fileName + File.separator;
+                m_fileName = "";
+            }
+        }
+        if ( m_exist )
+        {
+            m_protocol = "file";
+        }
+        else
+        {
+            if ( m_fileName.compareTo( "" ) == 0 )
+            {
+                m_folder = true;
+                m_file = false;
+            }
+            else
+            {
+                m_folder = false;
+                m_file = true;
+            }
+
+        }
+
+        // add the '/' before the complete path if it is absolute path
+        if ( !this.isRelative() && !m_pathFile.startsWith( "/" ) )
+        {
+            m_pathFile = "/".concat( m_pathFile );
+        }
+
+    }
+
+
+    /**
+     * get if the filename is relative or absolute.
+     * @return true if the path is relative, else false
+     */
+    private boolean extractRelative()
+    {
+        if ( m_pathFile.startsWith( "." + File.separator, 1 ) || m_pathFile.startsWith( ".." + File.separator, 1 ) )
+        {
+            m_pathFile = m_pathFile.substring( 1 );
+            m_valid = false;
+            return true;
+        }
+
+        return false;
+    }
+
+
+    /**
+     * get only the name from the filename.
+     * @param fullFilename full filename
+     * @return the name of the file or folder
+     */
+    private String extractFileName( String fullFilename )
+    {
+        int index = fullFilename.lastIndexOf( '/' ); // Given path 
+        return fullFilename.substring( index + 1, fullFilename.length() );
+    }
+
+
+    /**
+     * get the path from the filename.
+     * @param fullFilename full filename
+     * @return the path of the file
+     */
+    private String extractPathFile( String fullFilename )
+    {
+        String substring;
+        if ( extractFileName( fullFilename ).compareTo( "" ) == 0 )
+        {
+            // it is a folder
+            substring = fullFilename;
+        }
+        else
+        {
+            substring = fullFilename.substring( 0, fullFilename.indexOf( extractFileName( fullFilename ) ) );
+        }
+
+        if ( getProtocol().compareTo( "" ) != 0 )
+        {
+            substring = substring.substring( 5 );
+        }
+
+        return substring;
+    }
+
+
+    /**
+     * determine which protocol is used.
+     * @param filename the full fileneme
+     * @return "file" or "http" or ""
+     */
+    private String extractProtocol( String filename )
+    {
+        if ( filename.startsWith( "file:" ) )
+        {
+            return "file";
+        }
+        if ( filename.startsWith( "http:" ) )
+        {
+            return "http";
+        }
+        return "";
+    }
+
+
+    /**
+     * set the base directory.
+     * @param baseDir new value for the base directory
+     */
+    public void setBaseDir( String baseDir )
+    {
+        this.m_baseDir = baseDir;
+        if ( isRelative() && this.m_fullFilename != null )
+        {
+            this.m_valid = true;
+            if ( getProtocol().compareTo( "file" ) == 0 || getProtocol().compareTo( "" ) == 0 )
+            {
+                File f = new File( getOnlyAbsoluteFilename() );
+                m_file = f.isFile();
+                m_folder = f.isDirectory();
+                m_exist = f.exists();
+            }
+            if ( m_exist )
+            {
+                m_protocol = "file";
+            }
+        }
+
+    }
+
+
+    /**
+     * get the base directory.
+     * @return base directory
+     */
+    public String getBaseDir()
+    {
+        return this.m_baseDir;
+    }
+
+
+    public boolean isValid()
+    {
+        return m_valid;
+    }
+
+
+    public boolean isRelative()
+    {
+        return m_relative;
+    }
+
+
+    public boolean isExists()
+    {
+        return m_exist;
+    }
+
+
+    public boolean isFile()
+    {
+        return m_file;
+    }
+
+
+    public boolean isFolder()
+    {
+        return m_folder;
+    }
+
+
+    /**
+     * get a File which points on the same file.
+     * @return a File object
+     */
+    public File getFile()
+    {
+        if ( !this.isValid() )
+        {
+            return null;
+        }
+        String path = PathFile.uniformSeparator( this.getOnlyAbsoluteFilename() );
+        if ( File.separatorChar == '\\' )
+        {
+            path = path.replace( '\\', '/' );
+        }
+        File f = new File( path );
+        return f;
+    }
+
+
+    /**
+     * get an URI which points on the same file.
+     * @return an URI object
+     */
+    public URI getUri()
+    {
+        if ( !this.isValid() )
+        {
+            return null;
+        }
+        String path = PathFile.uniformSeparator( getAbsoluteFilename() );
+        if ( File.separatorChar == '\\' )
+        {
+            path = path.replace( '\\', '/' );
+        }
+
+        path = path.replaceAll( " ", "%20" );
+
+        URI uri = null;
+        try
+        {
+            uri = new URI( path );
+        }
+        catch ( URISyntaxException e )
+        {
+            System.err.println( "Malformed URI: " + path );
+            System.err.println( e.getMessage() );
+            return null;
+        }
+        return uri;
+    }
+
+
+    /**
+     * get protocol + relative path of this file.
+     * @return the relative path or null if it is not valid
+     */
+    public String getRelativePath()
+    {
+        if ( !this.isValid() )
+        {
+            return null;
+        }
+
+        return getProtocol() + ":/" + getOnlyRelativePath();
+    }
+
+
+    /**
+     * get only (without protocol) relative path of this file.
+     * @return the relative path or null if it is not valid
+     */
+    public String getOnlyRelativePath()
+    {
+        if ( !this.isValid() )
+        {
+            return null;
+        }
+        if ( this.isRelative() )
+        {
+            return m_pathFile;
+
+        }
+        else
+        {
+            if ( m_baseDir != null )
+            {
+                // System.err.println(m_pathFile);
+                // System.err.println(m_baseDir);
+                if ( m_pathFile.startsWith( m_baseDir ) )
+                {
+                    /*
+                     * String ch1 = m_pathFile; String ch2 = m_baseDir; System.err.println(ch1); System.err.println(ch2); System.err.println("."+File.separator+ch1.substring(ch2.length()));
+                     */
+                    return "." + File.separator + m_pathFile.substring( m_baseDir.length() );
+                }
+            }
+            return m_pathFile;
+        }
+    }
+
+
+    /**
+     * calcul absolute path from relative path.
+     * @param baseDir base directory
+     * @param path path to convert
+     * @return the absolute path or null
+     */
+    private String calculAbsolutePath( String baseDir, String path )
+    {
+        if ( path.startsWith( ".." + File.separatorChar ) )
+        {
+            String base = baseDir;
+            int lastIndex;
+            lastIndex = base.lastIndexOf( File.separator );
+            if ( lastIndex == base.length() )
+            {
+                base = base.substring( 0, base.length() - 1 );
+                lastIndex = base.lastIndexOf( File.separator );
+            }
+            if ( lastIndex < base.length() )
+            {
+                return calculAbsolutePath( base.substring( 0, lastIndex + 1 ), path.substring( 3 ) );
+            }
+            else
+            {
+                return null;
+            }
+        }
+        else if ( path.startsWith( "." + File.separatorChar ) )
+        {
+            String res;
+            if ( File.separatorChar == '\\' )
+            {
+                res = path.replaceFirst( ".", baseDir.replace( '\\', '/' ) );
+            }
+            else
+            {
+                res = path.replaceFirst( ".", baseDir );
+            }
+
+            return PathFile.uniformSeparator( res );
+        }
+        else
+        {
+            return PathFile.uniformSeparator( baseDir + path );
+        }
+    }
+
+
+    /**
+     * get only (without protocol) absolute path (without filename).
+     * @return absolute path
+     */
+    public String getOnlyAbsolutePath()
+    {
+        if ( !this.isValid() )
+        {
+            return null;
+        }
+        if ( isRelative() )
+        {
+            return calculAbsolutePath( m_baseDir, m_pathFile );
+        }
+        else
+        {
+            return m_pathFile;
+        }
+    }
+
+
+    /**
+     * get protocol + absolute path (without filename).
+     * @return absolute path
+     */
+    public String getAbsolutePath()
+    {
+
+        if ( isRelative() )
+        {
+            return getProtocol() + ":/" + calculAbsolutePath( m_baseDir, m_pathFile );
+        }
+        else
+        {
+            if ( getProtocol().compareTo( "" ) == 0 || m_pathFile == null )
+            {
+                return m_pathFile;
+            }
+            else
+            {
+                return getProtocol() + ":" + m_pathFile;
+            }
+        }
+    }
+
+
+    /**
+     * get only (without protocol) absolute path + filename.
+     * @return absolute filename
+     */
+    public String getOnlyAbsoluteFilename()
+    {
+        if ( getOnlyAbsolutePath() != null && getFilename() != null )
+        {
+            return getOnlyAbsolutePath() + getFilename();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * get protocol + absolute path + filename.
+     * @return absolute filenama
+     */
+    public String getAbsoluteFilename()
+    {
+        if ( getAbsolutePath() != null && getFilename() != null )
+        {
+            return getAbsolutePath() + getFilename();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * get only (without protocol) relative path + filename.
+     * @return relative filename
+     */
+    public String getOnlyRelativeFilename()
+    {
+        if ( !this.isValid() )
+        {
+            return "";
+        }
+
+        return getOnlyRelativePath() + getFilename();
+
+    }
+
+
+    /**
+     * get protocol + relative path + filename.
+     * @return relative filename
+     */
+    public String getRelativeFilename()
+    {
+        if ( !this.isValid() )
+        {
+            return "";
+        }
+
+        if ( this.isRelative() )
+        {
+            return getRelativePath() + getFilename();
+        }
+        else
+        {
+            return getAbsoluteFilename();
+        }
+    }
+
+
+    public String getFilename()
+    {
+        return m_fileName;
+    }
+
+
+    public String getProtocol()
+    {
+        return m_protocol;
+    }
+
+
+    /**
+     * create all the directories not also present in the current path.
+     * @return true if all directories was created, else false
+     */
+    public boolean createPath()
+    {
+        File path = new File( this.getOnlyAbsolutePath() );
+        if ( path.exists() )
+        {
+            return true;
+        }
+        return path.mkdirs();
+    }
+
+
+    /**
+     * create all the directories not also present in the current path and the file.
+     * @return true it was created, else false
+     */
+    public boolean createFile()
+    {
+        File path = new File( this.getOnlyAbsolutePath() );
+        if ( !path.exists() )
+        {
+            if ( !this.createPath() )
+            {
+                return false;
+            }
+        }
+        path = new File( this.getOnlyAbsoluteFilename() );
+        try
+        {
+            return path.createNewFile();
+        }
+        catch ( IOException e )
+        {
+            return false;
+        }
+
+    }
+
+
+    /**
+     * delete the current file.
+     * @return true if it was deleted, else false
+     */
+    public boolean delete()
+    {
+        File path = new File( this.getAbsoluteFilename() );
+        if ( path.exists() )
+        {
+            return path.delete();
+        }
+        else
+        {
+            return true;
+        }
+
+    }
+
+    private static final String REGEXP_BACKSLASH = "\\\\";
+
+
+    /**
+     * replace all '\' by '\\' in the given string.
+     * @param path string where replace the search pattern
+     * @return string replaced
+     */
+    public static String doubleSeparator( String path )
+    {
+        // double the '\' in the path
+        if ( path != null && File.separatorChar == '\\' )
+        {
+            return path.replaceAll( REGEXP_BACKSLASH, REGEXP_BACKSLASH + REGEXP_BACKSLASH );
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * file separator('\' or '/') by the one of the current system.
+     * @param path string where replace the search pattern
+     * @return string replaced
+     */
+    public static String uniformSeparator( String path )
+    {
+        if ( File.separatorChar == '\\' )
+        {
+            if ( path.startsWith( "/" ) )
+            {
+                return path.substring( 1 ).replace( '/', File.separatorChar );
+            }
+            else
+            {
+                return path.replace( '/', File.separatorChar );
+            }
+        }
+        else
+        {
+            return path.replace( '\\', File.separatorChar );
+        }
+    }
+
+
+    /**
+     * copy file from src to dest.
+     * @param src source file
+     * @param dest destination file
+     * @return true if the file was correctly copied, else false
+     */
+    public static boolean copyFile( PathFile src, PathFile dest )
+    {
+        FileChannel in = null;
+        FileChannel out = null;
+
+        if ( !src.isExists() )
+        {
+            System.err.println( "src file must exist: " + src.getAbsoluteFilename() );
+            return false;
+        }
+        if ( !dest.isExists() )
+        {
+            dest.createFile();
+        }
+        try
+        {
+            in = new FileInputStream( src.getOnlyAbsoluteFilename() ).getChannel();
+            out = new FileOutputStream( dest.getOnlyAbsoluteFilename() ).getChannel();
+
+            in.transferTo( 0, in.size(), out );
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+        finally
+        {
+            if ( in != null )
+            {
+                try
+                {
+                    in.close();
+                }
+                catch ( IOException e )
+                {
+                    return false;
+                }
+            }
+            if ( out != null )
+            {
+                try
+                {
+                    out.close();
+                }
+                catch ( IOException e )
+                {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+}

Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/RemoteFileManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/RemoteFileManager.java?rev=615140&r1=615139&r2=615140&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/RemoteFileManager.java (original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/RemoteFileManager.java Fri Jan 25 00:10:25 2008
@@ -1,280 +1,280 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.obr.plugin;
-
-
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.maven.artifact.manager.WagonConfigurationException;
-import org.apache.maven.artifact.manager.WagonManager;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugin.logging.Log;
-import org.apache.maven.settings.Proxy;
-import org.apache.maven.settings.Settings;
-import org.apache.maven.wagon.ConnectionException;
-import org.apache.maven.wagon.ResourceDoesNotExistException;
-import org.apache.maven.wagon.TransferFailedException;
-import org.apache.maven.wagon.UnsupportedProtocolException;
-import org.apache.maven.wagon.Wagon;
-import org.apache.maven.wagon.authentication.AuthenticationException;
-import org.apache.maven.wagon.authorization.AuthorizationException;
-import org.apache.maven.wagon.observers.Debug;
-import org.apache.maven.wagon.proxy.ProxyInfo;
-import org.apache.maven.wagon.repository.Repository;
-
-
-/**
- * this class is used to manage all connections by wagon.
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class RemoteFileManager
-{
-
-    /**
-     * save the connection.
-     */
-    private Wagon m_wagon;
-
-    /**
-     * the wagon manager.
-     */
-    private WagonManager m_wagonManager;
-
-    /**
-     * artifact repository.
-     */
-    private ArtifactRepository m_artifactRepository;
-
-    /**
-     * the project settings.
-     */
-    private Settings m_settings;
-
-    /**
-     * logger instance.
-     */
-    private Log m_log;
-
-
-    /**
-     * initialize main information.
-     * @param ar ArtifactRepository provides by maven
-     * @param wm WagonManager provides by maven
-     * @param settings settings of the current project provides by maven
-     * @param log logger
-     */
-    public RemoteFileManager( ArtifactRepository ar, WagonManager wm, Settings settings, Log log )
-    {
-        m_artifactRepository = ar;
-        m_wagonManager = wm;
-        m_settings = settings;
-        m_log = log;
-        m_wagon = null;
-    }
-
-
-    /**
-     * disconnect the current object.
-     *
-     */
-    public void disconnect()
-    {
-        if ( m_wagon == null )
-        {
-            m_log.error( "must be connected first!" );
-            return;
-        }
-        try
-        {
-            m_wagon.disconnect();
-        }
-        catch ( ConnectionException e )
-        {
-            m_log.error( "Error disconnecting wagon - ignored", e );
-        }
-    }
-
-
-    /**
-     * connect the current object to artifact repository given in constructor.
-     * @throws MojoExecutionException if connection failed
-     */
-    public void connect() throws MojoExecutionException
-    {
-        String url = m_artifactRepository.getUrl();
-        String id = m_artifactRepository.getId();
-
-        Repository repository = new Repository( id, url );
-
-        try
-        {
-            m_wagon = m_wagonManager.getWagon( repository );
-            //configureWagon(m_wagon, repository.getId());
-        }
-        catch ( UnsupportedProtocolException e )
-        {
-            throw new MojoExecutionException( "Unsupported protocol: '" + repository.getProtocol() + "'", e );
-        }
-        catch ( WagonConfigurationException e )
-        {
-            throw new MojoExecutionException( "Unable to configure Wagon: '" + repository.getProtocol() + "'", e );
-        }
-
-        try
-        {
-            Debug debug = new Debug();
-            m_wagon.addTransferListener( debug );
-
-            ProxyInfo proxyInfo = getProxyInfo( m_settings );
-            if ( proxyInfo != null )
-            {
-                m_wagon.connect( repository, m_wagonManager.getAuthenticationInfo( id ), proxyInfo );
-            }
-            else
-            {
-                m_wagon.connect( repository, m_wagonManager.getAuthenticationInfo( id ) );
-            }
-
-        }
-        catch ( ConnectionException e )
-        {
-            throw new MojoExecutionException( "Error uploading file", e );
-        }
-        catch ( AuthenticationException e )
-        {
-            throw new MojoExecutionException( "Error uploading file", e );
-        }
-    }
-
-
-    /**
-     * get a file from the current repository connected.
-     * @param url url to the targeted file
-     * @return  get a file descriptor on the requiered resource
-     * @throws IOException if an IO error occurs
-     * @throws TransferFailedException  if the transfer failed 
-     * @throws ResourceDoesNotExistException if the targeted resource doesn't exist
-     * @throws AuthorizationException if the connection authorization failed
-     */
-    public File get( String url ) throws IOException, TransferFailedException, ResourceDoesNotExistException,
-        AuthorizationException
-    {
-
-        if ( m_wagon == null )
-        {
-            m_log.error( "must be connected first!" );
-            return null;
-        }
-
-        File file = File.createTempFile( String.valueOf( System.currentTimeMillis() ), "tmp" );
-        m_wagon.get( url, file );
-        return file;
-    }
-
-
-    /**
-     * put a file on the current repository connected.
-     * @param file file to upload
-     * @param url url to copy file
-     * @throws TransferFailedException if the transfer failed 
-     * @throws ResourceDoesNotExistException if the targeted resource doesn't exist
-     * @throws AuthorizationException if the connection authorization failed
-     */
-    public void put( File file, String url ) throws TransferFailedException, ResourceDoesNotExistException,
-        AuthorizationException
-    {
-        if ( m_wagon == null )
-        {
-            m_log.error( "must be connected first!" );
-            return;
-        }
-        m_wagon.put( file, url );
-    }
-
-
-    /**
-     * Convenience method to map a Proxy object from the user system settings to a ProxyInfo object.
-     * @param settings project settings given by maven
-     * @return a proxyInfo object instancied or null if no active proxy is define in the settings.xml
-     */
-    public static ProxyInfo getProxyInfo( Settings settings )
-    {
-        ProxyInfo proxyInfo = null;
-        if ( settings != null && settings.getActiveProxy() != null )
-        {
-            Proxy settingsProxy = settings.getActiveProxy();
-
-            proxyInfo = new ProxyInfo();
-            proxyInfo.setHost( settingsProxy.getHost() );
-            proxyInfo.setType( settingsProxy.getProtocol() );
-            proxyInfo.setPort( settingsProxy.getPort() );
-            proxyInfo.setNonProxyHosts( settingsProxy.getNonProxyHosts() );
-            proxyInfo.setUserName( settingsProxy.getUsername() );
-            proxyInfo.setPassword( settingsProxy.getPassword() );
-        }
-
-        return proxyInfo;
-    }
-
-
-    /**
-     * this method indicates if the targeted file is locked or not.
-     * @param remote connection manager
-     * @param fileName name targeted
-     * @return  true if thr reuiered file is locked, else false
-     * @throws MojoFailureException if the plugin failed
-     */
-    public boolean isLockedFile( RemoteFileManager remote, String fileName ) throws MojoFailureException
-    {
-        File file = null;
-        try
-        {
-            file = remote.get( fileName + ".lock" );
-        }
-        catch ( TransferFailedException e )
-        {
-            e.printStackTrace();
-            throw new MojoFailureException( "TransferFailedException" );
-
-        }
-        catch ( ResourceDoesNotExistException e )
-        {
-            return false;
-        }
-        catch ( AuthorizationException e )
-        {
-            e.printStackTrace();
-            throw new MojoFailureException( "AuthorizationException" );
-        }
-        catch ( IOException e )
-        {
-            e.printStackTrace();
-            throw new MojoFailureException( "IOException" );
-        }
-        if ( file != null && file.length() == 0 )
-        {
-            return false;
-        }
-        return true;
-    }
-
-}
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.obr.plugin;
+
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.maven.artifact.manager.WagonConfigurationException;
+import org.apache.maven.artifact.manager.WagonManager;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.settings.Proxy;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.wagon.ConnectionException;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.UnsupportedProtocolException;
+import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.authentication.AuthenticationException;
+import org.apache.maven.wagon.authorization.AuthorizationException;
+import org.apache.maven.wagon.observers.Debug;
+import org.apache.maven.wagon.proxy.ProxyInfo;
+import org.apache.maven.wagon.repository.Repository;
+
+
+/**
+ * this class is used to manage all connections by wagon.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class RemoteFileManager
+{
+
+    /**
+     * save the connection.
+     */
+    private Wagon m_wagon;
+
+    /**
+     * the wagon manager.
+     */
+    private WagonManager m_wagonManager;
+
+    /**
+     * artifact repository.
+     */
+    private ArtifactRepository m_artifactRepository;
+
+    /**
+     * the project settings.
+     */
+    private Settings m_settings;
+
+    /**
+     * logger instance.
+     */
+    private Log m_log;
+
+
+    /**
+     * initialize main information.
+     * @param ar ArtifactRepository provides by maven
+     * @param wm WagonManager provides by maven
+     * @param settings settings of the current project provides by maven
+     * @param log logger
+     */
+    public RemoteFileManager( ArtifactRepository ar, WagonManager wm, Settings settings, Log log )
+    {
+        m_artifactRepository = ar;
+        m_wagonManager = wm;
+        m_settings = settings;
+        m_log = log;
+        m_wagon = null;
+    }
+
+
+    /**
+     * disconnect the current object.
+     *
+     */
+    public void disconnect()
+    {
+        if ( m_wagon == null )
+        {
+            m_log.error( "must be connected first!" );
+            return;
+        }
+        try
+        {
+            m_wagon.disconnect();
+        }
+        catch ( ConnectionException e )
+        {
+            m_log.error( "Error disconnecting wagon - ignored", e );
+        }
+    }
+
+
+    /**
+     * connect the current object to artifact repository given in constructor.
+     * @throws MojoExecutionException if connection failed
+     */
+    public void connect() throws MojoExecutionException
+    {
+        String url = m_artifactRepository.getUrl();
+        String id = m_artifactRepository.getId();
+
+        Repository repository = new Repository( id, url );
+
+        try
+        {
+            m_wagon = m_wagonManager.getWagon( repository );
+            //configureWagon(m_wagon, repository.getId());
+        }
+        catch ( UnsupportedProtocolException e )
+        {
+            throw new MojoExecutionException( "Unsupported protocol: '" + repository.getProtocol() + "'", e );
+        }
+        catch ( WagonConfigurationException e )
+        {
+            throw new MojoExecutionException( "Unable to configure Wagon: '" + repository.getProtocol() + "'", e );
+        }
+
+        try
+        {
+            Debug debug = new Debug();
+            m_wagon.addTransferListener( debug );
+
+            ProxyInfo proxyInfo = getProxyInfo( m_settings );
+            if ( proxyInfo != null )
+            {
+                m_wagon.connect( repository, m_wagonManager.getAuthenticationInfo( id ), proxyInfo );
+            }
+            else
+            {
+                m_wagon.connect( repository, m_wagonManager.getAuthenticationInfo( id ) );
+            }
+
+        }
+        catch ( ConnectionException e )
+        {
+            throw new MojoExecutionException( "Error uploading file", e );
+        }
+        catch ( AuthenticationException e )
+        {
+            throw new MojoExecutionException( "Error uploading file", e );
+        }
+    }
+
+
+    /**
+     * get a file from the current repository connected.
+     * @param url url to the targeted file
+     * @return  get a file descriptor on the requiered resource
+     * @throws IOException if an IO error occurs
+     * @throws TransferFailedException  if the transfer failed 
+     * @throws ResourceDoesNotExistException if the targeted resource doesn't exist
+     * @throws AuthorizationException if the connection authorization failed
+     */
+    public File get( String url ) throws IOException, TransferFailedException, ResourceDoesNotExistException,
+        AuthorizationException
+    {
+
+        if ( m_wagon == null )
+        {
+            m_log.error( "must be connected first!" );
+            return null;
+        }
+
+        File file = File.createTempFile( String.valueOf( System.currentTimeMillis() ), "tmp" );
+        m_wagon.get( url, file );
+        return file;
+    }
+
+
+    /**
+     * put a file on the current repository connected.
+     * @param file file to upload
+     * @param url url to copy file
+     * @throws TransferFailedException if the transfer failed 
+     * @throws ResourceDoesNotExistException if the targeted resource doesn't exist
+     * @throws AuthorizationException if the connection authorization failed
+     */
+    public void put( File file, String url ) throws TransferFailedException, ResourceDoesNotExistException,
+        AuthorizationException
+    {
+        if ( m_wagon == null )
+        {
+            m_log.error( "must be connected first!" );
+            return;
+        }
+        m_wagon.put( file, url );
+    }
+
+
+    /**
+     * Convenience method to map a Proxy object from the user system settings to a ProxyInfo object.
+     * @param settings project settings given by maven
+     * @return a proxyInfo object instancied or null if no active proxy is define in the settings.xml
+     */
+    public static ProxyInfo getProxyInfo( Settings settings )
+    {
+        ProxyInfo proxyInfo = null;
+        if ( settings != null && settings.getActiveProxy() != null )
+        {
+            Proxy settingsProxy = settings.getActiveProxy();
+
+            proxyInfo = new ProxyInfo();
+            proxyInfo.setHost( settingsProxy.getHost() );
+            proxyInfo.setType( settingsProxy.getProtocol() );
+            proxyInfo.setPort( settingsProxy.getPort() );
+            proxyInfo.setNonProxyHosts( settingsProxy.getNonProxyHosts() );
+            proxyInfo.setUserName( settingsProxy.getUsername() );
+            proxyInfo.setPassword( settingsProxy.getPassword() );
+        }
+
+        return proxyInfo;
+    }
+
+
+    /**
+     * this method indicates if the targeted file is locked or not.
+     * @param remote connection manager
+     * @param fileName name targeted
+     * @return  true if thr reuiered file is locked, else false
+     * @throws MojoFailureException if the plugin failed
+     */
+    public boolean isLockedFile( RemoteFileManager remote, String fileName ) throws MojoFailureException
+    {
+        File file = null;
+        try
+        {
+            file = remote.get( fileName + ".lock" );
+        }
+        catch ( TransferFailedException e )
+        {
+            e.printStackTrace();
+            throw new MojoFailureException( "TransferFailedException" );
+
+        }
+        catch ( ResourceDoesNotExistException e )
+        {
+            return false;
+        }
+        catch ( AuthorizationException e )
+        {
+            e.printStackTrace();
+            throw new MojoFailureException( "AuthorizationException" );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+            throw new MojoFailureException( "IOException" );
+        }
+        if ( file != null && file.length() == 0 )
+        {
+            return false;
+        }
+        return true;
+    }
+
+}

Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/Require.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/Require.java?rev=615140&r1=615139&r2=615140&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/Require.java (original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/Require.java Fri Jan 25 00:10:25 2008
@@ -1,204 +1,204 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.obr.plugin;
-
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-
-/**
- * this class store a Require tag.
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class Require
-{
-
-    /**
-     * store the extend attribute.
-     */
-    private String m_extend;
-
-    /**
-     * store the multiple attribute.
-     */
-    private String m_multiple;
-
-    /**
-     * store the optional attribute.
-     */
-    private String m_optional;
-
-    /**
-     * store the name attribute.
-     */
-    private String m_name;
-
-    /**
-     * store the filter attribute.
-     */
-    private String m_filter;
-
-    /**
-     * store the value of the tag.
-     */
-    private String m_value;
-
-
-    /**
-     * get the extend attribute.
-     * @return a string which contains the value of the boolean
-     */
-    public String getExtend()
-    {
-        return m_extend;
-    }
-
-
-    /**
-     * set the extend attribute.
-     * @param extend new value for the extend attribute
-     */
-    public void setExtend( String extend )
-    {
-        this.m_extend = extend;
-    }
-
-
-    /**
-     * get the filter attribute.
-     * @return m_filter value
-     */
-    public String getFilter()
-    {
-        return m_filter;
-    }
-
-
-    /**
-     * set the filter attribute.
-     * @param filter new value for filter
-     */
-    public void setFilter( String filter )
-    {
-        this.m_filter = filter;
-    }
-
-
-    /**
-     * get multiple attribute.
-     * @return m_multiple value
-     */
-    public String getMultiple()
-    {
-        return m_multiple;
-    }
-
-
-    /**
-     * set multiple attribute.
-     * @param multiple new value for m_multiple
-     */
-    public void setMultiple( String multiple )
-    {
-        this.m_multiple = multiple;
-    }
-
-
-    /**
-     * get name attribute.
-     * @return m_name value
-     */
-    public String getName()
-    {
-        return m_name;
-    }
-
-
-    /**
-     * set name attribute.
-     * @param name new value for m_name
-     */
-    public void setName( String name )
-    {
-        this.m_name = name;
-    }
-
-
-    /**
-     * get the optional attribute.
-     * @return m_optional value
-     */
-    public String getOptional()
-    {
-        return m_optional;
-    }
-
-
-    /**
-     * set the optional attribute.
-     * @param optionnal new value for m_optional
-     */
-    public void setOptional( String optionnal )
-    {
-        this.m_optional = optionnal;
-    }
-
-
-    /**
-     * get value of the tag.
-     * @return value of this tag
-     */
-    public String getValue()
-    {
-        return m_value;
-    }
-
-
-    /**
-     * set the value of the tag.
-     * @param value new value for this tag
-     */
-    public void setValue( String value )
-    {
-        this.m_value = value;
-    }
-
-
-    /**
-     * transform this object to Node.
-     * 
-     * @param father father document for create Node
-     * @return node
-     */
-    public Node getNode( Document father )
-    {
-        Element require = father.createElement( "require" );
-        require.setAttribute( "name", this.getName() );
-        require.setAttribute( "filter", this.getFilter() );
-        require.setAttribute( "extend", this.getExtend() );
-        require.setAttribute( "multiple", this.getMultiple() );
-        require.setAttribute( "optional", this.getOptional() );
-        XmlHelper.setTextContent( require, this.getValue() );
-
-        return require;
-    }
-
-}
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.obr.plugin;
+
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+
+/**
+ * this class store a Require tag.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Require
+{
+
+    /**
+     * store the extend attribute.
+     */
+    private String m_extend;
+
+    /**
+     * store the multiple attribute.
+     */
+    private String m_multiple;
+
+    /**
+     * store the optional attribute.
+     */
+    private String m_optional;
+
+    /**
+     * store the name attribute.
+     */
+    private String m_name;
+
+    /**
+     * store the filter attribute.
+     */
+    private String m_filter;
+
+    /**
+     * store the value of the tag.
+     */
+    private String m_value;
+
+
+    /**
+     * get the extend attribute.
+     * @return a string which contains the value of the boolean
+     */
+    public String getExtend()
+    {
+        return m_extend;
+    }
+
+
+    /**
+     * set the extend attribute.
+     * @param extend new value for the extend attribute
+     */
+    public void setExtend( String extend )
+    {
+        this.m_extend = extend;
+    }
+
+
+    /**
+     * get the filter attribute.
+     * @return m_filter value
+     */
+    public String getFilter()
+    {
+        return m_filter;
+    }
+
+
+    /**
+     * set the filter attribute.
+     * @param filter new value for filter
+     */
+    public void setFilter( String filter )
+    {
+        this.m_filter = filter;
+    }
+
+
+    /**
+     * get multiple attribute.
+     * @return m_multiple value
+     */
+    public String getMultiple()
+    {
+        return m_multiple;
+    }
+
+
+    /**
+     * set multiple attribute.
+     * @param multiple new value for m_multiple
+     */
+    public void setMultiple( String multiple )
+    {
+        this.m_multiple = multiple;
+    }
+
+
+    /**
+     * get name attribute.
+     * @return m_name value
+     */
+    public String getName()
+    {
+        return m_name;
+    }
+
+
+    /**
+     * set name attribute.
+     * @param name new value for m_name
+     */
+    public void setName( String name )
+    {
+        this.m_name = name;
+    }
+
+
+    /**
+     * get the optional attribute.
+     * @return m_optional value
+     */
+    public String getOptional()
+    {
+        return m_optional;
+    }
+
+
+    /**
+     * set the optional attribute.
+     * @param optionnal new value for m_optional
+     */
+    public void setOptional( String optionnal )
+    {
+        this.m_optional = optionnal;
+    }
+
+
+    /**
+     * get value of the tag.
+     * @return value of this tag
+     */
+    public String getValue()
+    {
+        return m_value;
+    }
+
+
+    /**
+     * set the value of the tag.
+     * @param value new value for this tag
+     */
+    public void setValue( String value )
+    {
+        this.m_value = value;
+    }
+
+
+    /**
+     * transform this object to Node.
+     * 
+     * @param father father document for create Node
+     * @return node
+     */
+    public Node getNode( Document father )
+    {
+        Element require = father.createElement( "require" );
+        require.setAttribute( "name", this.getName() );
+        require.setAttribute( "filter", this.getFilter() );
+        require.setAttribute( "extend", this.getExtend() );
+        require.setAttribute( "multiple", this.getMultiple() );
+        require.setAttribute( "optional", this.getOptional() );
+        XmlHelper.setTextContent( require, this.getValue() );
+
+        return require;
+    }
+
+}