Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Removing SLF4J usage to deal with class path issues #60
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Aug 31, 2015
1 parent fecf223 commit f5d9426
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 53 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Changelog of Pull Request Notifier for Stash.

## 1.23
* Removing SLF4J usage to deal with classpath issues.

## 1.22
* Adding feature that can inject variable evaluated in content of a URL. Raw content or value of an xPath or JsonPath.
* Bugfix: Closing inputstream after invocation. This may have caused "IOException: Too many open files".
Expand Down
29 changes: 12 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.0.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- WIRED TEST RUNNER DEPENDENCIES -->
<dependency>
<groupId>org.mockito</groupId>
Expand All @@ -139,29 +151,12 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.0.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/se/bjurr/prnfs/admin/ConfigResource.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package se.bjurr.prnfs.admin;

import static com.atlassian.stash.user.Permission.ADMIN;
import static java.util.logging.Level.SEVERE;
import static java.util.logging.Logger.getLogger;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.Response.noContent;
import static javax.ws.rs.core.Response.ok;
Expand All @@ -17,6 +19,8 @@
import static se.bjurr.prnfs.settings.SettingsStorage.injectFormIdentifierIfNotSet;
import static se.bjurr.prnfs.settings.SettingsStorage.storeSettings;

import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
Expand All @@ -28,9 +32,6 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import se.bjurr.prnfs.settings.PrnfsSettings;
import se.bjurr.prnfs.settings.ValidationException;

Expand All @@ -44,7 +45,7 @@

