Adding environment variable for user config file

This commit is contained in:
Martin Stockhammer 2018-10-25 22:04:55 +02:00
parent e45634e2c9
commit c069d160f9
3 changed files with 41 additions and 11 deletions

23
Jenkinsfile vendored
View File

@ -33,6 +33,7 @@ buildJdk9 = 'JDK 1.9 (latest)'
buildJdk10 = 'JDK 10 (latest)'
buildMvn = 'Maven 3.5.2'
deploySettings = 'archiva-uid-jenkins'
INTEGRATION_PIPELINE = "Archiva-IntegrationTests-Gitbox"
pipeline {
@ -40,9 +41,14 @@ pipeline {
label "${LABEL}"
}
stages {
stage('BuildAndDeploy') {
environment {
ARCHIVA_USER_CONFIG_FILE='/tmp/archiva-master-jdk-8-${env.JOB_NAME}.xml'
}
steps {
timeout(120) {
withMaven(maven: buildMvn, jdk: buildJdk,
@ -75,6 +81,7 @@ pipeline {
}
post {
always {
sh "rm -f /tmp/archiva-master-jdk-8-${env.JOB_NAME}.xml"
junit testResults: '**/target/surefire-reports/TEST-*.xml'
}
success {
@ -95,6 +102,9 @@ pipeline {
stage('JDKs') {
parallel {
stage('JDK9') {
environment {
ARCHIVA_USER_CONFIG_FILE='/tmp/archiva-master-jdk-9-${env.JOB_NAME}.xml'
}
steps {
ws("${env.JOB_NAME}-JDK9") {
checkout scm
@ -114,8 +124,16 @@ pipeline {
}
}
}
post {
always {
sh "rm -f /tmp/archiva-master-jdk-9-${env.JOB_NAME}.xml"
}
}
}
stage('JDK10') {
environment {
ARCHIVA_USER_CONFIG_FILE='/tmp/archiva-master-jdk-10-${env.JOB_NAME}.xml'
}
steps {
ws("${env.JOB_NAME}-JDK10") {
checkout scm
@ -135,6 +153,11 @@ pipeline {
}
}
}
post {
always {
sh "rm -f /tmp/archiva-master-jdk-10-${env.JOB_NAME}.xml"
}
}
}
}
}

View File

@ -22,6 +22,7 @@ package org.apache.archiva.configuration;
import org.apache.archiva.redback.components.registry.RegistryException;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@ -326,10 +327,20 @@ public class ArchivaConfigurationTest
{
DefaultArchivaConfiguration archivaConfiguration =
(DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class, "default" );
String expectedFile = System.getProperty( "user.home" ) + "/.m2/archiva.xml";
String systemFile = System.getProperty(ArchivaConfiguration.USER_CONFIG_PROPERTY);
if (StringUtils.isNotEmpty( systemFile )) {
expectedFile = systemFile;
} else
{
String envFile = System.getenv( ArchivaConfiguration.USER_CONFIG_ENVVAR );
if ( StringUtils.isNotEmpty( envFile ) )
expectedFile = envFile;
}
archivaConfiguration.reload();
assertEquals( System.getProperty( "user.home" ) + "/.m2/archiva.xml",
assertEquals( expectedFile,
archivaConfiguration.getUserConfigFilename() );
assertEquals( System.getProperty( "appserver.base", "${appserver.base}" ) + "/conf/archiva.xml",
archivaConfiguration.getAltConfigFilename() );
@ -496,6 +507,8 @@ public class ArchivaConfigurationTest
public void testLoadConfigurationFromInvalidBothLocationsOnDisk()
throws Exception
{
String propFile = System.getProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY );
System.setProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY, "${basedir}/target/*intentionally:invalid*/.m2/archiva-user.xml" );
ArchivaConfiguration archivaConfiguration =
lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
Configuration config = archivaConfiguration.getConfiguration();
@ -509,6 +522,10 @@ public class ArchivaConfigurationTest
{
/* expected exception */
}
if (propFile!=null)
{
System.setProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY, propFile );
}
}
@Test

View File

@ -77,16 +77,6 @@
<configuration>
<system/>
<jndi prefix="java:comp/env" config-optional="true"/>
<xml fileName="${user.home}/.m2/archiva.xml" config-optional="true"
config-name="org.apache.archiva.user"
config-at="org.apache.archiva"/>
<xml fileName="${user.home}/.m2/shared.xml" config-optional="true"
config-name="org.apache.maven.shared.app.user" config-at="org.apache.maven.shared.app"
config-forceCreate="true"/>
<properties fileName="${user.home}/.m2/security.properties" config-optional="true"
config-at="org.apache.archiva.redback"/>
<properties fileName="${user.home}/.m2/archiva.properties" config-optional="true"
config-at="org.apache.archiva.redback"/>
<xml fileName="${appserver.base}/conf/archiva.xml" config-optional="true"
config-name="org.apache.archiva.base"
config-at="org.apache.archiva"/>