aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base/archiva-configuration
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2017-05-07 17:26:49 +0200
committerMartin Stockhammer <martin_s@apache.org>2017-05-10 21:39:15 +0200
commit1acc6e7b8439b482e611392700f2decaef54b6e6 (patch)
treefc98db8d5433006bb83e4389f1dfc7f6ddf8ebdf /archiva-modules/archiva-base/archiva-configuration
parent10b408249ea9d8e2d63054ba95714e3a628ca782 (diff)
downloadarchiva-1acc6e7b8439b482e611392700f2decaef54b6e6.tar.gz
archiva-1acc6e7b8439b482e611392700f2decaef54b6e6.zip
Adding check path to remote repositories
Allow to set a check path for connection checks to the remote repositories. This is useful for repositories that do not allow to browse the base directory. Improved the fix for MRM-1933
Diffstat (limited to 'archiva-modules/archiva-base/archiva-configuration')
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/pom.xml2
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java107
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo62
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/resources/org/apache/archiva/configuration/default-archiva.xml14
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java1
5 files changed, 178 insertions, 8 deletions
diff --git a/archiva-modules/archiva-base/archiva-configuration/pom.xml b/archiva-modules/archiva-base/archiva-configuration/pom.xml
index df5a1f2de..df2556af1 100644
--- a/archiva-modules/archiva-base/archiva-configuration/pom.xml
+++ b/archiva-modules/archiva-base/archiva-configuration/pom.xml
@@ -169,7 +169,7 @@
</execution>
</executions>
<configuration>
- <version>1.4.1</version>
+ <version>1.4.2</version>
<models>
<model>src/main/mdo/configuration.mdo</model>
</models>
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 f37171afa..44f25212b 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
@@ -162,6 +162,9 @@ public class DefaultArchivaConfiguration
private static final String KEY = "org.apache.archiva";
+ // Section used for default only configuration
+ private static final String KEY_DEFAULT_ONLY = "org.apache.archiva_default";
+
@Override
public Configuration getConfiguration()
{
@@ -183,6 +186,11 @@ public class DefaultArchivaConfiguration
return configuration;
}
+ private boolean hasConfigVersionChanged(Configuration current, Registry defaultOnlyConfiguration) {
+ return current==null || current.getVersion()==null ||
+ !current.getVersion().trim().equals(defaultOnlyConfiguration.getString("version","").trim());
+ }
+
@SuppressWarnings("unchecked")
private Configuration load()
{
@@ -200,6 +208,7 @@ public class DefaultArchivaConfiguration
Configuration config = new ConfigurationRegistryReader().read( subset );
+
config.getRepositoryGroups();
config.getRepositoryGroupsAsMap();
if ( !config.getRepositories().isEmpty() )
@@ -363,9 +372,63 @@ public class DefaultArchivaConfiguration
}
}
+
+
return config;
}
+ /*
+ * Updates the checkpath list for repositories.
+ *
+ * We are replacing existing ones and adding new ones. This allows to update the list with new releases.
+ *
+ * We are also updating existing remote repositories, if they exist already.
+ *
+ * This update method should only be called, if the config version changes to avoid overwriting
+ * user repository settings all the time.
+ */
+ private void updateCheckPathDefaults(Configuration config, Registry defaultConfiguration) {
+ List<RepositoryCheckPath> existingCheckPathList = config.getArchivaDefaultConfiguration().getDefaultCheckPaths();
+ HashMap<String, RepositoryCheckPath> existingCheckPaths = new HashMap<>();
+ HashMap<String, RepositoryCheckPath> newCheckPaths = new HashMap<>();
+ for (RepositoryCheckPath path : config.getArchivaDefaultConfiguration().getDefaultCheckPaths()) {
+ existingCheckPaths.put(path.getUrl(), path);
+ }
+ List defaultCheckPathsSubsets = defaultConfiguration.getSubsetList("archivaDefaultConfiguration.defaultCheckPaths.defaultCheckPath" );
+ for ( Iterator i = defaultCheckPathsSubsets.iterator(); i.hasNext(); )
+ {
+ RepositoryCheckPath v = readRepositoryCheckPath( (Registry) i.next() );
+ if (existingCheckPaths.containsKey(v.getUrl())) {
+ existingCheckPathList.remove(existingCheckPaths.get(v.getUrl()));
+ }
+ existingCheckPathList.add(v);
+ newCheckPaths.put(v.getUrl(), v);
+ }
+ // Remote repositories update
+ for (RemoteRepositoryConfiguration remoteRepositoryConfiguration : config.getRemoteRepositories()) {
+ String url = remoteRepositoryConfiguration.getUrl().toLowerCase();
+ if (newCheckPaths.containsKey(url)) {
+ String currentPath = remoteRepositoryConfiguration.getCheckPath();
+ String newPath = newCheckPaths.get(url).getPath();
+ log.info("Updating connection check path for repository {}, from '{}' to '{}'.", remoteRepositoryConfiguration.getId(),
+ currentPath, newPath);
+ remoteRepositoryConfiguration.setCheckPath(newPath);
+ }
+ }
+ }
+
+ private RepositoryCheckPath readRepositoryCheckPath( Registry registry )
+ {
+ RepositoryCheckPath value = new RepositoryCheckPath();
+
+ String url = registry.getString( "url", value.getUrl() );
+
+ value.setUrl( url );
+ String path = registry.getString( "path", value.getPath() );
+ value.setPath( path );
+ return value;
+ }
+
private Policy findPolicy( String policyId )
{
if ( MapUtils.isEmpty( prePolicies ) )
@@ -439,6 +502,25 @@ public class DefaultArchivaConfiguration
return registry.getSubset( KEY );
}
+ /*
+ * Reads the default only configuration into a special prefix. This allows to check for changes
+ * of the default configuration.
+ */
+ private Registry readDefaultOnlyConfiguration()
+ {
+ registry.removeSubset(KEY_DEFAULT_ONLY);
+ try
+ {
+ registry.addConfigurationFromResource( "org/apache/archiva/configuration/default-archiva.xml", KEY_DEFAULT_ONLY);
+ }
+ catch ( RegistryException e )
+ {
+ throw new ConfigurationRuntimeException(
+ "Fatal error: Unable to find the built-in default configuration and load it into the registry", e );
+ }
+ return registry.getSubset(KEY_DEFAULT_ONLY);
+ }
+
@SuppressWarnings("unchecked")
@Override
public synchronized void save( Configuration configuration )
@@ -527,6 +609,9 @@ public class DefaultArchivaConfiguration
section.removeSubset( "repositoryScanning.invalidContentConsumers" );
}
}
+ if (configuration.getArchivaRuntimeConfiguration()!=null) {
+ section.removeSubset("archivaRuntimeConfiguration.defaultCheckPaths");
+ }
new ConfigurationRegistryWriter().write( configuration, section );
section.save();
@@ -736,7 +821,7 @@ public class DefaultArchivaConfiguration
}
/**
- * upgrade from 1.3
+ * Handle upgrade to newer version
*/
private void handleUpgradeConfiguration()
throws RegistryException, IndeterminateConfigurationException
@@ -781,8 +866,24 @@ public class DefaultArchivaConfiguration
knowContentConsumers.add( "duplicate-artifacts" );
configuration.getRepositoryScanning().setKnownContentConsumers( knowContentConsumers );
}
- // save ??
- //save( configuration );
+
+ Registry defaultOnlyConfiguration = readDefaultOnlyConfiguration();
+ // Currently we check only for configuration version change, not certain version numbers.
+ if (hasConfigVersionChanged(configuration, defaultOnlyConfiguration)) {
+ updateCheckPathDefaults(configuration, defaultOnlyConfiguration);
+ String newVersion = defaultOnlyConfiguration.getString("version");
+ if (newVersion==null) {
+ throw new IndeterminateConfigurationException("The default configuration has no version information!");
+ }
+ configuration.setVersion(newVersion);
+ try {
+ save(configuration);
+ } catch (IndeterminateConfigurationException e) {
+ log.error("Error occured during configuration update to new version: {}", e.getMessage());
+ } catch (RegistryException e) {
+ log.error("Error occured during configuration update to new version: {}", e.getMessage());
+ }
+ }
}
@Override
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
index fc5169ff2..494af1204 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
+++ b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
@@ -197,6 +197,15 @@
The list of ProxyConnectorRuleConfigurations.
</description>
</field>
+ <field>
+ <name>archivaDefaultConfiguration</name>
+ <version>1.4.2+</version>
+ <association>
+ <type>ArchivaDefaultConfiguration</type>
+ <multiplicity>1</multiplicity>
+ </association>
+ <description>Archiva default settings.</description>
+ </field>
</fields>
<codeSegments>
<codeSegment>
@@ -597,12 +606,18 @@
<name>extraHeaders</name>
<version>1.4.0+</version>
<type>Map</type>
- <description>Additionnal http headers to add to url when requesting remote repositories.</description>
+ <description>Additional http headers to add to url when requesting remote repositories.</description>
<association xml.mapStyle="inline">
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>
+ <field>
+ <name>checkPath</name>
+ <version>1.4.2+</version>
+ <type>String</type>
+ <description>The path to check the repository availability (relative to the repository URL). Some repositories do not allow browsing, so a certain artifact must be checked.</description>
+ </field>
</fields>
<codeSegments>
<codeSegment>
@@ -877,6 +892,30 @@
</field>
</fields>
</class>
+ <class>
+ <name>RepositoryCheckPath</name>
+ <version>1.4.2+</version>
+ <fields >
+ <field >
+ <name>url</name>
+ <version>1.4.2+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The URL for which this path should be used
+ </description>
+ </field>
+ <field>
+ <name>path</name>
+ <version>1.4.2+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The path to use for checking the repository connection.
+ </description>
+ </field>
+ </fields>
+ </class>
<!--
____ _
@@ -1584,6 +1623,25 @@
</class>
<class>
+ <name>ArchivaDefaultConfiguration</name>
+ <version>1.4.2+</version>
+ <description>
+ Archiva default settings.
+ </description>
+ <fields>
+ <field>
+ <name>defaultCheckPaths</name>
+ <description>The default check paths for certain remote repositories</description>
+ <version>1.4.2+</version>
+ <association>
+ <type>RepositoryCheckPath</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ </fields>
+ </class>
+
+ <class>
<name>LdapConfiguration</name>
<version>1.4.0+</version>
<description>
@@ -1670,7 +1728,7 @@
<name>extraProperties</name>
<version>1.4.0+</version>
<type>Map</type>
- <description>Additionnal properties to use for ldap connection.</description>
+ <description>Additional properties to use for ldap connection.</description>
<association xml.mapStyle="inline">
<type>String</type>
<multiplicity>*</multiplicity>
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/resources/org/apache/archiva/configuration/default-archiva.xml b/archiva-modules/archiva-base/archiva-configuration/src/main/resources/org/apache/archiva/configuration/default-archiva.xml
index a74f09ceb..877b6a59b 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/main/resources/org/apache/archiva/configuration/default-archiva.xml
+++ b/archiva-modules/archiva-base/archiva-configuration/src/main/resources/org/apache/archiva/configuration/default-archiva.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
- <version>2</version>
+ <version>3</version>
<managedRepositories>
<managedRepository>
<id>internal</id>
@@ -151,5 +151,17 @@
</rbacManagerImpls>
</redbackRuntimeConfiguration>
+ <archivaDefaultConfiguration>
+ <defaultCheckPaths>
+ <defaultCheckPath>
+ <url>http://download.oracle.com/maven</url>
+ <path>com/sleepycat/je/license.txt</path>
+ </defaultCheckPath>
+ <defaultCheckPath>
+ <url>https://download.oracle.com/maven</url>
+ <path>com/sleepycat/je/license.txt</path>
+ </defaultCheckPath>
+ </defaultCheckPaths>
+ </archivaDefaultConfiguration>
</configuration>
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 03bb489b2..15080d873 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
@@ -814,7 +814,6 @@ public class ArchivaConfigurationTest
{
ArchivaConfiguration archivaConfiguration = lookup( ArchivaConfiguration.class, "test-configuration" );
- archivaConfiguration.reload();
Configuration configuration = archivaConfiguration.getConfiguration();
assertConfiguration( configuration, 2, 2, 2 );
assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );