Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[BZ 1203799] Add liquidbase and antcontrib to taskdef-default-path in…
Browse files Browse the repository at this point in the history
… bundle-deployer tool

(cherry picked from commit d05fc4e)
  • Loading branch information
Michael Burman committed Nov 18, 2015
1 parent 9c04981 commit 75ac45d
Showing 1 changed file with 67 additions and 1 deletion.
Expand Up @@ -32,12 +32,27 @@
import java.util.Set;
import java.util.Vector;

import org.apache.tools.ant.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.BuildLogger;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.DemuxInputStream;
import org.apache.tools.ant.DemuxOutputStream;
import org.apache.tools.ant.Diagnostics;
import org.apache.tools.ant.ExitStatusException;
import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Main;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.input.DefaultInputHandler;
import org.apache.tools.ant.input.InputHandler;
import org.apache.tools.ant.util.ClasspathUtils;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.ProxySetup;

import org.rhq.core.util.updater.DeploymentsMetadata;

/**
Expand All @@ -51,6 +66,11 @@
*/
public class AntMain implements org.apache.tools.ant.launch.AntMain {

private static final Log LOG = LogFactory.getLog(AntMain.class);

private static final String ANTCONTRIB_ANT_TASKS = "net/sf/antcontrib/antcontrib.properties";
private static final String LIQUIBASE_ANT_TASKS = "liquibasetasks.properties";

/**
* A Set of args are are handled by the launcher and should
* not be seen by Main.
Expand Down Expand Up @@ -691,6 +711,10 @@ private DeploymentPhase[] getLifecycle() {
}

private void initProject(Project project, ClassLoader coreLoader, DeploymentPhase phase) {
if(coreLoader == null) {
coreLoader = getClass().getClassLoader();
}

project.setCoreLoader(coreLoader);
project.setProperty(DeployPropertyNames.DEPLOY_PHASE, phase.name());

Expand Down Expand Up @@ -745,6 +769,14 @@ private void initProject(Project project, ClassLoader coreLoader, DeploymentPhas
project.setProperty(arg, value);
}

try {
addTaskDefsForBundledTasks(project);
} catch (IOException ie) {
throw new RuntimeException(ie);
} catch (ClassNotFoundException ce) {
throw new RuntimeException(ce);
}

project.setProperty(MagicNames.ANT_FILE,
buildFile.getAbsolutePath());
project.setProperty(MagicNames.ANT_FILE_TYPE,
Expand Down Expand Up @@ -772,6 +804,40 @@ private void initProject(Project project, ClassLoader coreLoader, DeploymentPhas
}
}

private void addTaskDefsForBundledTasks(Project project) throws IOException, ClassNotFoundException {
Properties taskDefs = buildTaskDefProperties(project.getCoreLoader());

for (Map.Entry<Object, Object> taskDef : taskDefs.entrySet()) {
project.addTaskDefinition(taskDef.getKey().toString(),
Class.forName(taskDef.getValue().toString(), true, project.getCoreLoader()));
}
}

private Properties buildTaskDefProperties(ClassLoader classLoader) throws IOException {
Set<String> customTaskDefs = new HashSet<String>(1);

customTaskDefs.add(ANTCONTRIB_ANT_TASKS);
customTaskDefs.add(LIQUIBASE_ANT_TASKS);

Properties taskDefProps = new Properties();
for (String customTaskDef : customTaskDefs) {
InputStream taskDefsStream = classLoader.getResourceAsStream(customTaskDef);
if (taskDefsStream != null) {
try {
taskDefProps.load(taskDefsStream);
} catch (Exception e) {
LOG.warn("Ant task definitions [" + customTaskDef
+ "] failed to load - ant bundles cannot use their tasks", e);
} finally {
taskDefsStream.close();
}
} else {
LOG.warn("Missing ant task definitions [" + customTaskDef + "] - ant bundles cannot use their tasks");
}
}
return taskDefProps;
}

/**
* Adds the listeners specified in the command line arguments,
* along with the default listener, to the specified project.
Expand Down

0 comments on commit 75ac45d

Please sign in to comment.