Tal Nisan has uploaded a new change for review.

Change subject: core: Remove FileUtil unneeded methods
......................................................................

core: Remove FileUtil unneeded methods

Remove the FileUtil unused methods and replace the ones used to standard
implementation with Java File class

Change-Id: Ia9aac66024e244bdbff52c3b7b86948a236ad0af
Signed-off-by: Tal Nisan <tni...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetCACertificateQuery.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InstallVdsCommand.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacadeLocator.java
M 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/FileUtil.java
M 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/CachedTar.java
M 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/hostinstall/OpenSslCAWrapper.java
M 
backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/FileUtilTest.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsManager.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/SysprepHandler.java
10 files changed, 41 insertions(+), 135 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/25/12425/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java
index 5288e81..5531997 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java
@@ -1,5 +1,6 @@
 package org.ovirt.engine.core.bll;
 
+import java.io.File;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -48,7 +49,6 @@
 import org.ovirt.engine.core.dal.VdcBllMessages;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.dal.job.ExecutionMessageDirector;
-import org.ovirt.engine.core.utils.FileUtil;
 import org.ovirt.engine.core.utils.ssh.SSHClient;
 import org.ovirt.engine.core.utils.threadpool.ThreadPoolUtil;
 import org.ovirt.engine.core.utils.transaction.TransactionMethod;
@@ -307,7 +307,7 @@
                 returnValue = returnValue && 
