From: Mathieu Baudier Date: Sat, 31 May 2008 19:55:59 +0000 (+0000) Subject: Create separate agent project X-Git-Tag: argeo-slc-2.1.7~2872 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;ds=sidebyside;h=2d5e7c7e91522b14d917fdd8cb39c0df1b25bf11;p=gpl%2Fargeo-slc.git Create separate agent project git-svn-id: https://svn.argeo.org/slc/trunk@1168 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/org.argeo.slc.core/pom.xml b/org.argeo.slc.core/pom.xml index 54184e74d..285fe9ef9 100644 --- a/org.argeo.slc.core/pom.xml +++ b/org.argeo.slc.core/pom.xml @@ -70,10 +70,6 @@ org.springframework spring-context - - org.springframework.ws - spring-ws-core - org.springframework.ws spring-oxm @@ -101,15 +97,6 @@ activation - - org.apache.ant - ant - - - org.apache.ant - ant-commons-logging - - org.apache.commons commons-io @@ -126,14 +113,5 @@ xalan xalan - - org.apache.maven - maven-embedder - - - org.apache.maven - maven-settings - - \ No newline at end of file diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java deleted file mode 100644 index e81fb30eb..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java +++ /dev/null @@ -1,121 +0,0 @@ -package org.argeo.slc.ant; - -import java.io.File; -import java.net.URL; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.ProjectHelper; -import org.apache.tools.ant.listener.CommonsLoggingListener; -import org.argeo.slc.core.structure.StructurePath; -import org.argeo.slc.core.structure.StructureRegistry; - -/** Utilities to manipulate the structure registry in SLC Ant. */ -public class AntRegistryUtil { - private static Log log = LogFactory.getLog(AntRegistryUtil.class); - - /** Reads a structure registry from an Ant file without executing it. */ - public static StructureRegistry readRegistry(File antFile) { - if (log.isDebugEnabled()) - log.debug("Reads registry for Ant file " + antFile); - Project p = new Project(); - p.setUserProperty("ant.file", antFile.getAbsolutePath()); - p.setBaseDir(antFile.getParentFile()); - p.init(); - ProjectHelper helper = new SlcProjectHelper(); - p.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper); - helper.parse(p, antFile); - - StructureRegistry registry = (StructureRegistry) p - .getReference(SlcProjectHelper.REF_STRUCTURE_REGISTRY); - registry.setMode(StructureRegistry.READ); - - p.executeTarget(p.getDefaultTarget()); - return registry; - } - - /** Executes only the active paths of the Ant file. */ - public static Project runActive(File antFile, - List activePaths) { - if (log.isDebugEnabled()) - log.debug("Runs the " + activePaths.size() - + " provided active paths of Ant file " + antFile); - Project p = new Project(); - p.setUserProperty("ant.file", antFile.getAbsolutePath()); - p.setBaseDir(antFile.getParentFile()); - p.init(); - ProjectHelper helper = new SlcProjectHelper(); - p.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper); - helper.parse(p, antFile); - - StructureRegistry registry = (StructureRegistry) p - .getReference(SlcProjectHelper.REF_STRUCTURE_REGISTRY); - registry.setMode(StructureRegistry.ACTIVE); - registry.setActivePaths(activePaths); - - runProject(p, null); - return p; - } - - /** Executes all paths of the provided target of the Ant file. */ - public static Project runAll(File antFile, String target) { - if (log.isDebugEnabled()) - log.debug("Runs all paths of Ant file " + antFile); - Project p = new Project(); - p.setUserProperty("ant.file", antFile.getAbsolutePath()); - p.setBaseDir(antFile.getParentFile()); - p.init(); - ProjectHelper helper = new SlcProjectHelper(); - p.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper); - helper.parse(p, antFile); - - runProject(p, target); - return p; - } - - /** Executes all paths of the provided target of the Ant URL. */ - public static Project runAll(URL url, String target, Properties properties) { - if (log.isDebugEnabled()) - log.debug("Runs all paths of Ant URL " + url); - Project p = new Project(); - p.setUserProperty("ant.file", url.toString()); - // p.setBaseDir(url.toString()); - p.addBuildListener(new CommonsLoggingListener()); - p.init(); - ProjectHelper helper = new SlcProjectHelper(); - p.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper); - helper.parse(p, url); - - if (properties != null) { - for (Map.Entry entry : properties.entrySet()) { - p.setUserProperty(entry.getKey().toString(), entry.getValue() - .toString()); - } - } - - runProject(p, target); - return p; - } - - /** Executes all paths of the default target of the Ant file. */ - public static Project runAll(File antFile) { - return runAll(antFile, null); - } - - protected static void runProject(Project p, String target) { - p.fireBuildStarted(); - Throwable exception = null; - try { - p.executeTarget(target != null ? target : p.getDefaultTarget()); - } catch (Throwable e) { - exception = e; - log.error("Exception when running Ant: ",e); - } finally { - p.fireBuildFinished(exception); - } - } -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/AntRunner.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/AntRunner.java deleted file mode 100644 index da88eafa1..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/AntRunner.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.argeo.slc.ant; - -import java.io.File; -import java.net.URL; -import java.util.Arrays; -import java.util.Collections; -import java.util.Map; -import java.util.Properties; -import java.util.Vector; - -import org.springframework.context.ApplicationContext; - -import org.apache.tools.ant.Project; -import org.apache.tools.ant.ProjectHelper; - -public class AntRunner { - private ApplicationContext context; - private ProjectHelper projectHelper; - private URL buildFile; - private String[] targets; - private Properties properties; - - public AntRunner() { - - } - - public AntRunner(ApplicationContext context, ProjectHelper projectHelper, - URL buildFile, String[] targets) { - super(); - this.context = context; - this.projectHelper = projectHelper; - this.buildFile = buildFile; - this.targets = targets; - } - - public AntRunner(ApplicationContext context, URL buildFile, String target) { - super(); - this.context = context; - - BasicSlcProjectHelper basicSlcProjectHelper = new BasicSlcProjectHelper(); - this.projectHelper = basicSlcProjectHelper; - basicSlcProjectHelper.setContext(context); - - this.buildFile = buildFile; - this.targets = new String[] { target }; - } - - public void run() { - Project p = new Project(); - - String path = buildFile.getFile(); - p.setUserProperty("ant.file", path); - p.setBaseDir(extractBaseDir(path)); - - p.init(); - p.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, projectHelper); - projectHelper.parse(p, buildFile); - - if (properties != null) { - for (Map.Entry entry : properties.entrySet()) { - p.setUserProperty(entry.getKey().toString(), entry.getValue() - .toString()); - } - } - - p.fireBuildStarted(); - Throwable exception = null; - try { - if (targets == null) { - p.executeTarget(p.getDefaultTarget()); - } else { - p.executeTargets(new Vector(Arrays.asList(targets))); - } - } catch (Throwable e) { - exception = e; - throw new SlcAntException("Could not run Ant script " + buildFile, - e); - } finally { - p.fireBuildFinished(exception); - } - - } - - private File extractBaseDir(String path) { - String baseDir = null; - if (path.length() > 1) { - int indx = path.lastIndexOf('/', path.length() - 1); - if (indx == -1 || indx == 0) { - baseDir = "/"; - } else { - baseDir = path.substring(0, indx) + "/"; - } - } else { - baseDir = "/"; - } - File file = new File(baseDir); - if (file.exists()) { - return file; - } else { - return new File(System.getProperty("user.dir")); - } - } - - public static void main(String[] args) { - // TODO Auto-generated method stub - - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/BasicSlcProjectHelper.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/BasicSlcProjectHelper.java deleted file mode 100644 index 620acdfcb..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/BasicSlcProjectHelper.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.argeo.slc.ant; - -import org.springframework.context.ApplicationContext; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.helper.ProjectHelper2; - -import org.argeo.slc.core.structure.SimpleSElement; -import org.argeo.slc.core.structure.tree.TreeSPath; -import org.argeo.slc.core.structure.tree.TreeSRegistry; - -public class BasicSlcProjectHelper extends ProjectHelper2 { - private ApplicationContext context; - - private String projectRootPath = "/project"; - - @Override - public void parse(Project project, Object source) throws BuildException { - TreeSRegistry registry = new TreeSRegistry(); - TreeSPath projectPath = TreeSPath.parseToCreatePath(projectRootPath); - - // FIXME - registry.register(projectPath, new SimpleSElement("ROOT")); - - project.addReference(SlcProjectHelper.REF_STRUCTURE_REGISTRY, registry); - project.addReference(SlcProjectHelper.REF_PROJECT_PATH, projectPath); - - super.parse(project, source); - - project.addReference(SlcProjectHelper.REF_ROOT_CONTEXT, context); - SlcProjectHelper.createAndRegisterSlcExecution(project); - - SlcProjectHelper.addCustomTaskAndTypes(project); - } - - public void setContext(ApplicationContext context) { - this.context = context; - } - - - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/ProjectRelatedBuildListener.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/ProjectRelatedBuildListener.java deleted file mode 100644 index 6d047d5d0..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/ProjectRelatedBuildListener.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.argeo.slc.ant; - -import org.apache.tools.ant.BuildListener; -import org.apache.tools.ant.Project; - -public interface ProjectRelatedBuildListener extends BuildListener { - public Project getProject(); - - /** SlcExecution must already have been registered in project*/ - public void init(Project project); -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/RemoveRootDirMapper.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/RemoveRootDirMapper.java deleted file mode 100644 index 43b247c2b..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/RemoveRootDirMapper.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.argeo.slc.ant; - -import java.util.StringTokenizer; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tools.ant.util.FileNameMapper; - -public class RemoveRootDirMapper implements FileNameMapper { - private Log log = LogFactory.getLog(RemoveRootDirMapper.class); - private String to = "enabled"; - - public String[] mapFileName(String sourceFileName) { - StringTokenizer st = new StringTokenizer(sourceFileName, "/"); - boolean first = true; - boolean skipRoot = !to.equals("disabled"); - StringBuffer buf = new StringBuffer(""); - while (st.hasMoreTokens()) { - if (first && skipRoot) { // skip - st.nextToken(); - first = false; - } else { - buf.append(st.nextToken()).append('/'); - } - } - - if (log.isTraceEnabled()) { - log.trace("Source: " + sourceFileName + " - out: " + buf); - } - return new String[] { buf.toString() }; - } - - public void setFrom(String from) { - } - - public void setTo(String to) { - this.to = to; - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcAntConfig.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcAntConfig.java deleted file mode 100644 index 9b2824886..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcAntConfig.java +++ /dev/null @@ -1,344 +0,0 @@ -package org.argeo.slc.ant; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Map; -import java.util.Properties; -import java.util.StringTokenizer; - -import org.springframework.util.Log4jConfigurer; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tools.ant.Project; - -/** - *

- * Manager and initializer of the properties required by SLC Ant. - *

- * - *

- * All properties described here will get a value one way or another (see below - * for details)/ Each property will be accessible via Ant or Spring properties. - *

- * - *

- * The property slc.rootFile is set based on the location of the SLC - * root property file found in the directory structure of a called Ant file. The - * default name of this file is slcRoot.properties (can be set by - * {@link #setSlcRootFileName(String)}).
- * This property provides the absolute path to the unique SLC root property file - * which marks the root of an Ant SLC tree structure. - *

- * - *

- * The property slc.rootDir is inferred from slc.rootFile and - * provides a convenient shortcut to the root directory of the Ant files - * directory structure. - *

- * - *

- * A few directory and file related properties can be set in the SLC root - * property file (if they are not explicitly set their default values will be - * used): - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
PropertyDescriptionDefault
slc.confDirDirectory where to find the various configuration files of a given SLC - * Ant deployment${slc.rootDir}/../conf
slc.workDirDirectory where data can be retrieved or generated: build outputs, test - * inputs/outputs, test results, etc. The underlying directory structure is - * specified by the specific SLC application.${slc.rootDir}/../work
slc.propertyFileNamesComma-separated list of the files names of the property files to load - * from the conf directory. Having various files allows to separate between SLC - * framework properties and properties specific to a given application built on - * top of SLC. All will be available across Ant and Spring.slc.properties
Note: Only the properties above can be set in the SLC root - * properties file. All other properties should be defined in the registered - * conf files. - *

- * - *

- * Any property can be defined in the conf files defined in the SLC root - * properties file (see above). SLC expects some which will have defaults but - * can be overriden there. By convention they should be defined in the - * slc.properties file, while application specific properties should be - * defined in other conf files. This allows for a clean spearation between SLC - * and the applications built on top of it: - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
PropertyDescriptionDefault
slc.applicationContextPath to the root Spring application context file used by SLC Ant.${slc.confDir}/applicationContext.xml
slc.defaultTestRunName of the {@link WritableTestRun} Spring bean that the - * slc.test task will use by default. This can be overridden when - * calling the task from Ant.defaultTestRun
- *

- */ -public class SlcAntConfig { - // SLC ROOT PROPERTIES - /** Property for the root file (SLC root property file). */ - public final static String ROOT_FILE_PROPERTY = "slc.rootFile"; - /** Property for the root dir (SLC root property file). */ - public final static String ROOT_DIR_PROPERTY = "slc.rootDir"; - /** Property for the conf dir (SLC root property file). */ - public final static String CONF_DIR_PROPERTY = "slc.confDir"; - /** Property for the work dir (SLC root property file). */ - public final static String WORK_DIR_PROPERTY = "slc.workDir"; - /** - * Comma-separated list of property file names to load from the conf dir and - * add to project user properties - */ - public final static String PROPERTY_FILE_NAMES_PROPERTY = "slc.propertyFileNames"; - - // SLC CONF PROPERTIES - /** Path to the root Spring application context */ - public static String APPLICATION_CONTEXT_PROPERTY = "slc.applicationContext"; - /** Name of the Spring bean used by default */ - public static String DEFAULT_TEST_RUN_PROPERTY = "slc.defaultTestRun"; - - // SLC LOCAL PROPERTIES - /** Property for the dir label (SLC local property file). */ - public static String DIR_LABEL_PROPERTY = "slc.dirLabel"; - - private String slcRootFileName = "slcRoot.properties"; - private String slcLocalFileName = "slcLocal.properties"; - - /** - * Retrieves or infers all properties and set them as project user - * properties. All these properties will be set as project properties if - * they had not been set as project properties before (like by - * overriding through the standard Ant mechanisms). - * - * @param project - * the Ant Project being run. - * @return whether the project could be initialized for SLC usage (e.g. - * presence of an SLC root file) - */ - public boolean initProject(Project project) { - File projectBaseDir = project.getBaseDir(); - File slcRootFile = findSlcRootFile(projectBaseDir); - if (slcRootFile == null) { - return false; - } - - // pass the project properties through the System properties - System.getProperties().putAll((Map) project.getUserProperties()); - Properties all = new Properties(); - all.putAll(System.getProperties()); - prepareAllProperties(slcRootFile, all); - - Log log = LogFactory.getLog(this.getClass()); - for (Object o : all.keySet()) { - String key = o.toString(); - // System.out.println(key+"="+all.getProperty(key)); - if (project.getUserProperty(key) == null) {// not already set - // if (log.isDebugEnabled()) - // log.debug(key + "=" + all.getProperty(key)); - project.setUserProperty(key, all.getProperty(key)); - } - } - return true; - } - - /** - * Retrieves or infers all required properties. - * - * @param slcRootFile - * the location of the SLC root file - * - * @return the prepared properties. Note that it also contains the System - * and Ant properties which had previously been set. - */ - public void prepareAllProperties(File slcRootFile, Properties all) { - try { - final String fileUrlPrefix = ""; - - all.put(ROOT_FILE_PROPERTY, slcRootFile.getCanonicalPath()); - // Remove basedir property in order to avoid conflict with Maven - if (all.containsKey("basedir")) - all.remove("basedir"); - - Properties rootProps = loadFile(slcRootFile.getCanonicalPath()); - - final File confDir; - final File workDir; - // Root dir - final File rootDir = slcRootFile.getParentFile(); - all.setProperty(ROOT_DIR_PROPERTY, fileUrlPrefix - + rootDir.getCanonicalPath()); - - // Conf dir - if (all.getProperty(CONF_DIR_PROPERTY) == null) { - confDir = new File(rootProps.getProperty(CONF_DIR_PROPERTY, - rootDir.getAbsolutePath() + "/../conf")) - .getCanonicalFile(); - all.setProperty(CONF_DIR_PROPERTY, fileUrlPrefix - + confDir.getAbsolutePath()); - } else { - confDir = new File(all.getProperty(CONF_DIR_PROPERTY)) - .getCanonicalFile(); - } - - // Work dir - if (all.getProperty(WORK_DIR_PROPERTY) == null) { - workDir = new File(rootProps.getProperty(WORK_DIR_PROPERTY, - rootDir.getAbsolutePath() + "/../work")) - .getCanonicalFile(); - all.setProperty(WORK_DIR_PROPERTY, fileUrlPrefix - + workDir.getAbsolutePath()); - } else { - workDir = new File(all.getProperty(WORK_DIR_PROPERTY)) - .getCanonicalFile(); - } - - // Properties from the conf dir files - Properties properties = new Properties(); - StringTokenizer st = new StringTokenizer(rootProps.getProperty( - PROPERTY_FILE_NAMES_PROPERTY, "slc.properties"), ","); - while (st.hasMoreTokens()) { - String fileName = st.nextToken(); - properties.putAll(loadFile(confDir.getAbsolutePath() - + File.separator + fileName)); - } - - for (Object o : properties.keySet()) { - String key = o.toString(); - if (all.getProperty(key) == null) {// not already set - all.setProperty(key, properties.getProperty(key)); - } - } - - // Default application context - if (all.getProperty(APPLICATION_CONTEXT_PROPERTY) == null) { - all.setProperty(APPLICATION_CONTEXT_PROPERTY, confDir - .getAbsolutePath() - + "/applicationContext.xml"); - } - // Default test run - if (all.getProperty(DEFAULT_TEST_RUN_PROPERTY) == null) { - all.setProperty(DEFAULT_TEST_RUN_PROPERTY, - "defaultTestRun"); - } - - // Default log4j - if (all.getProperty("log4j.configuration") == null) { - System.setProperty("log4j.configuration", confDir - .getCanonicalPath() - + File.separator + "log4j.properties"); - // TODO: fix dependency to log4j - Log4jConfigurer.initLogging(confDir.getCanonicalPath() - + File.separator + "log4j.properties"); - } - } catch (Exception e) { - throw new SlcAntException("Unexpected exception while configuring", - e); - } - } - - /** Loads the content of a file as Properties. */ - private Properties loadFile(String path) { - Properties p = new Properties(); - try { - FileInputStream in = new FileInputStream(path); - p.load(in); - in.close(); - } catch (IOException e) { - throw new SlcAntException("Cannot read SLC root file", e); - } - return p; - } - - /** - * Looks for a file named {@link #getSlcLocalFileName()} in the directory, - * loads it as properties file and return the value of the property - * {@link #DIR_LABEL_PROPERTY}. - */ - public String getDescriptionForDir(File dir) { - String description = dir.getName(); - File slcLocal = new File(dir.getPath() + File.separator - + getSlcLocalFileName()); - if (slcLocal.exists()) { - Properties properties = loadFile(slcLocal.getAbsolutePath()); - description = properties.getProperty( - SlcAntConfig.DIR_LABEL_PROPERTY, description); - } - return description; - } - - /** - * Recursively scans directories downwards until it find a file names as - * defined by {@link #getSlcRootFileName()}. - */ - public File findSlcRootFile(File dir) { - for (File file : dir.listFiles()) { - if (!file.isDirectory() - && file.getName().equals(getSlcRootFileName())) { - return file; - } - } - - File parentDir = dir.getParentFile(); - if (parentDir == null) { - return null;// stop condition: not found - } else { - return findSlcRootFile(parentDir); - } - } - - /** - * Gets the file name of the file marking the root directory, default being - * slcRoot.properties. - */ - public String getSlcRootFileName() { - return slcRootFileName; - } - - /** Sets the file name of the file marking the root directory. */ - public void setSlcRootFileName(String slcRootFileName) { - this.slcRootFileName = slcRootFileName; - } - - /** - * Gets the file name of the file containing directory specific properties, - * default being slcLocal.properties. - */ - public String getSlcLocalFileName() { - return slcLocalFileName; - } - - /** Sets the file name of the file containing directory specific properties. */ - public void setSlcLocalFileName(String slcLocalFileName) { - this.slcLocalFileName = slcLocalFileName; - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcAntException.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcAntException.java deleted file mode 100644 index 854df33cf..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcAntException.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.argeo.slc.ant; - -import org.argeo.slc.core.SlcException; - -/** Base for all SLC Ant exceptions. */ -public class SlcAntException extends SlcException { - static final long serialVersionUID = 1l; - - /** Constructor. */ - public SlcAntException(String message) { - super(message); - } - - /** Constructor. */ - public SlcAntException(String message, Throwable cause) { - super(message, cause); - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcExecutionBuildListener.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcExecutionBuildListener.java deleted file mode 100644 index a8dd15c7d..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcExecutionBuildListener.java +++ /dev/null @@ -1,233 +0,0 @@ -package org.argeo.slc.ant; - -import java.util.List; -import java.util.Vector; - -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.LogManager; -import org.apache.log4j.spi.LoggingEvent; -import org.apache.tools.ant.BuildEvent; -import org.apache.tools.ant.Project; - -import org.argeo.slc.core.process.SlcExecution; -import org.argeo.slc.core.process.SlcExecutionNotifier; -import org.argeo.slc.core.process.SlcExecutionStep; -import org.argeo.slc.core.process.WebServiceSlcExecutionNotifier; - -public class SlcExecutionBuildListener extends AppenderSkeleton implements - ProjectRelatedBuildListener { - public static final String ANT_TYPE = "org.apache.tools.ant"; - public static final String SLC_ANT_TYPE = "org.argeo.slc.ant"; - - public static final String REF_SLC_EXECUTION = "slcExecution"; - - private Project project; - - // to avoid stack overflow when logging for log4j - private boolean isLogging = false; - - private List notifiers = new Vector(); - - private boolean currentStepNotified = true; - - // CUSTOMIZATIONS - private boolean logBeforeFirstTarget = false; - private boolean firstTargetStarted = false; - - private boolean logTaskStartFinish = true; - - public void init(Project project) { - if (this.project != null) { - throw new SlcAntException("Build listener already initialized"); - } - - this.project = project; - - if (!LogManager.getRootLogger().isAttached(this)) { - LogManager.getRootLogger().addAppender(this); - } - - SlcExecution slcExecution = (SlcExecution) project - .getReference(REF_SLC_EXECUTION); - if (slcExecution == null) - throw new SlcAntException("No SLC Execution registered."); - - for (SlcExecutionNotifier notifier : notifiers) { - notifier.newExecution(slcExecution); - } - - } - - public void buildStarted(BuildEvent event) { - } - - public void buildFinished(BuildEvent event) { - SlcExecution slcExecution = getSlcExecution(event); - String oldStatus = slcExecution.getStatus(); - slcExecution.setStatus(SlcExecution.STATUS_FINISHED); - - for (SlcExecutionNotifier notifier : notifiers) { - notifier.updateStatus(slcExecution, oldStatus, slcExecution - .getStatus()); - } - } - - public void messageLogged(BuildEvent event) { - if (!shouldLog()) - return; - - SlcExecution slcExecution = getSlcExecution(event); - if (slcExecution != null) { - if (currentStepNotified) { - slcExecution.getSteps().add( - new SlcExecutionStep("LOG", event.getMessage())); - notifyStep(slcExecution, slcExecution.currentStep()); - currentStepNotified = true; - } else { - slcExecution.currentStep().addLog(event.getMessage()); - } - } else { - // TODO: log before initialization? - } - } - - public void targetStarted(BuildEvent event) { - if (!firstTargetStarted) - firstTargetStarted = true; - - addLogStep(event, "Target " + event.getTarget().getName() + " started"); - } - - public void targetFinished(BuildEvent event) { - addLogStep(event, "Target " + event.getTarget().getName() + " finished"); - } - - public void taskStarted(BuildEvent event) { - if (!shouldLog()) - return; - - SlcExecution slcExecution = getSlcExecution(event); - if (!currentStepNotified) { - notifyStep(slcExecution, slcExecution.currentStep()); - currentStepNotified = true; - } - - String msg = null; - if (logTaskStartFinish) - msg = "Task " + event.getTask().getTaskName() + " started"; - - slcExecution.getSteps().add(new SlcExecutionStep("LOG", msg)); - - currentStepNotified = false; - } - - public void taskFinished(BuildEvent event) { - if (!shouldLog()) - return; - - SlcExecution slcExecution = getSlcExecution(event); - if (!currentStepNotified) { - - if (logTaskStartFinish) - slcExecution.currentStep().addLog( - "Task " + event.getTask().getTaskName() + " finished"); - - notifyStep(slcExecution, slcExecution.currentStep()); - currentStepNotified = true; - } - } - - public void setNotifiers(List notifiers) { - this.notifiers = notifiers; - } - - protected SlcExecution getSlcExecution(BuildEvent event) { - Project projectEvt = event.getProject(); - if (!projectEvt.equals(project)) - throw new SlcAntException("Event project " + projectEvt - + " not consistent with listener project " + project); - - SlcExecution slcExecution = (SlcExecution) project - .getReference(REF_SLC_EXECUTION); - - if (slcExecution == null) - throw new SlcAntException("No SLC Execution registered."); - return slcExecution; - } - - protected void addLogStep(BuildEvent event, String msg) { - SlcExecution slcExecution = getSlcExecution(event); - slcExecution.getSteps().add(new SlcExecutionStep("LOG", msg)); - - notifyStep(slcExecution, slcExecution.currentStep()); - currentStepNotified = true; - } - - protected void notifyStep(SlcExecution slcExecution, SlcExecutionStep step) { - Vector additionalSteps = new Vector(); - additionalSteps.add(step); - notifySteps(slcExecution, additionalSteps); - } - - protected void notifySteps(SlcExecution slcExecution, - List additionalSteps) { - for (SlcExecutionNotifier notifier : notifiers) { - notifier.addSteps(slcExecution, additionalSteps); - } - } - - /* Log4j methods */ - - @Override - protected void append(LoggingEvent event) { - if (isLogging) { - // avoid StackOverflow if notification calls Log4j itself. - return; - } - - if (event.getLoggerName().equals( - WebServiceSlcExecutionNotifier.class.getName())) { - return; - } - - isLogging = true; - - try { - SlcExecution slcExecution = (SlcExecution) project - .getReference(REF_SLC_EXECUTION); - if (slcExecution != null) { - if (currentStepNotified) { - slcExecution.getSteps().add( - new SlcExecutionStep("LOG", event.getMessage() - .toString())); - currentStepNotified = false; - } - slcExecution.currentStep() - .addLog(event.getMessage().toString()); - } else { - // TODO: log before initialization? - } - } finally { - isLogging = false; - } - - } - - protected boolean shouldLog() { - return logBeforeFirstTarget || firstTargetStarted; - } - - @Override - public void close() { - } - - @Override - public boolean requiresLayout() { - return false; - } - - public Project getProject() { - return project; - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java deleted file mode 100644 index 001ead97b..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java +++ /dev/null @@ -1,266 +0,0 @@ -package org.argeo.slc.ant; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.UUID; -import java.util.Vector; - -import org.springframework.beans.factory.ListableBeanFactory; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.AbstractApplicationContext; -import org.springframework.context.support.FileSystemXmlApplicationContext; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.log4j.LogManager; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.BuildListener; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.helper.ProjectHelper2; - -import org.argeo.slc.core.process.SlcExecution; -import org.argeo.slc.core.process.SlcExecutionNotifier; -import org.argeo.slc.core.structure.DefaultSRegistry; -import org.argeo.slc.core.structure.SimpleSElement; -import org.argeo.slc.core.structure.StructureRegistry; -import org.argeo.slc.core.structure.tree.TreeSPath; - -/** - * Custom implementation of an Ant ProjectHelper binding a Spring - * application context and a structure registry with the Ant project. - */ -public class SlcProjectHelper extends ProjectHelper2 { - private static Log log; - - /** The Ant reference to the Spring application context used. */ - public static String REF_ROOT_CONTEXT = "slcApplicationContext"; - /** The Ant reference to the SLC structure registry used. */ - public static String REF_STRUCTURE_REGISTRY = "slcStructureRegistry"; - /** The Ant reference to the TreePath of the current project */ - public static String REF_PROJECT_PATH = "slcProjectPath"; - /** - * Resource path to the property file listing the SLC specific Ant tasks: - * /org/argeo/slc/ant/taskdefs.properties - */ - private static String SLC_TASKDEFS_RESOURCE_PATH = "/org/argeo/slc/ant/taskdefs.properties"; - private static String SLC_TYPEDEFS_RESOURCE_PATH = "/org/argeo/slc/ant/typedefs.properties"; - - protected SlcAntConfig slcAntConfig = null; - - @Override - public void parse(Project project, Object source) throws BuildException { - - if (source instanceof File) { - File sourceFile = (File) source; - // Reset basedir property, in order to avoid base dir override when - // running in Maven - project.setProperty("basedir", sourceFile.getParentFile() - .getAbsolutePath()); - } - - if (slcAntConfig != null) { - // Config already initialized (probably import), only parse - super.parse(project, source); - return; - } - - // Initialize config - slcAntConfig = new SlcAntConfig(); - - if (!slcAntConfig.initProject(project)) { - // not SLC compatible, do normal Ant - super.parse(project, source); - return; - } - - if (log == null) { - // log4j is initialized only now - log = LogFactory.getLog(SlcProjectHelper.class); - } - - if (log.isDebugEnabled()) - log.debug("SLC properties are set, starting initialization for " - + source + " (projectHelper=" + this + ")"); - - beforeParsing(project); - - // Calls the underlying implementation to do the actual work - super.parse(project, source); - - afterParsing(project); - } - - /** - * Performs operations after config initialization and before Ant file - * parsing. Performed only once when the main project file is parsed. Should - * be called by overriding methods. - */ - protected void beforeParsing(Project project) { - // Init Spring application context - initSpringContext(project); - - // Init structure registry - DefaultSRegistry registry = new DefaultSRegistry(); - project.addReference(REF_STRUCTURE_REGISTRY, registry); - } - - /** - * Performs operations after parsing of the main file. Called only once (not - * for imports). - */ - protected void afterParsing(Project project) { - // Creates structure root - registerProjectAndParents(project, slcAntConfig); - addCustomTaskAndTypes(project); - } - - /** Creates the tree-based structure for this project. */ - private void registerProjectAndParents(Project project, - SlcAntConfig slcAntConfig) { - StructureRegistry registry = (StructureRegistry) project - .getReference(REF_STRUCTURE_REGISTRY); - File rootDir = new File(project - .getUserProperty(SlcAntConfig.ROOT_DIR_PROPERTY)) - .getAbsoluteFile(); - File baseDir = project.getBaseDir().getAbsoluteFile(); - List dirs = new Vector(); - File currentDir = baseDir; - do { - dirs.add(currentDir); - currentDir = currentDir.getParentFile(); - if (log.isTraceEnabled()) - log.trace("List " + currentDir); - } while (!currentDir.equals(rootDir.getParentFile())); - - // first path is root dir (because of previous algorithm) - TreeSPath currPath = TreeSPath.createRootPath(rootDir.getName()); - for (int i = dirs.size() - 1; i >= 0; i--) { - File dir = dirs.get(i); - - // retrieves description for this path - final String description; - if (i == 0) {// project itself - description = project.getDescription() != null - && !project.getDescription().equals("") ? project - .getDescription() : project.getName() != null ? project - .getName() : slcAntConfig.getDescriptionForDir(dir); - } else { - description = slcAntConfig.getDescriptionForDir(dir); - if (log.isTraceEnabled()) - log.trace("Dir desc " + i + "/" + dirs.size() + ": " - + description); - } - SimpleSElement element = new SimpleSElement(description); - - // creates and register path - if (!dir.equals(rootDir)) {// already set - currPath = currPath.createChild(dir.getName()); - } - registry.register(currPath, element); - } - project.addReference(REF_PROJECT_PATH, currPath); - } - - /** Gets the path of a project (root). */ - // private static TreeSPath getProjectPath(Project project) { - // return (TreeSPath) project.getReference(REF_PROJECT_PATH); - // } - /** Initializes the Spring application context. */ - private void initSpringContext(Project project) { - System.getProperties().putAll((Map) project.getProperties()); - String acPath = project - .getUserProperty(SlcAntConfig.APPLICATION_CONTEXT_PROPERTY); - if (log.isDebugEnabled()) - log.debug("Loading Spring application context from " + acPath); - // FIXME: workaround to the removal of leading '/' by Spring - // use URL instead? - AbstractApplicationContext context = new FileSystemXmlApplicationContext( - '/' + acPath); - context.registerShutdownHook(); - project.addReference(REF_ROOT_CONTEXT, context); - - createAndRegisterSlcExecution(project); - // Add build listeners declared in Spring context - // Map listeners = context.getBeansOfType( - // BuildListener.class, false, true); - // for (BuildListener listener : listeners.values()) { - // project.addBuildListener(listener); - // } - } - - /** Loads the SLC specific Ant tasks. */ - protected static void addCustomTaskAndTypes(Project project) { - Properties taskdefs = getDefs(project, SLC_TASKDEFS_RESOURCE_PATH); - for (Object o : taskdefs.keySet()) { - String name = o.toString(); - try { - project.addTaskDefinition(name, Class.forName(taskdefs - .getProperty(name))); - } catch (ClassNotFoundException e) { - log.error("Unknown class for task " + name, e); - } - } - Properties typedefs = getDefs(project, SLC_TYPEDEFS_RESOURCE_PATH); - for (Object o : typedefs.keySet()) { - String name = o.toString(); - try { - project.addDataTypeDefinition(name, Class.forName(typedefs - .getProperty(name))); - } catch (ClassNotFoundException e) { - log.error("Unknown class for type " + name, e); - } - } - } - - private static Properties getDefs(Project project, String path) { - Properties defs = new Properties(); - try { - InputStream in = project.getClass().getResourceAsStream(path); - defs.load(in); - in.close(); - } catch (IOException e) { - throw new SlcAntException("Cannot load task definitions", e); - } - return defs; - } - - protected static void createAndRegisterSlcExecution(Project project) { - SlcExecution slcExecution = new SlcExecution(); - slcExecution.setUuid(UUID.randomUUID().toString()); - try { - slcExecution.setHost(InetAddress.getLocalHost().getHostName()); - } catch (UnknownHostException e) { - slcExecution.setHost(SlcExecution.UNKOWN_HOST); - } - - if (project.getReference(SlcProjectHelper.REF_ROOT_CONTEXT) != null) { - slcExecution.setType(SlcExecutionBuildListener.SLC_ANT_TYPE); - } else { - slcExecution.setType(SlcExecutionBuildListener.ANT_TYPE); - } - - slcExecution.setUser(System.getProperty("user.name")); - slcExecution.setStatus(SlcExecution.STATUS_RUNNING); - slcExecution.getAttributes().put("ant.file", - project.getProperty("ant.file")); - - project.addReference(SlcExecutionBuildListener.REF_SLC_EXECUTION, - slcExecution); - - // Add build listeners declared in Spring context - Map listeners = ((ListableBeanFactory) project - .getReference(REF_ROOT_CONTEXT)).getBeansOfType( - ProjectRelatedBuildListener.class, false, true); - for (ProjectRelatedBuildListener listener : listeners.values()) { - listener.init(project); - project.addBuildListener(listener); - } - - } -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/deploy/SlcDeployTask.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/deploy/SlcDeployTask.java deleted file mode 100644 index 36c22547b..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/deploy/SlcDeployTask.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.argeo.slc.ant.deploy; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tools.ant.BuildException; - -import org.argeo.slc.ant.spring.AbstractSpringArg; -import org.argeo.slc.ant.structure.SAwareTask; -import org.argeo.slc.core.deploy.DeploymentData; -import org.argeo.slc.core.deploy.TargetData; -import org.argeo.slc.core.deploy.WritableDeployment; - -/** Ant task wrapping a deployment. */ -public class SlcDeployTask extends SAwareTask { - private Log log = LogFactory.getLog(SlcDeployTask.class); - - private String deploymentBean = null; - - private DeploymentDataArg deploymentDataArg; - private TargetDataArg targetDataArg; - - @Override - public void executeActions(String mode) throws BuildException { - WritableDeployment deployment = (WritableDeployment) getContext() - .getBean(deploymentBean); - - // set overridden references - if (deploymentDataArg != null) { - deployment.setDeploymentData(deploymentDataArg.getDeploymentData()); - log.trace("Overrides deployment data"); - } - - if (targetDataArg != null) { - deployment.setTargetData(targetDataArg.getTargetData()); - log.trace("Overrides target data"); - } - - deployment.execute(); - } - - /** - * The bean name of the test run to use. If not set the default is used. - * - * @see SlcAntConfig - */ - public void setDeployment(String deploymentBean) { - this.deploymentBean = deploymentBean; - } - - /** Creates deployment data sub tag. */ - public DeploymentDataArg createDeploymentData() { - deploymentDataArg = new DeploymentDataArg(); - return deploymentDataArg; - } - - /** Creates target data sub tag. */ - public TargetDataArg createTargetData() { - targetDataArg = new TargetDataArg(); - return targetDataArg; - } -} - -class DeploymentDataArg extends AbstractSpringArg { - DeploymentData getDeploymentData() { - return (DeploymentData) getBeanInstance(); - } - -} - -class TargetDataArg extends AbstractSpringArg { - TargetData getTargetData() { - return (TargetData) getBeanInstance(); - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/deploy/package.html b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/deploy/package.html deleted file mode 100644 index 76582d159..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/deploy/package.html +++ /dev/null @@ -1,6 +0,0 @@ - - - -Integration of SLC Deploy in Ant. - - \ No newline at end of file diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/package.html b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/package.html deleted file mode 100644 index 9f36fb1bf..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/package.html +++ /dev/null @@ -1,38 +0,0 @@ - - - -Bases classes for SLC Ant extensions. -

Introduction

-SLC Ant allows to integrate Ant and Spring in order to run an -application based on top of SLC. Sequence of actions are defined in Ant -files with specific Ant tasks referencing Spring beans implementing the -SLC interfaces. The properties of these beans can be overridden at -runtime in the Ant scripts. -
-SLC Ant also provides a tree-based implementation of the SLC structure -which allows to uniquely identify and reference the various actions. - -

Installation

-The structure will be first defined by the directory tree where the Ant -files are stored. In order to define the root of this tree, you need to -place in the root directory an -SLC Ant root file -(default name: slcRoot.properties). -
-In this root file you can define a configuration directory and a work -directory (default values are provided if they are not explicitly set). -
-Additional properties can then be defined in files stored under the -configuration directory. -
-For details about the configuration and the various properties, please -refer to {@link org.argeo.slc.ant.SlcAntConfig}. - -

Running SLC Ant

-SLC Ant can be run either via pure Ant scripts or programmatically using -{@link org.argeo.slc.ant.AntRegistryUtil}. In both cases, make sure that -SLC and its dependencies are in the classpath (Spring (always), logging -system such as log4j, Hibernate, etc.). - - - \ No newline at end of file diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/spring/AbstractSpringArg.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/spring/AbstractSpringArg.java deleted file mode 100644 index 6096f1f63..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/spring/AbstractSpringArg.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.argeo.slc.ant.spring; - -import java.util.List; -import java.util.Vector; - -import org.springframework.beans.BeanWrapper; -import org.springframework.beans.BeanWrapperImpl; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.context.ApplicationContext; - -import org.apache.commons.logging.LogFactory; -import org.apache.tools.ant.types.DataType; - -import org.argeo.slc.ant.SlcAntException; -import org.argeo.slc.ant.SlcProjectHelper; -import org.argeo.slc.core.SlcException; - -/** Abstract Ant type wrapping a Spring bean. */ -public abstract class AbstractSpringArg extends DataType { - private List overrides = new Vector(); - - private String bean; - - // cache bean instance to avoid reading it twice if it is a prototype - private Object beanInstance = null; - - /** The name of the underlying bean, as set throught the attribute. */ - public String getBean() { - return bean; - } - - /** Setter for the bean name. */ - public void setBean(String bean) { - this.bean = bean; - } - - /** - * Retrieve the instance of the bean, and sets the overriden properties. - * The value is cached. - */ - public Object getBeanInstance() { - if (beanInstance == null) { - beanInstance = getContext().getBean(bean); - - setOverridenProperties(beanInstance); - - if (beanInstance instanceof InitializingBean) { - try { - ((InitializingBean) beanInstance).afterPropertiesSet(); - } catch (Exception e) { - throw new SlcException("Could not initialize bean", e); - } - } - } - return beanInstance; - } - - protected void setOverridenProperties(Object obj){ - BeanWrapper wrapper = new BeanWrapperImpl(obj); - for (OverrideArg override : overrides) { - if (override.getName() == null) { - throw new SlcAntException( - "The name of the property to override has to be set."); - } - -// LogFactory.getLog(getClass()).debug( -// "Prop " + override.getName()); - wrapper.setPropertyValue(override.getName(), override - .getObject()); - } - - } - - /** Creates an override subtag. */ - public OverrideArg createOverride() { - OverrideArg propertyArg = new OverrideArg(); - overrides.add(propertyArg); - return propertyArg; - } - - /** The related Spring application context. */ - protected ApplicationContext getContext() { - return (ApplicationContext) getProject().getReference( - SlcProjectHelper.REF_ROOT_CONTEXT); - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/spring/AbstractSpringTask.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/spring/AbstractSpringTask.java deleted file mode 100644 index 925140fa5..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/spring/AbstractSpringTask.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.argeo.slc.ant.spring; - -import org.springframework.context.ApplicationContext; - -import org.apache.tools.ant.Task; - -import org.argeo.slc.ant.SlcExecutionBuildListener; -import org.argeo.slc.ant.SlcProjectHelper; -import org.argeo.slc.core.process.SlcExecution; - -/** Abstract Ant task providing access to a Spring context. */ -public abstract class AbstractSpringTask extends Task { - - /** Gets the related Spring context. */ - protected ApplicationContext getContext() { - return (ApplicationContext) getProject().getReference( - SlcProjectHelper.REF_ROOT_CONTEXT); - } - - /** Gets the related slc execution or null if not is registered. */ - protected SlcExecution getSlcExecution() { - return (SlcExecution) getProject().getReference( - SlcExecutionBuildListener.REF_SLC_EXECUTION); - } -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/spring/MapArg.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/spring/MapArg.java deleted file mode 100644 index eb4527644..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/spring/MapArg.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.argeo.slc.ant.spring; - -import java.util.List; -import java.util.Map; -import java.util.TreeMap; -import java.util.Vector; - -import org.apache.tools.ant.BuildException; - -import org.argeo.slc.core.SlcException; - -public class MapArg { - private List entries = new Vector(); - private Map map = new TreeMap(); - - public EntryArg createEntry() { - EntryArg arg = new EntryArg(); - entries.add(arg); - return arg; - } - - public Map getMap() { - if (map.size() == 0) { - for (EntryArg arg : entries) { - String key = arg.getKey(); - if (map.containsKey(key)) { - throw new SlcException("Key '" + key + "' already set."); - } else { - map.put(key, arg.getValueStr()); - } - } - } - return map; - } - - public static class EntryArg { - private String key; - private Object valueStr; - private OverrideArg overrideArg; - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public Object getValueStr() { - if (overrideArg != null) { - return overrideArg.getObject(); - } else if (valueStr != null) { - return valueStr; - } else { - throw new BuildException("Value not set."); - } - } - - public void setValue(String value) { - check(); - this.valueStr = value; - } - - public OverrideArg createOverride() { - check(); - overrideArg = new OverrideArg(); - return overrideArg; - } - - private void check() { - if (valueStr != null || overrideArg != null) { - throw new BuildException("Value already set"); - } - } - } -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/spring/OverrideArg.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/spring/OverrideArg.java deleted file mode 100644 index 5c0dc3e69..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/spring/OverrideArg.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.argeo.slc.ant.spring; - -import java.util.List; -import java.util.Vector; - -import org.apache.tools.ant.BuildException; - -import org.argeo.slc.core.SlcException; - -/** Ant type allowing to override bean properties. */ -public class OverrideArg extends AbstractSpringArg { - private String name; - private Object value; - private OverrideList overrideList; - private MapArg overrideMap; - private String antref; - - /** The name of the property to override. */ - public String getName() { - return name; - } - - /** Sets the name. */ - public void setName(String name) { - this.name = name; - } - - /** Sets a reference to an ant data type. */ - public void setAntref(String antref) { - checkValueAlreadySet(); - this.antref = antref; - } - - /** Both value and bean cannot be set. */ - public void setValue(String value) { - checkValueAlreadySet(); - this.value = value; - } - - @Override - public void setBean(String bean) { - checkValueAlreadySet(); - super.setBean(bean); - } - - /** Creates override list sub tag. */ - public OverrideList createList() { - checkValueAlreadySet(); - overrideList = new OverrideList(); - return overrideList; - } - - public MapArg createMap() { - checkValueAlreadySet(); - overrideMap = new MapArg(); - return overrideMap; - } - - /** - * The related object: the value if a value had been set or an instance of - * the bean if not. - */ - public Object getObject() { - if (value != null) { - return value; - } else if (getBean() != null) { - return getBeanInstance(); - } else if (overrideList != null) { - return overrideList.getAsObjectList(); - } else if (overrideMap != null) { - return overrideMap.getMap(); - } else if (antref != null) { - Object obj = getProject().getReference(antref); - if (obj == null) { - throw new SlcException("No object found for reference " - + antref); - } - setOverridenProperties(obj); - return obj; - } else { - throw new BuildException("Value or bean not set."); - } - } - - private void checkValueAlreadySet() { - if (value != null || overrideList != null || antref != null - || getBean() != null || overrideMap != null) { - throw new BuildException("Value already set."); - } - } - - /** List of overrides */ - protected class OverrideList { - private List list = new Vector(); - - /** Creates override sub tag. */ - public OverrideArg createOverride() { - OverrideArg overrideArg = new OverrideArg(); - list.add(overrideArg); - return overrideArg; - } - - /** Gets as list of objects. */ - public List getAsObjectList() { - List objectList = new Vector(); - for (OverrideArg arg : list) { - objectList.add(arg.getObject()); - } - return objectList; - } - } -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/spring/package.html b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/spring/package.html deleted file mode 100644 index 6d141d993..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/spring/package.html +++ /dev/null @@ -1,6 +0,0 @@ - - - -Integration of Spring in Ant. - - \ No newline at end of file diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/structure/SAwareTask.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/structure/SAwareTask.java deleted file mode 100644 index d248a3870..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/structure/SAwareTask.java +++ /dev/null @@ -1,157 +0,0 @@ -package org.argeo.slc.ant.structure; - -import java.util.List; -import java.util.Vector; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Target; - -import org.argeo.slc.ant.SlcAntException; -import org.argeo.slc.ant.SlcProjectHelper; -import org.argeo.slc.ant.spring.AbstractSpringArg; -import org.argeo.slc.ant.spring.AbstractSpringTask; -import org.argeo.slc.core.structure.SimpleSElement; -import org.argeo.slc.core.structure.StructureAware; -import org.argeo.slc.core.structure.StructureElement; -import org.argeo.slc.core.structure.StructureRegistry; -import org.argeo.slc.core.structure.tree.TreeSPath; - -/** Ant task that can be registered within a structure. */ -public abstract class SAwareTask extends AbstractSpringTask { - private String path; - private TreeSPath treeSPath; - private final List sAwareArgs = new Vector(); - - private StructureElementArg structureElementArg; - - @Override - public void init() throws BuildException { - StructureRegistry registry = getRegistry(); - Target target = getOwningTarget(); - - TreeSPath targetPath = createTargetPath(target); - SimpleSElement targetElement = (SimpleSElement) registry - .getElement(createTargetPath(target)); - - if (targetElement == null) { - targetElement = new SimpleSElement(target.getDescription(), - ""); - registry.register(targetPath, targetElement); - } - } - - /** - * Includes this arg in the checks for propagation of structure related - * information. - */ - protected void addSAwareArg(AbstractSpringArg arg) { - sAwareArgs.add(arg); - } - - @Override - /** - * Called by Ant at runtime. Decides whether to call the actions depending - * of the mode of the underlying structure registry. - * - * @see #executeActions - * @see StructureRegistry - */ - public final void execute() throws BuildException { - if (path == null) { - // register the task in the structure - TreeSPath targetPath = createTargetPath(getOwningTarget()); - TreeSPath taskPath = targetPath.createChild(getTaskName() - + targetPath.listChildren(getRegistry()).size()); - - treeSPath = taskPath; - } else { - treeSPath = new TreeSPath(path); - } - - if (getRegistry().getElement(treeSPath) == null) { - // No structure element registered. - if (structureElementArg != null) { - getRegistry().register(treeSPath, - structureElementArg.getStructureElement()); - } else { - if (getDescription() != null) { - getRegistry().register(treeSPath, - new SimpleSElement(getDescription())); - } - } - } - - // notify registered args - for (AbstractSpringArg arg : sAwareArgs) { - Object obj = arg.getBeanInstance(); - - if (obj instanceof StructureAware) { - StructureAware sAwareT = (StructureAware) obj; - sAwareT.notifyCurrentPath(getRegistry(), treeSPath); - } - } - - // execute depending on the registry mode - String mode = getRegistry().getMode(); - if (mode.equals(StructureRegistry.ALL)) { - executeActions(mode); - } else if (mode.equals(StructureRegistry.ACTIVE)) { - List activePaths = getRegistry().getActivePaths(); - - if (activePaths.contains(treeSPath)) { - if (activePaths.contains(treeSPath)) { - executeActions(mode); - } - } - } - - } - - /** Actions to be executed by the implementor. */ - protected abstract void executeActions(String mode); - - /** Create a reference to an external structure element. */ - public StructureElementArg createStructureElement() { - if (structureElementArg != null) - throw new SlcAntException("Arg already set."); - structureElementArg = new StructureElementArg(); - return structureElementArg; - } - - /** Gets the underlying structure registry. */ - protected StructureRegistry getRegistry() { - return (StructureRegistry) getProject().getReference( - SlcProjectHelper.REF_STRUCTURE_REGISTRY); - } - - /** Creates the treeSPath for a given Ant target. */ - protected static TreeSPath createTargetPath(Target target) { - TreeSPath projectPath = (TreeSPath) target.getProject().getReference( - SlcProjectHelper.REF_PROJECT_PATH); - return projectPath.createChild(target.getName()); - } - - /** Gets the treeSPath under which this task is registered. */ - public TreeSPath getTreeSPath() { - return treeSPath; - } - - public String getLabel() { - String description = super.getDescription(); - if (description == null) { - return ""; - } else { - return description; - } - } - - public void setPath(String path) { - this.path = path; - } -} - -class StructureElementArg extends AbstractSpringArg { - public StructureElement getStructureElement() { - return (StructureElement) getBeanInstance(); - } -} \ No newline at end of file diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/structure/package.html b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/structure/package.html deleted file mode 100644 index 99e45d335..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/structure/package.html +++ /dev/null @@ -1,6 +0,0 @@ - - - -Integration of SLC Structure in Ant. - - \ No newline at end of file diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/ParentContextType.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/ParentContextType.java deleted file mode 100644 index 7915b1a42..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/ParentContextType.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.argeo.slc.ant.test; - -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -import org.apache.tools.ant.types.DataType; - -import org.argeo.slc.ant.spring.MapArg; -import org.argeo.slc.core.SlcException; -import org.argeo.slc.core.test.context.ContextAware; -import org.argeo.slc.core.test.context.ContextUtils; -import org.argeo.slc.core.test.context.ParentContextAware; - -public class ParentContextType extends DataType implements ParentContextAware { - private MapArg values = null; - private MapArg expectedValues = null; - - private String contextAnyFlag = DEFAULT_ANY_FLAG; - private String contextSkipFlag = DEFAULT_SKIP_FLAG; - - private String basedon = null; - - private List children = new Vector(); - - public MapArg createValues() { - values = new MapArg(); - return values; - } - - public MapArg createExpectedValues() { - expectedValues = new MapArg(); - return expectedValues; - } - - public void addChildContext(ContextAware contextAware) { - children.add(contextAware); - } - - public Collection getChildContexts() { - return children; - } - - public String getContextAnyFlag() { - return contextAnyFlag; - } - - public void setContextAnyFlag(String contextAnyFlag) { - this.contextAnyFlag = contextAnyFlag; - } - - public String getContextSkipFlag() { - return contextSkipFlag; - } - - public void setContextSkipFlag(String contextSkipFlag) { - this.contextSkipFlag = contextSkipFlag; - } - - public Map getExpectedValues() { - if (expectedValues == null) - expectedValues = new MapArg(); - if (basedon != null) { - Map map = getBaseContext().getExpectedValues(); - ContextUtils.putNotContained(expectedValues.getMap(), map); - } - return expectedValues.getMap(); - } - - public Map getValues() { - if (values == null) - values = new MapArg(); - if (basedon != null) { - Map map = getBaseContext().getValues(); - ContextUtils.putNotContained(values.getMap(), map); - } - return values.getMap(); - } - - private ParentContextType getBaseContext() { - return (ParentContextType) getProject().getReference(basedon); - } - - public void setValues(Map values) { - throw new SlcException("Cannot override values map."); - } - - public void setUpdateValues(Map overrideValues) { - getValues().putAll(overrideValues); - } - - public void setUpdateExpectedValues( - Map overrideExpectedValues) { - getExpectedValues().putAll(overrideExpectedValues); - } - - public void setBasedon(String basedon) { - this.basedon = basedon; - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/SlcCloseTestResultTask.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/SlcCloseTestResultTask.java deleted file mode 100644 index bc0c2ba1a..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/SlcCloseTestResultTask.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.argeo.slc.ant.test; - -import org.argeo.slc.ant.structure.SAwareTask; -import org.argeo.slc.core.structure.StructureRegistry; -import org.argeo.slc.core.test.TestResult; - -/** Ant tasks closing a given result. */ -public class SlcCloseTestResultTask extends SAwareTask { - private String result; - - @Override - public void executeActions(String mode) { - if (!mode.equals(StructureRegistry.READ)) { - TestResult testResult = (TestResult) getContext().getBean(result); - testResult.close(); - } - } - - /** Sets the bean name of the result to close. */ - public void setResult(String bean) { - this.result = bean; - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/SlcReportTask.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/SlcReportTask.java deleted file mode 100644 index 75877625d..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/SlcReportTask.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.argeo.slc.ant.test; - -import org.argeo.slc.ant.structure.SAwareTask; -import org.argeo.slc.core.structure.StructureAware; -import org.argeo.slc.core.structure.StructureRegistry; -import org.argeo.slc.core.test.TestReport; -import org.argeo.slc.core.test.TestResult; - -/** Ant tasks generating a report. */ -public class SlcReportTask extends SAwareTask { - private String result; - private String report; - - @Override - public void executeActions(String mode) { - if (!mode.equals(StructureRegistry.READ)) { - TestResult testResult = null; - if (result != null) { - testResult = (TestResult) getContext().getBean(result); - } - TestReport testReport = (TestReport) getContext().getBean(report); - if (testReport instanceof StructureAware) { - ((StructureAware) testReport).notifyCurrentPath(getRegistry(), - null); - } - testReport.generateTestReport(testResult); - } - } - - /** Sets the bean name of the result to close. */ - public void setResult(String bean) { - this.result = bean; - } - - /** Sets the bean name of the report to generate. */ - public void setReport(String report) { - this.report = report; - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java deleted file mode 100644 index 6f2411c00..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java +++ /dev/null @@ -1,176 +0,0 @@ -package org.argeo.slc.ant.test; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tools.ant.BuildException; - -import org.argeo.slc.ant.SlcAntConfig; -import org.argeo.slc.ant.spring.AbstractSpringArg; -import org.argeo.slc.ant.structure.SAwareTask; -import org.argeo.slc.core.SlcException; -import org.argeo.slc.core.deploy.DeployedSystem; -import org.argeo.slc.core.process.SlcExecution; -import org.argeo.slc.core.process.SlcExecutionAware; -import org.argeo.slc.core.structure.StructureAware; -import org.argeo.slc.core.structure.tree.TreeSPath; -import org.argeo.slc.core.test.ExecutableTestRun; -import org.argeo.slc.core.test.SimpleTestResult; -import org.argeo.slc.core.test.SimpleTestRun; -import org.argeo.slc.core.test.TestData; -import org.argeo.slc.core.test.TestDefinition; -import org.argeo.slc.core.test.TestResult; -import org.argeo.slc.core.test.WritableTestRun; -import org.argeo.slc.spring.SpringUtils; - -/** Ant task wrapping a test run. */ -public class SlcTestTask extends SAwareTask { - private Log log = LogFactory.getLog(SlcTestTask.class); - - private String testRunBean = null; - - private TestDefinitionArg testDefinitionArg; - private TestDataArg testDataArg; - private DeployedSystemArg deployedSystemArg; - private TestResultArg testResultArg; - - @Override - public void executeActions(String mode) throws BuildException { - // find test run - final String testRunBeanT; - if (testRunBean != null) { - testRunBeanT = testRunBean; - } else { - testRunBeanT = getProject().getUserProperty( - SlcAntConfig.DEFAULT_TEST_RUN_PROPERTY); - } - WritableTestRun testRun = null; - - if (testRunBeanT != null) { - testRun = (WritableTestRun) getContext().getBean(testRunBeanT); - if (log.isTraceEnabled()) - log.trace("Load test run bean from bean name " + testRunBeanT); - } - - if (testRun == null) { - testRun = loadSingleFromContext(WritableTestRun.class); - if (testRun == null) { - testRun = new SimpleTestRun(); - log.warn("Created default simple test run"); - } else { - if (log.isTraceEnabled()) - log.trace("Load test run from scanning Spring context"); - } - } - - // set overridden references - if (testDataArg != null) { - testRun.setTestData(testDataArg.getTestData()); - log.trace("Overrides test data"); - } - - if (testDefinitionArg != null) { - testRun.setTestDefinition(testDefinitionArg.getTestDefinition()); - log.trace("Overrides test definition"); - } - - if (deployedSystemArg != null) { - testRun.setDeployedSystem(deployedSystemArg.getDeployedSystem()); - log.trace("Overrides deployed system"); - } - - if (testResultArg != null) { - testRun.setTestResult(testResultArg.getTestResult()); - log.trace("Overrides test result"); - } - - // notify path to test result - TestResult result = testRun.getTestResult(); - if (result == null) { - result = loadSingleFromContext(TestResult.class); - if (result == null) { - result = new SimpleTestResult(); - log.warn("Created default simple test result"); - } else { - if (log.isTraceEnabled()) - log.trace("Load test result from scanning Spring context"); - } - testRun.setTestResult(result); - } - - SlcExecution slcExecution = getSlcExecution(); - testRun.notifySlcExecution(slcExecution); - - if (result != null && result instanceof StructureAware) { - ((StructureAware) result).notifyCurrentPath( - getRegistry(), getTreeSPath()); - } - - ((ExecutableTestRun) testRun).execute(); - } - - /** - * The bean name of the test run to use. If not set the default is used. - * - * @see SlcAntConfig - */ - public void setTestRun(String testRunBean) { - this.testRunBean = testRunBean; - } - - /** Creates sub tag. */ - public TestDefinitionArg createTestDefinition() { - testDefinitionArg = new TestDefinitionArg(); - // only test definitions can add to path - addSAwareArg(testDefinitionArg); - return testDefinitionArg; - } - - /** Creates sub tag. */ - public TestDataArg createTestData() { - testDataArg = new TestDataArg(); - return testDataArg; - } - - /** Creates sub tag. */ - public DeployedSystemArg createDeployedSystem() { - deployedSystemArg = new DeployedSystemArg(); - return deployedSystemArg; - } - - /** Creates sub tag. */ - public TestResultArg createTestResult() { - testResultArg = new TestResultArg(); - return testResultArg; - } - - protected T loadSingleFromContext(Class clss) { - return SpringUtils.loadSingleFromContext(getContext(), clss); - } -} - -class TestDefinitionArg extends AbstractSpringArg { - TestDefinition getTestDefinition() { - return (TestDefinition) getBeanInstance(); - } -} - -class TestDataArg extends AbstractSpringArg { - TestData getTestData() { - return (TestData) getBeanInstance(); - } - -} - -class DeployedSystemArg extends AbstractSpringArg { - DeployedSystem getDeployedSystem() { - return (DeployedSystem) getBeanInstance(); - } - -} - -class TestResultArg extends AbstractSpringArg { - TestResult getTestResult() { - return (TestResult) getBeanInstance(); - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/package.html b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/package.html deleted file mode 100644 index 179159b39..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/package.html +++ /dev/null @@ -1,6 +0,0 @@ - - - -Integration of SLC Test in Ant. - - \ No newline at end of file diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/process/WebServiceSlcExecutionNotifier.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/process/WebServiceSlcExecutionNotifier.java deleted file mode 100644 index 969234487..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/process/WebServiceSlcExecutionNotifier.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.argeo.slc.core.process; - -import java.util.List; - -import org.springframework.ws.client.WebServiceIOException; -import org.springframework.ws.client.core.WebServiceTemplate; -import org.springframework.ws.soap.client.SoapFaultClientException; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.argeo.slc.msg.process.SlcExecutionRequest; -import org.argeo.slc.msg.process.SlcExecutionStatusRequest; -import org.argeo.slc.msg.process.SlcExecutionStepsRequest; -import org.argeo.slc.ws.client.WebServiceUtils; - -public class WebServiceSlcExecutionNotifier implements SlcExecutionNotifier { - private WebServiceTemplate template; - - private Log log = LogFactory.getLog(getClass()); - - private Boolean cannotConnect = false; - - public void newExecution(SlcExecution slcExecution) { - if (cannotConnect) - return; - - SlcExecutionRequest req = new SlcExecutionRequest(); - req.setSlcExecution(slcExecution); - try { - WebServiceUtils.marshalSendAndReceive(template, req); - if (log.isTraceEnabled()) - log.trace("Notified creation of slc execution " - + slcExecution.getUuid()); - } catch (SoapFaultClientException e) { - WebServiceUtils.manageSoapException(e); - } catch (WebServiceIOException e) { - manageIoException(e); - } - } - - public void updateExecution(SlcExecution slcExecution) { - if (cannotConnect) - return; - - SlcExecutionRequest req = new SlcExecutionRequest(); - req.setSlcExecution(slcExecution); - try { - WebServiceUtils.marshalSendAndReceive(template, req); - if (log.isTraceEnabled()) - log.trace("Notified update of slc execution " - + slcExecution.getUuid()); - } catch (SoapFaultClientException e) { - WebServiceUtils.manageSoapException(e); - } catch (WebServiceIOException e) { - manageIoException(e); - } - } - - public void updateStatus(SlcExecution slcExecution, String oldStatus, - String newStatus) { - if (cannotConnect) - return; - - SlcExecutionStatusRequest req = new SlcExecutionStatusRequest( - slcExecution.getUuid(), newStatus); - try { - WebServiceUtils.marshalSendAndReceive(template, req); - if (log.isTraceEnabled()) - log.trace("Notified status update of slc execution " - + slcExecution.getUuid()); - } catch (SoapFaultClientException e) { - WebServiceUtils.manageSoapException(e); - } catch (WebServiceIOException e) { - manageIoException(e); - } - } - - public void addSteps(SlcExecution slcExecution, - List additionalSteps) { - if (cannotConnect) - return; - - SlcExecutionStepsRequest req = new SlcExecutionStepsRequest(); - req.setSlcExecutionUuid(slcExecution.getUuid()); - req.setSteps(additionalSteps); - if (log.isTraceEnabled()) { - for (SlcExecutionStep step : additionalSteps) { - log.trace("Step " + step.getUuid() + ": " + step.logAsString()); - } - } - - try { - WebServiceUtils.marshalSendAndReceive(template, req); - if (log.isTraceEnabled()) - log.trace("Added steps to slc execution " - + slcExecution.getUuid()); - } catch (SoapFaultClientException e) { - WebServiceUtils.manageSoapException(e); - } catch (WebServiceIOException e) { - manageIoException(e); - } - } - - public void setTemplate(WebServiceTemplate template) { - this.template = template; - } - - protected void manageIoException(WebServiceIOException e) { - if (!cannotConnect) { - log.error("Cannot connect to " + template.getDefaultUri() - + ". Won't try again.", e); - cannotConnect = true; - } - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/WebServiceTreeTestResultNotifier.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/WebServiceTreeTestResultNotifier.java deleted file mode 100644 index 6cfd4da61..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/WebServiceTreeTestResultNotifier.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.argeo.slc.core.test.tree; - -import org.springframework.ws.client.WebServiceIOException; -import org.springframework.ws.client.core.WebServiceTemplate; -import org.springframework.ws.soap.client.SoapFaultClientException; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.argeo.slc.core.test.TestResultListener; -import org.argeo.slc.core.test.TestResultPart; -import org.argeo.slc.msg.test.tree.CloseTreeTestResultRequest; -import org.argeo.slc.msg.test.tree.CreateTreeTestResultRequest; -import org.argeo.slc.msg.test.tree.ResultPartRequest; -import org.argeo.slc.ws.client.WebServiceUtils; - -public class WebServiceTreeTestResultNotifier implements - TestResultListener { - private WebServiceTemplate template; - private Boolean onlyOnClose = false; - - private Log log = LogFactory.getLog(getClass()); - - private Boolean cannotConnect = false; - - public void resultPartAdded(TreeTestResult testResult, - TestResultPart testResultPart) { - if (onlyOnClose) - return; - - if (cannotConnect) - return; - - try { - if (testResult.getResultParts().size() == 1 - && testResult.getResultParts().values().iterator().next() - .getParts().size() == 1) { - CreateTreeTestResultRequest req = new CreateTreeTestResultRequest( - testResult); - - if (log.isDebugEnabled()) - log.debug("Send create result request for result " - + testResult.getUuid()); - - WebServiceUtils.marshalSendAndReceive(template, req); - } else { - ResultPartRequest req = new ResultPartRequest(testResult); - - if (log.isDebugEnabled()) - log.debug("Send result parts for result " - + testResult.getUuid()); - - WebServiceUtils.marshalSendAndReceive(template, req); - } - } catch (SoapFaultClientException e) { - WebServiceUtils.manageSoapException(e); - - } catch (WebServiceIOException e) { - manageIoException(e); - } - } - - public void close(TreeTestResult testResult) { - if (cannotConnect) - return; - - try { - if (onlyOnClose) { - CreateTreeTestResultRequest req = new CreateTreeTestResultRequest( - testResult); - - if (log.isDebugEnabled()) - log.debug("Send create result request for result " - + testResult.getUuid()); - - WebServiceUtils.marshalSendAndReceive(template, req); - } else { - CloseTreeTestResultRequest req = new CloseTreeTestResultRequest( - testResult); - - if (log.isDebugEnabled()) - log.debug("Send close result request for result " - + testResult.getUuid()); - - WebServiceUtils.marshalSendAndReceive(template, req); - - } - } catch (SoapFaultClientException e) { - WebServiceUtils.manageSoapException(e); - } catch (WebServiceIOException e) { - manageIoException(e); - } - } - - public void setTemplate(WebServiceTemplate template) { - this.template = template; - } - - public void setOnlyOnClose(Boolean onlyOnClose) { - this.onlyOnClose = onlyOnClose; - } - - protected void manageIoException(WebServiceIOException e) { - if (!cannotConnect) { - log.error("Cannot connect to " + template.getDefaultUri() - + ". Won't try again.", e); - cannotConnect = true; - } - } -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/maven/MavenDeployEnvironment.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/maven/MavenDeployEnvironment.java deleted file mode 100644 index d10b073e1..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/maven/MavenDeployEnvironment.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.argeo.slc.maven; - -import java.io.File; -import java.net.URL; -import java.util.Map; -import java.util.Properties; -import java.util.UUID; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.slc.ant.AntRegistryUtil; -import org.argeo.slc.core.SlcException; -import org.argeo.slc.core.deploy.DeployEnvironment; - -public class MavenDeployEnvironment implements DeployEnvironment { - private static final Log log = LogFactory - .getLog(MavenDeployEnvironment.class); - private MavenManager mavenManager; - - public void unpackTo(Object packg, File targetLocation, - Map filter) { - File packageLocation; - String type = null; - String removeRootDir = "enabled"; - if (packg instanceof MavenFile) { - packageLocation = mavenManager - .getPackageLocation((MavenFile) packg); - type = ((MavenFile) packg).getType(); - } else if (packg instanceof File) { - packageLocation = (File) packg; - // TODO: type based on extension - } else { - throw new SlcException("Unrecognized package type " - + packg.getClass()); - } - if (log.isDebugEnabled()) { - log.debug("Unpack " + packageLocation + " of type " + type + " to " - + targetLocation); - } - - try { - File tempDir = new File("/tmp/"+UUID.randomUUID().toString()); - tempDir.mkdirs(); - targetLocation.mkdirs(); - Properties props = new Properties(); - props.setProperty("dest", targetLocation.getAbsolutePath()); - props.setProperty("src", packageLocation.getAbsolutePath()); - props.setProperty("tempDir", tempDir.getAbsolutePath()); - props.setProperty("removeRootDir", removeRootDir); - - URL antUrl = getClass().getClassLoader().getResource( - "org/argeo/slc/support/deploy/ant/build.xml"); - - if (type == null || type.equals("zip")) { - AntRegistryUtil.runAll(antUrl, "deployZip", props); - } else if (type.equals("tar.gz")) { - AntRegistryUtil.runAll(antUrl, "deployTarGz", props); - } else { - throw new SlcException("Unknow package type " + type); - } - } catch (SlcException e) { - throw e; - } catch (Exception e) { - throw new SlcException("Cannot unpack package " + packg + " to " - + targetLocation, e); - } - } - - public void setMavenManager(MavenManager mavenManager) { - this.mavenManager = mavenManager; - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/maven/MavenFile.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/maven/MavenFile.java deleted file mode 100644 index 31c6385a6..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/maven/MavenFile.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.argeo.slc.maven; - -import org.argeo.slc.core.build.Distribution; -import org.argeo.slc.core.deploy.DeploymentData; - -public class MavenFile implements Distribution, DeploymentData { - private String groupId; - private String artifactId; - private String version; - private String type; - private String classifier; - - private String distributionId; - - public String getDistributionId() { - return distributionId; - } - - public void setDistributionId(String distributionId) { - this.distributionId = distributionId; - } - - public String getGroupId() { - return groupId; - } - - public void setGroupId(String groupId) { - this.groupId = groupId; - } - - public String getArtifactId() { - return artifactId; - } - - public void setArtifactId(String artifactId) { - this.artifactId = artifactId; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getClassifier() { - return classifier; - } - - public void setClassifier(String classifier) { - this.classifier = classifier; - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/maven/MavenManager.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/maven/MavenManager.java deleted file mode 100644 index 3a07e227a..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/maven/MavenManager.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.argeo.slc.maven; - -import java.io.File; -import java.util.List; -import java.util.Vector; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.embedder.MavenEmbedder; -import org.apache.maven.embedder.MavenEmbedderException; - -import org.argeo.slc.core.SlcException; - -public class MavenManager { - private final Log log = LogFactory.getLog(getClass()); - - private String repositoryId; - private String repositoryUrl; - private String localRepositoryPath; - - private ArtifactRepository localRepository; - private List remoteRepositories; - - private MavenEmbedder mavenEmbedder; - - public void init() { - try { - mavenEmbedder = new MavenEmbedder(); - mavenEmbedder.setOffline(true); - mavenEmbedder.setClassLoader(Thread.currentThread() - .getContextClassLoader()); - mavenEmbedder.start(); - - mavenEmbedder.setLocalRepositoryDirectory(new File( - localRepositoryPath)); - - localRepository = mavenEmbedder.getLocalRepository(); - - // localRepository = mavenEmbedder.createLocalRepository(new File( - // localRepositoryPath)); - - ArtifactRepository repository = mavenEmbedder.createRepository( - repositoryUrl, repositoryId); - - remoteRepositories = new Vector(); - remoteRepositories.add(repository); - } catch (Exception e) { - throw new SlcException("Cannot initialize Maven manager", e); - } - } - - private Artifact resolve(MavenFile mavenDistribution) { - try { - Artifact artifact; - if (mavenDistribution.getClassifier() == null) { - artifact = mavenEmbedder.createArtifact(mavenDistribution - .getGroupId(), mavenDistribution.getArtifactId(), - mavenDistribution.getVersion(), - Artifact.SCOPE_PROVIDED, mavenDistribution.getType()); - } else { - artifact = mavenEmbedder.createArtifactWithClassifier( - mavenDistribution.getGroupId(), mavenDistribution - .getArtifactId(), mavenDistribution - .getVersion(), mavenDistribution.getType(), - mavenDistribution.getClassifier()); - } - - mavenEmbedder - .resolve(artifact, remoteRepositories, localRepository); - - return artifact; - } catch (Exception e) { - throw new SlcException("Cannot resolve artifact.", e); - } - } - - public File getPackageLocation(MavenFile mavenDistribution) { - return resolve(mavenDistribution).getFile(); - } - - public void destroy() { - try { - if (mavenEmbedder != null) { - mavenEmbedder.stop(); - } - } catch (MavenEmbedderException e) { - log.error("Cannot destroy Maven manager", e); - } - } - - public void setRepositoryId(String repositoryId) { - this.repositoryId = repositoryId; - } - - public void setRepositoryUrl(String repositoryUrl) { - this.repositoryUrl = repositoryUrl; - } - - public void setLocalRepositoryPath(String localRepositoryPath) { - this.localRepositoryPath = localRepositoryPath; - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ws/client/ValidatingClientInterceptor.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ws/client/ValidatingClientInterceptor.java deleted file mode 100644 index cd3add67c..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ws/client/ValidatingClientInterceptor.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.argeo.slc.ws.client; - -import java.io.IOException; - -import javax.xml.transform.Source; - -import org.springframework.ws.client.WebServiceClientException; -import org.springframework.ws.client.WebServiceIOException; -import org.springframework.ws.client.support.interceptor.ClientInterceptor; -import org.springframework.ws.context.MessageContext; -import org.springframework.xml.validation.XmlValidator; -import org.xml.sax.SAXParseException; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -public class ValidatingClientInterceptor implements ClientInterceptor { - private final static Log log = LogFactory - .getLog(ValidatingClientInterceptor.class); - - private Boolean validateRequest = true; - private Boolean validateResponse = false; - private XmlValidator validator = null; - - public boolean handleFault(MessageContext messageContext) - throws WebServiceClientException { - return true; - } - - public boolean handleRequest(MessageContext messageContext) - throws WebServiceClientException { - if (validateRequest) { - if (messageContext.getRequest() == null) - return true; - - Source source = messageContext.getRequest().getPayloadSource(); - try { - return validate(source); - } catch (IOException e) { - throw new WebServiceIOException("Cannot validate request", e); - } - } else { - return true; - } - } - - public boolean handleResponse(MessageContext messageContext) - throws WebServiceClientException { - if (validateResponse) { - if (messageContext.getResponse() == null) - return true; - - Source source = messageContext.getResponse().getPayloadSource(); - try { - return validate(source); - } catch (IOException e) { - throw new WebServiceIOException("Cannot validate response", e); - } - } else { - return true; - } - } - - protected boolean validate(Source source) throws IOException { - SAXParseException[] exceptions = validator.validate(source); - if (exceptions.length != 0) { - for (SAXParseException ex : exceptions) { - log.error(ex.getMessage()); - } - return false; - } else { - return true; - } - } - - public void setValidateRequest(Boolean validateRequest) { - this.validateRequest = validateRequest; - } - - public void setValidateResponse(Boolean validateResponse) { - this.validateResponse = validateResponse; - } - - public void setValidator(XmlValidator validator) { - this.validator = validator; - } - -} diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ws/client/WebServiceUtils.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ws/client/WebServiceUtils.java deleted file mode 100644 index d37a27efe..000000000 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ws/client/WebServiceUtils.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.argeo.slc.ws.client; - -import java.util.Iterator; - -import javax.xml.transform.Source; -import javax.xml.transform.dom.DOMSource; - -import org.springframework.ws.client.core.WebServiceTemplate; -import org.springframework.ws.soap.SoapFaultDetail; -import org.springframework.ws.soap.SoapFaultDetailElement; -import org.springframework.ws.soap.client.SoapFaultClientException; -import org.springframework.xml.transform.StringResult; -import org.w3c.dom.Node; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -public abstract class WebServiceUtils { - private final static Log log = LogFactory.getLog(WebServiceUtils.class); - - public static Object marshalSendAndReceiveSafe(WebServiceTemplate template, - Object req) { - try { - Object resp = marshalSendAndReceive(template, req); - return resp; - } catch (Exception e) { - log.error("Cannot send web servicerequest: "+e.getMessage()); - if(log.isDebugEnabled()){ - log.debug("Webservice exception details: ",e); - } - return null; - } - } - - public static Object marshalSendAndReceive( - WebServiceTemplate template, Object req) { - if (log.isTraceEnabled()) { - try { - StringResult result = new StringResult(); - template.getMarshaller().marshal(req, result); - log.trace("About to send " + result); - } catch (Exception e) { - log.error("Cannot marshall " + req + " for logging", e); - } - } - Object resp = template.marshalSendAndReceive(req); - return resp; - } - - public static void manageSoapException(SoapFaultClientException e) { - log - .error("WS root cause: " - + e.getSoapFault().getFaultStringOrReason()); - StringBuffer stack = new StringBuffer(""); - SoapFaultDetail detail = e.getSoapFault().getFaultDetail(); - if (detail != null) { - Iterator it = (Iterator) detail - .getDetailEntries(); - while (it.hasNext()) { - SoapFaultDetailElement elem = it.next(); - if (elem.getName().getLocalPart().equals("StackElement")) { - Source source = elem.getSource(); - if (source instanceof DOMSource) { - Node node = ((DOMSource) source).getNode(); - stack.append(node.getTextContent()).append('\n'); - } - } - } - - if (stack.length() > 0 && log.isTraceEnabled()) - log.error("WS root cause stack: " + stack); - } - } - - private WebServiceUtils() { - - } -} diff --git a/org.argeo.slc.core/src/test/java/org/argeo/slc/ant/SlcAntTest.java b/org.argeo.slc.core/src/test/java/org/argeo/slc/ant/SlcAntTest.java deleted file mode 100644 index c19cdd4a2..000000000 --- a/org.argeo.slc.core/src/test/java/org/argeo/slc/ant/SlcAntTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.argeo.slc.ant; - -import java.net.URL; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.argeo.slc.unit.AbstractSpringTestCase; - -public class SlcAntTest extends AbstractSpringTestCase { - private Log log = LogFactory.getLog(getClass()); - - public void testSimpleRun() { - // AntRegistryUtil.runAll(getClass().getResource( - // "/org/argeo/slc/ant/build.xml"), "test", null); - - URL url = getClass().getResource("/org/argeo/slc/ant/build.xml"); - log.info("Run Ant file from URL: " + url); - AntRunner antRunner = new AntRunner(getContext(), url, "test"); - - antRunner.run(); - } - -} diff --git a/org.argeo.slc.core/src/test/java/org/argeo/slc/ws/SlcAntWsIntegrationTest.java b/org.argeo.slc.core/src/test/java/org/argeo/slc/ws/SlcAntWsIntegrationTest.java deleted file mode 100644 index 7b3d662f7..000000000 --- a/org.argeo.slc.core/src/test/java/org/argeo/slc/ws/SlcAntWsIntegrationTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.argeo.slc.ws; - -import java.net.URL; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.argeo.slc.ant.AntRunner; -import org.argeo.slc.unit.AbstractSpringTestCase; - -public class SlcAntWsIntegrationTest extends AbstractSpringTestCase { - private Log log = LogFactory.getLog(getClass()); - - public void testSimpleRun() { - // AntRegistryUtil.runAll(getClass().getResource( - // "/org/argeo/slc/ant/build.xml"), "test", null); - - URL url = getClass().getResource("/org/argeo/slc/ant/build.xml"); - log.info("Run Ant file from URL: " + url); - AntRunner antRunner = new AntRunner(getContext(), url, "test"); - - antRunner.run(); - } - -} diff --git a/org.argeo.slc.core/src/test/java/org/argeo/slc/ws/SlcExecutionWsIntegrationTest.java b/org.argeo.slc.core/src/test/java/org/argeo/slc/ws/SlcExecutionWsIntegrationTest.java deleted file mode 100644 index 47d584f23..000000000 --- a/org.argeo.slc.core/src/test/java/org/argeo/slc/ws/SlcExecutionWsIntegrationTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.argeo.slc.ws; - -import org.springframework.ws.client.core.WebServiceTemplate; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.argeo.slc.core.process.SlcExecution; -import org.argeo.slc.msg.process.SlcExecutionRequest; -import org.argeo.slc.unit.AbstractSpringTestCase; -import org.argeo.slc.unit.process.SlcExecutionTestUtils; - -public class SlcExecutionWsIntegrationTest extends AbstractSpringTestCase { - private Log log = LogFactory.getLog(getClass()); - - public void testSendSlcExecutionrequest() { - WebServiceTemplate template = getBean(WebServiceTemplate.class); - SlcExecution slcExec = SlcExecutionTestUtils.createSimpleSlcExecution(); - - SlcExecutionRequest req = new SlcExecutionRequest(); - req.setSlcExecution(slcExec); - - log.info("Send SlcExecutionRequest for SlcExecution " - + slcExec.getUuid()); - - Object resp = template.marshalSendAndReceive(req); - log.info("Resp: " + resp); - } -} diff --git a/org.argeo.slc.core/src/test/java/org/argeo/slc/ws/TreeTestResultWsIntegrationTest.java b/org.argeo.slc.core/src/test/java/org/argeo/slc/ws/TreeTestResultWsIntegrationTest.java deleted file mode 100644 index 7796c26d7..000000000 --- a/org.argeo.slc.core/src/test/java/org/argeo/slc/ws/TreeTestResultWsIntegrationTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.argeo.slc.ws; - -import org.springframework.ws.client.core.WebServiceTemplate; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import static org.argeo.slc.unit.test.tree.TreeTestResultTestUtils.createCompleteTreeTestResult; -import static org.argeo.slc.unit.test.tree.TreeTestResultTestUtils.createSimpleResultPartRequest; - -import org.argeo.slc.core.test.tree.TreeTestResult; -import org.argeo.slc.msg.test.tree.CloseTreeTestResultRequest; -import org.argeo.slc.msg.test.tree.CreateTreeTestResultRequest; -import org.argeo.slc.msg.test.tree.ResultPartRequest; -import org.argeo.slc.unit.AbstractSpringTestCase; - -public class TreeTestResultWsIntegrationTest extends AbstractSpringTestCase { - private Log log = LogFactory.getLog(getClass()); - - public void testCreateTreeTestResultRequest() { - WebServiceTemplate template = getBean(WebServiceTemplate.class); - CreateTreeTestResultRequest req = new CreateTreeTestResultRequest( - createCompleteTreeTestResult()); - req.getTreeTestResult().close();// in order to avoid unclosed in test db - - log.info("Send CreateTreeTestResultRequest for result " - + req.getTreeTestResult().getUuid()); - - Object resp = template.marshalSendAndReceive(req); - log.info("Resp: " + resp); - } - - public void testResultPartRequest() { - WebServiceTemplate template = getBean(WebServiceTemplate.class); - TreeTestResult ttr = createCompleteTreeTestResult(); - ttr.close();// in order to avoid unclosed in test db - CreateTreeTestResultRequest reqCreate = new CreateTreeTestResultRequest( - ttr); - log.info("Send CreateTreeTestResultRequest for result " - + reqCreate.getTreeTestResult().getUuid()); - template.marshalSendAndReceive(reqCreate); - - ResultPartRequest req = createSimpleResultPartRequest(ttr); - - log.info("Send ResultPartRequest for result " + req.getResultUuid()); - Object resp = template.marshalSendAndReceive(req); - log.info("Resp: " + resp); - } - - public void testCloseTreeTestResultRequest() { - WebServiceTemplate template = getBean(WebServiceTemplate.class); - - TreeTestResult ttr = createCompleteTreeTestResult(); - CreateTreeTestResultRequest reqCreate = new CreateTreeTestResultRequest( - ttr); - log.info("Send CreateTreeTestResultRequest for result " - + reqCreate.getTreeTestResult().getUuid()); - template.marshalSendAndReceive(reqCreate); - - ttr.close(); - CloseTreeTestResultRequest req = new CloseTreeTestResultRequest(ttr - .getUuid(), ttr.getCloseDate()); - - log.info("Send CloseTreeTestResultRequest for result " - + req.getResultUuid()); - - Object resp = template.marshalSendAndReceive(req); - log.info("Resp: " + resp); - } -}