Archive for August, 2009

scp2here: scp command to here

I usually need to scp stuff from/over-to servers on a regular basis. And here is a function in .bashrc that I use:

#function to get the scp path to here
function scp2here
{
    user=`whoami`
    server=`hostname`
    pathToHere=`pwd`

     output=$user"@"$server":"$pathToHere

    if [ ! -z "$1" ]
    then
        output=$output"/"$1
    fi

    echo $output
}

This function prints out the scp command argument to copy a file/directory to a location.

Examples

Then to copy something to a target server where I have scp2here, I can cd to the target directory and do this:

srasul@some.cool.host ~ $ scp2here
srasul@some.cool.host.com:/home/srasul
...
srasul@another.cooler.host ~ $ scp bigassfile.txt srasul@some.cool.host.com:/home/srasul

Or if I want to copy a file from a location that has scp2here:

srasul@some.cool.host ~ $ scp2here somefile.txt
srasul@some.cool.host.com:/home/srasul/somefile.txt
...
srasul@another.cooler.host ~ $ scp srasul@some.cool.host.com:/home/srasul/somefile.txt .


                    

How to import java projects with eclipse JDT

During the coding of my Bulk Import Plugin, I had the needs to import java projects into a workspace via code. Via Eclipse’s API to be precise. After reading the code of what happens when you import a project, here is the critical bit of code:

Runnable runnable = new Runnable() {
    public void run() {
    try {
        IPath projectDotProjectFile = new Path(pathToMyProjectDir+ "/.project");
            IProjectDescription projectDescription =
                workspace.loadProjectDescription(projectDotProjectFile);
            IProject project = workspace.getRoot().
                getProject(projectDescription.getName());
            JavaCapabilityConfigurationPage.createProject(project, projectDescription
                .getLocationURI(), progressMonitor);
        }
        catch(CoreException e) {
            e.printStackTrace();
        }
    }
};

// and now get the workbench to do the work
final IWorkbench workbench = PlatformUI.getWorkbench();
workbench.getDisplay().syncExec(runnable);