X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fant%2FSlcProjectHelper.java;h=001ead97bd28db91d77d5bbea186bcde54aa4675;hb=97db5f361ffc416c328274422e5b268a931910a3;hp=ab2cc176385bca9a387adbb13e0553654df6bad9;hpb=da056b9eca7583803c33dcba7ebae04bf0811618;p=gpl%2Fargeo-slc.git
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
index ab2cc1763..001ead97b 100644
--- 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
@@ -3,20 +3,29 @@ 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;
@@ -34,7 +43,7 @@ public class SlcProjectHelper extends ProjectHelper2 {
/** 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 */
- private static String REF_PROJECT_PATH = "slcProjectPath";
+ 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
@@ -159,10 +168,9 @@ public class SlcProjectHelper extends ProjectHelper2 {
}
/** Gets the path of a project (root). */
- public static TreeSPath getProjectPath(Project project) {
- return (TreeSPath) project.getReference(REF_PROJECT_PATH);
- }
-
+ // 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());
@@ -176,10 +184,18 @@ public class SlcProjectHelper extends ProjectHelper2 {
'/' + 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. */
- private void addCustomTaskAndTypes(Project project) {
+ protected static void addCustomTaskAndTypes(Project project) {
Properties taskdefs = getDefs(project, SLC_TASKDEFS_RESOURCE_PATH);
for (Object o : taskdefs.keySet()) {
String name = o.toString();
@@ -202,7 +218,7 @@ public class SlcProjectHelper extends ProjectHelper2 {
}
}
- private Properties getDefs(Project project, String path) {
+ private static Properties getDefs(Project project, String path) {
Properties defs = new Properties();
try {
InputStream in = project.getClass().getResourceAsStream(path);
@@ -213,4 +229,38 @@ public class SlcProjectHelper extends ProjectHelper2 {
}
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);
+ }
+
+ }
}