aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Stockhammer <martin.stockhammer@ars.de>2017-11-16 19:54:13 +0100
committerMartin Stockhammer <martin.stockhammer@ars.de>2017-11-16 20:01:32 +0100
commit2fe8227634acfeaf7837e953e0f8fd2a44dae3a5 (patch)
tree57d58c89ffb939707027092a97e9b06a19df0758
parent7236f4d8a93b4db42694cfa919473ec288546dc7 (diff)
downloadarchiva-2fe8227634acfeaf7837e953e0f8fd2a44dae3a5.tar.gz
archiva-2fe8227634acfeaf7837e953e0f8fd2a44dae3a5.zip
Resolving base paths in archiva configuration
Adding methods for retrieving base path information to ArchivaConfiguration resolving paths according to the configuration entries.
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java12
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java62
2 files changed, 68 insertions, 6 deletions
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java
index acda2b710..e656b7e9d 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java
@@ -95,5 +95,17 @@ public interface ArchivaConfiguration
public List<Locale.LanguageRange> getLanguagePriorities();
public Path getAppServerBaseDir();
+
+ /**
+ * Returns the base directory for repositories that have a relative location path set.
+ * @return
+ */
+ public Path getRepositoryBaseDir();
+
+ /**
+ * Returns the data directory where repositories and metadata reside
+ * @return
+ */
+ public Path getDataDirectory();
}
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 0222a426a..b28bed201 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
@@ -174,11 +174,16 @@ public class DefaultArchivaConfiguration
private List<Locale.LanguageRange> languagePriorities = new ArrayList<>( );
+ private volatile Path dataDirectory;
+ private volatile Path repositoryBaseDirectory;
+
@PostConstruct
private void init() {
languagePriorities = Locale.LanguageRange.parse( "en,fr,de" );
}
+
+
@Override
public Configuration getConfiguration()
{
@@ -223,15 +228,41 @@ public class DefaultArchivaConfiguration
}
Configuration config = new ConfigurationRegistryReader().read( subset );
- if (StringUtils.isEmpty( config.getArchivaRuntimeConfiguration().getDataDirectory() )) {
- Path appserverBaseDir = Paths.get(registry.getString("appserver.base", ""));
- config.getArchivaRuntimeConfiguration().setDataDirectory( appserverBaseDir.normalize().toString() );
+
+ // Resolving data and repositories directories
+ // If the config entries are absolute, the path is used as it is
+ // if the config entries are empty, they are resolved:
+ // dataDirectory = ${appserver.base}/data
+ // repositoryDirectory = ${dataDirectory}/repositories
+ // If the entries are relative they are resolved
+ // relative to the appserver.base, for dataDirectory
+ // relative to dataDirectory for repositoryBase
+ String dataDir = config.getArchivaRuntimeConfiguration().getDataDirectory();
+ if (StringUtils.isEmpty( dataDir )) {
+ dataDirectory = getAppServerBaseDir().resolve( "data");
+ } else {
+ Path tmpDataDir = Paths.get(dataDir);
+ if (tmpDataDir.isAbsolute()) {
+ dataDirectory = tmpDataDir;
+ } else {
+ dataDirectory = getAppServerBaseDir().resolve(tmpDataDir);
+ }
}
- if (StringUtils.isEmpty( config.getArchivaRuntimeConfiguration().getRepositoryBaseDirectory())) {
- Path baseDir = Paths.get(config.getArchivaRuntimeConfiguration().getDataDirectory());
- config.getArchivaRuntimeConfiguration().setRepositoryBaseDirectory( baseDir.resolve("repositories").toString() );
+ config.getArchivaRuntimeConfiguration().setDataDirectory( dataDirectory.normalize().toString() );
+ String repoBaseDir = config.getArchivaRuntimeConfiguration().getRepositoryBaseDirectory();
+ if (StringUtils.isEmpty( repoBaseDir )) {
+ repositoryBaseDirectory = dataDirectory.resolve("repositories");
+
+ } else {
+ Path tmpRepoBaseDir = Paths.get(repoBaseDir);
+ if (tmpRepoBaseDir.isAbsolute()) {
+ repositoryBaseDirectory = tmpRepoBaseDir;
+ } else {
+ dataDirectory.resolve(tmpRepoBaseDir);
+ }
}
+
config.getRepositoryGroups();
config.getRepositoryGroupsAsMap();
if ( !CollectionUtils.isEmpty( config.getRemoteRepositories() ) )
@@ -902,6 +933,23 @@ public class DefaultArchivaConfiguration
}
@Override
+ public Path getRepositoryBaseDir() {
+ if (repositoryBaseDirectory==null) {
+ getConfiguration();
+ }
+ return repositoryBaseDirectory;
+
+ }
+
+ @Override
+ public Path getDataDirectory() {
+ if (dataDirectory==null) {
+ getConfiguration();
+ }
+ return dataDirectory;
+ }
+
+ @Override
public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
{
// nothing to do here
@@ -911,6 +959,8 @@ public class DefaultArchivaConfiguration
public synchronized void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
{
configuration = null;
+ this.dataDirectory=null;
+ this.repositoryBaseDirectory=null;
}
private String removeExpressions( String directory )