All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lingocoder.plugin.jarexec.ExecJar Maven / Gradle / Ivy

The newest version!
/**
 * A Gradle plugin that executes Java Jar files.
 *
 * Copyright (C) 2019 lingocoder 
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 */
package com.lingocoder.plugin.jarexec;

import org.gradle.api.DefaultTask;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.FileTree;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.*;

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

import static org.gradle.api.tasks.PathSensitivity.RELATIVE;

/**
 * An implementation of Gradle {@link DefaultTask} that provides the functionality for the {@link JarExecPlugin}.
 */
@CacheableTask
public class ExecJar extends DefaultTask {

    private final ListProperty args;

    private final Property classpath;

    private final Property jar;

    private final Property mainClass;
    
    private final Property watchInFile;

    private final Property watchInFiles;

    private final Property watchOutDir;

    private final Execution exe;

    public ExecJar() {

        this.args = getProject().getObjects().listProperty(String.class);
        this.classpath = getProject().getObjects().property(FileCollection.class);
        this.jar = getProject().getObjects().property(File.class);
        this.mainClass = getProject().getObjects().property(String.class);
        this.watchInFile = getProject().getObjects().property(File.class);
        this.watchInFiles = getProject().getObjects().property(FileTree.class);
        this.watchOutDir = getProject( ).getObjects( ).property( File.class );
        this.exe = new Execution( );
    }

    @Input
    public List getArgs() {
        return args.get();
    }

    public void setArgs(ListProperty args) {
        this.args.set(args);
    }

    @Classpath
    @Optional
    public FileCollection getClasspath() {
        return classpath.getOrNull();
    }

    public void setClasspath(Provider classpath) {
        this.classpath.set(classpath);
    }

    @InputFile
    @PathSensitive(RELATIVE)
    public File getJar() {
        return jar.get();
    }

    public void setJar(Provider jar) {
        this.jar.set(jar);
    }

    @Input
    @Optional
    public String getMainClass() { return mainClass.getOrElse(""); }

    public void setMainClass(Provider mainClass) {
        this.mainClass.set(mainClass);
    }
    
    @InputFile
    @PathSensitive(RELATIVE)
    @Optional
    public File getWatchInFile() {
        return watchInFile.getOrNull();
    }

    public void setWatchInFile(Provider watchInFile) {
        this.watchInFile.set(watchInFile);
    }

    @InputFiles
    @PathSensitive(RELATIVE)
    @Optional
    public FileTree getWatchInFiles() {
        return watchInFiles.getOrNull();
    }

    public void setWatchInFiles(Provider watchInFiles) {
        this.watchInFiles.set(watchInFiles);
    }

    @OutputDirectory
    @PathSensitive(RELATIVE)
    @Optional
    public File getWatchOutDir(){ return watchOutDir.getOrNull(); }

    public void setWatchOutDir(Provider watchOutDir){ this.watchOutDir.set(watchOutDir);}


    @TaskAction
    void executeJar() {

        this.exe.execute( this.jar, this.classpath, this.args, this.mainClass );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy