From: Mathieu Baudier Date: Sat, 21 Jun 2008 18:14:17 +0000 (+0000) Subject: Remove old runtime X-Git-Tag: argeo-slc-2.1.7~2765 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=8912b1cdb0b73547d70d2a2729ea075751f37f35;p=gpl%2Fargeo-slc.git Remove old runtime git-svn-id: https://svn.argeo.org/slc/trunk@1277 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java deleted file mode 100644 index 476384cd2..000000000 --- a/org.argeo.slc.agent/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(SlcAntConstants.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(SlcAntConstants.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.agent/src/main/java/org/argeo/slc/ant/AntRunner.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntRunner.java index 5ce4b53b7..4bedc9bac 100644 --- a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntRunner.java +++ b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntRunner.java @@ -9,12 +9,10 @@ import java.util.Vector; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; -import org.springframework.context.ApplicationContext; +import org.apache.tools.ant.helper.ProjectHelper2; -/** @deprecated */ +/** Run regular Ant script (that is, not SLC instrumented) */ public class AntRunner { - private ApplicationContext context; - private ProjectHelper projectHelper; private URL buildFile; private String[] targets; private Properties properties; @@ -23,25 +21,14 @@ public class 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(URL buildFile, String target, Properties properties) { + this(buildFile, new String[] { target }, properties); } - public AntRunner(ApplicationContext context, URL buildFile, String target) { - super(); - this.context = context; - - BasicSlcProjectHelper basicSlcProjectHelper = new BasicSlcProjectHelper(); - this.projectHelper = basicSlcProjectHelper; - basicSlcProjectHelper.setContext(context); - + public AntRunner(URL buildFile, String[] targets, Properties properties) { this.buildFile = buildFile; - this.targets = new String[] { target }; + this.targets = targets; + this.properties = properties; } public void run() { @@ -52,6 +39,7 @@ public class AntRunner { p.setBaseDir(extractBaseDir(path)); p.init(); + ProjectHelper projectHelper = new ProjectHelper2(); p.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, projectHelper); projectHelper.parse(p, buildFile); @@ -100,9 +88,4 @@ public class AntRunner { } } - public static void main(String[] args) { - // TODO Auto-generated method stub - - } - } diff --git a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntSlcApplication.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntSlcApplication.java index ab2316ae0..ed214b49e 100644 --- a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntSlcApplication.java +++ b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntSlcApplication.java @@ -20,16 +20,13 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; import org.apache.tools.ant.helper.ProjectHelper2; import org.apache.tools.ant.listener.CommonsLoggingListener; -import org.argeo.slc.core.SlcException; import org.argeo.slc.core.process.SlcExecution; import org.argeo.slc.core.structure.SimpleSElement; import org.argeo.slc.core.structure.StructureRegistry; import org.argeo.slc.core.structure.tree.TreeSPath; import org.argeo.slc.core.structure.tree.TreeSRegistry; import org.argeo.slc.logging.Log4jUtils; -import org.argeo.slc.runtime.SlcExecutionContext; import org.argeo.slc.runtime.SlcExecutionOutput; -import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; diff --git a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/BasicSlcProjectHelper.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/BasicSlcProjectHelper.java deleted file mode 100644 index 7a797d613..000000000 --- a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/BasicSlcProjectHelper.java +++ /dev/null @@ -1,42 +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; - -/** @deprecated */ -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(SlcAntConstants.REF_STRUCTURE_REGISTRY, registry); - project.addReference(SlcAntConstants.REF_PROJECT_PATH, projectPath); - - super.parse(project, source); - - project.addReference(SlcAntConstants.REF_ROOT_CONTEXT, context); - SlcProjectHelper.createAndRegisterSlcExecution(project); - - SlcProjectHelper.addCustomTaskAndTypes(project); - } - - public void setContext(ApplicationContext context) { - this.context = context; - } - -} diff --git a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/ProjectRelatedBuildListener.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/ProjectRelatedBuildListener.java deleted file mode 100644 index f6077b39b..000000000 --- a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/ProjectRelatedBuildListener.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.argeo.slc.ant; - -import org.apache.tools.ant.BuildListener; -import org.apache.tools.ant.Project; - -/** @deprecated */ -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.agent/src/main/java/org/argeo/slc/ant/SlcAntConfig.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/SlcAntConfig.java deleted file mode 100644 index 4c8981c17..000000000 --- a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/SlcAntConfig.java +++ /dev/null @@ -1,334 +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.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tools.ant.Project; -import org.argeo.slc.core.test.WritableTestRun; -import org.springframework.util.Log4jConfigurer; - -/** - *

