Permalink
Browse files

Use Transifex API instead of username/password

  • Loading branch information...
abhinayagarwal committed Sep 6, 2018
1 parent d5a2562 commit 9d5ebe3289a8e9deb34102514ffc4a122bbbbf58
Showing with 16 additions and 22 deletions.
  1. +4 −4 bitbucket-pipelines.yml
  2. +5 −10 controlsfx/build.gradle
  3. +7 −8 controlsfx/src/main/java/impl/build/transifex/Transifex.java
@@ -8,7 +8,7 @@ pipelines:
- gradle
script:
- chmod +x gradlew
- ./gradlew clean assemble uploadPublished -PsonatypeUsername=$SONATYPE_USERNAME -PsonatypePassword=$SONATYPE_PASSWORD -Ptransifex.username=$TRANSIFEX_USERNAME -Ptransifex.password=$TRANSIFEX_PASSWORD
- ./gradlew clean assemble uploadPublished -PsonatypeUsername=$SONATYPE_USERNAME -PsonatypePassword=$SONATYPE_PASSWORD -Ptransifex.api=$TRANSIFEX_API
9.0.0:
- step:
name: Build and assemble 9.0.0 branch
@@ -17,7 +17,7 @@ pipelines:
- gradle
script:
- chmod +x gradlew
- ./gradlew clean assemble uploadPublished -PsonatypeUsername=$SONATYPE_USERNAME -PsonatypePassword=$SONATYPE_PASSWORD -Ptransifex.username=$TRANSIFEX_USERNAME -Ptransifex.password=$TRANSIFEX_PASSWORD
- ./gradlew clean assemble uploadPublished -PsonatypeUsername=$SONATYPE_USERNAME -PsonatypePassword=$SONATYPE_PASSWORD -Ptransifex.api=$TRANSIFEX_API

bookmarks:
8.[0-9][0-9]*.[0-9][0-9]*:
@@ -29,7 +29,7 @@ pipelines:
script:
- chmod +x gradlew .ci/update.sh .ci/commit.sh
- ./.ci/update.sh
- ./gradlew clean assemble uploadPublished -PsonatypeUsername=$SONATYPE_USERNAME -PsonatypePassword=$SONATYPE_PASSWORD -Ptransifex.username=$TRANSIFEX_USERNAME -Ptransifex.password=$TRANSIFEX_PASSWORD
- ./gradlew clean assemble uploadPublished -PsonatypeUsername=$SONATYPE_USERNAME -PsonatypePassword=$SONATYPE_PASSWORD -Ptransifex.api=$TRANSIFEX_API
- ./.ci/commit.sh
9.[0-9][0-9]*.[0-9][0-9]*:
- step:
@@ -40,5 +40,5 @@ pipelines:
script:
- chmod +x gradlew .ci/update.sh .ci/commit.sh
- ./.ci/update.sh
- ./gradlew clean assemble uploadPublished -PsonatypeUsername=$SONATYPE_USERNAME -PsonatypePassword=$SONATYPE_PASSWORD -Ptransifex.username=$TRANSIFEX_USERNAME -Ptransifex.password=$TRANSIFEX_PASSWORD
- ./gradlew clean assemble uploadPublished -PsonatypeUsername=$SONATYPE_USERNAME -PsonatypePassword=$SONATYPE_PASSWORD -Ptransifex.api=$TRANSIFEX_API
- ./.ci/commit.sh
@@ -7,18 +7,14 @@ dependencies {
}

ext {
transifex_username = ""
transifex_password = ""
transifex_api = ""
}

configurations {
jdk

if (project.hasProperty("transifex.username")) {
transifex_username = project.property("transifex.username")
}
if (project.hasProperty("transifex.password")) {
transifex_password = project.getProperty("transifex.password")
if (project.hasProperty("transifex.api")) {
transifex_api = project.getProperty("transifex.api")
}
}

@@ -32,7 +28,7 @@ sourceSets {
task downloadTranslations {
description = "Download translations from Transifex"
doLast {
if (transifex_username.equals("") || transifex_password.equals("")) {
if (transifex_api.isEmpty()) {
logger.warn "----------------------------------------------------------"
logger.warn "Cannot determine Transifex Username/Password."
logger.warn "If you want to build ControlsFX with its translations then"
@@ -44,8 +40,7 @@ task downloadTranslations {
javaexec {
main = 'impl.build.transifex.Transifex'
classpath = sourceSets.main.runtimeClasspath
systemProperty 'transifex.username', transifex_username
systemProperty 'transifex.password', transifex_password
systemProperty 'transifex.api', transifex_api
}
}
}
@@ -53,20 +53,19 @@
private static final String GET_TRANSLATION = BASE_URI + "project/controlsfx/resource/controlsfx-core/translation/%1s?file"; // gets a translation for one language //$NON-NLS-1$
private static final String TRANSLATION_STATS = BASE_URI + "project/controlsfx/resource/controlsfx-core/stats/%1s/"; // gets a translation for one language //$NON-NLS-1$

private static final String USERNAME = System.getProperty("$transifex_username"); //$NON-NLS-1$
private static final String PASSWORD = System.getProperty("$transifex_password"); //$NON-NLS-1$
private static final String TRANSIFEX_API = System.getProperty("transifex.api"); //$NON-NLS-1$
private static final boolean FILTER_INCOMPLETE_TRANSLATIONS = Boolean.parseBoolean(System.getProperty("transifex.filterIncompleteTranslations", "false"));

public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
public static void main(String[] args) {
new Transifex().doTransifexCheck();
}

@SuppressWarnings("unchecked")
private void doTransifexCheck() {
System.out.println("=== Starting Transifex Check ==="); //$NON-NLS-1$

if (USERNAME == null || PASSWORD == null || USERNAME.isEmpty() || PASSWORD.isEmpty()) {
System.out.println(" transifex.username and transifex.password system properties must be specified"); //$NON-NLS-1$
if (TRANSIFEX_API == null || TRANSIFEX_API.isEmpty()) {
System.out.println("transifex.api system properties must be specified"); //$NON-NLS-1$
return;
}

@@ -115,9 +114,9 @@ private String parseInputStream(InputStream inputStream) {
connection.setUseCaches(false);
connection.setDoInput(true);

// pass in username / password
String encoded = Base64.getEncoder().encodeToString((USERNAME+":"+PASSWORD).getBytes()); //$NON-NLS-1$
connection.setRequestProperty("Authorization", "Basic "+encoded); //$NON-NLS-1$ //$NON-NLS-2$
// pass in API details
String encoded = Base64.getEncoder().encodeToString(("api" + ":" + TRANSIFEX_API).getBytes()); //$NON-NLS-1$
connection.setRequestProperty("Authorization", "Basic " + encoded); //$NON-NLS-1$ //$NON-NLS-2$
connection.setRequestProperty("Accept-Charset", CHARSET); //$NON-NLS-1$

return consumer.apply(connection.getInputStream());

0 comments on commit 9d5ebe3

Please sign in to comment.