Skip to content

Commit 8e101bc

Browse files
committed
Merge pull request #5 from studyplus/jar-publishing
Add archive type to publish of .jar other than current .aar
2 parents e5303b3 + 176c37c commit 8e101bc

File tree

9 files changed

+83
-40
lines changed

9 files changed

+83
-40
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ Graddle Project
1414

1515
```groovy
1616
repositories {
17-
maven { url 'http://raw.github.com/studyplus/Studyplus-Android-SDK/master/repository' }
17+
mavenCentral()
1818
}
1919
dependencies {
20-
compile 'jp.studyplus.android.sdk:studyplus-android-sdk:1.0.0'
20+
compile 'jp.studyplus.android.sdk:studyplus-android-sdk:1.0.2'
2121
}
2222
```
2323

StudyplusAndroidSDK/build.gradle

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,6 @@ dependencies {
3434
forTesting.each{ instrumentTestCompile it }
3535
}
3636

37-
if (gradle.startParameter.taskNames.contains('uploadArchives')) {
38-
apply from: 'gradle/build.publish.gradle'
39-
}
37+
apply from: 'gradle/build.values.gradle'
4038

41-
android.libraryVariants.all { variant ->
42-
def name = variant.name
43-
task "javadoc-$name"(type: Javadoc) {
44-
description = "Generates javadoc for build $name"
45-
destinationDir = new File(destinationDir, variant.baseName)
46-
source = files(variant.javaCompile.source)
47-
classpath = files(android.plugin.runtimeJarList, variant.javaCompile.classpath)
48-
exclude '**/R.java'
49-
}
50-
}
39+
apply from: 'gradle/build.publish.gradle'

StudyplusAndroidSDK/gradle.properties.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ signing.keyId=__your_value__
22
signing.password=__your_value__
33
signing.secretKeyRingFile=__your_value__
44

5-
sonatypeUsername=__your_value__
6-
sonatypePassword=__your_value__
5+
debugApiEndpoint = __your_value__

StudyplusAndroidSDK/gradle/build.publish.gradle

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,43 @@ signing {
55
sign configurations.archives
66
}
77

8+
task sdkJar(type: Jar) {
9+
from fileTree(dir: 'build/classes/release').matching { include 'jp/studyplus/android/sdk/**' }
10+
}
11+
12+
task androidJavadocs(type: Javadoc) {
13+
source = android.sourceSets.main.allJava
14+
}
15+
16+
task androidJavadocsJar(type: Jar) {
17+
classifier = 'javadoc'
18+
from androidJavadocs.destinationDir
19+
}
20+
21+
task androidSourcesJar(type: Jar) {
22+
classifier = 'sources'
23+
from android.sourceSets.main.allSource
24+
}
25+
26+
artifacts {
27+
archives sdkJar
28+
archives androidSourcesJar
29+
archives androidJavadocsJar
30+
}
31+
32+
if (!gradle.startParameter.taskNames.contains('uploadArchives')) {
33+
return
34+
}
35+
36+
// gradle --daemon option makes System.console() null.
37+
// you must turn --daemon off when executing uploadArchives.
38+
def requireInput = { message ->
39+
if (System.console() == null){
40+
throw new IllegalStateException("try turning --daemon off")
41+
}
42+
"${System.console().readPassword(message)}"
43+
}
44+
845
uploadArchives {
946
repositories {
1047
mavenDeployer {
@@ -13,15 +50,14 @@ uploadArchives {
1350
}
1451
repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') {
1552
authentication(
16-
userName: project.properties.sonatypeUsername,
17-
password: project.properties.sonatypePassword)
53+
userName: requireInput("\nsonatype-username:"),
54+
password: requireInput("sonatype-password:") )
1855
}
1956
pom.version = "1.0.2"
2057
pom.groupId = 'jp.studyplus.android.sdk'
2158
pom.artifactId = "studyplus-android-sdk"
2259
pom.project {
2360
name 'Studyplus Android SDK'
24-
packaging 'aar'
2561
description 'Studyplus SDK for Android'
2662
url 'https://github.com/studyplus/Studyplus-Android-SDK'
2763
scm {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
def apiEndpoint = {
3+
def debugTasks = [
4+
':SDKExample:assembleDevelopmentDebug',
5+
]
6+
def isCurrentTaskForDebug = {
7+
debugTasks.any {
8+
gradle.startParameter.taskNames.contains it
9+
}
10+
}
11+
if (isCurrentTaskForDebug()){
12+
project.properties.debugApiEndpoint
13+
} else {
14+
"https://external-api.studyplus.jp"
15+
}
16+
}
17+
18+
android{
19+
def quote = { '"' + it + '"' }
20+
release {
21+
buildConfigField "String", "API_ENDPOINT", quote(apiEndpoint())
22+
}
23+
/**
24+
* CAUTION: this debug `buildConfigField` does NOT work!
25+
* rf. https://code.google.com/p/android/issues/detail?id=52962
26+
*/
27+
debug {
28+
buildConfigField "String", "API_ENDPOINT", quote(project.properties.debugApiEndpoint)
29+
}
30+
}

StudyplusAndroidSDK/src/main/java/jp/studyplus/android/sdk/service/api/ApiCertification.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
public interface ApiCertification {
77

88
public String getAccessToken();
9-
10-
public String getBaseUrl();
119
}

StudyplusAndroidSDK/src/main/java/jp/studyplus/android/sdk/service/api/ApiRequester.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.io.IOException;
66

7+
import jp.studyplus.android.sdk.BuildConfig;
78
import jp.studyplus.android.sdk.internal.api.ApiAccess;
89
import jp.studyplus.android.sdk.internal.api.ApiResponse;
910

@@ -15,7 +16,7 @@ class ApiRequester {
1516
public ApiRequester(ApiRequest request, ApiCertification certification) {
1617
this.request = request;
1718
this.access = new ApiAccess(
18-
certification.getBaseUrl() + request.getScriptPath(),
19+
BuildConfig.API_ENDPOINT + request.getScriptPath(),
1920
certification.getAccessToken());
2021
}
2122
public ApiEither request() throws IOException {

StudyplusAndroidSDK/src/main/java/jp/studyplus/android/sdk/service/auth/CertificationStore.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import com.google.common.base.Optional;
99

10-
import jp.studyplus.android.sdk.R;
10+
import jp.studyplus.android.sdk.BuildConfig;
1111
import jp.studyplus.android.sdk.service.api.ApiCertification;
1212

1313
import static android.content.SharedPreferences.Editor;
@@ -19,18 +19,16 @@ public class CertificationStore {
1919
private final SharedPreferences preferences;
2020

2121
private static String KEY_ACCESS_TOKEN = "access_token";
22-
private final String baseUrl;
2322

2423
public static CertificationStore create(Context context) {
25-
String baseUrl = context.getString(R.string.studyplus_api_base_url);
26-
String prefName = "Certification:" + Uri.parse(baseUrl).getHost();
24+
String prefName = "Certification:" + Uri.parse(BuildConfig.API_ENDPOINT).getHost();
2725
SharedPreferences pref = context.getSharedPreferences(prefName, Context.MODE_PRIVATE);
28-
return new CertificationStore(pref, baseUrl);
26+
return new CertificationStore(pref);
2927
}
30-
private CertificationStore(SharedPreferences preferences, String baseUrl) {
28+
private CertificationStore(SharedPreferences preferences) {
3129
this.preferences = preferences;
32-
this.baseUrl = baseUrl;
3330
}
31+
3432
public void update(Intent data){
3533
if (data == null){
3634
return;
@@ -57,26 +55,19 @@ public ApiCertification getDefault() {
5755
if (!token.isPresent()){
5856
throw new AccessTokenNotFound();
5957
}
60-
return new ApiCertificationImpl(token.get(), baseUrl);
58+
return new ApiCertificationImpl(token.get());
6159
}
6260

6361
private static class ApiCertificationImpl implements ApiCertification{
6462
private final String accessToken;
65-
private final String baseUrl;
6663

67-
private ApiCertificationImpl(String accessToken, String baseUrl) {
64+
private ApiCertificationImpl(String accessToken) {
6865
this.accessToken = accessToken;
69-
this.baseUrl = baseUrl;
7066
}
7167

7268
@Override
7369
public String getAccessToken() {
7470
return accessToken;
7571
}
76-
77-
@Override
78-
public String getBaseUrl() {
79-
return baseUrl;
80-
}
8172
}
8273
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<resources>
22
<string name="app_name">StudyplusAndroidSDK</string>
3-
<string name="studyplus_api_base_url">https://external-api.studyplus.jp</string>
43
</resources>

0 commit comments

Comments
 (0)