Skip to content

Commit

Permalink
Added missing constructor argument in update tests.
Browse files Browse the repository at this point in the history
Added null check and empty check on token error message.
Change gradle settings to look at web3j master snapshot version.
Reverted main gradle overwrite value to true.
  • Loading branch information
AlexandrouR committed Mar 6, 2020
1 parent 242358c commit 17f8ad5
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ apply {
download {
src "https://raw.githubusercontent.com/web3j/build-tools/master/gradle/$buildScript/build.gradle"
dest "$rootDir/gradle/$buildScript/build.gradle"
overwrite false
overwrite true
quiet true
onlyIfModified true
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=4.5.15
version=4.6.0-SNAPSHOT
1 change: 0 additions & 1 deletion gradle/repositories/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven { url 'https://oss.sonatype.org/content/repositories/releases/' }
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/web3j/console/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public class Runner {

public static void main(String[] args) throws Exception {
System.out.println(LOGO);

CliConfig config = CliConfig.getConfig(CliConfig.getWeb3jConfigPath().toFile());
Updater updater = new Updater(config);
updater.promptIfUpdateAvailable();
Expand Down Expand Up @@ -97,7 +96,6 @@ public static void main(String[] args) throws Exception {
}
}
config.save();
// TODO change this with a no argument method when the update is done in web3j
Console.exitSuccess("");
Console.exitSuccess();
}
}
7 changes: 6 additions & 1 deletion src/main/java/org/web3j/console/account/AccountManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ public void createAccount(String email) throws IOException {
JsonObject responseJsonObj = JsonParser.parseString(rawResponse).getAsJsonObject();

if (responseJsonObj.get("token") == null) {

String tokenError = responseJsonObj.get("tokenError").getAsString();
System.out.println(tokenError);
if (tokenError == null || tokenError.isEmpty()) {
System.out.println("Could not retrieve token. Try again later.");
} else {
System.out.println(tokenError);
}
return;
}
String token = responseJsonObj.get("token").getAsString();
Expand Down
71 changes: 47 additions & 24 deletions src/main/java/org/web3j/console/project/InteractiveOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
package org.web3j.console.project;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;
import java.util.Scanner;

import com.fasterxml.jackson.databind.node.ObjectNode;

import org.web3j.account.LocalWeb3jAccount;
import org.web3j.console.project.utils.InputVerifier;

import static java.io.File.separator;
Expand Down Expand Up @@ -73,55 +77,55 @@ public static Optional<String> getGeneratedWrapperLocation() {
print(
"Please enter the path of the generated contract wrappers ["
+ String.join(
separator,
System.getProperty("user.dir"),
"build",
"generated",
"source",
"web3j",
"main",
"java")
separator,
System.getProperty("user.dir"),
"build",
"generated",
"source",
"web3j",
"main",
"java")
+ "]");
String pathToTheWrappers = getUserInput();
return pathToTheWrappers.isEmpty()
? Optional.of(
String.join(
separator,
System.getProperty("user.dir"),
"build",
"generated",
"source",
"web3j",
"main",
"java"))
String.join(
separator,
System.getProperty("user.dir"),
"build",
"generated",
"source",
"web3j",
"main",
"java"))
: Optional.of(pathToTheWrappers);
}

public static Optional<String> setGeneratedTestLocationJava() {
print(
"Where would you like to save your tests ["
+ String.join(
separator, System.getProperty("user.dir"), "src", "test", "java")
separator, System.getProperty("user.dir"), "src", "test", "java")
+ "]");
String outputPath = getUserInput();
return outputPath.isEmpty()
? Optional.of(
String.join(
separator, System.getProperty("user.dir"), "src", "test", "java"))
String.join(
separator, System.getProperty("user.dir"), "src", "test", "java"))
: Optional.of(outputPath);
}

