com.consol.citrus.actions.AntRunAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of citrus-base Show documentation
Show all versions of citrus-base Show documentation
Citrus base and default implementation
/*
* Copyright 2006-2012 the original author or authors.
*
* 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 com.consol.citrus.actions;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Stack;
import com.consol.citrus.AbstractTestActionBuilder;
import com.consol.citrus.context.TestContext;
import com.consol.citrus.exceptions.CitrusRuntimeException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.util.StringUtils;
/**
* Action calls Apache ANT with given build file and runs ANT targets
* as separate build. User can set and overwrite properties for the build.
*
* Build logging output is forwarded to test run logger.
*
* @author Christoph Deppisch
* @since 1.3
*/
public class AntRunAction extends AbstractTestAction {
/** The build.xml file path */
private final String buildFilePath;
/** Target to execute */
private final String target;
/** Multiple targets to execute as comma separated list */
private final String targets;
/** Optional build file properties to set */
private final Properties properties;
/** Optional build property file path */
private final String propertyFilePath;
/** Custom build listener */
private final BuildListener buildListener;
/** Logger */
private static Logger log = LoggerFactory.getLogger(AntRunAction.class);
/**
* Default constructor.
* @param builder
*/
private AntRunAction(Builder builder) {
super("antrun", builder);
this.buildFilePath = builder.buildFilePath;
this.target = builder.target;
this.targets = builder.targets;
this.properties = builder.properties;
this.propertyFilePath = builder.propertyFilePath;
this.buildListener = builder.buildListener;
}
@Override
public void doExecute(TestContext context) {
Project project = new Project();
project.init();
String buildFileResource = context.replaceDynamicContentInString(buildFilePath);
try {
ProjectHelper.configureProject(project, new PathMatchingResourcePatternResolver().getResource(buildFileResource).getFile());
for (Entry