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 2015/11/30 00:36:19 UTC

svn commit: r1717136 [4/4] - in /devicemap/trunk/clients/1.0/java: ./ client/ client/src/ client/src/main/ client/src/main/java/ client/src/main/java/org/ client/src/main/java/org/apache/ client/src/main/java/org/apache/devicemap/ client/src/main/java/...

Propchange: devicemap/trunk/clients/1.0/java/console/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Nov 29 23:36:18 2015
@@ -0,0 +1,4 @@
+target
+.settings
+.classpath
+.project

Added: 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=1717136&view=auto
==============================================================================
--- devicemap/trunk/clients/1.0/java/console/pom.xml (added)
+++ devicemap/trunk/clients/1.0/java/console/pom.xml Sun Nov 29 23:36:18 2015
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor 
+	license agreements. See the NOTICE file distributed with this work for additional 
+	information regarding copyright ownership. The ASF licenses this file to 
+	you under the Apache License, Version 2.0 (the "License"); you may not use 
+	this file except in compliance with the License. You may obtain a copy of 
+	the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required 
+	by applicable law or agreed to in writing, software distributed under the 
+	License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
+	OF ANY KIND, either express or implied. See the License for the specific 
+	language governing permissions and limitations under the License. -->
+<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/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<groupId>org.apache.devicemap</groupId>
+		<artifactId>devicemap-java</artifactId>
+		<version>1.1.1-SNAPSHOT</version>
+	</parent>
+
+	<artifactId>devicemap-java-console</artifactId>
+	<packaging>jar</packaging>
+	<name>Apache DeviceMap Java Console</name>
+	<description>Apache DeviceMap Java API</description>
+	<url>http://devicemap.apache.org/</url>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+
+	<scm>
+		<connection>scm:svn:http://svn.apache.org/repos/asf/devicemap/trunk/devicemap/java/classifier</connection>
+		<developerConnection>scm:svn:https://svn.apache.org/repos/asf/devicemap/trunk/devicemap/java/classifier</developerConnection>
+		<url>http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/classifier</url>
+	</scm>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.devicemap</groupId>
+			<artifactId>devicemap-client</artifactId>
+			<version>1.1.1-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.6</source>
+					<target>1.6</target>
+					<debug>true</debug>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-surefire-plugin</artifactId>
+			</plugin>
+		</plugins>
+	</build>
+</project>

Added: devicemap/trunk/clients/1.0/java/console/src/main/java/org/apache/devicemap/console/Main.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/console/src/main/java/org/apache/devicemap/console/Main.java?rev=1717136&view=auto
==============================================================================
--- devicemap/trunk/clients/1.0/java/console/src/main/java/org/apache/devicemap/console/Main.java (added)
+++ devicemap/trunk/clients/1.0/java/console/src/main/java/org/apache/devicemap/console/Main.java Sun Nov 29 23:36:18 2015
@@ -0,0 +1,153 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.devicemap.console;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.devicemap.DeviceMapClient;
+import org.apache.devicemap.data.Device;
+import org.apache.devicemap.loader.LoaderOption;
+import org.apache.devicemap.loader.impl.DDRLoader;
+
+/**
+ * @author Reza Naghibi
+ * @author Werner Keil
+ */
+public class Main {
+
+    public static void main(String[] args) throws Exception {
+
+        System.out.println("DeviceMap Java Console " + DeviceMapClient.class.getPackage().getImplementationVersion());
+        
+        if(args.length == 0) {
+            System.out.println("Usage: -h for help");
+        }
+
+        String loaderPath = null;
+        LoaderOption option = LoaderOption.UNINITIALIZED;
+        String parameter = null;
+        boolean debug = true;
+
+        for (int i = 0; i < args.length; i++) {
+            if (args[i].equals("-f")) {
+                option = LoaderOption.FOLDER;
+                if (args.length > (++i)) {
+                    loaderPath = args[i];
+                }
+            } else if (args[i].equals("-u")) {
+                option = LoaderOption.URL;
+                if (args.length > (++i)) {
+                    loaderPath = args[i];
+                }
+            } else if (args[i].equals("-j")) {
+                option = LoaderOption.JAR;
+            } else if (args[i].equals("-d")) {
+                debug = false;
+            } else if (args[i].startsWith("-h") || args[i].startsWith("--h")) {
+                System.out.println("Usage: " + Main.class.getName() + " [OPTIONS] [FILE|STRING]\n");
+                System.out.println("  -f <path>            load DeviceMap resouces from folder or \"default\"");
+                System.out.println("  -j                   load DeviceMap resouces from jar file in classpath");
+                System.out.println("  -u <url>             load DeviceMap resouces from URL or \"default\"");
+                System.out.println("  -d                   no debug logging");
+                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];
+            }
+        }
+        
+        if(debug) {
+            Logger.getLogger(DeviceMapClient.class.getName()).setLevel(Level.ALL);
+            Logger.getLogger(DDRLoader.class.getName()).setLevel(Level.ALL);
+            for (Handler h : Logger.getLogger(DeviceMapClient.class.getName()).getParent().getHandlers()) {
+                if (h instanceof ConsoleHandler) {
+                  h.setLevel(Level.ALL);
+                }
+            }
+        }
+
+        if ("default".equals(loaderPath)) {
+            loaderPath = null;
+        }
+
+        DeviceMapClient client = new DeviceMapClient();
+        final long start = System.currentTimeMillis();
+        client.initDeviceData(option, loaderPath);
+        long diff = System.currentTimeMillis() - start;
+
+        System.out.println("Loaded " + client.getDeviceCount() + " devices with " + client.getPatternCount() +
+                " patterns and " + client.getNodeCount() + " nodes in " + diff + "ms");
+
+        final String test = "Mozilla/5.0 (Linux; U; Android 2.2; en; HTC Aria A6380 Build/ERE27) AppleWebKit/540.13+ (KHTML, like Gecko) Version/3.1 Mobile Safari/524.15.0";
+        long startn = System.nanoTime();
+        Device device = client.classifyDevice(test);
+        long diffn = (System.nanoTime() - startn) / 1000;
+
+        System.out.println("Test lookup: '" + device.getId() + "' time: " + diffn + "usec");
+
+        if (parameter == null) {
+        } else if ((new File(parameter)).exists()) {
+            System.out.println("Text file: " + parameter);
+
+            int count = 0;
+            int total = 0;
+
+            BufferedReader in = new BufferedReader(new FileReader(parameter));
+            String line;
+
+            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 + ": '" + device.getId() + "' time: " + (diffn / 1000) + "usec");
+            }
+
+            in.close();
+
+            if (count == 0) {
+                count = 1;
+            }
+
+            total /= count;
+
+            System.out.println("TOTAL lookups: " + count + ", average time: " + (total / 1000) + "usec");
+        } else {
+            System.out.println("Text: '" + parameter + "'");
+
+            startn = System.nanoTime();
+            device = client.classifyDevice(parameter);
+            diffn = System.nanoTime() - startn;
+            System.out.println("Text lookup: '" + device.getId() + "' time: " + (diffn / 1000) + "usec");
+            System.out.println("DeviceMap JSON => " + device.toString());
+        }
+    }
+}

Modified: devicemap/trunk/clients/1.0/java/pom.xml
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/pom.xml?rev=1717136&r1=1717135&r2=1717136&view=diff
==============================================================================
--- devicemap/trunk/clients/1.0/java/pom.xml (original)
+++ devicemap/trunk/clients/1.0/java/pom.xml Sun Nov 29 23:36:18 2015
@@ -1,81 +1,67 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-   Licensed to the Apache Software Foundation (ASF) under one
-   or more contributor license agreements.  See the NOTICE file
-   distributed with this work for additional information
-   regarding copyright ownership.  The ASF licenses this file
-   to you under the Apache License, Version 2.0 (the
-   "License"); you may not use this file except in compliance
-   with the License.  You may obtain a copy of the License at
-
-     http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing,
-   software distributed under the License is distributed on an
-   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-   KIND, either express or implied.  See the License for the
-   specific language governing permissions and limitations
-   under the License.
--->
-<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/maven-v4_0_0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-  
-  <parent>
-    <groupId>org.apache</groupId>
-    <artifactId>apache</artifactId>
-    <version>16</version>
-    <relativePath />
-  </parent>
-
-  <groupId>org.apache.devicemap</groupId>
-  <artifactId>devicemap-client</artifactId>
-  <packaging>jar</packaging>
-  <version>1.1.1-SNAPSHOT</version>
-  <name>Apache DeviceMap Java Client</name>
-  <description>Apache DeviceMap Java API</description>
-  <url>http://devicemap.apache.org/</url>
-  
-  <properties>
-    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-  </properties>
-
-  <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/devicemap/trunk/devicemap/java/classifier</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/devicemap/trunk/devicemap/java/classifier</developerConnection>
-    <url>http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/classifier</url>
-  </scm>
-
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.devicemap</groupId>
-      <artifactId>devicemap-data</artifactId>
-      <version>1.0.3</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>4.11</version>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-compiler-plugin</artifactId>
-        <configuration>
-          <source>1.6</source>
-          <target>1.6</target>
-          <debug>true</debug>
-        </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-surefire-plugin</artifactId>
-      </plugin>
-    </plugins>
-  </build>
-  
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor 
+	license agreements. See the NOTICE file distributed with this work for additional 
+	information regarding copyright ownership. The ASF licenses this file to 
+	you under the Apache License, Version 2.0 (the "License"); you may not use 
+	this file except in compliance with the License. You may obtain a copy of 
+	the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required 
+	by applicable law or agreed to in writing, software distributed under the 
+	License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
+	OF ANY KIND, either express or implied. See the License for the specific 
+	language governing permissions and limitations under the License. -->
+<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/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<groupId>org.apache</groupId>
+		<artifactId>apache</artifactId>
+		<version>16</version>
+		<relativePath />
+	</parent>
+
+	<groupId>org.apache.devicemap</groupId>
+	<artifactId>devicemap-java</artifactId>
+	<packaging>pom</packaging>
+	<version>1.1.1-SNAPSHOT</version>
+	<name>Apache DeviceMap for Java</name>
+	<description>Apache DeviceMap Java API</description>
+	<url>http://devicemap.apache.org/</url>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+
+	<scm>
+		<connection>scm:svn:http://svn.apache.org/repos/asf/devicemap/trunk/devicemap/clients/1.0/java</connection>
+		<developerConnection>scm:svn:https://svn.apache.org/repos/asf/devicemap/trunk/devicemap/java/classifier</developerConnection>
+		<url>http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/classifier</url>
+	</scm>
+
+	<dependencyManagement>
+		<dependencies>
+			<dependency>
+				<groupId>org.apache.devicemap</groupId>
+				<artifactId>devicemap-data</artifactId>
+				<version>1.0.3</version>
+				<scope>test</scope>
+			</dependency>
+			<dependency>
+				<groupId>org.apache.devicemap</groupId>
+				<artifactId>devicemap-client</artifactId>
+				<version>${project.version}</version>
+				<scope>test</scope>
+			</dependency>
+			<dependency>
+				<groupId>junit</groupId>
+				<artifactId>junit</artifactId>
+				<version>4.12</version>
+				<scope>test</scope>
+			</dependency>
+		</dependencies>
+	</dependencyManagement>
+
+	<modules>
+		<module>client</module>
+	</modules>
 </project>