Commit 8eb55e5c authored by Philip Makedonski's avatar Philip Makedonski
Browse files

* switch to outsourced resource handler

parent 60d17888
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ Require-Bundle: org.eclipse.emf.common,
 org.eclipse.emf.ecore;visibility:=reexport,
 org.eclipse.emf.ecore.xmi,
 org.etsi.mts.tdl.model,
 org.etsi.mts.tdl.common,
 org.eclipse.xtext,
 org.eclipse.epsilon.common.dt,
 org.eclipse.ocl.xtext.completeocl
+2 −1
Original line number Diff line number Diff line
@@ -4,4 +4,5 @@ output.. = target/classes/
bin.includes = META-INF/,\
               .,\
               plugin.xml,\
               epsilon/
               epsilon/,\
               ocl/
+4 −58
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ import org.eclipse.xtext.nodemodel.ICompositeNode;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.resource.XtextResource;
import org.etsi.mts.tdl.tdlPackage;
import org.etsi.mts.tdl.resources.ResourceHandler;
import org.etsi.mts.tdl.structuredobjectives.StructuredObjectivesPackage;
import org.etsi.mts.tdl.extendedconfigurations.ExtendedConfigurationsPackage;
import org.osgi.framework.Bundle;
@@ -103,7 +104,7 @@ public class Validator {
	public void validateOCL2(Resource r) {
		try {
			OCL ocl = OCL.newInstance(EPackage.Registry.INSTANCE);
			URI uri = getSourceUri("/ocl/tdl-constraints.ocl");
			URI uri = ResourceHandler.getSourceUri(this.getClass(), "org.etsi.mts.tdl.constraints", "/ocl/tdl-constraints.ocl");
			org.eclipse.emf.common.util.URI oclURI = org.eclipse.emf.common.util.URI.createURI(uri.toString());
			Resource asResource = ocl.parse(oclURI);
			ComposedEValidator newEValidator = ComposedEValidator.install(tdlPackage.eINSTANCE);
@@ -127,7 +128,7 @@ public class Validator {
		//TODO: does not quite work yet
		ComposedEValidator oclValidator = ComposedEValidator.install(tdlPackage.eINSTANCE);
		try {
			URI uri = getSourceUri("/ocl/tdl-constraints.ocl");
			URI uri = ResourceHandler.getSourceUri(this.getClass(), "org.etsi.mts.tdl.constraints", "/ocl/tdl-constraints.ocl");
			org.eclipse.emf.common.util.URI oclURI = org.eclipse.emf.common.util.URI.createURI(uri.toString());
			
			CompleteOCLEObjectValidator validator = new CompleteOCLEObjectValidator(tdlPackage.eINSTANCE,
@@ -186,7 +187,7 @@ public class Validator {

			for (String part : constraints) {
				String source = "epsilon/constraints/"+part;
				URI uri = getSourceUri(source);
				URI uri = ResourceHandler.getSourceUri(this.getClass(), "org.etsi.mts.tdl.constraints", source);
				
				EvlModule module = new EvlModule();
				module.parse(uri);
@@ -252,61 +253,6 @@ public class Validator {
		return violations;
	}

	private URI getSourceUri(String source) throws URISyntaxException {
		URI uri = new File(source).toURI();
		//FIXED: also for TO? -> should work with all now
		if (Platform.isRunning()) {
			//System.out.println("Running as plugin...");
			Bundle bundle = Platform.getBundle("org.etsi.mts.tdl.constraints");
			URL url = bundle.getEntry(source);
			uri = url.toURI();
		} else {
			//WS
			//TODO: this does not work with exported JAR
			
//			String binPath=this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
//			String projectPath = new File(binPath).getParent();
//			uri = new File(projectPath+"/"+source).toURI();
			uri = getResourceFile(source);
		}
		return uri;
	}
	
	//TODO: simplify
	public URI getResourceFile(String relativePath)
	{
	    URI uri = null;
	    URL location = this.getClass().getProtectionDomain().getCodeSource().getLocation();
	    String codeLocation = location.toString();
	    try{
	        if (codeLocation.endsWith(".jar")) {
	            //Call from jar
	        	//DONE: this does not work.. -> fixed
	        	//should get file out of jar / bundle instead
	        	//TODO: simplify and merge with above, test other cases
	        	//TODO: generalise for use in other cases, e.g. for docx and others?
	        	try {
					Enumeration<URL> resources = ClassLoader.getSystemResources(relativePath.replaceAll("epsilon/", ""));
					URL nextElement = resources.nextElement();
					uri = nextElement.toURI();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
//	            Path path = Paths.get(location.toURI()).resolve("../classes/" + relativePath.replaceAll("epsilon/", "")).normalize();
//	            file = path.toFile();
//	            System.out.println("File: "+file);
	        }else{
	            //Call from IDE
	            URL resource = this.getClass().getClassLoader().getResource(relativePath.replaceAll("epsilon/", ""));
				uri = resource.toURI();
//	            file = new File(resource.getPath());
	        }
	    }catch(URISyntaxException ex){
	        ex.printStackTrace();
	    }
	    return uri;
	}

	public void dumpViolations(List<UnsatisfiedConstraint> violations, boolean includeLocation) {
		for (UnsatisfiedConstraint constraint : violations) {
+1 −1
Original line number Diff line number Diff line
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Next
Bundle-Name: OpenAPI to TDL Translator (Next)
Bundle-SymbolicName: org.etsi.mts.tdl.openapi2tdl.next
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: European Telecommunications Standards Institute (ETSI)
+2 −1
Original line number Diff line number Diff line
@@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.core.runtime,
 org.etsi.mts.tdl.model,
 org.etsi.mts.tdl.TPLan2,
 org.eclipse.emf.mwe.utils,
 org.eclipse.ocl.xtext.essentialocl
 org.eclipse.ocl.xtext.essentialocl,
 org.etsi.mts.tdl.common
Bundle-RequiredExecutionEnvironment: JavaSE-11
Automatic-Module-Name: org.etsi.mts.tdl.tools.to.docx.poi
Bundle-ActivationPolicy: lazy
Loading