두 번째 워크 벤치의 모델에서 Xpand 워크 플로를 프로그래밍 방식으로 실행하는 방법은 무엇입니까?
문제
Xtext/Xpand (OAW 4.3, Eclipse 3.4) 발전기 플러그인이 있으며, 이는 두 번째 워크 벤치의 편집기 플러그인과 함께 실행됩니다. 그곳에서 내가 만든 모델 파일에서 프로그래밍 방식으로 XPand 워크 플로우를 실행하고 싶습니다. 내가 가진 Ifile의 절대 경로를 사용하여 모델 파일을 설정하면 다음과 같이합니다.
String dslFile = file.getLocation().makeAbsolute().toOSString();
또는 파일을 사용하는 경우 URI를 검색 한 경우 다음과 같습니다.
String dslFile = file.getLocationURI().toString();
파일을 찾을 수 없습니다.
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Resource '/absolute/path/to/my/existing/dsl.file' does not exist.
at org.openarchitectureware.xtext.parser.impl.AbstractParserComponent.invokeInternal(AbstractParserComponent.java:55)
맵에서 모델 파일 속성 (dslfile)을 설정 해야하는 값에 대해
Map properties = new HashMap();
properties.put("modelFile", dslFile);
또한 속성을 비워두고 워크 플로 파일 (워크 플로 파일 내부)을 기준으로 모델 파일을 참조하려고했지만 filenotfoundException이 생성되었습니다. 이 모든 것을 일반 앱 (두 번째 워크 벤치가 아님)에서 실행하는 것은 잘 작동합니다.
해결책 2
나는 도움을 찾았다 OpenArchitectureWare 포럼. 기본적으로 사용합니다
properties.put("modelFile", file.getLocation().makeAbsolute().toOSString());
작동하지만 호출하는 워크 플로에서 URI를 통해 찾아보기를 지정해야합니다.
<component class="org.eclipse.mwe.emf.Reader">
<uri value='${modelFile}'/>
<modelSlot value='theModel'/>
</component>
다른 팁
2 여기 여기를보고있는 사람들을위한 중요한 것들 ... TE는 "file.get ...
이것은 샘플 응용 프로그램입니다 발사기. 자바 (기본 패키지에 앉아) :
import gnu.getopt.Getopt;
import gnu.getopt.LongOpt;
import java.io.File;
import java.io.IOException;
import org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher;
public class Launcher implements Runnable {
//
// main program
//
public static void main(final String[] args) {
new Launcher(args).run();
}
//
// private final fields
//
private static final String defaultModelDir = "src/main/resources/model";
private static final String defaultTargetDir = "target/generated/pageflow-maven-plugin/java";
private static final String defaultFileEncoding = "UTF-8";
private static final LongOpt[] longopts = new LongOpt[] {
new LongOpt("baseDir", LongOpt.REQUIRED_ARGUMENT, new StringBuffer(), 'b'),
new LongOpt("modelDir", LongOpt.REQUIRED_ARGUMENT, new StringBuffer(), 'm'),
new LongOpt("targetDir", LongOpt.REQUIRED_ARGUMENT, new StringBuffer(), 't'),
new LongOpt("encoding", LongOpt.REQUIRED_ARGUMENT, new StringBuffer(), 'e'),
new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h'),
new LongOpt("verbose", LongOpt.NO_ARGUMENT, null, 'v'),
};
private final String[] args;
//
// public constructors
//
public Launcher(final String[] args) {
this.args = args;
}
public void run() {
final String cwd = System.getProperty("user.dir");
String baseDir = cwd;
String modelDir = defaultModelDir;
String targetDir = defaultTargetDir;
String encoding = defaultFileEncoding;
boolean verbose = false;
final StringBuffer sb = new StringBuffer();
final Getopt g = new Getopt("pageflow-dsl-generator", this.args, "b:m:t:e:hv;", longopts);
g.setOpterr(false); // We'll do our own error handling
int c;
while ((c = g.getopt()) != -1)
switch (c) {
case 'b':
baseDir = g.getOptarg();
break;
case 'm':
modelDir = g.getOptarg();
break;
case 't':
targetDir = g.getOptarg();
break;
case 'e':
encoding = g.getOptarg();
break;
case 'h':
printUsage();
System.exit(0);
break;
case 'v':
verbose = true;
break;
case '?':
default:
System.out.println("The option '" + (char) g.getOptopt() + "' is not valid");
printUsage();
System.exit(1);
break;
}
String absoluteModelDir;
String absoluteTargetDir;
try {
absoluteModelDir = checkDir(baseDir, modelDir, false, true);
absoluteTargetDir = checkDir(baseDir, targetDir, true, true);
} catch (final IOException e) {
throw new RuntimeException(e.getMessage(), e.getCause());
}
if (verbose) {
System.err.println(String.format("modeldir = %s", absoluteModelDir));
System.err.println(String.format("targetdir = %s", absoluteTargetDir));
System.err.println(String.format("encoding = %s", encoding));
}
Mwe2Launcher.main(
new String[] {
"workflow.PageflowGenerator",
"-p", "modelDir=".concat(absoluteModelDir),
"-p", "targetDir=".concat(absoluteTargetDir),
"-p", "fileEncoding=".concat(encoding)
});
}
private void printUsage() {
System.err.println("Syntax: [-b <baseDir>] [-m <modelDir>] [-t <targetDir>] [-e <encoding>] [-h] [-v]");
System.err.println("Options:");
System.err.println(" -b, --baseDir project home directory, e.g: /home/workspace/myapp");
System.err.println(" -m, --modelDir default is: ".concat(defaultModelDir));
System.err.println(" -t, --targetDir default is: ".concat(defaultTargetDir));
System.err.println(" -e, --encoding default is: ".concat(defaultFileEncoding));
System.err.println(" -h, --help this help text");
System.err.println(" -v, --verbose verbose mode");
}
private String checkDir(final String basedir, final String dir, final boolean create, final boolean fail) throws IOException {
final StringBuilder sb = new StringBuilder();
sb.append(basedir).append('/').append(dir);
final File f = new File(sb.toString()).getCanonicalFile();
final String absolutePath = f.getAbsolutePath();
if (create) {
if (f.isDirectory()) return absolutePath;
if (f.mkdirs()) return absolutePath;
} else {
if (f.isDirectory()) return absolutePath;
}
if (!fail) return null;
throw new IOException(String.format("Failed to locate or create directory %s", absolutePath));
}
private String checkFile(final String basedir, final String file, final boolean fail) throws IOException {
final StringBuilder sb = new StringBuilder();
sb.append(basedir).append('/').append(file);
final File f = new File(sb.toString()).getCanonicalFile();
final String absolutePath = f.getAbsolutePath();
if (f.isFile()) return absolutePath;
if (!fail) return null;
throw new IOException(String.format("Failed to find or locate directory %s", absolutePath));
}
}
... 그리고 이것은 그것입니다 pom.xml:
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.vaadin</groupId>
<artifactId>pageflow-dsl-generator</artifactId>
<version>0.1.0-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<index>true</index>
<manifest>
<mainClass>Launcher</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>urbanophile</groupId>
<artifactId>java-getopt</artifactId>
<version>1.0.9</version>
</dependency>
</dependencies>
</project>
불행히도,이 pom.xml은 그것을 포장하기위한 것이 아닙니다 (적어도 아직은 아닙니다). 포장에 관한 지침은 살펴보십시오링크 텍스트
재미있게 보내세요 :)
Richard Gomes
제휴하지 않습니다 StackOverflow