Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Maven not able to find MWE2 file referred by unit tests.
Maven not able to find MWE2 file referred by unit tests. [message #1756029] Fri, 10 March 2017 09:38 Go to next message
Mahesh B M is currently offline Mahesh B MFriend
Messages: 3
Registered: March 2017
Junior Member
I have junit tests referring a workflow of other plugin. It resolves the mwe2 when tests are run from eclipse environment but failed to do so in maven tests.

I have created a tiny project excluding the DSL plugins and keeping only the required plugins to reproduce the problem and attached to the post. Below are the details.

PrintToFile.mwe2 file in project com.mwe2maventest.problem is invoked by tests of PrintMessageTest from com.mwe2maventest.problem.test

Project structure of com.mwe2maventest.problem
com.mwe2maventest.problem
    - src
        - com (contains java classes)
        - workflow
            -PrintToFile.mwe2

manifest.mf of com.mwe2maventest.problem
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Problem
Bundle-SymbolicName: com.mwe2maventest.problem
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.emf.mwe2.runtime;bundle-version="2.9.0",
 org.eclipse.emf.mwe2.lib;bundle-version="2.9.0",
 org.eclipse.emf.mwe.core,
 org.junit
Export-Package: com.mwe2Maventest.problem.print


manifest.mf of com.mwe2maventest.problem.test
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Test
Bundle-SymbolicName: com.mwe2maventest.problem.test
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: MWE2MAVENTEST
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.emf.mwe2.runtime;bundle-version="2.9.0",
 org.eclipse.emf.mwe2.lib;bundle-version="2.9.0",
 com.mwe2maventest.problem;bundle-version="1.0.0",
 org.junit;bundle-version="4.11.0",
 org.eclipse.emf.mwe2.launch,
 org.apache.log4j;bundle-version="1.2.15",
 org.eclipse.equinox.common;bundle-version="3.8.0",
 org.eclipse.xtext.xbase;bundle-version="2.10.0",
 org.apache.commons.logging;bundle-version="1.1.1"


when maven tests are run i am getting error complaining about missing workflow "workflow.PrintToFile"
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.mwe2Maventest.problem.print.PrintMessageTest
Tests run: 3, Failures: 0, Errors: 3, Skipped: 0, Time elapsed: 1.03 sec <<< FAILURE! - in com.mwe2Maventest.problem.print.PrintMessageTest
testFileGenM1(com.mwe2Maventest.problem.print.PrintMessageTest)  Time elapsed: 0.928 sec  <<< ERROR!
java.lang.IllegalStateException: Couldn't find module workflow.PrintToFile
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:77)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:71)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:80)
        at com.mwe2Maventest.problem.print.PrintMessageTest.runner(PrintMessageTest.java:47)
        at com.mwe2Maventest.problem.print.PrintMessageTest.testFileGenM1(PrintMessageTest.java:19)

testFileGenM2(com.mwe2Maventest.problem.print.PrintMessageTest)  Time elapsed: 0.049 sec  <<< ERROR!
java.lang.IllegalStateException: Couldn't find module workflow.PrintToFile
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:77)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:71)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:80)
        at com.mwe2Maventest.problem.print.PrintMessageTest.runner(PrintMessageTest.java:47)
        at com.mwe2Maventest.problem.print.PrintMessageTest.testFileGenM2(PrintMessageTest.java:27)

testFileGenM3(com.mwe2Maventest.problem.print.PrintMessageTest)  Time elapsed: 0.03 sec  <<< ERROR!
java.lang.IllegalStateException: Couldn't find module workflow.PrintToFile
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:77)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:71)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:80)
        at com.mwe2Maventest.problem.print.PrintMessageTest.runner(PrintMessageTest.java:47)
        at com.mwe2Maventest.problem.print.PrintMessageTest.testFileGenM3(PrintMessageTest.java:35)

[Updated on: Mon, 13 March 2017 13:13]

Report message to a moderator

