From 3236432c39f1d5a1bbbe362c5cfdb088756fd04f Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 8 Jun 2014 13:18:46 +0200 Subject: [PATCH] Make minidns Android agnostic there is really no need for minidns to be Android exclusive. Replacing the Android log API with JUL make minidns available for Android and Java SE. --- AndroidManifest.xml | 13 -- README.md | 2 +- build.gradle | 152 ++++++++++++++---- build.xml | 92 ----------- proguard-project.txt | 0 project.properties | 2 - .../java}/de/measite/minidns/Client.java | 13 +- .../java}/de/measite/minidns/DNSMessage.java | 0 .../java}/de/measite/minidns/Question.java | 0 .../java}/de/measite/minidns/Record.java | 0 .../java}/de/measite/minidns/record/A.java | 0 .../java}/de/measite/minidns/record/AAAA.java | 0 .../de/measite/minidns/record/CNAME.java | 0 .../java}/de/measite/minidns/record/Data.java | 0 .../java}/de/measite/minidns/record/NS.java | 0 .../java}/de/measite/minidns/record/SRV.java | 0 .../de/measite/minidns/util/NameUtil.java | 0 17 files changed, 129 insertions(+), 145 deletions(-) delete mode 100644 AndroidManifest.xml delete mode 100644 build.xml delete mode 100644 proguard-project.txt delete mode 100644 project.properties rename src/{ => main/java}/de/measite/minidns/Client.java (95%) rename src/{ => main/java}/de/measite/minidns/DNSMessage.java (100%) rename src/{ => main/java}/de/measite/minidns/Question.java (100%) rename src/{ => main/java}/de/measite/minidns/Record.java (100%) rename src/{ => main/java}/de/measite/minidns/record/A.java (100%) rename src/{ => main/java}/de/measite/minidns/record/AAAA.java (100%) rename src/{ => main/java}/de/measite/minidns/record/CNAME.java (100%) rename src/{ => main/java}/de/measite/minidns/record/Data.java (100%) rename src/{ => main/java}/de/measite/minidns/record/NS.java (100%) rename src/{ => main/java}/de/measite/minidns/record/SRV.java (100%) rename src/{ => main/java}/de/measite/minidns/util/NameUtil.java (100%) diff --git a/AndroidManifest.xml b/AndroidManifest.xml deleted file mode 100644 index 6c9477d9c..000000000 --- a/AndroidManifest.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - diff --git a/README.md b/README.md index 99ba78b31..3c1417a18 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ MiniDNS ------- -MiniDNS is a minial dns client library for android. It can parse a basic set +MiniDNS is a minimal dns client library for android. It can parse a basic set of resource records (A, AAAA, NS, SRV) and is easy to use and extend. This library is not intended to be used as a DNS server. You might want to diff --git a/build.gradle b/build.gradle index ae9c7693a..7cf467180 100644 --- a/build.gradle +++ b/build.gradle @@ -1,34 +1,126 @@ -buildscript { - repositories { - mavenCentral() - } +apply plugin: 'java' +apply plugin: 'eclipse' +apply plugin: 'maven' +apply plugin: 'osgi' +apply plugin: 'signing' - dependencies { - classpath 'com.android.tools.build:gradle:0.9.0' - } +ext { + shortVersion = '0.1' + isSnapshot = true + gitCommit = getGitCommit() + isReleaseVersion = !shortVersion + sonatypeCredentialsAvailable = project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword') + signingRequired = isReleaseVersion + sonatypeSnapshotUrl = 'https://oss.sonatype.org/content/repositories/snapshots' + sonatypeStagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2' + buildDate = (new java.text.SimpleDateFormat("yyyy-MM-dd")).format(new Date()) } -apply plugin: 'android-library' - -android { - compileSdkVersion 19 - buildToolsVersion '19.0.3' - - // NOTE: We are using the old folder structure to also support Eclipse - sourceSets { - main { - manifest.srcFile 'AndroidManifest.xml' - java.srcDirs = ['src'] - resources.srcDirs = ['src'] - aidl.srcDirs = ['src'] - renderscript.srcDirs = ['src'] - res.srcDirs = ['res'] - assets.srcDirs = ['assets'] - } - } - - // Do not abort build if lint finds errors - lintOptions { - abortOnError false - } +group = 'de.measite.minidns' +description = "A minimal DNS client library with support for A, AAAA, NS and SRV records" +sourceCompatibility = 1.7 +version = shortVersion +if (isSnapshot) { + version += '-SNAPSHOT' +} + +jar { + manifest { + instruction 'Implementation-GitRevision:', project.ext.gitCommit + } +} + +gradle.taskGraph.whenReady { taskGraph -> + if (signingRequired + && taskGraph.allTasks.any { it instanceof Sign }) { + // Use Java 6's console to read from the console (no good for a CI environment) + Console console = System.console() + console.printf '\n\nWe have to sign some things in this build.\n\nPlease enter your signing details.\n\n' + def password = console.readPassword('GnuPG Private Key Password: ') + + allprojects { ext.'signing.password' = password } + + console.printf '\nThanks.\n\n' + } +} + +uploadArchives { + repositories { + mavenDeployer { + if (signingRequired) { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + } + repository(url: project.sonatypeStagingUrl) { + if (sonatypeCredentialsAvailable) { + authentication(userName: sonatypeUsername, password: sonatypePassword) + } + } + snapshotRepository(url: project.sonatypeSnapshotUrl) { + if (sonatypeCredentialsAvailable) { + authentication(userName: sonatypeUsername, password: sonatypePassword) + } + } + + pom.project { + name 'minidns' + packaging 'jar' + inceptionYear '2014' + url 'https://github.com/rtreffer/minidns' + description project.description + + issueManagement { + system 'GitHub' + url 'https://github.com/rtreffer/minidns/issues' + } + + distributionManagement { + snapshotRepository { + id 'minidns.snapshot' + url project.sonatypeSnapshotUrl + } + } + + scm { + url 'https://github.com/rtreffer/minidns' + connection 'scm:git:https://github.com/rtreffer/minidns.git' + developerConnection 'scm:git:https://github.com/rtreffer/minidns.git' + } + + licenses { + license { + name 'The Apache Software License, Version 2.0' + url 'http://www.apache.org/licenses/LICENSE-2.0.txt' + distribution 'repo' + } + } + + developers { + developer { + id 'rtreffer' + name 'Rene Treffer' + } + developer { + id 'flow' + name 'Florian Schmaus' + email 'flow@geekplace.eu' + } + } + } + } + } + signing { + required { signingRequired } + sign configurations.archives + } +} + +def getGitCommit() { + def dotGit = new File("$projectDir/.git") + if (!dotGit.isDirectory()) return 'non-git build' + + def cmd = 'git describe --all --dirty=+' + def proc = cmd.execute() + def gitCommit = proc.text.trim() + assert !gitCommit.isEmpty() + gitCommit } diff --git a/build.xml b/build.xml deleted file mode 100644 index e10480a05..000000000 --- a/build.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/proguard-project.txt b/proguard-project.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/project.properties b/project.properties deleted file mode 100644 index 9e86aa644..000000000 --- a/project.properties +++ /dev/null @@ -1,2 +0,0 @@ -target=android-19 -android.library=true diff --git a/src/de/measite/minidns/Client.java b/src/main/java/de/measite/minidns/Client.java similarity index 95% rename from src/de/measite/minidns/Client.java rename to src/main/java/de/measite/minidns/Client.java index 8bc75d015..fb42cd25a 100644 --- a/src/de/measite/minidns/Client.java +++ b/src/main/java/de/measite/minidns/Client.java @@ -14,8 +14,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.Random; +import java.util.logging.Logger; -import android.util.Log; import de.measite.minidns.Record.CLASS; import de.measite.minidns.Record.TYPE; @@ -25,6 +25,8 @@ import de.measite.minidns.Record.TYPE; */ public class Client { + private static final Logger LOGGER = Logger.getLogger(Client.class.getName()); + /** * The internal random class for sequence generation. */ @@ -177,22 +179,19 @@ public class Client { public String[] findDNS() { String[] result = findDNSByReflection(); if (result != null) { - Log.d("minidns/client", - "Got DNS servers via reflection: " + Arrays.toString(result)); + LOGGER.fine("Got DNS servers via reflection: " + Arrays.toString(result)); return result; } result = findDNSByExec(); if (result != null) { - Log.d("minidns/client", - "Got DNS servers via exec: " + Arrays.toString(result)); + LOGGER.fine("Got DNS servers via exec: " + Arrays.toString(result)); return result; } // fallback for ipv4 and ipv6 connectivity // see https://developers.google.com/speed/public-dns/docs/using - Log.d("minidns/client", - "No DNS found? Using fallback [8.8.8.8, [2001:4860:4860::8888]]"); + LOGGER.fine("No DNS found? Using fallback [8.8.8.8, [2001:4860:4860::8888]]"); return new String[]{"8.8.8.8", "[2001:4860:4860::8888]"}; } diff --git a/src/de/measite/minidns/DNSMessage.java b/src/main/java/de/measite/minidns/DNSMessage.java similarity index 100% rename from src/de/measite/minidns/DNSMessage.java rename to src/main/java/de/measite/minidns/DNSMessage.java diff --git a/src/de/measite/minidns/Question.java b/src/main/java/de/measite/minidns/Question.java similarity index 100% rename from src/de/measite/minidns/Question.java rename to src/main/java/de/measite/minidns/Question.java diff --git a/src/de/measite/minidns/Record.java b/src/main/java/de/measite/minidns/Record.java similarity index 100% rename from src/de/measite/minidns/Record.java rename to src/main/java/de/measite/minidns/Record.java diff --git a/src/de/measite/minidns/record/A.java b/src/main/java/de/measite/minidns/record/A.java similarity index 100% rename from src/de/measite/minidns/record/A.java rename to src/main/java/de/measite/minidns/record/A.java diff --git a/src/de/measite/minidns/record/AAAA.java b/src/main/java/de/measite/minidns/record/AAAA.java similarity index 100% rename from src/de/measite/minidns/record/AAAA.java rename to src/main/java/de/measite/minidns/record/AAAA.java diff --git a/src/de/measite/minidns/record/CNAME.java b/src/main/java/de/measite/minidns/record/CNAME.java similarity index 100% rename from src/de/measite/minidns/record/CNAME.java rename to src/main/java/de/measite/minidns/record/CNAME.java diff --git a/src/de/measite/minidns/record/Data.java b/src/main/java/de/measite/minidns/record/Data.java similarity index 100% rename from src/de/measite/minidns/record/Data.java rename to src/main/java/de/measite/minidns/record/Data.java diff --git a/src/de/measite/minidns/record/NS.java b/src/main/java/de/measite/minidns/record/NS.java similarity index 100% rename from src/de/measite/minidns/record/NS.java rename to src/main/java/de/measite/minidns/record/NS.java diff --git a/src/de/measite/minidns/record/SRV.java b/src/main/java/de/measite/minidns/record/SRV.java similarity index 100% rename from src/de/measite/minidns/record/SRV.java rename to src/main/java/de/measite/minidns/record/SRV.java diff --git a/src/de/measite/minidns/util/NameUtil.java b/src/main/java/de/measite/minidns/util/NameUtil.java similarity index 100% rename from src/de/measite/minidns/util/NameUtil.java rename to src/main/java/de/measite/minidns/util/NameUtil.java