validateSingleHostAttachedToLocalStorage();
 
                 if (Config.<Boolean> 
GetValue(ConfigValues.UseSecureConnectionWithServers)
-                        && 
!FileUtil.fileExists(Config.resolveCertificatePath())) {
+                        && !new 
File(Config.resolveCertificatePath()).exists()) {
                     
addCanDoActionMessage(VdcBllMessages.VDS_TRY_CREATE_SECURE_CERTIFICATE_NOT_FOUND);
                     returnValue = false;
                 } else if (!getParameters().getAddPending()
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetCACertificateQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetCACertificateQuery.java
index 459fe8c..e7a93de 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetCACertificateQuery.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetCACertificateQuery.java
@@ -1,5 +1,7 @@
 package org.ovirt.engine.core.bll;
 
+import java.io.File;
+
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.queries.VdcQueryParametersBase;
 import org.ovirt.engine.core.utils.FileUtil;
@@ -13,7 +15,7 @@
     protected void executeQueryCommand() {
         getQueryReturnValue().setSucceeded(false);
         String path = Config.resolveCACertificatePath();
-        if (FileUtil.fileExists(path)) {
+        if (new File(path).exists()) {
             getQueryReturnValue().setReturnValue(FileUtil.readAllText(path));
             getQueryReturnValue().setSucceeded(true);
         }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InstallVdsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InstallVdsCommand.java
index f408602..3099232 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InstallVdsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InstallVdsCommand.java
@@ -1,5 +1,7 @@
 package org.ovirt.engine.core.bll;
 
+import java.io.File;
+
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.exception.ExceptionUtils;
 import org.ovirt.engine.core.common.AuditLogType;
@@ -12,7 +14,6 @@
 import org.ovirt.engine.core.compat.RpmVersion;
 import org.ovirt.engine.core.compat.backendcompat.Path;
 import org.ovirt.engine.core.dal.VdcBllMessages;
-import org.ovirt.engine.core.utils.FileUtil;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
 
@@ -55,7 +56,7 @@
 
     private boolean isIsoFileValid(String isoFile) {
         return StringUtils.isNotBlank(isoFile)
-                && 
FileUtil.fileExists(Path.Combine(Config.resolveOVirtISOsRepositoryPath(), 
isoFile));
+                && new 
File(Path.Combine(Config.resolveOVirtISOsRepositoryPath(), isoFile)).exists();
     }
 
     @Override
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacadeLocator.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacadeLocator.java
index 7216c22..1a02562 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacadeLocator.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacadeLocator.java
@@ -1,5 +1,6 @@
 package org.ovirt.engine.core.dal.dbbroker;
 
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.util.Properties;
@@ -8,7 +9,6 @@
 
 import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.commons.lang.math.NumberUtils;
-import org.ovirt.engine.core.utils.FileUtil;
 import org.ovirt.engine.core.utils.ResourceUtils;
 import org.ovirt.engine.core.utils.ejb.ContainerManagedResourceType;
 import org.ovirt.engine.core.utils.ejb.EjbUtils;
@@ -79,7 +79,7 @@
             String onStartConnectionTimeout = null;
             String connectionCheckInterval = null;
             Properties props = new Properties();
-            if (FileUtil.fileExists(ENGINE_CONF_FILE)) {
+            if (new File(ENGINE_CONF_FILE).exists()) {
                 // File exists, load /etc/ovirt-engine/engine.conf and set 
values in DbFacade
                 inputStream = new FileInputStream(ENGINE_CONF_FILE);
                 props.load(inputStream);
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/FileUtil.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/FileUtil.java
index 0fd4396..4b07843 100644
--- 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/FileUtil.java
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/FileUtil.java
@@ -1,66 +1,12 @@
 package org.ovirt.engine.core.utils;
 
-import java.io.Closeable;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Date;
 
 import org.ovirt.engine.core.compat.CompatException;
 
 public class FileUtil {
-    public static InputStream findFile(String name) {
-        try {
-            InputStream fis = 
FileUtil.class.getClassLoader().getResourceAsStream(name);
-            // If this is null, look on the file system
-            if (fis == null) {
-                fis = new FileInputStream(name);
-            }
-            return fis;
-        } catch (FileNotFoundException e) {
-            throw new VdcException(e);
-        }
-    }
-
-    public static void copyFile(String srcFilePath, String dstFilePath) throws 
IOException {
-        InputStream in = new FileInputStream(srcFilePath);
-        OutputStream out = new FileOutputStream(dstFilePath);
-
-        // Transfer bytes from in to out
-        byte[] buf = new byte[1024];
-        int len;
-        while ((len = in.read(buf)) > 0) {
-            out.write(buf, 0, len);
-        }
-        in.close();
-        out.close();
-    }
-
-    public static boolean fileExists(String filePath) {
-        File file = new File(filePath);
-        return file.exists();
-    }
-
-    public static void deleteFile(String filePath) {
-        File file = new File(filePath);
-        if (fileExists(filePath)) {
-            file.delete();
-        }
-    }
-
-    public static void closeQuietly(Closeable... closeables) {
-        for (Closeable c : closeables) {
-            try {
-                c.close();
-            } catch (Exception e) {
-                // Ignore
-            }
-        }
-    }
 
     public static String readAllText(final String filename) {
         FileInputStream fis = null;
@@ -82,45 +28,6 @@
                     // ignore
                 }
             }
-        }
-    }
-
-    public static Date getLastWriteTime(Object filename) {
-        try {
-            java.io.File file = new java.io.File(filename.toString());
-            return new Date(file.lastModified());
-        } catch (Exception e) {
-            throw new CompatException(e);
-        }
-    }
-
-    /**
-     * Returns the maximum timestamp of directory tree.
-     * @param file directory/file name.
-     * @return max timestamp.
-     */
-    public static long getTimestampRecursive(String file) {
-        return getTimestampRecursive(new File(file));
-    }
-
-    /**
-     * Returns the maximum timestamp of directory tree.
-     * @param file directory/file name.
-     * @return max timestamp.
-     */
-    public static long getTimestampRecursive(File file) {
-        if (file.isDirectory()) {
-            long m = 0;
-            for (String name : file.list()) {
-                m = Math.max(m, getTimestampRecursive(new File(file, name)));
-            }
-            return m;
-        }
-        else if (file.isFile()) {
-            return file.lastModified();
-        }
-        else {
-            return 0;
         }
     }
 }
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/CachedTar.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/CachedTar.java
index 2b46f3b..d4c6bdf 100644
--- 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/CachedTar.java
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/CachedTar.java
@@ -2,15 +2,13 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.OutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
-import org.ovirt.engine.core.utils.FileUtil;
 
 /**
  * Handles cache tar file based on directory.
@@ -104,12 +102,12 @@
                 )
             );
             this.nextCheckTime = System.currentTimeMillis() + 
this.refreshInterval;
-            create(FileUtil.getTimestampRecursive(this.dir));
+            create(getTimestampRecursive(this.dir));
         }
         else if (this.nextCheckTime <= System.currentTimeMillis()) {
             this.nextCheckTime = System.currentTimeMillis() + 
this.refreshInterval;
 
-            long treeTimestamp = FileUtil.getTimestampRecursive(this.dir);
+            long treeTimestamp = getTimestampRecursive(this.dir);
             if (archive.lastModified() != treeTimestamp) {
                 log.info(
                     String.format(
@@ -153,4 +151,27 @@
         ensure();
         return this.archive;
     }
+
+    /**
+     * Returns the maximum timestamp of directory tree.
+     *
+     * @param file
+     *            directory/file name.
+     * @return max timestamp.
+     */
+    private static long getTimestampRecursive(File file) {
+        if (file.isDirectory()) {
+            long m = 0;
+            for (String name : file.list()) {
+                m = Math.max(m, getTimestampRecursive(new File(file, name)));
+            }
+            return m;
+        }
+        else if (file.isFile()) {
+            return file.lastModified();
+        }
+        else {
+            return 0;
+        }
+    }
 }
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/hostinstall/OpenSslCAWrapper.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/hostinstall/OpenSslCAWrapper.java
index 2ad8f77..0913045 100644
--- 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/hostinstall/OpenSslCAWrapper.java
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/hostinstall/OpenSslCAWrapper.java
@@ -15,12 +15,11 @@
 import java.util.TimeZone;
 
 import org.apache.commons.codec.binary.Base64;
-
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
+import org.ovirt.engine.core.utils.FileUtil;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
-import org.ovirt.engine.core.utils.FileUtil;
 
 public class OpenSslCAWrapper {
 
@@ -109,7 +108,7 @@
         log.debug("Entered SignCertificateRequest");
         boolean returnValue = true;
         String signRequestBatch = Config.resolveSignScriptPath();
-        if (FileUtil.fileExists(signRequestBatch)) {
+        if (new File(signRequestBatch).exists()) {
             String organization = Config.<String> 
GetValue(ConfigValues.OrganizationName);
             Integer signatureTimeout = Config.<Integer> 
GetValue(ConfigValues.SignCertTimeoutInSeconds);
             String[] command_array =
diff --git 
a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/FileUtilTest.java
 
b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/FileUtilTest.java
index 660446e..52139a9 100644
--- 
a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/FileUtilTest.java
+++ 
b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/FileUtilTest.java
@@ -2,34 +2,10 @@
 
 import java.io.File;
 import java.io.FileWriter;
-import java.util.Date;
 
 import junit.framework.TestCase;
 
 public class FileUtilTest extends TestCase {
-
-    public void testFileExists() throws Exception {
-        File iFile = File.createTempFile("Test", ".txt");
-        assertTrue("Temp files are there", 
FileUtil.fileExists(iFile.getAbsolutePath()));
-        assertFalse("Garbage should not be there", 
FileUtil.fileExists("/foof/dkjfhsk/fsjhfkjds"));
-    }
-
-    public void testDeleteFile() throws Exception {
-        File iFile = File.createTempFile("Test", ".txt");
-        FileUtil.deleteFile(iFile.getAbsolutePath());
-        assertFalse("Deleted File should be gone", 
FileUtil.fileExists(iFile.getAbsolutePath()));
-    }
-
-    public void testGetLastWriteTime() throws Exception {
-        Date before = new Date();
-        Thread.sleep(1000);
-        File iFile = File.createTempFile("Test", ".txt");
-        Thread.sleep(1000);
-        Date after = new Date();
-        Date creation = FileUtil.getLastWriteTime(iFile.getAbsoluteFile());
-        assertTrue("Creation should be after before ", 
creation.compareTo(before) > 0);
-        assertTrue("Creation should be before after ", 
creation.compareTo(after) < 0);
-    }
 
     public void testReadAllText() throws Exception {
         File iFile = File.createTempFile("Test", ".txt");
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsManager.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsManager.java
index 79a4168..d031781 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsManager.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsManager.java
@@ -1,5 +1,6 @@
 package org.ovirt.engine.core.vdsbroker;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
@@ -33,7 +34,6 @@
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase;
-import org.ovirt.engine.core.utils.FileUtil;
 import org.ovirt.engine.core.utils.lock.EngineLock;
 import org.ovirt.engine.core.utils.lock.LockManagerFactory;
 import org.ovirt.engine.core.utils.log.Log;
@@ -146,7 +146,7 @@
         }
         // if ssl is on and no certificate file
         if (Config.<Boolean> 
GetValue(ConfigValues.UseSecureConnectionWithServers)
-                && !FileUtil.fileExists(Config.resolveCertificatePath())) {
+                && !new File(Config.resolveCertificatePath()).exists()) {
             if (_vds.getStatus() != VDSStatus.Maintenance && _vds.getStatus() 
!= VDSStatus.InstallFailed) {
                 setStatus(VDSStatus.NonResponsive, _vds);
                 UpdateDynamicData(_vds.getDynamicData());
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/SysprepHandler.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/SysprepHandler.java
index 768e617..f97c5d1 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/SysprepHandler.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/SysprepHandler.java
@@ -225,7 +225,7 @@
     private static String LoadFile(String fileName) {
         String content = "";
         fileName = ConfigUtil.resolvePath(getSysprepDir(), fileName);
-        if (FileUtil.fileExists(fileName)) {
+        if (new File(fileName).exists()) {
             try {
                 content = FileUtil.readAllText(fileName);
             } catch (RuntimeException e) {


--
To view, visit http://gerrit.ovirt.org/12425
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia9aac66024e244bdbff52c3b7b86948a236ad0af
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Tal Nisan <tni...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to