* Ensure configuration is synched with database. * Fix application.xml for new Configuration load-on-starts. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@532431 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-1.0-alpha-1
@@ -33,6 +33,11 @@ | |||
<groupId>org.apache.maven.archiva</groupId> | |||
<artifactId>archiva-common</artifactId> | |||
</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> | |||
@@ -42,6 +47,10 @@ | |||
<groupId>org.codehaus.plexus</groupId> | |||
<artifactId>plexus-component-api</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.codehaus.plexus</groupId> | |||
<artifactId>plexus-container-default</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.codehaus.plexus</groupId> | |||
<artifactId>plexus-utils</artifactId> |
@@ -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 ); | |||
} | |||
} | |||
} |
@@ -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> |
@@ -1,5 +1,6 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<configuration> | |||
<version>1</version> | |||
<repositories> | |||
<repository> | |||
<id>internal</id> |
@@ -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; | |||
} |
@@ -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> |
@@ -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 */ | |||
} | |||
} |
@@ -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 |
@@ -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> |
@@ -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() ); | |||
@@ -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; | |||
} | |||
} |
@@ -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 ); | |||
} | |||
} |
@@ -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(); | |||
} | |||
} |
@@ -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"> |
@@ -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> | |||
@@ -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 ); | |||
} | |||
} |