devicemap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wk...@apache.org
Subject svn commit: r1648961 - in /devicemap/trunk/devicemap/java: ./ simpleddr/ simpleddr/src/main/java/org/apache/devicemap/simpleddr/ simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/ simpleddr/src/main/java/org/apache/devicemap/simpled...
Date Thu, 01 Jan 2015 23:26:14 GMT
Author: wkeil
Date: Thu Jan  1 23:26:13 2015
New Revision: 1648961

URL: http://svn.apache.org/r1648961
Log:
DMAP-118: Replace SLF4J/JUL/System.out with Log4J 2 

Task-Url: https://issues.apache.org/jira/browse/DMAP-118
DMAP-111: Improve Web Examples 

Task-Url: https://issues.apache.org/jira/browse/DMAP-111

Added:
    devicemap/trunk/devicemap/java/simpleddr/src/test/resources/log4j2.xml
Modified:
    devicemap/trunk/devicemap/java/pom.xml
    devicemap/trunk/devicemap/java/simpleddr/pom.xml
    devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/ODDRService.java
    devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/AndroidDeviceBuilder.java
    devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/identificator/BrowserIdentificator.java
    devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/identificator/OSIdentificator.java

Modified: devicemap/trunk/devicemap/java/pom.xml
URL: http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/pom.xml?rev=1648961&r1=1648960&r2=1648961&view=diff
==============================================================================
--- devicemap/trunk/devicemap/java/pom.xml (original)
+++ devicemap/trunk/devicemap/java/pom.xml Thu Jan  1 23:26:13 2015
@@ -1,22 +1,14 @@
 <?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.
--->
+<!-- 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>
@@ -49,7 +41,8 @@ under the License.
 		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 
 		<!-- The test data file maps User-Agent values to expected device properties -->
-		<!-- TODO this folder/module should be deprecated, check if still used and consider
local solution in downstream project -->
+		<!-- TODO this folder/module should be deprecated, check if still used 
+			and consider local solution in downstream project -->
 		<devicemap.test.data.file>${project.build.directory}/devicemap/test-data/dmap_20130522.txt</devicemap.test.data.file>
 	</properties>
 
@@ -67,15 +60,14 @@ under the License.
 				<version>2.1.1</version>
 			</dependency>
 			<dependency>
-				<groupId>org.slf4j</groupId>
-				<artifactId>slf4j-api</artifactId>
-				<version>1.6.6</version>
+				<groupId>org.apache.logging.log4j</groupId>
+				<artifactId>log4j-api</artifactId>
+				<version>2.1</version>
 			</dependency>
 			<dependency>
-				<groupId>org.slf4j</groupId>
-				<artifactId>slf4j-simple</artifactId>
-				<version>1.6.6</version>
-				<scope>test</scope>
+				<groupId>org.apache.logging.log4j</groupId>
+				<artifactId>log4j-core</artifactId>
+				<version>2.1</version>
 			</dependency>
 			<dependency>
 				<groupId>commons-lang</groupId>

Modified: devicemap/trunk/devicemap/java/simpleddr/pom.xml
URL: http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/simpleddr/pom.xml?rev=1648961&r1=1648960&r2=1648961&view=diff
==============================================================================
--- devicemap/trunk/devicemap/java/simpleddr/pom.xml (original)
+++ devicemap/trunk/devicemap/java/simpleddr/pom.xml Thu Jan  1 23:26:13 2015
@@ -196,13 +196,12 @@
 			<artifactId>commons-jexl</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>org.slf4j</groupId>
-			<artifactId>slf4j-api</artifactId>
+			<groupId>org.apache.logging.log4j</groupId>
+			<artifactId>log4j-api</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>org.slf4j</groupId>
-			<artifactId>slf4j-simple</artifactId>
-			<scope>test</scope>
+			<groupId>org.apache.logging.log4j</groupId>
+			<artifactId>log4j-core</artifactId>
 		</dependency>
 		<dependency>
 			<groupId>commons-lang</groupId>
@@ -210,11 +209,6 @@
 		</dependency>
 
 		<dependency>
-			<groupId>commons-logging</groupId>
-			<artifactId>commons-logging</artifactId>
-			<version>1.1.1</version>
-		</dependency>
-		<dependency>
 			<groupId>org.apache.devicemap</groupId>
 			<artifactId>devicemap-data</artifactId>
 			<scope>test</scope>

Modified: devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/ODDRService.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/ODDRService.java?rev=1648961&r1=1648960&r2=1648961&view=diff
==============================================================================
--- devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/ODDRService.java
(original)
+++ devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/ODDRService.java
Thu Jan  1 23:26:13 2015
@@ -65,8 +65,8 @@ import org.apache.devicemap.simpleddr.mo
 import org.apache.devicemap.simpleddr.model.vocabulary.Vocabulary;
 import org.apache.devicemap.simpleddr.model.vocabulary.VocabularyProperty;
 import org.apache.devicemap.simpleddr.vocabulary.VocabularyHolder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.w3c.ddr.simple.Evidence;
 import org.w3c.ddr.simple.PropertyName;
 import org.w3c.ddr.simple.PropertyRef;
