HelloWorld
// In commandline
echo out("HelloWorld"); | "%JAVA_HOME%/bin/java" -classpath "release\bin\jgazm.jar" com.crazedout.jgazm.JGazm -stdin
// In jgazm code.
out("HelloWorld");
Handle exception in main code:
Integer.parseInt("a");
@exception {
alert(ex.getMessage());
}
Read file, filter word and save results to file
String file = readFile("release\\setup.bat");
String found = filter(file,"@echo");
writeFile(new File("result.txt"),found);
Some input stuff
@import javax.swing.JOptionPane;
String[] choices = {"Beginner","Standard","Expert"};
String choice = showChoiceDialog("Choose mode", choices);
alert("Your choice: " + choice);
String name = JOptionPane.showInputDialog(null,"Enter name");
alert("Your name is:" + name);
Make executable jar file:
File dir = new File(MYCLASSDIR);
@string(name="manifest"){
Manifest-Version: 1.0
Built-By: Fredrik
Build-Jdk: 1.7.0_45
Created-By: Apache Maven 3.1.1
Main-Class: com.crazedout.jgazm.JGazm
Archiver-Version: Plexus Archiver
}
out(MYCLASSDIR + File.separatorChar + "META-INF" + File.separatorChar + "MANIFEST.MF");
(new File(MYCLASSDIR + File.separatorChar + "META-INF")).mkdirs();
if(writeFile(new File(MYCLASSDIR + File.separatorChar + "META-INF" + File.separatorChar + "MANIFEST.MF"),manifest)){
out(dir.getParentFile().getAbsolutePath() + File.separatorChar + "myjar.jar");
zip(dir,new File(dir.getParentFile().getAbsolutePath() + File.separatorChar + "myjar.jar"));
}else{
out("Bad file");
}
@exception {
alert(ex.getMessage());
}
FTP Upload:
@include "./lib/FTP.jgazm"
FTP ftp = new FTP("ftp.company.com","user","passwd");
out("Connected to:" + "ftp.company.com");
int n = 0;
if(ftp.putBinaryFile("/downloads", file1)){
n++;
}
if(ftp.putBinaryFile("/downloads", file2)){
n++;
}
alert((n + " files uploaded ok"));
ftp.logout();
@exception {
errorAlert("Err",ex.getMessage());
}
jGazm setup script
@import java.io.*;
@classpath "./bin/jgazm.jar";
@global File bin = new File(System.getProperty("jgazm.bin"));
@global File home = bin.getParentFile().getParentFile();
@global File props = new File(System.getProperty("jgazm.props"));
@string(name="bat"){
\@echo off
REM %JAVA_HOME% must point to current JDK.
set JAVA_HOME=$System.getProperty("java.home")$
REM Path to jgazm.jar file.
set JGAZ_BIN=$bin.getAbsolutePath()$
set JGAZ_HOME=$home.getAbsolutePath()$
REM Path to user imports file.
set JGAZM_PROPS=$props.getAbsolutePath()$
"%JAVA_HOME%/bin/java" -classpath "%JGAZ_BIN%" -Djgazm.home="%JGAZ_HOME%" -Djgazm.props="%JGAZM_PROPS%" com.crazedout.jgazm.JGazm %1 %2 %3 %4
}
writeLines(new File("jgazm.bat"),bat);
@string(name="bat2"){
\@echo off
REM %JAVA_HOME% must point to current JDK.
set JAVA_HOME=$System.getProperty("java.home")$
REM Path to jgazm.jar file.
set JGAZ_BIN=$bin.getAbsolutePath()$
set JGAZ_HOME=$home.getAbsolutePath()$
REM Path to user imports file.
set JGAZM_PROPS=$props.getAbsolutePath()$
"%JAVA_HOME%/bin/javaw" -classpath "%JGAZ_BIN%" -Djgazm.home="%JGAZ_HOME%" -Djgazm.props="%JGAZM_PROPS%" com.crazedout.jgazm.editor.Editor %1 %2 %3 %4
}
writeLines(new File("jgazmEdit.bat"),bat2);
String user = "jgazm.user.classpath=\njgazm.user.jdbc.driver=\njgazm.user.imports=\njgazm.workdir=" + home.getAbsolutePath() + File.separatorChar + "work";
writeLines(props,user.replace("\\","/"));
String dir = "current.file=" + (new File("helloworld.jgazm")).getAbsolutePath();
File edit = new File(home.getAbsolutePath() + File.separatorChar + "gazmedit.properties");
writeFile(edit,dir.replace("\\","/"));
String code = "@classpath .; //Set to current dir for example. Change to what ever classpath you want or remove.\r\n\r\n";
code += "@import javax.swing.*; // Not needed in this example but put here for reference.\r\n\r\n";
code +="/* execute the whole file or selected text as long as the texts is executable Java */\r\n";
code +="System.out.println(\"Hello from jGazm\"); // Select only this statement and hit CTRL+ENTER...\r\n\r\n";
code += "/* View the .setup file for more reference */\r\n\r\n";
code += "String hello = \"Hello World\";\r\n\r\n";
code += "MyClass mc = new MyClass(\"Ringo\");\r\n";
code += "out(mc.getName()); //com.crazedout.jgazm.Lang.out(Object out);\r\n";
code += "showMessage(hello);\r\n\r\n";
code +="@method /* Needed to identify method */\r\n";
code +="void showMessage(String msg){\r\n";
code +=" alert(msg); //com.crazedout.jgazm.Lang.alert(String msg);\r\n";
code +="}\r\n\r\n";
code += "@class /* Needed to identify inner class */\r\n";
code += "public class MyClass {\r\n";
code +=" String name;\r\n";
code +=" public MyClass(String name){\r\n";
code +=" this.name = name + \" Star\";\r\n";
code +=" }\r\n\r\n";
code +=" public String getName(){\r\n";
code +=" return this.name;\r\n";
code +=" }\r\n";
code +="}\r\n";
code += "@thread {\r\n";
code += " out(\"Executed inside a threads run() method\");\r\n";
code += "}\r\n\r\n";
code += "@exception {\r\n";
code += " out(\"Handle exception:\" + ex.getMessage());\r\n";
code += "}\r\n";
writeFile(new File("helloworld.jgazm"),code);
@import javax.swing.*;
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
if(JOptionPane.showConfirmDialog(null,"jGazm 1.2 setup complete. Start jGazm editor now?","Start editor?",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
com.crazedout.jgazm.editor.Editor.main(new String[0]);
}
|