Skip to content

Commit

Permalink
Add depedendency on GitHub Java API.
Browse files Browse the repository at this point in the history
This required obfuscating the org.apache dependencies
so that they do not clash with the build in Android versions.

This required registering a custom log factory that forwards
the Android Log utility
  • Loading branch information
kevinsawicki committed Oct 16, 2011
1 parent 9cc476f commit e155a4b
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 3 deletions.
5 changes: 5 additions & 0 deletions github-android/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<artifactId>guice-assisted-inject</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.mylyn.github</groupId>
<artifactId>org.eclipse.egit.github.core</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
package com.github.mobile.android;

import static java.util.Arrays.asList;
import android.app.Instrumentation;
import android.content.Context;
import android.util.Log;

import com.google.inject.Module;
import roboguice.application.RoboApplication;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.List;

import static java.util.Arrays.asList;
import org.apache.commons.logging.LogFactory;

import roboguice.application.RoboApplication;

public class GitHubApplication extends RoboApplication {

public static final String TAG = "GHA";

public GitHubApplication() {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
return System.setProperty(LogFactory.class.getName(),
com.github.mobile.android.LogFactory.class.getName());
}
});
}

public GitHubApplication(Context context) {
Expand Down
119 changes: 119 additions & 0 deletions github-android/src/main/java/com/github/mobile/android/LogFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.github.mobile.android;

import static android.util.Log.d;
import static android.util.Log.e;
import static android.util.Log.i;
import static android.util.Log.isLoggable;
import static android.util.Log.v;
import static android.util.Log.w;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogConfigurationException;

/**
* Log
*/
public class LogFactory extends org.apache.commons.logging.LogFactory {

private final String TAG = "GHLog";

private final Log log = new Log() {

public void warn(Object message, Throwable throwable) {
w(TAG, String.valueOf(message), throwable);
}

public void warn(Object message) {
w(TAG, String.valueOf(message));
}

public void trace(Object message, Throwable throwable) {
v(TAG, String.valueOf(message), throwable);
}

public void trace(Object message) {
v(TAG, String.valueOf(message));
}

public boolean isWarnEnabled() {
return isLoggable(TAG, android.util.Log.WARN);
}

public boolean isTraceEnabled() {
return isLoggable(TAG, android.util.Log.VERBOSE);
}

public boolean isInfoEnabled() {
return isLoggable(TAG, android.util.Log.INFO);
}

public boolean isFatalEnabled() {
return isLoggable(TAG, android.util.Log.ERROR);
}

public boolean isErrorEnabled() {
return isLoggable(TAG, android.util.Log.ERROR);
}

public boolean isDebugEnabled() {
return isLoggable(TAG, android.util.Log.DEBUG);
}

public void info(Object message, Throwable throwable) {
i(TAG, String.valueOf(message), throwable);
}

public void info(Object message) {
i(TAG, String.valueOf(message));
}

public void fatal(Object message, Throwable throwable) {
e(TAG, String.valueOf(message), throwable);
}

public void fatal(Object message) {
e(TAG, String.valueOf(message));
}

public void error(Object message, Throwable throwable) {
e(TAG, String.valueOf(message), throwable);
}

public void error(Object message) {
e(TAG, String.valueOf(message));
}

public void debug(Object message, Throwable throwable) {
d(TAG, String.valueOf(message), throwable);
}

public void debug(Object message) {
d(TAG, String.valueOf(message));
}
};

public Object getAttribute(String name) {
return null;
}

public String[] getAttributeNames() {
return null;
}

public Log getInstance(@SuppressWarnings("rawtypes") Class clazz) throws LogConfigurationException {
return log;
}

public Log getInstance(String name) throws LogConfigurationException {
return log;
}

public void release() {
}

public void removeAttribute(String name) {
}

public void setAttribute(String name, Object value) {
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<lib>${rt.jar.path}</lib>
<lib>${jsse.jar.path}</lib>
</libs>
<obfuscate>false</obfuscate>
<obfuscate>true</obfuscate>
<addMavenDescriptor>false</addMavenDescriptor>
<proguardInclude>../proguard.cfg</proguardInclude>
<!-- sadly, relative to sub-modules -->
Expand Down
3 changes: 3 additions & 0 deletions proguard.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

-keeppackagenames !org.apache.**
-keepnames class !org.apache.** { *; }
-keepattributes Signature

-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }

Expand Down

0 comments on commit e155a4b

Please sign in to comment.