aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--archiva-base/archiva-configuration/pom.xml9
-rw-r--r--archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationUpgrade.java150
-rw-r--r--archiva-base/archiva-configuration/src/main/mdo/configuration.mdo9
-rw-r--r--archiva-base/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml1
-rw-r--r--archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaConfigurationAdaptor.java19
-rw-r--r--archiva-scheduled/pom.xml14
-rw-r--r--archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/ArchivaTaskQueue.java42
-rw-r--r--archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java2
-rw-r--r--archiva-scheduled/src/main/resources/META-INF/plexus/components.xml36
-rw-r--r--archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/check/RoleExistanceEnvironmentCheck.java2
-rw-r--r--archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ArchivaVersion.java98
-rw-r--r--archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/Banner.java225
-rw-r--r--archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ConfigurationSynchronization.java121
-rw-r--r--archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml19
-rw-r--r--archiva-web/archiva-webapp/src/main/resources/log4j.xml2
-rw-r--r--archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/startup/BannerTest.java90
-rwxr-xr-xarchiva-web/archiva-webapp/src/test/resources/banner.gzbin0 -> 282 bytes
17 files changed, 783 insertions, 56 deletions
diff --git a/archiva-base/archiva-configuration/pom.xml b/archiva-base/archiva-configuration/pom.xml
index 4b0d815c2..4fd8e9441 100644
--- a/archiva-base/archiva-configuration/pom.xml
+++ b/archiva-base/archiva-configuration/pom.xml
@@ -35,6 +35,11 @@
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-xml-tools</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-policies</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
@@ -44,6 +49,10 @@
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationUpgrade.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationUpgrade.java
new file mode 100644
index 000000000..6b37e7955
--- /dev/null
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ConfigurationUpgrade.java
@@ -0,0 +1,150 @@
+package org.apache.maven.archiva.configuration;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.NumberUtils;
+import org.apache.maven.archiva.xml.XMLException;
+import org.apache.maven.archiva.xml.XMLReader;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * A component that is first in the plexus startup that ensure that the configuration
+ * file format has been upgraded properly.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.configuration.ConfigurationUpgrade"
+ * role-hint="default"
+ */
+public class ConfigurationUpgrade
+ extends AbstractLogEnabled
+ implements Initializable
+{
+ public static final int CURRENT_CONFIG_VERSION = 1;
+
+ /* NOTE: This component should *NOT USE* the configuration api to do it's upgrade */
+
+ public void initialize()
+ throws InitializationException
+ {
+ File userConfigFile = new File( System.getProperty( "user.home" ), ".m2/archiva.xml" );
+
+ if ( !userConfigFile.exists() )
+ {
+ writeDefaultConfigFile( userConfigFile );
+ return;
+ }
+
+ boolean configOk = false;
+ try
+ {
+ XMLReader xml = new XMLReader( "configuration", userConfigFile );
+ String configVersion = xml.getElementText( "//configuration/version" );
+ if ( StringUtils.isNotBlank( configVersion ) )
+ {
+ configOk = true;
+
+ // Found an embedded configuration version.
+ int version = NumberUtils.toInt( configVersion, 0 );
+ if ( version < CURRENT_CONFIG_VERSION )
+ {
+ upgradeVersion( userConfigFile, xml );
+ }
+ }
+ }
+ catch ( XMLException e )
+ {
+ getLogger().warn( "Unable to read user configuration XML: " + e.getMessage(), e );
+ }
+
+ if ( !configOk )
+ {
+ try
+ {
+ FileUtils.copyFile( userConfigFile, new File( userConfigFile.getAbsolutePath() + ".bak" ) );
+ writeDefaultConfigFile( userConfigFile );
+ }
+ catch ( IOException e )
+ {
+ getLogger().warn( "Unable to create backup of your configuration file: "
+ + e.getMessage(), e );
+ }
+ }
+
+ }
+
+ private void upgradeVersion( File userConfigFile, XMLReader xml )
+ {
+ // TODO: write implementation when we have a current version greater than 1.
+ }
+
+ private void writeDefaultConfigFile( File userConfigFile )
+ {
+ URL defaultConfigURL = this.getClass()
+ .getResource( "/org/apache/maven/archiva/configuration/default-archiva.xml" );
+
+ if ( defaultConfigURL == null )
+ {
+ try
+ {
+ FileWriter writer = new FileWriter( userConfigFile );
+ writer.write( "<?xml version=\"1.0\"?>\n" );
+ writer.write( "<configuration />" );
+ writer.flush();
+ writer.close();
+ return;
+ }
+ catch ( IOException e )
+ {
+ getLogger().warn( "Unable to write default (generic) configuration file: "
+ + e.getMessage(), e );
+ }
+ }
+
+ // Write default to user config file location.
+ try
+ {
+ FileOutputStream output = new FileOutputStream( userConfigFile );
+ InputStream input = defaultConfigURL.openStream();
+ IOUtils.copy( input, output );
+ output.flush();
+ input.close();
+ output.close();
+ }
+ catch ( IOException e )
+ {
+ getLogger().warn( "Unable to write default configuration file: " + e.getMessage(), e );
+ }
+ }
+
+}
diff --git a/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
index 9cd044f55..6de28dc79 100644
--- a/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
+++ b/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
@@ -33,7 +33,14 @@
<class rootElement="true" xml.tagName="configuration">
<name>Configuration</name>
<version>1.0.0+</version>
- <fields>
+ <fields>
+ <field>
+ <name>version</name>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <required>true</required>
+ <description>This is the version of the configuration format.</description>
+ </field>
<field>
<name>repositories</name>
<version>1.0.0+</version>
diff --git a/archiva-base/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml b/archiva-base/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml
index 50558d644..e5c3a7692 100644
--- a/archiva-base/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml
+++ b/archiva-base/archiva-configuration/src/main/resources/org/apache/maven/archiva/configuration/default-archiva.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
+ <version>1</version>
<repositories>
<repository>
<id>internal</id>
diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaConfigurationAdaptor.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaConfigurationAdaptor.java
index aeb4b8944..4867fe7a5 100644
--- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaConfigurationAdaptor.java
+++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaConfigurationAdaptor.java
@@ -19,6 +19,7 @@ package org.apache.maven.archiva.repository;
* under the License.
*/
+import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.RepositoryConfiguration;
import org.apache.maven.archiva.model.ArchivaRepository;
@@ -33,9 +34,27 @@ public class ArchivaConfigurationAdaptor
{
public static ArchivaRepository toArchivaRepository( RepositoryConfiguration config )
{
+ if ( config == null )
+ {
+ throw new IllegalArgumentException( "Unable to convert null repository config to archiva repository." );
+ }
+
+ if ( StringUtils.isBlank( config.getId() ) )
+ {
+ throw new IllegalArgumentException( "Unable to repository config with blank ID to archiva repository." );
+ }
+
+ if ( StringUtils.isBlank( config.getUrl() ) )
+ {
+ throw new IllegalArgumentException(
+ "Unable to convert repository config with blank URL to archiva repository." );
+ }
+
ArchivaRepository repository = new ArchivaRepository( config.getId(), config.getName(), config.getUrl() );
repository.getModel().setLayoutName( config.getLayout() );
+ repository.getModel().setReleasePolicy( config.isReleases() );
+ repository.getModel().setSnapshotPolicy( config.isSnapshots() );
return repository;
}
diff --git a/archiva-scheduled/pom.xml b/archiva-scheduled/pom.xml
index 63e68f4dc..50fa26016 100644
--- a/archiva-scheduled/pom.xml
+++ b/archiva-scheduled/pom.xml
@@ -115,20 +115,6 @@
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>merge</id>
- <goals>
- <goal>merge-descriptors</goal>
- </goals>
- <configuration>
- <descriptors>
- <descriptor>${basedir}/src/main/resources/META-INF/plexus/components.xml</descriptor>
- <descriptor>${project.build.directory}/generated-resources/plexus/META-INF/plexus/components.xml</descriptor>
- </descriptors>
- </configuration>
- </execution>
- </executions>
</plugin>
</plugins>
</build>
diff --git a/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/ArchivaTaskQueue.java b/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/ArchivaTaskQueue.java
new file mode 100644
index 000000000..f2deaa106
--- /dev/null
+++ b/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/ArchivaTaskQueue.java
@@ -0,0 +1,42 @@
+package org.apache.maven.archiva.scheduled;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.taskqueue.DefaultTaskQueue;
+
+/**
+ * ArchivaTaskQueue
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ * @plexus.component role="org.codehaus.plexus.taskqueue.TaskQueue"
+ * role-hint="archiva-task-queue"
+ * lifecycle-handler="plexus-configurable"
+ */
+public class ArchivaTaskQueue
+ extends DefaultTaskQueue
+{
+
+ public ArchivaTaskQueue()
+ {
+ super();
+ /* do nothing special */
+ }
+}
diff --git a/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java b/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java
index 2ea5311c9..7b351e482 100644
--- a/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java
+++ b/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java
@@ -50,7 +50,7 @@ import java.util.List;
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @author <a href="mailto:jmcconnell@apache.org">Jesse McConnell</a>
- * @plexus.component role="org.apache.maven.archiva.scheduler.ArchivaTaskScheduler"
+ * @plexus.component role="org.apache.maven.archiva.scheduled.ArchivaTaskScheduler" role-hint="default"
*/
public class DefaultArchivaTaskScheduler
extends AbstractLogEnabled
diff --git a/archiva-scheduled/src/main/resources/META-INF/plexus/components.xml b/archiva-scheduled/src/main/resources/META-INF/plexus/components.xml
deleted file mode 100644
index 9c8752e90..000000000
--- a/archiva-scheduled/src/main/resources/META-INF/plexus/components.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied. See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
- -->
-
-<components>
- <component>
- <role>org.codehaus.plexus.taskqueue.TaskQueue</role>
- <role-hint>archiva-task-queue</role-hint>
- <implementation>org.codehaus.plexus.taskqueue.DefaultTaskQueue</implementation>
- <lifecycle-handler>plexus-configurable</lifecycle-handler>
- <configuration>
- <task-entry-evaluators>
- </task-entry-evaluators>
- <task-exit-evaluators>
- </task-exit-evaluators>
- <task-viability-evaluators>
- </task-viability-evaluators>
- </configuration>
- </component>
-</components> \ No newline at end of file
diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/check/RoleExistanceEnvironmentCheck.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/check/RoleExistanceEnvironmentCheck.java
index 1d93d8b05..3a87e0130 100644
--- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/check/RoleExistanceEnvironmentCheck.java
+++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/check/RoleExistanceEnvironmentCheck.java
@@ -73,7 +73,7 @@ public class RoleExistanceEnvironmentCheck
Iterator it = repos.iterator();
while ( it.hasNext() )
{
- RepositoryConfiguration repository = (RepositoryConfiguration) it.next();
+ ArchivaRepository repository = (ArchivaRepository) it.next();
roleProfileManager.getDynamicRole( "archiva-repository-manager", repository.getId() );
diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ArchivaVersion.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ArchivaVersion.java
new file mode 100644
index 000000000..7a463192d
--- /dev/null
+++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ArchivaVersion.java
@@ -0,0 +1,98 @@
+package org.apache.maven.archiva.web.startup;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.lang.StringUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Properties;
+
+/**
+ * ArchivaVersion
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ArchivaVersion
+{
+ public static String determineVersion( ClassLoader cloader )
+ {
+ /* This is the search order of modules to find the version.
+ */
+ String modules[] = new String[] {
+ "archiva-common",
+ "archiva-configuration",
+ "archiva-database",
+ "archiva-consumer-api",
+ "archiva-core-consumers",
+ "archiva-signature-consumers",
+ "archiva-database-consumers",
+ "archiva-lucene-consumers",
+ "archiva-indexer",
+ "archiva-model",
+ "archiva-policies",
+ "archiva-proxy",
+ "archiva-report-manager",
+ "archiva-artifact-reports",
+ "archiva-project-reports",
+ "archiva-metadata-reports",
+ "archiva-repository-layer",
+ "archiva-scheduled",
+ "archiva-webapp",
+ "archiva-security",
+ "archiva-applet",
+ "archiva-cli",
+ "archiva-xml-tools" };
+
+ for ( int i = 0; i < modules.length; i++ )
+ {
+ String module = modules[i];
+ URL pomurl = findModulePom( cloader, module );
+ if ( pomurl != null )
+ {
+ try
+ {
+ Properties props = new Properties();
+ InputStream is = pomurl.openStream();
+ props.load( is );
+ String version = props.getProperty( "version" );
+ if ( StringUtils.isNotBlank( version ) )
+ {
+ return version;
+ }
+ }
+ catch ( IOException e )
+ {
+ /* do nothing */
+ }
+ }
+ }
+
+ return "Unknown";
+ }
+
+ private static URL findModulePom( ClassLoader cloader, String module )
+ {
+ URL ret = cloader.getResource( "/META-INF/maven/org.apache.maven.archiva/" + module + "/pom.properties" );
+ return ret;
+ }
+}
diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/Banner.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/Banner.java
new file mode 100644
index 000000000..84a40eb9b
--- /dev/null
+++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/Banner.java
@@ -0,0 +1,225 @@
+package org.apache.maven.archiva.web.startup;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.lang.StringUtils;
+import org.codehaus.plexus.logging.Logger;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Banner
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class Banner
+{
+ public static String encode( String raw )
+ {
+ StringBuffer encoded = new StringBuffer();
+ int rawlen = raw.length();
+
+ for ( int i = 0; i < rawlen; i++ )
+ {
+ char c = raw.charAt( i );
+ if ( c == '\\' )
+ {
+ encoded.append( "$." );
+ }
+ else if ( c == '$' )
+ {
+ encoded.append( "$$" );
+ }
+ else if ( c == '\n' )
+ {
+ encoded.append( "$n" );
+ }
+ else if ( Character.isDigit( c ) )
+ {
+ encoded.append( c );
+ }
+ else if ( Character.isLetter( c ) )
+ {
+ encoded.append( rot13( c ) );
+ }
+ else if ( i < raw.length() - 1 )
+ {
+ char nc;
+ boolean done = false;
+ int count = 0;
+ for ( int n = i; !done; n++ )
+ {
+ if ( n >= rawlen )
+ {
+ break;
+ }
+
+ nc = raw.charAt( n );
+
+ if ( nc != c )
+ {
+ done = true;
+ }
+ else
+ {
+ count++;
+ }
+ }
+ if ( count < 3 )
+ {
+ encoded.append( c );
+ }
+ else
+ {
+ encoded.append( "$" ).append( String.valueOf( count ) ).append( c );
+ i += count - 1;
+ }
+ }
+ else
+ {
+ encoded.append( c );
+ }
+ }
+
+ return encoded.toString();
+ }
+
+ public static String decode( String encoded )
+ {
+ StringBuffer decoded = new StringBuffer();
+ int enlen = encoded.length();
+ for ( int i = 0; i < enlen; i++ )
+ {
+ char c = encoded.charAt( i );
+ if ( c == '$' )
+ {
+ char nc = encoded.charAt( i + 1 );
+ if ( nc == '$' )
+ {
+ decoded.append( '$' );
+ i++;
+ }
+ else if ( nc == '.' )
+ {
+ decoded.append( '\\' );
+ i++;
+ }
+ else if ( nc == 'n' )
+ {
+ decoded.append( '\n' );
+ i++;
+ }
+ else if ( Character.isDigit( nc ) )
+ {
+ int count = 0;
+ int nn = i + 1;
+ while ( Character.isDigit( nc ) )
+ {
+ count = ( count * 10 );
+ count += ( nc - '0' );
+ nc = encoded.charAt( ++nn );
+ }
+ for ( int d = 0; d < count; d++ )
+ {
+ decoded.append( nc );
+ }
+ i = nn;
+ }
+ }
+ else if ( Character.isLetter( c ) )
+ {
+ decoded.append( rot13( c ) );
+ }
+ else
+ {
+ decoded.append( c );
+ }
+ }
+
+ return decoded.toString();
+ }
+
+ private static char rot13( char c )
+ {
+ if ( ( c >= 'a' ) && ( c <= 'z' ) )
+ {
+ char dc = c += 13;
+ if ( dc > 'z' )
+ {
+ dc -= 26;
+ }
+ return dc;
+ }
+ else if ( ( c >= 'A' ) && ( c <= 'Z' ) )
+ {
+ char dc = c += 13;
+ if ( dc > 'Z' )
+ {
+ dc -= 26;
+ }
+ return dc;
+ }
+ else
+ {
+ return c;
+ }
+ }
+
+ public static String injectVersion( String text, String version )
+ {
+ Pattern pat = Pattern.compile( "#{2,}" );
+ Matcher mat = pat.matcher( text );
+ StringBuffer ret = new StringBuffer();
+ int off = 0;
+
+ while ( mat.find( off ) )
+ {
+ ret.append( text.substring( off, mat.start() ) );
+ String repl = mat.group();
+ ret.append( StringUtils.center( version, repl.length() ) );
+ off = mat.end();
+ }
+
+ ret.append( text.substring( off ) );
+
+ return ret.toString();
+ }
+
+ public static String getBanner( String version )
+ {
+ String encodedBanner = "$26 $34_$n$15 /$._$7 /$34 $.$n$14 /`/@),$4 | Ba" +
+ " orunys bs nyy bs gur nycnpn'f |$n$14 | (~' __| gbvyvat njnl ba " +
+ "gur Ncnpur Znira |$n$6 _,--.$3_/ |$4 $.$5 cebwrpg grnzf, V jbhyq y" +
+ "vxr gb$3 |$n$4 ,' ,$5 ($3 |$5 $.$5 jrypbzr lbh gb Znira Nepuvin$4 |$" +
+ "n$4 | ($6 $. /$6 | $32# |$n$5 $. )$._/ ,_/$7 |$36 |$n$5 / /$3 " +
+ "( |/$9 | uggc://znira.ncnpur.bet/nepuvin/ |$n$4 ( |$4 ( |$10 | ne" +
+ "puvin-hfref@znira.ncnpur.bet$4 |$n$5 $.|$5 $.|$11 $.$34_/$n$n";
+
+ return injectVersion( decode( encodedBanner ), version );
+ }
+
+ public static void display( Logger logger, String version )
+ {
+ String banner = getBanner( version );
+ logger.info( StringUtils.repeat( "_", 25 ) + "\n" + banner );
+ }
+}
diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ConfigurationSynchronization.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ConfigurationSynchronization.java
new file mode 100644
index 000000000..a2b66876d
--- /dev/null
+++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/ConfigurationSynchronization.java
@@ -0,0 +1,121 @@
+package org.apache.maven.archiva.web.startup;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.ConfigurationNames;
+import org.apache.maven.archiva.configuration.RepositoryConfiguration;
+import org.apache.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.ArchivaDatabaseException;
+import org.apache.maven.archiva.database.ObjectNotFoundException;
+import org.apache.maven.archiva.model.ArchivaRepository;
+import org.apache.maven.archiva.repository.ArchivaConfigurationAdaptor;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.codehaus.plexus.registry.Registry;
+import org.codehaus.plexus.registry.RegistryListener;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * ConfigurationSynchronization
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.web.startup.ConfigurationSynchronization"
+ * role-hint="default"
+ */
+public class ConfigurationSynchronization
+ extends AbstractLogEnabled
+ implements RegistryListener, Initializable
+{
+ /**
+ * @plexus.requirement
+ */
+ private ArchivaDAO dao;
+
+ /**
+ * @plexus.requirement
+ */
+ private ArchivaConfiguration archivaConfiguration;
+
+ public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
+ {
+ if ( ConfigurationNames.isRepositories( propertyName ) )
+ {
+ synchConfiguration();
+ }
+ }
+
+ public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
+ {
+ /* do nothing */
+ }
+
+ private void synchConfiguration()
+ {
+ List repos = archivaConfiguration.getConfiguration().getRepositories();
+ Iterator it = repos.iterator();
+ while ( it.hasNext() )
+ {
+ RepositoryConfiguration repoConfig = (RepositoryConfiguration) it.next();
+ try
+ {
+ try
+ {
+ ArchivaRepository repository = dao.getRepositoryDAO().getRepository( repoConfig.getId() );
+ // Found repository. Update it.
+
+ repository.getModel().setName( repoConfig.getName() );
+ repository.getModel().setUrl( repoConfig.getUrl() );
+ repository.getModel().setLayoutName( repoConfig.getLayout() );
+ repository.getModel().setCreationSource( "configuration" );
+ repository.getModel().setReleasePolicy( repoConfig.isReleases() );
+ repository.getModel().setSnapshotPolicy( repoConfig.isSnapshots() );
+
+ dao.getRepositoryDAO().saveRepository( repository );
+ }
+ catch ( ObjectNotFoundException e )
+ {
+ // Add the repository to the database.
+ getLogger().info( "Adding repository configuration to DB: " + repoConfig );
+ ArchivaRepository drepo = ArchivaConfigurationAdaptor.toArchivaRepository( repoConfig );
+ drepo.getModel().setCreationSource( "configuration" );
+ dao.getRepositoryDAO().saveRepository( drepo );
+ }
+ }
+ catch ( ArchivaDatabaseException e )
+ {
+ // Log error.
+ getLogger().error( "Unable to add configured repositories to the database: " + e.getMessage(), e );
+ }
+ }
+ }
+
+ public void initialize()
+ throws InitializationException
+ {
+ Banner.display( getLogger(), ArchivaVersion.determineVersion( this.getClass().getClassLoader() ) );
+ synchConfiguration();
+ }
+}
diff --git a/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml b/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml
index a470eae16..802f0c744 100644
--- a/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml
+++ b/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml
@@ -196,12 +196,27 @@
<load-on-start>
<component>
- <role>org.apache.maven.archiva.scheduler.RepositoryTaskScheduler</role>
+ <role>org.apache.maven.archiva.configuration.ConfigurationUpgrade</role>
+ <role-hint>default</role-hint>
+ </component>
+ <component>
+ <role>org.apache.maven.archiva.web.startup.ConfigurationSynchronization</role>
+ <role-hint>default</role-hint>
+ </component>
+ <component>
+ <role>org.apache.maven.archiva.web.startup.ConfigurationSynchronization</role>
+ <role-hint>default</role-hint>
+ </component>
+ <component>
+ <role>org.apache.maven.archiva.scheduled.ArchivaTaskScheduler</role>
+ <role-hint>default</role-hint>
</component>
+ <!--
<component>
<role>org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor</role>
- <role-hint>data-refresh</role-hint>
+ <role-hint>archiva-task-executor</role-hint>
</component>
+ -->
</load-on-start>
<lifecycle-handler-manager implementation="org.codehaus.plexus.lifecycle.DefaultLifecycleHandlerManager">
diff --git a/archiva-web/archiva-webapp/src/main/resources/log4j.xml b/archiva-web/archiva-webapp/src/main/resources/log4j.xml
index 9520f8923..89ee23fb5 100644
--- a/archiva-web/archiva-webapp/src/main/resources/log4j.xml
+++ b/archiva-web/archiva-webapp/src/main/resources/log4j.xml
@@ -15,7 +15,7 @@
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d [%t] %-5p %-30c{1} - %m%n"/>
+ <param name="ConversionPattern" value="%d [%t] %-5p %c{1} - %m%n"/>
</layout>
</appender>
diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/startup/BannerTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/startup/BannerTest.java
new file mode 100644
index 000000000..486d051d9
--- /dev/null
+++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/startup/BannerTest.java
@@ -0,0 +1,90 @@
+package org.apache.maven.archiva.web.startup;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.io.IOUtils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.zip.GZIPInputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * BannerTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class BannerTest
+ extends TestCase
+{
+ private void assertEncodeDecode( String encoded, String decoded )
+ {
+ assertEquals( "Encoding: ", encoded, Banner.encode( decoded ) );
+ assertEquals( "Decoding: ", decoded, Banner.decode( encoded ) );
+ }
+
+ public void testEncodeDecode()
+ {
+ assertEncodeDecode( "[$10 ]", "[ ]" );
+ assertEncodeDecode( "$$$5_$n$5_", "$_____\n_____" );
+ assertEncodeDecode( "$${Refgjuvyr}", "${Erstwhile}" );
+ }
+
+ public void testInjectVersion()
+ {
+ assertEquals( "[ 1.0 ]", Banner.injectVersion( "[#####]", "1.0" ) );
+ assertEquals( ".\\ 1.0-SNAPSHOT \\._____", Banner.injectVersion( ".\\################\\._____",
+ "1.0-SNAPSHOT" ) );
+ assertEquals( "Archiva:\n ( 1.0-alpha-1 )", Banner
+ .injectVersion( "Archiva:\n (##############)", "1.0-alpha-1" ) );
+ }
+
+ public void testGetBanner()
+ throws IOException
+ {
+ String version = "1.0-alpha-1-SNAPSHOT";
+ String banner = Banner.getBanner( version );
+ assertNotNull( "Banner should not be null.", banner );
+ assertTrue( "Banner contains version.", banner.indexOf( version ) > 0 );
+
+ /* Want to make a new banner?
+ * Steps to do it.
+ * 1) Edit the src/test/resources/banner.gz file.
+ * 2) Save it compressed.
+ * 3) Add (to this test method) ...
+ * System.out.println( "\"" + Banner.encode( getRawBanner() ) + "\"" );
+ * 4) Run the test
+ * 5) Copy / Paste the encoded form into the Banner.getBanner() method.
+ */
+ }
+
+ public String getRawBanner()
+ throws IOException
+ {
+ File gzBanner = new File( "src/test/resources/banner.gz" );
+ assertTrue( "File [" + gzBanner.getPath() + "] not found.", gzBanner.exists() );
+ FileInputStream fis = new FileInputStream( gzBanner );
+ GZIPInputStream gzis = new GZIPInputStream( fis );
+ return IOUtils.toString( gzis );
+ }
+}
diff --git a/archiva-web/archiva-webapp/src/test/resources/banner.gz b/archiva-web/archiva-webapp/src/test/resources/banner.gz
new file mode 100755
index 000000000..9715c46e7
--- /dev/null
+++ b/archiva-web/archiva-webapp/src/test/resources/banner.gz
Binary files differ