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

io.sealights.onpremise.agents.plugin.SealightsPluginExtension Maven / Gradle / Ivy

There is a newer version: 4.0.954
Show newest version
package io.sealights.onpremise.agents.plugin;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.gradle.api.Project;
import org.gradle.api.logging.Logging;

import io.sealights.onpremise.agents.infra.utils.StringUtils;
import io.sealights.onpremise.agents.plugin.Constants.TestTaskInfo;
import io.sealights.plugins.engine.api.ExecutionStage;
import io.sealights.plugins.engine.api.PluginExecData;
import io.sealights.plugins.engine.lifecycle.BuildLifeCycle;
import lombok.Data;

@Data
public class SealightsPluginExtension {

    private EnhancedLogger logger = new EnhancedLogger(Logging.getLogger(this.getClass()));

    private Project project;

    private String token;
    private String tokenFile;
    private String customerid;
    private String server;
    private String proxy;
    private String workspacepath;
    private boolean createBuildSessionId = false;
    private String buildSessionId;
    private String buildSessionIdFile;
    private String appName;
    private String moduleName;
    private String environment;
    private String branch;
    private String build = String.valueOf(new Date().getTime());
    private String packagesIncluded;
    private String packagesExcluded;
    private String filesIncluded;
    private String filesExcluded;
    private boolean recursive = true;
    private boolean logEnabled = true;
    private String logLevel = "info";
    private boolean logToFile = false;
    private String logFolder = "logs";	
	private boolean logToConsole=false;
    private String javaPath = "java";
    private String filesStorage;
    /**
     * Meta data of the build currently executed.
     */
    private Map metadata;
    private Map sealightsJvmParams;
    private String overrideMetaJsonPath;
    private boolean includeResources = false;
	/**
	 * Should be removed as soon as all customers will move to the new sealights-gradle-plugin implementation,
	 * which uses the property testTasksAndStages instead of the properties testTasks
	 * and testStage
	 */
	@Deprecated
    private String testStage;
    private String labId;
    private boolean createExecutionId = true;
    private boolean runTestOnly = false;
    private boolean runFunctionalTests = false;

    // Build scanner params
    private String buildScannerJar;
    private boolean enableNoneZeroErrorCode;
    private String buildScannerPackagesincluded;
    private String buildScannerPackagesexcluded;
    private Map buildScannerParams;
    private Boolean sendContributors;
    private boolean buildScannerIgnoreLogEnabled;

    // Test listener params
    private boolean testListenerEnabled = true;
    private String testListenerJar;
    private String testListenerPath;
    private String testListenerConfigFile;
    private Map testListenerJvmParams;
    private String initialColor;
    private String classLoadersExcluded;
    private boolean testListenerIgnoreLogEnabled;

    private String javaAgentArg;
    private Map javaAgentJvmParams;

	// These properties are relevant for gradle implementation only
	/**
	 * Should be removed as soon as all customers will move to the new sealights-gradle-plugin implementation,
	 * which uses the property testTasksAndStages instead of the properties testTasks
	 * and testStage
	 */
	@Deprecated
	private List testTasks;
	@Deprecated
	private boolean tasksAndStagesValueWasSet = false;
	private Map testTasksAndStages;
    private String currentTestStage;
	
    private boolean sealightsDisabled = false;

    public SealightsPluginExtension(Project project) {
        this.project = project;
        getExecData().setExecStage(ExecutionStage.init);
        initDefaultTestTasksAndStages();
    }    

    public PluginExecData getExecData() {
    	return BuildLifeCycle.getExecData();
    }

    public void setDefaultWorkspacepathIfNull() {
        if (workspacepath == null) {
            workspacepath = project.getBuildDir().getAbsolutePath();
            logger.info("Setting the default workspacepath:'{}'", workspacepath);
        }
        else {
        	logger.info("Using provided workspacepath:'{}'", workspacepath);
        }
    }
    
	/**
	 * Should be removed as soon as all customers will move to the new sealights-gradle-plugin implementation,
	 * which uses the property testTasksAndStages instead of the properties testTasks
	 * and testStage
	 * 
	 * @param testStage - test stage value
	 */
    @Deprecated
    public void setTestStage(String testStage) {
    	this.testStage = testStage;
		logger.lifecycle("Deprecated property 'testStage' is used; if the property 'testTasksAndStages' is not defined, the same  test stage '{}' will be applied to all default test-tasks", testStage);
    	// Default test-task stages should be updated to the provided testStage
		setDeprecatedDefaultTestStageForAllTasks();
    }
    
