Skip to content

Commit

Permalink
sonar fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuszkubis committed Sep 22, 2016
1 parent f55fbb6 commit 2a4ffa7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/cognifide/secureaem/HttpHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ public String getBasePath(String url, boolean removeExtension) throws IOExceptio
EntityUtils.consume(response.getEntity());
HttpUriRequest request = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);

URI uri = request.getURI();
String baseUrl = context.getAttribute(ExecutionContext.HTTP_TARGET_HOST).toString() + uri.getPath();
if (removeExtension && uri.getPath().contains(".")) {
String uriPath = request.getURI().getPath();
String baseUrl = context.getAttribute(ExecutionContext.HTTP_TARGET_HOST).toString() + uriPath;
if (removeExtension && uriPath.contains(".")) {
baseUrl = StringUtils.substringBeforeLast(baseUrl, ".");
}
if (!"/".equals(uri.getPath())) {
if (!"/".equals(uriPath)) {
baseUrl = StringUtils.removeEnd(baseUrl, "/");
}
return baseUrl;
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/cognifide/secureaem/UserHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
/**
* Created by Mariusz Kubiś on 19.09.16
*/
public class UserHelper {
public final class UserHelper {

private UserHelper() {
// To prevent initialization
}

public static String[] splitUser(String user) {
int colon = user.indexOf(':');
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/com/cognifide/secureaem/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,25 @@ public class Main {

private static final String DEFAULT_TEST_SUITE_PATH = "/test_suite.properties";

private static final String CMD_SUITE_OPTION = "suite";

public static void main(String[] args) throws Exception {
CommandLine cmdLine = createOptions(args);
if (!cmdLine.hasOption('a') && !cmdLine.hasOption('p') && !cmdLine.hasOption('d')) {
printf("Usage: ");
printf("java -jar secure-aem.jar [-a AUTHOR_URL] [-p PUBLISH_URL] [-d DISPATCHER_URL] ");
System.exit(1);
}
List<TestLoader> testLoaders = createTestLoaders(cmdLine);
List<TestLoader> testLoaders = createTestLoaders(cmdLine);
boolean result = true;
for (TestLoader testLoader : testLoaders) {
result = doTest(testLoader, cmdLine) && result;
}
System.exit(result ? 0 : -1);
}

private static List<TestLoader> createTestLoaders(CommandLine cmdLine) throws IOException, ClassNotFoundException {
private static List<TestLoader> createTestLoaders(CommandLine cmdLine)
throws IOException, ClassNotFoundException {
try (BufferedReader reader = getBufferedReader(cmdLine)) {
List<TestLoader> testLoaders = new ArrayList<>();
String line;
Expand All @@ -57,9 +60,9 @@ private static List<TestLoader> createTestLoaders(CommandLine cmdLine) throws IO

private static BufferedReader getBufferedReader(CommandLine cmdLine) throws FileNotFoundException {
BufferedReader reader;
if (cmdLine.hasOption("suite")) {
if (cmdLine.hasOption(CMD_SUITE_OPTION)) {
reader = new BufferedReader(
new InputStreamReader(new FileInputStream(cmdLine.getOptionValue("suite")),
new InputStreamReader(new FileInputStream(cmdLine.getOptionValue(CMD_SUITE_OPTION)),
StandardCharsets.UTF_8));
} else {
InputStream is = Main.class.getClass().getResourceAsStream(DEFAULT_TEST_SUITE_PATH);
Expand Down Expand Up @@ -87,7 +90,8 @@ private static boolean doTest(TestLoader testLoader, CommandLine cmdLine) throws
printf(" * %s", message);
}
}
if (!test.getInfoMessages().isEmpty() && !"true".equals(config.getStringValue("hidePassed", "false"))) {
if (!test.getInfoMessages().isEmpty() && !"true"
.equals(config.getStringValue("hidePassed", "false"))) {
printf("");
printf("Passed tests:");
for (String message : test.getInfoMessages()) {
Expand All @@ -102,12 +106,12 @@ private static void printf(String format, Object... args) {
System.out.println(String.format(format, args));
}

private static CommandLine createOptions(String args[]) throws ParseException {
private static CommandLine createOptions(String[] args) throws ParseException {
Options options = new Options();
options.addOption("a", true, "author URL");
options.addOption("p", true, "publish URL");
options.addOption("d", true, "dispatcher URL");
options.addOption("suite", true, "test suite");
options.addOption(CMD_SUITE_OPTION, true, "test suite");
options.addOption("aCredentials", true, "author credentials");
options.addOption("pCredentials", true, "publish credentials");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,10 @@ protected void activate() throws LoginException {
ResourceResolver resolver = resolverFactory.getAdministrativeResourceResolver(null);
try {
String currentHost = getCurrentHost();
String publishHost = getTransportUri(new AgentConfigFilter() {
@Override
public boolean matches(AgentConfig agentConfig) {
return "durbo".equals(agentConfig.getSerializationType());
}
});
String dispatcher = getTransportUri(new AgentConfigFilter() {
@Override
public boolean matches(AgentConfig agentConfig) {
return "flush".equals(agentConfig.getSerializationType());
}
});
String publishHost = getTransportUri(
agentConfig -> "durbo".equals(agentConfig.getSerializationType()));
String dispatcher = getTransportUri(
agentConfig -> "flush".equals(agentConfig.getSerializationType()));
LOG.info("Discovered author instance URL: " + currentHost);
LOG.info("Discovered publish instance URL: " + publishHost);
LOG.info("Discovered dispatcher URL: " + dispatcher);
Expand Down Expand Up @@ -137,7 +129,7 @@ private String getCurrentHost() {
}
}

private static interface AgentConfigFilter {
private interface AgentConfigFilter {
boolean matches(AgentConfig agentConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.cognifide.secureaem.cli.CliConfiguration;

public class ResourceConfiguration implements Configuration {
private static final Logger LOG = LoggerFactory.getLogger(DefaultConfigurationProvider.class);
private static final Logger LOG = LoggerFactory.getLogger(ResourceConfiguration.class);
private final ValueMap globalConfig;

private final SlingHttpServletRequest request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.cognifide.secureaem.AbstractTest;
import com.cognifide.secureaem.Configuration;
import com.cognifide.secureaem.UserHelper;
import com.cognifide.secureaem.markers.AuthorTest;
import com.cognifide.secureaem.markers.PublishTest;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.cognifide.secureaem.AbstractTest;
import com.cognifide.secureaem.Configuration;
import com.cognifide.secureaem.UserHelper;
import com.cognifide.secureaem.markers.AuthorTest;
import com.cognifide.secureaem.markers.PublishTest;

Expand Down

0 comments on commit 2a4ffa7

Please sign in to comment.