Skip to content

Commit

Permalink
Merge pull request #30 from massivedisaster/release/0.1.0
Browse files Browse the repository at this point in the history
Release/0.1.0
  • Loading branch information
jzeferino authored Feb 27, 2018
2 parents 2a41276 + 55aad0f commit 72f42ba
Show file tree
Hide file tree
Showing 17 changed files with 505 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
.mtj.tmp/

# Package Files #
*.jar
#*.jar
*.war
*.ear
*.zip
Expand Down
50 changes: 27 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
Bintray deploy automator
===============
This project is a tool to publish artifacts to Bintray for gradle projects with multiple modules that use [Gradle Bintray Plugin](https://github.com/bintray/gradle-bintray-plugin).

Usage
-----
With this automator you just have to create a configuration file like the one below, build the jar and run it. It will clean and build your project and then for each module will run `bintrayUpload` task.
At the end if no errors occurred it will run the extra tasks from configuration.

Configuration
-------------
### Install
Run `jar` task from gradle 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`.
```js
// The json configuration
# Bintray deploy automator

This tool to publish artifacts to Bintray for gradle projects with multiple modules that use [Gradle Bintray Plugin](https://github.com/bintray/gradle-bintray-plugin) or [Novoda Bintray Release](https://github.com/novoda/bintray-release).

## How it works

Bintray deploy automator clean and build your project's modules and then for each module will run `bintrayUpload` task. At the end if no errors occurred it will run the extra tasks.

## How to run

1. Create a configuration file named `configuration.json` like the one below.

```
{
"basePath": "./project", // The path of your project
"version": "0.1.9", // The new version of project to be uploaded
"version": "0.1.0", // The new version of project to be uploaded
// The list of modules to be uploaded to the bintray
"modules": [
"module-1",
"module-2",
"module-3"
],
// Extra tasks
"extraTasks": [
"task-1",
"module-1:task-2"
]
}
```

2. Download the latest [release](https://github.com/massivedisaster/bintray-deploy-automator/releases).
3. Execute `java -jar BintrayDeployAutomator-0.1.0.jar -u Username -k Key`

### Generate release JAR

Run `jar` task from gradle.

* Linux/macOS: `./gradlew jar`
* Windows: `gradlew.bat jar`

### License

[MIT LICENSE](LICENSE.md)
42 changes: 39 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
group 'com.massivedisaster.bintraydeployautomator.Automator'
version '0.0.5'
version '0.1.0'
apply from: "$project.rootDir/updateReadme.gradle"

apply plugin: 'java'

Expand All @@ -11,12 +12,47 @@ repositories {
}

dependencies {
compile "org.gradle:gradle-tooling-api:4.0"
compile "org.gradle:gradle-tooling-api:4.5"
compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.google.code.gson:gson:2.8.2'
compile 'me.tongfei:progressbar:0.5.5'
runtime 'org.slf4j:slf4j-simple:1.7.10'
}

// Task to create an dynamic class with configuration data.
task generateConfig {
inputs.property "version", project.version
doFirst {
def versionFile = file("$buildDir/generated/source/Config.java")
versionFile.parentFile.mkdirs()
versionFile.text =
"""
package com.massivedisaster.bintraydeployautomator.utils;
/**
* Automatically generated file. DO NOT MODIFY
*/
public class Config {
public static final String VERSION = "$project.version";
public static final String NAME = "BintrayDeployAutomator-$project.version";
}
"""
}
}

project.sourceSets.matching { it.name == "main" } .all {
it.java.srcDir "$buildDir/generated/source"
}

task updateReadme {
doLast {
processUpdateReadme file("$project.rootDir"), ".md", version.toString()
}
}

compileJava.dependsOn generateConfig
compileJava.dependsOn updateReadme

jar {
baseName 'BintrayDeployAutomator'

Expand Down
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
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-4.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.massivedisaster.bintraydeployautomator;

import com.massivedisaster.bintraydeployautomator.model.Arguments;
import com.massivedisaster.bintraydeployautomator.model.Configuration;
import com.massivedisaster.bintraydeployautomator.output.BarProgress;
import com.massivedisaster.bintraydeployautomator.output.ConsoleProgress;
import com.massivedisaster.bintraydeployautomator.output.ProgressManager;
import com.massivedisaster.bintraydeployautomator.utils.CommandLineUtils;
import com.massivedisaster.bintraydeployautomator.utils.FileUtils;
import com.massivedisaster.bintraydeployautomator.utils.Config;
import com.massivedisaster.bintraydeployautomator.utils.ConsoleUtils;
import com.massivedisaster.bintraydeployautomator.utils.GradleUtils;
import javafx.util.Pair;
import org.gradle.tooling.GradleConnector;
import org.gradle.tooling.ProjectConnection;

import java.io.File;
import java.io.*;
import java.util.List;

/**
* Bintray deploy automator.
Expand All @@ -20,56 +25,83 @@ public class Automator {
*
* @param args command line arguments.
*/
public static void main(String args[]) {
public static void main(String args[]) throws IOException {

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

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

configuration.setBintrayUsername(auth.getKey());
configuration.setBintrayKey(auth.getValue());
List<String> modules = configuration.getModules();
boolean hasModules = modules != null;
int steps = hasModules ? modules.size() * 2 : 1;

gradleConnection = GradleConnector.newConnector()
.forProjectDirectory(new File(configuration.getBasePath()))
configuration.setBintrayUsername(auth.getUser());
configuration.setBintrayKey(auth.getKey());
configuration.setVerbose(auth.isVerbose());
outputFile = auth.getLogFile();
if (outputFile != null) {
File output = new File(outputFile);
if (output.exists()) {
new FileWriter(outputFile).close();
}
progressManager = new ProgressManager(new BarProgress(), Config.NAME, steps);
} else {
progressManager = new ProgressManager(new ConsoleProgress(), Config.NAME, steps);
}

gradleConnection = GradleConnector.newConnector().forProjectDirectory(new File(configuration.getBasePath()))
.connect();

// Clean build and deploy all projects.
rebuildAndBintrayDeploy(gradleConnection, configuration);
ConsoleUtils.DrawInConsoleBox("Start process");

if (hasModules) {
progressManager.start();
//clean and build
for (String module : modules) {
progressManager.logMessage("Clean and building module " + module + "...");
GradleUtils.runGradle(gradleConnection, outputFile, new String[]{module + ":clean", module + ":build"},
configuration.getArguments());
progressManager.step();
}

//clean and build
for (String module : modules) {
progressManager.logMessage("Uploading to bintray module " + module + "...");
GradleUtils.runGradle(gradleConnection, outputFile, new String[]{module + ":bintrayUpload"}, configuration.getArguments());
progressManager.step();
}
progressManager.stop();
} else {
GradleUtils.runGradle(gradleConnection, outputFile, configuration.getTasks(), configuration.getArguments());
}

if (configuration.canRunExtraTasks()) {
runExtraTasks(gradleConnection, configuration);
ConsoleUtils.DrawInConsoleBox("Executing extra tasks");
GradleUtils.runGradle(gradleConnection, auth.getLogFile(), configuration.getExtraTasks(), configuration.getArguments());
}

ConsoleUtils.DrawInConsoleBox("End process");

} catch (Exception e) {
System.out.println("Automator Error: " + e.toString());
progressManager.stop();
if (outputFile == null) {
progressManager.logMessage("Automator Error: " + e.toString());
} else {
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile, true)));
out.append("Automator Error: ");
out.append(e.toString());
out.append("\n");
out.close();
}
} finally {
if (gradleConnection != null) {
gradleConnection.close();
}
}
}


/**
* Run build and upload to bintray.
*
* @param gradleConnection the gradle connection.
* @param configuration the configuration model.
*/
private static void rebuildAndBintrayDeploy(ProjectConnection gradleConnection, Configuration configuration) {
GradleUtils.runGradle(gradleConnection, configuration.getTasks(), configuration.getArguments());
}

/**
* Run extra tasks from project.
*
* @param gradleConnection the gradle connection.
* @param configuration the configuration model.
*/
private static void runExtraTasks(ProjectConnection gradleConnection, Configuration configuration) {
GradleUtils.runGradle(gradleConnection, configuration.getExtraTasks(), configuration.getArguments());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.massivedisaster.bintraydeployautomator.model;

public class Arguments {

private String mUser;
private String mKey;
private boolean isVerbose;
private String mLogFile;

public Arguments(String user, String key, boolean verbose, String logFile) {
mUser = user;
mKey = key;
isVerbose = verbose;
mLogFile = logFile;
}

public String getUser() {
return mUser;
}

public void setUser(String user) {
this.mUser = user;
}

public String getKey() {
return mKey;
}

public void setKey(String key) {
this.mKey = key;
}

public boolean isVerbose() {
return isVerbose;
}

public void setVerbose(boolean verbose) {
isVerbose = verbose;
}

public String getLogFile() {
return mLogFile;
}

public void setLogFile(String logFile) {
this.mLogFile = logFile;
}

}
Loading

0 comments on commit 72f42ba

Please sign in to comment.