Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Plugin DSL more typesafe #339

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/main/groovy/com/jfrog/bintray/gradle/BintrayExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class BintrayExtension {
this.project = project
}

def pkg(Closure closure) {
def pkg(Closure<PackageConfig> closure) {
ConfigureUtil.configure(closure, pkg)
}

def filesSpec(Closure closure) {
filesSpec = project.task(type: RecordingCopyTask, RecordingCopyTask.NAME)
def filesSpec(Closure<RecordingCopyTask> closure) {
filesSpec = (RecordingCopyTask) project.task(type: RecordingCopyTask, RecordingCopyTask.NAME)
ConfigureUtil.configure(closure, filesSpec)
filesSpec.outputs.upToDateWhen { false }
}
Expand All @@ -59,12 +59,12 @@ class BintrayExtension {
Map attributes

VersionConfig version = new VersionConfig()
def version(Closure closure) {
def version(Closure<VersionConfig> closure) {
ConfigureUtil.configure(closure, version)
}

DebianConfig debian = new DebianConfig()
def debian(Closure closure) {
def debian(Closure<DebianConfig> closure) {
ConfigureUtil.configure(closure, debian)
}
}
Expand All @@ -83,12 +83,12 @@ class BintrayExtension {
Map attributes

GpgConfig gpg = new GpgConfig()
def gpg(Closure closure) {
def gpg(Closure<GpgConfig> closure) {
ConfigureUtil.configure(closure, gpg)
}

MavenCentralSyncConfig mavenCentralSync = new MavenCentralSyncConfig()
def mavenCentralSync(Closure closure) {
def mavenCentralSync(Closure<MavenCentralSyncConfig> closure) {
ConfigureUtil.configure(closure, mavenCentralSync)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BintrayHttpClientFactory {
static HTTPBuilder create(apiUrl, user, apiKey) {
def assertNotEmpty = { String name, String val ->
if (val?.isEmpty()) {
throw new IllegalArgumentException("Bintray $name cannot be empty!");
throw new IllegalArgumentException("Bintray $name cannot be empty!")
}
}
assertNotEmpty('apiUrl', apiUrl)
Expand Down Expand Up @@ -80,7 +80,7 @@ class BintrayHttpClientFactory {

if (System.getProperty('http.proxyHost')) {
String proxyHost = System.getProperty('http.proxyHost')
Integer proxyPort = Integer.parseInt(System.getProperty('http.proxyPort', '80'));
Integer proxyPort = Integer.parseInt(System.getProperty('http.proxyPort', '80'))
String proxyUser = System.getProperty('http.proxyUser')
String proxyPassword = System.getProperty('http.proxyPassword', '')
logger.info "Using proxy ${proxyUser}:${proxyPassword}@${proxyHost}:${proxyPort}"
Expand Down
21 changes: 11 additions & 10 deletions src/main/groovy/com/jfrog/bintray/gradle/BintrayPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import org.gradle.api.*

class BintrayPlugin implements Plugin<Project> {

public void apply(Project project) {
void apply(Project project) {
if (project.getTasks().findByName(BintrayUploadTask.TASK_NAME) == null) {
//Create and configure the task
BintrayUploadTask bintrayUpload = project.task(type: BintrayUploadTask, BintrayUploadTask.TASK_NAME)
BintrayUploadTask bintrayUpload = (BintrayUploadTask) project.task(type: BintrayUploadTask, BintrayUploadTask.TASK_NAME)
bintrayUpload.project = project
project.gradle.addListener(new ProjectsEvaluatedBuildListener(bintrayUpload))
}
Expand All @@ -20,7 +20,7 @@ class BintrayPlugin implements Plugin<Project> {
} else {
if (!project.getRootProject().getPluginManager().hasPlugin("com.jfrog.bintray")) {
// Reached this state means that the plugin is not enabled on the root project
BintrayUploadTask bintrayUploadRoot = project.getRootProject().task(type: BintrayUploadTask, BintrayUploadTask.TASK_NAME)
BintrayUploadTask bintrayUploadRoot = (BintrayUploadTask) project.getRootProject().task(type: BintrayUploadTask, BintrayUploadTask.TASK_NAME)
bintrayUploadRoot.setEnabled(false)
bintrayUploadRoot.project = project.getRootProject()
project.getRootProject().gradle.addListener(new ProjectsEvaluatedBuildListener(bintrayUploadRoot))
Expand All @@ -29,35 +29,36 @@ class BintrayPlugin implements Plugin<Project> {
}
}

private BintrayUploadTask addBintrayUploadTask(Project project) {
BintrayUploadTask bintrayUploadTask = project.tasks.findByName(BintrayUploadTask.TASK_NAME)
private static BintrayUploadTask addBintrayUploadTask(Project project) {
BintrayUploadTask bintrayUploadTask = (BintrayUploadTask) project.tasks.findByName(BintrayUploadTask.TASK_NAME)
if (bintrayUploadTask == null) {
bintrayUploadTask = createBintrayUploadTask(project)
bintrayUploadTask.setGroup(BintrayUploadTask.GROUP)
}
return bintrayUploadTask
}

BintrayUploadTask createBintrayUploadTask(Project project) {
static BintrayUploadTask createBintrayUploadTask(Project project) {
def result = project.getTasks().create(BintrayUploadTask.TASK_NAME, BintrayUploadTask.class)
result.setDescription('''AddS bintray closure''')
return result
}

private static boolean isRootProject(Project project) {
project.equals(project.getRootProject())
project == project.getRootProject()
}

private BintrayPublishTask addBintrayPublishTask(Project project) {
Task signAndPublish = project.tasks.findByName(BintrayPublishTask.TASK_NAME)
private static BintrayPublishTask addBintrayPublishTask(Project project) {
BintrayPublishTask signAndPublish = (BintrayPublishTask) project.tasks.findByName(BintrayPublishTask.TASK_NAME)
if (signAndPublish == null) {
project.getLogger().info("Configuring signAndPublish task for project ${project.path}")
signAndPublish = createBintraySignAndPublishTask(project)
signAndPublish.setGroup(BintrayUploadTask.GROUP)
}
return signAndPublish
}

protected BintrayPublishTask createBintraySignAndPublishTask(Project project) {
protected static BintrayPublishTask createBintraySignAndPublishTask(Project project) {
def result = project.getTasks().create(BintrayPublishTask.TASK_NAME, BintrayPublishTask.class)
result.setDescription('''Bintray Sign, publish and Maven central sync task''')
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.util.concurrent.ConcurrentHashMap

class ProjectsEvaluatedBuildListener extends BuildAdapter implements ProjectEvaluationListener {
private BintrayUploadTask bintrayUpload
private final Set<BintrayUploadTask> bintrayUploadTasks = Collections.newSetFromMap(new ConcurrentHashMap<Task, Boolean>());
private final Set<BintrayUploadTask> bintrayUploadTasks = Collections.newSetFromMap(new ConcurrentHashMap<BintrayUploadTask, Boolean>())

ProjectsEvaluatedBuildListener(BintrayUploadTask bintrayUpload) {
this.bintrayUpload = bintrayUpload
Expand Down
20 changes: 10 additions & 10 deletions src/main/groovy/com/jfrog/bintray/gradle/Utils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import java.text.ParseException
import java.text.SimpleDateFormat

class Utils {
public static void addHeaders(Map<?,?> headers) {
static void addHeaders(Map<?,?> headers) {
headers.put("User-Agent","gradle-bintray-plugin/${new Utils().pluginVersion}")
}

public String getPluginVersion() {
String getPluginVersion() {
Properties props = new Properties()
props.load(getClass().classLoader.getResource("bintray.plugin.release.properties").openStream())
props.get('version')
Expand All @@ -24,26 +24,26 @@ class Utils {
* In case the input string already has the target format, it is returned as is.
* If the input string has a different format, a ParseException is thrown.
*/
public static String toIsoDateFormat(String dateString) throws ParseException {
static String toIsoDateFormat(String dateString) throws ParseException {
if (dateString == null) {
return null
}
DateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
try {
isoFormat.parse(dateString)
return dateString
} catch (ParseException e) {
} catch (ParseException ignored) {
}

DateFormat dateToStringFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH)
return isoFormat.format(dateToStringFormat.parse(dateString))
}

public static String readArtifactIdFromPom(File pom) {
FileReader reader = new FileReader(pom);
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
Model model = mavenreader.read(reader);
MavenProject project = new MavenProject(model);
return project.getArtifactId();
static String readArtifactIdFromPom(File pom) {
FileReader reader = new FileReader(pom)
MavenXpp3Reader mavenReader = new MavenXpp3Reader()
Model model = mavenReader.read(reader)
MavenProject project = new MavenProject(model)
return project.getArtifactId()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class BintrayUploadTask extends DefaultTask {

@TaskAction
void bintrayUpload() {
logger.info("Gradle Bintray Plugin version: ${new Utils().pluginVersion}");
logger.info("Gradle Bintray Plugin version: ${new Utils().pluginVersion}")
if (getEnabled()) {
validateDebianDefinition()
//TODO: [by yl] replace with findResults for Gradle 2.x
Expand Down Expand Up @@ -414,14 +414,14 @@ class BintrayUploadTask extends DefaultTask {
return version ? version : v
}

void setPackageAsCreated(Package pkg) {
static void setPackageAsCreated(Package pkg) {
pkg.setAsCreated()
synchronized (pkg) {
pkg.notifyAll()
}
}

void setVersionAsCreated(Version version) {
static void setVersionAsCreated(Version version) {
version.setAsCreated()
synchronized (version) {
version.notifyAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Package {
this.created = true
}

public Version addVersionIfAbsent(Version version) {
Version addVersionIfAbsent(Version version) {
Version v = versions.putIfAbsent(version.name, version)
if (v) {
v.merge(version)
Expand Down