You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wagon-commits@maven.apache.org by tr...@apache.org on 2005/09/05 22:54:17 UTC
svn commit: r278834 - in /maven/wagon/trunk/wagon-providers/wagon-ssh/src:
main/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtils.java
test/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtilsTest.java
Author: trygvis
Date: Mon Sep 5 13:54:09 2005
New Revision: 278834
URL: http://svn.apache.org/viewcvs?rev=278834&view=rev
Log:
o Adding missed files.
Added:
maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtils.java (with props)
maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtilsTest.java (with props)
Added: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtils.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtils.java?rev=278834&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtils.java (added)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtils.java Mon Sep 5 13:54:09 2005
@@ -0,0 +1,65 @@
+package org.apache.maven.wagon.providers.ssh;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * Utility class for common operations for file/directory permissions.
+ *
+ * @author <a href="mailto:juam at users.sourceforge.net">Juan F. Codagnone</a>
+ * @see PermissionModeUtils
+ * @since Sep 3, 2005
+ */
+public class PermissionModeUtils
+{
+ /**
+ * See the System Interfaces volume of IEEE Std 1003.1-2001, umask(1)
+ *
+ * @param modeStr permision mode (numeric or symbolic)
+ * @return the mode that can be used with unmask to acomplish modeStr.
+ */
+ public static String getUserMaskFor( String modeStr )
+ {
+ String ret = null;
+
+ try
+ {
+ int mode = Integer.valueOf( modeStr, 8 ).intValue();
+
+ mode = mode % 8 + ( ( mode / 8 ) % 8 ) * 8 + ( ( mode / 64 ) % 8 ) * 64;
+
+ ret = Integer.toOctalString( 0777 - mode );
+ }
+ catch ( final NumberFormatException e )
+ {
+ try
+ {
+ Integer.parseInt( modeStr );
+ }
+ catch ( final NumberFormatException e1 )
+ {
+ ret = modeStr;
+ }
+ }
+
+ if ( ret == null )
+ {
+ throw new IllegalArgumentException( "The mode is a number but is not octal" );
+ }
+
+ return ret;
+ }
+}
Propchange: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtils.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtilsTest.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtilsTest.java?rev=278834&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtilsTest.java (added)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtilsTest.java Mon Sep 5 13:54:09 2005
@@ -0,0 +1,67 @@
+package org.apache.maven.wagon.providers.ssh;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import junit.framework.TestCase;
+
+/**
+ * Unit test for PermissionModeUtils class
+ *
+ * @author <a href="mailto:juam at users.sourceforge.net">Juan F. Codagnone</a>
+ * @see PermissionModeUtils
+ * @since Sep 3, 2005
+ */
+public class PermissionModeUtilsTest
+ extends TestCase
+{
+ /**
+ * @throws Exception on error
+ */
+ public void testNumeric()
+ throws Exception
+ {
+ final String[][] tests = {
+ {"0", "777"},
+ {"0000", "777"},
+ {"770", "7"},
+ {"0770", "7"},
+ {"0123", "654"},
+ {"9", null},
+ {"678", null},
+ {"ug+rwX,o-rwX", "ug+rwX,o-rwX"},
+ {"1770", "7"},
+ {"14770", "7"},
+
+ };
+
+ for ( int i = 0; i < tests.length; i++ )
+ {
+ String umask = null;
+
+ try
+ {
+ umask = PermissionModeUtils.getUserMaskFor( tests[ i ][ 0 ] );
+ }
+ catch ( IllegalArgumentException e )
+ {
+ // nothing to do
+ }
+
+ assertEquals( tests[ i ][ 1 ], umask );
+ }
+ }
+}
Propchange: maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtilsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtilsTest.java
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-cvs-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-cvs-help@maven.apache.org