You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2015/09/08 16:33:42 UTC
[2/3] activemq-artemis git commit: ARTEMIS-219 fixing path resolution
for windows
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
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/cc88be51
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/cc88be51
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/cc88be51
Branch: refs/heads/master
Commit: cc88be51e4504b58f57c3263bf775de6bf0cdf9e
Parents: 82f6a88
Author: Clebert Suconic <cl...@apache.org>
Authored: Tue Sep 8 09:25:09 2015 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Tue Sep 8 10:29:29 2015 -0400
----------------------------------------------------------------------
.../core/config/impl/ConfigurationImpl.java | 6 +-
.../core/config/impl/ConfigurationImplTest.java | 64 ++++++++++++++++++++
2 files changed, 65 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/cc88be51/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
index 75fbe59..8b21f8a 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
@@ -22,7 +22,6 @@ import java.io.File;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
-import java.net.URI;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
@@ -1425,10 +1424,7 @@ public class ConfigurationImpl implements Configuration, Serializable {
*/
private File subFolder(String subFolder) {
try {
- // Resolve wont work without "/" as the last character
- URI artemisHome = new URI(getBrokerInstance().toURI() + "/");
- URI relative = artemisHome.resolve(subFolder);
- return new File(relative.getPath());
+ return getBrokerInstance().toPath().resolve(subFolder).toFile();
}
catch (Exception e) {
throw new RuntimeException(e);
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/cc88be51/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
index 1fdcdbd..447d51b 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
@@ -16,6 +16,8 @@
*/
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.core.SimpleString;
import org.apache.activemq.artemis.core.config.Configuration;
@@ -483,6 +485,68 @@ public class ConfigurationImplTest extends ActiveMQTestBase {
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
@Before
public void setUp() throws Exception {