Hi Susinda,

Please use the existing FileUtils utility class in Dev Studio instead of
introducing a new class. All these methods are available in the existing
FileUtils class. So this is a redundant classes.

Thanks and Regards,
Harshana

---------- Forwarded message ----------
From: <[email protected]>
Date: Tue, Nov 26, 2013 at 5:42 PM
Subject: [Commits] [tools-branch] svn commit r191830 -
branches/tools/eclipse/developer-studio/3.3.0/common/org.wso2.developerstudio.eclipse.utils/src/org/wso2/developerstudio/eclipse/utils/file
To: [email protected]


Author: [email protected]
Date: Tue Nov 26 17:42:39 2013
New Revision: 191830
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=191830

Log:
IFile relted utility methods added

Modified:

 
branches/tools/eclipse/developer-studio/3.3.0/common/org.wso2.developerstudio.eclipse.utils/src/org/wso2/developerstudio/eclipse/utils/file/FileUtils.java

Modified:
branches/tools/eclipse/developer-studio/3.3.0/common/org.wso2.developerstudio.eclipse.utils/src/org/wso2/developerstudio/eclipse/utils/file/FileUtils.java
URL:
http://wso2.org/svn/browse/wso2/branches/tools/eclipse/developer-studio/3.3.0/common/org.wso2.developerstudio.eclipse.utils/src/org/wso2/developerstudio/eclipse/utils/file/FileUtils.java?rev=191830&r1=191829&r2=191830&view=diff
==============================================================================
---
branches/tools/eclipse/developer-studio/3.3.0/common/org.wso2.developerstudio.eclipse.utils/src/org/wso2/developerstudio/eclipse/utils/file/FileUtils.java
 (original)
+++
branches/tools/eclipse/developer-studio/3.3.0/common/org.wso2.developerstudio.eclipse.utils/src/org/wso2/developerstudio/eclipse/utils/file/FileUtils.java
 Tue Nov 26 17:42:39 2013
@@ -48,13 +48,20 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;

 import org.apache.commons.io.FilenameUtils;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
+import org.eclipse.ui.IEditorInput;
 import org.wso2.developerstudio.eclipse.utils.data.ITemporaryFileTag;
 import org.wso2.developerstudio.eclipse.utils.internal.model.TempFileTag;

@@ -62,7 +69,11 @@

        private static Map<String,ITemporaryFileTag> temporaryTags;

-
+       /**
+        * Name of the directory which holds temporary files.
+        */
+       public static final String TEMPORARY_RESOURCES_DIRECTORY =
".org.wso2.developerstudio.eclipse.esb";
+
        public FileUtils(){
                super();
        }
@@ -781,4 +792,88 @@
             }
         }
     }
+
+       /**
+        * Utility method for obtaining the IFile from a given absolute path
+        * given extension.
+        *
+        * @param file Absolute file
+        *
+        * @return IFile
+        *
+        */
+       public static IFile getIFile(File file){
+       IFile ifile  = ResourcesPlugin
+                       .getWorkspace()
+                       .getRoot()
+
.getFileForLocation(Path.fromOSString(file.getAbsolutePath()));
+       return ifile;
+       }
+
+       /**
+        * Utility method for obtaining a reference to a temporary file
with the
+        * given extension.
+        *
+        * @param extension
+        *            extension of the temporary file.
+        * @return {@link IFile} instance corresponding to the spefied
temporary
+        *         file.
+        * @throws Exception
+        *             if a temporary file cannot be created.
+        */
+       public static IFile getTemporaryFile(String extension) throws
Exception {
+               String fileName = String.format("%s.%s",
UUID.randomUUID().toString(),
+                               extension);
+               IFile tempFile = getTemporaryDirectory().getFile(fileName);
+               if (!tempFile.exists()) {
+                       tempFile.create(new ByteArrayInputStream(new
byte[0]), true, null);
+               }
+
+               return tempFile;
+       }
+
+       /**
+        * Utility method for obtaining a reference to the temporary files
+        * directory.
+        *
+        * @return reference to the temporary files directory inside the
current
+        *         project.
+        * @throws Exception
+        *             if an error occurs while creating the temporary
resources
+        *             directory.
+        */
+       public static IFolder getTemporaryDirectory() throws Exception {
+
+                       IProject tempProject =
ResourcesPlugin.getWorkspace().getRoot().getProject(".tmp");
+
+                       if (!tempProject.exists()){
+                               tempProject.create(new
NullProgressMonitor());
+                       }
+
+                       if (!tempProject.isOpen()){
+                               tempProject.open(new NullProgressMonitor());
+                       }
+
+                       if (!tempProject.isHidden()) {
+                               tempProject.setHidden(true);
+                       }
+
+                       IFolder folder =
tempProject.getFolder(TEMPORARY_RESOURCES_DIRECTORY);
+
+                       if (!folder.exists()) {
+                               folder.create(true, true, new
NullProgressMonitor());
+                       }
+
+                       return folder;
+
+       }
+
+       public static String removeExtension(String name) {
+               String nameWithoutExtension = name;
+               if (name.lastIndexOf(".") > 0) {
+                       nameWithoutExtension = name.substring(0,
name.lastIndexOf("."));
+               }
+               return nameWithoutExtension;
+       }
+
 }
_______________________________________________
Commits mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/commits



-- 

Harshana Martin
Associate Technical Lead
WSO2 Inc. : http://wso2.com

Mobile: +94 775 998 115
Profile: https://www.google.com/profiles/harshana05
Blog: http://harshana05.blogspot.com
Twitter: http://twitter.com/harshana05
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to