ScriptPublisher - helps you auto-deploy and reload a script

Have you created a useful tool? or Do you want to get help building one? This is the right place!
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
Hyrelius
Posts: 257
Joined: Thu Dec 16, 2010 5:16 am

ScriptPublisher - helps you auto-deploy and reload a script

Post by Hyrelius »

Hey there!

How many times you reload your script during development? If the answer is many, I suggest you take a look at this little tool.

ScriptPublisher helps you copy over the files from your project directory to the corresponding script directory on your L2J-driven server and reload it using telnet commands. For telnet to work properly, it requires telnet to be activated in Telnet.properties.

ScriptPublisher works based on 3 tasks:
- collect the arguments passed to it and perform a simple sanity check
- execute the copy task
- execute the telnet task if the copy task was successful

I defined an external tool in Eclipse. This tool is a launch configuration.
There you specify the location (in this case you need to specify the location to the java.exe file, which will execute the jar), working directory (where your ScriptPublisher.jar file is) and arguments. In my case the arguments look like this:

Code: Select all

-jar ScriptPublisher.jar script ${project_source} ${server_source} custom\scripts\communityboard CommunityBoardScript.java true 127.0.0.1 54321
  • -jar means, that we are executing a jar file
  • ScriptPublisher.jar is the program itself (it's a runnable jar, which give you further information on command line)
  • script states what kind of element will be reloaded; currently "script" is the only value allowed, but "skills", "items" etc. might be added later in order to ease the reloading of corresponding XMLs
  • {project_source} is the project folder, which contains your scripts in question (e.g. C:\dev\ScriptProject\src)
  • {server_source} is the server root folder; further folders are appended automatically
  • custom\scripts\communityboard folder structure for your script (should be the same as the package your script is in)
  • CommunityBoardScript.java filename of the class, which extends L2Script and contains main method; this is used when reloading script via telnet
  • true means, that we want to reload HTML files afterwards, too
  • 127.0.0.1 telnet host
  • 54321 telnet port
    you may append a password if you have one set for telnet access
ScriptPublisher makes use of several apache-libraries. It does include the classes and license agreements in the jar.

Further more ScriptPublisher has a few JUnit4 tests - they ensure the functionality of the Task classes. I use Mockito for easier mocking and verification of objects - however: the coverage is rather bad, because I was rather lazy. I still hope it works for you.
If you need more in-depth help, try executing "java -jar ScriptPublisher.jar" on the command line. It will give you some more information about the arguments as well as the values.

I also include a simple "how-to-use" file as well as an example launch configuration.

Feel free to ask any questions you have.

Questions:
  • does that work on Linux, too? No as I screwed up the slashes - might correct that later if someone wants to use it on a linux-based machine.
  • I don't use telnet - can this program still be useful for me? Yes! It can copy the files and folders for you. For that to work, just enter reload type, project- and server-source folders and the script folder and don't enter telnet-related information at all.
Download (version will be updated here):
GIT-repository: https://github.com/divStar/ScriptPublisher
binary version: https://github.com/divStar/ScriptPublis ... lisher.jar (click on "Raw" to download)
Last edited by Hyrelius on Fri Jan 10, 2014 6:55 am, edited 1 time in total.
Image
I don't mind helping - however: I only do so if I want to.
No support for other server packs than L2J.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: ScriptPublisher - helps you auto-deploy and reload a scr

Post by jurchiks »

Just use Linux directory separator, it works on both Windows and Linux.
Seems like a github repo for this would be just right.
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: ScriptPublisher - helps you auto-deploy and reload a scr

Post by UnAfraid »

Code: Select all

File.pathSeparator
Image
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: ScriptPublisher - helps you auto-deploy and reload a scr

Post by jurchiks »

http://stackoverflow.com/questions/5971 ... hseparator
File.pathSeparator is used to separate individual file paths in a list of file paths. Consider on windows, the PATH environment variable. You use a ; to separate the file paths so on Windows File.pathSeparator would be ;.

File.separator is either / or \ that is used to split up the path to a specific file. For example on Windows it is \ or C:\Documents\Test
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Hyrelius
Posts: 257
Joined: Thu Dec 16, 2010 5:16 am

Re: ScriptPublisher - helps you auto-deploy and reload a scr

Post by Hyrelius »

Thanks. Fixed and now it's on GitHub.
Image
I don't mind helping - however: I only do so if I want to.
No support for other server packs than L2J.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: ScriptPublisher - helps you auto-deploy and reload a scr

Post by jurchiks »

tools/mondial/scriptpublisher/AutomatedTelnetClient.java

Code: Select all

public String readUntil(final String... patterns) {    if (patterns == null) { // just in case        return null;    }    return readUntil(patterns, false);}
Ellipsis is syntactic sugar for array, so no matter if you supply one or more elements, Java will create an array.
If you use this, no need for readUntil(final String pattern).

There's no need for try/catch in sendCommand, because write catches its exceptions and doesn't re-throw them.

tools/mondial/scriptpublisher/tasks/ArgumentsTask.java
mapCopyParameters(final String[] args)

Code: Select all

StringBuilder sb = new StringBuilder(args[1]); if (!sb.toString().endsWith(File.separator)) {    sb.append(File.separator);} projectFolder = sb.toString(); sb.replace(0, sb.length(), args[2]); // or just new StringBuilder if (!sb.toString().endsWith(File.separator)) {    sb.append(File.separator);} serverFolder = sb.toString(); sb.replace(0, sb.length(), args[3]); if (!sb.toString().endsWith(File.separator)) {    sb.append(File.separator);} scriptFolder = sb.toString();
I know this is longer code, but at least you don't call StringBuilder.toString() every time you call getProjectFolder()/getServerFolder()/getScriptFolder().

tasks/TelnetTask.java line 48:
final String response = automatedTelnetClient.readUntil("\r\n");
Won't work if both boxes are using Linux OS. Maybe there's some way to find out the destination OS?
Anyway, using just "\n" would work for both Windows and Linux, I have been using scripts with "\n" on a Windows box for a long time. You might need to check if pre-last character is "\r", but at least it would work.
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Hyrelius
Posts: 257
Joined: Thu Dec 16, 2010 5:16 am

Re: ScriptPublisher - helps you auto-deploy and reload a scr

Post by Hyrelius »

Thanks.

Will look into the readUntil(String pattern) method - I think it might've been not used at all, but I didn't want to remove it, because it might be used.

As to the StringBuilder: it doesn't take that long to do a .toString() on a StringBuilder. Also it's much faster than e.g. using a + to create a String. Since the String might change (at least in theory), I decided to always return the newest String. The overhead of keeping the StringBuilders separate isn't that big either, which is why I wouldn't reuse a StringBuilder.

As to the \r\n Problem: yes, I guess you are right. I could go with just \n. Haven't really bothered trying it out on Linux (as it (still) says in the first post: it might not work on Linux).
Image
I don't mind helping - however: I only do so if I want to.
No support for other server packs than L2J.
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: ScriptPublisher - helps you auto-deploy and reload a scr

Post by jurchiks »

It depends on whether or not getProjectFolder()/getServerFolder()/getScriptFolder() are called often.
If they are called only 1 or 2 times, then there isn't much difference either way, but if they are called more often, it'd be better to save the final Strings, unless they are being changed frequently (but it doesn't look like they are).
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Post Reply