ARTEMIS-219 fixing path resolution for windows
https://issues.apache.org/jira/browse/ARTEMIS-219 The fix will basically use Path.resolve insead of URI.resolve
This commit is contained in:
parent
82f6a88d59
commit
cc88be51e4
|
@ -22,7 +22,6 @@ import java.io.File;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.net.URI;
|
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedExceptionAction;
|
import java.security.PrivilegedExceptionAction;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -1425,10 +1424,7 @@ public class ConfigurationImpl implements Configuration, Serializable {
|
||||||
*/
|
*/
|
||||||
private File subFolder(String subFolder) {
|
private File subFolder(String subFolder) {
|
||||||
try {
|
try {
|
||||||
// Resolve wont work without "/" as the last character
|
return getBrokerInstance().toPath().resolve(subFolder).toFile();
|
||||||
URI artemisHome = new URI(getBrokerInstance().toURI() + "/");
|
|
||||||
URI relative = artemisHome.resolve(subFolder);
|
|
||||||
return new File(relative.getPath());
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.artemis.core.config.impl;
|
package org.apache.activemq.artemis.core.config.impl;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
|
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
|
||||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||||
import org.apache.activemq.artemis.core.config.Configuration;
|
import org.apache.activemq.artemis.core.config.Configuration;
|
||||||
|
@ -483,6 +485,68 @@ public class ConfigurationImplTest extends ActiveMQTestBase {
|
||||||
Assert.assertTrue(conf.equals(conf2));
|
Assert.assertTrue(conf.equals(conf2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResolvePath() throws Throwable {
|
||||||
|
// Validate that the resolve method will work even with artemis.instance doesn't exist
|
||||||
|
|
||||||
|
String oldProperty = System.getProperty("artemis.instance");
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.setProperty("artemis.instance", "/tmp/" + RandomUtil.randomString());
|
||||||
|
ConfigurationImpl configuration = new ConfigurationImpl();
|
||||||
|
configuration.setJournalDirectory("./data-journal");
|
||||||
|
File journalLocation = configuration.getJournalLocation();
|
||||||
|
Assert.assertFalse("This path shouldn't resolve to a real folder", journalLocation.exists());
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (oldProperty == null) {
|
||||||
|
System.clearProperty("artemis.instance");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.setProperty("artemis.instance", oldProperty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAbsolutePath() throws Throwable {
|
||||||
|
// Validate that the resolve method will work even with artemis.instance doesn't exist
|
||||||
|
|
||||||
|
String oldProperty = System.getProperty("artemis.instance");
|
||||||
|
|
||||||
|
File tempFolder = null;
|
||||||
|
try {
|
||||||
|
System.setProperty("artemis.instance", "/tmp/" + RandomUtil.randomString());
|
||||||
|
tempFolder = File.createTempFile("journal-folder", "");
|
||||||
|
tempFolder.delete();
|
||||||
|
|
||||||
|
tempFolder = new File(tempFolder.getAbsolutePath());
|
||||||
|
tempFolder.mkdirs();
|
||||||
|
|
||||||
|
System.out.println("TempFolder = " + tempFolder.getAbsolutePath());
|
||||||
|
|
||||||
|
ConfigurationImpl configuration = new ConfigurationImpl();
|
||||||
|
configuration.setJournalDirectory(tempFolder.getAbsolutePath());
|
||||||
|
File journalLocation = configuration.getJournalLocation();
|
||||||
|
|
||||||
|
Assert.assertTrue(journalLocation.exists());
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (oldProperty == null) {
|
||||||
|
System.clearProperty("artemis.instance");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.setProperty("artemis.instance", oldProperty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tempFolder != null) {
|
||||||
|
tempFolder.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue