Skip to content

Commit e4db092

Browse files
committed
Merge branch 'release/3'
2 parents 1f96a9c + fdea208 commit e4db092

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1252
-883
lines changed

build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
buildscript {
2+
ext.kotlin_version = '1.1.2-2'
3+
24
repositories {
35
mavenCentral()
46
}
7+
8+
dependencies {
9+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
10+
}
511
}
612

713
subprojects {
814
apply plugin: "java"
15+
apply plugin: "kotlin"
916

1017
repositories {
1118
mavenCentral()

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
### General options ###
33
javaVersion=1.8
44
gradleVersion=3.5
5-
pluginVersion=2.1
5+
pluginVersion=3
66
# if set the 'idePath' then the version ignoring
77
# if 'sandboxDir' not set then use default sandbox directory (build/${product}-sandbox)
88
# if 'ideVersion' not set then use LATEST-EAP-SNAPSHOT
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri Apr 21 02:06:06 NOVT 2017
1+
#Fri May 26 23:16:13 NOVT 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip

stepik-java-api/src/main/java/org/stepik/api/client/HttpTransportClient.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public class HttpTransportClient implements TransportClient {
4747
private static final String ENCODING = "UTF-8";
4848
private static final String CONTENT_TYPE = "application/x-www-form-urlencoded";
4949
private static final String CONTENT_TYPE_HEADER = "Content-Type";
50-
private static final String USER_AGENT = "Stepik Java API Client/" + StepikApiClient.getVersion();
5150

5251
private static final int MAX_SIMULTANEOUS_CONNECTIONS = 100000;
5352
private static final int FULL_CONNECTION_TIMEOUT_S = 30;
@@ -57,11 +56,11 @@ public class HttpTransportClient implements TransportClient {
5756
private static HttpTransportClient instance;
5857
private final CloseableHttpClient httpClient;
5958

60-
private HttpTransportClient() {
61-
this(null, 0);
59+
private HttpTransportClient(@NotNull String userAgent) {
60+
this(null, 0, userAgent);
6261
}
6362

64-
private HttpTransportClient(@Nullable String proxyHost, int proxyPort) {
63+
private HttpTransportClient(@Nullable String proxyHost, int proxyPort, @NotNull String userAgent) {
6564
CookieStore cookieStore = new BasicCookieStore();
6665
RequestConfig requestConfig = RequestConfig.custom()
6766
.setSocketTimeout(SOCKET_TIMEOUT_MS)
@@ -74,7 +73,7 @@ private HttpTransportClient(@Nullable String proxyHost, int proxyPort) {
7473
.setDefaultRequestConfig(requestConfig)
7574
.setDefaultCookieStore(cookieStore)
7675
.setMaxConnPerRoute(MAX_SIMULTANEOUS_CONNECTIONS)
77-
.setUserAgent(USER_AGENT)
76+
.setUserAgent(userAgent)
7877
.setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE);
7978

8079
try {
@@ -99,25 +98,20 @@ private HttpTransportClient(@Nullable String proxyHost, int proxyPort) {
9998
}
10099

101100
@NotNull
102-
public static HttpTransportClient getInstance() {
101+
public static HttpTransportClient getInstance(@NotNull String userAgent) {
103102
if (instance == null) {
104-
instance = new HttpTransportClient();
103+
instance = new HttpTransportClient(userAgent);
105104
}
106105

107106
return instance;
108107
}
109108

110109
@NotNull
111-
public static HttpTransportClient getInstance(@Nullable String proxyHost, int proxyPort) {
110+
public static HttpTransportClient getInstance(@Nullable String proxyHost, int proxyPort, @NotNull String userAgent) {
112111
Pair<String, Integer> proxy = new Pair<>(proxyHost, proxyPort);
113112

114-
if (!instances.containsKey(proxy)) {
115-
HttpTransportClient instance = new HttpTransportClient(proxyHost, proxyPort);
116-
instances.put(proxy, instance);
117-
return instance;
118-
}
119-
120-
return instances.get(proxy);
113+
return instances.computeIfAbsent(proxy,
114+
k -> new HttpTransportClient(proxyHost, proxyPort, userAgent));
121115
}
122116

123117
@NotNull
@@ -147,7 +141,7 @@ public ClientResponse post(
147141
headers = new HashMap<>();
148142
}
149143

150-
headers.entrySet().forEach(entry -> request.setHeader(entry.getKey(), entry.getValue()));
144+
headers.forEach(request::setHeader);
151145

152146
if (body != null) {
153147
ContentType contentType;
@@ -164,7 +158,7 @@ public ClientResponse get(
164158
@Nullable Map<String, String> headers) {
165159
HttpGet request = new HttpGet(url);
166160
if (headers != null) {
167-
headers.entrySet().forEach(entry -> request.setHeader(entry.getKey(), entry.getValue()));
161+
headers.forEach(request::setHeader);
168162
}
169163
return call(stepikApiClient, request);
170164
}

stepik-java-api/src/main/java/org/stepik/api/client/StepikApiClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public class StepikApiClient {
104104
private Path cachePath = Paths.get(System.getProperty("user.home"), ".stepik", "stepik-api", "cache");
105105
private boolean cacheEnabled = true;
106106

107-
public StepikApiClient() {
108-
this(HttpTransportClient.getInstance());
107+
public StepikApiClient(@NotNull String userAgent) {
108+
this(HttpTransportClient.getInstance(userAgent));
109109
}
110110

111111
public StepikApiClient(@NotNull HttpTransportClient transportClient) {

stepik-java-api/src/main/java/org/stepik/api/queries/StepikAbstractQuery.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.HashMap;
2020
import java.util.List;
2121
import java.util.Map;
22+
import java.util.concurrent.CompletableFuture;
2223
import java.util.stream.Collectors;
2324

2425
/**
@@ -104,6 +105,11 @@ protected List<String> getParam(@NotNull String key) {
104105
@NotNull
105106
protected abstract String getUrl();
106107

108+
@NotNull
109+
public CompletableFuture<T> executeAsync() {
110+
return CompletableFuture.supplyAsync(this::execute);
111+
}
112+
107113
@NotNull
108114
public T execute() {
109115
StepikApiClient stepikApi = stepikAction.getStepikApiClient();

stepik-union/src/main/java/org/stepik/core/StudyUtils.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,13 @@ public static StudyNode getStudyNode(@NotNull StudyNode root, @NotNull String re
146146
}
147147

148148
StudyNode studyNode = null;
149+
150+
StepikApiClient stepikClient = authAndGetStepikApiClient();
151+
if (!isAuthenticated()) {
152+
return null;
153+
}
154+
149155
try {
150-
StepikApiClient stepikClient = authAndGetStepikApiClient();
151-
if (!isAuthenticated()) {
152-
return null;
153-
}
154156
Recommendations recommendations = stepikClient.recommendations()
155157
.get()
156158
.course(root.getId())

stepik-union/src/main/java/org/stepik/core/SupportedLanguages.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ public enum SupportedLanguages {
1818
"haskell",
1919
"Main.hs",
2020
"--",
21-
new String[]{"module Main where", "main = print $ \"Hello, world!\""},
21+
"module Main where\nmain = print $ \"Hello, world!\"",
2222
null),
2323
HASKELL_7_10("Haskell 7.10",
2424
"haskell 7.10",
2525
"Main.hs",
2626
"--",
27-
new String[]{"module Main where", "main = print $ \"Hello, world!\""},
27+
"module Main where\nmain = print $ \"Hello, world!\"",
2828
null),
2929
HASKELL_8_0("Haskell 8.0",
3030
"haskell 8.0",
3131
"Main.hs",
3232
"--",
33-
new String[]{"module Main where", "main = print $ \"Hello, world!\""},
33+
"module Main where\nmain = print $ \"Hello, world!\"",
3434
null),
35-
JAVA8("Java 8", "java8", "Main.java", "//", new String[]{"class Main {"}, new String[]{"}"}),
36-
JAVA("Java", "java", "Main.java", "//", new String[]{"class Main {"}, new String[]{"}"}, JAVA8),
35+
JAVA8("Java 8", "java8", "Main.java", "//", "class Main {", "}"),
36+
JAVA("Java", "java", "Main.java", "//", "class Main {", "}", JAVA8),
3737
JAVASCRIPT("JavaScript", "javascript", "main.js", "//", null, null),
3838
KOTLIN("Kotlin", "kotlin", "Main.kt", "//", null, null),
3939
MONO_CS("Mono c#", "mono c#", "main.cs", "//", null, null),
@@ -51,8 +51,8 @@ public enum SupportedLanguages {
5151
private final String name;
5252
private final String comment;
5353
private final String mainFileName;
54-
private final String[] beforeCode;
55-
private final String[] afterCode;
54+
private final String beforeCode;
55+
private final String afterCode;
5656
private final String title;
5757
private final SupportedLanguages nextVersion;
5858

@@ -69,8 +69,8 @@ public enum SupportedLanguages {
6969
@NotNull String name,
7070
@NotNull String mainFileName,
7171
@NotNull String comment,
72-
@Nullable String[] beforeCode,
73-
@Nullable String[] afterCode) {
72+
@Nullable String beforeCode,
73+
@Nullable String afterCode) {
7474
this(title, name, mainFileName, comment, beforeCode, afterCode, null);
7575

7676
}
@@ -80,8 +80,8 @@ public enum SupportedLanguages {
8080
@NotNull String name,
8181
@NotNull String mainFileName,
8282
@NotNull String comment,
83-
@Nullable String[] beforeCode,
84-
@Nullable String[] afterCode,
83+
@Nullable String beforeCode,
84+
@Nullable String afterCode,
8585
@Nullable SupportedLanguages nextVersion) {
8686
this.title = title;
8787
this.name = name;
@@ -128,13 +128,13 @@ public String getMainFileName() {
128128
}
129129

130130
@NotNull
131-
public String[] getBeforeCode() {
132-
return beforeCode != null ? beforeCode : new String[0];
131+
public String getBeforeCode() {
132+
return beforeCode != null ? beforeCode : "";
133133
}
134134

135135
@NotNull
136-
public String[] getAfterCode() {
137-
return afterCode != null ? afterCode : new String[0];
136+
public String getAfterCode() {
137+
return afterCode != null ? afterCode : "";
138138
}
139139

140140
/**

stepik-union/src/main/java/org/stepik/core/courseFormat/Node.java

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -307,64 +307,66 @@ public StudyStatus getStatus() {
307307
if (!isAuthenticated()) {
308308
return;
309309
}
310-
try {
311-
Map<String, StudyNode> progressMap = new HashMap<>();
312-
Node.this.getChildren().stream()
313-
.filter(StudyNode::isUnknownStatus)
314-
.forEach(child -> {
315-
DC data = child.getData();
316-
if (data != null) {
317-
progressMap.put(data.getProgress(), child);
318-
}
319-
});
320-
D data = Node.this.getData();
321-
if (data != null) {
322-
String progressId = data.getProgress();
323-
if (progressId != null) {
324-
progressMap.put(progressId, Node.this);
325-
}
326310

327-
Set<String> progressIds = progressMap.keySet();
311+
Map<String, StudyNode> progressMap = new HashMap<>();
312+
Node.this.getChildren().stream()
313+
.filter(StudyNode::isUnknownStatus)
314+
.forEach(child -> {
315+
DC data = child.getData();
316+
if (data != null) {
317+
progressMap.put(data.getProgress(), child);
318+
}
319+
});
320+
D data = Node.this.getData();
321+
if (data != null) {
322+
String progressId = data.getProgress();
323+
if (progressId != null) {
324+
progressMap.put(progressId, Node.this);
325+
}
328326

329-
if (!progressIds.isEmpty()) {
330-
int size = progressIds.size();
331-
String[] list = progressIds.toArray(new String[size]);
332-
int start = 0;
333-
int end;
327+
Set<String> progressIds = progressMap.keySet();
334328

335-
while (start < size) {
336-
end = start + 20;
337-
if (end > size) {
338-
end = size;
339-
}
340-
String[] part = Arrays.copyOfRange(list, start, end);
341-
start = end;
329+
if (!progressIds.isEmpty()) {
330+
int size = progressIds.size();
331+
String[] list = progressIds.toArray(new String[size]);
332+
int start = 0;
333+
int end;
334+
335+
while (start < size) {
336+
end = start + 20;
337+
if (end > size) {
338+
end = size;
339+
}
340+
String[] part = Arrays.copyOfRange(list, start, end);
341+
start = end;
342342

343-
Progresses progresses = stepikApiClient.progresses()
343+
Progresses progresses;
344+
try {
345+
progresses = stepikApiClient.progresses()
344346
.get()
345347
.id(part)
346348
.execute();
347-
348-
progresses.getItems().forEach(progress -> {
349-
String id = progress.getId();
350-
StudyNode node = progressMap.get(id);
351-
if (progress.isPassed()) {
352-
node.setRawStatus(SOLVED);
353-
}
354-
});
349+
} catch (StepikClientException e) {
350+
logger.warn(e);
351+
return;
355352
}
356-
}
357-
}
358353

359-
ApplicationManager.getApplication().invokeLater(() -> {
360-
if (!project.isDisposed()) {
361-
ProjectView.getInstance(project).refresh();
354+
progresses.getItems().forEach(progress -> {
355+
String id = progress.getId();
356+
StudyNode node = progressMap.get(id);
357+
if (progress.isPassed()) {
358+
node.setRawStatus(SOLVED);
359+
}
360+
});
362361
}
363-
});
364-
365-
} catch (StepikClientException e) {
366-
logger.warn(e);
362+
}
367363
}
364+
365+
ApplicationManager.getApplication().invokeLater(() -> {
366+
if (!project.isDisposed()) {
367+
ProjectView.getInstance(project).refresh();
368+
}
369+
});
368370
});
369371
}
370372

stepik-union/src/main/java/org/stepik/core/courseFormat/stepHelpers/FreeAnswerQuizHelper.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ private boolean isFrozen() {
6363
return true;
6464
}
6565

66+
StepikApiClient stepikClient = authAndGetStepikApiClient();
67+
if (!isAuthenticated()) {
68+
return true;
69+
}
70+
6671
try {
67-
StepikApiClient stepikClient = authAndGetStepikApiClient();
68-
if (!isAuthenticated()) {
69-
return true;
70-
}
7172
Instructions instructions = stepikClient.instructions()
7273
.get()
7374
.id(instructionId)

0 commit comments

Comments
 (0)