modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/type/FileType.java | 17
++++++----
modules/common/ant-bundle/src/test/java/org/rhq/bundle/ant/AntLauncherTest.java | 5
++
modules/common/ant-bundle/src/test/resources/test-bundle-subdir.xml | 1
3 files changed, 16 insertions(+), 7 deletions(-)
New commits:
commit 45656ceb9d368f0549e02aef560e476c2491d276
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Dec 23 11:24:39 2010 -0500
support a default location for <file>s so you don't have to specify a
destination if its the same as its name
diff --git a/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/type/FileType.java
b/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/type/FileType.java
index 2e55c0e..b968ced 100644
--- a/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/type/FileType.java
+++ b/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/type/FileType.java
@@ -22,10 +22,10 @@
*/
package org.rhq.bundle.ant.type;
-import org.apache.tools.ant.BuildException;
-
import java.io.File;
+import org.apache.tools.ant.BuildException;
+
/**
* A file to be copied during the bundle deployment. If the replace attribute is set to
true, any template variables
* (e.g. @@http.port(a)@) inside the file will be replaced with the value of the
corresponding property.
@@ -43,19 +43,24 @@ public class FileType extends AbstractFileType {
// Pass in a String, rather than a File, since we don't want Ant to resolve the
path relative to basedir if it's relative.
public void setDestinationDir(String destinationDir) {
- if (getDestinationFile() != null) {
- throw new BuildException("Both 'destinationDir' and
'destinationFile' attributes are defined - only one or the other may be
specified.");
+ if (this.destinationFile != null) {
+ throw new BuildException(
+ "Both 'destinationDir' and 'destinationFile'
attributes are defined - only one or the other may be specified.");
}
this.destinationDir = new File(destinationDir);
}
public File getDestinationFile() {
+ if (this.destinationDir == null && this.destinationFile == null) {
+ return new File(getName()); // the default destination is the same relative
path as that of its local name
+ }
return this.destinationFile;
}
public void setDestinationFile(String destinationFile) {
- if (getDestinationDir() != null) {
- throw new BuildException("Both 'destinationDir' and
'destinationFile' attributes are defined - only one or the other may be
specified.");
+ if (this.destinationDir != null) {
+ throw new BuildException(
+ "Both 'destinationDir' and 'destinationFile'
attributes are defined - only one or the other may be specified.");
}
this.destinationFile = new File(destinationFile);
}
diff --git
a/modules/common/ant-bundle/src/test/java/org/rhq/bundle/ant/AntLauncherTest.java
b/modules/common/ant-bundle/src/test/java/org/rhq/bundle/ant/AntLauncherTest.java
index 956ea93..4eb4369 100644
--- a/modules/common/ant-bundle/src/test/java/org/rhq/bundle/ant/AntLauncherTest.java
+++ b/modules/common/ant-bundle/src/test/java/org/rhq/bundle/ant/AntLauncherTest.java
@@ -486,6 +486,7 @@ public class AntLauncherTest {
try {
File subdir = new File(antBasedir, "subdir"); // must match the
name in the recipe
subdir.mkdirs();
+ writeFile("file0", subdir, "test0.txt"); // filename must
match recipe
writeFile("file1", subdir, "test1.txt"); // filename must
match recipe
writeFile("file2", subdir, "test2.txt"); // filename must
match recipe
createZip(new String[] { "one", "two" }, subdir,
"test.zip", new String[] { "one.txt", "two.txt" });
@@ -506,13 +507,15 @@ public class AntLauncherTest {
assert project != null;
Set<String> bundleFiles = project.getBundleFileNames();
assert bundleFiles != null;
- assert bundleFiles.size() == 5 : bundleFiles;
+ assert bundleFiles.size() == 6 : bundleFiles;
+ assert bundleFiles.contains("subdir/test0.txt") : bundleFiles;
assert bundleFiles.contains("subdir/test1.txt") : bundleFiles;
assert bundleFiles.contains("subdir/test2.txt") : bundleFiles;
assert bundleFiles.contains("subdir/test.zip") : bundleFiles;
assert bundleFiles.contains("subdir/test-explode.zip") :
bundleFiles;
assert bundleFiles.contains("subdir/test-replace.zip") :
bundleFiles;
+ assert new File(DEPLOY_DIR, "subdir/test0.txt").exists() :
"missing raw file from default destination location";
assert new File(DEPLOY_DIR, "another/foo.txt").exists() :
"missing raw file from the destinationFile";
assert new File(DEPLOY_DIR, "second.dir/test2.txt").exists() :
"missing raw file from the destinationDir";
assert !new File(DEPLOY_DIR, "subdir/test1.zip").exists() :
"should not be here because destinationFile was specified";
diff --git a/modules/common/ant-bundle/src/test/resources/test-bundle-subdir.xml
b/modules/common/ant-bundle/src/test/resources/test-bundle-subdir.xml
index 940ecf1..af3dbd2 100644
--- a/modules/common/ant-bundle/src/test/resources/test-bundle-subdir.xml
+++ b/modules/common/ant-bundle/src/test/resources/test-bundle-subdir.xml
@@ -7,6 +7,7 @@
<rhq:input-property name="X" />
<rhq:deployment-unit name="appserver">
+ <rhq:file name="subdir/test0.txt" replace="false"
/>
<rhq:file name="subdir/test1.txt"
destinationFile="another/foo.txt" replace="false"/>
<rhq:file name="subdir/test2.txt"
destinationDir="second.dir" replace="false"/>
<rhq:archive name="subdir/test.zip" exploded="false"
/>
Show replies by date