import org.apache.commons.lang.builder.ReflectionToStringBuilder
variable= new ComplexObject()
println new ReflectionToStringBuilder( variable).toString()
#!/usr/bin/env groovy
// file: FtpSvr.groovy
/*
Laurence Toenjes Jan 12, 2013
Standalone Groovy ftp server script (no jars to download if Groovy is
properly installed).
The default user is guest with password of guest
and the ftp home/base directory is the home folder of the account
running this script.
A root account is also created with the ftp home/base dir set to /
and the password is root (for root to fully work you would obviously
have to run it under an account with expanded file permissions).
Optional command line args:
arg0 defaults to port 8021.
arg1 (ftp base dir) defaults to the home directory of the user running this script.
*/
// See http://mina.apache.org/ftpserver/ for more details.
// for OS X/*nix
// don't forget to do: chmod +x FtpServer.groovy
// also run as sudo ./FtpSvr.groovy for when using a port number < 1024
@Grapes([
@Grab(group='org.apache.ftpserver', module='ftpserver-core', version='1.0.6')
, @Grab(group='ch.qos.logback', module='logback-classic', version='1.0.9')
])
import org.apache.ftpserver.FtpServerFactory;
import org.apache.ftpserver.FtpServer;
import org.apache.ftpserver.listener.ListenerFactory;
import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory;
import org.apache.ftpserver.usermanager.SaltedPasswordEncryptor;
import org.apache.ftpserver.usermanager.impl.BaseUser;
import org.apache.ftpserver.ftplet.UserManager;
import org.apache.ftpserver.ftplet.Authority;
import org.apache.ftpserver.usermanager.impl.WritePermission;
import java.util.Properties;
public class FtpSvr {
def go(String[] args) {
String ftpUsersPropFileName = "FtpSvrUsers.properties"
int defaultPort = 8021
String userHome = System.properties.'user.home';
String homeDir = args.size()>=2 ? args[1].replace('~', userHome) : userHome ;
assert new File(homeDir).exists();
def gi = groovy.inspect.swingui.ObjectBrowser.&inspect; // for debug
int port = args.size()>=1 ? args[0].toInteger() : defaultPort ;
println "### ftp port : $port"
println "### ftp homeDir: $homeDir"
println ''
// the basics
// FtpServerFactory serverFactory = new FtpServerFactory();
// FtpServer server = serverFactory.createServer();
// server.start();
// setup users
PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
def myusersPropsFile = new File( ftpUsersPropFileName );
if ( !myusersPropsFile.exists() ) {
myusersPropsFile.createNewFile();
}
userManagerFactory.setFile( myusersPropsFile );
userManagerFactory.setPasswordEncryptor(new SaltedPasswordEncryptor());
UserManager um = userManagerFactory.createUserManager();
def users = []
users << [ uid:'guest', pwd:'guest', home:homeDir ]
users << [ uid:'root' , pwd:'root' , home:'/' ]
def addUser = { map ->
BaseUser user = new BaseUser();
user.setName( map.uid );
user.setPassword( map.pwd );
user.setHomeDirectory( map.home );
List<Authority> auths = new ArrayList<Authority>();
Authority auth = new WritePermission();
auths.add(auth);
user.setAuthorities(auths);
// gi user;
// gi user.getAuthorities();
um.save(user);
}
users.each { itUserMap -> addUser( itUserMap ) }
FtpServerFactory serverFactory = new FtpServerFactory();
serverFactory.setUserManager( um );
ListenerFactory factory = new ListenerFactory();
// set the port of the listener
factory.setPort( port );
// replace the default listener
serverFactory.addListener("default", factory.createListener());
// start the server
FtpServer server = serverFactory.createServer();
// groovy.inspect.swingui.ObjectBrowser.inspect( server );
// groovy.inspect.swingui.ObjectBrowser.inspect( server.userManager );
// gi server.userManager.getAllUserNames() as List;
server.start();
}
public static void main(String[] args) {
def mo = new FtpSvr();
mo.go(args)
}
}
/*
File : helperSvn.gradle
Author: Laurence Toenjes
Date : 3/31/2013
Example of how to use:
1. Put this file in the same directory as your build.gradle file.
2. Near the very top of your build.gradle source file add this line:
apply from: 'helperSvn.gradle'
3. You can now do svn commands like:
doSvnMain( 'export', 'http://svn.codehaus.org/gmod/gsql/tags/gsql-1.5.0/', 'build/svnExport' );
doSvnMain( 'help' );
... etc. ...
Note: each command line arg you would normally supply to a svn command should be an arg passed to doSvnMain
(since we are not using the OS shell you should probably not have to double quote any of the args).
*/
import org.tmatesoft.svn.cli.SVN;
buildscript {
repositories { mavenCentral() }
dependencies { classpath( 'org.tmatesoft.svnkit:svnkit:1.7.8', 'org.tmatesoft.svnkit:svnkit-cli:1.7.8' ) }
}
project.ext.SVN = SVN; /* for certain scenarios might be useful to share this project var */
def _disableSystemExitCall = {
System.setSecurityManager(
new SecurityManager() {
@Override public void checkPermission(java.security.Permission perm) {}
@Override public void checkExit(int status) { throw new SecurityException(); }
}
);
};
def _enableSystemExitCall = { System.setSecurityManager(null); };
/* for certain scenarios might be useful to share these closures with build */
project.ext.disableSystemExitCall = _disableSystemExitCall;
project.ext.enableSystemExitCall = _enableSystemExitCall;
/* key method/closure - used as: doSvnMain( 'your', 'svn', 'args', 'go', 'here' ); */
project.ext.doSvnMain = { String... aSvnArgs ->
_disableSystemExitCall(); /* stop SVN.main from doing a System.exit call */
try {
SVN.main( aSvnArgs as String[] );
} finally {
_enableSystemExitCall();
}
} ;
def c
c = {println "Dir ${it.canonicalPath}"; it.eachDir(c); it.eachFile{println "File ${it.canonicalPath}"; it.delete()}}
c new File("test")