Commit 0cdfe6b5 authored by stancakapost's avatar stancakapost
Browse files

minor changes and refactoring

parent 1d715ddc
Loading
Loading
Loading
Loading
+31 −23
Original line number Original line Diff line number Diff line
@@ -90,6 +90,7 @@ public class TestMacroProcessor {
		}
		}
	}
	}


	@SuppressWarnings("resource")
  public static void copyFile(File in, File out) throws IOException {
  public static void copyFile(File in, File out) throws IOException {
		FileChannel inChannel = new FileInputStream(in).getChannel();
		FileChannel inChannel = new FileInputStream(in).getChannel();
		FileChannel outChannel = new FileOutputStream(out).getChannel();
		FileChannel outChannel = new FileOutputStream(out).getChannel();
@@ -98,12 +99,19 @@ public class TestMacroProcessor {
		} catch (IOException e) {
		} catch (IOException e) {
			throw e;
			throw e;
		} finally {
		} finally {
			if (inChannel != null)
			if (inChannel != null) {
			  try {
			    inChannel.close();
			    inChannel.close();
			if (outChannel != null)
			  } catch (IOException e) {
			    // ignore close error
			  }
			}
			if (outChannel != null) {
			  // throws error further since target file
				outChannel.close();
				outChannel.close();
			}
			}
		}
		}
	}


	/**
	/**
	 * Expecting //# TC or //# TC2(param1, param2)
	 * Expecting //# TC or //# TC2(param1, param2)
@@ -169,25 +177,15 @@ public class TestMacroProcessor {
		File[] listXSDFiles = null;
		File[] listXSDFiles = null;
		File parentFile = inputFile.getParentFile();
		File parentFile = inputFile.getParentFile();
		File testData = new File(parentFile, "test_data");
		File testData = new File(parentFile, "test_data");
		boolean fromTestData = false;
		// First try to load XSD files from "test_data" folder
		// First try to load XSD files from "test_data" subfolder
		boolean fromTestData = true;
		if (testData.exists() && testData.isDirectory()) {
		if (testData.exists() && testData.isDirectory()) {
			listXSDFiles = testData.listFiles(new FilenameFilter() {
			listXSDFiles = listXSDFiles(testData);
				public boolean accept(File dir, String name) {
					return name.toLowerCase().endsWith(".xsd");
				}
				
			});			
		}
		}
		if (listXSDFiles == null || listXSDFiles.length == 0) {
		if (listXSDFiles == null || listXSDFiles.length == 0) {
			// No XSD files in "test_data" subfolder. Fallback to the main folder
			// No XSD files in "test_data" folder. Fall-back to the main folder
			listXSDFiles = parentFile.listFiles(new FilenameFilter() {
      listXSDFiles = listXSDFiles(parentFile);      
				public boolean accept(File dir, String name) {
      fromTestData = false;
					return name.toLowerCase().endsWith(".xsd");
				}
			});
		} else {
			fromTestData = true;
		}
		}


		boolean firstFile = true;
		boolean firstFile = true;
@@ -200,7 +198,8 @@ public class TestMacroProcessor {
			if (fromTestData) {
			if (fromTestData) {
				xsdFileList.append("test_data").append('/');
				xsdFileList.append("test_data").append('/');
			}
			}
			xsdFileList.append(xsdFile.getName()).append("\"");
			xsdFileList.append(xsdFile.getName());
			xsdFileList.append("\"");
		}
		}
		xsdFileList.append(" }");
		xsdFileList.append(" }");
		macroString = macroString.replace("${xsdFileList}", xsdFileList);
		macroString = macroString.replace("${xsdFileList}", xsdFileList);
@@ -213,6 +212,15 @@ public class TestMacroProcessor {
		}
		}
	}
	}


  private File[] listXSDFiles(File parentFolder) {
    File[] listXSDFiles = parentFolder.listFiles(new FilenameFilter() {
    	public boolean accept(File dir, String name) {
    		return name.toLowerCase().endsWith(".xsd");
    	}
    });
    return listXSDFiles;
  }

	private File computeTargetFileName(File inputFile, File inputPath, File outputPath) throws IOException, IOException {
	private File computeTargetFileName(File inputFile, File inputPath, File outputPath) throws IOException, IOException {
		String canonicalInputFile = inputFile.getCanonicalPath();
		String canonicalInputFile = inputFile.getCanonicalPath();
		String canonicalInputPath = inputPath.getCanonicalPath();
		String canonicalInputPath = inputPath.getCanonicalPath();