Skip to content

Commit

Permalink
Merge pull request #16 from massivedisaster/feature/auth_in_arguments
Browse files Browse the repository at this point in the history
Moved username and key from json to command line arguments
  • Loading branch information
jzeferino authored Jun 12, 2017
2 parents 59953b0 + 98d03e2 commit 3fbe422
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 21 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ At the end if no errors occurred it will update your readme specified configurat
Configuration
-------------
### Install
Run `jar` task from gradle and create configuration file.

Just build and create configuration file.
### How to run
`java -jar BintrayDeployAutomator.jar -u Username -k Key`

### Configuration file (configuration.json)
The configuration file must be named `configuration.json`.
Expand All @@ -26,9 +28,7 @@ The configuration file must be named `configuration.json`.
"module-1",
"module-2",
"module-3"
],
"bintrayUsername": "{username}", // The bintray username
"bintrayKey": "{key}" // The api key of bintray
]
}
```
### License
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repositories {

dependencies {
compile "org.gradle:gradle-tooling-api:3.5"
compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
compile 'com.google.code.gson:gson:2.8.0'
runtime 'org.slf4j:slf4j-simple:1.7.10'
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.massivedisaster.bintraydeployautomator;

import com.massivedisaster.bintraydeployautomator.model.Configuration;
import com.massivedisaster.bintraydeployautomator.utils.CommandLineUtils;
import com.massivedisaster.bintraydeployautomator.utils.FileUtils;
import com.massivedisaster.bintraydeployautomator.utils.GradleUtils;
import javafx.util.Pair;
import org.gradle.tooling.GradleConnector;
import org.gradle.tooling.ProjectConnection;

Expand All @@ -22,10 +24,14 @@ public static void main(String args[]) {

ProjectConnection gradleConnection = null;
try {
Pair<String, String> auth = CommandLineUtils.commandLineArgs(args);

// Get configuration from .json.
Configuration configuration = Configuration.parseConfiguration("configuration.json");

configuration.setBintrayUsername(auth.getKey());
configuration.setBintrayKey(auth.getValue());

gradleConnection = GradleConnector.newConnector()
.forProjectDirectory(new File(configuration.getBasePath()))
.connect();
Expand All @@ -47,8 +53,9 @@ public static void main(String args[]) {
}
}


/**
* Rubuild and upload to bintray.
* Run build and upload to bintray.
*
* @param gradleConnection the gradle connection.
* @param configuration the configuration model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.gson.Gson;
import com.massivedisaster.bintraydeployautomator.utils.ArrayUtils;

import org.gradle.internal.impldep.org.apache.commons.lang.StringUtils;

import java.io.IOException;
Expand Down Expand Up @@ -69,22 +68,12 @@ public List<String> getModules() {
return modules;
}

/**
* Gets bintray username.
*
* @return bintray username.
*/
public String getBintrayUsername() {
return bintrayUsername;
public void setBintrayUsername(String bintrayUsername) {
this.bintrayUsername = bintrayUsername;
}

/**
* Gets bintray key.
*
* @return bintray key.
*/
public String getBintrayKey() {
return bintrayKey;
public void setBintrayKey(String bintrayKey) {
this.bintrayKey = bintrayKey;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.massivedisaster.bintraydeployautomator.utils;

import javafx.util.Pair;
import org.apache.commons.cli.*;

public class CommandLineUtils {

public static Pair<String, String> commandLineArgs(String[] args) {
Options options = new Options();

Option input = new Option("u", "user", true, "Bintray Username");
input.setRequired(true);
options.addOption(input);

Option output = new Option("k", "key", true, "Bintray Key");
output.setRequired(true);
options.addOption(output);

CommandLineParser parser = new DefaultParser();
HelpFormatter formatter = new HelpFormatter();
CommandLine cmd;

try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
System.out.println(e.getMessage());
formatter.printHelp("Java -jar BintrayDeployAutomator-0.0.2.jar", options);

System.exit(1);
return null;
}

String user = cmd.getOptionValue("user");
String key = cmd.getOptionValue("key");

return new Pair<>(user, key);
}

}

0 comments on commit 3fbe422

Please sign in to comment.