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

Commit

Permalink
Update deprecated reference used.
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 45657c2
Author: Alex Eng <aeng@redhat.com>
Date:   Mon May 18 10:17:55 2015 +1000

    Update console not available message

commit 6bf2bfa
Author: Alex Eng <aeng@redhat.com>
Date:   Mon May 18 07:45:56 2015 +1000

    Add checking of null System.console

commit e8f5085
Author: Alex Eng <aeng@redhat.com>
Date:   Fri May 15 13:12:52 2015 +1000

    update deprecated reference used
  • Loading branch information
Alex Eng committed May 20, 2015
1 parent cdfdd2a commit cde2858
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 17 deletions.
Expand Up @@ -61,6 +61,7 @@
@Path(FileResource.SERVICE_PATH)
public class MockFileResource implements FileResource {
@Override
@Deprecated
public Response acceptedFileTypes() {
StringSet extensions = new StringSet("");
for (DocumentType docType : ProjectType
Expand Down
Expand Up @@ -46,6 +46,9 @@ public class ConsoleInteractorImpl implements ConsoleInteractor {

public ConsoleInteractorImpl() {
console = System.console();
if (console == null) {
throw new RuntimeException("Console not available: please run from a console, or use batch mode.");
}
out = AnsiConsole.out();
}

Expand Down
Expand Up @@ -21,13 +21,11 @@

package org.zanata.client.commands;

import java.io.Console;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -50,6 +48,8 @@
import org.zanata.rest.dto.resource.TranslationsResource;
import org.zanata.util.PathUtil;

import static org.zanata.client.commands.ConsoleInteractor.DisplayMode.Question;

/**
* @author Sean Flanigan <a
* href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
Expand Down Expand Up @@ -89,13 +89,9 @@ public PushPullCommand(O opts) {

protected void confirmWithUser(String message) throws IOException {
if (getOpts().isInteractiveMode()) {
Console console = System.console();
if (console == null) {
throw new RuntimeException(
"console not available: please run Maven from a console, or use batch mode option (-B)");
}
console.printf(message + "\nAre you sure (y/n)? ");
expectYes(console);
ConsoleInteractor console = new ConsoleInteractorImpl();
console.printf(Question, message + "\nAre you sure (y/n)? ");
console.expectYes();
}
}

Expand Down
@@ -1,6 +1,6 @@
package org.zanata.client.commands;

@edu.umd.cs.findbugs.annotations.SuppressWarnings({ "DM_EXIT" })
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings({ "DM_EXIT" })
public class SystemExitStrategy implements AppAbortStrategy {
@Override
public void abort(String msg) {
Expand Down
Expand Up @@ -78,6 +78,11 @@ public InitCommand(InitOptions opts) {
userConfigHandler = new UserConfigHandler(console, getOpts());
}

@VisibleForTesting
protected InitCommand(InitOptions opts, ConsoleInteractor console) {
this(opts, console, new RestClientFactory() {});
}

@VisibleForTesting
protected InitCommand(InitOptions opts,
ConsoleInteractor console,
Expand Down
Expand Up @@ -66,6 +66,7 @@
import org.zanata.rest.client.RestClientFactory;
import org.zanata.rest.dto.ChunkUploadResponse;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;

Expand All @@ -85,19 +86,28 @@ public class RawPushCommand extends PushPullCommand<PushOptions> {
private static final Pattern fileNameExtensionsPattern = Pattern.compile(
"(?:([^\\[]*)?(?:\\[(.*?)\\])?)");

private final ConsoleInteractor consoleInteractor =
new ConsoleInteractorImpl();
private final ConsoleInteractor consoleInteractor;

private FileResourceClient client;

public RawPushCommand(PushOptions opts) {
super(opts);
client = getClientFactory().getFileResourceClient();
consoleInteractor = new ConsoleInteractorImpl();
}

public RawPushCommand(PushOptions opts, RestClientFactory clientFactory) {
super(opts, clientFactory);
client = getClientFactory().getFileResourceClient();
consoleInteractor = new ConsoleInteractorImpl();
}

@VisibleForTesting
protected RawPushCommand(PushOptions opts, RestClientFactory clientFactory,
ConsoleInteractor console) {
super(opts, clientFactory);
client = getClientFactory().getFileResourceClient();
this.consoleInteractor = console;
}

/**
Expand Down
Expand Up @@ -78,7 +78,7 @@ public int compare(TranslationStatistics o1,
TranslationStatistics s = stats.get(i);
data[i] =
new Object[] { s.getLocale(), s.getUnit(), s.getTotal(),
s.getTranslated(), s.getNeedReview(),
s.getTranslatedAndApproved(), s.getDraft(),
s.getUntranslated(), s.getLastTranslated() };
}

Expand Down
Expand Up @@ -81,8 +81,8 @@ private void writeToCsv(ContainerTranslationStatistics statistics,
writer.writeNext(new String[] { transStats.getLocale(),
transStats.getUnit().toString(),
Long.toString(transStats.getTotal()),
Long.toString(transStats.getTranslated()),
Long.toString(transStats.getNeedReview()),
Long.toString(transStats.getTranslatedAndApproved()),
Long.toString(transStats.getDraft()),
Long.toString(transStats.getUntranslated()),
transStats.getLastTranslated() });
}
Expand Down
Expand Up @@ -57,7 +57,7 @@ public void setUp() throws IOException {
@Test
public void createCommandWithoutMandatoryOptionsWillNotCauseException() {
// we don't have server url etc yet
command = new InitCommand(opts);
command = new InitCommand(opts, console);
}

@Test
Expand Down
Expand Up @@ -6,6 +6,7 @@
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.zanata.client.commands.ConsoleInteractor;
import org.zanata.rest.client.RestClientFactory;

import static org.hamcrest.Matchers.contains;
Expand All @@ -23,6 +24,8 @@ public class RawPushCommandTest {
private PushOptions opts;
@Mock
private RestClientFactory clientFactory;
@Mock
private ConsoleInteractor console;

private RawPushCommand command;

Expand All @@ -32,7 +35,7 @@ public void setup() {
when(opts.getProj()).thenReturn("project");
when(opts.getProjectVersion()).thenReturn("version");
when(opts.getProjectType()).thenReturn("File");
command = new RawPushCommand(opts, clientFactory);
command = new RawPushCommand(opts, clientFactory, console);
}

@Test
Expand Down

0 comments on commit cde2858

Please sign in to comment.