|
|
@@ -22,43 +22,38 @@ import java.io.File; |
|
|
|
import java.io.FileReader; |
|
|
|
import java.io.FileWriter; |
|
|
|
import org.apache.tools.ant.util.FileUtils; |
|
|
|
import org.junit.Rule; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.rules.TemporaryFolder; |
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.containsString; |
|
|
|
import static org.junit.Assert.assertThat; |
|
|
|
|
|
|
|
public class PropertyFileCLITest { |
|
|
|
@Rule |
|
|
|
public TemporaryFolder testFolder = new TemporaryFolder(); |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testPropertyResolution() throws Exception { |
|
|
|
FileUtils fu = FileUtils.getFileUtils(); |
|
|
|
File props = fu.createTempFile("propertyfilecli", ".properties", |
|
|
|
null, true, true); |
|
|
|
File build = fu.createTempFile("propertyfilecli", ".xml", null, true, |
|
|
|
true); |
|
|
|
File log = fu.createTempFile("propertyfilecli", ".log", null, true, |
|
|
|
true); |
|
|
|
FileWriter fw = null; |
|
|
|
FileReader fr = null; |
|
|
|
try { |
|
|
|
fw = new FileWriter(props); |
|
|
|
File props = testFolder.newFile("propertyfilecli.properties"); |
|
|
|
try (FileWriter fw = new FileWriter(props)) { |
|
|
|
fw.write("w=world\nmessage=Hello, ${w}\n"); |
|
|
|
fw.close(); |
|
|
|
fw = new FileWriter(build); |
|
|
|
} |
|
|
|
|
|
|
|
File build = testFolder.newFile("propertyfilecli.xml"); |
|
|
|
try (FileWriter fw = new FileWriter(build)) { |
|
|
|
fw.write("<project><echo>${message}</echo></project>"); |
|
|
|
fw.close(); |
|
|
|
fw = null; |
|
|
|
Main m = new NoExitMain(); |
|
|
|
m.startAnt(new String[] { |
|
|
|
"-propertyfile", props.getAbsolutePath(), |
|
|
|
"-f", build.getAbsolutePath(), |
|
|
|
"-l", log.getAbsolutePath() |
|
|
|
}, null, null); |
|
|
|
String l = FileUtils.safeReadFully(fr = new FileReader(log)); |
|
|
|
assertThat(l, containsString("Hello, world")); |
|
|
|
} finally { |
|
|
|
FileUtils.close(fw); |
|
|
|
FileUtils.close(fr); |
|
|
|
} |
|
|
|
|
|
|
|
Main m = new NoExitMain(); |
|
|
|
File log = testFolder.newFile("propertyfilecli.log"); |
|
|
|
m.startAnt(new String[] { |
|
|
|
"-propertyfile", props.getAbsolutePath(), |
|
|
|
"-f", build.getAbsolutePath(), |
|
|
|
"-l", log.getAbsolutePath() |
|
|
|
}, null, null); |
|
|
|
try (FileReader fr = new FileReader(log)) { |
|
|
|
assertThat(FileUtils.safeReadFully(fr), containsString("Hello, world")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|