com.sqlapp.gradle.plugins.AbstractTask.groovy Maven / Gradle / Ivy
/*
* Copyright (C) 2007-2017 Tatsuo Satoh
*
* This file is part of sqlapp-gradle-plugin.
*
* sqlapp-gradle-plugin is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sqlapp-gradle-plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with sqlapp-gradle-plugin. If not, see .
*/
package com.sqlapp.gradle.plugins
import com.sqlapp.data.db.command.AbstractCommand
import com.sqlapp.gradle.plugins.pojo.AbstractPojo
import java.io.File
import java.util.List
import java.util.Map;
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.TaskAction;
import com.sqlapp.util.CommonUtils;
abstract class AbstractTask extends DefaultTask {
protected void run(AbstractCommand command){
if (this.parameters!=null){
command.context.putAll(parameters);
}
if (isDebug()){
println("parameters="+this.parameters);
}
if (this.enable){
try{
command.run();
} catch (Exception e){
e.printStackTrace();
throw e;
}
}else{
println("This task is disabled.");
}
}
AbstractPojo pojo;
@Input
@Optional
boolean enable=true;
@Input
@Optional
boolean debug;
@Input
@Optional
Map parameters;
void enable(boolean enable){
this.enable=enable;
}
void debug(boolean debug){
this.debug=debug;
}
protected boolean isDebug(){
return debug;
}
/**
* @return the file
*/
protected File getFile(def file) {
if (file==null){
return null;
}
return project.file(file);
}
/**
* @return the files
*/
protected List getFiles(def files) {
if (files==null){
return Collections.emptyList();
}
return CommonUtils.list(project.files(files).getFiles());
}
void setPojo(AbstractPojo pojo){
this.pojo=pojo;
this.parameters=pojo.parameters;
this.debug=pojo.debug;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy