Author: vyemialyanchyk
Date: 2009-06-05 08:33:49 -0400 (Fri, 05 Jun 2009)
New Revision: 15729
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/project/src/
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/project/src/hibernate.cfg.xml
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/project/src/mapping/
Removed:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/project/hibernate.cfg.xml
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/project/mapping/
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/ConsoleConfigurationTest.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/Customization.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HibernateAllMappingTests.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/TestSet.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/ConfigurableTestProject.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/TestProject.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/utils/FilesTransfer.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4366 - code rafactoring
Deleted:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/project/hibernate.cfg.xml
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/project/hibernate.cfg.xml 2009-06-05
11:59:42 UTC (rev 15728)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/project/hibernate.cfg.xml 2009-06-05
12:33:49 UTC (rev 15729)
@@ -1,9 +0,0 @@
-<!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
-
-<hibernate-configuration>
- <session-factory>
-
- </session-factory>
-</hibernate-configuration>
\ No newline at end of file
Copied:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/project/src/hibernate.cfg.xml
(from rev 15019,
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/project/hibernate.cfg.xml)
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/project/src/hibernate.cfg.xml
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/project/src/hibernate.cfg.xml 2009-06-05
12:33:49 UTC (rev 15729)
@@ -0,0 +1,9 @@
+<!DOCTYPE hibernate-configuration PUBLIC
+ "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+
+<hibernate-configuration>
+ <session-factory>
+
+ </session-factory>
+</hibernate-configuration>
\ No newline at end of file
Copied:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/project/src/mapping
(from rev 15019,
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/project/mapping)
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/ConsoleConfigurationTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/ConsoleConfigurationTest.java 2009-06-05
11:59:42 UTC (rev 15728)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/ConsoleConfigurationTest.java 2009-06-05
12:33:49 UTC (rev 15729)
@@ -20,6 +20,8 @@
public class ConsoleConfigurationTest extends TestCase {
+ public static final String HIBERNATE_CFG_XML_PATH =
"/res/project/src/hibernate.cfg.xml".replaceAll("//", File.separator);
//$NON-NLS-1$ //$NON-NLS-2$
+
private ConsoleConfiguration consoleCfg;
public ConsoleConfigurationTest(String name) {
@@ -61,10 +63,10 @@
File xmlConfig = null;
Bundle bundle = HibernateConsoleTestPlugin.getDefault().getBundle();
try {
- URL url =
FileLocator.resolve(bundle.getEntry("/res/project/hibernate.cfg.xml"));
//$NON-NLS-1$
+ URL url = FileLocator.resolve(bundle.getEntry(HIBERNATE_CFG_XML_PATH));
xmlConfig = new File(url.getFile());
} catch (IOException e) {
- fail("Cannot find /res/project/hibernate.cfg.xml file"); //$NON-NLS-1$
+ fail("Cannot find file: " + HIBERNATE_CFG_XML_PATH); //$NON-NLS-1$
}
return xmlConfig;
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/Customization.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/Customization.java 2009-06-05
11:59:42 UTC (rev 15728)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/Customization.java 2009-06-05
12:33:49 UTC (rev 15729)
@@ -34,11 +34,6 @@
public static final boolean STOP_AFTER_MISSING_PACK = false;
/**
- * Delay in milliseconds after each package
- */
- public static final int EACTH_PACK_TEST_DELAY = 0;
-
- /**
* Use time profiler
*/
public static final boolean USE_CONSOLE_OUTPUT = true;
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HibernateAllMappingTests.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HibernateAllMappingTests.java 2009-06-05
11:59:42 UTC (rev 15728)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/HibernateAllMappingTests.java 2009-06-05
12:33:49 UTC (rev 15729)
@@ -11,6 +11,7 @@
package org.hibernate.eclipse.console.test.mappingproject;
import java.io.File;
+import java.io.IOException;
import java.util.regex.Pattern;
import junit.framework.Test;
@@ -18,14 +19,12 @@
import junit.framework.TestResult;
import junit.framework.TestSuite;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
import org.eclipse.jdt.ui.IPackagesViewPart;
import org.eclipse.jdt.ui.JavaUI;
@@ -53,6 +52,8 @@
protected TestResult result = null;
+ protected int executions = 0;
+
public HibernateAllMappingTests(String name) {
super(name);
}
@@ -85,7 +86,7 @@
ConsoleConfigUtils.createConsoleConfig(consoleConfigName,
cfgFilePath, testProject.getIProject().getName());
ProjectUtils.toggleHibernateOnProject(testProject.getIProject(), true,
consoleConfigName);
- testProject.getIProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
+ testProject.fullBuild();
}
/* (non-Javadoc)
@@ -107,9 +108,13 @@
super.tearDown();
}
- public void testEachPackWithTestSet() throws JavaModelException {
- long start_time = System.currentTimeMillis();
- int pack_count = 0;
+ /**
+ * Inspect all it's packages of the current testProject and
+ * execute all tests from TestSet, considering one test package as active.
+ * @throws CoreException
+ */
+ public void allTestsRunForProject() throws CoreException {
+ testProject.fullBuild();
IPackageFragmentRoot[] roots =
testProject.getIJavaProject().getAllPackageFragmentRoots();
for (int i = 0; i < roots.length; i++) {
if (roots[i].getClass() != PackageFragmentRoot.class) {
@@ -149,7 +154,7 @@
}
closeAllEditors();
//==============================
- pack_count++;
+ executions++;
if (Customization.USE_CONSOLE_OUTPUT) {
System.out.print(result.errorCount() - prev_errCount +
ConsoleTestMessages.HibernateAllMappingTests_errors + " \t"); //$NON-NLS-1$
System.out.print(result.failureCount() - prev_failCount +
ConsoleTestMessages.HibernateAllMappingTests_fails + "\t"); //$NON-NLS-1$
@@ -168,12 +173,32 @@
prev_errCount = result.errorCount();
}
}
+ }
+
+ public void testEachPackWithTestSet() throws CoreException, IOException {
+ long start_time = System.currentTimeMillis();
+ // 1) ---
+ // here we use one BIG project configuration for testing - time consuming thing
+ //boolean useAllRes = testProject.useAllSources();
+ //assertTrue(useAllRes);
+ // 1) ---
+ // 2) +++
+ // here we use many SMALL projects configurations for testing.
+ // this case is essential better for run time.
+ boolean createListRes = testProject.createTestFoldersList();
+ assertTrue(createListRes);
+ // 2) +++
+ testProject.restartTestFolders();
+ executions = 0;
+ while (testProject.setupNextTestFolder()) {
+ allTestsRunForProject();
+ }
if (Customization.USE_CONSOLE_OUTPUT) {
- System.out.println(
"====================================================="); //$NON-NLS-1$
- System.out.print( result.errorCount() +
ConsoleTestMessages.HibernateAllMappingTests_errors + " \t"); //$NON-NLS-1$
- System.out.print( result.failureCount() +
ConsoleTestMessages.HibernateAllMappingTests_fails + "\t"); //$NON-NLS-1$
- System.out.print(( System.currentTimeMillis() - start_time ) / 1000 +
ConsoleTestMessages.HibernateAllMappingTests_seconds + "\t" ); //$NON-NLS-1$
- System.out.println( pack_count +
ConsoleTestMessages.HibernateAllMappingTests_packages_tested );
+ System.out.println("=====================================================");
//$NON-NLS-1$
+ System.out.print(result.errorCount() +
ConsoleTestMessages.HibernateAllMappingTests_errors + " \t"); //$NON-NLS-1$
+ System.out.print(result.failureCount() +
ConsoleTestMessages.HibernateAllMappingTests_fails + "\t"); //$NON-NLS-1$
+ System.out.print((System.currentTimeMillis() - start_time) / 1000 +
ConsoleTestMessages.HibernateAllMappingTests_seconds + "\t" ); //$NON-NLS-1$
+ System.out.println(executions +
ConsoleTestMessages.HibernateAllMappingTests_packages_tested );
}
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/TestSet.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/TestSet.java 2009-06-05
11:59:42 UTC (rev 15728)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/TestSet.java 2009-06-05
12:33:49 UTC (rev 15729)
@@ -23,7 +23,10 @@
public class TestSet {
/**
- * use only addTestSuit to prevent errors!!!
+ * Creates test suite for configurable project
+ * @param consoleConfigName
+ * @param testPackage
+ * @param testProject
* @return
*/
public static TestSuite createTestSuite(String consoleConfigName,
@@ -33,6 +36,7 @@
test1.setConsoleConfigName(consoleConfigName);
test1.setTestPackage(testPackage);
test1.setTestProject(testProject);
+ /**/
OpenSourceFileTest test2 = new OpenSourceFileTest("testOpenSourceFileTest");
//$NON-NLS-1$
test2.setConsoleConfigName(consoleConfigName);
test2.setTestPackage(testPackage);
@@ -42,11 +46,14 @@
OpenMappingDiagramTest test4 = new
OpenMappingDiagramTest("testOpenMappingDiagram"); //$NON-NLS-1$
test4.setConsoleConfigName(consoleConfigName);
test4.setTestPackage(testPackage);
+ /**/
//
suite.addTest(test1);
+ /**/
suite.addTest(test2);
suite.addTest(test3);
suite.addTest(test4);
+ /**/
return suite;
}
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/ConfigurableTestProject.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/ConfigurableTestProject.java 2009-06-05
11:59:42 UTC (rev 15728)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/ConfigurableTestProject.java 2009-06-05
12:33:49 UTC (rev 15729)
@@ -13,9 +13,11 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
@@ -37,33 +39,29 @@
*/
public class ConfigurableTestProject extends TestProject {
- public static final String RESOURCE_PATH = "res/project/"; //$NON-NLS-1$
+ public static final String RESOURCE_SRC_PATH =
"res/project/src/".replaceAll("//", File.separator); //$NON-NLS-1$
//$NON-NLS-2$
+ public static final String RESOURCE_LIB_PATH =
"res/project/lib/".replaceAll("//", File.separator); //$NON-NLS-1$
//$NON-NLS-2$
+
+ protected ArrayList<String> foldersList = new ArrayList<String>();
+ protected int activePackage = -1;
+
public ConfigurableTestProject(String projectName) {
super(projectName);
}
protected void buildProject() throws JavaModelException, CoreException, IOException {
super.buildProject();
- IPath resourcePath = new Path(RESOURCE_PATH);
- File resourceFolder = resourcePath.toFile();
- URL entry =
HibernateConsoleTestPlugin.getDefault().getBundle().getEntry(RESOURCE_PATH);
- URL resProject = FileLocator.resolve(entry);
- String tplPrjLcStr= FileLocator.resolve(resProject).getFile();
- resourceFolder = new File(tplPrjLcStr);
- if (!resourceFolder.exists()) {
- String out = NLS.bind(ConsoleTestMessages.MappingTestProject_folder_not_found,
- RESOURCE_PATH);
- throw new RuntimeException(out);
- }
+ //final File srcFolder = getFolder(RESOURCE_SRC_PATH);
long startCopyFiles = System.currentTimeMillis();
- IPackageFragmentRoot sourceFolder = createSourceFolder();
- FilesTransfer.copyFolder(resourceFolder, (IFolder) sourceFolder.getResource());
+ IPackageFragmentRoot sourcePackageFragment = createSourceFolder();
+ //FilesTransfer.copyFolder(srcFolder, (IFolder)sourcePackageFragment.getResource());
long startCopyLibs = System.currentTimeMillis();
- List<IPath> libs = copyLibs(resourceFolder);
+ final File libFolder = getFolder(RESOURCE_LIB_PATH);
+ List<IPath> libs = copyLibs(libFolder);
long startBuild = System.currentTimeMillis();
- generateClassPath(libs, sourceFolder);
- project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
+ generateClassPath(libs, sourcePackageFragment);
+ fullBuild();
long stopBuild = System.currentTimeMillis();
if (Customization.USE_CONSOLE_OUTPUT){
System.out.println("=====================================================");
//$NON-NLS-1$
@@ -72,4 +70,86 @@
System.out.println("build: " + ( ( stopBuild - startBuild ) / 1000 ));
//$NON-NLS-1$
}
}
+
+ public void restartTestFolders() {
+ activePackage = -1;
+ }
+
+ public boolean setupNextTestFolder() throws IOException, CoreException {
+ activePackage++;
+ if (activePackage >= foldersList.size()) {
+ return false;
+ }
+ final String pack = foldersList.get(activePackage);
+ final File srcFolder = getFolder(RESOURCE_SRC_PATH + pack);
+ FilesTransfer.delete(new File(project.getLocation().append(SRC_FOLDER).toOSString()));
+ IPackageFragmentRoot sourcePackageFragment = createFolder(SRC_FOLDER + File.separator +
pack);
+ FilesTransfer.copyFolder(srcFolder, (IFolder)sourcePackageFragment.getResource());
+ return true;
+ }
+
+ protected File getFolder(String path) throws IOException {
+ URL entry = HibernateConsoleTestPlugin.getDefault().getBundle().getEntry(path);
+ URL resProject = FileLocator.resolve(entry);
+ String resolvePath = FileLocator.resolve(resProject).getFile();
+ File folder = new File(resolvePath);
+ if (!folder.exists()) {
+ String out = NLS.bind(ConsoleTestMessages.MappingTestProject_folder_not_found, path);
+ throw new RuntimeException(out);
+ }
+ return folder;
+ }
+
+ public boolean createTestFoldersList() {
+ activePackage = -1;
+ foldersList = new ArrayList<String>();
+ File srcFolder = null;
+ try {
+ srcFolder = getFolder(RESOURCE_SRC_PATH);
+ } catch (IOException e) {
+ // ignore
+ }
+ if (srcFolder == null) {
+ return false;
+ }
+ FilesTransfer.collectFoldersWithFiles(srcFolder, FilesTransfer.filterFilesJava,
+ FilesTransfer.filterFolders, foldersList);
+ IPath base = Path.fromOSString(srcFolder.getPath());
+ for (int i = 0; i < foldersList.size(); i++) {
+ String str = foldersList.get(i);
+ IPath path = Path.fromOSString(str);
+ path = path.makeRelativeTo(base);
+ foldersList.set(i, path.toOSString());
+ }
+ return true;
+ }
+
+ public boolean useAllSources() {
+ activePackage = -1;
+ foldersList = new ArrayList<String>();
+ File srcFolder = null;
+ try {
+ srcFolder = getFolder(RESOURCE_SRC_PATH);
+ } catch (IOException e) {
+ // ignore
+ }
+ IPackageFragmentRoot sourcePackageFragment = null;
+ try {
+ sourcePackageFragment = createSourceFolder();
+ } catch (CoreException e) {
+ // ignore
+ }
+ if (srcFolder != null && sourcePackageFragment != null) {
+ FilesTransfer.copyFolder(srcFolder, (IFolder)sourcePackageFragment.getResource());
+ foldersList.add(""); //$NON-NLS-1$
+ return true;
+ }
+ return false;
+ }
+
+ public void fullBuild() throws CoreException {
+ IPackageFragmentRoot sourcePackageFragment = createSourceFolder();
+ sourcePackageFragment.getResource().refreshLocal(IResource.DEPTH_INFINITE, null);
+ project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
+ }
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/TestProject.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/TestProject.java 2009-06-05
11:59:42 UTC (rev 15728)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/TestProject.java 2009-06-05
12:33:49 UTC (rev 15729)
@@ -123,12 +123,16 @@
}
public IPackageFragmentRoot createFolder(String strFolder) throws CoreException {
+ IPath path = Path.fromOSString(strFolder);
+ for (int i = 0; i < path.segmentCount(); i++) {
+ IFolder folder = project.getFolder(path.uptoSegment(i + 1).toOSString());
+ if (!folder.exists()) {
+ folder.create(true, true, null);
+ }
+ }
IFolder folder = project.getFolder(strFolder);
if (!folder.exists()) {
folder.create(true, true, null);
- IPackageFragmentRoot root = javaProject
- .getPackageFragmentRoot(folder);
- return root;
}
return javaProject.getPackageFragmentRoot(folder);
}
@@ -138,7 +142,7 @@
}
public List<IPath> copyLibs(File res) throws CoreException {
- return copyLibs2(res.getAbsolutePath() + File.separator + LIB_FOLDER);
+ return copyLibs2(res.getAbsolutePath());
}
public List<IPath> copyLibs2(String absolutePath) throws CoreException {
@@ -155,7 +159,7 @@
throw new RuntimeException(out);
}
List<IPath> libs = new ArrayList<IPath>();
- FilesTransfer.copyFolder(libFolder, dst, FilesTransfer.filterJars,
+ FilesTransfer.copyFolder(libFolder, dst, FilesTransfer.filterFilesJar,
FilesTransfer.filterFolders, libs);
return libs;
}
@@ -167,7 +171,9 @@
for (IPath lib_path : libs) {
entries.add(JavaCore.newLibraryEntry(lib_path, null, null));
}
- entries.add(JavaCore.newSourceEntry(sourceFolder.getPath()));
+ if (sourceFolder != null) {
+ entries.add(JavaCore.newSourceEntry(sourceFolder.getPath()));
+ }
entries.add(JavaCore.newContainerEntry(JRE_CONTAINER));
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[0]), null);
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/utils/FilesTransfer.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/utils/FilesTransfer.java 2009-06-05
11:59:42 UTC (rev 15728)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/utils/FilesTransfer.java 2009-06-05
12:33:49 UTC (rev 15729)
@@ -24,27 +24,35 @@
private FilesTransfer() {}
public static final FileFilter filterFiles = new FileFilter() {
- public boolean accept(File pathname) {
- return !pathname.isDirectory();
+ public boolean accept(File f) {
+ return f.exists() && f.isFile() && !f.isHidden();
}
};
public static final FileFilter filterFolders = new FileFilter() {
- public boolean accept(File pathname) {
- // exclude hidden files/folders
- if (pathname.isHidden()) {
- return false;
- }
- return pathname.isDirectory();
+ public boolean accept(File f) {
+ return f.exists() && f.isDirectory() && !f.isHidden();
}
};
- public static final FileFilter filterJars = new FileFilter() {
- public boolean accept(File pathname) {
- return pathname.isFile() && pathname.getName().endsWith(".jar");
//$NON-NLS-1$
+ public static final FileFilter filterFilesJar = new FileFilter() {
+ public boolean accept(File f) {
+ return f.exists() && f.isFile() && !f.isHidden() &&
f.getName().toLowerCase().endsWith(".jar"); //$NON-NLS-1$
}
};
+ public static final FileFilter filterFilesJava = new FileFilter() {
+ public boolean accept(File f) {
+ return f.exists() && f.isFile() && !f.isHidden() &&
f.getName().toLowerCase().endsWith(".java"); //$NON-NLS-1$
+ }
+ };
+
+ public static final FileFilter filterFilesXml = new FileFilter() {
+ public boolean accept(File f) {
+ return f.exists() && f.isFile() && !f.isHidden() &&
f.getName().toLowerCase().endsWith(".xml"); //$NON-NLS-1$
+ }
+ };
+
/**
* Copy whole folder content from source folder to destination folder.
* @param src - source folder
@@ -67,9 +75,6 @@
File[] files = src.listFiles(filterFiles);
for (int i = 0; i < files.length; i++) {
File file = files[i];
- if (!file.exists()) {
- continue;
- }
IFile iFile = dst.getFile(file.getName());
FileInputStream fis = null;
BufferedInputStream bis = null;
@@ -102,21 +107,38 @@
}
File[] dirs = src.listFiles(filterFolders);
for (int i = 0; i < dirs.length; i++) {
- File dir = dirs[i];
- if (!dir.exists()) {
- continue;
- }
- IFolder iFolder = dst.getFolder(dir.getName());
+ File srcDir = dirs[i];
+ IFolder dstDir = dst.getFolder(srcDir.getName());
try {
- if (!iFolder.exists()) {
- iFolder.create(true, true, null);
+ if (!dstDir.exists()) {
+ dstDir.create(true, true, null);
}
- copyFolder(dir, iFolder, filterFiles, filterFolders, filesList);
+ copyFolder(srcDir, dstDir, filterFiles, filterFolders, filesList);
} catch (CoreException e) {
e.printStackTrace();
}
}
}
+
+ /**
+ * Collect all folders starting from src folder, which contains at least one file
+ * accepted by filterFiles.
+ * @param src
+ * @param filterFiles
+ * @param filterFolders
+ * @param foldersList
+ */
+ public static void collectFoldersWithFiles(File src, FileFilter filterFiles,
+ FileFilter filterFolders, List<String> foldersList) {
+ File[] files = src.listFiles(filterFiles);
+ if (files.length > 0) {
+ foldersList.add(src.getPath());
+ }
+ File[] dirs = src.listFiles(filterFolders);
+ for (int i = 0; i < dirs.length; i++) {
+ collectFoldersWithFiles(dirs[i], filterFiles, filterFolders, foldersList);
+ }
+ }
/**
* Delete the whole directory
@@ -143,8 +165,10 @@
*/
public static void deleteFile(File file) {
try {
- if (!file.delete()) {
- throw new RuntimeException(getMessage(file));
+ if (file.exists()) {
+ if (!file.delete()) {
+ throw new RuntimeException(getMessage(file));
+ }
}
} catch (Throwable e) {
throw new RuntimeException(getMessage(file) ,e);