Re: Maven not able to find MWE2 file referred by unit tests. [message #1756092 is a reply to message #1756029] Fri, 10 March 2017 21:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14668
Registered: July 2009
Senior Member
Hi,

- do you run the test in eclipse as plugin test?
- the stuff is not buildable cause of the target platform. can you share something that is buildable?
- is the mwe2 file part of the jar that is built? if yes how is the path?
- how does the claspath look like that the test sees when called from maven?

i assume the classpath is not the same (mwe uses java.class.path, am not sure if surefire sets that correct)
=> i think you have to care about this (or run the test as junit test instead of as plugin test)

=> i do not really have an idea on how to solve this

https://bugs.eclipse.org/bugs/show_bug.cgi?id=318721

especially calling standalonesetups from workflow might be dangerous

you may try the workaround there but i am not sure if it will work in your case and how that could look like.

package com.mwe2Maventest.problem.print;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.mwe2.language.Mwe2RuntimeModule;
import org.eclipse.emf.mwe2.language.Mwe2StandaloneSetup;
import org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner;
import org.eclipse.xtext.mwe.RuntimeResourceSetInitializer;

import com.google.inject.Guice;
import com.google.inject.Injector;

public class Mwe2LauncherExtended {
	private static final String PARAM = "p";
	
	private static final Logger logger = Logger.getLogger(Mwe2LauncherExtended.class);

	public static void main(String[] args) {
		try {
			new Mwe2LauncherExtended().run(args);
		} catch(Throwable throwable) {
			logger.error(throwable.getMessage(), throwable);
			System.exit(1);
		}
	}

	public void run(String[] args) {
		Options options = getOptions();
		final CommandLineParser parser = new PosixParser();
		CommandLine line = null;
		try {
			line = parser.parse(options, args);
			if (line.getArgs().length == 0)
				throw new ParseException("No module name specified.");
			if (line.getArgs().length > 1)
				throw new ParseException("Only one module name expected. But " + line.getArgs().length
						+ " were passed (" + line.getArgList() + ")");

			String moduleName = line.getArgs()[0];
			Map<String, String> params = new HashMap<String, String>();
			String[] optionValues = line.getOptionValues(PARAM);
			if (optionValues != null) {
				for (String string : optionValues) {
					int index = string.indexOf('=');
					if (index == -1) {
						throw new ParseException("Incorrect parameter syntax '" + string
								+ "'. It should be 'name=value'");
					}
					String name = string.substring(0, index);
					String value = string.substring(index + 1);
					if (params.put(name, value) != null) {
						throw new ParseException("Duplicate parameter '" + name + "'.");
					}
				}
			}
			// check  OperationCanceledException is accessible
			OperationCanceledException.class.getName();
			
			Injector injector = new Mwe2StandaloneSetup() {
	            @Override
	            public Injector createInjector() {
	                return Guice.createInjector(new Mwe2RuntimeModule() {
	                    public Class<? extends RuntimeResourceSetInitializer> bindRuntimeResourceSetInitializer() {
	                        return OSGiResourceSetInitializer.class;
	                    }
	                });
	            }
	        }.createInjectorAndDoEMFRegistration();
			Mwe2Runner mweRunner = injector.getInstance(Mwe2Runner.class);
			if (moduleName.contains("/")) {
				mweRunner.run(URI.createURI(moduleName), params);
			} else {
				mweRunner.run(moduleName, params);
			}
		} catch(NoClassDefFoundError e) {
			if ("org/eclipse/core/runtime/OperationCanceledException".equals(e.getMessage())){
				System.err.println("Could not load class: org.eclipse.core.runtime.OperationCanceledException");
				System.err.println("Add org.eclipse.equinox.common to the class path.");
			} else {
				throw e;
			}
		} catch (final ParseException exp) {
			final HelpFormatter formatter = new HelpFormatter();
			System.err.println("Parsing arguments failed.  Reason: " + exp.getMessage());
			formatter.printHelp("java " + Mwe2LauncherExtended.class.getName() + " some.mwe2.Module [options]\n", options);
			return;
		}
	}

	@SuppressWarnings("static-access")
	public Options getOptions() {
		final Options options = new Options();
		final Option paramOption = OptionBuilder.withArgName("key=value").withDescription(
				"external property that is handled as workflow property").hasArgs().create(PARAM);
		paramOption.setLongOpt("param");
		options.addOption(paramOption);
		return options;
	}
}


package com.mwe2Maventest.problem.print;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.List;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.eclipse.xtext.mwe.RuntimeResourceSetInitializer;

public class OSGiResourceSetInitializer extends RuntimeResourceSetInitializer {
    public List<String> getClassPathEntries() {
        List<String> classPathEntries = super.getClassPathEntries();
        try {
//maybe you can do this more generic ?!?			
File resolved = FileLocator.getBundleFile(Platform.getBundle("com.mwe2maventest.problem"));
			System.out.println(resolved);
			classPathEntries.add(resolved.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
        return classPathEntries;
    }
}



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Maven not able to find MWE2 file referred by unit tests. [message #1756173 is a reply to message #1756092] Mon, 13 March 2017 13:17 Go to previous messageGo to next message
Mahesh B M is currently offline Mahesh B MFriend
Messages: 3
Registered: March 2017
Junior Member
Hi,

- do you run the test in eclipse as plugin test?
No, I run as normal tests.

- the stuff is not buildable cause of the target platform. can you share something that is buildable?
sorry about that, I have corrected the target and replaced the old zip.

- is the mwe2 file part of the jar that is built? if yes how is the path?
Yes, xxx.jar/workflow/PrintToFile.mwe2 is the path of workflow file

- how does the claspath look like that the test sees when called from maven?
No idea, how will I get to see that?

I will try above suggested method and update the results later.
Thanks.

[Updated on: Mon, 13 March 2017 14:58]

Report message to a moderator

Re: Maven not able to find MWE2 file referred by unit tests. [message #1756288 is a reply to message #1756173] Wed, 15 March 2017 06:55 Go to previous messageGo to next message
Mahesh B M is currently offline Mahesh B MFriend
Messages: 3
Registered: March 2017
Junior Member
Hi Christian,
After suggested changes (extended mwe2 runner),when I run it from eclipse the tests will fail because I get null from this statement "Platform.getBundle("com.mwe2maventest.problem")",

here are the changes I have done in test reunner.
Mwe2LauncherExtended mwe2launcher = new Mwe2LauncherExtended();

Re: Maven not able to find MWE2 file referred by unit tests. [message #1756289 is a reply to message #1756288] Wed, 15 March 2017 06:59 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14668
Registered: July 2009
Senior Member
are you sure the bundle is on the path of the test path?
if you run it as PLUGIN TEST, which is what maven does, it should work fine

=> either you run both maven and eclipse as plain unit test (use maven surefire instead of tycho surefire - googling might help, dont know excactly how to do this)
=> or you run both maven and eclipse as plugin test (context menu in eclipse)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:XText grammar with lookbehind
Next Topic:Serializing expressions results in an exception
Goto Forum:
  


Current Time: Fri Apr 26 18:57:52 GMT 2024

Powered by FUDForum. Page generated in 0.03616 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top