@Path("/")
public class ConfigResource {
private static final Logger logger = LoggerFactory.getLogger(ConfigResource.class);
private static final Logger logger = getLogger(ConfigResource.class.getName());
private final PluginSettingsFactory pluginSettingsFactory;
private final TransactionTemplate transactionTemplate;
private final UserManager userManager;
Expand Down Expand Up @@ -157,7 +158,7 @@ public Object doInTransaction() {
try {
storeSettings(pluginSettingsFactory.createGlobalSettings(), config);
} catch (final ValidationException e) {
logger.error("", e);
logger.log(SEVERE, "", e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static com.google.common.collect.Maps.newHashMap;
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import static java.util.logging.Level.SEVERE;
import static java.util.logging.Logger.getLogger;
import static java.util.regex.Pattern.compile;
import static javax.ws.rs.core.HttpHeaders.AUTHORIZATION;
import static javax.xml.bind.DatatypeConverter.printBase64Binary;
Expand All @@ -14,9 +16,7 @@
import static se.bjurr.prnfs.settings.SettingsStorage.getPrnfsSettings;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.logging.Logger;

import se.bjurr.prnfs.listener.PrnfsRenderer.PrnfsVariable;
import se.bjurr.prnfs.settings.Header;
Expand Down Expand Up @@ -50,7 +50,7 @@ public class PrnfsPullRequestEventListener {
private final PluginSettingsFactory pluginSettingsFactory;
private final RepositoryService repositoryService;
private final ApplicationPropertiesService propertiesService;
private static final Logger logger = LoggerFactory.getLogger(PrnfsPullRequestEventListener.class);
private static final Logger logger = getLogger(PrnfsPullRequestEventListener.class.getName());

private static Invoker invoker = new Invoker() {
@Override
Expand Down Expand Up @@ -144,7 +144,7 @@ public String get() {
notify(notification, action, pullRequestEvent.getPullRequest(), variables, renderer);
}
} catch (final ValidationException e) {
logger.error("", e);
logger.log(SEVERE, "", e);
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/se/bjurr/prnfs/listener/PrnfsRenderer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package se.bjurr.prnfs.listener;

import static java.util.logging.Level.SEVERE;
import static java.util.logging.Logger.getLogger;
import static javax.xml.xpath.XPathConstants.STRING;
import static se.bjurr.prnfs.admin.AdminFormValues.INEJCTION_TYPE.JSONPATH;
import static se.bjurr.prnfs.admin.AdminFormValues.INEJCTION_TYPE.RAW;
Expand All @@ -11,13 +13,11 @@

import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPathFactory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import se.bjurr.prnfs.settings.PrnfsNotification;

import com.atlassian.stash.pull.PullRequest;
Expand All @@ -32,7 +32,7 @@
import com.jayway.jsonpath.JsonPath;

public class PrnfsRenderer {
private static final Logger logger = LoggerFactory.getLogger(PrnfsRenderer.class);
private static final Logger logger = getLogger(PrnfsRenderer.class.getName());
private static Invoker invoker = new Invoker() {
@Override
public void invoke(UrlInvoker urlInvoker) {
Expand Down Expand Up @@ -331,7 +331,8 @@ public String resolve(PullRequest pullRequest, PrnfsPullRequestAction pullReques
.evaluate(
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(urlInvoker.getResponseStringStream()), STRING);
} catch (Exception e) {
logger.error(prnfsNotification.getInjectionUrl().get() + " " + prnfsNotification.getInjectionUrlXPath().get(), e);
logger.log(SEVERE, prnfsNotification.getInjectionUrl().get() + " "
+ prnfsNotification.getInjectionUrlXPath().get(), e);
}
}
return "";
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/se/bjurr/prnfs/listener/UrlInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.io.CharStreams.readLines;
import static java.lang.Boolean.TRUE;
import static java.util.logging.Level.SEVERE;
import static java.util.logging.Logger.getLogger;
import static se.bjurr.prnfs.listener.UrlInvoker.HTTP_METHOD.GET;

import java.io.ByteArrayInputStream;
Expand All @@ -20,9 +22,7 @@
import java.net.Proxy;
import java.net.URL;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.logging.Logger;

import se.bjurr.prnfs.settings.Header;

Expand All @@ -36,7 +36,7 @@ public enum HTTP_METHOD {
GET, PUT, POST, DELETE
}

private static final Logger logger = LoggerFactory.getLogger(UrlInvoker.class);
private static final Logger logger = getLogger(UrlInvoker.class.getName());
private String urlParam;
private HTTP_METHOD method = GET;
private Optional<String> postContent;
Expand Down Expand Up @@ -103,17 +103,17 @@ public PasswordAuthentication getPasswordAuthentication() {
}
uc.setDoOutput(true);
if (shouldPostContent()) {
logger.debug(method + " >\n" + postContent.get());
logger.fine(method + " >\n" + postContent.get());
uc.setDoInput(true);
uc.setRequestProperty("Content-Length", postContent.get().length() + "");
wr = new DataOutputStream(uc.getOutputStream());
wr.write(postContent.get().getBytes(UTF_8));
}
ir = new InputStreamReader(uc.getInputStream(), UTF_8);
responseString = on("\n").join(readLines(ir));
logger.debug(responseString);
logger.fine(responseString);
} catch (final Exception e) {
logger.error("", e);
logger.log(SEVERE, "", e);
} finally {
try {
Closeables.close(ir, TRUE);
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/se/bjurr/prnfs/settings/SettingsStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newTreeMap;
import static java.lang.System.currentTimeMillis;
import static java.util.logging.Level.SEVERE;
import static se.bjurr.prnfs.admin.AdminFormValues.DEFAULT_NAME;
import static se.bjurr.prnfs.admin.AdminFormValues.NAME;
import static se.bjurr.prnfs.admin.AdminFormValues.VALUE;
Expand All @@ -22,9 +23,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.logging.Logger;

import se.bjurr.prnfs.admin.AdminFormValues;
import se.bjurr.prnfs.admin.AdminFormValues.BUTTON_VISIBILITY;
Expand All @@ -39,7 +38,7 @@
public class SettingsStorage {

private static final Gson gson = new Gson();
private static Logger logger = LoggerFactory.getLogger(SettingsStorage.class);
private static Logger logger = Logger.getLogger(SettingsStorage.class.getName());

private static Random random = new Random(currentTimeMillis());

Expand All @@ -51,7 +50,7 @@ public static void deleteSettings(PluginSettings pluginSettings, String id) {
try {
storeNotificationsMap(pluginSettings, map);
} catch (final ValidationException e) {
logger.error("", e);
logger.log(SEVERE, "", e);
}
}

Expand Down Expand Up @@ -222,7 +221,7 @@ public static List<AdminFormValues> getSettingsAsFormValues(PluginSettings setti
toReturn.add(injectConfigurationName(gson.fromJson(storedJson, AdminFormValues.class)));
}
} catch (final Exception e) {
logger.error("Unable to deserialize settings", e);
logger.log(SEVERE, "Unable to deserialize settings", e);
}
return toReturn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import static se.bjurr.prnfs.settings.SettingsStorage.getSettingsAsFormValues;

import java.util.List;
import java.util.logging.Logger;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.mockito.Matchers;

import se.bjurr.prnfs.settings.SettingsStorage;

Expand Down Expand Up @@ -46,19 +46,19 @@ public void before() {

@Test
public void whenItIsAListOfNoneJson() {
when(settings.get(Mockito.anyString())).thenReturn(newArrayList("this is not json"));
when(settings.get(Matchers.anyString())).thenReturn(newArrayList("this is not json"));
assertEmpty();
}

@Test
public void whenItIsAListOfUnrecognizedJson() {
when(settings.get(Mockito.anyString())).thenReturn(newArrayList("{\"this\": \"that\"}"));
when(settings.get(Matchers.anyString())).thenReturn(newArrayList("{\"this\": \"that\"}"));
assertEmpty();
}

@Test
public void whenItIsNotAList() {
when(settings.get(Mockito.anyString())).thenReturn("this is not a list!");
when(settings.get(Matchers.anyString())).thenReturn("this is not a list!");
assertEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;

import org.mockito.Matchers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import se.bjurr.prnfs.ManualResource;
import se.bjurr.prnfs.admin.AdminFormError;
Expand Down Expand Up @@ -84,7 +83,7 @@ public long nextLong() {

private static Long fakeRandomCounter = null;

private static final Logger logger = LoggerFactory.getLogger(PrnfsTestBuilder.class);
private static final Logger logger = Logger.getLogger(PrnfsTestBuilder.class.getName());

public static PrnfsTestBuilder prnfsTestBuilder() {
return new PrnfsTestBuilder();
Expand Down

0 comments on commit f5d9426

Please sign in to comment.