Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MOFScript » MOFScript:generate output with the same filename as the source file
MOFScript:generate output with the same filename as the source file [message #517647] Mon, 01 March 2010 10:39 Go to next message
yeliu is currently offline yeliu
Messages: 145
Registered: July 2009
Senior Member
Hello,
How to write the MOFScript transformation if I want the generate output has the same name as the source file. Since the 'self.name' only extract the name of the current context which may not be the file name.


Thanks a lot!



Ye
Re: MOFScript:generate output with the same filename as the source file [message #517912 is a reply to message #517647] Tue, 02 March 2010 09:00 Go to previous messageGo to next message
Gøran K. Olsen is currently offline Gøran K. Olsen
Messages: 184
Registered: July 2009
Senior Member
Hello Ye,

currently there are no buildt in support for getting the file name of a
given source model.
However it is always possible to do using the "black-box" java
functionality, e.g. writing a java class with an operation that retreives
the file name from for example an EObject.

If you are calling the transformation using the Java API it should also be
quite simple to get the name and using for example
setenv: Sets an environment variable. Equivalent to Java
System.setProperty().

then you could use the

getenv: Gets an environment variable. Equivalent to Java
System.getProperty()..

in your transformation.

Cheers,
G
Re: MOFScript:generate output with the same filename as the source file [message #517946 is a reply to message #517912] Tue, 02 March 2010 10:19 Go to previous messageGo to next message
yeliu is currently offline yeliu
Messages: 145
Registered: July 2009
Senior Member
Hello,
Talking about calling transformation from Java API, I've tried by copying the TestAPI.java found in Eclipse site (or the MOFscript user guide 2009, which has similar). And compile it from command line, it says there are imports unresolved.(part of the error message are shown below).But I've already add almost all of them in the Java classpath except " org.eclipse.mofscript.MOFScriptModel.MOFScriptSpecification; ", which I couldn't find in the library where MOFscript is installed.
So currently, I have to use MOFscript from Eclipse, and yet, I hope to call transformation from command line. Thank you very much.
-----------------------------------------.

src/TestAPI.java:12: package org.eclipse.mofscript.MOFScriptModel does not exist
import org.eclipse.mofscript.MOFScriptModel.MOFScriptSpecification;
^
src/TestAPI.java:13: package org.eclipse.mofscript.parser does not exist
import org.eclipse.mofscript.parser.MofScriptParseError;
^
src/TestAPI.java:14: package org.eclipse.mofscript.parser does not exist
import org.eclipse.mofscript.parser.ParserUtil;
^
src/TestAPI.java:15: package org.eclipse.mofscript.runtime does not exist
import org.eclipse.mofscript.runtime.ExecutionManager;
^
src/TestAPI.java:16: package org.eclipse.mofscript.runtime does not exist
import org.eclipse.mofscript.runtime.ExecutionMessageListener;
^
src/TestAPI.java:17: package org.eclipse.mofscript.runtime does not exist
import org.eclipse.mofscript.runtime.MofScriptExecutionException;
^
src/TestAPI.java:22: cannot find symbol
symbol: class ExecutionMessageListener
public class TestAPI implements ExecutionMessageListener {
^
src/TestAPI.java:24: cannot find symbol
symbol : class ParserUtil
location: class TestAPI
private ParserUtil parserUtil = null;
...
------------------------------
Re: MOFScript:generate output with the same filename as the source file [message #518156 is a reply to message #517946] Wed, 03 March 2010 05:06 Go to previous messageGo to next message
Gøran K. Olsen is currently offline Gøran K. Olsen
Messages: 184
Registered: July 2009
Senior Member
This looks like a typical classpath problem.
You should add the ones below.

antlr-3.1.1-runtime.jar
org.eclipse.emf_2.5.0.....jar
org.eclipse.emf.common_2.5.0.....jar
org.eclipse.emf.ecore_2.5.0......jar
org.eclipse.emf.ecore.xmi_2.5.0....jar
org.eclipse.mofscript.model...jar / or the bin folder if you have the source
org.eclipse.mofscript.parser...jar / or the bin folder if you have the
source
org.eclipse.mofscript.runtime...jar / or the bin folder if you have the
source
org.eclipse.mofscript.fileresource...jar / or the bin folder if you have the
source
org.eclipse.mofscript.traceability....jar / if you want to use traceability

org.whatever.models.you.are.using.jar
e.g.
org.eclipse.uml2.common-1.5.0....jar
org.eclipse.uml2.uml_3.0.1....jar

You could also try to make a separate plug-in inside Eclipse that loads and
executes a transformation, then you will see what is required to run.

Cheers,
G
Re: MOFScript:generate output with the same filename as the source file [message #518165 is a reply to message #517946] Wed, 03 March 2010 05:37 Go to previous messageGo to next message
Gøran K. Olsen is currently offline Gøran K. Olsen
Messages: 184
Registered: July 2009
Senior Member
And for comand line:

#!/bin/sh

#
# Home of Eclipse plugins..
#
EH=/home/jol/Apps/eclipse/plugins

#
# EMF JARS
#
EMF_CP=$EH/org.eclipse.emf_2.5.0.v200906151043.jar:$EH/org.e clipse.emf.common_2.5.0.v200906151043.jar:$EH/org.eclipse.em f.ecore_2.5.0.v200906151043.jar:$EH/org.eclipse.emf.ecore.xm i_2.5.0.v200906151043.jar

#
# UML Jars
# UML jars only needed if your input models are UML. Link with other jars if
input models are something else (and not EMF) #
UML_CP=$EH/org.eclipse.uml2.uml_3.0.1.v200908281330.jar:$EH/ org.eclipse.uml2.common_1.5.0.v200905041045.jar

#
# ANTLR Jar
# Antlr needed for execution, not for compiling
#
ANTLR=/home/jol/Work/Dev/MOFScript-Eclipse/org.eclipse.gmt.m ofscript/org.eclipse.mofscript.parser/lib/antlr-3.1.1-runtim e.jar

#
# MOFScript libs
# file resource model is needed for execution, not for compilation.
# traceability model needed if traceability is turned on.
#
MOFSCRIPT_LIB_DIR=/home/jol/mofscript-lib
MOFSCRIPT_CP=$MOFSCRIPT_LIB_DIR/org.eclipse.mofscript.model. jar:$MOFSCRIPT_LIB_DIR/org.eclipse.mofscript.parser.jar:$MOF SCRIPT_LIB_DIR/org.eclipse.mofscript.runtime.jar:$MOFSCRIPT_ LIB_DIR/org.eclipse.mofscript.fileresourcemodel.jar:

#
# Src dir
#
SRC_DIR=src/

###
### EXECUTE
###
java -cp $SRC_DIR:$MOFSCRIPT_CP:$EMF_CP:$UML_CP:$ANTLR TestAPI

###
### COMPILE
###
javac -cp $SRC_DIR:$MOFSCRIPT_CP:$EMF_CP:$UML_CP src/TestAPI.java


Cheers,
G
Re: MOFScript:generate output with the same filename as the source file [message #518481 is a reply to message #518165] Thu, 04 March 2010 04:31 Go to previous messageGo to next message
yeliu is currently offline yeliu
Messages: 145
Registered: July 2009
Senior Member
Hello,
Thanks very much for the answer and especially the script!
However when I run the program , there is error:
-------------
xception in thread "main" java.lang.NullPointerException
at TestAPI.parse(TestAPI.java:35)
at TestAPI.test(TestAPI.java:87)
at TestAPI.main(TestAPI.java:107)
---------------
The problem seems lies in the following line:
-----------
MOFscriptSpecification spec=parserUtil.parse(f, true)
------------
I tried searching the parserUtil , but couldn't find a matching one .
Do you know how to solve this error?

Re: MOFScript:generate output with the same filename as the source file [message #518487 is a reply to message #518481] Thu, 04 March 2010 04:43 Go to previous messageGo to next message
yeliu is currently offline yeliu
Messages: 145
Registered: July 2009
Senior Member
Hello,
I tried the following to solve the post I just posted and it seems that problem solved.
---------------
ParserUtil par=new ParserUtil();
MOFScriptSpecification spec = par.parse(f, true);
---------------
But there are a list of parse error, like (to paste a few)
--------------
Parsing result: 62 errors
: Error: MTTParseError: Illegal/unknown context: uml, line: 440, column: 0
: Error: MTTParseError: Type not found: 'PackageableElement' in metamodel 'null', line: 0, column: 0
: Error: MTTParseError: Can't find feature 'packagedElement' for type 'Model'., line: 17, column: 6
: Error: MTTParseError: Can't find feature 'name' for type 'PackageableElement'., line: 19, column: 37
: Error: MTTParseError: Can't find feature 'name' for type 'PackageableElement'., line: 21, column: 23
: Error: MTTParseError: Can't find feature 'nestedPackage' for type 'Model'., line: 41, column: 5
---------------
The transformation alone doesn't have any parsing error. But why the error message?


Thanks as always!
Re: MOFScript:generate output with the same filename as the source file [message #518648 is a reply to message #518487] Thu, 04 March 2010 11:54 Go to previous messageGo to next message
Gøran K. Olsen is currently offline Gøran K. Olsen
Messages: 184
Registered: July 2009
Senior Member
Hi,

have a look at:

Report message to a moderator

Re: MOFScript:generate output with the same filename as the source file [message #518832 is a reply to message #518648] Fri, 05 March 2010 04:04 Go to previous messageGo to next message
yeliu is currently offline yeliu
Messages: 145
Registered: July 2009
Senior Member
Hi,
Are you Gøran K. Olsen!
Re: MOFScript:generate output with the same filename as the source file [message #580294 is a reply to message #517912] Tue, 02 March 2010 10:19 Go to previous messageGo to next message
yeliu is currently offline yeliu
Messages: 145
Registered: July 2009
Senior Member
Hello,
Talking about calling transformation from Java API, I've tried by copying the TestAPI.java found in Eclipse site (or the MOFscript user guide 2009, which has similar). And compile it from command line, it says there are imports unresolved.(part of the error message are shown below).But I've already add almost all of them in the Java classpath except " org.eclipse.mofscript.MOFScriptModel.MOFScriptSpecification; ", which I couldn't find in the library where MOFscript is installed.
So currently, I have to use MOFscript from Eclipse, and yet, I hope to call transformation from command line. Thank you very much.
-----------------------------------------.

src/TestAPI.java:12: package org.eclipse.mofscript.MOFScriptModel does not exist
import org.eclipse.mofscript.MOFScriptModel.MOFScriptSpecification;
^
src/TestAPI.java:13: package org.eclipse.mofscript.parser does not exist
import org.eclipse.mofscript.parser.MofScriptParseError;
^
src/TestAPI.java:14: package org.eclipse.mofscript.parser does not exist
import org.eclipse.mofscript.parser.ParserUtil;
^
src/TestAPI.java:15: package org.eclipse.mofscript.runtime does not exist
import org.eclipse.mofscript.runtime.ExecutionManager;
^
src/TestAPI.java:16: package org.eclipse.mofscript.runtime does not exist
import org.eclipse.mofscript.runtime.ExecutionMessageListener;
^
src/TestAPI.java:17: package org.eclipse.mofscript.runtime does not exist
import org.eclipse.mofscript.runtime.MofScriptExecutionException;
^
src/TestAPI.java:22: cannot find symbol
symbol: class ExecutionMessageListener
public class TestAPI implements ExecutionMessageListener {
^
src/TestAPI.java:24: cannot find symbol
symbol : class ParserUtil
location: class TestAPI
private ParserUtil parserUtil = null;
...
------------------------------
Re: MOFScript:generate output with the same filename as the source file [message #580314 is a reply to message #517946] Wed, 03 March 2010 05:06 Go to previous messageGo to next message
Gøran K. Olsen is currently offline Gøran K. Olsen
Messages: 184
Registered: July 2009
Senior Member
This looks like a typical classpath problem.
You should add the ones below.

antlr-3.1.1-runtime.jar
org.eclipse.emf_2.5.0.....jar
org.eclipse.emf.common_2.5.0.....jar
org.eclipse.emf.ecore_2.5.0......jar
org.eclipse.emf.ecore.xmi_2.5.0....jar
org.eclipse.mofscript.model...jar / or the bin folder if you have the source
org.eclipse.mofscript.parser...jar / or the bin folder if you have the
source
org.eclipse.mofscript.runtime...jar / or the bin folder if you have the
source
org.eclipse.mofscript.fileresource...jar / or the bin folder if you have the
source
org.eclipse.mofscript.traceability....jar / if you want to use traceability

org.whatever.models.you.are.using.jar
e.g.
org.eclipse.uml2.common-1.5.0....jar
org.eclipse.uml2.uml_3.0.1....jar

You could also try to make a separate plug-in inside Eclipse that loads and
executes a transformation, then you will see what is required to run.

Cheers,
G
Re: MOFScript:generate output with the same filename as the source file [message #580327 is a reply to message #517946] Wed, 03 March 2010 05:37 Go to previous messageGo to next message
Gøran K. Olsen is currently offline Gøran K. Olsen
Messages: 184
Registered: July 2009
Senior Member
And for comand line:

#!/bin/sh

#
# Home of Eclipse plugins..
#
EH=/home/jol/Apps/eclipse/plugins

#
# EMF JARS
#
EMF_CP=$EH/org.eclipse.emf_2.5.0.v200906151043.jar:$EH/org.e clipse.emf.common_2.5.0.v200906151043.jar:$EH/org.eclipse.em f.ecore_2.5.0.v200906151043.jar:$EH/org.eclipse.emf.ecore.xm i_2.5.0.v200906151043.jar

#
# UML Jars
# UML jars only needed if your input models are UML. Link with other jars if
input models are something else (and not EMF) #
UML_CP=$EH/org.eclipse.uml2.uml_3.0.1.v200908281330.jar:$EH/ org.eclipse.uml2.common_1.5.0.v200905041045.jar

#
# ANTLR Jar
# Antlr needed for execution, not for compiling
#
ANTLR=/home/jol/Work/Dev/MOFScript-Eclipse/org.eclipse.gmt.m ofscript/org.eclipse.mofscript.parser/lib/antlr-3.1.1-runtim e.jar

#
# MOFScript libs
# file resource model is needed for execution, not for compilation.
# traceability model needed if traceability is turned on.
#
MOFSCRIPT_LIB_DIR=/home/jol/mofscript-lib
MOFSCRIPT_CP=$MOFSCRIPT_LIB_DIR/org.eclipse.mofscript.model. jar:$MOFSCRIPT_LIB_DIR/org.eclipse.mofscript.parser.jar:$MOF SCRIPT_LIB_DIR/org.eclipse.mofscript.runtime.jar:$MOFSCRIPT_ LIB_DIR/org.eclipse.mofscript.fileresourcemodel.jar:

#
# Src dir
#
SRC_DIR=src/

###
### EXECUTE
###
java -cp $SRC_DIR:$MOFSCRIPT_CP:$EMF_CP:$UML_CP:$ANTLR TestAPI

###
### COMPILE
###
javac -cp $SRC_DIR:$MOFSCRIPT_CP:$EMF_CP:$UML_CP src/TestAPI.java


Cheers,
G
Re: MOFScript:generate output with the same filename as the source file [message #580343 is a reply to message #518165] Thu, 04 March 2010 04:31 Go to previous messageGo to next message
yeliu is currently offline yeliu
Messages: 145
Registered: July 2009
Senior Member
Hello,
Thanks very much for the answer and especially the script!
However when I run the program , there is error:
-------------
xception in thread "main" java.lang.NullPointerException
at TestAPI.parse(TestAPI.java:35)
at TestAPI.test(TestAPI.java:87)
at TestAPI.main(TestAPI.java:107)
---------------
The problem seems lies in the following line:
-----------
MOFscriptSpecification spec=parserUtil.parse(f, true)
------------
I tried searching the parserUtil , but couldn't find a matching one .
Do you know how to solve this error?
Re: MOFScript:generate output with the same filename as the source file [message #580361 is a reply to message #518481] Thu, 04 March 2010 04:43 Go to previous messageGo to next message
yeliu is currently offline yeliu
Messages: 145
Registered: July 2009
Senior Member
Hello,
I tried the following to solve the post I just posted and it seems that problem solved.
---------------
ParserUtil par=new ParserUtil();
MOFScriptSpecification spec = par.parse(f, true);
---------------
But there are a list of parse error, like (to paste a few)
--------------
Parsing result: 62 errors
: Error: MTTParseError: Illegal/unknown context: uml, line: 440, column: 0
: Error: MTTParseError: Type not found: 'PackageableElement' in metamodel 'null', line: 0, column: 0
: Error: MTTParseError: Can't find feature 'packagedElement' for type 'Model'., line: 17, column: 6
: Error: MTTParseError: Can't find feature 'name' for type 'PackageableElement'., line: 19, column: 37
: Error: MTTParseError: Can't find feature 'name' for type 'PackageableElement'., line: 21, column: 23
: Error: MTTParseError: Can't find feature 'nestedPackage' for type 'Model'., line: 41, column: 5
---------------
The transformation alone doesn't have any parsing error. But why the error message?


Thanks as always!
Re: MOFScript:generate output with the same filename as the source file [message #589747 is a reply to message #580361] Thu, 04 March 2010 11:54 Go to previous messageGo to next message
Gøran K. Olsen is currently offline Gøran K. Olsen
Messages: 184
Registered: July 2009
Senior Member
Hi,

have a look at:

Report message to a moderator

Re: MOFScript:generate output with the same filename as the source file [message #589755 is a reply to message #518648] Fri, 05 March 2010 04:04 Go to previous message
yeliu is currently offline yeliu
Messages: 145
Registered: July 2009
Senior Member
Hi,
Are you Gøran K. Olsen!
Previous Topic:MOFScript:generate output with the same filename as the source file
Next Topic:call transformation from Java API
Goto Forum:
  


Current Time: Thu Apr 24 11:39:18 EDT 2014

Powered by FUDForum. Page generated in 0.07694 seconds