Permalink
Browse files

package name changes, added more static convert functions to GrooScript

  • Loading branch information...
chiquitinxx committed Nov 14, 2012
1 parent 1811f71 commit 70ee4f54a3578137183d0a4533dbceb3aee33869
Showing with 201 additions and 64 deletions.
  1. +75 −3 build.gradle
  2. +81 −0 src/main/groovy/org/grooscript/GrooScript.groovy
  3. +4 −4 src/main/groovy/org/{yila/gscript → grooscript}/GsConverter.groovy
  4. +2 −2 src/main/groovy/org/{yila/gscript → grooscript}/asts/GsNative.groovy
  5. +2 −2 src/main/groovy/org/{yila/gscript → grooscript}/asts/GsNotConvert.groovy
  6. +1 −1 src/main/groovy/org/{yila/gscript → grooscript}/asts/Native.groovy
  7. +1 −1 src/main/groovy/org/{yila/gscript → grooscript}/asts/NotConvert.groovy
  8. +3 −3 src/main/groovy/org/{yila/gscript → grooscript}/test/TestJs.groovy
  9. +1 −1 src/main/groovy/org/{yila/gscript → grooscript}/util/GsConsole.groovy
  10. +3 −3 src/main/groovy/org/{yila/gscript → grooscript}/util/Util.groovy
  11. +0 −24 src/main/groovy/org/yila/gscript/GrooScript.groovy
  12. +2 −2 src/test/groovy/org/{yila/gscript → grooscript}/TestAdvanced.groovy
  13. +2 −2 src/test/groovy/org/{yila/gscript → grooscript}/TestContributors.groovy
  14. +2 −3 src/test/groovy/org/{yila/gscript → grooscript}/TestConversionFails.groovy
  15. +2 −3 src/test/groovy/org/{yila/gscript → grooscript}/TestConvertBase.groovy
  16. +2 −2 src/test/groovy/org/{yila/gscript → grooscript}/TestGroovyBasics.groovy
  17. +4 −5 src/test/groovy/org/{yila/gscript → grooscript}/ast/TestAst.groovy
  18. +1 −1 src/test/groovy/org/{yila/gscript → grooscript}/test/TestJavaScriptEngine.groovy
  19. +11 −0 src/test/resources/TestFileConversion.groovy
  20. +1 −1 src/test/resources/asts/NotConvert.groovy
  21. +1 −1 src/test/resources/asts/native.groovy
