diff --git a/README.md b/README.md index a9d81d1..04ef083 100644 --- a/README.md +++ b/README.md @@ -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`. @@ -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 diff --git a/build.gradle b/build.gradle index 333ebd7..1151b8e 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b0b626c..4baab8f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/src/main/java/com/massivedisaster/bintraydeployautomator/Automator.java b/src/main/java/com/massivedisaster/bintraydeployautomator/Automator.java index a86de38..2037c09 100644 --- a/src/main/java/com/massivedisaster/bintraydeployautomator/Automator.java +++ b/src/main/java/com/massivedisaster/bintraydeployautomator/Automator.java @@ -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; @@ -22,10 +24,14 @@ public static void main(String args[]) { ProjectConnection gradleConnection = null; try { + Pair 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(); @@ -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. diff --git a/src/main/java/com/massivedisaster/bintraydeployautomator/model/Configuration.java b/src/main/java/com/massivedisaster/bintraydeployautomator/model/Configuration.java index eda4b03..4ade2de 100644 --- a/src/main/java/com/massivedisaster/bintraydeployautomator/model/Configuration.java +++ b/src/main/java/com/massivedisaster/bintraydeployautomator/model/Configuration.java @@ -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; @@ -69,22 +68,12 @@ public List 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; } /** diff --git a/src/main/java/com/massivedisaster/bintraydeployautomator/utils/CommandLineUtils.java b/src/main/java/com/massivedisaster/bintraydeployautomator/utils/CommandLineUtils.java new file mode 100644 index 0000000..76549f4 --- /dev/null +++ b/src/main/java/com/massivedisaster/bintraydeployautomator/utils/CommandLineUtils.java @@ -0,0 +1,39 @@ +package com.massivedisaster.bintraydeployautomator.utils; + +import javafx.util.Pair; +import org.apache.commons.cli.*; + +public class CommandLineUtils { + + public static Pair 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); + } + +}