google code with git

google code allows to use SVN to access the code and I was wondering whether there is way to access code with git.

  • Import
$ git svn clone --username your-name -s https://your-project.googlecode.com/svn
few other commands
git log
gitk
git diff HEAD^^
  • Developing
git add filename
git rm  filename
git commit -a     => commits to local repository
git push          => sends to server repository
  • Update – get online and check latest changes from google code
git svn rebase
  • Export – sends commits to google code
git svn dcommit       => sends commit
  • Other useful commads:
git branch -a         => shows all branches

You have noticed that svn command connected with git “git svn”. This is as already written google supports SVN, but git can comunicate “SVN” way 🙂

You can read more here. For GIT tutorial check git pages or this tutorial.

You can use “egit” plugin to connect your eclipse to git repository.

So summary time - equivalent svn/git commands - Git for SVN User

svn checkout $SVNREP/trunk -> git svn clone $SVNREP -T trunk -b branches -t tags svn checkout $SVNREP/branches/release-0.3 -> git checkout -b local/release-0.3 release-0.3 svn commit -> git commit -a, or git add then git commit followed by git-svn dcommit svn diff|less, svn commit -> git commit -v svn merge -> git cherry-pick or use "gitk --all" svn status -> git status svn revert, --recursive -> git checkout , git checkout -f or git reset --hard svn diff -> git diff svn update -> git svn rebase --all (see also git stash)
 

authentication against google in java

Google, Yahoo and others allows to authenticate users using OpenID protocol. Some pages are here and openid4j .

In my last post I have mentioned about google data libraries which is actually APIs for most of the google services, including to authenticate users and much more. GData libraries are let’s say higher level layer which handles all the openid pain for you. 2 simple lines of code and you are authenticate 🙂

Here is simple example

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.majecek.gdata</groupId>
 <artifactId>gdata_testing</artifactId>
 <version>1.0-SNAPSHOT</version>
 <packaging>jar</packaging>
 <name>gdata_testing</name>
 <url>http://maven.apache.org</url>
 <properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 </properties>

<repositories>
<repository>
<id>mandubian-mvn</id>
<url>http://mandubian-mvn.googlecode.com/svn/trunk/mandubian-mvn/repository</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
 <scope>test</scope>
 </dependency>
 <dependency>
 <groupId>com.google.gdata</groupId>
 <artifactId>gdata-calendar-2.0</artifactId>
 <version>1.41.3</version>
 </dependency>
 <dependency>
 <groupId>com.google.gdata</groupId>
 <artifactId>gdata-core-1.0</artifactId>
 <version>1.41.3</version>
 </dependency>
 </dependencies>
 </project>

Simple java project:

package com.majecek.gdata;
 import com.google.gdata.client.GoogleService;
 import com.google.gdata.client.calendar.CalendarService;
 import com.google.gdata.util.AuthenticationException;

public class App
 {
 public static void main( String[] args )
 {
 GoogleService myService = new CalendarService("some_apps");
 try {
 myService.setUserCredentials("userLogin".concat("@gmail.com"), "password");
 //if success then succes authentication occures
 System.out.println("success authentication");
 } catch (AuthenticationException e) {
 //if not then invalid credentials has been set
 //invalid username or password
 System.out.println("invalid authentication");
 }
 }
}

Example can be downloaded from google code repository. It is maven project.

I have updated and uploaded this example to github. Read README.

The bigest advantage is that we don’t need to handle any “openid” tricks, just creates service against google service (in my example Calendar) and call “setUserCredentials” which already authenticate user.

Credits go also @Petr Olivka


google data libraries in maven

I wanted to create new project and used google data libraries (com.google.gdata…) and connect with maven2.

Even though Google has these libraries as opensource, it is not in maven repository. Anyway there is project which added these google libraries into maven into google code.

Here is example of pom.xml (repository & libary dependency)

<project> ..

<repositories>
<repository>
 <id>mandubian-mvn</id>
 <url>http://mandubian-mvn.googlecode.com/svn/trunk/mandubian-mvn/repository</url>
 </repository>
</repositories>
.......
<dependencies>
 <dependency>
  <groupId>com.google.gdata</groupId>
  <artifactId>gdata-calendar-2.0</artifactId>
  <version>1.41.3</version>
 </dependency>
 <dependency>
  <groupId>com.google.gdata</groupId>
  <artifactId>gdata-core-1.0</artifactId>
  <version>1.41.3</version>
  </dependency>
</dependencies>
....
</project>

As you can see you can add google libraries according your needs. If you don’t know the full name and version of the library you want to use – check it here .