@@ -99,7 +99,7 @@ public class ODDRService implements Serv
     public static final String ODDR_VOCABULARY_IRI = "oddr.vocabulary.device";
     private static final String ODDR_API_VERSION = "1.0.0-SNAPSHOT";
     private static final String ODDR_DATA_VERSION = "1.0.2-SNAPSHOT";
-    private static final int ODDR_DEFAULT_THRESHOLD = 70;
+    public static final int ODDR_DEFAULT_THRESHOLD = 70;
     private String defaultVocabularyIRI = null;
     private DeviceIdentificator deviceIdentificator = null;
     private BrowserIdentificator browserIdentificator = null;
@@ -108,7 +108,7 @@ public class ODDRService implements Serv
     private int threshold = ODDR_DEFAULT_THRESHOLD;
     private static final String GROUP_REGEXPR = "\\$([^ ]+)";
     private Pattern groupRegexprPattern = Pattern.compile(GROUP_REGEXPR);
-    protected final Logger logger = LoggerFactory.getLogger(getClass());
+    protected final Logger logger = LogManager.getLogger(getClass());
 
     public void initialize(String defaultVocabularyIRI, Properties prprts) throws NameException,
InitializationException {
         if (defaultVocabularyIRI == null || defaultVocabularyIRI.trim().length() == 0) {

Modified: devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/AndroidDeviceBuilder.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/AndroidDeviceBuilder.java?rev=1648961&r1=1648960&r2=1648961&view=diff
==============================================================================
--- devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/AndroidDeviceBuilder.java
(original)
+++ devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/AndroidDeviceBuilder.java
Thu Jan  1 23:26:13 2015
@@ -18,6 +18,8 @@
  */
 package org.apache.devicemap.simpleddr.builder.device;
 
+import static org.apache.devicemap.simpleddr.ODDRService.ODDR_DEFAULT_THRESHOLD;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
@@ -28,6 +30,8 @@ import java.util.regex.Pattern;
 
 import org.apache.devicemap.simpleddr.model.device.Device;
 import org.apache.devicemap.simpleddr.model.UserAgent;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 
 public class AndroidDeviceBuilder extends OrderedTokenDeviceBuilder {
 
@@ -35,10 +39,11 @@ public class AndroidDeviceBuilder extend
     private Pattern buildHashPattern = Pattern.compile(BUILD_HASH_REGEXP);
     private Map<String, Device> devices;
     private static final String[] FUZZY_TOKEN_REGEXPS = { "SM-T5\\d\\d" };
-
+    protected static final Logger logger = LogManager.getLogger(AndroidDeviceBuilder.class);
+    
     public AndroidDeviceBuilder() {
         super();
-//        System.out.println("Constructor");
+        logger.debug("Constructor");
     }
 
     public boolean canBuild(UserAgent userAgent) {
@@ -50,16 +55,16 @@ public class AndroidDeviceBuilder extend
     }
 
     public Device build(UserAgent userAgent, int confidenceTreshold) {
-    	System.out.println("Building");
-    	System.out.println("UA: " + userAgent.getCompleteUserAgent() + " :: A=" + userAgent.containsAndroid());
+    	logger.info("Building");
+    	logger.debug("UA: " + userAgent.getCompleteUserAgent() + " :: A=" + userAgent.containsAndroid());
         final List<Device> foundDevices = new ArrayList<Device>();
         Iterator<String> it = orderedRules.keySet().iterator();
         while (it.hasNext()) {
             String token = it.next();
-//            System.out.println(token);
+//            logger.debug.println(token);
             Device d = elaborateAndroidDeviceWithToken(userAgent, token);
             if (d != null) {
-            	System.out.println("Token: " + token);
+            	logger.debug("Token: " + token);
                 if (d.getConfidence() > confidenceTreshold) {
                     return fixFromUserAgent(d, userAgent);
                 } else {
@@ -73,14 +78,17 @@ public class AndroidDeviceBuilder extend
             Collections.sort(foundDevices, Collections.reverseOrder());
             return fixFromUserAgent(foundDevices.get(0), userAgent);
         } else {
-        	it = orderedRules.keySet().iterator(); // need it again for "Fuzzy" patterns
-        	while (it.hasNext()) {
-        		String token = it.next();
-        		Device d = fuzzyAndroidDeviceWithToken(userAgent, token);
-        		if (d != null) {
-        			System.out.println("Got: " + token);
-        			return fixFromUserAgent(d, userAgent);
-        		}
+        	if (confidenceTreshold <= ODDR_DEFAULT_THRESHOLD) {
+        	// we only do this if confidence is at or below default threshold (otherwise a "closer"
result than this can offer is expected)
+	        	it = orderedRules.keySet().iterator(); // need it again for "Fuzzy" patterns
+	        	while (it.hasNext()) {
+	        		String token = it.next();
+	        		Device d = fuzzyAndroidDeviceWithToken(userAgent, token);
+	        		if (d != null) {
+	        			logger.debug("Got: " + token);
+	        			return fixFromUserAgent(d, userAgent);
+	        		}
+	        	}
         	}
         }
         return null;
@@ -96,15 +104,15 @@ public class AndroidDeviceBuilder extend
             String currentToken = token;
 
             String looseToken = token.replaceAll("[ _/-]", ".?");
-//System.out.println("Loose Token: " + looseToken);
+//logger.debug("Loose Token: " + looseToken);
             Pattern loosePattern = Pattern.compile("(?i).*" + looseToken + ".*");
-//System.out.println("Loose Pattern: " + loosePattern);
+//logger.debug("Loose Pattern: " + loosePattern);
             if (!loosePattern.matcher(userAgent.getCompleteUserAgent().replaceAll("Android",
"")).matches()) {
                 return null;
             }
 
             String patternElementInsideClean = cleanPatternElementInside(userAgent.getPatternElementsInside());
-//System.out.println("Pattern: " + patternElementInsideClean);
+//logger.debug("Pattern: " + patternElementInsideClean);
             Pattern currentPattern = null;
 
             for (int i = 0; i <= 1; i++) {
@@ -113,10 +121,10 @@ public class AndroidDeviceBuilder extend
                 }
 
                 currentPattern = Pattern.compile("(?i).*" + currentToken + ".?Build/.*");
-//System.out.println("Pattern: " + currentPattern);
+//logger.debug("Pattern: " + currentPattern);
                 if (patternElementInsideClean != null && currentPattern.matcher(patternElementInsideClean).matches())
{//&& userAgent.getPatternElementsInside().matches(".*" + currentToken + ".?Build/.*"))
{
                     String deviceId = (String) orderedRules.get(token);
-//System.out.println("DID: " + deviceId);
+//logger.debug("DID: " + deviceId);
                     if (devices.containsKey(deviceId)) {
                         Device retDevice = (Device) devices.get(deviceId).clone();
                         retDevice.setConfidence(100 - subtract);

Modified: devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/identificator/BrowserIdentificator.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/identificator/BrowserIdentificator.java?rev=1648961&r1=1648960&r2=1648961&view=diff
==============================================================================
--- devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/identificator/BrowserIdentificator.java
(original)
+++ devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/identificator/BrowserIdentificator.java
Thu Jan  1 23:26:13 2015
@@ -24,15 +24,15 @@ import org.apache.devicemap.simpleddr.bu
 import org.apache.devicemap.simpleddr.model.UserAgent;
 import org.apache.devicemap.simpleddr.model.UserAgentFactory;
 import org.apache.devicemap.simpleddr.model.browser.Browser;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.w3c.ddr.simple.Evidence;
 
 public class BrowserIdentificator implements Identificator {
 
     private Builder[] builders;
     private Map<String, Browser> browserCapabilities;
-    protected final Logger logger = LoggerFactory.getLogger(getClass());
+    protected static final Logger logger = LogManager.getLogger(BrowserIdentificator.class);
 
     public BrowserIdentificator(Builder[] builders, Map<String, Browser> browserCapabilities)
{
         this.builders = builders;

Modified: devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/identificator/OSIdentificator.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/identificator/OSIdentificator.java?rev=1648961&r1=1648960&r2=1648961&view=diff
==============================================================================
--- devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/identificator/OSIdentificator.java
(original)
+++ devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/identificator/OSIdentificator.java
Thu Jan  1 23:26:13 2015
@@ -24,15 +24,15 @@ import org.apache.devicemap.simpleddr.bu
 import org.apache.devicemap.simpleddr.model.UserAgent;
 import org.apache.devicemap.simpleddr.model.UserAgentFactory;
 import org.apache.devicemap.simpleddr.model.os.OperatingSystem;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.w3c.ddr.simple.Evidence;
 
 public class OSIdentificator implements Identificator {
 
     private Builder[] builders;
     private Map<String, OperatingSystem> operatingSystemCapabilities;
-    protected final Logger logger = LoggerFactory.getLogger(getClass());
+    protected final Logger logger = LogManager.getLogger(getClass());
 
     public OSIdentificator(Builder[] builders, Map<String, OperatingSystem> operatingSystemCapabilities)
{
         this.builders = builders;

Added: devicemap/trunk/devicemap/java/simpleddr/src/test/resources/log4j2.xml
URL: http://svn.apache.org/viewvc/devicemap/trunk/devicemap/java/simpleddr/src/test/resources/log4j2.xml?rev=1648961&view=auto
==============================================================================
--- devicemap/trunk/devicemap/java/simpleddr/src/test/resources/log4j2.xml (added)
+++ devicemap/trunk/devicemap/java/simpleddr/src/test/resources/log4j2.xml Thu Jan  1 23:26:13
2015
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="WARN">
+  <Appenders>
+    <Console name="Console" target="SYSTEM_OUT">
+      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
+    </Console>
+  </Appenders>
+  <Loggers>
+    <!-- Root level is "info", if you want to see more detailed output like data streams,
please change to "debug" -->
+    <Root level="info">
+      <AppenderRef ref="Console"/>
+    </Root>
+  </Loggers>
+</Configuration>
\ No newline at end of file



Mime
View raw message