Ubuntu insights, Programming in groovy, java, et als!

Wednesday, November 06, 2013

Fun with Git

Baby steps : 

1) create an account on github
2) create a git repository. Note down the repo URL.

Install git from terminal : 

sudo apt-get install git

Code Upload :
cd Scripts (or any new folder)
git init (local initialization. creates a local .git folder)
mkdir YourProjectDirectory (and add all source files under it).
git add .
git commit (commits the added source files to the local repository)
git remote add origin yourRepoURL (ex: https://github.com/vamsi-emani/pythonscripts.git)
git pull origin master (to sync with remote copy)
git push origin master (commits all the local changes to remote repository)

To delete a directory: 
git rm -r local-directory-name (recursively remove all local directory files)
git commit (commits to local repo)
git push origin master (commits to remote repo)

Checkout a branch : 
git checkout -b dev_temp origin/test
(creates a local branch dev_temp from remote branch named test)

List local branches only :
git branch

List local and remote branches : 
git branch -a

List all commits on all branches that aren't pushed yet
git log --branches --not --remotes

View commits on a branch (lists out the commits with their hashes)
git log dev_temp

View what's in a specific commit 
git log commit-hash

Remove untracked files
git clean -f --dry-run (to know the damage before doing the action)
git clean -f (to actually delete the untracked files)

Remove untracked files and directories
git clean -f -d

Thursday, July 04, 2013

SVN checkout and Sonar Ant Task Run

The ant script below checks out a java project from a given svn url and runs the downloaded source files against sonar.

Prerequisites: 

SVN Client installed
Included jars on classpath : ant.jar, sonar-ant-task-2.1.jar, svnjavahl.jar, svnClientAdapter.jar, svnant.jar

build.xml (Highlighted portions in red are to be set by user/setup dependent)

<?xml version="1.0" encoding="UTF-8"?>

<project name="Update" basedir="." default="update" xmlns:sonar="antlib:org.sonar.ant">

 <path id="svnant.classpath">
 <fileset dir="lib">    
  <include name="**/*.jar" />
 </fileset>
</path>

  <property name="project.svn.url" value="your-svn-url-of-project" />

  <!-- <taskdef resource="svntask.properties"  /> -->
 <taskdef  name="svn"  classname="org.tigris.subversion.svnant.SvnTask" classpathref="svnant.classpath"/>

  <target name="update">
    <svn>
      <checkout url="${project.svn.url}" revision="HEAD" destPath="MyProject" />
    </svn>
  </target>
   
<property name="sonar.jdbc.url" value="jdbc:h2:tcp://localhost:9092/sonar" />
<property name="sonar.jdbc.username" value="sonar" />
<property name="sonar.jdbc.password" value="sonar" />
<property name="sonar.projectKey" value="org.codehaus.sonar:example-java-ant" />
<property name="sonar.projectName" value="Sonar Sample Project Ant Run" />
<property name="sonar.projectVersion" value="1.0"/>
<property name="sonar.language" value="java" />
<property name="sonar.sources" value="MyProject/src" />
<!-- <property name="sonar.binaries" value="build/*.jar" />
 -->
<property name="sonar.host.url" value="http://localhost:9000" />

<target name="sonar" depends="update">
    <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml" classpathref="svnant.classpath">  
    </taskdef>
   
    <sonar:sonar/>  
</target>

</project>