	/**
	 * Should be removed as soon as all customers will move to the new sealights-gradle-plugin implementation,
	 * which uses the property testTasksAndStages instead of the properties testTasks
	 * and testStage
	 * 
	 * @param testTasks - test tasks value
	 */
	@Deprecated
	public void setTestTasks(List testTasks) {
		this.testTasks = testTasks;
		updateTestTasksAndStages();
	}
	
	public void setTestTasksAndStages(Map testTasksAndStages) {
		this.testTasksAndStages = testTasksAndStages;
		tasksAndStagesValueWasSet = true;
		updateTestTasksAndStages();
	}
	
	public void updateCurrentTestStage(String testTaskName) {
		String currentTestStage = testTasksAndStages.get(testTaskName);
		// Set or reset the current test stage
		setCurrentTestStage(currentTestStage);
		if (StringUtils.isNotEmpty(currentTestStage)) {
			logger.lifecycle("Current testStage was set to '{}', task:'{}'", currentTestStage, testTaskName);
		}
		else {
			logger.lifecycle("Undefined test stage for task '{}'", testTaskName);
		}
	}

    private void updateTestTasksAndStages() {
    	if ( !isTestTasksAndStagesProvided() && !isTestTasksProvided() ) {
            logger.lifecycle("Using the default 'testTasksAndStages':{}", testTasksAndStages);
            return;
    	}
    	// This is for backward compatibility - testTasks input provided and 
    	// testTasksAndStages is not provided
    	else if (isTestTasksProvided() && !tasksAndStagesValueWasSet) {
    		initTestTasksByDeprecatedTestTasks();
    		return;
    	}    	
    	else {
    		logger.lifecycle("Using provided 'testTasksAndStages':'{}'", testTasksAndStages);
    	}
    }
    
    private void initDefaultTestTasksAndStages() {
    	testTasksAndStages = new HashMap<>();
		for (TestTaskInfo entry : Constants.DEFAULT_TEST_TASK_STAGES) {
			testTasksAndStages.put(entry.taskName, entry.testStage);
		}
        logger.lifecycle("Set the default 'testTasksAndStages':{}", testTasksAndStages);
    }
    
    private boolean isTestTasksAndStagesProvided() {
    	return testTasksAndStages != null && !testTasksAndStages.isEmpty();
    }
    
    @Deprecated
    /**
     * The method is needed for backward compatibility - when plugin configuration
     * contains the properties testTasks or testStage
     * instead of the property testTasksAndStages.
     * The same default test stage is assigned to all defined tasks
     */
    private void setDeprecatedDefaultTestStageForAllTasks() {
    	if (testTasksAndStages != null) {
    		for (String taskName : testTasksAndStages.keySet()) {
    			testTasksAndStages.put(taskName, getDepreactedDefaultTestStage());
    		}
    		logger.lifecycle("The default test-stage '{}' was assigned to all test-tasks - 'testTasksAndStages':{}",
                    getDepreactedDefaultTestStage(), testTasksAndStages);
    	}
    }
    
    /**
     * The method is needed for backward compatibility - when plugin configuration
     * contains the properties testTasks or testStage
     * instead of the property testTasksAndStages.
     * The same default test stage is assigned to all defined tasks
     */
    @Deprecated
    private void initTestTasksByDeprecatedTestTasks() {
    	testTasksAndStages = new HashMap<>();
    	for (String task : testTasks) {
    		testTasksAndStages.put(task, getDepreactedDefaultTestStage());
    	}
		logger.lifecycle("Deprecated property 'testTasks' is used; the property 'testTasksAndStages' should be used instead; "
				+ "all provided tests tasks are attached to the test stage '{}': {}", getDepreactedDefaultTestStage(), testTasksAndStages);
    }
    
    /**
     * The method is needed for backward compatibility - when plugin configuration
     * contains the properties testTasks or testStage
     * instead of the property testTasksAndStages.
     * The default test stage is assigned as following: 
     * 

if property testStage is defined, it is assigned to all tasks, * else the 'Unit Tests' stage is assigned to all tasks */ @Deprecated private String getDepreactedDefaultTestStage() { if (isDeprecatedTestStageProvided()) { return testStage; } else { return Constants.UNIT_TESTS_STAGE; } } /** * The method is needed for backward compatibility - when plugin configuration * contains the property testTasks * instead of the property testTasksAndStages. * @return */ @Deprecated private boolean isTestTasksProvided() { return testTasks != null && !testTasks.isEmpty(); } /** * The method is needed for backward compatibility - when plugin configuration * contains the property testStage * instead of the property testTasksAndStages. * @return */ @Deprecated private boolean isDeprecatedTestStageProvided() { return StringUtils.isNotEmpty(testStage); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy