You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by wk...@apache.org on 2016/08/21 16:52:26 UTC
svn commit: r1757066 - in /devicemap/trunk/clients/1.0/java: ./
client/src/main/java/org/apache/devicemap/
client/src/main/java/org/apache/devicemap/loader/
client/src/main/java/org/apache/devicemap/loader/resource/ console/
console/src/main/java/org/a...
Author: wkeil
Date: Sun Aug 21 16:52:26 2016
New Revision: 1757066
URL: http://svn.apache.org/viewvc?rev=1757066&view=rev
Log:
DMAP-196: Deploy Snapshots to Apache Snapshot repo
Task-Url: https://issues.apache.org/jira/browse/DMAP-196
Added:
devicemap/trunk/clients/1.0/java/console/src/main/resources/
devicemap/trunk/clients/1.0/java/console/src/main/resources/app.properties
Modified:
devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java
devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapFactory.java
devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/loader/LoaderFactory.java
devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/loader/resource/URLResource.java
devicemap/trunk/clients/1.0/java/console/pom.xml
devicemap/trunk/clients/1.0/java/console/src/main/java/org/apache/devicemap/console/DeviceMapConsole.java
devicemap/trunk/clients/1.0/java/pom.xml
Modified: devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java?rev=1757066&r1=1757065&r2=1757066&view=diff
==============================================================================
--- devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java (original)
+++ devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java Sun Aug 21 16:52:26 2016
@@ -34,7 +34,7 @@ import org.apache.devicemap.loader.Loade
/**
* @author Werner Keil
- * @version 1.0.13
+ * @version 1.1
*/
public class DeviceMapClient {
private static final Logger LOG = Logger.getLogger(DeviceMapClient.class.getName());
@@ -57,18 +57,13 @@ public class DeviceMapClient {
uAttributes = Collections.unmodifiableMap(uAttributes);
unknown = new Device(Device.UNKNOWN_ID, uAttributes);
}
-
- public void initDeviceData(LoaderOption option, boolean snapshot) throws IOException {
- initDeviceData(option, null, snapshot);
- }
public void initDeviceData(LoaderOption option) throws IOException {
- initDeviceData(option, false);
+ initDeviceData(option, null);
}
- public synchronized void initDeviceData(LoaderOption option, String path,
- boolean snapshot) throws IOException {
- devices = LoaderFactory.getLoader(option, path, snapshot).getData();
+ public synchronized void initDeviceData(LoaderOption option, String path) throws IOException {
+ devices = LoaderFactory.getLoader(option, path).getData();
initCount++;
if (initCount % 1000 == 0) {
@@ -83,11 +78,6 @@ public class DeviceMapClient {
createIndex();
}
- public void initDeviceData(LoaderOption option, String path)
- throws IOException {
- initDeviceData(option, path, false);
- }
-
private void createIndex() {
patterns = new HashMap<String, List<DeviceType>>(8000);
Modified: devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapFactory.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapFactory.java?rev=1757066&r1=1757065&r2=1757066&view=diff
==============================================================================
--- devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapFactory.java (original)
+++ devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapFactory.java Sun Aug 21 16:52:26 2016
@@ -23,7 +23,7 @@ import org.apache.devicemap.loader.Loade
/**
* @author Werner Keil
- * @version 1.1
+ * @version 1.1.1
*/
public final class DeviceMapFactory {
private static DeviceMapClient client = null;
@@ -38,21 +38,17 @@ public final class DeviceMapFactory {
return getClient(DEFAULT, null);
}
- public static DeviceMapClient getClient(LoaderOption option, boolean snapshot) {
- return getClient(option, null, snapshot);
- }
-
public static DeviceMapClient getClient(LoaderOption option) {
- return getClient(option, false);
+ return getClient(option, null);
}
- public static DeviceMapClient getClient(LoaderOption option, String path, boolean snapshot) {
+ public static DeviceMapClient getClient(LoaderOption option, String path) {
if (!initialized) {
synchronized (DeviceMapFactory.class) {
if (!initialized) {
client = new DeviceMapClient();
try {
- client.initDeviceData(option, path, snapshot);
+ client.initDeviceData(option, path);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
@@ -62,11 +58,7 @@ public final class DeviceMapFactory {
}
return client;
}
-
- public static DeviceMapClient getClient(LoaderOption option, String path) {
- return getClient(option, path, false);
- }
-
+
public static void resetClient() {
initialized = false;
}
Modified: devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/loader/LoaderFactory.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/loader/LoaderFactory.java?rev=1757066&r1=1757065&r2=1757066&view=diff
==============================================================================
--- devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/loader/LoaderFactory.java (original)
+++ devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/loader/LoaderFactory.java Sun Aug 21 16:52:26 2016
@@ -28,11 +28,11 @@ import org.apache.devicemap.loader.impl.
/**
* @author Werner Keil
- * @version 1.1.1
+ * @version 1.2
*/
public abstract class LoaderFactory {
- public static Loader getLoader(LoaderOption option, String path, boolean snapshot) {
+ public static Loader getLoader(LoaderOption option, String path) {
switch (option) {
case JAR: {
return new DDRLoader(new JarResource(path));
@@ -41,7 +41,7 @@ public abstract class LoaderFactory {
return new DDRLoader(new FileResource(path));
}
case URL: {
- return new DDRLoader(new URLResource(path, snapshot));
+ return new DDRLoader(new URLResource(path));
}
case NOOP: {
return new NoopLoader();
@@ -50,8 +50,4 @@ public abstract class LoaderFactory {
return new UninitializedLoader();
}
}
-
- public static Loader getLoader(LoaderOption option, String path) {
- return getLoader(option, path, false);
- }
}
\ No newline at end of file
Modified: devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/loader/resource/URLResource.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/loader/resource/URLResource.java?rev=1757066&r1=1757065&r2=1757066&view=diff
==============================================================================
--- devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/loader/resource/URLResource.java (original)
+++ devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/loader/resource/URLResource.java Sun Aug 21 16:52:26 2016
@@ -29,33 +29,18 @@ import org.apache.devicemap.loader.Resou
* @version 1.1
*/
public class URLResource implements Resource {
- //FIXME: Move this out into DeviceMapConsole (or its config)
- private static final String LATEST_PATH = "http://devicemap-vm.apache.org/data/latest";
- private static final String SNAPSHOT_PATH = "http://devicemap-vm.apache.org/data/snapshot";
-
private final String path;
- private final boolean isSnapshot;
-
- public URLResource(String path, boolean snapshot) {
- this.isSnapshot = snapshot;
- if (path == null) {
- if (isSnapshot) {
- this.path = SNAPSHOT_PATH;
- } else {
- this.path = LATEST_PATH;
- }
- } else {
- this.path = path;
- }
- }
-
+
public URLResource(String path) {
- this(path, false);
+ this.path = path;
+ if (path == null) {
+ throw new NullPointerException("URL Path cannot be null");
+ }
}
@Override
public InputStream getResource(String file) throws IOException {
- String rpath = path + "/" + file;
- return new URL(rpath).openStream();
+ String rpath = path + "/" + file;
+ return new URL(rpath).openStream();
}
}
Modified: devicemap/trunk/clients/1.0/java/console/pom.xml
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/console/pom.xml?rev=1757066&r1=1757065&r2=1757066&view=diff
==============================================================================
--- devicemap/trunk/clients/1.0/java/console/pom.xml (original)
+++ devicemap/trunk/clients/1.0/java/console/pom.xml Sun Aug 21 16:52:26 2016
@@ -41,11 +41,19 @@
<artifactId>devicemap-client</artifactId>
</dependency>
<dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ </dependency>
+ <dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
+ <artifactId>commons-configuration2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
Modified: devicemap/trunk/clients/1.0/java/console/src/main/java/org/apache/devicemap/console/DeviceMapConsole.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/console/src/main/java/org/apache/devicemap/console/DeviceMapConsole.java?rev=1757066&r1=1757065&r2=1757066&view=diff
==============================================================================
--- devicemap/trunk/clients/1.0/java/console/src/main/java/org/apache/devicemap/console/DeviceMapConsole.java (original)
+++ devicemap/trunk/clients/1.0/java/console/src/main/java/org/apache/devicemap/console/DeviceMapConsole.java Sun Aug 21 16:52:26 2016
@@ -34,6 +34,8 @@ import org.apache.commons.cli.HelpFormat
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
+import org.apache.commons.configuration2.PropertiesConfiguration;
+import org.apache.commons.configuration2.builder.fluent.Configurations;
import org.apache.commons.lang3.time.StopWatch;
import org.apache.devicemap.DeviceMapClient;
import org.apache.devicemap.data.Device;
@@ -43,19 +45,25 @@ import org.apache.devicemap.loader.impl.
/**
* @author Reza Naghibi
* @author Werner Keil
- * @version 1.1.5
+ * @version 1.2
*/
public class DeviceMapConsole {
private static final String APP_NAME = "DeviceMap Java Console";
private static final String CLASS_NAME = DeviceMapConsole.class.getName();
- private final static Logger LOG = Logger.getLogger(CLASS_NAME);
-
+ private static final Logger LOG = Logger.getLogger(CLASS_NAME);
+ private static final String CONFIG_FILE = "app.properties";
+ private static final String CONFIG_PROP_CONNECT = "connectionString";
+
public static void main(String[] args) throws Exception {
System.out.println(APP_NAME
- + " "
- + DeviceMapConsole.class.getPackage()
- .getImplementationVersion());
+ + " " + DeviceMapConsole.class.getPackage()
+ .getImplementationVersion());
+ final Configurations configs = new Configurations();
+ // Read data from this file
+ final File propertiesFile = new File(CONFIG_FILE);
+ final PropertiesConfiguration config = configs.properties(propertiesFile);
+
@SuppressWarnings("unused")
boolean debug = false;
String loaderPath = null;
@@ -89,13 +97,11 @@ public class DeviceMapConsole {
.desc("Load DeviceMap resouces from folder or \"default\"")
.hasArg().optionalArg(true).build());
- lvOptions
- .addOption(Option
- .builder("j")
- .longOpt("jar")
- .argName("jar")
- .desc("Load DeviceMap resouces from JAR file in classpath or \"default\"")
- .hasArg().optionalArg(true).build());
+ lvOptions.addOption(Option.builder("j")
+ .longOpt("jar")
+ .argName("jar")
+ .desc("Load DeviceMap resouces from JAR file in classpath or \"default\"")
+ .hasArg().optionalArg(true).build());
try {
lvCmd = lvParser.parse(lvOptions, args);
@@ -123,46 +129,32 @@ public class DeviceMapConsole {
}
if (lvCmd.hasOption('f')) {
- option = LoaderOption.FOLDER;
- loaderPath = lvCmd.getOptionValue('f');
+ option = LoaderOption.FOLDER;
+ loaderPath = lvCmd.getOptionValue('f');
}
if (lvCmd.hasOption('j')) {
- LOG.fine("JAR: " + lvCmd.getOptionObject('j'));
- option = LoaderOption.JAR;
+ LOG.fine("JAR: " + lvCmd.getOptionObject('j'));
+ option = LoaderOption.JAR;
}
if (lvCmd.hasOption('u')) {
- option = LoaderOption.URL;
- loaderPath = lvCmd.getOptionValue('u');
- LOG.fine("URL: " + lvCmd.getOptionObject('u'));
+ option = LoaderOption.URL;
+ loaderPath = lvCmd.getOptionValue('u');
+ LOG.fine("URL: " + lvCmd.getOptionObject('u'));
}
if (lvCmd.hasOption('d')) {
- parameter = lvCmd.getOptionValue('d');
- LOG.fine("UA: " + lvCmd.getOptionObject('d'));
+ parameter = lvCmd.getOptionValue('d');
+ LOG.fine("UA: " + lvCmd.getOptionObject('d'));
}
- // lvFormater.printHelp(CLASS_NAME, lvOptions); // or shall we
- // classify with default UA?
-
- /*
- * } else if (args[i].startsWith("-h") || args[i].startsWith("--h"))
- * { System.out.println("Usage: " + DeviceMapConsole.class.getName()
- * + " [OPTIONS] [FILE|STRING]\n"); System.out
- * .println(" FILE text file of strings");
- * System.out.println(" STRING test string");
- *
- * return; } // [test string] | [test file] else if
- * (!args[i].isEmpty()) { parameter = args[i];
- * System.out.println(parameter); } }
- */
if ("default".equals(loaderPath)) {
- loaderPath = null;
+ loaderPath = config.getString(CONFIG_PROP_CONNECT);
}
if (LoaderOption.UNINITIALIZED.equals(option)) {
- option = LoaderOption.URL;
+ option = LoaderOption.URL;
}
final DeviceMapClient client = new DeviceMapClient();
final long start = System.currentTimeMillis();
@@ -188,60 +180,59 @@ public class DeviceMapConsole {
long diffn;
if (parameter == null) {
} else if ((new File(parameter)).exists()) {
- System.out.println("Text file: " + parameter);
- int count = 0;
- int total = 0;
+ System.out.println("Text file: " + parameter);
+ int count = 0;
+ int total = 0;
- BufferedReader in = new BufferedReader(
+ BufferedReader in = new BufferedReader(
new FileReader(parameter));
- String line;
- Device device;
- while ((line = in.readLine()) != null) {
- System.out.println("Text: '" + line + "'");
- startn = System.nanoTime();
- device = client.classifyDevice(line);
- diffn = System.nanoTime() - startn;
- total += diffn;
- count++;
+ String line;
+ Device device;
+ while ((line = in.readLine()) != null) {
+ System.out.println("Text: '" + line + "'");
+ startn = System.nanoTime();
+ device = client.classifyDevice(line);
+ diffn = System.nanoTime() - startn;
+ total += diffn;
+ count++;
- System.out.println("Text lookup " + count + ": '"
+ System.out.println("Text lookup " + count + ": '"
+ device.getId() + "' time: " + (diffn / 1000)
+ "usec");
- }
+ }
- in.close();
+ in.close();
- if (count == 0) {
- count = 1;
- }
- total /= count;
+ if (count == 0) {
+ count = 1;
+ }
+ total /= count;
- System.out.println("TOTAL lookups: " + count
+ System.out.println("TOTAL lookups: " + count
+ ", average time: " + (total / 1000) + "usec");
} else {
- System.out.println("UA: '" + parameter + "'");
- startn = System.nanoTime();
- final Device device = client.classifyDevice(parameter);
- diffn = System.nanoTime() - startn;
- System.out.println("UA lookup: '" + device.getId() + "' time: "
- + (diffn / 1000) + "usec");
- if (lvCmd.hasOption('o')) {
- System.out
- .println("DeviceMap JSON => " + device.toString());
+ System.out.println("UA: '" + parameter + "'");
+ startn = System.nanoTime();
+ final Device device = client.classifyDevice(parameter);
+ diffn = System.nanoTime() - startn;
+ System.out.println("UA lookup: '" + device.getId() + "' time: "
+ + (diffn / 1000) + "usec");
+ if (lvCmd.hasOption('o')) {
+ System.out.println("DeviceMap JSON => " + device.toString());
+ } else {
+ Map<String, String> m = device.getAttributes();
+ // iterate thru the attributes
+ if (m != null
+ && (m.keySet() != null && m.keySet().size() > 0)) {
+ System.out.println("=== ATTRIBUTES ===");
+ for (String attr : m.keySet()) {
+ System.out.println(attr + ": " + m.get(attr));
+ }
} else {
- Map<String, String> m = device.getAttributes();
- // iterate thru the attributes
- if (m != null
- && (m.keySet() != null && m.keySet().size() > 0)) {
- System.out.println("=== ATTRIBUTES ===");
- for (String attr : m.keySet()) {
- System.out.println(attr + ": " + m.get(attr));
- }
- } else {
- System.out.println("No attributes found for '"
+ System.out.println("No attributes found for '"
+ parameter + "'.");
- }
}
+ }
}
return;
@@ -260,7 +251,7 @@ public class DeviceMapConsole {
stopWatch.stop();
String deviceId = "unknown";
if (device != null) {
- deviceId = device.getId();
+ deviceId = device.getId();
}
System.out.println("Result: " + deviceId + " took "
+ stopWatch.getTime() + " ms");
Added: devicemap/trunk/clients/1.0/java/console/src/main/resources/app.properties
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/console/src/main/resources/app.properties?rev=1757066&view=auto
==============================================================================
--- devicemap/trunk/clients/1.0/java/console/src/main/resources/app.properties (added)
+++ devicemap/trunk/clients/1.0/java/console/src/main/resources/app.properties Sun Aug 21 16:52:26 2016
@@ -0,0 +1 @@
+connectionString = http://devicemap-vm.apache.org/data/latest
\ No newline at end of file
Modified: devicemap/trunk/clients/1.0/java/pom.xml
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/pom.xml?rev=1757066&r1=1757065&r2=1757066&view=diff
==============================================================================
--- devicemap/trunk/clients/1.0/java/pom.xml (original)
+++ devicemap/trunk/clients/1.0/java/pom.xml Sun Aug 21 16:52:26 2016
@@ -52,12 +52,22 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.9.2</version>
+ </dependency>
+ <dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
+ <artifactId>commons-configuration2</artifactId>
+ <version>2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>