aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base/archiva-configuration
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2019-06-30 22:47:24 +0200
committerMartin Stockhammer <martin_s@apache.org>2019-06-30 22:47:24 +0200
commit9ca52f4e279159bfd5623585d2a84c2cde0e3421 (patch)
tree2c697e37539365913fd9a2b949d7f04e9bf8f823 /archiva-modules/archiva-base/archiva-configuration
parent23099bcb581738f3c9cb13745ae2837eafd77ec6 (diff)
downloadarchiva-9ca52f4e279159bfd5623585d2a84c2cde0e3421.tar.gz
archiva-9ca52f4e279159bfd5623585d2a84c2cde0e3421.zip
Fixing tests after refactoring
Diffstat (limited to 'archiva-modules/archiva-base/archiva-configuration')
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java16
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/RepositoryGroupConfiguration.java3
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java3
-rwxr-xr-xarchiva-modules/archiva-base/archiva-configuration/src/test/resources/spring-context.xml8
4 files changed, 19 insertions, 11 deletions
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java
index 13e8a2898..8b633c7ca 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java
@@ -606,7 +606,7 @@ public class DefaultArchivaConfiguration
if (!writeFile("user configuration", userConfigFilename, contents)) {
fileLocation = altConfigFilename;
- if (!writeFile("alternative configuration", altConfigFilename, contents)) {
+ if (!writeFile("alternative configuration", altConfigFilename, contents, true)) {
throw new RegistryException(
"Unable to create configuration file in either user [" + userConfigFilename + "] or alternative ["
+ altConfigFilename
@@ -632,6 +632,10 @@ public class DefaultArchivaConfiguration
return section == null ? new CommonsConfigurationRegistry(new BaseConfiguration()) : section;
}
+ private boolean writeFile(String filetype, String path, String contents) {
+ return writeFile( filetype, path, contents, false );
+ }
+
/**
* Attempts to write the contents to a file, if an IOException occurs, return false.
* <p/>
@@ -642,14 +646,18 @@ public class DefaultArchivaConfiguration
* @param contents the contents to write.
* @return true if write successful.
*/
- private boolean writeFile(String filetype, String path, String contents) {
+ private boolean writeFile(String filetype, String path, String contents, boolean createDirs) {
Path file = Paths.get(path);
try {
// Check parent directory (if it is declared)
- if (file.getParent() != null) {
+ final Path parent = file.getParent();
+ if (parent != null) {
// Check that directory exists
- if (!Files.isDirectory(file.getParent())) {
+ if (!Files.exists( parent ) && createDirs) {
+ Files.createDirectories( parent );
+ }
+ if (!Files.isDirectory(parent)) {
// Directory to file must exist for file to be created
return false;
}
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/RepositoryGroupConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/RepositoryGroupConfiguration.java
index db3498be3..cf518951c 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/RepositoryGroupConfiguration.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/RepositoryGroupConfiguration.java
@@ -69,8 +69,7 @@ public class RepositoryGroupConfiguration
/**
*
* When to run the index merging for this group.
- * No default value.
- *
+ *
*/
private String cronExpression = "";
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java
index cd1635d6b..288986aaa 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java
@@ -34,6 +34,7 @@ import org.springframework.test.context.ContextConfiguration;
import javax.inject.Inject;
import java.nio.charset.Charset;
+import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -508,7 +509,7 @@ public class ArchivaConfigurationTest
throws Exception
{
String propFile = System.getProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY );
- System.setProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY, "${basedir}/target/*intentionally:invalid*/.m2/archiva-user.xml" );
+ System.setProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY, "/../../..//*intentionally:invalid*/.m2/archiva-user.xml" );
ArchivaConfiguration archivaConfiguration =
lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
Configuration config = archivaConfiguration.getConfiguration();
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-configuration/src/test/resources/spring-context.xml
index fd941ccda..f0bd4e10d 100755
--- a/archiva-modules/archiva-base/archiva-configuration/src/test/resources/spring-context.xml
+++ b/archiva-modules/archiva-base/archiva-configuration/src/test/resources/spring-context.xml
@@ -283,8 +283,8 @@
<bean name="archivaConfiguration#test-not-allowed-to-write-to-both" class="org.apache.archiva.configuration.DefaultArchivaConfiguration">
<property name="registry" ref="registry#test-not-allowed-to-write-to-both"/>
- <property name="userConfigFilename" value="${basedir}/target/*intentionally:invalid*/.m2/archiva-user.xml"/>
- <property name="altConfigFilename" value="${basedir}/target/*intentionally:invalid*/conf/archiva.xml"/>
+ <property name="userConfigFilename" value="/../../..//target/*intentionally:invalid*/.m2/archiva-user.xml"/>
+ <property name="altConfigFilename" value="/../../..//target/*intentionally:invalid*/conf/archiva.xml"/>
</bean>
<bean name="registry#test-not-allowed-to-write-to-both" class="org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry">
@@ -292,9 +292,9 @@
<value>
<![CDATA[
<configuration>
- <xml fileName="${basedir}/target/*intentionally:invalid*/.m2/archiva-user.xml" config-optional="true"
+ <xml fileName="/../../..//*intentionally:invalid*/.m2/archiva-user.xml" config-optional="true"
config-name="org.apache.archiva.user" config-at="org.apache.archiva"/>
- <xml fileName="${basedir}/target/*intentionally:invalid*/conf/archiva.xml" config-optional="true"
+ <xml fileName="/../../..//*intentionally:invalid*/conf/archiva.xml" config-optional="true"
config-name="org.apache.archiva.user" config-at="org.apache.archiva"/>
</configuration>
]]>