Browse Source

Fixed folder structure

Casper Thule 4 years ago
parent
commit
9f7b5a651e

+ 49 - 46
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp.tests/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/tests/CgCppBasicTest.xtend

@@ -24,6 +24,7 @@ import org.eclipse.xtext.testing.validation.ValidationTestHelper
 import org.junit.Test
 import org.junit.runner.RunWith
 import be.uantwerpen.ansymo.semanticadaptation.testframework.StaticGenerators
+import org.junit.Ignore
 
 @RunWith(XtextRunner)
 @InjectWith(SemanticAdaptationInjectorProvider)
@@ -33,6 +34,7 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 	@Inject extension ParseHelper<SemanticAdaptation>
 	@Inject extension  ValidationTestHelper
 
+	@Ignore
 	@Test def window_sa_canonical() {
 		__parseNoErrors('test_input/single_folder_spec/window/window_sa_canonical.BASE.sa', 'generated', "powerwindow");
 //		__parseNoErrorsWithValidation('test_input/single_folder_spec/window',
@@ -51,7 +53,8 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 
 		val fsa = new InMemoryFileSystemAccess()
 		val IGeneratorContext ctxt = null;
-		new CppGenerator().doGenerate(model.eResource, fsa, ctxt);
+		val cppGen = new CppGenerator();
+		cppGen.doGenerate(model.eResource, fsa, ctxt);
 
 		for (files : fsa.allFiles.entrySet) {
 			val filename2 = files.key.substring(14);
@@ -91,66 +94,66 @@ class CgCppBasicTest extends AbstractSemanticAdaptationTest {
 
 	}
 
-	def void deleteFolder(File folder) {
-		var	files = folder.listFiles();
-		if (files !== null) { // some JVMs return null for empty dirs
-			for (File f : files) {
-				if (f.isDirectory()) {
-					deleteFolder(f);
-				} else {
-					f.delete();
-				}
-			}
-		}
-		folder.delete();
-	}
-
-	def void writeToFile(File file, String content)
-	{
-		val FileWriter writer = new FileWriter(file);
-		writer.write(content);
-		writer.close;
-		System.out.println("Stored file at: " + file.absolutePath);
-	}
 
 	def __parseNoErrors(String filename, String directory, String projectName) {
-		val buildUtils = new BuildUtilities();
+		val saRootDir = new File(directory + File.separatorChar + projectName);
+		val srcGenPath = new File(saRootDir, "sources")
+		val resourcesPath = new File(saRootDir, "resources");
+		val saFrameworkPath = new File(saRootDir, "framework")
+
+		System.out.println("Rootdir: " + saRootDir.absolutePath)
+
 		val model = __parse(filename)
 		__assertNoParseErrors(model, filename)
 
-		val fsa = new InMemoryFileSystemAccess()
+		val fsa = new InMemoryFileSystemAccess();
 		val IGeneratorContext ctxt = null;
-		new CppGenerator().doGenerate(model.eResource, fsa, ctxt);
-
-		var genPath = new File(directory);
-		System.out.println(genPath.absolutePath)
-		if (genPath.exists) {
-			deleteFolder(genPath);
-		}
+		val cppGen = new CppGenerator();
+		cppGen.doGenerate(model.eResource, fsa, ctxt);
 		
-		val srcGenPath = new File(directory + File.separatorChar + "src")
-		srcGenPath.mkdirs();	
+		if (saRootDir.exists) {
+			BuildUtilities.deleteFolder(saRootDir);
+		}
+				
+		saRootDir.mkdirs();
+		srcGenPath.mkdirs();
+		resourcesPath.mkdirs();
+		saFrameworkPath.mkdirs();
 
 		for (files : fsa.allFiles.entrySet) {
-//			System.out.println("########################")
-//			System.out.println("Filename: " + files.key.substring(14))
-//			System.out.println(files.value)
-			val path = new File(srcGenPath, files.key.substring(14))
-
-			writeToFile(path, files.value.toString);
+			val fName = files.key.substring(14);
+			
+			var File fp;
+			if(fName.equals("modelDescription.xml"))
+			{
+				fp = new File(saRootDir, fName);
+			}
+			else
+			{
+				fp = new File(srcGenPath, fName);
+			}
+			
+			BuildUtilities.writeToFile(fp, files.value.toString);	
 		}
 		
-		val mainCpp = StaticGenerators.generateMainCppFile((new File(directory)).absolutePath.replace("\\","\\\\"));
-		writeToFile(new File(srcGenPath,"main.cpp"), mainCpp);
+		val mainCpp = StaticGenerators.generateMainCppFile(saRootDir.absolutePath.replace("\\","\\\\"));
+		BuildUtilities.writeToFile(new File(srcGenPath,"main.cpp"), mainCpp);
+		
+		
+		for(rf : cppGen.resourcePaths)
+		{
+			val sinkFile = new File(resourcesPath, rf.name);
+			System.out.println("Copied file to: " + sinkFile);
+			BuildUtilities.copyFile(rf, sinkFile);	
+		}			
 		
-		var saFrameworkPath = new File(directory + File.separatorChar + "framework")
-		saFrameworkPath.mkdirs();
-		buildUtils.copyNativeLibFiles(saFrameworkPath);
-		System.out.println("Stored sa framework at: " + saFrameworkPath.absolutePath);
 		
-		writeToFile(new File(genPath,"CMakeLists.txt"), StaticGenerators.generateCMakeLists(projectName, "framework"));
+		BuildUtilities.writeToFile(new File(saRootDir,"CMakeLists.txt"), StaticGenerators.generateCMakeLists(projectName, "framework"));
 		
+		(new BuildUtilities()).copyNativeLibFiles(saFrameworkPath);
+		System.out.println("Stored framework at: " + saFrameworkPath);
 		
+				
 	}
 
 	def __parseNoErrorsPrint(String filename) {

+ 29 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/BuildUtilities.java

@@ -2,8 +2,11 @@ package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation;
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.jar.JarEntry;
@@ -70,4 +73,30 @@ public class BuildUtilities {
 
 		return libFiles;
 	}
+
+	public static void writeToFile(File file, String content) throws IOException
+	{
+		FileWriter writer = new FileWriter(file);
+		writer.write(content);
+		writer.close();
+		System.out.println("Stored file: " + file);
+	}
+
+	public static void copyFile(File sourceFile, File sinkFile) throws IOException {
+	  Files.copy(sourceFile.toPath(), sinkFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
+	}
+	
+	public static void deleteFolder(File folder) {
+		File[] files = folder.listFiles();
+		if (files != null) { // some JVMs return null for empty dirs
+			for (File f : files) {
+				if (f.isDirectory()) {
+					deleteFolder(f);
+				} else {
+					f.delete();
+				}
+			}
+		}
+		folder.delete();
+	}
 }

+ 8 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.cg.cpp/src/be/uantwerpen/ansymo/semanticadaptation/cg/cpp/generation/CppGenerator.xtend

@@ -34,6 +34,7 @@ import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ParamDeclarati
 class CppGenerator extends SemanticAdaptationGenerator {
 	private var IFileSystemAccess2 fsa;
 
+	private List<File> resourcePaths = newArrayList();
 	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
 		this.fsa = fsa;
 		for (SemanticAdaptation type : resource.allContents.toIterable.filter(SemanticAdaptation)) {
@@ -42,6 +43,10 @@ class CppGenerator extends SemanticAdaptationGenerator {
 		}
 	}
 
+	def List<File> getResourcePaths(){
+		return resourcePaths;		
+	}
+
 	// TODO: Verify adaptation.name is not a C++ keyword
 	def void compile(SemanticAdaptation adaptation) {
 		for (Adaptation type : adaptation.elements.filter(Adaptation)) {
@@ -79,7 +84,9 @@ class CppGenerator extends SemanticAdaptationGenerator {
 			// TODO: Add support for multiple inner fmus
 			var ModelDescription md;
 			for (fmu : type.inner.eAllContents.toList.filter(InnerFMU)) {
-				md = new ModelDescription(fmu.name, fmu.type.name, new File(fmu.path.replace('\"', '')));
+				val fmuFile = new File(fmu.path.replace('\"', ''));
+				this.resourcePaths.add(fmuFile);
+				md = new ModelDescription(fmu.name, fmu.type.name, fmuFile);
 				fmus.add(fmu.name -> fmu.type.name);
 				val LinkedHashMap<String, MappedScalarVariable> mSV = newLinkedHashMap();
 				for (sv : md.sv.values) {