Commit bb08a240 authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ added recursive standalone mode

parent 5251722c
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -3,6 +3,9 @@ package org.etsi.mts.tdl.standalone;
import java.io.File;
import java.io.FilenameFilter;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.ArrayList;
@@ -39,6 +42,7 @@ public class Standalone {
	static String jsonExtension = "json";
	private List<MODE> modes = new ArrayList<>();
	private String path = "";
	private boolean recursive = true;

	enum MODE {
		all, 
@@ -138,6 +142,28 @@ public class Standalone {
	}
	
	private void processElements(String path, String extension, Consumer<String> operation) throws Exception {
		if (recursive) {
			processElementsRecursive(path, extension, operation);
		} else {
			processElementsFlat(path, extension, operation);
		}
	}

	private void processElementsRecursive(String path, String extension, Consumer<String> operation) throws Exception {
		System.out.println("Processing recursively: "+path);
		if (extension.contains("tdl")) {
			Files.walk(Path.of(path))
				.filter(e->e.getFileName().toString().endsWith(extension))
				.forEach(e->TDLHelper.load(e.toAbsolutePath().toString()));
			TDLHelper.link();
			TDLHelper.check();
		}
		Files.walk(Path.of(path))
				.filter(e->e.getFileName().toString().endsWith(extension))
				.forEach(e->operation.accept(e.toAbsolutePath().toString()));
	}

	private void processElementsFlat(String path, String extension, Consumer<String> operation) throws Exception {
		File target = new File(path);
		//TODO: make recursive?
		if (target.isDirectory()) {