directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1805834 - in /directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config: ExpandedLdifUtils.java OpenLdapConfigurationPlugin.java OpenLdapConfigurationPluginUtils.java
Date Tue, 22 Aug 2017 22:09:36 GMT
Author: elecharny
Date: Tue Aug 22 22:09:36 2017
New Revision: 1805834

URL: http://svn.apache.org/viewvc?rev=1805834&view=rev
Log:
Fixed many Sonar lint warnings

Modified:
    directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/ExpandedLdifUtils.java
    directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPlugin.java
    directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPluginUtils.java

Modified: directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/ExpandedLdifUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/ExpandedLdifUtils.java?rev=1805834&r1=1805833&r2=1805834&view=diff
==============================================================================
--- directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/ExpandedLdifUtils.java
(original)
+++ directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/ExpandedLdifUtils.java
Tue Aug 22 22:09:36 2017
@@ -47,13 +47,17 @@ import org.apache.directory.studio.openl
  */
 public class ExpandedLdifUtils 
 {
+    private ExpandedLdifUtils()
+    {
+        // Nothing to do
+    }
+    
+    
     /** The LDIF file extension (.ldif) */
     private static final String LDIF_FILE_EXTENSION = ".ldif";
 
     /** A filter used to pick all the LDIF files */
-    private static FileFilter ldifFileFilter = new FileFilter()
-    {
-        public boolean accept( File dir )
+    private static FileFilter ldifFileFilter = dir ->
         {
             if ( dir.getName().endsWith( LDIF_FILE_EXTENSION ) )
             {
@@ -63,8 +67,7 @@ public class ExpandedLdifUtils
             {
                 return false;
             }
-        }
-    };
+        };
 
 
     /**
@@ -76,7 +79,7 @@ public class ExpandedLdifUtils
      */
     public static DnNode<Entry> read( File directory ) throws IOException, LdapException
     {
-        DnNode<Entry> tree = new DnNode<Entry>();
+        DnNode<Entry> tree = new DnNode<>();
 
         readDirectory( directory, Dn.EMPTY_DN, tree );
 
@@ -121,64 +124,65 @@ public class ExpandedLdifUtils
 
             if ( ( ldifFiles != null ) && ( ldifFiles.length != 0 ) )
             {
-                LdifReader ldifReader = new LdifReader();
-
-                // Looping on LDIF files
-                for ( File ldifFile : ldifFiles )
+                try ( LdifReader ldifReader = new LdifReader() )
                 {
-                    // Checking if the LDIF file is a file
-                    if ( !ldifFile.isFile() )
-                    {
-                        throw new IOException( "Location '" + ldifFile + "' is not a file."
);
-                    }
-
-                    // Checking if the LDIF file is readable
-                    if ( !ldifFile.canRead() )
-                    {
-                        throw new IOException( "LDIF file '" + ldifFile + "' can not be read."
);
-                    }
-
-                    // Computing the DN of the entry
-                    Dn entryDn = parentDn.add( stripExtension( ldifFile.getName() ) );
-
-                    // Reading the LDIF file
-                    List<LdifEntry> ldifEntries = null;
-
-                    try
-                    {
-                        ldifEntries = ldifReader.parseLdifFile( ldifFile.getAbsolutePath()
);
-                    }
-                    finally
-                    {
-                        ldifReader.close();
-                    }
-
-                    // The LDIF file should have only one entry
-                    if ( ( ldifEntries != null ) && ( ldifEntries.size() == 1 ) )
+                    // Looping on LDIF files
+                    for ( File ldifFile : ldifFiles )
                     {
-                        // Getting the LDIF entry
-                        LdifEntry ldifEntry = ldifEntries.get( 0 );
-
-                        if ( ldifEntry != null )
+                        // Checking if the LDIF file is a file
+                        if ( !ldifFile.isFile() )
                         {
-                            // Getting the entry
-                            Entry entry = ldifEntry.getEntry();
-
-                            if ( entry != null )
+                            throw new IOException( "Location '" + ldifFile + "' is not a
file." );
+                        }
+    
+                        // Checking if the LDIF file is readable
+                        if ( !ldifFile.canRead() )
+                        {
+                            throw new IOException( "LDIF file '" + ldifFile + "' can not
be read." );
+                        }
+    
+                        // Computing the DN of the entry
+                        Dn entryDn = parentDn.add( stripExtension( ldifFile.getName() ) );
+    
+                        // Reading the LDIF file
+                        List<LdifEntry> ldifEntries = null;
+    
+                        try
+                        {
+                            ldifEntries = ldifReader.parseLdifFile( ldifFile.getAbsolutePath()
);
+                        }
+                        finally
+                        {
+                            ldifReader.close();
+                        }
+    
+                        // The LDIF file should have only one entry
+                        if ( ( ldifEntries != null ) && ( ldifEntries.size() == 1
) )
+                        {
+                            // Getting the LDIF entry
+                            LdifEntry ldifEntry = ldifEntries.get( 0 );
+    
+                            if ( ldifEntry != null )
                             {
-                                // Refactoring the DN to set the "FULL" DN of the entry
-                                entry.setDn( entryDn );
-
-                                // Creating the new entry node
-                                tree.add( entryDn, entry );
-
-                                // Creating a file without the LDIF extension (corresponding
to children directory)
-                                File childrenDirectoryFile = new File( stripExtension( ldifFile.getAbsolutePath()
) );
-
-                                // If the directory exists, recursively read it
-                                if ( childrenDirectoryFile.exists() )
+                                // Getting the entry
+                                Entry entry = ldifEntry.getEntry();
+    
+                                if ( entry != null )
                                 {
-                                    readDirectory( childrenDirectoryFile, entryDn, tree );
+                                    // Refactoring the DN to set the "FULL" DN of the entry
+                                    entry.setDn( entryDn );
+    
+                                    // Creating the new entry node
+                                    tree.add( entryDn, entry );
+    
+                                    // Creating a file without the LDIF extension (corresponding
to children directory)
+                                    File childrenDirectoryFile = new File( stripExtension(
ldifFile.getAbsolutePath() ) );
+    
+                                    // If the directory exists, recursively read it
+                                    if ( childrenDirectoryFile.exists() )
+                                    {
+                                        readDirectory( childrenDirectoryFile, entryDn, tree
);
+                                    }
                                 }
                             }
                         }
@@ -284,20 +288,10 @@ public class ExpandedLdifUtils
             }
 
             // Writing the LDIF file to the disk
-            FileWriter fw = null;
-            try
+            try ( FileWriter fw = new FileWriter( new File( directory, getLdifFilename( entry.getDn()
) ) ) )
             {
-                fw = new FileWriter( new File( directory, getLdifFilename( entry.getDn()
) ) );
                 fw.write( new LdifEntry( entry ).toString() );
             }
-            finally
-            {
-                // Closing the file write in any case
-                if ( fw != null )
-                {
-                    fw.close();
-                }
-            }
 
             // Checking if the entry has children
             if ( node.hasChildren() )

Modified: directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPlugin.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPlugin.java?rev=1805834&r1=1805833&r2=1805834&view=diff
==============================================================================
--- directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPlugin.java
(original)
+++ directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPlugin.java
Tue Aug 22 22:09:36 2017
@@ -78,7 +78,7 @@ public class OpenLdapConfigurationPlugin
             schemaManager.loadWithDeps( OpenLdapSchemaLoader.OPENLDAPCONFIG_SCHEMA_NAME );
 
             // Checking if no error occurred when loading the schemas
-            if ( schemaManager.getErrors().size() != 0 )
+            if ( !schemaManager.getErrors().isEmpty() )
             {
                 schemaManager = null;
                 throw new Exception( "Could not load the OpenLDAP schema correctly." );
@@ -89,24 +89,6 @@ public class OpenLdapConfigurationPlugin
     }
 
 
-    /**
-     * {@inheritDoc}
-     */
-    public void start( BundleContext context ) throws Exception
-    {
-        super.start( context );
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public void stop( BundleContext context ) throws Exception
-    {
-        super.stop( context );
-    }
-
-
     /**
      * Returns the shared instance.
      *

Modified: directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPluginUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPluginUtils.java?rev=1805834&r1=1805833&r2=1805834&view=diff
==============================================================================
--- directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPluginUtils.java
(original)
+++ directory/studio/branches/studio-value/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/OpenLdapConfigurationPluginUtils.java
Tue Aug 22 22:09:36 2017
@@ -31,6 +31,12 @@ import org.apache.directory.api.util.Str
  */
 public class OpenLdapConfigurationPluginUtils 
 {
+    private OpenLdapConfigurationPluginUtils()
+    {
+        // Nothing to do
+    }
+    
+    
     /**
      * Strips the ordering prefix if the given string contains one.
      *
@@ -297,7 +303,7 @@ public class OpenLdapConfigurationPlugin
      */
     public static String getFirstValueString( List<String> values )
     {
-        if ( ( values != null ) && ( values.size() > 0 ) )
+        if ( ( values != null ) && !values.isEmpty() )
         {
             return values.get( 0 );
         }
@@ -314,7 +320,7 @@ public class OpenLdapConfigurationPlugin
      */
     public static String getFirstValueDn( List<Dn> values )
     {
-        if ( ( values != null ) && ( values.size() > 0 ) )
+        if ( ( values != null ) && !values.isEmpty() )
         {
             return values.get( 0 ).toString();
         }



Mime
View raw message