public static Optional<String> setGeneratedTestLocationKotlin() {
print(
"Where would you like to save your tests ["
+ String.join(
separator, System.getProperty("user.dir"), "src", "test", "kotlin")
separator, System.getProperty("user.dir"), "src", "test", "kotlin")
+ "]");
String outputPath = getUserInput();
return outputPath.isEmpty()
? Optional.of(
String.join(
separator, System.getProperty("user.dir"), "src", "test", "kotlin"))
String.join(
separator, System.getProperty("user.dir"), "src", "test", "kotlin"))
: Optional.of(outputPath);
}

Expand All @@ -137,7 +141,6 @@ public static String getSolidityProjectPath() {
}

static String getUserInput() {

return scanner.nextLine();
}

Expand All @@ -150,4 +153,24 @@ public static boolean overrideExistingProject() {
String userAnswer = getUserInput();
return userAnswer.toLowerCase().equals("y");
}

public static boolean userHasWeb3jAccount() throws IOException {
if (LocalWeb3jAccount.configExists()) {
ObjectNode objectNode = LocalWeb3jAccount.readConfigAsJson();
return LocalWeb3jAccount.loginTokenExists(objectNode);
}
return false;
}

public static boolean configFileExists() {
return LocalWeb3jAccount.configExists();
}

public static boolean userWantsWeb3jAccount() throws IOException {

print("It looks like you don’t have a Web3j account, would you like to create one?");
print("This will provide free access to the Ethereum network [Y/n]");
String userAnswer = getUserInput();
return userAnswer.toLowerCase().equals("y") || userAnswer.trim().equals("");
}
}
24 changes: 22 additions & 2 deletions src/main/java/org/web3j/console/project/ProjectCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.web3j.console.project;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
Expand All @@ -22,6 +23,8 @@
import org.jetbrains.annotations.NotNull;
import picocli.CommandLine;

import org.web3j.console.account.AccountManager;
import org.web3j.console.config.CliConfig;
import org.web3j.console.project.java.JavaBuilder;
import org.web3j.console.project.java.JavaProjectCreatorCLIRunner;
import org.web3j.console.project.kotlin.KotlinBuilder;
Expand All @@ -48,7 +51,7 @@ public ProjectCreator(final String root, final String packageName, final String
this.root = root;
}

public static void main(String[] args) {
public static void main(String[] args) throws IOException {
final List<String> stringOptions = new ArrayList<>();
if (args.length > 0 && args[0].toLowerCase().equals(COMMAND_JAVA)) {
args = tail(args);
Expand All @@ -61,7 +64,8 @@ public static void main(String[] args) {
}

@NotNull
private static String[] getValues(String[] args, List<String> stringOptions) {
private static String[] getValues(String[] args, List<String> stringOptions)
throws IOException {
String projectName;
if (args.length == 0) {
stringOptions.add("-n");
Expand All @@ -75,6 +79,22 @@ private static String[] getValues(String[] args, List<String> stringOptions) {
stringOptions.add("-o");
stringOptions.add(projectDest);
});
if (InteractiveOptions.configFileExists()) {
if (!InteractiveOptions.userHasWeb3jAccount()) {
if (InteractiveOptions.userWantsWeb3jAccount()) {
AccountManager.main(
CliConfig.getConfig(CliConfig.getWeb3jConfigPath().toFile()),
new String[] {"create"});
}
}
} else {
if (InteractiveOptions.userWantsWeb3jAccount()) {
AccountManager.main(
CliConfig.getConfig(CliConfig.getWeb3jConfigPath().toFile()),
new String[] {"create"});
}
}

args = stringOptions.toArray(new String[0]);
}
return args;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/web3j/console/project/UpdaterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void testWorksWithVersion(String version) throws IOException {
"http://localhost:8081",
UUID.randomUUID().toString(),
Version.getVersion(),
null)
null,null)
.defaultAnswer(Mockito.CALLS_REAL_METHODS));

doAnswer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void verifyThatTestsAreGenerated() {
}

@Test
public void testWithPicoCliWhenArgumentsAreEmpty() {
public void testWithPicoCliWhenArgumentsAreEmpty() throws IOException {
final String[] args = {"--java", "-n=", "-p="};
ProjectCreator.main(args);
assertEquals(
Expand Down

0 comments on commit 17f8ad5

Please sign in to comment.