<commit_before>/**
 * Copyright (C) 2011 SINTEF <<EMAIL>>
 *
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3, 29 June 2007;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.gnu.org/licenses/lgpl-3.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3, 29 June 2007;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.gnu.org/licenses/lgpl-3.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.thingml.graphexport.test;

import java.io.*;

import junit.framework.TestCase;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.sintef.thingml.Configuration;
import org.sintef.thingml.Thing;
import org.sintef.thingml.ThingMLModel;
import org.sintef.thingml.ThingmlPackage;
import org.sintef.thingml.resource.thingml.mopp.ThingmlResourceFactory;
import org.thingml.cgenerator.*;
import org.thingml.scalagenerator.*;
import org.thingml.javagenerator.gui.*;
import org.thingml.graphexport.*;



import java.util.AbstractMap.SimpleEntry;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import scala.io.Source$;

/**
 *
 * @author ffl
 */
public class StandaloneParserTestLoadFile extends TestCase {

    String model_path;

    public StandaloneParserTestLoadFile(String model_path) {
        this.model_path = model_path;
    }

    @Override
    public void runTest() throws IOException {




        // Register the generated package and the XMI Factory
        EPackage.Registry.INSTANCE.put(ThingmlPackage.eNS_URI, ThingmlPackage.eINSTANCE);
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("thingml", new ThingmlResourceFactory());

        // Load the model
        ResourceSet rs = new ResourceSetImpl();
        URI xmiuri = URI.createFileURI(model_path);
        Resource model = rs.createResource(xmiuri);
        model.load(null);
        //org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(rs);

        assert (model.getContents().size() > 0);

        assert (model.getContents().get(0) instanceof ThingMLModel);

        System.out.println("Model : " + model + " : ");

        File dir = new File("test_out");
        if (!dir.exists()) {
            dir.mkdir();
        }

        try {
            Map<String, String> dots = ThingMLGraphExport.allGraphviz((ThingMLModel) model.getContents().get(0));
            for (String name : dots.keySet()) {
                System.out.println(" -> Writing file " + name + ".dot");
                PrintWriter w = new PrintWriter(new FileWriter("test_out/" + new File(name + ".dot")));
                w.println(dots.get(name));
                w.close();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }

        try {
            Map<String, String> gml = ThingMLGraphExport.allGraphML((ThingMLModel) model.getContents().get(0));
            for (String name : gml.keySet()) {
                System.out.println(" -> Writing file " + name + ".graphml");
                PrintWriter w = new PrintWriter(new FileWriter("test_out/" + new File(name + ".graphml")));
                w.println(gml.get(name));
                w.close();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }

        try {
            Map<Configuration, String> ccode = CGenerator.compileAllJava((ThingMLModel) model.getContents().get(0));
            for (Configuration t : ccode.keySet()) {
                System.out.println(" -> Writing file " + t.getName() + ".pde");
                PrintWriter w = new PrintWriter(new FileWriter("test_out/" + new File(t.getName() + ".pde")));
                w.println(ccode.get(t));
                w.close();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }

        try {
            Map<Configuration, SimpleEntry<String, String>> scalacode = ScalaGenerator.compileAllJava((ThingMLModel) model.getContents().get(0), "org.thingml.generated");
            for (Configuration t : scalacode.keySet()) {
                
                String pom = Source$.MODULE$.fromInputStream(this.getClass().getClassLoader().getResourceAsStream("pomtemplates/pom.xml"),"utf-8").getLines().mkString("\n");
                pom = pom.replace("<!--CONFIGURATIONNAME-->", t.getName());
                PrintWriter pomw = new PrintWriter(new FileWriter(new File("test_out/" + t.getName() + "/pom.xml")));
                pomw.println(pom);
                pomw.close();
                
                File scaladir = new File("test_out/" + t.getName() + "/src/main/scala/org/thingml/generated/");
                scaladir.mkdirs();
                System.out.println(" -> Writing file " + t.getName() + ".scala");
                PrintWriter w = new PrintWriter(new FileWriter(new File("test_out/" + t.getName() + "/src/main/scala/org/thingml/generated/" + t.getName() + ".scala")));
                w.println(scalacode.get(t).getKey());
                w.close();
                
                
                System.out.println(" -> Writing file " + t.getName() + "Main.java");
                w = new PrintWriter(new FileWriter(new File("test_out/" + t.getName() + "/src/main/scala/org/thingml/generated/Main.scala")));
                w.println(scalacode.get(t).getValue());
                w.close();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }


        try {
            Map<Thing, SimpleEntry<String, String>> swingcodeThing = SwingGenerator.compileAllThingJava((ThingMLModel) model.getContents().get(0), "org.thingml.generated");<commit_msg>bux fix when generating maven projects<commit_after>/**
 * Copyright (C) 2011 SINTEF <<EMAIL>>
 *
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3, 29 June 2007;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.gnu.org/licenses/lgpl-3.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3, 29 June 2007;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.gnu.org/licenses/lgpl-3.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.thingml.graphexport.test;

import java.io.*;

import junit.framework.TestCase;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.sintef.thingml.Configuration;
import org.sintef.thingml.Thing;
import org.sintef.thingml.ThingMLModel;
import org.sintef.thingml.ThingmlPackage;
import org.sintef.thingml.resource.thingml.mopp.ThingmlResourceFactory;
import org.thingml.cgenerator.*;
import org.thingml.scalagenerator.*;
import org.thingml.javagenerator.gui.*;
import org.thingml.graphexport.*;



import java.util.AbstractMap.SimpleEntry;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import scala.io.Source$;

/**
 *
 * @author ffl
 */
public class StandaloneParserTestLoadFile extends TestCase {

    String model_path;

    public StandaloneParserTestLoadFile(String model_path) {
        this.model_path = model_path;
    }

    @Override
    public void runTest() throws IOException {




        // Register the generated package and the XMI Factory
        EPackage.Registry.INSTANCE.put(ThingmlPackage.eNS_URI, ThingmlPackage.eINSTANCE);
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("thingml", new ThingmlResourceFactory());

        // Load the model
        ResourceSet rs = new ResourceSetImpl();
        URI xmiuri = URI.createFileURI(model_path);
        Resource model = rs.createResource(xmiuri);
        model.load(null);
        //org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(rs);

        assert (model.getContents().size() > 0);

        assert (model.getContents().get(0) instanceof ThingMLModel);

        System.out.println("Model : " + model + " : ");

        File dir = new File("test_out");
        if (!dir.exists()) {
            dir.mkdir();
        }

        try {
            Map<String, String> dots = ThingMLGraphExport.allGraphviz((ThingMLModel) model.getContents().get(0));
            for (String name : dots.keySet()) {
                System.out.println(" -> Writing file " + name + ".dot");
                PrintWriter w = new PrintWriter(new FileWriter("test_out/" + new File(name + ".dot")));
                w.println(dots.get(name));
                w.close();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }

        try {
            Map<String, String> gml = ThingMLGraphExport.allGraphML((ThingMLModel) model.getContents().get(0));
            for (String name : gml.keySet()) {
                System.out.println(" -> Writing file " + name + ".graphml");
                PrintWriter w = new PrintWriter(new FileWriter("test_out/" + new File(name + ".graphml")));
                w.println(gml.get(name));
                w.close();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }

        try {
            Map<Configuration, String> ccode = CGenerator.compileAllJava((ThingMLModel) model.getContents().get(0));
            for (Configuration t : ccode.keySet()) {
                System.out.println(" -> Writing file " + t.getName() + ".pde");
                PrintWriter w = new PrintWriter(new FileWriter("test_out/" + new File(t.getName() + ".pde")));
                w.println(ccode.get(t));
                w.close();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }

        try {
            Map<Configuration, SimpleEntry<String, String>> scalacode = ScalaGenerator.compileAllJava((ThingMLModel) model.getContents().get(0), "org.thingml.generated");
            for (Configuration t : scalacode.keySet()) {
                File scaladir = new File("test_out/" + t.getName() + "/src/main/scala/org/thingml/generated/");
                scaladir.mkdirs();
                
                String pom = Source$.MODULE$.fromInputStream(this.getClass().getClassLoader().getResourceAsStream("pomtemplates/pom.xml"),"utf-8").getLines().mkString("\n");
                pom = pom.replace("<!--CONFIGURATIONNAME-->", t.getName());
                System.out.println(" -> Writing file pom.xml");
                PrintWriter pomw = new PrintWriter(new FileWriter(new File("test_out/" + t.getName() + "/pom.xml")));
                pomw.println(pom);
                pomw.close();
                
                System.out.println(" -> Writing file " + t.getName() + ".scala");
                PrintWriter w = new PrintWriter(new FileWriter(new File("test_out/" + t.getName() + "/src/main/scala/org/thingml/generated/" + t.getName() + ".scala")));
                w.println(scalacode.get(t).getKey());
                w.close();
                
                
                System.out.println(" -> Writing file " + t.getName() + "Main.java");
                w = new PrintWriter(new FileWriter(new File("test_out/" + t.getName() + "/src/main/scala/org/thingml/generated/Main.scala")));
                w.println(scalacode.get(t).getValue());
                w.close();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }


        try {
            Map<Thing, SimpleEntry<String, String>> swingcodeThing = SwingGenerator.compileAllThingJava((ThingMLModel) model.getContents().get(0), "org.thingml.generated");
{'fraction_non_alphanumeric': 0.12762773995660956, 'fraction_numerical': 0.004488666118051919, 'mean_word_length': 2.5114263199369584, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6821692', 'n_tokens_mistral': 3880, 'n_tokens_neox': 3736, 'n_words': 922}