@ -22,16 +22,21 @@ import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.Input ;
import org.gradle.api.tasks.Input ;
import org.gradle.api.tasks.InputFile ;
import org.gradle.api.tasks.InputFile ;
import org.gradle.api.tasks.Optional ;
import org.gradle.api.tasks.Optional ;
import org.gradle.api.tasks.OutputFile ;
import org.gradle.api.tasks.TaskAction ;
import org.gradle.api.tasks.TaskAction ;
import org.gradle.work.DisableCachingByDefault ;
import org.yaml.snakeyaml.Yaml ;
import org.yaml.snakeyaml.Yaml ;
import org.yaml.snakeyaml.constructor.Constructor ;
import org.yaml.snakeyaml.constructor.Constructor ;
import java.io.File ;
import java.io.File ;
import java.io.FileInputStream ;
import java.io.FileInputStream ;
import java.io.FileNotFoundException ;
import java.io.IOException ;
import java.nio.file.Files ;
import java.nio.file.Path ;
import org.springframework.gradle.github.RepositoryRef ;
import org.springframework.gradle.github.RepositoryRef ;
@DisableCachingByDefault ( because = "the due date needs to be checked every time in case it changes" )
public abstract class GitHubMilestoneNextVersionDueTodayTask extends DefaultTask {
public abstract class GitHubMilestoneNextVersionDueTodayTask extends DefaultTask {
@Input
@Input
@ -44,10 +49,13 @@ public abstract class GitHubMilestoneNextVersionDueTodayTask extends DefaultTask
@InputFile
@InputFile
public abstract RegularFileProperty getNextVersionFile ( ) ;
public abstract RegularFileProperty getNextVersionFile ( ) ;
@OutputFile
public abstract RegularFileProperty getIsDueTodayFile ( ) ;
private GitHubMilestoneApi milestones = new GitHubMilestoneApi ( ) ;
private GitHubMilestoneApi milestones = new GitHubMilestoneApi ( ) ;
@TaskAction
@TaskAction
public void checkReleaseDueToday ( ) throws FileNotFound Exception {
public void checkReleaseDueToday ( ) throws IO Exception {
File nextVersionFile = getNextVersionFile ( ) . getAsFile ( ) . get ( ) ;
File nextVersionFile = getNextVersionFile ( ) . getAsFile ( ) . get ( ) ;
Yaml yaml = new Yaml ( new Constructor ( NextVersionYml . class ) ) ;
Yaml yaml = new Yaml ( new Constructor ( NextVersionYml . class ) ) ;
NextVersionYml nextVersionYml = yaml . load ( new FileInputStream ( nextVersionFile ) ) ;
NextVersionYml nextVersionYml = yaml . load ( new FileInputStream ( nextVersionFile ) ) ;
@ -57,12 +65,17 @@ public abstract class GitHubMilestoneNextVersionDueTodayTask extends DefaultTask
"Could not find version property in provided file " + nextVersionFile . getName ( ) ) ;
"Could not find version property in provided file " + nextVersionFile . getName ( ) ) ;
}
}
boolean milestoneDueToday = this . milestones . isMilestoneDueToday ( this . repository , nextVersion ) ;
boolean milestoneDueToday = this . milestones . isMilestoneDueToday ( this . repository , nextVersion ) ;
if ( ! milestoneDueToday ) {
Path isDueTodayPath = getIsDueTodayFile ( ) . getAsFile ( ) . get ( ) . toPath ( ) ;
throw new IllegalStateException ( "The milestone with the title " + nextVersion + " in the repository "
Files . writeString ( isDueTodayPath , String . valueOf ( milestoneDueToday ) ) ;
if ( milestoneDueToday ) {
System . out . println ( "The milestone with the title " + nextVersion + " in the repository " + this . repository
+ " is due today" ) ;
}
else {
System . out . println ( "The milestone with the title " + nextVersion + " in the repository "
+ this . repository + " is not due yet" ) ;
+ this . repository + " is not due yet" ) ;
}
}
System . out . println ( "The milestone with the title " + nextVersion + " in the repository " + this . repository
+ " is due today" ) ;
}
}
public RepositoryRef getRepository ( ) {
public RepositoryRef getRepository ( ) {