diff options
author | Tom Schindl | 2013-07-16 19:07:16 +0000 |
---|---|---|
committer | Tom Schindl | 2013-07-16 19:07:16 +0000 |
commit | 0b2d8da38c6443ae02d748d0da79363cc0038cc9 (patch) | |
tree | 225c9e8ba833830b34fee93114531d5a4a26d44d | |
parent | fea788d15721967ead85f2b3ac9d73632ef1a219 (diff) | |
download | org.eclipse.efxclipse-0b2d8da38c6443ae02d748d0da79363cc0038cc9.tar.gz org.eclipse.efxclipse-0b2d8da38c6443ae02d748d0da79363cc0038cc9.tar.xz org.eclipse.efxclipse-0b2d8da38c6443ae02d748d0da79363cc0038cc9.zip |
fixed location in repo
19 files changed, 632 insertions, 0 deletions
diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.classpath b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.classpath new file mode 100644 index 000000000..248b4c5dc --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.classpath @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="xtend-gen"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.gitignore b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.gitignore new file mode 100644 index 000000000..2a2f894bd --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.gitignore @@ -0,0 +1,3 @@ +/bin +/build.xml +/out-src diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.project b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.project new file mode 100644 index 000000000..46f4b99fd --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.project @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.fx.ide.fxml.compiler</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.xtext.ui.shared.xtextBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.xtext.ui.shared.xtextNature</nature> + </natures> +</projectDescription> diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.settings/org.eclipse.core.resources.prefs b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 000000000..99f26c020 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/<project>=UTF-8 diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.settings/org.eclipse.core.runtime.prefs b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 000000000..5a0ad22d2 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +line.separator=\n diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.settings/org.eclipse.jdt.core.prefs b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..f42de363a --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/META-INF/MANIFEST.MF b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/META-INF/MANIFEST.MF new file mode 100644 index 000000000..a32152a72 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Compiler
+Bundle-SymbolicName: org.eclipse.fx.ide.fxml.compiler
+Bundle-Version: 1.0.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+Require-Bundle: org.eclipse.xtend.lib,
+ com.google.guava,
+ org.eclipse.xtext.xbase.lib,
+ org.eclipse.fx.ide.fxgraph;bundle-version="0.8.1",
+ org.eclipse.xtext.common.types;bundle-version="2.4.2",
+ org.apache.ant;bundle-version="1.8.4"
+
diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/build.properties b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/build.properties new file mode 100644 index 000000000..34d2e4d2d --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/.gitignore b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/.gitignore new file mode 100644 index 000000000..e401ec7cb --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/.gitignore @@ -0,0 +1 @@ +/Sample.java diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/Sample.fxgraph b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/Sample.fxgraph new file mode 100644 index 000000000..e9ebba287 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/Sample.fxgraph @@ -0,0 +1,62 @@ +package a + +import javafx.scene.layout.BorderPane +import javafx.scene.control.Button +import javafx.scene.layout.HBox +import javafx.scene.control.Label +import javafx.scene.layout.VBox +import javafx.geometry.Insets +import javafx.scene.layout.GridPane + +component Sample { + BorderPane { + center : Button { + text : "Hello World" + }, + bottom : HBox { + children : [ + Label { + text : "Label 1", + minWidth : 100, + static hgrow : "ALWAYS" + }, + Label { + text : "Label 1", + static margin : Insets { + bottom : 5 + } + }, + VBox { + Label { + text : "Def 1" + }, + Label { + text : "Def 2" + } + }, + VBox { + children : [ + Label { + text : "Label 1", + static vgrow : "SOMETIMES" + }, + GridPane { + children : [ + Label { + text : "In Grid 0/0", + static columnIndex : 0, + static rowIndex : 0 + }, + Label { + text : "In Grid 0/1", + static columnIndex : 0, + static rowIndex : 1 + } + ] + } + ] + } + ] + } + } +} diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/Sample.fxml b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/Sample.fxml new file mode 100644 index 000000000..14b4f3842 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/sample-src/sample/Sample.fxml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Do not edit this file it is generated by e(fx)clipse from ../sample-src/sample/Sample.fxgraph
+-->
+
+<?import java.lang.*?>
+<?import javafx.geometry.Insets?>
+<?import javafx.scene.control.Button?>
+<?import javafx.scene.control.Label?>
+<?import javafx.scene.layout.BorderPane?>
+<?import javafx.scene.layout.GridPane?>
+<?import javafx.scene.layout.HBox?>
+<?import javafx.scene.layout.VBox?>
+
+<BorderPane xmlns:fx="http://javafx.com/fxml">
+
+ <center>
+ <Button text="Hello World"/>
+ </center>
+ <bottom>
+ <HBox>
+ <children>
+ <Label text="Label 1" minWidth="100" HBox.hgrow="ALWAYS"/>
+ <Label text="Label 1">
+ <HBox.margin>
+ <Insets bottom="5"/>
+ </HBox.margin>
+ </Label>
+ <VBox>
+ <Label text="Def 1"/>
+ <Label text="Def 2"/>
+ </VBox>
+ <VBox>
+ <children>
+ <Label text="Label 1" VBox.vgrow="SOMETIMES"/>
+ <GridPane>
+ <children>
+ <Label text="In Grid 0/0" GridPane.columnIndex="0" GridPane.rowIndex="0"/>
+ <Label text="In Grid 0/1" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
+ </children>
+ </GridPane>
+ </children>
+ </VBox>
+ </children>
+ </HBox>
+ </bottom>
+</BorderPane>
diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/FXGraphCompiler.java b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/FXGraphCompiler.java new file mode 100644 index 000000000..4ddd32a92 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/FXGraphCompiler.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2013 BestSolution.at and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + *******************************************************************************/ +package org.eclipse.fx.ide.fxml.compiler; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.UUID; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.fx.ide.fxgraph.converter.FXGraphConverter; +import org.eclipse.fx.ide.fxgraph.converter.FXMLLoader; +import org.eclipse.fx.ide.fxgraph.converter.IFXMLFile; +import org.eclipse.fx.ide.fxgraph.fXGraph.Model; + +import com.google.inject.Inject; +import com.google.inject.Injector; +import com.google.inject.Provider; + +public class FXGraphCompiler { + + @Inject + private Provider<ResourceSet> resourceSetProvider; + + public static void main(String[] args) { + Injector injector = new org.eclipse.fx.ide.fxgraph.FXGraphStandaloneSetupGenerated().createInjectorAndDoEMFRegistration(); + FXGraphCompiler main = injector.getInstance(FXGraphCompiler.class); + main.compile(args[0], args[1],null); + } + + public void compile(final String string, final String sourcePrefix, String outputPrefix) { + Model m; + String fxgraph = string; + if( string.endsWith("fxml") ) { + FXMLLoader loader = new FXMLLoader(); + m = loader.loadModel(new IFXMLFile() { + + @Override + public String getPackagename() { + if( sourcePrefix == null) { + return "dummy"; + } else { + String filePath = new File(string).getParent(); + String packagename = filePath.substring(sourcePrefix.length()+1); + return packagename.replace('/', '.'); + } + } + + @Override + public String getName() { + return new File(string).getName(); + } + + @Override + public InputStream getContent() { + try { + return new FileInputStream(string); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + }); + + fxgraph = "/tmp/"+UUID.randomUUID().toString()+".fxgraph"; + + File out = new File(fxgraph); + System.err.println(out); +// out.deleteOnExit(); + try { + FileOutputStream outStream = new FileOutputStream(out); + outStream.write(new FXGraphConverter().generate(m).toString().getBytes()); + outStream.close(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + ResourceSet set = resourceSetProvider.get(); + Resource resource = set.getResource(URI.createURI(fxgraph), true); + + m = (Model)resource.getContents().get(0); + + FXGraphJavaGenerator c = new FXGraphJavaGenerator(); + + try { + String outFile = string.replaceAll("fxgraph$", "java").replaceAll("fxml$", "java"); + + if( outputPrefix != null ) { + String filePath = new File(outFile).getAbsolutePath(); + String packagename = filePath.substring(sourcePrefix.length()+1); + File f = new File(outputPrefix,packagename); + f.getParentFile().mkdirs(); + outFile = f.getAbsolutePath(); + } + + FileOutputStream out = new FileOutputStream(outFile); + out.write(c.generate(m).toString().getBytes()); + out.close(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/FXGraphJavaGenerator.xtend b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/FXGraphJavaGenerator.xtend new file mode 100644 index 000000000..25f1c6890 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/FXGraphJavaGenerator.xtend @@ -0,0 +1,139 @@ +package org.eclipse.fx.ide.fxml.compiler
+
+import org.eclipse.fx.ide.fxgraph.fXGraph.Model
+import org.eclipse.fx.ide.fxgraph.fXGraph.Element
+import org.eclipse.fx.ide.fxgraph.fXGraph.SimpleValueProperty
import org.eclipse.fx.ide.fxgraph.fXGraph.ListValueProperty +import org.eclipse.fx.ide.fxgraph.fXGraph.StaticValueProperty
+
+import static extension org.eclipse.fx.ide.fxml.compiler.ReflectionHelper.* +import java.util.Set +import java.util.HashSet + +class FXGraphJavaGenerator {
+ int varIndex = 0;
+ Set<String> extraImports = new HashSet;
+
+ def getVarIndex() {
+ varIndex = varIndex + 1;
+ return varIndex;
+ }
+
+ def generate(Model model) '''
+ package «model.package.name»;
+
+ import org.eclipse.fx.core.fxml.FXMLDocument;
+ import java.util.ResourceBundle;
+
+ «var content = generateElementDef("root", model.componentDef.rootNode)»
+
+ «FOR i : model.imports»
+ import «i.importedNamespace»;
+ «ENDFOR»
+
+ «FOR i : extraImports»
+ import «i»;
+ «ENDFOR»
+
+ public class «model.componentDef.name» extends FXMLDocument<«model.componentDef.rootNode.type.simpleName»> {
+ public «model.componentDef.rootNode.type.simpleName» load(ResourceBundle bundle) {
+ «content»
+ return root;
+ }
+ }
+ '''
+
+ def CharSequence generateElementDef(String name, Element element) '''
+ «IF element.type.needsBuilder»
+ «element.type.simpleName» «name»;
+ «element.type.simpleName»Builder «name»Builder = «element.type.simpleName»Builder.create();
+ «val dummy = extraImports.add(element.type.qualifiedName+"Builder")»
+ «FOR p : element.properties»
+ «IF p.value instanceof SimpleValueProperty»
+ «name»Builder.«p.name»(«(p.value as SimpleValueProperty).simpleAttributeValue»);
+ «ENDIF»
+ «ENDFOR»
+ «name» = «name»Builder.build();
+ «ELSE»
+ «element.type.simpleName» «name» = new «element.type.simpleName»();
+ «FOR p : element.properties»
+ «IF p.value instanceof SimpleValueProperty»
+ «name».set«p.name.toFirstUpper»(«(p.value as SimpleValueProperty).simpleAttributeValue»);
+ «ELSEIF p.value instanceof Element»
+ {
+ «val varName = 'e_'+getVarIndex»
+ «generateElementDef(varName,p.value as Element)»
+ «name».set«p.name.toFirstUpper»(«varName»);
+ «staticProperties(varName,p.value as Element)»
+ }
+ «ELSEIF p.value instanceof ListValueProperty»
+ «FOR l : (p.value as ListValueProperty).value»
+ {
+ «val i = getVarIndex»
+ «val varName = 'e_'+i»
+ «IF l instanceof Element»
+ «generateElementDef(varName,l as Element)»
+ «name».get«p.name.toFirstUpper»().add(«varName»);
+ «staticProperties(varName,l as Element)»
+ «ENDIF»
+ }
+ «ENDFOR»
+ «ENDIF»
+ «ENDFOR»
+ «FOR p : element.defaultChildren»
+ {
+ «val i = getVarIndex»
+ «val varName = 'e_'+i»
+ «generateElementDef(varName,p)»
+ «name».get«element.type.defaultAttribute.toFirstUpper»().add(«varName»);
+ }
+ «ENDFOR»
+ «ENDIF»
+ '''
+
+ def staticProperties(String name, Element element) '''
+ «FOR prop : element.staticProperties»
+ «val type = prop.type»
+ «IF prop.value instanceof SimpleValueProperty»
+ «IF (prop.value as SimpleValueProperty).stringValue != null»
+ «val enumType = ReflectionHelper.getEnumType(type, prop.name, true)»
+ «IF enumType != null»
+ «type.simpleName».set«prop.name.toFirstUpper»(«name»,«enumType».«(prop.value as SimpleValueProperty).stringValue»);
+ «ELSE»
+ «type.simpleName».set«prop.name.toFirstUpper»(«name»,«(prop.value as SimpleValueProperty).simpleAttributeValue»);
+ «ENDIF»
+ «ELSE»
+ «type.simpleName».set«prop.name.toFirstUpper»(«name»,«(prop.value as SimpleValueProperty).simpleAttributeValue»);
+ «ENDIF»
+ «ELSEIF prop.value instanceof Element»
+ «val varname = 'e_'+getVarIndex»
+ «generateElementDef(varname,prop.value as Element)»
+ «type.simpleName».set«prop.name.toFirstUpper»(«name»,«varname»);
+ «ENDIF»
+ «ENDFOR»
+ '''
+
+ def simpleAttributeValue(SimpleValueProperty value) {
+ if( value.stringValue != null ) {
+ return '"' + value.stringValue + '"';
+ } else if( value.booleanValue != null ) {
+ return value.booleanValue;
+ } else if( value.number != null ) {
+ if( value.negative ) {
+ return "-" + value.number;
+ } else {
+ return value.number;
+ }
+ }
+ }
+
+ def type(StaticValueProperty prop) {
+ var el = prop.eContainer
+ while( el.eContainer != null ) {
+ if( el.eContainer instanceof Element ) {
+ val e = el.eContainer as Element
+ return e.type;
+ }
+ el = el.eContainer;
+ }
+ }
+}
\ No newline at end of file diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ReflectionHelper.xtend b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ReflectionHelper.xtend new file mode 100644 index 000000000..a8d403f66 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ReflectionHelper.xtend @@ -0,0 +1,30 @@ +package org.eclipse.fx.ide.fxml.compiler + +import org.eclipse.xtext.common.types.JvmTypeReference +import javafx.beans.DefaultProperty + +class ReflectionHelper { + def static getEnumType(JvmTypeReference type, String attributeName, boolean layoutConstraint) { + val c = Class::forName(type.qualifiedName, false, typeof(ReflectionHelper).getClassLoader()) + val methodName = "set"+attributeName.toFirstUpper + val m = c.methods.findFirst[name == methodName && (parameterCount == 1 || (layoutConstraint && parameterCount == 2) )] + + return m?.parameterTypes.get(if (layoutConstraint) 1 else 0)?.name + } + + def static needsBuilder(JvmTypeReference type) { + val c = Class::forName(type.qualifiedName, false, typeof(ReflectionHelper).getClassLoader()) + return c.constructors.findFirst[parameterCount==0] == null + } + + def static defaultAttribute(JvmTypeReference type) { + var c = Class::forName(type.qualifiedName, false, typeof(ReflectionHelper).getClassLoader()) + var DefaultProperty p + do { + p = c.getAnnotation(typeof(DefaultProperty)) + c = c.superclass; + } while( p == null && c != typeof(Object) ) + + return p.value; + } +}
\ No newline at end of file diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/CompilerTask.java b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/CompilerTask.java new file mode 100644 index 000000000..b4be8ac0e --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/CompilerTask.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2013 BestSolution.at and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + *******************************************************************************/ +package org.eclipse.fx.ide.fxml.compiler.ant; + +import java.io.File; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.eclipse.fx.ide.fxml.compiler.FXGraphCompiler; + +import com.google.inject.Injector; + +public abstract class CompilerTask extends Task { + private String srcDir; + private String destDir; + private final boolean fxgraph; + + public CompilerTask(boolean fxgraph) { + this.fxgraph = fxgraph; + } + + public void setSourceDir(String srcDir) { + this.srcDir = srcDir; + } + + public String getSrcDir() { + return srcDir; + } + + public void setDestDir(String destDir) { + this.destDir = destDir; + } + + public String getDestDir() { + return destDir; + } + + @Override + public void execute() throws BuildException { + File f = new File(getLocation().getFileName()); + File sourceDirectory = new File(f.getParentFile(), srcDir); + File outDirectory = new File(f.getParentFile(), destDir); + + final String sourcePrefix = sourceDirectory.getAbsolutePath(); + final String outPrefix = outDirectory.getAbsolutePath(); + Injector injector = new org.eclipse.fx.ide.fxgraph.FXGraphStandaloneSetupGenerated().createInjectorAndDoEMFRegistration(); + final FXGraphCompiler compiler = injector.getInstance(FXGraphCompiler.class); + + try { + Files.walkFileTree(Paths.get(sourceDirectory.getAbsolutePath()), new FileFinder(new Callable() { + + @Override + public void call(String file) { + System.out.println("Compiling " + file); + compiler.compile(file, sourcePrefix, outPrefix); + } + })); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + class FileFinder extends SimpleFileVisitor<Path> { + private final Callable runnable; + + public FileFinder(Callable runnable) { + this.runnable = runnable; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if ((file.toFile().getAbsolutePath().endsWith(".fxml") && !fxgraph) || (file.toFile().getAbsolutePath().endsWith(".fxgraph") && fxgraph)) { + runnable.call(file.toFile().getAbsolutePath()); + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + } + + public interface Callable { + public void call(String file); + } +}
\ No newline at end of file diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/FXGraphCompilerTask.java b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/FXGraphCompilerTask.java new file mode 100644 index 000000000..68c8bd1b4 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/FXGraphCompilerTask.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2013 BestSolution.at and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + *******************************************************************************/ +package org.eclipse.fx.ide.fxml.compiler.ant; + + +public class FXGraphCompilerTask extends CompilerTask { + + public FXGraphCompilerTask() { + super(true); + } + +}
\ No newline at end of file diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/FXMLCompilerTask.java b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/FXMLCompilerTask.java new file mode 100644 index 000000000..ea1de0cd6 --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/src/org/eclipse/fx/ide/fxml/compiler/ant/FXMLCompilerTask.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2013 BestSolution.at and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + *******************************************************************************/ +package org.eclipse.fx.ide.fxml.compiler.ant; + + +public class FXMLCompilerTask extends CompilerTask { + + public FXMLCompilerTask() { + super(false); + } + +}
\ No newline at end of file diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/xtend-gen/.gitignore b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/xtend-gen/.gitignore new file mode 100644 index 000000000..571ee510a --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/xtend-gen/.gitignore @@ -0,0 +1 @@ +/org diff --git a/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/xtend-gen/donotdelete b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/xtend-gen/donotdelete new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/bundles/tooling/org.eclipse.fx.ide.fxml.compiler/xtend-gen/donotdelete |