Java源码示例:org.eclipse.emf.mwe2.runtime.workflow.IWorkflowContext
示例1
@Override
public void invoke(IWorkflowContext ctx) {
File sourceFileOrDir = new File(sourcePath);
File targetFileOrDir = new File(targetPath);
try {
if (targetFileOrDir.exists()) {
if (targetFileOrDir.isDirectory()) {
org.eclipse.xtext.util.Files.sweepFolder(targetFileOrDir);
} else {
targetFileOrDir.delete();
}
}
internalTargetPath = targetFileOrDir.toPath();
internalSourcePath = sourceFileOrDir.toPath();
Files.walkFileTree(internalSourcePath, this);
} catch(IOException e) {
throw new RuntimeException(e);
} finally {
internalSourcePath = null;
internalTargetPath = null;
}
}
示例2
@Override
public void invoke(IWorkflowContext ctx) {
GeneratorDelegate instance = getCompiler();
IFileSystemAccess2 fileSystemAccess = getConfiguredFileSystemAccess();
for (String slot : slotNames) {
Object object = ctx.get(slot);
if (object == null) {
throw new IllegalStateException("Slot '"+slot+"' was empty!");
}
if (object instanceof Iterable) {
Iterable<?> iterable = (Iterable<?>) object;
for (Object object2 : iterable) {
if (!(object2 instanceof Resource)) {
throw new IllegalStateException("Slot contents was not a Resource but a '"+object.getClass().getSimpleName()+"'!");
}
GeneratorContext context = new GeneratorContext();
context.setCancelIndicator(CancelIndicator.NullImpl);
instance.generate((Resource) object2, fileSystemAccess, context);
}
} else if (object instanceof Resource) {
instance.doGenerate((Resource) object, fileSystemAccess);
} else {
throw new IllegalStateException("Slot contents was not a Resource but a '"+object.getClass().getSimpleName()+"'!");
}
}
}
示例3
public void invoke(IWorkflowContext ctx) {
Set<String> names = ctx.getSlotNames();
for (String slotName : names) {
Object slotContent = ctx.get(slotName);
if (slotContent instanceof Iterable) {
Iterator<?> iter = ((Iterable<?>) slotContent).iterator();
while (iter.hasNext()) {
Object o = iter.next();
if (o instanceof Resource) {
Resource r = ((Resource) o);
if(!r.isLoaded())
try {
r.load(null);
} catch (IOException e) {
throw new RuntimeException("Error loading slot "+ slotName, e);
}
if(r instanceof LazyLinkingResource)
ctx.put(slotName, r.getContents());
}
}
}
}
}
示例4
@Override
public void invoke(IWorkflowContext ctx) {
try {
buildN4jsLibs();
} catch (IOException e) {
throw new RuntimeException(e); // let MWE2 runner report the exception
}
}
示例5
@Override
public void invoke(IWorkflowContext ctx) {
try {
File binDirectory = new File(binPath + "/" + packagePath);
if (!binDirectory.exists())
throw new RuntimeException(binPath + "/" + packagePath);
File targetDirectory = new File(targetDir);
if (!targetDirectory.exists())
throw new RuntimeException(targetDir);
File zipFile = new File(targetDirectory, "testData.jar");
if (!zipFile.exists())
zipFile.createNewFile();
JarOutputStream outputStream = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
try {
String packagePathInJar = packagePath + "/";
for(File classFile: binDirectory.listFiles()) {
if (classFile.isFile() && classFile.getName().endsWith(".class") && !classFile.getName().endsWith("$RemoveMe.class")) {
addToJar(packagePathInJar, classFile, outputStream);
}
}
File rootBindDirectoy = new File(binPath);
File classFileWithoutPackage = new File(rootBindDirectoy, "ClassWithDefaultPackage.class");
if (classFileWithoutPackage.isFile()) {
addToJar("", classFileWithoutPackage, outputStream);
}
} finally {
outputStream.close();
}
} catch(IOException ioe) {
throw new RuntimeException(ioe);
}
}
示例6
@Override
public void invoke(IWorkflowContext ctx) {
try {
for(String pack: packages) {
String packagePath = pack.replace('.', '/');
File sourcePackage = new File(new File(sourceDirectory), packagePath);
if (!sourcePackage.exists())
throw new RuntimeException(sourcePackage.getAbsolutePath());
File targetPackage = new File(new File(targetDirectory), packagePath);
if (!targetPackage.exists() && !targetPackage.mkdirs()) {
throw new RuntimeException(targetPackage.getAbsolutePath());
}
for(File file: sourcePackage.listFiles()) {
String fileName = file.getName();
if (file.isFile() && (fileName.endsWith(".java") || fileName.endsWith(".xtend"))) {
File target = new File(targetPackage, fileName + ".txt");
if (!target.exists()) {
target.createNewFile();
}
FileChannel javaInputChannel = null;
FileChannel textOutputChannel = null;
try {
javaInputChannel = new FileInputStream(file).getChannel();
textOutputChannel = new FileOutputStream(target).getChannel();
textOutputChannel.transferFrom(javaInputChannel, 0, javaInputChannel.size());
}
finally {
if (javaInputChannel != null) {
javaInputChannel.close();
}
if (textOutputChannel != null) {
textOutputChannel.close();
}
}
}
}
}
} catch(IOException ioe) {
throw new RuntimeException(ioe);
}
}
示例7
@Override
public void invoke(IWorkflowContext ctx) {
}
示例8
@Override
public void invoke(IWorkflowContext ctx) {
}