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

org.wisepersist.gradle.plugins.gwt.GwtTestExtension Maven / Gradle / Ivy

/**
 * Copyright (C) 2013-2017 Steffen Schaefer
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.wisepersist.gradle.plugins.gwt;

import java.io.File;
import java.util.concurrent.Callable;

import org.gradle.api.internal.IConventionAware;

/**
 * GWT specific extension for the Test task.
 */
public class GwtTestExtension extends GwtTestOptionsBase {

	private File war;
	private File deploy;
	private File extra;
	private File workDir;
	private File gen;
	private File cacheDir;
	
	protected String getParameterString() {
		final StringBuilder builder = new StringBuilder();
		
		dirArgIfSet(builder, "-war", getWar());
		dirArgIfSet(builder, "-deploy", getDeploy());
		dirArgIfSet(builder, "-extra", getExtra());
		dirArgIfSet(builder, "-workDir", getWorkDir());
		dirArgIfSet(builder, "-gen", getGen());
		
		argIfSet(builder, "-logLevel", getLogLevel());
		
		argIfSet(builder, "-port", Boolean.TRUE.equals(getAutoPort())? "auto" : getPort());
		argIfSet(builder, "-whitelist", getWhitelist());
		argIfSet(builder, "-blacklist", getBlacklist());
		argIfSet(builder, "-logdir", getLogDir());
		argIfSet(builder, "-codeServerPort", Boolean.TRUE.equals(getAutoCodeServerPort())? "auto" : getCodeServerPort());
		
		argIfSet(builder, "-style", getStyle());
		argIfEnabled(builder, getEa(), "-ea");
		argIfEnabled(builder, getDisableClassMetadata(), "-XdisableClassMetadata");
		argIfEnabled(builder, getDisableCastChecking(), "-XdisableCastChecking");
		argIfEnabled(builder, getDraftCompile(), "-draftCompile");
		argIfSet(builder, "-localWorkers", getLocalWorkers());
		argIfEnabled(builder, getProd(), "-prod");
		argIfSet(builder, "-testMethodTimeout", getTestMethodTimeout());
		argIfSet(builder, "-testBeginTimeout", getTestBeginTimeout());
		argIfSet(builder, "-runStyle", getRunStyle());
		argIfEnabled(builder, getNotHeadless(), "-notHeadless");
		argIfEnabled(builder, getStandardsMode(), "-standardsMode");
		argIfEnabled(builder, getQuirksMode(), "-quirksMode");
		argIfSet(builder, "-Xtries", getTries());
		argIfSet(builder, "-userAgents", getUserAgents());
		
		return builder.toString();
	}
	
	private void argIfEnabled(StringBuilder builder, Boolean condition, String arg) {
		if (Boolean.TRUE.equals(condition)) {
			arg(builder, arg);
		}
	}

	private void dirArgIfSet(StringBuilder builder, String arg, File dir) {
		if (dir != null) {
			dir.mkdirs();
			arg(builder, arg, dir);
		}
	}

	private void argIfSet(StringBuilder builder, String arg, Object value) {
		if (value != null) {
			arg(builder, arg, value);
		}
	}
	
	private void arg(StringBuilder builder, Object... args) {
		for(Object arg : args) {
			if(builder.length() > 0) {
				builder.append(' ');
			}
			builder.append(arg.toString());
		}
	}
	
	protected void configure(final GwtPluginExtension extension, final IConventionAware conventionAware) {
		final GwtTestOptions testOptions = extension.getTest();
		
		conventionAware.getConventionMapping().map("war", new Callable(){
			@Override
			public File call() throws Exception {
				return extension.getDevWar();
			}});
		conventionAware.getConventionMapping().map("extra", new Callable(){
			@Override
			public File call() throws Exception {
				return extension.getExtraDir();
			}});
		conventionAware.getConventionMapping().map("workDir", new Callable(){
			@Override
			public File call() throws Exception {
				return extension.getWorkDir();
			}});
		conventionAware.getConventionMapping().map("gen", new Callable(){
			@Override
			public File call() throws Exception {
				return extension.getGenDir();
			}});
		conventionAware.getConventionMapping().map("cacheDir", new Callable(){
			@Override
			public File call() throws Exception {
				return extension.getCacheDir();
			}});
		conventionAware.getConventionMapping().map("logLevel", new Callable(){
			@Override
			public LogLevel call() throws Exception {
				return extension.getLogLevel();
			}});
		
		conventionAware.getConventionMapping().map("port", new Callable(){
			@Override
			public Integer call() throws Exception {
				return testOptions.getPort();
			}});
		conventionAware.getConventionMapping().map("autoPort", new Callable(){
			@Override
			public Boolean call() throws Exception {
				return testOptions.getAutoPort();
			}});
		conventionAware.getConventionMapping().map("whitelist", new Callable(){
			@Override
			public String call() throws Exception {
				return testOptions.getWhitelist();
			}});
		conventionAware.getConventionMapping().map("blacklist", new Callable(){
			@Override
			public String call() throws Exception {
				return testOptions.getBlacklist();
			}});
		conventionAware.getConventionMapping().map("logDir", new Callable(){
			@Override
			public File call() throws Exception {
				return testOptions.getLogDir();
			}});
		conventionAware.getConventionMapping().map("codeServerPort", new Callable(){
			@Override
			public Integer call() throws Exception {
				return testOptions.getCodeServerPort();
			}});
		conventionAware.getConventionMapping().map("autoCodeServerPort", new Callable(){
			@Override
			public Boolean call() throws Exception {
				return testOptions.getAutoCodeServerPort();
			}});
		
		conventionAware.getConventionMapping().map("style", new Callable