archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marti...@apache.org
Subject archiva-redback-core git commit: Switching redback to java.nio
Date Thu, 21 Sep 2017 16:51:50 GMT
Repository: archiva-redback-core
Updated Branches:
  refs/heads/master e7b05cfc2 -> 56febc67a


Switching redback to java.nio


Project: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/commit/56febc67
Tree: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/tree/56febc67
Diff: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/diff/56febc67

Branch: refs/heads/master
Commit: 56febc67a95617e79115dca577ab114fa5dfe27e
Parents: e7b05cf
Author: Martin Stockhammer <martin.stockhammer@ars.de>
Authored: Thu Sep 21 18:50:40 2017 +0200
Committer: Martin Stockhammer <martin.stockhammer@ars.de>
Committed: Thu Sep 21 18:50:40 2017 +0200

----------------------------------------------------------------------
 .../configuration/DefaultUserConfiguration.java |  8 +--
 .../redback/management/DataManagementTool.java  | 14 ++---
 .../redback/management/DataManagementTest.java  | 55 +++++++++-----------
 .../checks/security/AdminAutoCreateCheck.java   | 12 +++--
 .../role/processor/RoleModelProcessorTest.java  |  7 +--
 .../template/RoleTemplateProcessorTest.java     |  7 +--
 .../role/validator/RoleModelValidatorTest.java  | 15 +++---
 7 files changed, 59 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/56febc67/redback-configuration/src/main/java/org/apache/archiva/redback/configuration/DefaultUserConfiguration.java
----------------------------------------------------------------------
diff --git a/redback-configuration/src/main/java/org/apache/archiva/redback/configuration/DefaultUserConfiguration.java
b/redback-configuration/src/main/java/org/apache/archiva/redback/configuration/DefaultUserConfiguration.java
index a5c0ac3..c66a60e 100644
--- a/redback-configuration/src/main/java/org/apache/archiva/redback/configuration/DefaultUserConfiguration.java
+++ b/redback-configuration/src/main/java/org/apache/archiva/redback/configuration/DefaultUserConfiguration.java
@@ -19,12 +19,12 @@ package org.apache.archiva.redback.configuration;
  * under the License.
  */
 
-import org.apache.archiva.redback.components.registry.Registry;
-import org.apache.archiva.redback.components.registry.RegistryException;
 import org.apache.archiva.redback.components.evaluator.DefaultExpressionEvaluator;
 import org.apache.archiva.redback.components.evaluator.EvaluatorException;
 import org.apache.archiva.redback.components.evaluator.ExpressionEvaluator;
 import org.apache.archiva.redback.components.evaluator.sources.SystemPropertyExpressionSource;
+import org.apache.archiva.redback.components.registry.Registry;
+import org.apache.archiva.redback.components.registry.RegistryException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -32,7 +32,7 @@ import org.springframework.stereotype.Service;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Named;
-import java.io.File;
+import java.nio.file.Paths;
 import java.util.Collection;
 import java.util.List;
 
@@ -133,7 +133,7 @@ public class DefaultUserConfiguration
                 }
                 log.info( "Attempting to find configuration [{}] (resolved to [{}])", configName,
configName );
 
-                registry.addConfigurationFromFile( new File( configName ), PREFIX );
+                registry.addConfigurationFromFile(Paths.get(configName).toFile(), PREFIX
);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/56febc67/redback-data-management/src/main/java/org/apache/archiva/redback/management/DataManagementTool.java
----------------------------------------------------------------------
diff --git a/redback-data-management/src/main/java/org/apache/archiva/redback/management/DataManagementTool.java
b/redback-data-management/src/main/java/org/apache/archiva/redback/management/DataManagementTool.java
index 343120c..a64a1d3 100644
--- a/redback-data-management/src/main/java/org/apache/archiva/redback/management/DataManagementTool.java
+++ b/redback-data-management/src/main/java/org/apache/archiva/redback/management/DataManagementTool.java
@@ -26,8 +26,8 @@ import org.apache.archiva.redback.rbac.RbacManagerException;
 import org.apache.archiva.redback.users.UserManagerException;
 
 import javax.xml.stream.XMLStreamException;
-import java.io.File;
 import java.io.IOException;
+import java.nio.file.Path;
 
 /**
  * Data management tool API.
@@ -35,22 +35,22 @@ import java.io.IOException;
 public interface DataManagementTool
 {
 
-    void backupRBACDatabase( RBACManager manager, File backupDirectory )
+    void backupRBACDatabase( RBACManager manager, Path backupDirectory )
         throws RbacManagerException, IOException, XMLStreamException;
 
-    void backupUserDatabase( UserManager manager, File backupDirectory )
+    void backupUserDatabase( UserManager manager, Path backupDirectory )
         throws IOException, XMLStreamException, UserManagerException;
 
-    void backupKeyDatabase( KeyManager manager, File backupDirectory )
+    void backupKeyDatabase( KeyManager manager, Path backupDirectory )
         throws IOException, XMLStreamException;
 
-    void restoreRBACDatabase( RBACManager manager, File backupDirectory )
+    void restoreRBACDatabase( RBACManager manager, Path backupDirectory )
         throws IOException, XMLStreamException, RbacManagerException;
 
-    void restoreUsersDatabase( UserManager manager, File backupDirectory )
+    void restoreUsersDatabase( UserManager manager, Path backupDirectory )
         throws IOException, XMLStreamException, UserManagerException;
 
-    void restoreKeysDatabase( KeyManager manager, File backupDirectory )
+    void restoreKeysDatabase( KeyManager manager, Path backupDirectory )
         throws IOException, XMLStreamException;
 
     void eraseRBACDatabase( RBACManager manager );

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/56febc67/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java
----------------------------------------------------------------------
diff --git a/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java
b/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java
index 3a78182..c8920c6 100644
--- a/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java
+++ b/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java
@@ -23,11 +23,7 @@ import junit.framework.TestCase;
 import org.apache.archiva.redback.keys.AuthenticationKey;
 import org.apache.archiva.redback.keys.KeyManager;
 import org.apache.archiva.redback.keys.KeyManagerException;
-import org.apache.archiva.redback.rbac.Permission;
-import org.apache.archiva.redback.rbac.RBACManager;
-import org.apache.archiva.redback.rbac.RbacManagerException;
-import org.apache.archiva.redback.rbac.Role;
-import org.apache.archiva.redback.rbac.UserAssignment;
+import org.apache.archiva.redback.rbac.*;
 import org.apache.archiva.redback.tests.utils.RBACDefaults;
 import org.apache.archiva.redback.users.User;
 import org.apache.archiva.redback.users.UserManager;
@@ -45,11 +41,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
 import javax.inject.Inject;
 import javax.inject.Named;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.io.StringWriter;
+import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.Date;
@@ -67,7 +63,7 @@ public class DataManagementTest
     @Inject
     private DataManagementTool dataManagementTool;
 
-    private File targetDirectory;
+    private Path targetDirectory;
 
     @Inject
     @Named(value = "userManager#jpa")
@@ -128,16 +124,16 @@ public class DataManagementTest
 
         dataManagementTool.backupRBACDatabase( manager, targetDirectory );
 
-        File backupFile = new File( targetDirectory, "rbac.xml" );
+        Path backupFile = targetDirectory.resolve( "rbac.xml" );
 
-        assertTrue( "Check database exists", backupFile.exists() );
+        assertTrue( "Check database exists", Files.exists(backupFile) );
 
         StringWriter sw = new StringWriter();
 
         IOUtils.copy( getClass().getResourceAsStream( "/expected-rbac.xml" ), sw );
 
         XMLAssert.assertXMLEqual( new StringReader( sw.toString() ),
-                                  new StringReader( FileUtils.readFileToString( backupFile
) ) );
+                                  new StringReader( FileUtils.readFileToString( backupFile.toFile()
) ) );
 
     }
 
@@ -167,15 +163,15 @@ public class DataManagementTest
 
         dataManagementTool.backupUserDatabase( manager, targetDirectory );
 
-        File backupFile = new File( targetDirectory, "users.xml" );
+        Path backupFile = targetDirectory.resolve( "users.xml" );
 
-        assertTrue( "Check database exists", backupFile.exists() );
+        assertTrue( "Check database exists", Files.exists(backupFile) );
 
         StringWriter sw = new StringWriter();
 
         IOUtils.copy( getClass().getResourceAsStream( "/expected-users.xml" ), sw );
 
-        String actual = FileUtils.readFileToString( backupFile ).trim();
+        String actual = FileUtils.readFileToString( backupFile.toFile() ).trim();
         String expected = sw.toString().trim();
 
         XMLAssert.assertXMLEqual( removeTimestampVariance( expected ), removeTimestampVariance(
actual ) );
@@ -210,15 +206,15 @@ public class DataManagementTest
 
         dataManagementTool.backupKeyDatabase( manager, targetDirectory );
 
-        File backupFile = new File( targetDirectory, "keys.xml" );
+        Path backupFile = targetDirectory.resolve( "keys.xml" );
 
-        assertTrue( "Check database exists", backupFile.exists() );
+        assertTrue( "Check database exists", Files.exists(backupFile) );
 
         StringWriter sw = new StringWriter();
 
         IOUtils.copy( getClass().getResourceAsStream( "/expected-keys.xml" ), sw );
 
-        String actual = FileUtils.readFileToString( backupFile ).trim();
+        String actual = FileUtils.readFileToString( backupFile.toFile() ).trim();
         String expected = sw.toString().trim();
 
         XMLAssert.assertXMLEqual( removeKeyAndTimestampVariance( expected ), removeKeyAndTimestampVariance(
actual ) );
@@ -244,11 +240,11 @@ public class DataManagementTest
 
         assertEmpty( manager );
 
-        File backupFile = new File( targetDirectory, "rbac.xml" );
+        Path backupFile = targetDirectory.resolve("rbac.xml" );
 
         InputStream is = getClass().getResourceAsStream( "/expected-rbac.xml" );
 
-        FileWriter fw = new FileWriter( backupFile );
+        BufferedWriter fw = Files.newBufferedWriter(backupFile, StandardOpenOption.CREATE_NEW);
 
         IOUtils.copy( is, fw );
 
@@ -331,9 +327,9 @@ public class DataManagementTest
 
         assertEmpty( manager );
 
-        File backupFile = new File( targetDirectory, "users.xml" );
+        Path backupFile = targetDirectory.resolve( "users.xml" );
 
-        FileWriter fw = new FileWriter( backupFile );
+        BufferedWriter fw = Files.newBufferedWriter(backupFile, StandardOpenOption.CREATE_NEW
);
 
         IOUtils.copy( getClass().getResourceAsStream( "/expected-users.xml" ), fw );
 
@@ -389,9 +385,9 @@ public class DataManagementTest
 
         assertEmpty( manager );
 
-        File backupFile = new File( targetDirectory, "keys.xml" );
+        Path backupFile = targetDirectory.resolve( "keys.xml" );
 
-        FileWriter fw = new FileWriter( backupFile );
+        BufferedWriter fw = Files.newBufferedWriter( backupFile, StandardOpenOption.CREATE_NEW
);
 
         IOUtils.copy( getClass().getResourceAsStream( "/expected-keys.xml" ), fw );
 
@@ -451,12 +447,11 @@ public class DataManagementTest
         assertEquals( resource, permission.getResource().getIdentifier() );
     }
 
-    private static File createBackupDirectory()
-    {
+    private static Path createBackupDirectory() throws IOException {
         String timestamp = new SimpleDateFormat( "yyyyMMdd.HHmmss", Locale.US ).format( new
Date() );
 
-        File targetDirectory = new File( SystemUtils.getJavaIoTmpDir(), "./target/backups/"
+ timestamp );
-        targetDirectory.mkdirs();
+        Path targetDirectory = Paths.get( SystemUtils.getJavaIoTmpDir().toString(), "./target/backups/"
+ timestamp );
+        Files.createDirectories(targetDirectory);
 
         return targetDirectory;
     }

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/56febc67/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/AdminAutoCreateCheck.java
----------------------------------------------------------------------
diff --git a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/AdminAutoCreateCheck.java
b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/AdminAutoCreateCheck.java
index 8ab0e81..6821a4b 100644
--- a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/AdminAutoCreateCheck.java
+++ b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/AdminAutoCreateCheck.java
@@ -40,8 +40,10 @@ import org.springframework.stereotype.Service;
 
 import javax.inject.Inject;
 import javax.inject.Named;
-import java.io.File;
-import java.io.FileInputStream;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Date;
 import java.util.List;
 import java.util.Properties;
@@ -113,15 +115,15 @@ public class AdminAutoCreateCheck
                 log.info( "{} system props is empty don't use an auto creation admin ", FORCE_ADMIN_FILE_PATH
);
                 return;
             }
-            File file = new File( forceAdminFilePath );
-            if ( !file.exists() )
+            Path file = Paths.get( forceAdminFilePath );
+            if ( !Files.exists(file) )
             {
                 log.warn( "file set in sysprops {} not exists skip admin auto creation",
FORCE_ADMIN_FILE_PATH );
                 return;
             }
             log.debug( "user {} not found try auto creation", getAdminUid() );
             Properties properties = new Properties();
-            FileInputStream fis = new FileInputStream( file );
+            InputStream fis = Files.newInputStream(file);
             try
             {
                 properties.load( fis );

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/56febc67/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/processor/RoleModelProcessorTest.java
----------------------------------------------------------------------
diff --git a/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/processor/RoleModelProcessorTest.java
b/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/processor/RoleModelProcessorTest.java
index d1a53c6..38f1330 100644
--- a/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/processor/RoleModelProcessorTest.java
+++ b/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/processor/RoleModelProcessorTest.java
@@ -36,8 +36,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.xml.stream.XMLStreamException;
-import java.io.File;
 import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 
 /**
  * RoleProfileTest:
@@ -89,13 +90,13 @@ public class RoleModelProcessorTest
     private RedbackRoleModel getModelFromFile( String file )
         throws IOException, XMLStreamException
     {
-        File resource = new File( getBasedir() + file );
+        Path resource = Paths.get( getBasedir() + file );
 
         assertNotNull( resource );
 
         RedbackRoleModelStaxReader modelReader = new RedbackRoleModelStaxReader();
 
-        RedbackRoleModel redback = modelReader.read( resource.getAbsolutePath() );
+        RedbackRoleModel redback = modelReader.read( resource.toAbsolutePath().toString()
);
 
         assertNotNull( redback );
         return redback;

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/56febc67/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/template/RoleTemplateProcessorTest.java
----------------------------------------------------------------------
diff --git a/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/template/RoleTemplateProcessorTest.java
b/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/template/RoleTemplateProcessorTest.java
index 4c8ef7b..d20d6e6 100644
--- a/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/template/RoleTemplateProcessorTest.java
+++ b/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/template/RoleTemplateProcessorTest.java
@@ -35,7 +35,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
 import javax.inject.Inject;
 import javax.inject.Named;
-import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 
 /**
  * RoleProfileTest:
@@ -77,13 +78,13 @@ public class RoleTemplateProcessorTest
     public void testLoading()
         throws Exception
     {
-        File resource = new File( getBasedir() + "/src/test/template-tests/redback-1.xml"
);
+        Path resource = Paths.get(getBasedir() + "/src/test/template-tests/redback-1.xml");
 
         assertNotNull( resource );
 
         RedbackRoleModelStaxReader modelReader = new RedbackRoleModelStaxReader();
 
-        RedbackRoleModel redback = modelReader.read( resource.getAbsolutePath() );
+        RedbackRoleModel redback = modelReader.read( resource.toAbsolutePath().toString()
);
 
         assertNotNull( redback );
 

http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/56febc67/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/validator/RoleModelValidatorTest.java
----------------------------------------------------------------------
diff --git a/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/validator/RoleModelValidatorTest.java
b/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/validator/RoleModelValidatorTest.java
index 473e645..e360f64 100644
--- a/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/validator/RoleModelValidatorTest.java
+++ b/redback-rbac/redback-rbac-role-manager/src/test/java/org/apache/archiva/redback/role/validator/RoleModelValidatorTest.java
@@ -29,7 +29,8 @@ import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
 import javax.inject.Inject;
-import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.List;
 
 /**
@@ -71,13 +72,13 @@ public class RoleModelValidatorTest
     @Test
     public void testGood() throws Exception 
     {
-        File resource = new File( getBasedir() + "/src/test/validation-tests/redback-good.xml");
+        Path resource = Paths.get(getBasedir() + "/src/test/validation-tests/redback-good.xml");
         
         assertNotNull( resource );
         
         RedbackRoleModelStaxReader modelReader = new RedbackRoleModelStaxReader();
         
-        RedbackRoleModel redback = modelReader.read( resource.getAbsolutePath() );
+        RedbackRoleModel redback = modelReader.read( resource.toAbsolutePath().toString()
);
         
         assertNotNull( redback );
 
@@ -89,13 +90,13 @@ public class RoleModelValidatorTest
     @Test
     public void testBad() throws Exception 
     {
-        File resource = new File( getBasedir() + "/src/test/validation-tests/redback-bad.xml");
+        Path resource = Paths.get( getBasedir() + "/src/test/validation-tests/redback-bad.xml");
         
         assertNotNull( resource );
         
         RedbackRoleModelStaxReader modelReader = new RedbackRoleModelStaxReader();
         
-        RedbackRoleModel redback = modelReader.read( resource.getAbsolutePath() );
+        RedbackRoleModel redback = modelReader.read( resource.toAbsolutePath().toString()
);
         
         assertNotNull( redback );
 
@@ -120,13 +121,13 @@ public class RoleModelValidatorTest
     @Test
     public void testCore() throws Exception 
     {
-        File resource = new File( getBasedir() + "/src/test/validation-tests/redback-core.xml");
+        Path resource = Paths.get( getBasedir() + "/src/test/validation-tests/redback-core.xml");
         
         assertNotNull( resource );
         
         RedbackRoleModelStaxReader modelReader = new RedbackRoleModelStaxReader();
         
-        RedbackRoleModel redback = modelReader.read( resource.getAbsolutePath() );
+        RedbackRoleModel redback = modelReader.read( resource.toAbsolutePath().toString()
);
         
         assertNotNull( redback );
 


Mime
View raw message