- * 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"; - /** - * 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"; - // 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(SlcAntConstants.ROOT_DIR_PROPERTY, fileUrlPrefix - + rootDir.getCanonicalPath()); - - // Conf dir - if (all.getProperty(SlcAntConstants.CONF_DIR_PROPERTY) == null) { - confDir = new File(rootProps.getProperty(SlcAntConstants.CONF_DIR_PROPERTY, - rootDir.getAbsolutePath() + "/../conf")) - .getCanonicalFile(); - all.setProperty(SlcAntConstants.CONF_DIR_PROPERTY, fileUrlPrefix - + confDir.getAbsolutePath()); - } else { - confDir = new File(all.getProperty(SlcAntConstants.CONF_DIR_PROPERTY)) - .getCanonicalFile(); - } - - // Work dir - if (all.getProperty(SlcAntConstants.WORK_DIR_PROPERTY) == null) { - workDir = new File(rootProps.getProperty(SlcAntConstants.WORK_DIR_PROPERTY, - rootDir.getAbsolutePath() + "/../work")) - .getCanonicalFile(); - all.setProperty(SlcAntConstants.WORK_DIR_PROPERTY, fileUrlPrefix - + workDir.getAbsolutePath()); - } else { - workDir = new File(all.getProperty(SlcAntConstants.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(SlcAntConstants.DEFAULT_TEST_RUN_PROPERTY) == null) { - all.setProperty(SlcAntConstants.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.agent/src/main/java/org/argeo/slc/ant/SlcExecutionBuildListener.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/SlcExecutionBuildListener.java index 2b9400e4b..da682ba6f 100644 --- a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/SlcExecutionBuildListener.java +++ b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/SlcExecutionBuildListener.java @@ -5,9 +5,7 @@ import java.util.Vector; import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.Level; -import org.apache.log4j.LogManager; import org.apache.log4j.MDC; -import org.apache.log4j.Priority; import org.apache.log4j.spi.LoggingEvent; import org.apache.tools.ant.BuildEvent; import org.apache.tools.ant.BuildListener; @@ -16,7 +14,6 @@ import org.argeo.slc.core.SlcException; 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.ws.process.WebServiceSlcExecutionNotifier; public class SlcExecutionBuildListener extends AppenderSkeleton implements BuildListener { diff --git a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java deleted file mode 100644 index 227148189..000000000 --- a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java +++ /dev/null @@ -1,247 +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.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tools.ant.BuildException; -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.structure.DefaultSRegistry; -import org.argeo.slc.core.structure.SimpleSElement; -import org.argeo.slc.core.structure.StructureRegistry; -import org.argeo.slc.core.structure.tree.TreeSPath; -import org.springframework.beans.factory.ListableBeanFactory; -import org.springframework.context.support.AbstractApplicationContext; -import org.springframework.context.support.FileSystemXmlApplicationContext; - -/** - * 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; - - 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(SlcAntConstants.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(SlcAntConstants.REF_STRUCTURE_REGISTRY); - File rootDir = new File(project - .getUserProperty(SlcAntConstants.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(SlcAntConstants.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(SlcAntConstants.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, SlcAntConstants.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, SlcAntConstants.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(SlcAntConstants.REF_ROOT_CONTEXT) != null) { - slcExecution.setType(SlcAntConstants.EXECTYPE_SLC_ANT); - } else { - slcExecution.setType(SlcAntConstants.EXECTYPE_ANT); - } - - slcExecution.setUser(System.getProperty("user.name")); - slcExecution.setStatus(SlcExecution.STATUS_RUNNING); - slcExecution.getAttributes().put("ant.file", - project.getProperty("ant.file")); - - project.addReference(SlcAntConstants.REF_SLC_EXECUTION, - slcExecution); - - // Add build listeners declared in Spring context - Map listeners = ((ListableBeanFactory) project - .getReference(SlcAntConstants.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.agent/src/main/java/org/argeo/slc/ant/deploy/SlcDeployTask.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/deploy/SlcDeployTask.java index 8e6fc63b1..e6d42db9a 100644 --- a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/deploy/SlcDeployTask.java +++ b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/deploy/SlcDeployTask.java @@ -3,7 +3,6 @@ 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.SlcAntConfig; import org.argeo.slc.ant.spring.SpringArg; import org.argeo.slc.ant.structure.SAwareTask; import org.argeo.slc.core.build.Distribution; diff --git a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java index 651ccad7b..e5ccab51a 100644 --- a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java +++ b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java @@ -3,7 +3,6 @@ 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.SlcAntConstants; import org.argeo.slc.ant.spring.SpringArg; import org.argeo.slc.ant.structure.SAwareTask; diff --git a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/unit/SlcAntAppliTestCase.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/unit/SlcAntAppliTestCase.java index efe4ca73e..22050b4e8 100644 --- a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/unit/SlcAntAppliTestCase.java +++ b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/unit/SlcAntAppliTestCase.java @@ -2,10 +2,8 @@ package org.argeo.slc.ant.unit; import junit.framework.TestCase; -import org.apache.tools.ant.launch.AntMain; import org.argeo.slc.ant.AntExecutionContext; import org.argeo.slc.cli.DefaultSlcRuntime; -import org.argeo.slc.runtime.SlcExecutionContext; import org.argeo.slc.runtime.SlcExecutionOutput; public abstract class SlcAntAppliTestCase extends TestCase implements diff --git a/org.argeo.slc.agent/src/main/java/org/argeo/slc/cli/DefaultSlcRuntime.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/cli/DefaultSlcRuntime.java index fcf272464..adae463c2 100644 --- a/org.argeo.slc.agent/src/main/java/org/argeo/slc/cli/DefaultSlcRuntime.java +++ b/org.argeo.slc.agent/src/main/java/org/argeo/slc/cli/DefaultSlcRuntime.java @@ -18,7 +18,6 @@ import org.argeo.slc.ant.SlcAntConstants; import org.argeo.slc.ant.SlcAntException; import org.argeo.slc.core.SlcException; import org.argeo.slc.core.process.SlcExecution; -import org.argeo.slc.runtime.SlcExecutionContext; import org.argeo.slc.runtime.SlcExecutionOutput; import org.argeo.slc.spring.SpringUtils; import org.springframework.core.io.DefaultResourceLoader; diff --git a/org.argeo.slc.agent/src/main/java/org/argeo/slc/cli/SlcMain.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/cli/SlcMain.java index dfbd7053c..10636f3d4 100644 --- a/org.argeo.slc.agent/src/main/java/org/argeo/slc/cli/SlcMain.java +++ b/org.argeo.slc.agent/src/main/java/org/argeo/slc/cli/SlcMain.java @@ -1,6 +1,5 @@ package org.argeo.slc.cli; -import java.io.File; import java.util.Properties; import org.apache.commons.cli.CommandLine; @@ -15,9 +14,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.slc.core.SlcException; import org.argeo.slc.logging.Log4jUtils; -import org.springframework.core.io.DefaultResourceLoader; -import org.springframework.core.io.FileSystemResource; -import org.springframework.core.io.Resource; public class SlcMain { public enum Mode { diff --git a/org.argeo.slc.agent/src/main/java/org/argeo/slc/maven/MavenDeployEnvironment.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/maven/MavenDeployEnvironment.java index ebe06ea82..223eb300f 100644 --- a/org.argeo.slc.agent/src/main/java/org/argeo/slc/maven/MavenDeployEnvironment.java +++ b/org.argeo.slc.agent/src/main/java/org/argeo/slc/maven/MavenDeployEnvironment.java @@ -8,7 +8,7 @@ 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.ant.AntRunner; import org.argeo.slc.core.SlcException; import org.argeo.slc.core.deploy.DeployEnvironment; @@ -52,9 +52,9 @@ public class MavenDeployEnvironment implements DeployEnvironment { "org/argeo/slc/support/deploy/ant/build.xml"); if (type == null || type.equals("zip")) { - AntRegistryUtil.runAll(antUrl, "deployZip", props); + new AntRunner(antUrl, "deployZip", props).run(); } else if (type.equals("tar.gz")) { - AntRegistryUtil.runAll(antUrl, "deployTarGz", props); + new AntRunner(antUrl, "deployTarGz", props).run(); } else { throw new SlcException("Unknow package type " + type); } diff --git a/org.argeo.slc.agent/src/main/resources/META-INF/services/org.apache.tools.ant.ProjectHelper b/org.argeo.slc.agent/src/main/resources/META-INF/services/org.apache.tools.ant.ProjectHelper deleted file mode 100644 index 1c222d5e1..000000000 --- a/org.argeo.slc.agent/src/main/resources/META-INF/services/org.apache.tools.ant.ProjectHelper +++ /dev/null @@ -1 +0,0 @@ -org.argeo.slc.ant.SlcProjectHelper \ No newline at end of file diff --git a/org.argeo.slc.agent/src/test/java/org/argeo/slc/ws/SlcAntWsIntegrationTest.java b/org.argeo.slc.agent/src/test/java/org/argeo/slc/ws/SlcAntWsIntegrationTest.java index 7b3d662f7..ab80744af 100644 --- a/org.argeo.slc.agent/src/test/java/org/argeo/slc/ws/SlcAntWsIntegrationTest.java +++ b/org.argeo.slc.agent/src/test/java/org/argeo/slc/ws/SlcAntWsIntegrationTest.java @@ -1,25 +1,22 @@ 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() { + fail("Adapt to new runtime"); // 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(); + // 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(); } }