View
@@ -1,6 +1,12 @@
apply plugin: 'idea'
apply plugin: 'groovy'
-//apply plugin: 'application'
+apply plugin: 'maven'
+apply plugin: 'signing'
+
+//name = 'grooscript'
+group = 'org.grooscript'
+version = '0.1'
+
//mainClassName = 'org.yila.gscript'
@@ -31,12 +37,79 @@ dependencies {
//testCompile fileTree(dir: 'lib', include: '*.jar')
}
+//Sonar repository stuff
+
+task javadocJar(type: Jar, dependsOn: javadoc) {
+ classifier = 'javadoc'
+ from 'build/docs/javadoc'
+}
+
+task sourcesJar(type: Jar) {
+ from sourceSets.main.allSource
+ classifier = 'sources'
+}
+
+artifacts {
+ archives jar
+ archives javadocJar
+ archives sourcesJar
+}
+
+signing {
+ sign configurations.archives
+}
+
+uploadArchives {
+ repositories {
+ mavenDeployer {
+ beforeDeployment { MavenDeployment deployment -> signPom(deployment) }
+
+ repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
+ authentication(userName: sonatypeUsername, password: sonatypePassword)
+ }
+
+ pom.project {
+ name 'grooscript'
+ packaging 'jar'
+ description 'GrooScript converts your groovy code to javascript'
+ url 'http://grooscript.org/'
+
+ scm {
+ url 'scm:git@github.com:chiquitinxx/grooscript.git'
+ connection 'scm:git@github.com:chiquitinxx/grooscript.git'
+ developerConnection 'scm:git@github.com:chiquitinxx/grooscript.git'
+ }
+
+ licenses {
+ license {
+ name 'The Apache Software License, Version 2.0'
+ url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
+ distribution 'repo'
+ }
+ }
+
+ developers {
+ developer {
+ id 'chiquitinxx'
+ name 'Jorge Franco'
+ }
+ }
+ }
+ }
+ }
+}
+//End Sonar
+
+//Copy jar, js file, and examples to web directory, defined at start
task copyToGscriptWeb(dependsOn: build) << {
println "Copying $appName jar to $webDirJar ..."
copy {
into "$webDirJar"
from "build/libs"
include "**/*.jar"
+ rename {
+ return "grooscript.jar"
+ }
}
println "Copying $appName jsFiles to $webDirJs ..."
@@ -56,6 +129,5 @@ task copyToGscriptWeb(dependsOn: build) << {
return "${key}.groovy"
}
}
- }
-
+ }
}
@@ -0,0 +1,81 @@
+package org.grooscript
+
+/**
+ * JFL 09/11/12
+ */
+class GrooScript {
+
+ def private static GsConverter converter
+
+ /**
+ * Get a GsConverter singleton
+ * @return
+ */
+ def static GsConverter getConverter() {
+ if (!converter) {
+ converter = new GsConverter()
+ }
+ converter
+ }
+
+ /**
+ * Convert a piece of groovy code to javascript
+ * @param String text groovy code
+ * @return String javascript result code
+ * @throws Exception If conversion fails or text is null
+ */
+ def static convert(String text) {
+ if (text) {
+ return getConverter().toJs(text)
+ } else {
+ throw new Exception("Nothing to Convert.")
+ }
+ }
+
+ /**
+ * Converts from a source to destination, groovy files to javascript files
+ * Result files will be .js with same name that groovy file
+ * @param source path to directory with groovy files, or a groovy file path. Not recursive
+ * @param destination directory of .js files
+ * @throws Exception something fails
+ */
+ def static convert(String source, String destination) {
+ if (source && destination) {
+ File fSource = new File(source)
+ File fDestination = new File(destination)
+
+ if (fSource.exists() && fDestination.exists() && fDestination.isDirectory()) {
+ if (!fSource.isDirectory()) {
+ fileConvert(fSource,fDestination)
+ } else {
+ fSource.eachFile { file ->
+ if (file.isFile()) {
+ fileConvert(file,fDestination)
+ }
+ }
+ }
+ } else {
+ throw new Exception("Source and destination must exist, and destination must be a directory.")
+ }
+
+ } else {
+ throw new Exception("Have to define source and destination.")
+ }
+ }
+
+ def private static fileConvert(File source,File destination) {
+ if (source.isFile() && source.name.endsWith('.groovy')) {
+ //println 'Name file->'+source.name
+ def name = source.name.split(/\./)[0]
+ def jsResult = getConverter().toJs(source.text)
+
+ //println 'Result file->'+destination.path+System.getProperty('file.separator')+name+'.js'
+ def newFile = new File(destination.path+System.getProperty('file.separator')+name+'.js')
+ if (newFile.exists()) {
+ newFile.delete()
+ }
+ newFile.write(jsResult)
+ println 'Converted file: '+newFile.name
+ }
+ }
+}
@@ -1,11 +1,11 @@
-package org.yila.gscript
+package org.grooscript
import org.codehaus.groovy.ast.builder.AstBuilder
import org.codehaus.groovy.control.CompilePhase
import org.codehaus.groovy.ast.stmt.*
import org.codehaus.groovy.ast.expr.*
-import org.yila.gscript.util.Util
-import org.yila.gscript.util.GsConsole
+import org.grooscript.util.Util
+import org.grooscript.util.GsConsole
import org.codehaus.groovy.ast.*
/**
@@ -513,7 +513,7 @@ class GsConverter {
node?.methods?.each { MethodNode method ->
if (!haveAnnotationNonConvert(method.annotations)) {
if (method.isStatic()) {
- println 'Static!'
+ //println 'Static!'
processBasicFunction("${translateClassName(node.name)}.${method.name}",method,false)
}
}
@@ -1,4 +1,4 @@
-package org.yila.gscript.asts
+package org.grooscript.asts
import org.codehaus.groovy.transform.GroovyASTTransformationClass
@@ -13,6 +13,6 @@ import java.lang.annotation.Target
@Retention(RetentionPolicy.SOURCE)
@Target([ElementType.METHOD])
//@GroovyASTTransformationClass(["Nativing"])
-@GroovyASTTransformationClass(['org.yila.gscript.asts.Native'])
+@GroovyASTTransformationClass(['org.grooscript.asts.Native'])
public @interface GsNative {
}
@@ -1,4 +1,4 @@
-package org.yila.gscript.asts
+package org.grooscript.asts
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
@@ -12,6 +12,6 @@ import org.codehaus.groovy.transform.GroovyASTTransformationClass
@Retention(RetentionPolicy.SOURCE)
@Target([ElementType.METHOD,ElementType.TYPE])
//@GroovyASTTransformationClass(["Nativing"])
-@GroovyASTTransformationClass(['org.yila.gscript.asts.NotConvert'])
+@GroovyASTTransformationClass(['org.grooscript.asts.NotConvert'])
public @interface GsNotConvert {
}
@@ -1,4 +1,4 @@
-package org.yila.gscript.asts
+package org.grooscript.asts
import org.codehaus.groovy.ast.ASTNode
import org.codehaus.groovy.control.CompilePhase
@@ -1,4 +1,4 @@
-package org.yila.gscript.asts
+package org.grooscript.asts
import org.codehaus.groovy.transform.GroovyASTTransformation
import org.codehaus.groovy.control.CompilePhase
@@ -1,10 +1,10 @@
-package org.yila.gscript.test
+package org.grooscript.test
import javax.script.ScriptEngineManager
import javax.script.ScriptEngine
import javax.script.Bindings
-import org.yila.gscript.util.GsConsole
-import org.yila.gscript.util.Util
+import org.grooscript.util.GsConsole
+import org.grooscript.util.Util
/**
* JFL 27/08/12
@@ -1,4 +1,4 @@
-package org.yila.gscript.util
+package org.grooscript.util
/**
* JFL 27/08/12
@@ -1,7 +1,7 @@
-package org.yila.gscript.util
+package org.grooscript.util
-import org.yila.gscript.test.TestJs
-import org.yila.gscript.GsConverter
+import org.grooscript.test.TestJs
+import org.grooscript.GsConverter
/**
* JFL 29/08/12
@@ -1,24 +0,0 @@
-package org.yila.gscript
-
-/**
- * JFL 09/11/12
- */
-class GrooScript {
-
- def static GsConverter converter
-
- def static GsConverter getConverter() {
- if (!converter) {
- converter = new GsConverter()
- }
- converter
- }
-
- def static convert(String text) {
- if (text) {
- return getConverter().toJs(text)
- } else {
- throw new Exception("Nothing to Convert.")
- }
- }
-}
@@ -1,6 +1,6 @@
-package org.yila.gscript
+package org.grooscript
-import org.yila.gscript.test.TestJs
+import org.grooscript.test.TestJs
import spock.lang.Specification
/**
@@ -1,7 +1,7 @@
-package org.yila.gscript
+package org.grooscript
import spock.lang.Specification
-import org.yila.gscript.test.TestJs
+import org.grooscript.test.TestJs
/**
* First test for converts groovy code to javascript code
@@ -1,8 +1,7 @@
-package org.yila.gscript
+package org.grooscript
-import org.yila.gscript.GsConverter
import spock.lang.Specification
-import org.yila.gscript.test.TestJs
+import org.grooscript.test.TestJs
/**
* First test for converts groovy code to javascript code
@@ -1,8 +1,7 @@
-package org.yila.gscript
+package org.grooscript
import spock.lang.Specification
-import org.yila.gscript.GsConverter
-import org.yila.gscript.util.Util
+import org.grooscript.util.Util
/**
* Tests for converter initialization and run modes
@@ -1,6 +1,6 @@
-package org.yila.gscript
+package org.grooscript
-import org.yila.gscript.test.TestJs
+import org.grooscript.test.TestJs
import spock.lang.Specification
/**
@@ -1,9 +1,8 @@
-package org.yila.gscript.ast
+package org.grooscript.ast
-import org.yila.gscript.GsConverter
-import org.yila.gscript.test.TestJs
+import org.grooscript.test.TestJs
import spock.lang.Specification
-import org.yila.gscript.util.Util
+import org.grooscript.util.Util
/**
* First test for converts groovy code to javascript code
@@ -39,7 +38,7 @@ class TestAst extends Specification {
def 'test GsNative' () {
when:
- def result = readAndConvert('asts/Native',true)
+ def result = readAndConvert('asts/Native',false)
then:
!result.assertFails
@@ -1,4 +1,4 @@
-package org.yila.gscript.test
+package org.grooscript.test
import spock.lang.Specification
import javax.script.ScriptEngine
@@ -0,0 +1,11 @@
+import org.grooscript.GrooScript
+/**
+ * JFL 14/11/12
+ */
+new File('newDir').mkdir()
+
+GrooScript.convert('staticRealm.groovy','newDir')
+
+GrooScript.convert('.','newDir')
+
+new File('newDir').deleteDir()
Oops, something went wrong.

0 comments on commit 70ee4f5

Please sign in to comment.