From: Brett Porter Date: Sat, 26 Aug 2006 05:47:59 +0000 (+0000) Subject: rename archiva artifacts X-Git-Tag: archiva-0.9-alpha-1~657 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=209ef5ca84ee8de9e5ee61952e0d380749c3074b;p=archiva.git rename archiva artifacts git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@437088 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-applet/pom.xml b/archiva-applet/pom.xml new file mode 100644 index 000000000..a581215ae --- /dev/null +++ b/archiva-applet/pom.xml @@ -0,0 +1,75 @@ + + + + 4.0.0 + + org.apache.maven.archiva + archiva + 1.0-SNAPSHOT + + archiva-applet + Archiva Applet + + Applet for performing local operations on files such as creating a checksum of an artifact + before uploading it. + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1-SNAPSHOT + + src/keystore/keystore + mykey + password + password + + + + + sign + + + + + + org.codehaus.mojo + cobertura-maven-plugin + + + + + **/** + + + + + + + + + apache.snapshots + Apache Snapshot Repository + http://svn.apache.org/maven-snapshot-repository + + true + + + + diff --git a/archiva-applet/src/keystore/keystore b/archiva-applet/src/keystore/keystore new file mode 100644 index 000000000..dda84744a Binary files /dev/null and b/archiva-applet/src/keystore/keystore differ diff --git a/archiva-applet/src/main/java/org/apache/maven/repository/applet/ChecksumApplet.java b/archiva-applet/src/main/java/org/apache/maven/repository/applet/ChecksumApplet.java new file mode 100644 index 000000000..9b8697fd0 --- /dev/null +++ b/archiva-applet/src/main/java/org/apache/maven/repository/applet/ChecksumApplet.java @@ -0,0 +1,140 @@ +package org.apache.maven.repository.applet; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 javax.swing.*; +import java.applet.Applet; +import java.awt.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.security.AccessController; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.PrivilegedAction; + +/** + * Applet that takes a file on the local filesystem and checksums it for sending to the server. + * + * @author Brett Porter + */ +public class ChecksumApplet + extends Applet +{ + private static final int CHECKSUM_BUFFER_SIZE = 8192; + + private static final int BYTE_MASK = 0xFF; + + private JProgressBar progressBar; + + public void init() + { + setLayout( new BorderLayout() ); + progressBar = new JProgressBar(); + progressBar.setStringPainted( true ); + add( progressBar, BorderLayout.CENTER ); + JLabel label = new JLabel( "Checksum progress: " ); + add( label, BorderLayout.WEST ); + } + + public String generateMd5( final String file ) + throws IOException, NoSuchAlgorithmException + { + Object o = AccessController.doPrivileged( new PrivilegedAction() + { + public Object run() + { + try + { + return checksumFile( file ); + } + catch ( NoSuchAlgorithmException e ) + { + return "Error checksumming file: " + e.getMessage(); + } + catch ( FileNotFoundException e ) + { + return "Couldn't find the file. " + e.getMessage(); + } + catch ( IOException e ) + { + return "Error reading file: " + e.getMessage(); + } + } + } ); + return (String) o; + } + + protected String checksumFile( String file ) + throws NoSuchAlgorithmException, IOException + { + MessageDigest digest = MessageDigest.getInstance( "MD5" ); + + long total = new File( file ).length(); + InputStream fis = new FileInputStream( file ); + try + { + long totalRead = 0; + byte[] buffer = new byte[CHECKSUM_BUFFER_SIZE]; + int numRead; + do + { + numRead = fis.read( buffer ); + if ( numRead > 0 ) + { + digest.update( buffer, 0, numRead ); + totalRead += numRead; + progressBar.setValue( (int) ( totalRead * progressBar.getMaximum() / total ) ); + } + } + while ( numRead != -1 ); + } + finally + { + fis.close(); + } + + return byteArrayToHexStr( digest.digest() ); + } + + protected static String byteArrayToHexStr( byte[] data ) + { + String output = ""; + + for ( int cnt = 0; cnt < data.length; cnt++ ) + { + //Deposit a byte into the 8 lsb of an int. + int tempInt = data[cnt] & BYTE_MASK; + + //Get hex representation of the int as a string. + String tempStr = Integer.toHexString( tempInt ); + + //Append a leading 0 if necessary so that each hex string will contain 2 characters. + if ( tempStr.length() == 1 ) + { + tempStr = "0" + tempStr; + } + + //Concatenate the two characters to the output string. + output = output + tempStr; + } + + return output.toUpperCase(); + } +} \ No newline at end of file diff --git a/archiva-configuration/pom.xml b/archiva-configuration/pom.xml new file mode 100644 index 000000000..25c939a50 --- /dev/null +++ b/archiva-configuration/pom.xml @@ -0,0 +1,64 @@ + + + + archiva + org.apache.maven.archiva + 1.0-SNAPSHOT + + 4.0.0 + archiva-configuration + Archiva Configuration + + + org.codehaus.plexus + plexus-container-default + + + org.codehaus.plexus + plexus-utils + + + easymock + easymock + 1.2_Java1.3 + test + + + + + + org.codehaus.modello + modello-maven-plugin + 1.0-alpha-10 + + + + xpp3-writer + java + xpp3-reader + + + + + 1.0.0 + src/main/mdo/configuration.mdo + + + + org.codehaus.mojo + cobertura-maven-plugin + + + + + org/apache/maven/repository/configuration/io/** + org/apache/maven/repository/configuration/*RepositoryConfiguration.* + org/apache/maven/repository/configuration/Configuration.* + org/apache/maven/repository/configuration/Proxy.* + + + + + + + diff --git a/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeException.java b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeException.java new file mode 100644 index 000000000..547bff7a4 --- /dev/null +++ b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeException.java @@ -0,0 +1,31 @@ +package org.apache.maven.repository.configuration; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * An error changing the configuration + * + * @author Brett Porter + */ +public class ConfigurationChangeException + extends Exception +{ + public ConfigurationChangeException( String message, Throwable cause ) + { + super( message, cause ); + } +} diff --git a/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java new file mode 100644 index 000000000..ca01a493f --- /dev/null +++ b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java @@ -0,0 +1,36 @@ +package org.apache.maven.repository.configuration; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * Component capable of noticing configuration changes and adjusting accordingly. + * This is not a Plexus role. + * + * @author Brett Porter + */ +public interface ConfigurationChangeListener +{ + /** + * Notify the object that there has been a configuration change. + * + * @param configuration the new configuration + * @throws InvalidConfigurationException if there is a problem with the new configuration + * @throws ConfigurationChangeException if there is a problem changing the configuration, but the configuration is valid + */ + void notifyOfConfigurationChange( Configuration configuration ) + throws InvalidConfigurationException, ConfigurationChangeException; +} diff --git a/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java new file mode 100644 index 000000000..968ce25d6 --- /dev/null +++ b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java @@ -0,0 +1,55 @@ +package org.apache.maven.repository.configuration; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * A component for loading the configuration into the model. + * + * @author Brett Porter + * @todo this is something that could possibly be generalised into Modello. + */ +public interface ConfigurationStore +{ + /** + * The Plexus role for the component. + */ + String ROLE = ConfigurationStore.class.getName(); + + /** + * Get the configuration from the store. A cached version may be used. + * + * @return the configuration + * @throws ConfigurationStoreException if there is a problem loading the configuration + */ + Configuration getConfigurationFromStore() + throws ConfigurationStoreException; + + /** + * Save the configuration to the store. + * + * @param configuration the configuration to store + */ + void storeConfiguration( Configuration configuration ) + throws ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException; + + /** + * Add a configuration change listener. + * + * @param listener the listener + */ + void addChangeListener( ConfigurationChangeListener listener ); +} diff --git a/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStoreException.java b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStoreException.java new file mode 100644 index 000000000..04dd8990b --- /dev/null +++ b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStoreException.java @@ -0,0 +1,36 @@ +package org.apache.maven.repository.configuration; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * Exception occurring using the configuration store. + * + * @author Brett Porter + */ +public class ConfigurationStoreException + extends Exception +{ + public ConfigurationStoreException( String message ) + { + super( message ); + } + + public ConfigurationStoreException( String message, Throwable e ) + { + super( message, e ); + } +} diff --git a/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java new file mode 100644 index 000000000..ad771cba7 --- /dev/null +++ b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java @@ -0,0 +1,143 @@ +package org.apache.maven.repository.configuration; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.repository.configuration.io.xpp3.ConfigurationXpp3Reader; +import org.apache.maven.repository.configuration.io.xpp3.ConfigurationXpp3Writer; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +/** + * Load and store the configuration. No synchronization is used, but it is unnecessary as the old configuration object + * can continue to be used. + * + * @author Brett Porter + * @todo would be great for plexus to do this for us - so the configuration would be a component itself rather than this store + * @todo would be good to monitor the store file for changes + * @todo support other implementations than XML file + * @plexus.component + */ +public class DefaultConfigurationStore + extends AbstractLogEnabled + implements ConfigurationStore +{ + /** + * @plexus.configuration default-value="${configuration.store.file}" + */ + private File file; + + /** + * The cached configuration. + */ + private Configuration configuration; + + /** + * List of listeners to configuration changes. + */ + private List/**/ listeners = new LinkedList(); + + public Configuration getConfigurationFromStore() + throws ConfigurationStoreException + { + if ( configuration == null ) + { + ConfigurationXpp3Reader reader = new ConfigurationXpp3Reader(); + + if ( file == null ) + { + file = new File( System.getProperty( "user.home" ), "/.m2/repository-manager.xml" ); + } + + FileReader fileReader; + try + { + fileReader = new FileReader( file ); + } + catch ( FileNotFoundException e ) + { + getLogger().warn( "Configuration file: " + file + " not found. Using defaults." ); + configuration = new Configuration(); + return configuration; + } + + getLogger().info( "Reading configuration from " + file ); + try + { + configuration = reader.read( fileReader, false ); + } + catch ( IOException e ) + { + throw new ConfigurationStoreException( e.getMessage(), e ); + } + catch ( XmlPullParserException e ) + { + throw new ConfigurationStoreException( e.getMessage(), e ); + } + finally + { + IOUtil.close( fileReader ); + } + } + return configuration; + } + + public void storeConfiguration( Configuration configuration ) + throws ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException + { + for ( Iterator i = listeners.iterator(); i.hasNext(); ) + { + ConfigurationChangeListener listener = (ConfigurationChangeListener) i.next(); + + listener.notifyOfConfigurationChange( configuration ); + } + + ConfigurationXpp3Writer writer = new ConfigurationXpp3Writer(); + + getLogger().info( "Writing configuration to " + file ); + FileWriter fileWriter = null; + try + { + file.getParentFile().mkdirs(); + + fileWriter = new FileWriter( file ); + writer.write( fileWriter, configuration ); + } + catch ( IOException e ) + { + throw new ConfigurationStoreException( e.getMessage(), e ); + } + finally + { + IOUtil.close( fileWriter ); + } + } + + public void addChangeListener( ConfigurationChangeListener listener ) + { + listeners.add( listener ); + } +} diff --git a/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/InvalidConfigurationException.java b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/InvalidConfigurationException.java new file mode 100644 index 000000000..05006df96 --- /dev/null +++ b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/InvalidConfigurationException.java @@ -0,0 +1,46 @@ +package org.apache.maven.repository.configuration; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * An error in the configuration. + * + * @author Brett Porter + */ +public class InvalidConfigurationException + extends Exception +{ + private final String name; + + public InvalidConfigurationException( String name, String message ) + { + super( message ); + this.name = name; + } + + public InvalidConfigurationException( String name, String message, Throwable cause ) + { + super( message, cause ); + + this.name = name; + } + + public String getName() + { + return name; + } +} diff --git a/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoader.java b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoader.java new file mode 100644 index 000000000..814cec7b1 --- /dev/null +++ b/archiva-configuration/src/main/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoader.java @@ -0,0 +1,146 @@ +package org.apache.maven.repository.configuration; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.util.StringUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.Properties; +import java.util.StringTokenizer; + +/** + * @author Ben Walding + * @author Brett Porter + */ +public class MavenProxyPropertyLoader +{ + private static final String REPO_LOCAL_STORE = "repo.local.store"; + + private static final String PROXY_LIST = "proxy.list"; + + private static final String REPO_LIST = "repo.list"; + + public void load( Properties props, Configuration configuration ) + throws InvalidConfigurationException + { + // set up the managed repository + String localCachePath = getMandatoryProperty( props, REPO_LOCAL_STORE ); + + RepositoryConfiguration config = new RepositoryConfiguration(); + config.setDirectory( localCachePath ); + config.setName( "Imported Maven-Proxy Cache" ); + config.setId( "maven-proxy" ); + configuration.addRepository( config ); + + //just get the first HTTP proxy and break + String propertyList = props.getProperty( PROXY_LIST ); + if ( propertyList != null ) + { + StringTokenizer tok = new StringTokenizer( propertyList, "," ); + while ( tok.hasMoreTokens() ) + { + String key = tok.nextToken(); + if ( StringUtils.isNotEmpty( key ) ) + { + Proxy proxy = new Proxy(); + proxy.setHost( getMandatoryProperty( props, "proxy." + key + ".host" ) ); + proxy.setPort( Integer.parseInt( getMandatoryProperty( props, "proxy." + key + ".port" ) ) ); + + // the username and password isn't required + proxy.setUsername( props.getProperty( "proxy." + key + ".username" ) ); + proxy.setPassword( props.getProperty( "proxy." + key + ".password" ) ); + + configuration.setProxy( proxy ); + + //accept only one proxy configuration + break; + } + } + } + + //get the remote repository list + String repoList = getMandatoryProperty( props, REPO_LIST ); + + StringTokenizer tok = new StringTokenizer( repoList, "," ); + while ( tok.hasMoreTokens() ) + { + String key = tok.nextToken(); + + Properties repoProps = getSubset( props, "repo." + key + "." ); + String url = getMandatoryProperty( props, "repo." + key + ".url" ); + String proxyKey = repoProps.getProperty( "proxy" ); + + boolean cacheFailures = + Boolean.valueOf( repoProps.getProperty( "cache.failures", "false" ) ).booleanValue(); + boolean hardFail = Boolean.valueOf( repoProps.getProperty( "hardfail", "true" ) ).booleanValue(); + int cachePeriod = Integer.parseInt( repoProps.getProperty( "cache.period", "60" ) ); + + ProxiedRepositoryConfiguration repository = new ProxiedRepositoryConfiguration(); + repository.setId( key ); + repository.setLayout( "legacy" ); + repository.setManagedRepository( config.getId() ); + repository.setName( "Imported Maven-Proxy Remote Proxy" ); + repository.setSnapshotsInterval( cachePeriod ); + repository.setUrl( url ); + repository.setUseNetworkProxy( StringUtils.isNotEmpty( proxyKey ) ); + repository.setCacheFailures( cacheFailures ); + repository.setHardFail( hardFail ); + + configuration.addProxiedRepository( repository ); + } + } + + private Properties getSubset( Properties props, String prefix ) + { + Enumeration keys = props.keys(); + Properties result = new Properties(); + while ( keys.hasMoreElements() ) + { + String key = (String) keys.nextElement(); + String value = props.getProperty( key ); + if ( key.startsWith( prefix ) ) + { + String newKey = key.substring( prefix.length() ); + result.setProperty( newKey, value ); + } + } + return result; + } + + public void load( InputStream is, Configuration configuration ) + throws IOException, InvalidConfigurationException + { + Properties props = new Properties(); + props.load( is ); + load( props, configuration ); + } + + private String getMandatoryProperty( Properties props, String key ) + throws InvalidConfigurationException + { + String value = props.getProperty( key ); + + if ( value == null ) + { + throw new InvalidConfigurationException( key, "Missing required field: " + key ); + } + + return value; + } +} \ No newline at end of file diff --git a/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-configuration/src/main/mdo/configuration.mdo new file mode 100644 index 000000000..a2f772800 --- /dev/null +++ b/archiva-configuration/src/main/mdo/configuration.mdo @@ -0,0 +1,477 @@ + + configuration + Configuration + + Configuration for the Maven Repository Manager. + + + + package + org.apache.maven.repository.configuration + + + + + + Configuration + 1.0.0 + + + repositories + 1.0.0 + + RepositoryConfiguration + * + + + + proxiedRepositories + 1.0.0 + + ProxiedRepositoryConfiguration + * + + + + syncedRepositories + 1.0.0 + + SyncedRepositoryConfiguration + * + + + + localRepository + 1.0.0 + String + + The location of the local repository. + + + + indexPath + 1.0.0 + String + + The location of the Lucene index to use for the repository. The default is the .index subdirectory of + the repository. + + + + minimalIndexPath + 1.0.0 + String + + The location of the reduced Lucene index to use for the repository. The default is the .small-index + subdirectory of the repository. + + + + indexerCronExpression + 1.0.0 + String + When to run the indexing mechanism. Default is every hour on the hour. + 0 0 * * * ? + + + converterCronExpression + 1.0.0 + String + When to run the converter mechanism. Default is every 4 hours, on the half hour. + 0 30 0/4 * * ? + + + globalBlackListPatterns + 1.0.0 + String + Blacklisted patterns in the discovery process + + + proxy + 1.0.0 + + Proxy + + The network proxy to use for outgoing requests. + + + + + 1.0.0 + + + + + + AbstractRepositoryConfiguration + true + 1.0.0 + + + id + 1.0.0 + String + true + + The repository identifier. + + + + name + 1.0.0 + String + true + + The descriptive name of the repository. + + + + layout + 1.0.0 + String + true + + The layout of the repository. Valid values are "default" and "legacy". + + + default + + + + + 1.0.0 + + + + + + AbstractRepositoryConfiguration + RepositoryConfiguration + 1.0.0 + + + directory + 1.0.0 + String + true + + The location of the repository to monitor. + + + + includeSnapshots + 1.0.0 + boolean + Whether to include snapshot versions in the discovery process + false + + + indexed + 1.0.0 + boolean + Whether to index the artifacts in this repository. + true + + + blackListPatterns + 1.0.0 + String + Blacklisted patterns in the discovery process + + + + + AbstractRepositoryConfiguration + ProxiedRepositoryConfiguration + 1.0.0 + + + url + 1.0.0 + String + true + + The URL of the remote repository to proxy. + + + + + managedRepository + 1.0.0 + true + String + + The ID of the managed repository to use as the local storage for proxied artifacts. + + + + snapshotsPolicy + 1.0.0 + String + disabled + + The policy for snapshots: one of disabled, daily, hourly, interval, never + (allow snapshots, but never update once retrieved). + + + + snapshotsInterval + 1.0.0 + int + + The interval in minutes before updating snapshots if the policy is set to 'interval'. + + + + releasesPolicy + 1.0.0 + String + daily + + The policy for releases: one of disabled, daily, hourly, interval, never + (allow releases, but never update once retrieved). + + + + releasesInterval + 1.0.0 + int + + The interval in minutes before updating releases if the policy is set to 'interval'. + + + + useNetworkProxy + 1.0.0 + boolean + false + + Whether to use the network proxy, if one is configured for the protocol of this repository. + + + + cacheFailures + 1.0.0 + boolean + false + + Whether to cache failures to avoid re-attempting them over the network. The cache will last for the duration + of the intervals specified above depending on whether it a release or snapshot. + + + + hardFail + 1.0.0 + boolean + false + + Whether to cause the entire request to fail if attempts to retrieve from this proxy fail. + + + + + + AbstractRepositoryConfiguration + SyncedRepositoryConfiguration + true + 1.0.0 + + + + managedRepository + 1.0.0 + true + String + + The ID of the managed repository to use as the local storage for proxied artifacts. + + + + cronExpression + 1.0.0 + String + When to run the sync mechanism. Default is every hour on the hour. + 0 0 * * * ? + + + method + 1.0.0 + String + The type of synchronization to use. + rsync + + + properties + 1.0.0 + Properties + Configuration for the repository synchronization. + + String + * + + + + + + Proxy + 1.0.0 + + + protocol + 1.0.0 + + String + http + + + username + 1.0.0 + + String + + + password + 1.0.0 + + String + + + port + 1.0.0 + + int + 8080 + + + host + 1.0.0 + + String + true + + + nonProxyHosts + 1.0.0 + + String + + + + + + + diff --git a/archiva-configuration/src/main/resources/org/apache/maven/repository/configuration/SyncedRepositoryConfiguration-conversion.properties b/archiva-configuration/src/main/resources/org/apache/maven/repository/configuration/SyncedRepositoryConfiguration-conversion.properties new file mode 100644 index 000000000..0bf28d59c --- /dev/null +++ b/archiva-configuration/src/main/resources/org/apache/maven/repository/configuration/SyncedRepositoryConfiguration-conversion.properties @@ -0,0 +1,18 @@ +# +# Copyright 2005-2006 The Apache Software Foundation. +# +# Licensed 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. +# + +Key_properties=java.lang.String +Element_properties=java.lang.String diff --git a/archiva-configuration/src/test/conf/corrupt.xml b/archiva-configuration/src/test/conf/corrupt.xml new file mode 100644 index 000000000..2476f91ff --- /dev/null +++ b/archiva-configuration/src/test/conf/corrupt.xml @@ -0,0 +1,16 @@ + + diff --git a/archiva-configuration/src/test/conf/maven-proxy-complete.conf b/archiva-configuration/src/test/conf/maven-proxy-complete.conf new file mode 100644 index 000000000..7908a9ad9 --- /dev/null +++ b/archiva-configuration/src/test/conf/maven-proxy-complete.conf @@ -0,0 +1,144 @@ +################ GLOBAL SETTINGS +# This is where maven-proxy stores files it has downloaded +repo.local.store=target + +#The port to listen on - not used if loaded as a webapp +port=9999 + +#This is the base area that all files are loaded from. While it is possible to leave this blank, this behaviour +#is deprecated and will be disabled in version 2.0. There are too many namespace conflicts caused by not using +#a prefix. +#The repository will be shown at http://localhost:9999/repository/ +#for the .war loaded into a webapp server, the default prefix is "repository" (edit the web.xml to change) +# As maven doesn't like a trailing slash, this address shouldn't have one either. +prefix=repository + +#This is the simple date format used to display the last modified date while browsing the repository. +lastModifiedDateFormat=yyyy/MM/dd HH:mm:ss + +################ SNAPSHOT HANDLING +#If you want the proxy to look for newer snapshots, set to true +snapshot.update=true + +################ M2 METADATA HANDLING +#If you want the proxy to prevent looking for newer metadata, set to false (default is true) +#metadata.update=false + +################ M2 POM HANDLING +#If you want the proxy to look for newer POMs, set to true (default is false) +pom.update=true + +################ PROMOTION HANDLING +# ***** NOT CURRENTLY IMPLEMENTED ***** +#Promotion describes the process by which new artifacts are loaded to global maven-proxy repository. It +# is designed to be used by "higher security installations" that do not want to acquire artifacts from +# remote repositories without approval. +# +#If promotion handling is enabled, then the proxy will not download remote artifacts without permission +# (local repositories with copy=false are considered to be local) +# +#Permission to download is granted via the Promotion menu which will be enabled +# when promotion handling is enabled. +# +#If promotion is false, artifacts are sourced from any repository as per normal. +# +#Promotion and snapshots: If promotion is enabled, snapshots are not downloadable. The concept of using +# a snapshot in a production build (which is primarily what promotion is for) is counterintuitive. +## +promotion=false + +################ WEB INTERFACE +# This defines the absolute URL the server should use to identify itself. +# This can often be determined automatically, but we recommend you specify +# it explicitly to prevent problems during startup. +# The prefix will be added to this for the actual repository +# i.e. proxy available at http://localhost:9999/, repository at http://localhost:9999/repository +serverName=http://localhost:9999 + +#If true, the repository can be browsed +browsable=true + +#If true, the repository can be searched +searchable=true + +#Not currently implemented. Will allow webdav access to the repository at some point. +webdav=true + +#Stylesheet - if configured, will override the default stylesheet shipped with maven-proxy - absolute URLs only +#eg. /maven-proxy/style.css, http://www.example.com/style.css +stylesheet=/maven-proxy/style.css + +#bgColor / bgColorHighlight are replaced in the built in stylesheet to produce a simple color scheme. +#If a stylesheet is set, these are not used. +bgColor=#14B +bgColorHighlight=#94B + +#rowColor / rowColorHighlight are replaced in the built in stylesheet to produce a simple color scheme. +#If a stylesheet is set, these are not used. +rowColor=#CCF +rowColorHighlight=#DDF + + +################ PROXIES +#This is just a hack, it should auto discover them +proxy.list=one,two,three + +#Unauthenticated proxy +proxy.one.host=proxy1.example.com +proxy.one.port=3128 + +#Authenticated proxy +proxy.two.host=proxy2.example.org +proxy.two.port=80 +proxy.two.username=username2 +proxy.two.password=password2 + +#Authenticated proxy +proxy.three.host=proxy3.example.net +proxy.three.port=3129 +proxy.three.username=username3 +proxy.three.password=password3 + + +################# REPOSITORIES +#This is not just a hack, it specifies the order repositories should be checked +#Note that the proxy adds a "/" which is why the urls aren't suffixed with a "/" +repo.list=local-repo,www-ibiblio-org,dist-codehaus-org,private-example-com + +#local-store +# The local store represents a location that local jars you host can be located. +# This could also be achieved by having a local http repository, but this is less cumbersome +repo.local-repo.url=file://target +repo.local-repo.description=Super Secret Custom Repository +#If copy is true, jars are copied from the store to the proxy-repo. Only configurable for file:/// repos +repo.local-repo.copy=false +#If hardfail is true, any unexpected errors from the repository will cause +#the client download to fail (typically with a 500 error) +repo.local-repo.hardfail=true +#Don't cache a file repository +repo.local-repo.cache.period=0 + + +#www.ibiblio.org +repo.www-ibiblio-org.url=http://www.ibiblio.org/maven2 +repo.www-ibiblio-org.description=www.ibiblio.org +repo.www-ibiblio-org.proxy=one +repo.www-ibiblio-org.hardfail=true +#Cache this repository for 1 hour +repo.www-ibiblio-org.cache.period=3600 +repo.www-ibiblio-org.cache.failures=true + +#dist.codehaus.org +repo.dist-codehaus-org.url=http://dist.codehaus.org +repo.dist-codehaus-org.proxy=two +repo.dist-codehaus-org.hardfail=false +repo.dist-codehaus-org.cache.period=3600 +repo.dist-codehaus-org.cache.failures=true + +#private.example.com +repo.private-example-com.url=http://private.example.com/internal +repo.private-example-com.description=Commercial In Confidence Repository +repo.private-example-com.username=username1 +repo.private-example-com.password=password1 +repo.private-example-com.proxy=three +repo.private-example-com.cache.period=3600 diff --git a/archiva-configuration/src/test/conf/repository-manager.xml b/archiva-configuration/src/test/conf/repository-manager.xml new file mode 100644 index 000000000..a3f1f2745 --- /dev/null +++ b/archiva-configuration/src/test/conf/repository-manager.xml @@ -0,0 +1,53 @@ + + + + + + + + managed-repository + local + local + + + + + http://www.ibiblio.org/maven2/ + local + + + true + ibiblio + Ibiblio + + + + + apache + ASF + 0 0 * * * ? + local + rsync + + host + ssh + + + + local-repository + .index + diff --git a/archiva-configuration/src/test/java/org/apache/maven/repository/configuration/ConfigurationStoreTest.java b/archiva-configuration/src/test/java/org/apache/maven/repository/configuration/ConfigurationStoreTest.java new file mode 100644 index 000000000..34d350a68 --- /dev/null +++ b/archiva-configuration/src/test/java/org/apache/maven/repository/configuration/ConfigurationStoreTest.java @@ -0,0 +1,154 @@ +package org.apache.maven.repository.configuration; + +import org.codehaus.plexus.PlexusTestCase; +import org.easymock.MockControl; + +import java.io.File; +import java.util.Properties; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * Test the configuration store. + * + * @author Brett Porter + * @noinspection JavaDoc + */ +public class ConfigurationStoreTest + extends PlexusTestCase +{ + public void testInvalidFile() + throws Exception + { + ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "invalid-file" ); + + Configuration configuration = configurationStore.getConfigurationFromStore(); + + // check default configuration + assertNotNull( "check configuration returned", configuration ); + assertEquals( "check configuration has default elements", "0 0 * * * ?", + configuration.getIndexerCronExpression() ); + assertNull( "check configuration has default elements", configuration.getIndexPath() ); + assertTrue( "check configuration has default elements", configuration.getRepositories().isEmpty() ); + } + + public void testCorruptFile() + throws Exception + { + ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "corrupt-file" ); + + try + { + configurationStore.getConfigurationFromStore(); + fail( "Configuration should not have succeeded" ); + } + catch ( ConfigurationStoreException e ) + { + // expected + assertTrue( true ); + } + } + + public void testGetConfiguration() + throws Exception + { + ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "default" ); + + Configuration configuration = configurationStore.getConfigurationFromStore(); + + assertEquals( "check indexPath", ".index", configuration.getIndexPath() ); + assertEquals( "check localRepository", "local-repository", configuration.getLocalRepository() ); + + assertEquals( "check managed repositories", 1, configuration.getRepositories().size() ); + RepositoryConfiguration repository = + (RepositoryConfiguration) configuration.getRepositories().iterator().next(); + + assertEquals( "check managed repositories", "managed-repository", repository.getDirectory() ); + assertEquals( "check managed repositories", "local", repository.getName() ); + assertEquals( "check managed repositories", "local", repository.getId() ); + assertEquals( "check managed repositories", "default", repository.getLayout() ); + assertTrue( "check managed repositories", repository.isIndexed() ); + + assertEquals( "check proxied repositories", 1, configuration.getProxiedRepositories().size() ); + ProxiedRepositoryConfiguration proxiedRepository = + (ProxiedRepositoryConfiguration) configuration.getProxiedRepositories().iterator().next(); + + assertEquals( "check proxied repositories", "local", proxiedRepository.getManagedRepository() ); + assertEquals( "check proxied repositories", "http://www.ibiblio.org/maven2/", proxiedRepository.getUrl() ); + assertEquals( "check proxied repositories", "ibiblio", proxiedRepository.getId() ); + assertEquals( "check proxied repositories", "Ibiblio", proxiedRepository.getName() ); + assertEquals( "check proxied repositories", 0, proxiedRepository.getSnapshotsInterval() ); + assertEquals( "check proxied repositories", 0, proxiedRepository.getReleasesInterval() ); + assertTrue( "check proxied repositories", proxiedRepository.isUseNetworkProxy() ); + + assertEquals( "check synced repositories", 1, configuration.getSyncedRepositories().size() ); + SyncedRepositoryConfiguration syncedRepository = + (SyncedRepositoryConfiguration) configuration.getSyncedRepositories().iterator().next(); + + assertEquals( "check synced repositories", "local", syncedRepository.getManagedRepository() ); + assertEquals( "check synced repositories", "apache", syncedRepository.getId() ); + assertEquals( "check synced repositories", "ASF", syncedRepository.getName() ); + assertEquals( "check synced repositories", "0 0 * * * ?", syncedRepository.getCronExpression() ); + assertEquals( "check synced repositories", "rsync", syncedRepository.getMethod() ); + Properties properties = new Properties(); + properties.setProperty( "rsyncHost", "host" ); + properties.setProperty( "rsyncMethod", "ssh" ); + assertEquals( "check synced repositories", properties, syncedRepository.getProperties() ); + } + + public void testStoreConfiguration() + throws Exception + { + ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "save-file" ); + + Configuration configuration = new Configuration(); + configuration.setIndexPath( "index-path" ); + + File file = getTestFile( "target/test/test-file.xml" ); + file.delete(); + assertFalse( file.exists() ); + + configurationStore.storeConfiguration( configuration ); + + assertTrue( "Check file exists", file.exists() ); + + // read it back + configuration = configurationStore.getConfigurationFromStore(); + assertEquals( "check value", "index-path", configuration.getIndexPath() ); + } + + /** + * @noinspection JUnitTestMethodWithNoAssertions + */ + public void testChangeListeners() + throws Exception + { + ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "save-file" ); + + MockControl control = MockControl.createControl( ConfigurationChangeListener.class ); + ConfigurationChangeListener mock = (ConfigurationChangeListener) control.getMock(); + configurationStore.addChangeListener( mock ); + + Configuration configuration = new Configuration(); + mock.notifyOfConfigurationChange( configuration ); + control.replay(); + + configurationStore.storeConfiguration( configuration ); + + control.verify(); + } +} diff --git a/archiva-configuration/src/test/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoaderTest.java b/archiva-configuration/src/test/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoaderTest.java new file mode 100644 index 000000000..de8fb8d01 --- /dev/null +++ b/archiva-configuration/src/test/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoaderTest.java @@ -0,0 +1,103 @@ +package org.apache.maven.repository.configuration; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.PlexusTestCase; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.List; +import java.util.Properties; + +/** + * @author Edwin Punzalan + */ +public class MavenProxyPropertyLoaderTest + extends PlexusTestCase +{ + private static final int DEFAULT_CACHE_PERIOD = 3600; + + private MavenProxyPropertyLoader loader; + + public void testLoadValidMavenProxyConfiguration() + throws IOException, InvalidConfigurationException + { + File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" ); + + Configuration configuration = new Configuration(); + Proxy proxy = new Proxy(); + proxy.setHost( "original-host" ); + configuration.setProxy( proxy ); // overwritten + configuration.setIndexPath( "index-path" ); // existing value + + loader.load( new FileInputStream( confFile ), configuration ); + + List list = configuration.getRepositories(); + assertEquals( "check single managed repository", 1, list.size() ); + RepositoryConfiguration managedRepository = (RepositoryConfiguration) list.iterator().next(); + assertEquals( "cache path changed", "target", managedRepository.getDirectory() ); + + assertEquals( "Count repositories", 4, configuration.getProxiedRepositories().size() ); + + list = configuration.getProxiedRepositories(); + ProxiedRepositoryConfiguration repo = (ProxiedRepositoryConfiguration) list.get( 0 ); + assertEquals( "Repository name not as expected", "local-repo", repo.getId() ); + assertEquals( "Repository url does not match its name", "file://target", repo.getUrl() ); + assertEquals( "Repository cache period check failed", 0, repo.getSnapshotsInterval() ); + assertFalse( "Repository failure caching check failed", repo.isCacheFailures() ); + + repo = (ProxiedRepositoryConfiguration) list.get( 1 ); + assertEquals( "Repository name not as expected", "www-ibiblio-org", repo.getId() ); + assertEquals( "Repository url does not match its name", "http://www.ibiblio.org/maven2", repo.getUrl() ); + assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() ); + assertTrue( "Repository failure caching check failed", repo.isCacheFailures() ); + + repo = (ProxiedRepositoryConfiguration) list.get( 2 ); + assertEquals( "Repository name not as expected", "dist-codehaus-org", repo.getId() ); + assertEquals( "Repository url does not match its name", "http://dist.codehaus.org", repo.getUrl() ); + assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() ); + assertTrue( "Repository failure caching check failed", repo.isCacheFailures() ); + + repo = (ProxiedRepositoryConfiguration) list.get( 3 ); + assertEquals( "Repository name not as expected", "private-example-com", repo.getId() ); + assertEquals( "Repository url does not match its name", "http://private.example.com/internal", repo.getUrl() ); + assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() ); + assertFalse( "Repository failure caching check failed", repo.isCacheFailures() ); + } + + public void testInvalidConfiguration() + { + Configuration configuration = new Configuration(); + try + { + loader.load( new Properties(), configuration ); + fail( "Incomplete config should have failed" ); + } + catch ( InvalidConfigurationException e ) + { + assertTrue( true ); + } + } + + protected void setUp() + throws Exception + { + super.setUp(); + loader = new MavenProxyPropertyLoader(); + } +} diff --git a/archiva-configuration/src/test/resources/org/apache/maven/repository/configuration/ConfigurationStoreTest.xml b/archiva-configuration/src/test/resources/org/apache/maven/repository/configuration/ConfigurationStoreTest.xml new file mode 100644 index 000000000..39a15a996 --- /dev/null +++ b/archiva-configuration/src/test/resources/org/apache/maven/repository/configuration/ConfigurationStoreTest.xml @@ -0,0 +1,52 @@ + + + + + + org.apache.maven.repository.configuration.ConfigurationStore + default + org.apache.maven.repository.configuration.DefaultConfigurationStore + + ${basedir}/src/test/conf/repository-manager.xml + + + + org.apache.maven.repository.configuration.ConfigurationStore + corrupt-file + org.apache.maven.repository.configuration.DefaultConfigurationStore + + ${basedir}/src/test/conf/corrupt.xml + + + + org.apache.maven.repository.configuration.ConfigurationStore + invalid-file + org.apache.maven.repository.configuration.DefaultConfigurationStore + + ${basedir}/src/test/conf/nada.txt + + + + org.apache.maven.repository.configuration.ConfigurationStore + save-file + org.apache.maven.repository.configuration.DefaultConfigurationStore + + ${basedir}/target/test/test-file.xml + + + + diff --git a/archiva-converter/pom.xml b/archiva-converter/pom.xml new file mode 100644 index 000000000..5de65c928 --- /dev/null +++ b/archiva-converter/pom.xml @@ -0,0 +1,50 @@ + + + + + org.apache.maven.archiva + archiva + 1.0-SNAPSHOT + + 4.0.0 + archiva-converter + Archiva Repository Converter + + + org.codehaus.plexus + plexus-utils + + + org.apache.maven + maven-artifact + + + org.apache.maven + maven-model-converter + + + org.apache.maven.archiva + archiva-reports-standard + + + org.codehaus.plexus + plexus-i18n + 1.0-beta-6 + + + diff --git a/archiva-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java b/archiva-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java new file mode 100644 index 000000000..86078ef6b --- /dev/null +++ b/archiva-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java @@ -0,0 +1,661 @@ +package org.apache.maven.repository.converter; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Metadata; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Snapshot; +import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Versioning; +import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; +import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer; +import org.apache.maven.model.DistributionManagement; +import org.apache.maven.model.Model; +import org.apache.maven.model.Relocation; +import org.apache.maven.model.converter.ArtifactPomRewriter; +import org.apache.maven.model.converter.ModelConverter; +import org.apache.maven.model.converter.PomTranslationException; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader; +import org.apache.maven.repository.converter.transaction.FileTransaction; +import org.apache.maven.repository.digest.Digester; +import org.apache.maven.repository.digest.DigesterException; +import org.apache.maven.repository.reporting.ArtifactReporter; +import org.codehaus.plexus.i18n.I18N; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Properties; +import java.util.regex.Matcher; + +/** + * Implementation of repository conversion class. + * + * @author Brett Porter + * @plexus.component role="org.apache.maven.repository.converter.RepositoryConverter" role-hint="default" + */ +public class DefaultRepositoryConverter + implements RepositoryConverter +{ + /** + * @plexus.requirement role-hint="sha1" + */ + private Digester sha1Digester; + + /** + * @plexus.requirement role-hint="md5" + */ + private Digester md5Digester; + + /** + * @plexus.requirement + */ + private ArtifactFactory artifactFactory; + + /** + * @plexus.requirement + */ + private ArtifactPomRewriter rewriter; + + /** + * @plexus.requirement + */ + private ModelConverter translator; + + /** + * @plexus.configuration default-value="false" + */ + private boolean force; + + /** + * @plexus.configuration default-value="false" + */ + private boolean dryrun; + + /** + * @plexus.requirement + */ + private I18N i18n; + + public void convert( Artifact artifact, ArtifactRepository targetRepository, ArtifactReporter reporter ) + throws RepositoryConversionException + { + if ( artifact.getRepository().getUrl().equals( targetRepository.getUrl() ) ) + { + throw new RepositoryConversionException( getI18NString( "exception.repositories.match" ) ); + } + + if ( validateMetadata( artifact, reporter ) ) + { + FileTransaction transaction = new FileTransaction(); + + if ( copyPom( artifact, targetRepository, reporter, transaction ) ) + { + if ( copyArtifact( artifact, targetRepository, reporter, transaction ) ) + { + Metadata metadata = createBaseMetadata( artifact ); + Versioning versioning = new Versioning(); + versioning.addVersion( artifact.getBaseVersion() ); + metadata.setVersioning( versioning ); + updateMetadata( new ArtifactRepositoryMetadata( artifact ), targetRepository, metadata, + transaction ); + + metadata = createBaseMetadata( artifact ); + metadata.setVersion( artifact.getBaseVersion() ); + versioning = new Versioning(); + + Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( artifact.getVersion() ); + if ( matcher.matches() ) + { + Snapshot snapshot = new Snapshot(); + snapshot.setBuildNumber( Integer.valueOf( matcher.group( 3 ) ).intValue() ); + snapshot.setTimestamp( matcher.group( 2 ) ); + versioning.setSnapshot( snapshot ); + } + + // TODO: merge latest/release/snapshot from source instead + metadata.setVersioning( versioning ); + updateMetadata( new SnapshotArtifactRepositoryMetadata( artifact ), targetRepository, metadata, + transaction ); + + if ( !dryrun ) + { + transaction.commit(); + } + reporter.addSuccess( artifact ); + } + } + } + } + + private static Metadata createBaseMetadata( Artifact artifact ) + { + Metadata metadata = new Metadata(); + metadata.setArtifactId( artifact.getArtifactId() ); + metadata.setGroupId( artifact.getGroupId() ); + return metadata; + } + + private void updateMetadata( RepositoryMetadata artifactMetadata, ArtifactRepository targetRepository, + Metadata newMetadata, FileTransaction transaction ) + throws RepositoryConversionException + { + File file = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); + + Metadata metadata; + boolean changed; + + if ( file.exists() ) + { + metadata = readMetadata( file ); + changed = metadata.merge( newMetadata ); + } + else + { + changed = true; + metadata = newMetadata; + } + + if ( changed ) + { + StringWriter writer = null; + try + { + writer = new StringWriter(); + + MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer(); + + mappingWriter.write( writer, metadata ); + + transaction.createFile( writer.toString(), file ); + } + catch ( IOException e ) + { + throw new RepositoryConversionException( "Error writing target metadata", e ); + } + finally + { + IOUtil.close( writer ); + } + } + } + + private Metadata readMetadata( File file ) + throws RepositoryConversionException + { + Metadata metadata; + MetadataXpp3Reader reader = new MetadataXpp3Reader(); + FileReader fileReader = null; + try + { + fileReader = new FileReader( file ); + metadata = reader.read( fileReader ); + } + catch ( FileNotFoundException e ) + { + throw new RepositoryConversionException( "Error reading target metadata", e ); + } + catch ( IOException e ) + { + throw new RepositoryConversionException( "Error reading target metadata", e ); + } + catch ( XmlPullParserException e ) + { + throw new RepositoryConversionException( "Error reading target metadata", e ); + } + finally + { + IOUtil.close( fileReader ); + } + return metadata; + } + + private boolean validateMetadata( Artifact artifact, ArtifactReporter reporter ) + throws RepositoryConversionException + { + ArtifactRepository repository = artifact.getRepository(); + + boolean result = true; + + RepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact ); + File file = + new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) ); + if ( file.exists() ) + { + Metadata metadata = readMetadata( file ); + result = validateMetadata( metadata, repositoryMetadata, artifact, reporter ); + } + + repositoryMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); + file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) ); + if ( file.exists() ) + { + Metadata metadata = readMetadata( file ); + result = result && validateMetadata( metadata, repositoryMetadata, artifact, reporter ); + } + + return result; + } + + private boolean validateMetadata( Metadata metadata, RepositoryMetadata repositoryMetadata, Artifact artifact, + ArtifactReporter reporter ) + { + String groupIdKey; + String artifactIdKey = null; + String snapshotKey = null; + String versionKey = null; + String versionsKey = null; + if ( repositoryMetadata.storedInGroupDirectory() ) + { + groupIdKey = "failure.incorrect.groupMetadata.groupId"; + } + else if ( repositoryMetadata.storedInArtifactVersionDirectory() ) + { + groupIdKey = "failure.incorrect.snapshotMetadata.groupId"; + artifactIdKey = "failure.incorrect.snapshotMetadata.artifactId"; + versionKey = "failure.incorrect.snapshotMetadata.version"; + snapshotKey = "failure.incorrect.snapshotMetadata.snapshot"; + } + else + { + groupIdKey = "failure.incorrect.artifactMetadata.groupId"; + artifactIdKey = "failure.incorrect.artifactMetadata.artifactId"; + versionsKey = "failure.incorrect.artifactMetadata.versions"; + } + + boolean result = true; + + if ( !metadata.getGroupId().equals( artifact.getGroupId() ) ) + { + reporter.addFailure( artifact, getI18NString( groupIdKey ) ); + result = false; + } + if ( !repositoryMetadata.storedInGroupDirectory() ) + { + if ( !metadata.getArtifactId().equals( artifact.getArtifactId() ) ) + { + reporter.addFailure( artifact, getI18NString( artifactIdKey ) ); + result = false; + } + if ( !repositoryMetadata.storedInArtifactVersionDirectory() ) + { + // artifact metadata + + boolean foundVersion = false; + if ( metadata.getVersioning() != null ) + { + for ( Iterator i = metadata.getVersioning().getVersions().iterator(); + i.hasNext() && !foundVersion; ) + { + String version = (String) i.next(); + if ( version.equals( artifact.getBaseVersion() ) ) + { + foundVersion = true; + } + } + } + + if ( !foundVersion ) + { + reporter.addFailure( artifact, getI18NString( versionsKey ) ); + result = false; + } + } + else + { + // snapshot metadata + if ( !artifact.getBaseVersion().equals( metadata.getVersion() ) ) + { + reporter.addFailure( artifact, getI18NString( versionKey ) ); + result = false; + } + + if ( artifact.isSnapshot() ) + { + Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( artifact.getVersion() ); + if ( matcher.matches() ) + { + boolean correct = false; + if ( metadata.getVersioning() != null && metadata.getVersioning().getSnapshot() != null ) + { + Snapshot snapshot = metadata.getVersioning().getSnapshot(); + int build = Integer.valueOf( matcher.group( 3 ) ).intValue(); + String ts = matcher.group( 2 ); + if ( build == snapshot.getBuildNumber() && ts.equals( snapshot.getTimestamp() ) ) + { + correct = true; + } + } + + if ( !correct ) + { + reporter.addFailure( artifact, getI18NString( snapshotKey ) ); + result = false; + } + } + } + } + } + return result; + } + + private boolean copyPom( Artifact artifact, ArtifactRepository targetRepository, ArtifactReporter reporter, + FileTransaction transaction ) + throws RepositoryConversionException + { + Artifact pom = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), + artifact.getVersion() ); + pom.setBaseVersion( artifact.getBaseVersion() ); + ArtifactRepository repository = artifact.getRepository(); + File file = new File( repository.getBasedir(), repository.pathOf( pom ) ); + + boolean result = true; + if ( file.exists() ) + { + File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pom ) ); + + String contents = null; + boolean checksumsValid = false; + try + { + if ( testChecksums( artifact, file, reporter ) ) + { + checksumsValid = true; + contents = FileUtils.fileRead( file ); + } + } + catch ( IOException e ) + { + throw new RepositoryConversionException( "Unable to read source POM: " + e.getMessage(), e ); + } + + if ( checksumsValid && contents.indexOf( "modelVersion" ) >= 0 ) + { + // v4 POM + try + { + boolean matching = false; + if ( !force && targetFile.exists() ) + { + String targetContents = FileUtils.fileRead( targetFile ); + matching = targetContents.equals( contents ); + } + if ( force || !matching ) + { + transaction.createFile( contents, targetFile ); + } + } + catch ( IOException e ) + { + throw new RepositoryConversionException( "Unable to write target POM: " + e.getMessage(), e ); + } + } + else + { + // v3 POM + StringReader stringReader = new StringReader( contents ); + StringWriter writer = null; + try + { + MavenXpp3Reader v3Reader = new MavenXpp3Reader(); + org.apache.maven.model.v3_0_0.Model v3Model = v3Reader.read( stringReader ); + + if ( doRelocation( artifact, v3Model, targetRepository, transaction ) ) + { + Artifact relocatedPom = artifactFactory.createProjectArtifact( artifact.getGroupId(), + artifact.getArtifactId(), + artifact.getVersion() ); + targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( relocatedPom ) ); + } + + Model v4Model = translator.translate( v3Model ); + + translator.validateV4Basics( v4Model, v3Model.getGroupId(), v3Model.getArtifactId(), + v3Model.getVersion(), v3Model.getPackage() ); + + writer = new StringWriter(); + MavenXpp3Writer Xpp3Writer = new MavenXpp3Writer(); + Xpp3Writer.write( writer, v4Model ); + + transaction.createFile( writer.toString(), targetFile ); + + List warnings = translator.getWarnings(); + + for ( Iterator i = warnings.iterator(); i.hasNext(); ) + { + String message = (String) i.next(); + reporter.addWarning( artifact, message ); + } + } + catch ( XmlPullParserException e ) + { + reporter.addFailure( artifact, getI18NString( "failure.invalid.source.pom", e.getMessage() ) ); + result = false; + } + catch ( IOException e ) + { + throw new RepositoryConversionException( "Unable to write converted POM", e ); + } + catch ( PomTranslationException e ) + { + reporter.addFailure( artifact, getI18NString( "failure.invalid.source.pom", e.getMessage() ) ); + result = false; + } + finally + { + IOUtil.close( writer ); + } + } + } + else + { + reporter.addWarning( artifact, getI18NString( "warning.missing.pom" ) ); + } + return result; + } + + private boolean doRelocation( Artifact artifact, org.apache.maven.model.v3_0_0.Model v3Model, + ArtifactRepository repository, FileTransaction transaction ) + throws IOException + { + Properties properties = v3Model.getProperties(); + if ( properties.containsKey( "relocated.groupId" ) || properties.containsKey( "relocated.artifactId" ) || + properties.containsKey( "relocated.version" ) ) + { + String newGroupId = properties.getProperty( "relocated.groupId", v3Model.getGroupId() ); + properties.remove( "relocated.groupId" ); + + String newArtifactId = properties.getProperty( "relocated.artifactId", v3Model.getArtifactId() ); + properties.remove( "relocated.artifactId" ); + + String newVersion = properties.getProperty( "relocated.version", v3Model.getVersion() ); + properties.remove( "relocated.version" ); + + String message = properties.getProperty( "relocated.message", "" ); + properties.remove( "relocated.message" ); + + if ( properties.isEmpty() ) + { + v3Model.setProperties( null ); + } + + writeRelocationPom( v3Model.getGroupId(), v3Model.getArtifactId(), v3Model.getVersion(), newGroupId, + newArtifactId, newVersion, message, repository, transaction ); + + v3Model.setGroupId( newGroupId ); + v3Model.setArtifactId( newArtifactId ); + v3Model.setVersion( newVersion ); + + artifact.setGroupId( newGroupId ); + artifact.setArtifactId( newArtifactId ); + artifact.setVersion( newVersion ); + + return true; + } + else + { + return false; + } + } + + private void writeRelocationPom( String groupId, String artifactId, String version, String newGroupId, + String newArtifactId, String newVersion, String message, + ArtifactRepository repository, FileTransaction transaction ) + throws IOException + { + Model pom = new Model(); + pom.setGroupId( groupId ); + pom.setArtifactId( artifactId ); + pom.setVersion( version ); + + DistributionManagement dMngt = new DistributionManagement(); + + Relocation relocation = new Relocation(); + relocation.setGroupId( newGroupId ); + relocation.setArtifactId( newArtifactId ); + relocation.setVersion( newVersion ); + if ( message != null && message.length() > 0 ) + { + relocation.setMessage( message ); + } + + dMngt.setRelocation( relocation ); + + pom.setDistributionManagement( dMngt ); + + Artifact artifact = artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" ); + File pomFile = new File( repository.getBasedir(), repository.pathOf( artifact ) ); + + StringWriter strWriter = new StringWriter(); + MavenXpp3Writer pomWriter = new MavenXpp3Writer(); + pomWriter.write( strWriter, pom ); + + transaction.createFile( strWriter.toString(), pomFile ); + } + + private String getI18NString( String key, String arg0 ) + { + return i18n.format( getClass().getName(), Locale.getDefault(), key, arg0 ); + } + + private String getI18NString( String key ) + { + return i18n.getString( getClass().getName(), Locale.getDefault(), key ); + } + + private boolean testChecksums( Artifact artifact, File file, ArtifactReporter reporter ) + throws IOException + { + + boolean result = + verifyChecksum( file, file.getName() + ".md5", md5Digester, reporter, artifact, "failure.incorrect.md5" ); + result = result && verifyChecksum( file, file.getName() + ".sha1", sha1Digester, reporter, artifact, + "failure.incorrect.sha1" ); + return result; + } + + private boolean verifyChecksum( File file, String fileName, Digester digester, ArtifactReporter reporter, + Artifact artifact, String key ) + throws IOException + { + boolean result = true; + + File checksumFile = new File( file.getParentFile(), fileName ); + if ( checksumFile.exists() ) + { + String checksum = FileUtils.fileRead( checksumFile ); + try + { + digester.verify( file, checksum ); + } + catch ( DigesterException e ) + { + reporter.addFailure( artifact, getI18NString( key ) ); + result = false; + } + } + return result; + } + + private boolean copyArtifact( Artifact artifact, ArtifactRepository targetRepository, ArtifactReporter reporter, + FileTransaction transaction ) + throws RepositoryConversionException + { + File sourceFile = artifact.getFile(); + + File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + + boolean result = true; + try + { + boolean matching = false; + if ( !force && targetFile.exists() ) + { + matching = FileUtils.contentEquals( sourceFile, targetFile ); + if ( !matching ) + { + reporter.addFailure( artifact, getI18NString( "failure.target.already.exists" ) ); + result = false; + } + } + if ( result ) + { + if ( force || !matching ) + { + if ( testChecksums( artifact, sourceFile, reporter ) ) + { + transaction.copyFile( sourceFile, targetFile ); + } + else + { + result = false; + } + } + } + } + catch ( IOException e ) + { + throw new RepositoryConversionException( "Error copying artifact", e ); + } + return result; + } + + public void convert( List artifacts, ArtifactRepository targetRepository, ArtifactReporter reporter ) + throws RepositoryConversionException + { + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + convert( artifact, targetRepository, reporter ); + } + } +} diff --git a/archiva-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConversionException.java b/archiva-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConversionException.java new file mode 100644 index 000000000..2409235bb --- /dev/null +++ b/archiva-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConversionException.java @@ -0,0 +1,36 @@ +package org.apache.maven.repository.converter; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * Exception occuring during repository conversion. + * + * @author Brett Porter + */ +public class RepositoryConversionException + extends Exception +{ + public RepositoryConversionException( String message ) + { + super( message ); + } + + public RepositoryConversionException( String message, Throwable cause ) + { + super( message, cause ); + } +} diff --git a/archiva-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConverter.java b/archiva-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConverter.java new file mode 100644 index 000000000..cf6e1b151 --- /dev/null +++ b/archiva-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConverter.java @@ -0,0 +1,54 @@ +package org.apache.maven.repository.converter; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.repository.reporting.ArtifactReporter; + +import java.util.List; +import java.io.File; + +/** + * Copy a set of artifacts from one repository to the other, converting if necessary. + * + * @author Brett Porter + */ +public interface RepositoryConverter +{ + String ROLE = RepositoryConverter.class.getName(); + + /** + * Convert a single artifact, writing it into the target repository. + * + * @param artifact the artifact to convert + * @param targetRepository the target repository + * @param reporter reporter to track the results of the conversion + */ + void convert( Artifact artifact, ArtifactRepository targetRepository, ArtifactReporter reporter ) + throws RepositoryConversionException; + + /** + * Convert a set of artifacts, writing them into the target repository. + * + * @param artifacts the set of artifacts to convert + * @param targetRepository the target repository + * @param reporter reporter to track the results of the conversions + */ + void convert( List artifacts, ArtifactRepository targetRepository, ArtifactReporter reporter ) + throws RepositoryConversionException; +} diff --git a/archiva-converter/src/main/java/org/apache/maven/repository/converter/transaction/AbstractTransactionEvent.java b/archiva-converter/src/main/java/org/apache/maven/repository/converter/transaction/AbstractTransactionEvent.java new file mode 100644 index 000000000..521930a28 --- /dev/null +++ b/archiva-converter/src/main/java/org/apache/maven/repository/converter/transaction/AbstractTransactionEvent.java @@ -0,0 +1,120 @@ +package org.apache.maven.repository.converter.transaction; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.util.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.ArrayList; + +/** + * Abstract class for the TransactionEvents + * + * @author Edwin Punzalan + */ +public abstract class AbstractTransactionEvent + implements TransactionEvent +{ + private File backup; + + private List createdDirs; + + /** + * Method that creates a directory as well as all the parent directories needed + * + * @param dir The File directory to be created + * @throws IOException when an unrecoverable error occurred + */ + protected void mkDirs( File dir ) + throws IOException + { + List createDirs = new ArrayList(); + + File parent = dir; + while( !parent.exists() || !parent.isDirectory() ) + { + createDirs.add( parent ); + + parent = parent.getParentFile(); + } + + createdDirs = new ArrayList(); + + while ( !createDirs.isEmpty() ) + { + File directory = (File) createDirs.remove( createDirs.size() - 1 ); + + if ( directory.mkdir() ) + { + createdDirs.add( directory ); + } + else + { + throw new IOException( "Failed to create directory: " + directory.getAbsolutePath() ); + } + } + } + + protected void revertMkDirs() + throws IOException + { + if ( createdDirs != null ) + { + Collections.reverse( createdDirs ); + + while( !createdDirs.isEmpty() ) + { + File dir = (File) createdDirs.remove( 0 ); + + if ( dir.isDirectory() && dir.list().length == 0 ) + { + FileUtils.deleteDirectory( dir.getAbsolutePath() ); + } + else + { + //cannot rollback created directory if it still contains files + break; + } + } + } + } + + protected void createBackup( File file ) + throws IOException + { + if ( file.exists() && file.isFile() ) + { + backup = File.createTempFile( "temp-", ".backup" ); + + FileUtils.copyFile( file, backup ); + + backup.deleteOnExit(); + } + } + + protected void restoreBackup( File file ) + throws IOException + { + if ( backup != null ) + { + FileUtils.copyFile( backup, file ); + } + } +} diff --git a/archiva-converter/src/main/java/org/apache/maven/repository/converter/transaction/CopyFileEvent.java b/archiva-converter/src/main/java/org/apache/maven/repository/converter/transaction/CopyFileEvent.java new file mode 100644 index 000000000..cddc854cc --- /dev/null +++ b/archiva-converter/src/main/java/org/apache/maven/repository/converter/transaction/CopyFileEvent.java @@ -0,0 +1,61 @@ +package org.apache.maven.repository.converter.transaction; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.util.FileUtils; + +import java.io.File; +import java.io.IOException; + +/** + * Event to copy a file. + * + * @author Brett Porter + */ +public class CopyFileEvent + extends AbstractTransactionEvent +{ + private final File source; + + private final File destination; + + public CopyFileEvent( File source, File destination ) + { + this.source = source; + this.destination = destination; + } + + public void commit() + throws IOException + { + createBackup( destination ); + + mkDirs( destination.getParentFile() ); + + FileUtils.copyFile( source, destination ); + } + + public void rollback() + throws IOException + { + FileUtils.fileDelete( destination.getAbsolutePath() ); + + revertMkDirs(); + + restoreBackup( destination ); + } +} diff --git a/archiva-converter/src/main/java/org/apache/maven/repository/converter/transaction/CreateFileEvent.java b/archiva-converter/src/main/java/org/apache/maven/repository/converter/transaction/CreateFileEvent.java new file mode 100644 index 000000000..283ee60fd --- /dev/null +++ b/archiva-converter/src/main/java/org/apache/maven/repository/converter/transaction/CreateFileEvent.java @@ -0,0 +1,66 @@ +package org.apache.maven.repository.converter.transaction; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.util.FileUtils; + +import java.io.File; +import java.io.IOException; + +/** + * Event for creating a file from a string content. + * + * @author Brett Porter + */ +public class CreateFileEvent + extends AbstractTransactionEvent +{ + private final File destination; + + private final String content; + + public CreateFileEvent( String content, File destination ) + { + this.content = content; + this.destination = destination; + } + + public void commit() + throws IOException + { + createBackup( destination ); + + mkDirs( destination.getParentFile() ); + + if ( !destination.exists() && !destination.createNewFile() ) + { + throw new IOException( "Unable to create new file" ); + } + + FileUtils.fileWrite( destination.getAbsolutePath(), content ); + } + + public void rollback() + throws IOException + { + FileUtils.fileDelete( destination.getAbsolutePath() ); + + revertMkDirs(); + + restoreBackup( destination ); + } +} diff --git a/archiva-converter/src/main/java/org/apache/maven/repository/converter/transaction/FileTransaction.java b/archiva-converter/src/main/java/org/apache/maven/repository/converter/transaction/FileTransaction.java new file mode 100644 index 000000000..ceb368660 --- /dev/null +++ b/archiva-converter/src/main/java/org/apache/maven/repository/converter/transaction/FileTransaction.java @@ -0,0 +1,89 @@ +package org.apache.maven.repository.converter.transaction; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.repository.converter.RepositoryConversionException; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * Implement commit/rollback semantics for a set of files. + * + * @author Brett Porter + */ +public class FileTransaction +{ + private List events = new ArrayList(); + + public void commit() + throws RepositoryConversionException + { + List toRollback = new ArrayList( events.size() ); + + for ( Iterator i = events.iterator(); i.hasNext(); ) + { + TransactionEvent event = (TransactionEvent) i.next(); + + try + { + event.commit(); + + toRollback.add( event ); + } + catch ( IOException e ) + { + try + { + rollback( toRollback ); + + throw new RepositoryConversionException( "Unable to commit file transaction", e ); + } + catch ( IOException ioe ) + { + throw new RepositoryConversionException( + "Unable to commit file transaction, and rollback failed with error: '" + ioe.getMessage() + "'", + e ); + } + } + } + } + + private void rollback( List toRollback ) + throws IOException + { + for ( Iterator i = toRollback.iterator(); i.hasNext(); ) + { + TransactionEvent event = (TransactionEvent) i.next(); + + event.rollback(); + } + } + + public void copyFile( File source, File destination ) + { + events.add( new CopyFileEvent( source, destination ) ); + } + + public void createFile( String content, File destination ) + { + events.add( new CreateFileEvent( content, destination ) ); + } +} diff --git a/archiva-converter/src/main/java/org/apache/maven/repository/converter/transaction/TransactionEvent.java b/archiva-converter/src/main/java/org/apache/maven/repository/converter/transaction/TransactionEvent.java new file mode 100644 index 000000000..2f8a528e4 --- /dev/null +++ b/archiva-converter/src/main/java/org/apache/maven/repository/converter/transaction/TransactionEvent.java @@ -0,0 +1,43 @@ +package org.apache.maven.repository.converter.transaction; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 java.io.IOException; + +/** + * Interface for individual events in a transaction. + * + * @author Brett Porter + */ +public interface TransactionEvent +{ + /** + * Commit this event. + * + * @throws IOException if an error occurred committing the change + */ + void commit() + throws IOException; + + /** + * Rollback the even already committed. + * + * @throws IOException if an error occurred reverting the change + */ + void rollback() + throws IOException; +} diff --git a/archiva-converter/src/main/resources/org/apache/maven/repository/converter/DefaultRepositoryConverter.properties b/archiva-converter/src/main/resources/org/apache/maven/repository/converter/DefaultRepositoryConverter.properties new file mode 100644 index 000000000..f6089c1f5 --- /dev/null +++ b/archiva-converter/src/main/resources/org/apache/maven/repository/converter/DefaultRepositoryConverter.properties @@ -0,0 +1,35 @@ +# +# Copyright 2005-2006 The Apache Software Foundation. +# +# Licensed 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. +# + +failure.incorrect.md5=The MD5 checksum value was incorrect. +failure.incorrect.sha1=The SHA1 checksum value was incorrect. +failure.target.already.exists=The artifact could not be converted because it already exists. +failure.invalid.source.pom=The source POM was invalid: {0}. + +warning.missing.pom=The artifact had no POM in the source repository. + +exception.repositories.match=Source and target repositories are identical. + +failure.incorrect.groupMetadata.groupId=The group ID in the source group metadata is incorrect. + +failure.incorrect.artifactMetadata.artifactId=The artifact ID in the source artifact metadata is incorrect. +failure.incorrect.artifactMetadata.groupId=The group ID in the source artifact metadata is incorrect. +failure.incorrect.artifactMetadata.versions=The version list in the source artifact metadata is incorrect. + +failure.incorrect.snapshotMetadata.artifactId=The artifact ID in the source artifact version metadata is incorrect. +failure.incorrect.snapshotMetadata.groupId=The group ID in the source artifact version metadata is incorrect. +failure.incorrect.snapshotMetadata.version=The version in the source artifact version metadata is incorrect. +failure.incorrect.snapshotMetadata.snapshot=The snapshot information in the source artifact version metadata is incorrect. diff --git a/archiva-converter/src/test/expected-files/converted-artifact-one.pom b/archiva-converter/src/test/expected-files/converted-artifact-one.pom new file mode 100644 index 000000000..cd3862d35 --- /dev/null +++ b/archiva-converter/src/test/expected-files/converted-artifact-one.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + artifact-one + 1.0.0 + diff --git a/archiva-converter/src/test/expected-files/converted-artifact-three.pom b/archiva-converter/src/test/expected-files/converted-artifact-three.pom new file mode 100644 index 000000000..343291037 --- /dev/null +++ b/archiva-converter/src/test/expected-files/converted-artifact-three.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + artifact-three + 1.0.0 + diff --git a/archiva-converter/src/test/expected-files/converted-artifact-two.pom b/archiva-converter/src/test/expected-files/converted-artifact-two.pom new file mode 100644 index 000000000..227470167 --- /dev/null +++ b/archiva-converter/src/test/expected-files/converted-artifact-two.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + artifact-two + 1.0.0 + diff --git a/archiva-converter/src/test/expected-files/converted-v3-snapshot.pom b/archiva-converter/src/test/expected-files/converted-v3-snapshot.pom new file mode 100644 index 000000000..9134c3cdf --- /dev/null +++ b/archiva-converter/src/test/expected-files/converted-v3-snapshot.pom @@ -0,0 +1,22 @@ + + 4.0.0 + test + v3artifact + 1.0.0-SNAPSHOT + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + + + groupId + artifactId + version + + + groupId + test-artifactId + version + test + + + diff --git a/archiva-converter/src/test/expected-files/converted-v3-timestamped-snapshot.pom b/archiva-converter/src/test/expected-files/converted-v3-timestamped-snapshot.pom new file mode 100644 index 000000000..46eacaf2e --- /dev/null +++ b/archiva-converter/src/test/expected-files/converted-v3-timestamped-snapshot.pom @@ -0,0 +1,22 @@ + + 4.0.0 + test + v3artifact + 1.0.0-20060105.130101-3 + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + + + groupId + artifactId + version + + + groupId + test-artifactId + version + test + + + diff --git a/archiva-converter/src/test/expected-files/converted-v3-warnings.pom b/archiva-converter/src/test/expected-files/converted-v3-warnings.pom new file mode 100644 index 000000000..e07664932 --- /dev/null +++ b/archiva-converter/src/test/expected-files/converted-v3-warnings.pom @@ -0,0 +1,22 @@ + + 4.0.0 + test + v3-warnings-artifact + 1.0.0 + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + + + groupId + artifactId + version + + + groupId + test-artifactId + version + test + + + diff --git a/archiva-converter/src/test/expected-files/converted-v3.pom b/archiva-converter/src/test/expected-files/converted-v3.pom new file mode 100644 index 000000000..29ba92771 --- /dev/null +++ b/archiva-converter/src/test/expected-files/converted-v3.pom @@ -0,0 +1,22 @@ + + 4.0.0 + test + v3artifact + 1.0.0 + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + + + groupId + artifactId + version + + + groupId + test-artifactId + version + test + + + diff --git a/archiva-converter/src/test/expected-files/newversion-artifact-metadata.xml b/archiva-converter/src/test/expected-files/newversion-artifact-metadata.xml new file mode 100644 index 000000000..ecc7f09a0 --- /dev/null +++ b/archiva-converter/src/test/expected-files/newversion-artifact-metadata.xml @@ -0,0 +1,10 @@ + + test + newversion-artifact + + + 1.0.0 + 1.0.1 + + + diff --git a/archiva-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/maven-metadata.xml b/archiva-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/maven-metadata.xml new file mode 100644 index 000000000..ebd9be970 --- /dev/null +++ b/archiva-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/maven-metadata.xml @@ -0,0 +1,6 @@ + + relocated-test + relocated-v3artifact + 1.0.0 + + \ No newline at end of file diff --git a/archiva-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.jar b/archiva-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.pom b/archiva-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.pom new file mode 100644 index 000000000..253ef3466 --- /dev/null +++ b/archiva-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.pom @@ -0,0 +1,22 @@ + + 4.0.0 + relocated-test + relocated-v3artifact + 1.0.0 + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + + + groupId + artifactId + version + + + groupId + test-artifactId + version + test + + + \ No newline at end of file diff --git a/archiva-converter/src/test/expected-files/relocated-test/relocated-v3artifact/maven-metadata.xml b/archiva-converter/src/test/expected-files/relocated-test/relocated-v3artifact/maven-metadata.xml new file mode 100644 index 000000000..b4b1a864a --- /dev/null +++ b/archiva-converter/src/test/expected-files/relocated-test/relocated-v3artifact/maven-metadata.xml @@ -0,0 +1,9 @@ + + relocated-test + relocated-v3artifact + + + 1.0.0 + + + \ No newline at end of file diff --git a/archiva-converter/src/test/expected-files/test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.pom b/archiva-converter/src/test/expected-files/test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.pom new file mode 100644 index 000000000..b20f62f9e --- /dev/null +++ b/archiva-converter/src/test/expected-files/test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.pom @@ -0,0 +1,12 @@ + + test + relocated-v3artifact + 1.0.0 + + + relocated-test + relocated-v3artifact + 1.0.0 + + + \ No newline at end of file diff --git a/archiva-converter/src/test/expected-files/v3-artifact-metadata.xml b/archiva-converter/src/test/expected-files/v3-artifact-metadata.xml new file mode 100644 index 000000000..a8a7f3748 --- /dev/null +++ b/archiva-converter/src/test/expected-files/v3-artifact-metadata.xml @@ -0,0 +1,9 @@ + + test + v3artifact + + + 1.0.0 + + + diff --git a/archiva-converter/src/test/expected-files/v3-snapshot-artifact-metadata.xml b/archiva-converter/src/test/expected-files/v3-snapshot-artifact-metadata.xml new file mode 100644 index 000000000..24d25a0e0 --- /dev/null +++ b/archiva-converter/src/test/expected-files/v3-snapshot-artifact-metadata.xml @@ -0,0 +1,9 @@ + + test + v3artifact + + + 1.0.0-SNAPSHOT + + + diff --git a/archiva-converter/src/test/expected-files/v3-snapshot-metadata.xml b/archiva-converter/src/test/expected-files/v3-snapshot-metadata.xml new file mode 100644 index 000000000..b19c537b5 --- /dev/null +++ b/archiva-converter/src/test/expected-files/v3-snapshot-metadata.xml @@ -0,0 +1,6 @@ + + test + v3artifact + 1.0.0-SNAPSHOT + + diff --git a/archiva-converter/src/test/expected-files/v3-timestamped-snapshot-metadata.xml b/archiva-converter/src/test/expected-files/v3-timestamped-snapshot-metadata.xml new file mode 100644 index 000000000..602c38ec8 --- /dev/null +++ b/archiva-converter/src/test/expected-files/v3-timestamped-snapshot-metadata.xml @@ -0,0 +1,11 @@ + + test + v3artifact + 1.0.0-SNAPSHOT + + + 20060105.130101 + 3 + + + diff --git a/archiva-converter/src/test/expected-files/v3-version-metadata.xml b/archiva-converter/src/test/expected-files/v3-version-metadata.xml new file mode 100644 index 000000000..3c8938984 --- /dev/null +++ b/archiva-converter/src/test/expected-files/v3-version-metadata.xml @@ -0,0 +1,6 @@ + + test + v3artifact + 1.0.0 + + diff --git a/archiva-converter/src/test/expected-files/v4-artifact-metadata.xml b/archiva-converter/src/test/expected-files/v4-artifact-metadata.xml new file mode 100644 index 000000000..c0cdbfdb4 --- /dev/null +++ b/archiva-converter/src/test/expected-files/v4-artifact-metadata.xml @@ -0,0 +1,9 @@ + + test + v4artifact + + + 1.0.0 + + + diff --git a/archiva-converter/src/test/expected-files/v4-snapshot-artifact-metadata.xml b/archiva-converter/src/test/expected-files/v4-snapshot-artifact-metadata.xml new file mode 100644 index 000000000..f8072b0df --- /dev/null +++ b/archiva-converter/src/test/expected-files/v4-snapshot-artifact-metadata.xml @@ -0,0 +1,9 @@ + + test + v4artifact + + + 1.0.0-SNAPSHOT + + + diff --git a/archiva-converter/src/test/expected-files/v4-snapshot-metadata.xml b/archiva-converter/src/test/expected-files/v4-snapshot-metadata.xml new file mode 100644 index 000000000..d5ecb7d47 --- /dev/null +++ b/archiva-converter/src/test/expected-files/v4-snapshot-metadata.xml @@ -0,0 +1,6 @@ + + test + v4artifact + 1.0.0-SNAPSHOT + + diff --git a/archiva-converter/src/test/expected-files/v4-timestamped-snapshot-metadata.xml b/archiva-converter/src/test/expected-files/v4-timestamped-snapshot-metadata.xml new file mode 100644 index 000000000..060a79cdd --- /dev/null +++ b/archiva-converter/src/test/expected-files/v4-timestamped-snapshot-metadata.xml @@ -0,0 +1,11 @@ + + test + v4artifact + 1.0.0-SNAPSHOT + + + 20060111.120115 + 1 + + + diff --git a/archiva-converter/src/test/expected-files/v4-version-metadata.xml b/archiva-converter/src/test/expected-files/v4-version-metadata.xml new file mode 100644 index 000000000..7cbd8ad3d --- /dev/null +++ b/archiva-converter/src/test/expected-files/v4-version-metadata.xml @@ -0,0 +1,6 @@ + + test + v4artifact + 1.0.0 + + diff --git a/archiva-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java b/archiva-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java new file mode 100644 index 000000000..d7b83cf7e --- /dev/null +++ b/archiva-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java @@ -0,0 +1,947 @@ +package org.apache.maven.repository.converter; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; +import org.apache.maven.repository.reporting.ArtifactReporter; +import org.apache.maven.repository.reporting.ArtifactResult; +import org.apache.maven.repository.reporting.DefaultArtifactReporter; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.i18n.I18N; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.regex.Matcher; + +/** + * Test the repository converter. + * + * @author Brett Porter + * @todo what about deletions from the source repository? + * @todo use artifact-test instead + * @todo should reject if dependencies are missing - rely on reporting? + * @todo group metadata + */ +public class RepositoryConverterTest + extends PlexusTestCase +{ + private ArtifactRepository sourceRepository; + + private ArtifactRepository targetRepository; + + private RepositoryConverter repositoryConverter; + + private ArtifactFactory artifactFactory; + + private ArtifactReporter reporter; + + private static final int SLEEP_MILLIS = 100; + + private I18N i18n; + + protected void setUp() + throws Exception + { + super.setUp(); + + ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); + + File sourceBase = getTestFile( "src/test/source-repository" ); + sourceRepository = + factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null, null ); + + layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + + File targetBase = getTestFile( "target/test-target-repository" ); + copyDirectoryStructure( getTestFile( "src/test/target-repository" ), targetBase ); + + targetRepository = + factory.createArtifactRepository( "target", targetBase.toURL().toString(), layout, null, null ); + + repositoryConverter = (RepositoryConverter) lookup( RepositoryConverter.ROLE, "default" ); + + artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + + i18n = (I18N) lookup( I18N.ROLE ); + + reporter = new DefaultArtifactReporter(); + } + + private void copyDirectoryStructure( File sourceDirectory, File destinationDirectory ) + throws IOException + { + if ( !sourceDirectory.exists() ) + { + throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." ); + } + + File[] files = sourceDirectory.listFiles(); + + String sourcePath = sourceDirectory.getAbsolutePath(); + + for ( int i = 0; i < files.length; i++ ) + { + File file = files[i]; + + String dest = file.getAbsolutePath(); + + dest = dest.substring( sourcePath.length() + 1 ); + + File destination = new File( destinationDirectory, dest ); + + if ( file.isFile() ) + { + destination = destination.getParentFile(); + + FileUtils.copyFileToDirectory( file, destination ); + } + else if ( file.isDirectory() ) + { + if ( !".svn".equals( file.getName() ) ) + { + if ( !destination.exists() && !destination.mkdirs() ) + { + throw new IOException( + "Could not create destination directory '" + destination.getAbsolutePath() + "'." ); + } + copyDirectoryStructure( file, destination ); + } + } + else + { + throw new IOException( "Unknown file type: " + file.getAbsolutePath() ); + } + } + } + + public void testV4PomConvert() + throws IOException, RepositoryConversionException + { + // test that it is copied as is + + Artifact artifact = createArtifact( "test", "v4artifact", "1.0.0" ); + ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); + File artifactMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); + artifactMetadataFile.delete(); + + ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); + File versionMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); + versionMetadataFile.delete(); + + File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + artifactFile.delete(); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkSuccess(); + + assertTrue( "Check artifact created", artifactFile.exists() ); + assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); + + artifact = createPomArtifact( artifact ); + File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); + assertTrue( "Check POM created", pomFile.exists() ); + + compareFiles( sourcePomFile, pomFile ); + + assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() ); + + File expectedMetadataFile = getTestFile( "src/test/expected-files/v4-artifact-metadata.xml" ); + + compareFiles( expectedMetadataFile, artifactMetadataFile ); + + assertTrue( "Check snapshot metadata created", versionMetadataFile.exists() ); + + expectedMetadataFile = getTestFile( "src/test/expected-files/v4-version-metadata.xml" ); + + compareFiles( expectedMetadataFile, versionMetadataFile ); + } + + public void testV3PomConvert() + throws IOException, RepositoryConversionException + { + // test that the pom is coverted + + Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0" ); + ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); + File artifactMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); + artifactMetadataFile.delete(); + + ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); + File versionMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); + versionMetadataFile.delete(); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkSuccess(); + + File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + assertTrue( "Check artifact created", artifactFile.exists() ); + assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); + + artifact = createPomArtifact( artifact ); + File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3.pom" ); + assertTrue( "Check POM created", pomFile.exists() ); + + compareFiles( expectedPomFile, pomFile ); + + assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() ); + + File expectedMetadataFile = getTestFile( "src/test/expected-files/v3-artifact-metadata.xml" ); + + compareFiles( expectedMetadataFile, artifactMetadataFile ); + + assertTrue( "Check snapshot metadata created", versionMetadataFile.exists() ); + + expectedMetadataFile = getTestFile( "src/test/expected-files/v3-version-metadata.xml" ); + + compareFiles( expectedMetadataFile, versionMetadataFile ); + } + + public void testV3PomConvertWithRelocation() + throws RepositoryConversionException, IOException + { + Artifact artifact = createArtifact( "test", "relocated-v3artifact", "1.0.0" ); + ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); + File artifactMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); + artifactMetadataFile.delete(); + + ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); + File versionMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); + versionMetadataFile.delete(); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + //checkSuccess(); --> commented until MNG-2100 is fixed + + File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + assertTrue( "Check if relocated artifact created", artifactFile.exists() ); + assertTrue( "Check if relocated artifact matches", + FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); + Artifact pomArtifact = createArtifact( "relocated-test", "relocated-v3artifact", "1.0.0", "1.0.0", "pom" ); + File pomFile = getTestFile( "src/test/expected-files/" + targetRepository.pathOf( pomArtifact ) ); + File testFile = getTestFile( "target/test-target-repository/" + targetRepository.pathOf( pomArtifact ) ); + compareFiles( pomFile, testFile ); + + Artifact orig = createArtifact( "test", "relocated-v3artifact", "1.0.0", "1.0.0", "pom" ); + artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( orig ) ); + assertTrue( "Check if relocation artifact pom is created", artifactFile.exists() ); + testFile = getTestFile( "src/test/expected-files/" + targetRepository.pathOf( orig ) ); + compareFiles( artifactFile, testFile ); + } + + public void testV3PomWarningsOnConvert() + throws RepositoryConversionException, IOException + { + // test that the pom is converted but that warnings are reported + + Artifact artifact = createArtifact( "test", "v3-warnings-artifact", "1.0.0" ); + ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); + File artifactMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); + artifactMetadataFile.delete(); + + ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); + File versionMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); + versionMetadataFile.delete(); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + assertEquals( "check no errors", 0, reporter.getFailures() ); + assertEquals( "check number of warnings", 2, reporter.getWarnings() ); + assertEquals( "check success", 1, reporter.getSuccesses() ); + + File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + assertTrue( "Check artifact created", artifactFile.exists() ); + assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); + + artifact = createPomArtifact( artifact ); + File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3-warnings.pom" ); + assertTrue( "Check POM created", pomFile.exists() ); + + compareFiles( expectedPomFile, pomFile ); + + // TODO: check 2 warnings (extend and versions) matched on i18n key + } + + private void doTestV4SnapshotPomConvert( String version, String expectedMetadataFileName ) + throws RepositoryConversionException, IOException + { + // test that it is copied as is + + Artifact artifact = createArtifact( "test", "v4artifact", version ); + ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); + File artifactMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); + artifactMetadataFile.delete(); + + ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); + File snapshotMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) ); + snapshotMetadataFile.delete(); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkSuccess(); + + File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + assertTrue( "Check artifact created", artifactFile.exists() ); + assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); + + artifact = createPomArtifact( artifact ); + File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); + assertTrue( "Check POM created", pomFile.exists() ); + + compareFiles( sourcePomFile, pomFile ); + + assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() ); + + File expectedMetadataFile = getTestFile( "src/test/expected-files/v4-snapshot-artifact-metadata.xml" ); + + compareFiles( expectedMetadataFile, artifactMetadataFile ); + + assertTrue( "Check snapshot metadata created", snapshotMetadataFile.exists() ); + + expectedMetadataFile = getTestFile( expectedMetadataFileName ); + + compareFiles( expectedMetadataFile, snapshotMetadataFile ); + } + + public void testV3SnapshotPomConvert() + throws IOException, RepositoryConversionException + { + // test that the pom is coverted + + Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0-SNAPSHOT" ); + ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); + File artifactMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); + artifactMetadataFile.delete(); + + ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); + File snapshotMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) ); + snapshotMetadataFile.delete(); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkSuccess(); + + File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + assertTrue( "Check artifact created", artifactFile.exists() ); + assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); + + artifact = createPomArtifact( artifact ); + File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3-snapshot.pom" ); + assertTrue( "Check POM created", pomFile.exists() ); + + compareFiles( expectedPomFile, pomFile ); + + assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() ); + + File expectedMetadataFile = getTestFile( "src/test/expected-files/v3-snapshot-artifact-metadata.xml" ); + + compareFiles( expectedMetadataFile, artifactMetadataFile ); + + assertTrue( "Check snapshot metadata created", snapshotMetadataFile.exists() ); + + expectedMetadataFile = getTestFile( "src/test/expected-files/v3-snapshot-metadata.xml" ); + + compareFiles( expectedMetadataFile, snapshotMetadataFile ); + } + + public void testV4SnapshotPomConvert() + throws IOException, RepositoryConversionException + { + doTestV4SnapshotPomConvert( "1.0.0-SNAPSHOT", "src/test/expected-files/v4-snapshot-metadata.xml" ); + + assertTrue( true ); + } + + public void testV4TimestampedSnapshotPomConvert() + throws IOException, RepositoryConversionException + { + doTestV4SnapshotPomConvert( "1.0.0-20060111.120115-1", + "src/test/expected-files/v4-timestamped-snapshot-metadata.xml" ); + + assertTrue( true ); + } + + public void testV3TimestampedSnapshotPomConvert() + throws IOException, RepositoryConversionException + { + // test that the pom is coverted + + Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0-20060105.130101-3" ); + ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); + File artifactMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); + artifactMetadataFile.delete(); + + ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); + File snapshotMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) ); + snapshotMetadataFile.delete(); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkSuccess(); + + File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + assertTrue( "Check artifact created", artifactFile.exists() ); + assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); + + artifact = createPomArtifact( artifact ); + File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3-timestamped-snapshot.pom" ); + assertTrue( "Check POM created", pomFile.exists() ); + + compareFiles( expectedPomFile, pomFile ); + + assertTrue( "Check artifact snapshotMetadata created", artifactMetadataFile.exists() ); + + File expectedMetadataFile = getTestFile( "src/test/expected-files/v3-snapshot-artifact-metadata.xml" ); + + compareFiles( expectedMetadataFile, artifactMetadataFile ); + + assertTrue( "Check snapshot snapshotMetadata created", snapshotMetadataFile.exists() ); + + expectedMetadataFile = getTestFile( "src/test/expected-files/v3-timestamped-snapshot-metadata.xml" ); + + compareFiles( expectedMetadataFile, snapshotMetadataFile ); + } + + public void testNoPomConvert() + throws IOException, RepositoryConversionException + { + // test that a POM is not created when there was none at the source + + Artifact artifact = createArtifact( "test", "noPomArtifact", "1.0.0" ); + repositoryConverter.convert( artifact, targetRepository, reporter ); + assertEquals( "check no errors", 0, reporter.getFailures() ); + assertEquals( "check no warnings", 1, reporter.getWarnings() ); + assertEquals( "check success", 1, reporter.getSuccesses() ); + assertEquals( "check warning message", getI18nString( "warning.missing.pom" ), getWarning().getReason() ); + + File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + assertTrue( "Check artifact created", artifactFile.exists() ); + assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); + + artifact = createPomArtifact( artifact ); + File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); + + assertFalse( "Check no POM created", pomFile.exists() ); + assertFalse( "No source POM", sourcePomFile.exists() ); + } + + public void testIncorrectSourceChecksumMd5() + throws RepositoryConversionException + { + // test that it fails when the source md5 is wrong + + Artifact artifact = createArtifact( "test", "incorrectMd5Artifact", "1.0.0" ); + File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + file.delete(); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkFailure(); + assertEquals( "check failure message", getI18nString( "failure.incorrect.md5" ), getFailure().getReason() ); + + assertFalse( "Check artifact not created", file.exists() ); + + ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); + File metadataFile = + new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); + assertFalse( "Check metadata not created", metadataFile.exists() ); + } + + public void testIncorrectSourceChecksumSha1() + throws RepositoryConversionException + { + // test that it fails when the source sha1 is wrong + + Artifact artifact = createArtifact( "test", "incorrectSha1Artifact", "1.0.0" ); + File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + file.delete(); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkFailure(); + assertEquals( "check failure message", getI18nString( "failure.incorrect.sha1" ), getFailure().getReason() ); + + assertFalse( "Check artifact not created", file.exists() ); + + ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); + File metadataFile = + new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); + assertFalse( "Check metadata not created", metadataFile.exists() ); + } + + public void testUnmodifiedArtifact() + throws RepositoryConversionException, IOException, InterruptedException + { + // test the unmodified artifact is untouched + + Artifact artifact = createArtifact( "test", "unmodified-artifact", "1.0.0" ); + Artifact pomArtifact = createPomArtifact( artifact ); + + File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); + File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) ); + File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); + + assertTrue( "Check target file exists", targetFile.exists() ); + assertTrue( "Check target POM exists", targetPomFile.exists() ); + + sourceFile.setLastModified( System.currentTimeMillis() ); + sourcePomFile.setLastModified( System.currentTimeMillis() ); + + long origTime = targetFile.lastModified(); + long origPomTime = targetPomFile.lastModified(); + + // Need to guarantee last modified is not equal + Thread.sleep( SLEEP_MILLIS ); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkSuccess(); + + compareFiles( sourceFile, targetFile ); + compareFiles( sourcePomFile, targetPomFile ); + + assertEquals( "Check unmodified", origTime, targetFile.lastModified() ); + assertEquals( "Check unmodified", origPomTime, targetPomFile.lastModified() ); + } + + public void testModifedArtifactFails() + throws InterruptedException, RepositoryConversionException, IOException + { + // test that it fails when the source artifact has changed and is different to the existing artifact in the + // target repository + + Artifact artifact = createArtifact( "test", "modified-artifact", "1.0.0" ); + Artifact pomArtifact = createPomArtifact( artifact ); + + File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); + File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) ); + File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); + + assertTrue( "Check target file exists", targetFile.exists() ); + assertTrue( "Check target POM exists", targetPomFile.exists() ); + + sourceFile.setLastModified( System.currentTimeMillis() ); + sourcePomFile.setLastModified( System.currentTimeMillis() ); + + long origTime = targetFile.lastModified(); + long origPomTime = targetPomFile.lastModified(); + + // Need to guarantee last modified is not equal + Thread.sleep( SLEEP_MILLIS ); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkFailure(); + assertEquals( "Check failure message", getI18nString( "failure.target.already.exists" ), + getFailure().getReason() ); + + assertEquals( "Check unmodified", origTime, targetFile.lastModified() ); + assertEquals( "Check unmodified", origPomTime, targetPomFile.lastModified() ); + + ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); + File metadataFile = + new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); + assertFalse( "Check metadata not created", metadataFile.exists() ); + } + + public void testForcedUnmodifiedArtifact() + throws Exception, IOException + { + // test unmodified artifact is still converted when set to force + + repositoryConverter = (RepositoryConverter) lookup( RepositoryConverter.ROLE, "force-repository-converter" ); + + Artifact artifact = createArtifact( "test", "unmodified-artifact", "1.0.0" ); + Artifact pomArtifact = createPomArtifact( artifact ); + + File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); + File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) ); + File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); + + SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd", Locale.getDefault() ); + long origTime = dateFormat.parse( "2006-03-03" ).getTime(); + targetFile.setLastModified( origTime ); + targetPomFile.setLastModified( origTime ); + + sourceFile.setLastModified( dateFormat.parse( "2006-01-01" ).getTime() ); + sourcePomFile.setLastModified( dateFormat.parse( "2006-02-02" ).getTime() ); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkSuccess(); + + compareFiles( sourceFile, targetFile ); + compareFiles( sourcePomFile, targetPomFile ); + + assertFalse( "Check modified", origTime == targetFile.lastModified() ); + assertFalse( "Check modified", origTime == targetPomFile.lastModified() ); + + ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); + File metadataFile = + new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); + assertTrue( "Check metadata created", metadataFile.exists() ); + } + + public void testDryRunSuccess() + throws Exception + { + // test dry run does nothing on a run that will be successful, and returns success + + repositoryConverter = (RepositoryConverter) lookup( RepositoryConverter.ROLE, "dryrun-repository-converter" ); + + Artifact artifact = createArtifact( "test", "dryrun-artifact", "1.0.0" ); + Artifact pomArtifact = createPomArtifact( artifact ); + + File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); + File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) ); + File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkSuccess(); + + assertTrue( "Check source file exists", sourceFile.exists() ); + assertTrue( "Check source POM exists", sourcePomFile.exists() ); + + assertFalse( "Check target file doesn't exist", targetFile.exists() ); + assertFalse( "Check target POM doesn't exist", targetPomFile.exists() ); + + ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); + File metadataFile = + new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); + assertFalse( "Check metadata not created", metadataFile.exists() ); + } + + public void testDryRunFailure() + throws Exception + { + // test dry run does nothing on a run that will fail, and returns failure + + repositoryConverter = (RepositoryConverter) lookup( RepositoryConverter.ROLE, "dryrun-repository-converter" ); + + Artifact artifact = createArtifact( "test", "modified-artifact", "1.0.0" ); + Artifact pomArtifact = createPomArtifact( artifact ); + + File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); + File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) ); + File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); + + assertTrue( "Check target file exists", targetFile.exists() ); + assertTrue( "Check target POM exists", targetPomFile.exists() ); + + sourceFile.setLastModified( System.currentTimeMillis() ); + sourcePomFile.setLastModified( System.currentTimeMillis() ); + + long origTime = targetFile.lastModified(); + long origPomTime = targetPomFile.lastModified(); + + // Need to guarantee last modified is not equal + Thread.sleep( SLEEP_MILLIS ); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkFailure(); + assertEquals( "Check failure message", getI18nString( "failure.target.already.exists" ), + getFailure().getReason() ); + + assertEquals( "Check unmodified", origTime, targetFile.lastModified() ); + assertEquals( "Check unmodified", origPomTime, targetPomFile.lastModified() ); + + ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); + File metadataFile = + new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); + assertFalse( "Check metadata not created", metadataFile.exists() ); + } + + public void testRollbackArtifactCreated() + throws RepositoryConversionException, IOException + { + // test rollback can remove a created artifact, including checksums + + Artifact artifact = createArtifact( "test", "rollback-created-artifact", "1.0.0" ); + ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); + File artifactMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); + FileUtils.deleteDirectory( artifactMetadataFile.getParentFile() ); + + ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); + File versionMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); + + File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkFailure(); + String pattern = "^" + getI18nString( "failure.invalid.source.pom" ).replaceFirst( "\\{0\\}", ".*" ) + "$"; + assertTrue( "Check failure message", getFailure().getReason().matches( pattern ) ); + + assertFalse( "check artifact rolled back", artifactFile.exists() ); + assertFalse( "check metadata rolled back", artifactMetadataFile.exists() ); + assertFalse( "check metadata rolled back", versionMetadataFile.exists() ); + } + + public void testMultipleArtifacts() + throws RepositoryConversionException, IOException + { + // test multiple artifacts are converted + + List artifacts = new ArrayList(); + artifacts.add( createArtifact( "test", "artifact-one", "1.0.0" ) ); + artifacts.add( createArtifact( "test", "artifact-two", "1.0.0" ) ); + artifacts.add( createArtifact( "test", "artifact-three", "1.0.0" ) ); + repositoryConverter.convert( artifacts, targetRepository, reporter ); + assertEquals( "check no errors", 0, reporter.getFailures() ); + assertEquals( "check no warnings", 0, reporter.getWarnings() ); + assertEquals( "check successes", 3, reporter.getSuccesses() ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + + File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + assertTrue( "Check artifact created", artifactFile.exists() ); + assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); + + artifact = createPomArtifact( artifact ); + File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File expectedPomFile = + getTestFile( "src/test/expected-files/converted-" + artifact.getArtifactId() + ".pom" ); + assertTrue( "Check POM created", pomFile.exists() ); + + compareFiles( expectedPomFile, pomFile ); + } + } + + public void testInvalidSourceArtifactMetadata() + throws Exception + { + // test artifact is not converted when source metadata is invalid, and returns failure + + createModernSourceRepository(); + + Artifact artifact = createArtifact( "test", "incorrectArtifactMetadata", "1.0.0" ); + File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + file.delete(); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkFailure(); + assertEquals( "check failure message", getI18nString( "failure.incorrect.artifactMetadata.versions" ), + getFailure().getReason() ); + + assertFalse( "Check artifact not created", file.exists() ); + + ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); + File metadataFile = + new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); + assertFalse( "Check metadata not created", metadataFile.exists() ); + } + + public void testInvalidSourceSnapshotMetadata() + throws Exception, MalformedURLException + { + // test artifact is not converted when source snapshot metadata is invalid and returns failure + + createModernSourceRepository(); + + Artifact artifact = createArtifact( "test", "incorrectSnapshotMetadata", "1.0.0-20060102.030405-6" ); + File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + file.delete(); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkFailure(); + assertEquals( "check failure message", getI18nString( "failure.incorrect.snapshotMetadata.snapshot" ), + getFailure().getReason() ); + + assertFalse( "Check artifact not created", file.exists() ); + + ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); + File metadataFile = + new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); + assertFalse( "Check metadata not created", metadataFile.exists() ); + } + + public void testMergeArtifactMetadata() + throws RepositoryConversionException, IOException + { + // test artifact level metadata is merged when it already exists on successful conversion + + Artifact artifact = createArtifact( "test", "newversion-artifact", "1.0.1" ); + + repositoryConverter.convert( artifact, targetRepository, reporter ); + checkSuccess(); + + File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + assertTrue( "Check artifact created", artifactFile.exists() ); + assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); + + artifact = createPomArtifact( artifact ); + File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); + assertTrue( "Check POM created", pomFile.exists() ); + + compareFiles( sourcePomFile, pomFile ); + + ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); + File artifactMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); + assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() ); + + File expectedMetadataFile = getTestFile( "src/test/expected-files/newversion-artifact-metadata.xml" ); + + compareFiles( expectedMetadataFile, artifactMetadataFile ); + } + + public void testSourceAndTargetRepositoriesMatch() + throws Exception + { + // test that it fails if the same + + ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + + sourceRepository = factory.createArtifactRepository( "source", targetRepository.getUrl(), + targetRepository.getLayout(), null, null ); + + Artifact artifact = createArtifact( "test", "repository-artifact", "1.0" ); + + try + { + repositoryConverter.convert( artifact, targetRepository, reporter ); + fail( "Should have failed trying to convert within the same repository" ); + } + catch ( RepositoryConversionException e ) + { + // expected + assertEquals( "check message", getI18nString( "exception.repositories.match" ), e.getMessage() ); + assertNull( "Check no additional cause", e.getCause() ); + } + } + + private Artifact createArtifact( String groupId, String artifactId, String version ) + { + Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( version ); + String baseVersion; + if ( matcher.matches() ) + { + baseVersion = matcher.group( 1 ) + "-SNAPSHOT"; + } + else + { + baseVersion = version; + } + return createArtifact( groupId, artifactId, baseVersion, version, "jar" ); + } + + private Artifact createArtifact( String groupId, String artifactId, String baseVersion, String version, + String type ) + { + Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, type ); + artifact.setBaseVersion( baseVersion ); + artifact.setRepository( sourceRepository ); + artifact.setFile( new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ) ); + return artifact; + } + + private Artifact createPomArtifact( Artifact artifact ) + { + return createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), + artifact.getVersion(), "pom" ); + } + + private static void compareFiles( File expectedPomFile, File pomFile ) + throws IOException + { + String expectedContent = normalizeString( FileUtils.fileRead( expectedPomFile ) ); + String targetContent = normalizeString( FileUtils.fileRead( pomFile ) ); + assertEquals( "Check file match between " + expectedPomFile + " and " + pomFile, expectedContent, + targetContent ); + } + + private static String normalizeString( String path ) + { + return path.trim().replaceAll( "\r\n", "\n" ).replace( '\r', '\n' ).replaceAll( "<\\?xml .+\\?>", "" ); + } + + private void checkSuccess() + { + assertEquals( "check no errors", 0, reporter.getFailures() ); + assertEquals( "check no warnings", 0, reporter.getWarnings() ); + assertEquals( "check success", 1, reporter.getSuccesses() ); + } + + private void checkFailure() + { + assertEquals( "check num errors", 1, reporter.getFailures() ); + assertEquals( "check no warnings", 0, reporter.getWarnings() ); + assertEquals( "check no success", 0, reporter.getSuccesses() ); + } + + private String getI18nString( String key ) + { + return i18n.getString( repositoryConverter.getClass().getName(), Locale.getDefault(), key ); + } + + private ArtifactResult getFailure() + { + return (ArtifactResult) reporter.getArtifactFailureIterator().next(); + } + + private ArtifactResult getWarning() + { + return (ArtifactResult) reporter.getArtifactWarningIterator().next(); + } + + private void createModernSourceRepository() + throws Exception + { + ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + + File sourceBase = getTestFile( "src/test/source-modern-repository" ); + sourceRepository = + factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null, null ); + } +} diff --git a/archiva-converter/src/test/java/org/apache/maven/repository/converter/transaction/CopyFileEventTest.java b/archiva-converter/src/test/java/org/apache/maven/repository/converter/transaction/CopyFileEventTest.java new file mode 100644 index 000000000..627c32cde --- /dev/null +++ b/archiva-converter/src/test/java/org/apache/maven/repository/converter/transaction/CopyFileEventTest.java @@ -0,0 +1,138 @@ +package org.apache.maven.repository.converter.transaction; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.PlexusTestCase; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; + +/** + * @author Edwin Punzalan + */ +public class CopyFileEventTest + extends PlexusTestCase +{ + private File testDir = new File( PlexusTestCase.getBasedir(), "target/transaction-tests/copy-file" ); + + private File testDest = new File( testDir, "test-file.txt" ); + + private File testSource = new File( PlexusTestCase.getBasedir(), "target/transaction-tests/test-file.txt" ); + + public void setUp() + throws Exception + { + super.setUp(); + + testSource.getParentFile().mkdirs(); + + testSource.createNewFile(); + + FileUtils.fileWrite( testSource.getAbsolutePath(), "source contents" ); + } + + public void testCopyCommitRollback() + throws Exception + { + assertTrue( "Test if the source exists", testSource.exists() ); + + String source = FileUtils.fileRead( testSource.getAbsolutePath() ); + + CopyFileEvent event = new CopyFileEvent( testSource, testDest ); + + assertFalse( "Test that the destination is not yet created", testDest.exists() ); + + event.commit(); + + assertTrue( "Test that the destination is created", testDest.exists() ); + + String target = FileUtils.fileRead( testDest.getAbsolutePath() ); + + assertTrue( "Test that the destination contents are copied correctly", source.equals( target ) ); + + event.rollback(); + + assertFalse( "Test that the destination file has been deleted", testDest.exists() ); + } + + public void testCopyCommitRollbackWithBackup() + throws Exception + { + assertTrue( "Test if the source exists", testSource.exists() ); + + String source = FileUtils.fileRead( testSource.getAbsolutePath() ); + + testDest.getParentFile().mkdirs(); + + testDest.createNewFile(); + + FileUtils.fileWrite( testDest.getAbsolutePath(), "overwritten contents" ); + + assertTrue( "Test that the destination exists", testDest.exists() ); + + CopyFileEvent event = new CopyFileEvent( testSource, testDest ); + + String target = FileUtils.fileRead( testDest.getAbsolutePath() ); + + assertTrue( "Test that the destination contents have not changed", target.equals( "overwritten contents" ) ); + + event.commit(); + + target = FileUtils.fileRead( testDest.getAbsolutePath() ); + + assertTrue( "Test that the destination contents are copied correctly", source.equals( target ) ); + + event.rollback(); + + target = FileUtils.fileRead( testDest.getAbsolutePath() ); + + assertTrue( "Test the destination file contents have been restored", target.equals( "overwritten contents" ) ); + } + + public void testCreateRollbackCommit() + throws Exception + { + assertTrue( "Test if the source exists", testSource.exists() ); + + String source = FileUtils.fileRead( testSource.getAbsolutePath() ); + + CopyFileEvent event = new CopyFileEvent( testSource, testDest ); + + assertFalse( "Test that the destination is not yet created", testDest.exists() ); + + event.rollback(); + + assertFalse( "Test that the destination file is not yet created", testDest.exists() ); + + event.commit(); + + assertTrue( "Test that the destination is created", testDest.exists() ); + + String target = FileUtils.fileRead( testDest.getAbsolutePath() ); + + assertTrue( "Test that the destination contents are copied correctly", source.equals( target ) ); + } + + protected void tearDown() + throws Exception + { + super.tearDown(); + + FileUtils.deleteDirectory( new File( PlexusTestCase.getBasedir(), + "target/transaction-tests" ).getAbsolutePath() ); + } +} diff --git a/archiva-converter/src/test/java/org/apache/maven/repository/converter/transaction/CreateFileEventTest.java b/archiva-converter/src/test/java/org/apache/maven/repository/converter/transaction/CreateFileEventTest.java new file mode 100644 index 000000000..2018e89a2 --- /dev/null +++ b/archiva-converter/src/test/java/org/apache/maven/repository/converter/transaction/CreateFileEventTest.java @@ -0,0 +1,108 @@ +package org.apache.maven.repository.converter.transaction; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.PlexusTestCase; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; + +/** + * @author Edwin Punzalan + */ +public class CreateFileEventTest + extends PlexusTestCase +{ + private File testDir = new File( PlexusTestCase.getBasedir(), "target/transaction-tests/create-file" ); + + public void testCreateCommitRollback() + throws Exception + { + File testFile = new File( testDir, "test-file.txt" ); + + CreateFileEvent event = new CreateFileEvent( "file contents", testFile ); + + assertFalse( "Test file is not yet created", testFile.exists() ); + + event.commit(); + + assertTrue( "Test file is not yet created", testFile.exists() ); + + event.rollback(); + + assertFalse( "Test file is has been deleted after rollback", testFile.exists() ); + assertFalse( "Test file parent directories has been rolledback too", testDir.exists() ); + assertTrue( "target directory still exists", new File( PlexusTestCase.getBasedir(), "target" ).exists() ); + } + + public void testCreateCommitRollbackWithBackup() + throws Exception + { + File testFile = new File( testDir, "test-file.txt" ); + + testFile.getParentFile().mkdirs(); + + testFile.createNewFile(); + + FileUtils.fileWrite( testFile.getAbsolutePath(), "original contents" ); + + CreateFileEvent event = new CreateFileEvent( "modified contents", testFile ); + + String contents = FileUtils.fileRead( testFile.getAbsolutePath() ); + + assertEquals( "Test contents have not changed", "original contents", contents ); + + event.commit(); + + contents = FileUtils.fileRead( testFile.getAbsolutePath() ); + + assertEquals( "Test contents have not changed", "modified contents", contents ); + + event.rollback(); + + contents = FileUtils.fileRead( testFile.getAbsolutePath() ); + + assertEquals( "Test contents have not changed", "original contents", contents ); + } + + public void testCreateRollbackCommit() + throws Exception + { + File testFile = new File( testDir, "test-file.txt" ); + + CreateFileEvent event = new CreateFileEvent( "file contents", testFile ); + + assertFalse( "Test file is not yet created", testFile.exists() ); + + event.rollback(); + + assertFalse( "Test file is not yet created", testFile.exists() ); + + event.commit(); + + assertTrue( "Test file is not yet created", testFile.exists() ); + } + + protected void tearDown() + throws Exception + { + super.tearDown(); + + FileUtils.deleteDirectory( new File( PlexusTestCase.getBasedir(), + "target/transaction-tests" ).getAbsolutePath() ); + } +} diff --git a/archiva-converter/src/test/resources/org/apache/maven/repository/converter/RepositoryConverterTest.xml b/archiva-converter/src/test/resources/org/apache/maven/repository/converter/RepositoryConverterTest.xml new file mode 100644 index 000000000..f2caaffca --- /dev/null +++ b/archiva-converter/src/test/resources/org/apache/maven/repository/converter/RepositoryConverterTest.xml @@ -0,0 +1,84 @@ + + + + + + org.apache.maven.repository.converter.RepositoryConverter + org.apache.maven.repository.converter.DefaultRepositoryConverter + force-repository-converter + + true + + + + org.apache.maven.repository.digest.Digester + sha1 + sha1Digester + + + org.apache.maven.repository.digest.Digester + md5 + md5Digester + + + org.apache.maven.artifact.factory.ArtifactFactory + artifactFactory + + + org.apache.maven.model.converter.ArtifactPomRewriter + rewriter + + + org.codehaus.plexus.i18n.I18N + i18n + + + + + org.apache.maven.repository.converter.RepositoryConverter + org.apache.maven.repository.converter.DefaultRepositoryConverter + dryrun-repository-converter + + true + + + + org.apache.maven.repository.digest.Digester + sha1 + sha1Digester + + + org.apache.maven.repository.digest.Digester + md5 + md5Digester + + + org.apache.maven.artifact.factory.ArtifactFactory + artifactFactory + + + org.apache.maven.model.converter.ArtifactPomRewriter + rewriter + + + org.codehaus.plexus.i18n.I18N + i18n + + + + + \ No newline at end of file diff --git a/archiva-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/1.0.0/incorrectArtifactMetadata-1.0.0.jar b/archiva-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/1.0.0/incorrectArtifactMetadata-1.0.0.jar new file mode 100644 index 000000000..72af4bc10 --- /dev/null +++ b/archiva-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/1.0.0/incorrectArtifactMetadata-1.0.0.jar @@ -0,0 +1 @@ +incorrectMd5 diff --git a/archiva-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/1.0.0/incorrectArtifactMetadata-1.0.0.pom b/archiva-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/1.0.0/incorrectArtifactMetadata-1.0.0.pom new file mode 100644 index 000000000..e9ec6a15c --- /dev/null +++ b/archiva-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/1.0.0/incorrectArtifactMetadata-1.0.0.pom @@ -0,0 +1,22 @@ + + + + 3 + incorrectArtifactMetadata + test + 1.0.0 + diff --git a/archiva-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/maven-metadata.xml b/archiva-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/maven-metadata.xml new file mode 100644 index 000000000..5ed142599 --- /dev/null +++ b/archiva-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/maven-metadata.xml @@ -0,0 +1,25 @@ + + + + test + incorrectArtifactMetadata + + + 0.9 + + + \ No newline at end of file diff --git a/archiva-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/incorrectSnapshotMetadata-1.0.0-20060102.030405-6.jar b/archiva-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/incorrectSnapshotMetadata-1.0.0-20060102.030405-6.jar new file mode 100644 index 000000000..72af4bc10 --- /dev/null +++ b/archiva-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/incorrectSnapshotMetadata-1.0.0-20060102.030405-6.jar @@ -0,0 +1 @@ +incorrectMd5 diff --git a/archiva-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/incorrectSnapshotMetadata-1.0.0-20060102.030405-6.pom b/archiva-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/incorrectSnapshotMetadata-1.0.0-20060102.030405-6.pom new file mode 100644 index 000000000..70118f64a --- /dev/null +++ b/archiva-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/incorrectSnapshotMetadata-1.0.0-20060102.030405-6.pom @@ -0,0 +1,22 @@ + + + + 3 + incorrectSnapshotMetadata + test + 1.0.0-20060102.030405-6 + diff --git a/archiva-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/maven-metadata.xml b/archiva-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/maven-metadata.xml new file mode 100644 index 000000000..031fb19b6 --- /dev/null +++ b/archiva-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/maven-metadata.xml @@ -0,0 +1,27 @@ + + + + test + incorrectSnapshotMetadata + 1.0.0-SNAPSHOT + + + 10 + 20060102.040506 + + + \ No newline at end of file diff --git a/archiva-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/maven-metadata.xml b/archiva-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/maven-metadata.xml new file mode 100644 index 000000000..db6ce9a7f --- /dev/null +++ b/archiva-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/maven-metadata.xml @@ -0,0 +1,25 @@ + + + + test + incorrectSnapshotMetadata + + + 1.0.0-SNAPSHOT + + + \ No newline at end of file diff --git a/archiva-converter/src/test/source-repository/test/jars/artifact-one-1.0.0.jar b/archiva-converter/src/test/source-repository/test/jars/artifact-one-1.0.0.jar new file mode 100644 index 000000000..5626abf0f --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/artifact-one-1.0.0.jar @@ -0,0 +1 @@ +one diff --git a/archiva-converter/src/test/source-repository/test/jars/artifact-three-1.0.0.jar b/archiva-converter/src/test/source-repository/test/jars/artifact-three-1.0.0.jar new file mode 100644 index 000000000..2bdf67abb --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/artifact-three-1.0.0.jar @@ -0,0 +1 @@ +three diff --git a/archiva-converter/src/test/source-repository/test/jars/artifact-two-1.0.0.jar b/archiva-converter/src/test/source-repository/test/jars/artifact-two-1.0.0.jar new file mode 100644 index 000000000..f719efd43 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/artifact-two-1.0.0.jar @@ -0,0 +1 @@ +two diff --git a/archiva-converter/src/test/source-repository/test/jars/dryrun-artifact-1.0.0.jar b/archiva-converter/src/test/source-repository/test/jars/dryrun-artifact-1.0.0.jar new file mode 100644 index 000000000..cbaf024e5 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/dryrun-artifact-1.0.0.jar @@ -0,0 +1 @@ +existing diff --git a/archiva-converter/src/test/source-repository/test/jars/existing-artifact-1.0.0.jar b/archiva-converter/src/test/source-repository/test/jars/existing-artifact-1.0.0.jar new file mode 100644 index 000000000..cbaf024e5 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/existing-artifact-1.0.0.jar @@ -0,0 +1 @@ +existing diff --git a/archiva-converter/src/test/source-repository/test/jars/incorrectMd5Artifact-1.0.0.jar b/archiva-converter/src/test/source-repository/test/jars/incorrectMd5Artifact-1.0.0.jar new file mode 100644 index 000000000..72af4bc10 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/incorrectMd5Artifact-1.0.0.jar @@ -0,0 +1 @@ +incorrectMd5 diff --git a/archiva-converter/src/test/source-repository/test/jars/incorrectMd5Artifact-1.0.0.jar.md5 b/archiva-converter/src/test/source-repository/test/jars/incorrectMd5Artifact-1.0.0.jar.md5 new file mode 100644 index 000000000..316d9a4eb --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/incorrectMd5Artifact-1.0.0.jar.md5 @@ -0,0 +1 @@ +379dcfcd1e6312cc859111f696047eb4 diff --git a/archiva-converter/src/test/source-repository/test/jars/incorrectSha1Artifact-1.0.0.jar b/archiva-converter/src/test/source-repository/test/jars/incorrectSha1Artifact-1.0.0.jar new file mode 100644 index 000000000..f5812f3e5 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/incorrectSha1Artifact-1.0.0.jar @@ -0,0 +1 @@ +incorrectSha1 diff --git a/archiva-converter/src/test/source-repository/test/jars/incorrectSha1Artifact-1.0.0.jar.sha1 b/archiva-converter/src/test/source-repository/test/jars/incorrectSha1Artifact-1.0.0.jar.sha1 new file mode 100644 index 000000000..cce322eb2 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/incorrectSha1Artifact-1.0.0.jar.sha1 @@ -0,0 +1 @@ +52e07b82d944741f66bba5896d4cd74e9879e289 diff --git a/archiva-converter/src/test/source-repository/test/jars/modified-artifact-1.0.0.jar b/archiva-converter/src/test/source-repository/test/jars/modified-artifact-1.0.0.jar new file mode 100644 index 000000000..2e0996000 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/modified-artifact-1.0.0.jar @@ -0,0 +1 @@ +modified diff --git a/archiva-converter/src/test/source-repository/test/jars/newversion-artifact-1.0.1.jar b/archiva-converter/src/test/source-repository/test/jars/newversion-artifact-1.0.1.jar new file mode 100644 index 000000000..c694117fd --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/newversion-artifact-1.0.1.jar @@ -0,0 +1 @@ +v4 diff --git a/archiva-converter/src/test/source-repository/test/jars/noPomArtifact-1.0.0.jar b/archiva-converter/src/test/source-repository/test/jars/noPomArtifact-1.0.0.jar new file mode 100644 index 000000000..3d27acdcc --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/noPomArtifact-1.0.0.jar @@ -0,0 +1 @@ +noPom diff --git a/archiva-converter/src/test/source-repository/test/jars/relocated-v3artifact-1.0.0.jar b/archiva-converter/src/test/source-repository/test/jars/relocated-v3artifact-1.0.0.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/relocated-v3artifact-1.0.0.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-converter/src/test/source-repository/test/jars/rollback-created-artifact-1.0.0.jar b/archiva-converter/src/test/source-repository/test/jars/rollback-created-artifact-1.0.0.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/rollback-created-artifact-1.0.0.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-converter/src/test/source-repository/test/jars/unmodified-artifact-1.0.0.jar b/archiva-converter/src/test/source-repository/test/jars/unmodified-artifact-1.0.0.jar new file mode 100644 index 000000000..27597bc21 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/unmodified-artifact-1.0.0.jar @@ -0,0 +1 @@ +unmodified diff --git a/archiva-converter/src/test/source-repository/test/jars/v3-warnings-artifact-1.0.0.jar b/archiva-converter/src/test/source-repository/test/jars/v3-warnings-artifact-1.0.0.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/v3-warnings-artifact-1.0.0.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-converter/src/test/source-repository/test/jars/v3artifact-1.0.0-20060105.130101-3.jar b/archiva-converter/src/test/source-repository/test/jars/v3artifact-1.0.0-20060105.130101-3.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/v3artifact-1.0.0-20060105.130101-3.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-converter/src/test/source-repository/test/jars/v3artifact-1.0.0-SNAPSHOT.jar b/archiva-converter/src/test/source-repository/test/jars/v3artifact-1.0.0-SNAPSHOT.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/v3artifact-1.0.0-SNAPSHOT.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-converter/src/test/source-repository/test/jars/v3artifact-1.0.0.jar b/archiva-converter/src/test/source-repository/test/jars/v3artifact-1.0.0.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/v3artifact-1.0.0.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-converter/src/test/source-repository/test/jars/v4artifact-1.0.0-20060111.120115-1.jar b/archiva-converter/src/test/source-repository/test/jars/v4artifact-1.0.0-20060111.120115-1.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/v4artifact-1.0.0-20060111.120115-1.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-converter/src/test/source-repository/test/jars/v4artifact-1.0.0-SNAPSHOT.jar b/archiva-converter/src/test/source-repository/test/jars/v4artifact-1.0.0-SNAPSHOT.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/v4artifact-1.0.0-SNAPSHOT.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar b/archiva-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar new file mode 100644 index 000000000..c694117fd --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar @@ -0,0 +1 @@ +v4 diff --git a/archiva-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar.md5 b/archiva-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar.md5 new file mode 100644 index 000000000..1930bc6d3 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar.md5 @@ -0,0 +1 @@ +4289bbdd6fba75013b317b2f9a540736 *v4artifact-1.0.0.jar diff --git a/archiva-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar.sha1 b/archiva-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar.sha1 new file mode 100644 index 000000000..466f209a7 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar.sha1 @@ -0,0 +1 @@ +e3e4159da65a4257f0bffb7cac8e3e78241a4dca *v4artifact-1.0.0.jar diff --git a/archiva-converter/src/test/source-repository/test/poms/artifact-one-1.0.0.pom b/archiva-converter/src/test/source-repository/test/poms/artifact-one-1.0.0.pom new file mode 100644 index 000000000..cd3862d35 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/artifact-one-1.0.0.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + artifact-one + 1.0.0 + diff --git a/archiva-converter/src/test/source-repository/test/poms/artifact-three-1.0.0.pom b/archiva-converter/src/test/source-repository/test/poms/artifact-three-1.0.0.pom new file mode 100644 index 000000000..343291037 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/artifact-three-1.0.0.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + artifact-three + 1.0.0 + diff --git a/archiva-converter/src/test/source-repository/test/poms/artifact-two-1.0.0.pom b/archiva-converter/src/test/source-repository/test/poms/artifact-two-1.0.0.pom new file mode 100644 index 000000000..227470167 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/artifact-two-1.0.0.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + artifact-two + 1.0.0 + diff --git a/archiva-converter/src/test/source-repository/test/poms/dryrun-artifact-1.0.0.pom b/archiva-converter/src/test/source-repository/test/poms/dryrun-artifact-1.0.0.pom new file mode 100644 index 000000000..1953c5523 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/dryrun-artifact-1.0.0.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + dryrun-artifact + test + 1.0.0 + diff --git a/archiva-converter/src/test/source-repository/test/poms/incorrectMd5Artifact-1.0.0.pom b/archiva-converter/src/test/source-repository/test/poms/incorrectMd5Artifact-1.0.0.pom new file mode 100644 index 000000000..74d5e12b4 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/incorrectMd5Artifact-1.0.0.pom @@ -0,0 +1,6 @@ + + 3 + incorrectMd5Artifact + test + 1.0.0 + diff --git a/archiva-converter/src/test/source-repository/test/poms/incorrectSha1Artifact-1.0.0.pom b/archiva-converter/src/test/source-repository/test/poms/incorrectSha1Artifact-1.0.0.pom new file mode 100644 index 000000000..fe3c7fd91 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/incorrectSha1Artifact-1.0.0.pom @@ -0,0 +1,6 @@ + + 3 + incorrectSha1Artifact + test + 1.0.0 + diff --git a/archiva-converter/src/test/source-repository/test/poms/modified-artifact-1.0.0.pom b/archiva-converter/src/test/source-repository/test/poms/modified-artifact-1.0.0.pom new file mode 100644 index 000000000..fcfdaacb4 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/modified-artifact-1.0.0.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + modified-artifact + test + 1.0.0 + diff --git a/archiva-converter/src/test/source-repository/test/poms/newversion-artifact-1.0.1.pom b/archiva-converter/src/test/source-repository/test/poms/newversion-artifact-1.0.1.pom new file mode 100644 index 000000000..f441c9a46 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/newversion-artifact-1.0.1.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + test + newversoin-artifact + 1.0.1 + diff --git a/archiva-converter/src/test/source-repository/test/poms/relocated-v3artifact-1.0.0.pom b/archiva-converter/src/test/source-repository/test/poms/relocated-v3artifact-1.0.0.pom new file mode 100644 index 000000000..10823fe89 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/relocated-v3artifact-1.0.0.pom @@ -0,0 +1,27 @@ + + 3 + relocated-v3artifact + test + 1.0.0 + + + groupId + artifactId + version + + + groupId + test-artifactId + version + + test + + + + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + + relocated-test + + \ No newline at end of file diff --git a/archiva-converter/src/test/source-repository/test/poms/rollback-created-artifact-1.0.0.pom b/archiva-converter/src/test/source-repository/test/poms/rollback-created-artifact-1.0.0.pom new file mode 100644 index 000000000..00692be72 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/rollback-created-artifact-1.0.0.pom @@ -0,0 +1,39 @@ + + + + 3 + v3artifact + test + 1.0.0 + + + groupId + artifactId + version + + + groupId + test-artifactId + version + + test + + + + + + diff --git a/archiva-converter/src/test/source-repository/test/poms/unmodified-artifact-1.0.0.pom b/archiva-converter/src/test/source-repository/test/poms/unmodified-artifact-1.0.0.pom new file mode 100644 index 000000000..c570979f4 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/unmodified-artifact-1.0.0.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + unmodified-artifact + test + 1.0.0 + diff --git a/archiva-converter/src/test/source-repository/test/poms/v3-warnings-artifact-1.0.0.pom b/archiva-converter/src/test/source-repository/test/poms/v3-warnings-artifact-1.0.0.pom new file mode 100644 index 000000000..5f347f371 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/v3-warnings-artifact-1.0.0.pom @@ -0,0 +1,48 @@ + + + + 3 + ../project.xml + v3-warnings-artifact + test + 1.0.0 + + + 1.0 + 1.0 + 1_0 + + + + + groupId + artifactId + version + + + groupId + test-artifactId + version + + test + + + + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + diff --git a/archiva-converter/src/test/source-repository/test/poms/v3artifact-1.0.0-20060105.130101-3.pom b/archiva-converter/src/test/source-repository/test/poms/v3artifact-1.0.0-20060105.130101-3.pom new file mode 100644 index 000000000..d7ae8953b --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/v3artifact-1.0.0-20060105.130101-3.pom @@ -0,0 +1,40 @@ + + + + 3 + v3artifact + test + 1.0.0-20060105.130101-3 + + + groupId + artifactId + version + + + groupId + test-artifactId + version + + test + + + + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + diff --git a/archiva-converter/src/test/source-repository/test/poms/v3artifact-1.0.0-SNAPSHOT.pom b/archiva-converter/src/test/source-repository/test/poms/v3artifact-1.0.0-SNAPSHOT.pom new file mode 100644 index 000000000..3958a3358 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/v3artifact-1.0.0-SNAPSHOT.pom @@ -0,0 +1,40 @@ + + + + 3 + v3artifact + test + 1.0.0-SNAPSHOT + + + groupId + artifactId + version + + + groupId + test-artifactId + version + + test + + + + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + diff --git a/archiva-converter/src/test/source-repository/test/poms/v3artifact-1.0.0.pom b/archiva-converter/src/test/source-repository/test/poms/v3artifact-1.0.0.pom new file mode 100644 index 000000000..5aed3437a --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/v3artifact-1.0.0.pom @@ -0,0 +1,24 @@ + + 3 + v3artifact + test + 1.0.0 + + + groupId + artifactId + version + + + groupId + test-artifactId + version + + test + + + + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + diff --git a/archiva-converter/src/test/source-repository/test/poms/v4artifact-1.0.0-20060111.120115-1.pom b/archiva-converter/src/test/source-repository/test/poms/v4artifact-1.0.0-20060111.120115-1.pom new file mode 100644 index 000000000..e4f36566a --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/v4artifact-1.0.0-20060111.120115-1.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + test + v4artifact + 1.0.0-20060111.120115-1 + diff --git a/archiva-converter/src/test/source-repository/test/poms/v4artifact-1.0.0-SNAPSHOT.pom b/archiva-converter/src/test/source-repository/test/poms/v4artifact-1.0.0-SNAPSHOT.pom new file mode 100644 index 000000000..be5b8b7e2 --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/v4artifact-1.0.0-SNAPSHOT.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + test + v4artifact + 1.0.0-SNAPSHOT + diff --git a/archiva-converter/src/test/source-repository/test/poms/v4artifact-1.0.0.pom b/archiva-converter/src/test/source-repository/test/poms/v4artifact-1.0.0.pom new file mode 100644 index 000000000..fa6e82b1e --- /dev/null +++ b/archiva-converter/src/test/source-repository/test/poms/v4artifact-1.0.0.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + v4artifact + 1.0.0 + diff --git a/archiva-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.jar b/archiva-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.jar new file mode 100644 index 000000000..27597bc21 --- /dev/null +++ b/archiva-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.jar @@ -0,0 +1 @@ +unmodified diff --git a/archiva-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.pom b/archiva-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.pom new file mode 100644 index 000000000..fcfdaacb4 --- /dev/null +++ b/archiva-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + modified-artifact + test + 1.0.0 + diff --git a/archiva-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.jar b/archiva-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.jar new file mode 100644 index 000000000..27597bc21 --- /dev/null +++ b/archiva-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.jar @@ -0,0 +1 @@ +unmodified diff --git a/archiva-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.pom b/archiva-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.pom new file mode 100644 index 000000000..836cc236b --- /dev/null +++ b/archiva-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + newversion-artifact + test + 1.0.0 + diff --git a/archiva-converter/src/test/target-repository/test/newversion-artifact/maven-metadata.xml b/archiva-converter/src/test/target-repository/test/newversion-artifact/maven-metadata.xml new file mode 100644 index 000000000..f4d211741 --- /dev/null +++ b/archiva-converter/src/test/target-repository/test/newversion-artifact/maven-metadata.xml @@ -0,0 +1,9 @@ + + test + newversion-artifact + + + 1.0.0 + + + \ No newline at end of file diff --git a/archiva-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.jar b/archiva-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.jar new file mode 100644 index 000000000..27597bc21 --- /dev/null +++ b/archiva-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.jar @@ -0,0 +1 @@ +unmodified diff --git a/archiva-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.pom b/archiva-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.pom new file mode 100644 index 000000000..c570979f4 --- /dev/null +++ b/archiva-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + unmodified-artifact + test + 1.0.0 + diff --git a/archiva-core/pom.xml b/archiva-core/pom.xml new file mode 100644 index 000000000..8862ab6b3 --- /dev/null +++ b/archiva-core/pom.xml @@ -0,0 +1,54 @@ + + + + archiva + org.apache.maven.archiva + 1.0-SNAPSHOT + + 4.0.0 + archiva-core + Archiva Core + + + org.apache.maven.archiva + archiva-configuration + + + org.apache.maven.archiva + archiva-converter + + + org.apache.maven.archiva + archiva-discoverer + + + org.apache.maven.archiva + archiva-proxy + + + org.apache.maven.archiva + archiva-reports-standard + + + org.codehaus.plexus + plexus-quartz + 1.0-alpha-2 + + + + + + org.codehaus.mojo + cobertura-maven-plugin + + + + + **/** + + + + + + + diff --git a/archiva-core/src/main/java/org/apache/maven/repository/DefaultRepositoryManager.java b/archiva-core/src/main/java/org/apache/maven/repository/DefaultRepositoryManager.java new file mode 100644 index 000000000..e753c0d3f --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/repository/DefaultRepositoryManager.java @@ -0,0 +1,81 @@ +package org.apache.maven.repository; + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.repository.converter.RepositoryConversionException; +import org.apache.maven.repository.converter.RepositoryConverter; +import org.apache.maven.repository.discovery.ArtifactDiscoverer; +import org.apache.maven.repository.discovery.DiscovererException; +import org.apache.maven.repository.reporting.ArtifactReporter; + +import java.io.File; +import java.net.MalformedURLException; +import java.util.List; + +/** + * @author Jason van Zyl + * @plexus.component + */ +public class DefaultRepositoryManager + implements RepositoryManager +{ + /** + * @plexus.requirement role-hint="legacy" + */ + private ArtifactDiscoverer artifactDiscoverer; + + /** + * @plexus.requirement role-hint="legacy" + */ + private ArtifactRepositoryLayout legacyLayout; + + /** + * @plexus.requirement role-hint="default" + */ + private ArtifactRepositoryLayout defaultLayout; + + /** + * @plexus.requirement + */ + private ArtifactRepositoryFactory artifactRepositoryFactory; + + /** + * @plexus.requirement + */ + private RepositoryConverter repositoryConverter; + + /** + * @plexus.requirement role-hint="default" + */ + private ArtifactReporter reporter; + + public void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory, + boolean includeSnapshots ) + throws RepositoryConversionException, DiscovererException + { + ArtifactRepository legacyRepository; + + ArtifactRepository repository; + + try + { + legacyRepository = artifactRepositoryFactory.createArtifactRepository( "legacy", + legacyRepositoryDirectory.toURI().toURL().toString(), + legacyLayout, null, null ); + + repository = artifactRepositoryFactory.createArtifactRepository( "default", + repositoryDirectory.toURI().toURL().toString(), + defaultLayout, null, null ); + } + catch ( MalformedURLException e ) + { + throw new RepositoryConversionException( "Error convering legacy repository.", e ); + } + + List legacyArtifacts = + artifactDiscoverer.discoverArtifacts( legacyRepository, "converter", null, includeSnapshots ); + + repositoryConverter.convert( legacyArtifacts, repository, reporter ); + } +} diff --git a/archiva-core/src/main/java/org/apache/maven/repository/RepositoryManager.java b/archiva-core/src/main/java/org/apache/maven/repository/RepositoryManager.java new file mode 100644 index 000000000..40d176e83 --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/repository/RepositoryManager.java @@ -0,0 +1,28 @@ +package org.apache.maven.repository; + +import org.apache.maven.repository.converter.RepositoryConversionException; +import org.apache.maven.repository.discovery.DiscovererException; + +import java.io.File; + +/** + * @author Jason van Zyl + */ +public interface RepositoryManager +{ + /** + * Role of the Repository Manager + */ + String ROLE = RepositoryManager.class.getName(); + + /** + * Convert a legacy repository to a modern repository. This means a Maven 1.x repository + * using v3 POMs to a Maven 2.x repository using v4.0.0 POMs. + * + * @param legacyRepositoryDirectory + * @param repositoryDirectory + * @throws RepositoryConversionException + */ + void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory, boolean includeSnapshots ) + throws RepositoryConversionException, DiscovererException; +} diff --git a/archiva-core/src/main/java/org/apache/maven/repository/configuration/ConfiguredRepositoryFactory.java b/archiva-core/src/main/java/org/apache/maven/repository/configuration/ConfiguredRepositoryFactory.java new file mode 100644 index 000000000..568e436da --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/repository/configuration/ConfiguredRepositoryFactory.java @@ -0,0 +1,72 @@ +package org.apache.maven.repository.configuration; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.repository.ArtifactRepository; +import org.apache.maven.repository.proxy.ProxiedArtifactRepository; + +import java.util.List; + +/** + * Create an artifact repository from the given configuration. + * + * @author Brett Porter + */ +public interface ConfiguredRepositoryFactory +{ + String ROLE = ConfiguredRepositoryFactory.class.getName(); + + /** + * Create an artifact repository from the given configuration. + * + * @param configuration the configuration + * @return the artifact repository + */ + ArtifactRepository createRepository( RepositoryConfiguration configuration ); + + /** + * Create artifact repositories from the given configuration. + * + * @param configuration the configuration containing the repositories + * @return the artifact repositories + */ + List createRepositories( Configuration configuration ); + + /** + * Create a local repository from the given configuration. + * + * @param configuration the configuration + * @return the local artifact repository + */ + ArtifactRepository createLocalRepository( Configuration configuration ); + + /** + * Create an artifact repository from the given proxy repository configuration. + * + * @param configuration the configuration + * @return the artifact repository + */ + ProxiedArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration ); + + /** + * Create artifact repositories from the given proxy repository configurations. + * + * @param configuration the configuration containing the repositories + * @return the artifact repositories + */ + List createProxiedRepositories( Configuration configuration ); +} diff --git a/archiva-core/src/main/java/org/apache/maven/repository/configuration/DefaultConfiguredRepositoryFactory.java b/archiva-core/src/main/java/org/apache/maven/repository/configuration/DefaultConfiguredRepositoryFactory.java new file mode 100644 index 000000000..290a52301 --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/repository/configuration/DefaultConfiguredRepositoryFactory.java @@ -0,0 +1,127 @@ +package org.apache.maven.repository.configuration; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.repository.proxy.ProxiedArtifactRepository; + +import java.io.File; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * Create artifact repositories from a configuration. + * + * @author Brett Porter + * @plexus.component role="org.apache.maven.repository.configuration.ConfiguredRepositoryFactory" + */ +public class DefaultConfiguredRepositoryFactory + implements ConfiguredRepositoryFactory +{ + /** + * @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" + */ + private Map repositoryLayouts; + + /** + * @plexus.requirement + */ + private ArtifactRepositoryFactory repoFactory; + + public ArtifactRepository createRepository( RepositoryConfiguration configuration ) + { + File repositoryDirectory = new File( configuration.getDirectory() ); + String repoDir = repositoryDirectory.toURI().toString(); + + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getLayout() ); + return repoFactory.createArtifactRepository( configuration.getId(), repoDir, layout, null, null ); + } + + public ProxiedArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration ) + { + boolean enabled = isEnabled( configuration.getSnapshotsPolicy() ); + String updatePolicy = + getUpdatePolicy( configuration.getSnapshotsPolicy(), configuration.getSnapshotsInterval() ); + ArtifactRepositoryPolicy snapshotsPolicy = + new ArtifactRepositoryPolicy( enabled, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL ); + + enabled = isEnabled( configuration.getReleasesPolicy() ); + updatePolicy = getUpdatePolicy( configuration.getReleasesPolicy(), configuration.getReleasesInterval() ); + ArtifactRepositoryPolicy releasesPolicy = + new ArtifactRepositoryPolicy( enabled, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL ); + + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getLayout() ); + ArtifactRepository artifactRepository = repoFactory.createArtifactRepository( configuration.getId(), + configuration.getUrl(), layout, + snapshotsPolicy, releasesPolicy ); + ProxiedArtifactRepository repository = new ProxiedArtifactRepository( artifactRepository ); + repository.setCacheFailures( configuration.isCacheFailures() ); + repository.setHardFail( configuration.isHardFail() ); + repository.setName( configuration.getName() ); + repository.setUseNetworkProxy( configuration.isUseNetworkProxy() ); + return repository; + } + + public List createRepositories( Configuration configuration ) + { + List managedRepositories = configuration.getRepositories(); + List repositories = new ArrayList( managedRepositories.size() ); + + for ( Iterator i = managedRepositories.iterator(); i.hasNext(); ) + { + repositories.add( createRepository( (RepositoryConfiguration) i.next() ) ); + } + + return repositories; + } + + public List createProxiedRepositories( Configuration configuration ) + { + List proxiedRepositories = configuration.getProxiedRepositories(); + List repositories = new ArrayList( proxiedRepositories.size() ); + + for ( Iterator i = proxiedRepositories.iterator(); i.hasNext(); ) + { + repositories.add( createProxiedRepository( (ProxiedRepositoryConfiguration) i.next() ) ); + } + + return repositories; + } + + public ArtifactRepository createLocalRepository( Configuration configuration ) + { + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( "default" ); + File localRepository = new File( configuration.getLocalRepository() ); + localRepository.mkdirs(); + return repoFactory.createArtifactRepository( "local", localRepository.toURI().toString(), layout, null, null ); + } + + private static String getUpdatePolicy( String policy, int interval ) + { + return "interval".equals( policy ) ? policy + ":" + interval : policy; + } + + private static boolean isEnabled( String policy ) + { + return !"disabled".equals( policy ); + } +} diff --git a/archiva-core/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java b/archiva-core/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java new file mode 100644 index 000000000..5389fe5c7 --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java @@ -0,0 +1,233 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.repository.ArtifactRepository; +import org.apache.maven.repository.configuration.Configuration; +import org.apache.maven.repository.configuration.ConfigurationStore; +import org.apache.maven.repository.configuration.ConfigurationStoreException; +import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; +import org.apache.maven.repository.configuration.ProxiedRepositoryConfiguration; +import org.apache.maven.repository.configuration.Proxy; +import org.apache.maven.repository.configuration.RepositoryConfiguration; +import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.apache.maven.wagon.proxy.ProxyInfo; +import org.codehaus.plexus.util.StringUtils; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * Default implementation of the proxy manager that bridges the repository configuration classes to the proxy API. This + * class is not thread safe (due to the request handler being a non-thread safe requirement). + * + * @author Brett Porter + * @todo we should be able to configure "views" that sit in front of this (ie, prefix = /legacy, appears as layout maven-1.x, path gets translated before being passed on) + * @plexus.component instantiation-strategy="per-lookup" + */ +public class DefaultProxyManager + implements ProxyManager +{ + /** + * @plexus.requirement + */ + private ConfigurationStore configurationStore; + + /** + * @plexus.requirement role="org.apache.maven.repository.proxy.ProxyRequestHandler" + * @todo seems to be a bug in qdox that the role above is required + */ + private ProxyRequestHandler requestHandler; + + /** + * @plexus.requirement + */ + private ConfiguredRepositoryFactory repositoryFactory; + + /** + * The proxy groups for each managed repository. + */ + private static Map/**/ proxyGroups; + + /** + * The default proxy group/managed repository. + */ + private static ProxiedRepositoryGroup defaultProxyGroup; + + public File get( String path ) + throws ProxyException, ResourceDoesNotExistException + { + assert path.startsWith( "/" ); + + Map groups = getProxyGroups(); + + ProxiedRepositoryGroup proxyGroup = parseRepositoryId( path, groups ); + + String repositoryPath = path; + if ( proxyGroup == null ) + { + if ( defaultProxyGroup != null ) + { + proxyGroup = defaultProxyGroup; + } + else + { + throw new ResourceDoesNotExistException( "No repositories exist under the path: " + path ); + } + } + else + { + repositoryPath = repositoryPath.substring( proxyGroup.getManagedRepository().getId().length() + 2 ); + } + + return requestHandler.get( repositoryPath, proxyGroup.getProxiedRepositories(), + proxyGroup.getManagedRepository(), proxyGroup.getWagonProxy() ); + } + + public File getAlways( String path ) + throws ProxyException, ResourceDoesNotExistException + { + assert path.startsWith( "/" ); + + Map groups = getProxyGroups(); + + ProxiedRepositoryGroup proxyGroup = parseRepositoryId( path, groups ); + + String repositoryPath = path; + if ( proxyGroup == null ) + { + if ( defaultProxyGroup != null ) + { + proxyGroup = defaultProxyGroup; + } + else + { + throw new ResourceDoesNotExistException( "No repositories exist under the path: " + path ); + } + } + else + { + repositoryPath = repositoryPath.substring( proxyGroup.getManagedRepository().getId().length() + 2 ); + } + + return requestHandler.getAlways( repositoryPath, proxyGroup.getProxiedRepositories(), + proxyGroup.getManagedRepository(), proxyGroup.getWagonProxy() ); + } + + private Configuration getConfiguration() + throws ProxyException + { + Configuration configuration; + try + { + configuration = configurationStore.getConfigurationFromStore(); + } + catch ( ConfigurationStoreException e ) + { + throw new ProxyException( "Error reading configuration, unable to proxy any requests: " + e.getMessage(), + e ); + } + return configuration; + } + + private Map getProxyGroups() + throws ProxyException + { + if ( proxyGroups == null ) + { + Map groups = new HashMap(); + + Configuration configuration = getConfiguration(); + + ProxyInfo wagonProxy = createWagonProxy( configuration.getProxy() ); + + for ( Iterator i = configuration.getRepositories().iterator(); i.hasNext(); ) + { + RepositoryConfiguration repository = (RepositoryConfiguration) i.next(); + ArtifactRepository managedRepository = repositoryFactory.createRepository( repository ); + List proxiedRepositories = getProxiedRepositoriesForManagedRepository( + configuration.getProxiedRepositories(), repository.getId() ); + + groups.put( repository.getId(), + new ProxiedRepositoryGroup( proxiedRepositories, managedRepository, wagonProxy ) ); + } + + // TODO: ability to configure default proxy separately + + if ( groups.size() == 1 ) + { + defaultProxyGroup = (ProxiedRepositoryGroup) groups.values().iterator().next(); + } + + proxyGroups = groups; + } + return proxyGroups; + } + + private List getProxiedRepositoriesForManagedRepository( List proxiedRepositories, String id ) + { + List repositories = new ArrayList(); + for ( Iterator i = proxiedRepositories.iterator(); i.hasNext(); ) + { + ProxiedRepositoryConfiguration config = (ProxiedRepositoryConfiguration) i.next(); + + if ( config.getManagedRepository().equals( id ) ) + { + repositories.add( repositoryFactory.createProxiedRepository( config ) ); + } + } + return repositories; + } + + private static ProxiedRepositoryGroup parseRepositoryId( String path, Map groups ) + throws ProxyException, ResourceDoesNotExistException + { + ProxiedRepositoryGroup group = null; + + for ( Iterator i = groups.entrySet().iterator(); i.hasNext() && group == null; ) + { + Map.Entry entry = (Map.Entry) i.next(); + + if ( path.startsWith( "/" + entry.getKey() + "/" ) ) + { + group = (ProxiedRepositoryGroup) entry.getValue(); + } + } + + return group; + } + + private static ProxyInfo createWagonProxy( Proxy proxy ) + { + ProxyInfo proxyInfo = null; + if ( proxy != null && !StringUtils.isEmpty( proxy.getHost() ) ) + { + proxyInfo = new ProxyInfo(); + proxyInfo.setHost( proxy.getHost() ); + proxyInfo.setPort( proxy.getPort() ); + proxyInfo.setUserName( proxy.getUsername() ); + proxyInfo.setPassword( proxy.getPassword() ); + proxyInfo.setNonProxyHosts( proxy.getNonProxyHosts() ); + proxyInfo.setType( proxy.getProtocol() ); + } + return proxyInfo; + } +} diff --git a/archiva-core/src/main/java/org/apache/maven/repository/proxy/ProxiedRepositoryGroup.java b/archiva-core/src/main/java/org/apache/maven/repository/proxy/ProxiedRepositoryGroup.java new file mode 100644 index 000000000..326646c6f --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/repository/proxy/ProxiedRepositoryGroup.java @@ -0,0 +1,92 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.repository.ArtifactRepository; +import org.apache.maven.wagon.proxy.ProxyInfo; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * A set of information to store for a group of proxies. + * + * @author Brett Porter + */ +public class ProxiedRepositoryGroup +{ + + /** + * The locally managed repository that caches proxied artifacts. + */ + private ArtifactRepository managedRepository; + + /** + * The remote repositories that are being proxied. + */ + private List/**/ proxiedRepositories; + + /** + * A wagon proxy to communicate to the proxy repository over a proxy (eg, http proxy)... TerminologyOverflowException + */ + private final ProxyInfo wagonProxy; + + /** + * Constructor. + * + * @param proxiedRepositories the proxied repository + * @param managedRepository the locally managed repository + * @param wagonProxy the network proxy to use + */ + public ProxiedRepositoryGroup( List/**/ proxiedRepositories, + ArtifactRepository managedRepository, ProxyInfo wagonProxy ) + { + this.proxiedRepositories = proxiedRepositories; + + this.managedRepository = managedRepository; + + this.wagonProxy = wagonProxy; + } + + /** + * Constructor. + * + * @param proxiedRepositories the proxied repository + * @param managedRepository the locally managed repository + */ + public ProxiedRepositoryGroup( List/**/ proxiedRepositories, + ArtifactRepository managedRepository ) + { + this( proxiedRepositories, managedRepository, null ); + } + + public ArtifactRepository getManagedRepository() + { + return managedRepository; + } + + public List getProxiedRepositories() + { + return proxiedRepositories; + } + + public ProxyInfo getWagonProxy() + { + return wagonProxy; + } +} diff --git a/archiva-core/src/main/java/org/apache/maven/repository/proxy/ProxyManager.java b/archiva-core/src/main/java/org/apache/maven/repository/proxy/ProxyManager.java new file mode 100644 index 000000000..7973013a2 --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/repository/proxy/ProxyManager.java @@ -0,0 +1,58 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.wagon.ResourceDoesNotExistException; + +import java.io.File; + +/** + * Repository proxying component. This component will take requests for a given path within a managed repository + * and if it is not found or expired, will look in the specified proxy repositories. + * + * @author Brett Porter + */ +public interface ProxyManager +{ + /** The Plexus role for the component. */ + String ROLE = ProxyManager.class.getName(); + + /** + * Used to retrieve a cached path or retrieve one if the cache does not contain it yet. + * + * @param path the expected repository path + * @return File object referencing the requested path in the cache + * @throws ProxyException when an exception occurred during the retrieval of the requested path + * @throws org.apache.maven.wagon.ResourceDoesNotExistException when the requested object can't be found in any of the + * configured repositories + */ + File get( String path ) + throws ProxyException, ResourceDoesNotExistException; + + /** + * Used to force remote download of the requested path from any the configured repositories. This method will + * only bypass the cache for searching but the requested path will still be cached. + * + * @param path the expected repository path + * @return File object referencing the requested path in the cache + * @throws ProxyException when an exception occurred during the retrieval of the requested path + * @throws ResourceDoesNotExistException when the requested object can't be found in any of the + * configured repositories + */ + File getAlways( String path ) + throws ProxyException, ResourceDoesNotExistException; +} diff --git a/archiva-core/src/main/java/org/apache/maven/repository/scheduler/DefaultRepositoryTaskScheduler.java b/archiva-core/src/main/java/org/apache/maven/repository/scheduler/DefaultRepositoryTaskScheduler.java new file mode 100644 index 000000000..4e145b890 --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/repository/scheduler/DefaultRepositoryTaskScheduler.java @@ -0,0 +1,171 @@ +package org.apache.maven.repository.scheduler; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.repository.configuration.Configuration; +import org.apache.maven.repository.configuration.ConfigurationChangeException; +import org.apache.maven.repository.configuration.ConfigurationChangeListener; +import org.apache.maven.repository.configuration.ConfigurationStore; +import org.apache.maven.repository.configuration.ConfigurationStoreException; +import org.apache.maven.repository.configuration.InvalidConfigurationException; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartingException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.StoppingException; +import org.codehaus.plexus.scheduler.AbstractJob; +import org.codehaus.plexus.scheduler.Scheduler; +import org.quartz.CronTrigger; +import org.quartz.JobDataMap; +import org.quartz.JobDetail; +import org.quartz.SchedulerException; + +import java.text.ParseException; + +/** + * Default implementation of a scheduling component for the application. + * + * @author Brett Porter + * @todo should we use plexus-taskqueue instead of or in addition to this? + * @plexus.component role="org.apache.maven.repository.scheduler.RepositoryTaskScheduler" + */ +public class DefaultRepositoryTaskScheduler + extends AbstractLogEnabled + implements RepositoryTaskScheduler, Startable, ConfigurationChangeListener +{ + /** + * @plexus.requirement + */ + private Scheduler scheduler; + + /** + * @plexus.requirement + */ + private ConfigurationStore configurationStore; + + private static final String DISCOVERER_GROUP = "DISCOVERER"; + + private static final String INDEXER_JOB = "indexerTask"; + + /** + * @plexus.requirement role-hint="indexer" + */ + private RepositoryTask indexerTask; + + public void start() + throws StartingException + { + Configuration configuration; + try + { + configuration = configurationStore.getConfigurationFromStore(); + configurationStore.addChangeListener( this ); + } + catch ( ConfigurationStoreException e ) + { + throw new StartingException( "Unable to read configuration from the store", e ); + } + + try + { + scheduleJobs( configuration ); + } + catch ( ParseException e ) + { + throw new StartingException( "Invalid configuration: " + configuration.getIndexerCronExpression(), e ); + } + catch ( SchedulerException e ) + { + throw new StartingException( "Unable to start scheduler: " + e.getMessage(), e ); + } + } + + private void scheduleJobs( Configuration configuration ) + throws ParseException, SchedulerException + { + if ( configuration.getIndexPath() != null ) + { + JobDetail jobDetail = new JobDetail( INDEXER_JOB, DISCOVERER_GROUP, RepositoryTaskJob.class ); + JobDataMap dataMap = new JobDataMap(); + dataMap.put( AbstractJob.LOGGER, getLogger() ); + dataMap.put( RepositoryTaskJob.TASK_KEY, indexerTask ); + jobDetail.setJobDataMap( dataMap ); + + getLogger().info( "Scheduling indexer: " + configuration.getIndexerCronExpression() ); + CronTrigger trigger = + new CronTrigger( INDEXER_JOB + "Trigger", DISCOVERER_GROUP, configuration.getIndexerCronExpression() ); + scheduler.scheduleJob( jobDetail, trigger ); + + // TODO: run as a job so it doesn't block startup/configuration saving + try + { + indexerTask.executeNowIfNeeded(); + } + catch ( TaskExecutionException e ) + { + getLogger().error( "Error executing task first time, continuing anyway: " + e.getMessage(), e ); + } + } + else + { + getLogger().info( "Not scheduling indexer - index path is not configured" ); + } + + // TODO: wire in the converter + } + + public void stop() + throws StoppingException + { + try + { + scheduler.unscheduleJob( INDEXER_JOB, DISCOVERER_GROUP ); + } + catch ( SchedulerException e ) + { + throw new StoppingException( "Unable to unschedule tasks", e ); + } + } + + public void notifyOfConfigurationChange( Configuration configuration ) + throws InvalidConfigurationException, ConfigurationChangeException + { + try + { + stop(); + + scheduleJobs( configuration ); + } + catch ( StoppingException e ) + { + throw new ConfigurationChangeException( "Unable to unschedule previous tasks", e ); + } + catch ( ParseException e ) + { + throw new InvalidConfigurationException( "indexerCronExpression", "Invalid cron expression", e ); + } + catch ( SchedulerException e ) + { + throw new ConfigurationChangeException( "Unable to schedule new tasks", e ); + } + } + + public void runIndexer() + throws TaskExecutionException + { + indexerTask.execute(); + } +} diff --git a/archiva-core/src/main/java/org/apache/maven/repository/scheduler/IndexerTask.java b/archiva-core/src/main/java/org/apache/maven/repository/scheduler/IndexerTask.java new file mode 100644 index 000000000..38b43a0ac --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/repository/scheduler/IndexerTask.java @@ -0,0 +1,182 @@ +package org.apache.maven.repository.scheduler; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.repository.configuration.Configuration; +import org.apache.maven.repository.configuration.ConfigurationStore; +import org.apache.maven.repository.configuration.ConfigurationStoreException; +import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; +import org.apache.maven.repository.configuration.RepositoryConfiguration; +import org.apache.maven.repository.discovery.ArtifactDiscoverer; +import org.apache.maven.repository.discovery.DiscovererException; +import org.apache.maven.repository.indexing.RepositoryArtifactIndex; +import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; +import org.apache.maven.repository.indexing.RepositoryIndexException; +import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory; +import org.codehaus.plexus.logging.AbstractLogEnabled; + +import java.io.File; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * Task for discovering changes in the repository. + * + * @author Brett Porter + * @plexus.component role="org.apache.maven.repository.scheduler.RepositoryTask" role-hint="indexer" + */ +public class IndexerTask + extends AbstractLogEnabled + implements RepositoryTask +{ + /** + * Configuration store. + * + * @plexus.requirement + */ + private ConfigurationStore configurationStore; + + /** + * @plexus.requirement + */ + private RepositoryArtifactIndexFactory indexFactory; + + /** + * @plexus.requirement + */ + private ConfiguredRepositoryFactory repoFactory; + + /** + * @plexus.requirement role="org.apache.maven.repository.discovery.ArtifactDiscoverer" + */ + private Map artifactDiscoverers; + + /** + * @plexus.requirement role-hint="standard" + */ + private RepositoryIndexRecordFactory recordFactory; + + public void execute() + throws TaskExecutionException + { + Configuration configuration; + try + { + configuration = configurationStore.getConfigurationFromStore(); + } + catch ( ConfigurationStoreException e ) + { + throw new TaskExecutionException( e.getMessage(), e ); + } + + File indexPath = new File( configuration.getIndexPath() ); + + execute( configuration, indexPath ); + } + + private void execute( Configuration configuration, File indexPath ) + throws TaskExecutionException + { + long time = System.currentTimeMillis(); + getLogger().info( "Starting repository discovery process" ); + + try + { + for ( Iterator i = configuration.getRepositories().iterator(); i.hasNext(); ) + { + RepositoryConfiguration repositoryConfiguration = (RepositoryConfiguration) i.next(); + + if ( repositoryConfiguration.isIndexed() ) + { + // TODO! include global ones + String blacklistedPatterns = repositoryConfiguration.getBlackListPatterns(); + boolean includeSnapshots = repositoryConfiguration.isIncludeSnapshots(); + + ArtifactRepository repository = repoFactory.createRepository( repositoryConfiguration ); + + String layoutProperty = repositoryConfiguration.getLayout(); + ArtifactDiscoverer discoverer = (ArtifactDiscoverer) artifactDiscoverers.get( layoutProperty ); + List artifacts = + discoverer.discoverArtifacts( repository, "indexer", blacklistedPatterns, includeSnapshots ); + if ( !artifacts.isEmpty() ) + { + getLogger().info( "Indexing " + artifacts.size() + " new artifacts" ); + indexArtifacts( artifacts, indexPath ); + } + } + } + } + catch ( RepositoryIndexException e ) + { + throw new TaskExecutionException( e.getMessage(), e ); + } + catch ( DiscovererException e ) + { + throw new TaskExecutionException( e.getMessage(), e ); + } + + time = System.currentTimeMillis() - time; + getLogger().info( "Finished repository indexing process in " + time + "ms" ); + } + + public void executeNowIfNeeded() + throws TaskExecutionException + { + Configuration configuration; + try + { + configuration = configurationStore.getConfigurationFromStore(); + } + catch ( ConfigurationStoreException e ) + { + throw new TaskExecutionException( e.getMessage(), e ); + } + + File indexPath = new File( configuration.getIndexPath() ); + + try + { + RepositoryArtifactIndex artifactIndex = indexFactory.createStandardIndex( indexPath ); + if ( !artifactIndex.exists() ) + { + execute( configuration, indexPath ); + } + } + catch ( RepositoryIndexException e ) + { + throw new TaskExecutionException( e.getMessage(), e ); + } + } + + private void indexArtifacts( List artifacts, File indexPath ) + throws RepositoryIndexException + { + List records = new ArrayList(); + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + records.add( recordFactory.createRecord( a ) ); + } + + RepositoryArtifactIndex artifactIndex = indexFactory.createStandardIndex( indexPath ); + artifactIndex.indexRecords( records ); + } +} diff --git a/archiva-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTask.java b/archiva-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTask.java new file mode 100644 index 000000000..92b6f93cd --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTask.java @@ -0,0 +1,37 @@ +package org.apache.maven.repository.scheduler; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * A repository task. + * + * @author Brett Porter + */ +public interface RepositoryTask +{ + /** + * Execute the task. + */ + void execute() + throws TaskExecutionException; + + /** + * Execute the task now if needed because the target doesn't exist. + */ + void executeNowIfNeeded() + throws TaskExecutionException; +} diff --git a/archiva-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskJob.java b/archiva-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskJob.java new file mode 100644 index 000000000..874f6bcf2 --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskJob.java @@ -0,0 +1,56 @@ +package org.apache.maven.repository.scheduler; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.scheduler.AbstractJob; +import org.quartz.JobDataMap; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +/** + * This class is the discoverer job that is executed by the scheduler. + */ +public class RepositoryTaskJob + extends AbstractJob +{ + static final String TASK_KEY = "EXECUTION"; + + /** + * Execute the discoverer and the indexer. + * + * @param context + * @throws org.quartz.JobExecutionException + * + */ + public void execute( JobExecutionContext context ) + throws JobExecutionException + { + JobDataMap dataMap = context.getJobDetail().getJobDataMap(); + setJobDataMap( dataMap ); + + RepositoryTask executor = (RepositoryTask) dataMap.get( TASK_KEY ); + try + { + executor.execute(); + } + catch ( TaskExecutionException e ) + { + throw new JobExecutionException( e ); + } + } + +} diff --git a/archiva-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskScheduler.java b/archiva-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskScheduler.java new file mode 100644 index 000000000..46db976b3 --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskScheduler.java @@ -0,0 +1,33 @@ +package org.apache.maven.repository.scheduler; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * The component that takes care of scheduling in the application. + * + * @author Brett Porter + */ +public interface RepositoryTaskScheduler +{ + /** + * The Plexus component role. + */ + String ROLE = RepositoryTaskScheduler.class.getName(); + + void runIndexer() + throws TaskExecutionException; +} diff --git a/archiva-core/src/main/java/org/apache/maven/repository/scheduler/TaskExecutionException.java b/archiva-core/src/main/java/org/apache/maven/repository/scheduler/TaskExecutionException.java new file mode 100644 index 000000000..7ab229021 --- /dev/null +++ b/archiva-core/src/main/java/org/apache/maven/repository/scheduler/TaskExecutionException.java @@ -0,0 +1,31 @@ +package org.apache.maven.repository.scheduler; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * Exception occurring during task execution. + * + * @author Brett Porter + */ +public class TaskExecutionException + extends Exception +{ + public TaskExecutionException( String message, Throwable t ) + { + super( message, t ); + } +} diff --git a/archiva-core/src/test/java/org/apache/maven/repository/RepositoryManagerTest.java b/archiva-core/src/test/java/org/apache/maven/repository/RepositoryManagerTest.java new file mode 100644 index 000000000..5fb084590 --- /dev/null +++ b/archiva-core/src/test/java/org/apache/maven/repository/RepositoryManagerTest.java @@ -0,0 +1,24 @@ +package org.apache.maven.repository; + +import org.codehaus.plexus.PlexusTestCase; + +import java.io.File; + +/** + * @author Jason van Zyl + */ +public class RepositoryManagerTest + extends PlexusTestCase +{ + public void testLegacyRepositoryConversion() + throws Exception + { + File legacyRepositoryDirectory = getTestFile( "src/test/maven-1.x-repository" ); + + File repositoryDirectory = getTestFile( "target/maven-2.x-repository" ); + + RepositoryManager rm = (RepositoryManager) lookup( RepositoryManager.ROLE ); + + rm.convertLegacyRepository( legacyRepositoryDirectory, repositoryDirectory, true ); + } +} diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/artifact-one-1.0.0.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/artifact-one-1.0.0.jar new file mode 100644 index 000000000..5626abf0f --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/artifact-one-1.0.0.jar @@ -0,0 +1 @@ +one diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/artifact-three-1.0.0.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/artifact-three-1.0.0.jar new file mode 100644 index 000000000..2bdf67abb --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/artifact-three-1.0.0.jar @@ -0,0 +1 @@ +three diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/artifact-two-1.0.0.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/artifact-two-1.0.0.jar new file mode 100644 index 000000000..f719efd43 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/artifact-two-1.0.0.jar @@ -0,0 +1 @@ +two diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/dryrun-artifact-1.0.0.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/dryrun-artifact-1.0.0.jar new file mode 100644 index 000000000..cbaf024e5 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/dryrun-artifact-1.0.0.jar @@ -0,0 +1 @@ +existing diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/existing-artifact-1.0.0.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/existing-artifact-1.0.0.jar new file mode 100644 index 000000000..cbaf024e5 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/existing-artifact-1.0.0.jar @@ -0,0 +1 @@ +existing diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/incorrectMd5Artifact-1.0.0.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/incorrectMd5Artifact-1.0.0.jar new file mode 100644 index 000000000..72af4bc10 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/incorrectMd5Artifact-1.0.0.jar @@ -0,0 +1 @@ +incorrectMd5 diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/incorrectMd5Artifact-1.0.0.jar.md5 b/archiva-core/src/test/maven-1.x-repository/test/jars/incorrectMd5Artifact-1.0.0.jar.md5 new file mode 100644 index 000000000..316d9a4eb --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/incorrectMd5Artifact-1.0.0.jar.md5 @@ -0,0 +1 @@ +379dcfcd1e6312cc859111f696047eb4 diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/incorrectSha1Artifact-1.0.0.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/incorrectSha1Artifact-1.0.0.jar new file mode 100644 index 000000000..f5812f3e5 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/incorrectSha1Artifact-1.0.0.jar @@ -0,0 +1 @@ +incorrectSha1 diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/incorrectSha1Artifact-1.0.0.jar.sha1 b/archiva-core/src/test/maven-1.x-repository/test/jars/incorrectSha1Artifact-1.0.0.jar.sha1 new file mode 100644 index 000000000..cce322eb2 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/incorrectSha1Artifact-1.0.0.jar.sha1 @@ -0,0 +1 @@ +52e07b82d944741f66bba5896d4cd74e9879e289 diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/modified-artifact-1.0.0.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/modified-artifact-1.0.0.jar new file mode 100644 index 000000000..2e0996000 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/modified-artifact-1.0.0.jar @@ -0,0 +1 @@ +modified diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/newversion-artifact-1.0.1.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/newversion-artifact-1.0.1.jar new file mode 100644 index 000000000..c694117fd --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/newversion-artifact-1.0.1.jar @@ -0,0 +1 @@ +v4 diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/noPomArtifact-1.0.0.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/noPomArtifact-1.0.0.jar new file mode 100644 index 000000000..3d27acdcc --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/noPomArtifact-1.0.0.jar @@ -0,0 +1 @@ +noPom diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/relocated-v3artifact-1.0.0.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/relocated-v3artifact-1.0.0.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/relocated-v3artifact-1.0.0.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/rollback-created-artifact-1.0.0.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/rollback-created-artifact-1.0.0.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/rollback-created-artifact-1.0.0.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/unmodified-artifact-1.0.0.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/unmodified-artifact-1.0.0.jar new file mode 100644 index 000000000..27597bc21 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/unmodified-artifact-1.0.0.jar @@ -0,0 +1 @@ +unmodified diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/v3-warnings-artifact-1.0.0.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/v3-warnings-artifact-1.0.0.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/v3-warnings-artifact-1.0.0.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0-20060105.130101-3.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0-20060105.130101-3.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0-20060105.130101-3.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0-SNAPSHOT.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0-SNAPSHOT.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0-SNAPSHOT.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0-20060111.120115-1.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0-20060111.120115-1.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0-20060111.120115-1.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0-SNAPSHOT.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0-SNAPSHOT.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0-SNAPSHOT.jar @@ -0,0 +1 @@ +v3 diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar b/archiva-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar new file mode 100644 index 000000000..c694117fd --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar @@ -0,0 +1 @@ +v4 diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar.md5 b/archiva-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar.md5 new file mode 100644 index 000000000..1930bc6d3 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar.md5 @@ -0,0 +1 @@ +4289bbdd6fba75013b317b2f9a540736 *v4artifact-1.0.0.jar diff --git a/archiva-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar.sha1 b/archiva-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar.sha1 new file mode 100644 index 000000000..466f209a7 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar.sha1 @@ -0,0 +1 @@ +e3e4159da65a4257f0bffb7cac8e3e78241a4dca *v4artifact-1.0.0.jar diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/artifact-one-1.0.0.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/artifact-one-1.0.0.pom new file mode 100644 index 000000000..cd3862d35 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/artifact-one-1.0.0.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + artifact-one + 1.0.0 + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/artifact-three-1.0.0.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/artifact-three-1.0.0.pom new file mode 100644 index 000000000..343291037 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/artifact-three-1.0.0.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + artifact-three + 1.0.0 + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/artifact-two-1.0.0.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/artifact-two-1.0.0.pom new file mode 100644 index 000000000..227470167 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/artifact-two-1.0.0.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + artifact-two + 1.0.0 + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/dryrun-artifact-1.0.0.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/dryrun-artifact-1.0.0.pom new file mode 100644 index 000000000..1953c5523 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/dryrun-artifact-1.0.0.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + dryrun-artifact + test + 1.0.0 + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/incorrectMd5Artifact-1.0.0.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/incorrectMd5Artifact-1.0.0.pom new file mode 100644 index 000000000..74d5e12b4 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/incorrectMd5Artifact-1.0.0.pom @@ -0,0 +1,6 @@ + + 3 + incorrectMd5Artifact + test + 1.0.0 + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/incorrectSha1Artifact-1.0.0.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/incorrectSha1Artifact-1.0.0.pom new file mode 100644 index 000000000..fe3c7fd91 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/incorrectSha1Artifact-1.0.0.pom @@ -0,0 +1,6 @@ + + 3 + incorrectSha1Artifact + test + 1.0.0 + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/modified-artifact-1.0.0.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/modified-artifact-1.0.0.pom new file mode 100644 index 000000000..fcfdaacb4 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/modified-artifact-1.0.0.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + modified-artifact + test + 1.0.0 + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/newversion-artifact-1.0.1.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/newversion-artifact-1.0.1.pom new file mode 100644 index 000000000..f441c9a46 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/newversion-artifact-1.0.1.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + test + newversoin-artifact + 1.0.1 + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/relocated-v3artifact-1.0.0.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/relocated-v3artifact-1.0.0.pom new file mode 100644 index 000000000..10823fe89 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/relocated-v3artifact-1.0.0.pom @@ -0,0 +1,27 @@ + + 3 + relocated-v3artifact + test + 1.0.0 + + + groupId + artifactId + version + + + groupId + test-artifactId + version + + test + + + + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + + relocated-test + + \ No newline at end of file diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/rollback-created-artifact-1.0.0.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/rollback-created-artifact-1.0.0.pom new file mode 100644 index 000000000..00692be72 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/rollback-created-artifact-1.0.0.pom @@ -0,0 +1,39 @@ + + + + 3 + v3artifact + test + 1.0.0 + + + groupId + artifactId + version + + + groupId + test-artifactId + version + + test + + + + + + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/unmodified-artifact-1.0.0.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/unmodified-artifact-1.0.0.pom new file mode 100644 index 000000000..c570979f4 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/unmodified-artifact-1.0.0.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + unmodified-artifact + test + 1.0.0 + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/v3-warnings-artifact-1.0.0.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/v3-warnings-artifact-1.0.0.pom new file mode 100644 index 000000000..5f347f371 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/v3-warnings-artifact-1.0.0.pom @@ -0,0 +1,48 @@ + + + + 3 + ../project.xml + v3-warnings-artifact + test + 1.0.0 + + + 1.0 + 1.0 + 1_0 + + + + + groupId + artifactId + version + + + groupId + test-artifactId + version + + test + + + + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0-20060105.130101-3.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0-20060105.130101-3.pom new file mode 100644 index 000000000..d7ae8953b --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0-20060105.130101-3.pom @@ -0,0 +1,40 @@ + + + + 3 + v3artifact + test + 1.0.0-20060105.130101-3 + + + groupId + artifactId + version + + + groupId + test-artifactId + version + + test + + + + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0-SNAPSHOT.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0-SNAPSHOT.pom new file mode 100644 index 000000000..3958a3358 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0-SNAPSHOT.pom @@ -0,0 +1,40 @@ + + + + 3 + v3artifact + test + 1.0.0-SNAPSHOT + + + groupId + artifactId + version + + + groupId + test-artifactId + version + + test + + + + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0.pom new file mode 100644 index 000000000..5aed3437a --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0.pom @@ -0,0 +1,24 @@ + + 3 + v3artifact + test + 1.0.0 + + + groupId + artifactId + version + + + groupId + test-artifactId + version + + test + + + + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0-20060111.120115-1.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0-20060111.120115-1.pom new file mode 100644 index 000000000..e4f36566a --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0-20060111.120115-1.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + test + v4artifact + 1.0.0-20060111.120115-1 + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0-SNAPSHOT.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0-SNAPSHOT.pom new file mode 100644 index 000000000..be5b8b7e2 --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0-SNAPSHOT.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + test + v4artifact + 1.0.0-SNAPSHOT + diff --git a/archiva-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0.pom b/archiva-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0.pom new file mode 100644 index 000000000..fa6e82b1e --- /dev/null +++ b/archiva-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + v4artifact + 1.0.0 + diff --git a/archiva-discoverer/pom.xml b/archiva-discoverer/pom.xml new file mode 100755 index 000000000..fed41016b --- /dev/null +++ b/archiva-discoverer/pom.xml @@ -0,0 +1,57 @@ + + + + + org.apache.maven.archiva + archiva + 1.0-SNAPSHOT + + 4.0.0 + archiva-discoverer + Archiva Artifact Discoverer + + + org.apache.maven.archiva + archiva-utils + + + org.codehaus.plexus + plexus-utils + + + org.codehaus.plexus + plexus-container-default + + + org.apache.maven + maven-artifact + + + org.apache.maven + maven-repository-metadata + + + org.apache.maven + maven-artifact-manager + + + org.apache.maven + maven-model + + + diff --git a/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java new file mode 100644 index 000000000..3faa8bd47 --- /dev/null +++ b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java @@ -0,0 +1,149 @@ +package org.apache.maven.repository.discovery; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.codehaus.plexus.util.xml.Xpp3Dom; + +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; + +/** + * Base class for artifact discoverers. + * + * @author John Casey + * @author Brett Porter + */ +public abstract class AbstractArtifactDiscoverer + extends AbstractDiscoverer + implements ArtifactDiscoverer +{ + /** + * Standard patterns to exclude from discovery as they are not artifacts. + */ + private static final String[] STANDARD_DISCOVERY_EXCLUDES = {"bin/**", "reports/**", ".maven/**", "**/*.md5", + "**/*.MD5", "**/*.sha1", "**/*.SHA1", "**/*snapshot-version", "*/website/**", "*/licenses/**", "*/licences/**", + "**/.htaccess", "**/*.html", "**/*.asc", "**/*.txt", "**/*.xml", "**/README*", "**/CHANGELOG*", "**/KEYS*"}; + + private List scanForArtifactPaths( File repositoryBase, String blacklistedPatterns, long comparisonTimestamp ) + { + return scanForArtifactPaths( repositoryBase, blacklistedPatterns, null, STANDARD_DISCOVERY_EXCLUDES, + comparisonTimestamp ); + } + + public List discoverArtifacts( ArtifactRepository repository, String operation, String blacklistedPatterns, + boolean includeSnapshots ) + throws DiscovererException + { + if ( !"file".equals( repository.getProtocol() ) ) + { + throw new UnsupportedOperationException( "Only filesystem repositories are supported" ); + } + + Xpp3Dom dom = getLastArtifactDiscoveryDom( readRepositoryMetadataDom( repository ) ); + long comparisonTimestamp = readComparisonTimestamp( repository, operation, dom ); + + // Note that last checked time is deliberately set to the start of the process so that anything added + // mid-discovery and missed by the scanner will get checked next time. + // Due to this, there must be no negative side-effects of discovering something twice. + Date newLastCheckedTime = new Date(); + + File repositoryBase = new File( repository.getBasedir() ); + + List artifacts = new ArrayList(); + + List artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns, comparisonTimestamp ); + + // Also note that the last check time, while set at the start, is saved at the end, so that if any exceptions + // occur, then the timestamp is not updated so that the discovery is attempted again + // TODO: under the list-return behaviour we have now, exceptions might occur later and the timestamp will not be reset - see MRM-83 + try + { + setLastCheckedTime( repository, operation, newLastCheckedTime ); + } + catch ( IOException e ) + { + throw new DiscovererException( "Error writing metadata: " + e.getMessage(), e ); + } + + for ( Iterator i = artifactPaths.iterator(); i.hasNext(); ) + { + String path = (String) i.next(); + + try + { + Artifact artifact = buildArtifactFromPath( path, repository ); + + if ( includeSnapshots || !artifact.isSnapshot() ) + { + artifacts.add( artifact ); + } + } + catch ( DiscovererException e ) + { + addKickedOutPath( path, e.getMessage() ); + } + } + + return artifacts; + } + + /** + * Returns an artifact object that is represented by the specified path in a repository + * + * @param path The path that is pointing to an artifact + * @param repository The repository of the artifact + * @return Artifact + * @throws DiscovererException when the specified path does correspond to an artifact + */ + public Artifact buildArtifactFromPath( String path, ArtifactRepository repository ) + throws DiscovererException + { + Artifact artifact = buildArtifact( path ); + + if ( artifact != null ) + { + artifact.setRepository( repository ); + artifact.setFile( new File( repository.getBasedir(), path ) ); + } + + return artifact; + } + + public void setLastCheckedTime( ArtifactRepository repository, String operation, Date date ) + throws IOException + { + // see notes in resetLastCheckedTime + + File file = new File( repository.getBasedir(), "maven-metadata.xml" ); + + Xpp3Dom dom = readDom( file ); + + String dateString = new SimpleDateFormat( DATE_FMT, Locale.US ).format( date ); + + setEntry( getLastArtifactDiscoveryDom( dom ), operation, dateString ); + + saveDom( file, dom ); + } +} diff --git a/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java new file mode 100644 index 000000000..6888b23a9 --- /dev/null +++ b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java @@ -0,0 +1,304 @@ +package org.apache.maven.repository.discovery; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.DirectoryScanner; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.codehaus.plexus.util.xml.Xpp3DomBuilder; +import org.codehaus.plexus.util.xml.Xpp3DomWriter; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; + +/** + * Base class for the artifact and metadata discoverers. + * + * @author Brett Porter + */ +public abstract class AbstractDiscoverer + extends AbstractLogEnabled + implements Discoverer +{ + private List kickedOutPaths = new ArrayList(); + + /** + * @plexus.requirement + */ + protected ArtifactFactory artifactFactory; + + private static final String[] EMPTY_STRING_ARRAY = new String[0]; + + private List excludedPaths = new ArrayList(); + + /** + * @plexus.configuration default-value="60000" + */ + private int blackoutPeriod; + + protected static final String DATE_FMT = "yyyyMMddHHmmss"; + + /** + * Add a path to the list of files that were kicked out due to being invalid. + * + * @param path the path to add + * @param reason the reason why the path is being kicked out + */ + protected void addKickedOutPath( String path, String reason ) + { + kickedOutPaths.add( new DiscovererPath( path, reason ) ); + } + + /** + * Returns an iterator for the list if DiscovererPaths that were found to not represent a searched object + * + * @return Iterator for the DiscovererPath List + */ + public Iterator getKickedOutPathsIterator() + { + return kickedOutPaths.iterator(); + } + + protected List scanForArtifactPaths( File repositoryBase, String blacklistedPatterns, String[] includes, + String[] excludes, long comparisonTimestamp ) + { + List allExcludes = new ArrayList(); + allExcludes.addAll( FileUtils.getDefaultExcludesAsList() ); + if ( excludes != null ) + { + allExcludes.addAll( Arrays.asList( excludes ) ); + } + + if ( !StringUtils.isEmpty( blacklistedPatterns ) ) + { + allExcludes.addAll( Arrays.asList( blacklistedPatterns.split( "," ) ) ); + } + + DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir( repositoryBase ); + if ( includes != null ) + { + scanner.setIncludes( includes ); + } + scanner.setExcludes( (String[]) allExcludes.toArray( EMPTY_STRING_ARRAY ) ); + + // TODO: Correct for extremely large repositories (artifact counts over 200,000 entries) + scanner.scan(); + + for ( Iterator files = Arrays.asList( scanner.getExcludedFiles() ).iterator(); files.hasNext(); ) + { + String path = files.next().toString(); + + excludedPaths.add( new DiscovererPath( path, "Artifact was in the specified list of exclusions" ) ); + } + + // TODO: this could be a part of the scanner + List includedPaths = new ArrayList(); + for ( Iterator files = Arrays.asList( scanner.getIncludedFiles() ).iterator(); files.hasNext(); ) + { + String path = files.next().toString(); + + long modTime = new File( repositoryBase, path ).lastModified(); + if ( modTime < System.currentTimeMillis() - blackoutPeriod ) + { + if ( modTime > comparisonTimestamp ) + { + includedPaths.add( path ); + } + } + } + + return includedPaths; + } + + /** + * Returns an iterator for the list if DiscovererPaths that were not processed because they are explicitly excluded + * + * @return Iterator for the DiscovererPath List + */ + public Iterator getExcludedPathsIterator() + { + return excludedPaths.iterator(); + } + + protected long readComparisonTimestamp( ArtifactRepository repository, String operation, Xpp3Dom dom ) + { + Xpp3Dom entry = dom.getChild( operation ); + long comparisonTimestamp = 0; + if ( entry != null ) + { + try + { + comparisonTimestamp = new SimpleDateFormat( DATE_FMT, Locale.US ).parse( entry.getValue() ).getTime(); + } + catch ( ParseException e ) + { + getLogger().error( "Timestamp was invalid: " + entry.getValue() + "; ignoring" ); + } + } + return comparisonTimestamp; + } + + protected Xpp3Dom readDom( File file ) + { + Xpp3Dom dom; + FileReader fileReader = null; + try + { + fileReader = new FileReader( file ); + dom = Xpp3DomBuilder.build( fileReader ); + } + catch ( FileNotFoundException e ) + { + // Safe to ignore + dom = new Xpp3Dom( "metadata" ); + } + catch ( XmlPullParserException e ) + { + getLogger().error( "Error reading metadata (ignoring and recreating): " + e.getMessage() ); + dom = new Xpp3Dom( "metadata" ); + } + catch ( IOException e ) + { + getLogger().error( "Error reading metadata (ignoring and recreating): " + e.getMessage() ); + dom = new Xpp3Dom( "metadata" ); + } + finally + { + IOUtil.close( fileReader ); + } + return dom; + } + + protected Xpp3Dom getLastArtifactDiscoveryDom( Xpp3Dom dom ) + { + Xpp3Dom lastDiscoveryDom = dom.getChild( "lastArtifactDiscovery" ); + if ( lastDiscoveryDom == null ) + { + dom.addChild( new Xpp3Dom( "lastArtifactDiscovery" ) ); + lastDiscoveryDom = dom.getChild( "lastArtifactDiscovery" ); + } + return lastDiscoveryDom; + } + + protected Xpp3Dom getLastMetadataDiscoveryDom( Xpp3Dom dom ) + { + Xpp3Dom lastDiscoveryDom = dom.getChild( "lastMetadataDiscovery" ); + if ( lastDiscoveryDom == null ) + { + dom.addChild( new Xpp3Dom( "lastMetadataDiscovery" ) ); + lastDiscoveryDom = dom.getChild( "lastMetadataDiscovery" ); + } + return lastDiscoveryDom; + } + + public void resetLastCheckedTime( ArtifactRepository repository, String operation ) + throws IOException + { + // TODO: get these changes into maven-metadata.xml and migrate towards that. The model is further diverging to a different layout at each level so submodels might be a good idea. + // TODO: maven-artifact probably needs an improved pathOfMetadata to cope with top level metadata + // TODO: might we need to write this as maven-metadata-local in some circumstances? merge others? Probably best to keep it simple and just use this format at the root. No need to merge anything that I can see + // TODO: since this metadata isn't meant to be shared, perhaps another file is called for after all. + // Format is: yyyyMMddHHmmss (ie, flat properties) + + File file = new File( repository.getBasedir(), "maven-metadata.xml" ); + + Xpp3Dom dom = readDom( file ); + + boolean changed = false; + + if ( removeEntry( getLastArtifactDiscoveryDom( dom ), operation ) ) + { + changed = true; + } + + if ( removeEntry( getLastMetadataDiscoveryDom( dom ), operation ) ) + { + changed = true; + } + + if ( changed ) + { + saveDom( file, dom ); + } + } + + private boolean removeEntry( Xpp3Dom lastDiscoveryDom, String operation ) + { + boolean changed = false; + + // do this in reverse so that removing doesn't affect counter + Xpp3Dom[] children = lastDiscoveryDom.getChildren(); + for ( int i = lastDiscoveryDom.getChildCount() - 1; i >= 0; i-- ) + { + if ( children[i].getName().equals( operation ) ) + { + changed = true; + lastDiscoveryDom.removeChild( i ); + } + } + return changed; + } + + protected void saveDom( File file, Xpp3Dom dom ) + throws IOException + { + FileWriter writer = new FileWriter( file ); + + // save metadata + try + { + Xpp3DomWriter.write( writer, dom ); + } + finally + { + IOUtil.close( writer ); + } + } + + protected void setEntry( Xpp3Dom lastDiscoveryDom, String operation, String dateString ) + { + Xpp3Dom entry = lastDiscoveryDom.getChild( operation ); + if ( entry == null ) + { + entry = new Xpp3Dom( operation ); + lastDiscoveryDom.addChild( entry ); + } + entry.setValue( dateString ); + } + + protected Xpp3Dom readRepositoryMetadataDom( ArtifactRepository repository ) + { + return readDom( new File( repository.getBasedir(), "maven-metadata.xml" ) ); + } +} diff --git a/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java new file mode 100644 index 000000000..ec9698cdf --- /dev/null +++ b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java @@ -0,0 +1,64 @@ +package org.apache.maven.repository.discovery; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; + +import java.util.List; + +/** + * Interface for implementation that can discover artifacts within a repository. + * + * @author John Casey + * @author Brett Porter + * @todo do we want blacklisted patterns in another form? Part of the object construction? + * @todo should includeSnapshots be configuration on the component? If not, should the methods be changed to include alternates for both possibilities (discoverReleaseArtifacts, discoverReleaseAndSnapshotArtifacts)? + * @todo instead of a returned list, should a listener be passed in? + */ +public interface ArtifactDiscoverer + extends Discoverer +{ + String ROLE = ArtifactDiscoverer.class.getName(); + + /** + * Discover artifacts in the repository. Only artifacts added since the last attempt at discovery will be found. + * This process guarantees never to miss an artifact, however it is possible that an artifact will be received twice + * consecutively even if unchanged, so any users of this list must handle such a situation gracefully. + * + * @param repository the location of the repository + * @param operation the operation being used to discover for timestamp checking + * @param blacklistedPatterns pattern that lists any files to prevent from being included when scanning + * @param includeSnapshots whether to discover snapshots + * @return the list of artifacts discovered + * @throws DiscovererException if there was an unrecoverable problem discovering artifacts or recording progress + */ + List discoverArtifacts( ArtifactRepository repository, String operation, String blacklistedPatterns, + boolean includeSnapshots ) + throws DiscovererException; + + /** + * Build an artifact from a path in the repository + * + * @param path the path + * @return the artifact + * @throws DiscovererException if the file is not a valid artifact + * @todo this should be in maven-artifact + */ + Artifact buildArtifact( String path ) + throws DiscovererException; +} diff --git a/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java new file mode 100644 index 000000000..f7dabe3fc --- /dev/null +++ b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java @@ -0,0 +1,190 @@ +package org.apache.maven.repository.discovery; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.codehaus.plexus.util.StringUtils; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.StringTokenizer; + +/** + * Artifact discoverer for the new repository layout (Maven 2.0+). + * + * @author John Casey + * @author Brett Porter + * @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="default" + */ +public class DefaultArtifactDiscoverer + extends AbstractArtifactDiscoverer +{ + /** + * @see org.apache.maven.repository.discovery.ArtifactDiscoverer#buildArtifact(String) + */ + public Artifact buildArtifact( String path ) + throws DiscovererException + { + List pathParts = new ArrayList(); + StringTokenizer st = new StringTokenizer( path, "/\\" ); + while ( st.hasMoreTokens() ) + { + pathParts.add( st.nextToken() ); + } + + Collections.reverse( pathParts ); + + Artifact artifact; + if ( pathParts.size() >= 4 ) + { + // maven 2.x path + + // the actual artifact filename. + String filename = (String) pathParts.remove( 0 ); + + // the next one is the version. + String version = (String) pathParts.remove( 0 ); + + // the next one is the artifactId. + String artifactId = (String) pathParts.remove( 0 ); + + // the remaining are the groupId. + Collections.reverse( pathParts ); + String groupId = StringUtils.join( pathParts.iterator(), "." ); + + String remainingFilename = filename; + if ( remainingFilename.startsWith( artifactId + "-" ) ) + { + remainingFilename = remainingFilename.substring( artifactId.length() + 1 ); + + String classifier = null; + + // TODO: use artifact handler, share with legacy discoverer + String type; + if ( remainingFilename.endsWith( ".tar.gz" ) ) + { + type = "distribution-tgz"; + remainingFilename = + remainingFilename.substring( 0, remainingFilename.length() - ".tar.gz".length() ); + } + else if ( remainingFilename.endsWith( ".zip" ) ) + { + type = "distribution-zip"; + remainingFilename = remainingFilename.substring( 0, remainingFilename.length() - ".zip".length() ); + } + else if ( remainingFilename.endsWith( "-sources.jar" ) ) + { + type = "java-source"; + classifier = "sources"; + remainingFilename = + remainingFilename.substring( 0, remainingFilename.length() - "-sources.jar".length() ); + } + else + { + int index = remainingFilename.lastIndexOf( "." ); + if ( index >= 0 ) + { + type = remainingFilename.substring( index + 1 ); + remainingFilename = remainingFilename.substring( 0, index ); + } + else + { + throw new DiscovererException( "Path filename does not have an extension" ); + } + } + + Artifact result; + if ( classifier == null ) + { + result = + artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, type ); + } + else + { + result = + artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier ); + } + + if ( result.isSnapshot() ) + { + // version is *-SNAPSHOT, filename is *-yyyyMMdd.hhmmss-b + int classifierIndex = remainingFilename.indexOf( '-', version.length() + 8 ); + if ( classifierIndex >= 0 ) + { + classifier = remainingFilename.substring( classifierIndex + 1 ); + remainingFilename = remainingFilename.substring( 0, classifierIndex ); + result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, remainingFilename, + type, classifier ); + } + else + { + result = artifactFactory.createArtifact( groupId, artifactId, remainingFilename, + Artifact.SCOPE_RUNTIME, type ); + } + + // poor encapsulation requires we do this to populate base version + if ( !result.isSnapshot() ) + { + throw new DiscovererException( "Failed to create a snapshot artifact: " + result ); + } + else if ( !result.getBaseVersion().equals( version ) ) + { + throw new DiscovererException( + "Built snapshot artifact base version does not match path version: " + result + + "; should have been version: " + version ); + } + else + { + artifact = result; + } + } + else if ( !remainingFilename.startsWith( version ) ) + { + throw new DiscovererException( "Built artifact version does not match path version" ); + } + else if ( !remainingFilename.equals( version ) ) + { + if ( remainingFilename.charAt( version.length() ) == '-' ) + { + classifier = remainingFilename.substring( version.length() + 1 ); + artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, + classifier ); + } + else + { + throw new DiscovererException( "Path version does not corresspond to an artifact version" ); + } + } + else + { + artifact = result; + } + } + else + { + throw new DiscovererException( "Path filename does not correspond to an artifact" ); + } + } + else + { + throw new DiscovererException( "Path is too short to build an artifact from" ); + } + + return artifact; + } +} diff --git a/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java new file mode 100644 index 000000000..6aad837df --- /dev/null +++ b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java @@ -0,0 +1,254 @@ +package org.apache.maven.repository.discovery; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Metadata; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.MalformedURLException; +import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.StringTokenizer; + +/** + * This class gets all the paths that contain the metadata files. + * + * @plexus.component role="org.apache.maven.repository.discovery.MetadataDiscoverer" role-hint="default" + */ +public class DefaultMetadataDiscoverer + extends AbstractDiscoverer + implements MetadataDiscoverer +{ + /** + * Standard patterns to include in discovery of metadata files. + * + * @todo Note that only the remote format is supported at this time: you cannot search local repository metadata due + * to the way it is later loaded in the searchers. Review code using pathOfRemoteMetadata. IS there any value in + * searching the local metadata in the first place though? + */ + private static final String[] STANDARD_DISCOVERY_INCLUDES = {"**/maven-metadata.xml"}; + + public List discoverMetadata( ArtifactRepository repository, String operation, String blacklistedPatterns ) + throws DiscovererException + { + if ( !"file".equals( repository.getProtocol() ) ) + { + throw new UnsupportedOperationException( "Only filesystem repositories are supported" ); + } + + Xpp3Dom dom = getLastMetadataDiscoveryDom( readRepositoryMetadataDom( repository ) ); + long comparisonTimestamp = readComparisonTimestamp( repository, operation, dom ); + + // Note that last checked time is deliberately set to the start of the process so that anything added + // mid-discovery and missed by the scanner will get checked next time. + // Due to this, there must be no negative side-effects of discovering something twice. + Date newLastCheckedTime = new Date(); + + List metadataFiles = new ArrayList(); + List metadataPaths = scanForArtifactPaths( new File( repository.getBasedir() ), blacklistedPatterns, + STANDARD_DISCOVERY_INCLUDES, null, comparisonTimestamp ); + + // Also note that the last check time, while set at the start, is saved at the end, so that if any exceptions + // occur, then the timestamp is not updated so that the discovery is attempted again + // TODO: under the list-return behaviour we have now, exceptions might occur later and the timestamp will not be reset - see MRM-83 + try + { + setLastCheckedTime( repository, operation, newLastCheckedTime ); + } + catch ( IOException e ) + { + throw new DiscovererException( "Error writing metadata: " + e.getMessage(), e ); + } + + for ( Iterator i = metadataPaths.iterator(); i.hasNext(); ) + { + String metadataPath = (String) i.next(); + try + { + RepositoryMetadata metadata = buildMetadata( repository.getBasedir(), metadataPath ); + metadataFiles.add( metadata ); + } + catch ( DiscovererException e ) + { + addKickedOutPath( metadataPath, e.getMessage() ); + } + } + + return metadataFiles; + } + + private RepositoryMetadata buildMetadata( String repo, String metadataPath ) + throws DiscovererException + { + Metadata m; + String repoPath = repo + "/" + metadataPath; + try + { + URL url = new File( repoPath ).toURI().toURL(); + InputStream is = url.openStream(); + Reader reader = new InputStreamReader( is ); + MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); + + m = metadataReader.read( reader ); + } + catch ( XmlPullParserException e ) + { + throw new DiscovererException( "Error parsing metadata file '" + repoPath + "': " + e.getMessage(), e ); + } + catch ( MalformedURLException e ) + { + // shouldn't happen + throw new DiscovererException( "Error constructing metadata file '" + repoPath + "': " + e.getMessage(), + e ); + } + catch ( IOException e ) + { + throw new DiscovererException( "Error reading metadata file '" + repoPath + "': " + e.getMessage(), e ); + } + + RepositoryMetadata repositoryMetadata = buildMetadata( m, metadataPath ); + + if ( repositoryMetadata == null ) + { + throw new DiscovererException( "Unable to build a repository metadata from path" ); + } + + return repositoryMetadata; + } + + /** + * Builds a RepositoryMetadata object from a Metadata object and its path. + * + * @param m Metadata + * @param metadataPath path + * @return RepositoryMetadata if the parameters represent one; null if not + * @todo should we just be using the path information, and loading it later when it is needed? (for reporting, etc) + */ + private RepositoryMetadata buildMetadata( Metadata m, String metadataPath ) + { + String metaGroupId = m.getGroupId(); + String metaArtifactId = m.getArtifactId(); + String metaVersion = m.getVersion(); + + // check if the groupId, artifactId and version is in the + // metadataPath + // parse the path, in reverse order + List pathParts = new ArrayList(); + StringTokenizer st = new StringTokenizer( metadataPath, "/\\" ); + while ( st.hasMoreTokens() ) + { + pathParts.add( st.nextToken() ); + } + + Collections.reverse( pathParts ); + // remove the metadata file + pathParts.remove( 0 ); + Iterator it = pathParts.iterator(); + String tmpDir = (String) it.next(); + + Artifact artifact = null; + if ( !StringUtils.isEmpty( metaVersion ) ) + { + artifact = artifactFactory.createProjectArtifact( metaGroupId, metaArtifactId, metaVersion ); + } + + // snapshotMetadata + RepositoryMetadata metadata = null; + if ( tmpDir != null && tmpDir.equals( metaVersion ) ) + { + if ( artifact != null ) + { + metadata = new SnapshotArtifactRepositoryMetadata( artifact ); + } + } + else if ( tmpDir != null && tmpDir.equals( metaArtifactId ) ) + { + // artifactMetadata + if ( artifact != null ) + { + metadata = new ArtifactRepositoryMetadata( artifact ); + } + else + { + artifact = artifactFactory.createProjectArtifact( metaGroupId, metaArtifactId, "1.0" ); + metadata = new ArtifactRepositoryMetadata( artifact ); + } + } + else + { + String groupDir = ""; + int ctr = 0; + for ( it = pathParts.iterator(); it.hasNext(); ) + { + String path = (String) it.next(); + if ( ctr == 0 ) + { + groupDir = path; + } + else + { + groupDir = path + "." + groupDir; + } + ctr++; + } + + // groupMetadata + if ( metaGroupId != null && metaGroupId.equals( groupDir ) ) + { + metadata = new GroupRepositoryMetadata( metaGroupId ); + } + } + + return metadata; + } + + public void setLastCheckedTime( ArtifactRepository repository, String operation, Date date ) + throws IOException + { + // see notes in resetLastCheckedTime + + File file = new File( repository.getBasedir(), "maven-metadata.xml" ); + + Xpp3Dom dom = readDom( file ); + + String dateString = new SimpleDateFormat( DATE_FMT, Locale.US ).format( date ); + + setEntry( getLastMetadataDiscoveryDom( dom ), operation, dateString ); + + saveDom( file, dom ); + } +} diff --git a/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/Discoverer.java b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/Discoverer.java new file mode 100644 index 000000000..b0896bcad --- /dev/null +++ b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/Discoverer.java @@ -0,0 +1,64 @@ +package org.apache.maven.repository.discovery; + +import org.apache.maven.artifact.repository.ArtifactRepository; + +import java.io.IOException; +import java.util.Date; +import java.util.Iterator; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * @author Edwin Punzalan + */ +public interface Discoverer +{ + /** + * Get the list of paths kicked out during the discovery process. + * + * @return the paths as Strings. + */ + Iterator getKickedOutPathsIterator(); + + /** + * Get the list of paths excluded during the discovery process. + * + * @return the paths as Strings. + */ + Iterator getExcludedPathsIterator(); + + /** + * Reset the time in the repository that indicates the last time a check was performed. + * + * @param repository the location of the repository + * @param operation the operation to record the timestamp for + * @throws java.io.IOException if there is a non-recoverable problem reading or writing the metadata + */ + void resetLastCheckedTime( ArtifactRepository repository, String operation ) + throws IOException; + + /** + * Set the time in the repository that indicates the last time a check was performed. + * + * @param repository the location of the repository + * @param operation the operation to record the timestamp for + * @param date the date to set the last check to + * @throws java.io.IOException if there is a non-recoverable problem reading or writing the metadata + */ + void setLastCheckedTime( ArtifactRepository repository, String operation, Date date ) + throws IOException; +} diff --git a/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/DiscovererException.java b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/DiscovererException.java new file mode 100644 index 000000000..02e45e699 --- /dev/null +++ b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/DiscovererException.java @@ -0,0 +1,34 @@ +package org.apache.maven.repository.discovery; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * @author Edwin Punzalan + */ +public class DiscovererException + extends Exception +{ + public DiscovererException( String message ) + { + super( message ); + } + + public DiscovererException( String message, Throwable cause ) + { + super( message, cause ); + } +} diff --git a/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/DiscovererPath.java b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/DiscovererPath.java new file mode 100644 index 000000000..ae2ecee73 --- /dev/null +++ b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/DiscovererPath.java @@ -0,0 +1,49 @@ +package org.apache.maven.repository.discovery; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * @author Edwin Punzalan + */ +public class DiscovererPath +{ + /** + * The path discovered. + */ + private final String path; + + /** + * A comment about why the path is being processed. + */ + private final String comment; + + public DiscovererPath( String path, String comment ) + { + this.path = path; + this.comment = comment; + } + + public String getPath() + { + return path; + } + + public String getComment() + { + return comment; + } +} diff --git a/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java new file mode 100644 index 000000000..9a8f7fc22 --- /dev/null +++ b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java @@ -0,0 +1,282 @@ +package org.apache.maven.repository.discovery; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; + +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.StringTokenizer; + +/** + * Artifact discoverer for the legacy repository layout (Maven 1.x). + * Method used to build an artifact object using a relative path from a repository base directory. An artifactId + * having the words "DEV", "PRE", "RC", "ALPHA", "BETA", "DEBUG", "UNOFFICIAL", "CURRENT", "LATEST", "FCS", + * "RELEASE", "NIGHTLY", "SNAPSHOT" and "TEST" (not case-sensitive) will most likely make this method fail as + * they are reserved for version usage. + * + * @author John Casey + * @author Brett Porter + * @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="legacy" + */ +public class LegacyArtifactDiscoverer + extends AbstractArtifactDiscoverer +{ + /** + * @see org.apache.maven.repository.discovery.ArtifactDiscoverer#buildArtifact(String) + */ + public Artifact buildArtifact( String path ) + throws DiscovererException + { + StringTokenizer tokens = new StringTokenizer( path, "/\\" ); + + Artifact result; + + int numberOfTokens = tokens.countTokens(); + + if ( numberOfTokens == 3 ) + { + String groupId = tokens.nextToken(); + + String type = tokens.nextToken(); + + if ( type.endsWith( "s" ) ) + { + type = type.substring( 0, type.length() - 1 ); + + // contains artifactId, version, classifier, and extension. + String avceGlob = tokens.nextToken(); + + //noinspection CollectionDeclaredAsConcreteClass + LinkedList avceTokenList = new LinkedList(); + + StringTokenizer avceTokenizer = new StringTokenizer( avceGlob, "-" ); + while ( avceTokenizer.hasMoreTokens() ) + { + avceTokenList.addLast( avceTokenizer.nextToken() ); + } + + String lastAvceToken = (String) avceTokenList.removeLast(); + + // TODO: share with other discoverer, use artifact handlers instead + if ( lastAvceToken.endsWith( ".tar.gz" ) ) + { + type = "distribution-tgz"; + + lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".tar.gz".length() ); + + avceTokenList.addLast( lastAvceToken ); + } + else if ( lastAvceToken.endsWith( "sources.jar" ) ) + { + type = "java-source"; + + lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".jar".length() ); + + avceTokenList.addLast( lastAvceToken ); + } + else if ( lastAvceToken.endsWith( ".zip" ) ) + { + type = "distribution-zip"; + + lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".zip".length() ); + + avceTokenList.addLast( lastAvceToken ); + } + else + { + int extPos = lastAvceToken.lastIndexOf( '.' ); + + if ( extPos > 0 ) + { + String ext = lastAvceToken.substring( extPos + 1 ); + if ( type.equals( ext ) ) + { + lastAvceToken = lastAvceToken.substring( 0, extPos ); + + avceTokenList.addLast( lastAvceToken ); + } + else + { + throw new DiscovererException( "Path type does not match the extension" ); + } + } + else + { + throw new DiscovererException( "Path filename does not have an extension" ); + } + } + + // let's discover the version, and whatever's leftover will be either + // a classifier, or part of the artifactId, depending on position. + // Since version is at the end, we have to move in from the back. + Collections.reverse( avceTokenList ); + + // TODO: this is obscene - surely a better way? + String validVersionParts = "([Dd][Ee][Vv][_.0-9]*)|" + "([Ss][Nn][Aa][Pp][Ss][Hh][Oo][Tt])|" + + "([0-9][_.0-9a-zA-Z]*)|" + "([Gg]?[_.0-9ab]*([Pp][Rr][Ee]|[Rr][Cc]|[Gg]|[Mm])[_.0-9]*)|" + + "([Aa][Ll][Pp][Hh][Aa][_.0-9]*)|" + "([Bb][Ee][Tt][Aa][_.0-9]*)|" + "([Rr][Cc][_.0-9]*)|" + + "([Tt][Ee][Ss][Tt][_.0-9]*)|" + "([Dd][Ee][Bb][Uu][Gg][_.0-9]*)|" + + "([Uu][Nn][Oo][Ff][Ff][Ii][Cc][Ii][Aa][Ll][_.0-9]*)|" + "([Cc][Uu][Rr][Rr][Ee][Nn][Tt])|" + + "([Ll][Aa][Tt][Ee][Ss][Tt])|" + "([Ff][Cc][Ss])|" + "([Rr][Ee][Ll][Ee][Aa][Ss][Ee][_.0-9]*)|" + + "([Nn][Ii][Gg][Hh][Tt][Ll][Yy])|" + "[Ff][Ii][Nn][Aa][Ll]|" + "([AaBb][_.0-9]*)"; + + StringBuffer classifierBuffer = new StringBuffer(); + StringBuffer versionBuffer = new StringBuffer(); + + boolean firstVersionTokenEncountered = false; + boolean firstToken = true; + + int tokensIterated = 0; + for ( Iterator it = avceTokenList.iterator(); it.hasNext(); ) + { + String token = (String) it.next(); + + boolean tokenIsVersionPart = token.matches( validVersionParts ); + + StringBuffer bufferToUpdate; + + // NOTE: logic in code is reversed, since we're peeling off the back + // Any token after the last versionPart will be in the classifier. + // Any token UP TO first non-versionPart is part of the version. + if ( !tokenIsVersionPart ) + { + if ( firstVersionTokenEncountered ) + { + //noinspection BreakStatement + break; + } + else + { + bufferToUpdate = classifierBuffer; + } + } + else + { + firstVersionTokenEncountered = true; + + bufferToUpdate = versionBuffer; + } + + if ( firstToken ) + { + firstToken = false; + } + else + { + bufferToUpdate.insert( 0, '-' ); + } + + bufferToUpdate.insert( 0, token ); + + tokensIterated++; + } + + // Now, restore the proper ordering so we can build the artifactId. + Collections.reverse( avceTokenList ); + + // if we didn't find a version, then punt. Use the last token + // as the version, and set the classifier empty. + if ( versionBuffer.length() < 1 ) + { + if ( avceTokenList.size() > 1 ) + { + int lastIdx = avceTokenList.size() - 1; + + versionBuffer.append( avceTokenList.get( lastIdx ) ); + avceTokenList.remove( lastIdx ); + } + + classifierBuffer.setLength( 0 ); + } + else + { + // if everything is kosher, then pop off all the classifier and + // version tokens, leaving the naked artifact id in the list. + avceTokenList = + new LinkedList( avceTokenList.subList( 0, avceTokenList.size() - tokensIterated ) ); + } + + StringBuffer artifactIdBuffer = new StringBuffer(); + + firstToken = true; + for ( Iterator it = avceTokenList.iterator(); it.hasNext(); ) + { + String token = (String) it.next(); + + if ( firstToken ) + { + firstToken = false; + } + else + { + artifactIdBuffer.append( '-' ); + } + + artifactIdBuffer.append( token ); + } + + String artifactId = artifactIdBuffer.toString(); + + if ( artifactId.length() > 0 ) + { + int lastVersionCharIdx = versionBuffer.length() - 1; + if ( lastVersionCharIdx > -1 && versionBuffer.charAt( lastVersionCharIdx ) == '-' ) + { + versionBuffer.setLength( lastVersionCharIdx ); + } + + String version = versionBuffer.toString(); + + if ( version.length() > 0 ) + { + if ( classifierBuffer.length() > 0 ) + { + result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, + type, + classifierBuffer.toString() ); + } + else + { + result = artifactFactory.createArtifact( groupId, artifactId, version, + Artifact.SCOPE_RUNTIME, type ); + } + } + else + { + throw new DiscovererException( "Path filename version is empty" ); + } + } + else + { + throw new DiscovererException( "Path filename artifactId is empty" ); + } + } + else + { + throw new DiscovererException( "Path artifact type does not corresspond to an artifact type" ); + } + } + else + { + throw new DiscovererException( "Path does not match a legacy repository path for an artifact" ); + } + + return result; + } +} diff --git a/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java new file mode 100644 index 000000000..3877c7723 --- /dev/null +++ b/archiva-discoverer/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java @@ -0,0 +1,41 @@ +package org.apache.maven.repository.discovery; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.repository.ArtifactRepository; + +import java.util.List; + +/** + * Interface for discovering metadata files. + */ +public interface MetadataDiscoverer + extends Discoverer +{ + String ROLE = MetadataDiscoverer.class.getName(); + + /** + * Search for metadata files in the repository. + * + * @param repository The repository. + * @param operation the operation being performed (used for timestamp comparison) + * @param blacklistedPatterns Patterns that are to be excluded from the discovery process. + * @return the list of artifacts found + */ + List discoverMetadata( ArtifactRepository repository, String operation, String blacklistedPatterns ) + throws DiscovererException; +} diff --git a/archiva-discoverer/src/site/apt/design.apt b/archiva-discoverer/src/site/apt/design.apt new file mode 100644 index 000000000..6a482e0ab --- /dev/null +++ b/archiva-discoverer/src/site/apt/design.apt @@ -0,0 +1,37 @@ + ----- + Discoverer Design + ----- + Brett Porter + ----- + 24 July 2006 + ----- + +Discoverer Design + + The artifact discoverer is designed to traverse the paths in the repository and identify files that are part of + a legitimate artifact. + + There are two plexus components available: + + * {{{../apidocs/org/apache/maven/repository/discovery/ArtifactDiscoverer.html} ArtifactDiscoverer}} + + * {{{../apidocs/org/apache/maven/repository/discovery/MetadataDiscoverer.html} MetadataDiscoverer}} + + Each of these components currently have an implementation for the both <<>> and <<>> repository + layouts. + + The artifact discoverer will find all artifacts in the repository, while metadata discovery finds any + <<>> files (both remote and local repository formats). + + * Limitations + + * In the artifact discoverer, POMs will be identified as separate artifacts to their related artifacts, as will each + individual derivative artifact at present. Later, these will be linked - see + {{{http://jira.codehaus.org/browse/MRM-40} MRM-40}}. + + * Currently, deleted artifacts are not tracked. This requires a separate event - see + {{{http://jira.codehaus.org/browse/MRM-37} MRM-37}}. + + * Currently, all artifacts are discovered instead of just those changed since the last discovery for a particular + operation - see {{{http://jira.codehaus.org/browse/MRM-125} MRM-125}}. + diff --git a/archiva-discoverer/src/site/site.xml b/archiva-discoverer/src/site/site.xml new file mode 100644 index 000000000..245a0bf34 --- /dev/null +++ b/archiva-discoverer/src/site/site.xml @@ -0,0 +1,24 @@ + + + + + + + + + + diff --git a/archiva-discoverer/src/test/java/org/apache/maven/repository/discovery/AbstractArtifactDiscovererTest.java b/archiva-discoverer/src/test/java/org/apache/maven/repository/discovery/AbstractArtifactDiscovererTest.java new file mode 100644 index 000000000..c016fe0bc --- /dev/null +++ b/archiva-discoverer/src/test/java/org/apache/maven/repository/discovery/AbstractArtifactDiscovererTest.java @@ -0,0 +1,254 @@ +package org.apache.maven.repository.discovery; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +import java.io.File; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +/** + * @author Edwin Punzalan + */ +public abstract class AbstractArtifactDiscovererTest + extends PlexusTestCase +{ + protected ArtifactDiscoverer discoverer; + + private ArtifactFactory factory; + + protected ArtifactRepository repository; + + protected static final String TEST_OPERATION = "test"; + + protected abstract String getLayout(); + + protected abstract File getRepositoryFile(); + + protected void setUp() + throws Exception + { + super.setUp(); + + discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, getLayout() ); + + factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + + repository = getRepository(); + + removeTimestampMetadata(); + } + + protected ArtifactRepository getRepository() + throws Exception + { + File basedir = getRepositoryFile(); + + ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + + ArtifactRepositoryLayout layout = + (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, getLayout() ); + + return factory.createArtifactRepository( "discoveryRepo", "file://" + basedir, layout, null, null ); + } + + protected Artifact createArtifact( String groupId, String artifactId, String version ) + { + Artifact artifact = factory.createArtifact( groupId, artifactId, version, null, "jar" ); + artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); + artifact.setRepository( repository ); + return artifact; + } + + protected Artifact createArtifact( String groupId, String artifactId, String version, String type ) + { + return factory.createArtifact( groupId, artifactId, version, null, type ); + } + + protected Artifact createArtifact( String groupId, String artifactId, String version, String type, + String classifier ) + { + return factory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier ); + } + + public void testUpdatedInRepository() + throws ComponentLookupException, DiscovererException, ParseException, IOException + { + // Set repository time to 1-1-2000, a time in the distant past so definitely updated + discoverer.setLastCheckedTime( repository, "update", + new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).parse( "2000-01-01" ) ); + + List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check included", + artifacts.contains( createArtifact( "org.apache.maven.update", "test-updated", "1.0" ) ) ); + + // try again with the updated timestamp + artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertFalse( "Check not included", + artifacts.contains( createArtifact( "org.apache.maven.update", "test-updated", "1.0" ) ) ); + } + + public void testNotUpdatedInRepository() + throws ComponentLookupException, DiscovererException, IOException + { + // Set repository time to now, which is after any artifacts, so definitely not updated + discoverer.setLastCheckedTime( repository, "update", new Date() ); + + List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertFalse( "Check not included", + artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) ); + } + + public void testNotUpdatedInRepositoryForcedDiscovery() + throws ComponentLookupException, DiscovererException, IOException + { + discoverer.resetLastCheckedTime( repository, "update" ); + + List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check included", + artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) ); + + // try again with the updated timestamp + artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertFalse( "Check not included", + artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) ); + } + + public void testUpdatedInRepositoryBlackout() + throws ComponentLookupException, DiscovererException, IOException + { + discoverer.resetLastCheckedTime( repository, "update" ); + + Artifact artifact = createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ); + artifact.getFile().setLastModified( System.currentTimeMillis() ); + + List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertFalse( "Check not included", artifacts.contains( artifact ) ); + + // try again with the updated timestamp + artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertFalse( "Check not included", artifacts.contains( artifact ) ); + } + + public void testUpdatedInRepositoryNotBlackout() + throws ComponentLookupException, DiscovererException, IOException + { + discoverer.resetLastCheckedTime( repository, "update" ); + + Artifact artifact = createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ); + artifact.getFile().setLastModified( System.currentTimeMillis() - 61000 ); + + List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check included", artifacts.contains( artifact ) ); + + // try again with the updated timestamp + artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertFalse( "Check not included", artifacts.contains( artifact ) ); + } + + public void testNotUpdatedInRepositoryForcedDiscoveryMetadataAlreadyExists() + throws ComponentLookupException, DiscovererException, IOException + { + discoverer.setLastCheckedTime( repository, "update", new Date() ); + + discoverer.resetLastCheckedTime( repository, "update" ); + + List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check included", + artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) ); + + // try again with the updated timestamp + artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertFalse( "Check not included", + artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) ); + } + + public void testNotUpdatedInRepositoryForcedDiscoveryOtherMetadataAlreadyExists() + throws ComponentLookupException, DiscovererException, IOException + { + discoverer.setLastCheckedTime( repository, "test", new Date() ); + + discoverer.resetLastCheckedTime( repository, "update" ); + + List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check included", + artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) ); + + // try again with the updated timestamp + artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertFalse( "Check not included", + artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) ); + } + + public void testNoRepositoryMetadata() + throws ComponentLookupException, DiscovererException, ParseException, IOException + { + removeTimestampMetadata(); + + // should find all + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check included", + artifacts.contains( createArtifact( "org.apache.maven.update", "test-updated", "1.0" ) ) ); + } + + private void removeTimestampMetadata() + { + // remove the metadata that tracks time + File file = new File( repository.getBasedir(), "maven-metadata.xml" ); + file.delete(); + assertFalse( file.exists() ); + } +} diff --git a/archiva-discoverer/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java b/archiva-discoverer/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java new file mode 100644 index 000000000..7832c4d68 --- /dev/null +++ b/archiva-discoverer/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java @@ -0,0 +1,668 @@ +package org.apache.maven.repository.discovery; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +import java.io.File; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * Test the default artifact discoverer. + * + * @author Brett Porter + * @version $Id$ + * @todo test location of poms, checksums + */ +public class DefaultArtifactDiscovererTest + extends AbstractArtifactDiscovererTest +{ + + protected String getLayout() + { + return "default"; + } + + protected File getRepositoryFile() + { + return getTestFile( "src/test/repository" ); + } + + public void testDefaultExcludes() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + boolean b = path.indexOf( ".svn" ) >= 0; + if ( b ) + { + found = true; + assertEquals( "Check comment", "Artifact was in the specified list of exclusions", dPath.getComment() ); + } + } + assertTrue( "Check exclusion was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not .svn", a.getFile().getPath().indexOf( ".svn" ) >= 0 ); + } + } + + public void testStandardExcludes() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "KEYS".equals( path ) ) + { + found = true; + assertEquals( "Check comment", "Artifact was in the specified list of exclusions", dPath.getComment() ); + } + } + assertTrue( "Check exclusion was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not KEYS", "KEYS".equals( a.getFile().getName() ) ); + } + } + + public void testBlacklistedExclude() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, "javax/**", false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "javax/sql/jdbc/2.0/jdbc-2.0.jar".equals( path.replace( '\\', '/' ) ) ) + { + found = true; + assertEquals( "Check comment is about blacklisting", "Artifact was in the specified list of exclusions", + dPath.getComment() ); + } + } + assertTrue( "Check exclusion was found", found ); + + assertFalse( "Check jdbc not included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) ); + } + + public void testKickoutWithShortPath() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "invalid/invalid-1.0.jar".equals( path.replace( '\\', '/' ) ) ) + { + found = true; + assertEquals( "Check reason for kickout", "Path is too short to build an artifact from", + dPath.getComment() ); + + } + } + assertTrue( "Check kickout was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not invalid-1.0.jar", "invalid-1.0.jar".equals( a.getFile().getName() ) ); + } + } + + public void testKickoutWithWrongArtifactId() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar".equals( + path.replace( '\\', '/' ) ) ) + { + found = true; + assertEquals( "Check reason for kickout", "Path filename does not correspond to an artifact", + dPath.getComment() ); + } + } + assertTrue( "Check kickout was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not wrong jar", + "wrong-artifactId-1.0-20050611.112233-1.jar".equals( a.getFile().getName() ) ); + } + } + + public void testKickoutWithNoType() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "invalid/invalid/1/invalid-1".equals( path.replace( '\\', '/' ) ) ) + { + found = true; + assertEquals( "Check reason for kickout", "Path filename does not have an extension", + dPath.getComment() ); + } + } + assertTrue( "Check kickout was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not 'invalid-1'", "invalid-1".equals( a.getFile().getName() ) ); + } + } + + public void testKickoutWithWrongVersion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "invalid/invalid/1.0/invalid-2.0.jar".equals( path.replace( '\\', '/' ) ) ) + { + found = true; + assertEquals( "Check reason for kickout", "Built artifact version does not match path version", + dPath.getComment() ); + } + } + assertTrue( "Check kickout was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not 'invalid-2.0.jar'", "invalid-2.0.jar".equals( a.getFile().getName() ) ); + } + } + + public void testKickoutWithLongerVersion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "invalid/invalid/1.0/invalid-1.0b.jar".equals( path.replace( '\\', '/' ) ) ) + { + found = true; + assertEquals( "Check reason for kickout", "Path version does not corresspond to an artifact version", + dPath.getComment() ); + } + } + assertTrue( "Check kickout was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not 'invalid-1.0b.jar'", "invalid-1.0b.jar".equals( a.getFile().getName() ) ); + } + } + + public void testKickoutWithWrongSnapshotVersion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar".equals( path.replace( '\\', '/' ) ) ) + { + found = true; + assertEquals( "Check reason for kickout", + "Failed to create a snapshot artifact: invalid:invalid:jar:1.0:runtime", + dPath.getComment() ); + } + } + assertTrue( "Check kickout was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not 'invalid-1.0.jar'", "invalid-1.0.jar".equals( a.getFile().getName() ) ); + } + } + + public void testKickoutWithSnapshotBaseVersion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar".equals( + path.replace( '\\', '/' ) ) ) + { + found = true; + assertEquals( "Check reason for kickout", + "Built snapshot artifact base version does not match path version: invalid:invalid:jar:1.0-SNAPSHOT:runtime; should have been version: 1.0-20050611.123456-1", + dPath.getComment() ); + } + } + assertTrue( "Check kickout was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not 'invalid-1.0-20050611-123456-1.jar'", + "invalid-1.0-20050611.123456-1.jar".equals( a.getFile().getName() ) ); + } + } + + public void testInclusion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check normal included", + artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0" ) ) ); + } + + public void testArtifactWithClassifier() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check normal included", + artifacts.contains( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ) ) ); + } + + public void testJavaSourcesInclusion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check normal included", artifacts.contains( + createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ) ) ); + } + + public void testDistributionInclusion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check zip included", + artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ) ) ); + + assertTrue( "Check tar.gz included", + artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ) ) ); + } + + public void testSnapshotInclusion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) ); + assertTrue( "Check snapshot included", + artifacts.contains( createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1" ) ) ); + } + + public void testSnapshotInclusionWithClassifier() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check snapshot included", artifacts.contains( + createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1", "jar", "javadoc" ) ) ); + } + + public void testSnapshotExclusion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) ); + assertFalse( "Check snapshot included", + artifacts.contains( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ) ) ); + } + + public void testFileSet() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + assertNotNull( "Check file is set", artifact.getFile() ); + } + } + + public void testRepositorySet() + throws MalformedURLException, DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + String url = repository.getUrl(); + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + assertNotNull( "Check repository set", artifact.getRepository() ); + assertEquals( "Check repository url is correct", url, artifact.getRepository().getUrl() ); + } + } + + public void testStandalonePoms() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + + // cull down to actual artifacts (only standalone poms will have type = pom) + Map keyedArtifacts = new HashMap(); + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + String key = a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion(); + if ( !"pom".equals( a.getType() ) || !keyedArtifacts.containsKey( key ) ) + { + keyedArtifacts.put( key, a ); + } + } + + List models = new ArrayList(); + + for ( Iterator i = keyedArtifacts.values().iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + + if ( "pom".equals( a.getType() ) ) + { + models.add( a ); + } + } + + assertEquals( 4, models.size() ); + + // Define order we expect + Collections.sort( models ); + + Iterator itr = models.iterator(); + Artifact model = (Artifact) itr.next(); + assertEquals( "org.apache.maven", model.getGroupId() ); + assertEquals( "B", model.getArtifactId() ); + assertEquals( "1.0", model.getVersion() ); + model = (Artifact) itr.next(); + assertEquals( "org.apache.maven", model.getGroupId() ); + assertEquals( "B", model.getArtifactId() ); + assertEquals( "2.0", model.getVersion() ); + model = (Artifact) itr.next(); + assertEquals( "org.apache.maven", model.getGroupId() ); + assertEquals( "discovery", model.getArtifactId() ); + assertEquals( "1.0", model.getVersion() ); + model = (Artifact) itr.next(); + assertEquals( "org.apache.testgroup", model.getGroupId() ); + assertEquals( "discovery", model.getArtifactId() ); + assertEquals( "1.0", model.getVersion() ); + } + + public void testShortPath() + throws ComponentLookupException + { + try + { + discoverer.buildArtifact( "invalid/invalid-1.0.jar" ); + + fail( "Artifact should be null for short paths" ); + } + catch ( DiscovererException e ) + { + // excellent + } + } + + public void testWrongArtifactId() + throws ComponentLookupException + { + + try + { + discoverer.buildArtifact( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar" ); + + fail( "Artifact should be null for wrong ArtifactId" ); + } + catch ( DiscovererException e ) + { + // excellent + } + } + + public void testNoType() + throws ComponentLookupException + { + try + { + discoverer.buildArtifact( "invalid/invalid/1/invalid-1" ); + + fail( "Artifact should be null for no type" ); + } + catch ( DiscovererException e ) + { + // excellent + } + } + + public void testWrongVersion() + throws ComponentLookupException + { + try + { + discoverer.buildArtifact( "invalid/invalid/1.0/invalid-2.0.jar" ); + + fail( "Artifact should be null for wrong version" ); + } + catch ( DiscovererException e ) + { + // excellent + } + } + + public void testLongVersion() + throws ComponentLookupException + { + try + { + discoverer.buildArtifact( "invalid/invalid/1.0/invalid-1.0b.jar" ); + + fail( "Artifact should be null for long version" ); + } + catch ( DiscovererException e ) + { + // excellent + } + } + + public void testWrongSnapshotVersion() + throws ComponentLookupException + { + try + { + discoverer.buildArtifact( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar" ); + + fail( "Artifact should be null for wrong snapshot version" ); + } + catch ( DiscovererException e ) + { + // excellent + } + } + + public void testSnapshotBaseVersion() + throws ComponentLookupException + { + try + { + discoverer.buildArtifact( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" ); + + fail( "Artifact should be null for snapshot base version" ); + } + catch ( DiscovererException e ) + { + // excellent + } + } + + public void testPathWithClassifier() + throws ComponentLookupException, DiscovererException + { + String testPath = "org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar"; + + Artifact artifact = discoverer.buildArtifact( testPath ); + + assertEquals( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ), artifact ); + } + + public void testWithJavaSourceInclusion() + throws ComponentLookupException, DiscovererException + { + String testPath = "org/apache/maven/testing/1.0/testing-1.0-sources.jar"; + + Artifact artifact = discoverer.buildArtifact( testPath ); + + assertEquals( createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ), artifact ); + } + + public void testDistributionArtifacts() + throws ComponentLookupException, DiscovererException + { + String testPath = "org/apache/maven/testing/1.0/testing-1.0.tar.gz"; + + Artifact artifact = discoverer.buildArtifact( testPath ); + + assertEquals( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ), artifact ); + + testPath = "org/apache/maven/testing/1.0/testing-1.0.zip"; + + artifact = discoverer.buildArtifact( testPath ); + + assertEquals( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ), artifact ); + } + + public void testSnapshot() + throws ComponentLookupException, DiscovererException + { + String testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar"; + + Artifact artifact = discoverer.buildArtifact( testPath ); + + assertEquals( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ), artifact ); + + testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar"; + + artifact = discoverer.buildArtifact( testPath ); + + assertEquals( createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1" ), artifact ); + } + + public void testNormal() + throws ComponentLookupException, DiscovererException + { + String testPath = "javax/sql/jdbc/2.0/jdbc-2.0.jar"; + + Artifact artifact = discoverer.buildArtifact( testPath ); + + assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact ); + } + + public void testSnapshotWithClassifier() + throws ComponentLookupException, DiscovererException + { + String testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1-javadoc.jar"; + + Artifact artifact = discoverer.buildArtifact( testPath ); + + assertEquals( createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1", "jar", "javadoc" ), + artifact ); + } +} diff --git a/archiva-discoverer/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java b/archiva-discoverer/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java new file mode 100644 index 000000000..52471ab25 --- /dev/null +++ b/archiva-discoverer/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java @@ -0,0 +1,311 @@ +package org.apache.maven.repository.discovery; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +import java.io.File; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; + +/** + * This class tests the DefaultMetadataDiscoverer class. + */ +public class DefaultMetadataDiscovererTest + extends PlexusTestCase +{ + private MetadataDiscoverer discoverer; + + private static final String TEST_OPERATION = "test"; + + private ArtifactRepository repository; + + private ArtifactFactory factory; + + /** + * + */ + public void setUp() + throws Exception + { + super.setUp(); + + discoverer = (MetadataDiscoverer) lookup( MetadataDiscoverer.ROLE, "default" ); + + factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + + repository = getRepository(); + + removeTimestampMetadata(); + } + + protected ArtifactRepository getRepository() + throws Exception + { + File basedir = getTestFile( "src/test/repository" ); + + ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + + return factory.createArtifactRepository( "discoveryRepo", "file://" + basedir, layout, null, null ); + } + + /** + * + */ + public void tearDown() + throws Exception + { + super.tearDown(); + discoverer = null; + } + + /** + * Test if metadata file in wrong directory was added to the kickedOutPaths. + */ + public void testKickoutWrongDirectory() + throws DiscovererException + { + discoverer.discoverMetadata( repository, TEST_OPERATION, null ); + Iterator iter = discoverer.getKickedOutPathsIterator(); + boolean found = false; + while ( iter.hasNext() && !found ) + { + DiscovererPath dPath = (DiscovererPath) iter.next(); + String dir = dPath.getPath(); + + String normalizedDir = dir.replace( '\\', '/' ); + if ( "javax/maven-metadata.xml".equals( normalizedDir ) ) + { + found = true; + assertEquals( "Check reason for kickout", "Unable to build a repository metadata from path", + dPath.getComment() ); + } + } + assertTrue( found ); + } + + /** + * Test if blank metadata file was added to the kickedOutPaths. + */ + public void testKickoutBlankMetadata() + throws DiscovererException + { + discoverer.discoverMetadata( repository, TEST_OPERATION, null ); + Iterator iter = discoverer.getKickedOutPathsIterator(); + boolean found = false; + while ( iter.hasNext() && !found ) + { + DiscovererPath dPath = (DiscovererPath) iter.next(); + String dir = dPath.getPath(); + + String normalizedDir = dir.replace( '\\', '/' ); + if ( "org/apache/maven/some-ejb/1.0/maven-metadata.xml".equals( normalizedDir ) ) + { + found = true; + assertTrue( "Check reason for kickout", dPath.getComment().matches( + "Error reading metadata file '(.*)': input contained no data" ) ); + } + } + assertTrue( found ); + } + + private void removeTimestampMetadata() + throws IOException + { + // remove the metadata that tracks time + File file = new File( repository.getBasedir(), "maven-metadata.xml" ); + System.gc(); // for Windows + file.delete(); + assertFalse( file.exists() ); + } + + public void testDiscoverMetadata() + throws DiscovererException + { + List metadataPaths = discoverer.discoverMetadata( repository, TEST_OPERATION, null ); + assertNotNull( "Check metadata not null", metadataPaths ); + + RepositoryMetadata metadata = + new ArtifactRepositoryMetadata( createArtifact( "org.apache.testgroup", "discovery" ) ); + assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); + + metadata = + new SnapshotArtifactRepositoryMetadata( createArtifact( "org.apache.testgroup", "discovery", "1.0" ) ); + assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); + + metadata = new GroupRepositoryMetadata( "org.apache.maven" ); + assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); + } + + public void testUpdatedInRepository() + throws ComponentLookupException, DiscovererException, ParseException, IOException + { + // Set repository time to 1-1-2000, a time in the distant past so definitely updated + discoverer.setLastCheckedTime( repository, "update", + new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).parse( "2000-01-01" ) ); + + List metadataPaths = discoverer.discoverMetadata( repository, "update", null ); + assertNotNull( "Check metadata not null", metadataPaths ); + + RepositoryMetadata metadata = + new ArtifactRepositoryMetadata( createArtifact( "org.apache.maven.update", "test-updated" ) ); + assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); + + // try again with the updated timestamp + metadataPaths = discoverer.discoverMetadata( repository, "update", null ); + assertNotNull( "Check metadata not null", metadataPaths ); + + assertFalse( "Check not included", containsMetadata( metadataPaths, metadata ) ); + } + + private boolean containsMetadata( List metadataPaths, RepositoryMetadata metadata ) + { + for ( Iterator i = metadataPaths.iterator(); i.hasNext(); ) + { + RepositoryMetadata m = (RepositoryMetadata) i.next(); + + if ( m.getGroupId().equals( metadata.getGroupId() ) ) + { + if ( m.getArtifactId() == null && metadata.getArtifactId() == null ) + { + return true; + } + else if ( m.getArtifactId() != null && m.getArtifactId().equals( metadata.getArtifactId() ) ) + { + return true; + } + } + } + return false; + } + + public void testNotUpdatedInRepository() + throws ComponentLookupException, DiscovererException, IOException + { + // Set repository time to now, which is after any artifacts, so definitely not updated + discoverer.setLastCheckedTime( repository, "update", new Date() ); + + List metadataPaths = discoverer.discoverMetadata( repository, "update", null ); + assertNotNull( "Check metadata not null", metadataPaths ); + + RepositoryMetadata metadata = + new ArtifactRepositoryMetadata( createArtifact( "org.apache.maven.update", "test-not-updated" ) ); + assertFalse( "Check not included", containsMetadata( metadataPaths, metadata ) ); + } + + public void testNotUpdatedInRepositoryForcedDiscovery() + throws ComponentLookupException, DiscovererException, IOException + { + discoverer.resetLastCheckedTime( repository, "update" ); + + List metadataPaths = discoverer.discoverMetadata( repository, "update", null ); + assertNotNull( "Check metadata not null", metadataPaths ); + + RepositoryMetadata metadata = + new ArtifactRepositoryMetadata( createArtifact( "org.apache.maven.update", "test-not-updated" ) ); + assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); + + // try again with the updated timestamp + metadataPaths = discoverer.discoverMetadata( repository, "update", null ); + assertNotNull( "Check metadata not null", metadataPaths ); + + assertFalse( "Check not included", containsMetadata( metadataPaths, metadata ) ); + } + + public void testNotUpdatedInRepositoryForcedDiscoveryMetadataAlreadyExists() + throws ComponentLookupException, DiscovererException, IOException + { + discoverer.setLastCheckedTime( repository, "update", new Date() ); + + discoverer.resetLastCheckedTime( repository, "update" ); + + List metadataPaths = discoverer.discoverMetadata( repository, "update", null ); + assertNotNull( "Check metadata not null", metadataPaths ); + + RepositoryMetadata metadata = + new ArtifactRepositoryMetadata( createArtifact( "org.apache.maven.update", "test-not-updated" ) ); + assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); + + // try again with the updated timestamp + metadataPaths = discoverer.discoverMetadata( repository, "update", null ); + assertNotNull( "Check metadata not null", metadataPaths ); + + assertFalse( "Check not included", containsMetadata( metadataPaths, metadata ) ); + } + + public void testNotUpdatedInRepositoryForcedDiscoveryOtherMetadataAlreadyExists() + throws ComponentLookupException, DiscovererException, IOException + { + discoverer.setLastCheckedTime( repository, "test", new Date() ); + + discoverer.resetLastCheckedTime( repository, "update" ); + + List metadataPaths = discoverer.discoverMetadata( repository, "update", null ); + assertNotNull( "Check metadata not null", metadataPaths ); + + RepositoryMetadata metadata = + new ArtifactRepositoryMetadata( createArtifact( "org.apache.maven.update", "test-not-updated" ) ); + assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); + + // try again with the updated timestamp + metadataPaths = discoverer.discoverMetadata( repository, "update", null ); + assertNotNull( "Check metadata not null", metadataPaths ); + + assertFalse( "Check not included", containsMetadata( metadataPaths, metadata ) ); + } + + public void testNoRepositoryMetadata() + throws ComponentLookupException, DiscovererException, ParseException, IOException + { + removeTimestampMetadata(); + + // should find all + List metadataPaths = discoverer.discoverMetadata( repository, TEST_OPERATION, null ); + assertNotNull( "Check metadata not null", metadataPaths ); + + RepositoryMetadata metadata = + new ArtifactRepositoryMetadata( createArtifact( "org.apache.maven.update", "test-updated" ) ); + assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); + } + + protected Artifact createArtifact( String groupId, String artifactId ) + { + return createArtifact( groupId, artifactId, "1.0" ); + } + + private Artifact createArtifact( String groupId, String artifactId, String version ) + { + return factory.createArtifact( groupId, artifactId, version, null, "jar" ); + } +} diff --git a/archiva-discoverer/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java b/archiva-discoverer/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java new file mode 100644 index 000000000..88cc07ad1 --- /dev/null +++ b/archiva-discoverer/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java @@ -0,0 +1,479 @@ +package org.apache.maven.repository.discovery; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +import java.io.File; +import java.net.MalformedURLException; +import java.util.Iterator; +import java.util.List; + +/** + * Test the legacy artifact discoverer. + * + * @author Brett Porter + * @version $Id$ + */ +public class LegacyArtifactDiscovererTest + extends AbstractArtifactDiscovererTest +{ + protected String getLayout() + { + return "legacy"; + } + + protected File getRepositoryFile() + { + return getTestFile( "src/test/legacy-repository" ); + } + + public void testDefaultExcludes() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( path.indexOf( ".svn" ) >= 0 ) + { + found = true; + assertEquals( "Check comment", "Artifact was in the specified list of exclusions", dPath.getComment() ); + } + } + assertTrue( "Check exclusion was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not .svn", a.getFile().getPath().indexOf( ".svn" ) >= 0 ); + } + } + + public void testStandardExcludes() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "KEYS".equals( path ) ) + { + found = true; + assertEquals( "Check comment", "Artifact was in the specified list of exclusions", dPath.getComment() ); + } + } + assertTrue( "Check exclusion was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not KEYS", "KEYS".equals( a.getFile().getName() ) ); + } + } + + public void testBlacklistedExclude() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, "javax.sql/**", false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "javax.sql/jars/jdbc-2.0.jar".equals( path.replace( '\\', '/' ) ) ) + { + found = true; + assertEquals( "Check comment is about blacklisting", "Artifact was in the specified list of exclusions", + dPath.getComment() ); + } + } + assertTrue( "Check exclusion was found", found ); + + assertFalse( "Check jdbc not included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) ); + } + + public void testKickoutWithShortPath() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "invalid/invalid-1.0.jar".equals( path.replace( '\\', '/' ) ) ) + { + found = true; + assertEquals( "Check reason for kickout", + "Path does not match a legacy repository path for an artifact", dPath.getComment() ); + } + } + assertTrue( "Check kickout was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not invalid-1.0.jar", "invalid-1.0.jar".equals( a.getFile().getName() ) ); + } + } + + public void testKickoutWithLongPath() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "invalid/jars/1.0/invalid-1.0.jar".equals( path.replace( '\\', '/' ) ) ) + { + found = true; + assertEquals( "Check reason for kickout", + "Path does not match a legacy repository path for an artifact", dPath.getComment() ); + } + } + assertTrue( "Check kickout was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not invalid-1.0.jar", "invalid-1.0.jar".equals( a.getFile().getName() ) ); + } + } + + public void testKickoutWithInvalidType() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "invalid/foo/invalid-1.0.foo".equals( path.replace( '\\', '/' ) ) ) + { + found = true; + assertEquals( "Check reason for kickout", "Path artifact type does not corresspond to an artifact type", + dPath.getComment() ); + } + } + assertTrue( "Check kickout was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not invalid-1.0.foo", "invalid-1.0.foo".equals( a.getFile().getName() ) ); + } + } + + public void testKickoutWithNoExtension() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "invalid/jars/no-extension".equals( path.replace( '\\', '/' ) ) ) + { + found = true; + assertEquals( "Check reason for kickout", "Path filename does not have an extension", + dPath.getComment() ); + } + } + assertTrue( "Check kickout was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not 'no-extension'", "no-extension".equals( a.getFile().getName() ) ); + } + } + + public void testKickoutWithWrongExtension() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "invalid/jars/invalid-1.0.rar".equals( path.replace( '\\', '/' ) ) ) + { + found = true; + assertEquals( "Check reason for kickout", "Path type does not match the extension", + dPath.getComment() ); + } + } + assertTrue( "Check kickout was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not 'invalid-1.0.rar'", "invalid-1.0.rar".equals( a.getFile().getName() ) ); + } + } + + public void testKickoutWithNoVersion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) + { + DiscovererPath dPath = (DiscovererPath) i.next(); + + String path = dPath.getPath(); + + if ( "invalid/jars/invalid.jar".equals( path.replace( '\\', '/' ) ) ) + { + found = true; + assertEquals( "Check reason for kickout", "Path filename version is empty", dPath.getComment() ); + } + } + assertTrue( "Check kickout was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not 'invalid.jar'", "invalid.jar".equals( a.getFile().getName() ) ); + } + } + + public void testInclusion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check normal included", + artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0" ) ) ); + } + + public void testTextualVersion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check normal included", + artifacts.contains( createArtifact( "org.apache.maven", "testing", "UNKNOWN" ) ) ); + } + + public void testArtifactWithClassifier() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check normal included", + artifacts.contains( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ) ) ); + } + + public void testJavaSourcesInclusion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check normal included", artifacts.contains( + createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ) ) ); + } + + public void testDistributionInclusion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check zip included", + artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ) ) ); + + assertTrue( "Check tar.gz included", + artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ) ) ); + } + + public void testSnapshotInclusion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) ); + assertTrue( "Check snapshot included", + artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) ); + } + + public void testSnapshotExclusion() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) ); + assertFalse( "Check snapshot included", + artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) ); + } + + public void testFileSet() + throws DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + assertNotNull( "Check file is set", artifact.getFile() ); + } + } + + public void testRepositorySet() + throws MalformedURLException, DiscovererException + { + List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + String url = repository.getUrl(); + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + assertNotNull( "Check repository set", artifact.getRepository() ); + assertEquals( "Check repository url is correct", url, artifact.getRepository().getUrl() ); + } + } + + public void testWrongArtifactPackaging() + throws ComponentLookupException, DiscovererException + { + try + { + discoverer.buildArtifact( "org.apache.maven.test/jars/artifactId-1.0.jar.md5" ); + + fail( "Artifact should be null for wrong package extension" ); + } + catch ( DiscovererException e ) + { + // excellent + } + } + + public void testNoArtifactId() + throws DiscovererException + { + try + { + discoverer.buildArtifact( "groupId/jars/-1.0.jar" ); + + fail( "Artifact should be null when artifactId is missing" ); + } + catch ( DiscovererException e ) + { + // excellent + } + + try + { + discoverer.buildArtifact( "groupId/jars/1.0.jar" ); + + fail( "Artifact should be null when artifactId is missing" ); + } + catch ( DiscovererException e ) + { + // excellent + } + } + + public void testNoType() + throws ComponentLookupException, DiscovererException + { + try + { + discoverer.buildArtifact( "invalid/invalid/1/invalid-1" ); + + fail( "Artifact should be null for no type" ); + } + catch ( DiscovererException e ) + { + // excellent + } + } + + public void testSnapshot() + throws ComponentLookupException, DiscovererException + { + String testPath = "org.apache.maven.test/jars/maven-model-1.0-SNAPSHOT.jar"; + + Artifact artifact = discoverer.buildArtifact( testPath ); + + assertEquals( createArtifact( "org.apache.maven.test", "maven-model", "1.0-SNAPSHOT" ), artifact ); + } + + public void testFinal() + throws ComponentLookupException, DiscovererException + { + String testPath = "org.apache.maven.test/jars/maven-model-1.0-final-20060606.jar"; + + Artifact artifact = discoverer.buildArtifact( testPath ); + + assertEquals( createArtifact( "org.apache.maven.test", "maven-model", "1.0-final-20060606" ), artifact ); + } + + public void testNormal() + throws ComponentLookupException, DiscovererException + { + String testPath = "javax.sql/jars/jdbc-2.0.jar"; + + Artifact artifact = discoverer.buildArtifact( testPath ); + + assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact ); + } +} diff --git a/archiva-discoverer/src/test/legacy-repository/KEYS b/archiva-discoverer/src/test/legacy-repository/KEYS new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/legacy-repository/invalid/foo/invalid-1.0.foo b/archiva-discoverer/src/test/legacy-repository/invalid/foo/invalid-1.0.foo new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/legacy-repository/invalid/invalid-1.0.jar b/archiva-discoverer/src/test/legacy-repository/invalid/invalid-1.0.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/legacy-repository/invalid/jars/1.0/invalid-1.0.jar b/archiva-discoverer/src/test/legacy-repository/invalid/jars/1.0/invalid-1.0.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/legacy-repository/invalid/jars/invalid-1.0.rar b/archiva-discoverer/src/test/legacy-repository/invalid/jars/invalid-1.0.rar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/legacy-repository/invalid/jars/invalid.jar b/archiva-discoverer/src/test/legacy-repository/invalid/jars/invalid.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/legacy-repository/invalid/jars/no-extension b/archiva-discoverer/src/test/legacy-repository/invalid/jars/no-extension new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/legacy-repository/javax.sql/jars/jdbc-2.0.jar b/archiva-discoverer/src/test/legacy-repository/javax.sql/jars/jdbc-2.0.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/legacy-repository/org.apache.maven.update/jars/test-not-updated-1.0.jar b/archiva-discoverer/src/test/legacy-repository/org.apache.maven.update/jars/test-not-updated-1.0.jar new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-discoverer/src/test/legacy-repository/org.apache.maven.update/jars/test-not-updated-1.0.jar @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-discoverer/src/test/legacy-repository/org.apache.maven.update/jars/test-updated-1.0.jar b/archiva-discoverer/src/test/legacy-repository/org.apache.maven.update/jars/test-updated-1.0.jar new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-discoverer/src/test/legacy-repository/org.apache.maven.update/jars/test-updated-1.0.jar @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-discoverer/src/test/legacy-repository/org.apache.maven/jars/some-ejb-1.0-client.jar b/archiva-discoverer/src/test/legacy-repository/org.apache.maven/jars/some-ejb-1.0-client.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/legacy-repository/org.apache.maven/jars/testing-1.0-20050611.112233-1.jar b/archiva-discoverer/src/test/legacy-repository/org.apache.maven/jars/testing-1.0-20050611.112233-1.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/legacy-repository/org.apache.maven/jars/testing-1.0-sources.jar b/archiva-discoverer/src/test/legacy-repository/org.apache.maven/jars/testing-1.0-sources.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/legacy-repository/org.apache.maven/jars/testing-1.0.jar b/archiva-discoverer/src/test/legacy-repository/org.apache.maven/jars/testing-1.0.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/legacy-repository/org.apache.maven/jars/testing-1.0.tar.gz b/archiva-discoverer/src/test/legacy-repository/org.apache.maven/jars/testing-1.0.tar.gz new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/legacy-repository/org.apache.maven/jars/testing-1.0.zip b/archiva-discoverer/src/test/legacy-repository/org.apache.maven/jars/testing-1.0.zip new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/legacy-repository/org.apache.maven/jars/testing-UNKNOWN.jar b/archiva-discoverer/src/test/legacy-repository/org.apache.maven/jars/testing-UNKNOWN.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/A/1.0/A-1.0.pom b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/A/1.0/A-1.0.pom new file mode 100644 index 000000000..411d77c7d --- /dev/null +++ b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/A/1.0/A-1.0.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.maven + A + 1.0 + Maven Test Repository Artifact Discovery + war + diff --git a/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/A/1.0/A-1.0.war b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/A/1.0/A-1.0.war new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/A/1.0/A-1.0.war @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/B/1.0/B-1.0.pom b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/B/1.0/B-1.0.pom new file mode 100644 index 000000000..35641a048 --- /dev/null +++ b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/B/1.0/B-1.0.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.maven + B + 1.0 + Maven Test Repository Artifact Discovery + pom + diff --git a/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/B/2.0/B-2.0.pom b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/B/2.0/B-2.0.pom new file mode 100644 index 000000000..6ab1e498b --- /dev/null +++ b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/B/2.0/B-2.0.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.maven + B + 2.0 + Maven Test Repository Artifact Discovery + pom + diff --git a/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/C/1.0/C-1.0.pom b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/C/1.0/C-1.0.pom new file mode 100644 index 000000000..867de41f0 --- /dev/null +++ b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/C/1.0/C-1.0.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.maven + C + 1.0 + Maven Test Repository Artifact Discovery + war + diff --git a/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/C/1.0/C-1.0.war b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/C/1.0/C-1.0.war new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/C/1.0/C-1.0.war @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/discovery/1.0/discovery-1.0.pom b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/discovery/1.0/discovery-1.0.pom new file mode 100644 index 000000000..4dfd1f4e5 --- /dev/null +++ b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/discovery/1.0/discovery-1.0.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.maven + discovery + 1.0 + Maven Test Repository Artifact Discovery + pom + diff --git a/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/samplejar/1.0/samplejar-1.0.jar b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/samplejar/1.0/samplejar-1.0.jar new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/samplejar/1.0/samplejar-1.0.jar @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/samplejar/1.0/samplejar-1.0.pom b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/samplejar/1.0/samplejar-1.0.pom new file mode 100644 index 000000000..51d5e433c --- /dev/null +++ b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/samplejar/1.0/samplejar-1.0.pom @@ -0,0 +1,10 @@ + + 4.0.0 + org.apache.maven + C + 1.0 + Maven Test Repository Artifact Discovery + + + diff --git a/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/samplejar/2.0/samplejar-2.0.jar b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/samplejar/2.0/samplejar-2.0.jar new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/samplejar/2.0/samplejar-2.0.jar @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/samplejar/2.0/samplejar-2.0.pom b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/samplejar/2.0/samplejar-2.0.pom new file mode 100644 index 000000000..c6f89f932 --- /dev/null +++ b/archiva-discoverer/src/test/pom-artifacts/org/apache/maven/samplejar/2.0/samplejar-2.0.pom @@ -0,0 +1,10 @@ + + 4.0.0 + org.apache.maven + C + 1.0 + Maven Test Repository Artifact Discovery + + jar + diff --git a/archiva-discoverer/src/test/pom-artifacts/org/apache/testgroup/discovery/1.0/discovery-1.0.pom b/archiva-discoverer/src/test/pom-artifacts/org/apache/testgroup/discovery/1.0/discovery-1.0.pom new file mode 100644 index 000000000..ac5ca14b3 --- /dev/null +++ b/archiva-discoverer/src/test/pom-artifacts/org/apache/testgroup/discovery/1.0/discovery-1.0.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.testgroup + discovery + 1.0 + Maven Test Repository Artifact Discovery + pom + diff --git a/archiva-discoverer/src/test/repository/KEYS b/archiva-discoverer/src/test/repository/KEYS new file mode 100644 index 000000000..d3b34d5ad --- /dev/null +++ b/archiva-discoverer/src/test/repository/KEYS @@ -0,0 +1 @@ +test KEYS file \ No newline at end of file diff --git a/archiva-discoverer/src/test/repository/invalid/invalid-1.0.jar b/archiva-discoverer/src/test/repository/invalid/invalid-1.0.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar b/archiva-discoverer/src/test/repository/invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar b/archiva-discoverer/src/test/repository/invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/invalid/invalid/1.0/invalid-1.0b.jar b/archiva-discoverer/src/test/repository/invalid/invalid/1.0/invalid-1.0b.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/invalid/invalid/1.0/invalid-2.0.jar b/archiva-discoverer/src/test/repository/invalid/invalid/1.0/invalid-2.0.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/invalid/invalid/1/invalid-1 b/archiva-discoverer/src/test/repository/invalid/invalid/1/invalid-1 new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/javax/maven-metadata.xml b/archiva-discoverer/src/test/repository/javax/maven-metadata.xml new file mode 100644 index 000000000..17775863b --- /dev/null +++ b/archiva-discoverer/src/test/repository/javax/maven-metadata.xml @@ -0,0 +1,21 @@ + + + + javax.sql + jdbc + 2.0 + diff --git a/archiva-discoverer/src/test/repository/javax/sql/jdbc/2.0/jdbc-2.0.jar b/archiva-discoverer/src/test/repository/javax/sql/jdbc/2.0/jdbc-2.0.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/javax/sql/jdbc/2.0/maven-metadata-repository.xml b/archiva-discoverer/src/test/repository/javax/sql/jdbc/2.0/maven-metadata-repository.xml new file mode 100644 index 000000000..17775863b --- /dev/null +++ b/archiva-discoverer/src/test/repository/javax/sql/jdbc/2.0/maven-metadata-repository.xml @@ -0,0 +1,21 @@ + + + + javax.sql + jdbc + 2.0 + diff --git a/archiva-discoverer/src/test/repository/javax/sql/jdbc/maven-metadata-repository.xml b/archiva-discoverer/src/test/repository/javax/sql/jdbc/maven-metadata-repository.xml new file mode 100644 index 000000000..214b7dc28 --- /dev/null +++ b/archiva-discoverer/src/test/repository/javax/sql/jdbc/maven-metadata-repository.xml @@ -0,0 +1,26 @@ + + + + javax.sql + jdbc + 2.0 + + + 2.0 + + + diff --git a/archiva-discoverer/src/test/repository/javax/sql/maven-metadata-repository.xml b/archiva-discoverer/src/test/repository/javax/sql/maven-metadata-repository.xml new file mode 100644 index 000000000..17775863b --- /dev/null +++ b/archiva-discoverer/src/test/repository/javax/sql/maven-metadata-repository.xml @@ -0,0 +1,21 @@ + + + + javax.sql + jdbc + 2.0 + diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/A/1.0/A-1.0.pom b/archiva-discoverer/src/test/repository/org/apache/maven/A/1.0/A-1.0.pom new file mode 100644 index 000000000..411d77c7d --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/A/1.0/A-1.0.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.maven + A + 1.0 + Maven Test Repository Artifact Discovery + war + diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/A/1.0/A-1.0.war b/archiva-discoverer/src/test/repository/org/apache/maven/A/1.0/A-1.0.war new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/A/1.0/A-1.0.war @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/B/1.0/B-1.0.pom b/archiva-discoverer/src/test/repository/org/apache/maven/B/1.0/B-1.0.pom new file mode 100644 index 000000000..35641a048 --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/B/1.0/B-1.0.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.maven + B + 1.0 + Maven Test Repository Artifact Discovery + pom + diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/B/2.0/B-2.0.pom b/archiva-discoverer/src/test/repository/org/apache/maven/B/2.0/B-2.0.pom new file mode 100644 index 000000000..6ab1e498b --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/B/2.0/B-2.0.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.maven + B + 2.0 + Maven Test Repository Artifact Discovery + pom + diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/C/1.0/C-1.0.pom b/archiva-discoverer/src/test/repository/org/apache/maven/C/1.0/C-1.0.pom new file mode 100644 index 000000000..867de41f0 --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/C/1.0/C-1.0.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.maven + C + 1.0 + Maven Test Repository Artifact Discovery + war + diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/C/1.0/C-1.0.war b/archiva-discoverer/src/test/repository/org/apache/maven/C/1.0/C-1.0.war new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/C/1.0/C-1.0.war @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/discovery/1.0/discovery-1.0.pom b/archiva-discoverer/src/test/repository/org/apache/maven/discovery/1.0/discovery-1.0.pom new file mode 100644 index 000000000..4dfd1f4e5 --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/discovery/1.0/discovery-1.0.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.maven + discovery + 1.0 + Maven Test Repository Artifact Discovery + pom + diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/maven-metadata.xml b/archiva-discoverer/src/test/repository/org/apache/maven/maven-metadata.xml new file mode 100644 index 000000000..22f46c19b --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/maven-metadata.xml @@ -0,0 +1,3 @@ + + org.apache.maven + \ No newline at end of file diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar b/archiva-discoverer/src/test/repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/samplejar/1.0/samplejar-1.0.pom b/archiva-discoverer/src/test/repository/org/apache/maven/samplejar/1.0/samplejar-1.0.pom new file mode 100644 index 000000000..51d5e433c --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/samplejar/1.0/samplejar-1.0.pom @@ -0,0 +1,10 @@ + + 4.0.0 + org.apache.maven + C + 1.0 + Maven Test Repository Artifact Discovery + + + diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/samplejar/2.0/samplejar-2.0.jar b/archiva-discoverer/src/test/repository/org/apache/maven/samplejar/2.0/samplejar-2.0.jar new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/samplejar/2.0/samplejar-2.0.jar @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/samplejar/2.0/samplejar-2.0.pom b/archiva-discoverer/src/test/repository/org/apache/maven/samplejar/2.0/samplejar-2.0.pom new file mode 100644 index 000000000..c6f89f932 --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/samplejar/2.0/samplejar-2.0.pom @@ -0,0 +1,10 @@ + + 4.0.0 + org.apache.maven + C + 1.0 + Maven Test Repository Artifact Discovery + + jar + diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/some-ejb/1.0/maven-metadata.xml b/archiva-discoverer/src/test/repository/org/apache/maven/some-ejb/1.0/maven-metadata.xml new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar b/archiva-discoverer/src/test/repository/org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1-javadoc.jar b/archiva-discoverer/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1-javadoc.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar b/archiva-discoverer/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar b/archiva-discoverer/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/testing/1.0/testing-1.0-sources.jar b/archiva-discoverer/src/test/repository/org/apache/maven/testing/1.0/testing-1.0-sources.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.jar b/archiva-discoverer/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.tar.gz b/archiva-discoverer/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.tar.gz new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.zip b/archiva-discoverer/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.zip new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.jar b/archiva-discoverer/src/test/repository/org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.jar new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.jar @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.pom b/archiva-discoverer/src/test/repository/org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.pom new file mode 100644 index 000000000..21bef0276 --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.pom @@ -0,0 +1,10 @@ + + 4.0.0 + org.apache.maven.update + test-not-updated + 1.0 + Maven Test Repository Artifact Discovery + + + diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/update/test-not-updated/maven-metadata.xml b/archiva-discoverer/src/test/repository/org/apache/maven/update/test-not-updated/maven-metadata.xml new file mode 100644 index 000000000..71fc9790f --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/update/test-not-updated/maven-metadata.xml @@ -0,0 +1,4 @@ + + org.apache.maven.update + test-not-updated + \ No newline at end of file diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/update/test-updated/1.0/test-updated-1.0.jar b/archiva-discoverer/src/test/repository/org/apache/maven/update/test-updated/1.0/test-updated-1.0.jar new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/update/test-updated/1.0/test-updated-1.0.jar @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/update/test-updated/1.0/test-updated-1.0.pom b/archiva-discoverer/src/test/repository/org/apache/maven/update/test-updated/1.0/test-updated-1.0.pom new file mode 100644 index 000000000..5f88c44df --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/update/test-updated/1.0/test-updated-1.0.pom @@ -0,0 +1,10 @@ + + 4.0.0 + org.apache.maven.update + test-updated + 1.0 + Maven Test Repository Artifact Discovery + + + diff --git a/archiva-discoverer/src/test/repository/org/apache/maven/update/test-updated/maven-metadata.xml b/archiva-discoverer/src/test/repository/org/apache/maven/update/test-updated/maven-metadata.xml new file mode 100644 index 000000000..fc17a16d7 --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/maven/update/test-updated/maven-metadata.xml @@ -0,0 +1,4 @@ + + org.apache.maven.update + test-updated + \ No newline at end of file diff --git a/archiva-discoverer/src/test/repository/org/apache/testgroup/discovery/1.0/discovery-1.0.pom b/archiva-discoverer/src/test/repository/org/apache/testgroup/discovery/1.0/discovery-1.0.pom new file mode 100644 index 000000000..ac5ca14b3 --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/testgroup/discovery/1.0/discovery-1.0.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.testgroup + discovery + 1.0 + Maven Test Repository Artifact Discovery + pom + diff --git a/archiva-discoverer/src/test/repository/org/apache/testgroup/discovery/1.0/maven-metadata.xml b/archiva-discoverer/src/test/repository/org/apache/testgroup/discovery/1.0/maven-metadata.xml new file mode 100644 index 000000000..9bb9b5a58 --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/testgroup/discovery/1.0/maven-metadata.xml @@ -0,0 +1,5 @@ + + org.apache.testgroup + discovery + 1.0 + \ No newline at end of file diff --git a/archiva-discoverer/src/test/repository/org/apache/testgroup/discovery/maven-metadata.xml b/archiva-discoverer/src/test/repository/org/apache/testgroup/discovery/maven-metadata.xml new file mode 100644 index 000000000..50215f42b --- /dev/null +++ b/archiva-discoverer/src/test/repository/org/apache/testgroup/discovery/maven-metadata.xml @@ -0,0 +1,4 @@ + + org.apache.testgroup + discovery + \ No newline at end of file diff --git a/archiva-indexer/pom.xml b/archiva-indexer/pom.xml new file mode 100644 index 000000000..8f5aa5e51 --- /dev/null +++ b/archiva-indexer/pom.xml @@ -0,0 +1,81 @@ + + + + + org.apache.maven.archiva + archiva + 1.0-SNAPSHOT + + 4.0.0 + archiva-indexer + Archiva Repository Indexer + + + org.apache.maven + maven-artifact + + + org.apache.maven + maven-artifact-manager + + + org.apache.maven + maven-project + + + org.apache.maven + maven-model + + + org.apache.lucene + lucene-core + 2.0.0 + + + org.codehaus.plexus + plexus-utils + + + org.codehaus.plexus + plexus-container-default + + + org.apache.maven.archiva + archiva-utils + + + org.apache.maven + maven-repository-metadata + + + + + + org.codehaus.mojo + cobertura-maven-plugin + + + + 80 + 80 + + + + + + diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java new file mode 100644 index 000000000..03803ed53 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java @@ -0,0 +1,69 @@ +package org.apache.maven.repository.indexing; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.repository.indexing.query.Query; + +import java.util.Collection; +import java.util.List; + +/** + * Maintain an artifact index on the repository. + * + * @author Brett Porter + */ +public interface RepositoryArtifactIndex +{ + /** + * Indexes the artifacts found within the specified list of index records. If the artifacts are already in the + * repository they are updated. + * + * @param records the artifacts to index + * @throws RepositoryIndexException if there is a problem indexing the records + */ + void indexRecords( Collection records ) + throws RepositoryIndexException; + + /** + * Search the index based on the search criteria specified. Returns a list of index records. + * + * @param query The query that contains the search criteria + * @return the index records found + * @throws RepositoryIndexSearchException if there is a problem searching + * @todo should it return "SearchResult" instances that contain the index record and other search data (like score?) + */ + List search( Query query ) + throws RepositoryIndexSearchException; + + /** + * Check if the index already exists. + * + * @return true if the index already exists + * @throws RepositoryIndexException if the index location is not valid + */ + boolean exists() + throws RepositoryIndexException; + + /** + * Delete records from the index. Simply ignore the request any did not exist. + * + * @param records the records to delete + * @throws RepositoryIndexException if there is a problem removing the record + */ + void deleteRecords( Collection records ) + throws RepositoryIndexException; +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndexFactory.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndexFactory.java new file mode 100644 index 000000000..ed0100527 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndexFactory.java @@ -0,0 +1,48 @@ +package org.apache.maven.repository.indexing; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 java.io.File; + +/** + * Obtain an index instance. + * + * @author Brett Porter + */ +public interface RepositoryArtifactIndexFactory +{ + /** + * Plexus role. + */ + String ROLE = RepositoryArtifactIndexFactory.class.getName(); + + /** + * Method to create an instance of the standard index. + * + * @param indexPath the path where the index will be created/updated + * @return the index instance + */ + RepositoryArtifactIndex createStandardIndex( File indexPath ); + + /** + * Method to create an instance of the minimal index. + * + * @param indexPath the path where the index will be created/updated + * @return the index instance + */ + RepositoryArtifactIndex createMinimalIndex( File indexPath ); +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexException.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexException.java new file mode 100644 index 000000000..fe16c022c --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexException.java @@ -0,0 +1,34 @@ +package org.apache.maven.repository.indexing; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * @author Edwin Punzalan + */ +public class RepositoryIndexException + extends Exception +{ + public RepositoryIndexException( String message, Throwable cause ) + { + super( message, cause ); + } + + public RepositoryIndexException( String message ) + { + super( message ); + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java new file mode 100644 index 000000000..cd84bde19 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java @@ -0,0 +1,29 @@ +package org.apache.maven.repository.indexing; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * @author Brett Porter + */ +public class RepositoryIndexSearchException + extends Exception +{ + public RepositoryIndexSearchException( String message, Throwable cause ) + { + super( message, cause ); + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneIndexRecordConverter.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneIndexRecordConverter.java new file mode 100644 index 000000000..7aaf123e3 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneIndexRecordConverter.java @@ -0,0 +1,48 @@ +package org.apache.maven.repository.indexing.lucene; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.lucene.document.Document; +import org.apache.maven.repository.indexing.record.RepositoryIndexRecord; + +import java.text.ParseException; + +/** + * Converts repository records to Lucene documents. + * + * @author Brett Porter + */ +public interface LuceneIndexRecordConverter +{ + /** + * Convert an index record to a Lucene document. + * + * @param record the record + * @return the document + */ + Document convert( RepositoryIndexRecord record ); + + /** + * Convert a Lucene document to an index record. + * + * @param document the document + * @return the record + * @throws java.text.ParseException if there is a problem parsing a field (specifically, dates) + */ + RepositoryIndexRecord convert( Document document ) + throws ParseException; +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalIndexRecordConverter.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalIndexRecordConverter.java new file mode 100644 index 000000000..02def2dbd --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalIndexRecordConverter.java @@ -0,0 +1,84 @@ +package org.apache.maven.repository.indexing.lucene; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.lucene.document.DateTools; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.NumberTools; +import org.apache.maven.repository.indexing.record.MinimalArtifactIndexRecord; +import org.apache.maven.repository.indexing.record.MinimalIndexRecordFields; +import org.apache.maven.repository.indexing.record.RepositoryIndexRecord; +import org.codehaus.plexus.util.StringUtils; + +import java.text.ParseException; +import java.util.Arrays; + +/** + * Convert the minimal index record to a Lucene document. + * + * @author Brett Porter + */ +public class LuceneMinimalIndexRecordConverter + implements LuceneIndexRecordConverter +{ + public Document convert( RepositoryIndexRecord record ) + { + MinimalArtifactIndexRecord rec = (MinimalArtifactIndexRecord) record; + + Document document = new Document(); + addTokenizedField( document, MinimalIndexRecordFields.FILENAME, rec.getFilename() ); + addUntokenizedField( document, MinimalIndexRecordFields.LAST_MODIFIED, + DateTools.timeToString( rec.getLastModified(), DateTools.Resolution.SECOND ) ); + addUntokenizedField( document, MinimalIndexRecordFields.FILE_SIZE, NumberTools.longToString( rec.getSize() ) ); + addUntokenizedField( document, MinimalIndexRecordFields.MD5, rec.getMd5Checksum() ); + addTokenizedField( document, MinimalIndexRecordFields.CLASSES, + StringUtils.join( rec.getClasses().iterator(), "\n" ) ); + + return document; + } + + public RepositoryIndexRecord convert( Document document ) + throws ParseException + { + MinimalArtifactIndexRecord record = new MinimalArtifactIndexRecord(); + + record.setFilename( document.get( MinimalIndexRecordFields.FILENAME ) ); + record.setLastModified( DateTools.stringToTime( document.get( MinimalIndexRecordFields.LAST_MODIFIED ) ) ); + record.setSize( NumberTools.stringToLong( document.get( MinimalIndexRecordFields.FILE_SIZE ) ) ); + record.setMd5Checksum( document.get( MinimalIndexRecordFields.MD5 ) ); + record.setClasses( Arrays.asList( document.get( MinimalIndexRecordFields.CLASSES ).split( "\n" ) ) ); + + return record; + } + + private static void addUntokenizedField( Document document, String name, String value ) + { + if ( value != null ) + { + document.add( new Field( name, value, Field.Store.YES, Field.Index.UN_TOKENIZED ) ); + } + } + + private static void addTokenizedField( Document document, String name, String value ) + { + if ( value != null ) + { + document.add( new Field( name, value, Field.Store.YES, Field.Index.TOKENIZED ) ); + } + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneQuery.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneQuery.java new file mode 100644 index 000000000..13fdcaf5c --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneQuery.java @@ -0,0 +1,40 @@ +package org.apache.maven.repository.indexing.lucene; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.repository.indexing.query.Query; + +/** + * A holder for a lucene query to pass to the indexer API. + * + * @author Brett Porter + */ +public class LuceneQuery + implements Query +{ + private final org.apache.lucene.search.Query query; + + public LuceneQuery( org.apache.lucene.search.Query query ) + { + this.query = query; + } + + org.apache.lucene.search.Query getLuceneQuery() + { + return query; + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java new file mode 100644 index 000000000..dff648ec5 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java @@ -0,0 +1,276 @@ +package org.apache.maven.repository.indexing.lucene; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.Hits; +import org.apache.lucene.search.IndexSearcher; +import org.apache.maven.repository.indexing.RepositoryArtifactIndex; +import org.apache.maven.repository.indexing.RepositoryIndexException; +import org.apache.maven.repository.indexing.RepositoryIndexSearchException; +import org.apache.maven.repository.indexing.query.Query; +import org.apache.maven.repository.indexing.record.RepositoryIndexRecord; + +import java.io.File; +import java.io.IOException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +/** + * Lucene implementation of a repository index. + * + * @author Brett Porter + */ +public class LuceneRepositoryArtifactIndex + implements RepositoryArtifactIndex +{ + /** + * The location of the index on the file system. + */ + private File indexLocation; + + /** + * Convert repository records to Lucene documents. + */ + private LuceneIndexRecordConverter converter; + + private static final String FLD_PK = "pk"; + + public LuceneRepositoryArtifactIndex( File indexPath, LuceneIndexRecordConverter converter ) + { + this.indexLocation = indexPath; + this.converter = converter; + } + + public void indexRecords( Collection records ) + throws RepositoryIndexException + { + deleteRecords( records ); + + addRecords( records ); + } + + private void addRecords( Collection records ) + throws RepositoryIndexException + { + IndexWriter indexWriter; + try + { + indexWriter = new IndexWriter( indexLocation, getAnalyzer(), !exists() ); + } + catch ( IOException e ) + { + throw new RepositoryIndexException( "Unable to open index", e ); + } + + try + { + for ( Iterator i = records.iterator(); i.hasNext(); ) + { + RepositoryIndexRecord record = (RepositoryIndexRecord) i.next(); + + if ( record != null ) + { + Document document = converter.convert( record ); + document.add( + new Field( FLD_PK, record.getPrimaryKey(), Field.Store.NO, Field.Index.UN_TOKENIZED ) ); + + indexWriter.addDocument( document ); + } + } + + indexWriter.optimize(); + } + catch ( IOException e ) + { + throw new RepositoryIndexException( "Failed to add an index document", e ); + } + finally + { + close( indexWriter ); + } + } + + private void close( IndexWriter indexWriter ) + throws RepositoryIndexException + { + try + { + if ( indexWriter != null ) + { + indexWriter.close(); + } + } + catch ( IOException e ) + { + throw new RepositoryIndexException( e.getMessage(), e ); + } + } + + private Analyzer getAnalyzer() + { + // TODO: investigate why changed in original! Probably for MD5 and number querying. + return new StandardAnalyzer(); + } + + public void deleteRecords( Collection records ) + throws RepositoryIndexException + { + if ( exists() ) + { + IndexReader indexReader = null; + try + { + indexReader = IndexReader.open( indexLocation ); + + for ( Iterator artifacts = records.iterator(); artifacts.hasNext(); ) + { + RepositoryIndexRecord record = (RepositoryIndexRecord) artifacts.next(); + + if ( record != null ) + { + Term term = new Term( FLD_PK, record.getPrimaryKey() ); + + indexReader.deleteDocuments( term ); + } + } + } + catch ( IOException e ) + { + throw new RepositoryIndexException( "Error deleting document: " + e.getMessage(), e ); + } + finally + { + if ( indexReader != null ) + { + closeQuietly( indexReader ); + } + } + } + } + + public boolean exists() + throws RepositoryIndexException + { + if ( IndexReader.indexExists( indexLocation ) ) + { + return true; + } + else if ( !indexLocation.exists() ) + { + return false; + } + else if ( indexLocation.isDirectory() ) + { + if ( indexLocation.listFiles().length > 1 ) + { + throw new RepositoryIndexException( indexLocation + " is not a valid index directory." ); + } + else + { + return false; + } + } + else + { + throw new RepositoryIndexException( indexLocation + " is not a directory." ); + } + } + + public List search( Query query ) + throws RepositoryIndexSearchException + { + LuceneQuery lQuery = (LuceneQuery) query; + + org.apache.lucene.search.Query luceneQuery = lQuery.getLuceneQuery(); + + IndexSearcher searcher; + try + { + searcher = new IndexSearcher( indexLocation.getAbsolutePath() ); + } + catch ( IOException e ) + { + throw new RepositoryIndexSearchException( "Unable to open index: " + e.getMessage(), e ); + } + + List records = new ArrayList(); + try + { + Hits hits = searcher.search( luceneQuery ); + for ( int i = 0; i < hits.length(); i++ ) + { + Document doc = hits.doc( i ); + + records.add( converter.convert( doc ) ); + } + } + catch ( IOException e ) + { + throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e ); + } + catch ( ParseException e ) + { + throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e ); + } + finally + { + closeQuietly( searcher ); + } + + return records; + } + + private static void closeQuietly( IndexSearcher searcher ) + { + try + { + if ( searcher != null ) + { + searcher.close(); + } + } + catch ( IOException e ) + { + // ignore + } + } + + private static void closeQuietly( IndexReader reader ) + { + try + { + if ( reader != null ) + { + reader.close(); + } + } + catch ( IOException e ) + { + // ignore + } + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndexFactory.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndexFactory.java new file mode 100644 index 000000000..97278b009 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndexFactory.java @@ -0,0 +1,42 @@ +package org.apache.maven.repository.indexing.lucene; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.repository.indexing.RepositoryArtifactIndex; +import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; + +import java.io.File; + +/** + * Factory for Lucene artifact index instances. + * + * @author Brett Porter + * @plexus.component role="org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory" role-hint="lucene" + */ +public class LuceneRepositoryArtifactIndexFactory + implements RepositoryArtifactIndexFactory +{ + public RepositoryArtifactIndex createStandardIndex( File indexPath ) + { + return new LuceneRepositoryArtifactIndex( indexPath, new LuceneStandardIndexRecordConverter() ); + } + + public RepositoryArtifactIndex createMinimalIndex( File indexPath ) + { + return new LuceneRepositoryArtifactIndex( indexPath, new LuceneMinimalIndexRecordConverter() ); + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneStandardIndexRecordConverter.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneStandardIndexRecordConverter.java new file mode 100644 index 000000000..f8f6a53b2 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneStandardIndexRecordConverter.java @@ -0,0 +1,145 @@ +package org.apache.maven.repository.indexing.lucene; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.lucene.document.DateTools; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.NumberTools; +import org.apache.maven.repository.indexing.record.RepositoryIndexRecord; +import org.apache.maven.repository.indexing.record.StandardArtifactIndexRecord; +import org.apache.maven.repository.indexing.record.StandardIndexRecordFields; +import org.codehaus.plexus.util.StringUtils; + +import java.text.ParseException; +import java.util.Arrays; + +/** + * Convert the standard index record to a Lucene document. + * + * @author Brett Porter + */ +public class LuceneStandardIndexRecordConverter + implements LuceneIndexRecordConverter +{ + public Document convert( RepositoryIndexRecord record ) + { + StandardArtifactIndexRecord rec = (StandardArtifactIndexRecord) record; + + Document document = new Document(); + addTokenizedField( document, StandardIndexRecordFields.FILENAME, rec.getFilename() ); + addTokenizedField( document, StandardIndexRecordFields.GROUPID, rec.getGroupId() ); + addExactField( document, StandardIndexRecordFields.GROUPID_EXACT, rec.getGroupId() ); + addTokenizedField( document, StandardIndexRecordFields.ARTIFACTID, rec.getArtifactId() ); + addExactField( document, StandardIndexRecordFields.ARTIFACTID_EXACT, rec.getArtifactId() ); + addTokenizedField( document, StandardIndexRecordFields.VERSION, rec.getVersion() ); + addExactField( document, StandardIndexRecordFields.VERSION_EXACT, rec.getVersion() ); + addTokenizedField( document, StandardIndexRecordFields.BASE_VERSION, rec.getBaseVersion() ); + addExactField( document, StandardIndexRecordFields.BASE_VERSION_EXACT, rec.getBaseVersion() ); + addUntokenizedField( document, StandardIndexRecordFields.TYPE, rec.getType() ); + addTokenizedField( document, StandardIndexRecordFields.CLASSIFIER, rec.getClassifier() ); + addUntokenizedField( document, StandardIndexRecordFields.PACKAGING, rec.getPackaging() ); + addUntokenizedField( document, StandardIndexRecordFields.REPOSITORY, rec.getRepository() ); + addUntokenizedField( document, StandardIndexRecordFields.LAST_MODIFIED, + DateTools.timeToString( rec.getLastModified(), DateTools.Resolution.SECOND ) ); + addUntokenizedField( document, StandardIndexRecordFields.FILE_SIZE, NumberTools.longToString( rec.getSize() ) ); + addUntokenizedField( document, StandardIndexRecordFields.MD5, rec.getMd5Checksum() ); + addUntokenizedField( document, StandardIndexRecordFields.SHA1, rec.getSha1Checksum() ); + if ( rec.getClasses() != null ) + { + addTokenizedField( document, StandardIndexRecordFields.CLASSES, + StringUtils.join( rec.getClasses().iterator(), "\n" ) ); + } + if ( rec.getFiles() != null ) + { + addTokenizedField( document, StandardIndexRecordFields.FILES, + StringUtils.join( rec.getFiles().iterator(), "\n" ) ); + } + addUntokenizedField( document, StandardIndexRecordFields.PLUGIN_PREFIX, rec.getPluginPrefix() ); + addUntokenizedField( document, StandardIndexRecordFields.INCEPTION_YEAR, rec.getInceptionYear() ); + addTokenizedField( document, StandardIndexRecordFields.PROJECT_NAME, rec.getProjectName() ); + addTokenizedField( document, StandardIndexRecordFields.PROJECT_DESCRIPTION, rec.getProjectDescription() ); +/* TODO: add later + document.add( Field.Keyword( StandardIndexRecordFields.FLD_LICENSE_URLS, "" ) ); + document.add( Field.Keyword( StandardIndexRecordFields.FLD_DEPENDENCIES, "" ) ); + document.add( Field.Keyword( StandardIndexRecordFields.FLD_PLUGINS_REPORT, "" ) ); + document.add( Field.Keyword( StandardIndexRecordFields.FLD_PLUGINS_BUILD, "" ) ); +*/ + + return document; + } + + public RepositoryIndexRecord convert( Document document ) + throws ParseException + { + StandardArtifactIndexRecord record = new StandardArtifactIndexRecord(); + + record.setFilename( document.get( StandardIndexRecordFields.FILENAME ) ); + record.setGroupId( document.get( StandardIndexRecordFields.GROUPID ) ); + record.setArtifactId( document.get( StandardIndexRecordFields.ARTIFACTID ) ); + record.setVersion( document.get( StandardIndexRecordFields.VERSION ) ); + record.setBaseVersion( document.get( StandardIndexRecordFields.BASE_VERSION ) ); + record.setType( document.get( StandardIndexRecordFields.TYPE ) ); + record.setClassifier( document.get( StandardIndexRecordFields.CLASSIFIER ) ); + record.setPackaging( document.get( StandardIndexRecordFields.PACKAGING ) ); + record.setRepository( document.get( StandardIndexRecordFields.REPOSITORY ) ); + record.setLastModified( DateTools.stringToTime( document.get( StandardIndexRecordFields.LAST_MODIFIED ) ) ); + record.setSize( NumberTools.stringToLong( document.get( StandardIndexRecordFields.FILE_SIZE ) ) ); + record.setMd5Checksum( document.get( StandardIndexRecordFields.MD5 ) ); + record.setSha1Checksum( document.get( StandardIndexRecordFields.SHA1 ) ); + String classes = document.get( StandardIndexRecordFields.CLASSES ); + if ( classes != null ) + { + record.setClasses( Arrays.asList( classes.split( "\n" ) ) ); + } + String files = document.get( StandardIndexRecordFields.FILES ); + if ( files != null ) + { + record.setFiles( Arrays.asList( files.split( "\n" ) ) ); + } + record.setPluginPrefix( document.get( StandardIndexRecordFields.PLUGIN_PREFIX ) ); + record.setInceptionYear( document.get( StandardIndexRecordFields.INCEPTION_YEAR ) ); + record.setProjectName( document.get( StandardIndexRecordFields.PROJECT_NAME ) ); + record.setProjectDescription( document.get( StandardIndexRecordFields.PROJECT_DESCRIPTION ) ); + + return record; + } + + private static void addUntokenizedField( Document document, String name, String value ) + { + if ( value != null ) + { + document.add( new Field( name, value, Field.Store.YES, Field.Index.UN_TOKENIZED ) ); + } + } + + private static void addExactField( Document document, String name, String value ) + { + if ( value != null ) + { + document.add( new Field( name, value, Field.Store.NO, Field.Index.UN_TOKENIZED ) ); + } + } + + private static void addTokenizedField( Document document, String name, String value ) + { + if ( value != null ) + { + document.add( new Field( name, value, Field.Store.YES, Field.Index.TOKENIZED ) ); + } + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java new file mode 100644 index 000000000..85760b621 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java @@ -0,0 +1,105 @@ +package org.apache.maven.repository.indexing.query; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 java.util.ArrayList; +import java.util.List; + +/** + * Class to hold multiple SinglePhraseQueries and/or other CompoundQueries. + * + * @author Edwin Punzalan + */ +public class CompoundQuery + implements Query +{ + /** + * The query terms. + */ + private final List compoundQueryTerms = new ArrayList(); + + /** + * Appends a required term to this query. + * + * @param term the term to be appended to this query + */ + public void and( QueryTerm term ) + { + compoundQueryTerms.add( CompoundQueryTerm.and( new SingleTermQuery( term ) ) ); + } + + /** + * Appends an optional term to this query. + * + * @param term the term to be appended to this query + */ + public void or( QueryTerm term ) + { + compoundQueryTerms.add( CompoundQueryTerm.or( new SingleTermQuery( term ) ) ); + } + + /** + * Appends a prohibited term to this query. + * + * @param term the term to be appended to this query + */ + public void not( QueryTerm term ) + { + compoundQueryTerms.add( CompoundQueryTerm.not( new SingleTermQuery( term ) ) ); + } + + /** + * Appends a required subquery to this query. + * + * @param query the subquery to be appended to this query + */ + public void and( Query query ) + { + compoundQueryTerms.add( CompoundQueryTerm.and( query ) ); + } + + /** + * Appends an optional subquery to this query. + * + * @param query the subquery to be appended to this query + */ + public void or( Query query ) + { + compoundQueryTerms.add( CompoundQueryTerm.or( query ) ); + } + + /** + * Appends a prohibited subquery to this query. + * + * @param query the subquery to be appended to this query + */ + public void not( Query query ) + { + compoundQueryTerms.add( CompoundQueryTerm.not( query ) ); + } + + /** + * Method to get the List of Queries appended into this + * + * @return List of all Queries added to this Query + */ + public List getCompoundQueryTerms() + { + return compoundQueryTerms; + } + +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java new file mode 100644 index 000000000..abc99bd13 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java @@ -0,0 +1,100 @@ +package org.apache.maven.repository.indexing.query; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * Base of all query terms. + * + * @author Brett Porter + */ +public class CompoundQueryTerm +{ + /** + * The query to add to the compound query. + */ + private final Query query; + + /** + * Whether the term is required (an AND). + */ + private final boolean required; + + /** + * Whether the term is prohibited (a NOT). + */ + private final boolean prohibited; + + /** + * Class constructor + * + * @param query the subquery to add + * @param required whether the term is required (an AND) + * @param prohibited whether the term is prohibited (a NOT) + */ + private CompoundQueryTerm( Query query, boolean required, boolean prohibited ) + { + this.query = query; + this.prohibited = prohibited; + this.required = required; + } + + /** + * Method to test if the Query is a search requirement + * + * @return true if this Query is a search requirement, otherwise returns false + */ + public boolean isRequired() + { + return required; + } + + /** + * Method to test if the Query is prohibited in the search result + * + * @return true if this Query is prohibited in the search result + */ + public boolean isProhibited() + { + return prohibited; + } + + + /** + * The subquery to execute. + * + * @return the query + */ + public Query getQuery() + { + return query; + } + + static CompoundQueryTerm and( Query query ) + { + return new CompoundQueryTerm( query, true, false ); + } + + static CompoundQueryTerm or( Query query ) + { + return new CompoundQueryTerm( query, false, false ); + } + + static CompoundQueryTerm not( Query query ) + { + return new CompoundQueryTerm( query, false, true ); + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/Query.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/Query.java new file mode 100644 index 000000000..2c6ac6137 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/Query.java @@ -0,0 +1,26 @@ +package org.apache.maven.repository.indexing.query; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * Interface to label the query classes + * + * @author Edwin Punzalan + */ +public interface Query +{ +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/QueryTerm.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/QueryTerm.java new file mode 100644 index 000000000..6db240b3a --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/QueryTerm.java @@ -0,0 +1,61 @@ +package org.apache.maven.repository.indexing.query; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * Class to hold a single field search condition + * + * @author Edwin Punzalan + */ +public class QueryTerm +{ + private String field; + + private String value; + + /** + * Class constructor + * + * @param field the index field to search + * @param value the index value requirement + */ + public QueryTerm( String field, String value ) + { + this.field = field; + this.value = value; + } + + /** + * Method to retrieve the name of the index field searched + * + * @return the name of the index field + */ + public String getField() + { + return field; + } + + /** + * Method to retrieve the value used in searching the index field + * + * @return the value to corresspond the index field + */ + public String getValue() + { + return value; + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.java new file mode 100644 index 000000000..68e6d4a6a --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.java @@ -0,0 +1,150 @@ +package org.apache.maven.repository.indexing.query; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * Query object that handles range queries (presently used for dates). + * + * @author Maria Odea Ching + * @author Brett Porter + */ +public class RangeQuery + implements Query +{ + /** + * Whether values equal to the boundaries are included in the query results. + */ + private final boolean inclusive; + + /** + * The lower bound. + */ + private final QueryTerm begin; + + /** + * The upper bound. + */ + private final QueryTerm end; + + /** + * Constructor. + * + * @param begin the lower bound + * @param end the upper bound + * @param inclusive whether to include the boundaries in the query + */ + private RangeQuery( QueryTerm begin, QueryTerm end, boolean inclusive ) + { + this.begin = begin; + this.end = end; + this.inclusive = inclusive; + } + + /** + * Create an open range, including all results. + * + * @return the query object + */ + public static RangeQuery createOpenRange() + { + return new RangeQuery( null, null, false ); + } + + /** + * Create a bounded range, excluding the endpoints. + * + * @param begin the lower bound value to compare to + * @param end the upper bound value to compare to + * @return the query object + */ + public static RangeQuery createExclusiveRange( QueryTerm begin, QueryTerm end ) + { + return new RangeQuery( begin, end, false ); + } + + /** + * Create a bounded range, including the endpoints. + * + * @param begin the lower bound value to compare to + * @param end the upper bound value to compare to + * @return the query object + */ + public static RangeQuery createInclusiveRange( QueryTerm begin, QueryTerm end ) + { + return new RangeQuery( begin, end, true ); + } + + /** + * Create a range that is greater than or equal to a given term. + * + * @param begin the value to compare to + * @return the query object + */ + public static RangeQuery createGreaterThanOrEqualToRange( QueryTerm begin ) + { + return new RangeQuery( begin, null, true ); + } + + /** + * Create a range that is greater than a given term. + * + * @param begin the value to compare to + * @return the query object + */ + public static RangeQuery createGreaterThanRange( QueryTerm begin ) + { + return new RangeQuery( begin, null, false ); + } + + /** + * Create a range that is less than or equal to a given term. + * + * @param end the value to compare to + * @return the query object + */ + public static RangeQuery createLessThanOrEqualToRange( QueryTerm end ) + { + return new RangeQuery( null, end, true ); + } + + /** + * Create a range that is less than a given term. + * + * @param end the value to compare to + * @return the query object + */ + public static RangeQuery createLessThanRange( QueryTerm end ) + { + return new RangeQuery( null, end, false ); + } + + public QueryTerm getBegin() + { + return begin; + } + + public QueryTerm getEnd() + { + return end; + } + + public boolean isInclusive() + { + return inclusive; + } + +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/SingleTermQuery.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/SingleTermQuery.java new file mode 100644 index 000000000..f7ae019fa --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/query/SingleTermQuery.java @@ -0,0 +1,62 @@ +package org.apache.maven.repository.indexing.query; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * Query for a single term. + * + * @author Brett Porter + */ +public class SingleTermQuery + implements Query +{ + /** + * The term to query for. + */ + private final QueryTerm term; + + /** + * Constructor. + * + * @param term the term to query + */ + public SingleTermQuery( QueryTerm term ) + { + this.term = term; + } + + /** + * Shorthand constructor - create a single term query from a field and value + * + * @param field the field name + * @param value the value to check for + */ + public SingleTermQuery( String field, String value ) + { + this.term = new QueryTerm( field, value ); + } + + public String getField() + { + return term.getField(); + } + + public String getValue() + { + return term.getValue(); + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/AbstractArtifactIndexRecordFactory.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/AbstractArtifactIndexRecordFactory.java new file mode 100644 index 000000000..8a9a8cc91 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/AbstractArtifactIndexRecordFactory.java @@ -0,0 +1,98 @@ +package org.apache.maven.repository.indexing.record; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.repository.digest.Digester; +import org.apache.maven.repository.digest.DigesterException; +import org.codehaus.plexus.logging.AbstractLogEnabled; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +/** + * Base class for the index record factories. + * + * @author Brett Porter + */ +public abstract class AbstractArtifactIndexRecordFactory + extends AbstractLogEnabled + implements RepositoryIndexRecordFactory +{ + protected String readChecksum( File file, Digester digester ) + { + String checksum; + try + { + checksum = digester.calc( file ).toLowerCase(); + } + catch ( DigesterException e ) + { + getLogger().error( "Error getting checksum for artifact file, leaving empty in index: " + e.getMessage() ); + checksum = null; + } + return checksum; + } + + protected List readFilesInArchive( File file ) + throws IOException + { + ZipFile zipFile = new ZipFile( file ); + List files; + try + { + files = new ArrayList( zipFile.size() ); + + for ( Enumeration entries = zipFile.entries(); entries.hasMoreElements(); ) + { + ZipEntry entry = (ZipEntry) entries.nextElement(); + + files.add( entry.getName() ); + } + } + finally + { + closeQuietly( zipFile ); + } + return files; + } + + protected static boolean isClass( String name ) + { + // TODO: verify if class is public or protected (this might require the original ZipEntry) + return name.endsWith( ".class" ) && name.lastIndexOf( "$" ) < 0; + } + + protected static void closeQuietly( ZipFile zipFile ) + { + try + { + if ( zipFile != null ) + { + zipFile.close(); + } + } + catch ( IOException e ) + { + // ignored + } + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecord.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecord.java new file mode 100644 index 000000000..4c212520c --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecord.java @@ -0,0 +1,170 @@ +package org.apache.maven.repository.indexing.record; + +import java.util.Date; +import java.util.List; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * The a record with the fields in the minimal index. + * + * @author Brett Porter + */ +public class MinimalArtifactIndexRecord + implements RepositoryIndexRecord +{ + /** + * The classes in the archive for the artifact, if it is a JAR. + */ + private List classes; + + /** + * The MD5 checksum of the artifact file. + */ + private String md5Checksum; + + /** + * The filename of the artifact file (no path). + */ + private String filename; + + /** + * The timestamp that the artifact file was last modified. Granularity is seconds. + */ + private long lastModified; + + /** + * The size of the artifact file in bytes. + */ + private long size; + + private static final int MS_PER_SEC = 1000; + + public void setClasses( List classes ) + { + this.classes = classes; + } + + public void setMd5Checksum( String md5Checksum ) + { + this.md5Checksum = md5Checksum; + } + + public void setFilename( String filename ) + { + this.filename = filename; + } + + public void setLastModified( long lastModified ) + { + this.lastModified = lastModified - lastModified % MS_PER_SEC; + } + + public void setSize( long size ) + { + this.size = size; + } + + public List getClasses() + { + return classes; + } + + public String getMd5Checksum() + { + return md5Checksum; + } + + public String getFilename() + { + return filename; + } + + public long getLastModified() + { + return lastModified; + } + + public long getSize() + { + return size; + } + + /** + * @noinspection RedundantIfStatement + */ + public boolean equals( Object obj ) + { + if ( this == obj ) + { + return true; + } + if ( obj == null || getClass() != obj.getClass() ) + { + return false; + } + + MinimalArtifactIndexRecord that = (MinimalArtifactIndexRecord) obj; + + if ( lastModified != that.lastModified ) + { + return false; + } + if ( size != that.size ) + { + return false; + } + if ( classes != null ? !classes.equals( that.classes ) : that.classes != null ) + { + return false; + } + if ( !filename.equals( that.filename ) ) + { + return false; + } + if ( md5Checksum != null ? !md5Checksum.equals( that.md5Checksum ) : that.md5Checksum != null ) + { + return false; + } + + return true; + } + + /** + * @noinspection UnnecessaryParentheses + */ + public int hashCode() + { + int result = classes != null ? classes.hashCode() : 0; + result = 31 * result + ( md5Checksum != null ? md5Checksum.hashCode() : 0 ); + result = 31 * result + filename.hashCode(); + result = 31 * result + (int) ( lastModified ^ ( lastModified >>> 32 ) ); + result = 31 * result + (int) ( size ^ ( size >>> 32 ) ); + return result; + } + + public String toString() + { + return "Filename: " + filename + "; checksum: " + md5Checksum + "; size: " + size + "; lastModified: " + + new Date( lastModified ) + "; classes: " + classes; + } + + public String getPrimaryKey() + { + return filename; + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactory.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactory.java new file mode 100644 index 000000000..7f007747c --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactory.java @@ -0,0 +1,100 @@ +package org.apache.maven.repository.indexing.record; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.repository.digest.Digester; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +/** + * An index record type for the minimal index. + * + * @author Edwin Punzalan + * @author Brett Porter + * @plexus.component role="org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory" role-hint="minimal" + */ +public class MinimalArtifactIndexRecordFactory + extends AbstractArtifactIndexRecordFactory +{ + /* List of types to index. */ + private static final Set INDEXED_TYPES = new HashSet( Arrays.asList( new String[]{"jar", "maven-plugin"} ) ); + /** + * @plexus.requirement role-hint="sha1" + */ + protected Digester sha1Digester; + /** + * @plexus.requirement role-hint="md5" + */ + protected Digester md5Digester; + + public RepositoryIndexRecord createRecord( Artifact artifact ) + { + MinimalArtifactIndexRecord record = null; + + File file = artifact.getFile(); + if ( file != null && INDEXED_TYPES.contains( artifact.getType() ) && file.exists() ) + { + String md5 = readChecksum( file, md5Digester ); + + List files = null; + try + { + files = readFilesInArchive( file ); + } + catch ( IOException e ) + { + getLogger().error( "Error reading artifact file, omitting from index: " + e.getMessage() ); + } + + if ( files != null ) + { + record = new MinimalArtifactIndexRecord(); + record.setMd5Checksum( md5 ); + record.setFilename( artifact.getRepository().pathOf( artifact ) ); + record.setLastModified( file.lastModified() ); + record.setSize( file.length() ); + record.setClasses( getClassesFromFiles( files ) ); + } + } + return record; + } + + private List getClassesFromFiles( List files ) + { + List classes = new ArrayList(); + + for ( Iterator i = files.iterator(); i.hasNext(); ) + { + String name = (String) i.next(); + + if ( isClass( name ) ) + { + classes.add( name.substring( 0, name.length() - 6 ).replace( '/', '.' ) ); + } + } + + return classes; + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalIndexRecordFields.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalIndexRecordFields.java new file mode 100644 index 000000000..5bb8add24 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalIndexRecordFields.java @@ -0,0 +1,41 @@ +package org.apache.maven.repository.indexing.record; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * The fields in a minimal artifact index record. + * + * @author Brett Porter + * @todo should be an enum + */ +public class MinimalIndexRecordFields +{ + public static final String FILENAME = "j"; + + public static final String LAST_MODIFIED = "d"; + + public static final String FILE_SIZE = "s"; + + public static final String MD5 = "m"; + + public static final String CLASSES = "c"; + + private MinimalIndexRecordFields() + { + // No touchy! + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecord.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecord.java new file mode 100644 index 000000000..10c99f1a3 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecord.java @@ -0,0 +1,32 @@ +package org.apache.maven.repository.indexing.record; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * A repository index record. + * + * @author Brett Porter + */ +public interface RepositoryIndexRecord +{ + /** + * Get the primary key used to identify the record uniquely in the index. + * + * @return the primary key + */ + String getPrimaryKey(); +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecordFactory.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecordFactory.java new file mode 100644 index 000000000..2dde9674d --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecordFactory.java @@ -0,0 +1,44 @@ +package org.apache.maven.repository.indexing.record; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.repository.indexing.RepositoryIndexException; + +/** + * The layout of a record in a repository index. + * + * @author Brett Porter + */ +public interface RepositoryIndexRecordFactory +{ + /** + * The Plexus role. + */ + String ROLE = RepositoryIndexRecordFactory.class.getName(); + + /** + * Create an index record from an artifact. + * + * @param artifact the artifact + * @return the index record + * @throws RepositoryIndexException if there is a problem constructing the record (due to not being able to read the artifact file as a POM) + */ + RepositoryIndexRecord createRecord( Artifact artifact ) + throws RepositoryIndexException; + +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecord.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecord.java new file mode 100644 index 000000000..d2e97a4b2 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecord.java @@ -0,0 +1,339 @@ +package org.apache.maven.repository.indexing.record; + +import java.util.List; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * The a record with the fields in the standard index. + * + * @author Brett Porter + */ +public class StandardArtifactIndexRecord + extends MinimalArtifactIndexRecord +{ + /** + * The SHA-1 checksum of the artifact file. + */ + private String sha1Checksum; + + /** + * The artifact's group. + */ + private String groupId; + + /** + * The artifact's identifier within the group. + */ + private String artifactId; + + /** + * The artifact's version. + */ + private String version; + + /** + * The classifier, if there is one. + */ + private String classifier; + + /** + * The artifact type (from the file). + */ + private String type; + + /** + * A list of files (separated by '\n') in the artifact if it is an archive. + */ + private List files; + + /** + * The identifier of the repository that the artifact came from. + */ + private String repository; + + /** + * The packaging specified in the POM for this artifact. + */ + private String packaging; + + /** + * The plugin prefix specified in the metadata if the artifact is a plugin. + */ + private String pluginPrefix; + + /** + * The year the project was started. + */ + private String inceptionYear; + + /** + * The description of the project. + */ + private String projectDescription; + + /** + * The name of the project. + */ + private String projectName; + + /** + * The base version (before the snapshot is determined). + */ + private String baseVersion; + + public void setSha1Checksum( String sha1Checksum ) + { + this.sha1Checksum = sha1Checksum; + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public void setVersion( String version ) + { + this.version = version; + } + + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + + public void setType( String type ) + { + this.type = type; + } + + public void setFiles( List files ) + { + this.files = files; + } + + public void setRepository( String repository ) + { + this.repository = repository; + } + + /** + * @noinspection RedundantIfStatement + */ + public boolean equals( Object obj ) + { + if ( this == obj ) + { + return true; + } + if ( obj == null || getClass() != obj.getClass() ) + { + return false; + } + if ( !super.equals( obj ) ) + { + return false; + } + + StandardArtifactIndexRecord that = (StandardArtifactIndexRecord) obj; + + if ( !artifactId.equals( that.artifactId ) ) + { + return false; + } + if ( classifier != null ? !classifier.equals( that.classifier ) : that.classifier != null ) + { + return false; + } + if ( files != null ? !files.equals( that.files ) : that.files != null ) + { + return false; + } + if ( !groupId.equals( that.groupId ) ) + { + return false; + } + if ( repository != null ? !repository.equals( that.repository ) : that.repository != null ) + { + return false; + } + if ( sha1Checksum != null ? !sha1Checksum.equals( that.sha1Checksum ) : that.sha1Checksum != null ) + { + return false; + } + if ( type != null ? !type.equals( that.type ) : that.type != null ) + { + return false; + } + if ( !version.equals( that.version ) ) + { + return false; + } + if ( !baseVersion.equals( that.baseVersion ) ) + { + return false; + } + if ( packaging != null ? !packaging.equals( that.packaging ) : that.packaging != null ) + { + return false; + } + if ( pluginPrefix != null ? !pluginPrefix.equals( that.pluginPrefix ) : that.pluginPrefix != null ) + { + return false; + } + if ( projectName != null ? !projectName.equals( that.projectName ) : that.projectName != null ) + { + return false; + } + if ( inceptionYear != null ? !inceptionYear.equals( that.inceptionYear ) : that.inceptionYear != null ) + { + return false; + } + if ( projectDescription != null ? !projectDescription.equals( that.projectDescription ) + : that.projectDescription != null ) + { + return false; + } + + return true; + } + + public int hashCode() + { + int result = super.hashCode(); + result = 31 * result + ( sha1Checksum != null ? sha1Checksum.hashCode() : 0 ); + result = 31 * result + groupId.hashCode(); + result = 31 * result + artifactId.hashCode(); + result = 31 * result + version.hashCode(); + result = 31 * result + baseVersion.hashCode(); + result = 31 * result + ( classifier != null ? classifier.hashCode() : 0 ); + result = 31 * result + ( type != null ? type.hashCode() : 0 ); + result = 31 * result + ( files != null ? files.hashCode() : 0 ); + result = 31 * result + ( repository != null ? repository.hashCode() : 0 ); + result = 31 * result + ( packaging != null ? packaging.hashCode() : 0 ); + result = 31 * result + ( pluginPrefix != null ? pluginPrefix.hashCode() : 0 ); + result = 31 * result + ( inceptionYear != null ? inceptionYear.hashCode() : 0 ); + result = 31 * result + ( projectName != null ? projectName.hashCode() : 0 ); + result = 31 * result + ( projectDescription != null ? projectDescription.hashCode() : 0 ); + return result; + } + + public String getSha1Checksum() + { + return sha1Checksum; + } + + public String getGroupId() + { + return groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public String getVersion() + { + return version; + } + + public String getClassifier() + { + return classifier; + } + + public String getType() + { + return type; + } + + public List getFiles() + { + return files; + } + + public String getRepository() + { + return repository; + } + + public String getPackaging() + { + return packaging; + } + + public String getPluginPrefix() + { + return pluginPrefix; + } + + public void setPackaging( String packaging ) + { + this.packaging = packaging; + } + + public void setPluginPrefix( String pluginPrefix ) + { + this.pluginPrefix = pluginPrefix; + } + + public void setInceptionYear( String inceptionYear ) + { + this.inceptionYear = inceptionYear; + } + + public void setProjectDescription( String description ) + { + this.projectDescription = description; + } + + public void setProjectName( String projectName ) + { + this.projectName = projectName; + } + + public String getInceptionYear() + { + return inceptionYear; + } + + public String getProjectDescription() + { + return projectDescription; + } + + public String getProjectName() + { + return projectName; + } + + public void setBaseVersion( String baseVersion ) + { + this.baseVersion = baseVersion; + } + + public String getBaseVersion() + { + return baseVersion; + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java new file mode 100644 index 000000000..ec20288b2 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java @@ -0,0 +1,302 @@ +package org.apache.maven.repository.indexing.record; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Model; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.repository.digest.Digester; +import org.apache.maven.repository.indexing.RepositoryIndexException; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.codehaus.plexus.util.xml.Xpp3DomBuilder; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; + +/** + * An index record type for the standard index. + * + * @author Edwin Punzalan + * @author Brett Porter + * @plexus.component role="org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory" role-hint="standard" + */ +public class StandardArtifactIndexRecordFactory + extends AbstractArtifactIndexRecordFactory +{ + /** + * A list of artifact types to treat as a zip archive. + * + * @todo this should be smarter (perhaps use plexus archiver to look for an unarchiver, and make the ones for zip configurable since sar, par, etc can be added at random. + */ + private static final Set ARCHIVE_TYPES = + new HashSet( Arrays.asList( new String[]{"jar", "ejb", "par", "sar", "war", "ear", "rar"} ) ); + + /** + * @plexus.requirement + */ + private ArtifactFactory artifactFactory; + + /** + * @plexus.requirement + */ + private MavenProjectBuilder projectBuilder; + + /** + * @plexus.requirement role-hint="sha1" + */ + protected Digester sha1Digester; + + /** + * @plexus.requirement role-hint="md5" + */ + protected Digester md5Digester; + + private static final String PLUGIN_METADATA_NAME = "META-INF/maven/plugin.xml"; + + private static final String ARCHETYPE_METADATA_NAME = "META-INF/maven/archetype.xml"; + + // some current/old archetypes have the archetype.xml at different location. + private static final String ARCHETYPE_METADATA_NAME_OLD = "META-INF/archetype.xml"; + + public RepositoryIndexRecord createRecord( Artifact artifact ) + throws RepositoryIndexException + { + StandardArtifactIndexRecord record = null; + + File file = artifact.getFile(); + + // TODO: is this condition really a possibility? + if ( file != null && file.exists() ) + { + String md5 = readChecksum( file, md5Digester ); + String sha1 = readChecksum( file, sha1Digester ); + + List files = null; + boolean archive = ARCHIVE_TYPES.contains( artifact.getType() ); + try + { + if ( archive ) + { + files = readFilesInArchive( file ); + } + } + catch ( IOException e ) + { + getLogger().error( "Error reading artifact file, omitting from index: " + e.getMessage() ); + } + + // If it's an archive with no files, don't create a record + if ( !archive || files != null ) + { + record = new StandardArtifactIndexRecord(); + + record.setGroupId( artifact.getGroupId() ); + record.setArtifactId( artifact.getArtifactId() ); + record.setBaseVersion( artifact.getBaseVersion() ); + record.setVersion( artifact.getVersion() ); + record.setClassifier( artifact.getClassifier() ); + record.setType( artifact.getType() ); + record.setMd5Checksum( md5 ); + record.setSha1Checksum( sha1 ); + record.setFilename( artifact.getRepository().pathOf( artifact ) ); + record.setLastModified( file.lastModified() ); + record.setSize( file.length() ); + record.setRepository( artifact.getRepository().getId() ); + if ( files != null ) + { + populateArchiveEntries( files, record, artifact.getFile() ); + } + + if ( !"pom".equals( artifact.getType() ) ) + { + Artifact pomArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), + artifact.getArtifactId(), + artifact.getVersion() ); + pomArtifact.isSnapshot(); // gross hack around bug in maven-artifact + File pomFile = new File( artifact.getRepository().getBasedir(), + artifact.getRepository().pathOf( pomArtifact ) ); + if ( pomFile.exists() ) + { + try + { + populatePomEntries( readPom( pomArtifact, artifact.getRepository() ), record ); + } + catch ( ProjectBuildingException e ) + { + getLogger().error( "Error reading POM file, not populating in index: " + e.getMessage() ); + } + } + } + else + { + Model model; + try + { + model = readPom( artifact, artifact.getRepository() ); + + if ( !"pom".equals( model.getPackaging() ) ) + { + // Don't return a record for a POM that is does not belong on its own + record = null; + } + else + { + populatePomEntries( model, record ); + } + } + catch ( ProjectBuildingException e ) + { + getLogger().error( "Error reading POM file, not populating in index: " + e.getMessage() ); + } + } + } + } + + return record; + } + + private void populatePomEntries( Model pom, StandardArtifactIndexRecord record ) + { + record.setPackaging( pom.getPackaging() ); + record.setProjectName( pom.getName() ); + record.setProjectDescription( pom.getDescription() ); + record.setInceptionYear( pom.getInceptionYear() ); + +/* TODO: fields for later + indexPlugins( doc, FLD_PLUGINS_BUILD, pom.getBuild().getPlugins().iterator() ); + indexReportPlugins( doc, FLD_PLUGINS_REPORT, pom.getReporting().getPlugins().iterator() ); + record.setDependencies( dependencies ); + record.setLicenses( licenses ); +*/ + } + + private Model readPom( Artifact artifact, ArtifactRepository repository ) + throws RepositoryIndexException, ProjectBuildingException + { + // TODO: this can create a -SNAPSHOT.pom when it didn't exist and a timestamped one did. This is harmless, but should be avoided + // TODO: will this pollute with local repo metadata? + MavenProject project = projectBuilder.buildFromRepository( artifact, Collections.EMPTY_LIST, repository ); + return project.getModel(); + } + + private void populateArchiveEntries( List files, StandardArtifactIndexRecord record, File artifactFile ) + throws RepositoryIndexException + { + List classes = new ArrayList(); + List fileList = new ArrayList(); + + for ( Iterator i = files.iterator(); i.hasNext(); ) + { + String name = (String) i.next(); + + // ignore directories + if ( !name.endsWith( "/" ) ) + { + fileList.add( name ); + + if ( isClass( name ) ) + { + classes.add( name.substring( 0, name.length() - 6 ).replace( '/', '.' ) ); + } + else if ( PLUGIN_METADATA_NAME.equals( name ) ) + { + populatePluginEntries( readXmlMetadataFileInJar( artifactFile, PLUGIN_METADATA_NAME ), record ); + } + else if ( ARCHETYPE_METADATA_NAME.equals( name ) || ARCHETYPE_METADATA_NAME_OLD.equals( name ) ) + { + populateArchetypeEntries( record ); + } + } + } + + if ( !classes.isEmpty() ) + { + record.setClasses( classes ); + } + if ( !fileList.isEmpty() ) + { + record.setFiles( fileList ); + } + } + + private void populateArchetypeEntries( StandardArtifactIndexRecord record ) + { + // Typically discovered as a JAR + record.setType( "maven-archetype" ); + } + + private Xpp3Dom readXmlMetadataFileInJar( File file, String name ) + throws RepositoryIndexException + { + // TODO: would be more efficient with original ZipEntry still around + + Xpp3Dom xpp3Dom; + ZipFile zipFile = null; + try + { + zipFile = new ZipFile( file ); + ZipEntry entry = zipFile.getEntry( name ); + xpp3Dom = Xpp3DomBuilder.build( new InputStreamReader( zipFile.getInputStream( entry ) ) ); + } + catch ( ZipException e ) + { + throw new RepositoryIndexException( "Unable to read plugin metadata: " + e.getMessage(), e ); + } + catch ( IOException e ) + { + throw new RepositoryIndexException( "Unable to read plugin metadata: " + e.getMessage(), e ); + } + catch ( XmlPullParserException e ) + { + throw new RepositoryIndexException( "Unable to read plugin metadata: " + e.getMessage(), e ); + } + finally + { + closeQuietly( zipFile ); + } + return xpp3Dom; + } + + public void populatePluginEntries( Xpp3Dom metadata, StandardArtifactIndexRecord record ) + { + // Typically discovered as a JAR + record.setType( "maven-plugin" ); + + Xpp3Dom prefix = metadata.getChild( "goalPrefix" ); + + if ( prefix != null ) + { + record.setPluginPrefix( prefix.getValue() ); + } + } +} diff --git a/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardIndexRecordFields.java b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardIndexRecordFields.java new file mode 100644 index 000000000..5bfdf3347 --- /dev/null +++ b/archiva-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardIndexRecordFields.java @@ -0,0 +1,77 @@ +package org.apache.maven.repository.indexing.record; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * The fields in a minimal artifact index record. + * + * @author Brett Porter + * @todo should be an enum + */ +public class StandardIndexRecordFields +{ + public static final String FILENAME = "filename"; + + public static final String GROUPID = "groupId"; + + public static final String GROUPID_EXACT = GROUPID + "_u"; + + public static final String ARTIFACTID = "artifactId"; + + public static final String ARTIFACTID_EXACT = ARTIFACTID + "_u"; + + public static final String VERSION = "version"; + + public static final String VERSION_EXACT = VERSION + "_u"; + + public static final String BASE_VERSION = "baseVersion"; + + public static final String BASE_VERSION_EXACT = BASE_VERSION + "_u"; + + public static final String TYPE = "type"; + + public static final String CLASSIFIER = "classifier"; + + public static final String PACKAGING = "packaging"; + + public static final String REPOSITORY = "repo"; + + public static final String LAST_MODIFIED = "lastModified"; + + public static final String FILE_SIZE = "fileSize"; + + public static final String MD5 = "md5"; + + public static final String SHA1 = "sha1"; + + public static final String CLASSES = "classes"; + + public static final String PLUGIN_PREFIX = "pluginPrefix"; + + public static final String FILES = "files"; + + public static final String INCEPTION_YEAR = "inceptionYear"; + + public static final String PROJECT_NAME = "projectName"; + + public static final String PROJECT_DESCRIPTION = "projectDesc"; + + private StandardIndexRecordFields() + { + // No touchy! + } +} diff --git a/archiva-indexer/src/site/apt/design.apt b/archiva-indexer/src/site/apt/design.apt new file mode 100644 index 000000000..d083789e3 --- /dev/null +++ b/archiva-indexer/src/site/apt/design.apt @@ -0,0 +1,136 @@ + ----- + Indexer Design + ----- + Brett Porter + ----- + 25 July 2006 + ----- + +Indexer Design + + <> + + ~~TODO: separate API design from Lucene implementation design + +* Standard Artifact Index + + We currently want to index these elements from the repository: + + * for each artifact file: the artifact ID, version, group ID, classifier, type (extension), filename (including path + from the repository base), checksums (md5, sha1) and size + + * for each artifact POM: the packaging, licenses, dependencies, build plugins, reporting plugins + + * plugin prefix + + * Java classes within a JAR artifact (delimited by \n) + + * filenames within an archive (delimited by \n) + + * the identifier of the source repository + + Each record in the index refers to an artifact. Since the content for a record can come from various sources, the + record may need to be updated when different files that are related to the same artifact are discovered (ie, the + POM, or for plugins the metadata that contains their prefix). + + To simplify this, the process for discovery is as follows: + + * Discovered artifacts will read the related POM and metadata from the repository to index, rather than relying on + it being discovered. This ensures that partial discovery still yields correct results in all cases, and it is + possible to construct the entire record without having to read back from the index. + + * POMs that do not have a packaging of POM are not sent to the indexer. + + The result of this process is that updates to a POM or repository metadata and not the corresponding artifact(s) will + not update the index. As POMs should not be modified, this will not be a major concern. Likewise, updates to metadata + will only accompany updates to the artifact itself, so will not cause a problem. + + The above case may have a problem if the discovery happens during the middle of a deployment outside of the + repository manager (where the artifact is present, but the metadata or POM is not). To avoid such cases, the + discoverer should only detect changes more than a minute old (this blackout should be configurable). + + Other techniques were considered: + + * Processing each artifact file individually, updating each record as needed. This would result in having to read + back each index record before writing. This is quite costly in Lucene as it would be "read, delete, add". You + must have a reader and writer open for that process, and it greatly complicates the code. + + * Have three indices, one for each. This would complicate searching (and may affect ranking of results, though this + was not analysed). While Lucene is + {{{http://wiki.apache.org/jakarta-lucene/LuceneFAQ#head-b11296f9e7b2a5e7496d67118d0a5898f2fd9823} capable of + searching multiple indices}}, it is expected that the results would be in the form of a list of separate records + rather than the "table join" this effectively is. A similar derivative of this technique would be to store + everything in one index, using a field (previously, doctype) to identify each record. + + Records in the index are keyed by their path from the repository root. While this is longer than using the + dependency conflict ID, Lucene cannot delete by a combination of terms, so would require storing an additional + field in the index where the file already exists. + + The plugin prefix could be found either from inside the plugin JAR (<<>>), or from the + repository metadata for the plugin's group. For simplicity, the first approach will be used. This means at present + there is no need to index the repository metadata, however that may be considered in future. + + Note that archetypes currently don't have a packaging associated with them in Maven, so it is not recorded in the POM. + However, to be able to search by this type, the indexer will look for a <<>> file, and + if found set its packaging to <<>>. In the future, this handling will be deprecated as the POMs + can start using the appropriate packaging. + + The index is shared among multiple repositories. The source repository is recorded in the index record. The + discovery/conversion/reporting mechanisms are expected to deal with duplicates before reaching the indexer, so if the + indexer encounters an artifact from a different repository than it was already added, it will simply replace the + record. + + When indexing metadata from a POM, the POM should be loaded using the Maven project builder so that inheritance and + interpolation are performed. This ensures that the record is as complete as possible, and that searching by + fields that are inherited will reveal both the parent and the children in the search results. + +* Reduced Size Index + + An additional index is maintained by the repository manager in the + {{{../apidocs/org/apache/maven/repository/indexing/MinimalArtifactIndexRecord.html} MinimalIndex}} class. This + indexes all of the same artifacts as the first index, but stores them with shorter field names and less information to + maintain a smaller size. This index is appropriate for use by certain clients such as IDE integration for fast + searching. For a fuller interface to the repository information, the integration should use the XMLRPC interface. + + The following fields are in the reduced index: + + * <<>>: The JAR filename + + * <<>>: The JAR size + + * <<>>: The last modified timestamp + + * <<>>: A list of classes in the JAR (\n delimited) + + * <<>>: md5 checksum of the JAR + + * <<>>: the primary key of the artifact + + Only JARs are indexed at present. The JAR filename is used as the key for later deleting entries. + +* Searching + + Searching will be reasonably flexible, though the general use case will be to enter a single parsed query that is + applied to all fields in the index. + + Some features that will be available: + + * : the general case described above. + + * : This would be needed for search by checksum. + + * : This would be needed for searching based on update time. Note that in + Lucene it may be better to search by other fields (or return all), and then filter the results by dates rather + than making dates part of a search query. + + * : It will be useful to only search Java classes and packages, for example + + Another thing to note is that the search results should be able to be composed entirely from the index for performance + reasons. It should not have to read any metadata files or properties of files such as size and checksum from the disk. + This enables searching a repository remotely without having the physical repository available, which is useful for + IDE integration among other things. + + Note that to be able to do an exact match search, a field must be stored untokenized. For fields where it makes sense + to search both tokenized and untokenized, they will be stored twice. This currently includes: artifact ID, group ID, + and version. diff --git a/archiva-indexer/src/site/site.xml b/archiva-indexer/src/site/site.xml new file mode 100644 index 000000000..565d18fd0 --- /dev/null +++ b/archiva-indexer/src/site/site.xml @@ -0,0 +1,24 @@ + + + + + + + + + + diff --git a/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexSearchTest.java b/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexSearchTest.java new file mode 100644 index 000000000..63198db55 --- /dev/null +++ b/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexSearchTest.java @@ -0,0 +1,218 @@ +package org.apache.maven.repository.indexing.lucene; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.lucene.index.Term; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.TermQuery; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.repository.indexing.RepositoryArtifactIndex; +import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; +import org.apache.maven.repository.indexing.RepositoryIndexSearchException; +import org.apache.maven.repository.indexing.record.MinimalIndexRecordFields; +import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Test the Lucene implementation of the artifact index search. + * + * @author Brett Porter + * @todo would be nice to abstract some of the query away, but for now passing in a Lucene query directly is good enough + */ +public class LuceneMinimalArtifactIndexSearchTest + extends PlexusTestCase +{ + private RepositoryArtifactIndex index; + + private ArtifactRepository repository; + + private ArtifactFactory artifactFactory; + + private File indexLocation; + + private RepositoryIndexRecordFactory recordFactory; + + private Map records = new HashMap(); + + protected void setUp() + throws Exception + { + super.setUp(); + + recordFactory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "minimal" ); + + artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + + ArtifactRepositoryFactory repositoryFactory = + (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + + File file = getTestFile( "src/test/managed-repository" ); + repository = + repositoryFactory.createArtifactRepository( "test", file.toURI().toURL().toString(), layout, null, null ); + + RepositoryArtifactIndexFactory factory = + (RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" ); + + indexLocation = getTestFile( "target/test-index" ); + + FileUtils.deleteDirectory( indexLocation ); + + index = factory.createMinimalIndex( indexLocation ); + + records.put( "test-jar", recordFactory.createRecord( createArtifact( "test-jar" ) ) ); + records.put( "test-jar-jdk14", + recordFactory.createRecord( createArtifact( "test-jar", "1.0", "jar", "jdk14" ) ) ); + records.put( "test-jar-and-pom", + recordFactory.createRecord( createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar" ) ) ); + records.put( "test-jar-and-pom-jdk14", recordFactory.createRecord( + createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar", "jdk14" ) ) ); + records.put( "test-child-pom", + recordFactory.createRecord( createArtifact( "test-child-pom", "1.0-20060728.121314-1", "jar" ) ) ); + records.put( "test-archetype", recordFactory.createRecord( createArtifact( "test-archetype" ) ) ); + records.put( "test-plugin", recordFactory.createRecord( createArtifact( "test-plugin" ) ) ); + records.put( "test-pom", recordFactory.createRecord( createArtifact( "test-pom", "1.0", "pom" ) ) ); + records.put( "parent-pom", recordFactory.createRecord( createArtifact( "parent-pom", "1", "pom" ) ) ); + records.put( "test-dll", recordFactory.createRecord( createArtifact( "test-dll", "1.0.1.34", "dll" ) ) ); + + index.indexRecords( records.values() ); + } + + public void testExactMatchMd5() + throws RepositoryIndexSearchException + { + Query query = new TermQuery( new Term( MinimalIndexRecordFields.MD5, "3a0adc365f849366cd8b633cad155cb7" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); + assertEquals( "Check results size", 5, results.size() ); + + // test non-match fails + query = new TermQuery( new Term( MinimalIndexRecordFields.MD5, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testMatchFilename() + throws RepositoryIndexSearchException + { + Query query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "maven" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertFalse( "Check result", results.contains( records.get( "test-pom" ) ) ); + assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) ); + assertFalse( "Check result", results.contains( records.get( "test-dll" ) ) ); + assertEquals( "Check results size", 7, results.size() ); + +/* TODO: if this is a result we want, we need to change the analyzer. Currently, it is tokenizing it as plugin-1.0 and plugin/1.0 in the path + query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "plugin" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); + assertEquals( "Check results size", 1, results.size() ); +*/ + query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "test" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) ); + assertFalse( "Check result", results.contains( records.get( "test-pom" ) ) ); + assertFalse( "Check result", results.contains( records.get( "test-dll" ) ) ); + assertEquals( "Check results size", 7, results.size() ); + + // test non-match fails + query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testMatchClass() + throws RepositoryIndexSearchException + { + // TODO: should be preserving case! + Query query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "b.c.c" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); + assertEquals( "Check results size", 5, results.size() ); + +/* TODO!: need to change the analyzer if we want partial classes (split on '.') + query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "C" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); + assertEquals( "Check results size", 4, results.size() ); + + query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "MyMojo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); + assertEquals( "Check results size", 1, results.size() ); +*/ + + // test non-match fails + query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + private Artifact createArtifact( String artifactId ) + { + return createArtifact( artifactId, "1.0", "jar", null ); + } + + private Artifact createArtifact( String artifactId, String version, String type ) + { + return createArtifact( artifactId, version, type, null ); + } + + private Artifact createArtifact( String artifactId, String version, String type, String classifier ) + { + Artifact artifact = artifactFactory.createDependencyArtifact( "org.apache.maven.repository.record", artifactId, + VersionRange.createFromVersion( version ), type, + classifier, Artifact.SCOPE_RUNTIME ); + artifact.isSnapshot(); + artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); + artifact.setRepository( repository ); + return artifact; + } +} diff --git a/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java b/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java new file mode 100644 index 000000000..a08d181ac --- /dev/null +++ b/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java @@ -0,0 +1,351 @@ +package org.apache.maven.repository.indexing.lucene; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.NumberTools; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriter; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.repository.indexing.RepositoryArtifactIndex; +import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; +import org.apache.maven.repository.indexing.RepositoryIndexException; +import org.apache.maven.repository.indexing.record.MinimalIndexRecordFields; +import org.apache.maven.repository.indexing.record.RepositoryIndexRecord; +import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.TimeZone; + +/** + * Test the Lucene implementation of the artifact index. + * + * @author Brett Porter + */ +public class LuceneMinimalArtifactIndexTest + extends PlexusTestCase +{ + private RepositoryArtifactIndex index; + + private ArtifactRepository repository; + + private ArtifactFactory artifactFactory; + + private File indexLocation; + + private RepositoryIndexRecordFactory recordFactory; + + protected void setUp() + throws Exception + { + super.setUp(); + + recordFactory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "minimal" ); + + artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + + ArtifactRepositoryFactory repositoryFactory = + (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + + File file = getTestFile( "src/test/managed-repository" ); + repository = + repositoryFactory.createArtifactRepository( "test", file.toURI().toURL().toString(), layout, null, null ); + + RepositoryArtifactIndexFactory factory = + (RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" ); + + indexLocation = getTestFile( "target/test-index" ); + + FileUtils.deleteDirectory( indexLocation ); + + index = factory.createMinimalIndex( indexLocation ); + } + + public void testIndexExists() + throws IOException, RepositoryIndexException + { + assertFalse( "check index doesn't exist", index.exists() ); + + // create empty directory + indexLocation.mkdirs(); + assertFalse( "check index doesn't exist even if directory does", index.exists() ); + + // create index, with no records + createEmptyIndex(); + assertTrue( "check index is considered to exist", index.exists() ); + + // Test non-directory + FileUtils.deleteDirectory( indexLocation ); + indexLocation.createNewFile(); + try + { + index.exists(); + fail( "Index operation should fail as the location is not valid" ); + } + catch ( RepositoryIndexException e ) + { + // great + } + finally + { + indexLocation.delete(); + } + } + + public void testAddRecordNoIndex() + throws IOException, RepositoryIndexException + { + Artifact artifact = createArtifact( "test-jar" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + index.indexRecords( Collections.singletonList( record ) ); + + IndexReader reader = IndexReader.open( indexLocation ); + try + { + Document document = reader.document( 0 ); + assertEquals( "Check document", repository.pathOf( artifact ), + document.get( MinimalIndexRecordFields.FILENAME ) ); + assertEquals( "Check index size", 1, reader.numDocs() ); + } + finally + { + reader.close(); + } + } + + public void testAddRecordExistingEmptyIndex() + throws IOException, RepositoryIndexException + { + createEmptyIndex(); + + Artifact artifact = createArtifact( "test-jar" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + index.indexRecords( Collections.singletonList( record ) ); + + IndexReader reader = IndexReader.open( indexLocation ); + try + { + Document document = reader.document( 0 ); + assertRecord( document, artifact, "3a0adc365f849366cd8b633cad155cb7", "A\nb.B\nb.c.C" ); + assertEquals( "Check index size", 1, reader.numDocs() ); + } + finally + { + reader.close(); + } + } + + public void testAddRecordInIndex() + throws IOException, RepositoryIndexException + { + createEmptyIndex(); + + Artifact artifact = createArtifact( "test-jar" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + index.indexRecords( Collections.singletonList( record ) ); + + // Do it again + record = recordFactory.createRecord( artifact ); + index.indexRecords( Collections.singletonList( record ) ); + + IndexReader reader = IndexReader.open( indexLocation ); + try + { + Document document = reader.document( 0 ); + assertRecord( document, artifact, "3a0adc365f849366cd8b633cad155cb7", "A\nb.B\nb.c.C" ); + assertEquals( "Check index size", 1, reader.numDocs() ); + } + finally + { + reader.close(); + } + } + + public void testDeleteRecordInIndex() + throws IOException, RepositoryIndexException + { + createEmptyIndex(); + + Artifact artifact = createArtifact( "test-jar" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + index.indexRecords( Collections.singletonList( record ) ); + + index.deleteRecords( Collections.singletonList( record ) ); + + IndexReader reader = IndexReader.open( indexLocation ); + try + { + assertEquals( "No documents", 0, reader.numDocs() ); + } + finally + { + reader.close(); + } + } + + public void testDeleteRecordNotInIndex() + throws IOException, RepositoryIndexException + { + createEmptyIndex(); + + Artifact artifact = createArtifact( "test-jar" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + + index.deleteRecords( Collections.singletonList( record ) ); + + IndexReader reader = IndexReader.open( indexLocation ); + try + { + assertEquals( "No documents", 0, reader.numDocs() ); + } + finally + { + reader.close(); + } + } + + public void testDeleteRecordNoIndex() + throws IOException, RepositoryIndexException + { + Artifact artifact = createArtifact( "test-jar" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + index.deleteRecords( Collections.singleton( record ) ); + + assertFalse( index.exists() ); + } + + public void testAddPomRecord() + throws IOException, RepositoryIndexException + { + createEmptyIndex(); + + Artifact artifact = createArtifact( "test-pom", "1.0", "pom" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + index.indexRecords( Collections.singletonList( record ) ); + + IndexReader reader = IndexReader.open( indexLocation ); + try + { + assertEquals( "No documents", 0, reader.numDocs() ); + } + finally + { + reader.close(); + } + } + + public void testAddPlugin() + throws IOException, RepositoryIndexException, XmlPullParserException + { + createEmptyIndex(); + + Artifact artifact = createArtifact( "test-plugin" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + + index.indexRecords( Collections.singletonList( record ) ); + + IndexReader reader = IndexReader.open( indexLocation ); + try + { + Document document = reader.document( 0 ); + assertRecord( document, artifact, "06f6fe25e46c4d4fb5be4f56a9bab0ee", + "org.apache.maven.repository.record.MyMojo" ); + assertEquals( "Check index size", 1, reader.numDocs() ); + } + finally + { + reader.close(); + } + } + + private Artifact createArtifact( String artifactId ) + { + return createArtifact( artifactId, "1.0", "jar" ); + } + + private Artifact createArtifact( String artifactId, String version, String type ) + { + Artifact artifact = + artifactFactory.createBuildArtifact( "org.apache.maven.repository.record", artifactId, version, type ); + artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); + artifact.setRepository( repository ); + return artifact; + } + + private void createEmptyIndex() + throws IOException + { + createIndex( Collections.EMPTY_LIST ); + } + + private void createIndex( List docments ) + throws IOException + { + IndexWriter writer = new IndexWriter( indexLocation, new StandardAnalyzer(), true ); + for ( Iterator i = docments.iterator(); i.hasNext(); ) + { + Document document = (Document) i.next(); + writer.addDocument( document ); + } + writer.optimize(); + writer.close(); + } + + private void assertRecord( Document document, Artifact artifact, String expectedChecksum, String expectedClasses ) + { + assertEquals( "Check document filename", repository.pathOf( artifact ), + document.get( MinimalIndexRecordFields.FILENAME ) ); + assertEquals( "Check document timestamp", getLastModified( artifact.getFile() ), + document.get( MinimalIndexRecordFields.LAST_MODIFIED ) ); + assertEquals( "Check document checksum", expectedChecksum, document.get( MinimalIndexRecordFields.MD5 ) ); + assertEquals( "Check document size", artifact.getFile().length(), + NumberTools.stringToLong( document.get( MinimalIndexRecordFields.FILE_SIZE ) ) ); + assertEquals( "Check document classes", expectedClasses, document.get( MinimalIndexRecordFields.CLASSES ) ); + } + + private String getLastModified( File file ) + { + SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyyMMddHHmmss", Locale.US ); + dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); + return dateFormat.format( new Date( file.lastModified() ) ); + } +} diff --git a/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexSearchTest.java b/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexSearchTest.java new file mode 100644 index 000000000..19ff16439 --- /dev/null +++ b/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexSearchTest.java @@ -0,0 +1,700 @@ +package org.apache.maven.repository.indexing.lucene; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.lucene.index.Term; +import org.apache.lucene.search.BooleanClause; +import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.search.MatchAllDocsQuery; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.TermQuery; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.repository.indexing.RepositoryArtifactIndex; +import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; +import org.apache.maven.repository.indexing.RepositoryIndexSearchException; +import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory; +import org.apache.maven.repository.indexing.record.StandardIndexRecordFields; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Test the Lucene implementation of the artifact index search. + * + * @author Brett Porter + * @todo would be nice to abstract some of the query away, but for now passing in a Lucene query directly is good enough + */ +public class LuceneStandardArtifactIndexSearchTest + extends PlexusTestCase +{ + private RepositoryArtifactIndex index; + + private ArtifactRepository repository; + + private ArtifactFactory artifactFactory; + + private File indexLocation; + + private RepositoryIndexRecordFactory recordFactory; + + private Map records = new HashMap(); + + protected void setUp() + throws Exception + { + super.setUp(); + + recordFactory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "standard" ); + + artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + + ArtifactRepositoryFactory repositoryFactory = + (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + + File file = getTestFile( "src/test/managed-repository" ); + repository = + repositoryFactory.createArtifactRepository( "test", file.toURI().toURL().toString(), layout, null, null ); + + RepositoryArtifactIndexFactory factory = + (RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" ); + + indexLocation = getTestFile( "target/test-index" ); + + FileUtils.deleteDirectory( indexLocation ); + + index = factory.createStandardIndex( indexLocation ); + + records.put( "test-jar", recordFactory.createRecord( createArtifact( "test-jar" ) ) ); + records.put( "test-jar-jdk14", + recordFactory.createRecord( createArtifact( "test-jar", "1.0", "jar", "jdk14" ) ) ); + records.put( "test-jar-and-pom", + recordFactory.createRecord( createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar" ) ) ); + records.put( "test-jar-and-pom-jdk14", recordFactory.createRecord( + createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar", "jdk14" ) ) ); + records.put( "test-child-pom", + recordFactory.createRecord( createArtifact( "test-child-pom", "1.0-20060728.121314-1", "jar" ) ) ); + records.put( "test-archetype", recordFactory.createRecord( createArtifact( "test-archetype" ) ) ); + records.put( "test-plugin", recordFactory.createRecord( createArtifact( "test-plugin" ) ) ); + records.put( "test-pom", recordFactory.createRecord( createArtifact( "test-pom", "1.0", "pom" ) ) ); + records.put( "parent-pom", recordFactory.createRecord( createArtifact( "parent-pom", "1", "pom" ) ) ); + records.put( "test-dll", recordFactory.createRecord( createArtifact( "test-dll", "1.0.1.34", "dll" ) ) ); + + index.indexRecords( records.values() ); + } + + public void testExactMatchVersion() + throws RepositoryIndexSearchException + { + Query query = new TermQuery( new Term( StandardIndexRecordFields.VERSION_EXACT, "1.0" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) ); + assertEquals( "Check results size", 5, results.size() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.VERSION_EXACT, "1.0-SNAPSHOT" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.VERSION_EXACT, "1.0-20060728.121314-1" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); + assertEquals( "Check results size", 1, results.size() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.VERSION_EXACT, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testExactMatchBaseVersion() + throws RepositoryIndexSearchException + { + Query query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION_EXACT, "1.0" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) ); + assertEquals( "Check results size", 5, results.size() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION_EXACT, "1.0-SNAPSHOT" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); + assertEquals( "Check results size", 1, results.size() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION_EXACT, "1.0-20060728.121314-1" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION_EXACT, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testExactMatchGroupId() + throws RepositoryIndexSearchException + { + Query query = + new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, "org.apache.maven.repository.record" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertEquals( "Check results size", 10, results.size() ); + + // test partial match fails + query = new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, "org.apache.maven" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testExactMatchArtifactId() + throws RepositoryIndexSearchException + { + Query query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID_EXACT, "test-jar" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); + assertEquals( "Check results size", 2, results.size() ); + + // test partial match fails + query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID_EXACT, "test" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID_EXACT, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testExactMatchType() + throws RepositoryIndexSearchException + { + Query query = new TermQuery( new Term( StandardIndexRecordFields.TYPE, "maven-plugin" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); + assertEquals( "Check results size", 1, results.size() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.TYPE, "jar" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); + assertEquals( "Check results size", 5, results.size() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.TYPE, "dll" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-dll" ) ) ); + assertEquals( "Check results size", 1, results.size() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.TYPE, "maven-archetype" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) ); + assertEquals( "Check results size", 1, results.size() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.TYPE, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testExactMatchPackaging() + throws RepositoryIndexSearchException + { + Query query = new TermQuery( new Term( StandardIndexRecordFields.PACKAGING, "maven-plugin" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); + assertEquals( "Check results size", 1, results.size() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.PACKAGING, "jar" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); + assertEquals( "Check results size", 4, results.size() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.PACKAGING, "dll" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.PACKAGING, "maven-archetype" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.PACKAGING, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testExactMatchPluginPrefix() + throws RepositoryIndexSearchException + { + Query query = new TermQuery( new Term( StandardIndexRecordFields.PLUGIN_PREFIX, "test" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); + assertEquals( "Check results size", 1, results.size() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.PLUGIN_PREFIX, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testExactMatchRepository() + throws RepositoryIndexSearchException + { + Query query = new TermQuery( new Term( StandardIndexRecordFields.REPOSITORY, "test" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertEquals( "Check results size", 10, results.size() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.REPOSITORY, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testExactMatchMd5() + throws RepositoryIndexSearchException + { + Query query = new TermQuery( new Term( StandardIndexRecordFields.MD5, "3a0adc365f849366cd8b633cad155cb7" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); + assertEquals( "Check results size", 5, results.size() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.MD5, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testExactMatchSha1() + throws RepositoryIndexSearchException + { + Query query = + new TermQuery( new Term( StandardIndexRecordFields.SHA1, "c66f18bf192cb613fc2febb4da541a34133eedc2" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); + assertEquals( "Check results size", 5, results.size() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.SHA1, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testExactMatchInceptionYear() + throws RepositoryIndexSearchException + { + Query query = new TermQuery( new Term( StandardIndexRecordFields.INCEPTION_YEAR, "2005" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "parent-pom" ) ) ); + assertEquals( "Check results size", 3, results.size() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.INCEPTION_YEAR, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testMatchFilename() + throws RepositoryIndexSearchException + { + Query query = new TermQuery( new Term( StandardIndexRecordFields.FILENAME, "maven" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertEquals( "Check results size", 10, results.size() ); + +/* TODO: if this is a result we want, we need to change the analyzer. Currently, it is tokenizing it as plugin-1.0 and plugin/1.0 in the path + query = new TermQuery( new Term( StandardIndexRecordFields.FILENAME, "plugin" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); + assertEquals( "Check results size", 1, results.size() ); +*/ + query = new TermQuery( new Term( StandardIndexRecordFields.FILENAME, "test" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) ); + assertEquals( "Check results size", 9, results.size() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.FILENAME, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testMatchGroupId() + throws RepositoryIndexSearchException + { + Query query = + new TermQuery( new Term( StandardIndexRecordFields.GROUPID, "org.apache.maven.repository.record" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertEquals( "Check results size", 10, results.size() ); + +/* TODO: if we want this result, must change the analyzer to split on '.' + query = new TermQuery( new Term( StandardIndexRecordFields.GROUPID, "maven" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertEquals( "Check results size", 10, results.size() ); +*/ + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.GROUPID, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testMatchArtifactId() + throws RepositoryIndexSearchException + { + Query query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID, "plugin" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); + assertEquals( "Check results size", 1, results.size() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID, "test" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) ); + assertEquals( "Check results size", 9, results.size() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID, "maven" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testMatchVersion() + throws RepositoryIndexSearchException + { + // If partial matches are desired, need to change the analyzer for versions to split on '.' + Query query = new TermQuery( new Term( StandardIndexRecordFields.VERSION, "1" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "parent-pom" ) ) ); + assertEquals( "Check results size", 1, results.size() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.VERSION, "1.0" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) ); + assertEquals( "Check results size", 5, results.size() ); + +/* TODO: need to change analyzer to split on - if we want this + query = new TermQuery( new Term( StandardIndexRecordFields.VERSION, "snapshot" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.VERSION, "alpha" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); + assertEquals( "Check results size", 2, results.size() ); +*/ + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.VERSION, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testMatchBaseVersion() + throws RepositoryIndexSearchException + { + // If partial matches are desired, need to change the analyzer for versions to split on '.' + Query query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION, "1" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "parent-pom" ) ) ); + assertEquals( "Check results size", 1, results.size() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION, "1.0" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) ); + assertEquals( "Check results size", 5, results.size() ); + +/* TODO: need to change analyzer to split on - if we want this + query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION, "snapshot" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); + assertEquals( "Check results size", 1, results.size() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION, "alpha" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); + assertEquals( "Check results size", 2, results.size() ); +*/ + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testMatchClassifier() + throws RepositoryIndexSearchException + { + BooleanQuery bQuery = new BooleanQuery(); + bQuery.add( new MatchAllDocsQuery(), BooleanClause.Occur.MUST ); + bQuery.add( new TermQuery( new Term( StandardIndexRecordFields.CLASSIFIER, "jdk14" ) ), + BooleanClause.Occur.MUST_NOT ); + List results = index.search( new LuceneQuery( bQuery ) ); + + assertFalse( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); + assertFalse( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); + assertEquals( "Check results size", 8, results.size() ); + + // TODO: can we search for "anything with no classifier" ? + + Query query = new TermQuery( new Term( StandardIndexRecordFields.CLASSIFIER, "jdk14" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); + assertEquals( "Check results size", 2, results.size() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.CLASSIFIER, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testMatchClass() + throws RepositoryIndexSearchException + { + // TODO: should be preserving case! + Query query = new TermQuery( new Term( StandardIndexRecordFields.CLASSES, "b.c.c" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); + assertEquals( "Check results size", 5, results.size() ); + +/* TODO!: need to change the analyzer if we want partial classes (split on '.') + query = new TermQuery( new Term( StandardIndexRecordFields.CLASSES, "C" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); + assertEquals( "Check results size", 4, results.size() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.CLASSES, "MyMojo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); + assertEquals( "Check results size", 1, results.size() ); +*/ + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.CLASSES, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testMatchFiles() + throws RepositoryIndexSearchException + { + // TODO: should be preserving case! + Query query = new TermQuery( new Term( StandardIndexRecordFields.FILES, "manifest.mf" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertFalse( "Check result", results.contains( records.get( "test-pom" ) ) ); + assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) ); + assertFalse( "Check result", results.contains( records.get( "test-dll" ) ) ); + assertEquals( "Check results size", 7, results.size() ); + +/* + // TODO: should be preserving case, and '-inf'! + query = new TermQuery( new Term( StandardIndexRecordFields.FILES, "meta-inf" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertFalse( "Check result", results.contains( records.get( "test-pom" ) ) ); + assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) ); + assertFalse( "Check result", results.contains( records.get( "test-dll" ) ) ); + assertEquals( "Check results size", 7, results.size() ); +*/ + + query = new TermQuery( new Term( StandardIndexRecordFields.FILES, "plugin.xml" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); + assertEquals( "Check results size", 1, results.size() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.FILES, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testMatchProjectName() + throws RepositoryIndexSearchException + { + Query query = new TermQuery( new Term( StandardIndexRecordFields.PROJECT_NAME, "mojo" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); + assertEquals( "Check results size", 1, results.size() ); + + query = new TermQuery( new Term( StandardIndexRecordFields.PROJECT_NAME, "maven" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) ); + assertFalse( "Check result", results.contains( records.get( "test-child-pom" ) ) ); + assertEquals( "Check results size", 2, results.size() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.PROJECT_NAME, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + public void testMatchProjectDescription() + throws RepositoryIndexSearchException + { + Query query = new TermQuery( new Term( StandardIndexRecordFields.PROJECT_DESCRIPTION, "description" ) ); + List results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "parent-pom" ) ) ); + assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) ); + assertEquals( "Check results size", 3, results.size() ); + + // test non-match fails + query = new TermQuery( new Term( StandardIndexRecordFields.PROJECT_DESCRIPTION, "foo" ) ); + results = index.search( new LuceneQuery( query ) ); + + assertTrue( "Check results size", results.isEmpty() ); + } + + private Artifact createArtifact( String artifactId ) + { + return createArtifact( artifactId, "1.0", "jar", null ); + } + + private Artifact createArtifact( String artifactId, String version, String type ) + { + return createArtifact( artifactId, version, type, null ); + } + + private Artifact createArtifact( String artifactId, String version, String type, String classifier ) + { + Artifact artifact = artifactFactory.createDependencyArtifact( "org.apache.maven.repository.record", artifactId, + VersionRange.createFromVersion( version ), type, + classifier, Artifact.SCOPE_RUNTIME ); + artifact.isSnapshot(); + artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); + artifact.setRepository( repository ); + return artifact; + } +} diff --git a/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java b/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java new file mode 100644 index 000000000..4329dc452 --- /dev/null +++ b/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java @@ -0,0 +1,408 @@ +package org.apache.maven.repository.indexing.lucene; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.NumberTools; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriter; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.repository.indexing.RepositoryArtifactIndex; +import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; +import org.apache.maven.repository.indexing.RepositoryIndexException; +import org.apache.maven.repository.indexing.record.RepositoryIndexRecord; +import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory; +import org.apache.maven.repository.indexing.record.StandardIndexRecordFields; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.TimeZone; + +/** + * Test the Lucene implementation of the artifact index. + * + * @author Brett Porter + */ +public class LuceneStandardArtifactIndexTest + extends PlexusTestCase +{ + private RepositoryArtifactIndex index; + + private ArtifactRepository repository; + + private ArtifactFactory artifactFactory; + + private File indexLocation; + + private RepositoryIndexRecordFactory recordFactory; + + protected void setUp() + throws Exception + { + super.setUp(); + + recordFactory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "standard" ); + + artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + + ArtifactRepositoryFactory repositoryFactory = + (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + + File file = getTestFile( "src/test/managed-repository" ); + repository = + repositoryFactory.createArtifactRepository( "test", file.toURI().toURL().toString(), layout, null, null ); + + RepositoryArtifactIndexFactory factory = + (RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" ); + + indexLocation = getTestFile( "target/test-index" ); + + FileUtils.deleteDirectory( indexLocation ); + + index = factory.createStandardIndex( indexLocation ); + } + + public void testIndexExists() + throws IOException, RepositoryIndexException + { + assertFalse( "check index doesn't exist", index.exists() ); + + // create empty directory + indexLocation.mkdirs(); + assertFalse( "check index doesn't exist even if directory does", index.exists() ); + + // create index, with no records + createEmptyIndex(); + assertTrue( "check index is considered to exist", index.exists() ); + + // Test non-directory + FileUtils.deleteDirectory( indexLocation ); + indexLocation.createNewFile(); + try + { + index.exists(); + fail( "Index operation should fail as the location is not valid" ); + } + catch ( RepositoryIndexException e ) + { + // great + } + finally + { + indexLocation.delete(); + } + } + + public void testAddRecordNoIndex() + throws IOException, RepositoryIndexException + { + Artifact artifact = createArtifact( "test-jar" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + index.indexRecords( Collections.singletonList( record ) ); + + IndexReader reader = IndexReader.open( indexLocation ); + try + { + Document document = reader.document( 0 ); + assertJarRecord( artifact, document ); + assertEquals( "Check index size", 1, reader.numDocs() ); + } + finally + { + reader.close(); + } + } + + public void testAddRecordExistingEmptyIndex() + throws IOException, RepositoryIndexException + { + createEmptyIndex(); + + Artifact artifact = createArtifact( "test-jar" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + index.indexRecords( Collections.singletonList( record ) ); + + IndexReader reader = IndexReader.open( indexLocation ); + try + { + Document document = reader.document( 0 ); + assertJarRecord( artifact, document ); + assertEquals( "Check index size", 1, reader.numDocs() ); + } + finally + { + reader.close(); + } + } + + public void testAddRecordInIndex() + throws IOException, RepositoryIndexException + { + createEmptyIndex(); + + Artifact artifact = createArtifact( "test-jar" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + index.indexRecords( Collections.singletonList( record ) ); + + // Do it again + record = recordFactory.createRecord( artifact ); + index.indexRecords( Collections.singletonList( record ) ); + + IndexReader reader = IndexReader.open( indexLocation ); + try + { + Document document = reader.document( 0 ); + assertJarRecord( artifact, document ); + assertEquals( "Check index size", 1, reader.numDocs() ); + } + finally + { + reader.close(); + } + } + + public void testAddPomRecord() + throws IOException, RepositoryIndexException + { + createEmptyIndex(); + + Artifact artifact = createArtifact( "test-pom", "1.0", "pom" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + index.indexRecords( Collections.singletonList( record ) ); + + IndexReader reader = IndexReader.open( indexLocation ); + try + { + Document document = reader.document( 0 ); + assertPomRecord( artifact, document ); + assertEquals( "Check index size", 1, reader.numDocs() ); + } + finally + { + reader.close(); + } + } + + public void testAddPlugin() + throws IOException, RepositoryIndexException, XmlPullParserException + { + createEmptyIndex(); + + Artifact artifact = createArtifact( "test-plugin" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + + index.indexRecords( Collections.singletonList( record ) ); + + IndexReader reader = IndexReader.open( indexLocation ); + try + { + Document document = reader.document( 0 ); + assertPluginRecord( artifact, document ); + assertEquals( "Check index size", 1, reader.numDocs() ); + } + finally + { + reader.close(); + } + } + + public void testDeleteRecordInIndex() + throws IOException, RepositoryIndexException + { + createEmptyIndex(); + + Artifact artifact = createArtifact( "test-jar" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + index.indexRecords( Collections.singletonList( record ) ); + + index.deleteRecords( Collections.singletonList( record ) ); + + IndexReader reader = IndexReader.open( indexLocation ); + try + { + assertEquals( "No documents", 0, reader.numDocs() ); + } + finally + { + reader.close(); + } + } + + public void testDeleteRecordNotInIndex() + throws IOException, RepositoryIndexException + { + createEmptyIndex(); + + Artifact artifact = createArtifact( "test-jar" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + + index.deleteRecords( Collections.singletonList( record ) ); + + IndexReader reader = IndexReader.open( indexLocation ); + try + { + assertEquals( "No documents", 0, reader.numDocs() ); + } + finally + { + reader.close(); + } + } + + public void testDeleteRecordNoIndex() + throws IOException, RepositoryIndexException + { + Artifact artifact = createArtifact( "test-jar" ); + + RepositoryIndexRecord record = recordFactory.createRecord( artifact ); + index.deleteRecords( Collections.singleton( record ) ); + + assertFalse( index.exists() ); + } + + private Artifact createArtifact( String artifactId ) + { + return createArtifact( artifactId, "1.0", "jar" ); + } + + private Artifact createArtifact( String artifactId, String version, String type ) + { + Artifact artifact = + artifactFactory.createBuildArtifact( "org.apache.maven.repository.record", artifactId, version, type ); + artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); + artifact.setRepository( repository ); + return artifact; + } + + private void createEmptyIndex() + throws IOException + { + createIndex( Collections.EMPTY_LIST ); + } + + private void createIndex( List docments ) + throws IOException + { + IndexWriter writer = new IndexWriter( indexLocation, new StandardAnalyzer(), true ); + for ( Iterator i = docments.iterator(); i.hasNext(); ) + { + Document document = (Document) i.next(); + writer.addDocument( document ); + } + writer.optimize(); + writer.close(); + } + + private void assertRecord( Artifact artifact, Document document, String expectedArtifactId, String expectedType, + String expectedMd5, String expectedSha1 ) + { + assertEquals( "Check document filename", repository.pathOf( artifact ), + document.get( StandardIndexRecordFields.FILENAME ) ); + assertEquals( "Check document groupId", "org.apache.maven.repository.record", + document.get( StandardIndexRecordFields.GROUPID ) ); + assertEquals( "Check document artifactId", expectedArtifactId, + document.get( StandardIndexRecordFields.ARTIFACTID ) ); + assertEquals( "Check document version", "1.0", document.get( StandardIndexRecordFields.VERSION ) ); + assertEquals( "Check document type", expectedType, document.get( StandardIndexRecordFields.TYPE ) ); + assertEquals( "Check document repository", "test", document.get( StandardIndexRecordFields.REPOSITORY ) ); + assertEquals( "Check document timestamp", getLastModified( artifact.getFile() ), + document.get( StandardIndexRecordFields.LAST_MODIFIED ) ); + assertEquals( "Check document md5", expectedMd5, document.get( StandardIndexRecordFields.MD5 ) ); + assertEquals( "Check document sha1", expectedSha1, document.get( StandardIndexRecordFields.SHA1 ) ); + assertEquals( "Check document file size", artifact.getFile().length(), + NumberTools.stringToLong( document.get( StandardIndexRecordFields.FILE_SIZE ) ) ); + assertNull( "Check document classifier", document.get( StandardIndexRecordFields.CLASSIFIER ) ); + } + + private void assertPomRecord( Artifact artifact, Document document ) + { + assertRecord( artifact, document, "test-pom", "pom", "32dbef7ff11eb933bd8b7e7bcab85406", + "c3b374e394607e1e705e71c227f62641e8621ebe" ); + assertNull( "Check document classes", document.get( StandardIndexRecordFields.CLASSES ) ); + assertNull( "Check document files", document.get( StandardIndexRecordFields.FILES ) ); + assertNull( "Check document pluginPrefix", document.get( StandardIndexRecordFields.PLUGIN_PREFIX ) ); + assertEquals( "Check document year", "2005", document.get( StandardIndexRecordFields.INCEPTION_YEAR ) ); + assertEquals( "Check document project name", "Maven Repository Manager Test POM", + document.get( StandardIndexRecordFields.PROJECT_NAME ) ); + assertEquals( "Check document project description", "Description", + document.get( StandardIndexRecordFields.PROJECT_DESCRIPTION ) ); + assertEquals( "Check document packaging", "pom", document.get( StandardIndexRecordFields.PACKAGING ) ); + } + + private void assertJarRecord( Artifact artifact, Document document ) + { + assertRecord( artifact, document, "test-jar", "jar", "3a0adc365f849366cd8b633cad155cb7", + "c66f18bf192cb613fc2febb4da541a34133eedc2" ); + assertEquals( "Check document classes", "A\nb.B\nb.c.C", document.get( StandardIndexRecordFields.CLASSES ) ); + assertEquals( "Check document files", "META-INF/MANIFEST.MF\nA.class\nb/B.class\nb/c/C.class", + document.get( StandardIndexRecordFields.FILES ) ); + assertNull( "Check document inceptionYear", document.get( StandardIndexRecordFields.INCEPTION_YEAR ) ); + assertNull( "Check document projectName", document.get( StandardIndexRecordFields.PROJECT_NAME ) ); + assertNull( "Check document projectDesc", document.get( StandardIndexRecordFields.PROJECT_DESCRIPTION ) ); + assertNull( "Check document pluginPrefix", document.get( StandardIndexRecordFields.PLUGIN_PREFIX ) ); + assertNull( "Check document packaging", document.get( StandardIndexRecordFields.PACKAGING ) ); + } + + private void assertPluginRecord( Artifact artifact, Document document ) + { + assertRecord( artifact, document, "test-plugin", "maven-plugin", "06f6fe25e46c4d4fb5be4f56a9bab0ee", + "382c1ebfb5d0c7d6061c2f8569fb53f8fc00fec2" ); + assertEquals( "Check document classes", "org.apache.maven.repository.record.MyMojo", + document.get( StandardIndexRecordFields.CLASSES ) ); + assertEquals( "Check document files", "META-INF/MANIFEST.MF\n" + "META-INF/maven/plugin.xml\n" + + "org/apache/maven/repository/record/MyMojo.class\n" + + "META-INF/maven/org.apache.maven.repository.record/test-plugin/pom.xml\n" + + "META-INF/maven/org.apache.maven.repository.record/test-plugin/pom.properties", + document.get( StandardIndexRecordFields.FILES ) ); + assertEquals( "Check document pluginPrefix", "test", document.get( StandardIndexRecordFields.PLUGIN_PREFIX ) ); + assertEquals( "Check document packaging", "maven-plugin", document.get( StandardIndexRecordFields.PACKAGING ) ); + assertNull( "Check document inceptionYear", document.get( StandardIndexRecordFields.INCEPTION_YEAR ) ); + assertEquals( "Check document project name", "Maven Mojo Archetype", + document.get( StandardIndexRecordFields.PROJECT_NAME ) ); + assertNull( "Check document projectDesc", document.get( StandardIndexRecordFields.PROJECT_DESCRIPTION ) ); + } + + private String getLastModified( File file ) + { + SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyyMMddHHmmss", Locale.US ); + dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); + return dateFormat.format( new Date( file.lastModified() ) ); + } +} diff --git a/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java b/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java new file mode 100644 index 000000000..17364046f --- /dev/null +++ b/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java @@ -0,0 +1,156 @@ +package org.apache.maven.repository.indexing.query; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 junit.framework.TestCase; + +import java.util.Iterator; + +/** + * @author Brett Porter + */ +public class QueryTest + extends TestCase +{ + private QueryTerm term1 = new QueryTerm( "field1", "value1" ); + + private QueryTerm term2 = new QueryTerm( "field2", "value2" ); + + private QueryTerm term3 = new QueryTerm( "field3", "value3" ); + + public void testQueryTerm() + { + QueryTerm query = new QueryTerm( "Field", "Value" ); + assertEquals( "check field setting", "Field", query.getField() ); + assertEquals( "check value setting", "Value", query.getValue() ); + } + + public void testSingleTermQuery() + { + SingleTermQuery query = new SingleTermQuery( "Field", "Value" ); + assertEquals( "check field setting", "Field", query.getField() ); + assertEquals( "check value setting", "Value", query.getValue() ); + + query = new SingleTermQuery( term1 ); + assertEquals( "check field setting", "field1", query.getField() ); + assertEquals( "check value setting", "value1", query.getValue() ); + } + + public void testRangeQueryOpen() + { + RangeQuery rangeQuery = RangeQuery.createOpenRange(); + assertNull( "Check range has no start", rangeQuery.getBegin() ); + assertNull( "Check range has no end", rangeQuery.getEnd() ); + } + + public void testRangeQueryExclusive() + { + RangeQuery rangeQuery = RangeQuery.createExclusiveRange( term1, term2 ); + assertEquals( "Check range start", term1, rangeQuery.getBegin() ); + assertEquals( "Check range end", term2, rangeQuery.getEnd() ); + assertFalse( "Check exclusive", rangeQuery.isInclusive() ); + } + + public void testRangeQueryInclusive() + { + RangeQuery rangeQuery = RangeQuery.createInclusiveRange( term1, term2 ); + assertEquals( "Check range start", term1, rangeQuery.getBegin() ); + assertEquals( "Check range end", term2, rangeQuery.getEnd() ); + assertTrue( "Check inclusive", rangeQuery.isInclusive() ); + } + + public void testRangeQueryOpenEnded() + { + RangeQuery rangeQuery = RangeQuery.createGreaterThanOrEqualToRange( term1 ); + assertEquals( "Check range start", term1, rangeQuery.getBegin() ); + assertNull( "Check range end", rangeQuery.getEnd() ); + assertTrue( "Check inclusive", rangeQuery.isInclusive() ); + + rangeQuery = RangeQuery.createGreaterThanRange( term1 ); + assertEquals( "Check range start", term1, rangeQuery.getBegin() ); + assertNull( "Check range end", rangeQuery.getEnd() ); + assertFalse( "Check exclusive", rangeQuery.isInclusive() ); + + rangeQuery = RangeQuery.createLessThanOrEqualToRange( term1 ); + assertNull( "Check range start", rangeQuery.getBegin() ); + assertEquals( "Check range end", term1, rangeQuery.getEnd() ); + assertTrue( "Check inclusive", rangeQuery.isInclusive() ); + + rangeQuery = RangeQuery.createLessThanRange( term1 ); + assertNull( "Check range start", rangeQuery.getBegin() ); + assertEquals( "Check range end", term1, rangeQuery.getEnd() ); + assertFalse( "Check exclusive", rangeQuery.isInclusive() ); + } + + public void testCompundQuery() + { + CompoundQuery query = new CompoundQuery(); + assertTrue( "check query is empty", query.getCompoundQueryTerms().isEmpty() ); + + query.and( term1 ); + query.or( term2 ); + query.not( term3 ); + + Iterator i = query.getCompoundQueryTerms().iterator(); + CompoundQueryTerm term = (CompoundQueryTerm) i.next(); + assertEquals( "Check first term", "field1", getQuery( term ).getField() ); + assertEquals( "Check first term", "value1", getQuery( term ).getValue() ); + assertTrue( "Check first term", term.isRequired() ); + assertFalse( "Check first term", term.isProhibited() ); + + term = (CompoundQueryTerm) i.next(); + assertEquals( "Check second term", "field2", getQuery( term ).getField() ); + assertEquals( "Check second term", "value2", getQuery( term ).getValue() ); + assertFalse( "Check second term", term.isRequired() ); + assertFalse( "Check second term", term.isProhibited() ); + + term = (CompoundQueryTerm) i.next(); + assertEquals( "Check third term", "field3", getQuery( term ).getField() ); + assertEquals( "Check third term", "value3", getQuery( term ).getValue() ); + assertFalse( "Check third term", term.isRequired() ); + assertTrue( "Check third term", term.isProhibited() ); + + CompoundQuery query2 = new CompoundQuery(); + query2.and( query ); + query2.or( new SingleTermQuery( term2 ) ); + query2.not( new SingleTermQuery( term3 ) ); + + i = query2.getCompoundQueryTerms().iterator(); + term = (CompoundQueryTerm) i.next(); + assertEquals( "Check first term", query, term.getQuery() ); + assertTrue( "Check first term", term.isRequired() ); + assertFalse( "Check first term", term.isProhibited() ); + + term = (CompoundQueryTerm) i.next(); + assertEquals( "Check second term", "field2", getQuery( term ).getField() ); + assertEquals( "Check second term", "value2", getQuery( term ).getValue() ); + assertFalse( "Check second term", term.isRequired() ); + assertFalse( "Check second term", term.isProhibited() ); + + term = (CompoundQueryTerm) i.next(); + assertEquals( "Check third term", "field3", getQuery( term ).getField() ); + assertEquals( "Check third term", "value3", getQuery( term ).getValue() ); + assertFalse( "Check third term", term.isRequired() ); + assertTrue( "Check third term", term.isProhibited() ); + } + + private static SingleTermQuery getQuery( CompoundQueryTerm term ) + { + return (SingleTermQuery) term.getQuery(); + } +} + diff --git a/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactoryTest.java b/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactoryTest.java new file mode 100644 index 000000000..32d97b329 --- /dev/null +++ b/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactoryTest.java @@ -0,0 +1,240 @@ +package org.apache.maven.repository.indexing.record; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.repository.indexing.RepositoryIndexException; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * Test the minimal artifact index record. + * + * @author Brett Porter + */ +public class MinimalArtifactIndexRecordFactoryTest + extends PlexusTestCase +{ + private RepositoryIndexRecordFactory factory; + + private ArtifactRepository repository; + + private ArtifactFactory artifactFactory; + + private static final String TEST_GROUP_ID = "org.apache.maven.repository.record"; + + private static final List JAR_CLASS_LIST = Arrays.asList( new String[]{"A", "b.B", "b.c.C"} ); + + protected void setUp() + throws Exception + { + super.setUp(); + + factory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "minimal" ); + + artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + + ArtifactRepositoryFactory repositoryFactory = + (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + + File file = getTestFile( "src/test/managed-repository" ); + repository = + repositoryFactory.createArtifactRepository( "test", file.toURI().toURL().toString(), layout, null, null ); + } + + public void testIndexedJar() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-jar" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + MinimalArtifactIndexRecord expectedRecord = new MinimalArtifactIndexRecord(); + expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); + expectedRecord.setFilename( repository.pathOf( artifact ) ); + expectedRecord.setLastModified( artifact.getFile().lastModified() ); + expectedRecord.setSize( artifact.getFile().length() ); + expectedRecord.setClasses( JAR_CLASS_LIST ); + + assertEquals( "check record", expectedRecord, record ); + } + + public void testIndexedJarWithClassifier() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-jar", "1.0", "jar", "jdk14" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + MinimalArtifactIndexRecord expectedRecord = new MinimalArtifactIndexRecord(); + expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); + expectedRecord.setFilename( repository.pathOf( artifact ) ); + expectedRecord.setLastModified( artifact.getFile().lastModified() ); + expectedRecord.setSize( artifact.getFile().length() ); + expectedRecord.setClasses( JAR_CLASS_LIST ); + + assertEquals( "check record", expectedRecord, record ); + } + + public void testIndexedJarAndPom() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + MinimalArtifactIndexRecord expectedRecord = new MinimalArtifactIndexRecord(); + expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); + expectedRecord.setFilename( repository.pathOf( artifact ) ); + expectedRecord.setLastModified( artifact.getFile().lastModified() ); + expectedRecord.setSize( artifact.getFile().length() ); + expectedRecord.setClasses( JAR_CLASS_LIST ); + + assertEquals( "check record", expectedRecord, record ); + } + + public void testIndexedJarAndPomWithClassifier() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar", "jdk14" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + MinimalArtifactIndexRecord expectedRecord = new MinimalArtifactIndexRecord(); + expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); + expectedRecord.setFilename( repository.pathOf( artifact ) ); + expectedRecord.setLastModified( artifact.getFile().lastModified() ); + expectedRecord.setSize( artifact.getFile().length() ); + expectedRecord.setClasses( JAR_CLASS_LIST ); + + assertEquals( "check record", expectedRecord, record ); + } + + public void testIndexedPom() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-pom", "1.0", "pom" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + assertNull( "Check no record", record ); + } + + public void testNonIndexedPom() + throws RepositoryIndexException + { + // If we pass in only the POM that belongs to a JAR, then expect null not the POM + Artifact artifact = createArtifact( "test-jar-and-pom", "1.0-alpha-1", "pom" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + assertNull( "Check no record", record ); + + artifact = createArtifact( "test-plugin", "1.0", "pom" ); + + record = factory.createRecord( artifact ); + + assertNull( "Check no record", record ); + + artifact = createArtifact( "test-archetype", "1.0", "pom" ); + + record = factory.createRecord( artifact ); + + assertNull( "Check no record", record ); + } + + public void testIndexedPlugin() + throws RepositoryIndexException, IOException, XmlPullParserException + { + Artifact artifact = createArtifact( "test-plugin" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + MinimalArtifactIndexRecord expectedRecord = new MinimalArtifactIndexRecord(); + expectedRecord.setMd5Checksum( "06f6fe25e46c4d4fb5be4f56a9bab0ee" ); + expectedRecord.setFilename( repository.pathOf( artifact ) ); + expectedRecord.setLastModified( artifact.getFile().lastModified() ); + expectedRecord.setSize( artifact.getFile().length() ); + expectedRecord.setClasses( Collections.singletonList( "org.apache.maven.repository.record.MyMojo" ) ); + + assertEquals( "check record", expectedRecord, record ); + } + + public void testCorruptJar() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-corrupt-jar" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + assertNull( "Confirm no record is returned", record ); + } + + public void testNonJar() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-dll", "1.0.1.34", "dll" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + assertNull( "Confirm no record is returned", record ); + } + + public void testMissingFile() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-foo" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + assertNull( "Confirm no record is returned", record ); + } + + private Artifact createArtifact( String artifactId ) + { + return createArtifact( artifactId, "1.0", "jar" ); + } + + private Artifact createArtifact( String artifactId, String version, String type ) + { + return createArtifact( artifactId, version, type, null ); + } + + private Artifact createArtifact( String artifactId, String version, String type, String classifier ) + { + Artifact artifact = artifactFactory.createDependencyArtifact( TEST_GROUP_ID, artifactId, + VersionRange.createFromVersion( version ), type, + classifier, Artifact.SCOPE_RUNTIME ); + artifact.isSnapshot(); + artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); + artifact.setRepository( repository ); + return artifact; + } +} diff --git a/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java b/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java new file mode 100644 index 000000000..790c2bed4 --- /dev/null +++ b/archiva-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java @@ -0,0 +1,382 @@ +package org.apache.maven.repository.indexing.record; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.repository.indexing.RepositoryIndexException; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +/** + * Test the minimal artifact index record. + * + * @author Brett Porter + */ +public class StandardArtifactIndexRecordFactoryTest + extends PlexusTestCase +{ + private RepositoryIndexRecordFactory factory; + + private ArtifactRepository repository; + + private ArtifactFactory artifactFactory; + + private static final String TEST_GROUP_ID = "org.apache.maven.repository.record"; + + private static final List JAR_CLASS_LIST = Arrays.asList( new String[]{"A", "b.B", "b.c.C"} ); + + private static final List JAR_FILE_LIST = + Arrays.asList( new String[]{"META-INF/MANIFEST.MF", "A.class", "b/B.class", "b/c/C.class"} ); + + protected void setUp() + throws Exception + { + super.setUp(); + + factory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "standard" ); + + artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + + ArtifactRepositoryFactory repositoryFactory = + (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + + File file = getTestFile( "src/test/managed-repository" ); + repository = + repositoryFactory.createArtifactRepository( "test", file.toURI().toURL().toString(), layout, null, null ); + } + + public void testIndexedJar() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-jar" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); + expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); + expectedRecord.setFilename( repository.pathOf( artifact ) ); + expectedRecord.setLastModified( artifact.getFile().lastModified() ); + expectedRecord.setSize( artifact.getFile().length() ); + expectedRecord.setClasses( JAR_CLASS_LIST ); + expectedRecord.setArtifactId( "test-jar" ); + expectedRecord.setGroupId( TEST_GROUP_ID ); + expectedRecord.setBaseVersion( "1.0" ); + expectedRecord.setVersion( "1.0" ); + expectedRecord.setFiles( JAR_FILE_LIST ); + expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" ); + expectedRecord.setType( "jar" ); + expectedRecord.setRepository( "test" ); + + assertEquals( "check record", expectedRecord, record ); + } + + public void testIndexedJarWithClassifier() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-jar", "1.0", "jar", "jdk14" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); + expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); + expectedRecord.setFilename( repository.pathOf( artifact ) ); + expectedRecord.setLastModified( artifact.getFile().lastModified() ); + expectedRecord.setSize( artifact.getFile().length() ); + expectedRecord.setClasses( JAR_CLASS_LIST ); + expectedRecord.setArtifactId( "test-jar" ); + expectedRecord.setGroupId( TEST_GROUP_ID ); + expectedRecord.setBaseVersion( "1.0" ); + expectedRecord.setVersion( "1.0" ); + expectedRecord.setFiles( JAR_FILE_LIST ); + expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" ); + expectedRecord.setType( "jar" ); + expectedRecord.setRepository( "test" ); + expectedRecord.setClassifier( "jdk14" ); + + assertEquals( "check record", expectedRecord, record ); + } + + public void testIndexedJarAndPom() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); + expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); + expectedRecord.setFilename( repository.pathOf( artifact ) ); + expectedRecord.setLastModified( artifact.getFile().lastModified() ); + expectedRecord.setSize( artifact.getFile().length() ); + expectedRecord.setClasses( JAR_CLASS_LIST ); + expectedRecord.setArtifactId( "test-jar-and-pom" ); + expectedRecord.setGroupId( TEST_GROUP_ID ); + expectedRecord.setBaseVersion( "1.0-alpha-1" ); + expectedRecord.setVersion( "1.0-alpha-1" ); + expectedRecord.setFiles( JAR_FILE_LIST ); + expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" ); + expectedRecord.setType( "jar" ); + expectedRecord.setRepository( "test" ); + expectedRecord.setPackaging( "jar" ); + expectedRecord.setProjectName( "Test JAR and POM" ); + + assertEquals( "check record", expectedRecord, record ); + } + + public void testIndexedJarAndPomWithClassifier() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar", "jdk14" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); + expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); + expectedRecord.setFilename( repository.pathOf( artifact ) ); + expectedRecord.setLastModified( artifact.getFile().lastModified() ); + expectedRecord.setSize( artifact.getFile().length() ); + expectedRecord.setClasses( JAR_CLASS_LIST ); + expectedRecord.setArtifactId( "test-jar-and-pom" ); + expectedRecord.setGroupId( TEST_GROUP_ID ); + expectedRecord.setBaseVersion( "1.0-alpha-1" ); + expectedRecord.setVersion( "1.0-alpha-1" ); + expectedRecord.setFiles( JAR_FILE_LIST ); + expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" ); + expectedRecord.setType( "jar" ); + expectedRecord.setRepository( "test" ); + expectedRecord.setPackaging( "jar" ); + expectedRecord.setProjectName( "Test JAR and POM" ); + expectedRecord.setClassifier( "jdk14" ); + + assertEquals( "check record", expectedRecord, record ); + } + + public void testIndexedJarWithParentPom() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-child-pom", "1.0-20060728.121314-1", "jar" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); + expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); + expectedRecord.setFilename( repository.pathOf( artifact ) ); + expectedRecord.setLastModified( artifact.getFile().lastModified() ); + expectedRecord.setSize( artifact.getFile().length() ); + expectedRecord.setClasses( JAR_CLASS_LIST ); + expectedRecord.setArtifactId( "test-child-pom" ); + expectedRecord.setGroupId( TEST_GROUP_ID ); + expectedRecord.setBaseVersion( "1.0-SNAPSHOT" ); + expectedRecord.setVersion( "1.0-20060728.121314-1" ); + expectedRecord.setFiles( JAR_FILE_LIST ); + expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" ); + expectedRecord.setType( "jar" ); + expectedRecord.setRepository( "test" ); + expectedRecord.setPackaging( "jar" ); + expectedRecord.setProjectName( "Child Project" ); + expectedRecord.setProjectDescription( "Description" ); + expectedRecord.setInceptionYear( "2005" ); + + assertEquals( "check record", expectedRecord, record ); + } + + public void testIndexedPom() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-pom", "1.0", "pom" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); + expectedRecord.setMd5Checksum( "32dbef7ff11eb933bd8b7e7bcab85406" ); + expectedRecord.setFilename( repository.pathOf( artifact ) ); + expectedRecord.setLastModified( artifact.getFile().lastModified() ); + expectedRecord.setSize( artifact.getFile().length() ); + expectedRecord.setArtifactId( "test-pom" ); + expectedRecord.setGroupId( TEST_GROUP_ID ); + expectedRecord.setBaseVersion( "1.0" ); + expectedRecord.setVersion( "1.0" ); + expectedRecord.setSha1Checksum( "c3b374e394607e1e705e71c227f62641e8621ebe" ); + expectedRecord.setType( "pom" ); + expectedRecord.setRepository( "test" ); + expectedRecord.setPackaging( "pom" ); + expectedRecord.setInceptionYear( "2005" ); + expectedRecord.setProjectName( "Maven Repository Manager Test POM" ); + expectedRecord.setProjectDescription( "Description" ); + + assertEquals( "check record", expectedRecord, record ); + } + + public void testNonIndexedPom() + throws RepositoryIndexException + { + // If we pass in only the POM that belongs to a JAR, then expect null not the POM + Artifact artifact = createArtifact( "test-jar-and-pom", "1.0", "pom" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + assertNull( "Check no record", record ); + + artifact = createArtifact( "test-plugin", "1.0", "pom" ); + + record = factory.createRecord( artifact ); + + assertNull( "Check no record", record ); + + artifact = createArtifact( "test-archetype", "1.0", "pom" ); + + record = factory.createRecord( artifact ); + + assertNull( "Check no record", record ); + } + + public void testIndexedPlugin() + throws RepositoryIndexException, IOException, XmlPullParserException + { + Artifact artifact = createArtifact( "test-plugin" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); + expectedRecord.setMd5Checksum( "06f6fe25e46c4d4fb5be4f56a9bab0ee" ); + expectedRecord.setFilename( repository.pathOf( artifact ) ); + expectedRecord.setLastModified( artifact.getFile().lastModified() ); + expectedRecord.setSize( artifact.getFile().length() ); + expectedRecord.setArtifactId( "test-plugin" ); + expectedRecord.setGroupId( TEST_GROUP_ID ); + expectedRecord.setBaseVersion( "1.0" ); + expectedRecord.setVersion( "1.0" ); + expectedRecord.setSha1Checksum( "382c1ebfb5d0c7d6061c2f8569fb53f8fc00fec2" ); + expectedRecord.setType( "maven-plugin" ); + expectedRecord.setRepository( "test" ); + expectedRecord.setClasses( Arrays.asList( new String[]{"org.apache.maven.repository.record.MyMojo"} ) ); + expectedRecord.setFiles( Arrays.asList( new String[]{"META-INF/MANIFEST.MF", "META-INF/maven/plugin.xml", + "org/apache/maven/repository/record/MyMojo.class", + "META-INF/maven/org.apache.maven.repository.record/test-plugin/pom.xml", + "META-INF/maven/org.apache.maven.repository.record/test-plugin/pom.properties"} ) ); + expectedRecord.setPackaging( "maven-plugin" ); + expectedRecord.setProjectName( "Maven Mojo Archetype" ); + expectedRecord.setPluginPrefix( "test" ); + + assertEquals( "check record", expectedRecord, record ); + } + + public void testIndexedArchetype() + throws RepositoryIndexException, IOException, XmlPullParserException + { + Artifact artifact = createArtifact( "test-archetype" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); + expectedRecord.setMd5Checksum( "ecefd4674c75a175119572b19edc45f1" ); + expectedRecord.setFilename( repository.pathOf( artifact ) ); + expectedRecord.setLastModified( artifact.getFile().lastModified() ); + expectedRecord.setSize( artifact.getFile().length() ); + expectedRecord.setArtifactId( "test-archetype" ); + expectedRecord.setGroupId( TEST_GROUP_ID ); + expectedRecord.setBaseVersion( "1.0" ); + expectedRecord.setVersion( "1.0" ); + expectedRecord.setSha1Checksum( "5ebabafdbcd6684ae434c06e22c32844df284b05" ); + expectedRecord.setType( "maven-archetype" ); + expectedRecord.setRepository( "test" ); + expectedRecord.setFiles( Arrays.asList( new String[]{"META-INF/MANIFEST.MF", "archetype-resources/pom.xml", + "archetype-resources/src/main/java/App.java", "archetype-resources/src/test/java/AppTest.java", + "META-INF/maven/archetype.xml", "META-INF/maven/org.apache.maven.repository.record/test-archetype/pom.xml", + "META-INF/maven/org.apache.maven.repository.record/test-archetype/pom.properties"} ) ); + expectedRecord.setPackaging( "jar" ); + expectedRecord.setProjectName( "Archetype - test-archetype" ); + + assertEquals( "check record", expectedRecord, record ); + } + + public void testCorruptJar() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-corrupt-jar" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + assertNull( "Confirm no record is returned", record ); + } + + public void testDll() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-dll", "1.0.1.34", "dll" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); + expectedRecord.setMd5Checksum( "d41d8cd98f00b204e9800998ecf8427e" ); + expectedRecord.setFilename( repository.pathOf( artifact ) ); + expectedRecord.setLastModified( artifact.getFile().lastModified() ); + expectedRecord.setSize( artifact.getFile().length() ); + expectedRecord.setArtifactId( "test-dll" ); + expectedRecord.setGroupId( TEST_GROUP_ID ); + expectedRecord.setBaseVersion( "1.0.1.34" ); + expectedRecord.setVersion( "1.0.1.34" ); + expectedRecord.setSha1Checksum( "da39a3ee5e6b4b0d3255bfef95601890afd80709" ); + expectedRecord.setType( "dll" ); + expectedRecord.setRepository( "test" ); + + assertEquals( "check record", expectedRecord, record ); + } + + public void testMissingFile() + throws RepositoryIndexException + { + Artifact artifact = createArtifact( "test-foo" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + assertNull( "Confirm no record is returned", record ); + } + + private Artifact createArtifact( String artifactId ) + { + return createArtifact( artifactId, "1.0", "jar" ); + } + + private Artifact createArtifact( String artifactId, String version, String type ) + { + return createArtifact( artifactId, version, type, null ); + } + + private Artifact createArtifact( String artifactId, String version, String type, String classifier ) + { + Artifact artifact = artifactFactory.createDependencyArtifact( TEST_GROUP_ID, artifactId, + VersionRange.createFromVersion( version ), type, + classifier, Artifact.SCOPE_RUNTIME ); + artifact.isSnapshot(); + artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); + artifact.setRepository( repository ); + return artifact; + } +} diff --git a/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/parent-pom/1/parent-pom-1.pom b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/parent-pom/1/parent-pom-1.pom new file mode 100644 index 000000000..162f02ac6 --- /dev/null +++ b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/parent-pom/1/parent-pom-1.pom @@ -0,0 +1,38 @@ + + + 4.0.0 + org.apache.maven.repository.record + parent-pom + 1 + pom + Test Parent POM + Description + 2005 + + + junit + junit + 3.8.1 + test + + + + test-child-pom + + + diff --git a/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.jar b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.jar new file mode 100644 index 000000000..e1686a206 Binary files /dev/null and b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.jar differ diff --git a/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.pom b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.pom new file mode 100644 index 000000000..7b9d7c7f7 --- /dev/null +++ b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.pom @@ -0,0 +1,8 @@ + + 4.0.0 + org.apache.maven.repository.record + test-archetype + 1.0 + Archetype - test-archetype + diff --git a/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.jar b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.jar new file mode 100644 index 000000000..b78be2eb8 Binary files /dev/null and b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.jar differ diff --git a/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.pom b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.pom new file mode 100644 index 000000000..b247e7aa3 --- /dev/null +++ b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.pom @@ -0,0 +1,28 @@ + + + + 4.0.0 + + org.apache.maven.repository.record + parent-pom + 1 + + test-child-pom + 1.0-20060731-121314-1 + Child Project + diff --git a/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-corrupt-jar/1.0/test-corrupt-jar-1.0.jar b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-corrupt-jar/1.0/test-corrupt-jar-1.0.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-dll/1.0.1.34/test-dll-1.0.1.34.dll b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-dll/1.0.1.34/test-dll-1.0.1.34.dll new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1-jdk14.jar b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1-jdk14.jar new file mode 100644 index 000000000..b78be2eb8 Binary files /dev/null and b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1-jdk14.jar differ diff --git a/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.jar b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.jar new file mode 100644 index 000000000..b78be2eb8 Binary files /dev/null and b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.jar differ diff --git a/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.pom b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.pom new file mode 100644 index 000000000..6d2d2a78a --- /dev/null +++ b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.pom @@ -0,0 +1,32 @@ + + + + 4.0.0 + org.apache.maven.repository.record + test-jar-and-pom + 1.0-alpha-1 + Test JAR and POM + + + junit + junit + 3.8.1 + test + + + diff --git a/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar/1.0/test-jar-1.0-jdk14.jar b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar/1.0/test-jar-1.0-jdk14.jar new file mode 100644 index 000000000..b78be2eb8 Binary files /dev/null and b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar/1.0/test-jar-1.0-jdk14.jar differ diff --git a/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar/1.0/test-jar-1.0.jar b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar/1.0/test-jar-1.0.jar new file mode 100644 index 000000000..b78be2eb8 Binary files /dev/null and b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar/1.0/test-jar-1.0.jar differ diff --git a/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.jar b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.jar new file mode 100644 index 000000000..a7f3a67a8 Binary files /dev/null and b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.jar differ diff --git a/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.pom b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.pom new file mode 100644 index 000000000..7baa980d2 --- /dev/null +++ b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.pom @@ -0,0 +1,22 @@ + + 4.0.0 + org.apache.maven.repository.record + test-plugin + maven-plugin + 1.0 + Maven Mojo Archetype + + + org.apache.maven + maven-plugin-api + 2.0 + + + junit + junit + 3.8.1 + test + + + diff --git a/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-pom/1.0/test-pom-1.0.pom b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-pom/1.0/test-pom-1.0.pom new file mode 100644 index 000000000..34b9e1f3f --- /dev/null +++ b/archiva-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-pom/1.0/test-pom-1.0.pom @@ -0,0 +1,11 @@ + + 4.0.0 + org.apache.maven.repository.record + test-pom + 1.0 + Maven Repository Manager Test POM + 2005 + Description + pom + diff --git a/archiva-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-artifact-2.0.1.jar b/archiva-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-artifact-2.0.1.jar new file mode 100644 index 000000000..14fa95ab9 Binary files /dev/null and b/archiva-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-artifact-2.0.1.jar differ diff --git a/archiva-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-artifact-2.0.1.pom b/archiva-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-artifact-2.0.1.pom new file mode 100644 index 000000000..0121c43d3 --- /dev/null +++ b/archiva-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-artifact-2.0.1.pom @@ -0,0 +1,45 @@ + + + + maven + org.apache.maven + 2.0.1 + + 4.0.0 + org.apache.maven + maven-artifact + Maven Artifact + 2.0.1 + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + org.codehaus.plexus + plexus-utils + 1.0.5 + + + org.codehaus.plexus + plexus-container-default + 1.0-alpha-9 + test + + + + deployed + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.0 + + + + \ No newline at end of file diff --git a/archiva-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-metadata.xml b/archiva-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-metadata.xml new file mode 100644 index 000000000..f9f9abc99 --- /dev/null +++ b/archiva-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-metadata.xml @@ -0,0 +1,5 @@ + + org.apache.maven + maven-artifact + 2.0.1 + diff --git a/archiva-indexer/src/test/repository/org/apache/maven/maven-artifact/maven-metadata.xml b/archiva-indexer/src/test/repository/org/apache/maven/maven-artifact/maven-metadata.xml new file mode 100644 index 000000000..d4b28f93e --- /dev/null +++ b/archiva-indexer/src/test/repository/org/apache/maven/maven-artifact/maven-metadata.xml @@ -0,0 +1,12 @@ + + org.apache.maven + maven-artifact + 2.0.1 + + 2.0.1 + + 2.0.1 + + 20051212044643 + + diff --git a/archiva-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.jar b/archiva-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.pom b/archiva-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.pom new file mode 100644 index 000000000..e5dc3f3a8 --- /dev/null +++ b/archiva-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.pom @@ -0,0 +1,95 @@ + + + maven + org.apache.maven + 2.0 + + 4.0.0 + org.apache.maven + maven-corrupt-jar + Maven Model + 2.0 + Maven Model + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + org.codehaus.modello + modello-maven-plugin + 2.0 + + + + xpp3-writer + java + xpp3-reader + xsd + + + + + 4.0.0 + maven.mdo + + + + + + + all-models + + + + org.codehaus.modello + modello-maven-plugin + + + v3 + + xpp3-writer + java + xpp3-reader + xsd + + + 3.0.0 + true + + + + + + maven-jar-plugin + + + package + + jar + + + all + + + + + + + + + + + org.codehaus.plexus + plexus-utils + 1.0.5 + + + + deployed + + \ No newline at end of file diff --git a/archiva-indexer/src/test/repository/org/apache/maven/maven-metadata.xml b/archiva-indexer/src/test/repository/org/apache/maven/maven-metadata.xml new file mode 100644 index 000000000..3a837529b --- /dev/null +++ b/archiva-indexer/src/test/repository/org/apache/maven/maven-metadata.xml @@ -0,0 +1,9 @@ + + org.apache.maven + + + org.apache.maven + org.apache.maven-maven-plugin + + + diff --git a/archiva-indexer/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar b/archiva-indexer/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar new file mode 100644 index 000000000..d6820d6fe Binary files /dev/null and b/archiva-indexer/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar differ diff --git a/archiva-indexer/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom b/archiva-indexer/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom new file mode 100644 index 000000000..2abd766dc --- /dev/null +++ b/archiva-indexer/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom @@ -0,0 +1,95 @@ + + + maven + org.apache.maven + 2.0 + + 4.0.0 + org.apache.maven + maven-model + Maven Model + 2.0 + Maven Model + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + org.codehaus.modello + modello-maven-plugin + 2.0 + + + + xpp3-writer + java + xpp3-reader + xsd + + + + + 4.0.0 + maven.mdo + + + + + + + all-models + + + + org.codehaus.modello + modello-maven-plugin + + + v3 + + xpp3-writer + java + xpp3-reader + xsd + + + 3.0.0 + true + + + + + + maven-jar-plugin + + + package + + jar + + + all + + + + + + + + + + + org.codehaus.plexus + plexus-utils + 1.0.5 + + + + deployed + + \ No newline at end of file diff --git a/archiva-indexer/src/test/repository/test/inherited/test-inherited/1.0.15/test-inherited-1.0.15.pom b/archiva-indexer/src/test/repository/test/inherited/test-inherited/1.0.15/test-inherited-1.0.15.pom new file mode 100644 index 000000000..19faa7910 --- /dev/null +++ b/archiva-indexer/src/test/repository/test/inherited/test-inherited/1.0.15/test-inherited-1.0.15.pom @@ -0,0 +1,11 @@ + + 4.0.0 + + test.inherited + 1.0.15 + test-inherited-parent + + + test-inherited + pom + \ No newline at end of file diff --git a/archiva-indexer/src/test/repository/test/maven-metadata.xml b/archiva-indexer/src/test/repository/test/maven-metadata.xml new file mode 100644 index 000000000..e1f2008ef --- /dev/null +++ b/archiva-indexer/src/test/repository/test/maven-metadata.xml @@ -0,0 +1,9 @@ + + test + + + + test-test-plugin + + + diff --git a/archiva-indexer/src/test/repository/test/test-artifactId/1.0/test-artifactId-1.0.jar b/archiva-indexer/src/test/repository/test/test-artifactId/1.0/test-artifactId-1.0.jar new file mode 100644 index 000000000..00eb58b70 Binary files /dev/null and b/archiva-indexer/src/test/repository/test/test-artifactId/1.0/test-artifactId-1.0.jar differ diff --git a/archiva-indexer/src/test/repository/test/test-artifactId/1.0/test-artifactId-1.0.pom b/archiva-indexer/src/test/repository/test/test-artifactId/1.0/test-artifactId-1.0.pom new file mode 100644 index 000000000..157d74f41 --- /dev/null +++ b/archiva-indexer/src/test/repository/test/test-artifactId/1.0/test-artifactId-1.0.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + test-artifactId + 1.0 + \ No newline at end of file diff --git a/archiva-proxy/pom.xml b/archiva-proxy/pom.xml new file mode 100644 index 000000000..a4cfbcfdd --- /dev/null +++ b/archiva-proxy/pom.xml @@ -0,0 +1,52 @@ + + + + + org.apache.maven.archiva + archiva + 1.0-SNAPSHOT + + 4.0.0 + archiva-proxy + Archiva Proxy + + + org.apache.maven.archiva + archiva-discoverer + + + org.apache.maven + maven-artifact + + + org.apache.maven.wagon + wagon-file + test + + + org.apache.maven.wagon + wagon-provider-api + + + easymock + easymock + 1.2_Java1.3 + test + + + diff --git a/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyRequestHandler.java b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyRequestHandler.java new file mode 100644 index 000000000..90a21726a --- /dev/null +++ b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyRequestHandler.java @@ -0,0 +1,672 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.metadata.Metadata; +import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; +import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer; +import org.apache.maven.repository.digest.DigestUtils; +import org.apache.maven.repository.digest.DigesterException; +import org.apache.maven.repository.discovery.ArtifactDiscoverer; +import org.apache.maven.repository.discovery.DiscovererException; +import org.apache.maven.wagon.ConnectionException; +import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.apache.maven.wagon.TransferFailedException; +import org.apache.maven.wagon.Wagon; +import org.apache.maven.wagon.authentication.AuthenticationException; +import org.apache.maven.wagon.authorization.AuthorizationException; +import org.apache.maven.wagon.observers.ChecksumObserver; +import org.apache.maven.wagon.proxy.ProxyInfo; +import org.apache.maven.wagon.repository.Repository; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.security.NoSuchAlgorithmException; +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * An implementation of the proxy handler. This class is not thread safe (the class itself is, but the wagons it uses + * are not) - it is declared per-lookup for that reason. + * + * @author Brett Porter + * @plexus.component instantiation-strategy="per-lookup" + * @todo use wagonManager for cache use file:// as URL + * @todo this currently duplicates a lot of the wagon manager, and doesn't do things like snapshot resolution, etc. + * The checksum handling is inconsistent with that of the wagon manager. + * Should we have a more artifact based one? This will merge metadata so should behave correctly, and it is able to + * correct some limitations of the wagon manager (eg, it can retrieve newer SNAPSHOT files without metadata) + */ +public class DefaultProxyRequestHandler + extends AbstractLogEnabled + implements ProxyRequestHandler +{ + /** + * @plexus.requirement role-hint="default" + * @todo use a map, and have priorities in them + */ + private ArtifactDiscoverer defaultArtifactDiscoverer; + + /** + * @plexus.requirement role-hint="legacy" + */ + private ArtifactDiscoverer legacyArtifactDiscoverer; + + /** + * @plexus.requirement role="org.apache.maven.wagon.Wagon" + */ + private Map/**/ wagons; + + public File get( String path, List proxiedRepositories, ArtifactRepository managedRepository ) + throws ProxyException, ResourceDoesNotExistException + { + return get( path, proxiedRepositories, managedRepository, null ); + } + + public File get( String path, List proxiedRepositories, ArtifactRepository managedRepository, ProxyInfo wagonProxy ) + throws ProxyException, ResourceDoesNotExistException + { + return get( managedRepository, path, proxiedRepositories, wagonProxy, false ); + } + + public File getAlways( String path, List proxiedRepositories, ArtifactRepository managedRepository ) + throws ProxyException, ResourceDoesNotExistException + { + return getAlways( path, proxiedRepositories, managedRepository, null ); + } + + public File getAlways( String path, List proxiedRepositories, ArtifactRepository managedRepository, + ProxyInfo wagonProxy ) + throws ResourceDoesNotExistException, ProxyException + { + return get( managedRepository, path, proxiedRepositories, wagonProxy, true ); + } + + private File get( ArtifactRepository managedRepository, String path, List proxiedRepositories, ProxyInfo wagonProxy, + boolean force ) + throws ProxyException, ResourceDoesNotExistException + { + File target = new File( managedRepository.getBasedir(), path ); + + for ( Iterator i = proxiedRepositories.iterator(); i.hasNext(); ) + { + ProxiedArtifactRepository repository = (ProxiedArtifactRepository) i.next(); + + if ( !force && repository.isCachedFailure( path ) ) + { + processCachedRepositoryFailure( repository, "Cached failure found for: " + path ); + } + else + { + get( path, target, repository, managedRepository, wagonProxy, force ); + } + } + + if ( !target.exists() ) + { + throw new ResourceDoesNotExistException( "Could not find " + path + " in any of the repositories." ); + } + + return target; + } + + private void get( String path, File target, ProxiedArtifactRepository repository, + ArtifactRepository managedRepository, ProxyInfo wagonProxy, boolean force ) + throws ProxyException + { + ArtifactRepositoryPolicy policy; + + if ( path.endsWith( ".md5" ) || path.endsWith( ".sha1" ) ) + { + // always read from the managed repository, no need to make remote request + } + else if ( path.endsWith( "maven-metadata.xml" ) ) + { + File metadataFile = new File( target.getParentFile(), ".metadata-" + repository.getRepository().getId() ); + + policy = repository.getRepository().getReleases(); + + // if it is snapshot metadata, use a different policy + if ( path.endsWith( "-SNAPSHOT/maven-metadata.xml" ) ) + { + policy = repository.getRepository().getSnapshots(); + } + + if ( force || !metadataFile.exists() || isOutOfDate( policy, metadataFile ) ) + { + getFileFromRepository( path, repository, managedRepository.getBasedir(), wagonProxy, metadataFile, + policy, force ); + + mergeMetadataFiles( target, metadataFile ); + } + } + else + { + Artifact artifact = null; + try + { + artifact = defaultArtifactDiscoverer.buildArtifact( path ); + } + catch ( DiscovererException e ) + { + getLogger().debug( "Failed to build artifact using default layout with message: " + e.getMessage() ); + } + + if ( artifact == null ) + { + try + { + artifact = legacyArtifactDiscoverer.buildArtifact( path ); + } + catch ( DiscovererException e ) + { + getLogger().debug( "Failed to build artifact using legacy layout with message: " + e.getMessage() ); + } + } + + if ( artifact != null ) + { + ArtifactRepository artifactRepository = repository.getRepository(); + + // we use the release policy for tracking failures, but only check for updates on snapshots + // also, we don't look for updates on timestamp snapshot files, only non-unique-version ones + policy = artifact.isSnapshot() ? artifactRepository.getSnapshots() : artifactRepository.getReleases(); + + boolean needsUpdate = false; + if ( artifact.getVersion().endsWith( "-SNAPSHOT" ) && isOutOfDate( policy, target ) ) + { + needsUpdate = true; + } + + if ( needsUpdate || force || !target.exists() ) + { + getFileFromRepository( artifactRepository.pathOf( artifact ), repository, + managedRepository.getBasedir(), wagonProxy, target, policy, force ); + } + } + else + { + // Some other unknown file in the repository, proxy as is + if ( force || !target.exists() ) + { + policy = repository.getRepository().getReleases(); + getFileFromRepository( path, repository, managedRepository.getBasedir(), wagonProxy, target, policy, + force ); + } + } + } + + if ( target.exists() ) + { + // in case it previously failed and we've since found it + repository.clearFailure( path ); + } + } + + private void mergeMetadataFiles( File target, File metadataFile ) + throws ProxyException + { + MetadataXpp3Reader reader = new MetadataXpp3Reader(); + if ( metadataFile.exists() ) + { + Metadata metadata = null; + if ( target.exists() ) + { + FileReader fileReader = null; + try + { + fileReader = new FileReader( target ); + metadata = reader.read( fileReader ); + } + catch ( XmlPullParserException e ) + { + throw new ProxyException( "Unable to parse existing metadata: " + e.getMessage(), e ); + } + catch ( IOException e ) + { + throw new ProxyException( "Unable to read existing metadata: " + e.getMessage(), e ); + } + finally + { + IOUtil.close( fileReader ); + } + } + + FileReader fileReader = null; + boolean changed = false; + try + { + fileReader = new FileReader( metadataFile ); + Metadata newMetadata = reader.read( fileReader ); + + if ( metadata != null ) + { + changed = metadata.merge( newMetadata ); + } + else + { + metadata = newMetadata; + changed = true; + } + } + catch ( IOException e ) + { + // ignore the merged file + getLogger().warn( "Unable to read new metadata: " + e.getMessage() ); + } + catch ( XmlPullParserException e ) + { + // ignore the merged file + getLogger().warn( "Unable to parse new metadata: " + e.getMessage() ); + } + finally + { + IOUtil.close( fileReader ); + } + + if ( changed ) + { + FileWriter fileWriter = null; + try + { + fileWriter = new FileWriter( target ); + new MetadataXpp3Writer().write( fileWriter, metadata ); + } + catch ( IOException e ) + { + getLogger().warn( "Unable to store new metadata: " + e.getMessage() ); + } + finally + { + IOUtil.close( fileWriter ); + } + } + } + } + + private void getFileFromRepository( String path, ProxiedArtifactRepository repository, String repositoryCachePath, + ProxyInfo httpProxy, File target, ArtifactRepositoryPolicy policy, + boolean force ) + throws ProxyException + { + if ( !policy.isEnabled() ) + { + getLogger().debug( "Skipping disabled repository " + repository.getName() ); + return; + } + + Map checksums = null; + Wagon wagon = null; + + File temp = new File( target.getAbsolutePath() + ".tmp" ); + temp.deleteOnExit(); + + boolean connected = false; + try + { + String protocol = repository.getRepository().getProtocol(); + wagon = (Wagon) wagons.get( protocol ); + if ( wagon == null ) + { + throw new ProxyException( "Unsupported remote protocol: " + protocol ); + } + + //@todo configure wagon (ssh settings, etc) + + checksums = prepareChecksumListeners( wagon ); + + connected = connectToRepository( wagon, repository, httpProxy ); + if ( connected ) + { + int tries = 0; + boolean success; + + do + { + tries++; + + getLogger().debug( "Trying " + path + " from " + repository.getName() + "..." ); + + boolean downloaded = true; + if ( force || !target.exists() ) + { + wagon.get( path, temp ); + } + else + { + downloaded = wagon.getIfNewer( path, temp, target.lastModified() ); + } + + if ( downloaded ) + { + success = checkChecksum( checksums, path, wagon, repositoryCachePath ); + + if ( tries > 1 && !success ) + { + processRepositoryFailure( repository, + "Checksum failures occurred while downloading " + path, path, + policy ); + return; + } + } + else + { + // getIfNewer determined we were up to date + success = true; + } + } + while ( !success ); + + // temp won't exist if we called getIfNewer and it was older, but its still a successful return + if ( temp.exists() ) + { + moveTempToTarget( temp, target ); + } + } + //try next repository + } + catch ( TransferFailedException e ) + { + processRepositoryFailure( repository, e, path, policy ); + } + catch ( AuthorizationException e ) + { + processRepositoryFailure( repository, e, path, policy ); + } + catch ( ResourceDoesNotExistException e ) + { + // hard failure setting doesn't affect "not found". + getLogger().debug( "Artifact not found in repository: " + repository.getName() + ": " + e.getMessage() ); + } + finally + { + temp.delete(); + + if ( wagon != null && checksums != null ) + { + releaseChecksumListeners( wagon, checksums ); + } + + if ( connected ) + { + disconnectWagon( wagon ); + } + } + } + + private static boolean isOutOfDate( ArtifactRepositoryPolicy policy, File target ) + { + return policy != null && policy.checkOutOfDate( new Date( target.lastModified() ) ); + } + + /** + * Used to add checksum observers as transfer listeners to the wagonManager object + * + * @param wagon the wagonManager object to use the checksum with + * @return map of ChecksumObservers added into the wagonManager transfer listeners + */ + private Map prepareChecksumListeners( Wagon wagon ) + { + Map checksums = new LinkedHashMap(); + try + { + ChecksumObserver checksum = new ChecksumObserver( "SHA-1" ); + wagon.addTransferListener( checksum ); + checksums.put( "sha1", checksum ); + + checksum = new ChecksumObserver( "MD5" ); + wagon.addTransferListener( checksum ); + checksums.put( "md5", checksum ); + } + catch ( NoSuchAlgorithmException e ) + { + getLogger().error( "An error occurred while preparing checksum observers: " + e.getMessage() ); + } + return checksums; + } + + private void releaseChecksumListeners( Wagon wagon, Map checksumMap ) + { + for ( Iterator checksums = checksumMap.values().iterator(); checksums.hasNext(); ) + { + ChecksumObserver listener = (ChecksumObserver) checksums.next(); + wagon.removeTransferListener( listener ); + } + } + + private boolean connectToRepository( Wagon wagon, ProxiedArtifactRepository repository, ProxyInfo httpProxy ) + { + boolean connected = false; + try + { + ArtifactRepository artifactRepository = repository.getRepository(); + Repository wagonRepository = new Repository( artifactRepository.getId(), artifactRepository.getUrl() ); + if ( repository.isUseNetworkProxy() && httpProxy != null ) + { + wagon.connect( wagonRepository, httpProxy ); + } + else + { + wagon.connect( wagonRepository ); + } + connected = true; + } + catch ( ConnectionException e ) + { + getLogger().info( "Could not connect to " + repository.getName() + ": " + e.getMessage() ); + } + catch ( AuthenticationException e ) + { + getLogger().info( "Could not connect to " + repository.getName() + ": " + e.getMessage() ); + } + + return connected; + } + + private boolean checkChecksum( Map checksumMap, String path, Wagon wagon, String repositoryCachePath ) + throws ProxyException + { + releaseChecksumListeners( wagon, checksumMap ); + + boolean correctChecksum = false; + + boolean allNotFound = true; + + for ( Iterator i = checksumMap.keySet().iterator(); i.hasNext() && !correctChecksum; ) + { + String checksumExt = (String) i.next(); + ChecksumObserver checksum = (ChecksumObserver) checksumMap.get( checksumExt ); + String checksumPath = path + "." + checksumExt; + File checksumFile = new File( repositoryCachePath, checksumPath ); + + File tempChecksumFile = new File( checksumFile.getAbsolutePath() + ".tmp" ); + tempChecksumFile.deleteOnExit(); + + try + { + wagon.get( checksumPath, tempChecksumFile ); + + allNotFound = false; + + String remoteChecksum = DigestUtils.cleanChecksum( FileUtils.fileRead( tempChecksumFile ), + checksumExt.toUpperCase(), + path.substring( path.lastIndexOf( '/' ) ) ); + + String actualChecksum = checksum.getActualChecksum().toUpperCase(); + remoteChecksum = remoteChecksum.toUpperCase(); + + if ( remoteChecksum.equals( actualChecksum ) ) + { + moveTempToTarget( tempChecksumFile, checksumFile ); + + correctChecksum = true; + } + else + { + getLogger().warn( + "The checksum '" + actualChecksum + "' did not match the remote value: " + remoteChecksum ); + } + } + catch ( TransferFailedException e ) + { + getLogger().warn( "An error occurred during the download of " + checksumPath + ": " + e.getMessage() ); + // do nothing try the next checksum + + allNotFound = false; + } + catch ( ResourceDoesNotExistException e ) + { + getLogger().debug( "The checksum did not exist: " + checksumPath + "; " + e.getMessage() ); + // do nothing try the next checksum + // remove it if it is present locally in case there is an old incorrect one + if ( checksumFile.exists() ) + { + checksumFile.delete(); + } + } + catch ( AuthorizationException e ) + { + getLogger().warn( "An error occurred during the download of " + checksumPath + ": " + e.getMessage() ); + // do nothing try the next checksum + + allNotFound = false; + } + catch ( IOException e ) + { + getLogger().warn( "An error occurred while reading the temporary checksum file: " + e.getMessage() ); + // do nothing try the next checksum + + allNotFound = false; + } + catch ( DigesterException e ) + { + getLogger().warn( "The checksum was invalid: " + checksumPath + ": " + e.getMessage() ); + // do nothing try the next checksum + + allNotFound = false; + } + finally + { + tempChecksumFile.delete(); + } + } + return correctChecksum || allNotFound; + } + + /** + * Used to move the temporary file to its real destination. This is patterned from the way WagonManager handles + * its downloaded files. + * + * @param temp The completed download file + * @param target The final location of the downloaded file + * @throws ProxyException when the temp file cannot replace the target file + */ + private void moveTempToTarget( File temp, File target ) + throws ProxyException + { + if ( target.exists() && !target.delete() ) + { + throw new ProxyException( "Unable to overwrite existing target file: " + target.getAbsolutePath() ); + } + + if ( !temp.renameTo( target ) ) + { + getLogger().warn( "Unable to rename tmp file to its final name... resorting to copy command." ); + + try + { + FileUtils.copyFile( temp, target ); + } + catch ( IOException e ) + { + throw new ProxyException( "Cannot copy tmp file to its final location", e ); + } + finally + { + temp.delete(); + } + } + } + + /** + * Used to disconnect the wagonManager from its repository + * + * @param wagon the connected wagonManager object + */ + private void disconnectWagon( Wagon wagon ) + { + try + { + wagon.disconnect(); + } + catch ( ConnectionException e ) + { + getLogger().error( "Problem disconnecting from wagonManager - ignoring: " + e.getMessage() ); + } + } + + private void processRepositoryFailure( ProxiedArtifactRepository repository, Throwable t, String path, + ArtifactRepositoryPolicy policy ) + throws ProxyException + { + repository.addFailure( path, policy ); + + String message = t.getMessage(); + if ( repository.isHardFail() ) + { + repository.addFailure( path, policy ); + throw new ProxyException( + "An error occurred in hardfailing repository " + repository.getName() + "...\n " + message, t ); + } + + getLogger().warn( "Skipping repository " + repository.getName() + ": " + message ); + getLogger().debug( "Cause", t ); + } + + private void processRepositoryFailure( ProxiedArtifactRepository repository, String message, String path, + ArtifactRepositoryPolicy policy ) + throws ProxyException + { + repository.addFailure( path, policy ); + + processCachedRepositoryFailure( repository, message ); + } + + private void processCachedRepositoryFailure( ProxiedArtifactRepository repository, String message ) + throws ProxyException + { + if ( repository.isHardFail() ) + { + throw new ProxyException( + "An error occurred in hardfailing repository " + repository.getName() + "...\n " + message ); + } + + getLogger().warn( "Skipping repository " + repository.getName() + ": " + message ); + } +} diff --git a/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxiedArtifactRepository.java b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxiedArtifactRepository.java new file mode 100644 index 000000000..ff3aaa3ff --- /dev/null +++ b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxiedArtifactRepository.java @@ -0,0 +1,197 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; + +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; + +/** + * A proxied artifact repository - contains the artifact repository and additional information about + * the proxied repository. + * + * @author Brett Porter + */ +public class ProxiedArtifactRepository +{ + /** + * Whether to cache failures or not. + */ + private boolean cacheFailures; + + /** + * Whether failures on this repository cause the whole group to fail. + */ + private boolean hardFail; + + /** + * Whether to use the network proxy for any requests. + */ + private boolean useNetworkProxy; + + /** + * The artifact repository on the other end of the proxy. + */ + private final ArtifactRepository repository; + + /** + * Cache of failures that have already occurred, containing paths from the repository root. The value given + * specifies when the failure should expire. + */ + private Map/**/ failureCache = new HashMap/**/(); + + /** + * A user friendly name for the repository. + */ + private String name; + + public ProxiedArtifactRepository( ArtifactRepository repository ) + { + this.repository = repository; + } + + public boolean isHardFail() + { + return hardFail; + } + + public boolean isUseNetworkProxy() + { + return useNetworkProxy; + } + + public boolean isCacheFailures() + { + return cacheFailures; + } + + public ArtifactRepository getRepository() + { + return repository; + } + + /** + * Check if there is a previously cached failure for requesting the given path. + * + * @param path the path + * @return whether there is a failure + */ + public boolean isCachedFailure( String path ) + { + boolean failed = false; + if ( cacheFailures ) + { + Long time = (Long) failureCache.get( path ); + if ( time != null ) + { + if ( System.currentTimeMillis() < time.longValue() ) + { + failed = true; + } + else + { + clearFailure( path ); + } + } + } + return failed; + } + + /** + * Add a failure to the cache. + * + * @param path the path that failed + * @param policy the policy for when the failure should expire + */ + public void addFailure( String path, ArtifactRepositoryPolicy policy ) + { + failureCache.put( path, new Long( calculateExpiryTime( policy ) ) ); + } + + private long calculateExpiryTime( ArtifactRepositoryPolicy policy ) + { + String updatePolicy = policy.getUpdatePolicy(); + long time; + if ( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS.equals( updatePolicy ) ) + { + time = 0; + } + else if ( ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY.equals( updatePolicy ) ) + { + // Get midnight boundary + Calendar cal = Calendar.getInstance(); + cal.set( Calendar.HOUR_OF_DAY, 0 ); + cal.set( Calendar.MINUTE, 0 ); + cal.set( Calendar.SECOND, 0 ); + cal.set( Calendar.MILLISECOND, 0 ); + cal.add( Calendar.DAY_OF_MONTH, 1 ); + time = cal.getTime().getTime(); + } + else if ( updatePolicy.startsWith( ArtifactRepositoryPolicy.UPDATE_POLICY_INTERVAL ) ) + { + String s = updatePolicy.substring( ArtifactRepositoryPolicy.UPDATE_POLICY_INTERVAL.length() + 1 ); + int minutes = Integer.valueOf( s ).intValue(); + Calendar cal = Calendar.getInstance(); + cal.add( Calendar.MINUTE, minutes ); + time = cal.getTime().getTime(); + } + else + { + // else assume "never" + time = Long.MAX_VALUE; + } + return time; + } + + /** + * Remove a failure. + * + * @param path the path that had previously failed + */ + public void clearFailure( String path ) + { + failureCache.remove( path ); + } + + public String getName() + { + return name; + } + + public void setCacheFailures( boolean cacheFailures ) + { + this.cacheFailures = cacheFailures; + } + + public void setHardFail( boolean hardFail ) + { + this.hardFail = hardFail; + } + + public void setUseNetworkProxy( boolean useNetworkProxy ) + { + this.useNetworkProxy = useNetworkProxy; + } + + public void setName( String name ) + { + this.name = name; + } +} diff --git a/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyException.java b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyException.java new file mode 100644 index 000000000..cd6ecc323 --- /dev/null +++ b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyException.java @@ -0,0 +1,34 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * @author Edwin Punzalan + */ +public class ProxyException + extends Exception +{ + public ProxyException( String message ) + { + super( message ); + } + + public ProxyException( String message, Throwable t ) + { + super( message, t ); + } +} diff --git a/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyRequestHandler.java b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyRequestHandler.java new file mode 100644 index 000000000..4b8e3e5da --- /dev/null +++ b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyRequestHandler.java @@ -0,0 +1,101 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.repository.ArtifactRepository; +import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.apache.maven.wagon.proxy.ProxyInfo; + +import java.io.File; +import java.util.List; + +/** + * An individual request handler for the proxy. + * + * @author Brett Porter + */ +public interface ProxyRequestHandler +{ + /** + * The Plexus role of the component. + */ + String ROLE = ProxyRequestHandler.class.getName(); + + /** + * Used to retrieve an artifact at a particular path, giving the cached version if it exists. + * + * @param path the expected repository path + * @param proxiedRepositories the repositories being proxied to + * @param managedRepository the locally managed repository to cache artifacts in + * @return File object referencing the requested path in the cache + * @throws ProxyException when an exception occurred during the retrieval of the requested path + * @throws org.apache.maven.wagon.ResourceDoesNotExistException + * when the requested object can't be found in any of the + * configured repositories + */ + File get( String path, List proxiedRepositories, ArtifactRepository managedRepository ) + throws ProxyException, ResourceDoesNotExistException; + + /** + * Used to retrieve an artifact at a particular path, giving the cached version if it exists. + * + * @param path the expected repository path + * @param proxiedRepositories the repositories being proxied to + * @param managedRepository the locally managed repository to cache artifacts in + * @param wagonProxy a network proxy to use when transferring files if needed + * @return File object referencing the requested path in the cache + * @throws ProxyException when an exception occurred during the retrieval of the requested path + * @throws org.apache.maven.wagon.ResourceDoesNotExistException + * when the requested object can't be found in any of the + * configured repositories + */ + File get( String path, List proxiedRepositories, ArtifactRepository managedRepository, ProxyInfo wagonProxy ) + throws ProxyException, ResourceDoesNotExistException; + + /** + * Used to force remote download of the requested path from any the configured repositories. This method will + * only bypass the cache for searching but the requested path will still be cached. + * + * @param path the expected repository path + * @param proxiedRepositories the repositories being proxied to + * @param managedRepository the locally managed repository to cache artifacts in + * @return File object referencing the requested path in the cache + * @throws ProxyException when an exception occurred during the retrieval of the requested path + * @throws org.apache.maven.wagon.ResourceDoesNotExistException + * when the requested object can't be found in any of the + * configured repositories + */ + File getAlways( String path, List proxiedRepositories, ArtifactRepository managedRepository ) + throws ProxyException, ResourceDoesNotExistException; + + /** + * Used to force remote download of the requested path from any the configured repositories. This method will + * only bypass the cache for searching but the requested path will still be cached. + * + * @param path the expected repository path + * @param proxiedRepositories the repositories being proxied to + * @param managedRepository the locally managed repository to cache artifacts in + * @param wagonProxy a network proxy to use when transferring files if needed + * @return File object referencing the requested path in the cache + * @throws ProxyException when an exception occurred during the retrieval of the requested path + * @throws org.apache.maven.wagon.ResourceDoesNotExistException + * when the requested object can't be found in any of the + * configured repositories + */ + File getAlways( String path, List proxiedRepositories, ArtifactRepository managedRepository, ProxyInfo wagonProxy ) + throws ProxyException, ResourceDoesNotExistException; +} diff --git a/archiva-proxy/src/site/apt/how-to.apt b/archiva-proxy/src/site/apt/how-to.apt new file mode 100644 index 000000000..14cf1ef4b --- /dev/null +++ b/archiva-proxy/src/site/apt/how-to.apt @@ -0,0 +1,73 @@ +ProxyManager + + The ProxyManager is designed to be used as a simple object or bean for use by + a command-line application or web application. + +Configuration + + An instance of a ProxyManager requires a configuration object that will + define its behavior called ProxyConfiguration. The ProxyConfiguration is a + plexus component and can be looked up to get an instance of it. Below is a sample + plexus lookup statement: + +---------- + ProxyConfiguration config = (ProxyConfiguration) container.lookup( ProxyConfiguration.ROLE ); +---------- + + Currently, a ProxyConfiguration lookup will return an empty instance of the + ProxyConfiguration which means it doesn't have any default definitions yet on + how the ProxyManager should behave. So the next step is to explicitly define + its behavior. + +---------- + ProxyConfiguration config = (ProxyConfiguration) container.lookup( ProxyConfiguration.ROLE ); + + config.setRepositoryCachePath( "/user/proxy-cache" ); + + ArtifactRepositoryLayout defLayout = new DefaultRepositoryLayout(); + + File repo1File = new File( "src/test/remote-repo1" ); + + ProxyRepository repo1 = new ProxyRepository( "central", "http://www.ibiblio.org/maven2", defLayout ); + + config.addRepository( repo1 ); +---------- + + The above statements sets up the ProxyConfiguration to use the directory + <<>> as the location of the proxy's repository cache. + Then it creates a ProxyRepository instance with an id of <<>> to + look for remote files in ibiblio.org. + +Instantiation + + To create or retrieve an instance of a ProxyManager, one will need to use the + ProxyManagerFactory. + +---------- + ProxyManagerFactory factory = (ProxyManagerFactory) container.lookup( ProxyManagerFactory.ROLE ); + proxy = factory.getProxyManager( "default", config ); +---------- + + The factory requires two parameters. The first parameter is the proxy_type + that you will want to use. And the second parameter is the ProxyConfiguration + which we already did above. The proxy_type defines the client that the + ProxyManager is expected to service. Currently, only <<>> + ProxyManager type is available and is defined to be for Maven 2.x clients. + +Usage + +* The get() method + + The ProxyManager get( target ) method is used to retrieve a path file. This + method first looks into the cache if the target exists. If it does not, then + the ProxyManager will search all the ProxyRepositories present in its + ProxyConfiguration. When the target path is found, the ProxyManager creates + a copy of it in its cache and returns a File instance of the cached copy. + +* The getRemoteFile() method + + The ProxyManager getRemoteFile( path ) method is used to force the + ProxyManager to ignore the contents of its cache and search all the + ProxyRepository objects for the specified path and retrieve it when + available. When successful, the ProxyManager creates a copy of the remote + file in its cache and then returns a File instance of the cached copy. \ No newline at end of file diff --git a/archiva-proxy/src/test/java/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.java b/archiva-proxy/src/test/java/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.java new file mode 100644 index 000000000..3837ca91f --- /dev/null +++ b/archiva-proxy/src/test/java/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.java @@ -0,0 +1,1772 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.repository.metadata.Metadata; +import org.apache.maven.artifact.repository.metadata.Snapshot; +import org.apache.maven.artifact.repository.metadata.Versioning; +import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer; +import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.apache.maven.wagon.TransferFailedException; +import org.apache.maven.wagon.Wagon; +import org.apache.maven.wagon.authorization.AuthorizationException; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.FileUtils; +import org.easymock.MockControl; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.net.MalformedURLException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; + +/** + * Test the proxy handler. + * + * @author Brett Porter + */ +public class ProxyRequestHandlerTest + extends PlexusTestCase +{ + private ProxyRequestHandler requestHandler; + + private List proxiedRepositories; + + private List legacyProxiedRepositories; + + private ArtifactRepository defaultManagedRepository; + + private ArtifactRepository legacyManagedRepository; + + private ArtifactRepository proxiedRepository1; + + private ArtifactRepository proxiedRepository2; + + private ArtifactRepository legacyProxiedRepository; + + private ArtifactRepositoryLayout defaultLayout; + + private ArtifactRepositoryFactory factory; + + private MockControl wagonMockControl; + + private Wagon wagonMock; + + private static final ArtifactRepositoryPolicy DEFAULT_POLICY = + new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER, null ); + + private static final ArtifactRepositoryPolicy ALWAYS_UPDATE_POLICY = + new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, null ); + + protected void setUp() + throws Exception + { + super.setUp(); + + requestHandler = (ProxyRequestHandler) lookup( ProxyRequestHandler.ROLE ); + + factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + + File repoLocation = getTestFile( "target/test-repository/managed" ); + // faster only to delete this one before copying, the others are done case by case + FileUtils.deleteDirectory( new File( repoLocation, "org/apache/maven/test/get-merged-metadata" ) ); + copyDirectoryStructure( getTestFile( "src/test/repositories/managed" ), repoLocation ); + + defaultLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + + defaultManagedRepository = createRepository( "managed-repository", repoLocation ); + + repoLocation = getTestFile( "target/test-repository/legacy-managed" ); + FileUtils.deleteDirectory( repoLocation ); + copyDirectoryStructure( getTestFile( "src/test/repositories/legacy-managed" ), repoLocation ); + + ArtifactRepositoryLayout legacyLayout = + (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); + + legacyManagedRepository = createRepository( "managed-repository", repoLocation ); + + File location = getTestFile( "src/test/repositories/proxied1" ); + proxiedRepository1 = createRepository( "proxied1", location ); + + location = getTestFile( "src/test/repositories/proxied2" ); + proxiedRepository2 = createRepository( "proxied2", location ); + + proxiedRepositories = new ArrayList( 2 ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository1 ) ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + + location = getTestFile( "src/test/repositories/legacy-proxied" ); + legacyProxiedRepository = createRepository( "legacy-proxied", location, legacyLayout ); + + legacyProxiedRepositories = Collections.singletonList( createProxiedRepository( legacyProxiedRepository ) ); + + wagonMockControl = MockControl.createNiceControl( Wagon.class ); + wagonMock = (Wagon) wagonMockControl.getMock(); + WagonDelegate delegate = (WagonDelegate) lookup( Wagon.ROLE, "test" ); + delegate.setDelegate( wagonMock ); + } + + public void testGetDefaultLayoutNotPresent() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + // TODO: timestamp preservation requires support for that in wagon +// assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() ); + } + + public void testGetDefaultLayoutAlreadyPresent() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + long originalModificationTime = expectedFile.lastModified(); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() ); + assertEquals( "Check file timestamp is that of original managed file", originalModificationTime, + file.lastModified() ); + } + + public void testGetDefaultLayoutRemoteUpdate() + throws ResourceDoesNotExistException, ProxyException, IOException, ParseException + { + String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + expectedFile.setLastModified( getPastDate().getTime() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetWhenInBothProxiedRepos() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetInSecondProxiedRepo() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + } + + public void testNotFoundInAnyProxies() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/does-not-exist/1.0/does-not-exist-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "File returned was: " + file + "; should have got a not found exception" ); + } + catch ( ResourceDoesNotExistException e ) + { + // expected, but check file was not created + assertFalse( expectedFile.exists() ); + } + } + + public void testGetInSecondProxiedRepoFirstFails() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ).getAbsoluteFile(); + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + proxiedRepository1 = createRepository( "proxied1", "test://..." ); + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMockControl.replay(); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + wagonMockControl.verify(); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + assertTrue( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); + } + + public void testGetButAllRepositoriesFail() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ).getAbsoluteFile(); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + proxiedRepository1 = createRepository( "proxied1", "test://..." ); + proxiedRepository2 = createRepository( "proxied2", "test://..." ); + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository1 = createProxiedRepository( proxiedRepository1 ); + proxiedRepositories.add( proxiedArtifactRepository1 ); + ProxiedArtifactRepository proxiedArtifactRepository2 = createProxiedRepository( proxiedRepository2 ); + proxiedRepositories.add( proxiedArtifactRepository2 ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMockControl.replay(); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // as expected + wagonMockControl.verify(); + assertTrue( "Check failure", proxiedArtifactRepository1.isCachedFailure( path ) ); + assertTrue( "Check failure", proxiedArtifactRepository2.isCachedFailure( path ) ); + + // TODO: do we really want failures to present as a not found? + // TODO: How much information on each failure should we pass back to the user vs. logging in the proxy? + } + } + + public void testGetInSecondProxiedRepoFirstHardFails() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ).getAbsoluteFile(); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + proxiedRepository1 = createRepository( "proxied1", "test://..." ); + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createHardFailProxiedRepository( proxiedRepository1 ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + TransferFailedException failedException = new TransferFailedException( "transfer failed" ); + wagonMockControl.setThrowable( failedException ); + + wagonMockControl.replay(); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ProxyException e ) + { + // expect a failure + wagonMockControl.verify(); + + assertEquals( "Check cause", failedException, e.getCause() ); + assertTrue( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); + } + } + + public void testGetInSecondProxiedRepoFirstFailsFromCache() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + // fail from the cache, even though it is in the first repo now + + String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); + proxiedArtifactRepository.addFailure( path, DEFAULT_POLICY ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetInSecondProxiedRepoFirstHardFailsFromCache() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + // fail from the cache, even though it is in the first repo now + + String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createHardFailProxiedRepository( proxiedRepository1 ); + proxiedArtifactRepository.addFailure( path, DEFAULT_POLICY ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ProxyException e ) + { + // expect a failure + assertTrue( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); + } + } + + public void testGetInSecondProxiedRepoFirstFailsDisabledCacheFailure() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ).getAbsoluteFile(); + + assertFalse( expectedFile.exists() ); + + proxiedRepository1 = createRepository( "proxied1", "test://..." ); + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); + proxiedArtifactRepository.addFailure( path, DEFAULT_POLICY ); + proxiedArtifactRepository.setCacheFailures( false ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMockControl.replay(); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + wagonMockControl.verify(); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + assertFalse( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); + } + + public void testGetWhenInBothProxiedReposFirstHasExpiredCacheFailure() + throws ResourceDoesNotExistException, ProxyException, IOException, ParseException + { + String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); + proxiedArtifactRepository.addFailure( path, ALWAYS_UPDATE_POLICY ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + + assertFalse( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); + } + + public void testGetAlwaysAlreadyPresent() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetAlwaysAlreadyPresentRemovedFromProxies() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-removed-from-proxies/1.0/get-removed-from-proxies-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + // TODO: is this the correct behaviour, or should it be considered removed too? + } + + public void testGetAlwaysWithCachedFailure() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); + proxiedArtifactRepository.addFailure( path, DEFAULT_POLICY ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetRemovesTemporaryFileOnSuccess() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File tempFile = new File( file.getParentFile(), file.getName() + ".tmp" ); + assertFalse( "Check temporary file removed", tempFile.exists() ); + } + + public void testGetRemovesTemporaryFileOnError() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + proxiedRepository1 = createRepository( "proxied1", "test://..." ); + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository1 = createProxiedRepository( proxiedRepository1 ); + proxiedRepositories.add( proxiedArtifactRepository1 ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMockControl.replay(); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // as expected + wagonMockControl.verify(); + + File tempFile = new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ); + assertFalse( "Check temporary file removed", tempFile.exists() ); + } + } + + public void testGetRemovesTemporaryChecksumFileOnSuccess() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File tempFile = new File( file.getParentFile(), file.getName() + ".sha1.tmp" ); + assertFalse( "Check temporary file removed", tempFile.exists() ); + } + + public void testGetRemovesTemporaryChecksumFileOnError() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + proxiedRepository1 = createRepository( "proxied1", "test://..." ); + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository1 = createProxiedRepository( proxiedRepository1 ); + proxiedRepositories.add( proxiedArtifactRepository1 ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + + mockFailedChecksums( path, expectedFile ); + + wagonMockControl.replay(); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // as expected + wagonMockControl.verify(); + + File tempFile = new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ); + assertFalse( "Check temporary file removed", tempFile.exists() ); + + tempFile = new File( expectedFile.getParentFile(), expectedFile.getName() + ".sha1.tmp" ); + assertFalse( "Check temporary file removed", tempFile.exists() ); + } + } + + public void testGetChecksumBothCorrect() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File checksumFile = getChecksumFile( file, "sha1" ); + assertTrue( "Check file created", checksumFile.exists() ); + assertEquals( "Check checksum", "066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-both-right-1.0.jar", + FileUtils.fileRead( checksumFile ).trim() ); + + assertFalse( "Check file not created", getChecksumFile( file, "md5" ).exists() ); + } + + public void testGetCorrectSha1NoMd5() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File checksumFile = getChecksumFile( file, "sha1" ); + assertTrue( "Check file created", checksumFile.exists() ); + assertEquals( "Check checksum", "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", + FileUtils.fileRead( checksumFile ).trim() ); + + assertFalse( "Check file not created", getChecksumFile( file, "md5" ).exists() ); + } + + public void testGetCorrectSha1BadMd5() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File checksumFile = getChecksumFile( file, "sha1" ); + assertTrue( "Check file created", checksumFile.exists() ); + assertEquals( "Check checksum", "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar", + FileUtils.fileRead( checksumFile ).trim() ); + + assertFalse( "Check file not created", getChecksumFile( file, "md5" ).exists() ); + } + + public void testGetCorrectMd5NoSha1() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File checksumFile = getChecksumFile( file, "md5" ); + assertTrue( "Check file created", checksumFile.exists() ); + assertEquals( "Check checksum", "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar", + FileUtils.fileRead( checksumFile ).trim() ); + + assertFalse( "Check file not created", getChecksumFile( file, "sha1" ).exists() ); + } + + public void testGetCorrectMd5BadSha1() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File checksumFile = getChecksumFile( file, "md5" ); + assertTrue( "Check file created", checksumFile.exists() ); + assertEquals( "Check checksum", "8a02aa67549d27b2a03cd4547439c6d3 *get-checksum-md5-bad-sha1-1.0.jar", + FileUtils.fileRead( checksumFile ).trim() ); + + assertFalse( "Check file not created", getChecksumFile( file, "sha1" ).exists() ); + } + + public void testGetWithNoChecksums() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + assertFalse( "Check file not created", getChecksumFile( file, "md5" ).exists() ); + assertFalse( "Check file not created", getChecksumFile( file, "sha1" ).exists() ); + } + + public void testGetBadMd5BadSha1() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // expect a failure + assertFalse( "Check file not created", expectedFile.exists() ); + + assertFalse( "Check file not created", getChecksumFile( expectedFile, "md5" ).exists() ); + assertFalse( "Check file not created", getChecksumFile( expectedFile, "sha1" ).exists() ); + } + } + + public void testGetChecksumTransferFailed() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + proxiedRepository1 = createRepository( "proxied1", "test://..." ); + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository1 = createProxiedRepository( proxiedRepository1 ); + proxiedRepositories.add( proxiedArtifactRepository1 ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + + mockFailedChecksums( path, expectedFile ); + + wagonMockControl.replay(); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // as expected + wagonMockControl.verify(); + + assertFalse( "Check file not created", expectedFile.exists() ); + + assertFalse( "Check file not created", getChecksumFile( expectedFile, "md5" ).exists() ); + assertFalse( "Check file not created", getChecksumFile( expectedFile, "sha1" ).exists() ); + } + } + + public void testGetAlwaysBadChecksumPresentLocallyAbsentRemote() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + + assertFalse( "Check checksum removed", new File( file.getParentFile(), file.getName() + ".sha1" ).exists() ); + assertFalse( "Check checksum removed", new File( file.getParentFile(), file.getName() + ".md5" ).exists() ); + } + + public void testGetChecksumPresentInManagedRepo() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = + "org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetAlwaysChecksumPresentInManagedRepo() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = + "org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetChecksumNotPresentInManagedRepo() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar.sha1"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // expected + + assertFalse( expectedFile.exists() ); + } + } + + public void testGetAlwaysChecksumNotPresentInManagedRepo() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar.sha1"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + try + { + File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // expected + + assertFalse( expectedFile.exists() ); + } + } + + public void testGetMetadataNotPresent() + throws ProxyException, IOException + { + String path = "org/apache/maven/test/dummy-artifact/1.0/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // expected + + assertFalse( expectedFile.exists() ); + } + } + + public void testGetMetadataProxied() + throws ProxyException, ResourceDoesNotExistException, IOException + { + String path = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + String expectedContents = getExpectedMetadata( "get-default-metadata", "1.0" ); + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + } + + public void testGetMetadataMergeRepos() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org/apache/maven/test/get-merged-metadata/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + String expectedContents = getExpectedMetadata( "get-merged-metadata", getVersioning( + Arrays.asList( new String[]{"0.9", "1.0", "2.0", "3.0", "5.0", "4.0"} ) ) ); + + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + } + + public void testGetMetadataRemovedFromProxies() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-removed-metadata/1.0/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + } + + public void testGetReleaseMetadataNotExpired() + throws IOException, ResourceDoesNotExistException, ProxyException, ParseException + { + String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() ); + + proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); + proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + + String unexpectedContents = FileUtils.fileRead( new File( proxiedRepository1.getBasedir(), path ) ); + assertFalse( "Check content doesn't match proxy version", + unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetSnapshotMetadataNotExpired() + throws IOException, ResourceDoesNotExistException, ProxyException, ParseException + { + String path = "org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() ); + + proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + + String unexpectedContents = FileUtils.fileRead( new File( proxiedRepository1.getBasedir(), path ) ); + assertFalse( "Check content doesn't match proxy version", + unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetReleaseMetadataExpired() + throws IOException, ResourceDoesNotExistException, ProxyException, ParseException + { + String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() ); + + proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + String expectedContents = + getExpectedMetadata( "get-updated-metadata", getVersioning( Arrays.asList( new String[]{"1.0", "2.0"} ) ) ); + + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check content doesn't match proxy version", + unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetSnapshotMetadataExpired() + throws IOException, ResourceDoesNotExistException, ProxyException, ParseException + { + String path = "org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() ); + + proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); + proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + String expectedContents = + getExpectedMetadata( "get-updated-metadata", "1.0-SNAPSHOT", getVersioning( "20050831.111213", 2 ) ); + + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check content doesn't match proxy version", + unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetMetadataNotUpdated() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( proxiedFile.lastModified() ); + + proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check content doesn't match proxy version", + unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetMetadataUpdated() + throws IOException, ResourceDoesNotExistException, ProxyException, ParseException + { + String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + String expectedContents = + getExpectedMetadata( "get-updated-metadata", getVersioning( Arrays.asList( new String[]{"1.0", "2.0"} ) ) ); + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check content doesn't match old version", + unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetAlwaysMetadata() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + String expectedContents = + getExpectedMetadata( "get-updated-metadata", getVersioning( Arrays.asList( new String[]{"1.0", "2.0"} ) ) ); + + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check content doesn't match old version", + unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testSnapshotNonExistant() + throws ProxyException, IOException + { + String path = "org/apache/maven/test/does-not-exist/1.0-SNAPSHOT/does-not-exist-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "File returned was: " + file + "; should have got a not found exception" ); + } + catch ( ResourceDoesNotExistException e ) + { + // expected, but check file was not created + assertFalse( expectedFile.exists() ); + } + } + + public void testTimestampDrivenSnapshotNotPresentAlready() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = + "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + } + + public void testNewerTimestampDrivenSnapshotOnFirstRepo() + throws ResourceDoesNotExistException, ProxyException, IOException, ParseException + { + String path = + "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertTrue( expectedFile.exists() ); + + expectedFile.setLastModified( getPastDate().getTime() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + } + + public void testOlderTimestampDrivenSnapshotOnFirstRepo() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = + "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + expectedFile.setLastModified( getFutureDate().getTime() ); + + proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + +/* TODO: won't pass until Wagon preserves timestamp on download + public void testNewerTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready() + throws ResourceDoesNotExistException, ProxyException, IOException, ParseException + { + String path = + "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + File repoLocation = getTestFile( "target/test-repository/proxied1" ); + FileUtils.deleteDirectory( repoLocation ); + copyDirectoryStructure( getTestFile( "src/test/repositories/proxied1" ), repoLocation ); + proxiedRepository1 = createRepository( "proxied1", repoLocation ); + + new File( proxiedRepository1.getBasedir(), path ).setLastModified( getPastDate().getTime() ); + + proxiedRepositories.clear(); + proxiedRepositories.add( createProxiedRepository( proxiedRepository1 ) ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } +*/ + + public void testOlderTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready() + throws ParseException, ResourceDoesNotExistException, ProxyException, IOException + { + String path = + "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File repoLocation = getTestFile( "target/test-repository/proxied2" ); + FileUtils.deleteDirectory( repoLocation ); + copyDirectoryStructure( getTestFile( "src/test/repositories/proxied2" ), repoLocation ); + proxiedRepository2 = createRepository( "proxied2", repoLocation ); + + new File( proxiedRepository2.getBasedir(), path ).setLastModified( getPastDate().getTime() ); + + proxiedRepositories.clear(); + proxiedRepositories.add( createProxiedRepository( proxiedRepository1 ) ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testTimestampDrivenSnapshotNotExpired() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = + "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertTrue( expectedFile.exists() ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + proxiedFile.setLastModified( getFutureDate().getTime() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + String expectedContents = FileUtils.fileRead( expectedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testTimestampDrivenSnapshotNotUpdated() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = + "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + expectedFile.setLastModified( proxiedFile.lastModified() ); + + proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testTimestampDrivenSnapshotNotPresentAlreadyExpiredCacheFailure() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = + "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); + proxiedArtifactRepository.addFailure( path, ALWAYS_UPDATE_POLICY ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + assertFalse( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); + } + + public void testMetadataDrivenSnapshotNotPresentAlready() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = + "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + } + + public void testGetMetadataDrivenSnapshotRemoteUpdate() + throws ResourceDoesNotExistException, ProxyException, IOException, ParseException + { + // Metadata driven snapshots (using a full timestamp) are treated like a release. It is the timing of the + // updates to the metadata files that triggers which will be downloaded + + String path = + "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + expectedFile.setLastModified( getPastDate().getTime() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testLegacyManagedRepoGetNotPresent() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org.apache.maven.test/jars/get-default-layout-1.0.jar"; + File expectedFile = new File( legacyManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, legacyManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), + "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar" ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + // TODO: timestamp preservation requires support for that in wagon +// assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() ); + } + + public void testLegacyManagedRepoGetAlreadyPresent() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar"; + File expectedFile = new File( legacyManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + long originalModificationTime = expectedFile.lastModified(); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, legacyManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), + "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar" ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() ); + assertEquals( "Check file timestamp is that of original managed file", originalModificationTime, + file.lastModified() ); + } + + public void testLegacyProxyRepoGetNotPresent() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, legacyProxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = + new File( legacyProxiedRepository.getBasedir(), "org.apache.maven.test/jars/get-default-layout-1.0.jar" ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + // TODO: timestamp preservation requires support for that in wagon +// assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() ); + } + + public void testLegacyProxyRepoGetAlreadyPresent() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + long originalModificationTime = expectedFile.lastModified(); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.get( path, legacyProxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + File proxiedFile = new File( legacyProxiedRepository.getBasedir(), + "org.apache.maven.test/jars/get-default-layout-present-1.0.jar" ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() ); + assertEquals( "Check file timestamp is that of original managed file", originalModificationTime, + file.lastModified() ); + } + + public void testLegacyManagedAndProxyRepoGetNotPresent() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org.apache.maven.test/jars/get-default-layout-1.0.jar"; + File expectedFile = new File( legacyManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, legacyProxiedRepositories, legacyManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( legacyProxiedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + // TODO: timestamp preservation requires support for that in wagon +// assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() ); + } + + public void testLegacyManagedAndProxyRepoGetAlreadyPresent() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar"; + File expectedFile = new File( legacyManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + long originalModificationTime = expectedFile.lastModified(); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.get( path, legacyProxiedRepositories, legacyManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + File proxiedFile = new File( legacyProxiedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() ); + assertEquals( "Check file timestamp is that of original managed file", originalModificationTime, + file.lastModified() ); + } + + private static Versioning getVersioning( List versions ) + { + Versioning versioning = new Versioning(); + for ( Iterator i = versions.iterator(); i.hasNext(); ) + { + String v = (String) i.next(); + versioning.addVersion( v ); + } + return versioning; + } + + private static String getExpectedMetadata( String artifactId, Versioning versioning ) + throws IOException + { + return getExpectedMetadata( artifactId, null, versioning ); + } + + private static String getExpectedMetadata( String artifactId, String version, Versioning versioning ) + throws IOException + { + StringWriter expectedContents = new StringWriter(); + + Metadata m = new Metadata(); + m.setGroupId( "org.apache.maven.test" ); + m.setArtifactId( artifactId ); + m.setVersion( version ); + m.setVersioning( versioning ); + m.setModelEncoding( null ); + + new MetadataXpp3Writer().write( expectedContents, m ); + return expectedContents.toString(); + } + + private static String getExpectedMetadata( String artifactId, String version ) + throws IOException + { + return getExpectedMetadata( artifactId, version, null ); + } + + private static Versioning getVersioning( String timestamp, int buildNumber ) + { + Versioning versioning = new Versioning(); + versioning.setSnapshot( new Snapshot() ); + versioning.getSnapshot().setTimestamp( timestamp ); + versioning.getSnapshot().setBuildNumber( buildNumber ); + return versioning; + } + + private static Date getPastDate() + throws ParseException + { + return new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).parse( "2000-01-01" ); + } + + private static Date getFutureDate() + { + Calendar cal = Calendar.getInstance(); + cal.add( Calendar.YEAR, 1 ); + return cal.getTime(); + } + + private void mockFailedChecksums( String path, File expectedFile ) + throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException + { + // must do it twice as it will re-attempt it + wagonMock.get( path + ".sha1", new File( expectedFile.getParentFile(), expectedFile.getName() + ".sha1.tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMock.get( path + ".md5", new File( expectedFile.getParentFile(), expectedFile.getName() + ".md5.tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMock.get( path + ".sha1", new File( expectedFile.getParentFile(), expectedFile.getName() + ".sha1.tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMock.get( path + ".md5", new File( expectedFile.getParentFile(), expectedFile.getName() + ".md5.tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + } + + private File getChecksumFile( File file, String algorithm ) + { + return new File( file.getParentFile(), file.getName() + "." + algorithm ); + } + + /** + * A faster recursive copy that omits .svn directories. + * + * @param sourceDirectory the source directory to copy + * @param destDirectory the target location + * @throws java.io.IOException if there is a copying problem + * @todo get back into plexus-utils, share with converter module + */ + private static void copyDirectoryStructure( File sourceDirectory, File destDirectory ) + throws IOException + { + if ( !sourceDirectory.exists() ) + { + throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." ); + } + + File[] files = sourceDirectory.listFiles(); + + String sourcePath = sourceDirectory.getAbsolutePath(); + + for ( int i = 0; i < files.length; i++ ) + { + File file = files[i]; + + String dest = file.getAbsolutePath(); + + dest = dest.substring( sourcePath.length() + 1 ); + + File destination = new File( destDirectory, dest ); + + if ( file.isFile() ) + { + destination = destination.getParentFile(); + + FileUtils.copyFileToDirectory( file, destination ); + } + else if ( file.isDirectory() ) + { + if ( !".svn".equals( file.getName() ) ) + { + if ( !destination.exists() && !destination.mkdirs() ) + { + throw new IOException( + "Could not create destination directory '" + destination.getAbsolutePath() + "'." ); + } + + copyDirectoryStructure( file, destination ); + } + } + else + { + throw new IOException( "Unknown file type: " + file.getAbsolutePath() ); + } + } + } + + private static ProxiedArtifactRepository createProxiedRepository( ArtifactRepository repository ) + { + ProxiedArtifactRepository proxiedArtifactRepository = new ProxiedArtifactRepository( repository ); + proxiedArtifactRepository.setName( repository.getId() ); + proxiedArtifactRepository.setCacheFailures( true ); + return proxiedArtifactRepository; + } + + private static ProxiedArtifactRepository createHardFailProxiedRepository( ArtifactRepository repository ) + { + ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( repository ); + proxiedArtifactRepository.setHardFail( true ); + return proxiedArtifactRepository; + } + + private ArtifactRepository createRepository( String id, File repoLocation ) + throws MalformedURLException + { + return createRepository( id, repoLocation.toURI().toURL().toExternalForm() ); + } + + private ArtifactRepository createRepository( String id, File location, ArtifactRepositoryLayout layout ) + throws MalformedURLException + { + return createRepository( id, location.toURI().toURL().toExternalForm(), layout ); + } + + private ArtifactRepository createRepository( String id, String url ) + { + return createRepository( id, url, defaultLayout ); + } + + private ArtifactRepository createRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout ) + { + return factory.createArtifactRepository( id, url, repositoryLayout, null, null ); + } +} diff --git a/archiva-proxy/src/test/java/org/apache/maven/repository/proxy/WagonDelegate.java b/archiva-proxy/src/test/java/org/apache/maven/repository/proxy/WagonDelegate.java new file mode 100644 index 000000000..023195e4d --- /dev/null +++ b/archiva-proxy/src/test/java/org/apache/maven/repository/proxy/WagonDelegate.java @@ -0,0 +1,198 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.wagon.ConnectionException; +import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.apache.maven.wagon.TransferFailedException; +import org.apache.maven.wagon.Wagon; +import org.apache.maven.wagon.authentication.AuthenticationException; +import org.apache.maven.wagon.authentication.AuthenticationInfo; +import org.apache.maven.wagon.authorization.AuthorizationException; +import org.apache.maven.wagon.events.SessionListener; +import org.apache.maven.wagon.events.TransferListener; +import org.apache.maven.wagon.proxy.ProxyInfo; +import org.apache.maven.wagon.repository.Repository; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; + +/** + * A dummy wagon implementation + * + * @author Brett Porter + */ +public class WagonDelegate + implements Wagon +{ + private Wagon delegate; + + private String contentToGet; + + public void get( String resourceName, File destination ) + throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException + { + delegate.get( resourceName, destination ); + create( destination ); + } + + public boolean getIfNewer( String resourceName, File destination, long timestamp ) + throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException + { + boolean result = delegate.getIfNewer( resourceName, destination, timestamp ); + createIfMissing( destination ); + return result; + } + + public void put( File source, String destination ) + throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException + { + delegate.put( source, destination ); + } + + public void putDirectory( File sourceDirectory, String destinationDirectory ) + throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException + { + delegate.putDirectory( sourceDirectory, destinationDirectory ); + } + + public boolean supportsDirectoryCopy() + { + return delegate.supportsDirectoryCopy(); + } + + public Repository getRepository() + { + return delegate.getRepository(); + } + + public void connect( Repository source ) + throws ConnectionException, AuthenticationException + { + delegate.connect( source ); + } + + public void connect( Repository source, ProxyInfo proxyInfo ) + throws ConnectionException, AuthenticationException + { + delegate.connect( source, proxyInfo ); + } + + public void connect( Repository source, AuthenticationInfo authenticationInfo ) + throws ConnectionException, AuthenticationException + { + delegate.connect( source, authenticationInfo ); + } + + public void connect( Repository source, AuthenticationInfo authenticationInfo, ProxyInfo proxyInfo ) + throws ConnectionException, AuthenticationException + { + delegate.connect( source, authenticationInfo, proxyInfo ); + } + + public void openConnection() + throws ConnectionException, AuthenticationException + { + delegate.openConnection(); + } + + public void disconnect() + throws ConnectionException + { + delegate.disconnect(); + } + + public void addSessionListener( SessionListener listener ) + { + delegate.addSessionListener( listener ); + } + + public void removeSessionListener( SessionListener listener ) + { + delegate.removeSessionListener( listener ); + } + + public boolean hasSessionListener( SessionListener listener ) + { + return delegate.hasSessionListener( listener ); + } + + public void addTransferListener( TransferListener listener ) + { + delegate.addTransferListener( listener ); + } + + public void removeTransferListener( TransferListener listener ) + { + delegate.removeTransferListener( listener ); + } + + public boolean hasTransferListener( TransferListener listener ) + { + return delegate.hasTransferListener( listener ); + } + + public boolean isInteractive() + { + return delegate.isInteractive(); + } + + public void setInteractive( boolean interactive ) + { + delegate.setInteractive( interactive ); + } + + public void setDelegate( Wagon delegate ) + { + this.delegate = delegate; + } + + void setContentToGet( String content ) + { + contentToGet = content; + } + + private void createIfMissing( File destination ) + { + // since the mock won't actually copy a file, create an empty one to simulate file existence + if ( !destination.exists() ) + { + create( destination ); + } + } + + private void create( File destination ) + { + try + { + destination.getParentFile().mkdirs(); + if ( contentToGet == null ) + { + destination.createNewFile(); + } + else + { + FileUtils.fileWrite( destination.getAbsolutePath(), contentToGet ); + } + } + catch ( IOException e ) + { + throw new RuntimeException( e.getMessage(), e ); + } + } +} diff --git a/archiva-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/get-default-layout-present-1.0.jar b/archiva-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/get-default-layout-present-1.0.jar new file mode 100644 index 000000000..bf26f6b57 --- /dev/null +++ b/archiva-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/get-default-layout-present-1.0.jar @@ -0,0 +1,2 @@ +get-default-layout-present-1.0.jar +(managed) diff --git a/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-1.0.jar b/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-1.0.jar new file mode 100644 index 000000000..77dbb7858 --- /dev/null +++ b/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-1.0.jar @@ -0,0 +1 @@ +get-default-layout-1.0.jar diff --git a/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-present-1.0.jar b/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-present-1.0.jar new file mode 100644 index 000000000..9f4121a86 --- /dev/null +++ b/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-present-1.0.jar @@ -0,0 +1,2 @@ +get-default-layout-present-1.0.jar +(proxied) diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar new file mode 100644 index 000000000..62a1e1c71 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar @@ -0,0 +1,3 @@ +get-bad-local-checksum-1.0.jar +(managed) + diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.md5 b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.md5 new file mode 100644 index 000000000..5fd0ae2b7 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.md5 @@ -0,0 +1 @@ +invalid checksum file \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.sha1 new file mode 100644 index 000000000..5fd0ae2b7 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.sha1 @@ -0,0 +1 @@ +invalid checksum file \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 new file mode 100644 index 000000000..de9618d2f --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 @@ -0,0 +1 @@ +066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-from-managed-repo-1.0.jar diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar new file mode 100644 index 000000000..a3b38382c --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar @@ -0,0 +1,3 @@ +get-default-layout-present-1.0.jar +(managed) + diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-merged-metadata/maven-metadata.xml b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-merged-metadata/maven-metadata.xml new file mode 100644 index 000000000..8404eb8a9 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-merged-metadata/maven-metadata.xml @@ -0,0 +1,30 @@ + + + + org.apache.maven.test + get-merged-metadata + + + 0.9 + + 1.0 + + 2.0 + + + + \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar new file mode 100644 index 000000000..b71eb7b74 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar @@ -0,0 +1,2 @@ +get-present-metadata-snapshot-1.0-20050831.101112-1.jar +(managed) \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar new file mode 100644 index 000000000..0c2d93e3c --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar @@ -0,0 +1,2 @@ +get-present-timestamped-snapshot-1.0-SNAPSHOT.jar +(managed) \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-from-proxies/1.0/get-removed-from-proxies-1.0.jar b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-from-proxies/1.0/get-removed-from-proxies-1.0.jar new file mode 100644 index 000000000..54dc5ee86 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-from-proxies/1.0/get-removed-from-proxies-1.0.jar @@ -0,0 +1,3 @@ +get-removed-from-proxies-1.0.jar +(managed) + diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-metadata/1.0/maven-metadata.xml b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-metadata/1.0/maven-metadata.xml new file mode 100644 index 000000000..7bd77c137 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-metadata/1.0/maven-metadata.xml @@ -0,0 +1,19 @@ + + + + + \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/.metadata-proxied1 b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/.metadata-proxied1 new file mode 100644 index 000000000..76b43d62a --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/.metadata-proxied1 @@ -0,0 +1,25 @@ + + + + org.apache.maven.test + get-updated-metadata + + + 1.0 + + + diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/.metadata-proxied1 b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/.metadata-proxied1 new file mode 100644 index 000000000..6354f21bc --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/.metadata-proxied1 @@ -0,0 +1,27 @@ + + + + org.apache.maven.test + get-updated-metadata + 1.0-SNAPSHOT + + + 20050831.1011112 + 1 + + + \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml new file mode 100644 index 000000000..cd7216a64 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml @@ -0,0 +1,27 @@ + + + + org.apache.maven.test + get-updated-metadata + 1.0-SNAPSHOT + + + 20050831.1011112 + 1 + + + \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/maven-metadata.xml b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/maven-metadata.xml new file mode 100644 index 000000000..5cd8af101 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/maven-metadata.xml @@ -0,0 +1,25 @@ + + + + org.apache.maven.test + get-updated-metadata + + + 1.0 + + + \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar new file mode 100644 index 000000000..b5d8045c9 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar @@ -0,0 +1,3 @@ +get-bad-local-checksum-1.0.jar +(proxied 1) + diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar new file mode 100644 index 000000000..98fae8093 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar @@ -0,0 +1,2 @@ +get-checksum-both-bad-1.0.jar + diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.md5 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.md5 new file mode 100644 index 000000000..5fd0ae2b7 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.md5 @@ -0,0 +1 @@ +invalid checksum file \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.sha1 new file mode 100644 index 000000000..a2d3f29ea --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.sha1 @@ -0,0 +1 @@ +invalid checksum file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar new file mode 100644 index 000000000..7fa9ec4a0 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar @@ -0,0 +1 @@ +get-checksum-both-right-1.0.jar diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.md5 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.md5 new file mode 100644 index 000000000..9b9e3374c --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.md5 @@ -0,0 +1 @@ +e58f30c6a150a2e843552438d18e15cb *get-checksum-both-right-1.0.jar \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.sha1 new file mode 100644 index 000000000..cdd9a336b --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.sha1 @@ -0,0 +1 @@ +066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-both-right-1.0.jar diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 new file mode 100644 index 000000000..8fc645ca3 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 @@ -0,0 +1,2 @@ +066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-from-managed-repo-1.0.jar +(proxied 1) diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar new file mode 100644 index 000000000..68e3480fc --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar @@ -0,0 +1,2 @@ +get-checksum-md5-bad-sha1-1.0.jar + diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.md5 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.md5 new file mode 100644 index 000000000..d785caa7f --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.md5 @@ -0,0 +1 @@ +8a02aa67549d27b2a03cd4547439c6d3 *get-checksum-md5-bad-sha1-1.0.jar \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.sha1 new file mode 100644 index 000000000..a2d3f29ea --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.sha1 @@ -0,0 +1 @@ +invalid checksum file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar new file mode 100644 index 000000000..915323d0e --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar @@ -0,0 +1,2 @@ +get-checksum-md5-only-1.0.jar + diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar.md5 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar.md5 new file mode 100644 index 000000000..f5ecac3db --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar.md5 @@ -0,0 +1 @@ +f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar new file mode 100644 index 000000000..f02c91843 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar @@ -0,0 +1,2 @@ +get-checksum-sha1-bad-md5-1.0.jar + diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.md5 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.md5 new file mode 100644 index 000000000..a2d3f29ea --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.md5 @@ -0,0 +1 @@ +invalid checksum file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.sha1 new file mode 100644 index 000000000..425623525 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.sha1 @@ -0,0 +1 @@ +3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar new file mode 100644 index 000000000..efd9ed015 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar @@ -0,0 +1,2 @@ +get-checksum-sha1-only-1.0.jar + diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar.sha1 new file mode 100644 index 000000000..e64dccfd8 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar.sha1 @@ -0,0 +1 @@ +748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar new file mode 100644 index 000000000..15fd36d5d --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar @@ -0,0 +1,3 @@ +get-default-layout-present-1.0.jar +(proxied 1) + diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar new file mode 100644 index 000000000..a129891a7 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar @@ -0,0 +1,2 @@ +get-default-layout-1.0.jar + diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml new file mode 100644 index 000000000..7855530fb --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml @@ -0,0 +1,21 @@ + + + + org.apache.maven.test + get-default-metadata + 1.0 + \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar new file mode 100644 index 000000000..3cc35fa29 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar @@ -0,0 +1,3 @@ +get-in-both-proxies-1.0.jar +(proxied 1) + diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-merged-metadata/maven-metadata.xml b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-merged-metadata/maven-metadata.xml new file mode 100644 index 000000000..f697f68a9 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-merged-metadata/maven-metadata.xml @@ -0,0 +1,30 @@ + + + + org.apache.maven.test + get-merged-metadata + + + 2.0 + + 3.0 + + 5.0 + + + + \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar new file mode 100644 index 000000000..139c17b97 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar @@ -0,0 +1 @@ +get-metadata-snapshot-1.0-SNAPSHOT.jar \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar new file mode 100644 index 000000000..8bbffa00f --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar @@ -0,0 +1,2 @@ +get-present-metadata-snapshot-1.0-20050831.101112-1.jar +(proxied 1) \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar new file mode 100644 index 000000000..0bf178413 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar @@ -0,0 +1,2 @@ +get-present-timestamped-snapshot-1.0-SNAPSHOT.jar +(proxied 1) \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar new file mode 100644 index 000000000..dfacfaa15 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar @@ -0,0 +1,2 @@ +get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar +(proxied 1) \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar new file mode 100644 index 000000000..af86df92f --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar @@ -0,0 +1 @@ +get-timestamped-snapshot-1.0-SNAPSHOT.jar \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml new file mode 100644 index 000000000..67a3c6206 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml @@ -0,0 +1,27 @@ + + + + org.apache.maven.test + get-updated-metadata + 1.0-SNAPSHOT + + + 20050831.111213 + 2 + + + \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/maven-metadata.xml b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/maven-metadata.xml new file mode 100644 index 000000000..27c44b418 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/maven-metadata.xml @@ -0,0 +1,26 @@ + + + + org.apache.maven.test + get-updated-metadata + + + 1.0 + 2.0 + + + \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar new file mode 100644 index 000000000..e46d60ac3 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar @@ -0,0 +1,3 @@ +get-in-both-proxies-1.0.jar +(proxied 2) + diff --git a/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar new file mode 100644 index 000000000..3460f656d --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar @@ -0,0 +1,2 @@ +get-in-second-proxy-1.0.jar + diff --git a/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-merged-metadata/maven-metadata.xml b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-merged-metadata/maven-metadata.xml new file mode 100644 index 000000000..5a7a94818 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-merged-metadata/maven-metadata.xml @@ -0,0 +1,30 @@ + + + + org.apache.maven.test + get-merged-metadata + + + 1.0 + + 3.0 + + 4.0 + + + + \ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar new file mode 100644 index 000000000..915b2b22c --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar @@ -0,0 +1,2 @@ +get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar +(proxied 2) \ No newline at end of file diff --git a/archiva-proxy/src/test/resources/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.xml b/archiva-proxy/src/test/resources/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.xml new file mode 100644 index 000000000..a3a47dbbe --- /dev/null +++ b/archiva-proxy/src/test/resources/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.xml @@ -0,0 +1,34 @@ + + + + + + org.apache.maven.wagon.Wagon + test + org.apache.maven.repository.proxy.WagonDelegate + + + org.codehaus.plexus.logging.LoggerManager + org.codehaus.plexus.logging.console.ConsoleLoggerManager + basic + + + ERROR + + + + diff --git a/archiva-reports-standard/pom.xml b/archiva-reports-standard/pom.xml new file mode 100755 index 000000000..f6d85a9ba --- /dev/null +++ b/archiva-reports-standard/pom.xml @@ -0,0 +1,69 @@ + + + + + org.apache.maven.archiva + archiva + 1.0-SNAPSHOT + + 4.0.0 + archiva-reports-standard + Archiva Standard Reports + + + org.codehaus.plexus + plexus-utils + + + org.codehaus.plexus + plexus-container-default + + + org.apache.maven + maven-artifact + + + org.apache.maven + maven-artifact-manager + + + org.apache.maven + maven-model + + + org.apache.maven + maven-repository-metadata + + + org.apache.maven.wagon + wagon-provider-api + + + org.apache.maven + maven-artifact-manager + + + org.apache.maven.archiva + archiva-utils + + + org.apache.maven.archiva + archiva-indexer + + + diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java new file mode 100644 index 000000000..997597c77 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java @@ -0,0 +1,106 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Metadata; +import org.apache.maven.artifact.repository.metadata.Snapshot; +import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.List; + +/** + * + */ +public abstract class AbstractRepositoryQueryLayer + implements RepositoryQueryLayer +{ + protected ArtifactRepository repository; + + public boolean containsArtifact( Artifact artifact ) + { + File f = new File( repository.getBasedir(), repository.pathOf( artifact ) ); + return f.exists(); + } + + public boolean containsArtifact( Artifact artifact, Snapshot snapshot ) + { + String artifactPath = getSnapshotArtifactRepositoryPath( artifact, snapshot ); + File artifactFile = new File( artifactPath ); + return artifactFile.exists(); + } + + public List getVersions( Artifact artifact ) + throws RepositoryQueryLayerException + { + Metadata metadata = getMetadata( artifact ); + + return metadata.getVersioning().getVersions(); + } + + protected String getSnapshotArtifactRepositoryPath( Artifact artifact, Snapshot snapshot ) + { + File f = new File( repository.getBasedir(), repository.pathOf( artifact ) ); + String snapshotInfo = artifact.getVersion().replaceFirst( "SNAPSHOT", snapshot.getTimestamp() + "-" + + snapshot.getBuildNumber() + ".pom" ); + File snapshotFile = new File( f.getParentFile(), artifact.getArtifactId() + "-" + snapshotInfo ); + return snapshotFile.getAbsolutePath(); + } + + protected Metadata getMetadata( Artifact artifact ) + throws RepositoryQueryLayerException + { + Metadata metadata; + + ArtifactRepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact ); + String path = repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ); + File metadataFile = new File( repository.getBasedir(), path ); + if ( metadataFile.exists() ) + { + MetadataXpp3Reader reader = new MetadataXpp3Reader(); + try + { + metadata = reader.read( new FileReader( metadataFile ) ); + } + catch ( FileNotFoundException e ) + { + throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e ); + } + catch ( IOException e ) + { + throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e ); + } + catch ( XmlPullParserException e ) + { + throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e ); + } + } + else + { + throw new RepositoryQueryLayerException( "Metadata not found: " + metadataFile.getAbsolutePath() ); + } + + return metadata; + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java new file mode 100644 index 000000000..773b2c7f5 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java @@ -0,0 +1,34 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Model; + +/** + * This interface will be called by the main system for each artifact as it is discovered. This is how each of the + * different types of reports are implemented. + */ +public interface ArtifactReportProcessor +{ + String ROLE = ArtifactReportProcessor.class.getName(); + + void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, ArtifactRepository repository ) + throws ReportProcessorException; + +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java new file mode 100644 index 000000000..a48476491 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java @@ -0,0 +1,88 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; + +import java.util.Iterator; + +/** + * This interface is used by the single artifact processor. + *

+ * The initial implementation of this will just need to be a mock implementation in src/test/java, used to track the + * failures and successes for checking assertions. Later, implementations will be made to present reports on the + * web interface, send them via mail, and so on. + * + * @todo i18n + */ +public interface ArtifactReporter +{ + String ROLE = ArtifactReporter.class.getName(); + + String NULL_MODEL = "Provided model was null"; + + String NULL_ARTIFACT = "Provided artifact was null"; + + String EMPTY_GROUP_ID = "Group id was empty or null"; + + String EMPTY_ARTIFACT_ID = "Artifact id was empty or null"; + + String EMPTY_VERSION = "Version was empty or null"; + + String EMPTY_DEPENDENCY_GROUP_ID = "Group id was empty or null"; + + String EMPTY_DEPENDENCY_ARTIFACT_ID = "Artifact id was empty or null"; + + String EMPTY_DEPENDENCY_VERSION = "Version was empty or null"; + + String NO_DEPENDENCIES = "Artifact has no dependencies"; + + String ARTIFACT_NOT_FOUND = "Artifact does not exist in the repository"; + + String DEPENDENCY_NOT_FOUND = "Artifact's dependency does not exist in the repository"; + + void addFailure( Artifact artifact, String reason ); + + void addSuccess( Artifact artifact ); + + void addWarning( Artifact artifact, String message ); + + void addFailure( RepositoryMetadata metadata, String reason ); + + void addSuccess( RepositoryMetadata metadata ); + + void addWarning( RepositoryMetadata metadata, String message ); + + Iterator getArtifactFailureIterator(); + + Iterator getArtifactSuccessIterator(); + + Iterator getArtifactWarningIterator(); + + Iterator getRepositoryMetadataFailureIterator(); + + Iterator getRepositoryMetadataSuccessIterator(); + + Iterator getRepositoryMetadataWarningIterator(); + + int getFailures(); + + int getSuccesses(); + + int getWarnings(); +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java new file mode 100644 index 000000000..6c0aba900 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java @@ -0,0 +1,54 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; + +/** + * A result of the report for a given artifact being processed. + * + * @author Brett Porter + * @version $Id$ + */ +public class ArtifactResult +{ + private final Artifact artifact; + + private final String reason; + + public ArtifactResult( Artifact artifact ) + { + this.artifact = artifact; + this.reason = null; + } + + public ArtifactResult( Artifact artifact, String reason ) + { + this.artifact = artifact; + this.reason = reason; + } + + public Artifact getArtifact() + { + return artifact; + } + + public String getReason() + { + return reason; + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java new file mode 100644 index 000000000..fdba18d39 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java @@ -0,0 +1,330 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.metadata.Plugin; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Snapshot; +import org.apache.maven.artifact.repository.metadata.Versioning; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * This class will report on bad metadata files. These include invalid version declarations and incomplete version + * information inside the metadata file. Plugin metadata will be checked for validity of the latest plugin artifacts. + * + * @plexus.component role="org.apache.maven.repository.reporting.MetadataReportProcessor" role-hint="bad-metadata" + */ +public class BadMetadataReportProcessor + implements MetadataReportProcessor +{ + /** + * @plexus.requirement + */ + private ArtifactFactory artifactFactory; + + /** + * @plexus.requirement + */ + private RepositoryQueryLayerFactory repositoryQueryLayerFactory; + + /** + * Process the metadata encountered in the repository and report all errors found, if any. + * + * @param metadata the metadata to be processed. + * @param repository the repository where the metadata was encountered + * @param reporter the ArtifactReporter to receive processing results + * @throws ReportProcessorException if an error was occurred while processing the metadata + */ + public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter ) + throws ReportProcessorException + { + boolean hasFailures = false; + + if ( metadata.storedInGroupDirectory() ) + { + try + { + hasFailures = checkPluginMetadata( metadata, repository, reporter ); + } + catch ( IOException e ) + { + throw new ReportProcessorException( "Error getting plugin artifact directories versions", e ); + } + } + else + { + String lastUpdated = metadata.getMetadata().getVersioning().getLastUpdated(); + if ( lastUpdated == null || lastUpdated.length() == 0 ) + { + reporter.addFailure( metadata, "Missing lastUpdated element inside the metadata." ); + hasFailures = true; + } + + if ( metadata.storedInArtifactVersionDirectory() ) + { + hasFailures |= checkSnapshotMetadata( metadata, repository, reporter ); + } + else + { + if ( !checkMetadataVersions( metadata, repository, reporter ) ) + { + hasFailures = true; + } + + try + { + if ( checkRepositoryVersions( metadata, repository, reporter ) ) + { + hasFailures = true; + } + } + catch ( IOException e ) + { + throw new ReportProcessorException( "Error getting versions", e ); + } + } + } + + if ( !hasFailures ) + { + reporter.addSuccess( metadata ); + } + } + + /** + * Method for processing a GroupRepositoryMetadata + * + * @param metadata the metadata to be processed. + * @param repository the repository where the metadata was encountered + * @param reporter the ArtifactReporter to receive processing results + */ + private boolean checkPluginMetadata( RepositoryMetadata metadata, ArtifactRepository repository, + ArtifactReporter reporter ) + throws IOException + { + boolean hasFailures = false; + + File metadataDir = + new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( metadata ) ).getParentFile(); + List pluginDirs = getArtifactIdFiles( metadataDir ); + + Map prefixes = new HashMap(); + for ( Iterator plugins = metadata.getMetadata().getPlugins().iterator(); plugins.hasNext(); ) + { + Plugin plugin = (Plugin) plugins.next(); + + String artifactId = plugin.getArtifactId(); + if ( artifactId == null || artifactId.length() == 0 ) + { + reporter.addFailure( metadata, "Missing or empty artifactId in group metadata." ); + hasFailures = true; + } + + String prefix = plugin.getPrefix(); + if ( prefix == null || prefix.length() == 0 ) + { + reporter.addFailure( metadata, "Missing or empty plugin prefix for artifactId " + artifactId + "." ); + hasFailures = true; + } + else + { + if ( prefixes.containsKey( prefix ) ) + { + reporter.addFailure( metadata, "Duplicate plugin prefix found: " + prefix + "." ); + hasFailures = true; + } + else + { + prefixes.put( prefix, plugin ); + } + } + + if ( artifactId != null && artifactId.length() > 0 ) + { + File pluginDir = new File( metadataDir, artifactId ); + if ( !pluginDirs.contains( pluginDir ) ) + { + reporter.addFailure( metadata, "Metadata plugin " + artifactId + " not found in the repository" ); + hasFailures = true; + } + else + { + pluginDirs.remove( pluginDir ); + } + } + } + + if ( pluginDirs.size() > 0 ) + { + for ( Iterator plugins = pluginDirs.iterator(); plugins.hasNext(); ) + { + File plugin = (File) plugins.next(); + reporter.addFailure( metadata, "Plugin " + plugin.getName() + " is present in the repository but " + + "missing in the metadata." ); + } + hasFailures = true; + } + + return hasFailures; + } + + /** + * Method for processing a SnapshotArtifactRepository + * + * @param metadata the metadata to be processed. + * @param repository the repository where the metadata was encountered + * @param reporter the ArtifactReporter to receive processing results + */ + private boolean checkSnapshotMetadata( RepositoryMetadata metadata, ArtifactRepository repository, + ArtifactReporter reporter ) + { + RepositoryQueryLayer repositoryQueryLayer = + repositoryQueryLayerFactory.createRepositoryQueryLayer( repository ); + + boolean hasFailures = false; + + Snapshot snapshot = metadata.getMetadata().getVersioning().getSnapshot(); + String timestamp = snapshot.getTimestamp(); + String buildNumber = String.valueOf( snapshot.getBuildNumber() ); + + Artifact artifact = createArtifact( metadata ); + if ( !repositoryQueryLayer.containsArtifact( artifact, snapshot ) ) + { + reporter.addFailure( metadata, "Snapshot artifact " + timestamp + "-" + buildNumber + " does not exist." ); + hasFailures = true; + } + + return hasFailures; + } + + /** + * Method for validating the versions declared inside an ArtifactRepositoryMetadata + * + * @param metadata the metadata to be processed. + * @param repository the repository where the metadata was encountered + * @param reporter the ArtifactReporter to receive processing results + */ + private boolean checkMetadataVersions( RepositoryMetadata metadata, ArtifactRepository repository, + ArtifactReporter reporter ) + { + RepositoryQueryLayer repositoryQueryLayer = + repositoryQueryLayerFactory.createRepositoryQueryLayer( repository ); + + boolean hasFailures = false; + Versioning versioning = metadata.getMetadata().getVersioning(); + for ( Iterator versions = versioning.getVersions().iterator(); versions.hasNext(); ) + { + String version = (String) versions.next(); + + Artifact artifact = createArtifact( metadata, version ); + + if ( !repositoryQueryLayer.containsArtifact( artifact ) ) + { + reporter.addFailure( metadata, "Artifact version " + version + " is present in metadata but " + + "missing in the repository." ); + hasFailures = true; + } + } + return hasFailures; + } + + /** + * Searches the artifact repository directory for all versions and verifies that all of them are listed in the + * ArtifactRepositoryMetadata + * + * @param metadata the metadata to be processed. + * @param repository the repository where the metadata was encountered + * @param reporter the ArtifactReporter to receive processing results + */ + private boolean checkRepositoryVersions( RepositoryMetadata metadata, ArtifactRepository repository, + ArtifactReporter reporter ) + throws IOException + { + boolean hasFailures = false; + Versioning versioning = metadata.getMetadata().getVersioning(); + File versionsDir = + new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( metadata ) ).getParentFile(); + List versions = FileUtils.getFileNames( versionsDir, "*/*.pom", null, false ); + for ( Iterator i = versions.iterator(); i.hasNext(); ) + { + File path = new File( (String) i.next() ); + String version = path.getParentFile().getName(); + if ( !versioning.getVersions().contains( version ) ) + { + reporter.addFailure( metadata, "Artifact version " + version + " found in the repository but " + + "missing in the metadata." ); + hasFailures = true; + } + } + return hasFailures; + } + + /** + * Used to create an artifact object from a metadata base version + */ + private Artifact createArtifact( RepositoryMetadata metadata ) + { + return artifactFactory.createBuildArtifact( metadata.getGroupId(), metadata.getArtifactId(), + metadata.getBaseVersion(), "pom" ); + } + + /** + * Used to create an artifact object with a specified version + */ + private Artifact createArtifact( RepositoryMetadata metadata, String version ) + { + return artifactFactory.createBuildArtifact( metadata.getGroupId(), metadata.getArtifactId(), version, "pom" ); + } + + /** + * Used to gather artifactIds from a groupId directory + */ + private List getArtifactIdFiles( File groupIdDir ) + throws IOException + { + List artifactIdFiles = new ArrayList(); + + List fileArray = new ArrayList( Arrays.asList( groupIdDir.listFiles() ) ); + for ( Iterator files = fileArray.iterator(); files.hasNext(); ) + { + File artifactDir = (File) files.next(); + + if ( artifactDir.isDirectory() ) + { + List versions = FileUtils.getFileNames( artifactDir, "*/*.pom", null, false ); + if ( versions.size() > 0 ) + { + artifactIdFiles.add( artifactDir ); + } + } + } + + return artifactIdFiles; + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java new file mode 100644 index 000000000..8f695f91d --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java @@ -0,0 +1,221 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Class to implement caching. + */ +public class Cache +{ + private final Map cache; + + private final double cacheHitRatio; + + private final int cacheMaxSize; + + private long cacheHits; + + private long cacheMiss; + + /** + * Caches all data and expires only the oldest data when the specified cache hit rate is reached. + */ + public Cache( double cacheHitRatio ) + { + this( cacheHitRatio, 0 ); + } + + /** + * Caches all data and expires only the oldest data when the maximum cache size is reached + */ + public Cache( int cacheMaxSize ) + { + this( (double) 1, cacheMaxSize ); + } + + /** + * Caches all data and expires only the oldest data when either the specified cache hit rate is reached + * or the maximum cache size is reached. + */ + public Cache( double cacheHitRatio, int cacheMaxSize ) + { + this.cacheHitRatio = cacheHitRatio; + this.cacheMaxSize = cacheMaxSize; + + if ( cacheMaxSize > 0 ) + { + cache = new LinkedHashMap( cacheMaxSize ); + } + else + { + cache = new LinkedHashMap(); + } + } + + /** + * Check if the specified key is already mapped to an object. + * + * @param key the key used to map the cached object + * @return true if the cache contains an object associated with the given key + */ + public boolean containsKey( Object key ) + { + boolean contains; + synchronized ( cache ) + { + contains = cache.containsKey( key ); + + if ( contains ) + { + cacheHits++; + } + else + { + cacheMiss++; + } + } + + return contains; + } + + /** + * Check for a cached object and return it if it exists. Returns null when the keyed object is not found + * + * @param key the key used to map the cached object + * @return the object mapped to the given key, or null if no cache object is mapped to the given key + */ + public Object get( Object key ) + { + Object retValue = null; + + synchronized ( cache ) + { + if ( cache.containsKey( key ) ) + { + // remove and put: this promotes it to the top since we use a linked hash map + retValue = cache.remove( key ); + + cache.put( key, retValue ); + + cacheHits++; + } + else + { + cacheMiss++; + } + } + + return retValue; + } + + /** + * Cache the given value and map it using the given key + * + * @param key the object to map the valued object + * @param value the object to cache + */ + public void put( Object key, Object value ) + { + // remove and put: this promotes it to the top since we use a linked hash map + synchronized ( cache ) + { + if ( cache.containsKey( key ) ) + { + cache.remove( key ); + } + + cache.put( key, value ); + } + + manageCache(); + } + + /** + * Compute for the efficiency of this cache. + * + * @return the ratio of cache hits to the cache misses to queries for cache objects + */ + public double getHitRate() + { + synchronized ( cache ) + { + return cacheHits == 0 && cacheMiss == 0 ? 0 : (double) cacheHits / (double) ( cacheHits + cacheMiss ); + } + } + + /** + * Get the total number of cache objects currently cached. + */ + public int size() + { + return cache.size(); + } + + /** + * Empty the cache and reset the cache hit rate + */ + public void clear() + { + synchronized ( cache ) + { + cacheHits = 0; + cacheMiss = 0; + cache.clear(); + } + } + + private void manageCache() + { + synchronized ( cache ) + { + Iterator iterator = cache.entrySet().iterator(); + if ( cacheMaxSize == 0 ) + { + //desired HitRatio is reached, we can trim the cache to conserve memory + if ( cacheHitRatio <= getHitRate() ) + { + iterator.next(); + iterator.remove(); + } + } + else if ( cache.size() > cacheMaxSize ) + { + // maximum cache size is reached + while ( cache.size() > cacheMaxSize ) + { + iterator.next(); + iterator.remove(); + } + } + else + { + //even though the max has not been reached, the desired HitRatio is already reached, + // so we can trim the cache to conserve memory + if ( cacheHitRatio <= getHitRate() ) + { + iterator.next(); + iterator.remove(); + } + } + } + } + +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java new file mode 100644 index 000000000..b0c1eac27 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java @@ -0,0 +1,99 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.metadata.Metadata; +import org.apache.maven.artifact.repository.metadata.Snapshot; + + +/** + * + */ +public class CachedRepositoryQueryLayer + extends AbstractRepositoryQueryLayer +{ + private Cache cache; + + public static final double CACHE_HIT_RATIO = 0.5; + + public CachedRepositoryQueryLayer( ArtifactRepository repository ) + { + this.repository = repository; + + cache = new Cache( CACHE_HIT_RATIO ); + } + + public double getCacheHitRate() + { + return cache.getHitRate(); + } + + public boolean containsArtifact( Artifact artifact ) + { + boolean artifactFound = true; + + String artifactPath = repository.getBasedir() + "/" + repository.pathOf( artifact ); + + if ( cache.get( artifactPath ) == null ) + { + artifactFound = super.containsArtifact( artifact ); + if ( artifactFound ) + { + cache.put( artifactPath, artifactPath ); + } + } + + return artifactFound; + } + + public boolean containsArtifact( Artifact artifact, Snapshot snapshot ) + { + boolean artifactFound = true; + + String path = getSnapshotArtifactRepositoryPath( artifact, snapshot ); + + if ( cache.get( path ) == null ) + { + artifactFound = super.containsArtifact( artifact, snapshot ); + if ( artifactFound ) + { + cache.put( path, path ); + } + } + + return artifactFound; + } + + /** + * Override method to utilize the cache + */ + protected Metadata getMetadata( Artifact artifact ) + throws RepositoryQueryLayerException + { + Metadata metadata = (Metadata) cache.get( artifact.getId() ); + + if ( metadata == null ) + { + metadata = super.getMetadata( artifact ); + cache.put( artifact.getId(), metadata ); + } + + return metadata; + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java new file mode 100644 index 000000000..51b4a8772 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java @@ -0,0 +1,100 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Model; +import org.apache.maven.repository.digest.Digester; +import org.apache.maven.repository.digest.DigesterException; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; + +/** + * This class reports invalid and mismatched checksums of artifacts and metadata files. + * It validates MD5 and SHA-1 checksums. + * + * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="checksum" + */ +public class ChecksumArtifactReporter + implements ArtifactReportProcessor +{ + /** + * @plexus.requirement role-hint="sha1" + */ + private Digester sha1Digester; + + /** + * @plexus.requirement role-hint="md5" + */ + private Digester md5Digester; + + /** + * Validate the checksum of the specified artifact. + * + * @param model + * @param artifact + * @param reporter + * @param repository + */ + public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, + ArtifactRepository repository ) + { + if ( !"file".equals( repository.getProtocol() ) ) + { + // We can't check other types of URLs yet. Need to use Wagon, with an exists() method. + throw new UnsupportedOperationException( + "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" ); + } + + //check if checksum files exist + String path = repository.pathOf( artifact ); + File file = new File( repository.getBasedir(), path ); + + verifyChecksum( repository, path + ".md5", file, md5Digester, reporter, artifact ); + verifyChecksum( repository, path + ".sha1", file, sha1Digester, reporter, artifact ); + } + + private void verifyChecksum( ArtifactRepository repository, String path, File file, Digester digester, + ArtifactReporter reporter, Artifact artifact ) + { + File checksumFile = new File( repository.getBasedir(), path ); + if ( checksumFile.exists() ) + { + try + { + digester.verify( file, FileUtils.fileRead( checksumFile ) ); + + reporter.addSuccess( artifact ); + } + catch ( DigesterException e ) + { + reporter.addFailure( artifact, e.getMessage() ); + } + catch ( IOException e ) + { + reporter.addFailure( artifact, "Read file error: " + e.getMessage() ); + } + } + else + { + reporter.addFailure( artifact, digester.getAlgorithm() + " checksum file does not exist." ); + } + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumMetadataReporter.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumMetadataReporter.java new file mode 100644 index 000000000..df732f656 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumMetadataReporter.java @@ -0,0 +1,96 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.apache.maven.repository.digest.Digester; +import org.apache.maven.repository.digest.DigesterException; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; + +/** + * This class reports invalid and mismatched checksums of artifacts and metadata files. + * It validates MD5 and SHA-1 checksums. + * + * @plexus.component role="org.apache.maven.repository.reporting.MetadataReportProcessor" role-hint="checksum-metadata" + */ +public class ChecksumMetadataReporter + implements MetadataReportProcessor +{ + /** + * @plexus.requirement role-hint="sha1" + */ + private Digester sha1Digester; + + /** + * @plexus.requirement role-hint="md5" + */ + private Digester md5Digester; + + /** + * Validate the checksums of the metadata. Get the metadata file from the + * repository then validate the checksum. + */ + public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter ) + { + if ( !"file".equals( repository.getProtocol() ) ) + { + // We can't check other types of URLs yet. Need to use Wagon, with an exists() method. + throw new UnsupportedOperationException( + "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" ); + } + + //check if checksum files exist + String path = repository.pathOfRemoteRepositoryMetadata( metadata ); + File file = new File( repository.getBasedir(), path ); + + verifyChecksum( repository, path + ".md5", file, md5Digester, reporter, metadata ); + verifyChecksum( repository, path + ".sha1", file, sha1Digester, reporter, metadata ); + + } + + private void verifyChecksum( ArtifactRepository repository, String path, File file, Digester digester, + ArtifactReporter reporter, RepositoryMetadata metadata ) + { + File checksumFile = new File( repository.getBasedir(), path ); + if ( checksumFile.exists() ) + { + try + { + digester.verify( file, FileUtils.fileRead( checksumFile ) ); + + reporter.addSuccess( metadata ); + } + catch ( DigesterException e ) + { + reporter.addFailure( metadata, e.getMessage() ); + } + catch ( IOException e ) + { + reporter.addFailure( metadata, "Read file error: " + e.getMessage() ); + } + } + else + { + reporter.addFailure( metadata, digester.getAlgorithm() + " checksum file does not exist." ); + } + } + +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java new file mode 100644 index 000000000..b869e7e49 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java @@ -0,0 +1,161 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; + +import java.util.Iterator; +import java.util.List; + +/** + * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="default" + */ +public class DefaultArtifactReportProcessor + implements ArtifactReportProcessor +{ + private static final String EMPTY_STRING = ""; + + // plexus components + private ArtifactFactory artifactFactory; + + private RepositoryQueryLayer repositoryQueryLayer; + + public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, + ArtifactRepository repository ) + { + if ( artifact == null ) + { + reporter.addFailure( artifact, ArtifactReporter.NULL_ARTIFACT ); + } + else + { + processArtifact( artifact, reporter ); + } + + if ( model == null ) + { + reporter.addFailure( artifact, ArtifactReporter.NULL_MODEL ); + } + else + { + List dependencies = model.getDependencies(); + processDependencies( dependencies, reporter ); + } + } + + private void processArtifact( Artifact artifact, ArtifactReporter reporter ) + { + boolean hasFailed = false; + if ( EMPTY_STRING.equals( artifact.getGroupId() ) || artifact.getGroupId() == null ) + { + reporter.addFailure( artifact, ArtifactReporter.EMPTY_GROUP_ID ); + hasFailed = true; + } + if ( EMPTY_STRING.equals( artifact.getArtifactId() ) || artifact.getArtifactId() == null ) + { + reporter.addFailure( artifact, ArtifactReporter.EMPTY_ARTIFACT_ID ); + hasFailed = true; + } + if ( EMPTY_STRING.equals( artifact.getVersion() ) || artifact.getVersion() == null ) + { + reporter.addFailure( artifact, ArtifactReporter.EMPTY_VERSION ); + hasFailed = true; + } + if ( !hasFailed ) + { + if ( repositoryQueryLayer.containsArtifact( artifact ) ) + { + reporter.addSuccess( artifact ); + } + else + { + reporter.addFailure( artifact, ArtifactReporter.ARTIFACT_NOT_FOUND ); + } + } + } + + private void processDependencies( List dependencies, ArtifactReporter reporter ) + { + if ( dependencies.size() > 0 ) + { + Iterator iterator = dependencies.iterator(); + while ( iterator.hasNext() ) + { + boolean hasFailed = false; + Dependency dependency = (Dependency) iterator.next(); + Artifact artifact = createArtifact( dependency ); + if ( EMPTY_STRING.equals( dependency.getGroupId() ) || dependency.getGroupId() == null ) + { + reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID ); + hasFailed = true; + } + if ( EMPTY_STRING.equals( dependency.getArtifactId() ) || dependency.getArtifactId() == null ) + { + reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID ); + hasFailed = true; + } + if ( EMPTY_STRING.equals( dependency.getVersion() ) || dependency.getVersion() == null ) + { + reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_VERSION ); + hasFailed = true; + } + if ( !hasFailed ) + { + if ( repositoryQueryLayer.containsArtifact( artifact ) ) + { + reporter.addSuccess( artifact ); + } + else + { + reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_NOT_FOUND ); + } + } + } + } + + } + + /** + * Only used for passing a mock object when unit testing + * + * @param repositoryQueryLayer + */ + protected void setRepositoryQueryLayer( RepositoryQueryLayer repositoryQueryLayer ) + { + this.repositoryQueryLayer = repositoryQueryLayer; + } + + /** + * Only used for passing a mock object when unit testing + * + * @param artifactFactory + */ + protected void setArtifactFactory( ArtifactFactory artifactFactory ) + { + this.artifactFactory = artifactFactory; + } + + private Artifact createArtifact( Dependency dependency ) + { + return artifactFactory.createBuildArtifact( dependency.getGroupId(), dependency.getArtifactId(), + dependency.getVersion(), "pom" ); + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java new file mode 100644 index 000000000..32b4cd755 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java @@ -0,0 +1,118 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReporter" role-hint="default" + */ +public class DefaultArtifactReporter + implements ArtifactReporter +{ + private List artifactFailures = new ArrayList(); + + private List artifactSuccesses = new ArrayList(); + + private List artifactWarnings = new ArrayList(); + + private List metadataFailures = new ArrayList(); + + private List metadataSuccesses = new ArrayList(); + + private List metadataWarnings = new ArrayList(); + + public void addFailure( Artifact artifact, String reason ) + { + artifactFailures.add( new ArtifactResult( artifact, reason ) ); + } + + public void addSuccess( Artifact artifact ) + { + artifactSuccesses.add( new ArtifactResult( artifact ) ); + } + + public void addWarning( Artifact artifact, String message ) + { + artifactWarnings.add( new ArtifactResult( artifact, message ) ); + } + + public void addFailure( RepositoryMetadata metadata, String reason ) + { + metadataFailures.add( new RepositoryMetadataResult( metadata, reason ) ); + } + + public void addSuccess( RepositoryMetadata metadata ) + { + metadataSuccesses.add( new RepositoryMetadataResult( metadata ) ); + } + + public void addWarning( RepositoryMetadata metadata, String message ) + { + metadataWarnings.add( new RepositoryMetadataResult( metadata, message ) ); + } + + public Iterator getArtifactFailureIterator() + { + return artifactFailures.iterator(); + } + + public Iterator getArtifactSuccessIterator() + { + return artifactSuccesses.iterator(); + } + + public Iterator getArtifactWarningIterator() + { + return artifactWarnings.iterator(); + } + + public Iterator getRepositoryMetadataFailureIterator() + { + return metadataFailures.iterator(); + } + + public Iterator getRepositoryMetadataSuccessIterator() + { + return metadataSuccesses.iterator(); + } + + public Iterator getRepositoryMetadataWarningIterator() + { + return metadataWarnings.iterator(); + } + + public int getFailures() + { + return artifactFailures.size() + metadataFailures.size(); + } + + public int getSuccesses() + { + return artifactSuccesses.size() + metadataSuccesses.size(); + } + + public int getWarnings() + { + return artifactWarnings.size() + metadataWarnings.size(); + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java new file mode 100644 index 000000000..5570666dd --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java @@ -0,0 +1,31 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.repository.ArtifactRepository; + +/** + * + */ +public class DefaultRepositoryQueryLayer + extends AbstractRepositoryQueryLayer +{ + public DefaultRepositoryQueryLayer( ArtifactRepository repository ) + { + this.repository = repository; + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java new file mode 100644 index 000000000..56f9826dc --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java @@ -0,0 +1,35 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.repository.ArtifactRepository; + +/** + * Gets the default implementation of a repository query layer for the given repository. + * + * @author Brett Porter + * @version $Id$ + * @plexus.component role="org.apache.maven.repository.reporting.RepositoryQueryLayerFactory" + */ +public class DefaultRepositoryQueryLayerFactory + implements RepositoryQueryLayerFactory +{ + public RepositoryQueryLayer createRepositoryQueryLayer( ArtifactRepository repository ) + { + return new DefaultRepositoryQueryLayer( repository ); + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java new file mode 100644 index 000000000..df8c81a85 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java @@ -0,0 +1,124 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 java.io.File; +import java.util.Iterator; +import java.util.List; + +import org.apache.lucene.index.Term; +import org.apache.lucene.search.TermQuery; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Model; +import org.apache.maven.repository.digest.Digester; +import org.apache.maven.repository.digest.DigesterException; +import org.apache.maven.repository.indexing.RepositoryArtifactIndex; +import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; +import org.apache.maven.repository.indexing.RepositoryIndexSearchException; +import org.apache.maven.repository.indexing.lucene.LuceneQuery; +import org.apache.maven.repository.indexing.record.StandardArtifactIndexRecord; +import org.apache.maven.repository.indexing.record.StandardIndexRecordFields; + +/** + * Validates an artifact file for duplicates within the same groupId based from what's available in a repository index. + * + * @author Edwin Punzalan + * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="duplicate" + */ +public class DuplicateArtifactFileReportProcessor + implements ArtifactReportProcessor +{ + /** + * @plexus.requirement role-hint="md5" + */ + private Digester digester; + + /** + * @plexus.requirement + */ + private RepositoryArtifactIndexFactory indexFactory; + + /** + * @plexus.configuration + */ + private String indexDirectory; + + public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, + ArtifactRepository repository ) + throws ReportProcessorException + { + if ( artifact.getFile() != null ) + { + RepositoryArtifactIndex index = indexFactory.createStandardIndex( new File( indexDirectory ) ); + + String checksum; + try + { + checksum = digester.calc( artifact.getFile() ); + } + catch ( DigesterException e ) + { + throw new ReportProcessorException( "Failed to generate checksum", e ); + } + + try + { + List results = index.search( new LuceneQuery( + new TermQuery( new Term( StandardIndexRecordFields.MD5, checksum.toLowerCase() ) ) ) ); + + if ( results.isEmpty() ) + { + reporter.addSuccess( artifact ); + } + else + { + boolean hasDuplicates = false; + for ( Iterator i = results.iterator(); i.hasNext(); ) + { + StandardArtifactIndexRecord result = (StandardArtifactIndexRecord) i.next(); + + //make sure it is not the same artifact + if ( !result.getFilename().equals( repository.pathOf( artifact ) ) ) + { + //report only duplicates from the same groupId + String groupId = artifact.getGroupId(); + if ( groupId.equals( result.getGroupId() ) ) + { + hasDuplicates = true; + reporter.addFailure( artifact, "Found duplicate for " + artifact.getId() ); + } + } + } + + if ( !hasDuplicates ) + { + reporter.addSuccess( artifact ); + } + } + } + catch ( RepositoryIndexSearchException e ) + { + throw new ReportProcessorException( "Failed to search in index", e ); + } + } + else + { + reporter.addWarning( artifact, "Artifact file is null" ); + } + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java new file mode 100644 index 000000000..a11f35754 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java @@ -0,0 +1,101 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; + +/** + * This class validates well-formedness of pom xml file. + * + * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="invalid-pom" + */ +public class InvalidPomArtifactReportProcessor + implements ArtifactReportProcessor +{ + /** + * @param model + * @param artifact The pom xml file to be validated, passed as an artifact object. + * @param reporter The artifact reporter object. + * @param repository the repository where the artifact is located. + */ + public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, + ArtifactRepository repository ) + { + if ( !"file".equals( repository.getProtocol() ) ) + { + // We can't check other types of URLs yet. Need to use Wagon, with an exists() method. + throw new UnsupportedOperationException( + "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" ); + } + + if ( "pom".equals( artifact.getType().toLowerCase() ) ) + { + File f = new File( repository.getBasedir(), repository.pathOf( artifact ) ); + + if ( !f.exists() ) + { + reporter.addFailure( artifact, "Artifact not found." ); + } + else + { + Reader reader = null; + + MavenXpp3Reader pomReader = new MavenXpp3Reader(); + + try + { + reader = new FileReader( f ); + pomReader.read( reader ); + reporter.addSuccess( artifact ); + } + catch ( XmlPullParserException e ) + { + reporter.addFailure( artifact, "The pom xml file is not well-formed. Error while parsing: " + + e.getMessage() ); + } + catch ( FileNotFoundException e ) + { + reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() ); + } + catch ( IOException e ) + { + reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() ); + } + finally + { + IOUtil.close( reader ); + } + } + } + else + { + reporter.addWarning( artifact, "The artifact is not a pom xml file." ); + } + } + +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessor.java new file mode 100644 index 000000000..140425656 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessor.java @@ -0,0 +1,196 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +/** + * Validate the location of the artifact based on the values indicated + * in its pom (both the pom packaged with the artifact & the pom in the + * file system). + * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="artifact-location" + */ +public class LocationArtifactReportProcessor + implements ArtifactReportProcessor +{ + /** @plexus.requirement */ + private ArtifactFactory artifactFactory; + + /** + * Check whether the artifact is in its proper location. The location of the artifact + * is validated first against the groupId, artifactId and versionId in the specified model + * object (pom in the file system). Then unpack the artifact (jar file) and get the model (pom) + * included in the package. If a model exists inside the package, then check if the artifact's + * location is valid based on the location specified in the pom. Check if the both the location + * specified in the file system pom and in the pom included in the package is the same. + * + * @param model Represents the pom in the file system. + * @param artifact + * @param reporter + * @param repository + */ + public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, + ArtifactRepository repository ) + throws ReportProcessorException + { + if ( !"file".equals( repository.getProtocol() ) ) + { + // We can't check other types of URLs yet. Need to use Wagon, with an exists() method. + throw new UnsupportedOperationException( + "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" ); + } + + //check if the artifact is located in its proper location based on the info + //specified in the model object/pom + Artifact modelArtifact = artifactFactory.createBuildArtifact( model.getGroupId(), model.getArtifactId(), + model.getVersion(), model.getPackaging() ); + + boolean failed = false; + String modelPath = repository.pathOf( modelArtifact ); + String artifactPath = repository.pathOf( artifact ); + if ( modelPath.equals( artifactPath ) ) + { + //get the location of the artifact itself + File file = new File( repository.getBasedir(), artifactPath ); + + if ( file.exists() ) + { + //unpack the artifact (using the groupId, artifactId & version specified in the artifact object itself + //check if the pom is included in the package + Model extractedModel = readArtifactModel( file, artifact.getGroupId(), artifact.getArtifactId() ); + + if ( extractedModel != null ) + { + Artifact extractedArtifact = artifactFactory.createBuildArtifact( extractedModel.getGroupId(), + extractedModel.getArtifactId(), + extractedModel.getVersion(), + extractedModel.getPackaging() ); + if ( !repository.pathOf( extractedArtifact ).equals( artifactPath ) ) + { + reporter.addFailure( artifact, + "The artifact is out of place. It does not match the specified location in the packaged pom." ); + failed = true; + } + } + } + else + { + reporter.addFailure( artifact, + "The artifact is out of place. It does not exist at the specified location in the repository pom." ); + failed = true; + } + } + else + { + reporter.addFailure( artifact, + "The artifact is out of place. It does not match the specified location in the repository pom." ); + failed = true; + } + + if ( !failed ) + { + reporter.addSuccess( artifact ); + } + } + + /** + * Extract the contents of the artifact/jar file. + * + * @param file + * @param groupId + * @param artifactId + */ + private Model readArtifactModel( File file, String groupId, String artifactId ) + throws ReportProcessorException + { + Model model = null; + + JarFile jar = null; + try + { + jar = new JarFile( file ); + + //Get the entry and its input stream. + JarEntry entry = jar.getJarEntry( "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml" ); + + // If the entry is not null, extract it. + if ( entry != null ) + { + model = readModel( jar.getInputStream( entry ) ); + } + } + catch ( IOException e ) + { + // TODO: should just warn and continue? + throw new ReportProcessorException( "Unable to read artifact to extract model", e ); + } + catch ( XmlPullParserException e ) + { + // TODO: should just warn and continue? + throw new ReportProcessorException( "Unable to read artifact to extract model", e ); + } + finally + { + if ( jar != null ) + { + //noinspection UnusedCatchParameter + try + { + jar.close(); + } + catch ( IOException e ) + { + // ignore + } + } + } + return model; + } + + private Model readModel( InputStream entryStream ) + throws IOException, XmlPullParserException + { + Reader isReader = new InputStreamReader( entryStream ); + + Model model; + try + { + MavenXpp3Reader pomReader = new MavenXpp3Reader(); + model = pomReader.read( isReader ); + } + finally + { + IOUtil.close( isReader ); + } + return model; + } + +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java new file mode 100644 index 000000000..0431a8adf --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java @@ -0,0 +1,31 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; + +/** + * This interface is called by the main system for each piece of metadata as it is discovered. + */ +public interface MetadataReportProcessor +{ + String ROLE = MetadataReportProcessor.class.getName(); + + void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter ) + throws ReportProcessorException; +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java new file mode 100644 index 000000000..5f73dbdc0 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java @@ -0,0 +1,32 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * Exception occurring during reporting. + * + * @author Brett Porter + * @version $Id$ + */ +public class ReportProcessorException + extends Exception +{ + public ReportProcessorException( String msg, Throwable cause ) + { + super( msg, cause ); + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java new file mode 100644 index 000000000..4c962986a --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java @@ -0,0 +1,54 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.repository.metadata.RepositoryMetadata; + +/** + * A result of the report for a given artifact being processed. + * + * @author Brett Porter + * @version $Id$ + */ +public class RepositoryMetadataResult +{ + private final RepositoryMetadata metadata; + + private final String reason; + + public RepositoryMetadataResult( RepositoryMetadata metadata ) + { + this.metadata = metadata; + this.reason = null; + } + + public RepositoryMetadataResult( RepositoryMetadata metadata, String reason ) + { + this.metadata = metadata; + this.reason = reason; + } + + public RepositoryMetadata getMetadata() + { + return metadata; + } + + public String getReason() + { + return reason; + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java new file mode 100644 index 000000000..950f7a252 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java @@ -0,0 +1,38 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.metadata.Snapshot; + +import java.util.List; + +/** + * The transitive and metadata validation reports will need to query the repository for artifacts. + */ +public interface RepositoryQueryLayer +{ + String ROLE = RepositoryQueryLayer.class.getName(); + + boolean containsArtifact( Artifact artifact ); + + /** @todo I believe we can remove this [BP] - artifact should contain all the necessary version info */ + boolean containsArtifact( Artifact artifact, Snapshot snapshot ); + + List getVersions( Artifact artifact ) + throws RepositoryQueryLayerException; +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerException.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerException.java new file mode 100644 index 000000000..ae7f77947 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerException.java @@ -0,0 +1,34 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * + */ +public class RepositoryQueryLayerException + extends Exception +{ + public RepositoryQueryLayerException( String message, Throwable cause ) + { + super( message, cause ); + } + + public RepositoryQueryLayerException( String message ) + { + super( message ); + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java new file mode 100644 index 000000000..00f42b30d --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java @@ -0,0 +1,38 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.repository.ArtifactRepository; + +/** + * Gets the preferred implementation of a repository query layer for the given repository. + * + * @author Brett Porter + * @version $Id$ + */ +public interface RepositoryQueryLayerFactory +{ + String ROLE = RepositoryQueryLayerFactory.class.getName(); + + /** + * Create or obtain a query interface. + * + * @param repository the repository to query + * @return the obtained query layer + */ + RepositoryQueryLayer createRepositoryQueryLayer( ArtifactRepository repository ); +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java new file mode 100644 index 000000000..93b9b2e6e --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java @@ -0,0 +1,283 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.repository.digest.Digester; +import org.apache.maven.repository.digest.DigesterException; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.IOUtil; + +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; + +/** + * This class creates the artifact and metadata files used for testing the ChecksumArtifactReporter. + * It is extended by ChecksumArtifactReporterTest class. + */ +public abstract class AbstractChecksumArtifactReporterTestCase + extends AbstractRepositoryReportsTestCase +{ + private static final String[] validArtifactChecksumJars = {"validArtifact-1.0"}; + + private static final String[] invalidArtifactChecksumJars = {"invalidArtifact-1.0"}; + + private static final String metadataChecksumFilename = "maven-metadata"; + + private Digester sha1Digest; + + private Digester md5Digest; + + public void setUp() + throws Exception + { + super.setUp(); + + sha1Digest = (Digester) lookup( Digester.ROLE, "sha1" ); + md5Digest = (Digester) lookup( Digester.ROLE, "md5" ); + } + + /** + * Create checksum files. + * + * @param type The type of checksum file to be created. + */ + protected void createChecksumFile( String type ) + throws DigesterException, IOException + { + //loop through the valid artifact names.. + if ( "VALID".equals( type ) ) + { + for ( int i = 0; i < validArtifactChecksumJars.length; i++ ) + { + writeChecksumFile( "checksumTest/", validArtifactChecksumJars[i], "jar", true ); + } + } + else if ( "INVALID".equals( type ) ) + { + for ( int i = 0; i < invalidArtifactChecksumJars.length; i++ ) + { + writeChecksumFile( "checksumTest/", invalidArtifactChecksumJars[i], "jar", false ); + } + } + } + + /** + * Create checksum files for metadata. + * + * @param type The type of checksum to be created. (Valid or invalid) + */ + protected void createMetadataFile( String type ) + throws DigesterException, IOException + { + //loop through the valid artifact names.. + if ( "VALID".equals( type ) ) + { + writeMetadataFile( "checksumTest/validArtifact/1.0/", metadataChecksumFilename, "xml", true ); + writeMetadataFile( "checksumTest/validArtifact/", metadataChecksumFilename, "xml", true ); + writeMetadataFile( "checksumTest/", metadataChecksumFilename, "xml", true ); + } + else if ( "INVALID".equals( type ) ) + { + writeMetadataFile( "checksumTest/invalidArtifact/1.0/", metadataChecksumFilename, "xml", false ); + } + } + + /** + * Create artifact together with its checksums. + * + * @param relativePath The groupId + * @param filename The filename of the artifact to be created. + * @param type The file type (JAR) + * @param isValid Indicates whether the checksum to be created is valid or not. + */ + private void writeChecksumFile( String relativePath, String filename, String type, boolean isValid ) + throws IOException, DigesterException + { + //Initialize variables for creating jar files + String repoUrl = repository.getBasedir(); + + String dirs = filename.replace( '-', '/' ); + //create the group level directory of the artifact + File dirFiles = new File( repoUrl + relativePath + dirs ); + + if ( dirFiles.mkdirs() ) + { + // create a jar file + String path = repoUrl + relativePath + dirs + "/" + filename + "." + type; + FileOutputStream f = new FileOutputStream( path ); + JarOutputStream out = new JarOutputStream( new BufferedOutputStream( f ) ); + + // jar sample.txt + String filename1 = repoUrl + relativePath + dirs + "/sample.txt"; + createSampleFile( filename1 ); + + BufferedReader in = new BufferedReader( new FileReader( filename1 ) ); + out.putNextEntry( new JarEntry( filename1 ) ); + IOUtil.copy( in, out ); + in.close(); + out.close(); + + //Create md5 and sha-1 checksum files.. + + File file = new File( path + ".md5" ); + OutputStream os = new FileOutputStream( file ); + OutputStreamWriter osw = new OutputStreamWriter( os ); + String sum = md5Digest.calc( new File( path ) ); + if ( !isValid ) + { + osw.write( sum + "1" ); + } + else + { + osw.write( sum ); + } + osw.close(); + + file = new File( path + ".sha1" ); + os = new FileOutputStream( file ); + osw = new OutputStreamWriter( os ); + String sha1sum = sha1Digest.calc( new File( path ) ); + if ( !isValid ) + { + osw.write( sha1sum + "2" ); + } + else + { + osw.write( sha1sum ); + } + osw.close(); + } + } + + /** + * Create metadata file together with its checksums. + * + * @param relativePath The groupId + * @param filename The filename of the artifact to be created. + * @param type The file type (JAR) + * @param isValid Indicates whether the checksum to be created is valid or not. + */ + private void writeMetadataFile( String relativePath, String filename, String type, boolean isValid ) + throws IOException, DigesterException + { + //create checksum for the metadata file.. + String repoUrl = repository.getBasedir(); + String url = repository.getBasedir() + "/" + filename + "." + type; + + String path = repoUrl + relativePath + filename + "." + type; + FileUtils.copyFile( new File( url ), new File( path ) ); + + //Create md5 and sha-1 checksum files.. + File file = new File( path + ".md5" ); + OutputStream os = new FileOutputStream( file ); + OutputStreamWriter osw = new OutputStreamWriter( os ); + String md5sum = md5Digest.calc( new File( path ) ); + if ( !isValid ) + { + osw.write( md5sum + "1" ); + } + else + { + osw.write( md5sum ); + } + osw.close(); + + file = new File( path + ".sha1" ); + os = new FileOutputStream( file ); + osw = new OutputStreamWriter( os ); + String sha1sum = sha1Digest.calc( new File( path ) ); + if ( !isValid ) + { + osw.write( sha1sum + "2" ); + } + else + { + osw.write( sha1sum ); + } + osw.close(); + } + + /** + * Create the sample file that will be included in the jar. + * + * @param filename + */ + private void createSampleFile( String filename ) + throws IOException + { + File file = new File( filename ); + OutputStream os = new FileOutputStream( file ); + OutputStreamWriter osw = new OutputStreamWriter( os ); + osw.write( "This is the content of the sample file that will be included in the jar file." ); + osw.close(); + } + + /** + * Delete the test directory created in the repository. + * + * @param dir The directory to be deleted. + */ + protected void deleteTestDirectory( File dir ) + { + try + { + FileUtils.deleteDirectory( dir ); + } + catch ( IOException e ) + { + // ignore + } + } + + private void deleteFile( String filename ) + { + File f = new File( filename ); + f.delete(); + } + + protected void deleteChecksumFiles( String type ) + { + //delete valid checksum files of artifacts created + for ( int i = 0; i < validArtifactChecksumJars.length; i++ ) + { + deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) + + "/" + validArtifactChecksumJars[i] + "." + type + ".md5" ); + + deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) + + "/" + validArtifactChecksumJars[i] + "." + type + ".sha1" ); + } + + //delete valid checksum files of metadata file + for ( int i = 0; i < validArtifactChecksumJars.length; i++ ) + { + deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) + + "/" + metadataChecksumFilename + ".xml.md5" ); + + deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) + + "/" + metadataChecksumFilename + ".xml.sha1" ); + } + } + +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTestCase.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTestCase.java new file mode 100644 index 000000000..6de998c8f --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTestCase.java @@ -0,0 +1,142 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.repository.metadata.Snapshot; +import org.codehaus.plexus.PlexusTestCase; + +import java.io.File; +import java.util.List; + +/** + * + */ +public abstract class AbstractRepositoryQueryLayerTestCase + extends PlexusTestCase +{ + private ArtifactFactory artifactFactory; + + protected ArtifactRepository repository; + + protected CachedRepositoryQueryLayer queryLayer; + + protected void setUp() + throws Exception + { + super.setUp(); + File repositoryDirectory = getTestFile( "src/test/repository" ); + + artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + + repository = + factory.createArtifactRepository( "test", repositoryDirectory.toURL().toString(), layout, null, null ); + } + + public void testContainsArtifactTrue() + { + Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-alpha-1" ); + + assertTrue( "check artifact", queryLayer.containsArtifact( artifact ) ); + } + + public void testContainsArtifactFalse() + { + Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-beta-1" ); + + assertFalse( "check non-existent artifact", queryLayer.containsArtifact( artifact ) ); + } + + public void testContainsSnapshotArtifactTrue() + { + Snapshot snapshot = new Snapshot(); + snapshot.setTimestamp( "20050611.202024" ); + snapshot.setBuildNumber( 1 ); + + Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" ); + assertTrue( "check for snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) ); + } + + public void testContainsSnapshotArtifactFalse() + { + Snapshot snapshot = new Snapshot(); + snapshot.setTimestamp( "20050611.202024" ); + snapshot.setBuildNumber( 2 ); + + Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" ); + assertFalse( "check for non-existent snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) ); + } + + public void testArtifactVersionsTrue() + throws Exception + { + Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" ); + + List versions = queryLayer.getVersions( artifact ); + + assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) ); + assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) ); + assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) ); + } + + public void testArtifactVersionsFalse() + throws Exception + { + Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" ); + + List versions = queryLayer.getVersions( artifact ); + + assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) ); + assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) ); + assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) ); + } + + public void testArtifactVersionsError() + { + Artifact artifact = getArtifact( "groupId", "none", "ignored" ); + + try + { + queryLayer.getVersions( artifact ); + fail( "expected error not thrown" ); + } + catch ( RepositoryQueryLayerException e ) + { + //expected + } + } + + private Artifact getArtifact( String groupId, String artifactId, String version ) + { + return artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" ); + } + + protected void tearDown() + throws Exception + { + release( artifactFactory ); + super.tearDown(); + artifactFactory = null; + repository = null; + } +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java new file mode 100644 index 000000000..45f12964e --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java @@ -0,0 +1,64 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.codehaus.plexus.PlexusTestCase; + +import java.io.File; + +/** + * + */ +public abstract class AbstractRepositoryReportsTestCase + extends PlexusTestCase +{ + /** + * This should only be used for the few that can't use the query layer. + */ + protected ArtifactRepository repository; + + protected static final String remoteRepoUrl = "http://public.planetmirror.com/pub/maven2/"; + + protected static final String remoteArtifactGroup = "HTTPClient"; + + protected static final String remoteArtifactId = "HTTPClient"; + + protected static final String remoteArtifactVersion = "0.3-3"; + + protected static final String remoteArtifactScope = "compile"; + + protected static final String remoteArtifactType = "jar"; + + protected static final String remoteRepoId = "remote-repo"; + + protected void setUp() + throws Exception + { + super.setUp(); + File repositoryDirectory = getTestFile( "src/test/repository" ); + + ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + + repository = factory.createArtifactRepository( "repository", repositoryDirectory.toURL().toString(), layout, + null, null ); + } + +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java new file mode 100644 index 000000000..4d6c697f3 --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java @@ -0,0 +1,463 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; + +import java.util.Iterator; + +/** + * + */ +public class ArtifactReportProcessorTest + extends AbstractRepositoryReportsTestCase +{ + private static final String EMPTY_STRING = ""; + + private static final String VALID = "temp"; + + private MockArtifactReporter reporter; + + private Artifact artifact; + + private Model model; + + private DefaultArtifactReportProcessor processor; + + private static final boolean ARTIFACT_FOUND = true; + + private static final boolean ARTIFACT_NOT_FOUND = false; + + protected void setUp() + throws Exception + { + super.setUp(); + reporter = new MockArtifactReporter(); + artifact = new MockArtifact(); + model = new Model(); + processor = new DefaultArtifactReportProcessor(); + } + + public void testNullArtifact() + { + processor.processArtifact( model, null, reporter, null ); + assertEquals( 0, reporter.getSuccesses() ); + assertEquals( 1, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.NULL_ARTIFACT, result.getReason() ); + } + + public void testNoProjectDescriptor() + { + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + processor.setRepositoryQueryLayer( queryLayer ); + setRequiredElements( artifact, VALID, VALID, VALID ); + processor.processArtifact( null, artifact, reporter, null ); + assertEquals( 1, reporter.getSuccesses() ); + assertEquals( 1, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.NULL_MODEL, result.getReason() ); + } + + public void testArtifactFoundButNoDirectDependencies() + { + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + processor.setRepositoryQueryLayer( queryLayer ); + setRequiredElements( artifact, VALID, VALID, VALID ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 1, reporter.getSuccesses() ); + assertEquals( 0, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + } + + public void testArtifactNotFound() + { + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_NOT_FOUND ); + processor.setRepositoryQueryLayer( queryLayer ); + setRequiredElements( artifact, VALID, VALID, VALID ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 0, reporter.getSuccesses() ); + assertEquals( 1, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.ARTIFACT_NOT_FOUND, result.getReason() ); + } + + public void testValidArtifactWithNullDependency() + { + MockArtifactFactory artifactFactory = new MockArtifactFactory(); + processor.setArtifactFactory( artifactFactory ); + + setRequiredElements( artifact, VALID, VALID, VALID ); + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + Dependency dependency = new Dependency(); + setRequiredElements( dependency, VALID, VALID, VALID ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + processor.setRepositoryQueryLayer( queryLayer ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 2, reporter.getSuccesses() ); + assertEquals( 0, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + } + + public void testValidArtifactWithValidSingleDependency() + { + MockArtifactFactory artifactFactory = new MockArtifactFactory(); + processor.setArtifactFactory( artifactFactory ); + + setRequiredElements( artifact, VALID, VALID, VALID ); + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + Dependency dependency = new Dependency(); + setRequiredElements( dependency, VALID, VALID, VALID ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + processor.setRepositoryQueryLayer( queryLayer ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 2, reporter.getSuccesses() ); + assertEquals( 0, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + } + + public void testValidArtifactWithValidMultipleDependencies() + { + MockArtifactFactory artifactFactory = new MockArtifactFactory(); + processor.setArtifactFactory( artifactFactory ); + + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + Dependency dependency = new Dependency(); + setRequiredElements( dependency, VALID, VALID, VALID ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + setRequiredElements( artifact, VALID, VALID, VALID ); + processor.setRepositoryQueryLayer( queryLayer ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 6, reporter.getSuccesses() ); + assertEquals( 0, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + } + + public void testValidArtifactWithAnInvalidDependency() + { + MockArtifactFactory artifactFactory = new MockArtifactFactory(); + processor.setArtifactFactory( artifactFactory ); + + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + Dependency dependency = new Dependency(); + setRequiredElements( dependency, VALID, VALID, VALID ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_NOT_FOUND ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + setRequiredElements( artifact, VALID, VALID, VALID ); + processor.setRepositoryQueryLayer( queryLayer ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 5, reporter.getSuccesses() ); + assertEquals( 1, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() ); + } + + public void testEmptyGroupId() + { + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + processor.setRepositoryQueryLayer( queryLayer ); + + setRequiredElements( artifact, EMPTY_STRING, VALID, VALID ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 0, reporter.getSuccesses() ); + assertEquals( 1, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() ); + } + + public void testEmptyArtifactId() + { + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + processor.setRepositoryQueryLayer( queryLayer ); + + setRequiredElements( artifact, VALID, EMPTY_STRING, VALID ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 0, reporter.getSuccesses() ); + assertEquals( 1, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() ); + } + + public void testEmptyVersion() + { + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + processor.setRepositoryQueryLayer( queryLayer ); + + setRequiredElements( artifact, VALID, VALID, EMPTY_STRING ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 0, reporter.getSuccesses() ); + assertEquals( 1, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() ); + } + + public void testNullGroupId() + { + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + processor.setRepositoryQueryLayer( queryLayer ); + + setRequiredElements( artifact, null, VALID, VALID ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 0, reporter.getSuccesses() ); + assertEquals( 1, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() ); + } + + public void testNullArtifactId() + { + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + processor.setRepositoryQueryLayer( queryLayer ); + + setRequiredElements( artifact, VALID, null, VALID ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 0, reporter.getSuccesses() ); + assertEquals( 1, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() ); + } + + public void testNullVersion() + { + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + processor.setRepositoryQueryLayer( queryLayer ); + + setRequiredElements( artifact, VALID, VALID, null ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 0, reporter.getSuccesses() ); + assertEquals( 1, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() ); + } + + public void testMultipleFailures() + { + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + processor.setRepositoryQueryLayer( queryLayer ); + + setRequiredElements( artifact, null, null, null ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 0, reporter.getSuccesses() ); + assertEquals( 3, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() ); + result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() ); + result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() ); + } + + public void testValidArtifactWithInvalidDependencyGroupId() + { + MockArtifactFactory artifactFactory = new MockArtifactFactory(); + processor.setArtifactFactory( artifactFactory ); + + setRequiredElements( artifact, VALID, VALID, VALID ); + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + Dependency dependency = new Dependency(); + setRequiredElements( dependency, null, VALID, VALID ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + processor.setRepositoryQueryLayer( queryLayer ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 1, reporter.getSuccesses() ); + assertEquals( 1, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID, result.getReason() ); + } + + public void testValidArtifactWithInvalidDependencyArtifactId() + { + MockArtifactFactory artifactFactory = new MockArtifactFactory(); + processor.setArtifactFactory( artifactFactory ); + + setRequiredElements( artifact, VALID, VALID, VALID ); + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + Dependency dependency = new Dependency(); + setRequiredElements( dependency, VALID, null, VALID ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + processor.setRepositoryQueryLayer( queryLayer ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 1, reporter.getSuccesses() ); + assertEquals( 1, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID, result.getReason() ); + } + + public void testValidArtifactWithInvalidDependencyVersion() + { + MockArtifactFactory artifactFactory = new MockArtifactFactory(); + processor.setArtifactFactory( artifactFactory ); + + setRequiredElements( artifact, VALID, VALID, VALID ); + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + Dependency dependency = new Dependency(); + setRequiredElements( dependency, VALID, VALID, null ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + processor.setRepositoryQueryLayer( queryLayer ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 1, reporter.getSuccesses() ); + assertEquals( 1, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_VERSION, result.getReason() ); + } + + public void testValidArtifactWithInvalidDependencyRequiredElements() + { + MockArtifactFactory artifactFactory = new MockArtifactFactory(); + processor.setArtifactFactory( artifactFactory ); + + setRequiredElements( artifact, VALID, VALID, VALID ); + MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + Dependency dependency = new Dependency(); + setRequiredElements( dependency, null, null, null ); + model.addDependency( dependency ); + queryLayer.addReturnValue( ARTIFACT_FOUND ); + + processor.setRepositoryQueryLayer( queryLayer ); + processor.processArtifact( model, artifact, reporter, null ); + assertEquals( 1, reporter.getSuccesses() ); + assertEquals( 3, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID, result.getReason() ); + result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID, result.getReason() ); + result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_VERSION, result.getReason() ); + } + + protected void tearDown() + throws Exception + { + model = null; + artifact = null; + reporter = null; + super.tearDown(); + } + + private void setRequiredElements( Artifact artifact, String groupId, String artifactId, String version ) + { + artifact.setGroupId( groupId ); + artifact.setArtifactId( artifactId ); + artifact.setVersion( version ); + } + + private void setRequiredElements( Dependency dependency, String groupId, String artifactId, String version ) + { + dependency.setGroupId( groupId ); + dependency.setArtifactId( artifactId ); + dependency.setVersion( version ); + } +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java new file mode 100644 index 000000000..e3fc97f6b --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java @@ -0,0 +1,187 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.metadata.Versioning; +import org.apache.maven.model.Model; + +import java.util.Iterator; + +/** + * + */ +public class ArtifactReporterTest + extends AbstractRepositoryReportsTestCase +{ + private ArtifactReporter reporter; + + private Artifact artifact; + + private MockArtifactReportProcessor processor; + + private Model model; + + protected void setUp() + throws Exception + { + super.setUp(); + reporter = new DefaultArtifactReporter(); + ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); + processor = new MockArtifactReportProcessor(); + Versioning versioning = new Versioning(); + versioning.addVersion( "1.0-alpha-1" ); + versioning.setLastUpdated( "20050611.202020" ); + model = new Model(); + } + + public void testArtifactReporterSingleSuccess() + { + processor.addReturnValue( ReportCondition.SUCCESS, artifact, "all is good" ); + processor.processArtifact( model, artifact, reporter, null ); + Iterator success = reporter.getArtifactSuccessIterator(); + assertTrue( success.hasNext() ); + assertEquals( 1, reporter.getSuccesses() ); + Artifact result = ( (ArtifactResult) success.next() ).getArtifact(); + assertEquals( "groupId", result.getGroupId() ); + assertEquals( "artifactId", result.getArtifactId() ); + assertEquals( "1.0-alpha-1", result.getVersion() ); + assertFalse( success.hasNext() ); + } + + public void testArtifactReporterMultipleSuccess() + { + processor.clearList(); + processor.addReturnValue( ReportCondition.SUCCESS, artifact, "one" ); + processor.addReturnValue( ReportCondition.SUCCESS, artifact, "two" ); + processor.addReturnValue( ReportCondition.SUCCESS, artifact, "three" ); + reporter = new DefaultArtifactReporter(); + processor.processArtifact( model, artifact, reporter, null ); + Iterator success = reporter.getArtifactSuccessIterator(); + assertTrue( success.hasNext() ); + int i; + for ( i = 0; success.hasNext(); i++ ) + { + success.next(); + } + assertEquals( 3, i ); + assertEquals( 3, reporter.getSuccesses() ); + assertEquals( 0, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + } + + public void testArtifactReporterSingleFailure() + { + processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" ); + processor.processArtifact( model, artifact, reporter, null ); + Iterator failure = reporter.getArtifactFailureIterator(); + assertTrue( failure.hasNext() ); + failure.next(); + assertFalse( failure.hasNext() ); + assertEquals( 0, reporter.getSuccesses() ); + assertEquals( 1, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + } + + public void testArtifactReporterMultipleFailure() + { + processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" ); + processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed twice" ); + processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed thrice" ); + processor.processArtifact( model, artifact, reporter, null ); + Iterator failure = reporter.getArtifactFailureIterator(); + assertTrue( failure.hasNext() ); + int i; + for ( i = 0; failure.hasNext(); i++ ) + { + failure.next(); + } + assertEquals( 3, i ); + assertEquals( 0, reporter.getSuccesses() ); + assertEquals( 3, reporter.getFailures() ); + assertEquals( 0, reporter.getWarnings() ); + } + + public void testFailureMessages() + { + processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" ); + processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed twice" ); + processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed thrice" ); + processor.processArtifact( model, artifact, reporter, null ); + Iterator failure = reporter.getArtifactFailureIterator(); + assertEquals( "failed once", ( (ArtifactResult) failure.next() ).getReason() ); + assertEquals( "failed twice", ( (ArtifactResult) failure.next() ).getReason() ); + assertEquals( "failed thrice", ( (ArtifactResult) failure.next() ).getReason() ); + } + + public void testArtifactReporterSingleWarning() + { + processor.addReturnValue( ReportCondition.WARNING, artifact, "you've been warned" ); + processor.processArtifact( model, artifact, reporter, null ); + Iterator warning = reporter.getArtifactWarningIterator(); + assertTrue( warning.hasNext() ); + warning.next(); + assertFalse( warning.hasNext() ); + assertEquals( 0, reporter.getSuccesses() ); + assertEquals( 0, reporter.getFailures() ); + assertEquals( 1, reporter.getWarnings() ); + } + + public void testArtifactReporterMultipleWarning() + { + processor.addReturnValue( ReportCondition.WARNING, artifact, "i'm warning you" ); + processor.addReturnValue( ReportCondition.WARNING, artifact, "you have to stop now" ); + processor.addReturnValue( ReportCondition.WARNING, artifact, "all right... that does it!" ); + processor.processArtifact( model, artifact, reporter, null ); + Iterator warning = reporter.getArtifactWarningIterator(); + assertTrue( warning.hasNext() ); + int i; + for ( i = 0; warning.hasNext(); i++ ) + { + warning.next(); + } + assertEquals( 3, i ); + assertEquals( 0, reporter.getSuccesses() ); + assertEquals( 0, reporter.getFailures() ); + assertEquals( 3, reporter.getWarnings() ); + } + + public void testWarningMessages() + { + processor.addReturnValue( ReportCondition.WARNING, artifact, "i'm warning you" ); + processor.addReturnValue( ReportCondition.WARNING, artifact, "you have to stop now" ); + processor.addReturnValue( ReportCondition.WARNING, artifact, "all right... that does it!" ); + processor.processArtifact( model, artifact, reporter, null ); + Iterator warning = reporter.getArtifactWarningIterator(); + assertEquals( "i'm warning you", ( (ArtifactResult) warning.next() ).getReason() ); + assertEquals( "you have to stop now", ( (ArtifactResult) warning.next() ).getReason() ); + assertEquals( "all right... that does it!", ( (ArtifactResult) warning.next() ).getReason() ); + } + + protected void tearDown() + throws Exception + { + model = null; + processor.clearList(); + processor = null; + reporter = null; + super.tearDown(); + } + +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java new file mode 100644 index 000000000..828b27274 --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java @@ -0,0 +1,358 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Plugin; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Snapshot; +import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Versioning; + +import java.util.Iterator; + +/** + * @todo??? should use MetadataXpp3Reader instead ? + */ +public class BadMetadataReportProcessorTest + extends AbstractRepositoryReportsTestCase +{ + private ArtifactFactory artifactFactory; + + private MetadataReportProcessor badMetadataReportProcessor; + + protected void setUp() + throws Exception + { + super.setUp(); + + artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + + badMetadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE ); + } + + public void testMetadataMissingLastUpdated() + throws ReportProcessorException + { + ArtifactReporter reporter = new MockArtifactReporter(); + + Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); + + Versioning versioning = new Versioning(); + versioning.addVersion( "1.0-alpha-1" ); + versioning.addVersion( "1.0-alpha-2" ); + + RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); + + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); + assertTrue( "check there is a failure", failures.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); + assertEquals( "check metadata", metadata, result.getMetadata() ); + assertEquals( "check reason", "Missing lastUpdated element inside the metadata.", result.getReason() ); + assertFalse( "check no more failures", failures.hasNext() ); + } + + public void testMetadataValidVersions() + throws ReportProcessorException + { + ArtifactReporter reporter = new MockArtifactReporter(); + + Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); + + Versioning versioning = new Versioning(); + versioning.addVersion( "1.0-alpha-1" ); + versioning.addVersion( "1.0-alpha-2" ); + versioning.setLastUpdated( "20050611.202020" ); + + RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); + + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); + assertFalse( "check there are no failures", failures.hasNext() ); + } + + public void testMetadataMissingADirectory() + throws ReportProcessorException + { + ArtifactReporter reporter = new MockArtifactReporter(); + + Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); + + Versioning versioning = new Versioning(); + versioning.addVersion( "1.0-alpha-1" ); + versioning.setLastUpdated( "20050611.202020" ); + + RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); + + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); + assertTrue( "check there is a failure", failures.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); + assertEquals( "check metadata", metadata, result.getMetadata() ); + // TODO: should be more robust + assertEquals( "check reason", + "Artifact version 1.0-alpha-2 found in the repository but missing in the metadata.", + result.getReason() ); + assertFalse( "check no more failures", failures.hasNext() ); + } + + public void testMetadataInvalidArtifactVersion() + throws ReportProcessorException + { + ArtifactReporter reporter = new MockArtifactReporter(); + + Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); + + Versioning versioning = new Versioning(); + versioning.addVersion( "1.0-alpha-1" ); + versioning.addVersion( "1.0-alpha-2" ); + versioning.addVersion( "1.0-alpha-3" ); + versioning.setLastUpdated( "20050611.202020" ); + + RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); + + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); + assertTrue( "check there is a failure", failures.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); + assertEquals( "check metadata", metadata, result.getMetadata() ); + // TODO: should be more robust + assertEquals( "check reason", + "Artifact version 1.0-alpha-3 is present in metadata but missing in the repository.", + result.getReason() ); + assertFalse( "check no more failures", failures.hasNext() ); + } + + public void testMoreThanOneMetadataVersionErrors() + throws ReportProcessorException + { + ArtifactReporter reporter = new MockArtifactReporter(); + + Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); + + Versioning versioning = new Versioning(); + versioning.addVersion( "1.0-alpha-1" ); + versioning.addVersion( "1.0-alpha-3" ); + versioning.setLastUpdated( "20050611.202020" ); + + RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); + + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); + assertTrue( "check there is a failure", failures.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); + assertEquals( "check metadata", metadata, result.getMetadata() ); + // TODO: should be more robust + assertEquals( "check reason", + "Artifact version 1.0-alpha-3 is present in metadata but missing in the repository.", + result.getReason() ); + assertTrue( "check there is a 2nd failure", failures.hasNext() ); + result = (RepositoryMetadataResult) failures.next(); + // TODO: should be more robust + assertEquals( "check reason", + "Artifact version 1.0-alpha-2 found in the repository but missing in the metadata.", + result.getReason() ); + assertFalse( "check no more failures", failures.hasNext() ); + } + + public void testValidPluginMetadata() + throws ReportProcessorException + { + ArtifactReporter reporter = new MockArtifactReporter(); + + RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); + metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); + metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) ); + + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); + assertFalse( "check there are no failures", failures.hasNext() ); + } + + public void testMissingMetadataPlugin() + throws ReportProcessorException + { + ArtifactReporter reporter = new MockArtifactReporter(); + + RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); + metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); + metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) ); + metadata.getMetadata().addPlugin( createMetadataPlugin( "missing-plugin", "default3" ) ); + + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); + assertTrue( "check there is a failure", failures.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); + // TODO: should be more robust + assertEquals( "check reason", "Metadata plugin missing-plugin not found in the repository", + result.getReason() ); + assertFalse( "check no more failures", failures.hasNext() ); + } + + public void testIncompletePluginMetadata() + throws ReportProcessorException + { + ArtifactReporter reporter = new MockArtifactReporter(); + + RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); + metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); + + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); + assertTrue( "check there is a failure", failures.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); + // TODO: should be more robust + assertEquals( "check reason", + "Plugin snapshot-artifact is present in the repository but " + "missing in the metadata.", + result.getReason() ); + assertFalse( "check no more failures", failures.hasNext() ); + } + + public void testInvalidPluginArtifactId() + throws ReportProcessorException + { + ArtifactReporter reporter = new MockArtifactReporter(); + + RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); + metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); + metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) ); + metadata.getMetadata().addPlugin( createMetadataPlugin( null, "default3" ) ); + metadata.getMetadata().addPlugin( createMetadataPlugin( "", "default4" ) ); + + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); + assertTrue( "check there is a failure", failures.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); + // TODO: should be more robust + assertEquals( "check reason", "Missing or empty artifactId in group metadata.", result.getReason() ); + assertTrue( "check there is a 2nd failure", failures.hasNext() ); + result = (RepositoryMetadataResult) failures.next(); + // TODO: should be more robust + assertEquals( "check reason", "Missing or empty artifactId in group metadata.", result.getReason() ); + assertFalse( "check no more failures", failures.hasNext() ); + } + + public void testInvalidPluginPrefix() + throws ReportProcessorException + { + ArtifactReporter reporter = new MockArtifactReporter(); + + RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); + metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", null ) ); + metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "" ) ); + + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); + assertTrue( "check there is a failure", failures.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); + // TODO: should be more robust + assertEquals( "check reason", "Missing or empty plugin prefix for artifactId artifactId.", result.getReason() ); + assertTrue( "check there is a 2nd failure", failures.hasNext() ); + result = (RepositoryMetadataResult) failures.next(); + // TODO: should be more robust + assertEquals( "check reason", "Missing or empty plugin prefix for artifactId snapshot-artifact.", + result.getReason() ); + assertFalse( "check no more failures", failures.hasNext() ); + } + + public void testDuplicatePluginPrefixes() + throws ReportProcessorException + { + ArtifactReporter reporter = new MockArtifactReporter(); + + RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); + metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); + metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default" ) ); + + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); + assertTrue( "check there is a failure", failures.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); + // TODO: should be more robust + assertEquals( "check reason", "Duplicate plugin prefix found: default.", result.getReason() ); + assertFalse( "check no more failures", failures.hasNext() ); + } + + public void testValidSnapshotMetadata() + throws ReportProcessorException + { + ArtifactReporter reporter = new MockArtifactReporter(); + + Artifact artifact = + artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "type" ); + + Snapshot snapshot = new Snapshot(); + snapshot.setBuildNumber( 1 ); + snapshot.setTimestamp( "20050611.202024" ); + + RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot ); + + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); + assertFalse( "check there are no failures", failures.hasNext() ); + } + + public void testInvalidSnapshotMetadata() + throws ReportProcessorException + { + ArtifactReporter reporter = new MockArtifactReporter(); + + Artifact artifact = + artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "type" ); + + Snapshot snapshot = new Snapshot(); + snapshot.setBuildNumber( 2 ); + snapshot.setTimestamp( "20050611.202024" ); + + RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot ); + + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); + assertTrue( "check there is a failure", failures.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); + assertEquals( "check metadata", metadata, result.getMetadata() ); + // TODO: should be more robust + assertEquals( "check reason", "Snapshot artifact 20050611.202024-2 does not exist.", result.getReason() ); + assertFalse( "check no more failures", failures.hasNext() ); + } + + private Plugin createMetadataPlugin( String artifactId, String prefix ) + { + Plugin plugin = new Plugin(); + plugin.setArtifactId( artifactId ); + plugin.setName( artifactId ); + plugin.setPrefix( prefix ); + return plugin; + } +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java new file mode 100644 index 000000000..cfc83b309 --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java @@ -0,0 +1,143 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 junit.framework.TestCase; + +/** + * + */ +public class CacheTest + extends TestCase +{ + private Cache cache; + + private static final double CACHE_HIT_RATIO = 0.5; + + private static final double CACHE_HIT_RATIO_THRESHOLD = 0.75; + + public void testCacheManagementBasedOnHitsRatio() + { + cache = new Cache( CACHE_HIT_RATIO ); + newCacheObjectTests(); + + String key = "key"; + String value = "value"; + for ( int ctr = 1; ctr < 10; ctr++ ) + { + cache.put( key + ctr, value + ctr ); + } + + while ( cache.getHitRate() < CACHE_HIT_RATIO_THRESHOLD ) + { + cache.get( "key2" ); + } + cache.put( "key10", "value10" ); + assertNull( "first key must be expired", cache.get( "key1" ) ); + } + + public void testCacheManagementBasedOnCacheSize() + { + cache = new Cache( 9 ); + newCacheObjectTests(); + + String key = "key"; + String value = "value"; + for ( int ctr = 1; ctr < 10; ctr++ ) + { + cache.put( key + ctr, value + ctr ); + } + + cache.put( "key10", "value10" ); + assertNull( "first key must be expired", cache.get( "key1" ) ); + assertEquals( "check cache size to be max size", 9, cache.size() ); + } + + public void testCacheManagementBasedOnCacheSizeAndHitRate() + { + cache = new Cache( CACHE_HIT_RATIO, 9 ); + newCacheObjectTests(); + + String key = "key"; + String value = "value"; + for ( int ctr = 1; ctr < 5; ctr++ ) + { + cache.put( key + ctr, value + ctr ); + } + + while ( cache.getHitRate() < CACHE_HIT_RATIO ) + { + cache.get( "key3" ); + } + + cache.put( "key10", "value10" ); + assertNull( "first key must be expired", cache.get( "key1" ) ); + + while ( cache.getHitRate() >= CACHE_HIT_RATIO ) + { + cache.get( "key11" ); + } + + for ( int ctr = 5; ctr < 10; ctr++ ) + { + cache.put( key + ctr, value + ctr ); + } + + cache.put( "key11", "value11" ); + assertNull( "second key must be expired", cache.get( "key2" ) ); + assertEquals( "check cache size to be max size", 9, cache.size() ); + } + + public void testCacheOnRedundantData() + { + cache = new Cache( CACHE_HIT_RATIO, 9 ); + newCacheObjectTests(); + + String key = "key"; + String value = "value"; + for ( int ctr = 1; ctr < 10; ctr++ ) + { + cache.put( key + ctr, value + ctr ); + } + + cache.put( "key1", "value1" ); + cache.put( "key10", "value10" ); + assertNull( "second key must be gone", cache.get( "key2" ) ); + assertEquals( "check cache size to be max size", 9, cache.size() ); + } + + private void newCacheObjectTests() + { + assertEquals( (double) 0, cache.getHitRate(), 0 ); + assertEquals( "check cache size", 0, cache.size() ); + + String value = "value"; + String key = "key"; + + cache.put( key, value ); + assertEquals( "check cache hit", value, cache.get( key ) ); + assertEquals( (double) 1, cache.getHitRate(), 0 ); + assertEquals( "check cache size", 1, cache.size() ); + assertNull( "check cache miss", cache.get( "none" ) ); + assertEquals( CACHE_HIT_RATIO, cache.getHitRate(), 0 ); + cache.clear(); + assertNull( "check flushed object", cache.get( "key" ) ); + assertEquals( (double) 0, cache.getHitRate(), 0 ); + assertEquals( "check flushed cache size", 0, cache.size() ); + cache.clear(); + } +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java new file mode 100644 index 000000000..11c0b8e95 --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java @@ -0,0 +1,58 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * + */ +public class CachedRepositoryQueryLayerTest + extends AbstractRepositoryQueryLayerTestCase +{ + + protected void setUp() + throws Exception + { + super.setUp(); + + queryLayer = new CachedRepositoryQueryLayer( repository ); + } + + public void testUseFileCache() + { + testContainsArtifactTrue(); + assertEquals( 0, queryLayer.getCacheHitRate(), 0 ); + testContainsArtifactTrue(); + assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 ); + } + + public void testUseMetadataCache() + throws Exception + { + testArtifactVersionsTrue(); + assertEquals( 0, queryLayer.getCacheHitRate(), 0 ); + testArtifactVersionsTrue(); + assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 ); + } + + public void testUseFileCacheOnSnapshot() + { + testContainsSnapshotArtifactTrue(); + assertEquals( 0, queryLayer.getCacheHitRate(), 0 ); + testContainsSnapshotArtifactTrue(); + assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 ); + } +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java new file mode 100644 index 000000000..64585c52d --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java @@ -0,0 +1,220 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.repository.digest.DigesterException; + +import java.io.File; +import java.io.IOException; +import java.util.Iterator; + +/** + * This class tests the ChecksumArtifactReporter. + * It extends the AbstractChecksumArtifactReporterTestCase class. + */ +public class ChecksumArtifactReporterTest + extends AbstractChecksumArtifactReporterTestCase +{ + private ArtifactReportProcessor artifactReportProcessor; + + private ArtifactReporter reporter = new MockArtifactReporter(); + + private MetadataReportProcessor metadataReportProcessor; + + public void setUp() + throws Exception + { + super.setUp(); + artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "checksum" ); + metadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE, "checksum-metadata" ); + } + + /** + * Test the ChecksumArtifactReporter when the checksum files are valid. + */ + public void testChecksumArtifactReporterSuccess() + throws ReportProcessorException, IOException, DigesterException + { + createChecksumFile( "VALID" ); + createChecksumFile( "INVALID" ); + + ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); + VersionRange version = VersionRange.createFromVersion( "1.0" ); + Artifact artifact = + new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler ); + + artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); + assertEquals( 2, reporter.getSuccesses() ); + } + + /** + * Test the ChecksumArtifactReporter when the checksum files are invalid. + */ + public void testChecksumArtifactReporterFailed() + throws ReportProcessorException + { + ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); + VersionRange version = VersionRange.createFromVersion( "1.0" ); + Artifact artifact = + new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler ); + + artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); + assertEquals( 2, reporter.getFailures() ); + } + + /** + * Test the valid checksum of a metadata file. + * The reporter should report 2 success validation. + */ + public void testChecksumMetadataReporterSuccess() + throws ReportProcessorException, DigesterException, IOException + { + createMetadataFile( "VALID" ); + createMetadataFile( "INVALID" ); + + ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); + VersionRange version = VersionRange.createFromVersion( "1.0" ); + Artifact artifact = + new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler ); + + //Version level metadata + RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); + metadataReportProcessor.processMetadata( metadata, repository, reporter ); + + //Artifact level metadata + metadata = new ArtifactRepositoryMetadata( artifact ); + metadataReportProcessor.processMetadata( metadata, repository, reporter ); + + //Group level metadata + metadata = new GroupRepositoryMetadata( "checksumTest" ); + metadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator iter = reporter.getRepositoryMetadataSuccessIterator(); + assertTrue( "check if there is a success", iter.hasNext() ); + } + + /** + * Test the corrupted checksum of a metadata file. + * The reporter must report 2 failures. + */ + public void testChecksumMetadataReporterFailure() + throws ReportProcessorException + { + ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); + VersionRange version = VersionRange.createFromVersion( "1.0" ); + Artifact artifact = + new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler ); + + RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); + metadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator iter = reporter.getRepositoryMetadataFailureIterator(); + assertTrue( "check if there is a failure", iter.hasNext() ); + } + + /** + * Test the checksum of an artifact located in a remote location. + */ + /* public void testChecksumArtifactRemote() + { + ArtifactHandler handler = new DefaultArtifactHandler( remoteArtifactType ); + VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion ); + Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version, remoteArtifactScope, + remoteArtifactType, "", handler ); + ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl, + new DefaultRepositoryLayout() ); + + artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); + if ( reporter.getFailures() == 2 ) + assertTrue( reporter.getFailures() == 2 ); + + if ( reporter.getSuccesses() == 2 ) + assertTrue( reporter.getSuccesses() == 2 ); + + } + */ + + /** + * Test the checksum of a metadata file located in a remote location. + */ + /* public void testChecksumMetadataRemote() + { + + try + { + ArtifactHandler handler = new DefaultArtifactHandler( remoteArtifactType ); + VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion ); + Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version, + remoteArtifactScope, remoteArtifactType, "", handler ); + ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl, + new DefaultRepositoryLayout() ); + + RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); + + metadataReportProcessor.processMetadata( metadata, repository, reporter ); + Iterator iter = reporter.getRepositoryMetadataFailureIterator(); + if ( iter.hasNext() ) + assertTrue( "check if there is a failure", iter.hasNext() ); + + iter = reporter.getRepositoryMetadataSuccessIterator(); + if ( iter.hasNext() ) + assertTrue( "check if there is a success", iter.hasNext() ); + + } + catch ( Exception e ) + { + e.printStackTrace(); + } + } + */ + + /** + * Test the conditional when the checksum files of the artifact & metadata do not exist. + */ + public void testChecksumFilesDoNotExist() + throws ReportProcessorException, DigesterException, IOException + { + createChecksumFile( "VALID" ); + createMetadataFile( "VALID" ); + deleteChecksumFiles( "jar" ); + + ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); + VersionRange version = VersionRange.createFromVersion( "1.0" ); + Artifact artifact = + new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler ); + + artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); + assertEquals( 2, reporter.getFailures() ); + + RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); + metadataReportProcessor.processMetadata( metadata, repository, reporter ); + + Iterator iter = reporter.getRepositoryMetadataFailureIterator(); + assertTrue( "check if there is a failure", iter.hasNext() ); + + deleteTestDirectory( new File( repository.getBasedir() + "checksumTest" ) ); + } +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java new file mode 100644 index 000000000..ac19ab3e0 --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java @@ -0,0 +1,184 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.apache.maven.artifact.repository.metadata.Versioning; + +import java.util.Iterator; + +/** + * + */ +public class DefaultArtifactReporterTest + extends AbstractRepositoryReportsTestCase +{ + private ArtifactReporter reporter; + + private Artifact artifact; + + private RepositoryMetadata metadata; + + public void testEmptyArtifactReporter() + { + assertEquals( "No failures", 0, reporter.getFailures() ); + assertEquals( "No warnings", 0, reporter.getWarnings() ); + assertEquals( "No successes", 0, reporter.getSuccesses() ); + assertFalse( "No artifact failures", reporter.getArtifactFailureIterator().hasNext() ); + assertFalse( "No artifact warnings", reporter.getArtifactWarningIterator().hasNext() ); + assertFalse( "No artifact successes", reporter.getArtifactSuccessIterator().hasNext() ); + assertFalse( "No metadata failures", reporter.getRepositoryMetadataFailureIterator().hasNext() ); + assertFalse( "No metadata warnings", reporter.getRepositoryMetadataWarningIterator().hasNext() ); + assertFalse( "No metadata successes", reporter.getRepositoryMetadataSuccessIterator().hasNext() ); + } + + public void testMetadataSingleFailure() + { + reporter.addFailure( metadata, "Single Failure Reason" ); + assertEquals( "failures count", 1, reporter.getFailures() ); + assertEquals( "warnings count", 0, reporter.getWarnings() ); + assertEquals( "successes count", 0, reporter.getSuccesses() ); + + Iterator results = reporter.getRepositoryMetadataFailureIterator(); + assertTrue( "must have failures", results.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) results.next(); + assertEquals( "check failure cause", metadata, result.getMetadata() ); + assertEquals( "check failure reason", "Single Failure Reason", result.getReason() ); + assertFalse( "no more failures", results.hasNext() ); + } + + public void testMetadataMultipleFailures() + { + reporter.addFailure( metadata, "First Failure Reason" ); + reporter.addFailure( metadata, "Second Failure Reason" ); + assertEquals( "failures count", 2, reporter.getFailures() ); + assertEquals( "warnings count", 0, reporter.getWarnings() ); + assertEquals( "successes count", 0, reporter.getSuccesses() ); + + Iterator results = reporter.getRepositoryMetadataFailureIterator(); + assertTrue( "must have failures", results.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) results.next(); + assertEquals( "check failure cause", metadata, result.getMetadata() ); + assertEquals( "check failure reason", "First Failure Reason", result.getReason() ); + assertTrue( "must have 2nd failure", results.hasNext() ); + result = (RepositoryMetadataResult) results.next(); + assertEquals( "check failure cause", metadata, result.getMetadata() ); + assertEquals( "check failure reason", "Second Failure Reason", result.getReason() ); + assertFalse( "no more failures", results.hasNext() ); + } + + public void testMetadataSingleWarning() + { + reporter.addWarning( metadata, "Single Warning Message" ); + assertEquals( "failures count", 0, reporter.getFailures() ); + assertEquals( "warnings count", 1, reporter.getWarnings() ); + assertEquals( "successes count", 0, reporter.getSuccesses() ); + + Iterator results = reporter.getRepositoryMetadataWarningIterator(); + assertTrue( "must have failures", results.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) results.next(); + assertEquals( "check failure cause", metadata, result.getMetadata() ); + assertEquals( "check failure reason", "Single Warning Message", result.getReason() ); + assertFalse( "no more failures", results.hasNext() ); + } + + public void testMetadataMultipleWarnings() + { + reporter.addWarning( metadata, "First Warning" ); + reporter.addWarning( metadata, "Second Warning" ); + assertEquals( "failures count", 0, reporter.getFailures() ); + assertEquals( "warnings count", 2, reporter.getWarnings() ); + assertEquals( "successes count", 0, reporter.getSuccesses() ); + + Iterator results = reporter.getRepositoryMetadataWarningIterator(); + assertTrue( "must have warnings", results.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) results.next(); + assertEquals( "check failure cause", metadata, result.getMetadata() ); + assertEquals( "check failure reason", "First Warning", result.getReason() ); + assertTrue( "must have 2nd warning", results.hasNext() ); + result = (RepositoryMetadataResult) results.next(); + assertEquals( "check failure cause", metadata, result.getMetadata() ); + assertEquals( "check failure reason", "Second Warning", result.getReason() ); + assertFalse( "no more failures", results.hasNext() ); + } + + public void testMetadataSingleSuccess() + { + reporter.addSuccess( metadata ); + assertEquals( "failures count", 0, reporter.getFailures() ); + assertEquals( "warnings count", 0, reporter.getWarnings() ); + assertEquals( "successes count", 1, reporter.getSuccesses() ); + + Iterator results = reporter.getRepositoryMetadataSuccessIterator(); + assertTrue( "must have successes", results.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) results.next(); + assertEquals( "check success metadata", metadata, result.getMetadata() ); + assertNull( "check no reason", result.getReason() ); + assertFalse( "no more failures", results.hasNext() ); + } + + public void testMetadataMultipleSuccesses() + { + Versioning versioning = new Versioning(); + versioning.addVersion( "1.0-beta-1" ); + versioning.addVersion( "1.0-beta-2" ); + RepositoryMetadata metadata2 = new ArtifactRepositoryMetadata( artifact, versioning ); + + reporter.addSuccess( metadata ); + reporter.addSuccess( metadata2 ); + assertEquals( "failures count", 0, reporter.getFailures() ); + assertEquals( "warnings count", 0, reporter.getWarnings() ); + assertEquals( "successes count", 2, reporter.getSuccesses() ); + + Iterator results = reporter.getRepositoryMetadataSuccessIterator(); + assertTrue( "must have successes", results.hasNext() ); + RepositoryMetadataResult result = (RepositoryMetadataResult) results.next(); + assertEquals( "check success metadata", metadata, result.getMetadata() ); + assertNull( "check no reason", result.getReason() ); + assertTrue( "must have 2nd success", results.hasNext() ); + result = (RepositoryMetadataResult) results.next(); + assertEquals( "check success metadata", metadata2, result.getMetadata() ); + assertNull( "check no reason", result.getReason() ); + assertFalse( "no more successes", results.hasNext() ); + } + + protected void setUp() + throws Exception + { + super.setUp(); + + reporter = new DefaultArtifactReporter(); + ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); + + Versioning versioning = new Versioning(); + versioning.addVersion( "1.0-alpha-1" ); + versioning.addVersion( "1.0-alpha-2" ); + } + + protected void tearDown() + throws Exception + { + super.tearDown(); + + reporter = null; + metadata = null; + } +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java new file mode 100644 index 000000000..31dec3015 --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java @@ -0,0 +1,149 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.model.Model; +import org.apache.maven.repository.indexing.RepositoryArtifactIndex; +import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; +import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.util.Collections; + +/** + * @author Edwin Punzalan + */ +public class DuplicateArtifactFileReportProcessorTest + extends AbstractRepositoryReportsTestCase +{ + private Artifact artifact; + + private Model model; + + private ArtifactReportProcessor processor; + + private ArtifactFactory artifactFactory; + + File indexDirectory; + + protected void setUp() + throws Exception + { + super.setUp(); + + indexDirectory = getTestFile( "target/indexDirectory" ); + FileUtils.deleteDirectory( indexDirectory ); + + artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "jar" ); + model = new Model(); + + RepositoryArtifactIndexFactory factory = + (RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" ); + + RepositoryArtifactIndex index = factory.createStandardIndex( indexDirectory ); + + RepositoryIndexRecordFactory recordFactory = + (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "standard" ); + + index.indexRecords( Collections.singletonList( recordFactory.createRecord( artifact ) ) ); + + processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "duplicate" ); + } + + public void testNullArtifactFile() + throws Exception + { + artifact.setFile( null ); + + MockArtifactReporter reporter = new MockArtifactReporter(); + + processor.processArtifact( model, artifact, reporter, repository ); + + assertEquals( "Check no successes", 0, reporter.getSuccesses() ); + assertEquals( "Check warnings", 1, reporter.getWarnings() ); + assertEquals( "Check no failures", 0, reporter.getFailures() ); + } + + public void testSuccessOnAlreadyIndexedArtifact() + throws Exception + { + MockArtifactReporter reporter = new MockArtifactReporter(); + + processor.processArtifact( model, artifact, reporter, repository ); + + assertEquals( "Check no successes", 1, reporter.getSuccesses() ); + assertEquals( "Check warnings", 0, reporter.getWarnings() ); + assertEquals( "Check no failures", 0, reporter.getFailures() ); + } + + public void testSuccessOnDifferentGroupId() + throws Exception + { + MockArtifactReporter reporter = new MockArtifactReporter(); + + artifact.setGroupId( "different.groupId" ); + processor.processArtifact( model, artifact, reporter, repository ); + + assertEquals( "Check no successes", 1, reporter.getSuccesses() ); + assertEquals( "Check warnings", 0, reporter.getWarnings() ); + assertEquals( "Check no failures", 0, reporter.getFailures() ); + } + + public void testSuccessOnNewArtifact() + throws Exception + { + Artifact newArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "pom" ); + + MockArtifactReporter reporter = new MockArtifactReporter(); + + processor.processArtifact( model, newArtifact, reporter, repository ); + + assertEquals( "Check no successes", 1, reporter.getSuccesses() ); + assertEquals( "Check warnings", 0, reporter.getWarnings() ); + assertEquals( "Check no failures", 0, reporter.getFailures() ); + } + + public void testFailure() + throws Exception + { + Artifact duplicate = createArtifact( artifact.getGroupId(), "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", + artifact.getVersion(), artifact.getType() ); + duplicate.setFile( artifact.getFile() ); + + MockArtifactReporter reporter = new MockArtifactReporter(); + + processor.processArtifact( model, duplicate, reporter, repository ); + + assertEquals( "Check no successes", 0, reporter.getSuccesses() ); + assertEquals( "Check warnings", 0, reporter.getWarnings() ); + assertEquals( "Check no failures", 1, reporter.getFailures() ); + } + + private Artifact createArtifact( String groupId, String artifactId, String baseVersion, String version, + String type ) + { + Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, type ); + artifact.setBaseVersion( baseVersion ); + artifact.setRepository( repository ); + artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); + return artifact; + } +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java new file mode 100644 index 000000000..7ab3de250 --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java @@ -0,0 +1,62 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Edwin Punzalan + */ +public class GenericMockObject + implements InvocationHandler +{ + private Map invocations = new HashMap(); + + public GenericMockObject() + { + //default constructor + } + + public GenericMockObject( Map returnMap ) + { + invocations = new HashMap( returnMap ); + } + + public void setExpectedReturns( Method method, List returnList ) + { + invocations.put( method, returnList ); + } + + public Object invoke( Object proxy, Method method, Object[] args ) + { + if ( !invocations.containsKey( method ) ) + { + throw new UnsupportedOperationException( "No expected return values defined." ); + } + + List returnList = (List) invocations.get( method ); + if ( returnList.size() < 1 ) + { + throw new UnsupportedOperationException( "Too few expected return values defined." ); + } + return returnList.remove( 0 ); + } +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessorTest.java new file mode 100644 index 000000000..71c53d8bd --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessorTest.java @@ -0,0 +1,109 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.artifact.versioning.VersionRange; + +/** + * This class tests the InvalidPomArtifactReportProcessor class. + */ +public class InvalidPomArtifactReportProcessorTest + extends AbstractRepositoryReportsTestCase +{ + private ArtifactReportProcessor artifactReportProcessor; + + private ArtifactReporter reporter = new MockArtifactReporter(); + + public void setUp() + throws Exception + { + super.setUp(); + artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "invalid-pom" ); + } + + /** + * Test the InvalidPomArtifactReportProcessor when the artifact is an invalid pom. + */ + public void testInvalidPomArtifactReportProcessorFailure() + throws ReportProcessorException + { + ArtifactHandler handler = new DefaultArtifactHandler( "pom" ); + VersionRange version = VersionRange.createFromVersion( "1.0-alpha-3" ); + Artifact artifact = + new DefaultArtifact( "org.apache.maven", "artifactId", version, "compile", "pom", "", handler ); + + artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); + assertEquals( 1, reporter.getFailures() ); + } + + + /** + * Test the InvalidPomArtifactReportProcessor when the artifact is a valid pom. + */ + public void testInvalidPomArtifactReportProcessorSuccess() + throws ReportProcessorException + { + ArtifactHandler handler = new DefaultArtifactHandler( "pom" ); + VersionRange version = VersionRange.createFromVersion( "1.0-alpha-2" ); + Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "pom", "", handler ); + + artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); + assertEquals( 1, reporter.getSuccesses() ); + } + + + /** + * Test the InvalidPomArtifactReportProcessor when the artifact is not a pom. + */ + public void testNotAPomArtifactReportProcessorSuccess() + throws ReportProcessorException + { + ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); + VersionRange version = VersionRange.createFromVersion( "1.0-alpha-1" ); + Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler ); + + artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); + assertEquals( 1, reporter.getWarnings() ); + } + + /** + * Test the InvalidPomArtifactReportProcessor when the pom is located in + * a remote repository. + */ + /* public void testRemotePomArtifactReportProcessorSuccess(){ + try{ + ArtifactHandler handler = new DefaultArtifactHandler( "pom" ); + VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion ); + Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version, remoteArtifactScope, + "pom", "", handler ); + ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl, + new DefaultRepositoryLayout() ); + + artifactReportProcessor.processArtifact(null, artifact, reporter, repository); + if(reporter.getSuccesses() == 1) + assertTrue(reporter.getSuccesses() == 1); + + }catch(Exception e){ + + } + } + */ +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessorTest.java new file mode 100644 index 000000000..d892dd3a6 --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessorTest.java @@ -0,0 +1,224 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; + +/** + * This class tests the LocationArtifactReportProcessor. + */ +public class LocationArtifactReportProcessorTest + extends AbstractRepositoryReportsTestCase +{ + private ArtifactReportProcessor artifactReportProcessor; + + private ArtifactReporter reporter = new MockArtifactReporter(); + + private MavenXpp3Reader pomReader; + + public void setUp() + throws Exception + { + super.setUp(); + artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "artifact-location" ); + pomReader = new MavenXpp3Reader(); + } + + public void tearDown() + throws Exception + { + super.tearDown(); + artifactReportProcessor = null; + pomReader = null; + } + + /** + * Test the LocationArtifactReporter when the artifact's physical location matches the location specified + * both in the file system pom and in the pom included in the package. + */ + public void testPackagedPomLocationArtifactReporterSuccess() + throws ReportProcessorException, IOException, XmlPullParserException + { + ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); + VersionRange version = VersionRange.createFromVersion( "2.0" ); + Artifact artifact = + new DefaultArtifact( "org.apache.maven", "maven-model", version, "compile", "jar", "", handler ); + + String path = "org/apache/maven/maven-model/2.0/maven-model-2.0.pom"; + Model model = readPom( path ); + + artifactReportProcessor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 1, reporter.getSuccesses() ); + } + + /** + * Test the LocationArtifactReporter when the artifact is in the location specified in the + * file system pom (but the jar file does not have a pom included in its package). + */ + public void testLocationArtifactReporterSuccess() + throws ReportProcessorException, IOException, XmlPullParserException + { + ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); + VersionRange version = VersionRange.createFromVersion( "1.0-alpha-1" ); + Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler ); + + String path = "groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom"; + Model model = readPom( path ); + + artifactReportProcessor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 1, reporter.getSuccesses() ); + } + + /** + * Test the LocationArtifactReporter when the artifact is not in the location specified + * in the file system pom. + */ + public void testLocationArtifactReporterFailure() + throws IOException, XmlPullParserException, ReportProcessorException + { + ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); + VersionRange version = VersionRange.createFromVersion( "1.0-alpha-2" ); + Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler ); + + String path = "groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom"; + Model model = readPom( path ); + + artifactReportProcessor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 1, reporter.getFailures() ); + } + + /** + * Test the LocationArtifactReporter when the artifact's physical location does not match the + * location in the file system pom but instead matches the specified location in the packaged pom. + */ + public void testFsPomArtifactMatchFailure() + throws IOException, ReportProcessorException, XmlPullParserException + { + ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); + VersionRange version = VersionRange.createFromVersion( "2.0" ); + Artifact artifact = + new DefaultArtifact( "org.apache.maven", "maven-archiver", version, "compile", "jar", "", handler ); + + String path = "org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom"; + Model model = readPom( path ); + + artifactReportProcessor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 1, reporter.getFailures() ); + } + + private Model readPom( String path ) + throws IOException, XmlPullParserException + { + Reader reader = new FileReader( new File( repository.getBasedir(), path ) ); + Model model = pomReader.read( reader ); + // hokey inheritence to avoid some errors right now + if ( model.getGroupId() == null ) + { + model.setGroupId( model.getParent().getGroupId() ); + } + if ( model.getVersion() == null ) + { + model.setVersion( model.getParent().getVersion() ); + } + return model; + } + + /** + * Test the LocationArtifactReporter when the artifact's physical location does not match the + * location specified in the packaged pom but matches the location specified in the file system pom. + */ + public void testPkgPomArtifactMatchFailure() + throws IOException, XmlPullParserException, ReportProcessorException + { + ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); + VersionRange version = VersionRange.createFromVersion( "2.1" ); + Artifact artifact = + new DefaultArtifact( "org.apache.maven", "maven-monitor", version, "compile", "jar", "", handler ); + + String path = "org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.pom"; + Model model = readPom( path ); + + artifactReportProcessor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 1, reporter.getFailures() ); + } + + /** + * Test the LocationArtifactReporter when the artifact's physical location does not match both the + * location specified in the packaged pom and the location specified in the file system pom. + */ + public void testBothPomArtifactMatchFailure() + throws IOException, XmlPullParserException, ReportProcessorException + { + ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); + VersionRange version = VersionRange.createFromVersion( "2.1" ); + Artifact artifact = + new DefaultArtifact( "org.apache.maven", "maven-project", version, "compile", "jar", "", handler ); + + String path = "org/apache/maven/maven-project/2.1/maven-project-2.1.pom"; + Model model = readPom( path ); + + artifactReportProcessor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 1, reporter.getFailures() ); + } + + /** + * Test the LocationArtifactReportProcessor when the artifact is located in the remote repository. + */ + /* public void testRemoteArtifactReportProcessorFailure() + { + + ArtifactHandler handler = new DefaultArtifactHandler( remoteArtifactType ); + VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion ); + Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version, remoteArtifactScope, + remoteArtifactType, "", handler ); + ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl, + new DefaultRepositoryLayout() ); + try + { + URL url = new URL( remoteRepoUrl + remoteArtifactGroup + "/" + remoteArtifactId + "/" + + remoteArtifactVersion + "/" + remoteArtifactId + "-" + remoteArtifactVersion + ".pom" ); + InputStream is = url.openStream(); + Reader reader = new InputStreamReader( is ); + Model model = pomReader.read( reader ); + + artifactReportProcessor.processArtifact( model, artifact, reporter, repository ); + if ( reporter.getFailures() > 0 ) + assertTrue( reporter.getFailures() == 1 ); + + if ( reporter.getSuccesses() > 0 ) + assertTrue( reporter.getSuccesses() == 1 ); + + } + catch ( Exception e ) + { + e.printStackTrace(); + } + } + */ +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifact.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifact.java new file mode 100644 index 000000000..a9f3cd3f2 --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifact.java @@ -0,0 +1,258 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.OverConstrainedVersionException; +import org.apache.maven.artifact.versioning.VersionRange; + +import java.io.File; +import java.util.Collection; +import java.util.List; + +/** + * @noinspection ReturnOfNull + */ +public class MockArtifact + implements Artifact +{ + private String groupId; + + private String artifactId; + + private String version; + + public String getGroupId() + { + return groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public String getVersion() + { + return version; + } + + public void setVersion( String s ) + { + version = s; + } + + public String getScope() + { + return null; + } + + public String getType() + { + return null; + } + + public String getClassifier() + { + return null; + } + + public boolean hasClassifier() + { + return false; + } + + public File getFile() + { + return null; + } + + public void setFile( File file ) + { + } + + public String getBaseVersion() + { + return null; + } + + public void setBaseVersion( String s ) + { + } + + public String getId() + { + return null; + } + + public String getDependencyConflictId() + { + return null; + } + + public void addMetadata( ArtifactMetadata artifactMetadata ) + { + } + + public Collection getMetadataList() + { + return null; + } + + public void setRepository( ArtifactRepository artifactRepository ) + { + } + + public ArtifactRepository getRepository() + { + return null; + } + + public void updateVersion( String s, ArtifactRepository artifactRepository ) + { + } + + public String getDownloadUrl() + { + return null; + } + + public void setDownloadUrl( String s ) + { + } + + public ArtifactFilter getDependencyFilter() + { + return null; + } + + public void setDependencyFilter( ArtifactFilter artifactFilter ) + { + } + + public ArtifactHandler getArtifactHandler() + { + return null; + } + + public List getDependencyTrail() + { + return null; + } + + public void setDependencyTrail( List list ) + { + } + + public void setScope( String s ) + { + } + + public VersionRange getVersionRange() + { + return null; + } + + public void setVersionRange( VersionRange versionRange ) + { + } + + public void selectVersion( String s ) + { + } + + public void setGroupId( String s ) + { + groupId = s; + } + + public void setArtifactId( String s ) + { + artifactId = s; + } + + public boolean isSnapshot() + { + return false; + } + + public void setResolved( boolean b ) + { + } + + public boolean isResolved() + { + return false; + } + + public void setResolvedVersion( String s ) + { + } + + public void setArtifactHandler( ArtifactHandler artifactHandler ) + { + } + + public boolean isRelease() + { + return false; + } + + public void setRelease( boolean b ) + { + } + + public List getAvailableVersions() + { + return null; + } + + public void setAvailableVersions( List list ) + { + } + + public boolean isOptional() + { + return false; + } + + public ArtifactVersion getSelectedVersion() + throws OverConstrainedVersionException + { + return null; + } + + public boolean isSelectedVersionKnown() + throws OverConstrainedVersionException + { + return false; + } + + public int compareTo( Object o ) + { + return 0; + } + + public void setOptional( boolean b ) + { + } +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactFactory.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactFactory.java new file mode 100644 index 000000000..7bdc708a9 --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactFactory.java @@ -0,0 +1,92 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.versioning.VersionRange; + +/** + * @noinspection ReturnOfNull + */ +public class MockArtifactFactory + implements ArtifactFactory +{ + public Artifact createArtifact( String s, String s1, String s2, String s3, String s4 ) + { + return null; + } + + public Artifact createArtifactWithClassifier( String s, String s1, String s2, String s3, String s4 ) + { + return null; + } + + public Artifact createDependencyArtifact( String s, String s1, VersionRange versionRange, String s2, String s3, + String s4 ) + { + return null; + } + + public Artifact createDependencyArtifact( String s, String s1, VersionRange versionRange, String s2, String s3, + String s4, String s5 ) + { + return null; + } + + public Artifact createDependencyArtifact( String s, String s1, VersionRange versionRange, String s2, String s3, + String s4, String s5, boolean b ) + { + return null; + } + + public Artifact createBuildArtifact( String s, String s1, String s2, String s3 ) + { + return null; + } + + public Artifact createProjectArtifact( String s, String s1, String s2 ) + { + return null; + } + + public Artifact createParentArtifact( String s, String s1, String s2 ) + { + return null; + } + + public Artifact createPluginArtifact( String s, String s1, VersionRange versionRange ) + { + return null; + } + + public Artifact createProjectArtifact( String s, String s1, String s2, String s3 ) + { + return null; + } + + public Artifact createExtensionArtifact( String s, String s1, VersionRange versionRange ) + { + return null; + } + + public Artifact createDependencyArtifact( String string, String string1, VersionRange versionRange, String string2, + String string3, String string4, boolean b ) + { + return null; + } +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java new file mode 100644 index 000000000..00bdc23ae --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java @@ -0,0 +1,80 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Model; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * + */ +public class MockArtifactReportProcessor + implements ArtifactReportProcessor +{ + private List reportConditions; + + private Iterator iterator; + + public MockArtifactReportProcessor() + { + reportConditions = new ArrayList(); + } + + public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, + ArtifactRepository repository ) + { + if ( iterator == null || !iterator.hasNext() ) // not initialized or reached end of the list. start again + { + iterator = reportConditions.iterator(); + } + if ( !reportConditions.isEmpty() ) + { + while ( iterator.hasNext() ) + { + ReportCondition reportCondition = (ReportCondition) iterator.next(); + int i = reportCondition.getResult(); + if ( i == ReportCondition.SUCCESS ) + { + reporter.addSuccess( reportCondition.getArtifact() ); + } + else if ( i == ReportCondition.WARNING ) + { + reporter.addWarning( reportCondition.getArtifact(), reportCondition.getReason() ); + } + else if ( i == ReportCondition.FAILURE ) + { + reporter.addFailure( reportCondition.getArtifact(), reportCondition.getReason() ); + } + } + } + } + + public void addReturnValue( int result, Artifact artifact, String reason ) + { + reportConditions.add( new ReportCondition( result, artifact, reason ) ); + } + + public void clearList() + { + reportConditions.clear(); + } +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java new file mode 100755 index 000000000..f13e660cf --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java @@ -0,0 +1,121 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * Mock implementation of the artifact reporter. + * + * @author Brett Porter + * @version $Id$ + */ +public class MockArtifactReporter + implements ArtifactReporter +{ + private List artifactFailures = new ArrayList(); + + private List artifactSuccesses = new ArrayList(); + + private List artifactWarnings = new ArrayList(); + + private List metadataFailures = new ArrayList(); + + private List metadataSuccesses = new ArrayList(); + + private List metadataWarnings = new ArrayList(); + + public void addFailure( Artifact artifact, String reason ) + { + artifactFailures.add( new ArtifactResult( artifact, reason ) ); + } + + public void addSuccess( Artifact artifact ) + { + artifactSuccesses.add( new ArtifactResult( artifact ) ); + } + + public void addWarning( Artifact artifact, String message ) + { + artifactWarnings.add( new ArtifactResult( artifact, message ) ); + } + + public void addFailure( RepositoryMetadata metadata, String reason ) + { + metadataFailures.add( new RepositoryMetadataResult( metadata, reason ) ); + } + + public void addSuccess( RepositoryMetadata metadata ) + { + metadataSuccesses.add( new RepositoryMetadataResult( metadata ) ); + } + + public void addWarning( RepositoryMetadata metadata, String message ) + { + metadataWarnings.add( new RepositoryMetadataResult( metadata, message ) ); + } + + public Iterator getArtifactFailureIterator() + { + return artifactFailures.iterator(); + } + + public Iterator getArtifactSuccessIterator() + { + return artifactSuccesses.iterator(); + } + + public Iterator getArtifactWarningIterator() + { + return artifactWarnings.iterator(); + } + + public Iterator getRepositoryMetadataFailureIterator() + { + return metadataFailures.iterator(); + } + + public Iterator getRepositoryMetadataSuccessIterator() + { + return metadataSuccesses.iterator(); + } + + public Iterator getRepositoryMetadataWarningIterator() + { + return metadataWarnings.iterator(); + } + + public int getFailures() + { + return artifactFailures.size(); + } + + public int getSuccesses() + { + return artifactSuccesses.size(); + } + + public int getWarnings() + { + return artifactWarnings.size(); + } +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java new file mode 100644 index 000000000..e6ec4eef3 --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java @@ -0,0 +1,79 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; +import org.apache.maven.artifact.repository.metadata.Snapshot; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +/** + * + */ +public class MockRepositoryQueryLayer + implements RepositoryQueryLayer +{ + private List queryConditions; + + private Iterator iterator; + + public MockRepositoryQueryLayer() + { + queryConditions = new ArrayList(); + } + + public boolean containsArtifact( Artifact artifact ) + { + if ( iterator == null || !iterator.hasNext() ) // not initialized or reached end of the list. start again + { + iterator = queryConditions.iterator(); + } + boolean b; + if ( queryConditions.isEmpty() ) + { + b = false; + } + else + { + b = ( (Boolean) iterator.next() ).booleanValue(); + } + return b; + } + + public void addReturnValue( boolean queryCondition ) + { + queryConditions.add( Boolean.valueOf( queryCondition ) ); + } + + public void clearList() + { + queryConditions.clear(); + } + + public boolean containsArtifact( Artifact artifact, Snapshot snapshot ) + { + return containsArtifact( artifact ); + } + + public List getVersions( Artifact artifact ) + { + return Collections.EMPTY_LIST; + } +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java new file mode 100644 index 000000000..98df89646 --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java @@ -0,0 +1,74 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.artifact.Artifact; + +/** + * + */ +public class ReportCondition +{ + public static final int SUCCESS = 0; + + public static final int FAILURE = -1; + + public static final int WARNING = 1; + + private int result; + + private Artifact artifact; + + private String reason; + + public ReportCondition( int result, Artifact artifact, String reason ) + { + this.result = result; + this.artifact = artifact; + this.reason = reason; + } + + public int getResult() + { + return result; + } + + public void setResult( int result ) + { + this.result = result; + } + + public Artifact getArtifact() + { + return artifact; + } + + public void setArtifact( Artifact artifact ) + { + this.artifact = artifact; + } + + public String getReason() + { + return reason; + } + + public void setReason( String reason ) + { + this.reason = reason; + } +} diff --git a/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.jar b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.jar new file mode 100644 index 000000000..c2ea777c1 Binary files /dev/null and b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.jar differ diff --git a/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom new file mode 100644 index 000000000..24bca8028 --- /dev/null +++ b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom @@ -0,0 +1,6 @@ + + 4.0.0 + groupId + artifactId + 1.0-alpha-1 + diff --git a/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom new file mode 100644 index 000000000..fd07c6f14 --- /dev/null +++ b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom @@ -0,0 +1,6 @@ + + 4.0.0 + groupId + artifactId + 1.0-alpha-2 + diff --git a/archiva-reports-standard/src/test/repository/groupId/artifactId/maven-metadata.xml b/archiva-reports-standard/src/test/repository/groupId/artifactId/maven-metadata.xml new file mode 100644 index 000000000..a8ea6e7e0 --- /dev/null +++ b/archiva-reports-standard/src/test/repository/groupId/artifactId/maven-metadata.xml @@ -0,0 +1,27 @@ + + + + groupId + artifactId + 1.0-alpha-1 + + + 1.0-alpha-1 + 1.0-alpha-2 + + + diff --git a/archiva-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-20050611.202024-1.pom b/archiva-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-20050611.202024-1.pom new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-SNAPSHOT.pom b/archiva-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-SNAPSHOT.pom new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-reports-standard/src/test/repository/groupId/unexpectedfile.xml b/archiva-reports-standard/src/test/repository/groupId/unexpectedfile.xml new file mode 100644 index 000000000..44c9d51ff --- /dev/null +++ b/archiva-reports-standard/src/test/repository/groupId/unexpectedfile.xml @@ -0,0 +1,17 @@ +This file is here to make sure that it will not be processed during unit + + test. \ No newline at end of file diff --git a/archiva-reports-standard/src/test/repository/maven-metadata.xml b/archiva-reports-standard/src/test/repository/maven-metadata.xml new file mode 100644 index 000000000..9efaee38c --- /dev/null +++ b/archiva-reports-standard/src/test/repository/maven-metadata.xml @@ -0,0 +1,21 @@ + + + + checksumTest + invalidArtifact + 1.0 + diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/artifactId/1.0-alpha-3/artifactId-1.0-alpha-3.pom b/archiva-reports-standard/src/test/repository/org/apache/maven/artifactId/1.0-alpha-3/artifactId-1.0-alpha-3.pom new file mode 100644 index 000000000..31d626277 --- /dev/null +++ b/archiva-reports-standard/src/test/repository/org/apache/maven/artifactId/1.0-alpha-3/artifactId-1.0-alpha-3.pom @@ -0,0 +1,9 @@ + + 4.0.0 + org.apache.maven + artifactId + 1.0-alpha-3 + + + + diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.jar b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.jar new file mode 100644 index 000000000..2acfe605d Binary files /dev/null and b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.jar differ diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom new file mode 100644 index 000000000..e5cbe38fd --- /dev/null +++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom @@ -0,0 +1,31 @@ + + + maven + org.apache.maven + 2.1 + + 4.0.0 + maven-archiver + Maven Archiver + 2.1 + + + org.apache.maven + maven-project + 2.0 + + + org.codehaus.plexus + plexus-archiver + 1.0-alpha-3 + + + org.apache.maven + maven-artifact + 2.0 + + + + deployed + + diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/note.txt b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/note.txt new file mode 100644 index 000000000..bc218ba95 --- /dev/null +++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/note.txt @@ -0,0 +1,4 @@ +- The artifact location does not match the location specified in the file system, but + matches the location specified in the pom included in the package. +- The groupId, artifactId and version of the pom in the file system does not match + the groupId, artifactId and version of the pom included in the package. diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar new file mode 100644 index 000000000..d6820d6fe Binary files /dev/null and b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar differ diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom new file mode 100644 index 000000000..17bc67891 --- /dev/null +++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom @@ -0,0 +1,86 @@ + + + maven + org.apache.maven + 2.0 + + 4.0.0 + org.apache.maven + maven-model + Maven Model + 2.0 + Maven Model + + + + org.codehaus.modello + modello-maven-plugin + + + + xpp3-writer + java + xpp3-reader + xsd + + + + + 4.0.0 + maven.mdo + + + + + + + all-models + + + + org.codehaus.modello + modello-maven-plugin + + + v3 + + xpp3-writer + java + xpp3-reader + xsd + + + 3.0.0 + true + + + + + + maven-jar-plugin + + + package + + jar + + + all + + + + + + + + + + + org.codehaus.plexus + plexus-utils + + + + deployed + + diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/note.txt b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/note.txt new file mode 100644 index 000000000..13b46ec93 --- /dev/null +++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/note.txt @@ -0,0 +1,3 @@ +- The artifact is located in the proper location. +- The groupId, artifactId and version of the pom in the file system matches + the groupId, artifactId and version of the pom included in the package. diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.jar b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.jar new file mode 100644 index 000000000..c499d94ff Binary files /dev/null and b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.jar differ diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.pom b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.pom new file mode 100644 index 000000000..44ba7ed4e --- /dev/null +++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.pom @@ -0,0 +1,15 @@ + + + maven + org.apache.maven + 2.1 + + 4.0.0 + org.apache.maven + maven-monitor + Maven Monitor + 2.1 + + deployed + + diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/note.txt b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/note.txt new file mode 100644 index 000000000..796d100b0 --- /dev/null +++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/note.txt @@ -0,0 +1,4 @@ +- The artifact location matches the location specified in the file system, but + does not match the location specified in the pom included in the package. +- The groupId, artifactId and version of the pom in the file system does not match + the groupId, artifactId and version of the pom included in the package. diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.jar b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.jar new file mode 100644 index 000000000..efeb8d456 Binary files /dev/null and b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.jar differ diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.pom b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.pom new file mode 100644 index 000000000..8993ed385 --- /dev/null +++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.pom @@ -0,0 +1,52 @@ + + + maven + org.apache.maven + 2.0 + + 4.0.0 + maven-project + Maven Project Builder + 2.0 + This library is used to not only read Maven project object model files, but to assemble inheritence + and to retrieve remote models as required. + + + org.apache.maven + maven-artifact-test + 2.0 + test + + + org.apache.maven + maven-profile + 2.0 + + + org.apache.maven + maven-model + 2.0 + + + org.apache.maven + maven-artifact-manager + 2.0 + + + org.codehaus.plexus + plexus-utils + + + org.apache.maven + maven-artifact + 2.0 + + + org.codehaus.plexus + plexus-container-default + + + + deployed + + diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/note.txt b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/note.txt new file mode 100644 index 000000000..38aefadac --- /dev/null +++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/note.txt @@ -0,0 +1,4 @@ +- The artifact location does not match both the location specified in the file system pom + and in the pom included in the package. +- The groupId, artifactId and version of the pom in the file system does not match + the groupId, artifactId and version of the pom included in the package. diff --git a/archiva-reports-standard/src/test/resources/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.xml b/archiva-reports-standard/src/test/resources/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.xml new file mode 100644 index 000000000..d8b910c2e --- /dev/null +++ b/archiva-reports-standard/src/test/resources/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.xml @@ -0,0 +1,21 @@ + + + + org.apache.maven.repository.reporting.ArtifactReportProcessor + duplicate + org.apache.maven.repository.reporting.DuplicateArtifactFileReportProcessor + + + org.apache.maven.repository.digest.Digester + md5 + + + org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory + + + + ${basedir}/target/indexDirectory + + + + \ No newline at end of file diff --git a/archiva-utils/pom.xml b/archiva-utils/pom.xml new file mode 100644 index 000000000..baa86124e --- /dev/null +++ b/archiva-utils/pom.xml @@ -0,0 +1,42 @@ + + + + + org.apache.maven.archiva + archiva + 1.0-SNAPSHOT + + 4.0.0 + archiva-utils + Archiva Digester Utilities + + + org.codehaus.plexus + plexus-container-default + test + + + org.codehaus.plexus + plexus-utils + + + org.apache.maven + maven-artifact + + + diff --git a/archiva-utils/src/main/java/org/apache/maven/repository/digest/AbstractDigester.java b/archiva-utils/src/main/java/org/apache/maven/repository/digest/AbstractDigester.java new file mode 100644 index 000000000..c4c8cc7b1 --- /dev/null +++ b/archiva-utils/src/main/java/org/apache/maven/repository/digest/AbstractDigester.java @@ -0,0 +1,88 @@ +package org.apache.maven.repository.digest; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.util.IOUtil; +import org.codehaus.plexus.util.StringUtils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.security.NoSuchAlgorithmException; + +/** + * Create a digest for a file. + * + * @author Brett Porter + */ +public abstract class AbstractDigester + implements Digester +{ + private final StreamingDigester streamingDigester; + + protected AbstractDigester( StreamingDigester streamingDigester ) + throws NoSuchAlgorithmException + { + this.streamingDigester = streamingDigester; + } + + public String getAlgorithm() + { + return streamingDigester.getAlgorithm(); + } + + public String calc( File file ) + throws DigesterException + { + FileInputStream fis = null; + try + { + fis = new FileInputStream( file ); + streamingDigester.reset(); + streamingDigester.update( fis ); + return streamingDigester.calc(); + } + catch ( IOException e ) + { + throw new DigesterException( "Unable to calculate the " + streamingDigester.getAlgorithm() + + " hashcode for " + file.getAbsolutePath() + ": " + e.getMessage(), e ); + } + finally + { + IOUtil.close( fis ); + } + } + + public void verify( File file, String checksum ) + throws DigesterException + { + String trimmedChecksum = + DigestUtils.cleanChecksum( checksum, streamingDigester.getAlgorithm(), file.getName() ); + + //Create checksum for jar file + String sum = calc( file ); + if ( !StringUtils.equalsIgnoreCase( trimmedChecksum, sum ) ) + { + throw new DigesterException( "Checksum failed" ); + } + } + + public String toString() + { + return "[Digester:" + streamingDigester.getAlgorithm() + "]"; + } +} diff --git a/archiva-utils/src/main/java/org/apache/maven/repository/digest/AbstractStreamingDigester.java b/archiva-utils/src/main/java/org/apache/maven/repository/digest/AbstractStreamingDigester.java new file mode 100644 index 000000000..7d148f657 --- /dev/null +++ b/archiva-utils/src/main/java/org/apache/maven/repository/digest/AbstractStreamingDigester.java @@ -0,0 +1,102 @@ +package org.apache.maven.repository.digest; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 java.io.IOException; +import java.io.InputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * Gradually create a digest for a stream. + * + * @author Brett Porter + */ +public abstract class AbstractStreamingDigester + implements StreamingDigester +{ + protected final MessageDigest md; + + private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray(); + + private static final int HI_MASK = 0xF0; + + private static final int LO_MASK = 0x0F; + + private static final int BUFFER_SIZE = 32768; + + protected AbstractStreamingDigester( String algorithm ) + throws NoSuchAlgorithmException + { + md = MessageDigest.getInstance( algorithm ); + } + + public String getAlgorithm() + { + return md.getAlgorithm(); + } + + public String calc() + throws DigesterException + { + return calc( this.md ); + } + + public void reset() + throws DigesterException + { + md.reset(); + } + + public void update( InputStream is ) + throws DigesterException + { + update( is, md ); + } + + protected static String calc( MessageDigest md ) + { + byte[] digest = md.digest(); + + char[] hash = new char[digest.length * 2]; + for ( int i = 0; i < digest.length; i++ ) + { + hash[i * 2] = HEX_CHARS[( digest[i] & HI_MASK ) >> 4]; + hash[i * 2 + 1] = HEX_CHARS[( digest[i] & LO_MASK )]; + } + return new String( hash ); + } + + protected static void update( InputStream is, MessageDigest digest ) + throws DigesterException + { + try + { + byte[] buffer = new byte[BUFFER_SIZE]; + int size = is.read( buffer, 0, BUFFER_SIZE ); + while ( size >= 0 ) + { + digest.update( buffer, 0, size ); + size = is.read( buffer, 0, BUFFER_SIZE ); + } + } + catch ( IOException e ) + { + throw new DigesterException( "Unable to update " + digest.getAlgorithm() + " hash: " + e.getMessage(), e ); + } + } +} diff --git a/archiva-utils/src/main/java/org/apache/maven/repository/digest/DigestUtils.java b/archiva-utils/src/main/java/org/apache/maven/repository/digest/DigestUtils.java new file mode 100644 index 000000000..8bc76b8d2 --- /dev/null +++ b/archiva-utils/src/main/java/org/apache/maven/repository/digest/DigestUtils.java @@ -0,0 +1,67 @@ +package org.apache.maven.repository.digest; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Parse files from checksum file formats. + * + * @author Brett Porter + */ +public class DigestUtils +{ + private DigestUtils() + { + // don't create this class + } + + public static String cleanChecksum( String checksum, String algorithm, String path ) + throws DigesterException + { + String trimmedChecksum = checksum.replace( '\n', ' ' ).trim(); + + // Free-BSD / openssl + String regex = algorithm.replaceAll( "-", "" ) + "\\s*\\((.*?)\\)\\s*=\\s*([a-fA-F0-9]+)"; + Matcher m = Pattern.compile( regex ).matcher( trimmedChecksum ); + if ( m.matches() ) + { + String filename = m.group( 1 ); + if ( !path.endsWith( filename ) ) + { + throw new DigesterException( "Supplied checksum does not match checksum pattern" ); + } + trimmedChecksum = m.group( 2 ); + } + else + { + // GNU tools + m = Pattern.compile( "([a-fA-F0-9]+)\\s\\*?(.+)" ).matcher( trimmedChecksum ); + if ( m.matches() ) + { + String filename = m.group( 2 ); + if ( !path.endsWith( filename ) ) + { + throw new DigesterException( "Supplied checksum does not match checksum pattern" ); + } + trimmedChecksum = m.group( 1 ); + } + } + return trimmedChecksum; + } +} diff --git a/archiva-utils/src/main/java/org/apache/maven/repository/digest/Digester.java b/archiva-utils/src/main/java/org/apache/maven/repository/digest/Digester.java new file mode 100644 index 000000000..70fb8f6ee --- /dev/null +++ b/archiva-utils/src/main/java/org/apache/maven/repository/digest/Digester.java @@ -0,0 +1,57 @@ +package org.apache.maven.repository.digest; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 java.io.File; +import java.io.InputStream; + +/** + * Create a digest for a file. + * + * @author Brett Porter + */ +public interface Digester +{ + String ROLE = Digester.class.getName(); + + /** + * Get the algorithm used for the checksum. + * + * @return the algorithm + */ + String getAlgorithm(); + + /** + * Calculate a checksum for a file. + * + * @param file the file to calculate the checksum for + * @return the current checksum. + * @throws DigesterException if there was a problem computing the hashcode. + */ + String calc( File file ) + throws DigesterException; + + /** + * Verify that a checksum is correct. + * + * @param file the file to compute the checksum for + * @param checksum the checksum to compare to + * @throws DigesterException if there was a problem computing the hashcode. + */ + void verify( File file, String checksum ) + throws DigesterException; +} diff --git a/archiva-utils/src/main/java/org/apache/maven/repository/digest/DigesterException.java b/archiva-utils/src/main/java/org/apache/maven/repository/digest/DigesterException.java new file mode 100644 index 000000000..789957b84 --- /dev/null +++ b/archiva-utils/src/main/java/org/apache/maven/repository/digest/DigesterException.java @@ -0,0 +1,34 @@ +package org.apache.maven.repository.digest; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/** + * @author Edwin Punzalan + */ +public class DigesterException + extends Exception +{ + public DigesterException( String message ) + { + super( message ); + } + + public DigesterException( String message, Throwable cause ) + { + super( message, cause ); + } +} diff --git a/archiva-utils/src/main/java/org/apache/maven/repository/digest/Md5Digester.java b/archiva-utils/src/main/java/org/apache/maven/repository/digest/Md5Digester.java new file mode 100644 index 000000000..3ac6a04b2 --- /dev/null +++ b/archiva-utils/src/main/java/org/apache/maven/repository/digest/Md5Digester.java @@ -0,0 +1,34 @@ +package org.apache.maven.repository.digest; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 java.security.NoSuchAlgorithmException; + +/** + * Digester that does MD5 Message Digesting Only. + * + * @plexus.component role="org.apache.maven.repository.digest.Digester" role-hint="md5" + */ +public class Md5Digester + extends AbstractDigester +{ + public Md5Digester() + throws NoSuchAlgorithmException + { + super( new StreamingMd5Digester() ); + } +} diff --git a/archiva-utils/src/main/java/org/apache/maven/repository/digest/Sha1Digester.java b/archiva-utils/src/main/java/org/apache/maven/repository/digest/Sha1Digester.java new file mode 100644 index 000000000..f0383a0c1 --- /dev/null +++ b/archiva-utils/src/main/java/org/apache/maven/repository/digest/Sha1Digester.java @@ -0,0 +1,34 @@ +package org.apache.maven.repository.digest; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 java.security.NoSuchAlgorithmException; + +/** + * Digester that does SHA1 Message Digesting Only. + * + * @plexus.component role="org.apache.maven.repository.digest.Digester" role-hint="sha1" + */ +public class Sha1Digester + extends AbstractDigester +{ + public Sha1Digester() + throws NoSuchAlgorithmException + { + super( new StreamingSha1Digester() ); + } +} diff --git a/archiva-utils/src/main/java/org/apache/maven/repository/digest/StreamingDigester.java b/archiva-utils/src/main/java/org/apache/maven/repository/digest/StreamingDigester.java new file mode 100644 index 000000000..ec0c5a4b7 --- /dev/null +++ b/archiva-utils/src/main/java/org/apache/maven/repository/digest/StreamingDigester.java @@ -0,0 +1,64 @@ +package org.apache.maven.repository.digest; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 java.io.InputStream; + +/** + * Gradually create a digest for a stream. + * + * @author Brett Porter + */ +public interface StreamingDigester +{ + String ROLE = StreamingDigester.class.getName(); + + /** + * Get the algorithm used for the checksum. + * + * @return the algorithm + */ + String getAlgorithm(); + + /** + * Reset the hashcode calculation algorithm. + * Only useful when performing incremental hashcodes based on repeated use of {@link #update(InputStream)} + * + * @throws DigesterException if there was a problem with the internal message digest + */ + void reset() + throws DigesterException; + + /** + * Calculate the current checksum. + * + * @return the current checksum. + * @throws DigesterException if there was a problem computing the hashcode. + */ + String calc() + throws DigesterException; + + /** + * Update the checksum with the content of the input stream. + * + * @param is the input stream + * @throws DigesterException if there was a problem computing the hashcode. + */ + void update( InputStream is ) + throws DigesterException; + +} diff --git a/archiva-utils/src/main/java/org/apache/maven/repository/digest/StreamingMd5Digester.java b/archiva-utils/src/main/java/org/apache/maven/repository/digest/StreamingMd5Digester.java new file mode 100644 index 000000000..2fc11e45c --- /dev/null +++ b/archiva-utils/src/main/java/org/apache/maven/repository/digest/StreamingMd5Digester.java @@ -0,0 +1,35 @@ +package org.apache.maven.repository.digest; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 java.security.NoSuchAlgorithmException; + +/** + * An MD5 implementation of the streaming digester. + * + * @author Brett Porter + * @plexus.component role="org.apache.maven.repository.digest.StreamingDigester" role-hint="md5" + */ +public class StreamingMd5Digester + extends AbstractStreamingDigester +{ + public StreamingMd5Digester() + throws NoSuchAlgorithmException + { + super( "MD5" ); + } +} diff --git a/archiva-utils/src/main/java/org/apache/maven/repository/digest/StreamingSha1Digester.java b/archiva-utils/src/main/java/org/apache/maven/repository/digest/StreamingSha1Digester.java new file mode 100644 index 000000000..845989eca --- /dev/null +++ b/archiva-utils/src/main/java/org/apache/maven/repository/digest/StreamingSha1Digester.java @@ -0,0 +1,35 @@ +package org.apache.maven.repository.digest; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 java.security.NoSuchAlgorithmException; + +/** + * An SHA-1 implementation of the streaming digester. + * + * @author Brett Porter + * @plexus.component role="org.apache.maven.repository.digest.StreamingDigester" role-hint="sha1" + */ +public class StreamingSha1Digester + extends AbstractStreamingDigester +{ + public StreamingSha1Digester() + throws NoSuchAlgorithmException + { + super( "SHA-1" ); + } +} diff --git a/archiva-utils/src/test/java/org/apache/maven/repository/digest/DigesterTest.java b/archiva-utils/src/test/java/org/apache/maven/repository/digest/DigesterTest.java new file mode 100644 index 000000000..97477d142 --- /dev/null +++ b/archiva-utils/src/test/java/org/apache/maven/repository/digest/DigesterTest.java @@ -0,0 +1,229 @@ +package org.apache.maven.repository.digest; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.PlexusTestCase; + +import java.io.File; +import java.io.IOException; +import java.security.NoSuchAlgorithmException; + +/** + * Test the digester. + * + * @author Brett Porter + */ +public class DigesterTest + extends PlexusTestCase +{ + private static final String MD5 = "adbc688ce77fa2aece4bb72cad9f98ba"; + + private static final String SHA1 = "2a7b459938e12a2dc35d1bf6cff35e9c2b592fa9"; + + private static final String WRONG_SHA1 = "4d8703779816556cdb8be7f6bb5c954f4b5730e2"; + + private Digester sha1Digest; + + private Digester md5Digest; + + protected void setUp() + throws Exception + { + super.setUp(); + + sha1Digest = (Digester) lookup( Digester.ROLE, "sha1" ); + md5Digest = (Digester) lookup( Digester.ROLE, "md5" ); + } + + public void testAlgorithm() + { + assertEquals( "SHA-1", sha1Digest.getAlgorithm() ); + assertEquals( "MD5", md5Digest.getAlgorithm() ); + } + + public void testBareDigestFormat() + throws DigesterException, IOException + { + File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); + + try + { + md5Digest.verify( file, MD5 ); + } + catch ( DigesterException e ) + { + fail( "Bare format MD5 must not throw exception" ); + } + + try + { + sha1Digest.verify( file, SHA1 ); + } + catch ( DigesterException e ) + { + fail( "Bare format SHA1 must not throw exception" ); + } + + try + { + sha1Digest.verify( file, WRONG_SHA1 ); + fail( "wrong checksum must throw an exception" ); + } + catch ( DigesterException e ) + { + //expected + } + } + + public void testOpensslDigestFormat() + throws IOException, DigesterException + { + File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); + + try + { + md5Digest.verify( file, "MD5(test-file.txt)= " + MD5 ); + } + catch ( DigesterException e ) + { + fail( "OpenSSL MD5 format must not cause exception" ); + } + + try + { + md5Digest.verify( file, "MD5 (test-file.txt) = " + MD5 ); + } + catch ( DigesterException e ) + { + fail( "FreeBSD MD5 format must not cause exception" ); + } + + try + { + sha1Digest.verify( file, "SHA1(test-file.txt)= " + SHA1 ); + } + catch ( DigesterException e ) + { + fail( "OpenSSL SHA1 format must not cause exception" ); + } + + try + { + sha1Digest.verify( file, "SHA1 (test-file.txt) = " + SHA1 ); + } + catch ( DigesterException e ) + { + fail( "FreeBSD SHA1 format must not cause exception" ); + } + + try + { + sha1Digest.verify( file, "SHA1 (FOO) = " + SHA1 ); + fail( "Wrong filename should cause an exception" ); + } + catch ( DigesterException e ) + { + //expected + } + + try + { + sha1Digest.verify( file, "SHA1 (test-file.txt) = " + WRONG_SHA1 ); + fail( "Wrong sha1 should cause an exception" ); + } + catch ( DigesterException e ) + { + //expected + } + } + + public void testGnuDigestFormat() + throws NoSuchAlgorithmException, IOException, DigesterException + { + File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); + + try + { + md5Digest.verify( file, MD5 + " *test-file.txt" ); + } + catch ( DigesterException e ) + { + fail( "GNU format MD5 must not cause exception" ); + } + + try + { + md5Digest.verify( file, MD5 + " test-file.txt" ); + } + catch ( DigesterException e ) + { + fail( "GNU text format MD5 must not cause exception" ); + } + + try + { + sha1Digest.verify( file, SHA1 + " *test-file.txt" ); + } + catch ( DigesterException e ) + { + fail( "GNU format SHA1 must not cause exception" ); + } + + try + { + sha1Digest.verify( file, SHA1 + " test-file.txt" ); + } + catch ( DigesterException e ) + { + fail( "GNU text format SHA1 must not cause exception" ); + } + + try + { + sha1Digest.verify( file, SHA1 + " FOO" ); + fail( "Wrong filename cause an exception" ); + } + catch ( DigesterException e ) + { + //expected + } + + try + { + sha1Digest.verify( file, WRONG_SHA1 + " test-file.txt" ); + fail( "Wrong SHA1 cause an exception" ); + } + catch ( DigesterException e ) + { + //expected + } + } + + public void testUntrimmedContent() + throws NoSuchAlgorithmException, IOException + { + File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); + try + { + sha1Digest.verify( file, SHA1 + " *test-file.txt \n" ); + } + catch ( DigesterException e ) + { + fail( "GNU untrimmed SHA1 must not cause exception" ); + } + } +} diff --git a/archiva-utils/src/test/resources/test-file.txt b/archiva-utils/src/test/resources/test-file.txt new file mode 100644 index 000000000..ece41df91 --- /dev/null +++ b/archiva-utils/src/test/resources/test-file.txt @@ -0,0 +1 @@ +the quick brown fox, and all that \ No newline at end of file diff --git a/archiva-webapp/pom.xml b/archiva-webapp/pom.xml new file mode 100644 index 000000000..5a7f9c82b --- /dev/null +++ b/archiva-webapp/pom.xml @@ -0,0 +1,182 @@ + + + + 4.0.0 + + org.apache.maven.archiva + archiva + 1.0-SNAPSHOT + + archiva-webapp + war + Archiva Web Application + + + javax.servlet + servlet-api + 2.4 + provided + + + opensymphony + sitemesh + 2.2.1 + + + taglibs + standard + 1.1.2 + + + jstl + jstl + 1.1.2 + + + org.codehaus.plexus + plexus-xwork-integration + 1.0-alpha-2-SNAPSHOT + + + org.codehaus.plexus + plexus-log4j-logging + 1.1-alpha-2 + + + org.apache.maven.wagon + wagon-http-lightweight + 1.0-beta-1 + runtime + + + org.apache.maven.wagon + wagon-file + 1.0-beta-1 + runtime + + + org.codehaus.plexus + plexus-container-default + 1.0-alpha-10-SNAPSHOT + + + org.apache.maven.archiva + archiva-indexer + + + org.apache.maven.archiva + archiva-discoverer + + + org.apache.maven.archiva + archiva-configuration + + + org.apache.maven.archiva + archiva-proxy + + + org.apache.maven.archiva + archiva-core + + + org.apache.maven.archiva + archiva-applet + + provided + + + org.apache.maven + maven-project + + + + archiva-webapp + + + org.mortbay.jetty + maven-jetty-plugin + + 10 + / + + + 9000 + 60000 + + + + + + org.codehaus.mojo + dependency-maven-plugin + + + copy + process-resources + + copy + + + + + ${project.groupId} + archiva-applet + ${project.version} + src/main/webapp + archiva-applet.jar + + + + + + + + org.codehaus.plexus + plexus-maven-plugin + + + + com.opensymphony.xwork.Action + per-lookup + + + + + + org.codehaus.mojo + cobertura-maven-plugin + + + + + **/** + + + + + + + + + + codehaus.snapshots + http://snapshots.repository.codehaus.org + + + diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java new file mode 100644 index 000000000..ad7e9cbb5 --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java @@ -0,0 +1,353 @@ +package org.apache.maven.repository.manager.web.action; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 com.opensymphony.xwork.ActionSupport; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.BooleanClause; +import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.search.MatchAllDocsQuery; +import org.apache.lucene.search.TermQuery; +import org.apache.maven.repository.configuration.Configuration; +import org.apache.maven.repository.configuration.ConfigurationStore; +import org.apache.maven.repository.configuration.ConfigurationStoreException; +import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; +import org.apache.maven.repository.indexing.RepositoryArtifactIndex; +import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; +import org.apache.maven.repository.indexing.RepositoryIndexException; +import org.apache.maven.repository.indexing.RepositoryIndexSearchException; +import org.apache.maven.repository.indexing.lucene.LuceneQuery; +import org.apache.maven.repository.indexing.record.StandardArtifactIndexRecord; +import org.apache.maven.repository.indexing.record.StandardIndexRecordFields; +import org.codehaus.plexus.util.StringUtils; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.TreeMap; +import java.util.TreeSet; + +/** + * Browse the repository. + * + * @todo the tree part probably belongs in a browsing component, and the indexer could optimize how it retrieves the terms rather than querying everything + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="browseAction" + */ +public class BrowseAction + extends ActionSupport +{ + /** + * @plexus.requirement + */ + private RepositoryArtifactIndexFactory factory; + + /** + * @plexus.requirement + */ + private ConfiguredRepositoryFactory repositoryFactory; + + /** + * @plexus.requirement + */ + private ConfigurationStore configurationStore; + + private List groups; + + private String groupId; + + private static final String GROUP_SEPARATOR = "."; + + private List artifactIds; + + private String artifactId; + + private List versions; + + public String browse() + throws ConfigurationStoreException, RepositoryIndexException, IOException, RepositoryIndexSearchException + { + RepositoryArtifactIndex index = getIndex(); + + if ( !index.exists() ) + { + addActionError( "The repository is not yet indexed. Please wait, and then try again." ); + return ERROR; + } + + GroupTreeNode rootNode = buildGroupTree( index ); + + this.groups = collateGroups( rootNode ); + + return SUCCESS; + } + + public String browseGroup() + throws ConfigurationStoreException, RepositoryIndexException, IOException, RepositoryIndexSearchException + { + RepositoryArtifactIndex index = getIndex(); + + if ( !index.exists() ) + { + addActionError( "The repository is not yet indexed. Please wait, and then try again." ); + return ERROR; + } + + GroupTreeNode rootNode = buildGroupTree( index ); + + if ( StringUtils.isEmpty( groupId ) ) + { + // TODO: i18n + addActionError( "You must specify a group ID to browse" ); + return ERROR; + } + + StringTokenizer tok = new StringTokenizer( groupId, GROUP_SEPARATOR ); + while ( tok.hasMoreTokens() ) + { + String part = tok.nextToken(); + + if ( !rootNode.getChildren().containsKey( part ) ) + { + // TODO: i18n + addActionError( "The group specified was not found" ); + return ERROR; + } + else + { + rootNode = (GroupTreeNode) rootNode.getChildren().get( part ); + } + } + + this.groups = collateGroups( rootNode ); + + List records = index.search( + new LuceneQuery( new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, groupId ) ) ) ); + + Set artifactIds = new HashSet(); + for ( Iterator i = records.iterator(); i.hasNext(); ) + { + StandardArtifactIndexRecord record = (StandardArtifactIndexRecord) i.next(); + artifactIds.add( record.getArtifactId() ); + } + this.artifactIds = new ArrayList( artifactIds ); + Collections.sort( this.artifactIds ); + + return SUCCESS; + } + + public String browseArtifact() + throws ConfigurationStoreException, RepositoryIndexException, IOException, RepositoryIndexSearchException + { + RepositoryArtifactIndex index = getIndex(); + + if ( StringUtils.isEmpty( groupId ) ) + { + // TODO: i18n + addActionError( "You must specify a group ID to browse" ); + return ERROR; + } + + if ( StringUtils.isEmpty( artifactId ) ) + { + // TODO: i18n + addActionError( "You must specify a artifact ID to browse" ); + return ERROR; + } + + BooleanQuery query = new BooleanQuery(); + query.add( new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, groupId ) ), + BooleanClause.Occur.MUST ); + query.add( new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID_EXACT, artifactId ) ), + BooleanClause.Occur.MUST ); + + List records = index.search( new LuceneQuery( query ) ); + + if ( records.isEmpty() ) + { + // TODO: i18n + addActionError( "Could not find any artifacts with the given group and artifact ID" ); + return ERROR; + } + + Set versions = new HashSet(); + for ( Iterator i = records.iterator(); i.hasNext(); ) + { + StandardArtifactIndexRecord record = (StandardArtifactIndexRecord) i.next(); + versions.add( record.getVersion() ); + } + + this.versions = new ArrayList( versions ); + Collections.sort( this.versions ); + + return SUCCESS; + } + + private GroupTreeNode buildGroupTree( RepositoryArtifactIndex index ) + throws IOException, RepositoryIndexSearchException + { + // TODO: give action message if indexing is in progress + + // TODO: this will be inefficient over a very large number of artifacts, should be cached + + List records = index.search( new LuceneQuery( new MatchAllDocsQuery() ) ); + + Set groups = new TreeSet(); + for ( Iterator i = records.iterator(); i.hasNext(); ) + { + StandardArtifactIndexRecord record = (StandardArtifactIndexRecord) i.next(); + groups.add( record.getGroupId() ); + } + + GroupTreeNode rootNode = new GroupTreeNode(); + + // build a tree structure + for ( Iterator i = groups.iterator(); i.hasNext(); ) + { + String groupId = (String) i.next(); + + StringTokenizer tok = new StringTokenizer( groupId, GROUP_SEPARATOR ); + + GroupTreeNode node = rootNode; + + while ( tok.hasMoreTokens() ) + { + String part = tok.nextToken(); + + if ( !node.getChildren().containsKey( part ) ) + { + GroupTreeNode newNode = new GroupTreeNode( part, node ); + node.addChild( newNode ); + node = newNode; + } + else + { + node = (GroupTreeNode) node.getChildren().get( part ); + } + } + } + return rootNode; + } + + private List collateGroups( GroupTreeNode rootNode ) + { + List groups = new ArrayList(); + for ( Iterator i = rootNode.getChildren().values().iterator(); i.hasNext(); ) + { + GroupTreeNode node = (GroupTreeNode) i.next(); + + while ( node.getChildren().size() == 1 ) + { + node = (GroupTreeNode) node.getChildren().values().iterator().next(); + } + + groups.add( node.getFullName() ); + } + return groups; + } + + private RepositoryArtifactIndex getIndex() + throws ConfigurationStoreException, RepositoryIndexException + { + Configuration configuration = configurationStore.getConfigurationFromStore(); + File indexPath = new File( configuration.getIndexPath() ); + + return factory.createStandardIndex( indexPath ); + } + + public List getGroups() + { + return groups; + } + + public List getArtifactIds() + { + return artifactIds; + } + + public String getGroupId() + { + return groupId; + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public List getVersions() + { + return versions; + } + + private static class GroupTreeNode + { + private final String name; + + private final String fullName; + + private final Map children = new TreeMap(); + + GroupTreeNode() + { + name = null; + fullName = null; + } + + GroupTreeNode( String name, GroupTreeNode parent ) + { + this.name = name; + this.fullName = parent.fullName != null ? parent.fullName + GROUP_SEPARATOR + name : name; + } + + public String getName() + { + return name; + } + + public String getFullName() + { + return fullName; + } + + public Map getChildren() + { + return children; + } + + public void addChild( GroupTreeNode newNode ) + { + children.put( newNode.name, newNode ); + } + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ProxyAction.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ProxyAction.java new file mode 100644 index 000000000..246463d5d --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ProxyAction.java @@ -0,0 +1,104 @@ +package org.apache.maven.repository.manager.web.action; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 com.opensymphony.xwork.ActionSupport; +import org.apache.maven.repository.proxy.ProxyException; +import org.apache.maven.repository.proxy.ProxyManager; +import org.apache.maven.wagon.ResourceDoesNotExistException; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; + +/** + * Proxy functionality. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="proxyAction" + */ +public class ProxyAction + extends ActionSupport +{ + /** + * @plexus.requirement + */ + private ProxyManager proxyManager; + + private String path; + + private String filename; + + private String contentType; + + private static final String NOT_FOUND = "notFound"; + + private InputStream artifactStream; + + public String execute() + throws ProxyException + { + try + { + File file = proxyManager.get( path ); + + artifactStream = new FileInputStream( file ); + + // TODO: could be better + contentType = "application/octet-stream"; + + filename = file.getName(); + } + catch ( ResourceDoesNotExistException e ) + { + // TODO: set message? + return NOT_FOUND; + } + catch ( FileNotFoundException e ) + { + // TODO: set message? + return NOT_FOUND; + } + + return SUCCESS; + } + + public String getPath() + { + return path; + } + + public void setPath( String path ) + { + this.path = path; + } + + public String getFilename() + { + return filename; + } + + public String getContentType() + { + return contentType; + } + + public InputStream getArtifactStream() + { + return artifactStream; + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java new file mode 100644 index 000000000..d17b19349 --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java @@ -0,0 +1,181 @@ +package org.apache.maven.repository.manager.web.action; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 com.opensymphony.xwork.ActionSupport; +import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.index.Term; +import org.apache.lucene.queryParser.MultiFieldQueryParser; +import org.apache.lucene.queryParser.ParseException; +import org.apache.lucene.search.TermQuery; +import org.apache.maven.repository.configuration.Configuration; +import org.apache.maven.repository.configuration.ConfigurationStore; +import org.apache.maven.repository.configuration.ConfigurationStoreException; +import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; +import org.apache.maven.repository.indexing.RepositoryArtifactIndex; +import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; +import org.apache.maven.repository.indexing.RepositoryIndexException; +import org.apache.maven.repository.indexing.RepositoryIndexSearchException; +import org.apache.maven.repository.indexing.lucene.LuceneQuery; +import org.apache.maven.repository.indexing.record.StandardIndexRecordFields; + +import java.io.File; +import java.net.MalformedURLException; +import java.util.List; + +/** + * Search all indexed fields by the given criteria. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="searchAction" + */ +public class SearchAction + extends ActionSupport +{ + /** + * Query string. + */ + private String q; + + /** + * The MD5 to search by. + */ + private String md5; + + /** + * Search results. + */ + private List searchResults; + + /** + * @plexus.requirement + */ + private RepositoryArtifactIndexFactory factory; + + /** + * @plexus.requirement + */ + private ConfiguredRepositoryFactory repositoryFactory; + + /** + * @plexus.requirement + */ + private ConfigurationStore configurationStore; + + private static final String NO_RESULTS = "noResults"; + + private static final String RESULTS = "results"; + + private static final String ARTIFACT = "artifact"; + + public String quickSearch() + throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException, + ConfigurationStoreException, ParseException + { + // TODO: give action message if indexing is in progress + + assert q != null && q.length() != 0; + + RepositoryArtifactIndex index = getIndex(); + + if ( !index.exists() ) + { + addActionError( "The repository is not yet indexed. Please wait, and then try again." ); + return ERROR; + } + + // TODO! this is correct, but ugly + MultiFieldQueryParser parser = new MultiFieldQueryParser( new String[]{StandardIndexRecordFields.GROUPID, + StandardIndexRecordFields.ARTIFACTID, StandardIndexRecordFields.BASE_VERSION, + StandardIndexRecordFields.CLASSIFIER, StandardIndexRecordFields.CLASSES, StandardIndexRecordFields.FILES, + StandardIndexRecordFields.TYPE, StandardIndexRecordFields.PROJECT_NAME, + StandardIndexRecordFields.PROJECT_DESCRIPTION}, new StandardAnalyzer() ); + searchResults = index.search( new LuceneQuery( parser.parse( q ) ) ); + + return SUCCESS; + } + + public String findArtifact() + throws Exception + { + // TODO: give action message if indexing is in progress + + assert md5 != null && md5.length() != 0; + + RepositoryArtifactIndex index = getIndex(); + + if ( !index.exists() ) + { + addActionError( "The repository is not yet indexed. Please wait, and then try again." ); + return ERROR; + } + + searchResults = index.search( + new LuceneQuery( new TermQuery( new Term( StandardIndexRecordFields.MD5, md5.toLowerCase() ) ) ) ); + + if ( searchResults.isEmpty() ) + { + return NO_RESULTS; + } + if ( searchResults.size() == 1 ) + { + return ARTIFACT; + } + else + { + return RESULTS; + } + } + + private RepositoryArtifactIndex getIndex() + throws ConfigurationStoreException, RepositoryIndexException + { + Configuration configuration = configurationStore.getConfigurationFromStore(); + File indexPath = new File( configuration.getIndexPath() ); + + return factory.createStandardIndex( indexPath ); + } + + public String doInput() + { + return INPUT; + } + + public String getQ() + { + return q; + } + + public void setQ( String q ) + { + this.q = q; + } + + public String getMd5() + { + return md5; + } + + public void setMd5( String md5 ) + { + this.md5 = md5; + } + + public List getSearchResults() + { + return searchResults; + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ShowArtifactAction.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ShowArtifactAction.java new file mode 100644 index 000000000..b739f6aa9 --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ShowArtifactAction.java @@ -0,0 +1,144 @@ +package org.apache.maven.repository.manager.web.action; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 com.opensymphony.xwork.ActionSupport; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Model; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.repository.configuration.Configuration; +import org.apache.maven.repository.configuration.ConfigurationStore; +import org.apache.maven.repository.configuration.ConfigurationStoreException; +import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.IOException; +import java.util.List; + +/** + * Browse the repository. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="showArtifactAction" + */ +public class ShowArtifactAction + extends ActionSupport +{ + /** + * @plexus.requirement + */ + private ArtifactFactory artifactFactory; + + /** + * @plexus.requirement + */ + private ConfiguredRepositoryFactory repositoryFactory; + + /** + * @plexus.requirement + */ + private MavenProjectBuilder projectBuilder; + + /** + * @plexus.requirement + */ + private ConfigurationStore configurationStore; + + private String groupId; + + private String artifactId; + + private String version; + + private Model model; + + public String execute() + throws ConfigurationStoreException, IOException, XmlPullParserException, ProjectBuildingException + { + if ( StringUtils.isEmpty( groupId ) ) + { + // TODO: i18n + addActionError( "You must specify a group ID to browse" ); + return ERROR; + } + + if ( StringUtils.isEmpty( artifactId ) ) + { + // TODO: i18n + addActionError( "You must specify a artifact ID to browse" ); + return ERROR; + } + + if ( StringUtils.isEmpty( version ) ) + { + // TODO: i18n + addActionError( "You must specify a version to browse" ); + return ERROR; + } + + Configuration configuration = configurationStore.getConfigurationFromStore(); + List repositories = repositoryFactory.createRepositories( configuration ); + + Artifact artifact = artifactFactory.createProjectArtifact( groupId, artifactId, version ); + // TODO: maybe we can decouple the assembly parts of the project builder from the repository handling to get rid of the temp repo + ArtifactRepository localRepository = repositoryFactory.createLocalRepository( configuration ); + MavenProject project = projectBuilder.buildFromRepository( artifact, repositories, localRepository ); + + model = project.getModel(); + + return SUCCESS; + } + + public Model getModel() + { + return model; + } + + public String getGroupId() + { + return groupId; + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public String getVersion() + { + return version; + } + + public void setVersion( String version ) + { + this.version = version; + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/AbstractConfigureRepositoryAction.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/AbstractConfigureRepositoryAction.java new file mode 100644 index 000000000..223136b74 --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/AbstractConfigureRepositoryAction.java @@ -0,0 +1,153 @@ +package org.apache.maven.repository.manager.web.action.admin; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 com.opensymphony.xwork.ActionSupport; +import com.opensymphony.xwork.ModelDriven; +import com.opensymphony.xwork.Preparable; +import org.apache.maven.repository.configuration.AbstractRepositoryConfiguration; +import org.apache.maven.repository.configuration.Configuration; +import org.apache.maven.repository.configuration.ConfigurationChangeException; +import org.apache.maven.repository.configuration.ConfigurationStore; +import org.apache.maven.repository.configuration.ConfigurationStoreException; +import org.apache.maven.repository.configuration.InvalidConfigurationException; + +import java.io.IOException; + +/** + * Base action for repository configuration actions. + * + * @author Brett Porter + */ +public abstract class AbstractConfigureRepositoryAction + extends ActionSupport + implements ModelDriven, Preparable +{ + /** + * @plexus.requirement + */ + private ConfigurationStore configurationStore; + + /** + * The repository. + */ + private AbstractRepositoryConfiguration repository; + + /** + * The repository ID to lookup when editing a repository. + */ + private String repoId; + + /** + * The previously read configuration. + */ + protected Configuration configuration; + + public String add() + throws IOException, ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException + { + // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded + + AbstractRepositoryConfiguration existingRepository = getRepository( repository.getId() ); + if ( existingRepository != null ) + { + addFieldError( "id", "A repository with that id already exists" ); + return INPUT; + } + + return saveConfiguration(); + } + + public String edit() + throws IOException, ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException + { + // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded + + AbstractRepositoryConfiguration existingRepository = getRepository( repository.getId() ); + removeRepository( existingRepository ); + + return saveConfiguration(); + } + + protected abstract void removeRepository( AbstractRepositoryConfiguration existingRepository ); + + protected abstract AbstractRepositoryConfiguration getRepository( String id ); + + private String saveConfiguration() + throws IOException, ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException + { + addRepository(); + + configurationStore.storeConfiguration( configuration ); + + // TODO: do we need to check if indexing is needed? + + addActionMessage( "Successfully saved configuration" ); + + return SUCCESS; + } + + protected abstract void addRepository() + throws IOException; + + public String input() + { + return INPUT; + } + + public Object getModel() + { + return repository; + } + + protected abstract AbstractRepositoryConfiguration createRepository(); + + public void prepare() + throws ConfigurationStoreException + { + configuration = configurationStore.getConfigurationFromStore(); + + if ( repository == null ) + { + repository = getRepository( repoId ); + } + if ( repository == null ) + { + repository = createRepository(); + } + } + + public String getRepoId() + { + return repoId; + } + + public void setRepoId( String repoId ) + { + this.repoId = repoId; + } + + protected AbstractRepositoryConfiguration getRepository() + { + return repository; + } + + public Configuration getConfiguration() + { + return configuration; + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/AbstractDeleteRepositoryAction.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/AbstractDeleteRepositoryAction.java new file mode 100644 index 000000000..31244c227 --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/AbstractDeleteRepositoryAction.java @@ -0,0 +1,116 @@ +package org.apache.maven.repository.manager.web.action.admin; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.repository.configuration.AbstractRepositoryConfiguration; +import org.apache.maven.repository.configuration.Configuration; +import org.apache.maven.repository.configuration.ConfigurationChangeException; +import org.apache.maven.repository.configuration.ConfigurationStore; +import org.apache.maven.repository.configuration.ConfigurationStoreException; +import org.apache.maven.repository.configuration.InvalidConfigurationException; +import org.apache.maven.repository.configuration.RepositoryConfiguration; +import org.codehaus.plexus.xwork.action.PlexusActionSupport; + +import java.io.IOException; + +/** + * Base action for repository removal actions. + * + * @author Brett Porter + */ +public abstract class AbstractDeleteRepositoryAction + extends PlexusActionSupport +{ + /** + * @plexus.requirement + */ + private ConfigurationStore configurationStore; + + /** + * The repository ID to lookup when editing a repository. + */ + protected String repoId; + + /** + * Which operation to select. + */ + private String operation = "unmodified"; + + public String execute() + throws ConfigurationStoreException, IOException, InvalidConfigurationException, ConfigurationChangeException + { + // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded + + if ( "delete-entry".equals( operation ) || "delete-contents".equals( operation ) ) + { + Configuration configuration = configurationStore.getConfigurationFromStore(); + + AbstractRepositoryConfiguration existingRepository = getRepository( configuration ); + if ( existingRepository == null ) + { + addActionError( "A repository with that id does not exist" ); + return ERROR; + } + + // TODO: remove from index too! + + removeRepository( configuration, existingRepository ); + + configurationStore.storeConfiguration( configuration ); + + if ( "delete-contents".equals( operation ) ) + { + removeContents( existingRepository ); + } + } + + return SUCCESS; + } + + protected abstract void removeContents( AbstractRepositoryConfiguration existingRepository ) + throws IOException; + + protected abstract AbstractRepositoryConfiguration getRepository( Configuration configuration ); + + protected abstract void removeRepository( Configuration configuration, + AbstractRepositoryConfiguration existingRepository ); + + public String input() + { + return INPUT; + } + + public String getRepoId() + { + return repoId; + } + + public void setRepoId( String repoId ) + { + this.repoId = repoId; + } + + public String getOperation() + { + return operation; + } + + public void setOperation( String operation ) + { + this.operation = operation; + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureAction.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureAction.java new file mode 100644 index 000000000..5077365bb --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureAction.java @@ -0,0 +1,95 @@ +package org.apache.maven.repository.manager.web.action.admin; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 com.opensymphony.xwork.ActionSupport; +import com.opensymphony.xwork.ModelDriven; +import com.opensymphony.xwork.Preparable; +import org.apache.maven.repository.configuration.Configuration; +import org.apache.maven.repository.configuration.ConfigurationChangeException; +import org.apache.maven.repository.configuration.ConfigurationStore; +import org.apache.maven.repository.configuration.ConfigurationStoreException; +import org.apache.maven.repository.configuration.InvalidConfigurationException; +import org.apache.maven.repository.indexing.RepositoryIndexException; +import org.apache.maven.repository.indexing.RepositoryIndexSearchException; + +import java.io.File; +import java.io.IOException; + +/** + * Configures the application. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureAction" + */ +public class ConfigureAction + extends ActionSupport + implements ModelDriven, Preparable +{ + /** + * @plexus.requirement + */ + private ConfigurationStore configurationStore; + + /** + * The configuration. + */ + private Configuration configuration; + + public String execute() + throws IOException, RepositoryIndexException, RepositoryIndexSearchException, ConfigurationStoreException, + InvalidConfigurationException, ConfigurationChangeException + { + // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded + // TODO: if this is changed, do we move the index or recreate it? + + // Normalize the path + File file = new File( configuration.getIndexPath() ); + configuration.setIndexPath( file.getCanonicalPath() ); + if ( !file.exists() ) + { + file.mkdirs(); + // TODO: error handling when this fails, or is not a directory + } + + // Just double checking that our validation routines line up with what is expected in the configuration + assert configuration.isValid(); + + configurationStore.storeConfiguration( configuration ); + + // TODO: if the repository has changed, we need to check if indexing is needed + + addActionMessage( "Successfully saved configuration" ); + + return SUCCESS; + } + + public String input() + { + return INPUT; + } + + public Object getModel() + { + return configuration; + } + + public void prepare() + throws ConfigurationStoreException + { + configuration = configurationStore.getConfigurationFromStore(); + } +} \ No newline at end of file diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureProxiedRepositoryAction.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureProxiedRepositoryAction.java new file mode 100644 index 000000000..82607f814 --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureProxiedRepositoryAction.java @@ -0,0 +1,54 @@ +package org.apache.maven.repository.manager.web.action.admin; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.repository.configuration.AbstractRepositoryConfiguration; +import org.apache.maven.repository.configuration.ProxiedRepositoryConfiguration; + +import java.io.IOException; + +/** + * Configures the application repositories. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureProxiedRepositoryAction" + */ +public class ConfigureProxiedRepositoryAction + extends AbstractConfigureRepositoryAction +{ + protected void removeRepository( AbstractRepositoryConfiguration existingRepository ) + { + configuration.removeProxiedRepository( (ProxiedRepositoryConfiguration) existingRepository ); + } + + protected AbstractRepositoryConfiguration getRepository( String id ) + { + return configuration.getProxiedRepositoryById( id ); + } + + protected void addRepository() + throws IOException + { + ProxiedRepositoryConfiguration repository = (ProxiedRepositoryConfiguration) getRepository(); + + configuration.addProxiedRepository( repository ); + } + + protected AbstractRepositoryConfiguration createRepository() + { + return new ProxiedRepositoryConfiguration(); + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureRepositoryAction.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureRepositoryAction.java new file mode 100644 index 000000000..9c00b52a0 --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureRepositoryAction.java @@ -0,0 +1,66 @@ +package org.apache.maven.repository.manager.web.action.admin; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.repository.configuration.RepositoryConfiguration; +import org.apache.maven.repository.configuration.AbstractRepositoryConfiguration; + +import java.io.File; +import java.io.IOException; + +/** + * Configures the application repositories. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureRepositoryAction" + */ +public class ConfigureRepositoryAction + extends AbstractConfigureRepositoryAction +{ + protected void removeRepository( AbstractRepositoryConfiguration existingRepository ) + { + configuration.removeRepository( (RepositoryConfiguration) existingRepository ); + } + + protected AbstractRepositoryConfiguration getRepository( String id ) + { + return configuration.getRepositoryById( id ); + } + + protected void addRepository() + throws IOException + { + RepositoryConfiguration repository = (RepositoryConfiguration) getRepository(); + + // Normalize the path + File file = new File( repository.getDirectory() ); + repository.setDirectory( file.getCanonicalPath() ); + if ( !file.exists() ) + { + file.mkdirs(); + // TODO: error handling when this fails, or is not a directory + } + + configuration.addRepository( repository ); + } + + protected AbstractRepositoryConfiguration createRepository() + { + RepositoryConfiguration repository = new RepositoryConfiguration(); + repository.setIndexed( false ); + return repository; + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction.java new file mode 100644 index 000000000..7546238bc --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction.java @@ -0,0 +1,54 @@ +package org.apache.maven.repository.manager.web.action.admin; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.repository.configuration.AbstractRepositoryConfiguration; +import org.apache.maven.repository.configuration.SyncedRepositoryConfiguration; + +import java.io.IOException; + +/** + * Configures the application repositories. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureSyncedRepositoryAction" + */ +public class ConfigureSyncedRepositoryAction + extends AbstractConfigureRepositoryAction +{ + protected void removeRepository( AbstractRepositoryConfiguration existingRepository ) + { + configuration.removeSyncedRepository( (SyncedRepositoryConfiguration) existingRepository ); + } + + protected AbstractRepositoryConfiguration getRepository( String id ) + { + return configuration.getSyncedRepositoryById( id ); + } + + protected void addRepository() + throws IOException + { + SyncedRepositoryConfiguration repository = (SyncedRepositoryConfiguration) getRepository(); + + configuration.addSyncedRepository( repository ); + } + + protected AbstractRepositoryConfiguration createRepository() + { + return new SyncedRepositoryConfiguration(); + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteProxiedRepositoryAction.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteProxiedRepositoryAction.java new file mode 100644 index 000000000..69a7500fe --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteProxiedRepositoryAction.java @@ -0,0 +1,50 @@ +package org.apache.maven.repository.manager.web.action.admin; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.repository.configuration.AbstractRepositoryConfiguration; +import org.apache.maven.repository.configuration.Configuration; +import org.apache.maven.repository.configuration.ProxiedRepositoryConfiguration; +import org.apache.maven.repository.configuration.RepositoryConfiguration; +import org.codehaus.plexus.util.FileUtils; + +import java.io.IOException; + +/** + * Configures the application repositories. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="deleteProxiedRepositoryAction" + */ +public class DeleteProxiedRepositoryAction + extends AbstractDeleteRepositoryAction +{ + protected AbstractRepositoryConfiguration getRepository( Configuration configuration ) + { + return configuration.getProxiedRepositoryById( repoId ); + } + + protected void removeRepository( Configuration configuration, AbstractRepositoryConfiguration existingRepository ) + { + configuration.removeProxiedRepository( (ProxiedRepositoryConfiguration) existingRepository ); + } + + protected void removeContents( AbstractRepositoryConfiguration existingRepository ) + throws IOException + { + // TODO! + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteRepositoryAction.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteRepositoryAction.java new file mode 100644 index 000000000..0823afc61 --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteRepositoryAction.java @@ -0,0 +1,51 @@ +package org.apache.maven.repository.manager.web.action.admin; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.repository.configuration.AbstractRepositoryConfiguration; +import org.apache.maven.repository.configuration.Configuration; +import org.apache.maven.repository.configuration.RepositoryConfiguration; +import org.codehaus.plexus.util.FileUtils; + +import java.io.IOException; + +/** + * Configures the application repositories. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="deleteRepositoryAction" + */ +public class DeleteRepositoryAction + extends AbstractDeleteRepositoryAction +{ + protected AbstractRepositoryConfiguration getRepository( Configuration configuration ) + { + return configuration.getRepositoryById( repoId ); + } + + protected void removeRepository( Configuration configuration, AbstractRepositoryConfiguration existingRepository ) + { + configuration.removeRepository( (RepositoryConfiguration) existingRepository ); + } + + protected void removeContents( AbstractRepositoryConfiguration existingRepository ) + throws IOException + { + RepositoryConfiguration repository = (RepositoryConfiguration) existingRepository; + getLogger().info( "Removing " + repository.getDirectory() ); + FileUtils.deleteDirectory( repository.getDirectory() ); + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteSyncedRepositoryAction.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteSyncedRepositoryAction.java new file mode 100644 index 000000000..f12fe09e3 --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteSyncedRepositoryAction.java @@ -0,0 +1,48 @@ +package org.apache.maven.repository.manager.web.action.admin; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.repository.configuration.AbstractRepositoryConfiguration; +import org.apache.maven.repository.configuration.SyncedRepositoryConfiguration; +import org.apache.maven.repository.configuration.Configuration; + +import java.io.IOException; + +/** + * Configures the application repositories. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="deleteSyncedRepositoryAction" + */ +public class DeleteSyncedRepositoryAction + extends AbstractDeleteRepositoryAction +{ + protected AbstractRepositoryConfiguration getRepository( Configuration configuration ) + { + return configuration.getSyncedRepositoryById( repoId ); + } + + protected void removeRepository( Configuration configuration, AbstractRepositoryConfiguration existingRepository ) + { + configuration.removeSyncedRepository( (SyncedRepositoryConfiguration) existingRepository ); + } + + protected void removeContents( AbstractRepositoryConfiguration existingRepository ) + throws IOException + { + // TODO! + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/RunIndexerAction.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/RunIndexerAction.java new file mode 100644 index 000000000..244346081 --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/RunIndexerAction.java @@ -0,0 +1,43 @@ +package org.apache.maven.repository.manager.web.action.admin; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 com.opensymphony.xwork.ActionSupport; +import org.apache.maven.repository.scheduler.RepositoryTaskScheduler; +import org.apache.maven.repository.scheduler.TaskExecutionException; + +/** + * Configures the application. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="runIndexerAction" + */ +public class RunIndexerAction + extends ActionSupport +{ + /** + * @plexus.requirement + */ + private RepositoryTaskScheduler taskScheduler; + + public String execute() + throws TaskExecutionException + { + taskScheduler.runIndexer(); + + return SUCCESS; + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/interceptor/ConfigurationInterceptor.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/interceptor/ConfigurationInterceptor.java new file mode 100644 index 000000000..388c7222a --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/interceptor/ConfigurationInterceptor.java @@ -0,0 +1,74 @@ +package org.apache.maven.repository.manager.web.interceptor; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 com.opensymphony.xwork.ActionInvocation; +import com.opensymphony.xwork.interceptor.Interceptor; +import org.apache.maven.repository.configuration.Configuration; +import org.apache.maven.repository.configuration.ConfigurationStore; +import org.codehaus.plexus.logging.AbstractLogEnabled; + +/** + * An interceptor that makes the application configuration available + * + * @author Brett Porter + * @todo might be a generally useful thing in plexus-xwork-integration + * @plexus.component role="com.opensymphony.xwork.interceptor.Interceptor" role-hint="configurationInterceptor" + */ +public class ConfigurationInterceptor + extends AbstractLogEnabled + implements Interceptor +{ + /** + * @plexus.requirement + */ + private ConfigurationStore configurationStore; + + public String intercept( ActionInvocation actionInvocation ) + throws Exception + { + Configuration configuration = configurationStore.getConfigurationFromStore(); + + if ( !configuration.isValid() ) + { + if ( configuration.getRepositories().isEmpty() ) + { + getLogger().info( "No repositories were configured - forwarding to repository configuration page" ); + return "config-repository-needed"; + } + else + { + getLogger().info( "Configuration is incomplete - forwarding to configuration page" ); + return "config-needed"; + } + } + else + { + return actionInvocation.invoke(); + } + } + + public void destroy() + { + // This space left intentionally blank + } + + public void init() + { + // This space left intentionally blank + } +} diff --git a/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java new file mode 100644 index 000000000..ae89c3704 --- /dev/null +++ b/archiva-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java @@ -0,0 +1,110 @@ +package org.apache.maven.repository.manager.web.mapper; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 com.opensymphony.webwork.dispatcher.mapper.ActionMapping; +import com.opensymphony.webwork.dispatcher.mapper.DefaultActionMapper; + +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.Map; + +/** + * Map alternate URLs to specific actions. Used for the repository browser and the proxy. + * + * @author Brett Porter + */ +public class RepositoryActionMapper + extends DefaultActionMapper +{ + private static final String BROWSE_PREFIX = "/browse/"; + + private static final String PROXY_PREFIX = "/proxy/"; + + public String getUriFromActionMapping( ActionMapping actionMapping ) + { + Map params = actionMapping.getParams(); + if ( "browseGroup".equals( actionMapping.getName() ) ) + { + return BROWSE_PREFIX + params.remove( "groupId" ); + } + else if ( "browseArtifact".equals( actionMapping.getName() ) ) + { + return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ); + } + else if ( "showArtifact".equals( actionMapping.getName() ) ) + { + return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" + + params.remove( "version" ); + } + else if ( "proxy".equals( actionMapping.getName() ) ) + { + return PROXY_PREFIX + params.remove( "path" ); + } + + return super.getUriFromActionMapping( actionMapping ); + } + + public ActionMapping getMapping( HttpServletRequest httpServletRequest ) + { + String path = httpServletRequest.getServletPath(); + if ( path.startsWith( BROWSE_PREFIX ) ) + { + path = path.substring( BROWSE_PREFIX.length() ); + if ( path.length() == 0 ) + { + return new ActionMapping( "browse", "/", "", null ); + } + else + { + String[] parts = path.split( "/" ); + if ( parts.length == 1 ) + { + Map params = new HashMap(); + params.put( "groupId", parts[0] ); + return new ActionMapping( "browseGroup", "/", "", params ); + } + else if ( parts.length == 2 ) + { + Map params = new HashMap(); + params.put( "groupId", parts[0] ); + params.put( "artifactId", parts[1] ); + return new ActionMapping( "browseArtifact", "/", "", params ); + } + else if ( parts.length == 3 ) + { + Map params = new HashMap(); + params.put( "groupId", parts[0] ); + params.put( "artifactId", parts[1] ); + params.put( "version", parts[2] ); + return new ActionMapping( "showArtifact", "/", "", params ); + } + } + } + else if ( path.startsWith( PROXY_PREFIX ) ) + { + // retain the leading / + path = path.substring( PROXY_PREFIX.length() - 1 ); + + Map params = new HashMap(); + params.put( "path", path ); + return new ActionMapping( "proxy", "/", "", params ); + } + + return super.getMapping( httpServletRequest ); + } +} diff --git a/archiva-webapp/src/main/resources/META-INF/plexus/application.xml b/archiva-webapp/src/main/resources/META-INF/plexus/application.xml new file mode 100644 index 000000000..89bfd4b7e --- /dev/null +++ b/archiva-webapp/src/main/resources/META-INF/plexus/application.xml @@ -0,0 +1,100 @@ + + + + + + + org.codehaus.plexus.logging.LoggerManager + org.codehaus.plexus.logging.log4j.Log4JLoggerManager + basic + + + WARN + console + + + console + DEBUG + org.apache.log4j.ConsoleAppender + %d [%t] %-5p %-30c{1} - %m%n + + + + + org.codehaus.plexus.mailsender.MailSender + INFO + + + org.apache.jasper + INFO + + + com.opensymphony.xwork + INFO + + + com.opensymphony.webwork + INFO + + + org.apache.maven + DEBUG + + + + + + + + + webapp + + + webapp + Web Application Component Lifecycle Handler + + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.repository.scheduler.RepositoryTaskScheduler + + + diff --git a/archiva-webapp/src/main/resources/maven-proxy-complete.conf b/archiva-webapp/src/main/resources/maven-proxy-complete.conf new file mode 100644 index 000000000..cfa847144 --- /dev/null +++ b/archiva-webapp/src/main/resources/maven-proxy-complete.conf @@ -0,0 +1,145 @@ +################ GLOBAL SETTINGS +# This is where maven-proxy stores files it has downloaded +repo.local.store=/tmp/proxy-cache + +#The port to listen on - not used if loaded as a webapp +port=9999 + +#This is the base area that all files are loaded from. While it is possible to leave this blank, this behaviour +#is deprecated and will be disabled in version 2.0. There are too many namespace conflicts caused by not using +#a prefix. +#The repository will be shown at http://localhost:9999/repository/ +#for the .war loaded into a webapp server, the default prefix is "repository" (edit the web.xml to change) +# As maven doesn't like a trailing slash, this address shouldn't have one either. +prefix=repository + +#This is the simple date format used to display the last modified date while browsing the repository. +lastModifiedDateFormat=yyyy/MM/dd HH:mm:ss + +################ SNAPSHOT HANDLING +#If you want the proxy to look for newer snapshots, set to true +snapshot.update=true + +################ M2 METADATA HANDLING +#If you want the proxy to prevent looking for newer metadata, set to false (default is true) +#metadata.update=false + +################ M2 POM HANDLING +#If you want the proxy to look for newer POMs, set to true (default is false) +pom.update=true + +################ PROMOTION HANDLING +# ***** NOT CURRENTLY IMPLEMENTED ***** +#Promotion describes the process by which new artifacts are loaded to global maven-proxy repository. It +# is designed to be used by "higher security installations" that do not want to acquire artifacts from +# remote repositories without approval. +# +#If promotion handling is enabled, then the proxy will not download remote artifacts without permission +# (local repositories with copy=false are considered to be local) +# +#Permission to download is granted via the Promotion menu which will be enabled +# when promotion handling is enabled. +# +#If promotion is false, artifacts are sourced from any repository as per normal. +# +#Promotion and snapshots: If promotion is enabled, snapshots are not downloadable. The concept of using +# a snapshot in a production build (which is primarily what promotion is for) is counterintuitive. +## +promotion=false + +################ WEB INTERFACE +# This defines the absolute URL the server should use to identify itself. +# This can often be determined automatically, but we recommend you specify +# it explicitly to prevent problems during startup. +# The prefix will be added to this for the actual repository +# i.e. proxy available at http://localhost:9999/, repository at http://localhost:9999/repository +serverName=http://localhost:9999 + +#If true, the repository can be browsed +browsable=true + +#If true, the repository can be searched +searchable=true + +#Not currently implemented. Will allow webdav access to the repository at some point. +webdav=true + +#Stylesheet - if configured, will override the default stylesheet shipped with maven-proxy - absolute URLs only +#eg. /maven-proxy/style.css, http://www.example.com/style.css +stylesheet=/maven-proxy/style.css + +#bgColor / bgColorHighlight are replaced in the built in stylesheet to produce a simple color scheme. +#If a stylesheet is set, these are not used. +bgColor=#14B +bgColorHighlight=#94B + +#rowColor / rowColorHighlight are replaced in the built in stylesheet to produce a simple color scheme. +#If a stylesheet is set, these are not used. +rowColor=#CCF +rowColorHighlight=#DDF + + +################ PROXIES +#This is just a hack, it should auto discover them +#proxy.list=one,two,three +proxy.list= + +#Unauthenticated proxy +#proxy.one.host=proxy1.example.com +#proxy.one.port=3128 + +#Authenticated proxy +#proxy.two.host=proxy2.example.org +#proxy.two.port=80 +#proxy.two.username=username2 +#proxy.two.password=password2 + +#Authenticated proxy +#proxy.three.host=proxy3.example.net +#proxy.three.port=3129 +#proxy.three.username=username3 +#proxy.three.password=password3 + + +################# REPOSITORIES +#This is not just a hack, it specifies the order repositories should be checked +#Note that the proxy adds a "/" which is why the urls aren't suffixed with a "/" +repo.list=www-ibiblio-org + +#local-store +# The local store represents a location that local jars you host can be located. +# This could also be achieved by having a local http repository, but this is less cumbersome +repo.local-repo.url=file://target +repo.local-repo.description=Super Secret Custom Repository +#If copy is true, jars are copied from the store to the proxy-repo. Only configurable for file:/// repos +repo.local-repo.copy=false +#If hardfail is true, any unexpected errors from the repository will cause +#the client download to fail (typically with a 500 error) +repo.local-repo.hardfail=true +#Don't cache a file repository +repo.local-repo.cache.period=0 + + +#www.ibiblio.org +repo.www-ibiblio-org.url=http://www.ibiblio.org/maven2 +repo.www-ibiblio-org.description=www.ibiblio.org +repo.www-ibiblio-org.proxy= +repo.www-ibiblio-org.hardfail=true +#Cache this repository for 1 hour +repo.www-ibiblio-org.cache.period=3600 +repo.www-ibiblio-org.cache.failures=true + +#dist.codehaus.org +repo.dist-codehaus-org.url=http://dist.codehaus.org +repo.dist-codehaus-org.proxy=two +repo.dist-codehaus-org.hardfail=false +repo.dist-codehaus-org.cache.period=3600 +repo.dist-codehaus-org.cache.failures=true + +#private.example.com +repo.private-example-com.url=http://private.example.com/internal +repo.private-example-com.description=Commercial In Confidence Repository +repo.private-example-com.username=username1 +repo.private-example-com.password=password1 +repo.private-example-com.proxy=three +repo.private-example-com.cache.period=3600 diff --git a/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/SearchAction-checksumSearch-validation.xml b/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/SearchAction-checksumSearch-validation.xml new file mode 100644 index 000000000..771a8ab6b --- /dev/null +++ b/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/SearchAction-checksumSearch-validation.xml @@ -0,0 +1,29 @@ + + + + + + + + + You must select a file, or enter the checksum. If the file was given and you receive this message, + there may have been an error generating the checksum. + + + + \ No newline at end of file diff --git a/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/SearchAction-quickSearch-validation.xml b/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/SearchAction-quickSearch-validation.xml new file mode 100644 index 000000000..961cb7c8d --- /dev/null +++ b/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/SearchAction-quickSearch-validation.xml @@ -0,0 +1,26 @@ + + + + + + + + You must enter some search terms. + + + \ No newline at end of file diff --git a/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureAction-validation.xml b/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureAction-validation.xml new file mode 100644 index 000000000..60b774bc7 --- /dev/null +++ b/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureAction-validation.xml @@ -0,0 +1,26 @@ + + + + + + + + You must enter the index directory. + + + \ No newline at end of file diff --git a/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureProxiedRepositoryAction-validation.xml b/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureProxiedRepositoryAction-validation.xml new file mode 100644 index 000000000..ee58ed9f9 --- /dev/null +++ b/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureProxiedRepositoryAction-validation.xml @@ -0,0 +1,42 @@ + + + + + + + + + You must enter the repository identifier. + + + + + You must enter the repository name. + + + + + You must enter the repository URL. + + + + + + + + \ No newline at end of file diff --git a/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureRepositoryAction-validation.xml b/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureRepositoryAction-validation.xml new file mode 100644 index 000000000..0a1bb779d --- /dev/null +++ b/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureRepositoryAction-validation.xml @@ -0,0 +1,38 @@ + + + + + + + + + You must enter the repository identifier. + + + + + You must enter the repository name. + + + + + You must enter the repository directory. + + + + \ No newline at end of file diff --git a/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction-addSelectedSyncedRepository-validation.xml b/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction-addSelectedSyncedRepository-validation.xml new file mode 100644 index 000000000..0a9f275f7 --- /dev/null +++ b/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction-addSelectedSyncedRepository-validation.xml @@ -0,0 +1,34 @@ + + + + + + + + You must enter the repository identifier. + + + + + You must enter the repository name. + + + + + + \ No newline at end of file diff --git a/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction-validation.xml b/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction-validation.xml new file mode 100644 index 000000000..154b28fb3 --- /dev/null +++ b/archiva-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction-validation.xml @@ -0,0 +1,27 @@ + + + + + + + + + You must enter the synchronization method. + + + \ No newline at end of file diff --git a/archiva-webapp/src/main/resources/webwork.properties b/archiva-webapp/src/main/resources/webwork.properties new file mode 100644 index 000000000..6837803ce --- /dev/null +++ b/archiva-webapp/src/main/resources/webwork.properties @@ -0,0 +1,5 @@ +# define our own action mapper here +webwork.mapper.class=org.apache.maven.repository.manager.web.mapper.RepositoryActionMapper +webwork.objectFactory = org.codehaus.plexus.xwork.PlexusObjectFactory + +# TODO: package up a theme and share with Continuum. Should contain everything from xhtml, and set templateDir to WEB-INF/themes \ No newline at end of file diff --git a/archiva-webapp/src/main/resources/xwork.xml b/archiva-webapp/src/main/resources/xwork.xml new file mode 100644 index 000000000..db1d796a7 --- /dev/null +++ b/archiva-webapp/src/main/resources/xwork.xml @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /admin + configure + + + /admin + + addRepository!input + + /WEB-INF/jsp/generalError.jsp + + + + + + + + + + + + + + + + + + /WEB-INF/jsp/quickSearch.jsp + + + + /WEB-INF/jsp/quickSearch.jsp + /WEB-INF/jsp/results.jsp + /WEB-INF/jsp/quickSearch.jsp + /WEB-INF/jsp/noResults.jsp + + + + + /WEB-INF/jsp/findArtifact.jsp + + + + /WEB-INF/jsp/findArtifact.jsp + /WEB-INF/jsp/results.jsp + /WEB-INF/jsp/findArtifact.jsp + /WEB-INF/jsp/noResults.jsp + + + /browse/${searchResults[0].groupId}/${searchResults[0].artifactId}/${searchResults[0].version} + + + + + /WEB-INF/jsp/browse.jsp + + + + /WEB-INF/jsp/browseGroup.jsp + + + + /WEB-INF/jsp/browseArtifact.jsp + + + + /WEB-INF/jsp/showArtifact.jsp + + + + + ${contentType} + filename="${filename}" + artifactStream + 1024 + + 404 + + + + + + + /WEB-INF/jsp/admin/index.jsp + + + + /WEB-INF/jsp/admin/addRepository.jsp + index + + + + + /WEB-INF/jsp/admin/editRepository.jsp + index + + + + + /WEB-INF/jsp/admin/deleteRepository.jsp + index + + + + /WEB-INF/jsp/admin/proxiedRepositories.jsp + + + + /WEB-INF/jsp/admin/addProxiedRepository.jsp + proxiedRepositories + + + + /WEB-INF/jsp/admin/editProxiedRepository.jsp + proxiedRepositories + + + + + /WEB-INF/jsp/admin/deleteProxiedRepository.jsp + proxiedRepositories + + + + /WEB-INF/jsp/admin/syncedRepositories.jsp + + + + /WEB-INF/jsp/admin/selectSyncedRepository.jsp + + addSelectedSyncedRepository + input + + + + + /WEB-INF/jsp/admin/addSyncedRepository.jsp + syncedRepositories + + + + /WEB-INF/jsp/admin/editSyncedRepository.jsp + syncedRepositories + + + + + /WEB-INF/jsp/admin/deleteSyncedRepository.jsp + syncedRepositories + + + + /WEB-INF/jsp/admin/configure.jsp + + + + + /WEB-INF/jsp/admin/configure.jsp + /WEB-INF/jsp/admin/index.jsp + + + + + index + + + + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/decorators.xml b/archiva-webapp/src/main/webapp/WEB-INF/decorators.xml new file mode 100644 index 000000000..03131ae9f --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/decorators.xml @@ -0,0 +1,21 @@ + + + + + /* + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addProxiedRepository.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addProxiedRepository.jsp new file mode 100644 index 000000000..6b70fda5b --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addProxiedRepository.jsp @@ -0,0 +1,43 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + + + + Configuration + + + + + +

Configuration

+ +
+ +

Add Proxied Repository

+ + + + + <%@ include file="/WEB-INF/jsp/admin/include/proxiedRepositoryForm.jspf" %> + + + +
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRepository.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRepository.jsp new file mode 100644 index 000000000..82c470120 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRepository.jsp @@ -0,0 +1,43 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + + + + Configuration + + + + + +

Configuration

+ +
+ +

Add Managed Repository

+ + + + + <%@ include file="/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf" %> + + + +
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addSyncedRepository.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addSyncedRepository.jsp new file mode 100644 index 000000000..524164c81 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addSyncedRepository.jsp @@ -0,0 +1,44 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Configuration + + + + + +

Configuration

+ +
+ +

Add Synced Repository

+ + + + + <%@ include file="/WEB-INF/jsp/admin/include/syncedRepositoryForm.jspf" %> + + + +
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp new file mode 100644 index 000000000..725e4be7d --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp @@ -0,0 +1,44 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + + + + Configuration + + + + + +

Configuration

+ +
+ + + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteProxiedRepository.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteProxiedRepository.jsp new file mode 100644 index 000000000..b064b5678 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteProxiedRepository.jsp @@ -0,0 +1,48 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + + + + Configuration + + + + + +

Configuration

+ +
+ +

Delete Proxied Repository

+ +
+ WARNING: This operation can not be undone. +
+ + + + + + +
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRepository.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRepository.jsp new file mode 100644 index 000000000..cb2245256 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRepository.jsp @@ -0,0 +1,47 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + + + + Configuration + + + + + +

Configuration

+ +
+ +

Delete Managed Repository

+ +
+ WARNING: This operation can not be undone. +
+ + + + + + +
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteSyncedRepository.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteSyncedRepository.jsp new file mode 100644 index 000000000..7db55d5c7 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteSyncedRepository.jsp @@ -0,0 +1,48 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + + + + Configuration + + + + + +

Configuration

+ +
+ +

Delete Synced Repository

+ +
+ WARNING: This operation can not be undone. +
+ + + + + + +
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editProxiedRepository.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editProxiedRepository.jsp new file mode 100644 index 000000000..ee60cfe67 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editProxiedRepository.jsp @@ -0,0 +1,42 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + + + + Configuration + + + + + +

Configuration

+ +
+ +

Edit Proxied Repository

+ + + + + <%@ include file="/WEB-INF/jsp/admin/include/proxiedRepositoryForm.jspf" %> + + +
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRepository.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRepository.jsp new file mode 100644 index 000000000..9afd85681 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRepository.jsp @@ -0,0 +1,43 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + + + + Configuration + + + + + +

Configuration

+ +
+ +

Edit Managed Repository

+ + + + + <%@ include file="/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf" %> + + + +
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editSyncedRepository.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editSyncedRepository.jsp new file mode 100644 index 000000000..a39e2ac84 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editSyncedRepository.jsp @@ -0,0 +1,44 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Configuration + + + + + +

Configuration

+ +
+ +

Edit Synced Repository

+ + + + + <%@ include file="/WEB-INF/jsp/admin/include/syncedRepositoryForm.jspf" %> + + + +
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf new file mode 100644 index 000000000..2dcbce3be --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf @@ -0,0 +1,23 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxiedRepositoryForm.jspf b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxiedRepositoryForm.jspf new file mode 100644 index 000000000..4b46713e8 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxiedRepositoryForm.jspf @@ -0,0 +1,39 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + + + + + + + + + + + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/syncedRepositoryForm.jspf b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/syncedRepositoryForm.jspf new file mode 100644 index 000000000..91b2a1047 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/syncedRepositoryForm.jspf @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/index.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/index.jsp new file mode 100644 index 000000000..6f8a66e78 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/index.jsp @@ -0,0 +1,135 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Administration + + + + + +

Administration

+ +
+

Configuration

+ + + + + + + + + + + <%-- TODO: a "run now without timestamp checking" operation should be here too, to pick up any stragglers (in the event of a bug) --%> + <%-- TODO: a "delete index and run now" operation should be here too (really clean, remove deletions that didn't get picked up) --%> + + +
Index Directory + +
Indexing Schedule + + ">Run Now
+ + + +

HTTP Proxy

+ + + + + + + + + + + + + + +
Host${proxy.host}
Port${proxy.port}
Username${proxy.username}
+
+ +

+ ">Edit Configuration +

+ +

Managed Repositories

+ + + + There are no managed repositories configured yet. + + +
+
+ <%-- TODO replace with icons --%> + ">Edit + Repository | ">Delete + Repository +
+

${repository.name}

+ + + + + + + + + + + + + + + + + + + + + + +
Identifier + ${repository.id} +
Directory${repository.directory}
Type + + + Maven 2.x Repository + + + Maven 1.x Repository + + +
Snapshots Included
Indexed
+
+
+ +

+ ">Add Repository +

+
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/proxiedRepositories.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/proxiedRepositories.jsp new file mode 100644 index 000000000..b0670d29c --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/proxiedRepositories.jsp @@ -0,0 +1,148 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Administration + + + + + +

Administration

+ +
+

Proxied Repositories

+ + + + There are no proxied repositories configured yet. + + +
+
+ <%-- TODO replace with icons --%> + ">Edit + Repository | ">Delete + Repository +
+

${repository.name}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Identifier + ${repository.id} +
URL${repository.url}
Type + + + Maven 2.x Repository + + + Maven 1.x Repository + + +
Snapshots + + + + Disabled + + + Updated every request + + + Updated hourly + + + Updated daily + + + Updated every ${repository.snapshotsInterval} minutes + + +
Releases + + + + Disabled + + + Updated every request + + + Updated hourly + + + Updated daily + + + Updated every ${repository.releasesInterval} minutes + + +
Proxied through + + ${repositoriesMap[repository.managedRepository].name} + (${repositoriesMap[repository.managedRepository].id}) +
Use HTTP Proxy
Cache Failures
Fail Whole Group
+
+
+ +

+ ">Add Repository +

+
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/selectSyncedRepository.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/selectSyncedRepository.jsp new file mode 100644 index 000000000..9cd8384d4 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/selectSyncedRepository.jsp @@ -0,0 +1,46 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + + + + Configuration + + + + + +

Configuration

+ +
+ +

Add Synced Repository

+ + + + + + + +
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/syncedRepositories.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/syncedRepositories.jsp new file mode 100644 index 000000000..31ad29e64 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/syncedRepositories.jsp @@ -0,0 +1,145 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Administration + + + + + +

Administration

+ +
+

Synced Repositories

+ + + + There are no synced repositories configured yet. + + +
+
+ <%-- TODO replace with icons --%> + ">Edit + Repository | ">Delete + Repository +
+

${repository.name}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Identifier + ${repository.id} +
Method${repository.method}
CVS Root${repository.properties['cvsRoot']}
Subversion URL${repository.properties['svnUrl']}
Subversion Username${repository.properties['username']}
Rsync Host${repository.properties['rsyncHost']}
Rsync Directory${repository.properties['rsyncDirectory']}
Rsync Method + + + Anonymous + + + SSH + + +
Username${repository.properties['username']}
Directory${repository.properties['directory']}
Type + + + Maven 2.x Repository + + + Maven 1.x Repository + + +
Synced to + + ${repositoriesMap[repository.managedRepository].name} + (${repositoriesMap[repository.managedRepository].id}) +
Schedule${repository.cronExpression}
+
+
+ +

+ ">Add Repository +

+
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp new file mode 100644 index 000000000..da6c69ecc --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp @@ -0,0 +1,74 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Browse Repository + + + + + +

Browse Repository

+ +
+
+

Groups

+ +
+ + <%-- TODO: later, when supported in metadata +
+

Category

+ + + + + + + +
+ Java +
+ Ruby +
+
+ +

Labels

+ +
+

+ jdo + j2ee + maven +

+
+ --%> +
+ + + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/browseArtifact.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/browseArtifact.jsp new file mode 100644 index 000000000..f7ba822ee --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/browseArtifact.jsp @@ -0,0 +1,66 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Browse Repository + + + + + +

Browse Repository

+ +
+
+

+ + + + + + + + + + + + + ${part} / + + ${artifactId} +

+ +

Versions

+ +
+
+ + + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/browseGroup.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/browseGroup.jsp new file mode 100644 index 000000000..fb352b5ad --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/browseGroup.jsp @@ -0,0 +1,86 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Browse Repository + + + + + +

Browse Repository

+ +
+
+

+ + + + + + + + + + + + ${part} + + + + + + ${part} / + + + +

+ + + +

Group / Artifact

+ +
+ + + +

Artifacts

+ +
+
+
+ + + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp new file mode 100644 index 000000000..76f7b3402 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp @@ -0,0 +1,145 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> +<%@ taglib uri="/webwork" prefix="ww" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %> + + + Maven Repository Manager :: + <decorator:title default="Maven Repository Manager" /> + + + + + + + +" class="composite"> + + + + +
+ + +
+ +
+
+ +
+
+ +
+
+
+ + + + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/findArtifact.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/findArtifact.jsp new file mode 100644 index 000000000..bfc1b0959 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/findArtifact.jsp @@ -0,0 +1,86 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + + + + Find Artifact + + + + + +

Find Artifact

+ +
+ +
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/form.jspf b/archiva-webapp/src/main/webapp/WEB-INF/jsp/form.jspf new file mode 100644 index 000000000..6049fe788 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/form.jspf @@ -0,0 +1,53 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + + + +

Search by MD5 (select an artifact):

+ +
+ + + +
+ +

+ + +

+ +

Search:

+ +
+ + +
+ +

Search by Java Package:

+ +
+ + +
+ + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/generalError.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/generalError.jsp new file mode 100644 index 000000000..bef5023c3 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/generalError.jsp @@ -0,0 +1,33 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Error Occurred + + + + + +

Error Occurred

+ + + + + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/quickSearchForm.jspf b/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/quickSearchForm.jspf new file mode 100644 index 000000000..b40dcd7be --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/quickSearchForm.jspf @@ -0,0 +1,28 @@ +<%@ taglib prefix="ww" uri="/webwork" %> +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/quickSearch.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/quickSearch.jsp new file mode 100644 index 000000000..82ed0351c --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/quickSearch.jsp @@ -0,0 +1,33 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + + + Quick Search + + + + + +

Search

+ +
+ <%@ include file="/WEB-INF/jsp/include/quickSearchForm.jspf" %> +
+ + + \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp new file mode 100644 index 000000000..9ef4f69e3 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp @@ -0,0 +1,92 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib uri="/webwork" prefix="ww" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + Search Results + + + + + +

Search Results

+ +
+ +
+ + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp new file mode 100644 index 000000000..ed843a634 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp @@ -0,0 +1,266 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Browse Repository + + + + + +<%-- TODO: image by type +jar +--%> + +<%-- TODO: download link + +--%> + + +

+ + + ${model.artifactId} + + + ${model.name} + + +

+ +
+
+

+ Info + <%-- TODO: perhaps using ajax? + Dependencies + Depended On + Mailing Lists + Developers + POM + --%> +

+
+ +
+

+ + + + + + + + + + + + + ${part} / + + + + + + ${model.artifactId} / + ${model.version} + + +

+ +

${mode.description}

+ + + + + + + + + + + + + + + + + + + <%-- TODO: derivatives + + + + + --%> + + + + + + + <%-- TODO: deployment timestamp + + + + + --%> + +
Group ID${model.groupId}
Artifact ID${model.artifactId}
Version${model.version}
Packaging${model.packaging}
Derivatives + Source + | + Javadoc +
Parent + ${model.parent.groupId} ${model.parent.artifactId} ${model.parent.version} + + + + + + (View) +
Deployment Date + 15 Jan 2006, 20:38:00 +1000 +
+ + + +

Other Details

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
URL + ${model.url} +
Organisation + + + ${model.organization.name} + + + ${model.organization.name} + + +
License + + + ${license.name} + + + ${license.name} + + +
Issue Tracker + + + ${model.issueManagement.system} + + + ${model.issueManagement.system} + + +
Continuous Integration + + + ${model.ciManagement.system} + + + ${model.ciManagement.system} + + +
+
+ + +

SCM

+ + + + + + + + + + + + + + + + + + + +
Connection + ${model.scm.connection} +
Dev. Connection + ${model.scm.developerConnection} +
Viewer + ${model.scm.url} +
+
+ +
+
+ + + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/tags/currentWWUrl.tag b/archiva-webapp/src/main/webapp/WEB-INF/tags/currentWWUrl.tag new file mode 100644 index 000000000..6febd7f06 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/tags/currentWWUrl.tag @@ -0,0 +1,38 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%@ taglib uri="/webwork" prefix="ww" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ attribute name="action" required="true" %> +<%@ attribute name="namespace" required="true" %> + + + + + + + + + + + + + + + + + + diff --git a/archiva-webapp/src/main/webapp/WEB-INF/web.xml b/archiva-webapp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..49da01f29 --- /dev/null +++ b/archiva-webapp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,57 @@ + + + + + Maven Repository Manager + + + webwork-cleanup + com.opensymphony.webwork.dispatcher.ActionContextCleanUp + + + + sitemesh + com.opensymphony.module.sitemesh.filter.PageFilter + + + + webwork + com.opensymphony.webwork.dispatcher.FilterDispatcher + + + + + webwork-cleanup + /* + + + + sitemesh + /* + + + + webwork + /* + + + + org.codehaus.plexus.xwork.PlexusLifecycleListener + + diff --git a/archiva-webapp/src/main/webapp/css/maven-base.css b/archiva-webapp/src/main/webapp/css/maven-base.css new file mode 100644 index 000000000..9dc7da470 --- /dev/null +++ b/archiva-webapp/src/main/webapp/css/maven-base.css @@ -0,0 +1,200 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +body { + margin: 0px; + padding: 0px; +} + +img { + border: none; +} + +table { + padding: 0px; + width: 100%; + margin-left: -2px; + margin-right: -2px; +} + +acronym { + cursor: help; + border-bottom: 1px dotted #feb; +} + +table.bodyTable th, table.bodyTable td { + padding: 2px 4px 2px 4px; + vertical-align: top; +} + +div.clear { + clear: both; + visibility: hidden; +} + +div.clear hr { + display: none; +} + +#bannerLeft, #bannerRight { + font-size: xx-large; + font-weight: bold; +} + +#bannerLeft img, #bannerRight img { + margin: 0px; +} + +.xleft, #bannerLeft img { + float: left; + text-shadow: #7CFC00; +} + +.xright, #bannerRight img { + float: right; + text-shadow: #7CFC00; +} + +#banner { + padding: 0px; +} + +#banner img { + border: none; +} + +#breadcrumbs { + padding: 3px 10px 3px 10px; +} + +#leftColumn { + width: 170px; + float: left; + overflow: auto; +} + +#bodyColumn { + margin-right: 1.5em; + margin-left: 197px; +} + +#legend { + padding: 8px 0 8px 0; +} + +#navcolumn { + padding: 8px 4px 0 8px; +} + +#navcolumn h5 { + margin: 0; + padding: 0; + font-size: small; +} + +#navcolumn ul { + margin: 0; + padding: 0; + font-size: small; +} + +#navcolumn li { + list-style-type: none; + background-image: none; + background-repeat: no-repeat; + background-position: 0 0.4em; + padding-left: 16px; + list-style-position: outside; + line-height: 1.2em; + font-size: smaller; +} + +#navcolumn li.expanded { + background-image: url( ../images/expanded.gif ); +} + +#navcolumn li.collapsed { + background-image: url( ../images/collapsed.gif ); +} + +#poweredBy { + text-align: center; +} + +#navcolumn img { + margin-top: 10px; + margin-bottom: 3px; +} + +#poweredBy img { + display: block; + margin: 20px 0 20px 17px; + border: 1px solid black; + width: 90px; + height: 30px; +} + +#search img { + margin: 0px; + display: block; +} + +#search #q, #search #btnG { + border: 1px solid #999; + margin-bottom: 10px; +} + +#search form { + margin: 0px; +} + +#lastPublished { + font-size: x-small; +} + +.navSection { + margin-bottom: 2px; + padding: 8px; +} + +.navSectionHead { + font-weight: bold; + font-size: x-small; +} + +.section { + padding: 4px; +} + +#footer { + padding: 3px 10px 3px 10px; + font-size: x-small; +} + +#breadcrumbs { + font-size: x-small; + margin: 0pt; +} + +.source { + padding: 12px; + margin: 1em 7px 1em 7px; +} + +.source pre { + margin: 0px; + padding: 0px; +} diff --git a/archiva-webapp/src/main/webapp/css/maven-theme.css b/archiva-webapp/src/main/webapp/css/maven-theme.css new file mode 100644 index 000000000..e035dce77 --- /dev/null +++ b/archiva-webapp/src/main/webapp/css/maven-theme.css @@ -0,0 +1,230 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +body { + padding: 0px 0px 10px 0px; +} + +body, td, select, input, li { + font-family: Verdana, Helvetica, Arial, sans-serif; + font-size: 13px; +} + +select, input { + font-size: x-small; +} + +table { + width: auto; +} + +code { + font-family: Courier, monospace; + font-size: 13px; +} + +a { + text-decoration: none; +} + +#legend li.externalLink { + background: url( ../images/external.png ) left top no-repeat; + padding-left: 18px; +} + +a.externalLink, a.externalLink:link, a.externalLink:visited, a.externalLink:active, a.externalLink:hover { + background: url( ../images/external.png ) right center no-repeat; + padding-right: 18px; +} + +#legend li.newWindow { + background: url( ../images/newwindow.png ) left top no-repeat; + padding-left: 18px; +} + +a.newWindow, a.newWindow:link, a.newWindow:visited, a.newWindow:active, a.newWindow:hover { + background: url( ../images/newwindow.png ) right center no-repeat; + padding-right: 18px; +} + +p { + line-height: 1.3em; + font-size: small; +} + +#breadcrumbs { + border-top: 1px solid #fff; + border-bottom: 1px solid #999; + background-color: #F3B455; + padding: 2px 8px; +} + +#navcolumn h5 { + color: gray; + font-weight: bold; + font-size: 11px; + padding: 10px 0px 1px 19px; +} + +table.bodyTable th { + color: white; + background-color: #bbb; + text-align: left; + font-weight: bold; +} + +table.bodyTable th, table.bodyTable td { + font-size: 1em; +} + +table.bodyTable tr.a { + background-color: #ddd; +} + +table.bodyTable tr.b { + background-color: #eee; +} + +.source { + border: 1px solid #999; +} + +dl { + padding: 4px 4px 4px 6px; + border: 1px solid #aaa; + background-color: #ffc; +} + +dt { + color: #900; +} + +#organizationLogo img, #projectLogo img, #projectLogo span { + margin: 8px; +} + +#banner { + border-bottom: 1px solid #fff; + padding: 8px; +} + +#breadcrumbs a:link { + text-decoration: none; +} + +#breadcrumbs a:visited { + text-decoration: none; + color: #333 +} + +#breadcrumbs a:hover { + text-decoration: none; + color: white +} + +a:link { + color: #333; +} + +.errormark, .warningmark, .donemark, .infomark { + background: url( ../images/icon_error_sml.gif ) no-repeat; +} + +.warningmark { + background-image: url( ../images/icon_warning_sml.gif ); +} + +.donemark { + background-image: url( ../images/icon_success_sml.gif ); +} + +.infomark { + background-image: url( ../images/icon_info_sml.gif ); +} + +#leftColumn { + padding: 4px 4px 4px 4px; + overflow: hidden; +} + +#navcolumn { + padding: 6px 0 0 2px; +} + +#navcolumn li { + font-size: 9px; + text-indent: 19px; + line-height: 24px; + height: 25px; + width: 161px; + background-image: url( ../images/super.gif ); + background-position: 0 0; + background-repeat: no-repeat; + display: block; + padding-left: 0; +} + +#navcolumn li li { + padding-left: 16px; + background: none; + display: block; +} + +#navcolumn li li a:hover { + color: black !important; + background: none; + display: block; +} + +#navcolumn li li a:active { + color: red !important; + background: none; + display: block; +} + +#navcolumn li.expanded { + background-image: url( ../images/super.gif ); + height: inherit; +} + +#navcolumn li a:link { + color: #666; + display: block; +} + +#navcolumn li a:hover { + color: #fff !important; + background: url( ../images/super_hl.gif ) 0 -25px no-repeat; + display: block; +} + +#navcolumn li a:active { + color: #fff !important; + background: url( ../images/super_hl.gif ) 0 -50px no-repeat; + display: block; +} + +#navcolumn li a:visited { + color: #666; + display: block; +} + +#footer { + background: url( ../images/footerborder.gif ) 0 5px repeat-x; + padding: 14px 4px 12px 4px; + margin-top: 2em; +} + diff --git a/archiva-webapp/src/main/webapp/css/print.css b/archiva-webapp/src/main/webapp/css/print.css new file mode 100644 index 000000000..9a6106d2d --- /dev/null +++ b/archiva-webapp/src/main/webapp/css/print.css @@ -0,0 +1,24 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +#banner, #footer, #leftcol, #breadcrumbs, .docs #toc, .docs .courtesylinks, #leftColumn, #navColumn { + display: none !important; +} + +#bodyColumn, body.docs div.docs { + margin: 0 !important; + border: none !important +} diff --git a/archiva-webapp/src/main/webapp/css/site.css b/archiva-webapp/src/main/webapp/css/site.css new file mode 100644 index 000000000..98931b472 --- /dev/null +++ b/archiva-webapp/src/main/webapp/css/site.css @@ -0,0 +1,127 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +#sidebar { + float: right; + font-size: small; + margin: 10px; + padding: 10px; + border: 1px black solid; + width: 10em; +} + +#contentArea { + border: 1px solid black; + margin-right: 15em; + padding: 1em; +} + +#tabs strong { + border: 1px solid black; + padding-left: 1em; + padding-right: 1em; +} + +#tabs a { + border: 1px solid black; + padding-left: 1em; + padding-right: 1em; + text-decoration: none; +} + +#tabArea { + border: 1px solid black; + padding: 1em; +} + +#searchBox p { + font-size: x-small; + text-align: center; + color: gray; +} + +#searchTypes { + text-align: right; + font-size: xx-small; +} + +/* TODO: remove if they aren't used +#feed { + float: right; +} + +.downloadButton { + background-color: green; + border: double white; + float: right; + padding: 5px; +} + +.downloadButton a { + font-size: large; + color: white; + font-weight: bold; + text-decoration: none; +} + +#labels { + background-color: #f2f2f2; + padding: 0.5em 1em 0.5em 1em; +} + +.statusWarn { + color: orange; + font-weight: bold; +} +*/ + +.statusOk { + color: green; + font-weight: bold; +} + +.statusFailed { + color: red; + font-weight: bold; +} + +/* WebWork validation failures */ +.errorMessage { + color: red; + font-weight: bold; +} + +.actionMessage { + font-weight: bold; +} + +sWarn { + color: orange; + font-weight: bold; +} + +/* WebWork validation failures */ +.errorMessage { + color: red; + font-weight: bold; +} + +.actionMessage { + font-weight: bold; +} + + font-weight: bold; +} diff --git a/archiva-webapp/src/main/webapp/images/collapsed.gif b/archiva-webapp/src/main/webapp/images/collapsed.gif new file mode 100644 index 000000000..6e7108406 Binary files /dev/null and b/archiva-webapp/src/main/webapp/images/collapsed.gif differ diff --git a/archiva-webapp/src/main/webapp/images/expanded.gif b/archiva-webapp/src/main/webapp/images/expanded.gif new file mode 100644 index 000000000..0fef3d89e Binary files /dev/null and b/archiva-webapp/src/main/webapp/images/expanded.gif differ diff --git a/archiva-webapp/src/main/webapp/images/external.png b/archiva-webapp/src/main/webapp/images/external.png new file mode 100644 index 000000000..3f999fc88 Binary files /dev/null and b/archiva-webapp/src/main/webapp/images/external.png differ diff --git a/archiva-webapp/src/main/webapp/images/footerborder.gif b/archiva-webapp/src/main/webapp/images/footerborder.gif new file mode 100644 index 000000000..958ce7ae3 Binary files /dev/null and b/archiva-webapp/src/main/webapp/images/footerborder.gif differ diff --git a/archiva-webapp/src/main/webapp/images/icon_error_sml.gif b/archiva-webapp/src/main/webapp/images/icon_error_sml.gif new file mode 100644 index 000000000..61132ef2b Binary files /dev/null and b/archiva-webapp/src/main/webapp/images/icon_error_sml.gif differ diff --git a/archiva-webapp/src/main/webapp/images/icon_info_sml.gif b/archiva-webapp/src/main/webapp/images/icon_info_sml.gif new file mode 100644 index 000000000..c6cb9ad7c Binary files /dev/null and b/archiva-webapp/src/main/webapp/images/icon_info_sml.gif differ diff --git a/archiva-webapp/src/main/webapp/images/icon_success_sml.gif b/archiva-webapp/src/main/webapp/images/icon_success_sml.gif new file mode 100644 index 000000000..52e85a430 Binary files /dev/null and b/archiva-webapp/src/main/webapp/images/icon_success_sml.gif differ diff --git a/archiva-webapp/src/main/webapp/images/icon_warning_sml.gif b/archiva-webapp/src/main/webapp/images/icon_warning_sml.gif new file mode 100644 index 000000000..873bbb52c Binary files /dev/null and b/archiva-webapp/src/main/webapp/images/icon_warning_sml.gif differ diff --git a/archiva-webapp/src/main/webapp/images/newwindow.png b/archiva-webapp/src/main/webapp/images/newwindow.png new file mode 100644 index 000000000..6287f72bd Binary files /dev/null and b/archiva-webapp/src/main/webapp/images/newwindow.png differ diff --git a/archiva-webapp/src/main/webapp/images/super.gif b/archiva-webapp/src/main/webapp/images/super.gif new file mode 100644 index 000000000..c8ee24344 Binary files /dev/null and b/archiva-webapp/src/main/webapp/images/super.gif differ diff --git a/archiva-webapp/src/main/webapp/images/super_hl.gif b/archiva-webapp/src/main/webapp/images/super_hl.gif new file mode 100644 index 000000000..d90b8f0f8 Binary files /dev/null and b/archiva-webapp/src/main/webapp/images/super_hl.gif differ diff --git a/archiva-webapp/src/main/webapp/index.jsp b/archiva-webapp/src/main/webapp/index.jsp new file mode 100644 index 000000000..867a05e78 --- /dev/null +++ b/archiva-webapp/src/main/webapp/index.jsp @@ -0,0 +1,17 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + --%> + +<%response.sendRedirect( request.getContextPath() + "/index.action" );%> \ No newline at end of file diff --git a/archiva-webapp/src/main/webapp/template/repository-manager/radiomap.ftl b/archiva-webapp/src/main/webapp/template/repository-manager/radiomap.ftl new file mode 100644 index 000000000..89ef578d1 --- /dev/null +++ b/archiva-webapp/src/main/webapp/template/repository-manager/radiomap.ftl @@ -0,0 +1,39 @@ +<@ww.iterator value="parameters.list"> + <#if parameters.listKey?exists> + <#assign itemKey = stack.findValue(parameters.listKey)/> + <#else> + <#assign itemKey = stack.findValue('top')/> + + <#if parameters.listValue?exists> + <#assign itemValue = stack.findString(parameters.listValue)/> + <#else> + <#assign itemValue = stack.findString('top')/> + + +<#if tag.contains(parameters.nameValue, itemKey)> + checked="checked"<#rt/> + +<#if itemKey?exists> + value="${itemKey?html}"<#rt/> + +<#if parameters.disabled?default(false)> + disabled="disabled"<#rt/> + +<#if parameters.tabindex?exists> + tabindex="${parameters.tabindex?html}"<#rt/> + +<#if parameters.cssClass?exists> + class="${parameters.cssClass?html}"<#rt/> + +<#if parameters.cssStyle?exists> + style="${parameters.cssStyle?html}"<#rt/> + +<#if parameters.title?exists> + title="${parameters.title?html}"<#rt/> + +<#include "/${parameters.templateDir}/simple/scripting-events.ftl" /> +/><#rt/> +
+ diff --git a/archiva-webapp/src/main/webapp/template/repository-manager/theme.properties b/archiva-webapp/src/main/webapp/template/repository-manager/theme.properties new file mode 100644 index 000000000..b0dfbe775 --- /dev/null +++ b/archiva-webapp/src/main/webapp/template/repository-manager/theme.properties @@ -0,0 +1,17 @@ +# +# Copyright 2005-2006 The Apache Software Foundation. +# +# Licensed 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. +# + +parent = xhtml diff --git a/archiva-webapp/src/test/java/org/apache/maven/repository/proxy/web/action/test/stub/HttpServletRequestStub.java b/archiva-webapp/src/test/java/org/apache/maven/repository/proxy/web/action/test/stub/HttpServletRequestStub.java new file mode 100644 index 000000000..02c8fe5a7 --- /dev/null +++ b/archiva-webapp/src/test/java/org/apache/maven/repository/proxy/web/action/test/stub/HttpServletRequestStub.java @@ -0,0 +1,154 @@ +package org.apache.maven.repository.proxy.web.action.test.stub; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import java.security.Principal; +import java.util.Enumeration; + +public class HttpServletRequestStub + extends ServletRequestStub + implements HttpServletRequest +{ + + public String getAuthType() + { + return null; + } + + public String getContextPath() + { + return "/location1/location2/location3"; + } + + public Cookie[] getCookies() + { + return null; + } + + public long getDateHeader( String name ) + { + return -1; + } + + public String getHeader( String name ) + { + return null; + } + + public Enumeration getHeaderNames() + { + return null; + } + + public Enumeration getHeaders( String name ) + { + return null; + } + + public int getIntHeader( String name ) + { + return -1; + } + + public String getMethod() + { + return null; + } + + public String getPathInfo() + { + return null; + } + + public String getPathTranslated() + { + return null; + } + + public String getQueryString() + { + return null; + } + + public String getRemoteUser() + { + return null; + } + + public String getRequestedSessionId() + { + return null; + } + + public String getRequestURI() + { + return "/projectname/repository/org/sometest/artifact-0.0.jar"; + } + + public StringBuffer getRequestURL() + { + return null; + } + + public String getServletPath() + { + return "/repository/org/sometest/artifact-0.0.jar"; + } + + public HttpSession getSession() + { + return null; + } + + public HttpSession getSession( boolean create ) + { + return null; + } + + public Principal getUserPrincipal() + { + return null; + } + + public boolean isRequestedSessionIdFromCookie() + { + return false; + } + + public boolean isRequestedSessionIdFromUrl() + { + return false; + } + + public boolean isRequestedSessionIdFromURL() + { + return false; + } + + public boolean isRequestedSessionIdValid() + { + return false; + } + + public boolean isUserInRole( String role ) + { + return false; + } +} diff --git a/archiva-webapp/src/test/java/org/apache/maven/repository/proxy/web/action/test/stub/ServletRequestStub.java b/archiva-webapp/src/test/java/org/apache/maven/repository/proxy/web/action/test/stub/ServletRequestStub.java new file mode 100644 index 000000000..e5919d19b --- /dev/null +++ b/archiva-webapp/src/test/java/org/apache/maven/repository/proxy/web/action/test/stub/ServletRequestStub.java @@ -0,0 +1,181 @@ +package org.apache.maven.repository.proxy.web.action.test.stub; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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 javax.servlet.RequestDispatcher; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletRequest; +import java.io.BufferedReader; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +public class ServletRequestStub + implements ServletRequest +{ + + public Object getAttribute( String key ) + { + return null; + } + + public Enumeration getAttributeNames() + { + return null; + } + + public String getCharacterEncoding() + { + return null; + } + + public int getContentLength() + { + return -1; + } + + public int getRemotePort() + { + return -1; + } + + public int getLocalPort() + { + return -1; + } + + public String getLocalAddr() + { + return null; + } + + public String getLocalName() + { + return null; + } + + public String getContentType() + { + return null; + } + + public ServletInputStream getInputStream() + { + return null; + } + + public Locale getLocale() + { + return null; + } + + public Enumeration getLocales() + { + return null; + } + + public String getParameter( String name ) + { + return null; + } + + public Map getParameterMap() + { + HashMap parameterMap = new HashMap(); + + parameterMap.put( "key1", "value1" ); + parameterMap.put( "key2", "value2" ); + + return parameterMap; + } + + public Enumeration getParameterNames() + { + return null; + } + + public String[] getParameterValues( String name ) + { + return null; + } + + public String getProtocol() + { + return null; + } + + public BufferedReader getReader() + { + return null; + } + + public String getRealPath( String path ) + { + return null; + } + + public String getRemoteAddr() + { + return null; + } + + public String getRemoteHost() + { + return null; + } + + public RequestDispatcher getRequestDispatcher( String path ) + { + return null; + } + + public String getScheme() + { + return null; + } + + public String getServerName() + { + return null; + } + + public int getServerPort() + { + return -1; + } + + public boolean isSecure() + { + return false; + } + + public void removeAttribute( String name ) + { + + } + + public void setAttribute( String name, Object value ) + { + + } + + public void setCharacterEncoding( String env ) + { + + } +} diff --git a/archiva-webapp/src/test/resources/unit/proxy-test/maven-proxy-complete.conf b/archiva-webapp/src/test/resources/unit/proxy-test/maven-proxy-complete.conf new file mode 100644 index 000000000..95f01bb30 --- /dev/null +++ b/archiva-webapp/src/test/resources/unit/proxy-test/maven-proxy-complete.conf @@ -0,0 +1,145 @@ +################ GLOBAL SETTINGS +# This is where maven-proxy stores files it has downloaded +#repo.local.store=/tmp/proxy-cache + +#The port to listen on - not used if loaded as a webapp +port=9999 + +#This is the base area that all files are loaded from. While it is possible to leave this blank, this behaviour +#is deprecated and will be disabled in version 2.0. There are too many namespace conflicts caused by not using +#a prefix. +#The repository will be shown at http://localhost:9999/repository/ +#for the .war loaded into a webapp server, the default prefix is "repository" (edit the web.xml to change) +# As maven doesn't like a trailing slash, this address shouldn't have one either. +prefix=repository + +#This is the simple date format used to display the last modified date while browsing the repository. +lastModifiedDateFormat=yyyy/MM/dd HH:mm:ss + +################ SNAPSHOT HANDLING +#If you want the proxy to look for newer snapshots, set to true +snapshot.update=true + +################ M2 METADATA HANDLING +#If you want the proxy to prevent looking for newer metadata, set to false (default is true) +#metadata.update=false + +################ M2 POM HANDLING +#If you want the proxy to look for newer POMs, set to true (default is false) +pom.update=true + +################ PROMOTION HANDLING +# ***** NOT CURRENTLY IMPLEMENTED ***** +#Promotion describes the process by which new artifacts are loaded to global maven-proxy repository. It +# is designed to be used by "higher security installations" that do not want to acquire artifacts from +# remote repositories without approval. +# +#If promotion handling is enabled, then the proxy will not download remote artifacts without permission +# (local repositories with copy=false are considered to be local) +# +#Permission to download is granted via the Promotion menu which will be enabled +# when promotion handling is enabled. +# +#If promotion is false, artifacts are sourced from any repository as per normal. +# +#Promotion and snapshots: If promotion is enabled, snapshots are not downloadable. The concept of using +# a snapshot in a production build (which is primarily what promotion is for) is counterintuitive. +## +promotion=false + +################ WEB INTERFACE +# This defines the absolute URL the server should use to identify itself. +# This can often be determined automatically, but we recommend you specify +# it explicitly to prevent problems during startup. +# The prefix will be added to this for the actual repository +# i.e. proxy available at http://localhost:9999/, repository at http://localhost:9999/repository +serverName=http://localhost:9999 + +#If true, the repository can be browsed +browsable=true + +#If true, the repository can be searched +searchable=true + +#Not currently implemented. Will allow webdav access to the repository at some point. +webdav=true + +#Stylesheet - if configured, will override the default stylesheet shipped with maven-proxy - absolute URLs only +#eg. /maven-proxy/style.css, http://www.example.com/style.css +stylesheet=/maven-proxy/style.css + +#bgColor / bgColorHighlight are replaced in the built in stylesheet to produce a simple color scheme. +#If a stylesheet is set, these are not used. +bgColor=#14B +bgColorHighlight=#94B + +#rowColor / rowColorHighlight are replaced in the built in stylesheet to produce a simple color scheme. +#If a stylesheet is set, these are not used. +rowColor=#CCF +rowColorHighlight=#DDF + + +################ PROXIES +#This is just a hack, it should auto discover them +#proxy.list=one,two,three +proxy.list= + +#Unauthenticated proxy +#proxy.one.host=proxy1.example.com +#proxy.one.port=3128 + +#Authenticated proxy +#proxy.two.host=proxy2.example.org +#proxy.two.port=80 +#proxy.two.username=username2 +#proxy.two.password=password2 + +#Authenticated proxy +#proxy.three.host=proxy3.example.net +#proxy.three.port=3129 +#proxy.three.username=username3 +#proxy.three.password=password3 + + +################# REPOSITORIES +#This is not just a hack, it specifies the order repositories should be checked +#Note that the proxy adds a "/" which is why the urls aren't suffixed with a "/" +repo.list=www-ibiblio-org + +#local-store +# The local store represents a location that local jars you host can be located. +# This could also be achieved by having a local http repository, but this is less cumbersome +repo.local-repo.url=file://target +repo.local-repo.description=Super Secret Custom Repository +#If copy is true, jars are copied from the store to the proxy-repo. Only configurable for file:/// repos +repo.local-repo.copy=false +#If hardfail is true, any unexpected errors from the repository will cause +#the client download to fail (typically with a 500 error) +repo.local-repo.hardfail=true +#Don't cache a file repository +repo.local-repo.cache.period=0 + + +#www.ibiblio.org +repo.www-ibiblio-org.url=http://www.ibiblio.org/maven2 +repo.www-ibiblio-org.description=www.ibiblio.org +repo.www-ibiblio-org.proxy= +repo.www-ibiblio-org.hardfail=true +#Cache this repository for 1 hour +repo.www-ibiblio-org.cache.period=3600 +repo.www-ibiblio-org.cache.failures=true + +#dist.codehaus.org +repo.dist-codehaus-org.url=http://dist.codehaus.org +repo.dist-codehaus-org.proxy=two +repo.dist-codehaus-org.hardfail=false +repo.dist-codehaus-org.cache.period=3600 +repo.dist-codehaus-org.cache.failures=true + +#private.example.com +repo.private-example-com.url=http://private.example.com/internal +repo.private-example-com.description=Commercial In Confidence Repository +repo.private-example-com.username=username1 +repo.private-example-com.password=password1 +repo.private-example-com.proxy=three +repo.private-example-com.cache.period=3600 diff --git a/maven-meeper/pom.xml b/maven-meeper/pom.xml index 81abc0924..158a2c353 100644 --- a/maven-meeper/pom.xml +++ b/maven-meeper/pom.xml @@ -19,14 +19,12 @@ - maven-repository-manager - org.apache.maven.repository - 2.1-SNAPSHOT + archiva + org.apache.maven.archiva + 1.0-SNAPSHOT 4.0.0 maven-meeper - jar + pom Maven Meeper - 1.0-SNAPSHOT - diff --git a/maven-repository-artifact-applet/pom.xml b/maven-repository-artifact-applet/pom.xml deleted file mode 100644 index c18b795a9..000000000 --- a/maven-repository-artifact-applet/pom.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - 4.0.0 - - org.apache.maven.repository - maven-repository-manager - 1.0-SNAPSHOT - - maven-repository-artifact-applet - Maven Repository Manager Artifact Applet - - Applet for performing local operations on files such as creating a checksum of an artifact - before uploading it. - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.1-SNAPSHOT - - src/keystore/keystore - mykey - password - password - - - - - sign - - - - - - org.codehaus.mojo - cobertura-maven-plugin - - - - - **/** - - - - - - - - - apache.snapshots - Apache Snapshot Repository - http://svn.apache.org/maven-snapshot-repository - - true - - - - diff --git a/maven-repository-artifact-applet/src/keystore/keystore b/maven-repository-artifact-applet/src/keystore/keystore deleted file mode 100644 index dda84744a..000000000 Binary files a/maven-repository-artifact-applet/src/keystore/keystore and /dev/null differ diff --git a/maven-repository-artifact-applet/src/main/java/org/apache/maven/repository/applet/ChecksumApplet.java b/maven-repository-artifact-applet/src/main/java/org/apache/maven/repository/applet/ChecksumApplet.java deleted file mode 100644 index 9b8697fd0..000000000 --- a/maven-repository-artifact-applet/src/main/java/org/apache/maven/repository/applet/ChecksumApplet.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.apache.maven.repository.applet; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 javax.swing.*; -import java.applet.Applet; -import java.awt.*; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.security.AccessController; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.PrivilegedAction; - -/** - * Applet that takes a file on the local filesystem and checksums it for sending to the server. - * - * @author Brett Porter - */ -public class ChecksumApplet - extends Applet -{ - private static final int CHECKSUM_BUFFER_SIZE = 8192; - - private static final int BYTE_MASK = 0xFF; - - private JProgressBar progressBar; - - public void init() - { - setLayout( new BorderLayout() ); - progressBar = new JProgressBar(); - progressBar.setStringPainted( true ); - add( progressBar, BorderLayout.CENTER ); - JLabel label = new JLabel( "Checksum progress: " ); - add( label, BorderLayout.WEST ); - } - - public String generateMd5( final String file ) - throws IOException, NoSuchAlgorithmException - { - Object o = AccessController.doPrivileged( new PrivilegedAction() - { - public Object run() - { - try - { - return checksumFile( file ); - } - catch ( NoSuchAlgorithmException e ) - { - return "Error checksumming file: " + e.getMessage(); - } - catch ( FileNotFoundException e ) - { - return "Couldn't find the file. " + e.getMessage(); - } - catch ( IOException e ) - { - return "Error reading file: " + e.getMessage(); - } - } - } ); - return (String) o; - } - - protected String checksumFile( String file ) - throws NoSuchAlgorithmException, IOException - { - MessageDigest digest = MessageDigest.getInstance( "MD5" ); - - long total = new File( file ).length(); - InputStream fis = new FileInputStream( file ); - try - { - long totalRead = 0; - byte[] buffer = new byte[CHECKSUM_BUFFER_SIZE]; - int numRead; - do - { - numRead = fis.read( buffer ); - if ( numRead > 0 ) - { - digest.update( buffer, 0, numRead ); - totalRead += numRead; - progressBar.setValue( (int) ( totalRead * progressBar.getMaximum() / total ) ); - } - } - while ( numRead != -1 ); - } - finally - { - fis.close(); - } - - return byteArrayToHexStr( digest.digest() ); - } - - protected static String byteArrayToHexStr( byte[] data ) - { - String output = ""; - - for ( int cnt = 0; cnt < data.length; cnt++ ) - { - //Deposit a byte into the 8 lsb of an int. - int tempInt = data[cnt] & BYTE_MASK; - - //Get hex representation of the int as a string. - String tempStr = Integer.toHexString( tempInt ); - - //Append a leading 0 if necessary so that each hex string will contain 2 characters. - if ( tempStr.length() == 1 ) - { - tempStr = "0" + tempStr; - } - - //Concatenate the two characters to the output string. - output = output + tempStr; - } - - return output.toUpperCase(); - } -} \ No newline at end of file diff --git a/maven-repository-configuration/pom.xml b/maven-repository-configuration/pom.xml deleted file mode 100644 index 1b3fcbd8a..000000000 --- a/maven-repository-configuration/pom.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - - maven-repository-manager - org.apache.maven.repository - 1.0-SNAPSHOT - - 4.0.0 - maven-repository-configuration - Maven Repository Manager Configuration - - - org.codehaus.plexus - plexus-container-default - - - org.codehaus.plexus - plexus-utils - - - easymock - easymock - 1.2_Java1.3 - test - - - - - - org.codehaus.modello - modello-maven-plugin - 1.0-alpha-10 - - - - xpp3-writer - java - xpp3-reader - - - - - 1.0.0 - src/main/mdo/configuration.mdo - - - - org.codehaus.mojo - cobertura-maven-plugin - - - - - org/apache/maven/repository/configuration/io/** - org/apache/maven/repository/configuration/*RepositoryConfiguration.* - org/apache/maven/repository/configuration/Configuration.* - org/apache/maven/repository/configuration/Proxy.* - - - - - - - diff --git a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeException.java b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeException.java deleted file mode 100644 index 547bff7a4..000000000 --- a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeException.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.apache.maven.repository.configuration; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * An error changing the configuration - * - * @author Brett Porter - */ -public class ConfigurationChangeException - extends Exception -{ - public ConfigurationChangeException( String message, Throwable cause ) - { - super( message, cause ); - } -} diff --git a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java deleted file mode 100644 index ca01a493f..000000000 --- a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apache.maven.repository.configuration; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * Component capable of noticing configuration changes and adjusting accordingly. - * This is not a Plexus role. - * - * @author Brett Porter - */ -public interface ConfigurationChangeListener -{ - /** - * Notify the object that there has been a configuration change. - * - * @param configuration the new configuration - * @throws InvalidConfigurationException if there is a problem with the new configuration - * @throws ConfigurationChangeException if there is a problem changing the configuration, but the configuration is valid - */ - void notifyOfConfigurationChange( Configuration configuration ) - throws InvalidConfigurationException, ConfigurationChangeException; -} diff --git a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java deleted file mode 100644 index 968ce25d6..000000000 --- a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.apache.maven.repository.configuration; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * A component for loading the configuration into the model. - * - * @author Brett Porter - * @todo this is something that could possibly be generalised into Modello. - */ -public interface ConfigurationStore -{ - /** - * The Plexus role for the component. - */ - String ROLE = ConfigurationStore.class.getName(); - - /** - * Get the configuration from the store. A cached version may be used. - * - * @return the configuration - * @throws ConfigurationStoreException if there is a problem loading the configuration - */ - Configuration getConfigurationFromStore() - throws ConfigurationStoreException; - - /** - * Save the configuration to the store. - * - * @param configuration the configuration to store - */ - void storeConfiguration( Configuration configuration ) - throws ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException; - - /** - * Add a configuration change listener. - * - * @param listener the listener - */ - void addChangeListener( ConfigurationChangeListener listener ); -} diff --git a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStoreException.java b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStoreException.java deleted file mode 100644 index 04dd8990b..000000000 --- a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStoreException.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apache.maven.repository.configuration; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * Exception occurring using the configuration store. - * - * @author Brett Porter - */ -public class ConfigurationStoreException - extends Exception -{ - public ConfigurationStoreException( String message ) - { - super( message ); - } - - public ConfigurationStoreException( String message, Throwable e ) - { - super( message, e ); - } -} diff --git a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java deleted file mode 100644 index ad771cba7..000000000 --- a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.apache.maven.repository.configuration; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.repository.configuration.io.xpp3.ConfigurationXpp3Reader; -import org.apache.maven.repository.configuration.io.xpp3.ConfigurationXpp3Writer; -import org.codehaus.plexus.logging.AbstractLogEnabled; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -/** - * Load and store the configuration. No synchronization is used, but it is unnecessary as the old configuration object - * can continue to be used. - * - * @author Brett Porter - * @todo would be great for plexus to do this for us - so the configuration would be a component itself rather than this store - * @todo would be good to monitor the store file for changes - * @todo support other implementations than XML file - * @plexus.component - */ -public class DefaultConfigurationStore - extends AbstractLogEnabled - implements ConfigurationStore -{ - /** - * @plexus.configuration default-value="${configuration.store.file}" - */ - private File file; - - /** - * The cached configuration. - */ - private Configuration configuration; - - /** - * List of listeners to configuration changes. - */ - private List/**/ listeners = new LinkedList(); - - public Configuration getConfigurationFromStore() - throws ConfigurationStoreException - { - if ( configuration == null ) - { - ConfigurationXpp3Reader reader = new ConfigurationXpp3Reader(); - - if ( file == null ) - { - file = new File( System.getProperty( "user.home" ), "/.m2/repository-manager.xml" ); - } - - FileReader fileReader; - try - { - fileReader = new FileReader( file ); - } - catch ( FileNotFoundException e ) - { - getLogger().warn( "Configuration file: " + file + " not found. Using defaults." ); - configuration = new Configuration(); - return configuration; - } - - getLogger().info( "Reading configuration from " + file ); - try - { - configuration = reader.read( fileReader, false ); - } - catch ( IOException e ) - { - throw new ConfigurationStoreException( e.getMessage(), e ); - } - catch ( XmlPullParserException e ) - { - throw new ConfigurationStoreException( e.getMessage(), e ); - } - finally - { - IOUtil.close( fileReader ); - } - } - return configuration; - } - - public void storeConfiguration( Configuration configuration ) - throws ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException - { - for ( Iterator i = listeners.iterator(); i.hasNext(); ) - { - ConfigurationChangeListener listener = (ConfigurationChangeListener) i.next(); - - listener.notifyOfConfigurationChange( configuration ); - } - - ConfigurationXpp3Writer writer = new ConfigurationXpp3Writer(); - - getLogger().info( "Writing configuration to " + file ); - FileWriter fileWriter = null; - try - { - file.getParentFile().mkdirs(); - - fileWriter = new FileWriter( file ); - writer.write( fileWriter, configuration ); - } - catch ( IOException e ) - { - throw new ConfigurationStoreException( e.getMessage(), e ); - } - finally - { - IOUtil.close( fileWriter ); - } - } - - public void addChangeListener( ConfigurationChangeListener listener ) - { - listeners.add( listener ); - } -} diff --git a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/InvalidConfigurationException.java b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/InvalidConfigurationException.java deleted file mode 100644 index 05006df96..000000000 --- a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/InvalidConfigurationException.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.apache.maven.repository.configuration; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * An error in the configuration. - * - * @author Brett Porter - */ -public class InvalidConfigurationException - extends Exception -{ - private final String name; - - public InvalidConfigurationException( String name, String message ) - { - super( message ); - this.name = name; - } - - public InvalidConfigurationException( String name, String message, Throwable cause ) - { - super( message, cause ); - - this.name = name; - } - - public String getName() - { - return name; - } -} diff --git a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoader.java b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoader.java deleted file mode 100644 index 814cec7b1..000000000 --- a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoader.java +++ /dev/null @@ -1,146 +0,0 @@ -package org.apache.maven.repository.configuration; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.util.StringUtils; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Enumeration; -import java.util.Properties; -import java.util.StringTokenizer; - -/** - * @author Ben Walding - * @author Brett Porter - */ -public class MavenProxyPropertyLoader -{ - private static final String REPO_LOCAL_STORE = "repo.local.store"; - - private static final String PROXY_LIST = "proxy.list"; - - private static final String REPO_LIST = "repo.list"; - - public void load( Properties props, Configuration configuration ) - throws InvalidConfigurationException - { - // set up the managed repository - String localCachePath = getMandatoryProperty( props, REPO_LOCAL_STORE ); - - RepositoryConfiguration config = new RepositoryConfiguration(); - config.setDirectory( localCachePath ); - config.setName( "Imported Maven-Proxy Cache" ); - config.setId( "maven-proxy" ); - configuration.addRepository( config ); - - //just get the first HTTP proxy and break - String propertyList = props.getProperty( PROXY_LIST ); - if ( propertyList != null ) - { - StringTokenizer tok = new StringTokenizer( propertyList, "," ); - while ( tok.hasMoreTokens() ) - { - String key = tok.nextToken(); - if ( StringUtils.isNotEmpty( key ) ) - { - Proxy proxy = new Proxy(); - proxy.setHost( getMandatoryProperty( props, "proxy." + key + ".host" ) ); - proxy.setPort( Integer.parseInt( getMandatoryProperty( props, "proxy." + key + ".port" ) ) ); - - // the username and password isn't required - proxy.setUsername( props.getProperty( "proxy." + key + ".username" ) ); - proxy.setPassword( props.getProperty( "proxy." + key + ".password" ) ); - - configuration.setProxy( proxy ); - - //accept only one proxy configuration - break; - } - } - } - - //get the remote repository list - String repoList = getMandatoryProperty( props, REPO_LIST ); - - StringTokenizer tok = new StringTokenizer( repoList, "," ); - while ( tok.hasMoreTokens() ) - { - String key = tok.nextToken(); - - Properties repoProps = getSubset( props, "repo." + key + "." ); - String url = getMandatoryProperty( props, "repo." + key + ".url" ); - String proxyKey = repoProps.getProperty( "proxy" ); - - boolean cacheFailures = - Boolean.valueOf( repoProps.getProperty( "cache.failures", "false" ) ).booleanValue(); - boolean hardFail = Boolean.valueOf( repoProps.getProperty( "hardfail", "true" ) ).booleanValue(); - int cachePeriod = Integer.parseInt( repoProps.getProperty( "cache.period", "60" ) ); - - ProxiedRepositoryConfiguration repository = new ProxiedRepositoryConfiguration(); - repository.setId( key ); - repository.setLayout( "legacy" ); - repository.setManagedRepository( config.getId() ); - repository.setName( "Imported Maven-Proxy Remote Proxy" ); - repository.setSnapshotsInterval( cachePeriod ); - repository.setUrl( url ); - repository.setUseNetworkProxy( StringUtils.isNotEmpty( proxyKey ) ); - repository.setCacheFailures( cacheFailures ); - repository.setHardFail( hardFail ); - - configuration.addProxiedRepository( repository ); - } - } - - private Properties getSubset( Properties props, String prefix ) - { - Enumeration keys = props.keys(); - Properties result = new Properties(); - while ( keys.hasMoreElements() ) - { - String key = (String) keys.nextElement(); - String value = props.getProperty( key ); - if ( key.startsWith( prefix ) ) - { - String newKey = key.substring( prefix.length() ); - result.setProperty( newKey, value ); - } - } - return result; - } - - public void load( InputStream is, Configuration configuration ) - throws IOException, InvalidConfigurationException - { - Properties props = new Properties(); - props.load( is ); - load( props, configuration ); - } - - private String getMandatoryProperty( Properties props, String key ) - throws InvalidConfigurationException - { - String value = props.getProperty( key ); - - if ( value == null ) - { - throw new InvalidConfigurationException( key, "Missing required field: " + key ); - } - - return value; - } -} \ No newline at end of file diff --git a/maven-repository-configuration/src/main/mdo/configuration.mdo b/maven-repository-configuration/src/main/mdo/configuration.mdo deleted file mode 100644 index a2f772800..000000000 --- a/maven-repository-configuration/src/main/mdo/configuration.mdo +++ /dev/null @@ -1,477 +0,0 @@ - - configuration - Configuration - - Configuration for the Maven Repository Manager. - - - - package - org.apache.maven.repository.configuration - - - - - - Configuration - 1.0.0 - - - repositories - 1.0.0 - - RepositoryConfiguration - * - - - - proxiedRepositories - 1.0.0 - - ProxiedRepositoryConfiguration - * - - - - syncedRepositories - 1.0.0 - - SyncedRepositoryConfiguration - * - - - - localRepository - 1.0.0 - String - - The location of the local repository. - - - - indexPath - 1.0.0 - String - - The location of the Lucene index to use for the repository. The default is the .index subdirectory of - the repository. - - - - minimalIndexPath - 1.0.0 - String - - The location of the reduced Lucene index to use for the repository. The default is the .small-index - subdirectory of the repository. - - - - indexerCronExpression - 1.0.0 - String - When to run the indexing mechanism. Default is every hour on the hour. - 0 0 * * * ? - - - converterCronExpression - 1.0.0 - String - When to run the converter mechanism. Default is every 4 hours, on the half hour. - 0 30 0/4 * * ? - - - globalBlackListPatterns - 1.0.0 - String - Blacklisted patterns in the discovery process - - - proxy - 1.0.0 - - Proxy - - The network proxy to use for outgoing requests. - - - - - 1.0.0 - - - - - - AbstractRepositoryConfiguration - true - 1.0.0 - - - id - 1.0.0 - String - true - - The repository identifier. - - - - name - 1.0.0 - String - true - - The descriptive name of the repository. - - - - layout - 1.0.0 - String - true - - The layout of the repository. Valid values are "default" and "legacy". - - - default - - - - - 1.0.0 - - - - - - AbstractRepositoryConfiguration - RepositoryConfiguration - 1.0.0 - - - directory - 1.0.0 - String - true - - The location of the repository to monitor. - - - - includeSnapshots - 1.0.0 - boolean - Whether to include snapshot versions in the discovery process - false - - - indexed - 1.0.0 - boolean - Whether to index the artifacts in this repository. - true - - - blackListPatterns - 1.0.0 - String - Blacklisted patterns in the discovery process - - - - - AbstractRepositoryConfiguration - ProxiedRepositoryConfiguration - 1.0.0 - - - url - 1.0.0 - String - true - - The URL of the remote repository to proxy. - - - - - managedRepository - 1.0.0 - true - String - - The ID of the managed repository to use as the local storage for proxied artifacts. - - - - snapshotsPolicy - 1.0.0 - String - disabled - - The policy for snapshots: one of disabled, daily, hourly, interval, never - (allow snapshots, but never update once retrieved). - - - - snapshotsInterval - 1.0.0 - int - - The interval in minutes before updating snapshots if the policy is set to 'interval'. - - - - releasesPolicy - 1.0.0 - String - daily - - The policy for releases: one of disabled, daily, hourly, interval, never - (allow releases, but never update once retrieved). - - - - releasesInterval - 1.0.0 - int - - The interval in minutes before updating releases if the policy is set to 'interval'. - - - - useNetworkProxy - 1.0.0 - boolean - false - - Whether to use the network proxy, if one is configured for the protocol of this repository. - - - - cacheFailures - 1.0.0 - boolean - false - - Whether to cache failures to avoid re-attempting them over the network. The cache will last for the duration - of the intervals specified above depending on whether it a release or snapshot. - - - - hardFail - 1.0.0 - boolean - false - - Whether to cause the entire request to fail if attempts to retrieve from this proxy fail. - - - - - - AbstractRepositoryConfiguration - SyncedRepositoryConfiguration - true - 1.0.0 - - - - managedRepository - 1.0.0 - true - String - - The ID of the managed repository to use as the local storage for proxied artifacts. - - - - cronExpression - 1.0.0 - String - When to run the sync mechanism. Default is every hour on the hour. - 0 0 * * * ? - - - method - 1.0.0 - String - The type of synchronization to use. - rsync - - - properties - 1.0.0 - Properties - Configuration for the repository synchronization. - - String - * - - - - - - Proxy - 1.0.0 - - - protocol - 1.0.0 - - String - http - - - username - 1.0.0 - - String - - - password - 1.0.0 - - String - - - port - 1.0.0 - - int - 8080 - - - host - 1.0.0 - - String - true - - - nonProxyHosts - 1.0.0 - - String - - - - - - - diff --git a/maven-repository-configuration/src/main/resources/org/apache/maven/repository/configuration/SyncedRepositoryConfiguration-conversion.properties b/maven-repository-configuration/src/main/resources/org/apache/maven/repository/configuration/SyncedRepositoryConfiguration-conversion.properties deleted file mode 100644 index 0bf28d59c..000000000 --- a/maven-repository-configuration/src/main/resources/org/apache/maven/repository/configuration/SyncedRepositoryConfiguration-conversion.properties +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright 2005-2006 The Apache Software Foundation. -# -# Licensed 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. -# - -Key_properties=java.lang.String -Element_properties=java.lang.String diff --git a/maven-repository-configuration/src/test/conf/corrupt.xml b/maven-repository-configuration/src/test/conf/corrupt.xml deleted file mode 100644 index 2476f91ff..000000000 --- a/maven-repository-configuration/src/test/conf/corrupt.xml +++ /dev/null @@ -1,16 +0,0 @@ - - diff --git a/maven-repository-configuration/src/test/conf/maven-proxy-complete.conf b/maven-repository-configuration/src/test/conf/maven-proxy-complete.conf deleted file mode 100644 index 7908a9ad9..000000000 --- a/maven-repository-configuration/src/test/conf/maven-proxy-complete.conf +++ /dev/null @@ -1,144 +0,0 @@ -################ GLOBAL SETTINGS -# This is where maven-proxy stores files it has downloaded -repo.local.store=target - -#The port to listen on - not used if loaded as a webapp -port=9999 - -#This is the base area that all files are loaded from. While it is possible to leave this blank, this behaviour -#is deprecated and will be disabled in version 2.0. There are too many namespace conflicts caused by not using -#a prefix. -#The repository will be shown at http://localhost:9999/repository/ -#for the .war loaded into a webapp server, the default prefix is "repository" (edit the web.xml to change) -# As maven doesn't like a trailing slash, this address shouldn't have one either. -prefix=repository - -#This is the simple date format used to display the last modified date while browsing the repository. -lastModifiedDateFormat=yyyy/MM/dd HH:mm:ss - -################ SNAPSHOT HANDLING -#If you want the proxy to look for newer snapshots, set to true -snapshot.update=true - -################ M2 METADATA HANDLING -#If you want the proxy to prevent looking for newer metadata, set to false (default is true) -#metadata.update=false - -################ M2 POM HANDLING -#If you want the proxy to look for newer POMs, set to true (default is false) -pom.update=true - -################ PROMOTION HANDLING -# ***** NOT CURRENTLY IMPLEMENTED ***** -#Promotion describes the process by which new artifacts are loaded to global maven-proxy repository. It -# is designed to be used by "higher security installations" that do not want to acquire artifacts from -# remote repositories without approval. -# -#If promotion handling is enabled, then the proxy will not download remote artifacts without permission -# (local repositories with copy=false are considered to be local) -# -#Permission to download is granted via the Promotion menu which will be enabled -# when promotion handling is enabled. -# -#If promotion is false, artifacts are sourced from any repository as per normal. -# -#Promotion and snapshots: If promotion is enabled, snapshots are not downloadable. The concept of using -# a snapshot in a production build (which is primarily what promotion is for) is counterintuitive. -## -promotion=false - -################ WEB INTERFACE -# This defines the absolute URL the server should use to identify itself. -# This can often be determined automatically, but we recommend you specify -# it explicitly to prevent problems during startup. -# The prefix will be added to this for the actual repository -# i.e. proxy available at http://localhost:9999/, repository at http://localhost:9999/repository -serverName=http://localhost:9999 - -#If true, the repository can be browsed -browsable=true - -#If true, the repository can be searched -searchable=true - -#Not currently implemented. Will allow webdav access to the repository at some point. -webdav=true - -#Stylesheet - if configured, will override the default stylesheet shipped with maven-proxy - absolute URLs only -#eg. /maven-proxy/style.css, http://www.example.com/style.css -stylesheet=/maven-proxy/style.css - -#bgColor / bgColorHighlight are replaced in the built in stylesheet to produce a simple color scheme. -#If a stylesheet is set, these are not used. -bgColor=#14B -bgColorHighlight=#94B - -#rowColor / rowColorHighlight are replaced in the built in stylesheet to produce a simple color scheme. -#If a stylesheet is set, these are not used. -rowColor=#CCF -rowColorHighlight=#DDF - - -################ PROXIES -#This is just a hack, it should auto discover them -proxy.list=one,two,three - -#Unauthenticated proxy -proxy.one.host=proxy1.example.com -proxy.one.port=3128 - -#Authenticated proxy -proxy.two.host=proxy2.example.org -proxy.two.port=80 -proxy.two.username=username2 -proxy.two.password=password2 - -#Authenticated proxy -proxy.three.host=proxy3.example.net -proxy.three.port=3129 -proxy.three.username=username3 -proxy.three.password=password3 - - -################# REPOSITORIES -#This is not just a hack, it specifies the order repositories should be checked -#Note that the proxy adds a "/" which is why the urls aren't suffixed with a "/" -repo.list=local-repo,www-ibiblio-org,dist-codehaus-org,private-example-com - -#local-store -# The local store represents a location that local jars you host can be located. -# This could also be achieved by having a local http repository, but this is less cumbersome -repo.local-repo.url=file://target -repo.local-repo.description=Super Secret Custom Repository -#If copy is true, jars are copied from the store to the proxy-repo. Only configurable for file:/// repos -repo.local-repo.copy=false -#If hardfail is true, any unexpected errors from the repository will cause -#the client download to fail (typically with a 500 error) -repo.local-repo.hardfail=true -#Don't cache a file repository -repo.local-repo.cache.period=0 - - -#www.ibiblio.org -repo.www-ibiblio-org.url=http://www.ibiblio.org/maven2 -repo.www-ibiblio-org.description=www.ibiblio.org -repo.www-ibiblio-org.proxy=one -repo.www-ibiblio-org.hardfail=true -#Cache this repository for 1 hour -repo.www-ibiblio-org.cache.period=3600 -repo.www-ibiblio-org.cache.failures=true - -#dist.codehaus.org -repo.dist-codehaus-org.url=http://dist.codehaus.org -repo.dist-codehaus-org.proxy=two -repo.dist-codehaus-org.hardfail=false -repo.dist-codehaus-org.cache.period=3600 -repo.dist-codehaus-org.cache.failures=true - -#private.example.com -repo.private-example-com.url=http://private.example.com/internal -repo.private-example-com.description=Commercial In Confidence Repository -repo.private-example-com.username=username1 -repo.private-example-com.password=password1 -repo.private-example-com.proxy=three -repo.private-example-com.cache.period=3600 diff --git a/maven-repository-configuration/src/test/conf/repository-manager.xml b/maven-repository-configuration/src/test/conf/repository-manager.xml deleted file mode 100644 index a3f1f2745..000000000 --- a/maven-repository-configuration/src/test/conf/repository-manager.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - managed-repository - local - local - - - - - http://www.ibiblio.org/maven2/ - local - - - true - ibiblio - Ibiblio - - - - - apache - ASF - 0 0 * * * ? - local - rsync - - host - ssh - - - - local-repository - .index - diff --git a/maven-repository-configuration/src/test/java/org/apache/maven/repository/configuration/ConfigurationStoreTest.java b/maven-repository-configuration/src/test/java/org/apache/maven/repository/configuration/ConfigurationStoreTest.java deleted file mode 100644 index 34d350a68..000000000 --- a/maven-repository-configuration/src/test/java/org/apache/maven/repository/configuration/ConfigurationStoreTest.java +++ /dev/null @@ -1,154 +0,0 @@ -package org.apache.maven.repository.configuration; - -import org.codehaus.plexus.PlexusTestCase; -import org.easymock.MockControl; - -import java.io.File; -import java.util.Properties; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * Test the configuration store. - * - * @author Brett Porter - * @noinspection JavaDoc - */ -public class ConfigurationStoreTest - extends PlexusTestCase -{ - public void testInvalidFile() - throws Exception - { - ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "invalid-file" ); - - Configuration configuration = configurationStore.getConfigurationFromStore(); - - // check default configuration - assertNotNull( "check configuration returned", configuration ); - assertEquals( "check configuration has default elements", "0 0 * * * ?", - configuration.getIndexerCronExpression() ); - assertNull( "check configuration has default elements", configuration.getIndexPath() ); - assertTrue( "check configuration has default elements", configuration.getRepositories().isEmpty() ); - } - - public void testCorruptFile() - throws Exception - { - ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "corrupt-file" ); - - try - { - configurationStore.getConfigurationFromStore(); - fail( "Configuration should not have succeeded" ); - } - catch ( ConfigurationStoreException e ) - { - // expected - assertTrue( true ); - } - } - - public void testGetConfiguration() - throws Exception - { - ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "default" ); - - Configuration configuration = configurationStore.getConfigurationFromStore(); - - assertEquals( "check indexPath", ".index", configuration.getIndexPath() ); - assertEquals( "check localRepository", "local-repository", configuration.getLocalRepository() ); - - assertEquals( "check managed repositories", 1, configuration.getRepositories().size() ); - RepositoryConfiguration repository = - (RepositoryConfiguration) configuration.getRepositories().iterator().next(); - - assertEquals( "check managed repositories", "managed-repository", repository.getDirectory() ); - assertEquals( "check managed repositories", "local", repository.getName() ); - assertEquals( "check managed repositories", "local", repository.getId() ); - assertEquals( "check managed repositories", "default", repository.getLayout() ); - assertTrue( "check managed repositories", repository.isIndexed() ); - - assertEquals( "check proxied repositories", 1, configuration.getProxiedRepositories().size() ); - ProxiedRepositoryConfiguration proxiedRepository = - (ProxiedRepositoryConfiguration) configuration.getProxiedRepositories().iterator().next(); - - assertEquals( "check proxied repositories", "local", proxiedRepository.getManagedRepository() ); - assertEquals( "check proxied repositories", "http://www.ibiblio.org/maven2/", proxiedRepository.getUrl() ); - assertEquals( "check proxied repositories", "ibiblio", proxiedRepository.getId() ); - assertEquals( "check proxied repositories", "Ibiblio", proxiedRepository.getName() ); - assertEquals( "check proxied repositories", 0, proxiedRepository.getSnapshotsInterval() ); - assertEquals( "check proxied repositories", 0, proxiedRepository.getReleasesInterval() ); - assertTrue( "check proxied repositories", proxiedRepository.isUseNetworkProxy() ); - - assertEquals( "check synced repositories", 1, configuration.getSyncedRepositories().size() ); - SyncedRepositoryConfiguration syncedRepository = - (SyncedRepositoryConfiguration) configuration.getSyncedRepositories().iterator().next(); - - assertEquals( "check synced repositories", "local", syncedRepository.getManagedRepository() ); - assertEquals( "check synced repositories", "apache", syncedRepository.getId() ); - assertEquals( "check synced repositories", "ASF", syncedRepository.getName() ); - assertEquals( "check synced repositories", "0 0 * * * ?", syncedRepository.getCronExpression() ); - assertEquals( "check synced repositories", "rsync", syncedRepository.getMethod() ); - Properties properties = new Properties(); - properties.setProperty( "rsyncHost", "host" ); - properties.setProperty( "rsyncMethod", "ssh" ); - assertEquals( "check synced repositories", properties, syncedRepository.getProperties() ); - } - - public void testStoreConfiguration() - throws Exception - { - ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "save-file" ); - - Configuration configuration = new Configuration(); - configuration.setIndexPath( "index-path" ); - - File file = getTestFile( "target/test/test-file.xml" ); - file.delete(); - assertFalse( file.exists() ); - - configurationStore.storeConfiguration( configuration ); - - assertTrue( "Check file exists", file.exists() ); - - // read it back - configuration = configurationStore.getConfigurationFromStore(); - assertEquals( "check value", "index-path", configuration.getIndexPath() ); - } - - /** - * @noinspection JUnitTestMethodWithNoAssertions - */ - public void testChangeListeners() - throws Exception - { - ConfigurationStore configurationStore = (ConfigurationStore) lookup( ConfigurationStore.ROLE, "save-file" ); - - MockControl control = MockControl.createControl( ConfigurationChangeListener.class ); - ConfigurationChangeListener mock = (ConfigurationChangeListener) control.getMock(); - configurationStore.addChangeListener( mock ); - - Configuration configuration = new Configuration(); - mock.notifyOfConfigurationChange( configuration ); - control.replay(); - - configurationStore.storeConfiguration( configuration ); - - control.verify(); - } -} diff --git a/maven-repository-configuration/src/test/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoaderTest.java b/maven-repository-configuration/src/test/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoaderTest.java deleted file mode 100644 index de8fb8d01..000000000 --- a/maven-repository-configuration/src/test/java/org/apache/maven/repository/configuration/MavenProxyPropertyLoaderTest.java +++ /dev/null @@ -1,103 +0,0 @@ -package org.apache.maven.repository.configuration; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.PlexusTestCase; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.List; -import java.util.Properties; - -/** - * @author Edwin Punzalan - */ -public class MavenProxyPropertyLoaderTest - extends PlexusTestCase -{ - private static final int DEFAULT_CACHE_PERIOD = 3600; - - private MavenProxyPropertyLoader loader; - - public void testLoadValidMavenProxyConfiguration() - throws IOException, InvalidConfigurationException - { - File confFile = getTestFile( "src/test/conf/maven-proxy-complete.conf" ); - - Configuration configuration = new Configuration(); - Proxy proxy = new Proxy(); - proxy.setHost( "original-host" ); - configuration.setProxy( proxy ); // overwritten - configuration.setIndexPath( "index-path" ); // existing value - - loader.load( new FileInputStream( confFile ), configuration ); - - List list = configuration.getRepositories(); - assertEquals( "check single managed repository", 1, list.size() ); - RepositoryConfiguration managedRepository = (RepositoryConfiguration) list.iterator().next(); - assertEquals( "cache path changed", "target", managedRepository.getDirectory() ); - - assertEquals( "Count repositories", 4, configuration.getProxiedRepositories().size() ); - - list = configuration.getProxiedRepositories(); - ProxiedRepositoryConfiguration repo = (ProxiedRepositoryConfiguration) list.get( 0 ); - assertEquals( "Repository name not as expected", "local-repo", repo.getId() ); - assertEquals( "Repository url does not match its name", "file://target", repo.getUrl() ); - assertEquals( "Repository cache period check failed", 0, repo.getSnapshotsInterval() ); - assertFalse( "Repository failure caching check failed", repo.isCacheFailures() ); - - repo = (ProxiedRepositoryConfiguration) list.get( 1 ); - assertEquals( "Repository name not as expected", "www-ibiblio-org", repo.getId() ); - assertEquals( "Repository url does not match its name", "http://www.ibiblio.org/maven2", repo.getUrl() ); - assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() ); - assertTrue( "Repository failure caching check failed", repo.isCacheFailures() ); - - repo = (ProxiedRepositoryConfiguration) list.get( 2 ); - assertEquals( "Repository name not as expected", "dist-codehaus-org", repo.getId() ); - assertEquals( "Repository url does not match its name", "http://dist.codehaus.org", repo.getUrl() ); - assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() ); - assertTrue( "Repository failure caching check failed", repo.isCacheFailures() ); - - repo = (ProxiedRepositoryConfiguration) list.get( 3 ); - assertEquals( "Repository name not as expected", "private-example-com", repo.getId() ); - assertEquals( "Repository url does not match its name", "http://private.example.com/internal", repo.getUrl() ); - assertEquals( "Repository cache period check failed", DEFAULT_CACHE_PERIOD, repo.getSnapshotsInterval() ); - assertFalse( "Repository failure caching check failed", repo.isCacheFailures() ); - } - - public void testInvalidConfiguration() - { - Configuration configuration = new Configuration(); - try - { - loader.load( new Properties(), configuration ); - fail( "Incomplete config should have failed" ); - } - catch ( InvalidConfigurationException e ) - { - assertTrue( true ); - } - } - - protected void setUp() - throws Exception - { - super.setUp(); - loader = new MavenProxyPropertyLoader(); - } -} diff --git a/maven-repository-configuration/src/test/resources/org/apache/maven/repository/configuration/ConfigurationStoreTest.xml b/maven-repository-configuration/src/test/resources/org/apache/maven/repository/configuration/ConfigurationStoreTest.xml deleted file mode 100644 index 39a15a996..000000000 --- a/maven-repository-configuration/src/test/resources/org/apache/maven/repository/configuration/ConfigurationStoreTest.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - org.apache.maven.repository.configuration.ConfigurationStore - default - org.apache.maven.repository.configuration.DefaultConfigurationStore - - ${basedir}/src/test/conf/repository-manager.xml - - - - org.apache.maven.repository.configuration.ConfigurationStore - corrupt-file - org.apache.maven.repository.configuration.DefaultConfigurationStore - - ${basedir}/src/test/conf/corrupt.xml - - - - org.apache.maven.repository.configuration.ConfigurationStore - invalid-file - org.apache.maven.repository.configuration.DefaultConfigurationStore - - ${basedir}/src/test/conf/nada.txt - - - - org.apache.maven.repository.configuration.ConfigurationStore - save-file - org.apache.maven.repository.configuration.DefaultConfigurationStore - - ${basedir}/target/test/test-file.xml - - - - diff --git a/maven-repository-converter/pom.xml b/maven-repository-converter/pom.xml deleted file mode 100644 index e72b0846b..000000000 --- a/maven-repository-converter/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - org.apache.maven.repository - maven-repository-manager - 1.0-SNAPSHOT - - 4.0.0 - maven-repository-converter - Maven Repository Converter - - - org.codehaus.plexus - plexus-utils - - - org.apache.maven - maven-artifact - - - org.apache.maven - maven-model-converter - - - org.apache.maven.repository - maven-repository-reports-standard - - - org.codehaus.plexus - plexus-i18n - 1.0-beta-6 - - - diff --git a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java deleted file mode 100644 index 86078ef6b..000000000 --- a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java +++ /dev/null @@ -1,661 +0,0 @@ -package org.apache.maven.repository.converter; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.Metadata; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.Snapshot; -import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.Versioning; -import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; -import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer; -import org.apache.maven.model.DistributionManagement; -import org.apache.maven.model.Model; -import org.apache.maven.model.Relocation; -import org.apache.maven.model.converter.ArtifactPomRewriter; -import org.apache.maven.model.converter.ModelConverter; -import org.apache.maven.model.converter.PomTranslationException; -import org.apache.maven.model.io.xpp3.MavenXpp3Writer; -import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader; -import org.apache.maven.repository.converter.transaction.FileTransaction; -import org.apache.maven.repository.digest.Digester; -import org.apache.maven.repository.digest.DigesterException; -import org.apache.maven.repository.reporting.ArtifactReporter; -import org.codehaus.plexus.i18n.I18N; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Properties; -import java.util.regex.Matcher; - -/** - * Implementation of repository conversion class. - * - * @author Brett Porter - * @plexus.component role="org.apache.maven.repository.converter.RepositoryConverter" role-hint="default" - */ -public class DefaultRepositoryConverter - implements RepositoryConverter -{ - /** - * @plexus.requirement role-hint="sha1" - */ - private Digester sha1Digester; - - /** - * @plexus.requirement role-hint="md5" - */ - private Digester md5Digester; - - /** - * @plexus.requirement - */ - private ArtifactFactory artifactFactory; - - /** - * @plexus.requirement - */ - private ArtifactPomRewriter rewriter; - - /** - * @plexus.requirement - */ - private ModelConverter translator; - - /** - * @plexus.configuration default-value="false" - */ - private boolean force; - - /** - * @plexus.configuration default-value="false" - */ - private boolean dryrun; - - /** - * @plexus.requirement - */ - private I18N i18n; - - public void convert( Artifact artifact, ArtifactRepository targetRepository, ArtifactReporter reporter ) - throws RepositoryConversionException - { - if ( artifact.getRepository().getUrl().equals( targetRepository.getUrl() ) ) - { - throw new RepositoryConversionException( getI18NString( "exception.repositories.match" ) ); - } - - if ( validateMetadata( artifact, reporter ) ) - { - FileTransaction transaction = new FileTransaction(); - - if ( copyPom( artifact, targetRepository, reporter, transaction ) ) - { - if ( copyArtifact( artifact, targetRepository, reporter, transaction ) ) - { - Metadata metadata = createBaseMetadata( artifact ); - Versioning versioning = new Versioning(); - versioning.addVersion( artifact.getBaseVersion() ); - metadata.setVersioning( versioning ); - updateMetadata( new ArtifactRepositoryMetadata( artifact ), targetRepository, metadata, - transaction ); - - metadata = createBaseMetadata( artifact ); - metadata.setVersion( artifact.getBaseVersion() ); - versioning = new Versioning(); - - Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( artifact.getVersion() ); - if ( matcher.matches() ) - { - Snapshot snapshot = new Snapshot(); - snapshot.setBuildNumber( Integer.valueOf( matcher.group( 3 ) ).intValue() ); - snapshot.setTimestamp( matcher.group( 2 ) ); - versioning.setSnapshot( snapshot ); - } - - // TODO: merge latest/release/snapshot from source instead - metadata.setVersioning( versioning ); - updateMetadata( new SnapshotArtifactRepositoryMetadata( artifact ), targetRepository, metadata, - transaction ); - - if ( !dryrun ) - { - transaction.commit(); - } - reporter.addSuccess( artifact ); - } - } - } - } - - private static Metadata createBaseMetadata( Artifact artifact ) - { - Metadata metadata = new Metadata(); - metadata.setArtifactId( artifact.getArtifactId() ); - metadata.setGroupId( artifact.getGroupId() ); - return metadata; - } - - private void updateMetadata( RepositoryMetadata artifactMetadata, ArtifactRepository targetRepository, - Metadata newMetadata, FileTransaction transaction ) - throws RepositoryConversionException - { - File file = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); - - Metadata metadata; - boolean changed; - - if ( file.exists() ) - { - metadata = readMetadata( file ); - changed = metadata.merge( newMetadata ); - } - else - { - changed = true; - metadata = newMetadata; - } - - if ( changed ) - { - StringWriter writer = null; - try - { - writer = new StringWriter(); - - MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer(); - - mappingWriter.write( writer, metadata ); - - transaction.createFile( writer.toString(), file ); - } - catch ( IOException e ) - { - throw new RepositoryConversionException( "Error writing target metadata", e ); - } - finally - { - IOUtil.close( writer ); - } - } - } - - private Metadata readMetadata( File file ) - throws RepositoryConversionException - { - Metadata metadata; - MetadataXpp3Reader reader = new MetadataXpp3Reader(); - FileReader fileReader = null; - try - { - fileReader = new FileReader( file ); - metadata = reader.read( fileReader ); - } - catch ( FileNotFoundException e ) - { - throw new RepositoryConversionException( "Error reading target metadata", e ); - } - catch ( IOException e ) - { - throw new RepositoryConversionException( "Error reading target metadata", e ); - } - catch ( XmlPullParserException e ) - { - throw new RepositoryConversionException( "Error reading target metadata", e ); - } - finally - { - IOUtil.close( fileReader ); - } - return metadata; - } - - private boolean validateMetadata( Artifact artifact, ArtifactReporter reporter ) - throws RepositoryConversionException - { - ArtifactRepository repository = artifact.getRepository(); - - boolean result = true; - - RepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact ); - File file = - new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) ); - if ( file.exists() ) - { - Metadata metadata = readMetadata( file ); - result = validateMetadata( metadata, repositoryMetadata, artifact, reporter ); - } - - repositoryMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); - file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) ); - if ( file.exists() ) - { - Metadata metadata = readMetadata( file ); - result = result && validateMetadata( metadata, repositoryMetadata, artifact, reporter ); - } - - return result; - } - - private boolean validateMetadata( Metadata metadata, RepositoryMetadata repositoryMetadata, Artifact artifact, - ArtifactReporter reporter ) - { - String groupIdKey; - String artifactIdKey = null; - String snapshotKey = null; - String versionKey = null; - String versionsKey = null; - if ( repositoryMetadata.storedInGroupDirectory() ) - { - groupIdKey = "failure.incorrect.groupMetadata.groupId"; - } - else if ( repositoryMetadata.storedInArtifactVersionDirectory() ) - { - groupIdKey = "failure.incorrect.snapshotMetadata.groupId"; - artifactIdKey = "failure.incorrect.snapshotMetadata.artifactId"; - versionKey = "failure.incorrect.snapshotMetadata.version"; - snapshotKey = "failure.incorrect.snapshotMetadata.snapshot"; - } - else - { - groupIdKey = "failure.incorrect.artifactMetadata.groupId"; - artifactIdKey = "failure.incorrect.artifactMetadata.artifactId"; - versionsKey = "failure.incorrect.artifactMetadata.versions"; - } - - boolean result = true; - - if ( !metadata.getGroupId().equals( artifact.getGroupId() ) ) - { - reporter.addFailure( artifact, getI18NString( groupIdKey ) ); - result = false; - } - if ( !repositoryMetadata.storedInGroupDirectory() ) - { - if ( !metadata.getArtifactId().equals( artifact.getArtifactId() ) ) - { - reporter.addFailure( artifact, getI18NString( artifactIdKey ) ); - result = false; - } - if ( !repositoryMetadata.storedInArtifactVersionDirectory() ) - { - // artifact metadata - - boolean foundVersion = false; - if ( metadata.getVersioning() != null ) - { - for ( Iterator i = metadata.getVersioning().getVersions().iterator(); - i.hasNext() && !foundVersion; ) - { - String version = (String) i.next(); - if ( version.equals( artifact.getBaseVersion() ) ) - { - foundVersion = true; - } - } - } - - if ( !foundVersion ) - { - reporter.addFailure( artifact, getI18NString( versionsKey ) ); - result = false; - } - } - else - { - // snapshot metadata - if ( !artifact.getBaseVersion().equals( metadata.getVersion() ) ) - { - reporter.addFailure( artifact, getI18NString( versionKey ) ); - result = false; - } - - if ( artifact.isSnapshot() ) - { - Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( artifact.getVersion() ); - if ( matcher.matches() ) - { - boolean correct = false; - if ( metadata.getVersioning() != null && metadata.getVersioning().getSnapshot() != null ) - { - Snapshot snapshot = metadata.getVersioning().getSnapshot(); - int build = Integer.valueOf( matcher.group( 3 ) ).intValue(); - String ts = matcher.group( 2 ); - if ( build == snapshot.getBuildNumber() && ts.equals( snapshot.getTimestamp() ) ) - { - correct = true; - } - } - - if ( !correct ) - { - reporter.addFailure( artifact, getI18NString( snapshotKey ) ); - result = false; - } - } - } - } - } - return result; - } - - private boolean copyPom( Artifact artifact, ArtifactRepository targetRepository, ArtifactReporter reporter, - FileTransaction transaction ) - throws RepositoryConversionException - { - Artifact pom = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersion() ); - pom.setBaseVersion( artifact.getBaseVersion() ); - ArtifactRepository repository = artifact.getRepository(); - File file = new File( repository.getBasedir(), repository.pathOf( pom ) ); - - boolean result = true; - if ( file.exists() ) - { - File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pom ) ); - - String contents = null; - boolean checksumsValid = false; - try - { - if ( testChecksums( artifact, file, reporter ) ) - { - checksumsValid = true; - contents = FileUtils.fileRead( file ); - } - } - catch ( IOException e ) - { - throw new RepositoryConversionException( "Unable to read source POM: " + e.getMessage(), e ); - } - - if ( checksumsValid && contents.indexOf( "modelVersion" ) >= 0 ) - { - // v4 POM - try - { - boolean matching = false; - if ( !force && targetFile.exists() ) - { - String targetContents = FileUtils.fileRead( targetFile ); - matching = targetContents.equals( contents ); - } - if ( force || !matching ) - { - transaction.createFile( contents, targetFile ); - } - } - catch ( IOException e ) - { - throw new RepositoryConversionException( "Unable to write target POM: " + e.getMessage(), e ); - } - } - else - { - // v3 POM - StringReader stringReader = new StringReader( contents ); - StringWriter writer = null; - try - { - MavenXpp3Reader v3Reader = new MavenXpp3Reader(); - org.apache.maven.model.v3_0_0.Model v3Model = v3Reader.read( stringReader ); - - if ( doRelocation( artifact, v3Model, targetRepository, transaction ) ) - { - Artifact relocatedPom = artifactFactory.createProjectArtifact( artifact.getGroupId(), - artifact.getArtifactId(), - artifact.getVersion() ); - targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( relocatedPom ) ); - } - - Model v4Model = translator.translate( v3Model ); - - translator.validateV4Basics( v4Model, v3Model.getGroupId(), v3Model.getArtifactId(), - v3Model.getVersion(), v3Model.getPackage() ); - - writer = new StringWriter(); - MavenXpp3Writer Xpp3Writer = new MavenXpp3Writer(); - Xpp3Writer.write( writer, v4Model ); - - transaction.createFile( writer.toString(), targetFile ); - - List warnings = translator.getWarnings(); - - for ( Iterator i = warnings.iterator(); i.hasNext(); ) - { - String message = (String) i.next(); - reporter.addWarning( artifact, message ); - } - } - catch ( XmlPullParserException e ) - { - reporter.addFailure( artifact, getI18NString( "failure.invalid.source.pom", e.getMessage() ) ); - result = false; - } - catch ( IOException e ) - { - throw new RepositoryConversionException( "Unable to write converted POM", e ); - } - catch ( PomTranslationException e ) - { - reporter.addFailure( artifact, getI18NString( "failure.invalid.source.pom", e.getMessage() ) ); - result = false; - } - finally - { - IOUtil.close( writer ); - } - } - } - else - { - reporter.addWarning( artifact, getI18NString( "warning.missing.pom" ) ); - } - return result; - } - - private boolean doRelocation( Artifact artifact, org.apache.maven.model.v3_0_0.Model v3Model, - ArtifactRepository repository, FileTransaction transaction ) - throws IOException - { - Properties properties = v3Model.getProperties(); - if ( properties.containsKey( "relocated.groupId" ) || properties.containsKey( "relocated.artifactId" ) || - properties.containsKey( "relocated.version" ) ) - { - String newGroupId = properties.getProperty( "relocated.groupId", v3Model.getGroupId() ); - properties.remove( "relocated.groupId" ); - - String newArtifactId = properties.getProperty( "relocated.artifactId", v3Model.getArtifactId() ); - properties.remove( "relocated.artifactId" ); - - String newVersion = properties.getProperty( "relocated.version", v3Model.getVersion() ); - properties.remove( "relocated.version" ); - - String message = properties.getProperty( "relocated.message", "" ); - properties.remove( "relocated.message" ); - - if ( properties.isEmpty() ) - { - v3Model.setProperties( null ); - } - - writeRelocationPom( v3Model.getGroupId(), v3Model.getArtifactId(), v3Model.getVersion(), newGroupId, - newArtifactId, newVersion, message, repository, transaction ); - - v3Model.setGroupId( newGroupId ); - v3Model.setArtifactId( newArtifactId ); - v3Model.setVersion( newVersion ); - - artifact.setGroupId( newGroupId ); - artifact.setArtifactId( newArtifactId ); - artifact.setVersion( newVersion ); - - return true; - } - else - { - return false; - } - } - - private void writeRelocationPom( String groupId, String artifactId, String version, String newGroupId, - String newArtifactId, String newVersion, String message, - ArtifactRepository repository, FileTransaction transaction ) - throws IOException - { - Model pom = new Model(); - pom.setGroupId( groupId ); - pom.setArtifactId( artifactId ); - pom.setVersion( version ); - - DistributionManagement dMngt = new DistributionManagement(); - - Relocation relocation = new Relocation(); - relocation.setGroupId( newGroupId ); - relocation.setArtifactId( newArtifactId ); - relocation.setVersion( newVersion ); - if ( message != null && message.length() > 0 ) - { - relocation.setMessage( message ); - } - - dMngt.setRelocation( relocation ); - - pom.setDistributionManagement( dMngt ); - - Artifact artifact = artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" ); - File pomFile = new File( repository.getBasedir(), repository.pathOf( artifact ) ); - - StringWriter strWriter = new StringWriter(); - MavenXpp3Writer pomWriter = new MavenXpp3Writer(); - pomWriter.write( strWriter, pom ); - - transaction.createFile( strWriter.toString(), pomFile ); - } - - private String getI18NString( String key, String arg0 ) - { - return i18n.format( getClass().getName(), Locale.getDefault(), key, arg0 ); - } - - private String getI18NString( String key ) - { - return i18n.getString( getClass().getName(), Locale.getDefault(), key ); - } - - private boolean testChecksums( Artifact artifact, File file, ArtifactReporter reporter ) - throws IOException - { - - boolean result = - verifyChecksum( file, file.getName() + ".md5", md5Digester, reporter, artifact, "failure.incorrect.md5" ); - result = result && verifyChecksum( file, file.getName() + ".sha1", sha1Digester, reporter, artifact, - "failure.incorrect.sha1" ); - return result; - } - - private boolean verifyChecksum( File file, String fileName, Digester digester, ArtifactReporter reporter, - Artifact artifact, String key ) - throws IOException - { - boolean result = true; - - File checksumFile = new File( file.getParentFile(), fileName ); - if ( checksumFile.exists() ) - { - String checksum = FileUtils.fileRead( checksumFile ); - try - { - digester.verify( file, checksum ); - } - catch ( DigesterException e ) - { - reporter.addFailure( artifact, getI18NString( key ) ); - result = false; - } - } - return result; - } - - private boolean copyArtifact( Artifact artifact, ArtifactRepository targetRepository, ArtifactReporter reporter, - FileTransaction transaction ) - throws RepositoryConversionException - { - File sourceFile = artifact.getFile(); - - File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - - boolean result = true; - try - { - boolean matching = false; - if ( !force && targetFile.exists() ) - { - matching = FileUtils.contentEquals( sourceFile, targetFile ); - if ( !matching ) - { - reporter.addFailure( artifact, getI18NString( "failure.target.already.exists" ) ); - result = false; - } - } - if ( result ) - { - if ( force || !matching ) - { - if ( testChecksums( artifact, sourceFile, reporter ) ) - { - transaction.copyFile( sourceFile, targetFile ); - } - else - { - result = false; - } - } - } - } - catch ( IOException e ) - { - throw new RepositoryConversionException( "Error copying artifact", e ); - } - return result; - } - - public void convert( List artifacts, ArtifactRepository targetRepository, ArtifactReporter reporter ) - throws RepositoryConversionException - { - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact artifact = (Artifact) i.next(); - convert( artifact, targetRepository, reporter ); - } - } -} diff --git a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConversionException.java b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConversionException.java deleted file mode 100644 index 2409235bb..000000000 --- a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConversionException.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apache.maven.repository.converter; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * Exception occuring during repository conversion. - * - * @author Brett Porter - */ -public class RepositoryConversionException - extends Exception -{ - public RepositoryConversionException( String message ) - { - super( message ); - } - - public RepositoryConversionException( String message, Throwable cause ) - { - super( message, cause ); - } -} diff --git a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConverter.java b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConverter.java deleted file mode 100644 index cf6e1b151..000000000 --- a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConverter.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.apache.maven.repository.converter; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.repository.reporting.ArtifactReporter; - -import java.util.List; -import java.io.File; - -/** - * Copy a set of artifacts from one repository to the other, converting if necessary. - * - * @author Brett Porter - */ -public interface RepositoryConverter -{ - String ROLE = RepositoryConverter.class.getName(); - - /** - * Convert a single artifact, writing it into the target repository. - * - * @param artifact the artifact to convert - * @param targetRepository the target repository - * @param reporter reporter to track the results of the conversion - */ - void convert( Artifact artifact, ArtifactRepository targetRepository, ArtifactReporter reporter ) - throws RepositoryConversionException; - - /** - * Convert a set of artifacts, writing them into the target repository. - * - * @param artifacts the set of artifacts to convert - * @param targetRepository the target repository - * @param reporter reporter to track the results of the conversions - */ - void convert( List artifacts, ArtifactRepository targetRepository, ArtifactReporter reporter ) - throws RepositoryConversionException; -} diff --git a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/transaction/AbstractTransactionEvent.java b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/transaction/AbstractTransactionEvent.java deleted file mode 100644 index 521930a28..000000000 --- a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/transaction/AbstractTransactionEvent.java +++ /dev/null @@ -1,120 +0,0 @@ -package org.apache.maven.repository.converter.transaction; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.util.FileUtils; - -import java.io.File; -import java.io.IOException; -import java.util.Collections; -import java.util.List; -import java.util.ArrayList; - -/** - * Abstract class for the TransactionEvents - * - * @author Edwin Punzalan - */ -public abstract class AbstractTransactionEvent - implements TransactionEvent -{ - private File backup; - - private List createdDirs; - - /** - * Method that creates a directory as well as all the parent directories needed - * - * @param dir The File directory to be created - * @throws IOException when an unrecoverable error occurred - */ - protected void mkDirs( File dir ) - throws IOException - { - List createDirs = new ArrayList(); - - File parent = dir; - while( !parent.exists() || !parent.isDirectory() ) - { - createDirs.add( parent ); - - parent = parent.getParentFile(); - } - - createdDirs = new ArrayList(); - - while ( !createDirs.isEmpty() ) - { - File directory = (File) createDirs.remove( createDirs.size() - 1 ); - - if ( directory.mkdir() ) - { - createdDirs.add( directory ); - } - else - { - throw new IOException( "Failed to create directory: " + directory.getAbsolutePath() ); - } - } - } - - protected void revertMkDirs() - throws IOException - { - if ( createdDirs != null ) - { - Collections.reverse( createdDirs ); - - while( !createdDirs.isEmpty() ) - { - File dir = (File) createdDirs.remove( 0 ); - - if ( dir.isDirectory() && dir.list().length == 0 ) - { - FileUtils.deleteDirectory( dir.getAbsolutePath() ); - } - else - { - //cannot rollback created directory if it still contains files - break; - } - } - } - } - - protected void createBackup( File file ) - throws IOException - { - if ( file.exists() && file.isFile() ) - { - backup = File.createTempFile( "temp-", ".backup" ); - - FileUtils.copyFile( file, backup ); - - backup.deleteOnExit(); - } - } - - protected void restoreBackup( File file ) - throws IOException - { - if ( backup != null ) - { - FileUtils.copyFile( backup, file ); - } - } -} diff --git a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/transaction/CopyFileEvent.java b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/transaction/CopyFileEvent.java deleted file mode 100644 index cddc854cc..000000000 --- a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/transaction/CopyFileEvent.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.apache.maven.repository.converter.transaction; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.util.FileUtils; - -import java.io.File; -import java.io.IOException; - -/** - * Event to copy a file. - * - * @author Brett Porter - */ -public class CopyFileEvent - extends AbstractTransactionEvent -{ - private final File source; - - private final File destination; - - public CopyFileEvent( File source, File destination ) - { - this.source = source; - this.destination = destination; - } - - public void commit() - throws IOException - { - createBackup( destination ); - - mkDirs( destination.getParentFile() ); - - FileUtils.copyFile( source, destination ); - } - - public void rollback() - throws IOException - { - FileUtils.fileDelete( destination.getAbsolutePath() ); - - revertMkDirs(); - - restoreBackup( destination ); - } -} diff --git a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/transaction/CreateFileEvent.java b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/transaction/CreateFileEvent.java deleted file mode 100644 index 283ee60fd..000000000 --- a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/transaction/CreateFileEvent.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.apache.maven.repository.converter.transaction; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.util.FileUtils; - -import java.io.File; -import java.io.IOException; - -/** - * Event for creating a file from a string content. - * - * @author Brett Porter - */ -public class CreateFileEvent - extends AbstractTransactionEvent -{ - private final File destination; - - private final String content; - - public CreateFileEvent( String content, File destination ) - { - this.content = content; - this.destination = destination; - } - - public void commit() - throws IOException - { - createBackup( destination ); - - mkDirs( destination.getParentFile() ); - - if ( !destination.exists() && !destination.createNewFile() ) - { - throw new IOException( "Unable to create new file" ); - } - - FileUtils.fileWrite( destination.getAbsolutePath(), content ); - } - - public void rollback() - throws IOException - { - FileUtils.fileDelete( destination.getAbsolutePath() ); - - revertMkDirs(); - - restoreBackup( destination ); - } -} diff --git a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/transaction/FileTransaction.java b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/transaction/FileTransaction.java deleted file mode 100644 index ceb368660..000000000 --- a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/transaction/FileTransaction.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.apache.maven.repository.converter.transaction; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.repository.converter.RepositoryConversionException; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -/** - * Implement commit/rollback semantics for a set of files. - * - * @author Brett Porter - */ -public class FileTransaction -{ - private List events = new ArrayList(); - - public void commit() - throws RepositoryConversionException - { - List toRollback = new ArrayList( events.size() ); - - for ( Iterator i = events.iterator(); i.hasNext(); ) - { - TransactionEvent event = (TransactionEvent) i.next(); - - try - { - event.commit(); - - toRollback.add( event ); - } - catch ( IOException e ) - { - try - { - rollback( toRollback ); - - throw new RepositoryConversionException( "Unable to commit file transaction", e ); - } - catch ( IOException ioe ) - { - throw new RepositoryConversionException( - "Unable to commit file transaction, and rollback failed with error: '" + ioe.getMessage() + "'", - e ); - } - } - } - } - - private void rollback( List toRollback ) - throws IOException - { - for ( Iterator i = toRollback.iterator(); i.hasNext(); ) - { - TransactionEvent event = (TransactionEvent) i.next(); - - event.rollback(); - } - } - - public void copyFile( File source, File destination ) - { - events.add( new CopyFileEvent( source, destination ) ); - } - - public void createFile( String content, File destination ) - { - events.add( new CreateFileEvent( content, destination ) ); - } -} diff --git a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/transaction/TransactionEvent.java b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/transaction/TransactionEvent.java deleted file mode 100644 index 2f8a528e4..000000000 --- a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/transaction/TransactionEvent.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.apache.maven.repository.converter.transaction; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 java.io.IOException; - -/** - * Interface for individual events in a transaction. - * - * @author Brett Porter - */ -public interface TransactionEvent -{ - /** - * Commit this event. - * - * @throws IOException if an error occurred committing the change - */ - void commit() - throws IOException; - - /** - * Rollback the even already committed. - * - * @throws IOException if an error occurred reverting the change - */ - void rollback() - throws IOException; -} diff --git a/maven-repository-converter/src/main/resources/org/apache/maven/repository/converter/DefaultRepositoryConverter.properties b/maven-repository-converter/src/main/resources/org/apache/maven/repository/converter/DefaultRepositoryConverter.properties deleted file mode 100644 index f6089c1f5..000000000 --- a/maven-repository-converter/src/main/resources/org/apache/maven/repository/converter/DefaultRepositoryConverter.properties +++ /dev/null @@ -1,35 +0,0 @@ -# -# Copyright 2005-2006 The Apache Software Foundation. -# -# Licensed 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. -# - -failure.incorrect.md5=The MD5 checksum value was incorrect. -failure.incorrect.sha1=The SHA1 checksum value was incorrect. -failure.target.already.exists=The artifact could not be converted because it already exists. -failure.invalid.source.pom=The source POM was invalid: {0}. - -warning.missing.pom=The artifact had no POM in the source repository. - -exception.repositories.match=Source and target repositories are identical. - -failure.incorrect.groupMetadata.groupId=The group ID in the source group metadata is incorrect. - -failure.incorrect.artifactMetadata.artifactId=The artifact ID in the source artifact metadata is incorrect. -failure.incorrect.artifactMetadata.groupId=The group ID in the source artifact metadata is incorrect. -failure.incorrect.artifactMetadata.versions=The version list in the source artifact metadata is incorrect. - -failure.incorrect.snapshotMetadata.artifactId=The artifact ID in the source artifact version metadata is incorrect. -failure.incorrect.snapshotMetadata.groupId=The group ID in the source artifact version metadata is incorrect. -failure.incorrect.snapshotMetadata.version=The version in the source artifact version metadata is incorrect. -failure.incorrect.snapshotMetadata.snapshot=The snapshot information in the source artifact version metadata is incorrect. diff --git a/maven-repository-converter/src/test/expected-files/converted-artifact-one.pom b/maven-repository-converter/src/test/expected-files/converted-artifact-one.pom deleted file mode 100644 index cd3862d35..000000000 --- a/maven-repository-converter/src/test/expected-files/converted-artifact-one.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 4.0.0 - test - artifact-one - 1.0.0 - diff --git a/maven-repository-converter/src/test/expected-files/converted-artifact-three.pom b/maven-repository-converter/src/test/expected-files/converted-artifact-three.pom deleted file mode 100644 index 343291037..000000000 --- a/maven-repository-converter/src/test/expected-files/converted-artifact-three.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 4.0.0 - test - artifact-three - 1.0.0 - diff --git a/maven-repository-converter/src/test/expected-files/converted-artifact-two.pom b/maven-repository-converter/src/test/expected-files/converted-artifact-two.pom deleted file mode 100644 index 227470167..000000000 --- a/maven-repository-converter/src/test/expected-files/converted-artifact-two.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 4.0.0 - test - artifact-two - 1.0.0 - diff --git a/maven-repository-converter/src/test/expected-files/converted-v3-snapshot.pom b/maven-repository-converter/src/test/expected-files/converted-v3-snapshot.pom deleted file mode 100644 index 9134c3cdf..000000000 --- a/maven-repository-converter/src/test/expected-files/converted-v3-snapshot.pom +++ /dev/null @@ -1,22 +0,0 @@ - - 4.0.0 - test - v3artifact - 1.0.0-SNAPSHOT - - scm:cvs:ext:${maven.username}@localhost:/home/cvs - - - - groupId - artifactId - version - - - groupId - test-artifactId - version - test - - - diff --git a/maven-repository-converter/src/test/expected-files/converted-v3-timestamped-snapshot.pom b/maven-repository-converter/src/test/expected-files/converted-v3-timestamped-snapshot.pom deleted file mode 100644 index 46eacaf2e..000000000 --- a/maven-repository-converter/src/test/expected-files/converted-v3-timestamped-snapshot.pom +++ /dev/null @@ -1,22 +0,0 @@ - - 4.0.0 - test - v3artifact - 1.0.0-20060105.130101-3 - - scm:cvs:ext:${maven.username}@localhost:/home/cvs - - - - groupId - artifactId - version - - - groupId - test-artifactId - version - test - - - diff --git a/maven-repository-converter/src/test/expected-files/converted-v3-warnings.pom b/maven-repository-converter/src/test/expected-files/converted-v3-warnings.pom deleted file mode 100644 index e07664932..000000000 --- a/maven-repository-converter/src/test/expected-files/converted-v3-warnings.pom +++ /dev/null @@ -1,22 +0,0 @@ - - 4.0.0 - test - v3-warnings-artifact - 1.0.0 - - scm:cvs:ext:${maven.username}@localhost:/home/cvs - - - - groupId - artifactId - version - - - groupId - test-artifactId - version - test - - - diff --git a/maven-repository-converter/src/test/expected-files/converted-v3.pom b/maven-repository-converter/src/test/expected-files/converted-v3.pom deleted file mode 100644 index 29ba92771..000000000 --- a/maven-repository-converter/src/test/expected-files/converted-v3.pom +++ /dev/null @@ -1,22 +0,0 @@ - - 4.0.0 - test - v3artifact - 1.0.0 - - scm:cvs:ext:${maven.username}@localhost:/home/cvs - - - - groupId - artifactId - version - - - groupId - test-artifactId - version - test - - - diff --git a/maven-repository-converter/src/test/expected-files/newversion-artifact-metadata.xml b/maven-repository-converter/src/test/expected-files/newversion-artifact-metadata.xml deleted file mode 100644 index ecc7f09a0..000000000 --- a/maven-repository-converter/src/test/expected-files/newversion-artifact-metadata.xml +++ /dev/null @@ -1,10 +0,0 @@ - - test - newversion-artifact - - - 1.0.0 - 1.0.1 - - - diff --git a/maven-repository-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/maven-metadata.xml b/maven-repository-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/maven-metadata.xml deleted file mode 100644 index ebd9be970..000000000 --- a/maven-repository-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/maven-metadata.xml +++ /dev/null @@ -1,6 +0,0 @@ - - relocated-test - relocated-v3artifact - 1.0.0 - - \ No newline at end of file diff --git a/maven-repository-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.jar b/maven-repository-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.pom b/maven-repository-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.pom deleted file mode 100644 index 253ef3466..000000000 --- a/maven-repository-converter/src/test/expected-files/relocated-test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.pom +++ /dev/null @@ -1,22 +0,0 @@ - - 4.0.0 - relocated-test - relocated-v3artifact - 1.0.0 - - scm:cvs:ext:${maven.username}@localhost:/home/cvs - - - - groupId - artifactId - version - - - groupId - test-artifactId - version - test - - - \ No newline at end of file diff --git a/maven-repository-converter/src/test/expected-files/relocated-test/relocated-v3artifact/maven-metadata.xml b/maven-repository-converter/src/test/expected-files/relocated-test/relocated-v3artifact/maven-metadata.xml deleted file mode 100644 index b4b1a864a..000000000 --- a/maven-repository-converter/src/test/expected-files/relocated-test/relocated-v3artifact/maven-metadata.xml +++ /dev/null @@ -1,9 +0,0 @@ - - relocated-test - relocated-v3artifact - - - 1.0.0 - - - \ No newline at end of file diff --git a/maven-repository-converter/src/test/expected-files/test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.pom b/maven-repository-converter/src/test/expected-files/test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.pom deleted file mode 100644 index b20f62f9e..000000000 --- a/maven-repository-converter/src/test/expected-files/test/relocated-v3artifact/1.0.0/relocated-v3artifact-1.0.0.pom +++ /dev/null @@ -1,12 +0,0 @@ - - test - relocated-v3artifact - 1.0.0 - - - relocated-test - relocated-v3artifact - 1.0.0 - - - \ No newline at end of file diff --git a/maven-repository-converter/src/test/expected-files/v3-artifact-metadata.xml b/maven-repository-converter/src/test/expected-files/v3-artifact-metadata.xml deleted file mode 100644 index a8a7f3748..000000000 --- a/maven-repository-converter/src/test/expected-files/v3-artifact-metadata.xml +++ /dev/null @@ -1,9 +0,0 @@ - - test - v3artifact - - - 1.0.0 - - - diff --git a/maven-repository-converter/src/test/expected-files/v3-snapshot-artifact-metadata.xml b/maven-repository-converter/src/test/expected-files/v3-snapshot-artifact-metadata.xml deleted file mode 100644 index 24d25a0e0..000000000 --- a/maven-repository-converter/src/test/expected-files/v3-snapshot-artifact-metadata.xml +++ /dev/null @@ -1,9 +0,0 @@ - - test - v3artifact - - - 1.0.0-SNAPSHOT - - - diff --git a/maven-repository-converter/src/test/expected-files/v3-snapshot-metadata.xml b/maven-repository-converter/src/test/expected-files/v3-snapshot-metadata.xml deleted file mode 100644 index b19c537b5..000000000 --- a/maven-repository-converter/src/test/expected-files/v3-snapshot-metadata.xml +++ /dev/null @@ -1,6 +0,0 @@ - - test - v3artifact - 1.0.0-SNAPSHOT - - diff --git a/maven-repository-converter/src/test/expected-files/v3-timestamped-snapshot-metadata.xml b/maven-repository-converter/src/test/expected-files/v3-timestamped-snapshot-metadata.xml deleted file mode 100644 index 602c38ec8..000000000 --- a/maven-repository-converter/src/test/expected-files/v3-timestamped-snapshot-metadata.xml +++ /dev/null @@ -1,11 +0,0 @@ - - test - v3artifact - 1.0.0-SNAPSHOT - - - 20060105.130101 - 3 - - - diff --git a/maven-repository-converter/src/test/expected-files/v3-version-metadata.xml b/maven-repository-converter/src/test/expected-files/v3-version-metadata.xml deleted file mode 100644 index 3c8938984..000000000 --- a/maven-repository-converter/src/test/expected-files/v3-version-metadata.xml +++ /dev/null @@ -1,6 +0,0 @@ - - test - v3artifact - 1.0.0 - - diff --git a/maven-repository-converter/src/test/expected-files/v4-artifact-metadata.xml b/maven-repository-converter/src/test/expected-files/v4-artifact-metadata.xml deleted file mode 100644 index c0cdbfdb4..000000000 --- a/maven-repository-converter/src/test/expected-files/v4-artifact-metadata.xml +++ /dev/null @@ -1,9 +0,0 @@ - - test - v4artifact - - - 1.0.0 - - - diff --git a/maven-repository-converter/src/test/expected-files/v4-snapshot-artifact-metadata.xml b/maven-repository-converter/src/test/expected-files/v4-snapshot-artifact-metadata.xml deleted file mode 100644 index f8072b0df..000000000 --- a/maven-repository-converter/src/test/expected-files/v4-snapshot-artifact-metadata.xml +++ /dev/null @@ -1,9 +0,0 @@ - - test - v4artifact - - - 1.0.0-SNAPSHOT - - - diff --git a/maven-repository-converter/src/test/expected-files/v4-snapshot-metadata.xml b/maven-repository-converter/src/test/expected-files/v4-snapshot-metadata.xml deleted file mode 100644 index d5ecb7d47..000000000 --- a/maven-repository-converter/src/test/expected-files/v4-snapshot-metadata.xml +++ /dev/null @@ -1,6 +0,0 @@ - - test - v4artifact - 1.0.0-SNAPSHOT - - diff --git a/maven-repository-converter/src/test/expected-files/v4-timestamped-snapshot-metadata.xml b/maven-repository-converter/src/test/expected-files/v4-timestamped-snapshot-metadata.xml deleted file mode 100644 index 060a79cdd..000000000 --- a/maven-repository-converter/src/test/expected-files/v4-timestamped-snapshot-metadata.xml +++ /dev/null @@ -1,11 +0,0 @@ - - test - v4artifact - 1.0.0-SNAPSHOT - - - 20060111.120115 - 1 - - - diff --git a/maven-repository-converter/src/test/expected-files/v4-version-metadata.xml b/maven-repository-converter/src/test/expected-files/v4-version-metadata.xml deleted file mode 100644 index 7cbd8ad3d..000000000 --- a/maven-repository-converter/src/test/expected-files/v4-version-metadata.xml +++ /dev/null @@ -1,6 +0,0 @@ - - test - v4artifact - 1.0.0 - - diff --git a/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java b/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java deleted file mode 100644 index d7b83cf7e..000000000 --- a/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java +++ /dev/null @@ -1,947 +0,0 @@ -package org.apache.maven.repository.converter; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.metadata.ArtifactMetadata; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; -import org.apache.maven.repository.reporting.ArtifactReporter; -import org.apache.maven.repository.reporting.ArtifactResult; -import org.apache.maven.repository.reporting.DefaultArtifactReporter; -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.i18n.I18N; -import org.codehaus.plexus.util.FileUtils; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.regex.Matcher; - -/** - * Test the repository converter. - * - * @author Brett Porter - * @todo what about deletions from the source repository? - * @todo use artifact-test instead - * @todo should reject if dependencies are missing - rely on reporting? - * @todo group metadata - */ -public class RepositoryConverterTest - extends PlexusTestCase -{ - private ArtifactRepository sourceRepository; - - private ArtifactRepository targetRepository; - - private RepositoryConverter repositoryConverter; - - private ArtifactFactory artifactFactory; - - private ArtifactReporter reporter; - - private static final int SLEEP_MILLIS = 100; - - private I18N i18n; - - protected void setUp() - throws Exception - { - super.setUp(); - - ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); - - File sourceBase = getTestFile( "src/test/source-repository" ); - sourceRepository = - factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null, null ); - - layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - - File targetBase = getTestFile( "target/test-target-repository" ); - copyDirectoryStructure( getTestFile( "src/test/target-repository" ), targetBase ); - - targetRepository = - factory.createArtifactRepository( "target", targetBase.toURL().toString(), layout, null, null ); - - repositoryConverter = (RepositoryConverter) lookup( RepositoryConverter.ROLE, "default" ); - - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - - i18n = (I18N) lookup( I18N.ROLE ); - - reporter = new DefaultArtifactReporter(); - } - - private void copyDirectoryStructure( File sourceDirectory, File destinationDirectory ) - throws IOException - { - if ( !sourceDirectory.exists() ) - { - throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." ); - } - - File[] files = sourceDirectory.listFiles(); - - String sourcePath = sourceDirectory.getAbsolutePath(); - - for ( int i = 0; i < files.length; i++ ) - { - File file = files[i]; - - String dest = file.getAbsolutePath(); - - dest = dest.substring( sourcePath.length() + 1 ); - - File destination = new File( destinationDirectory, dest ); - - if ( file.isFile() ) - { - destination = destination.getParentFile(); - - FileUtils.copyFileToDirectory( file, destination ); - } - else if ( file.isDirectory() ) - { - if ( !".svn".equals( file.getName() ) ) - { - if ( !destination.exists() && !destination.mkdirs() ) - { - throw new IOException( - "Could not create destination directory '" + destination.getAbsolutePath() + "'." ); - } - copyDirectoryStructure( file, destination ); - } - } - else - { - throw new IOException( "Unknown file type: " + file.getAbsolutePath() ); - } - } - } - - public void testV4PomConvert() - throws IOException, RepositoryConversionException - { - // test that it is copied as is - - Artifact artifact = createArtifact( "test", "v4artifact", "1.0.0" ); - ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); - File artifactMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); - artifactMetadataFile.delete(); - - ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); - File versionMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); - versionMetadataFile.delete(); - - File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - artifactFile.delete(); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkSuccess(); - - assertTrue( "Check artifact created", artifactFile.exists() ); - assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); - - artifact = createPomArtifact( artifact ); - File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); - assertTrue( "Check POM created", pomFile.exists() ); - - compareFiles( sourcePomFile, pomFile ); - - assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() ); - - File expectedMetadataFile = getTestFile( "src/test/expected-files/v4-artifact-metadata.xml" ); - - compareFiles( expectedMetadataFile, artifactMetadataFile ); - - assertTrue( "Check snapshot metadata created", versionMetadataFile.exists() ); - - expectedMetadataFile = getTestFile( "src/test/expected-files/v4-version-metadata.xml" ); - - compareFiles( expectedMetadataFile, versionMetadataFile ); - } - - public void testV3PomConvert() - throws IOException, RepositoryConversionException - { - // test that the pom is coverted - - Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0" ); - ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); - File artifactMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); - artifactMetadataFile.delete(); - - ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); - File versionMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); - versionMetadataFile.delete(); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkSuccess(); - - File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - assertTrue( "Check artifact created", artifactFile.exists() ); - assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); - - artifact = createPomArtifact( artifact ); - File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3.pom" ); - assertTrue( "Check POM created", pomFile.exists() ); - - compareFiles( expectedPomFile, pomFile ); - - assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() ); - - File expectedMetadataFile = getTestFile( "src/test/expected-files/v3-artifact-metadata.xml" ); - - compareFiles( expectedMetadataFile, artifactMetadataFile ); - - assertTrue( "Check snapshot metadata created", versionMetadataFile.exists() ); - - expectedMetadataFile = getTestFile( "src/test/expected-files/v3-version-metadata.xml" ); - - compareFiles( expectedMetadataFile, versionMetadataFile ); - } - - public void testV3PomConvertWithRelocation() - throws RepositoryConversionException, IOException - { - Artifact artifact = createArtifact( "test", "relocated-v3artifact", "1.0.0" ); - ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); - File artifactMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); - artifactMetadataFile.delete(); - - ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); - File versionMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); - versionMetadataFile.delete(); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - //checkSuccess(); --> commented until MNG-2100 is fixed - - File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - assertTrue( "Check if relocated artifact created", artifactFile.exists() ); - assertTrue( "Check if relocated artifact matches", - FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); - Artifact pomArtifact = createArtifact( "relocated-test", "relocated-v3artifact", "1.0.0", "1.0.0", "pom" ); - File pomFile = getTestFile( "src/test/expected-files/" + targetRepository.pathOf( pomArtifact ) ); - File testFile = getTestFile( "target/test-target-repository/" + targetRepository.pathOf( pomArtifact ) ); - compareFiles( pomFile, testFile ); - - Artifact orig = createArtifact( "test", "relocated-v3artifact", "1.0.0", "1.0.0", "pom" ); - artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( orig ) ); - assertTrue( "Check if relocation artifact pom is created", artifactFile.exists() ); - testFile = getTestFile( "src/test/expected-files/" + targetRepository.pathOf( orig ) ); - compareFiles( artifactFile, testFile ); - } - - public void testV3PomWarningsOnConvert() - throws RepositoryConversionException, IOException - { - // test that the pom is converted but that warnings are reported - - Artifact artifact = createArtifact( "test", "v3-warnings-artifact", "1.0.0" ); - ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); - File artifactMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); - artifactMetadataFile.delete(); - - ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); - File versionMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); - versionMetadataFile.delete(); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - assertEquals( "check no errors", 0, reporter.getFailures() ); - assertEquals( "check number of warnings", 2, reporter.getWarnings() ); - assertEquals( "check success", 1, reporter.getSuccesses() ); - - File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - assertTrue( "Check artifact created", artifactFile.exists() ); - assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); - - artifact = createPomArtifact( artifact ); - File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3-warnings.pom" ); - assertTrue( "Check POM created", pomFile.exists() ); - - compareFiles( expectedPomFile, pomFile ); - - // TODO: check 2 warnings (extend and versions) matched on i18n key - } - - private void doTestV4SnapshotPomConvert( String version, String expectedMetadataFileName ) - throws RepositoryConversionException, IOException - { - // test that it is copied as is - - Artifact artifact = createArtifact( "test", "v4artifact", version ); - ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); - File artifactMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); - artifactMetadataFile.delete(); - - ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); - File snapshotMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) ); - snapshotMetadataFile.delete(); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkSuccess(); - - File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - assertTrue( "Check artifact created", artifactFile.exists() ); - assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); - - artifact = createPomArtifact( artifact ); - File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); - assertTrue( "Check POM created", pomFile.exists() ); - - compareFiles( sourcePomFile, pomFile ); - - assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() ); - - File expectedMetadataFile = getTestFile( "src/test/expected-files/v4-snapshot-artifact-metadata.xml" ); - - compareFiles( expectedMetadataFile, artifactMetadataFile ); - - assertTrue( "Check snapshot metadata created", snapshotMetadataFile.exists() ); - - expectedMetadataFile = getTestFile( expectedMetadataFileName ); - - compareFiles( expectedMetadataFile, snapshotMetadataFile ); - } - - public void testV3SnapshotPomConvert() - throws IOException, RepositoryConversionException - { - // test that the pom is coverted - - Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0-SNAPSHOT" ); - ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); - File artifactMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); - artifactMetadataFile.delete(); - - ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); - File snapshotMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) ); - snapshotMetadataFile.delete(); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkSuccess(); - - File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - assertTrue( "Check artifact created", artifactFile.exists() ); - assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); - - artifact = createPomArtifact( artifact ); - File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3-snapshot.pom" ); - assertTrue( "Check POM created", pomFile.exists() ); - - compareFiles( expectedPomFile, pomFile ); - - assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() ); - - File expectedMetadataFile = getTestFile( "src/test/expected-files/v3-snapshot-artifact-metadata.xml" ); - - compareFiles( expectedMetadataFile, artifactMetadataFile ); - - assertTrue( "Check snapshot metadata created", snapshotMetadataFile.exists() ); - - expectedMetadataFile = getTestFile( "src/test/expected-files/v3-snapshot-metadata.xml" ); - - compareFiles( expectedMetadataFile, snapshotMetadataFile ); - } - - public void testV4SnapshotPomConvert() - throws IOException, RepositoryConversionException - { - doTestV4SnapshotPomConvert( "1.0.0-SNAPSHOT", "src/test/expected-files/v4-snapshot-metadata.xml" ); - - assertTrue( true ); - } - - public void testV4TimestampedSnapshotPomConvert() - throws IOException, RepositoryConversionException - { - doTestV4SnapshotPomConvert( "1.0.0-20060111.120115-1", - "src/test/expected-files/v4-timestamped-snapshot-metadata.xml" ); - - assertTrue( true ); - } - - public void testV3TimestampedSnapshotPomConvert() - throws IOException, RepositoryConversionException - { - // test that the pom is coverted - - Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0-20060105.130101-3" ); - ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); - File artifactMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); - artifactMetadataFile.delete(); - - ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); - File snapshotMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) ); - snapshotMetadataFile.delete(); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkSuccess(); - - File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - assertTrue( "Check artifact created", artifactFile.exists() ); - assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); - - artifact = createPomArtifact( artifact ); - File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3-timestamped-snapshot.pom" ); - assertTrue( "Check POM created", pomFile.exists() ); - - compareFiles( expectedPomFile, pomFile ); - - assertTrue( "Check artifact snapshotMetadata created", artifactMetadataFile.exists() ); - - File expectedMetadataFile = getTestFile( "src/test/expected-files/v3-snapshot-artifact-metadata.xml" ); - - compareFiles( expectedMetadataFile, artifactMetadataFile ); - - assertTrue( "Check snapshot snapshotMetadata created", snapshotMetadataFile.exists() ); - - expectedMetadataFile = getTestFile( "src/test/expected-files/v3-timestamped-snapshot-metadata.xml" ); - - compareFiles( expectedMetadataFile, snapshotMetadataFile ); - } - - public void testNoPomConvert() - throws IOException, RepositoryConversionException - { - // test that a POM is not created when there was none at the source - - Artifact artifact = createArtifact( "test", "noPomArtifact", "1.0.0" ); - repositoryConverter.convert( artifact, targetRepository, reporter ); - assertEquals( "check no errors", 0, reporter.getFailures() ); - assertEquals( "check no warnings", 1, reporter.getWarnings() ); - assertEquals( "check success", 1, reporter.getSuccesses() ); - assertEquals( "check warning message", getI18nString( "warning.missing.pom" ), getWarning().getReason() ); - - File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - assertTrue( "Check artifact created", artifactFile.exists() ); - assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); - - artifact = createPomArtifact( artifact ); - File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); - - assertFalse( "Check no POM created", pomFile.exists() ); - assertFalse( "No source POM", sourcePomFile.exists() ); - } - - public void testIncorrectSourceChecksumMd5() - throws RepositoryConversionException - { - // test that it fails when the source md5 is wrong - - Artifact artifact = createArtifact( "test", "incorrectMd5Artifact", "1.0.0" ); - File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - file.delete(); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkFailure(); - assertEquals( "check failure message", getI18nString( "failure.incorrect.md5" ), getFailure().getReason() ); - - assertFalse( "Check artifact not created", file.exists() ); - - ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); - File metadataFile = - new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); - assertFalse( "Check metadata not created", metadataFile.exists() ); - } - - public void testIncorrectSourceChecksumSha1() - throws RepositoryConversionException - { - // test that it fails when the source sha1 is wrong - - Artifact artifact = createArtifact( "test", "incorrectSha1Artifact", "1.0.0" ); - File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - file.delete(); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkFailure(); - assertEquals( "check failure message", getI18nString( "failure.incorrect.sha1" ), getFailure().getReason() ); - - assertFalse( "Check artifact not created", file.exists() ); - - ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); - File metadataFile = - new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); - assertFalse( "Check metadata not created", metadataFile.exists() ); - } - - public void testUnmodifiedArtifact() - throws RepositoryConversionException, IOException, InterruptedException - { - // test the unmodified artifact is untouched - - Artifact artifact = createArtifact( "test", "unmodified-artifact", "1.0.0" ); - Artifact pomArtifact = createPomArtifact( artifact ); - - File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); - File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) ); - File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); - - assertTrue( "Check target file exists", targetFile.exists() ); - assertTrue( "Check target POM exists", targetPomFile.exists() ); - - sourceFile.setLastModified( System.currentTimeMillis() ); - sourcePomFile.setLastModified( System.currentTimeMillis() ); - - long origTime = targetFile.lastModified(); - long origPomTime = targetPomFile.lastModified(); - - // Need to guarantee last modified is not equal - Thread.sleep( SLEEP_MILLIS ); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkSuccess(); - - compareFiles( sourceFile, targetFile ); - compareFiles( sourcePomFile, targetPomFile ); - - assertEquals( "Check unmodified", origTime, targetFile.lastModified() ); - assertEquals( "Check unmodified", origPomTime, targetPomFile.lastModified() ); - } - - public void testModifedArtifactFails() - throws InterruptedException, RepositoryConversionException, IOException - { - // test that it fails when the source artifact has changed and is different to the existing artifact in the - // target repository - - Artifact artifact = createArtifact( "test", "modified-artifact", "1.0.0" ); - Artifact pomArtifact = createPomArtifact( artifact ); - - File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); - File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) ); - File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); - - assertTrue( "Check target file exists", targetFile.exists() ); - assertTrue( "Check target POM exists", targetPomFile.exists() ); - - sourceFile.setLastModified( System.currentTimeMillis() ); - sourcePomFile.setLastModified( System.currentTimeMillis() ); - - long origTime = targetFile.lastModified(); - long origPomTime = targetPomFile.lastModified(); - - // Need to guarantee last modified is not equal - Thread.sleep( SLEEP_MILLIS ); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkFailure(); - assertEquals( "Check failure message", getI18nString( "failure.target.already.exists" ), - getFailure().getReason() ); - - assertEquals( "Check unmodified", origTime, targetFile.lastModified() ); - assertEquals( "Check unmodified", origPomTime, targetPomFile.lastModified() ); - - ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); - File metadataFile = - new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); - assertFalse( "Check metadata not created", metadataFile.exists() ); - } - - public void testForcedUnmodifiedArtifact() - throws Exception, IOException - { - // test unmodified artifact is still converted when set to force - - repositoryConverter = (RepositoryConverter) lookup( RepositoryConverter.ROLE, "force-repository-converter" ); - - Artifact artifact = createArtifact( "test", "unmodified-artifact", "1.0.0" ); - Artifact pomArtifact = createPomArtifact( artifact ); - - File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); - File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) ); - File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); - - SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd", Locale.getDefault() ); - long origTime = dateFormat.parse( "2006-03-03" ).getTime(); - targetFile.setLastModified( origTime ); - targetPomFile.setLastModified( origTime ); - - sourceFile.setLastModified( dateFormat.parse( "2006-01-01" ).getTime() ); - sourcePomFile.setLastModified( dateFormat.parse( "2006-02-02" ).getTime() ); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkSuccess(); - - compareFiles( sourceFile, targetFile ); - compareFiles( sourcePomFile, targetPomFile ); - - assertFalse( "Check modified", origTime == targetFile.lastModified() ); - assertFalse( "Check modified", origTime == targetPomFile.lastModified() ); - - ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); - File metadataFile = - new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); - assertTrue( "Check metadata created", metadataFile.exists() ); - } - - public void testDryRunSuccess() - throws Exception - { - // test dry run does nothing on a run that will be successful, and returns success - - repositoryConverter = (RepositoryConverter) lookup( RepositoryConverter.ROLE, "dryrun-repository-converter" ); - - Artifact artifact = createArtifact( "test", "dryrun-artifact", "1.0.0" ); - Artifact pomArtifact = createPomArtifact( artifact ); - - File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); - File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) ); - File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkSuccess(); - - assertTrue( "Check source file exists", sourceFile.exists() ); - assertTrue( "Check source POM exists", sourcePomFile.exists() ); - - assertFalse( "Check target file doesn't exist", targetFile.exists() ); - assertFalse( "Check target POM doesn't exist", targetPomFile.exists() ); - - ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); - File metadataFile = - new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); - assertFalse( "Check metadata not created", metadataFile.exists() ); - } - - public void testDryRunFailure() - throws Exception - { - // test dry run does nothing on a run that will fail, and returns failure - - repositoryConverter = (RepositoryConverter) lookup( RepositoryConverter.ROLE, "dryrun-repository-converter" ); - - Artifact artifact = createArtifact( "test", "modified-artifact", "1.0.0" ); - Artifact pomArtifact = createPomArtifact( artifact ); - - File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); - File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) ); - File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); - - assertTrue( "Check target file exists", targetFile.exists() ); - assertTrue( "Check target POM exists", targetPomFile.exists() ); - - sourceFile.setLastModified( System.currentTimeMillis() ); - sourcePomFile.setLastModified( System.currentTimeMillis() ); - - long origTime = targetFile.lastModified(); - long origPomTime = targetPomFile.lastModified(); - - // Need to guarantee last modified is not equal - Thread.sleep( SLEEP_MILLIS ); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkFailure(); - assertEquals( "Check failure message", getI18nString( "failure.target.already.exists" ), - getFailure().getReason() ); - - assertEquals( "Check unmodified", origTime, targetFile.lastModified() ); - assertEquals( "Check unmodified", origPomTime, targetPomFile.lastModified() ); - - ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); - File metadataFile = - new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); - assertFalse( "Check metadata not created", metadataFile.exists() ); - } - - public void testRollbackArtifactCreated() - throws RepositoryConversionException, IOException - { - // test rollback can remove a created artifact, including checksums - - Artifact artifact = createArtifact( "test", "rollback-created-artifact", "1.0.0" ); - ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); - File artifactMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); - FileUtils.deleteDirectory( artifactMetadataFile.getParentFile() ); - - ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); - File versionMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); - - File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkFailure(); - String pattern = "^" + getI18nString( "failure.invalid.source.pom" ).replaceFirst( "\\{0\\}", ".*" ) + "$"; - assertTrue( "Check failure message", getFailure().getReason().matches( pattern ) ); - - assertFalse( "check artifact rolled back", artifactFile.exists() ); - assertFalse( "check metadata rolled back", artifactMetadataFile.exists() ); - assertFalse( "check metadata rolled back", versionMetadataFile.exists() ); - } - - public void testMultipleArtifacts() - throws RepositoryConversionException, IOException - { - // test multiple artifacts are converted - - List artifacts = new ArrayList(); - artifacts.add( createArtifact( "test", "artifact-one", "1.0.0" ) ); - artifacts.add( createArtifact( "test", "artifact-two", "1.0.0" ) ); - artifacts.add( createArtifact( "test", "artifact-three", "1.0.0" ) ); - repositoryConverter.convert( artifacts, targetRepository, reporter ); - assertEquals( "check no errors", 0, reporter.getFailures() ); - assertEquals( "check no warnings", 0, reporter.getWarnings() ); - assertEquals( "check successes", 3, reporter.getSuccesses() ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact artifact = (Artifact) i.next(); - - File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - assertTrue( "Check artifact created", artifactFile.exists() ); - assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); - - artifact = createPomArtifact( artifact ); - File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - File expectedPomFile = - getTestFile( "src/test/expected-files/converted-" + artifact.getArtifactId() + ".pom" ); - assertTrue( "Check POM created", pomFile.exists() ); - - compareFiles( expectedPomFile, pomFile ); - } - } - - public void testInvalidSourceArtifactMetadata() - throws Exception - { - // test artifact is not converted when source metadata is invalid, and returns failure - - createModernSourceRepository(); - - Artifact artifact = createArtifact( "test", "incorrectArtifactMetadata", "1.0.0" ); - File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - file.delete(); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkFailure(); - assertEquals( "check failure message", getI18nString( "failure.incorrect.artifactMetadata.versions" ), - getFailure().getReason() ); - - assertFalse( "Check artifact not created", file.exists() ); - - ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); - File metadataFile = - new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); - assertFalse( "Check metadata not created", metadataFile.exists() ); - } - - public void testInvalidSourceSnapshotMetadata() - throws Exception, MalformedURLException - { - // test artifact is not converted when source snapshot metadata is invalid and returns failure - - createModernSourceRepository(); - - Artifact artifact = createArtifact( "test", "incorrectSnapshotMetadata", "1.0.0-20060102.030405-6" ); - File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - file.delete(); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkFailure(); - assertEquals( "check failure message", getI18nString( "failure.incorrect.snapshotMetadata.snapshot" ), - getFailure().getReason() ); - - assertFalse( "Check artifact not created", file.exists() ); - - ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); - File metadataFile = - new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) ); - assertFalse( "Check metadata not created", metadataFile.exists() ); - } - - public void testMergeArtifactMetadata() - throws RepositoryConversionException, IOException - { - // test artifact level metadata is merged when it already exists on successful conversion - - Artifact artifact = createArtifact( "test", "newversion-artifact", "1.0.1" ); - - repositoryConverter.convert( artifact, targetRepository, reporter ); - checkSuccess(); - - File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - assertTrue( "Check artifact created", artifactFile.exists() ); - assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); - - artifact = createPomArtifact( artifact ); - File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); - assertTrue( "Check POM created", pomFile.exists() ); - - compareFiles( sourcePomFile, pomFile ); - - ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); - File artifactMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); - assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() ); - - File expectedMetadataFile = getTestFile( "src/test/expected-files/newversion-artifact-metadata.xml" ); - - compareFiles( expectedMetadataFile, artifactMetadataFile ); - } - - public void testSourceAndTargetRepositoriesMatch() - throws Exception - { - // test that it fails if the same - - ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - - sourceRepository = factory.createArtifactRepository( "source", targetRepository.getUrl(), - targetRepository.getLayout(), null, null ); - - Artifact artifact = createArtifact( "test", "repository-artifact", "1.0" ); - - try - { - repositoryConverter.convert( artifact, targetRepository, reporter ); - fail( "Should have failed trying to convert within the same repository" ); - } - catch ( RepositoryConversionException e ) - { - // expected - assertEquals( "check message", getI18nString( "exception.repositories.match" ), e.getMessage() ); - assertNull( "Check no additional cause", e.getCause() ); - } - } - - private Artifact createArtifact( String groupId, String artifactId, String version ) - { - Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( version ); - String baseVersion; - if ( matcher.matches() ) - { - baseVersion = matcher.group( 1 ) + "-SNAPSHOT"; - } - else - { - baseVersion = version; - } - return createArtifact( groupId, artifactId, baseVersion, version, "jar" ); - } - - private Artifact createArtifact( String groupId, String artifactId, String baseVersion, String version, - String type ) - { - Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, type ); - artifact.setBaseVersion( baseVersion ); - artifact.setRepository( sourceRepository ); - artifact.setFile( new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ) ); - return artifact; - } - - private Artifact createPomArtifact( Artifact artifact ) - { - return createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), - artifact.getVersion(), "pom" ); - } - - private static void compareFiles( File expectedPomFile, File pomFile ) - throws IOException - { - String expectedContent = normalizeString( FileUtils.fileRead( expectedPomFile ) ); - String targetContent = normalizeString( FileUtils.fileRead( pomFile ) ); - assertEquals( "Check file match between " + expectedPomFile + " and " + pomFile, expectedContent, - targetContent ); - } - - private static String normalizeString( String path ) - { - return path.trim().replaceAll( "\r\n", "\n" ).replace( '\r', '\n' ).replaceAll( "<\\?xml .+\\?>", "" ); - } - - private void checkSuccess() - { - assertEquals( "check no errors", 0, reporter.getFailures() ); - assertEquals( "check no warnings", 0, reporter.getWarnings() ); - assertEquals( "check success", 1, reporter.getSuccesses() ); - } - - private void checkFailure() - { - assertEquals( "check num errors", 1, reporter.getFailures() ); - assertEquals( "check no warnings", 0, reporter.getWarnings() ); - assertEquals( "check no success", 0, reporter.getSuccesses() ); - } - - private String getI18nString( String key ) - { - return i18n.getString( repositoryConverter.getClass().getName(), Locale.getDefault(), key ); - } - - private ArtifactResult getFailure() - { - return (ArtifactResult) reporter.getArtifactFailureIterator().next(); - } - - private ArtifactResult getWarning() - { - return (ArtifactResult) reporter.getArtifactWarningIterator().next(); - } - - private void createModernSourceRepository() - throws Exception - { - ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - - File sourceBase = getTestFile( "src/test/source-modern-repository" ); - sourceRepository = - factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null, null ); - } -} diff --git a/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/transaction/CopyFileEventTest.java b/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/transaction/CopyFileEventTest.java deleted file mode 100644 index 627c32cde..000000000 --- a/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/transaction/CopyFileEventTest.java +++ /dev/null @@ -1,138 +0,0 @@ -package org.apache.maven.repository.converter.transaction; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.PlexusTestCase; -import org.codehaus.plexus.util.FileUtils; - -import java.io.File; - -/** - * @author Edwin Punzalan - */ -public class CopyFileEventTest - extends PlexusTestCase -{ - private File testDir = new File( PlexusTestCase.getBasedir(), "target/transaction-tests/copy-file" ); - - private File testDest = new File( testDir, "test-file.txt" ); - - private File testSource = new File( PlexusTestCase.getBasedir(), "target/transaction-tests/test-file.txt" ); - - public void setUp() - throws Exception - { - super.setUp(); - - testSource.getParentFile().mkdirs(); - - testSource.createNewFile(); - - FileUtils.fileWrite( testSource.getAbsolutePath(), "source contents" ); - } - - public void testCopyCommitRollback() - throws Exception - { - assertTrue( "Test if the source exists", testSource.exists() ); - - String source = FileUtils.fileRead( testSource.getAbsolutePath() ); - - CopyFileEvent event = new CopyFileEvent( testSource, testDest ); - - assertFalse( "Test that the destination is not yet created", testDest.exists() ); - - event.commit(); - - assertTrue( "Test that the destination is created", testDest.exists() ); - - String target = FileUtils.fileRead( testDest.getAbsolutePath() ); - - assertTrue( "Test that the destination contents are copied correctly", source.equals( target ) ); - - event.rollback(); - - assertFalse( "Test that the destination file has been deleted", testDest.exists() ); - } - - public void testCopyCommitRollbackWithBackup() - throws Exception - { - assertTrue( "Test if the source exists", testSource.exists() ); - - String source = FileUtils.fileRead( testSource.getAbsolutePath() ); - - testDest.getParentFile().mkdirs(); - - testDest.createNewFile(); - - FileUtils.fileWrite( testDest.getAbsolutePath(), "overwritten contents" ); - - assertTrue( "Test that the destination exists", testDest.exists() ); - - CopyFileEvent event = new CopyFileEvent( testSource, testDest ); - - String target = FileUtils.fileRead( testDest.getAbsolutePath() ); - - assertTrue( "Test that the destination contents have not changed", target.equals( "overwritten contents" ) ); - - event.commit(); - - target = FileUtils.fileRead( testDest.getAbsolutePath() ); - - assertTrue( "Test that the destination contents are copied correctly", source.equals( target ) ); - - event.rollback(); - - target = FileUtils.fileRead( testDest.getAbsolutePath() ); - - assertTrue( "Test the destination file contents have been restored", target.equals( "overwritten contents" ) ); - } - - public void testCreateRollbackCommit() - throws Exception - { - assertTrue( "Test if the source exists", testSource.exists() ); - - String source = FileUtils.fileRead( testSource.getAbsolutePath() ); - - CopyFileEvent event = new CopyFileEvent( testSource, testDest ); - - assertFalse( "Test that the destination is not yet created", testDest.exists() ); - - event.rollback(); - - assertFalse( "Test that the destination file is not yet created", testDest.exists() ); - - event.commit(); - - assertTrue( "Test that the destination is created", testDest.exists() ); - - String target = FileUtils.fileRead( testDest.getAbsolutePath() ); - - assertTrue( "Test that the destination contents are copied correctly", source.equals( target ) ); - } - - protected void tearDown() - throws Exception - { - super.tearDown(); - - FileUtils.deleteDirectory( new File( PlexusTestCase.getBasedir(), - "target/transaction-tests" ).getAbsolutePath() ); - } -} diff --git a/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/transaction/CreateFileEventTest.java b/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/transaction/CreateFileEventTest.java deleted file mode 100644 index 2018e89a2..000000000 --- a/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/transaction/CreateFileEventTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.apache.maven.repository.converter.transaction; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.PlexusTestCase; -import org.codehaus.plexus.util.FileUtils; - -import java.io.File; - -/** - * @author Edwin Punzalan - */ -public class CreateFileEventTest - extends PlexusTestCase -{ - private File testDir = new File( PlexusTestCase.getBasedir(), "target/transaction-tests/create-file" ); - - public void testCreateCommitRollback() - throws Exception - { - File testFile = new File( testDir, "test-file.txt" ); - - CreateFileEvent event = new CreateFileEvent( "file contents", testFile ); - - assertFalse( "Test file is not yet created", testFile.exists() ); - - event.commit(); - - assertTrue( "Test file is not yet created", testFile.exists() ); - - event.rollback(); - - assertFalse( "Test file is has been deleted after rollback", testFile.exists() ); - assertFalse( "Test file parent directories has been rolledback too", testDir.exists() ); - assertTrue( "target directory still exists", new File( PlexusTestCase.getBasedir(), "target" ).exists() ); - } - - public void testCreateCommitRollbackWithBackup() - throws Exception - { - File testFile = new File( testDir, "test-file.txt" ); - - testFile.getParentFile().mkdirs(); - - testFile.createNewFile(); - - FileUtils.fileWrite( testFile.getAbsolutePath(), "original contents" ); - - CreateFileEvent event = new CreateFileEvent( "modified contents", testFile ); - - String contents = FileUtils.fileRead( testFile.getAbsolutePath() ); - - assertEquals( "Test contents have not changed", "original contents", contents ); - - event.commit(); - - contents = FileUtils.fileRead( testFile.getAbsolutePath() ); - - assertEquals( "Test contents have not changed", "modified contents", contents ); - - event.rollback(); - - contents = FileUtils.fileRead( testFile.getAbsolutePath() ); - - assertEquals( "Test contents have not changed", "original contents", contents ); - } - - public void testCreateRollbackCommit() - throws Exception - { - File testFile = new File( testDir, "test-file.txt" ); - - CreateFileEvent event = new CreateFileEvent( "file contents", testFile ); - - assertFalse( "Test file is not yet created", testFile.exists() ); - - event.rollback(); - - assertFalse( "Test file is not yet created", testFile.exists() ); - - event.commit(); - - assertTrue( "Test file is not yet created", testFile.exists() ); - } - - protected void tearDown() - throws Exception - { - super.tearDown(); - - FileUtils.deleteDirectory( new File( PlexusTestCase.getBasedir(), - "target/transaction-tests" ).getAbsolutePath() ); - } -} diff --git a/maven-repository-converter/src/test/resources/org/apache/maven/repository/converter/RepositoryConverterTest.xml b/maven-repository-converter/src/test/resources/org/apache/maven/repository/converter/RepositoryConverterTest.xml deleted file mode 100644 index f2caaffca..000000000 --- a/maven-repository-converter/src/test/resources/org/apache/maven/repository/converter/RepositoryConverterTest.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - org.apache.maven.repository.converter.RepositoryConverter - org.apache.maven.repository.converter.DefaultRepositoryConverter - force-repository-converter - - true - - - - org.apache.maven.repository.digest.Digester - sha1 - sha1Digester - - - org.apache.maven.repository.digest.Digester - md5 - md5Digester - - - org.apache.maven.artifact.factory.ArtifactFactory - artifactFactory - - - org.apache.maven.model.converter.ArtifactPomRewriter - rewriter - - - org.codehaus.plexus.i18n.I18N - i18n - - - - - org.apache.maven.repository.converter.RepositoryConverter - org.apache.maven.repository.converter.DefaultRepositoryConverter - dryrun-repository-converter - - true - - - - org.apache.maven.repository.digest.Digester - sha1 - sha1Digester - - - org.apache.maven.repository.digest.Digester - md5 - md5Digester - - - org.apache.maven.artifact.factory.ArtifactFactory - artifactFactory - - - org.apache.maven.model.converter.ArtifactPomRewriter - rewriter - - - org.codehaus.plexus.i18n.I18N - i18n - - - - - \ No newline at end of file diff --git a/maven-repository-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/1.0.0/incorrectArtifactMetadata-1.0.0.jar b/maven-repository-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/1.0.0/incorrectArtifactMetadata-1.0.0.jar deleted file mode 100644 index 72af4bc10..000000000 --- a/maven-repository-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/1.0.0/incorrectArtifactMetadata-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -incorrectMd5 diff --git a/maven-repository-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/1.0.0/incorrectArtifactMetadata-1.0.0.pom b/maven-repository-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/1.0.0/incorrectArtifactMetadata-1.0.0.pom deleted file mode 100644 index e9ec6a15c..000000000 --- a/maven-repository-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/1.0.0/incorrectArtifactMetadata-1.0.0.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 3 - incorrectArtifactMetadata - test - 1.0.0 - diff --git a/maven-repository-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/maven-metadata.xml b/maven-repository-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/maven-metadata.xml deleted file mode 100644 index 5ed142599..000000000 --- a/maven-repository-converter/src/test/source-modern-repository/test/incorrectArtifactMetadata/maven-metadata.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - test - incorrectArtifactMetadata - - - 0.9 - - - \ No newline at end of file diff --git a/maven-repository-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/incorrectSnapshotMetadata-1.0.0-20060102.030405-6.jar b/maven-repository-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/incorrectSnapshotMetadata-1.0.0-20060102.030405-6.jar deleted file mode 100644 index 72af4bc10..000000000 --- a/maven-repository-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/incorrectSnapshotMetadata-1.0.0-20060102.030405-6.jar +++ /dev/null @@ -1 +0,0 @@ -incorrectMd5 diff --git a/maven-repository-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/incorrectSnapshotMetadata-1.0.0-20060102.030405-6.pom b/maven-repository-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/incorrectSnapshotMetadata-1.0.0-20060102.030405-6.pom deleted file mode 100644 index 70118f64a..000000000 --- a/maven-repository-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/incorrectSnapshotMetadata-1.0.0-20060102.030405-6.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 3 - incorrectSnapshotMetadata - test - 1.0.0-20060102.030405-6 - diff --git a/maven-repository-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/maven-metadata.xml b/maven-repository-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/maven-metadata.xml deleted file mode 100644 index 031fb19b6..000000000 --- a/maven-repository-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/1.0.0-SNAPSHOT/maven-metadata.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - test - incorrectSnapshotMetadata - 1.0.0-SNAPSHOT - - - 10 - 20060102.040506 - - - \ No newline at end of file diff --git a/maven-repository-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/maven-metadata.xml b/maven-repository-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/maven-metadata.xml deleted file mode 100644 index db6ce9a7f..000000000 --- a/maven-repository-converter/src/test/source-modern-repository/test/incorrectSnapshotMetadata/maven-metadata.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - test - incorrectSnapshotMetadata - - - 1.0.0-SNAPSHOT - - - \ No newline at end of file diff --git a/maven-repository-converter/src/test/source-repository/test/jars/artifact-one-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/artifact-one-1.0.0.jar deleted file mode 100644 index 5626abf0f..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/artifact-one-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -one diff --git a/maven-repository-converter/src/test/source-repository/test/jars/artifact-three-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/artifact-three-1.0.0.jar deleted file mode 100644 index 2bdf67abb..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/artifact-three-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -three diff --git a/maven-repository-converter/src/test/source-repository/test/jars/artifact-two-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/artifact-two-1.0.0.jar deleted file mode 100644 index f719efd43..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/artifact-two-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -two diff --git a/maven-repository-converter/src/test/source-repository/test/jars/dryrun-artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/dryrun-artifact-1.0.0.jar deleted file mode 100644 index cbaf024e5..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/dryrun-artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -existing diff --git a/maven-repository-converter/src/test/source-repository/test/jars/existing-artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/existing-artifact-1.0.0.jar deleted file mode 100644 index cbaf024e5..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/existing-artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -existing diff --git a/maven-repository-converter/src/test/source-repository/test/jars/incorrectMd5Artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/incorrectMd5Artifact-1.0.0.jar deleted file mode 100644 index 72af4bc10..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/incorrectMd5Artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -incorrectMd5 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/incorrectMd5Artifact-1.0.0.jar.md5 b/maven-repository-converter/src/test/source-repository/test/jars/incorrectMd5Artifact-1.0.0.jar.md5 deleted file mode 100644 index 316d9a4eb..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/incorrectMd5Artifact-1.0.0.jar.md5 +++ /dev/null @@ -1 +0,0 @@ -379dcfcd1e6312cc859111f696047eb4 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/incorrectSha1Artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/incorrectSha1Artifact-1.0.0.jar deleted file mode 100644 index f5812f3e5..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/incorrectSha1Artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -incorrectSha1 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/incorrectSha1Artifact-1.0.0.jar.sha1 b/maven-repository-converter/src/test/source-repository/test/jars/incorrectSha1Artifact-1.0.0.jar.sha1 deleted file mode 100644 index cce322eb2..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/incorrectSha1Artifact-1.0.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -52e07b82d944741f66bba5896d4cd74e9879e289 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/modified-artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/modified-artifact-1.0.0.jar deleted file mode 100644 index 2e0996000..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/modified-artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -modified diff --git a/maven-repository-converter/src/test/source-repository/test/jars/newversion-artifact-1.0.1.jar b/maven-repository-converter/src/test/source-repository/test/jars/newversion-artifact-1.0.1.jar deleted file mode 100644 index c694117fd..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/newversion-artifact-1.0.1.jar +++ /dev/null @@ -1 +0,0 @@ -v4 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/noPomArtifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/noPomArtifact-1.0.0.jar deleted file mode 100644 index 3d27acdcc..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/noPomArtifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -noPom diff --git a/maven-repository-converter/src/test/source-repository/test/jars/relocated-v3artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/relocated-v3artifact-1.0.0.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/relocated-v3artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/rollback-created-artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/rollback-created-artifact-1.0.0.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/rollback-created-artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/unmodified-artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/unmodified-artifact-1.0.0.jar deleted file mode 100644 index 27597bc21..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/unmodified-artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -unmodified diff --git a/maven-repository-converter/src/test/source-repository/test/jars/v3-warnings-artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/v3-warnings-artifact-1.0.0.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/v3-warnings-artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/v3artifact-1.0.0-20060105.130101-3.jar b/maven-repository-converter/src/test/source-repository/test/jars/v3artifact-1.0.0-20060105.130101-3.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/v3artifact-1.0.0-20060105.130101-3.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/v3artifact-1.0.0-SNAPSHOT.jar b/maven-repository-converter/src/test/source-repository/test/jars/v3artifact-1.0.0-SNAPSHOT.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/v3artifact-1.0.0-SNAPSHOT.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/v3artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/v3artifact-1.0.0.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/v3artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0-20060111.120115-1.jar b/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0-20060111.120115-1.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0-20060111.120115-1.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0-SNAPSHOT.jar b/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0-SNAPSHOT.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0-SNAPSHOT.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar deleted file mode 100644 index c694117fd..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -v4 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar.md5 b/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar.md5 deleted file mode 100644 index 1930bc6d3..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar.md5 +++ /dev/null @@ -1 +0,0 @@ -4289bbdd6fba75013b317b2f9a540736 *v4artifact-1.0.0.jar diff --git a/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar.sha1 b/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar.sha1 deleted file mode 100644 index 466f209a7..000000000 --- a/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -e3e4159da65a4257f0bffb7cac8e3e78241a4dca *v4artifact-1.0.0.jar diff --git a/maven-repository-converter/src/test/source-repository/test/poms/artifact-one-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/artifact-one-1.0.0.pom deleted file mode 100644 index cd3862d35..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/artifact-one-1.0.0.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 4.0.0 - test - artifact-one - 1.0.0 - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/artifact-three-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/artifact-three-1.0.0.pom deleted file mode 100644 index 343291037..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/artifact-three-1.0.0.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 4.0.0 - test - artifact-three - 1.0.0 - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/artifact-two-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/artifact-two-1.0.0.pom deleted file mode 100644 index 227470167..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/artifact-two-1.0.0.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 4.0.0 - test - artifact-two - 1.0.0 - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/dryrun-artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/dryrun-artifact-1.0.0.pom deleted file mode 100644 index 1953c5523..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/dryrun-artifact-1.0.0.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 4.0.0 - dryrun-artifact - test - 1.0.0 - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/incorrectMd5Artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/incorrectMd5Artifact-1.0.0.pom deleted file mode 100644 index 74d5e12b4..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/incorrectMd5Artifact-1.0.0.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 3 - incorrectMd5Artifact - test - 1.0.0 - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/incorrectSha1Artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/incorrectSha1Artifact-1.0.0.pom deleted file mode 100644 index fe3c7fd91..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/incorrectSha1Artifact-1.0.0.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 3 - incorrectSha1Artifact - test - 1.0.0 - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/modified-artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/modified-artifact-1.0.0.pom deleted file mode 100644 index fcfdaacb4..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/modified-artifact-1.0.0.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 4.0.0 - modified-artifact - test - 1.0.0 - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/newversion-artifact-1.0.1.pom b/maven-repository-converter/src/test/source-repository/test/poms/newversion-artifact-1.0.1.pom deleted file mode 100644 index f441c9a46..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/newversion-artifact-1.0.1.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 4.0.0 - test - newversoin-artifact - 1.0.1 - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/relocated-v3artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/relocated-v3artifact-1.0.0.pom deleted file mode 100644 index 10823fe89..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/relocated-v3artifact-1.0.0.pom +++ /dev/null @@ -1,27 +0,0 @@ - - 3 - relocated-v3artifact - test - 1.0.0 - - - groupId - artifactId - version - - - groupId - test-artifactId - version - - test - - - - - scm:cvs:ext:${maven.username}@localhost:/home/cvs - - - relocated-test - - \ No newline at end of file diff --git a/maven-repository-converter/src/test/source-repository/test/poms/rollback-created-artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/rollback-created-artifact-1.0.0.pom deleted file mode 100644 index 00692be72..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/rollback-created-artifact-1.0.0.pom +++ /dev/null @@ -1,39 +0,0 @@ - - - - 3 - v3artifact - test - 1.0.0 - - - groupId - artifactId - version - - - groupId - test-artifactId - version - - test - - - - - - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/unmodified-artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/unmodified-artifact-1.0.0.pom deleted file mode 100644 index c570979f4..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/unmodified-artifact-1.0.0.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 4.0.0 - unmodified-artifact - test - 1.0.0 - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/v3-warnings-artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/v3-warnings-artifact-1.0.0.pom deleted file mode 100644 index 5f347f371..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/v3-warnings-artifact-1.0.0.pom +++ /dev/null @@ -1,48 +0,0 @@ - - - - 3 - ../project.xml - v3-warnings-artifact - test - 1.0.0 - - - 1.0 - 1.0 - 1_0 - - - - - groupId - artifactId - version - - - groupId - test-artifactId - version - - test - - - - - scm:cvs:ext:${maven.username}@localhost:/home/cvs - - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/v3artifact-1.0.0-20060105.130101-3.pom b/maven-repository-converter/src/test/source-repository/test/poms/v3artifact-1.0.0-20060105.130101-3.pom deleted file mode 100644 index d7ae8953b..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/v3artifact-1.0.0-20060105.130101-3.pom +++ /dev/null @@ -1,40 +0,0 @@ - - - - 3 - v3artifact - test - 1.0.0-20060105.130101-3 - - - groupId - artifactId - version - - - groupId - test-artifactId - version - - test - - - - - scm:cvs:ext:${maven.username}@localhost:/home/cvs - - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/v3artifact-1.0.0-SNAPSHOT.pom b/maven-repository-converter/src/test/source-repository/test/poms/v3artifact-1.0.0-SNAPSHOT.pom deleted file mode 100644 index 3958a3358..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/v3artifact-1.0.0-SNAPSHOT.pom +++ /dev/null @@ -1,40 +0,0 @@ - - - - 3 - v3artifact - test - 1.0.0-SNAPSHOT - - - groupId - artifactId - version - - - groupId - test-artifactId - version - - test - - - - - scm:cvs:ext:${maven.username}@localhost:/home/cvs - - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/v3artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/v3artifact-1.0.0.pom deleted file mode 100644 index 5aed3437a..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/v3artifact-1.0.0.pom +++ /dev/null @@ -1,24 +0,0 @@ - - 3 - v3artifact - test - 1.0.0 - - - groupId - artifactId - version - - - groupId - test-artifactId - version - - test - - - - - scm:cvs:ext:${maven.username}@localhost:/home/cvs - - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/v4artifact-1.0.0-20060111.120115-1.pom b/maven-repository-converter/src/test/source-repository/test/poms/v4artifact-1.0.0-20060111.120115-1.pom deleted file mode 100644 index e4f36566a..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/v4artifact-1.0.0-20060111.120115-1.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 4.0.0 - test - v4artifact - 1.0.0-20060111.120115-1 - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/v4artifact-1.0.0-SNAPSHOT.pom b/maven-repository-converter/src/test/source-repository/test/poms/v4artifact-1.0.0-SNAPSHOT.pom deleted file mode 100644 index be5b8b7e2..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/v4artifact-1.0.0-SNAPSHOT.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 4.0.0 - test - v4artifact - 1.0.0-SNAPSHOT - diff --git a/maven-repository-converter/src/test/source-repository/test/poms/v4artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/v4artifact-1.0.0.pom deleted file mode 100644 index fa6e82b1e..000000000 --- a/maven-repository-converter/src/test/source-repository/test/poms/v4artifact-1.0.0.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 4.0.0 - test - v4artifact - 1.0.0 - diff --git a/maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.jar b/maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.jar deleted file mode 100644 index 27597bc21..000000000 --- a/maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -unmodified diff --git a/maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.pom b/maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.pom deleted file mode 100644 index fcfdaacb4..000000000 --- a/maven-repository-converter/src/test/target-repository/test/modified-artifact/1.0.0/modified-artifact-1.0.0.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 4.0.0 - modified-artifact - test - 1.0.0 - diff --git a/maven-repository-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.jar b/maven-repository-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.jar deleted file mode 100644 index 27597bc21..000000000 --- a/maven-repository-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -unmodified diff --git a/maven-repository-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.pom b/maven-repository-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.pom deleted file mode 100644 index 836cc236b..000000000 --- a/maven-repository-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 4.0.0 - newversion-artifact - test - 1.0.0 - diff --git a/maven-repository-converter/src/test/target-repository/test/newversion-artifact/maven-metadata.xml b/maven-repository-converter/src/test/target-repository/test/newversion-artifact/maven-metadata.xml deleted file mode 100644 index f4d211741..000000000 --- a/maven-repository-converter/src/test/target-repository/test/newversion-artifact/maven-metadata.xml +++ /dev/null @@ -1,9 +0,0 @@ - - test - newversion-artifact - - - 1.0.0 - - - \ No newline at end of file diff --git a/maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.jar b/maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.jar deleted file mode 100644 index 27597bc21..000000000 --- a/maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -unmodified diff --git a/maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.pom b/maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.pom deleted file mode 100644 index c570979f4..000000000 --- a/maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 4.0.0 - unmodified-artifact - test - 1.0.0 - diff --git a/maven-repository-core/pom.xml b/maven-repository-core/pom.xml deleted file mode 100644 index 19c9874f5..000000000 --- a/maven-repository-core/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - maven-repository-manager - org.apache.maven.repository - 1.0-SNAPSHOT - - 4.0.0 - maven-repository-core - Maven Repository Manager Core - - - org.apache.maven.repository - maven-repository-configuration - - - org.apache.maven.repository - maven-repository-converter - - - org.apache.maven.repository - maven-repository-discovery - - - org.apache.maven.repository - maven-repository-proxy - - - org.apache.maven.repository - maven-repository-reports-standard - - - org.codehaus.plexus - plexus-quartz - 1.0-alpha-2 - - - - - - org.codehaus.mojo - cobertura-maven-plugin - - - - - **/** - - - - - - - diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/DefaultRepositoryManager.java b/maven-repository-core/src/main/java/org/apache/maven/repository/DefaultRepositoryManager.java deleted file mode 100644 index e753c0d3f..000000000 --- a/maven-repository-core/src/main/java/org/apache/maven/repository/DefaultRepositoryManager.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.apache.maven.repository; - -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.repository.converter.RepositoryConversionException; -import org.apache.maven.repository.converter.RepositoryConverter; -import org.apache.maven.repository.discovery.ArtifactDiscoverer; -import org.apache.maven.repository.discovery.DiscovererException; -import org.apache.maven.repository.reporting.ArtifactReporter; - -import java.io.File; -import java.net.MalformedURLException; -import java.util.List; - -/** - * @author Jason van Zyl - * @plexus.component - */ -public class DefaultRepositoryManager - implements RepositoryManager -{ - /** - * @plexus.requirement role-hint="legacy" - */ - private ArtifactDiscoverer artifactDiscoverer; - - /** - * @plexus.requirement role-hint="legacy" - */ - private ArtifactRepositoryLayout legacyLayout; - - /** - * @plexus.requirement role-hint="default" - */ - private ArtifactRepositoryLayout defaultLayout; - - /** - * @plexus.requirement - */ - private ArtifactRepositoryFactory artifactRepositoryFactory; - - /** - * @plexus.requirement - */ - private RepositoryConverter repositoryConverter; - - /** - * @plexus.requirement role-hint="default" - */ - private ArtifactReporter reporter; - - public void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory, - boolean includeSnapshots ) - throws RepositoryConversionException, DiscovererException - { - ArtifactRepository legacyRepository; - - ArtifactRepository repository; - - try - { - legacyRepository = artifactRepositoryFactory.createArtifactRepository( "legacy", - legacyRepositoryDirectory.toURI().toURL().toString(), - legacyLayout, null, null ); - - repository = artifactRepositoryFactory.createArtifactRepository( "default", - repositoryDirectory.toURI().toURL().toString(), - defaultLayout, null, null ); - } - catch ( MalformedURLException e ) - { - throw new RepositoryConversionException( "Error convering legacy repository.", e ); - } - - List legacyArtifacts = - artifactDiscoverer.discoverArtifacts( legacyRepository, "converter", null, includeSnapshots ); - - repositoryConverter.convert( legacyArtifacts, repository, reporter ); - } -} diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/RepositoryManager.java b/maven-repository-core/src/main/java/org/apache/maven/repository/RepositoryManager.java deleted file mode 100644 index 40d176e83..000000000 --- a/maven-repository-core/src/main/java/org/apache/maven/repository/RepositoryManager.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apache.maven.repository; - -import org.apache.maven.repository.converter.RepositoryConversionException; -import org.apache.maven.repository.discovery.DiscovererException; - -import java.io.File; - -/** - * @author Jason van Zyl - */ -public interface RepositoryManager -{ - /** - * Role of the Repository Manager - */ - String ROLE = RepositoryManager.class.getName(); - - /** - * Convert a legacy repository to a modern repository. This means a Maven 1.x repository - * using v3 POMs to a Maven 2.x repository using v4.0.0 POMs. - * - * @param legacyRepositoryDirectory - * @param repositoryDirectory - * @throws RepositoryConversionException - */ - void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory, boolean includeSnapshots ) - throws RepositoryConversionException, DiscovererException; -} diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/ConfiguredRepositoryFactory.java b/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/ConfiguredRepositoryFactory.java deleted file mode 100644 index 568e436da..000000000 --- a/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/ConfiguredRepositoryFactory.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.apache.maven.repository.configuration; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.repository.ArtifactRepository; -import org.apache.maven.repository.proxy.ProxiedArtifactRepository; - -import java.util.List; - -/** - * Create an artifact repository from the given configuration. - * - * @author Brett Porter - */ -public interface ConfiguredRepositoryFactory -{ - String ROLE = ConfiguredRepositoryFactory.class.getName(); - - /** - * Create an artifact repository from the given configuration. - * - * @param configuration the configuration - * @return the artifact repository - */ - ArtifactRepository createRepository( RepositoryConfiguration configuration ); - - /** - * Create artifact repositories from the given configuration. - * - * @param configuration the configuration containing the repositories - * @return the artifact repositories - */ - List createRepositories( Configuration configuration ); - - /** - * Create a local repository from the given configuration. - * - * @param configuration the configuration - * @return the local artifact repository - */ - ArtifactRepository createLocalRepository( Configuration configuration ); - - /** - * Create an artifact repository from the given proxy repository configuration. - * - * @param configuration the configuration - * @return the artifact repository - */ - ProxiedArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration ); - - /** - * Create artifact repositories from the given proxy repository configurations. - * - * @param configuration the configuration containing the repositories - * @return the artifact repositories - */ - List createProxiedRepositories( Configuration configuration ); -} diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/DefaultConfiguredRepositoryFactory.java b/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/DefaultConfiguredRepositoryFactory.java deleted file mode 100644 index 290a52301..000000000 --- a/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/DefaultConfiguredRepositoryFactory.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.apache.maven.repository.configuration; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.repository.proxy.ProxiedArtifactRepository; - -import java.io.File; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** - * Create artifact repositories from a configuration. - * - * @author Brett Porter - * @plexus.component role="org.apache.maven.repository.configuration.ConfiguredRepositoryFactory" - */ -public class DefaultConfiguredRepositoryFactory - implements ConfiguredRepositoryFactory -{ - /** - * @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" - */ - private Map repositoryLayouts; - - /** - * @plexus.requirement - */ - private ArtifactRepositoryFactory repoFactory; - - public ArtifactRepository createRepository( RepositoryConfiguration configuration ) - { - File repositoryDirectory = new File( configuration.getDirectory() ); - String repoDir = repositoryDirectory.toURI().toString(); - - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getLayout() ); - return repoFactory.createArtifactRepository( configuration.getId(), repoDir, layout, null, null ); - } - - public ProxiedArtifactRepository createProxiedRepository( ProxiedRepositoryConfiguration configuration ) - { - boolean enabled = isEnabled( configuration.getSnapshotsPolicy() ); - String updatePolicy = - getUpdatePolicy( configuration.getSnapshotsPolicy(), configuration.getSnapshotsInterval() ); - ArtifactRepositoryPolicy snapshotsPolicy = - new ArtifactRepositoryPolicy( enabled, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL ); - - enabled = isEnabled( configuration.getReleasesPolicy() ); - updatePolicy = getUpdatePolicy( configuration.getReleasesPolicy(), configuration.getReleasesInterval() ); - ArtifactRepositoryPolicy releasesPolicy = - new ArtifactRepositoryPolicy( enabled, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL ); - - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getLayout() ); - ArtifactRepository artifactRepository = repoFactory.createArtifactRepository( configuration.getId(), - configuration.getUrl(), layout, - snapshotsPolicy, releasesPolicy ); - ProxiedArtifactRepository repository = new ProxiedArtifactRepository( artifactRepository ); - repository.setCacheFailures( configuration.isCacheFailures() ); - repository.setHardFail( configuration.isHardFail() ); - repository.setName( configuration.getName() ); - repository.setUseNetworkProxy( configuration.isUseNetworkProxy() ); - return repository; - } - - public List createRepositories( Configuration configuration ) - { - List managedRepositories = configuration.getRepositories(); - List repositories = new ArrayList( managedRepositories.size() ); - - for ( Iterator i = managedRepositories.iterator(); i.hasNext(); ) - { - repositories.add( createRepository( (RepositoryConfiguration) i.next() ) ); - } - - return repositories; - } - - public List createProxiedRepositories( Configuration configuration ) - { - List proxiedRepositories = configuration.getProxiedRepositories(); - List repositories = new ArrayList( proxiedRepositories.size() ); - - for ( Iterator i = proxiedRepositories.iterator(); i.hasNext(); ) - { - repositories.add( createProxiedRepository( (ProxiedRepositoryConfiguration) i.next() ) ); - } - - return repositories; - } - - public ArtifactRepository createLocalRepository( Configuration configuration ) - { - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get( "default" ); - File localRepository = new File( configuration.getLocalRepository() ); - localRepository.mkdirs(); - return repoFactory.createArtifactRepository( "local", localRepository.toURI().toString(), layout, null, null ); - } - - private static String getUpdatePolicy( String policy, int interval ) - { - return "interval".equals( policy ) ? policy + ":" + interval : policy; - } - - private static boolean isEnabled( String policy ) - { - return !"disabled".equals( policy ); - } -} diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java b/maven-repository-core/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java deleted file mode 100644 index 5389fe5c7..000000000 --- a/maven-repository-core/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java +++ /dev/null @@ -1,233 +0,0 @@ -package org.apache.maven.repository.proxy; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.repository.ArtifactRepository; -import org.apache.maven.repository.configuration.Configuration; -import org.apache.maven.repository.configuration.ConfigurationStore; -import org.apache.maven.repository.configuration.ConfigurationStoreException; -import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; -import org.apache.maven.repository.configuration.ProxiedRepositoryConfiguration; -import org.apache.maven.repository.configuration.Proxy; -import org.apache.maven.repository.configuration.RepositoryConfiguration; -import org.apache.maven.wagon.ResourceDoesNotExistException; -import org.apache.maven.wagon.proxy.ProxyInfo; -import org.codehaus.plexus.util.StringUtils; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** - * Default implementation of the proxy manager that bridges the repository configuration classes to the proxy API. This - * class is not thread safe (due to the request handler being a non-thread safe requirement). - * - * @author Brett Porter - * @todo we should be able to configure "views" that sit in front of this (ie, prefix = /legacy, appears as layout maven-1.x, path gets translated before being passed on) - * @plexus.component instantiation-strategy="per-lookup" - */ -public class DefaultProxyManager - implements ProxyManager -{ - /** - * @plexus.requirement - */ - private ConfigurationStore configurationStore; - - /** - * @plexus.requirement role="org.apache.maven.repository.proxy.ProxyRequestHandler" - * @todo seems to be a bug in qdox that the role above is required - */ - private ProxyRequestHandler requestHandler; - - /** - * @plexus.requirement - */ - private ConfiguredRepositoryFactory repositoryFactory; - - /** - * The proxy groups for each managed repository. - */ - private static Map/**/ proxyGroups; - - /** - * The default proxy group/managed repository. - */ - private static ProxiedRepositoryGroup defaultProxyGroup; - - public File get( String path ) - throws ProxyException, ResourceDoesNotExistException - { - assert path.startsWith( "/" ); - - Map groups = getProxyGroups(); - - ProxiedRepositoryGroup proxyGroup = parseRepositoryId( path, groups ); - - String repositoryPath = path; - if ( proxyGroup == null ) - { - if ( defaultProxyGroup != null ) - { - proxyGroup = defaultProxyGroup; - } - else - { - throw new ResourceDoesNotExistException( "No repositories exist under the path: " + path ); - } - } - else - { - repositoryPath = repositoryPath.substring( proxyGroup.getManagedRepository().getId().length() + 2 ); - } - - return requestHandler.get( repositoryPath, proxyGroup.getProxiedRepositories(), - proxyGroup.getManagedRepository(), proxyGroup.getWagonProxy() ); - } - - public File getAlways( String path ) - throws ProxyException, ResourceDoesNotExistException - { - assert path.startsWith( "/" ); - - Map groups = getProxyGroups(); - - ProxiedRepositoryGroup proxyGroup = parseRepositoryId( path, groups ); - - String repositoryPath = path; - if ( proxyGroup == null ) - { - if ( defaultProxyGroup != null ) - { - proxyGroup = defaultProxyGroup; - } - else - { - throw new ResourceDoesNotExistException( "No repositories exist under the path: " + path ); - } - } - else - { - repositoryPath = repositoryPath.substring( proxyGroup.getManagedRepository().getId().length() + 2 ); - } - - return requestHandler.getAlways( repositoryPath, proxyGroup.getProxiedRepositories(), - proxyGroup.getManagedRepository(), proxyGroup.getWagonProxy() ); - } - - private Configuration getConfiguration() - throws ProxyException - { - Configuration configuration; - try - { - configuration = configurationStore.getConfigurationFromStore(); - } - catch ( ConfigurationStoreException e ) - { - throw new ProxyException( "Error reading configuration, unable to proxy any requests: " + e.getMessage(), - e ); - } - return configuration; - } - - private Map getProxyGroups() - throws ProxyException - { - if ( proxyGroups == null ) - { - Map groups = new HashMap(); - - Configuration configuration = getConfiguration(); - - ProxyInfo wagonProxy = createWagonProxy( configuration.getProxy() ); - - for ( Iterator i = configuration.getRepositories().iterator(); i.hasNext(); ) - { - RepositoryConfiguration repository = (RepositoryConfiguration) i.next(); - ArtifactRepository managedRepository = repositoryFactory.createRepository( repository ); - List proxiedRepositories = getProxiedRepositoriesForManagedRepository( - configuration.getProxiedRepositories(), repository.getId() ); - - groups.put( repository.getId(), - new ProxiedRepositoryGroup( proxiedRepositories, managedRepository, wagonProxy ) ); - } - - // TODO: ability to configure default proxy separately - - if ( groups.size() == 1 ) - { - defaultProxyGroup = (ProxiedRepositoryGroup) groups.values().iterator().next(); - } - - proxyGroups = groups; - } - return proxyGroups; - } - - private List getProxiedRepositoriesForManagedRepository( List proxiedRepositories, String id ) - { - List repositories = new ArrayList(); - for ( Iterator i = proxiedRepositories.iterator(); i.hasNext(); ) - { - ProxiedRepositoryConfiguration config = (ProxiedRepositoryConfiguration) i.next(); - - if ( config.getManagedRepository().equals( id ) ) - { - repositories.add( repositoryFactory.createProxiedRepository( config ) ); - } - } - return repositories; - } - - private static ProxiedRepositoryGroup parseRepositoryId( String path, Map groups ) - throws ProxyException, ResourceDoesNotExistException - { - ProxiedRepositoryGroup group = null; - - for ( Iterator i = groups.entrySet().iterator(); i.hasNext() && group == null; ) - { - Map.Entry entry = (Map.Entry) i.next(); - - if ( path.startsWith( "/" + entry.getKey() + "/" ) ) - { - group = (ProxiedRepositoryGroup) entry.getValue(); - } - } - - return group; - } - - private static ProxyInfo createWagonProxy( Proxy proxy ) - { - ProxyInfo proxyInfo = null; - if ( proxy != null && !StringUtils.isEmpty( proxy.getHost() ) ) - { - proxyInfo = new ProxyInfo(); - proxyInfo.setHost( proxy.getHost() ); - proxyInfo.setPort( proxy.getPort() ); - proxyInfo.setUserName( proxy.getUsername() ); - proxyInfo.setPassword( proxy.getPassword() ); - proxyInfo.setNonProxyHosts( proxy.getNonProxyHosts() ); - proxyInfo.setType( proxy.getProtocol() ); - } - return proxyInfo; - } -} diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/proxy/ProxiedRepositoryGroup.java b/maven-repository-core/src/main/java/org/apache/maven/repository/proxy/ProxiedRepositoryGroup.java deleted file mode 100644 index 326646c6f..000000000 --- a/maven-repository-core/src/main/java/org/apache/maven/repository/proxy/ProxiedRepositoryGroup.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.apache.maven.repository.proxy; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.repository.ArtifactRepository; -import org.apache.maven.wagon.proxy.ProxyInfo; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * A set of information to store for a group of proxies. - * - * @author Brett Porter - */ -public class ProxiedRepositoryGroup -{ - - /** - * The locally managed repository that caches proxied artifacts. - */ - private ArtifactRepository managedRepository; - - /** - * The remote repositories that are being proxied. - */ - private List/**/ proxiedRepositories; - - /** - * A wagon proxy to communicate to the proxy repository over a proxy (eg, http proxy)... TerminologyOverflowException - */ - private final ProxyInfo wagonProxy; - - /** - * Constructor. - * - * @param proxiedRepositories the proxied repository - * @param managedRepository the locally managed repository - * @param wagonProxy the network proxy to use - */ - public ProxiedRepositoryGroup( List/**/ proxiedRepositories, - ArtifactRepository managedRepository, ProxyInfo wagonProxy ) - { - this.proxiedRepositories = proxiedRepositories; - - this.managedRepository = managedRepository; - - this.wagonProxy = wagonProxy; - } - - /** - * Constructor. - * - * @param proxiedRepositories the proxied repository - * @param managedRepository the locally managed repository - */ - public ProxiedRepositoryGroup( List/**/ proxiedRepositories, - ArtifactRepository managedRepository ) - { - this( proxiedRepositories, managedRepository, null ); - } - - public ArtifactRepository getManagedRepository() - { - return managedRepository; - } - - public List getProxiedRepositories() - { - return proxiedRepositories; - } - - public ProxyInfo getWagonProxy() - { - return wagonProxy; - } -} diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/proxy/ProxyManager.java b/maven-repository-core/src/main/java/org/apache/maven/repository/proxy/ProxyManager.java deleted file mode 100644 index 7973013a2..000000000 --- a/maven-repository-core/src/main/java/org/apache/maven/repository/proxy/ProxyManager.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.apache.maven.repository.proxy; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.wagon.ResourceDoesNotExistException; - -import java.io.File; - -/** - * Repository proxying component. This component will take requests for a given path within a managed repository - * and if it is not found or expired, will look in the specified proxy repositories. - * - * @author Brett Porter - */ -public interface ProxyManager -{ - /** The Plexus role for the component. */ - String ROLE = ProxyManager.class.getName(); - - /** - * Used to retrieve a cached path or retrieve one if the cache does not contain it yet. - * - * @param path the expected repository path - * @return File object referencing the requested path in the cache - * @throws ProxyException when an exception occurred during the retrieval of the requested path - * @throws org.apache.maven.wagon.ResourceDoesNotExistException when the requested object can't be found in any of the - * configured repositories - */ - File get( String path ) - throws ProxyException, ResourceDoesNotExistException; - - /** - * Used to force remote download of the requested path from any the configured repositories. This method will - * only bypass the cache for searching but the requested path will still be cached. - * - * @param path the expected repository path - * @return File object referencing the requested path in the cache - * @throws ProxyException when an exception occurred during the retrieval of the requested path - * @throws ResourceDoesNotExistException when the requested object can't be found in any of the - * configured repositories - */ - File getAlways( String path ) - throws ProxyException, ResourceDoesNotExistException; -} diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/DefaultRepositoryTaskScheduler.java b/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/DefaultRepositoryTaskScheduler.java deleted file mode 100644 index 4e145b890..000000000 --- a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/DefaultRepositoryTaskScheduler.java +++ /dev/null @@ -1,171 +0,0 @@ -package org.apache.maven.repository.scheduler; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.repository.configuration.Configuration; -import org.apache.maven.repository.configuration.ConfigurationChangeException; -import org.apache.maven.repository.configuration.ConfigurationChangeListener; -import org.apache.maven.repository.configuration.ConfigurationStore; -import org.apache.maven.repository.configuration.ConfigurationStoreException; -import org.apache.maven.repository.configuration.InvalidConfigurationException; -import org.codehaus.plexus.logging.AbstractLogEnabled; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartingException; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.StoppingException; -import org.codehaus.plexus.scheduler.AbstractJob; -import org.codehaus.plexus.scheduler.Scheduler; -import org.quartz.CronTrigger; -import org.quartz.JobDataMap; -import org.quartz.JobDetail; -import org.quartz.SchedulerException; - -import java.text.ParseException; - -/** - * Default implementation of a scheduling component for the application. - * - * @author Brett Porter - * @todo should we use plexus-taskqueue instead of or in addition to this? - * @plexus.component role="org.apache.maven.repository.scheduler.RepositoryTaskScheduler" - */ -public class DefaultRepositoryTaskScheduler - extends AbstractLogEnabled - implements RepositoryTaskScheduler, Startable, ConfigurationChangeListener -{ - /** - * @plexus.requirement - */ - private Scheduler scheduler; - - /** - * @plexus.requirement - */ - private ConfigurationStore configurationStore; - - private static final String DISCOVERER_GROUP = "DISCOVERER"; - - private static final String INDEXER_JOB = "indexerTask"; - - /** - * @plexus.requirement role-hint="indexer" - */ - private RepositoryTask indexerTask; - - public void start() - throws StartingException - { - Configuration configuration; - try - { - configuration = configurationStore.getConfigurationFromStore(); - configurationStore.addChangeListener( this ); - } - catch ( ConfigurationStoreException e ) - { - throw new StartingException( "Unable to read configuration from the store", e ); - } - - try - { - scheduleJobs( configuration ); - } - catch ( ParseException e ) - { - throw new StartingException( "Invalid configuration: " + configuration.getIndexerCronExpression(), e ); - } - catch ( SchedulerException e ) - { - throw new StartingException( "Unable to start scheduler: " + e.getMessage(), e ); - } - } - - private void scheduleJobs( Configuration configuration ) - throws ParseException, SchedulerException - { - if ( configuration.getIndexPath() != null ) - { - JobDetail jobDetail = new JobDetail( INDEXER_JOB, DISCOVERER_GROUP, RepositoryTaskJob.class ); - JobDataMap dataMap = new JobDataMap(); - dataMap.put( AbstractJob.LOGGER, getLogger() ); - dataMap.put( RepositoryTaskJob.TASK_KEY, indexerTask ); - jobDetail.setJobDataMap( dataMap ); - - getLogger().info( "Scheduling indexer: " + configuration.getIndexerCronExpression() ); - CronTrigger trigger = - new CronTrigger( INDEXER_JOB + "Trigger", DISCOVERER_GROUP, configuration.getIndexerCronExpression() ); - scheduler.scheduleJob( jobDetail, trigger ); - - // TODO: run as a job so it doesn't block startup/configuration saving - try - { - indexerTask.executeNowIfNeeded(); - } - catch ( TaskExecutionException e ) - { - getLogger().error( "Error executing task first time, continuing anyway: " + e.getMessage(), e ); - } - } - else - { - getLogger().info( "Not scheduling indexer - index path is not configured" ); - } - - // TODO: wire in the converter - } - - public void stop() - throws StoppingException - { - try - { - scheduler.unscheduleJob( INDEXER_JOB, DISCOVERER_GROUP ); - } - catch ( SchedulerException e ) - { - throw new StoppingException( "Unable to unschedule tasks", e ); - } - } - - public void notifyOfConfigurationChange( Configuration configuration ) - throws InvalidConfigurationException, ConfigurationChangeException - { - try - { - stop(); - - scheduleJobs( configuration ); - } - catch ( StoppingException e ) - { - throw new ConfigurationChangeException( "Unable to unschedule previous tasks", e ); - } - catch ( ParseException e ) - { - throw new InvalidConfigurationException( "indexerCronExpression", "Invalid cron expression", e ); - } - catch ( SchedulerException e ) - { - throw new ConfigurationChangeException( "Unable to schedule new tasks", e ); - } - } - - public void runIndexer() - throws TaskExecutionException - { - indexerTask.execute(); - } -} diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/IndexerTask.java b/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/IndexerTask.java deleted file mode 100644 index 38b43a0ac..000000000 --- a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/IndexerTask.java +++ /dev/null @@ -1,182 +0,0 @@ -package org.apache.maven.repository.scheduler; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.repository.configuration.Configuration; -import org.apache.maven.repository.configuration.ConfigurationStore; -import org.apache.maven.repository.configuration.ConfigurationStoreException; -import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; -import org.apache.maven.repository.configuration.RepositoryConfiguration; -import org.apache.maven.repository.discovery.ArtifactDiscoverer; -import org.apache.maven.repository.discovery.DiscovererException; -import org.apache.maven.repository.indexing.RepositoryArtifactIndex; -import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; -import org.apache.maven.repository.indexing.RepositoryIndexException; -import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory; -import org.codehaus.plexus.logging.AbstractLogEnabled; - -import java.io.File; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** - * Task for discovering changes in the repository. - * - * @author Brett Porter - * @plexus.component role="org.apache.maven.repository.scheduler.RepositoryTask" role-hint="indexer" - */ -public class IndexerTask - extends AbstractLogEnabled - implements RepositoryTask -{ - /** - * Configuration store. - * - * @plexus.requirement - */ - private ConfigurationStore configurationStore; - - /** - * @plexus.requirement - */ - private RepositoryArtifactIndexFactory indexFactory; - - /** - * @plexus.requirement - */ - private ConfiguredRepositoryFactory repoFactory; - - /** - * @plexus.requirement role="org.apache.maven.repository.discovery.ArtifactDiscoverer" - */ - private Map artifactDiscoverers; - - /** - * @plexus.requirement role-hint="standard" - */ - private RepositoryIndexRecordFactory recordFactory; - - public void execute() - throws TaskExecutionException - { - Configuration configuration; - try - { - configuration = configurationStore.getConfigurationFromStore(); - } - catch ( ConfigurationStoreException e ) - { - throw new TaskExecutionException( e.getMessage(), e ); - } - - File indexPath = new File( configuration.getIndexPath() ); - - execute( configuration, indexPath ); - } - - private void execute( Configuration configuration, File indexPath ) - throws TaskExecutionException - { - long time = System.currentTimeMillis(); - getLogger().info( "Starting repository discovery process" ); - - try - { - for ( Iterator i = configuration.getRepositories().iterator(); i.hasNext(); ) - { - RepositoryConfiguration repositoryConfiguration = (RepositoryConfiguration) i.next(); - - if ( repositoryConfiguration.isIndexed() ) - { - // TODO! include global ones - String blacklistedPatterns = repositoryConfiguration.getBlackListPatterns(); - boolean includeSnapshots = repositoryConfiguration.isIncludeSnapshots(); - - ArtifactRepository repository = repoFactory.createRepository( repositoryConfiguration ); - - String layoutProperty = repositoryConfiguration.getLayout(); - ArtifactDiscoverer discoverer = (ArtifactDiscoverer) artifactDiscoverers.get( layoutProperty ); - List artifacts = - discoverer.discoverArtifacts( repository, "indexer", blacklistedPatterns, includeSnapshots ); - if ( !artifacts.isEmpty() ) - { - getLogger().info( "Indexing " + artifacts.size() + " new artifacts" ); - indexArtifacts( artifacts, indexPath ); - } - } - } - } - catch ( RepositoryIndexException e ) - { - throw new TaskExecutionException( e.getMessage(), e ); - } - catch ( DiscovererException e ) - { - throw new TaskExecutionException( e.getMessage(), e ); - } - - time = System.currentTimeMillis() - time; - getLogger().info( "Finished repository indexing process in " + time + "ms" ); - } - - public void executeNowIfNeeded() - throws TaskExecutionException - { - Configuration configuration; - try - { - configuration = configurationStore.getConfigurationFromStore(); - } - catch ( ConfigurationStoreException e ) - { - throw new TaskExecutionException( e.getMessage(), e ); - } - - File indexPath = new File( configuration.getIndexPath() ); - - try - { - RepositoryArtifactIndex artifactIndex = indexFactory.createStandardIndex( indexPath ); - if ( !artifactIndex.exists() ) - { - execute( configuration, indexPath ); - } - } - catch ( RepositoryIndexException e ) - { - throw new TaskExecutionException( e.getMessage(), e ); - } - } - - private void indexArtifacts( List artifacts, File indexPath ) - throws RepositoryIndexException - { - List records = new ArrayList(); - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - records.add( recordFactory.createRecord( a ) ); - } - - RepositoryArtifactIndex artifactIndex = indexFactory.createStandardIndex( indexPath ); - artifactIndex.indexRecords( records ); - } -} diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTask.java b/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTask.java deleted file mode 100644 index 92b6f93cd..000000000 --- a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTask.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.apache.maven.repository.scheduler; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * A repository task. - * - * @author Brett Porter - */ -public interface RepositoryTask -{ - /** - * Execute the task. - */ - void execute() - throws TaskExecutionException; - - /** - * Execute the task now if needed because the target doesn't exist. - */ - void executeNowIfNeeded() - throws TaskExecutionException; -} diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskJob.java b/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskJob.java deleted file mode 100644 index 874f6bcf2..000000000 --- a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskJob.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.apache.maven.repository.scheduler; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.scheduler.AbstractJob; -import org.quartz.JobDataMap; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; - -/** - * This class is the discoverer job that is executed by the scheduler. - */ -public class RepositoryTaskJob - extends AbstractJob -{ - static final String TASK_KEY = "EXECUTION"; - - /** - * Execute the discoverer and the indexer. - * - * @param context - * @throws org.quartz.JobExecutionException - * - */ - public void execute( JobExecutionContext context ) - throws JobExecutionException - { - JobDataMap dataMap = context.getJobDetail().getJobDataMap(); - setJobDataMap( dataMap ); - - RepositoryTask executor = (RepositoryTask) dataMap.get( TASK_KEY ); - try - { - executor.execute(); - } - catch ( TaskExecutionException e ) - { - throw new JobExecutionException( e ); - } - } - -} diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskScheduler.java b/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskScheduler.java deleted file mode 100644 index 46db976b3..000000000 --- a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskScheduler.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.apache.maven.repository.scheduler; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * The component that takes care of scheduling in the application. - * - * @author Brett Porter - */ -public interface RepositoryTaskScheduler -{ - /** - * The Plexus component role. - */ - String ROLE = RepositoryTaskScheduler.class.getName(); - - void runIndexer() - throws TaskExecutionException; -} diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/TaskExecutionException.java b/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/TaskExecutionException.java deleted file mode 100644 index 7ab229021..000000000 --- a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/TaskExecutionException.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.apache.maven.repository.scheduler; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * Exception occurring during task execution. - * - * @author Brett Porter - */ -public class TaskExecutionException - extends Exception -{ - public TaskExecutionException( String message, Throwable t ) - { - super( message, t ); - } -} diff --git a/maven-repository-core/src/test/java/org/apache/maven/repository/RepositoryManagerTest.java b/maven-repository-core/src/test/java/org/apache/maven/repository/RepositoryManagerTest.java deleted file mode 100644 index 5fb084590..000000000 --- a/maven-repository-core/src/test/java/org/apache/maven/repository/RepositoryManagerTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apache.maven.repository; - -import org.codehaus.plexus.PlexusTestCase; - -import java.io.File; - -/** - * @author Jason van Zyl - */ -public class RepositoryManagerTest - extends PlexusTestCase -{ - public void testLegacyRepositoryConversion() - throws Exception - { - File legacyRepositoryDirectory = getTestFile( "src/test/maven-1.x-repository" ); - - File repositoryDirectory = getTestFile( "target/maven-2.x-repository" ); - - RepositoryManager rm = (RepositoryManager) lookup( RepositoryManager.ROLE ); - - rm.convertLegacyRepository( legacyRepositoryDirectory, repositoryDirectory, true ); - } -} diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/artifact-one-1.0.0.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/artifact-one-1.0.0.jar deleted file mode 100644 index 5626abf0f..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/artifact-one-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -one diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/artifact-three-1.0.0.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/artifact-three-1.0.0.jar deleted file mode 100644 index 2bdf67abb..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/artifact-three-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -three diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/artifact-two-1.0.0.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/artifact-two-1.0.0.jar deleted file mode 100644 index f719efd43..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/artifact-two-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -two diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/dryrun-artifact-1.0.0.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/dryrun-artifact-1.0.0.jar deleted file mode 100644 index cbaf024e5..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/dryrun-artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -existing diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/existing-artifact-1.0.0.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/existing-artifact-1.0.0.jar deleted file mode 100644 index cbaf024e5..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/existing-artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -existing diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/incorrectMd5Artifact-1.0.0.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/incorrectMd5Artifact-1.0.0.jar deleted file mode 100644 index 72af4bc10..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/incorrectMd5Artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -incorrectMd5 diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/incorrectMd5Artifact-1.0.0.jar.md5 b/maven-repository-core/src/test/maven-1.x-repository/test/jars/incorrectMd5Artifact-1.0.0.jar.md5 deleted file mode 100644 index 316d9a4eb..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/incorrectMd5Artifact-1.0.0.jar.md5 +++ /dev/null @@ -1 +0,0 @@ -379dcfcd1e6312cc859111f696047eb4 diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/incorrectSha1Artifact-1.0.0.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/incorrectSha1Artifact-1.0.0.jar deleted file mode 100644 index f5812f3e5..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/incorrectSha1Artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -incorrectSha1 diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/incorrectSha1Artifact-1.0.0.jar.sha1 b/maven-repository-core/src/test/maven-1.x-repository/test/jars/incorrectSha1Artifact-1.0.0.jar.sha1 deleted file mode 100644 index cce322eb2..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/incorrectSha1Artifact-1.0.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -52e07b82d944741f66bba5896d4cd74e9879e289 diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/modified-artifact-1.0.0.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/modified-artifact-1.0.0.jar deleted file mode 100644 index 2e0996000..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/modified-artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -modified diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/newversion-artifact-1.0.1.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/newversion-artifact-1.0.1.jar deleted file mode 100644 index c694117fd..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/newversion-artifact-1.0.1.jar +++ /dev/null @@ -1 +0,0 @@ -v4 diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/noPomArtifact-1.0.0.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/noPomArtifact-1.0.0.jar deleted file mode 100644 index 3d27acdcc..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/noPomArtifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -noPom diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/relocated-v3artifact-1.0.0.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/relocated-v3artifact-1.0.0.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/relocated-v3artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/rollback-created-artifact-1.0.0.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/rollback-created-artifact-1.0.0.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/rollback-created-artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/unmodified-artifact-1.0.0.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/unmodified-artifact-1.0.0.jar deleted file mode 100644 index 27597bc21..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/unmodified-artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -unmodified diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v3-warnings-artifact-1.0.0.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/v3-warnings-artifact-1.0.0.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v3-warnings-artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0-20060105.130101-3.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0-20060105.130101-3.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0-20060105.130101-3.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0-SNAPSHOT.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0-SNAPSHOT.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0-SNAPSHOT.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v3artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0-20060111.120115-1.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0-20060111.120115-1.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0-20060111.120115-1.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0-SNAPSHOT.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0-SNAPSHOT.jar deleted file mode 100644 index 29ef827e8..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0-SNAPSHOT.jar +++ /dev/null @@ -1 +0,0 @@ -v3 diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar b/maven-repository-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar deleted file mode 100644 index c694117fd..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar +++ /dev/null @@ -1 +0,0 @@ -v4 diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar.md5 b/maven-repository-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar.md5 deleted file mode 100644 index 1930bc6d3..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar.md5 +++ /dev/null @@ -1 +0,0 @@ -4289bbdd6fba75013b317b2f9a540736 *v4artifact-1.0.0.jar diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar.sha1 b/maven-repository-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar.sha1 deleted file mode 100644 index 466f209a7..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/jars/v4artifact-1.0.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -e3e4159da65a4257f0bffb7cac8e3e78241a4dca *v4artifact-1.0.0.jar diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/artifact-one-1.0.0.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/artifact-one-1.0.0.pom deleted file mode 100644 index cd3862d35..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/artifact-one-1.0.0.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 4.0.0 - test - artifact-one - 1.0.0 - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/artifact-three-1.0.0.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/artifact-three-1.0.0.pom deleted file mode 100644 index 343291037..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/artifact-three-1.0.0.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 4.0.0 - test - artifact-three - 1.0.0 - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/artifact-two-1.0.0.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/artifact-two-1.0.0.pom deleted file mode 100644 index 227470167..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/artifact-two-1.0.0.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 4.0.0 - test - artifact-two - 1.0.0 - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/dryrun-artifact-1.0.0.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/dryrun-artifact-1.0.0.pom deleted file mode 100644 index 1953c5523..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/dryrun-artifact-1.0.0.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 4.0.0 - dryrun-artifact - test - 1.0.0 - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/incorrectMd5Artifact-1.0.0.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/incorrectMd5Artifact-1.0.0.pom deleted file mode 100644 index 74d5e12b4..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/incorrectMd5Artifact-1.0.0.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 3 - incorrectMd5Artifact - test - 1.0.0 - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/incorrectSha1Artifact-1.0.0.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/incorrectSha1Artifact-1.0.0.pom deleted file mode 100644 index fe3c7fd91..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/incorrectSha1Artifact-1.0.0.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 3 - incorrectSha1Artifact - test - 1.0.0 - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/modified-artifact-1.0.0.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/modified-artifact-1.0.0.pom deleted file mode 100644 index fcfdaacb4..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/modified-artifact-1.0.0.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 4.0.0 - modified-artifact - test - 1.0.0 - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/newversion-artifact-1.0.1.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/newversion-artifact-1.0.1.pom deleted file mode 100644 index f441c9a46..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/newversion-artifact-1.0.1.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 4.0.0 - test - newversoin-artifact - 1.0.1 - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/relocated-v3artifact-1.0.0.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/relocated-v3artifact-1.0.0.pom deleted file mode 100644 index 10823fe89..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/relocated-v3artifact-1.0.0.pom +++ /dev/null @@ -1,27 +0,0 @@ - - 3 - relocated-v3artifact - test - 1.0.0 - - - groupId - artifactId - version - - - groupId - test-artifactId - version - - test - - - - - scm:cvs:ext:${maven.username}@localhost:/home/cvs - - - relocated-test - - \ No newline at end of file diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/rollback-created-artifact-1.0.0.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/rollback-created-artifact-1.0.0.pom deleted file mode 100644 index 00692be72..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/rollback-created-artifact-1.0.0.pom +++ /dev/null @@ -1,39 +0,0 @@ - - - - 3 - v3artifact - test - 1.0.0 - - - groupId - artifactId - version - - - groupId - test-artifactId - version - - test - - - - - - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/unmodified-artifact-1.0.0.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/unmodified-artifact-1.0.0.pom deleted file mode 100644 index c570979f4..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/unmodified-artifact-1.0.0.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 4.0.0 - unmodified-artifact - test - 1.0.0 - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/v3-warnings-artifact-1.0.0.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/v3-warnings-artifact-1.0.0.pom deleted file mode 100644 index 5f347f371..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/v3-warnings-artifact-1.0.0.pom +++ /dev/null @@ -1,48 +0,0 @@ - - - - 3 - ../project.xml - v3-warnings-artifact - test - 1.0.0 - - - 1.0 - 1.0 - 1_0 - - - - - groupId - artifactId - version - - - groupId - test-artifactId - version - - test - - - - - scm:cvs:ext:${maven.username}@localhost:/home/cvs - - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0-20060105.130101-3.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0-20060105.130101-3.pom deleted file mode 100644 index d7ae8953b..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0-20060105.130101-3.pom +++ /dev/null @@ -1,40 +0,0 @@ - - - - 3 - v3artifact - test - 1.0.0-20060105.130101-3 - - - groupId - artifactId - version - - - groupId - test-artifactId - version - - test - - - - - scm:cvs:ext:${maven.username}@localhost:/home/cvs - - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0-SNAPSHOT.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0-SNAPSHOT.pom deleted file mode 100644 index 3958a3358..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0-SNAPSHOT.pom +++ /dev/null @@ -1,40 +0,0 @@ - - - - 3 - v3artifact - test - 1.0.0-SNAPSHOT - - - groupId - artifactId - version - - - groupId - test-artifactId - version - - test - - - - - scm:cvs:ext:${maven.username}@localhost:/home/cvs - - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0.pom deleted file mode 100644 index 5aed3437a..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/v3artifact-1.0.0.pom +++ /dev/null @@ -1,24 +0,0 @@ - - 3 - v3artifact - test - 1.0.0 - - - groupId - artifactId - version - - - groupId - test-artifactId - version - - test - - - - - scm:cvs:ext:${maven.username}@localhost:/home/cvs - - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0-20060111.120115-1.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0-20060111.120115-1.pom deleted file mode 100644 index e4f36566a..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0-20060111.120115-1.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 4.0.0 - test - v4artifact - 1.0.0-20060111.120115-1 - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0-SNAPSHOT.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0-SNAPSHOT.pom deleted file mode 100644 index be5b8b7e2..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0-SNAPSHOT.pom +++ /dev/null @@ -1,22 +0,0 @@ - - - - 4.0.0 - test - v4artifact - 1.0.0-SNAPSHOT - diff --git a/maven-repository-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0.pom b/maven-repository-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0.pom deleted file mode 100644 index fa6e82b1e..000000000 --- a/maven-repository-core/src/test/maven-1.x-repository/test/poms/v4artifact-1.0.0.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 4.0.0 - test - v4artifact - 1.0.0 - diff --git a/maven-repository-discovery/pom.xml b/maven-repository-discovery/pom.xml deleted file mode 100755 index dfd1a8b7f..000000000 --- a/maven-repository-discovery/pom.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - org.apache.maven.repository - maven-repository-manager - 1.0-SNAPSHOT - - 4.0.0 - maven-repository-discovery - Maven Repository Artifact Discovery - - - org.apache.maven.repository - maven-repository-utils - - - org.codehaus.plexus - plexus-utils - - - org.codehaus.plexus - plexus-container-default - - - org.apache.maven - maven-artifact - - - org.apache.maven - maven-repository-metadata - - - org.apache.maven - maven-artifact-manager - - - org.apache.maven - maven-model - - - diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java deleted file mode 100644 index 3faa8bd47..000000000 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java +++ /dev/null @@ -1,149 +0,0 @@ -package org.apache.maven.repository.discovery; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.codehaus.plexus.util.xml.Xpp3Dom; - -import java.io.File; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; - -/** - * Base class for artifact discoverers. - * - * @author John Casey - * @author Brett Porter - */ -public abstract class AbstractArtifactDiscoverer - extends AbstractDiscoverer - implements ArtifactDiscoverer -{ - /** - * Standard patterns to exclude from discovery as they are not artifacts. - */ - private static final String[] STANDARD_DISCOVERY_EXCLUDES = {"bin/**", "reports/**", ".maven/**", "**/*.md5", - "**/*.MD5", "**/*.sha1", "**/*.SHA1", "**/*snapshot-version", "*/website/**", "*/licenses/**", "*/licences/**", - "**/.htaccess", "**/*.html", "**/*.asc", "**/*.txt", "**/*.xml", "**/README*", "**/CHANGELOG*", "**/KEYS*"}; - - private List scanForArtifactPaths( File repositoryBase, String blacklistedPatterns, long comparisonTimestamp ) - { - return scanForArtifactPaths( repositoryBase, blacklistedPatterns, null, STANDARD_DISCOVERY_EXCLUDES, - comparisonTimestamp ); - } - - public List discoverArtifacts( ArtifactRepository repository, String operation, String blacklistedPatterns, - boolean includeSnapshots ) - throws DiscovererException - { - if ( !"file".equals( repository.getProtocol() ) ) - { - throw new UnsupportedOperationException( "Only filesystem repositories are supported" ); - } - - Xpp3Dom dom = getLastArtifactDiscoveryDom( readRepositoryMetadataDom( repository ) ); - long comparisonTimestamp = readComparisonTimestamp( repository, operation, dom ); - - // Note that last checked time is deliberately set to the start of the process so that anything added - // mid-discovery and missed by the scanner will get checked next time. - // Due to this, there must be no negative side-effects of discovering something twice. - Date newLastCheckedTime = new Date(); - - File repositoryBase = new File( repository.getBasedir() ); - - List artifacts = new ArrayList(); - - List artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns, comparisonTimestamp ); - - // Also note that the last check time, while set at the start, is saved at the end, so that if any exceptions - // occur, then the timestamp is not updated so that the discovery is attempted again - // TODO: under the list-return behaviour we have now, exceptions might occur later and the timestamp will not be reset - see MRM-83 - try - { - setLastCheckedTime( repository, operation, newLastCheckedTime ); - } - catch ( IOException e ) - { - throw new DiscovererException( "Error writing metadata: " + e.getMessage(), e ); - } - - for ( Iterator i = artifactPaths.iterator(); i.hasNext(); ) - { - String path = (String) i.next(); - - try - { - Artifact artifact = buildArtifactFromPath( path, repository ); - - if ( includeSnapshots || !artifact.isSnapshot() ) - { - artifacts.add( artifact ); - } - } - catch ( DiscovererException e ) - { - addKickedOutPath( path, e.getMessage() ); - } - } - - return artifacts; - } - - /** - * Returns an artifact object that is represented by the specified path in a repository - * - * @param path The path that is pointing to an artifact - * @param repository The repository of the artifact - * @return Artifact - * @throws DiscovererException when the specified path does correspond to an artifact - */ - public Artifact buildArtifactFromPath( String path, ArtifactRepository repository ) - throws DiscovererException - { - Artifact artifact = buildArtifact( path ); - - if ( artifact != null ) - { - artifact.setRepository( repository ); - artifact.setFile( new File( repository.getBasedir(), path ) ); - } - - return artifact; - } - - public void setLastCheckedTime( ArtifactRepository repository, String operation, Date date ) - throws IOException - { - // see notes in resetLastCheckedTime - - File file = new File( repository.getBasedir(), "maven-metadata.xml" ); - - Xpp3Dom dom = readDom( file ); - - String dateString = new SimpleDateFormat( DATE_FMT, Locale.US ).format( date ); - - setEntry( getLastArtifactDiscoveryDom( dom ), operation, dateString ); - - saveDom( file, dom ); - } -} diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java deleted file mode 100644 index 6888b23a9..000000000 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java +++ /dev/null @@ -1,304 +0,0 @@ -package org.apache.maven.repository.discovery; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.codehaus.plexus.logging.AbstractLogEnabled; -import org.codehaus.plexus.util.DirectoryScanner; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.codehaus.plexus.util.xml.Xpp3DomBuilder; -import org.codehaus.plexus.util.xml.Xpp3DomWriter; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; - -/** - * Base class for the artifact and metadata discoverers. - * - * @author Brett Porter - */ -public abstract class AbstractDiscoverer - extends AbstractLogEnabled - implements Discoverer -{ - private List kickedOutPaths = new ArrayList(); - - /** - * @plexus.requirement - */ - protected ArtifactFactory artifactFactory; - - private static final String[] EMPTY_STRING_ARRAY = new String[0]; - - private List excludedPaths = new ArrayList(); - - /** - * @plexus.configuration default-value="60000" - */ - private int blackoutPeriod; - - protected static final String DATE_FMT = "yyyyMMddHHmmss"; - - /** - * Add a path to the list of files that were kicked out due to being invalid. - * - * @param path the path to add - * @param reason the reason why the path is being kicked out - */ - protected void addKickedOutPath( String path, String reason ) - { - kickedOutPaths.add( new DiscovererPath( path, reason ) ); - } - - /** - * Returns an iterator for the list if DiscovererPaths that were found to not represent a searched object - * - * @return Iterator for the DiscovererPath List - */ - public Iterator getKickedOutPathsIterator() - { - return kickedOutPaths.iterator(); - } - - protected List scanForArtifactPaths( File repositoryBase, String blacklistedPatterns, String[] includes, - String[] excludes, long comparisonTimestamp ) - { - List allExcludes = new ArrayList(); - allExcludes.addAll( FileUtils.getDefaultExcludesAsList() ); - if ( excludes != null ) - { - allExcludes.addAll( Arrays.asList( excludes ) ); - } - - if ( !StringUtils.isEmpty( blacklistedPatterns ) ) - { - allExcludes.addAll( Arrays.asList( blacklistedPatterns.split( "," ) ) ); - } - - DirectoryScanner scanner = new DirectoryScanner(); - scanner.setBasedir( repositoryBase ); - if ( includes != null ) - { - scanner.setIncludes( includes ); - } - scanner.setExcludes( (String[]) allExcludes.toArray( EMPTY_STRING_ARRAY ) ); - - // TODO: Correct for extremely large repositories (artifact counts over 200,000 entries) - scanner.scan(); - - for ( Iterator files = Arrays.asList( scanner.getExcludedFiles() ).iterator(); files.hasNext(); ) - { - String path = files.next().toString(); - - excludedPaths.add( new DiscovererPath( path, "Artifact was in the specified list of exclusions" ) ); - } - - // TODO: this could be a part of the scanner - List includedPaths = new ArrayList(); - for ( Iterator files = Arrays.asList( scanner.getIncludedFiles() ).iterator(); files.hasNext(); ) - { - String path = files.next().toString(); - - long modTime = new File( repositoryBase, path ).lastModified(); - if ( modTime < System.currentTimeMillis() - blackoutPeriod ) - { - if ( modTime > comparisonTimestamp ) - { - includedPaths.add( path ); - } - } - } - - return includedPaths; - } - - /** - * Returns an iterator for the list if DiscovererPaths that were not processed because they are explicitly excluded - * - * @return Iterator for the DiscovererPath List - */ - public Iterator getExcludedPathsIterator() - { - return excludedPaths.iterator(); - } - - protected long readComparisonTimestamp( ArtifactRepository repository, String operation, Xpp3Dom dom ) - { - Xpp3Dom entry = dom.getChild( operation ); - long comparisonTimestamp = 0; - if ( entry != null ) - { - try - { - comparisonTimestamp = new SimpleDateFormat( DATE_FMT, Locale.US ).parse( entry.getValue() ).getTime(); - } - catch ( ParseException e ) - { - getLogger().error( "Timestamp was invalid: " + entry.getValue() + "; ignoring" ); - } - } - return comparisonTimestamp; - } - - protected Xpp3Dom readDom( File file ) - { - Xpp3Dom dom; - FileReader fileReader = null; - try - { - fileReader = new FileReader( file ); - dom = Xpp3DomBuilder.build( fileReader ); - } - catch ( FileNotFoundException e ) - { - // Safe to ignore - dom = new Xpp3Dom( "metadata" ); - } - catch ( XmlPullParserException e ) - { - getLogger().error( "Error reading metadata (ignoring and recreating): " + e.getMessage() ); - dom = new Xpp3Dom( "metadata" ); - } - catch ( IOException e ) - { - getLogger().error( "Error reading metadata (ignoring and recreating): " + e.getMessage() ); - dom = new Xpp3Dom( "metadata" ); - } - finally - { - IOUtil.close( fileReader ); - } - return dom; - } - - protected Xpp3Dom getLastArtifactDiscoveryDom( Xpp3Dom dom ) - { - Xpp3Dom lastDiscoveryDom = dom.getChild( "lastArtifactDiscovery" ); - if ( lastDiscoveryDom == null ) - { - dom.addChild( new Xpp3Dom( "lastArtifactDiscovery" ) ); - lastDiscoveryDom = dom.getChild( "lastArtifactDiscovery" ); - } - return lastDiscoveryDom; - } - - protected Xpp3Dom getLastMetadataDiscoveryDom( Xpp3Dom dom ) - { - Xpp3Dom lastDiscoveryDom = dom.getChild( "lastMetadataDiscovery" ); - if ( lastDiscoveryDom == null ) - { - dom.addChild( new Xpp3Dom( "lastMetadataDiscovery" ) ); - lastDiscoveryDom = dom.getChild( "lastMetadataDiscovery" ); - } - return lastDiscoveryDom; - } - - public void resetLastCheckedTime( ArtifactRepository repository, String operation ) - throws IOException - { - // TODO: get these changes into maven-metadata.xml and migrate towards that. The model is further diverging to a different layout at each level so submodels might be a good idea. - // TODO: maven-artifact probably needs an improved pathOfMetadata to cope with top level metadata - // TODO: might we need to write this as maven-metadata-local in some circumstances? merge others? Probably best to keep it simple and just use this format at the root. No need to merge anything that I can see - // TODO: since this metadata isn't meant to be shared, perhaps another file is called for after all. - // Format is: yyyyMMddHHmmss (ie, flat properties) - - File file = new File( repository.getBasedir(), "maven-metadata.xml" ); - - Xpp3Dom dom = readDom( file ); - - boolean changed = false; - - if ( removeEntry( getLastArtifactDiscoveryDom( dom ), operation ) ) - { - changed = true; - } - - if ( removeEntry( getLastMetadataDiscoveryDom( dom ), operation ) ) - { - changed = true; - } - - if ( changed ) - { - saveDom( file, dom ); - } - } - - private boolean removeEntry( Xpp3Dom lastDiscoveryDom, String operation ) - { - boolean changed = false; - - // do this in reverse so that removing doesn't affect counter - Xpp3Dom[] children = lastDiscoveryDom.getChildren(); - for ( int i = lastDiscoveryDom.getChildCount() - 1; i >= 0; i-- ) - { - if ( children[i].getName().equals( operation ) ) - { - changed = true; - lastDiscoveryDom.removeChild( i ); - } - } - return changed; - } - - protected void saveDom( File file, Xpp3Dom dom ) - throws IOException - { - FileWriter writer = new FileWriter( file ); - - // save metadata - try - { - Xpp3DomWriter.write( writer, dom ); - } - finally - { - IOUtil.close( writer ); - } - } - - protected void setEntry( Xpp3Dom lastDiscoveryDom, String operation, String dateString ) - { - Xpp3Dom entry = lastDiscoveryDom.getChild( operation ); - if ( entry == null ) - { - entry = new Xpp3Dom( operation ); - lastDiscoveryDom.addChild( entry ); - } - entry.setValue( dateString ); - } - - protected Xpp3Dom readRepositoryMetadataDom( ArtifactRepository repository ) - { - return readDom( new File( repository.getBasedir(), "maven-metadata.xml" ) ); - } -} diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java deleted file mode 100644 index ec9698cdf..000000000 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.apache.maven.repository.discovery; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; - -import java.util.List; - -/** - * Interface for implementation that can discover artifacts within a repository. - * - * @author John Casey - * @author Brett Porter - * @todo do we want blacklisted patterns in another form? Part of the object construction? - * @todo should includeSnapshots be configuration on the component? If not, should the methods be changed to include alternates for both possibilities (discoverReleaseArtifacts, discoverReleaseAndSnapshotArtifacts)? - * @todo instead of a returned list, should a listener be passed in? - */ -public interface ArtifactDiscoverer - extends Discoverer -{ - String ROLE = ArtifactDiscoverer.class.getName(); - - /** - * Discover artifacts in the repository. Only artifacts added since the last attempt at discovery will be found. - * This process guarantees never to miss an artifact, however it is possible that an artifact will be received twice - * consecutively even if unchanged, so any users of this list must handle such a situation gracefully. - * - * @param repository the location of the repository - * @param operation the operation being used to discover for timestamp checking - * @param blacklistedPatterns pattern that lists any files to prevent from being included when scanning - * @param includeSnapshots whether to discover snapshots - * @return the list of artifacts discovered - * @throws DiscovererException if there was an unrecoverable problem discovering artifacts or recording progress - */ - List discoverArtifacts( ArtifactRepository repository, String operation, String blacklistedPatterns, - boolean includeSnapshots ) - throws DiscovererException; - - /** - * Build an artifact from a path in the repository - * - * @param path the path - * @return the artifact - * @throws DiscovererException if the file is not a valid artifact - * @todo this should be in maven-artifact - */ - Artifact buildArtifact( String path ) - throws DiscovererException; -} diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java deleted file mode 100644 index f7dabe3fc..000000000 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java +++ /dev/null @@ -1,190 +0,0 @@ -package org.apache.maven.repository.discovery; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.codehaus.plexus.util.StringUtils; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.StringTokenizer; - -/** - * Artifact discoverer for the new repository layout (Maven 2.0+). - * - * @author John Casey - * @author Brett Porter - * @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="default" - */ -public class DefaultArtifactDiscoverer - extends AbstractArtifactDiscoverer -{ - /** - * @see org.apache.maven.repository.discovery.ArtifactDiscoverer#buildArtifact(String) - */ - public Artifact buildArtifact( String path ) - throws DiscovererException - { - List pathParts = new ArrayList(); - StringTokenizer st = new StringTokenizer( path, "/\\" ); - while ( st.hasMoreTokens() ) - { - pathParts.add( st.nextToken() ); - } - - Collections.reverse( pathParts ); - - Artifact artifact; - if ( pathParts.size() >= 4 ) - { - // maven 2.x path - - // the actual artifact filename. - String filename = (String) pathParts.remove( 0 ); - - // the next one is the version. - String version = (String) pathParts.remove( 0 ); - - // the next one is the artifactId. - String artifactId = (String) pathParts.remove( 0 ); - - // the remaining are the groupId. - Collections.reverse( pathParts ); - String groupId = StringUtils.join( pathParts.iterator(), "." ); - - String remainingFilename = filename; - if ( remainingFilename.startsWith( artifactId + "-" ) ) - { - remainingFilename = remainingFilename.substring( artifactId.length() + 1 ); - - String classifier = null; - - // TODO: use artifact handler, share with legacy discoverer - String type; - if ( remainingFilename.endsWith( ".tar.gz" ) ) - { - type = "distribution-tgz"; - remainingFilename = - remainingFilename.substring( 0, remainingFilename.length() - ".tar.gz".length() ); - } - else if ( remainingFilename.endsWith( ".zip" ) ) - { - type = "distribution-zip"; - remainingFilename = remainingFilename.substring( 0, remainingFilename.length() - ".zip".length() ); - } - else if ( remainingFilename.endsWith( "-sources.jar" ) ) - { - type = "java-source"; - classifier = "sources"; - remainingFilename = - remainingFilename.substring( 0, remainingFilename.length() - "-sources.jar".length() ); - } - else - { - int index = remainingFilename.lastIndexOf( "." ); - if ( index >= 0 ) - { - type = remainingFilename.substring( index + 1 ); - remainingFilename = remainingFilename.substring( 0, index ); - } - else - { - throw new DiscovererException( "Path filename does not have an extension" ); - } - } - - Artifact result; - if ( classifier == null ) - { - result = - artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, type ); - } - else - { - result = - artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier ); - } - - if ( result.isSnapshot() ) - { - // version is *-SNAPSHOT, filename is *-yyyyMMdd.hhmmss-b - int classifierIndex = remainingFilename.indexOf( '-', version.length() + 8 ); - if ( classifierIndex >= 0 ) - { - classifier = remainingFilename.substring( classifierIndex + 1 ); - remainingFilename = remainingFilename.substring( 0, classifierIndex ); - result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, remainingFilename, - type, classifier ); - } - else - { - result = artifactFactory.createArtifact( groupId, artifactId, remainingFilename, - Artifact.SCOPE_RUNTIME, type ); - } - - // poor encapsulation requires we do this to populate base version - if ( !result.isSnapshot() ) - { - throw new DiscovererException( "Failed to create a snapshot artifact: " + result ); - } - else if ( !result.getBaseVersion().equals( version ) ) - { - throw new DiscovererException( - "Built snapshot artifact base version does not match path version: " + result + - "; should have been version: " + version ); - } - else - { - artifact = result; - } - } - else if ( !remainingFilename.startsWith( version ) ) - { - throw new DiscovererException( "Built artifact version does not match path version" ); - } - else if ( !remainingFilename.equals( version ) ) - { - if ( remainingFilename.charAt( version.length() ) == '-' ) - { - classifier = remainingFilename.substring( version.length() + 1 ); - artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, - classifier ); - } - else - { - throw new DiscovererException( "Path version does not corresspond to an artifact version" ); - } - } - else - { - artifact = result; - } - } - else - { - throw new DiscovererException( "Path filename does not correspond to an artifact" ); - } - } - else - { - throw new DiscovererException( "Path is too short to build an artifact from" ); - } - - return artifact; - } -} diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java deleted file mode 100644 index 6aad837df..000000000 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java +++ /dev/null @@ -1,254 +0,0 @@ -package org.apache.maven.repository.discovery; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.Metadata; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.MalformedURLException; -import java.net.URL; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.StringTokenizer; - -/** - * This class gets all the paths that contain the metadata files. - * - * @plexus.component role="org.apache.maven.repository.discovery.MetadataDiscoverer" role-hint="default" - */ -public class DefaultMetadataDiscoverer - extends AbstractDiscoverer - implements MetadataDiscoverer -{ - /** - * Standard patterns to include in discovery of metadata files. - * - * @todo Note that only the remote format is supported at this time: you cannot search local repository metadata due - * to the way it is later loaded in the searchers. Review code using pathOfRemoteMetadata. IS there any value in - * searching the local metadata in the first place though? - */ - private static final String[] STANDARD_DISCOVERY_INCLUDES = {"**/maven-metadata.xml"}; - - public List discoverMetadata( ArtifactRepository repository, String operation, String blacklistedPatterns ) - throws DiscovererException - { - if ( !"file".equals( repository.getProtocol() ) ) - { - throw new UnsupportedOperationException( "Only filesystem repositories are supported" ); - } - - Xpp3Dom dom = getLastMetadataDiscoveryDom( readRepositoryMetadataDom( repository ) ); - long comparisonTimestamp = readComparisonTimestamp( repository, operation, dom ); - - // Note that last checked time is deliberately set to the start of the process so that anything added - // mid-discovery and missed by the scanner will get checked next time. - // Due to this, there must be no negative side-effects of discovering something twice. - Date newLastCheckedTime = new Date(); - - List metadataFiles = new ArrayList(); - List metadataPaths = scanForArtifactPaths( new File( repository.getBasedir() ), blacklistedPatterns, - STANDARD_DISCOVERY_INCLUDES, null, comparisonTimestamp ); - - // Also note that the last check time, while set at the start, is saved at the end, so that if any exceptions - // occur, then the timestamp is not updated so that the discovery is attempted again - // TODO: under the list-return behaviour we have now, exceptions might occur later and the timestamp will not be reset - see MRM-83 - try - { - setLastCheckedTime( repository, operation, newLastCheckedTime ); - } - catch ( IOException e ) - { - throw new DiscovererException( "Error writing metadata: " + e.getMessage(), e ); - } - - for ( Iterator i = metadataPaths.iterator(); i.hasNext(); ) - { - String metadataPath = (String) i.next(); - try - { - RepositoryMetadata metadata = buildMetadata( repository.getBasedir(), metadataPath ); - metadataFiles.add( metadata ); - } - catch ( DiscovererException e ) - { - addKickedOutPath( metadataPath, e.getMessage() ); - } - } - - return metadataFiles; - } - - private RepositoryMetadata buildMetadata( String repo, String metadataPath ) - throws DiscovererException - { - Metadata m; - String repoPath = repo + "/" + metadataPath; - try - { - URL url = new File( repoPath ).toURI().toURL(); - InputStream is = url.openStream(); - Reader reader = new InputStreamReader( is ); - MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); - - m = metadataReader.read( reader ); - } - catch ( XmlPullParserException e ) - { - throw new DiscovererException( "Error parsing metadata file '" + repoPath + "': " + e.getMessage(), e ); - } - catch ( MalformedURLException e ) - { - // shouldn't happen - throw new DiscovererException( "Error constructing metadata file '" + repoPath + "': " + e.getMessage(), - e ); - } - catch ( IOException e ) - { - throw new DiscovererException( "Error reading metadata file '" + repoPath + "': " + e.getMessage(), e ); - } - - RepositoryMetadata repositoryMetadata = buildMetadata( m, metadataPath ); - - if ( repositoryMetadata == null ) - { - throw new DiscovererException( "Unable to build a repository metadata from path" ); - } - - return repositoryMetadata; - } - - /** - * Builds a RepositoryMetadata object from a Metadata object and its path. - * - * @param m Metadata - * @param metadataPath path - * @return RepositoryMetadata if the parameters represent one; null if not - * @todo should we just be using the path information, and loading it later when it is needed? (for reporting, etc) - */ - private RepositoryMetadata buildMetadata( Metadata m, String metadataPath ) - { - String metaGroupId = m.getGroupId(); - String metaArtifactId = m.getArtifactId(); - String metaVersion = m.getVersion(); - - // check if the groupId, artifactId and version is in the - // metadataPath - // parse the path, in reverse order - List pathParts = new ArrayList(); - StringTokenizer st = new StringTokenizer( metadataPath, "/\\" ); - while ( st.hasMoreTokens() ) - { - pathParts.add( st.nextToken() ); - } - - Collections.reverse( pathParts ); - // remove the metadata file - pathParts.remove( 0 ); - Iterator it = pathParts.iterator(); - String tmpDir = (String) it.next(); - - Artifact artifact = null; - if ( !StringUtils.isEmpty( metaVersion ) ) - { - artifact = artifactFactory.createProjectArtifact( metaGroupId, metaArtifactId, metaVersion ); - } - - // snapshotMetadata - RepositoryMetadata metadata = null; - if ( tmpDir != null && tmpDir.equals( metaVersion ) ) - { - if ( artifact != null ) - { - metadata = new SnapshotArtifactRepositoryMetadata( artifact ); - } - } - else if ( tmpDir != null && tmpDir.equals( metaArtifactId ) ) - { - // artifactMetadata - if ( artifact != null ) - { - metadata = new ArtifactRepositoryMetadata( artifact ); - } - else - { - artifact = artifactFactory.createProjectArtifact( metaGroupId, metaArtifactId, "1.0" ); - metadata = new ArtifactRepositoryMetadata( artifact ); - } - } - else - { - String groupDir = ""; - int ctr = 0; - for ( it = pathParts.iterator(); it.hasNext(); ) - { - String path = (String) it.next(); - if ( ctr == 0 ) - { - groupDir = path; - } - else - { - groupDir = path + "." + groupDir; - } - ctr++; - } - - // groupMetadata - if ( metaGroupId != null && metaGroupId.equals( groupDir ) ) - { - metadata = new GroupRepositoryMetadata( metaGroupId ); - } - } - - return metadata; - } - - public void setLastCheckedTime( ArtifactRepository repository, String operation, Date date ) - throws IOException - { - // see notes in resetLastCheckedTime - - File file = new File( repository.getBasedir(), "maven-metadata.xml" ); - - Xpp3Dom dom = readDom( file ); - - String dateString = new SimpleDateFormat( DATE_FMT, Locale.US ).format( date ); - - setEntry( getLastMetadataDiscoveryDom( dom ), operation, dateString ); - - saveDom( file, dom ); - } -} diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/Discoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/Discoverer.java deleted file mode 100644 index b0896bcad..000000000 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/Discoverer.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.apache.maven.repository.discovery; - -import org.apache.maven.artifact.repository.ArtifactRepository; - -import java.io.IOException; -import java.util.Date; -import java.util.Iterator; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * @author Edwin Punzalan - */ -public interface Discoverer -{ - /** - * Get the list of paths kicked out during the discovery process. - * - * @return the paths as Strings. - */ - Iterator getKickedOutPathsIterator(); - - /** - * Get the list of paths excluded during the discovery process. - * - * @return the paths as Strings. - */ - Iterator getExcludedPathsIterator(); - - /** - * Reset the time in the repository that indicates the last time a check was performed. - * - * @param repository the location of the repository - * @param operation the operation to record the timestamp for - * @throws java.io.IOException if there is a non-recoverable problem reading or writing the metadata - */ - void resetLastCheckedTime( ArtifactRepository repository, String operation ) - throws IOException; - - /** - * Set the time in the repository that indicates the last time a check was performed. - * - * @param repository the location of the repository - * @param operation the operation to record the timestamp for - * @param date the date to set the last check to - * @throws java.io.IOException if there is a non-recoverable problem reading or writing the metadata - */ - void setLastCheckedTime( ArtifactRepository repository, String operation, Date date ) - throws IOException; -} diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DiscovererException.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DiscovererException.java deleted file mode 100644 index 02e45e699..000000000 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DiscovererException.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.maven.repository.discovery; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * @author Edwin Punzalan - */ -public class DiscovererException - extends Exception -{ - public DiscovererException( String message ) - { - super( message ); - } - - public DiscovererException( String message, Throwable cause ) - { - super( message, cause ); - } -} diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DiscovererPath.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DiscovererPath.java deleted file mode 100644 index ae2ecee73..000000000 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DiscovererPath.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.apache.maven.repository.discovery; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * @author Edwin Punzalan - */ -public class DiscovererPath -{ - /** - * The path discovered. - */ - private final String path; - - /** - * A comment about why the path is being processed. - */ - private final String comment; - - public DiscovererPath( String path, String comment ) - { - this.path = path; - this.comment = comment; - } - - public String getPath() - { - return path; - } - - public String getComment() - { - return comment; - } -} diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java deleted file mode 100644 index 9a8f7fc22..000000000 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java +++ /dev/null @@ -1,282 +0,0 @@ -package org.apache.maven.repository.discovery; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; - -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.StringTokenizer; - -/** - * Artifact discoverer for the legacy repository layout (Maven 1.x). - * Method used to build an artifact object using a relative path from a repository base directory. An artifactId - * having the words "DEV", "PRE", "RC", "ALPHA", "BETA", "DEBUG", "UNOFFICIAL", "CURRENT", "LATEST", "FCS", - * "RELEASE", "NIGHTLY", "SNAPSHOT" and "TEST" (not case-sensitive) will most likely make this method fail as - * they are reserved for version usage. - * - * @author John Casey - * @author Brett Porter - * @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="legacy" - */ -public class LegacyArtifactDiscoverer - extends AbstractArtifactDiscoverer -{ - /** - * @see org.apache.maven.repository.discovery.ArtifactDiscoverer#buildArtifact(String) - */ - public Artifact buildArtifact( String path ) - throws DiscovererException - { - StringTokenizer tokens = new StringTokenizer( path, "/\\" ); - - Artifact result; - - int numberOfTokens = tokens.countTokens(); - - if ( numberOfTokens == 3 ) - { - String groupId = tokens.nextToken(); - - String type = tokens.nextToken(); - - if ( type.endsWith( "s" ) ) - { - type = type.substring( 0, type.length() - 1 ); - - // contains artifactId, version, classifier, and extension. - String avceGlob = tokens.nextToken(); - - //noinspection CollectionDeclaredAsConcreteClass - LinkedList avceTokenList = new LinkedList(); - - StringTokenizer avceTokenizer = new StringTokenizer( avceGlob, "-" ); - while ( avceTokenizer.hasMoreTokens() ) - { - avceTokenList.addLast( avceTokenizer.nextToken() ); - } - - String lastAvceToken = (String) avceTokenList.removeLast(); - - // TODO: share with other discoverer, use artifact handlers instead - if ( lastAvceToken.endsWith( ".tar.gz" ) ) - { - type = "distribution-tgz"; - - lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".tar.gz".length() ); - - avceTokenList.addLast( lastAvceToken ); - } - else if ( lastAvceToken.endsWith( "sources.jar" ) ) - { - type = "java-source"; - - lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".jar".length() ); - - avceTokenList.addLast( lastAvceToken ); - } - else if ( lastAvceToken.endsWith( ".zip" ) ) - { - type = "distribution-zip"; - - lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".zip".length() ); - - avceTokenList.addLast( lastAvceToken ); - } - else - { - int extPos = lastAvceToken.lastIndexOf( '.' ); - - if ( extPos > 0 ) - { - String ext = lastAvceToken.substring( extPos + 1 ); - if ( type.equals( ext ) ) - { - lastAvceToken = lastAvceToken.substring( 0, extPos ); - - avceTokenList.addLast( lastAvceToken ); - } - else - { - throw new DiscovererException( "Path type does not match the extension" ); - } - } - else - { - throw new DiscovererException( "Path filename does not have an extension" ); - } - } - - // let's discover the version, and whatever's leftover will be either - // a classifier, or part of the artifactId, depending on position. - // Since version is at the end, we have to move in from the back. - Collections.reverse( avceTokenList ); - - // TODO: this is obscene - surely a better way? - String validVersionParts = "([Dd][Ee][Vv][_.0-9]*)|" + "([Ss][Nn][Aa][Pp][Ss][Hh][Oo][Tt])|" + - "([0-9][_.0-9a-zA-Z]*)|" + "([Gg]?[_.0-9ab]*([Pp][Rr][Ee]|[Rr][Cc]|[Gg]|[Mm])[_.0-9]*)|" + - "([Aa][Ll][Pp][Hh][Aa][_.0-9]*)|" + "([Bb][Ee][Tt][Aa][_.0-9]*)|" + "([Rr][Cc][_.0-9]*)|" + - "([Tt][Ee][Ss][Tt][_.0-9]*)|" + "([Dd][Ee][Bb][Uu][Gg][_.0-9]*)|" + - "([Uu][Nn][Oo][Ff][Ff][Ii][Cc][Ii][Aa][Ll][_.0-9]*)|" + "([Cc][Uu][Rr][Rr][Ee][Nn][Tt])|" + - "([Ll][Aa][Tt][Ee][Ss][Tt])|" + "([Ff][Cc][Ss])|" + "([Rr][Ee][Ll][Ee][Aa][Ss][Ee][_.0-9]*)|" + - "([Nn][Ii][Gg][Hh][Tt][Ll][Yy])|" + "[Ff][Ii][Nn][Aa][Ll]|" + "([AaBb][_.0-9]*)"; - - StringBuffer classifierBuffer = new StringBuffer(); - StringBuffer versionBuffer = new StringBuffer(); - - boolean firstVersionTokenEncountered = false; - boolean firstToken = true; - - int tokensIterated = 0; - for ( Iterator it = avceTokenList.iterator(); it.hasNext(); ) - { - String token = (String) it.next(); - - boolean tokenIsVersionPart = token.matches( validVersionParts ); - - StringBuffer bufferToUpdate; - - // NOTE: logic in code is reversed, since we're peeling off the back - // Any token after the last versionPart will be in the classifier. - // Any token UP TO first non-versionPart is part of the version. - if ( !tokenIsVersionPart ) - { - if ( firstVersionTokenEncountered ) - { - //noinspection BreakStatement - break; - } - else - { - bufferToUpdate = classifierBuffer; - } - } - else - { - firstVersionTokenEncountered = true; - - bufferToUpdate = versionBuffer; - } - - if ( firstToken ) - { - firstToken = false; - } - else - { - bufferToUpdate.insert( 0, '-' ); - } - - bufferToUpdate.insert( 0, token ); - - tokensIterated++; - } - - // Now, restore the proper ordering so we can build the artifactId. - Collections.reverse( avceTokenList ); - - // if we didn't find a version, then punt. Use the last token - // as the version, and set the classifier empty. - if ( versionBuffer.length() < 1 ) - { - if ( avceTokenList.size() > 1 ) - { - int lastIdx = avceTokenList.size() - 1; - - versionBuffer.append( avceTokenList.get( lastIdx ) ); - avceTokenList.remove( lastIdx ); - } - - classifierBuffer.setLength( 0 ); - } - else - { - // if everything is kosher, then pop off all the classifier and - // version tokens, leaving the naked artifact id in the list. - avceTokenList = - new LinkedList( avceTokenList.subList( 0, avceTokenList.size() - tokensIterated ) ); - } - - StringBuffer artifactIdBuffer = new StringBuffer(); - - firstToken = true; - for ( Iterator it = avceTokenList.iterator(); it.hasNext(); ) - { - String token = (String) it.next(); - - if ( firstToken ) - { - firstToken = false; - } - else - { - artifactIdBuffer.append( '-' ); - } - - artifactIdBuffer.append( token ); - } - - String artifactId = artifactIdBuffer.toString(); - - if ( artifactId.length() > 0 ) - { - int lastVersionCharIdx = versionBuffer.length() - 1; - if ( lastVersionCharIdx > -1 && versionBuffer.charAt( lastVersionCharIdx ) == '-' ) - { - versionBuffer.setLength( lastVersionCharIdx ); - } - - String version = versionBuffer.toString(); - - if ( version.length() > 0 ) - { - if ( classifierBuffer.length() > 0 ) - { - result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, - type, - classifierBuffer.toString() ); - } - else - { - result = artifactFactory.createArtifact( groupId, artifactId, version, - Artifact.SCOPE_RUNTIME, type ); - } - } - else - { - throw new DiscovererException( "Path filename version is empty" ); - } - } - else - { - throw new DiscovererException( "Path filename artifactId is empty" ); - } - } - else - { - throw new DiscovererException( "Path artifact type does not corresspond to an artifact type" ); - } - } - else - { - throw new DiscovererException( "Path does not match a legacy repository path for an artifact" ); - } - - return result; - } -} diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java deleted file mode 100644 index 3877c7723..000000000 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.apache.maven.repository.discovery; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.repository.ArtifactRepository; - -import java.util.List; - -/** - * Interface for discovering metadata files. - */ -public interface MetadataDiscoverer - extends Discoverer -{ - String ROLE = MetadataDiscoverer.class.getName(); - - /** - * Search for metadata files in the repository. - * - * @param repository The repository. - * @param operation the operation being performed (used for timestamp comparison) - * @param blacklistedPatterns Patterns that are to be excluded from the discovery process. - * @return the list of artifacts found - */ - List discoverMetadata( ArtifactRepository repository, String operation, String blacklistedPatterns ) - throws DiscovererException; -} diff --git a/maven-repository-discovery/src/site/apt/design.apt b/maven-repository-discovery/src/site/apt/design.apt deleted file mode 100644 index 6a482e0ab..000000000 --- a/maven-repository-discovery/src/site/apt/design.apt +++ /dev/null @@ -1,37 +0,0 @@ - ----- - Discoverer Design - ----- - Brett Porter - ----- - 24 July 2006 - ----- - -Discoverer Design - - The artifact discoverer is designed to traverse the paths in the repository and identify files that are part of - a legitimate artifact. - - There are two plexus components available: - - * {{{../apidocs/org/apache/maven/repository/discovery/ArtifactDiscoverer.html} ArtifactDiscoverer}} - - * {{{../apidocs/org/apache/maven/repository/discovery/MetadataDiscoverer.html} MetadataDiscoverer}} - - Each of these components currently have an implementation for the both <<>> and <<>> repository - layouts. - - The artifact discoverer will find all artifacts in the repository, while metadata discovery finds any - <<>> files (both remote and local repository formats). - - * Limitations - - * In the artifact discoverer, POMs will be identified as separate artifacts to their related artifacts, as will each - individual derivative artifact at present. Later, these will be linked - see - {{{http://jira.codehaus.org/browse/MRM-40} MRM-40}}. - - * Currently, deleted artifacts are not tracked. This requires a separate event - see - {{{http://jira.codehaus.org/browse/MRM-37} MRM-37}}. - - * Currently, all artifacts are discovered instead of just those changed since the last discovery for a particular - operation - see {{{http://jira.codehaus.org/browse/MRM-125} MRM-125}}. - diff --git a/maven-repository-discovery/src/site/site.xml b/maven-repository-discovery/src/site/site.xml deleted file mode 100644 index 245a0bf34..000000000 --- a/maven-repository-discovery/src/site/site.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - diff --git a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/AbstractArtifactDiscovererTest.java b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/AbstractArtifactDiscovererTest.java deleted file mode 100644 index c016fe0bc..000000000 --- a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/AbstractArtifactDiscovererTest.java +++ /dev/null @@ -1,254 +0,0 @@ -package org.apache.maven.repository.discovery; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; - -import java.io.File; -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -/** - * @author Edwin Punzalan - */ -public abstract class AbstractArtifactDiscovererTest - extends PlexusTestCase -{ - protected ArtifactDiscoverer discoverer; - - private ArtifactFactory factory; - - protected ArtifactRepository repository; - - protected static final String TEST_OPERATION = "test"; - - protected abstract String getLayout(); - - protected abstract File getRepositoryFile(); - - protected void setUp() - throws Exception - { - super.setUp(); - - discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, getLayout() ); - - factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - - repository = getRepository(); - - removeTimestampMetadata(); - } - - protected ArtifactRepository getRepository() - throws Exception - { - File basedir = getRepositoryFile(); - - ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - - ArtifactRepositoryLayout layout = - (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, getLayout() ); - - return factory.createArtifactRepository( "discoveryRepo", "file://" + basedir, layout, null, null ); - } - - protected Artifact createArtifact( String groupId, String artifactId, String version ) - { - Artifact artifact = factory.createArtifact( groupId, artifactId, version, null, "jar" ); - artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); - artifact.setRepository( repository ); - return artifact; - } - - protected Artifact createArtifact( String groupId, String artifactId, String version, String type ) - { - return factory.createArtifact( groupId, artifactId, version, null, type ); - } - - protected Artifact createArtifact( String groupId, String artifactId, String version, String type, - String classifier ) - { - return factory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier ); - } - - public void testUpdatedInRepository() - throws ComponentLookupException, DiscovererException, ParseException, IOException - { - // Set repository time to 1-1-2000, a time in the distant past so definitely updated - discoverer.setLastCheckedTime( repository, "update", - new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).parse( "2000-01-01" ) ); - - List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check included", - artifacts.contains( createArtifact( "org.apache.maven.update", "test-updated", "1.0" ) ) ); - - // try again with the updated timestamp - artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertFalse( "Check not included", - artifacts.contains( createArtifact( "org.apache.maven.update", "test-updated", "1.0" ) ) ); - } - - public void testNotUpdatedInRepository() - throws ComponentLookupException, DiscovererException, IOException - { - // Set repository time to now, which is after any artifacts, so definitely not updated - discoverer.setLastCheckedTime( repository, "update", new Date() ); - - List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertFalse( "Check not included", - artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) ); - } - - public void testNotUpdatedInRepositoryForcedDiscovery() - throws ComponentLookupException, DiscovererException, IOException - { - discoverer.resetLastCheckedTime( repository, "update" ); - - List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check included", - artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) ); - - // try again with the updated timestamp - artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertFalse( "Check not included", - artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) ); - } - - public void testUpdatedInRepositoryBlackout() - throws ComponentLookupException, DiscovererException, IOException - { - discoverer.resetLastCheckedTime( repository, "update" ); - - Artifact artifact = createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ); - artifact.getFile().setLastModified( System.currentTimeMillis() ); - - List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertFalse( "Check not included", artifacts.contains( artifact ) ); - - // try again with the updated timestamp - artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertFalse( "Check not included", artifacts.contains( artifact ) ); - } - - public void testUpdatedInRepositoryNotBlackout() - throws ComponentLookupException, DiscovererException, IOException - { - discoverer.resetLastCheckedTime( repository, "update" ); - - Artifact artifact = createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ); - artifact.getFile().setLastModified( System.currentTimeMillis() - 61000 ); - - List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check included", artifacts.contains( artifact ) ); - - // try again with the updated timestamp - artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertFalse( "Check not included", artifacts.contains( artifact ) ); - } - - public void testNotUpdatedInRepositoryForcedDiscoveryMetadataAlreadyExists() - throws ComponentLookupException, DiscovererException, IOException - { - discoverer.setLastCheckedTime( repository, "update", new Date() ); - - discoverer.resetLastCheckedTime( repository, "update" ); - - List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check included", - artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) ); - - // try again with the updated timestamp - artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertFalse( "Check not included", - artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) ); - } - - public void testNotUpdatedInRepositoryForcedDiscoveryOtherMetadataAlreadyExists() - throws ComponentLookupException, DiscovererException, IOException - { - discoverer.setLastCheckedTime( repository, "test", new Date() ); - - discoverer.resetLastCheckedTime( repository, "update" ); - - List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check included", - artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) ); - - // try again with the updated timestamp - artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertFalse( "Check not included", - artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) ); - } - - public void testNoRepositoryMetadata() - throws ComponentLookupException, DiscovererException, ParseException, IOException - { - removeTimestampMetadata(); - - // should find all - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check included", - artifacts.contains( createArtifact( "org.apache.maven.update", "test-updated", "1.0" ) ) ); - } - - private void removeTimestampMetadata() - { - // remove the metadata that tracks time - File file = new File( repository.getBasedir(), "maven-metadata.xml" ); - file.delete(); - assertFalse( file.exists() ); - } -} diff --git a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java deleted file mode 100644 index 7832c4d68..000000000 --- a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java +++ /dev/null @@ -1,668 +0,0 @@ -package org.apache.maven.repository.discovery; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; - -import java.io.File; -import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** - * Test the default artifact discoverer. - * - * @author Brett Porter - * @version $Id$ - * @todo test location of poms, checksums - */ -public class DefaultArtifactDiscovererTest - extends AbstractArtifactDiscovererTest -{ - - protected String getLayout() - { - return "default"; - } - - protected File getRepositoryFile() - { - return getTestFile( "src/test/repository" ); - } - - public void testDefaultExcludes() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - boolean b = path.indexOf( ".svn" ) >= 0; - if ( b ) - { - found = true; - assertEquals( "Check comment", "Artifact was in the specified list of exclusions", dPath.getComment() ); - } - } - assertTrue( "Check exclusion was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not .svn", a.getFile().getPath().indexOf( ".svn" ) >= 0 ); - } - } - - public void testStandardExcludes() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "KEYS".equals( path ) ) - { - found = true; - assertEquals( "Check comment", "Artifact was in the specified list of exclusions", dPath.getComment() ); - } - } - assertTrue( "Check exclusion was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not KEYS", "KEYS".equals( a.getFile().getName() ) ); - } - } - - public void testBlacklistedExclude() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, "javax/**", false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "javax/sql/jdbc/2.0/jdbc-2.0.jar".equals( path.replace( '\\', '/' ) ) ) - { - found = true; - assertEquals( "Check comment is about blacklisting", "Artifact was in the specified list of exclusions", - dPath.getComment() ); - } - } - assertTrue( "Check exclusion was found", found ); - - assertFalse( "Check jdbc not included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) ); - } - - public void testKickoutWithShortPath() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "invalid/invalid-1.0.jar".equals( path.replace( '\\', '/' ) ) ) - { - found = true; - assertEquals( "Check reason for kickout", "Path is too short to build an artifact from", - dPath.getComment() ); - - } - } - assertTrue( "Check kickout was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not invalid-1.0.jar", "invalid-1.0.jar".equals( a.getFile().getName() ) ); - } - } - - public void testKickoutWithWrongArtifactId() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar".equals( - path.replace( '\\', '/' ) ) ) - { - found = true; - assertEquals( "Check reason for kickout", "Path filename does not correspond to an artifact", - dPath.getComment() ); - } - } - assertTrue( "Check kickout was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not wrong jar", - "wrong-artifactId-1.0-20050611.112233-1.jar".equals( a.getFile().getName() ) ); - } - } - - public void testKickoutWithNoType() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "invalid/invalid/1/invalid-1".equals( path.replace( '\\', '/' ) ) ) - { - found = true; - assertEquals( "Check reason for kickout", "Path filename does not have an extension", - dPath.getComment() ); - } - } - assertTrue( "Check kickout was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not 'invalid-1'", "invalid-1".equals( a.getFile().getName() ) ); - } - } - - public void testKickoutWithWrongVersion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "invalid/invalid/1.0/invalid-2.0.jar".equals( path.replace( '\\', '/' ) ) ) - { - found = true; - assertEquals( "Check reason for kickout", "Built artifact version does not match path version", - dPath.getComment() ); - } - } - assertTrue( "Check kickout was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not 'invalid-2.0.jar'", "invalid-2.0.jar".equals( a.getFile().getName() ) ); - } - } - - public void testKickoutWithLongerVersion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "invalid/invalid/1.0/invalid-1.0b.jar".equals( path.replace( '\\', '/' ) ) ) - { - found = true; - assertEquals( "Check reason for kickout", "Path version does not corresspond to an artifact version", - dPath.getComment() ); - } - } - assertTrue( "Check kickout was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not 'invalid-1.0b.jar'", "invalid-1.0b.jar".equals( a.getFile().getName() ) ); - } - } - - public void testKickoutWithWrongSnapshotVersion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar".equals( path.replace( '\\', '/' ) ) ) - { - found = true; - assertEquals( "Check reason for kickout", - "Failed to create a snapshot artifact: invalid:invalid:jar:1.0:runtime", - dPath.getComment() ); - } - } - assertTrue( "Check kickout was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not 'invalid-1.0.jar'", "invalid-1.0.jar".equals( a.getFile().getName() ) ); - } - } - - public void testKickoutWithSnapshotBaseVersion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar".equals( - path.replace( '\\', '/' ) ) ) - { - found = true; - assertEquals( "Check reason for kickout", - "Built snapshot artifact base version does not match path version: invalid:invalid:jar:1.0-SNAPSHOT:runtime; should have been version: 1.0-20050611.123456-1", - dPath.getComment() ); - } - } - assertTrue( "Check kickout was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not 'invalid-1.0-20050611-123456-1.jar'", - "invalid-1.0-20050611.123456-1.jar".equals( a.getFile().getName() ) ); - } - } - - public void testInclusion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check normal included", - artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0" ) ) ); - } - - public void testArtifactWithClassifier() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check normal included", - artifacts.contains( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ) ) ); - } - - public void testJavaSourcesInclusion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check normal included", artifacts.contains( - createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ) ) ); - } - - public void testDistributionInclusion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check zip included", - artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ) ) ); - - assertTrue( "Check tar.gz included", - artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ) ) ); - } - - public void testSnapshotInclusion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) ); - assertTrue( "Check snapshot included", - artifacts.contains( createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1" ) ) ); - } - - public void testSnapshotInclusionWithClassifier() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check snapshot included", artifacts.contains( - createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1", "jar", "javadoc" ) ) ); - } - - public void testSnapshotExclusion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) ); - assertFalse( "Check snapshot included", - artifacts.contains( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ) ) ); - } - - public void testFileSet() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact artifact = (Artifact) i.next(); - assertNotNull( "Check file is set", artifact.getFile() ); - } - } - - public void testRepositorySet() - throws MalformedURLException, DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - String url = repository.getUrl(); - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact artifact = (Artifact) i.next(); - assertNotNull( "Check repository set", artifact.getRepository() ); - assertEquals( "Check repository url is correct", url, artifact.getRepository().getUrl() ); - } - } - - public void testStandalonePoms() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - - // cull down to actual artifacts (only standalone poms will have type = pom) - Map keyedArtifacts = new HashMap(); - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - String key = a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion(); - if ( !"pom".equals( a.getType() ) || !keyedArtifacts.containsKey( key ) ) - { - keyedArtifacts.put( key, a ); - } - } - - List models = new ArrayList(); - - for ( Iterator i = keyedArtifacts.values().iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - - if ( "pom".equals( a.getType() ) ) - { - models.add( a ); - } - } - - assertEquals( 4, models.size() ); - - // Define order we expect - Collections.sort( models ); - - Iterator itr = models.iterator(); - Artifact model = (Artifact) itr.next(); - assertEquals( "org.apache.maven", model.getGroupId() ); - assertEquals( "B", model.getArtifactId() ); - assertEquals( "1.0", model.getVersion() ); - model = (Artifact) itr.next(); - assertEquals( "org.apache.maven", model.getGroupId() ); - assertEquals( "B", model.getArtifactId() ); - assertEquals( "2.0", model.getVersion() ); - model = (Artifact) itr.next(); - assertEquals( "org.apache.maven", model.getGroupId() ); - assertEquals( "discovery", model.getArtifactId() ); - assertEquals( "1.0", model.getVersion() ); - model = (Artifact) itr.next(); - assertEquals( "org.apache.testgroup", model.getGroupId() ); - assertEquals( "discovery", model.getArtifactId() ); - assertEquals( "1.0", model.getVersion() ); - } - - public void testShortPath() - throws ComponentLookupException - { - try - { - discoverer.buildArtifact( "invalid/invalid-1.0.jar" ); - - fail( "Artifact should be null for short paths" ); - } - catch ( DiscovererException e ) - { - // excellent - } - } - - public void testWrongArtifactId() - throws ComponentLookupException - { - - try - { - discoverer.buildArtifact( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar" ); - - fail( "Artifact should be null for wrong ArtifactId" ); - } - catch ( DiscovererException e ) - { - // excellent - } - } - - public void testNoType() - throws ComponentLookupException - { - try - { - discoverer.buildArtifact( "invalid/invalid/1/invalid-1" ); - - fail( "Artifact should be null for no type" ); - } - catch ( DiscovererException e ) - { - // excellent - } - } - - public void testWrongVersion() - throws ComponentLookupException - { - try - { - discoverer.buildArtifact( "invalid/invalid/1.0/invalid-2.0.jar" ); - - fail( "Artifact should be null for wrong version" ); - } - catch ( DiscovererException e ) - { - // excellent - } - } - - public void testLongVersion() - throws ComponentLookupException - { - try - { - discoverer.buildArtifact( "invalid/invalid/1.0/invalid-1.0b.jar" ); - - fail( "Artifact should be null for long version" ); - } - catch ( DiscovererException e ) - { - // excellent - } - } - - public void testWrongSnapshotVersion() - throws ComponentLookupException - { - try - { - discoverer.buildArtifact( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar" ); - - fail( "Artifact should be null for wrong snapshot version" ); - } - catch ( DiscovererException e ) - { - // excellent - } - } - - public void testSnapshotBaseVersion() - throws ComponentLookupException - { - try - { - discoverer.buildArtifact( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" ); - - fail( "Artifact should be null for snapshot base version" ); - } - catch ( DiscovererException e ) - { - // excellent - } - } - - public void testPathWithClassifier() - throws ComponentLookupException, DiscovererException - { - String testPath = "org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar"; - - Artifact artifact = discoverer.buildArtifact( testPath ); - - assertEquals( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ), artifact ); - } - - public void testWithJavaSourceInclusion() - throws ComponentLookupException, DiscovererException - { - String testPath = "org/apache/maven/testing/1.0/testing-1.0-sources.jar"; - - Artifact artifact = discoverer.buildArtifact( testPath ); - - assertEquals( createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ), artifact ); - } - - public void testDistributionArtifacts() - throws ComponentLookupException, DiscovererException - { - String testPath = "org/apache/maven/testing/1.0/testing-1.0.tar.gz"; - - Artifact artifact = discoverer.buildArtifact( testPath ); - - assertEquals( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ), artifact ); - - testPath = "org/apache/maven/testing/1.0/testing-1.0.zip"; - - artifact = discoverer.buildArtifact( testPath ); - - assertEquals( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ), artifact ); - } - - public void testSnapshot() - throws ComponentLookupException, DiscovererException - { - String testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar"; - - Artifact artifact = discoverer.buildArtifact( testPath ); - - assertEquals( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ), artifact ); - - testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar"; - - artifact = discoverer.buildArtifact( testPath ); - - assertEquals( createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1" ), artifact ); - } - - public void testNormal() - throws ComponentLookupException, DiscovererException - { - String testPath = "javax/sql/jdbc/2.0/jdbc-2.0.jar"; - - Artifact artifact = discoverer.buildArtifact( testPath ); - - assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact ); - } - - public void testSnapshotWithClassifier() - throws ComponentLookupException, DiscovererException - { - String testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1-javadoc.jar"; - - Artifact artifact = discoverer.buildArtifact( testPath ); - - assertEquals( createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1", "jar", "javadoc" ), - artifact ); - } -} diff --git a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java deleted file mode 100644 index 52471ab25..000000000 --- a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java +++ /dev/null @@ -1,311 +0,0 @@ -package org.apache.maven.repository.discovery; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; - -import java.io.File; -import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; - -/** - * This class tests the DefaultMetadataDiscoverer class. - */ -public class DefaultMetadataDiscovererTest - extends PlexusTestCase -{ - private MetadataDiscoverer discoverer; - - private static final String TEST_OPERATION = "test"; - - private ArtifactRepository repository; - - private ArtifactFactory factory; - - /** - * - */ - public void setUp() - throws Exception - { - super.setUp(); - - discoverer = (MetadataDiscoverer) lookup( MetadataDiscoverer.ROLE, "default" ); - - factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - - repository = getRepository(); - - removeTimestampMetadata(); - } - - protected ArtifactRepository getRepository() - throws Exception - { - File basedir = getTestFile( "src/test/repository" ); - - ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - - return factory.createArtifactRepository( "discoveryRepo", "file://" + basedir, layout, null, null ); - } - - /** - * - */ - public void tearDown() - throws Exception - { - super.tearDown(); - discoverer = null; - } - - /** - * Test if metadata file in wrong directory was added to the kickedOutPaths. - */ - public void testKickoutWrongDirectory() - throws DiscovererException - { - discoverer.discoverMetadata( repository, TEST_OPERATION, null ); - Iterator iter = discoverer.getKickedOutPathsIterator(); - boolean found = false; - while ( iter.hasNext() && !found ) - { - DiscovererPath dPath = (DiscovererPath) iter.next(); - String dir = dPath.getPath(); - - String normalizedDir = dir.replace( '\\', '/' ); - if ( "javax/maven-metadata.xml".equals( normalizedDir ) ) - { - found = true; - assertEquals( "Check reason for kickout", "Unable to build a repository metadata from path", - dPath.getComment() ); - } - } - assertTrue( found ); - } - - /** - * Test if blank metadata file was added to the kickedOutPaths. - */ - public void testKickoutBlankMetadata() - throws DiscovererException - { - discoverer.discoverMetadata( repository, TEST_OPERATION, null ); - Iterator iter = discoverer.getKickedOutPathsIterator(); - boolean found = false; - while ( iter.hasNext() && !found ) - { - DiscovererPath dPath = (DiscovererPath) iter.next(); - String dir = dPath.getPath(); - - String normalizedDir = dir.replace( '\\', '/' ); - if ( "org/apache/maven/some-ejb/1.0/maven-metadata.xml".equals( normalizedDir ) ) - { - found = true; - assertTrue( "Check reason for kickout", dPath.getComment().matches( - "Error reading metadata file '(.*)': input contained no data" ) ); - } - } - assertTrue( found ); - } - - private void removeTimestampMetadata() - throws IOException - { - // remove the metadata that tracks time - File file = new File( repository.getBasedir(), "maven-metadata.xml" ); - System.gc(); // for Windows - file.delete(); - assertFalse( file.exists() ); - } - - public void testDiscoverMetadata() - throws DiscovererException - { - List metadataPaths = discoverer.discoverMetadata( repository, TEST_OPERATION, null ); - assertNotNull( "Check metadata not null", metadataPaths ); - - RepositoryMetadata metadata = - new ArtifactRepositoryMetadata( createArtifact( "org.apache.testgroup", "discovery" ) ); - assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); - - metadata = - new SnapshotArtifactRepositoryMetadata( createArtifact( "org.apache.testgroup", "discovery", "1.0" ) ); - assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); - - metadata = new GroupRepositoryMetadata( "org.apache.maven" ); - assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); - } - - public void testUpdatedInRepository() - throws ComponentLookupException, DiscovererException, ParseException, IOException - { - // Set repository time to 1-1-2000, a time in the distant past so definitely updated - discoverer.setLastCheckedTime( repository, "update", - new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).parse( "2000-01-01" ) ); - - List metadataPaths = discoverer.discoverMetadata( repository, "update", null ); - assertNotNull( "Check metadata not null", metadataPaths ); - - RepositoryMetadata metadata = - new ArtifactRepositoryMetadata( createArtifact( "org.apache.maven.update", "test-updated" ) ); - assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); - - // try again with the updated timestamp - metadataPaths = discoverer.discoverMetadata( repository, "update", null ); - assertNotNull( "Check metadata not null", metadataPaths ); - - assertFalse( "Check not included", containsMetadata( metadataPaths, metadata ) ); - } - - private boolean containsMetadata( List metadataPaths, RepositoryMetadata metadata ) - { - for ( Iterator i = metadataPaths.iterator(); i.hasNext(); ) - { - RepositoryMetadata m = (RepositoryMetadata) i.next(); - - if ( m.getGroupId().equals( metadata.getGroupId() ) ) - { - if ( m.getArtifactId() == null && metadata.getArtifactId() == null ) - { - return true; - } - else if ( m.getArtifactId() != null && m.getArtifactId().equals( metadata.getArtifactId() ) ) - { - return true; - } - } - } - return false; - } - - public void testNotUpdatedInRepository() - throws ComponentLookupException, DiscovererException, IOException - { - // Set repository time to now, which is after any artifacts, so definitely not updated - discoverer.setLastCheckedTime( repository, "update", new Date() ); - - List metadataPaths = discoverer.discoverMetadata( repository, "update", null ); - assertNotNull( "Check metadata not null", metadataPaths ); - - RepositoryMetadata metadata = - new ArtifactRepositoryMetadata( createArtifact( "org.apache.maven.update", "test-not-updated" ) ); - assertFalse( "Check not included", containsMetadata( metadataPaths, metadata ) ); - } - - public void testNotUpdatedInRepositoryForcedDiscovery() - throws ComponentLookupException, DiscovererException, IOException - { - discoverer.resetLastCheckedTime( repository, "update" ); - - List metadataPaths = discoverer.discoverMetadata( repository, "update", null ); - assertNotNull( "Check metadata not null", metadataPaths ); - - RepositoryMetadata metadata = - new ArtifactRepositoryMetadata( createArtifact( "org.apache.maven.update", "test-not-updated" ) ); - assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); - - // try again with the updated timestamp - metadataPaths = discoverer.discoverMetadata( repository, "update", null ); - assertNotNull( "Check metadata not null", metadataPaths ); - - assertFalse( "Check not included", containsMetadata( metadataPaths, metadata ) ); - } - - public void testNotUpdatedInRepositoryForcedDiscoveryMetadataAlreadyExists() - throws ComponentLookupException, DiscovererException, IOException - { - discoverer.setLastCheckedTime( repository, "update", new Date() ); - - discoverer.resetLastCheckedTime( repository, "update" ); - - List metadataPaths = discoverer.discoverMetadata( repository, "update", null ); - assertNotNull( "Check metadata not null", metadataPaths ); - - RepositoryMetadata metadata = - new ArtifactRepositoryMetadata( createArtifact( "org.apache.maven.update", "test-not-updated" ) ); - assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); - - // try again with the updated timestamp - metadataPaths = discoverer.discoverMetadata( repository, "update", null ); - assertNotNull( "Check metadata not null", metadataPaths ); - - assertFalse( "Check not included", containsMetadata( metadataPaths, metadata ) ); - } - - public void testNotUpdatedInRepositoryForcedDiscoveryOtherMetadataAlreadyExists() - throws ComponentLookupException, DiscovererException, IOException - { - discoverer.setLastCheckedTime( repository, "test", new Date() ); - - discoverer.resetLastCheckedTime( repository, "update" ); - - List metadataPaths = discoverer.discoverMetadata( repository, "update", null ); - assertNotNull( "Check metadata not null", metadataPaths ); - - RepositoryMetadata metadata = - new ArtifactRepositoryMetadata( createArtifact( "org.apache.maven.update", "test-not-updated" ) ); - assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); - - // try again with the updated timestamp - metadataPaths = discoverer.discoverMetadata( repository, "update", null ); - assertNotNull( "Check metadata not null", metadataPaths ); - - assertFalse( "Check not included", containsMetadata( metadataPaths, metadata ) ); - } - - public void testNoRepositoryMetadata() - throws ComponentLookupException, DiscovererException, ParseException, IOException - { - removeTimestampMetadata(); - - // should find all - List metadataPaths = discoverer.discoverMetadata( repository, TEST_OPERATION, null ); - assertNotNull( "Check metadata not null", metadataPaths ); - - RepositoryMetadata metadata = - new ArtifactRepositoryMetadata( createArtifact( "org.apache.maven.update", "test-updated" ) ); - assertTrue( "Check included", containsMetadata( metadataPaths, metadata ) ); - } - - protected Artifact createArtifact( String groupId, String artifactId ) - { - return createArtifact( groupId, artifactId, "1.0" ); - } - - private Artifact createArtifact( String groupId, String artifactId, String version ) - { - return factory.createArtifact( groupId, artifactId, version, null, "jar" ); - } -} diff --git a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java deleted file mode 100644 index 88cc07ad1..000000000 --- a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java +++ /dev/null @@ -1,479 +0,0 @@ -package org.apache.maven.repository.discovery; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; - -import java.io.File; -import java.net.MalformedURLException; -import java.util.Iterator; -import java.util.List; - -/** - * Test the legacy artifact discoverer. - * - * @author Brett Porter - * @version $Id$ - */ -public class LegacyArtifactDiscovererTest - extends AbstractArtifactDiscovererTest -{ - protected String getLayout() - { - return "legacy"; - } - - protected File getRepositoryFile() - { - return getTestFile( "src/test/legacy-repository" ); - } - - public void testDefaultExcludes() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( path.indexOf( ".svn" ) >= 0 ) - { - found = true; - assertEquals( "Check comment", "Artifact was in the specified list of exclusions", dPath.getComment() ); - } - } - assertTrue( "Check exclusion was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not .svn", a.getFile().getPath().indexOf( ".svn" ) >= 0 ); - } - } - - public void testStandardExcludes() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "KEYS".equals( path ) ) - { - found = true; - assertEquals( "Check comment", "Artifact was in the specified list of exclusions", dPath.getComment() ); - } - } - assertTrue( "Check exclusion was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not KEYS", "KEYS".equals( a.getFile().getName() ) ); - } - } - - public void testBlacklistedExclude() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, "javax.sql/**", false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "javax.sql/jars/jdbc-2.0.jar".equals( path.replace( '\\', '/' ) ) ) - { - found = true; - assertEquals( "Check comment is about blacklisting", "Artifact was in the specified list of exclusions", - dPath.getComment() ); - } - } - assertTrue( "Check exclusion was found", found ); - - assertFalse( "Check jdbc not included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) ); - } - - public void testKickoutWithShortPath() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "invalid/invalid-1.0.jar".equals( path.replace( '\\', '/' ) ) ) - { - found = true; - assertEquals( "Check reason for kickout", - "Path does not match a legacy repository path for an artifact", dPath.getComment() ); - } - } - assertTrue( "Check kickout was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not invalid-1.0.jar", "invalid-1.0.jar".equals( a.getFile().getName() ) ); - } - } - - public void testKickoutWithLongPath() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "invalid/jars/1.0/invalid-1.0.jar".equals( path.replace( '\\', '/' ) ) ) - { - found = true; - assertEquals( "Check reason for kickout", - "Path does not match a legacy repository path for an artifact", dPath.getComment() ); - } - } - assertTrue( "Check kickout was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not invalid-1.0.jar", "invalid-1.0.jar".equals( a.getFile().getName() ) ); - } - } - - public void testKickoutWithInvalidType() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "invalid/foo/invalid-1.0.foo".equals( path.replace( '\\', '/' ) ) ) - { - found = true; - assertEquals( "Check reason for kickout", "Path artifact type does not corresspond to an artifact type", - dPath.getComment() ); - } - } - assertTrue( "Check kickout was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not invalid-1.0.foo", "invalid-1.0.foo".equals( a.getFile().getName() ) ); - } - } - - public void testKickoutWithNoExtension() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "invalid/jars/no-extension".equals( path.replace( '\\', '/' ) ) ) - { - found = true; - assertEquals( "Check reason for kickout", "Path filename does not have an extension", - dPath.getComment() ); - } - } - assertTrue( "Check kickout was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not 'no-extension'", "no-extension".equals( a.getFile().getName() ) ); - } - } - - public void testKickoutWithWrongExtension() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "invalid/jars/invalid-1.0.rar".equals( path.replace( '\\', '/' ) ) ) - { - found = true; - assertEquals( "Check reason for kickout", "Path type does not match the extension", - dPath.getComment() ); - } - } - assertTrue( "Check kickout was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not 'invalid-1.0.rar'", "invalid-1.0.rar".equals( a.getFile().getName() ) ); - } - } - - public void testKickoutWithNoVersion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - boolean found = false; - for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) - { - DiscovererPath dPath = (DiscovererPath) i.next(); - - String path = dPath.getPath(); - - if ( "invalid/jars/invalid.jar".equals( path.replace( '\\', '/' ) ) ) - { - found = true; - assertEquals( "Check reason for kickout", "Path filename version is empty", dPath.getComment() ); - } - } - assertTrue( "Check kickout was found", found ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - assertFalse( "Check not 'invalid.jar'", "invalid.jar".equals( a.getFile().getName() ) ); - } - } - - public void testInclusion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check normal included", - artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0" ) ) ); - } - - public void testTextualVersion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check normal included", - artifacts.contains( createArtifact( "org.apache.maven", "testing", "UNKNOWN" ) ) ); - } - - public void testArtifactWithClassifier() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check normal included", - artifacts.contains( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ) ) ); - } - - public void testJavaSourcesInclusion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check normal included", artifacts.contains( - createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ) ) ); - } - - public void testDistributionInclusion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check zip included", - artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ) ) ); - - assertTrue( "Check tar.gz included", - artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ) ) ); - } - - public void testSnapshotInclusion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) ); - assertTrue( "Check snapshot included", - artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) ); - } - - public void testSnapshotExclusion() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false ); - assertNotNull( "Check artifacts not null", artifacts ); - - assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) ); - assertFalse( "Check snapshot included", - artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) ); - } - - public void testFileSet() - throws DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact artifact = (Artifact) i.next(); - assertNotNull( "Check file is set", artifact.getFile() ); - } - } - - public void testRepositorySet() - throws MalformedURLException, DiscovererException - { - List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true ); - assertNotNull( "Check artifacts not null", artifacts ); - - String url = repository.getUrl(); - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact artifact = (Artifact) i.next(); - assertNotNull( "Check repository set", artifact.getRepository() ); - assertEquals( "Check repository url is correct", url, artifact.getRepository().getUrl() ); - } - } - - public void testWrongArtifactPackaging() - throws ComponentLookupException, DiscovererException - { - try - { - discoverer.buildArtifact( "org.apache.maven.test/jars/artifactId-1.0.jar.md5" ); - - fail( "Artifact should be null for wrong package extension" ); - } - catch ( DiscovererException e ) - { - // excellent - } - } - - public void testNoArtifactId() - throws DiscovererException - { - try - { - discoverer.buildArtifact( "groupId/jars/-1.0.jar" ); - - fail( "Artifact should be null when artifactId is missing" ); - } - catch ( DiscovererException e ) - { - // excellent - } - - try - { - discoverer.buildArtifact( "groupId/jars/1.0.jar" ); - - fail( "Artifact should be null when artifactId is missing" ); - } - catch ( DiscovererException e ) - { - // excellent - } - } - - public void testNoType() - throws ComponentLookupException, DiscovererException - { - try - { - discoverer.buildArtifact( "invalid/invalid/1/invalid-1" ); - - fail( "Artifact should be null for no type" ); - } - catch ( DiscovererException e ) - { - // excellent - } - } - - public void testSnapshot() - throws ComponentLookupException, DiscovererException - { - String testPath = "org.apache.maven.test/jars/maven-model-1.0-SNAPSHOT.jar"; - - Artifact artifact = discoverer.buildArtifact( testPath ); - - assertEquals( createArtifact( "org.apache.maven.test", "maven-model", "1.0-SNAPSHOT" ), artifact ); - } - - public void testFinal() - throws ComponentLookupException, DiscovererException - { - String testPath = "org.apache.maven.test/jars/maven-model-1.0-final-20060606.jar"; - - Artifact artifact = discoverer.buildArtifact( testPath ); - - assertEquals( createArtifact( "org.apache.maven.test", "maven-model", "1.0-final-20060606" ), artifact ); - } - - public void testNormal() - throws ComponentLookupException, DiscovererException - { - String testPath = "javax.sql/jars/jdbc-2.0.jar"; - - Artifact artifact = discoverer.buildArtifact( testPath ); - - assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact ); - } -} diff --git a/maven-repository-discovery/src/test/legacy-repository/KEYS b/maven-repository-discovery/src/test/legacy-repository/KEYS deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/legacy-repository/invalid/foo/invalid-1.0.foo b/maven-repository-discovery/src/test/legacy-repository/invalid/foo/invalid-1.0.foo deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/legacy-repository/invalid/invalid-1.0.jar b/maven-repository-discovery/src/test/legacy-repository/invalid/invalid-1.0.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/legacy-repository/invalid/jars/1.0/invalid-1.0.jar b/maven-repository-discovery/src/test/legacy-repository/invalid/jars/1.0/invalid-1.0.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/legacy-repository/invalid/jars/invalid-1.0.rar b/maven-repository-discovery/src/test/legacy-repository/invalid/jars/invalid-1.0.rar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/legacy-repository/invalid/jars/invalid.jar b/maven-repository-discovery/src/test/legacy-repository/invalid/jars/invalid.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/legacy-repository/invalid/jars/no-extension b/maven-repository-discovery/src/test/legacy-repository/invalid/jars/no-extension deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/legacy-repository/javax.sql/jars/jdbc-2.0.jar b/maven-repository-discovery/src/test/legacy-repository/javax.sql/jars/jdbc-2.0.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/legacy-repository/org.apache.maven.update/jars/test-not-updated-1.0.jar b/maven-repository-discovery/src/test/legacy-repository/org.apache.maven.update/jars/test-not-updated-1.0.jar deleted file mode 100644 index 54d190b23..000000000 --- a/maven-repository-discovery/src/test/legacy-repository/org.apache.maven.update/jars/test-not-updated-1.0.jar +++ /dev/null @@ -1 +0,0 @@ -dummy content. sample file only. diff --git a/maven-repository-discovery/src/test/legacy-repository/org.apache.maven.update/jars/test-updated-1.0.jar b/maven-repository-discovery/src/test/legacy-repository/org.apache.maven.update/jars/test-updated-1.0.jar deleted file mode 100644 index 54d190b23..000000000 --- a/maven-repository-discovery/src/test/legacy-repository/org.apache.maven.update/jars/test-updated-1.0.jar +++ /dev/null @@ -1 +0,0 @@ -dummy content. sample file only. diff --git a/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/some-ejb-1.0-client.jar b/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/some-ejb-1.0-client.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0-20050611.112233-1.jar b/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0-20050611.112233-1.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0-sources.jar b/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0-sources.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0.jar b/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0.tar.gz b/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0.tar.gz deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0.zip b/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0.zip deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-UNKNOWN.jar b/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-UNKNOWN.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/A/1.0/A-1.0.pom b/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/A/1.0/A-1.0.pom deleted file mode 100644 index 411d77c7d..000000000 --- a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/A/1.0/A-1.0.pom +++ /dev/null @@ -1,9 +0,0 @@ - - 4.0.0 - org.apache.maven - A - 1.0 - Maven Test Repository Artifact Discovery - war - diff --git a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/A/1.0/A-1.0.war b/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/A/1.0/A-1.0.war deleted file mode 100644 index 54d190b23..000000000 --- a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/A/1.0/A-1.0.war +++ /dev/null @@ -1 +0,0 @@ -dummy content. sample file only. diff --git a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/B/1.0/B-1.0.pom b/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/B/1.0/B-1.0.pom deleted file mode 100644 index 35641a048..000000000 --- a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/B/1.0/B-1.0.pom +++ /dev/null @@ -1,9 +0,0 @@ - - 4.0.0 - org.apache.maven - B - 1.0 - Maven Test Repository Artifact Discovery - pom - diff --git a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/B/2.0/B-2.0.pom b/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/B/2.0/B-2.0.pom deleted file mode 100644 index 6ab1e498b..000000000 --- a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/B/2.0/B-2.0.pom +++ /dev/null @@ -1,9 +0,0 @@ - - 4.0.0 - org.apache.maven - B - 2.0 - Maven Test Repository Artifact Discovery - pom - diff --git a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/C/1.0/C-1.0.pom b/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/C/1.0/C-1.0.pom deleted file mode 100644 index 867de41f0..000000000 --- a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/C/1.0/C-1.0.pom +++ /dev/null @@ -1,9 +0,0 @@ - - 4.0.0 - org.apache.maven - C - 1.0 - Maven Test Repository Artifact Discovery - war - diff --git a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/C/1.0/C-1.0.war b/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/C/1.0/C-1.0.war deleted file mode 100644 index 54d190b23..000000000 --- a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/C/1.0/C-1.0.war +++ /dev/null @@ -1 +0,0 @@ -dummy content. sample file only. diff --git a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/discovery/1.0/discovery-1.0.pom b/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/discovery/1.0/discovery-1.0.pom deleted file mode 100644 index 4dfd1f4e5..000000000 --- a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/discovery/1.0/discovery-1.0.pom +++ /dev/null @@ -1,9 +0,0 @@ - - 4.0.0 - org.apache.maven - discovery - 1.0 - Maven Test Repository Artifact Discovery - pom - diff --git a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/samplejar/1.0/samplejar-1.0.jar b/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/samplejar/1.0/samplejar-1.0.jar deleted file mode 100644 index 54d190b23..000000000 --- a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/samplejar/1.0/samplejar-1.0.jar +++ /dev/null @@ -1 +0,0 @@ -dummy content. sample file only. diff --git a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/samplejar/1.0/samplejar-1.0.pom b/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/samplejar/1.0/samplejar-1.0.pom deleted file mode 100644 index 51d5e433c..000000000 --- a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/samplejar/1.0/samplejar-1.0.pom +++ /dev/null @@ -1,10 +0,0 @@ - - 4.0.0 - org.apache.maven - C - 1.0 - Maven Test Repository Artifact Discovery - - - diff --git a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/samplejar/2.0/samplejar-2.0.jar b/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/samplejar/2.0/samplejar-2.0.jar deleted file mode 100644 index 54d190b23..000000000 --- a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/samplejar/2.0/samplejar-2.0.jar +++ /dev/null @@ -1 +0,0 @@ -dummy content. sample file only. diff --git a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/samplejar/2.0/samplejar-2.0.pom b/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/samplejar/2.0/samplejar-2.0.pom deleted file mode 100644 index c6f89f932..000000000 --- a/maven-repository-discovery/src/test/pom-artifacts/org/apache/maven/samplejar/2.0/samplejar-2.0.pom +++ /dev/null @@ -1,10 +0,0 @@ - - 4.0.0 - org.apache.maven - C - 1.0 - Maven Test Repository Artifact Discovery - - jar - diff --git a/maven-repository-discovery/src/test/pom-artifacts/org/apache/testgroup/discovery/1.0/discovery-1.0.pom b/maven-repository-discovery/src/test/pom-artifacts/org/apache/testgroup/discovery/1.0/discovery-1.0.pom deleted file mode 100644 index ac5ca14b3..000000000 --- a/maven-repository-discovery/src/test/pom-artifacts/org/apache/testgroup/discovery/1.0/discovery-1.0.pom +++ /dev/null @@ -1,9 +0,0 @@ - - 4.0.0 - org.apache.testgroup - discovery - 1.0 - Maven Test Repository Artifact Discovery - pom - diff --git a/maven-repository-discovery/src/test/repository/KEYS b/maven-repository-discovery/src/test/repository/KEYS deleted file mode 100644 index d3b34d5ad..000000000 --- a/maven-repository-discovery/src/test/repository/KEYS +++ /dev/null @@ -1 +0,0 @@ -test KEYS file \ No newline at end of file diff --git a/maven-repository-discovery/src/test/repository/invalid/invalid-1.0.jar b/maven-repository-discovery/src/test/repository/invalid/invalid-1.0.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar b/maven-repository-discovery/src/test/repository/invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar b/maven-repository-discovery/src/test/repository/invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/invalid/invalid/1.0/invalid-1.0b.jar b/maven-repository-discovery/src/test/repository/invalid/invalid/1.0/invalid-1.0b.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/invalid/invalid/1.0/invalid-2.0.jar b/maven-repository-discovery/src/test/repository/invalid/invalid/1.0/invalid-2.0.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/invalid/invalid/1/invalid-1 b/maven-repository-discovery/src/test/repository/invalid/invalid/1/invalid-1 deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/javax/maven-metadata.xml b/maven-repository-discovery/src/test/repository/javax/maven-metadata.xml deleted file mode 100644 index 17775863b..000000000 --- a/maven-repository-discovery/src/test/repository/javax/maven-metadata.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - javax.sql - jdbc - 2.0 - diff --git a/maven-repository-discovery/src/test/repository/javax/sql/jdbc/2.0/jdbc-2.0.jar b/maven-repository-discovery/src/test/repository/javax/sql/jdbc/2.0/jdbc-2.0.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/javax/sql/jdbc/2.0/maven-metadata-repository.xml b/maven-repository-discovery/src/test/repository/javax/sql/jdbc/2.0/maven-metadata-repository.xml deleted file mode 100644 index 17775863b..000000000 --- a/maven-repository-discovery/src/test/repository/javax/sql/jdbc/2.0/maven-metadata-repository.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - javax.sql - jdbc - 2.0 - diff --git a/maven-repository-discovery/src/test/repository/javax/sql/jdbc/maven-metadata-repository.xml b/maven-repository-discovery/src/test/repository/javax/sql/jdbc/maven-metadata-repository.xml deleted file mode 100644 index 214b7dc28..000000000 --- a/maven-repository-discovery/src/test/repository/javax/sql/jdbc/maven-metadata-repository.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - javax.sql - jdbc - 2.0 - - - 2.0 - - - diff --git a/maven-repository-discovery/src/test/repository/javax/sql/maven-metadata-repository.xml b/maven-repository-discovery/src/test/repository/javax/sql/maven-metadata-repository.xml deleted file mode 100644 index 17775863b..000000000 --- a/maven-repository-discovery/src/test/repository/javax/sql/maven-metadata-repository.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - javax.sql - jdbc - 2.0 - diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/A/1.0/A-1.0.pom b/maven-repository-discovery/src/test/repository/org/apache/maven/A/1.0/A-1.0.pom deleted file mode 100644 index 411d77c7d..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/A/1.0/A-1.0.pom +++ /dev/null @@ -1,9 +0,0 @@ - - 4.0.0 - org.apache.maven - A - 1.0 - Maven Test Repository Artifact Discovery - war - diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/A/1.0/A-1.0.war b/maven-repository-discovery/src/test/repository/org/apache/maven/A/1.0/A-1.0.war deleted file mode 100644 index 54d190b23..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/A/1.0/A-1.0.war +++ /dev/null @@ -1 +0,0 @@ -dummy content. sample file only. diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/B/1.0/B-1.0.pom b/maven-repository-discovery/src/test/repository/org/apache/maven/B/1.0/B-1.0.pom deleted file mode 100644 index 35641a048..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/B/1.0/B-1.0.pom +++ /dev/null @@ -1,9 +0,0 @@ - - 4.0.0 - org.apache.maven - B - 1.0 - Maven Test Repository Artifact Discovery - pom - diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/B/2.0/B-2.0.pom b/maven-repository-discovery/src/test/repository/org/apache/maven/B/2.0/B-2.0.pom deleted file mode 100644 index 6ab1e498b..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/B/2.0/B-2.0.pom +++ /dev/null @@ -1,9 +0,0 @@ - - 4.0.0 - org.apache.maven - B - 2.0 - Maven Test Repository Artifact Discovery - pom - diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/C/1.0/C-1.0.pom b/maven-repository-discovery/src/test/repository/org/apache/maven/C/1.0/C-1.0.pom deleted file mode 100644 index 867de41f0..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/C/1.0/C-1.0.pom +++ /dev/null @@ -1,9 +0,0 @@ - - 4.0.0 - org.apache.maven - C - 1.0 - Maven Test Repository Artifact Discovery - war - diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/C/1.0/C-1.0.war b/maven-repository-discovery/src/test/repository/org/apache/maven/C/1.0/C-1.0.war deleted file mode 100644 index 54d190b23..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/C/1.0/C-1.0.war +++ /dev/null @@ -1 +0,0 @@ -dummy content. sample file only. diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/discovery/1.0/discovery-1.0.pom b/maven-repository-discovery/src/test/repository/org/apache/maven/discovery/1.0/discovery-1.0.pom deleted file mode 100644 index 4dfd1f4e5..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/discovery/1.0/discovery-1.0.pom +++ /dev/null @@ -1,9 +0,0 @@ - - 4.0.0 - org.apache.maven - discovery - 1.0 - Maven Test Repository Artifact Discovery - pom - diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/maven-metadata.xml b/maven-repository-discovery/src/test/repository/org/apache/maven/maven-metadata.xml deleted file mode 100644 index 22f46c19b..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/maven-metadata.xml +++ /dev/null @@ -1,3 +0,0 @@ - - org.apache.maven - \ No newline at end of file diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar deleted file mode 100644 index 54d190b23..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar +++ /dev/null @@ -1 +0,0 @@ -dummy content. sample file only. diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/samplejar/1.0/samplejar-1.0.pom b/maven-repository-discovery/src/test/repository/org/apache/maven/samplejar/1.0/samplejar-1.0.pom deleted file mode 100644 index 51d5e433c..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/samplejar/1.0/samplejar-1.0.pom +++ /dev/null @@ -1,10 +0,0 @@ - - 4.0.0 - org.apache.maven - C - 1.0 - Maven Test Repository Artifact Discovery - - - diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/samplejar/2.0/samplejar-2.0.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/samplejar/2.0/samplejar-2.0.jar deleted file mode 100644 index 54d190b23..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/samplejar/2.0/samplejar-2.0.jar +++ /dev/null @@ -1 +0,0 @@ -dummy content. sample file only. diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/samplejar/2.0/samplejar-2.0.pom b/maven-repository-discovery/src/test/repository/org/apache/maven/samplejar/2.0/samplejar-2.0.pom deleted file mode 100644 index c6f89f932..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/samplejar/2.0/samplejar-2.0.pom +++ /dev/null @@ -1,10 +0,0 @@ - - 4.0.0 - org.apache.maven - C - 1.0 - Maven Test Repository Artifact Discovery - - jar - diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/some-ejb/1.0/maven-metadata.xml b/maven-repository-discovery/src/test/repository/org/apache/maven/some-ejb/1.0/maven-metadata.xml deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1-javadoc.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1-javadoc.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0-sources.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0-sources.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.tar.gz b/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.tar.gz deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.zip b/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.zip deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.jar deleted file mode 100644 index 54d190b23..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.jar +++ /dev/null @@ -1 +0,0 @@ -dummy content. sample file only. diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.pom b/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.pom deleted file mode 100644 index 21bef0276..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.pom +++ /dev/null @@ -1,10 +0,0 @@ - - 4.0.0 - org.apache.maven.update - test-not-updated - 1.0 - Maven Test Repository Artifact Discovery - - - diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-not-updated/maven-metadata.xml b/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-not-updated/maven-metadata.xml deleted file mode 100644 index 71fc9790f..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-not-updated/maven-metadata.xml +++ /dev/null @@ -1,4 +0,0 @@ - - org.apache.maven.update - test-not-updated - \ No newline at end of file diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-updated/1.0/test-updated-1.0.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-updated/1.0/test-updated-1.0.jar deleted file mode 100644 index 54d190b23..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-updated/1.0/test-updated-1.0.jar +++ /dev/null @@ -1 +0,0 @@ -dummy content. sample file only. diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-updated/1.0/test-updated-1.0.pom b/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-updated/1.0/test-updated-1.0.pom deleted file mode 100644 index 5f88c44df..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-updated/1.0/test-updated-1.0.pom +++ /dev/null @@ -1,10 +0,0 @@ - - 4.0.0 - org.apache.maven.update - test-updated - 1.0 - Maven Test Repository Artifact Discovery - - - diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-updated/maven-metadata.xml b/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-updated/maven-metadata.xml deleted file mode 100644 index fc17a16d7..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/update/test-updated/maven-metadata.xml +++ /dev/null @@ -1,4 +0,0 @@ - - org.apache.maven.update - test-updated - \ No newline at end of file diff --git a/maven-repository-discovery/src/test/repository/org/apache/testgroup/discovery/1.0/discovery-1.0.pom b/maven-repository-discovery/src/test/repository/org/apache/testgroup/discovery/1.0/discovery-1.0.pom deleted file mode 100644 index ac5ca14b3..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/testgroup/discovery/1.0/discovery-1.0.pom +++ /dev/null @@ -1,9 +0,0 @@ - - 4.0.0 - org.apache.testgroup - discovery - 1.0 - Maven Test Repository Artifact Discovery - pom - diff --git a/maven-repository-discovery/src/test/repository/org/apache/testgroup/discovery/1.0/maven-metadata.xml b/maven-repository-discovery/src/test/repository/org/apache/testgroup/discovery/1.0/maven-metadata.xml deleted file mode 100644 index 9bb9b5a58..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/testgroup/discovery/1.0/maven-metadata.xml +++ /dev/null @@ -1,5 +0,0 @@ - - org.apache.testgroup - discovery - 1.0 - \ No newline at end of file diff --git a/maven-repository-discovery/src/test/repository/org/apache/testgroup/discovery/maven-metadata.xml b/maven-repository-discovery/src/test/repository/org/apache/testgroup/discovery/maven-metadata.xml deleted file mode 100644 index 50215f42b..000000000 --- a/maven-repository-discovery/src/test/repository/org/apache/testgroup/discovery/maven-metadata.xml +++ /dev/null @@ -1,4 +0,0 @@ - - org.apache.testgroup - discovery - \ No newline at end of file diff --git a/maven-repository-indexer/pom.xml b/maven-repository-indexer/pom.xml deleted file mode 100644 index 430b63565..000000000 --- a/maven-repository-indexer/pom.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - - org.apache.maven.repository - maven-repository-manager - 1.0-SNAPSHOT - - 4.0.0 - maven-repository-indexer - Maven Repository Indexer - - - org.apache.maven - maven-artifact - - - org.apache.maven - maven-artifact-manager - - - org.apache.maven - maven-project - - - org.apache.maven - maven-model - - - org.apache.lucene - lucene-core - 2.0.0 - - - org.codehaus.plexus - plexus-utils - - - org.codehaus.plexus - plexus-container-default - - - org.apache.maven.repository - maven-repository-utils - - - org.apache.maven - maven-repository-metadata - - - - - - org.codehaus.mojo - cobertura-maven-plugin - - - - 80 - 80 - - - - - - diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java deleted file mode 100644 index 03803ed53..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndex.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.apache.maven.repository.indexing; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.repository.indexing.query.Query; - -import java.util.Collection; -import java.util.List; - -/** - * Maintain an artifact index on the repository. - * - * @author Brett Porter - */ -public interface RepositoryArtifactIndex -{ - /** - * Indexes the artifacts found within the specified list of index records. If the artifacts are already in the - * repository they are updated. - * - * @param records the artifacts to index - * @throws RepositoryIndexException if there is a problem indexing the records - */ - void indexRecords( Collection records ) - throws RepositoryIndexException; - - /** - * Search the index based on the search criteria specified. Returns a list of index records. - * - * @param query The query that contains the search criteria - * @return the index records found - * @throws RepositoryIndexSearchException if there is a problem searching - * @todo should it return "SearchResult" instances that contain the index record and other search data (like score?) - */ - List search( Query query ) - throws RepositoryIndexSearchException; - - /** - * Check if the index already exists. - * - * @return true if the index already exists - * @throws RepositoryIndexException if the index location is not valid - */ - boolean exists() - throws RepositoryIndexException; - - /** - * Delete records from the index. Simply ignore the request any did not exist. - * - * @param records the records to delete - * @throws RepositoryIndexException if there is a problem removing the record - */ - void deleteRecords( Collection records ) - throws RepositoryIndexException; -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndexFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndexFactory.java deleted file mode 100644 index ed0100527..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryArtifactIndexFactory.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.apache.maven.repository.indexing; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 java.io.File; - -/** - * Obtain an index instance. - * - * @author Brett Porter - */ -public interface RepositoryArtifactIndexFactory -{ - /** - * Plexus role. - */ - String ROLE = RepositoryArtifactIndexFactory.class.getName(); - - /** - * Method to create an instance of the standard index. - * - * @param indexPath the path where the index will be created/updated - * @return the index instance - */ - RepositoryArtifactIndex createStandardIndex( File indexPath ); - - /** - * Method to create an instance of the minimal index. - * - * @param indexPath the path where the index will be created/updated - * @return the index instance - */ - RepositoryArtifactIndex createMinimalIndex( File indexPath ); -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexException.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexException.java deleted file mode 100644 index fe16c022c..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexException.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.maven.repository.indexing; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * @author Edwin Punzalan - */ -public class RepositoryIndexException - extends Exception -{ - public RepositoryIndexException( String message, Throwable cause ) - { - super( message, cause ); - } - - public RepositoryIndexException( String message ) - { - super( message ); - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java deleted file mode 100644 index cd84bde19..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apache.maven.repository.indexing; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * @author Brett Porter - */ -public class RepositoryIndexSearchException - extends Exception -{ - public RepositoryIndexSearchException( String message, Throwable cause ) - { - super( message, cause ); - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneIndexRecordConverter.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneIndexRecordConverter.java deleted file mode 100644 index 7aaf123e3..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneIndexRecordConverter.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.apache.maven.repository.indexing.lucene; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.lucene.document.Document; -import org.apache.maven.repository.indexing.record.RepositoryIndexRecord; - -import java.text.ParseException; - -/** - * Converts repository records to Lucene documents. - * - * @author Brett Porter - */ -public interface LuceneIndexRecordConverter -{ - /** - * Convert an index record to a Lucene document. - * - * @param record the record - * @return the document - */ - Document convert( RepositoryIndexRecord record ); - - /** - * Convert a Lucene document to an index record. - * - * @param document the document - * @return the record - * @throws java.text.ParseException if there is a problem parsing a field (specifically, dates) - */ - RepositoryIndexRecord convert( Document document ) - throws ParseException; -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalIndexRecordConverter.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalIndexRecordConverter.java deleted file mode 100644 index 02def2dbd..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalIndexRecordConverter.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.apache.maven.repository.indexing.lucene; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.lucene.document.DateTools; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.NumberTools; -import org.apache.maven.repository.indexing.record.MinimalArtifactIndexRecord; -import org.apache.maven.repository.indexing.record.MinimalIndexRecordFields; -import org.apache.maven.repository.indexing.record.RepositoryIndexRecord; -import org.codehaus.plexus.util.StringUtils; - -import java.text.ParseException; -import java.util.Arrays; - -/** - * Convert the minimal index record to a Lucene document. - * - * @author Brett Porter - */ -public class LuceneMinimalIndexRecordConverter - implements LuceneIndexRecordConverter -{ - public Document convert( RepositoryIndexRecord record ) - { - MinimalArtifactIndexRecord rec = (MinimalArtifactIndexRecord) record; - - Document document = new Document(); - addTokenizedField( document, MinimalIndexRecordFields.FILENAME, rec.getFilename() ); - addUntokenizedField( document, MinimalIndexRecordFields.LAST_MODIFIED, - DateTools.timeToString( rec.getLastModified(), DateTools.Resolution.SECOND ) ); - addUntokenizedField( document, MinimalIndexRecordFields.FILE_SIZE, NumberTools.longToString( rec.getSize() ) ); - addUntokenizedField( document, MinimalIndexRecordFields.MD5, rec.getMd5Checksum() ); - addTokenizedField( document, MinimalIndexRecordFields.CLASSES, - StringUtils.join( rec.getClasses().iterator(), "\n" ) ); - - return document; - } - - public RepositoryIndexRecord convert( Document document ) - throws ParseException - { - MinimalArtifactIndexRecord record = new MinimalArtifactIndexRecord(); - - record.setFilename( document.get( MinimalIndexRecordFields.FILENAME ) ); - record.setLastModified( DateTools.stringToTime( document.get( MinimalIndexRecordFields.LAST_MODIFIED ) ) ); - record.setSize( NumberTools.stringToLong( document.get( MinimalIndexRecordFields.FILE_SIZE ) ) ); - record.setMd5Checksum( document.get( MinimalIndexRecordFields.MD5 ) ); - record.setClasses( Arrays.asList( document.get( MinimalIndexRecordFields.CLASSES ).split( "\n" ) ) ); - - return record; - } - - private static void addUntokenizedField( Document document, String name, String value ) - { - if ( value != null ) - { - document.add( new Field( name, value, Field.Store.YES, Field.Index.UN_TOKENIZED ) ); - } - } - - private static void addTokenizedField( Document document, String name, String value ) - { - if ( value != null ) - { - document.add( new Field( name, value, Field.Store.YES, Field.Index.TOKENIZED ) ); - } - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneQuery.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneQuery.java deleted file mode 100644 index 13fdcaf5c..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneQuery.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.apache.maven.repository.indexing.lucene; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.repository.indexing.query.Query; - -/** - * A holder for a lucene query to pass to the indexer API. - * - * @author Brett Porter - */ -public class LuceneQuery - implements Query -{ - private final org.apache.lucene.search.Query query; - - public LuceneQuery( org.apache.lucene.search.Query query ) - { - this.query = query; - } - - org.apache.lucene.search.Query getLuceneQuery() - { - return query; - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java deleted file mode 100644 index dff648ec5..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndex.java +++ /dev/null @@ -1,276 +0,0 @@ -package org.apache.maven.repository.indexing.lucene; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.lucene.analysis.Analyzer; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.Term; -import org.apache.lucene.search.Hits; -import org.apache.lucene.search.IndexSearcher; -import org.apache.maven.repository.indexing.RepositoryArtifactIndex; -import org.apache.maven.repository.indexing.RepositoryIndexException; -import org.apache.maven.repository.indexing.RepositoryIndexSearchException; -import org.apache.maven.repository.indexing.query.Query; -import org.apache.maven.repository.indexing.record.RepositoryIndexRecord; - -import java.io.File; -import java.io.IOException; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -/** - * Lucene implementation of a repository index. - * - * @author Brett Porter - */ -public class LuceneRepositoryArtifactIndex - implements RepositoryArtifactIndex -{ - /** - * The location of the index on the file system. - */ - private File indexLocation; - - /** - * Convert repository records to Lucene documents. - */ - private LuceneIndexRecordConverter converter; - - private static final String FLD_PK = "pk"; - - public LuceneRepositoryArtifactIndex( File indexPath, LuceneIndexRecordConverter converter ) - { - this.indexLocation = indexPath; - this.converter = converter; - } - - public void indexRecords( Collection records ) - throws RepositoryIndexException - { - deleteRecords( records ); - - addRecords( records ); - } - - private void addRecords( Collection records ) - throws RepositoryIndexException - { - IndexWriter indexWriter; - try - { - indexWriter = new IndexWriter( indexLocation, getAnalyzer(), !exists() ); - } - catch ( IOException e ) - { - throw new RepositoryIndexException( "Unable to open index", e ); - } - - try - { - for ( Iterator i = records.iterator(); i.hasNext(); ) - { - RepositoryIndexRecord record = (RepositoryIndexRecord) i.next(); - - if ( record != null ) - { - Document document = converter.convert( record ); - document.add( - new Field( FLD_PK, record.getPrimaryKey(), Field.Store.NO, Field.Index.UN_TOKENIZED ) ); - - indexWriter.addDocument( document ); - } - } - - indexWriter.optimize(); - } - catch ( IOException e ) - { - throw new RepositoryIndexException( "Failed to add an index document", e ); - } - finally - { - close( indexWriter ); - } - } - - private void close( IndexWriter indexWriter ) - throws RepositoryIndexException - { - try - { - if ( indexWriter != null ) - { - indexWriter.close(); - } - } - catch ( IOException e ) - { - throw new RepositoryIndexException( e.getMessage(), e ); - } - } - - private Analyzer getAnalyzer() - { - // TODO: investigate why changed in original! Probably for MD5 and number querying. - return new StandardAnalyzer(); - } - - public void deleteRecords( Collection records ) - throws RepositoryIndexException - { - if ( exists() ) - { - IndexReader indexReader = null; - try - { - indexReader = IndexReader.open( indexLocation ); - - for ( Iterator artifacts = records.iterator(); artifacts.hasNext(); ) - { - RepositoryIndexRecord record = (RepositoryIndexRecord) artifacts.next(); - - if ( record != null ) - { - Term term = new Term( FLD_PK, record.getPrimaryKey() ); - - indexReader.deleteDocuments( term ); - } - } - } - catch ( IOException e ) - { - throw new RepositoryIndexException( "Error deleting document: " + e.getMessage(), e ); - } - finally - { - if ( indexReader != null ) - { - closeQuietly( indexReader ); - } - } - } - } - - public boolean exists() - throws RepositoryIndexException - { - if ( IndexReader.indexExists( indexLocation ) ) - { - return true; - } - else if ( !indexLocation.exists() ) - { - return false; - } - else if ( indexLocation.isDirectory() ) - { - if ( indexLocation.listFiles().length > 1 ) - { - throw new RepositoryIndexException( indexLocation + " is not a valid index directory." ); - } - else - { - return false; - } - } - else - { - throw new RepositoryIndexException( indexLocation + " is not a directory." ); - } - } - - public List search( Query query ) - throws RepositoryIndexSearchException - { - LuceneQuery lQuery = (LuceneQuery) query; - - org.apache.lucene.search.Query luceneQuery = lQuery.getLuceneQuery(); - - IndexSearcher searcher; - try - { - searcher = new IndexSearcher( indexLocation.getAbsolutePath() ); - } - catch ( IOException e ) - { - throw new RepositoryIndexSearchException( "Unable to open index: " + e.getMessage(), e ); - } - - List records = new ArrayList(); - try - { - Hits hits = searcher.search( luceneQuery ); - for ( int i = 0; i < hits.length(); i++ ) - { - Document doc = hits.doc( i ); - - records.add( converter.convert( doc ) ); - } - } - catch ( IOException e ) - { - throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e ); - } - catch ( ParseException e ) - { - throw new RepositoryIndexSearchException( "Unable to search index: " + e.getMessage(), e ); - } - finally - { - closeQuietly( searcher ); - } - - return records; - } - - private static void closeQuietly( IndexSearcher searcher ) - { - try - { - if ( searcher != null ) - { - searcher.close(); - } - } - catch ( IOException e ) - { - // ignore - } - } - - private static void closeQuietly( IndexReader reader ) - { - try - { - if ( reader != null ) - { - reader.close(); - } - } - catch ( IOException e ) - { - // ignore - } - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndexFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndexFactory.java deleted file mode 100644 index 97278b009..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneRepositoryArtifactIndexFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.apache.maven.repository.indexing.lucene; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.repository.indexing.RepositoryArtifactIndex; -import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; - -import java.io.File; - -/** - * Factory for Lucene artifact index instances. - * - * @author Brett Porter - * @plexus.component role="org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory" role-hint="lucene" - */ -public class LuceneRepositoryArtifactIndexFactory - implements RepositoryArtifactIndexFactory -{ - public RepositoryArtifactIndex createStandardIndex( File indexPath ) - { - return new LuceneRepositoryArtifactIndex( indexPath, new LuceneStandardIndexRecordConverter() ); - } - - public RepositoryArtifactIndex createMinimalIndex( File indexPath ) - { - return new LuceneRepositoryArtifactIndex( indexPath, new LuceneMinimalIndexRecordConverter() ); - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneStandardIndexRecordConverter.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneStandardIndexRecordConverter.java deleted file mode 100644 index f8f6a53b2..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/lucene/LuceneStandardIndexRecordConverter.java +++ /dev/null @@ -1,145 +0,0 @@ -package org.apache.maven.repository.indexing.lucene; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.lucene.document.DateTools; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.NumberTools; -import org.apache.maven.repository.indexing.record.RepositoryIndexRecord; -import org.apache.maven.repository.indexing.record.StandardArtifactIndexRecord; -import org.apache.maven.repository.indexing.record.StandardIndexRecordFields; -import org.codehaus.plexus.util.StringUtils; - -import java.text.ParseException; -import java.util.Arrays; - -/** - * Convert the standard index record to a Lucene document. - * - * @author Brett Porter - */ -public class LuceneStandardIndexRecordConverter - implements LuceneIndexRecordConverter -{ - public Document convert( RepositoryIndexRecord record ) - { - StandardArtifactIndexRecord rec = (StandardArtifactIndexRecord) record; - - Document document = new Document(); - addTokenizedField( document, StandardIndexRecordFields.FILENAME, rec.getFilename() ); - addTokenizedField( document, StandardIndexRecordFields.GROUPID, rec.getGroupId() ); - addExactField( document, StandardIndexRecordFields.GROUPID_EXACT, rec.getGroupId() ); - addTokenizedField( document, StandardIndexRecordFields.ARTIFACTID, rec.getArtifactId() ); - addExactField( document, StandardIndexRecordFields.ARTIFACTID_EXACT, rec.getArtifactId() ); - addTokenizedField( document, StandardIndexRecordFields.VERSION, rec.getVersion() ); - addExactField( document, StandardIndexRecordFields.VERSION_EXACT, rec.getVersion() ); - addTokenizedField( document, StandardIndexRecordFields.BASE_VERSION, rec.getBaseVersion() ); - addExactField( document, StandardIndexRecordFields.BASE_VERSION_EXACT, rec.getBaseVersion() ); - addUntokenizedField( document, StandardIndexRecordFields.TYPE, rec.getType() ); - addTokenizedField( document, StandardIndexRecordFields.CLASSIFIER, rec.getClassifier() ); - addUntokenizedField( document, StandardIndexRecordFields.PACKAGING, rec.getPackaging() ); - addUntokenizedField( document, StandardIndexRecordFields.REPOSITORY, rec.getRepository() ); - addUntokenizedField( document, StandardIndexRecordFields.LAST_MODIFIED, - DateTools.timeToString( rec.getLastModified(), DateTools.Resolution.SECOND ) ); - addUntokenizedField( document, StandardIndexRecordFields.FILE_SIZE, NumberTools.longToString( rec.getSize() ) ); - addUntokenizedField( document, StandardIndexRecordFields.MD5, rec.getMd5Checksum() ); - addUntokenizedField( document, StandardIndexRecordFields.SHA1, rec.getSha1Checksum() ); - if ( rec.getClasses() != null ) - { - addTokenizedField( document, StandardIndexRecordFields.CLASSES, - StringUtils.join( rec.getClasses().iterator(), "\n" ) ); - } - if ( rec.getFiles() != null ) - { - addTokenizedField( document, StandardIndexRecordFields.FILES, - StringUtils.join( rec.getFiles().iterator(), "\n" ) ); - } - addUntokenizedField( document, StandardIndexRecordFields.PLUGIN_PREFIX, rec.getPluginPrefix() ); - addUntokenizedField( document, StandardIndexRecordFields.INCEPTION_YEAR, rec.getInceptionYear() ); - addTokenizedField( document, StandardIndexRecordFields.PROJECT_NAME, rec.getProjectName() ); - addTokenizedField( document, StandardIndexRecordFields.PROJECT_DESCRIPTION, rec.getProjectDescription() ); -/* TODO: add later - document.add( Field.Keyword( StandardIndexRecordFields.FLD_LICENSE_URLS, "" ) ); - document.add( Field.Keyword( StandardIndexRecordFields.FLD_DEPENDENCIES, "" ) ); - document.add( Field.Keyword( StandardIndexRecordFields.FLD_PLUGINS_REPORT, "" ) ); - document.add( Field.Keyword( StandardIndexRecordFields.FLD_PLUGINS_BUILD, "" ) ); -*/ - - return document; - } - - public RepositoryIndexRecord convert( Document document ) - throws ParseException - { - StandardArtifactIndexRecord record = new StandardArtifactIndexRecord(); - - record.setFilename( document.get( StandardIndexRecordFields.FILENAME ) ); - record.setGroupId( document.get( StandardIndexRecordFields.GROUPID ) ); - record.setArtifactId( document.get( StandardIndexRecordFields.ARTIFACTID ) ); - record.setVersion( document.get( StandardIndexRecordFields.VERSION ) ); - record.setBaseVersion( document.get( StandardIndexRecordFields.BASE_VERSION ) ); - record.setType( document.get( StandardIndexRecordFields.TYPE ) ); - record.setClassifier( document.get( StandardIndexRecordFields.CLASSIFIER ) ); - record.setPackaging( document.get( StandardIndexRecordFields.PACKAGING ) ); - record.setRepository( document.get( StandardIndexRecordFields.REPOSITORY ) ); - record.setLastModified( DateTools.stringToTime( document.get( StandardIndexRecordFields.LAST_MODIFIED ) ) ); - record.setSize( NumberTools.stringToLong( document.get( StandardIndexRecordFields.FILE_SIZE ) ) ); - record.setMd5Checksum( document.get( StandardIndexRecordFields.MD5 ) ); - record.setSha1Checksum( document.get( StandardIndexRecordFields.SHA1 ) ); - String classes = document.get( StandardIndexRecordFields.CLASSES ); - if ( classes != null ) - { - record.setClasses( Arrays.asList( classes.split( "\n" ) ) ); - } - String files = document.get( StandardIndexRecordFields.FILES ); - if ( files != null ) - { - record.setFiles( Arrays.asList( files.split( "\n" ) ) ); - } - record.setPluginPrefix( document.get( StandardIndexRecordFields.PLUGIN_PREFIX ) ); - record.setInceptionYear( document.get( StandardIndexRecordFields.INCEPTION_YEAR ) ); - record.setProjectName( document.get( StandardIndexRecordFields.PROJECT_NAME ) ); - record.setProjectDescription( document.get( StandardIndexRecordFields.PROJECT_DESCRIPTION ) ); - - return record; - } - - private static void addUntokenizedField( Document document, String name, String value ) - { - if ( value != null ) - { - document.add( new Field( name, value, Field.Store.YES, Field.Index.UN_TOKENIZED ) ); - } - } - - private static void addExactField( Document document, String name, String value ) - { - if ( value != null ) - { - document.add( new Field( name, value, Field.Store.NO, Field.Index.UN_TOKENIZED ) ); - } - } - - private static void addTokenizedField( Document document, String name, String value ) - { - if ( value != null ) - { - document.add( new Field( name, value, Field.Store.YES, Field.Index.TOKENIZED ) ); - } - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java deleted file mode 100644 index 85760b621..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQuery.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.apache.maven.repository.indexing.query; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 java.util.ArrayList; -import java.util.List; - -/** - * Class to hold multiple SinglePhraseQueries and/or other CompoundQueries. - * - * @author Edwin Punzalan - */ -public class CompoundQuery - implements Query -{ - /** - * The query terms. - */ - private final List compoundQueryTerms = new ArrayList(); - - /** - * Appends a required term to this query. - * - * @param term the term to be appended to this query - */ - public void and( QueryTerm term ) - { - compoundQueryTerms.add( CompoundQueryTerm.and( new SingleTermQuery( term ) ) ); - } - - /** - * Appends an optional term to this query. - * - * @param term the term to be appended to this query - */ - public void or( QueryTerm term ) - { - compoundQueryTerms.add( CompoundQueryTerm.or( new SingleTermQuery( term ) ) ); - } - - /** - * Appends a prohibited term to this query. - * - * @param term the term to be appended to this query - */ - public void not( QueryTerm term ) - { - compoundQueryTerms.add( CompoundQueryTerm.not( new SingleTermQuery( term ) ) ); - } - - /** - * Appends a required subquery to this query. - * - * @param query the subquery to be appended to this query - */ - public void and( Query query ) - { - compoundQueryTerms.add( CompoundQueryTerm.and( query ) ); - } - - /** - * Appends an optional subquery to this query. - * - * @param query the subquery to be appended to this query - */ - public void or( Query query ) - { - compoundQueryTerms.add( CompoundQueryTerm.or( query ) ); - } - - /** - * Appends a prohibited subquery to this query. - * - * @param query the subquery to be appended to this query - */ - public void not( Query query ) - { - compoundQueryTerms.add( CompoundQueryTerm.not( query ) ); - } - - /** - * Method to get the List of Queries appended into this - * - * @return List of all Queries added to this Query - */ - public List getCompoundQueryTerms() - { - return compoundQueryTerms; - } - -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java deleted file mode 100644 index abc99bd13..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/CompoundQueryTerm.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.apache.maven.repository.indexing.query; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * Base of all query terms. - * - * @author Brett Porter - */ -public class CompoundQueryTerm -{ - /** - * The query to add to the compound query. - */ - private final Query query; - - /** - * Whether the term is required (an AND). - */ - private final boolean required; - - /** - * Whether the term is prohibited (a NOT). - */ - private final boolean prohibited; - - /** - * Class constructor - * - * @param query the subquery to add - * @param required whether the term is required (an AND) - * @param prohibited whether the term is prohibited (a NOT) - */ - private CompoundQueryTerm( Query query, boolean required, boolean prohibited ) - { - this.query = query; - this.prohibited = prohibited; - this.required = required; - } - - /** - * Method to test if the Query is a search requirement - * - * @return true if this Query is a search requirement, otherwise returns false - */ - public boolean isRequired() - { - return required; - } - - /** - * Method to test if the Query is prohibited in the search result - * - * @return true if this Query is prohibited in the search result - */ - public boolean isProhibited() - { - return prohibited; - } - - - /** - * The subquery to execute. - * - * @return the query - */ - public Query getQuery() - { - return query; - } - - static CompoundQueryTerm and( Query query ) - { - return new CompoundQueryTerm( query, true, false ); - } - - static CompoundQueryTerm or( Query query ) - { - return new CompoundQueryTerm( query, false, false ); - } - - static CompoundQueryTerm not( Query query ) - { - return new CompoundQueryTerm( query, false, true ); - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/Query.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/Query.java deleted file mode 100644 index 2c6ac6137..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/Query.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apache.maven.repository.indexing.query; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * Interface to label the query classes - * - * @author Edwin Punzalan - */ -public interface Query -{ -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/QueryTerm.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/QueryTerm.java deleted file mode 100644 index 6db240b3a..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/QueryTerm.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.apache.maven.repository.indexing.query; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * Class to hold a single field search condition - * - * @author Edwin Punzalan - */ -public class QueryTerm -{ - private String field; - - private String value; - - /** - * Class constructor - * - * @param field the index field to search - * @param value the index value requirement - */ - public QueryTerm( String field, String value ) - { - this.field = field; - this.value = value; - } - - /** - * Method to retrieve the name of the index field searched - * - * @return the name of the index field - */ - public String getField() - { - return field; - } - - /** - * Method to retrieve the value used in searching the index field - * - * @return the value to corresspond the index field - */ - public String getValue() - { - return value; - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.java deleted file mode 100644 index 68e6d4a6a..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/RangeQuery.java +++ /dev/null @@ -1,150 +0,0 @@ -package org.apache.maven.repository.indexing.query; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * Query object that handles range queries (presently used for dates). - * - * @author Maria Odea Ching - * @author Brett Porter - */ -public class RangeQuery - implements Query -{ - /** - * Whether values equal to the boundaries are included in the query results. - */ - private final boolean inclusive; - - /** - * The lower bound. - */ - private final QueryTerm begin; - - /** - * The upper bound. - */ - private final QueryTerm end; - - /** - * Constructor. - * - * @param begin the lower bound - * @param end the upper bound - * @param inclusive whether to include the boundaries in the query - */ - private RangeQuery( QueryTerm begin, QueryTerm end, boolean inclusive ) - { - this.begin = begin; - this.end = end; - this.inclusive = inclusive; - } - - /** - * Create an open range, including all results. - * - * @return the query object - */ - public static RangeQuery createOpenRange() - { - return new RangeQuery( null, null, false ); - } - - /** - * Create a bounded range, excluding the endpoints. - * - * @param begin the lower bound value to compare to - * @param end the upper bound value to compare to - * @return the query object - */ - public static RangeQuery createExclusiveRange( QueryTerm begin, QueryTerm end ) - { - return new RangeQuery( begin, end, false ); - } - - /** - * Create a bounded range, including the endpoints. - * - * @param begin the lower bound value to compare to - * @param end the upper bound value to compare to - * @return the query object - */ - public static RangeQuery createInclusiveRange( QueryTerm begin, QueryTerm end ) - { - return new RangeQuery( begin, end, true ); - } - - /** - * Create a range that is greater than or equal to a given term. - * - * @param begin the value to compare to - * @return the query object - */ - public static RangeQuery createGreaterThanOrEqualToRange( QueryTerm begin ) - { - return new RangeQuery( begin, null, true ); - } - - /** - * Create a range that is greater than a given term. - * - * @param begin the value to compare to - * @return the query object - */ - public static RangeQuery createGreaterThanRange( QueryTerm begin ) - { - return new RangeQuery( begin, null, false ); - } - - /** - * Create a range that is less than or equal to a given term. - * - * @param end the value to compare to - * @return the query object - */ - public static RangeQuery createLessThanOrEqualToRange( QueryTerm end ) - { - return new RangeQuery( null, end, true ); - } - - /** - * Create a range that is less than a given term. - * - * @param end the value to compare to - * @return the query object - */ - public static RangeQuery createLessThanRange( QueryTerm end ) - { - return new RangeQuery( null, end, false ); - } - - public QueryTerm getBegin() - { - return begin; - } - - public QueryTerm getEnd() - { - return end; - } - - public boolean isInclusive() - { - return inclusive; - } - -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/SingleTermQuery.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/SingleTermQuery.java deleted file mode 100644 index f7ae019fa..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/query/SingleTermQuery.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.apache.maven.repository.indexing.query; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * Query for a single term. - * - * @author Brett Porter - */ -public class SingleTermQuery - implements Query -{ - /** - * The term to query for. - */ - private final QueryTerm term; - - /** - * Constructor. - * - * @param term the term to query - */ - public SingleTermQuery( QueryTerm term ) - { - this.term = term; - } - - /** - * Shorthand constructor - create a single term query from a field and value - * - * @param field the field name - * @param value the value to check for - */ - public SingleTermQuery( String field, String value ) - { - this.term = new QueryTerm( field, value ); - } - - public String getField() - { - return term.getField(); - } - - public String getValue() - { - return term.getValue(); - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/AbstractArtifactIndexRecordFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/AbstractArtifactIndexRecordFactory.java deleted file mode 100644 index 8a9a8cc91..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/AbstractArtifactIndexRecordFactory.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.apache.maven.repository.indexing.record; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.repository.digest.Digester; -import org.apache.maven.repository.digest.DigesterException; -import org.codehaus.plexus.logging.AbstractLogEnabled; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -/** - * Base class for the index record factories. - * - * @author Brett Porter - */ -public abstract class AbstractArtifactIndexRecordFactory - extends AbstractLogEnabled - implements RepositoryIndexRecordFactory -{ - protected String readChecksum( File file, Digester digester ) - { - String checksum; - try - { - checksum = digester.calc( file ).toLowerCase(); - } - catch ( DigesterException e ) - { - getLogger().error( "Error getting checksum for artifact file, leaving empty in index: " + e.getMessage() ); - checksum = null; - } - return checksum; - } - - protected List readFilesInArchive( File file ) - throws IOException - { - ZipFile zipFile = new ZipFile( file ); - List files; - try - { - files = new ArrayList( zipFile.size() ); - - for ( Enumeration entries = zipFile.entries(); entries.hasMoreElements(); ) - { - ZipEntry entry = (ZipEntry) entries.nextElement(); - - files.add( entry.getName() ); - } - } - finally - { - closeQuietly( zipFile ); - } - return files; - } - - protected static boolean isClass( String name ) - { - // TODO: verify if class is public or protected (this might require the original ZipEntry) - return name.endsWith( ".class" ) && name.lastIndexOf( "$" ) < 0; - } - - protected static void closeQuietly( ZipFile zipFile ) - { - try - { - if ( zipFile != null ) - { - zipFile.close(); - } - } - catch ( IOException e ) - { - // ignored - } - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecord.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecord.java deleted file mode 100644 index 4c212520c..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecord.java +++ /dev/null @@ -1,170 +0,0 @@ -package org.apache.maven.repository.indexing.record; - -import java.util.Date; -import java.util.List; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * The a record with the fields in the minimal index. - * - * @author Brett Porter - */ -public class MinimalArtifactIndexRecord - implements RepositoryIndexRecord -{ - /** - * The classes in the archive for the artifact, if it is a JAR. - */ - private List classes; - - /** - * The MD5 checksum of the artifact file. - */ - private String md5Checksum; - - /** - * The filename of the artifact file (no path). - */ - private String filename; - - /** - * The timestamp that the artifact file was last modified. Granularity is seconds. - */ - private long lastModified; - - /** - * The size of the artifact file in bytes. - */ - private long size; - - private static final int MS_PER_SEC = 1000; - - public void setClasses( List classes ) - { - this.classes = classes; - } - - public void setMd5Checksum( String md5Checksum ) - { - this.md5Checksum = md5Checksum; - } - - public void setFilename( String filename ) - { - this.filename = filename; - } - - public void setLastModified( long lastModified ) - { - this.lastModified = lastModified - lastModified % MS_PER_SEC; - } - - public void setSize( long size ) - { - this.size = size; - } - - public List getClasses() - { - return classes; - } - - public String getMd5Checksum() - { - return md5Checksum; - } - - public String getFilename() - { - return filename; - } - - public long getLastModified() - { - return lastModified; - } - - public long getSize() - { - return size; - } - - /** - * @noinspection RedundantIfStatement - */ - public boolean equals( Object obj ) - { - if ( this == obj ) - { - return true; - } - if ( obj == null || getClass() != obj.getClass() ) - { - return false; - } - - MinimalArtifactIndexRecord that = (MinimalArtifactIndexRecord) obj; - - if ( lastModified != that.lastModified ) - { - return false; - } - if ( size != that.size ) - { - return false; - } - if ( classes != null ? !classes.equals( that.classes ) : that.classes != null ) - { - return false; - } - if ( !filename.equals( that.filename ) ) - { - return false; - } - if ( md5Checksum != null ? !md5Checksum.equals( that.md5Checksum ) : that.md5Checksum != null ) - { - return false; - } - - return true; - } - - /** - * @noinspection UnnecessaryParentheses - */ - public int hashCode() - { - int result = classes != null ? classes.hashCode() : 0; - result = 31 * result + ( md5Checksum != null ? md5Checksum.hashCode() : 0 ); - result = 31 * result + filename.hashCode(); - result = 31 * result + (int) ( lastModified ^ ( lastModified >>> 32 ) ); - result = 31 * result + (int) ( size ^ ( size >>> 32 ) ); - return result; - } - - public String toString() - { - return "Filename: " + filename + "; checksum: " + md5Checksum + "; size: " + size + "; lastModified: " + - new Date( lastModified ) + "; classes: " + classes; - } - - public String getPrimaryKey() - { - return filename; - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactory.java deleted file mode 100644 index 7f007747c..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactory.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.apache.maven.repository.indexing.record; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.repository.digest.Digester; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -/** - * An index record type for the minimal index. - * - * @author Edwin Punzalan - * @author Brett Porter - * @plexus.component role="org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory" role-hint="minimal" - */ -public class MinimalArtifactIndexRecordFactory - extends AbstractArtifactIndexRecordFactory -{ - /* List of types to index. */ - private static final Set INDEXED_TYPES = new HashSet( Arrays.asList( new String[]{"jar", "maven-plugin"} ) ); - /** - * @plexus.requirement role-hint="sha1" - */ - protected Digester sha1Digester; - /** - * @plexus.requirement role-hint="md5" - */ - protected Digester md5Digester; - - public RepositoryIndexRecord createRecord( Artifact artifact ) - { - MinimalArtifactIndexRecord record = null; - - File file = artifact.getFile(); - if ( file != null && INDEXED_TYPES.contains( artifact.getType() ) && file.exists() ) - { - String md5 = readChecksum( file, md5Digester ); - - List files = null; - try - { - files = readFilesInArchive( file ); - } - catch ( IOException e ) - { - getLogger().error( "Error reading artifact file, omitting from index: " + e.getMessage() ); - } - - if ( files != null ) - { - record = new MinimalArtifactIndexRecord(); - record.setMd5Checksum( md5 ); - record.setFilename( artifact.getRepository().pathOf( artifact ) ); - record.setLastModified( file.lastModified() ); - record.setSize( file.length() ); - record.setClasses( getClassesFromFiles( files ) ); - } - } - return record; - } - - private List getClassesFromFiles( List files ) - { - List classes = new ArrayList(); - - for ( Iterator i = files.iterator(); i.hasNext(); ) - { - String name = (String) i.next(); - - if ( isClass( name ) ) - { - classes.add( name.substring( 0, name.length() - 6 ).replace( '/', '.' ) ); - } - } - - return classes; - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalIndexRecordFields.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalIndexRecordFields.java deleted file mode 100644 index 5bb8add24..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/MinimalIndexRecordFields.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.apache.maven.repository.indexing.record; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * The fields in a minimal artifact index record. - * - * @author Brett Porter - * @todo should be an enum - */ -public class MinimalIndexRecordFields -{ - public static final String FILENAME = "j"; - - public static final String LAST_MODIFIED = "d"; - - public static final String FILE_SIZE = "s"; - - public static final String MD5 = "m"; - - public static final String CLASSES = "c"; - - private MinimalIndexRecordFields() - { - // No touchy! - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecord.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecord.java deleted file mode 100644 index 10c99f1a3..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecord.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.apache.maven.repository.indexing.record; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * A repository index record. - * - * @author Brett Porter - */ -public interface RepositoryIndexRecord -{ - /** - * Get the primary key used to identify the record uniquely in the index. - * - * @return the primary key - */ - String getPrimaryKey(); -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecordFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecordFactory.java deleted file mode 100644 index 2dde9674d..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/RepositoryIndexRecordFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.apache.maven.repository.indexing.record; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.repository.indexing.RepositoryIndexException; - -/** - * The layout of a record in a repository index. - * - * @author Brett Porter - */ -public interface RepositoryIndexRecordFactory -{ - /** - * The Plexus role. - */ - String ROLE = RepositoryIndexRecordFactory.class.getName(); - - /** - * Create an index record from an artifact. - * - * @param artifact the artifact - * @return the index record - * @throws RepositoryIndexException if there is a problem constructing the record (due to not being able to read the artifact file as a POM) - */ - RepositoryIndexRecord createRecord( Artifact artifact ) - throws RepositoryIndexException; - -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecord.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecord.java deleted file mode 100644 index d2e97a4b2..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecord.java +++ /dev/null @@ -1,339 +0,0 @@ -package org.apache.maven.repository.indexing.record; - -import java.util.List; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * The a record with the fields in the standard index. - * - * @author Brett Porter - */ -public class StandardArtifactIndexRecord - extends MinimalArtifactIndexRecord -{ - /** - * The SHA-1 checksum of the artifact file. - */ - private String sha1Checksum; - - /** - * The artifact's group. - */ - private String groupId; - - /** - * The artifact's identifier within the group. - */ - private String artifactId; - - /** - * The artifact's version. - */ - private String version; - - /** - * The classifier, if there is one. - */ - private String classifier; - - /** - * The artifact type (from the file). - */ - private String type; - - /** - * A list of files (separated by '\n') in the artifact if it is an archive. - */ - private List files; - - /** - * The identifier of the repository that the artifact came from. - */ - private String repository; - - /** - * The packaging specified in the POM for this artifact. - */ - private String packaging; - - /** - * The plugin prefix specified in the metadata if the artifact is a plugin. - */ - private String pluginPrefix; - - /** - * The year the project was started. - */ - private String inceptionYear; - - /** - * The description of the project. - */ - private String projectDescription; - - /** - * The name of the project. - */ - private String projectName; - - /** - * The base version (before the snapshot is determined). - */ - private String baseVersion; - - public void setSha1Checksum( String sha1Checksum ) - { - this.sha1Checksum = sha1Checksum; - } - - public void setGroupId( String groupId ) - { - this.groupId = groupId; - } - - public void setArtifactId( String artifactId ) - { - this.artifactId = artifactId; - } - - public void setVersion( String version ) - { - this.version = version; - } - - public void setClassifier( String classifier ) - { - this.classifier = classifier; - } - - public void setType( String type ) - { - this.type = type; - } - - public void setFiles( List files ) - { - this.files = files; - } - - public void setRepository( String repository ) - { - this.repository = repository; - } - - /** - * @noinspection RedundantIfStatement - */ - public boolean equals( Object obj ) - { - if ( this == obj ) - { - return true; - } - if ( obj == null || getClass() != obj.getClass() ) - { - return false; - } - if ( !super.equals( obj ) ) - { - return false; - } - - StandardArtifactIndexRecord that = (StandardArtifactIndexRecord) obj; - - if ( !artifactId.equals( that.artifactId ) ) - { - return false; - } - if ( classifier != null ? !classifier.equals( that.classifier ) : that.classifier != null ) - { - return false; - } - if ( files != null ? !files.equals( that.files ) : that.files != null ) - { - return false; - } - if ( !groupId.equals( that.groupId ) ) - { - return false; - } - if ( repository != null ? !repository.equals( that.repository ) : that.repository != null ) - { - return false; - } - if ( sha1Checksum != null ? !sha1Checksum.equals( that.sha1Checksum ) : that.sha1Checksum != null ) - { - return false; - } - if ( type != null ? !type.equals( that.type ) : that.type != null ) - { - return false; - } - if ( !version.equals( that.version ) ) - { - return false; - } - if ( !baseVersion.equals( that.baseVersion ) ) - { - return false; - } - if ( packaging != null ? !packaging.equals( that.packaging ) : that.packaging != null ) - { - return false; - } - if ( pluginPrefix != null ? !pluginPrefix.equals( that.pluginPrefix ) : that.pluginPrefix != null ) - { - return false; - } - if ( projectName != null ? !projectName.equals( that.projectName ) : that.projectName != null ) - { - return false; - } - if ( inceptionYear != null ? !inceptionYear.equals( that.inceptionYear ) : that.inceptionYear != null ) - { - return false; - } - if ( projectDescription != null ? !projectDescription.equals( that.projectDescription ) - : that.projectDescription != null ) - { - return false; - } - - return true; - } - - public int hashCode() - { - int result = super.hashCode(); - result = 31 * result + ( sha1Checksum != null ? sha1Checksum.hashCode() : 0 ); - result = 31 * result + groupId.hashCode(); - result = 31 * result + artifactId.hashCode(); - result = 31 * result + version.hashCode(); - result = 31 * result + baseVersion.hashCode(); - result = 31 * result + ( classifier != null ? classifier.hashCode() : 0 ); - result = 31 * result + ( type != null ? type.hashCode() : 0 ); - result = 31 * result + ( files != null ? files.hashCode() : 0 ); - result = 31 * result + ( repository != null ? repository.hashCode() : 0 ); - result = 31 * result + ( packaging != null ? packaging.hashCode() : 0 ); - result = 31 * result + ( pluginPrefix != null ? pluginPrefix.hashCode() : 0 ); - result = 31 * result + ( inceptionYear != null ? inceptionYear.hashCode() : 0 ); - result = 31 * result + ( projectName != null ? projectName.hashCode() : 0 ); - result = 31 * result + ( projectDescription != null ? projectDescription.hashCode() : 0 ); - return result; - } - - public String getSha1Checksum() - { - return sha1Checksum; - } - - public String getGroupId() - { - return groupId; - } - - public String getArtifactId() - { - return artifactId; - } - - public String getVersion() - { - return version; - } - - public String getClassifier() - { - return classifier; - } - - public String getType() - { - return type; - } - - public List getFiles() - { - return files; - } - - public String getRepository() - { - return repository; - } - - public String getPackaging() - { - return packaging; - } - - public String getPluginPrefix() - { - return pluginPrefix; - } - - public void setPackaging( String packaging ) - { - this.packaging = packaging; - } - - public void setPluginPrefix( String pluginPrefix ) - { - this.pluginPrefix = pluginPrefix; - } - - public void setInceptionYear( String inceptionYear ) - { - this.inceptionYear = inceptionYear; - } - - public void setProjectDescription( String description ) - { - this.projectDescription = description; - } - - public void setProjectName( String projectName ) - { - this.projectName = projectName; - } - - public String getInceptionYear() - { - return inceptionYear; - } - - public String getProjectDescription() - { - return projectDescription; - } - - public String getProjectName() - { - return projectName; - } - - public void setBaseVersion( String baseVersion ) - { - this.baseVersion = baseVersion; - } - - public String getBaseVersion() - { - return baseVersion; - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java deleted file mode 100644 index ec20288b2..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java +++ /dev/null @@ -1,302 +0,0 @@ -package org.apache.maven.repository.indexing.record; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Model; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectBuilder; -import org.apache.maven.project.ProjectBuildingException; -import org.apache.maven.repository.digest.Digester; -import org.apache.maven.repository.indexing.RepositoryIndexException; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.codehaus.plexus.util.xml.Xpp3DomBuilder; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.zip.ZipEntry; -import java.util.zip.ZipException; -import java.util.zip.ZipFile; - -/** - * An index record type for the standard index. - * - * @author Edwin Punzalan - * @author Brett Porter - * @plexus.component role="org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory" role-hint="standard" - */ -public class StandardArtifactIndexRecordFactory - extends AbstractArtifactIndexRecordFactory -{ - /** - * A list of artifact types to treat as a zip archive. - * - * @todo this should be smarter (perhaps use plexus archiver to look for an unarchiver, and make the ones for zip configurable since sar, par, etc can be added at random. - */ - private static final Set ARCHIVE_TYPES = - new HashSet( Arrays.asList( new String[]{"jar", "ejb", "par", "sar", "war", "ear", "rar"} ) ); - - /** - * @plexus.requirement - */ - private ArtifactFactory artifactFactory; - - /** - * @plexus.requirement - */ - private MavenProjectBuilder projectBuilder; - - /** - * @plexus.requirement role-hint="sha1" - */ - protected Digester sha1Digester; - - /** - * @plexus.requirement role-hint="md5" - */ - protected Digester md5Digester; - - private static final String PLUGIN_METADATA_NAME = "META-INF/maven/plugin.xml"; - - private static final String ARCHETYPE_METADATA_NAME = "META-INF/maven/archetype.xml"; - - // some current/old archetypes have the archetype.xml at different location. - private static final String ARCHETYPE_METADATA_NAME_OLD = "META-INF/archetype.xml"; - - public RepositoryIndexRecord createRecord( Artifact artifact ) - throws RepositoryIndexException - { - StandardArtifactIndexRecord record = null; - - File file = artifact.getFile(); - - // TODO: is this condition really a possibility? - if ( file != null && file.exists() ) - { - String md5 = readChecksum( file, md5Digester ); - String sha1 = readChecksum( file, sha1Digester ); - - List files = null; - boolean archive = ARCHIVE_TYPES.contains( artifact.getType() ); - try - { - if ( archive ) - { - files = readFilesInArchive( file ); - } - } - catch ( IOException e ) - { - getLogger().error( "Error reading artifact file, omitting from index: " + e.getMessage() ); - } - - // If it's an archive with no files, don't create a record - if ( !archive || files != null ) - { - record = new StandardArtifactIndexRecord(); - - record.setGroupId( artifact.getGroupId() ); - record.setArtifactId( artifact.getArtifactId() ); - record.setBaseVersion( artifact.getBaseVersion() ); - record.setVersion( artifact.getVersion() ); - record.setClassifier( artifact.getClassifier() ); - record.setType( artifact.getType() ); - record.setMd5Checksum( md5 ); - record.setSha1Checksum( sha1 ); - record.setFilename( artifact.getRepository().pathOf( artifact ) ); - record.setLastModified( file.lastModified() ); - record.setSize( file.length() ); - record.setRepository( artifact.getRepository().getId() ); - if ( files != null ) - { - populateArchiveEntries( files, record, artifact.getFile() ); - } - - if ( !"pom".equals( artifact.getType() ) ) - { - Artifact pomArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), - artifact.getArtifactId(), - artifact.getVersion() ); - pomArtifact.isSnapshot(); // gross hack around bug in maven-artifact - File pomFile = new File( artifact.getRepository().getBasedir(), - artifact.getRepository().pathOf( pomArtifact ) ); - if ( pomFile.exists() ) - { - try - { - populatePomEntries( readPom( pomArtifact, artifact.getRepository() ), record ); - } - catch ( ProjectBuildingException e ) - { - getLogger().error( "Error reading POM file, not populating in index: " + e.getMessage() ); - } - } - } - else - { - Model model; - try - { - model = readPom( artifact, artifact.getRepository() ); - - if ( !"pom".equals( model.getPackaging() ) ) - { - // Don't return a record for a POM that is does not belong on its own - record = null; - } - else - { - populatePomEntries( model, record ); - } - } - catch ( ProjectBuildingException e ) - { - getLogger().error( "Error reading POM file, not populating in index: " + e.getMessage() ); - } - } - } - } - - return record; - } - - private void populatePomEntries( Model pom, StandardArtifactIndexRecord record ) - { - record.setPackaging( pom.getPackaging() ); - record.setProjectName( pom.getName() ); - record.setProjectDescription( pom.getDescription() ); - record.setInceptionYear( pom.getInceptionYear() ); - -/* TODO: fields for later - indexPlugins( doc, FLD_PLUGINS_BUILD, pom.getBuild().getPlugins().iterator() ); - indexReportPlugins( doc, FLD_PLUGINS_REPORT, pom.getReporting().getPlugins().iterator() ); - record.setDependencies( dependencies ); - record.setLicenses( licenses ); -*/ - } - - private Model readPom( Artifact artifact, ArtifactRepository repository ) - throws RepositoryIndexException, ProjectBuildingException - { - // TODO: this can create a -SNAPSHOT.pom when it didn't exist and a timestamped one did. This is harmless, but should be avoided - // TODO: will this pollute with local repo metadata? - MavenProject project = projectBuilder.buildFromRepository( artifact, Collections.EMPTY_LIST, repository ); - return project.getModel(); - } - - private void populateArchiveEntries( List files, StandardArtifactIndexRecord record, File artifactFile ) - throws RepositoryIndexException - { - List classes = new ArrayList(); - List fileList = new ArrayList(); - - for ( Iterator i = files.iterator(); i.hasNext(); ) - { - String name = (String) i.next(); - - // ignore directories - if ( !name.endsWith( "/" ) ) - { - fileList.add( name ); - - if ( isClass( name ) ) - { - classes.add( name.substring( 0, name.length() - 6 ).replace( '/', '.' ) ); - } - else if ( PLUGIN_METADATA_NAME.equals( name ) ) - { - populatePluginEntries( readXmlMetadataFileInJar( artifactFile, PLUGIN_METADATA_NAME ), record ); - } - else if ( ARCHETYPE_METADATA_NAME.equals( name ) || ARCHETYPE_METADATA_NAME_OLD.equals( name ) ) - { - populateArchetypeEntries( record ); - } - } - } - - if ( !classes.isEmpty() ) - { - record.setClasses( classes ); - } - if ( !fileList.isEmpty() ) - { - record.setFiles( fileList ); - } - } - - private void populateArchetypeEntries( StandardArtifactIndexRecord record ) - { - // Typically discovered as a JAR - record.setType( "maven-archetype" ); - } - - private Xpp3Dom readXmlMetadataFileInJar( File file, String name ) - throws RepositoryIndexException - { - // TODO: would be more efficient with original ZipEntry still around - - Xpp3Dom xpp3Dom; - ZipFile zipFile = null; - try - { - zipFile = new ZipFile( file ); - ZipEntry entry = zipFile.getEntry( name ); - xpp3Dom = Xpp3DomBuilder.build( new InputStreamReader( zipFile.getInputStream( entry ) ) ); - } - catch ( ZipException e ) - { - throw new RepositoryIndexException( "Unable to read plugin metadata: " + e.getMessage(), e ); - } - catch ( IOException e ) - { - throw new RepositoryIndexException( "Unable to read plugin metadata: " + e.getMessage(), e ); - } - catch ( XmlPullParserException e ) - { - throw new RepositoryIndexException( "Unable to read plugin metadata: " + e.getMessage(), e ); - } - finally - { - closeQuietly( zipFile ); - } - return xpp3Dom; - } - - public void populatePluginEntries( Xpp3Dom metadata, StandardArtifactIndexRecord record ) - { - // Typically discovered as a JAR - record.setType( "maven-plugin" ); - - Xpp3Dom prefix = metadata.getChild( "goalPrefix" ); - - if ( prefix != null ) - { - record.setPluginPrefix( prefix.getValue() ); - } - } -} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardIndexRecordFields.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardIndexRecordFields.java deleted file mode 100644 index 5bfdf3347..000000000 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardIndexRecordFields.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.apache.maven.repository.indexing.record; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * The fields in a minimal artifact index record. - * - * @author Brett Porter - * @todo should be an enum - */ -public class StandardIndexRecordFields -{ - public static final String FILENAME = "filename"; - - public static final String GROUPID = "groupId"; - - public static final String GROUPID_EXACT = GROUPID + "_u"; - - public static final String ARTIFACTID = "artifactId"; - - public static final String ARTIFACTID_EXACT = ARTIFACTID + "_u"; - - public static final String VERSION = "version"; - - public static final String VERSION_EXACT = VERSION + "_u"; - - public static final String BASE_VERSION = "baseVersion"; - - public static final String BASE_VERSION_EXACT = BASE_VERSION + "_u"; - - public static final String TYPE = "type"; - - public static final String CLASSIFIER = "classifier"; - - public static final String PACKAGING = "packaging"; - - public static final String REPOSITORY = "repo"; - - public static final String LAST_MODIFIED = "lastModified"; - - public static final String FILE_SIZE = "fileSize"; - - public static final String MD5 = "md5"; - - public static final String SHA1 = "sha1"; - - public static final String CLASSES = "classes"; - - public static final String PLUGIN_PREFIX = "pluginPrefix"; - - public static final String FILES = "files"; - - public static final String INCEPTION_YEAR = "inceptionYear"; - - public static final String PROJECT_NAME = "projectName"; - - public static final String PROJECT_DESCRIPTION = "projectDesc"; - - private StandardIndexRecordFields() - { - // No touchy! - } -} diff --git a/maven-repository-indexer/src/site/apt/design.apt b/maven-repository-indexer/src/site/apt/design.apt deleted file mode 100644 index d083789e3..000000000 --- a/maven-repository-indexer/src/site/apt/design.apt +++ /dev/null @@ -1,136 +0,0 @@ - ----- - Indexer Design - ----- - Brett Porter - ----- - 25 July 2006 - ----- - -Indexer Design - - <> - - ~~TODO: separate API design from Lucene implementation design - -* Standard Artifact Index - - We currently want to index these elements from the repository: - - * for each artifact file: the artifact ID, version, group ID, classifier, type (extension), filename (including path - from the repository base), checksums (md5, sha1) and size - - * for each artifact POM: the packaging, licenses, dependencies, build plugins, reporting plugins - - * plugin prefix - - * Java classes within a JAR artifact (delimited by \n) - - * filenames within an archive (delimited by \n) - - * the identifier of the source repository - - Each record in the index refers to an artifact. Since the content for a record can come from various sources, the - record may need to be updated when different files that are related to the same artifact are discovered (ie, the - POM, or for plugins the metadata that contains their prefix). - - To simplify this, the process for discovery is as follows: - - * Discovered artifacts will read the related POM and metadata from the repository to index, rather than relying on - it being discovered. This ensures that partial discovery still yields correct results in all cases, and it is - possible to construct the entire record without having to read back from the index. - - * POMs that do not have a packaging of POM are not sent to the indexer. - - The result of this process is that updates to a POM or repository metadata and not the corresponding artifact(s) will - not update the index. As POMs should not be modified, this will not be a major concern. Likewise, updates to metadata - will only accompany updates to the artifact itself, so will not cause a problem. - - The above case may have a problem if the discovery happens during the middle of a deployment outside of the - repository manager (where the artifact is present, but the metadata or POM is not). To avoid such cases, the - discoverer should only detect changes more than a minute old (this blackout should be configurable). - - Other techniques were considered: - - * Processing each artifact file individually, updating each record as needed. This would result in having to read - back each index record before writing. This is quite costly in Lucene as it would be "read, delete, add". You - must have a reader and writer open for that process, and it greatly complicates the code. - - * Have three indices, one for each. This would complicate searching (and may affect ranking of results, though this - was not analysed). While Lucene is - {{{http://wiki.apache.org/jakarta-lucene/LuceneFAQ#head-b11296f9e7b2a5e7496d67118d0a5898f2fd9823} capable of - searching multiple indices}}, it is expected that the results would be in the form of a list of separate records - rather than the "table join" this effectively is. A similar derivative of this technique would be to store - everything in one index, using a field (previously, doctype) to identify each record. - - Records in the index are keyed by their path from the repository root. While this is longer than using the - dependency conflict ID, Lucene cannot delete by a combination of terms, so would require storing an additional - field in the index where the file already exists. - - The plugin prefix could be found either from inside the plugin JAR (<<>>), or from the - repository metadata for the plugin's group. For simplicity, the first approach will be used. This means at present - there is no need to index the repository metadata, however that may be considered in future. - - Note that archetypes currently don't have a packaging associated with them in Maven, so it is not recorded in the POM. - However, to be able to search by this type, the indexer will look for a <<>> file, and - if found set its packaging to <<>>. In the future, this handling will be deprecated as the POMs - can start using the appropriate packaging. - - The index is shared among multiple repositories. The source repository is recorded in the index record. The - discovery/conversion/reporting mechanisms are expected to deal with duplicates before reaching the indexer, so if the - indexer encounters an artifact from a different repository than it was already added, it will simply replace the - record. - - When indexing metadata from a POM, the POM should be loaded using the Maven project builder so that inheritance and - interpolation are performed. This ensures that the record is as complete as possible, and that searching by - fields that are inherited will reveal both the parent and the children in the search results. - -* Reduced Size Index - - An additional index is maintained by the repository manager in the - {{{../apidocs/org/apache/maven/repository/indexing/MinimalArtifactIndexRecord.html} MinimalIndex}} class. This - indexes all of the same artifacts as the first index, but stores them with shorter field names and less information to - maintain a smaller size. This index is appropriate for use by certain clients such as IDE integration for fast - searching. For a fuller interface to the repository information, the integration should use the XMLRPC interface. - - The following fields are in the reduced index: - - * <<>>: The JAR filename - - * <<>>: The JAR size - - * <<>>: The last modified timestamp - - * <<>>: A list of classes in the JAR (\n delimited) - - * <<>>: md5 checksum of the JAR - - * <<>>: the primary key of the artifact - - Only JARs are indexed at present. The JAR filename is used as the key for later deleting entries. - -* Searching - - Searching will be reasonably flexible, though the general use case will be to enter a single parsed query that is - applied to all fields in the index. - - Some features that will be available: - - * : the general case described above. - - * : This would be needed for search by checksum. - - * : This would be needed for searching based on update time. Note that in - Lucene it may be better to search by other fields (or return all), and then filter the results by dates rather - than making dates part of a search query. - - * : It will be useful to only search Java classes and packages, for example - - Another thing to note is that the search results should be able to be composed entirely from the index for performance - reasons. It should not have to read any metadata files or properties of files such as size and checksum from the disk. - This enables searching a repository remotely without having the physical repository available, which is useful for - IDE integration among other things. - - Note that to be able to do an exact match search, a field must be stored untokenized. For fields where it makes sense - to search both tokenized and untokenized, they will be stored twice. This currently includes: artifact ID, group ID, - and version. diff --git a/maven-repository-indexer/src/site/site.xml b/maven-repository-indexer/src/site/site.xml deleted file mode 100644 index 565d18fd0..000000000 --- a/maven-repository-indexer/src/site/site.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexSearchTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexSearchTest.java deleted file mode 100644 index 63198db55..000000000 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexSearchTest.java +++ /dev/null @@ -1,218 +0,0 @@ -package org.apache.maven.repository.indexing.lucene; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.lucene.index.Term; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TermQuery; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.repository.indexing.RepositoryArtifactIndex; -import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; -import org.apache.maven.repository.indexing.RepositoryIndexSearchException; -import org.apache.maven.repository.indexing.record.MinimalIndexRecordFields; -import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory; -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.util.FileUtils; - -import java.io.File; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Test the Lucene implementation of the artifact index search. - * - * @author Brett Porter - * @todo would be nice to abstract some of the query away, but for now passing in a Lucene query directly is good enough - */ -public class LuceneMinimalArtifactIndexSearchTest - extends PlexusTestCase -{ - private RepositoryArtifactIndex index; - - private ArtifactRepository repository; - - private ArtifactFactory artifactFactory; - - private File indexLocation; - - private RepositoryIndexRecordFactory recordFactory; - - private Map records = new HashMap(); - - protected void setUp() - throws Exception - { - super.setUp(); - - recordFactory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "minimal" ); - - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - - ArtifactRepositoryFactory repositoryFactory = - (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - - File file = getTestFile( "src/test/managed-repository" ); - repository = - repositoryFactory.createArtifactRepository( "test", file.toURI().toURL().toString(), layout, null, null ); - - RepositoryArtifactIndexFactory factory = - (RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" ); - - indexLocation = getTestFile( "target/test-index" ); - - FileUtils.deleteDirectory( indexLocation ); - - index = factory.createMinimalIndex( indexLocation ); - - records.put( "test-jar", recordFactory.createRecord( createArtifact( "test-jar" ) ) ); - records.put( "test-jar-jdk14", - recordFactory.createRecord( createArtifact( "test-jar", "1.0", "jar", "jdk14" ) ) ); - records.put( "test-jar-and-pom", - recordFactory.createRecord( createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar" ) ) ); - records.put( "test-jar-and-pom-jdk14", recordFactory.createRecord( - createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar", "jdk14" ) ) ); - records.put( "test-child-pom", - recordFactory.createRecord( createArtifact( "test-child-pom", "1.0-20060728.121314-1", "jar" ) ) ); - records.put( "test-archetype", recordFactory.createRecord( createArtifact( "test-archetype" ) ) ); - records.put( "test-plugin", recordFactory.createRecord( createArtifact( "test-plugin" ) ) ); - records.put( "test-pom", recordFactory.createRecord( createArtifact( "test-pom", "1.0", "pom" ) ) ); - records.put( "parent-pom", recordFactory.createRecord( createArtifact( "parent-pom", "1", "pom" ) ) ); - records.put( "test-dll", recordFactory.createRecord( createArtifact( "test-dll", "1.0.1.34", "dll" ) ) ); - - index.indexRecords( records.values() ); - } - - public void testExactMatchMd5() - throws RepositoryIndexSearchException - { - Query query = new TermQuery( new Term( MinimalIndexRecordFields.MD5, "3a0adc365f849366cd8b633cad155cb7" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); - assertEquals( "Check results size", 5, results.size() ); - - // test non-match fails - query = new TermQuery( new Term( MinimalIndexRecordFields.MD5, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testMatchFilename() - throws RepositoryIndexSearchException - { - Query query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "maven" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertFalse( "Check result", results.contains( records.get( "test-pom" ) ) ); - assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) ); - assertFalse( "Check result", results.contains( records.get( "test-dll" ) ) ); - assertEquals( "Check results size", 7, results.size() ); - -/* TODO: if this is a result we want, we need to change the analyzer. Currently, it is tokenizing it as plugin-1.0 and plugin/1.0 in the path - query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "plugin" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); - assertEquals( "Check results size", 1, results.size() ); -*/ - query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "test" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) ); - assertFalse( "Check result", results.contains( records.get( "test-pom" ) ) ); - assertFalse( "Check result", results.contains( records.get( "test-dll" ) ) ); - assertEquals( "Check results size", 7, results.size() ); - - // test non-match fails - query = new TermQuery( new Term( MinimalIndexRecordFields.FILENAME, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testMatchClass() - throws RepositoryIndexSearchException - { - // TODO: should be preserving case! - Query query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "b.c.c" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); - assertEquals( "Check results size", 5, results.size() ); - -/* TODO!: need to change the analyzer if we want partial classes (split on '.') - query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "C" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); - assertEquals( "Check results size", 4, results.size() ); - - query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "MyMojo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); - assertEquals( "Check results size", 1, results.size() ); -*/ - - // test non-match fails - query = new TermQuery( new Term( MinimalIndexRecordFields.CLASSES, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - private Artifact createArtifact( String artifactId ) - { - return createArtifact( artifactId, "1.0", "jar", null ); - } - - private Artifact createArtifact( String artifactId, String version, String type ) - { - return createArtifact( artifactId, version, type, null ); - } - - private Artifact createArtifact( String artifactId, String version, String type, String classifier ) - { - Artifact artifact = artifactFactory.createDependencyArtifact( "org.apache.maven.repository.record", artifactId, - VersionRange.createFromVersion( version ), type, - classifier, Artifact.SCOPE_RUNTIME ); - artifact.isSnapshot(); - artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); - artifact.setRepository( repository ); - return artifact; - } -} diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java deleted file mode 100644 index a08d181ac..000000000 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneMinimalArtifactIndexTest.java +++ /dev/null @@ -1,351 +0,0 @@ -package org.apache.maven.repository.indexing.lucene; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.NumberTools; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.repository.indexing.RepositoryArtifactIndex; -import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; -import org.apache.maven.repository.indexing.RepositoryIndexException; -import org.apache.maven.repository.indexing.record.MinimalIndexRecordFields; -import org.apache.maven.repository.indexing.record.RepositoryIndexRecord; -import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory; -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.TimeZone; - -/** - * Test the Lucene implementation of the artifact index. - * - * @author Brett Porter - */ -public class LuceneMinimalArtifactIndexTest - extends PlexusTestCase -{ - private RepositoryArtifactIndex index; - - private ArtifactRepository repository; - - private ArtifactFactory artifactFactory; - - private File indexLocation; - - private RepositoryIndexRecordFactory recordFactory; - - protected void setUp() - throws Exception - { - super.setUp(); - - recordFactory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "minimal" ); - - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - - ArtifactRepositoryFactory repositoryFactory = - (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - - File file = getTestFile( "src/test/managed-repository" ); - repository = - repositoryFactory.createArtifactRepository( "test", file.toURI().toURL().toString(), layout, null, null ); - - RepositoryArtifactIndexFactory factory = - (RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" ); - - indexLocation = getTestFile( "target/test-index" ); - - FileUtils.deleteDirectory( indexLocation ); - - index = factory.createMinimalIndex( indexLocation ); - } - - public void testIndexExists() - throws IOException, RepositoryIndexException - { - assertFalse( "check index doesn't exist", index.exists() ); - - // create empty directory - indexLocation.mkdirs(); - assertFalse( "check index doesn't exist even if directory does", index.exists() ); - - // create index, with no records - createEmptyIndex(); - assertTrue( "check index is considered to exist", index.exists() ); - - // Test non-directory - FileUtils.deleteDirectory( indexLocation ); - indexLocation.createNewFile(); - try - { - index.exists(); - fail( "Index operation should fail as the location is not valid" ); - } - catch ( RepositoryIndexException e ) - { - // great - } - finally - { - indexLocation.delete(); - } - } - - public void testAddRecordNoIndex() - throws IOException, RepositoryIndexException - { - Artifact artifact = createArtifact( "test-jar" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - index.indexRecords( Collections.singletonList( record ) ); - - IndexReader reader = IndexReader.open( indexLocation ); - try - { - Document document = reader.document( 0 ); - assertEquals( "Check document", repository.pathOf( artifact ), - document.get( MinimalIndexRecordFields.FILENAME ) ); - assertEquals( "Check index size", 1, reader.numDocs() ); - } - finally - { - reader.close(); - } - } - - public void testAddRecordExistingEmptyIndex() - throws IOException, RepositoryIndexException - { - createEmptyIndex(); - - Artifact artifact = createArtifact( "test-jar" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - index.indexRecords( Collections.singletonList( record ) ); - - IndexReader reader = IndexReader.open( indexLocation ); - try - { - Document document = reader.document( 0 ); - assertRecord( document, artifact, "3a0adc365f849366cd8b633cad155cb7", "A\nb.B\nb.c.C" ); - assertEquals( "Check index size", 1, reader.numDocs() ); - } - finally - { - reader.close(); - } - } - - public void testAddRecordInIndex() - throws IOException, RepositoryIndexException - { - createEmptyIndex(); - - Artifact artifact = createArtifact( "test-jar" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - index.indexRecords( Collections.singletonList( record ) ); - - // Do it again - record = recordFactory.createRecord( artifact ); - index.indexRecords( Collections.singletonList( record ) ); - - IndexReader reader = IndexReader.open( indexLocation ); - try - { - Document document = reader.document( 0 ); - assertRecord( document, artifact, "3a0adc365f849366cd8b633cad155cb7", "A\nb.B\nb.c.C" ); - assertEquals( "Check index size", 1, reader.numDocs() ); - } - finally - { - reader.close(); - } - } - - public void testDeleteRecordInIndex() - throws IOException, RepositoryIndexException - { - createEmptyIndex(); - - Artifact artifact = createArtifact( "test-jar" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - index.indexRecords( Collections.singletonList( record ) ); - - index.deleteRecords( Collections.singletonList( record ) ); - - IndexReader reader = IndexReader.open( indexLocation ); - try - { - assertEquals( "No documents", 0, reader.numDocs() ); - } - finally - { - reader.close(); - } - } - - public void testDeleteRecordNotInIndex() - throws IOException, RepositoryIndexException - { - createEmptyIndex(); - - Artifact artifact = createArtifact( "test-jar" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - - index.deleteRecords( Collections.singletonList( record ) ); - - IndexReader reader = IndexReader.open( indexLocation ); - try - { - assertEquals( "No documents", 0, reader.numDocs() ); - } - finally - { - reader.close(); - } - } - - public void testDeleteRecordNoIndex() - throws IOException, RepositoryIndexException - { - Artifact artifact = createArtifact( "test-jar" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - index.deleteRecords( Collections.singleton( record ) ); - - assertFalse( index.exists() ); - } - - public void testAddPomRecord() - throws IOException, RepositoryIndexException - { - createEmptyIndex(); - - Artifact artifact = createArtifact( "test-pom", "1.0", "pom" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - index.indexRecords( Collections.singletonList( record ) ); - - IndexReader reader = IndexReader.open( indexLocation ); - try - { - assertEquals( "No documents", 0, reader.numDocs() ); - } - finally - { - reader.close(); - } - } - - public void testAddPlugin() - throws IOException, RepositoryIndexException, XmlPullParserException - { - createEmptyIndex(); - - Artifact artifact = createArtifact( "test-plugin" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - - index.indexRecords( Collections.singletonList( record ) ); - - IndexReader reader = IndexReader.open( indexLocation ); - try - { - Document document = reader.document( 0 ); - assertRecord( document, artifact, "06f6fe25e46c4d4fb5be4f56a9bab0ee", - "org.apache.maven.repository.record.MyMojo" ); - assertEquals( "Check index size", 1, reader.numDocs() ); - } - finally - { - reader.close(); - } - } - - private Artifact createArtifact( String artifactId ) - { - return createArtifact( artifactId, "1.0", "jar" ); - } - - private Artifact createArtifact( String artifactId, String version, String type ) - { - Artifact artifact = - artifactFactory.createBuildArtifact( "org.apache.maven.repository.record", artifactId, version, type ); - artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); - artifact.setRepository( repository ); - return artifact; - } - - private void createEmptyIndex() - throws IOException - { - createIndex( Collections.EMPTY_LIST ); - } - - private void createIndex( List docments ) - throws IOException - { - IndexWriter writer = new IndexWriter( indexLocation, new StandardAnalyzer(), true ); - for ( Iterator i = docments.iterator(); i.hasNext(); ) - { - Document document = (Document) i.next(); - writer.addDocument( document ); - } - writer.optimize(); - writer.close(); - } - - private void assertRecord( Document document, Artifact artifact, String expectedChecksum, String expectedClasses ) - { - assertEquals( "Check document filename", repository.pathOf( artifact ), - document.get( MinimalIndexRecordFields.FILENAME ) ); - assertEquals( "Check document timestamp", getLastModified( artifact.getFile() ), - document.get( MinimalIndexRecordFields.LAST_MODIFIED ) ); - assertEquals( "Check document checksum", expectedChecksum, document.get( MinimalIndexRecordFields.MD5 ) ); - assertEquals( "Check document size", artifact.getFile().length(), - NumberTools.stringToLong( document.get( MinimalIndexRecordFields.FILE_SIZE ) ) ); - assertEquals( "Check document classes", expectedClasses, document.get( MinimalIndexRecordFields.CLASSES ) ); - } - - private String getLastModified( File file ) - { - SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyyMMddHHmmss", Locale.US ); - dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); - return dateFormat.format( new Date( file.lastModified() ) ); - } -} diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexSearchTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexSearchTest.java deleted file mode 100644 index 19ff16439..000000000 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexSearchTest.java +++ /dev/null @@ -1,700 +0,0 @@ -package org.apache.maven.repository.indexing.lucene; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.lucene.index.Term; -import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TermQuery; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.repository.indexing.RepositoryArtifactIndex; -import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; -import org.apache.maven.repository.indexing.RepositoryIndexSearchException; -import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory; -import org.apache.maven.repository.indexing.record.StandardIndexRecordFields; -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.util.FileUtils; - -import java.io.File; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Test the Lucene implementation of the artifact index search. - * - * @author Brett Porter - * @todo would be nice to abstract some of the query away, but for now passing in a Lucene query directly is good enough - */ -public class LuceneStandardArtifactIndexSearchTest - extends PlexusTestCase -{ - private RepositoryArtifactIndex index; - - private ArtifactRepository repository; - - private ArtifactFactory artifactFactory; - - private File indexLocation; - - private RepositoryIndexRecordFactory recordFactory; - - private Map records = new HashMap(); - - protected void setUp() - throws Exception - { - super.setUp(); - - recordFactory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "standard" ); - - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - - ArtifactRepositoryFactory repositoryFactory = - (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - - File file = getTestFile( "src/test/managed-repository" ); - repository = - repositoryFactory.createArtifactRepository( "test", file.toURI().toURL().toString(), layout, null, null ); - - RepositoryArtifactIndexFactory factory = - (RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" ); - - indexLocation = getTestFile( "target/test-index" ); - - FileUtils.deleteDirectory( indexLocation ); - - index = factory.createStandardIndex( indexLocation ); - - records.put( "test-jar", recordFactory.createRecord( createArtifact( "test-jar" ) ) ); - records.put( "test-jar-jdk14", - recordFactory.createRecord( createArtifact( "test-jar", "1.0", "jar", "jdk14" ) ) ); - records.put( "test-jar-and-pom", - recordFactory.createRecord( createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar" ) ) ); - records.put( "test-jar-and-pom-jdk14", recordFactory.createRecord( - createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar", "jdk14" ) ) ); - records.put( "test-child-pom", - recordFactory.createRecord( createArtifact( "test-child-pom", "1.0-20060728.121314-1", "jar" ) ) ); - records.put( "test-archetype", recordFactory.createRecord( createArtifact( "test-archetype" ) ) ); - records.put( "test-plugin", recordFactory.createRecord( createArtifact( "test-plugin" ) ) ); - records.put( "test-pom", recordFactory.createRecord( createArtifact( "test-pom", "1.0", "pom" ) ) ); - records.put( "parent-pom", recordFactory.createRecord( createArtifact( "parent-pom", "1", "pom" ) ) ); - records.put( "test-dll", recordFactory.createRecord( createArtifact( "test-dll", "1.0.1.34", "dll" ) ) ); - - index.indexRecords( records.values() ); - } - - public void testExactMatchVersion() - throws RepositoryIndexSearchException - { - Query query = new TermQuery( new Term( StandardIndexRecordFields.VERSION_EXACT, "1.0" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) ); - assertEquals( "Check results size", 5, results.size() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.VERSION_EXACT, "1.0-SNAPSHOT" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.VERSION_EXACT, "1.0-20060728.121314-1" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); - assertEquals( "Check results size", 1, results.size() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.VERSION_EXACT, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testExactMatchBaseVersion() - throws RepositoryIndexSearchException - { - Query query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION_EXACT, "1.0" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) ); - assertEquals( "Check results size", 5, results.size() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION_EXACT, "1.0-SNAPSHOT" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); - assertEquals( "Check results size", 1, results.size() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION_EXACT, "1.0-20060728.121314-1" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION_EXACT, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testExactMatchGroupId() - throws RepositoryIndexSearchException - { - Query query = - new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, "org.apache.maven.repository.record" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertEquals( "Check results size", 10, results.size() ); - - // test partial match fails - query = new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, "org.apache.maven" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testExactMatchArtifactId() - throws RepositoryIndexSearchException - { - Query query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID_EXACT, "test-jar" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); - assertEquals( "Check results size", 2, results.size() ); - - // test partial match fails - query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID_EXACT, "test" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID_EXACT, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testExactMatchType() - throws RepositoryIndexSearchException - { - Query query = new TermQuery( new Term( StandardIndexRecordFields.TYPE, "maven-plugin" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); - assertEquals( "Check results size", 1, results.size() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.TYPE, "jar" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); - assertEquals( "Check results size", 5, results.size() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.TYPE, "dll" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-dll" ) ) ); - assertEquals( "Check results size", 1, results.size() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.TYPE, "maven-archetype" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) ); - assertEquals( "Check results size", 1, results.size() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.TYPE, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testExactMatchPackaging() - throws RepositoryIndexSearchException - { - Query query = new TermQuery( new Term( StandardIndexRecordFields.PACKAGING, "maven-plugin" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); - assertEquals( "Check results size", 1, results.size() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.PACKAGING, "jar" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); - assertEquals( "Check results size", 4, results.size() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.PACKAGING, "dll" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.PACKAGING, "maven-archetype" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.PACKAGING, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testExactMatchPluginPrefix() - throws RepositoryIndexSearchException - { - Query query = new TermQuery( new Term( StandardIndexRecordFields.PLUGIN_PREFIX, "test" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); - assertEquals( "Check results size", 1, results.size() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.PLUGIN_PREFIX, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testExactMatchRepository() - throws RepositoryIndexSearchException - { - Query query = new TermQuery( new Term( StandardIndexRecordFields.REPOSITORY, "test" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertEquals( "Check results size", 10, results.size() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.REPOSITORY, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testExactMatchMd5() - throws RepositoryIndexSearchException - { - Query query = new TermQuery( new Term( StandardIndexRecordFields.MD5, "3a0adc365f849366cd8b633cad155cb7" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); - assertEquals( "Check results size", 5, results.size() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.MD5, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testExactMatchSha1() - throws RepositoryIndexSearchException - { - Query query = - new TermQuery( new Term( StandardIndexRecordFields.SHA1, "c66f18bf192cb613fc2febb4da541a34133eedc2" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); - assertEquals( "Check results size", 5, results.size() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.SHA1, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testExactMatchInceptionYear() - throws RepositoryIndexSearchException - { - Query query = new TermQuery( new Term( StandardIndexRecordFields.INCEPTION_YEAR, "2005" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "parent-pom" ) ) ); - assertEquals( "Check results size", 3, results.size() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.INCEPTION_YEAR, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testMatchFilename() - throws RepositoryIndexSearchException - { - Query query = new TermQuery( new Term( StandardIndexRecordFields.FILENAME, "maven" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertEquals( "Check results size", 10, results.size() ); - -/* TODO: if this is a result we want, we need to change the analyzer. Currently, it is tokenizing it as plugin-1.0 and plugin/1.0 in the path - query = new TermQuery( new Term( StandardIndexRecordFields.FILENAME, "plugin" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); - assertEquals( "Check results size", 1, results.size() ); -*/ - query = new TermQuery( new Term( StandardIndexRecordFields.FILENAME, "test" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) ); - assertEquals( "Check results size", 9, results.size() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.FILENAME, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testMatchGroupId() - throws RepositoryIndexSearchException - { - Query query = - new TermQuery( new Term( StandardIndexRecordFields.GROUPID, "org.apache.maven.repository.record" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertEquals( "Check results size", 10, results.size() ); - -/* TODO: if we want this result, must change the analyzer to split on '.' - query = new TermQuery( new Term( StandardIndexRecordFields.GROUPID, "maven" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertEquals( "Check results size", 10, results.size() ); -*/ - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.GROUPID, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testMatchArtifactId() - throws RepositoryIndexSearchException - { - Query query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID, "plugin" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); - assertEquals( "Check results size", 1, results.size() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID, "test" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) ); - assertEquals( "Check results size", 9, results.size() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID, "maven" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testMatchVersion() - throws RepositoryIndexSearchException - { - // If partial matches are desired, need to change the analyzer for versions to split on '.' - Query query = new TermQuery( new Term( StandardIndexRecordFields.VERSION, "1" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "parent-pom" ) ) ); - assertEquals( "Check results size", 1, results.size() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.VERSION, "1.0" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) ); - assertEquals( "Check results size", 5, results.size() ); - -/* TODO: need to change analyzer to split on - if we want this - query = new TermQuery( new Term( StandardIndexRecordFields.VERSION, "snapshot" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.VERSION, "alpha" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); - assertEquals( "Check results size", 2, results.size() ); -*/ - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.VERSION, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testMatchBaseVersion() - throws RepositoryIndexSearchException - { - // If partial matches are desired, need to change the analyzer for versions to split on '.' - Query query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION, "1" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "parent-pom" ) ) ); - assertEquals( "Check results size", 1, results.size() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION, "1.0" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-archetype" ) ) ); - assertEquals( "Check results size", 5, results.size() ); - -/* TODO: need to change analyzer to split on - if we want this - query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION, "snapshot" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); - assertEquals( "Check results size", 1, results.size() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION, "alpha" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); - assertEquals( "Check results size", 2, results.size() ); -*/ - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.BASE_VERSION, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testMatchClassifier() - throws RepositoryIndexSearchException - { - BooleanQuery bQuery = new BooleanQuery(); - bQuery.add( new MatchAllDocsQuery(), BooleanClause.Occur.MUST ); - bQuery.add( new TermQuery( new Term( StandardIndexRecordFields.CLASSIFIER, "jdk14" ) ), - BooleanClause.Occur.MUST_NOT ); - List results = index.search( new LuceneQuery( bQuery ) ); - - assertFalse( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); - assertFalse( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); - assertEquals( "Check results size", 8, results.size() ); - - // TODO: can we search for "anything with no classifier" ? - - Query query = new TermQuery( new Term( StandardIndexRecordFields.CLASSIFIER, "jdk14" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); - assertEquals( "Check results size", 2, results.size() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.CLASSIFIER, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testMatchClass() - throws RepositoryIndexSearchException - { - // TODO: should be preserving case! - Query query = new TermQuery( new Term( StandardIndexRecordFields.CLASSES, "b.c.c" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); - assertEquals( "Check results size", 5, results.size() ); - -/* TODO!: need to change the analyzer if we want partial classes (split on '.') - query = new TermQuery( new Term( StandardIndexRecordFields.CLASSES, "C" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-jar" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-jdk14" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-jar-and-pom-jdk14" ) ) ); - assertEquals( "Check results size", 4, results.size() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.CLASSES, "MyMojo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); - assertEquals( "Check results size", 1, results.size() ); -*/ - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.CLASSES, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testMatchFiles() - throws RepositoryIndexSearchException - { - // TODO: should be preserving case! - Query query = new TermQuery( new Term( StandardIndexRecordFields.FILES, "manifest.mf" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertFalse( "Check result", results.contains( records.get( "test-pom" ) ) ); - assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) ); - assertFalse( "Check result", results.contains( records.get( "test-dll" ) ) ); - assertEquals( "Check results size", 7, results.size() ); - -/* - // TODO: should be preserving case, and '-inf'! - query = new TermQuery( new Term( StandardIndexRecordFields.FILES, "meta-inf" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertFalse( "Check result", results.contains( records.get( "test-pom" ) ) ); - assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) ); - assertFalse( "Check result", results.contains( records.get( "test-dll" ) ) ); - assertEquals( "Check results size", 7, results.size() ); -*/ - - query = new TermQuery( new Term( StandardIndexRecordFields.FILES, "plugin.xml" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); - assertEquals( "Check results size", 1, results.size() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.FILES, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testMatchProjectName() - throws RepositoryIndexSearchException - { - Query query = new TermQuery( new Term( StandardIndexRecordFields.PROJECT_NAME, "mojo" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-plugin" ) ) ); - assertEquals( "Check results size", 1, results.size() ); - - query = new TermQuery( new Term( StandardIndexRecordFields.PROJECT_NAME, "maven" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertFalse( "Check result", results.contains( records.get( "parent-pom" ) ) ); - assertFalse( "Check result", results.contains( records.get( "test-child-pom" ) ) ); - assertEquals( "Check results size", 2, results.size() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.PROJECT_NAME, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - public void testMatchProjectDescription() - throws RepositoryIndexSearchException - { - Query query = new TermQuery( new Term( StandardIndexRecordFields.PROJECT_DESCRIPTION, "description" ) ); - List results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check result", results.contains( records.get( "test-child-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "parent-pom" ) ) ); - assertTrue( "Check result", results.contains( records.get( "test-pom" ) ) ); - assertEquals( "Check results size", 3, results.size() ); - - // test non-match fails - query = new TermQuery( new Term( StandardIndexRecordFields.PROJECT_DESCRIPTION, "foo" ) ); - results = index.search( new LuceneQuery( query ) ); - - assertTrue( "Check results size", results.isEmpty() ); - } - - private Artifact createArtifact( String artifactId ) - { - return createArtifact( artifactId, "1.0", "jar", null ); - } - - private Artifact createArtifact( String artifactId, String version, String type ) - { - return createArtifact( artifactId, version, type, null ); - } - - private Artifact createArtifact( String artifactId, String version, String type, String classifier ) - { - Artifact artifact = artifactFactory.createDependencyArtifact( "org.apache.maven.repository.record", artifactId, - VersionRange.createFromVersion( version ), type, - classifier, Artifact.SCOPE_RUNTIME ); - artifact.isSnapshot(); - artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); - artifact.setRepository( repository ); - return artifact; - } -} diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java deleted file mode 100644 index 4329dc452..000000000 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/lucene/LuceneStandardArtifactIndexTest.java +++ /dev/null @@ -1,408 +0,0 @@ -package org.apache.maven.repository.indexing.lucene; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.NumberTools; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.repository.indexing.RepositoryArtifactIndex; -import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; -import org.apache.maven.repository.indexing.RepositoryIndexException; -import org.apache.maven.repository.indexing.record.RepositoryIndexRecord; -import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory; -import org.apache.maven.repository.indexing.record.StandardIndexRecordFields; -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.TimeZone; - -/** - * Test the Lucene implementation of the artifact index. - * - * @author Brett Porter - */ -public class LuceneStandardArtifactIndexTest - extends PlexusTestCase -{ - private RepositoryArtifactIndex index; - - private ArtifactRepository repository; - - private ArtifactFactory artifactFactory; - - private File indexLocation; - - private RepositoryIndexRecordFactory recordFactory; - - protected void setUp() - throws Exception - { - super.setUp(); - - recordFactory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "standard" ); - - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - - ArtifactRepositoryFactory repositoryFactory = - (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - - File file = getTestFile( "src/test/managed-repository" ); - repository = - repositoryFactory.createArtifactRepository( "test", file.toURI().toURL().toString(), layout, null, null ); - - RepositoryArtifactIndexFactory factory = - (RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" ); - - indexLocation = getTestFile( "target/test-index" ); - - FileUtils.deleteDirectory( indexLocation ); - - index = factory.createStandardIndex( indexLocation ); - } - - public void testIndexExists() - throws IOException, RepositoryIndexException - { - assertFalse( "check index doesn't exist", index.exists() ); - - // create empty directory - indexLocation.mkdirs(); - assertFalse( "check index doesn't exist even if directory does", index.exists() ); - - // create index, with no records - createEmptyIndex(); - assertTrue( "check index is considered to exist", index.exists() ); - - // Test non-directory - FileUtils.deleteDirectory( indexLocation ); - indexLocation.createNewFile(); - try - { - index.exists(); - fail( "Index operation should fail as the location is not valid" ); - } - catch ( RepositoryIndexException e ) - { - // great - } - finally - { - indexLocation.delete(); - } - } - - public void testAddRecordNoIndex() - throws IOException, RepositoryIndexException - { - Artifact artifact = createArtifact( "test-jar" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - index.indexRecords( Collections.singletonList( record ) ); - - IndexReader reader = IndexReader.open( indexLocation ); - try - { - Document document = reader.document( 0 ); - assertJarRecord( artifact, document ); - assertEquals( "Check index size", 1, reader.numDocs() ); - } - finally - { - reader.close(); - } - } - - public void testAddRecordExistingEmptyIndex() - throws IOException, RepositoryIndexException - { - createEmptyIndex(); - - Artifact artifact = createArtifact( "test-jar" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - index.indexRecords( Collections.singletonList( record ) ); - - IndexReader reader = IndexReader.open( indexLocation ); - try - { - Document document = reader.document( 0 ); - assertJarRecord( artifact, document ); - assertEquals( "Check index size", 1, reader.numDocs() ); - } - finally - { - reader.close(); - } - } - - public void testAddRecordInIndex() - throws IOException, RepositoryIndexException - { - createEmptyIndex(); - - Artifact artifact = createArtifact( "test-jar" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - index.indexRecords( Collections.singletonList( record ) ); - - // Do it again - record = recordFactory.createRecord( artifact ); - index.indexRecords( Collections.singletonList( record ) ); - - IndexReader reader = IndexReader.open( indexLocation ); - try - { - Document document = reader.document( 0 ); - assertJarRecord( artifact, document ); - assertEquals( "Check index size", 1, reader.numDocs() ); - } - finally - { - reader.close(); - } - } - - public void testAddPomRecord() - throws IOException, RepositoryIndexException - { - createEmptyIndex(); - - Artifact artifact = createArtifact( "test-pom", "1.0", "pom" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - index.indexRecords( Collections.singletonList( record ) ); - - IndexReader reader = IndexReader.open( indexLocation ); - try - { - Document document = reader.document( 0 ); - assertPomRecord( artifact, document ); - assertEquals( "Check index size", 1, reader.numDocs() ); - } - finally - { - reader.close(); - } - } - - public void testAddPlugin() - throws IOException, RepositoryIndexException, XmlPullParserException - { - createEmptyIndex(); - - Artifact artifact = createArtifact( "test-plugin" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - - index.indexRecords( Collections.singletonList( record ) ); - - IndexReader reader = IndexReader.open( indexLocation ); - try - { - Document document = reader.document( 0 ); - assertPluginRecord( artifact, document ); - assertEquals( "Check index size", 1, reader.numDocs() ); - } - finally - { - reader.close(); - } - } - - public void testDeleteRecordInIndex() - throws IOException, RepositoryIndexException - { - createEmptyIndex(); - - Artifact artifact = createArtifact( "test-jar" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - index.indexRecords( Collections.singletonList( record ) ); - - index.deleteRecords( Collections.singletonList( record ) ); - - IndexReader reader = IndexReader.open( indexLocation ); - try - { - assertEquals( "No documents", 0, reader.numDocs() ); - } - finally - { - reader.close(); - } - } - - public void testDeleteRecordNotInIndex() - throws IOException, RepositoryIndexException - { - createEmptyIndex(); - - Artifact artifact = createArtifact( "test-jar" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - - index.deleteRecords( Collections.singletonList( record ) ); - - IndexReader reader = IndexReader.open( indexLocation ); - try - { - assertEquals( "No documents", 0, reader.numDocs() ); - } - finally - { - reader.close(); - } - } - - public void testDeleteRecordNoIndex() - throws IOException, RepositoryIndexException - { - Artifact artifact = createArtifact( "test-jar" ); - - RepositoryIndexRecord record = recordFactory.createRecord( artifact ); - index.deleteRecords( Collections.singleton( record ) ); - - assertFalse( index.exists() ); - } - - private Artifact createArtifact( String artifactId ) - { - return createArtifact( artifactId, "1.0", "jar" ); - } - - private Artifact createArtifact( String artifactId, String version, String type ) - { - Artifact artifact = - artifactFactory.createBuildArtifact( "org.apache.maven.repository.record", artifactId, version, type ); - artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); - artifact.setRepository( repository ); - return artifact; - } - - private void createEmptyIndex() - throws IOException - { - createIndex( Collections.EMPTY_LIST ); - } - - private void createIndex( List docments ) - throws IOException - { - IndexWriter writer = new IndexWriter( indexLocation, new StandardAnalyzer(), true ); - for ( Iterator i = docments.iterator(); i.hasNext(); ) - { - Document document = (Document) i.next(); - writer.addDocument( document ); - } - writer.optimize(); - writer.close(); - } - - private void assertRecord( Artifact artifact, Document document, String expectedArtifactId, String expectedType, - String expectedMd5, String expectedSha1 ) - { - assertEquals( "Check document filename", repository.pathOf( artifact ), - document.get( StandardIndexRecordFields.FILENAME ) ); - assertEquals( "Check document groupId", "org.apache.maven.repository.record", - document.get( StandardIndexRecordFields.GROUPID ) ); - assertEquals( "Check document artifactId", expectedArtifactId, - document.get( StandardIndexRecordFields.ARTIFACTID ) ); - assertEquals( "Check document version", "1.0", document.get( StandardIndexRecordFields.VERSION ) ); - assertEquals( "Check document type", expectedType, document.get( StandardIndexRecordFields.TYPE ) ); - assertEquals( "Check document repository", "test", document.get( StandardIndexRecordFields.REPOSITORY ) ); - assertEquals( "Check document timestamp", getLastModified( artifact.getFile() ), - document.get( StandardIndexRecordFields.LAST_MODIFIED ) ); - assertEquals( "Check document md5", expectedMd5, document.get( StandardIndexRecordFields.MD5 ) ); - assertEquals( "Check document sha1", expectedSha1, document.get( StandardIndexRecordFields.SHA1 ) ); - assertEquals( "Check document file size", artifact.getFile().length(), - NumberTools.stringToLong( document.get( StandardIndexRecordFields.FILE_SIZE ) ) ); - assertNull( "Check document classifier", document.get( StandardIndexRecordFields.CLASSIFIER ) ); - } - - private void assertPomRecord( Artifact artifact, Document document ) - { - assertRecord( artifact, document, "test-pom", "pom", "32dbef7ff11eb933bd8b7e7bcab85406", - "c3b374e394607e1e705e71c227f62641e8621ebe" ); - assertNull( "Check document classes", document.get( StandardIndexRecordFields.CLASSES ) ); - assertNull( "Check document files", document.get( StandardIndexRecordFields.FILES ) ); - assertNull( "Check document pluginPrefix", document.get( StandardIndexRecordFields.PLUGIN_PREFIX ) ); - assertEquals( "Check document year", "2005", document.get( StandardIndexRecordFields.INCEPTION_YEAR ) ); - assertEquals( "Check document project name", "Maven Repository Manager Test POM", - document.get( StandardIndexRecordFields.PROJECT_NAME ) ); - assertEquals( "Check document project description", "Description", - document.get( StandardIndexRecordFields.PROJECT_DESCRIPTION ) ); - assertEquals( "Check document packaging", "pom", document.get( StandardIndexRecordFields.PACKAGING ) ); - } - - private void assertJarRecord( Artifact artifact, Document document ) - { - assertRecord( artifact, document, "test-jar", "jar", "3a0adc365f849366cd8b633cad155cb7", - "c66f18bf192cb613fc2febb4da541a34133eedc2" ); - assertEquals( "Check document classes", "A\nb.B\nb.c.C", document.get( StandardIndexRecordFields.CLASSES ) ); - assertEquals( "Check document files", "META-INF/MANIFEST.MF\nA.class\nb/B.class\nb/c/C.class", - document.get( StandardIndexRecordFields.FILES ) ); - assertNull( "Check document inceptionYear", document.get( StandardIndexRecordFields.INCEPTION_YEAR ) ); - assertNull( "Check document projectName", document.get( StandardIndexRecordFields.PROJECT_NAME ) ); - assertNull( "Check document projectDesc", document.get( StandardIndexRecordFields.PROJECT_DESCRIPTION ) ); - assertNull( "Check document pluginPrefix", document.get( StandardIndexRecordFields.PLUGIN_PREFIX ) ); - assertNull( "Check document packaging", document.get( StandardIndexRecordFields.PACKAGING ) ); - } - - private void assertPluginRecord( Artifact artifact, Document document ) - { - assertRecord( artifact, document, "test-plugin", "maven-plugin", "06f6fe25e46c4d4fb5be4f56a9bab0ee", - "382c1ebfb5d0c7d6061c2f8569fb53f8fc00fec2" ); - assertEquals( "Check document classes", "org.apache.maven.repository.record.MyMojo", - document.get( StandardIndexRecordFields.CLASSES ) ); - assertEquals( "Check document files", "META-INF/MANIFEST.MF\n" + "META-INF/maven/plugin.xml\n" + - "org/apache/maven/repository/record/MyMojo.class\n" + - "META-INF/maven/org.apache.maven.repository.record/test-plugin/pom.xml\n" + - "META-INF/maven/org.apache.maven.repository.record/test-plugin/pom.properties", - document.get( StandardIndexRecordFields.FILES ) ); - assertEquals( "Check document pluginPrefix", "test", document.get( StandardIndexRecordFields.PLUGIN_PREFIX ) ); - assertEquals( "Check document packaging", "maven-plugin", document.get( StandardIndexRecordFields.PACKAGING ) ); - assertNull( "Check document inceptionYear", document.get( StandardIndexRecordFields.INCEPTION_YEAR ) ); - assertEquals( "Check document project name", "Maven Mojo Archetype", - document.get( StandardIndexRecordFields.PROJECT_NAME ) ); - assertNull( "Check document projectDesc", document.get( StandardIndexRecordFields.PROJECT_DESCRIPTION ) ); - } - - private String getLastModified( File file ) - { - SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyyMMddHHmmss", Locale.US ); - dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); - return dateFormat.format( new Date( file.lastModified() ) ); - } -} diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java deleted file mode 100644 index 17364046f..000000000 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/query/QueryTest.java +++ /dev/null @@ -1,156 +0,0 @@ -package org.apache.maven.repository.indexing.query; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 junit.framework.TestCase; - -import java.util.Iterator; - -/** - * @author Brett Porter - */ -public class QueryTest - extends TestCase -{ - private QueryTerm term1 = new QueryTerm( "field1", "value1" ); - - private QueryTerm term2 = new QueryTerm( "field2", "value2" ); - - private QueryTerm term3 = new QueryTerm( "field3", "value3" ); - - public void testQueryTerm() - { - QueryTerm query = new QueryTerm( "Field", "Value" ); - assertEquals( "check field setting", "Field", query.getField() ); - assertEquals( "check value setting", "Value", query.getValue() ); - } - - public void testSingleTermQuery() - { - SingleTermQuery query = new SingleTermQuery( "Field", "Value" ); - assertEquals( "check field setting", "Field", query.getField() ); - assertEquals( "check value setting", "Value", query.getValue() ); - - query = new SingleTermQuery( term1 ); - assertEquals( "check field setting", "field1", query.getField() ); - assertEquals( "check value setting", "value1", query.getValue() ); - } - - public void testRangeQueryOpen() - { - RangeQuery rangeQuery = RangeQuery.createOpenRange(); - assertNull( "Check range has no start", rangeQuery.getBegin() ); - assertNull( "Check range has no end", rangeQuery.getEnd() ); - } - - public void testRangeQueryExclusive() - { - RangeQuery rangeQuery = RangeQuery.createExclusiveRange( term1, term2 ); - assertEquals( "Check range start", term1, rangeQuery.getBegin() ); - assertEquals( "Check range end", term2, rangeQuery.getEnd() ); - assertFalse( "Check exclusive", rangeQuery.isInclusive() ); - } - - public void testRangeQueryInclusive() - { - RangeQuery rangeQuery = RangeQuery.createInclusiveRange( term1, term2 ); - assertEquals( "Check range start", term1, rangeQuery.getBegin() ); - assertEquals( "Check range end", term2, rangeQuery.getEnd() ); - assertTrue( "Check inclusive", rangeQuery.isInclusive() ); - } - - public void testRangeQueryOpenEnded() - { - RangeQuery rangeQuery = RangeQuery.createGreaterThanOrEqualToRange( term1 ); - assertEquals( "Check range start", term1, rangeQuery.getBegin() ); - assertNull( "Check range end", rangeQuery.getEnd() ); - assertTrue( "Check inclusive", rangeQuery.isInclusive() ); - - rangeQuery = RangeQuery.createGreaterThanRange( term1 ); - assertEquals( "Check range start", term1, rangeQuery.getBegin() ); - assertNull( "Check range end", rangeQuery.getEnd() ); - assertFalse( "Check exclusive", rangeQuery.isInclusive() ); - - rangeQuery = RangeQuery.createLessThanOrEqualToRange( term1 ); - assertNull( "Check range start", rangeQuery.getBegin() ); - assertEquals( "Check range end", term1, rangeQuery.getEnd() ); - assertTrue( "Check inclusive", rangeQuery.isInclusive() ); - - rangeQuery = RangeQuery.createLessThanRange( term1 ); - assertNull( "Check range start", rangeQuery.getBegin() ); - assertEquals( "Check range end", term1, rangeQuery.getEnd() ); - assertFalse( "Check exclusive", rangeQuery.isInclusive() ); - } - - public void testCompundQuery() - { - CompoundQuery query = new CompoundQuery(); - assertTrue( "check query is empty", query.getCompoundQueryTerms().isEmpty() ); - - query.and( term1 ); - query.or( term2 ); - query.not( term3 ); - - Iterator i = query.getCompoundQueryTerms().iterator(); - CompoundQueryTerm term = (CompoundQueryTerm) i.next(); - assertEquals( "Check first term", "field1", getQuery( term ).getField() ); - assertEquals( "Check first term", "value1", getQuery( term ).getValue() ); - assertTrue( "Check first term", term.isRequired() ); - assertFalse( "Check first term", term.isProhibited() ); - - term = (CompoundQueryTerm) i.next(); - assertEquals( "Check second term", "field2", getQuery( term ).getField() ); - assertEquals( "Check second term", "value2", getQuery( term ).getValue() ); - assertFalse( "Check second term", term.isRequired() ); - assertFalse( "Check second term", term.isProhibited() ); - - term = (CompoundQueryTerm) i.next(); - assertEquals( "Check third term", "field3", getQuery( term ).getField() ); - assertEquals( "Check third term", "value3", getQuery( term ).getValue() ); - assertFalse( "Check third term", term.isRequired() ); - assertTrue( "Check third term", term.isProhibited() ); - - CompoundQuery query2 = new CompoundQuery(); - query2.and( query ); - query2.or( new SingleTermQuery( term2 ) ); - query2.not( new SingleTermQuery( term3 ) ); - - i = query2.getCompoundQueryTerms().iterator(); - term = (CompoundQueryTerm) i.next(); - assertEquals( "Check first term", query, term.getQuery() ); - assertTrue( "Check first term", term.isRequired() ); - assertFalse( "Check first term", term.isProhibited() ); - - term = (CompoundQueryTerm) i.next(); - assertEquals( "Check second term", "field2", getQuery( term ).getField() ); - assertEquals( "Check second term", "value2", getQuery( term ).getValue() ); - assertFalse( "Check second term", term.isRequired() ); - assertFalse( "Check second term", term.isProhibited() ); - - term = (CompoundQueryTerm) i.next(); - assertEquals( "Check third term", "field3", getQuery( term ).getField() ); - assertEquals( "Check third term", "value3", getQuery( term ).getValue() ); - assertFalse( "Check third term", term.isRequired() ); - assertTrue( "Check third term", term.isProhibited() ); - } - - private static SingleTermQuery getQuery( CompoundQueryTerm term ) - { - return (SingleTermQuery) term.getQuery(); - } -} - diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactoryTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactoryTest.java deleted file mode 100644 index 32d97b329..000000000 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactoryTest.java +++ /dev/null @@ -1,240 +0,0 @@ -package org.apache.maven.repository.indexing.record; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.repository.indexing.RepositoryIndexException; -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -/** - * Test the minimal artifact index record. - * - * @author Brett Porter - */ -public class MinimalArtifactIndexRecordFactoryTest - extends PlexusTestCase -{ - private RepositoryIndexRecordFactory factory; - - private ArtifactRepository repository; - - private ArtifactFactory artifactFactory; - - private static final String TEST_GROUP_ID = "org.apache.maven.repository.record"; - - private static final List JAR_CLASS_LIST = Arrays.asList( new String[]{"A", "b.B", "b.c.C"} ); - - protected void setUp() - throws Exception - { - super.setUp(); - - factory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "minimal" ); - - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - - ArtifactRepositoryFactory repositoryFactory = - (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - - File file = getTestFile( "src/test/managed-repository" ); - repository = - repositoryFactory.createArtifactRepository( "test", file.toURI().toURL().toString(), layout, null, null ); - } - - public void testIndexedJar() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-jar" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - MinimalArtifactIndexRecord expectedRecord = new MinimalArtifactIndexRecord(); - expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); - expectedRecord.setFilename( repository.pathOf( artifact ) ); - expectedRecord.setLastModified( artifact.getFile().lastModified() ); - expectedRecord.setSize( artifact.getFile().length() ); - expectedRecord.setClasses( JAR_CLASS_LIST ); - - assertEquals( "check record", expectedRecord, record ); - } - - public void testIndexedJarWithClassifier() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-jar", "1.0", "jar", "jdk14" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - MinimalArtifactIndexRecord expectedRecord = new MinimalArtifactIndexRecord(); - expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); - expectedRecord.setFilename( repository.pathOf( artifact ) ); - expectedRecord.setLastModified( artifact.getFile().lastModified() ); - expectedRecord.setSize( artifact.getFile().length() ); - expectedRecord.setClasses( JAR_CLASS_LIST ); - - assertEquals( "check record", expectedRecord, record ); - } - - public void testIndexedJarAndPom() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - MinimalArtifactIndexRecord expectedRecord = new MinimalArtifactIndexRecord(); - expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); - expectedRecord.setFilename( repository.pathOf( artifact ) ); - expectedRecord.setLastModified( artifact.getFile().lastModified() ); - expectedRecord.setSize( artifact.getFile().length() ); - expectedRecord.setClasses( JAR_CLASS_LIST ); - - assertEquals( "check record", expectedRecord, record ); - } - - public void testIndexedJarAndPomWithClassifier() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar", "jdk14" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - MinimalArtifactIndexRecord expectedRecord = new MinimalArtifactIndexRecord(); - expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); - expectedRecord.setFilename( repository.pathOf( artifact ) ); - expectedRecord.setLastModified( artifact.getFile().lastModified() ); - expectedRecord.setSize( artifact.getFile().length() ); - expectedRecord.setClasses( JAR_CLASS_LIST ); - - assertEquals( "check record", expectedRecord, record ); - } - - public void testIndexedPom() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-pom", "1.0", "pom" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - assertNull( "Check no record", record ); - } - - public void testNonIndexedPom() - throws RepositoryIndexException - { - // If we pass in only the POM that belongs to a JAR, then expect null not the POM - Artifact artifact = createArtifact( "test-jar-and-pom", "1.0-alpha-1", "pom" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - assertNull( "Check no record", record ); - - artifact = createArtifact( "test-plugin", "1.0", "pom" ); - - record = factory.createRecord( artifact ); - - assertNull( "Check no record", record ); - - artifact = createArtifact( "test-archetype", "1.0", "pom" ); - - record = factory.createRecord( artifact ); - - assertNull( "Check no record", record ); - } - - public void testIndexedPlugin() - throws RepositoryIndexException, IOException, XmlPullParserException - { - Artifact artifact = createArtifact( "test-plugin" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - MinimalArtifactIndexRecord expectedRecord = new MinimalArtifactIndexRecord(); - expectedRecord.setMd5Checksum( "06f6fe25e46c4d4fb5be4f56a9bab0ee" ); - expectedRecord.setFilename( repository.pathOf( artifact ) ); - expectedRecord.setLastModified( artifact.getFile().lastModified() ); - expectedRecord.setSize( artifact.getFile().length() ); - expectedRecord.setClasses( Collections.singletonList( "org.apache.maven.repository.record.MyMojo" ) ); - - assertEquals( "check record", expectedRecord, record ); - } - - public void testCorruptJar() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-corrupt-jar" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - assertNull( "Confirm no record is returned", record ); - } - - public void testNonJar() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-dll", "1.0.1.34", "dll" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - assertNull( "Confirm no record is returned", record ); - } - - public void testMissingFile() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-foo" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - assertNull( "Confirm no record is returned", record ); - } - - private Artifact createArtifact( String artifactId ) - { - return createArtifact( artifactId, "1.0", "jar" ); - } - - private Artifact createArtifact( String artifactId, String version, String type ) - { - return createArtifact( artifactId, version, type, null ); - } - - private Artifact createArtifact( String artifactId, String version, String type, String classifier ) - { - Artifact artifact = artifactFactory.createDependencyArtifact( TEST_GROUP_ID, artifactId, - VersionRange.createFromVersion( version ), type, - classifier, Artifact.SCOPE_RUNTIME ); - artifact.isSnapshot(); - artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); - artifact.setRepository( repository ); - return artifact; - } -} diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java deleted file mode 100644 index 790c2bed4..000000000 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java +++ /dev/null @@ -1,382 +0,0 @@ -package org.apache.maven.repository.indexing.record; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.repository.indexing.RepositoryIndexException; -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.List; - -/** - * Test the minimal artifact index record. - * - * @author Brett Porter - */ -public class StandardArtifactIndexRecordFactoryTest - extends PlexusTestCase -{ - private RepositoryIndexRecordFactory factory; - - private ArtifactRepository repository; - - private ArtifactFactory artifactFactory; - - private static final String TEST_GROUP_ID = "org.apache.maven.repository.record"; - - private static final List JAR_CLASS_LIST = Arrays.asList( new String[]{"A", "b.B", "b.c.C"} ); - - private static final List JAR_FILE_LIST = - Arrays.asList( new String[]{"META-INF/MANIFEST.MF", "A.class", "b/B.class", "b/c/C.class"} ); - - protected void setUp() - throws Exception - { - super.setUp(); - - factory = (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "standard" ); - - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - - ArtifactRepositoryFactory repositoryFactory = - (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - - File file = getTestFile( "src/test/managed-repository" ); - repository = - repositoryFactory.createArtifactRepository( "test", file.toURI().toURL().toString(), layout, null, null ); - } - - public void testIndexedJar() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-jar" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); - expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); - expectedRecord.setFilename( repository.pathOf( artifact ) ); - expectedRecord.setLastModified( artifact.getFile().lastModified() ); - expectedRecord.setSize( artifact.getFile().length() ); - expectedRecord.setClasses( JAR_CLASS_LIST ); - expectedRecord.setArtifactId( "test-jar" ); - expectedRecord.setGroupId( TEST_GROUP_ID ); - expectedRecord.setBaseVersion( "1.0" ); - expectedRecord.setVersion( "1.0" ); - expectedRecord.setFiles( JAR_FILE_LIST ); - expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" ); - expectedRecord.setType( "jar" ); - expectedRecord.setRepository( "test" ); - - assertEquals( "check record", expectedRecord, record ); - } - - public void testIndexedJarWithClassifier() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-jar", "1.0", "jar", "jdk14" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); - expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); - expectedRecord.setFilename( repository.pathOf( artifact ) ); - expectedRecord.setLastModified( artifact.getFile().lastModified() ); - expectedRecord.setSize( artifact.getFile().length() ); - expectedRecord.setClasses( JAR_CLASS_LIST ); - expectedRecord.setArtifactId( "test-jar" ); - expectedRecord.setGroupId( TEST_GROUP_ID ); - expectedRecord.setBaseVersion( "1.0" ); - expectedRecord.setVersion( "1.0" ); - expectedRecord.setFiles( JAR_FILE_LIST ); - expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" ); - expectedRecord.setType( "jar" ); - expectedRecord.setRepository( "test" ); - expectedRecord.setClassifier( "jdk14" ); - - assertEquals( "check record", expectedRecord, record ); - } - - public void testIndexedJarAndPom() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); - expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); - expectedRecord.setFilename( repository.pathOf( artifact ) ); - expectedRecord.setLastModified( artifact.getFile().lastModified() ); - expectedRecord.setSize( artifact.getFile().length() ); - expectedRecord.setClasses( JAR_CLASS_LIST ); - expectedRecord.setArtifactId( "test-jar-and-pom" ); - expectedRecord.setGroupId( TEST_GROUP_ID ); - expectedRecord.setBaseVersion( "1.0-alpha-1" ); - expectedRecord.setVersion( "1.0-alpha-1" ); - expectedRecord.setFiles( JAR_FILE_LIST ); - expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" ); - expectedRecord.setType( "jar" ); - expectedRecord.setRepository( "test" ); - expectedRecord.setPackaging( "jar" ); - expectedRecord.setProjectName( "Test JAR and POM" ); - - assertEquals( "check record", expectedRecord, record ); - } - - public void testIndexedJarAndPomWithClassifier() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-jar-and-pom", "1.0-alpha-1", "jar", "jdk14" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); - expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); - expectedRecord.setFilename( repository.pathOf( artifact ) ); - expectedRecord.setLastModified( artifact.getFile().lastModified() ); - expectedRecord.setSize( artifact.getFile().length() ); - expectedRecord.setClasses( JAR_CLASS_LIST ); - expectedRecord.setArtifactId( "test-jar-and-pom" ); - expectedRecord.setGroupId( TEST_GROUP_ID ); - expectedRecord.setBaseVersion( "1.0-alpha-1" ); - expectedRecord.setVersion( "1.0-alpha-1" ); - expectedRecord.setFiles( JAR_FILE_LIST ); - expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" ); - expectedRecord.setType( "jar" ); - expectedRecord.setRepository( "test" ); - expectedRecord.setPackaging( "jar" ); - expectedRecord.setProjectName( "Test JAR and POM" ); - expectedRecord.setClassifier( "jdk14" ); - - assertEquals( "check record", expectedRecord, record ); - } - - public void testIndexedJarWithParentPom() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-child-pom", "1.0-20060728.121314-1", "jar" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); - expectedRecord.setMd5Checksum( "3a0adc365f849366cd8b633cad155cb7" ); - expectedRecord.setFilename( repository.pathOf( artifact ) ); - expectedRecord.setLastModified( artifact.getFile().lastModified() ); - expectedRecord.setSize( artifact.getFile().length() ); - expectedRecord.setClasses( JAR_CLASS_LIST ); - expectedRecord.setArtifactId( "test-child-pom" ); - expectedRecord.setGroupId( TEST_GROUP_ID ); - expectedRecord.setBaseVersion( "1.0-SNAPSHOT" ); - expectedRecord.setVersion( "1.0-20060728.121314-1" ); - expectedRecord.setFiles( JAR_FILE_LIST ); - expectedRecord.setSha1Checksum( "c66f18bf192cb613fc2febb4da541a34133eedc2" ); - expectedRecord.setType( "jar" ); - expectedRecord.setRepository( "test" ); - expectedRecord.setPackaging( "jar" ); - expectedRecord.setProjectName( "Child Project" ); - expectedRecord.setProjectDescription( "Description" ); - expectedRecord.setInceptionYear( "2005" ); - - assertEquals( "check record", expectedRecord, record ); - } - - public void testIndexedPom() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-pom", "1.0", "pom" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); - expectedRecord.setMd5Checksum( "32dbef7ff11eb933bd8b7e7bcab85406" ); - expectedRecord.setFilename( repository.pathOf( artifact ) ); - expectedRecord.setLastModified( artifact.getFile().lastModified() ); - expectedRecord.setSize( artifact.getFile().length() ); - expectedRecord.setArtifactId( "test-pom" ); - expectedRecord.setGroupId( TEST_GROUP_ID ); - expectedRecord.setBaseVersion( "1.0" ); - expectedRecord.setVersion( "1.0" ); - expectedRecord.setSha1Checksum( "c3b374e394607e1e705e71c227f62641e8621ebe" ); - expectedRecord.setType( "pom" ); - expectedRecord.setRepository( "test" ); - expectedRecord.setPackaging( "pom" ); - expectedRecord.setInceptionYear( "2005" ); - expectedRecord.setProjectName( "Maven Repository Manager Test POM" ); - expectedRecord.setProjectDescription( "Description" ); - - assertEquals( "check record", expectedRecord, record ); - } - - public void testNonIndexedPom() - throws RepositoryIndexException - { - // If we pass in only the POM that belongs to a JAR, then expect null not the POM - Artifact artifact = createArtifact( "test-jar-and-pom", "1.0", "pom" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - assertNull( "Check no record", record ); - - artifact = createArtifact( "test-plugin", "1.0", "pom" ); - - record = factory.createRecord( artifact ); - - assertNull( "Check no record", record ); - - artifact = createArtifact( "test-archetype", "1.0", "pom" ); - - record = factory.createRecord( artifact ); - - assertNull( "Check no record", record ); - } - - public void testIndexedPlugin() - throws RepositoryIndexException, IOException, XmlPullParserException - { - Artifact artifact = createArtifact( "test-plugin" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); - expectedRecord.setMd5Checksum( "06f6fe25e46c4d4fb5be4f56a9bab0ee" ); - expectedRecord.setFilename( repository.pathOf( artifact ) ); - expectedRecord.setLastModified( artifact.getFile().lastModified() ); - expectedRecord.setSize( artifact.getFile().length() ); - expectedRecord.setArtifactId( "test-plugin" ); - expectedRecord.setGroupId( TEST_GROUP_ID ); - expectedRecord.setBaseVersion( "1.0" ); - expectedRecord.setVersion( "1.0" ); - expectedRecord.setSha1Checksum( "382c1ebfb5d0c7d6061c2f8569fb53f8fc00fec2" ); - expectedRecord.setType( "maven-plugin" ); - expectedRecord.setRepository( "test" ); - expectedRecord.setClasses( Arrays.asList( new String[]{"org.apache.maven.repository.record.MyMojo"} ) ); - expectedRecord.setFiles( Arrays.asList( new String[]{"META-INF/MANIFEST.MF", "META-INF/maven/plugin.xml", - "org/apache/maven/repository/record/MyMojo.class", - "META-INF/maven/org.apache.maven.repository.record/test-plugin/pom.xml", - "META-INF/maven/org.apache.maven.repository.record/test-plugin/pom.properties"} ) ); - expectedRecord.setPackaging( "maven-plugin" ); - expectedRecord.setProjectName( "Maven Mojo Archetype" ); - expectedRecord.setPluginPrefix( "test" ); - - assertEquals( "check record", expectedRecord, record ); - } - - public void testIndexedArchetype() - throws RepositoryIndexException, IOException, XmlPullParserException - { - Artifact artifact = createArtifact( "test-archetype" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); - expectedRecord.setMd5Checksum( "ecefd4674c75a175119572b19edc45f1" ); - expectedRecord.setFilename( repository.pathOf( artifact ) ); - expectedRecord.setLastModified( artifact.getFile().lastModified() ); - expectedRecord.setSize( artifact.getFile().length() ); - expectedRecord.setArtifactId( "test-archetype" ); - expectedRecord.setGroupId( TEST_GROUP_ID ); - expectedRecord.setBaseVersion( "1.0" ); - expectedRecord.setVersion( "1.0" ); - expectedRecord.setSha1Checksum( "5ebabafdbcd6684ae434c06e22c32844df284b05" ); - expectedRecord.setType( "maven-archetype" ); - expectedRecord.setRepository( "test" ); - expectedRecord.setFiles( Arrays.asList( new String[]{"META-INF/MANIFEST.MF", "archetype-resources/pom.xml", - "archetype-resources/src/main/java/App.java", "archetype-resources/src/test/java/AppTest.java", - "META-INF/maven/archetype.xml", "META-INF/maven/org.apache.maven.repository.record/test-archetype/pom.xml", - "META-INF/maven/org.apache.maven.repository.record/test-archetype/pom.properties"} ) ); - expectedRecord.setPackaging( "jar" ); - expectedRecord.setProjectName( "Archetype - test-archetype" ); - - assertEquals( "check record", expectedRecord, record ); - } - - public void testCorruptJar() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-corrupt-jar" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - assertNull( "Confirm no record is returned", record ); - } - - public void testDll() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-dll", "1.0.1.34", "dll" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - StandardArtifactIndexRecord expectedRecord = new StandardArtifactIndexRecord(); - expectedRecord.setMd5Checksum( "d41d8cd98f00b204e9800998ecf8427e" ); - expectedRecord.setFilename( repository.pathOf( artifact ) ); - expectedRecord.setLastModified( artifact.getFile().lastModified() ); - expectedRecord.setSize( artifact.getFile().length() ); - expectedRecord.setArtifactId( "test-dll" ); - expectedRecord.setGroupId( TEST_GROUP_ID ); - expectedRecord.setBaseVersion( "1.0.1.34" ); - expectedRecord.setVersion( "1.0.1.34" ); - expectedRecord.setSha1Checksum( "da39a3ee5e6b4b0d3255bfef95601890afd80709" ); - expectedRecord.setType( "dll" ); - expectedRecord.setRepository( "test" ); - - assertEquals( "check record", expectedRecord, record ); - } - - public void testMissingFile() - throws RepositoryIndexException - { - Artifact artifact = createArtifact( "test-foo" ); - - RepositoryIndexRecord record = factory.createRecord( artifact ); - - assertNull( "Confirm no record is returned", record ); - } - - private Artifact createArtifact( String artifactId ) - { - return createArtifact( artifactId, "1.0", "jar" ); - } - - private Artifact createArtifact( String artifactId, String version, String type ) - { - return createArtifact( artifactId, version, type, null ); - } - - private Artifact createArtifact( String artifactId, String version, String type, String classifier ) - { - Artifact artifact = artifactFactory.createDependencyArtifact( TEST_GROUP_ID, artifactId, - VersionRange.createFromVersion( version ), type, - classifier, Artifact.SCOPE_RUNTIME ); - artifact.isSnapshot(); - artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); - artifact.setRepository( repository ); - return artifact; - } -} diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/parent-pom/1/parent-pom-1.pom b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/parent-pom/1/parent-pom-1.pom deleted file mode 100644 index 162f02ac6..000000000 --- a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/parent-pom/1/parent-pom-1.pom +++ /dev/null @@ -1,38 +0,0 @@ - - - 4.0.0 - org.apache.maven.repository.record - parent-pom - 1 - pom - Test Parent POM - Description - 2005 - - - junit - junit - 3.8.1 - test - - - - test-child-pom - - - diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.jar b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.jar deleted file mode 100644 index e1686a206..000000000 Binary files a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.jar and /dev/null differ diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.pom b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.pom deleted file mode 100644 index 7b9d7c7f7..000000000 --- a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-archetype/1.0/test-archetype-1.0.pom +++ /dev/null @@ -1,8 +0,0 @@ - - 4.0.0 - org.apache.maven.repository.record - test-archetype - 1.0 - Archetype - test-archetype - diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.jar b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.jar deleted file mode 100644 index b78be2eb8..000000000 Binary files a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.jar and /dev/null differ diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.pom b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.pom deleted file mode 100644 index b247e7aa3..000000000 --- a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-child-pom/1.0-SNAPSHOT/test-child-pom-1.0-20060728.121314-1.pom +++ /dev/null @@ -1,28 +0,0 @@ - - - - 4.0.0 - - org.apache.maven.repository.record - parent-pom - 1 - - test-child-pom - 1.0-20060731-121314-1 - Child Project - diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-corrupt-jar/1.0/test-corrupt-jar-1.0.jar b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-corrupt-jar/1.0/test-corrupt-jar-1.0.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-dll/1.0.1.34/test-dll-1.0.1.34.dll b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-dll/1.0.1.34/test-dll-1.0.1.34.dll deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1-jdk14.jar b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1-jdk14.jar deleted file mode 100644 index b78be2eb8..000000000 Binary files a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1-jdk14.jar and /dev/null differ diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.jar b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.jar deleted file mode 100644 index b78be2eb8..000000000 Binary files a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.jar and /dev/null differ diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.pom b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.pom deleted file mode 100644 index 6d2d2a78a..000000000 --- a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.pom +++ /dev/null @@ -1,32 +0,0 @@ - - - - 4.0.0 - org.apache.maven.repository.record - test-jar-and-pom - 1.0-alpha-1 - Test JAR and POM - - - junit - junit - 3.8.1 - test - - - diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar/1.0/test-jar-1.0-jdk14.jar b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar/1.0/test-jar-1.0-jdk14.jar deleted file mode 100644 index b78be2eb8..000000000 Binary files a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar/1.0/test-jar-1.0-jdk14.jar and /dev/null differ diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar/1.0/test-jar-1.0.jar b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar/1.0/test-jar-1.0.jar deleted file mode 100644 index b78be2eb8..000000000 Binary files a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-jar/1.0/test-jar-1.0.jar and /dev/null differ diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.jar b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.jar deleted file mode 100644 index a7f3a67a8..000000000 Binary files a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.jar and /dev/null differ diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.pom b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.pom deleted file mode 100644 index 7baa980d2..000000000 --- a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-plugin/1.0/test-plugin-1.0.pom +++ /dev/null @@ -1,22 +0,0 @@ - - 4.0.0 - org.apache.maven.repository.record - test-plugin - maven-plugin - 1.0 - Maven Mojo Archetype - - - org.apache.maven - maven-plugin-api - 2.0 - - - junit - junit - 3.8.1 - test - - - diff --git a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-pom/1.0/test-pom-1.0.pom b/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-pom/1.0/test-pom-1.0.pom deleted file mode 100644 index 34b9e1f3f..000000000 --- a/maven-repository-indexer/src/test/managed-repository/org/apache/maven/repository/record/test-pom/1.0/test-pom-1.0.pom +++ /dev/null @@ -1,11 +0,0 @@ - - 4.0.0 - org.apache.maven.repository.record - test-pom - 1.0 - Maven Repository Manager Test POM - 2005 - Description - pom - diff --git a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-artifact-2.0.1.jar b/maven-repository-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-artifact-2.0.1.jar deleted file mode 100644 index 14fa95ab9..000000000 Binary files a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-artifact-2.0.1.jar and /dev/null differ diff --git a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-artifact-2.0.1.pom b/maven-repository-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-artifact-2.0.1.pom deleted file mode 100644 index 0121c43d3..000000000 --- a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-artifact-2.0.1.pom +++ /dev/null @@ -1,45 +0,0 @@ - - - - maven - org.apache.maven - 2.0.1 - - 4.0.0 - org.apache.maven - maven-artifact - Maven Artifact - 2.0.1 - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - - org.codehaus.plexus - plexus-utils - 1.0.5 - - - org.codehaus.plexus - plexus-container-default - 1.0-alpha-9 - test - - - - deployed - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.0 - - - - \ No newline at end of file diff --git a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-metadata.xml b/maven-repository-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-metadata.xml deleted file mode 100644 index f9f9abc99..000000000 --- a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-artifact/2.0.1/maven-metadata.xml +++ /dev/null @@ -1,5 +0,0 @@ - - org.apache.maven - maven-artifact - 2.0.1 - diff --git a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-artifact/maven-metadata.xml b/maven-repository-indexer/src/test/repository/org/apache/maven/maven-artifact/maven-metadata.xml deleted file mode 100644 index d4b28f93e..000000000 --- a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-artifact/maven-metadata.xml +++ /dev/null @@ -1,12 +0,0 @@ - - org.apache.maven - maven-artifact - 2.0.1 - - 2.0.1 - - 2.0.1 - - 20051212044643 - - diff --git a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.jar b/maven-repository-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.jar deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.pom b/maven-repository-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.pom deleted file mode 100644 index e5dc3f3a8..000000000 --- a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-corrupt-jar/2.0/maven-corrupt-jar-2.0.pom +++ /dev/null @@ -1,95 +0,0 @@ - - - maven - org.apache.maven - 2.0 - - 4.0.0 - org.apache.maven - maven-corrupt-jar - Maven Model - 2.0 - Maven Model - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - - - org.codehaus.modello - modello-maven-plugin - 2.0 - - - - xpp3-writer - java - xpp3-reader - xsd - - - - - 4.0.0 - maven.mdo - - - - - - - all-models - - - - org.codehaus.modello - modello-maven-plugin - - - v3 - - xpp3-writer - java - xpp3-reader - xsd - - - 3.0.0 - true - - - - - - maven-jar-plugin - - - package - - jar - - - all - - - - - - - - - - - org.codehaus.plexus - plexus-utils - 1.0.5 - - - - deployed - - \ No newline at end of file diff --git a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-metadata.xml b/maven-repository-indexer/src/test/repository/org/apache/maven/maven-metadata.xml deleted file mode 100644 index 3a837529b..000000000 --- a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-metadata.xml +++ /dev/null @@ -1,9 +0,0 @@ - - org.apache.maven - - - org.apache.maven - org.apache.maven-maven-plugin - - - diff --git a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar b/maven-repository-indexer/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar deleted file mode 100644 index d6820d6fe..000000000 Binary files a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar and /dev/null differ diff --git a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom b/maven-repository-indexer/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom deleted file mode 100644 index 2abd766dc..000000000 --- a/maven-repository-indexer/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom +++ /dev/null @@ -1,95 +0,0 @@ - - - maven - org.apache.maven - 2.0 - - 4.0.0 - org.apache.maven - maven-model - Maven Model - 2.0 - Maven Model - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - - - org.codehaus.modello - modello-maven-plugin - 2.0 - - - - xpp3-writer - java - xpp3-reader - xsd - - - - - 4.0.0 - maven.mdo - - - - - - - all-models - - - - org.codehaus.modello - modello-maven-plugin - - - v3 - - xpp3-writer - java - xpp3-reader - xsd - - - 3.0.0 - true - - - - - - maven-jar-plugin - - - package - - jar - - - all - - - - - - - - - - - org.codehaus.plexus - plexus-utils - 1.0.5 - - - - deployed - - \ No newline at end of file diff --git a/maven-repository-indexer/src/test/repository/test/inherited/test-inherited/1.0.15/test-inherited-1.0.15.pom b/maven-repository-indexer/src/test/repository/test/inherited/test-inherited/1.0.15/test-inherited-1.0.15.pom deleted file mode 100644 index 19faa7910..000000000 --- a/maven-repository-indexer/src/test/repository/test/inherited/test-inherited/1.0.15/test-inherited-1.0.15.pom +++ /dev/null @@ -1,11 +0,0 @@ - - 4.0.0 - - test.inherited - 1.0.15 - test-inherited-parent - - - test-inherited - pom - \ No newline at end of file diff --git a/maven-repository-indexer/src/test/repository/test/maven-metadata.xml b/maven-repository-indexer/src/test/repository/test/maven-metadata.xml deleted file mode 100644 index e1f2008ef..000000000 --- a/maven-repository-indexer/src/test/repository/test/maven-metadata.xml +++ /dev/null @@ -1,9 +0,0 @@ - - test - - - - test-test-plugin - - - diff --git a/maven-repository-indexer/src/test/repository/test/test-artifactId/1.0/test-artifactId-1.0.jar b/maven-repository-indexer/src/test/repository/test/test-artifactId/1.0/test-artifactId-1.0.jar deleted file mode 100644 index 00eb58b70..000000000 Binary files a/maven-repository-indexer/src/test/repository/test/test-artifactId/1.0/test-artifactId-1.0.jar and /dev/null differ diff --git a/maven-repository-indexer/src/test/repository/test/test-artifactId/1.0/test-artifactId-1.0.pom b/maven-repository-indexer/src/test/repository/test/test-artifactId/1.0/test-artifactId-1.0.pom deleted file mode 100644 index 157d74f41..000000000 --- a/maven-repository-indexer/src/test/repository/test/test-artifactId/1.0/test-artifactId-1.0.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 4.0.0 - test - test-artifactId - 1.0 - \ No newline at end of file diff --git a/maven-repository-proxy/pom.xml b/maven-repository-proxy/pom.xml deleted file mode 100644 index 77bdc01de..000000000 --- a/maven-repository-proxy/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - org.apache.maven.repository - maven-repository-manager - 1.0-SNAPSHOT - - 4.0.0 - maven-repository-proxy - Maven Repository Proxy - - - org.apache.maven.repository - maven-repository-discovery - - - org.apache.maven - maven-artifact - - - org.apache.maven.wagon - wagon-file - test - - - org.apache.maven.wagon - wagon-provider-api - - - easymock - easymock - 1.2_Java1.3 - test - - - diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyRequestHandler.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyRequestHandler.java deleted file mode 100644 index 90a21726a..000000000 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyRequestHandler.java +++ /dev/null @@ -1,672 +0,0 @@ -package org.apache.maven.repository.proxy; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; -import org.apache.maven.artifact.repository.metadata.Metadata; -import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; -import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer; -import org.apache.maven.repository.digest.DigestUtils; -import org.apache.maven.repository.digest.DigesterException; -import org.apache.maven.repository.discovery.ArtifactDiscoverer; -import org.apache.maven.repository.discovery.DiscovererException; -import org.apache.maven.wagon.ConnectionException; -import org.apache.maven.wagon.ResourceDoesNotExistException; -import org.apache.maven.wagon.TransferFailedException; -import org.apache.maven.wagon.Wagon; -import org.apache.maven.wagon.authentication.AuthenticationException; -import org.apache.maven.wagon.authorization.AuthorizationException; -import org.apache.maven.wagon.observers.ChecksumObserver; -import org.apache.maven.wagon.proxy.ProxyInfo; -import org.apache.maven.wagon.repository.Repository; -import org.codehaus.plexus.logging.AbstractLogEnabled; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.security.NoSuchAlgorithmException; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * An implementation of the proxy handler. This class is not thread safe (the class itself is, but the wagons it uses - * are not) - it is declared per-lookup for that reason. - * - * @author Brett Porter - * @plexus.component instantiation-strategy="per-lookup" - * @todo use wagonManager for cache use file:// as URL - * @todo this currently duplicates a lot of the wagon manager, and doesn't do things like snapshot resolution, etc. - * The checksum handling is inconsistent with that of the wagon manager. - * Should we have a more artifact based one? This will merge metadata so should behave correctly, and it is able to - * correct some limitations of the wagon manager (eg, it can retrieve newer SNAPSHOT files without metadata) - */ -public class DefaultProxyRequestHandler - extends AbstractLogEnabled - implements ProxyRequestHandler -{ - /** - * @plexus.requirement role-hint="default" - * @todo use a map, and have priorities in them - */ - private ArtifactDiscoverer defaultArtifactDiscoverer; - - /** - * @plexus.requirement role-hint="legacy" - */ - private ArtifactDiscoverer legacyArtifactDiscoverer; - - /** - * @plexus.requirement role="org.apache.maven.wagon.Wagon" - */ - private Map/**/ wagons; - - public File get( String path, List proxiedRepositories, ArtifactRepository managedRepository ) - throws ProxyException, ResourceDoesNotExistException - { - return get( path, proxiedRepositories, managedRepository, null ); - } - - public File get( String path, List proxiedRepositories, ArtifactRepository managedRepository, ProxyInfo wagonProxy ) - throws ProxyException, ResourceDoesNotExistException - { - return get( managedRepository, path, proxiedRepositories, wagonProxy, false ); - } - - public File getAlways( String path, List proxiedRepositories, ArtifactRepository managedRepository ) - throws ProxyException, ResourceDoesNotExistException - { - return getAlways( path, proxiedRepositories, managedRepository, null ); - } - - public File getAlways( String path, List proxiedRepositories, ArtifactRepository managedRepository, - ProxyInfo wagonProxy ) - throws ResourceDoesNotExistException, ProxyException - { - return get( managedRepository, path, proxiedRepositories, wagonProxy, true ); - } - - private File get( ArtifactRepository managedRepository, String path, List proxiedRepositories, ProxyInfo wagonProxy, - boolean force ) - throws ProxyException, ResourceDoesNotExistException - { - File target = new File( managedRepository.getBasedir(), path ); - - for ( Iterator i = proxiedRepositories.iterator(); i.hasNext(); ) - { - ProxiedArtifactRepository repository = (ProxiedArtifactRepository) i.next(); - - if ( !force && repository.isCachedFailure( path ) ) - { - processCachedRepositoryFailure( repository, "Cached failure found for: " + path ); - } - else - { - get( path, target, repository, managedRepository, wagonProxy, force ); - } - } - - if ( !target.exists() ) - { - throw new ResourceDoesNotExistException( "Could not find " + path + " in any of the repositories." ); - } - - return target; - } - - private void get( String path, File target, ProxiedArtifactRepository repository, - ArtifactRepository managedRepository, ProxyInfo wagonProxy, boolean force ) - throws ProxyException - { - ArtifactRepositoryPolicy policy; - - if ( path.endsWith( ".md5" ) || path.endsWith( ".sha1" ) ) - { - // always read from the managed repository, no need to make remote request - } - else if ( path.endsWith( "maven-metadata.xml" ) ) - { - File metadataFile = new File( target.getParentFile(), ".metadata-" + repository.getRepository().getId() ); - - policy = repository.getRepository().getReleases(); - - // if it is snapshot metadata, use a different policy - if ( path.endsWith( "-SNAPSHOT/maven-metadata.xml" ) ) - { - policy = repository.getRepository().getSnapshots(); - } - - if ( force || !metadataFile.exists() || isOutOfDate( policy, metadataFile ) ) - { - getFileFromRepository( path, repository, managedRepository.getBasedir(), wagonProxy, metadataFile, - policy, force ); - - mergeMetadataFiles( target, metadataFile ); - } - } - else - { - Artifact artifact = null; - try - { - artifact = defaultArtifactDiscoverer.buildArtifact( path ); - } - catch ( DiscovererException e ) - { - getLogger().debug( "Failed to build artifact using default layout with message: " + e.getMessage() ); - } - - if ( artifact == null ) - { - try - { - artifact = legacyArtifactDiscoverer.buildArtifact( path ); - } - catch ( DiscovererException e ) - { - getLogger().debug( "Failed to build artifact using legacy layout with message: " + e.getMessage() ); - } - } - - if ( artifact != null ) - { - ArtifactRepository artifactRepository = repository.getRepository(); - - // we use the release policy for tracking failures, but only check for updates on snapshots - // also, we don't look for updates on timestamp snapshot files, only non-unique-version ones - policy = artifact.isSnapshot() ? artifactRepository.getSnapshots() : artifactRepository.getReleases(); - - boolean needsUpdate = false; - if ( artifact.getVersion().endsWith( "-SNAPSHOT" ) && isOutOfDate( policy, target ) ) - { - needsUpdate = true; - } - - if ( needsUpdate || force || !target.exists() ) - { - getFileFromRepository( artifactRepository.pathOf( artifact ), repository, - managedRepository.getBasedir(), wagonProxy, target, policy, force ); - } - } - else - { - // Some other unknown file in the repository, proxy as is - if ( force || !target.exists() ) - { - policy = repository.getRepository().getReleases(); - getFileFromRepository( path, repository, managedRepository.getBasedir(), wagonProxy, target, policy, - force ); - } - } - } - - if ( target.exists() ) - { - // in case it previously failed and we've since found it - repository.clearFailure( path ); - } - } - - private void mergeMetadataFiles( File target, File metadataFile ) - throws ProxyException - { - MetadataXpp3Reader reader = new MetadataXpp3Reader(); - if ( metadataFile.exists() ) - { - Metadata metadata = null; - if ( target.exists() ) - { - FileReader fileReader = null; - try - { - fileReader = new FileReader( target ); - metadata = reader.read( fileReader ); - } - catch ( XmlPullParserException e ) - { - throw new ProxyException( "Unable to parse existing metadata: " + e.getMessage(), e ); - } - catch ( IOException e ) - { - throw new ProxyException( "Unable to read existing metadata: " + e.getMessage(), e ); - } - finally - { - IOUtil.close( fileReader ); - } - } - - FileReader fileReader = null; - boolean changed = false; - try - { - fileReader = new FileReader( metadataFile ); - Metadata newMetadata = reader.read( fileReader ); - - if ( metadata != null ) - { - changed = metadata.merge( newMetadata ); - } - else - { - metadata = newMetadata; - changed = true; - } - } - catch ( IOException e ) - { - // ignore the merged file - getLogger().warn( "Unable to read new metadata: " + e.getMessage() ); - } - catch ( XmlPullParserException e ) - { - // ignore the merged file - getLogger().warn( "Unable to parse new metadata: " + e.getMessage() ); - } - finally - { - IOUtil.close( fileReader ); - } - - if ( changed ) - { - FileWriter fileWriter = null; - try - { - fileWriter = new FileWriter( target ); - new MetadataXpp3Writer().write( fileWriter, metadata ); - } - catch ( IOException e ) - { - getLogger().warn( "Unable to store new metadata: " + e.getMessage() ); - } - finally - { - IOUtil.close( fileWriter ); - } - } - } - } - - private void getFileFromRepository( String path, ProxiedArtifactRepository repository, String repositoryCachePath, - ProxyInfo httpProxy, File target, ArtifactRepositoryPolicy policy, - boolean force ) - throws ProxyException - { - if ( !policy.isEnabled() ) - { - getLogger().debug( "Skipping disabled repository " + repository.getName() ); - return; - } - - Map checksums = null; - Wagon wagon = null; - - File temp = new File( target.getAbsolutePath() + ".tmp" ); - temp.deleteOnExit(); - - boolean connected = false; - try - { - String protocol = repository.getRepository().getProtocol(); - wagon = (Wagon) wagons.get( protocol ); - if ( wagon == null ) - { - throw new ProxyException( "Unsupported remote protocol: " + protocol ); - } - - //@todo configure wagon (ssh settings, etc) - - checksums = prepareChecksumListeners( wagon ); - - connected = connectToRepository( wagon, repository, httpProxy ); - if ( connected ) - { - int tries = 0; - boolean success; - - do - { - tries++; - - getLogger().debug( "Trying " + path + " from " + repository.getName() + "..." ); - - boolean downloaded = true; - if ( force || !target.exists() ) - { - wagon.get( path, temp ); - } - else - { - downloaded = wagon.getIfNewer( path, temp, target.lastModified() ); - } - - if ( downloaded ) - { - success = checkChecksum( checksums, path, wagon, repositoryCachePath ); - - if ( tries > 1 && !success ) - { - processRepositoryFailure( repository, - "Checksum failures occurred while downloading " + path, path, - policy ); - return; - } - } - else - { - // getIfNewer determined we were up to date - success = true; - } - } - while ( !success ); - - // temp won't exist if we called getIfNewer and it was older, but its still a successful return - if ( temp.exists() ) - { - moveTempToTarget( temp, target ); - } - } - //try next repository - } - catch ( TransferFailedException e ) - { - processRepositoryFailure( repository, e, path, policy ); - } - catch ( AuthorizationException e ) - { - processRepositoryFailure( repository, e, path, policy ); - } - catch ( ResourceDoesNotExistException e ) - { - // hard failure setting doesn't affect "not found". - getLogger().debug( "Artifact not found in repository: " + repository.getName() + ": " + e.getMessage() ); - } - finally - { - temp.delete(); - - if ( wagon != null && checksums != null ) - { - releaseChecksumListeners( wagon, checksums ); - } - - if ( connected ) - { - disconnectWagon( wagon ); - } - } - } - - private static boolean isOutOfDate( ArtifactRepositoryPolicy policy, File target ) - { - return policy != null && policy.checkOutOfDate( new Date( target.lastModified() ) ); - } - - /** - * Used to add checksum observers as transfer listeners to the wagonManager object - * - * @param wagon the wagonManager object to use the checksum with - * @return map of ChecksumObservers added into the wagonManager transfer listeners - */ - private Map prepareChecksumListeners( Wagon wagon ) - { - Map checksums = new LinkedHashMap(); - try - { - ChecksumObserver checksum = new ChecksumObserver( "SHA-1" ); - wagon.addTransferListener( checksum ); - checksums.put( "sha1", checksum ); - - checksum = new ChecksumObserver( "MD5" ); - wagon.addTransferListener( checksum ); - checksums.put( "md5", checksum ); - } - catch ( NoSuchAlgorithmException e ) - { - getLogger().error( "An error occurred while preparing checksum observers: " + e.getMessage() ); - } - return checksums; - } - - private void releaseChecksumListeners( Wagon wagon, Map checksumMap ) - { - for ( Iterator checksums = checksumMap.values().iterator(); checksums.hasNext(); ) - { - ChecksumObserver listener = (ChecksumObserver) checksums.next(); - wagon.removeTransferListener( listener ); - } - } - - private boolean connectToRepository( Wagon wagon, ProxiedArtifactRepository repository, ProxyInfo httpProxy ) - { - boolean connected = false; - try - { - ArtifactRepository artifactRepository = repository.getRepository(); - Repository wagonRepository = new Repository( artifactRepository.getId(), artifactRepository.getUrl() ); - if ( repository.isUseNetworkProxy() && httpProxy != null ) - { - wagon.connect( wagonRepository, httpProxy ); - } - else - { - wagon.connect( wagonRepository ); - } - connected = true; - } - catch ( ConnectionException e ) - { - getLogger().info( "Could not connect to " + repository.getName() + ": " + e.getMessage() ); - } - catch ( AuthenticationException e ) - { - getLogger().info( "Could not connect to " + repository.getName() + ": " + e.getMessage() ); - } - - return connected; - } - - private boolean checkChecksum( Map checksumMap, String path, Wagon wagon, String repositoryCachePath ) - throws ProxyException - { - releaseChecksumListeners( wagon, checksumMap ); - - boolean correctChecksum = false; - - boolean allNotFound = true; - - for ( Iterator i = checksumMap.keySet().iterator(); i.hasNext() && !correctChecksum; ) - { - String checksumExt = (String) i.next(); - ChecksumObserver checksum = (ChecksumObserver) checksumMap.get( checksumExt ); - String checksumPath = path + "." + checksumExt; - File checksumFile = new File( repositoryCachePath, checksumPath ); - - File tempChecksumFile = new File( checksumFile.getAbsolutePath() + ".tmp" ); - tempChecksumFile.deleteOnExit(); - - try - { - wagon.get( checksumPath, tempChecksumFile ); - - allNotFound = false; - - String remoteChecksum = DigestUtils.cleanChecksum( FileUtils.fileRead( tempChecksumFile ), - checksumExt.toUpperCase(), - path.substring( path.lastIndexOf( '/' ) ) ); - - String actualChecksum = checksum.getActualChecksum().toUpperCase(); - remoteChecksum = remoteChecksum.toUpperCase(); - - if ( remoteChecksum.equals( actualChecksum ) ) - { - moveTempToTarget( tempChecksumFile, checksumFile ); - - correctChecksum = true; - } - else - { - getLogger().warn( - "The checksum '" + actualChecksum + "' did not match the remote value: " + remoteChecksum ); - } - } - catch ( TransferFailedException e ) - { - getLogger().warn( "An error occurred during the download of " + checksumPath + ": " + e.getMessage() ); - // do nothing try the next checksum - - allNotFound = false; - } - catch ( ResourceDoesNotExistException e ) - { - getLogger().debug( "The checksum did not exist: " + checksumPath + "; " + e.getMessage() ); - // do nothing try the next checksum - // remove it if it is present locally in case there is an old incorrect one - if ( checksumFile.exists() ) - { - checksumFile.delete(); - } - } - catch ( AuthorizationException e ) - { - getLogger().warn( "An error occurred during the download of " + checksumPath + ": " + e.getMessage() ); - // do nothing try the next checksum - - allNotFound = false; - } - catch ( IOException e ) - { - getLogger().warn( "An error occurred while reading the temporary checksum file: " + e.getMessage() ); - // do nothing try the next checksum - - allNotFound = false; - } - catch ( DigesterException e ) - { - getLogger().warn( "The checksum was invalid: " + checksumPath + ": " + e.getMessage() ); - // do nothing try the next checksum - - allNotFound = false; - } - finally - { - tempChecksumFile.delete(); - } - } - return correctChecksum || allNotFound; - } - - /** - * Used to move the temporary file to its real destination. This is patterned from the way WagonManager handles - * its downloaded files. - * - * @param temp The completed download file - * @param target The final location of the downloaded file - * @throws ProxyException when the temp file cannot replace the target file - */ - private void moveTempToTarget( File temp, File target ) - throws ProxyException - { - if ( target.exists() && !target.delete() ) - { - throw new ProxyException( "Unable to overwrite existing target file: " + target.getAbsolutePath() ); - } - - if ( !temp.renameTo( target ) ) - { - getLogger().warn( "Unable to rename tmp file to its final name... resorting to copy command." ); - - try - { - FileUtils.copyFile( temp, target ); - } - catch ( IOException e ) - { - throw new ProxyException( "Cannot copy tmp file to its final location", e ); - } - finally - { - temp.delete(); - } - } - } - - /** - * Used to disconnect the wagonManager from its repository - * - * @param wagon the connected wagonManager object - */ - private void disconnectWagon( Wagon wagon ) - { - try - { - wagon.disconnect(); - } - catch ( ConnectionException e ) - { - getLogger().error( "Problem disconnecting from wagonManager - ignoring: " + e.getMessage() ); - } - } - - private void processRepositoryFailure( ProxiedArtifactRepository repository, Throwable t, String path, - ArtifactRepositoryPolicy policy ) - throws ProxyException - { - repository.addFailure( path, policy ); - - String message = t.getMessage(); - if ( repository.isHardFail() ) - { - repository.addFailure( path, policy ); - throw new ProxyException( - "An error occurred in hardfailing repository " + repository.getName() + "...\n " + message, t ); - } - - getLogger().warn( "Skipping repository " + repository.getName() + ": " + message ); - getLogger().debug( "Cause", t ); - } - - private void processRepositoryFailure( ProxiedArtifactRepository repository, String message, String path, - ArtifactRepositoryPolicy policy ) - throws ProxyException - { - repository.addFailure( path, policy ); - - processCachedRepositoryFailure( repository, message ); - } - - private void processCachedRepositoryFailure( ProxiedArtifactRepository repository, String message ) - throws ProxyException - { - if ( repository.isHardFail() ) - { - throw new ProxyException( - "An error occurred in hardfailing repository " + repository.getName() + "...\n " + message ); - } - - getLogger().warn( "Skipping repository " + repository.getName() + ": " + message ); - } -} diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxiedArtifactRepository.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxiedArtifactRepository.java deleted file mode 100644 index ff3aaa3ff..000000000 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxiedArtifactRepository.java +++ /dev/null @@ -1,197 +0,0 @@ -package org.apache.maven.repository.proxy; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; - -import java.util.Calendar; -import java.util.HashMap; -import java.util.Map; - -/** - * A proxied artifact repository - contains the artifact repository and additional information about - * the proxied repository. - * - * @author Brett Porter - */ -public class ProxiedArtifactRepository -{ - /** - * Whether to cache failures or not. - */ - private boolean cacheFailures; - - /** - * Whether failures on this repository cause the whole group to fail. - */ - private boolean hardFail; - - /** - * Whether to use the network proxy for any requests. - */ - private boolean useNetworkProxy; - - /** - * The artifact repository on the other end of the proxy. - */ - private final ArtifactRepository repository; - - /** - * Cache of failures that have already occurred, containing paths from the repository root. The value given - * specifies when the failure should expire. - */ - private Map/**/ failureCache = new HashMap/**/(); - - /** - * A user friendly name for the repository. - */ - private String name; - - public ProxiedArtifactRepository( ArtifactRepository repository ) - { - this.repository = repository; - } - - public boolean isHardFail() - { - return hardFail; - } - - public boolean isUseNetworkProxy() - { - return useNetworkProxy; - } - - public boolean isCacheFailures() - { - return cacheFailures; - } - - public ArtifactRepository getRepository() - { - return repository; - } - - /** - * Check if there is a previously cached failure for requesting the given path. - * - * @param path the path - * @return whether there is a failure - */ - public boolean isCachedFailure( String path ) - { - boolean failed = false; - if ( cacheFailures ) - { - Long time = (Long) failureCache.get( path ); - if ( time != null ) - { - if ( System.currentTimeMillis() < time.longValue() ) - { - failed = true; - } - else - { - clearFailure( path ); - } - } - } - return failed; - } - - /** - * Add a failure to the cache. - * - * @param path the path that failed - * @param policy the policy for when the failure should expire - */ - public void addFailure( String path, ArtifactRepositoryPolicy policy ) - { - failureCache.put( path, new Long( calculateExpiryTime( policy ) ) ); - } - - private long calculateExpiryTime( ArtifactRepositoryPolicy policy ) - { - String updatePolicy = policy.getUpdatePolicy(); - long time; - if ( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS.equals( updatePolicy ) ) - { - time = 0; - } - else if ( ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY.equals( updatePolicy ) ) - { - // Get midnight boundary - Calendar cal = Calendar.getInstance(); - cal.set( Calendar.HOUR_OF_DAY, 0 ); - cal.set( Calendar.MINUTE, 0 ); - cal.set( Calendar.SECOND, 0 ); - cal.set( Calendar.MILLISECOND, 0 ); - cal.add( Calendar.DAY_OF_MONTH, 1 ); - time = cal.getTime().getTime(); - } - else if ( updatePolicy.startsWith( ArtifactRepositoryPolicy.UPDATE_POLICY_INTERVAL ) ) - { - String s = updatePolicy.substring( ArtifactRepositoryPolicy.UPDATE_POLICY_INTERVAL.length() + 1 ); - int minutes = Integer.valueOf( s ).intValue(); - Calendar cal = Calendar.getInstance(); - cal.add( Calendar.MINUTE, minutes ); - time = cal.getTime().getTime(); - } - else - { - // else assume "never" - time = Long.MAX_VALUE; - } - return time; - } - - /** - * Remove a failure. - * - * @param path the path that had previously failed - */ - public void clearFailure( String path ) - { - failureCache.remove( path ); - } - - public String getName() - { - return name; - } - - public void setCacheFailures( boolean cacheFailures ) - { - this.cacheFailures = cacheFailures; - } - - public void setHardFail( boolean hardFail ) - { - this.hardFail = hardFail; - } - - public void setUseNetworkProxy( boolean useNetworkProxy ) - { - this.useNetworkProxy = useNetworkProxy; - } - - public void setName( String name ) - { - this.name = name; - } -} diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyException.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyException.java deleted file mode 100644 index cd6ecc323..000000000 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyException.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.maven.repository.proxy; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * @author Edwin Punzalan - */ -public class ProxyException - extends Exception -{ - public ProxyException( String message ) - { - super( message ); - } - - public ProxyException( String message, Throwable t ) - { - super( message, t ); - } -} diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyRequestHandler.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyRequestHandler.java deleted file mode 100644 index 4b8e3e5da..000000000 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyRequestHandler.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.apache.maven.repository.proxy; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.repository.ArtifactRepository; -import org.apache.maven.wagon.ResourceDoesNotExistException; -import org.apache.maven.wagon.proxy.ProxyInfo; - -import java.io.File; -import java.util.List; - -/** - * An individual request handler for the proxy. - * - * @author Brett Porter - */ -public interface ProxyRequestHandler -{ - /** - * The Plexus role of the component. - */ - String ROLE = ProxyRequestHandler.class.getName(); - - /** - * Used to retrieve an artifact at a particular path, giving the cached version if it exists. - * - * @param path the expected repository path - * @param proxiedRepositories the repositories being proxied to - * @param managedRepository the locally managed repository to cache artifacts in - * @return File object referencing the requested path in the cache - * @throws ProxyException when an exception occurred during the retrieval of the requested path - * @throws org.apache.maven.wagon.ResourceDoesNotExistException - * when the requested object can't be found in any of the - * configured repositories - */ - File get( String path, List proxiedRepositories, ArtifactRepository managedRepository ) - throws ProxyException, ResourceDoesNotExistException; - - /** - * Used to retrieve an artifact at a particular path, giving the cached version if it exists. - * - * @param path the expected repository path - * @param proxiedRepositories the repositories being proxied to - * @param managedRepository the locally managed repository to cache artifacts in - * @param wagonProxy a network proxy to use when transferring files if needed - * @return File object referencing the requested path in the cache - * @throws ProxyException when an exception occurred during the retrieval of the requested path - * @throws org.apache.maven.wagon.ResourceDoesNotExistException - * when the requested object can't be found in any of the - * configured repositories - */ - File get( String path, List proxiedRepositories, ArtifactRepository managedRepository, ProxyInfo wagonProxy ) - throws ProxyException, ResourceDoesNotExistException; - - /** - * Used to force remote download of the requested path from any the configured repositories. This method will - * only bypass the cache for searching but the requested path will still be cached. - * - * @param path the expected repository path - * @param proxiedRepositories the repositories being proxied to - * @param managedRepository the locally managed repository to cache artifacts in - * @return File object referencing the requested path in the cache - * @throws ProxyException when an exception occurred during the retrieval of the requested path - * @throws org.apache.maven.wagon.ResourceDoesNotExistException - * when the requested object can't be found in any of the - * configured repositories - */ - File getAlways( String path, List proxiedRepositories, ArtifactRepository managedRepository ) - throws ProxyException, ResourceDoesNotExistException; - - /** - * Used to force remote download of the requested path from any the configured repositories. This method will - * only bypass the cache for searching but the requested path will still be cached. - * - * @param path the expected repository path - * @param proxiedRepositories the repositories being proxied to - * @param managedRepository the locally managed repository to cache artifacts in - * @param wagonProxy a network proxy to use when transferring files if needed - * @return File object referencing the requested path in the cache - * @throws ProxyException when an exception occurred during the retrieval of the requested path - * @throws org.apache.maven.wagon.ResourceDoesNotExistException - * when the requested object can't be found in any of the - * configured repositories - */ - File getAlways( String path, List proxiedRepositories, ArtifactRepository managedRepository, ProxyInfo wagonProxy ) - throws ProxyException, ResourceDoesNotExistException; -} diff --git a/maven-repository-proxy/src/site/apt/how-to.apt b/maven-repository-proxy/src/site/apt/how-to.apt deleted file mode 100644 index 14cf1ef4b..000000000 --- a/maven-repository-proxy/src/site/apt/how-to.apt +++ /dev/null @@ -1,73 +0,0 @@ -ProxyManager - - The ProxyManager is designed to be used as a simple object or bean for use by - a command-line application or web application. - -Configuration - - An instance of a ProxyManager requires a configuration object that will - define its behavior called ProxyConfiguration. The ProxyConfiguration is a - plexus component and can be looked up to get an instance of it. Below is a sample - plexus lookup statement: - ----------- - ProxyConfiguration config = (ProxyConfiguration) container.lookup( ProxyConfiguration.ROLE ); ----------- - - Currently, a ProxyConfiguration lookup will return an empty instance of the - ProxyConfiguration which means it doesn't have any default definitions yet on - how the ProxyManager should behave. So the next step is to explicitly define - its behavior. - ----------- - ProxyConfiguration config = (ProxyConfiguration) container.lookup( ProxyConfiguration.ROLE ); - - config.setRepositoryCachePath( "/user/proxy-cache" ); - - ArtifactRepositoryLayout defLayout = new DefaultRepositoryLayout(); - - File repo1File = new File( "src/test/remote-repo1" ); - - ProxyRepository repo1 = new ProxyRepository( "central", "http://www.ibiblio.org/maven2", defLayout ); - - config.addRepository( repo1 ); ----------- - - The above statements sets up the ProxyConfiguration to use the directory - <<>> as the location of the proxy's repository cache. - Then it creates a ProxyRepository instance with an id of <<>> to - look for remote files in ibiblio.org. - -Instantiation - - To create or retrieve an instance of a ProxyManager, one will need to use the - ProxyManagerFactory. - ----------- - ProxyManagerFactory factory = (ProxyManagerFactory) container.lookup( ProxyManagerFactory.ROLE ); - proxy = factory.getProxyManager( "default", config ); ----------- - - The factory requires two parameters. The first parameter is the proxy_type - that you will want to use. And the second parameter is the ProxyConfiguration - which we already did above. The proxy_type defines the client that the - ProxyManager is expected to service. Currently, only <<>> - ProxyManager type is available and is defined to be for Maven 2.x clients. - -Usage - -* The get() method - - The ProxyManager get( target ) method is used to retrieve a path file. This - method first looks into the cache if the target exists. If it does not, then - the ProxyManager will search all the ProxyRepositories present in its - ProxyConfiguration. When the target path is found, the ProxyManager creates - a copy of it in its cache and returns a File instance of the cached copy. - -* The getRemoteFile() method - - The ProxyManager getRemoteFile( path ) method is used to force the - ProxyManager to ignore the contents of its cache and search all the - ProxyRepository objects for the specified path and retrieve it when - available. When successful, the ProxyManager creates a copy of the remote - file in its cache and then returns a File instance of the cached copy. \ No newline at end of file diff --git a/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.java b/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.java deleted file mode 100644 index 3837ca91f..000000000 --- a/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.java +++ /dev/null @@ -1,1772 +0,0 @@ -package org.apache.maven.repository.proxy; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.artifact.repository.metadata.Metadata; -import org.apache.maven.artifact.repository.metadata.Snapshot; -import org.apache.maven.artifact.repository.metadata.Versioning; -import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer; -import org.apache.maven.wagon.ResourceDoesNotExistException; -import org.apache.maven.wagon.TransferFailedException; -import org.apache.maven.wagon.Wagon; -import org.apache.maven.wagon.authorization.AuthorizationException; -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.util.FileUtils; -import org.easymock.MockControl; - -import java.io.File; -import java.io.IOException; -import java.io.StringWriter; -import java.net.MalformedURLException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; - -/** - * Test the proxy handler. - * - * @author Brett Porter - */ -public class ProxyRequestHandlerTest - extends PlexusTestCase -{ - private ProxyRequestHandler requestHandler; - - private List proxiedRepositories; - - private List legacyProxiedRepositories; - - private ArtifactRepository defaultManagedRepository; - - private ArtifactRepository legacyManagedRepository; - - private ArtifactRepository proxiedRepository1; - - private ArtifactRepository proxiedRepository2; - - private ArtifactRepository legacyProxiedRepository; - - private ArtifactRepositoryLayout defaultLayout; - - private ArtifactRepositoryFactory factory; - - private MockControl wagonMockControl; - - private Wagon wagonMock; - - private static final ArtifactRepositoryPolicy DEFAULT_POLICY = - new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER, null ); - - private static final ArtifactRepositoryPolicy ALWAYS_UPDATE_POLICY = - new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, null ); - - protected void setUp() - throws Exception - { - super.setUp(); - - requestHandler = (ProxyRequestHandler) lookup( ProxyRequestHandler.ROLE ); - - factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - - File repoLocation = getTestFile( "target/test-repository/managed" ); - // faster only to delete this one before copying, the others are done case by case - FileUtils.deleteDirectory( new File( repoLocation, "org/apache/maven/test/get-merged-metadata" ) ); - copyDirectoryStructure( getTestFile( "src/test/repositories/managed" ), repoLocation ); - - defaultLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - - defaultManagedRepository = createRepository( "managed-repository", repoLocation ); - - repoLocation = getTestFile( "target/test-repository/legacy-managed" ); - FileUtils.deleteDirectory( repoLocation ); - copyDirectoryStructure( getTestFile( "src/test/repositories/legacy-managed" ), repoLocation ); - - ArtifactRepositoryLayout legacyLayout = - (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); - - legacyManagedRepository = createRepository( "managed-repository", repoLocation ); - - File location = getTestFile( "src/test/repositories/proxied1" ); - proxiedRepository1 = createRepository( "proxied1", location ); - - location = getTestFile( "src/test/repositories/proxied2" ); - proxiedRepository2 = createRepository( "proxied2", location ); - - proxiedRepositories = new ArrayList( 2 ); - proxiedRepositories.add( createProxiedRepository( proxiedRepository1 ) ); - proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); - - location = getTestFile( "src/test/repositories/legacy-proxied" ); - legacyProxiedRepository = createRepository( "legacy-proxied", location, legacyLayout ); - - legacyProxiedRepositories = Collections.singletonList( createProxiedRepository( legacyProxiedRepository ) ); - - wagonMockControl = MockControl.createNiceControl( Wagon.class ); - wagonMock = (Wagon) wagonMockControl.getMock(); - WagonDelegate delegate = (WagonDelegate) lookup( Wagon.ROLE, "test" ); - delegate.setDelegate( wagonMock ); - } - - public void testGetDefaultLayoutNotPresent() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - // TODO: timestamp preservation requires support for that in wagon -// assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() ); - } - - public void testGetDefaultLayoutAlreadyPresent() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( expectedFile ); - long originalModificationTime = expectedFile.lastModified(); - - assertTrue( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() ); - assertEquals( "Check file timestamp is that of original managed file", originalModificationTime, - file.lastModified() ); - } - - public void testGetDefaultLayoutRemoteUpdate() - throws ResourceDoesNotExistException, ProxyException, IOException, ParseException - { - String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( expectedFile ); - - assertTrue( expectedFile.exists() ); - - expectedFile.setLastModified( getPastDate().getTime() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testGetWhenInBothProxiedRepos() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - - proxiedFile = new File( proxiedRepository2.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testGetInSecondProxiedRepo() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File proxiedFile = new File( proxiedRepository2.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - } - - public void testNotFoundInAnyProxies() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/does-not-exist/1.0/does-not-exist-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - assertFalse( expectedFile.exists() ); - - try - { - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - fail( "File returned was: " + file + "; should have got a not found exception" ); - } - catch ( ResourceDoesNotExistException e ) - { - // expected, but check file was not created - assertFalse( expectedFile.exists() ); - } - } - - public void testGetInSecondProxiedRepoFirstFails() - throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, - AuthorizationException - { - String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ).getAbsoluteFile(); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - proxiedRepository1 = createRepository( "proxied1", "test://..." ); - proxiedRepositories.clear(); - ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); - proxiedRepositories.add( proxiedArtifactRepository ); - proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); - - wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); - wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); - - wagonMockControl.replay(); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - wagonMockControl.verify(); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File proxiedFile = new File( proxiedRepository2.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - - assertTrue( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); - } - - public void testGetButAllRepositoriesFail() - throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, - AuthorizationException - { - String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ).getAbsoluteFile(); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - proxiedRepository1 = createRepository( "proxied1", "test://..." ); - proxiedRepository2 = createRepository( "proxied2", "test://..." ); - proxiedRepositories.clear(); - ProxiedArtifactRepository proxiedArtifactRepository1 = createProxiedRepository( proxiedRepository1 ); - proxiedRepositories.add( proxiedArtifactRepository1 ); - ProxiedArtifactRepository proxiedArtifactRepository2 = createProxiedRepository( proxiedRepository2 ); - proxiedRepositories.add( proxiedArtifactRepository2 ); - - wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); - wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); - - wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); - wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); - - wagonMockControl.replay(); - - try - { - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - fail( "Found file: " + file + "; but was expecting a failure" ); - } - catch ( ResourceDoesNotExistException e ) - { - // as expected - wagonMockControl.verify(); - assertTrue( "Check failure", proxiedArtifactRepository1.isCachedFailure( path ) ); - assertTrue( "Check failure", proxiedArtifactRepository2.isCachedFailure( path ) ); - - // TODO: do we really want failures to present as a not found? - // TODO: How much information on each failure should we pass back to the user vs. logging in the proxy? - } - } - - public void testGetInSecondProxiedRepoFirstHardFails() - throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, - AuthorizationException - { - String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ).getAbsoluteFile(); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - proxiedRepository1 = createRepository( "proxied1", "test://..." ); - proxiedRepositories.clear(); - ProxiedArtifactRepository proxiedArtifactRepository = createHardFailProxiedRepository( proxiedRepository1 ); - proxiedRepositories.add( proxiedArtifactRepository ); - proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); - - wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); - TransferFailedException failedException = new TransferFailedException( "transfer failed" ); - wagonMockControl.setThrowable( failedException ); - - wagonMockControl.replay(); - - try - { - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - fail( "Found file: " + file + "; but was expecting a failure" ); - } - catch ( ProxyException e ) - { - // expect a failure - wagonMockControl.verify(); - - assertEquals( "Check cause", failedException, e.getCause() ); - assertTrue( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); - } - } - - public void testGetInSecondProxiedRepoFirstFailsFromCache() - throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, - AuthorizationException - { - // fail from the cache, even though it is in the first repo now - - String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - proxiedRepositories.clear(); - ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); - proxiedArtifactRepository.addFailure( path, DEFAULT_POLICY ); - proxiedRepositories.add( proxiedArtifactRepository ); - proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - File proxiedFile = new File( proxiedRepository2.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - - proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testGetInSecondProxiedRepoFirstHardFailsFromCache() - throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, - AuthorizationException - { - // fail from the cache, even though it is in the first repo now - - String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - proxiedRepositories.clear(); - ProxiedArtifactRepository proxiedArtifactRepository = createHardFailProxiedRepository( proxiedRepository1 ); - proxiedArtifactRepository.addFailure( path, DEFAULT_POLICY ); - proxiedRepositories.add( proxiedArtifactRepository ); - proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); - try - { - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - fail( "Found file: " + file + "; but was expecting a failure" ); - } - catch ( ProxyException e ) - { - // expect a failure - assertTrue( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); - } - } - - public void testGetInSecondProxiedRepoFirstFailsDisabledCacheFailure() - throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, - AuthorizationException - { - String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ).getAbsoluteFile(); - - assertFalse( expectedFile.exists() ); - - proxiedRepository1 = createRepository( "proxied1", "test://..." ); - proxiedRepositories.clear(); - ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); - proxiedArtifactRepository.addFailure( path, DEFAULT_POLICY ); - proxiedArtifactRepository.setCacheFailures( false ); - proxiedRepositories.add( proxiedArtifactRepository ); - proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); - - wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); - wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); - - wagonMockControl.replay(); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - wagonMockControl.verify(); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File proxiedFile = new File( proxiedRepository2.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - - assertFalse( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); - } - - public void testGetWhenInBothProxiedReposFirstHasExpiredCacheFailure() - throws ResourceDoesNotExistException, ProxyException, IOException, ParseException - { - String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - assertFalse( expectedFile.exists() ); - - proxiedRepositories.clear(); - ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); - proxiedArtifactRepository.addFailure( path, ALWAYS_UPDATE_POLICY ); - proxiedRepositories.add( proxiedArtifactRepository ); - proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - - proxiedFile = new File( proxiedRepository2.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - - assertFalse( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); - } - - public void testGetAlwaysAlreadyPresent() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( expectedFile ); - - assertTrue( expectedFile.exists() ); - - File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testGetAlwaysAlreadyPresentRemovedFromProxies() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-removed-from-proxies/1.0/get-removed-from-proxies-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( expectedFile ); - - assertTrue( expectedFile.exists() ); - - File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - - // TODO: is this the correct behaviour, or should it be considered removed too? - } - - public void testGetAlwaysWithCachedFailure() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( expectedFile ); - - assertTrue( expectedFile.exists() ); - - proxiedRepositories.clear(); - ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); - proxiedArtifactRepository.addFailure( path, DEFAULT_POLICY ); - proxiedRepositories.add( proxiedArtifactRepository ); - proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); - File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testGetRemovesTemporaryFileOnSuccess() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File tempFile = new File( file.getParentFile(), file.getName() + ".tmp" ); - assertFalse( "Check temporary file removed", tempFile.exists() ); - } - - public void testGetRemovesTemporaryFileOnError() - throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, - AuthorizationException - { - String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - proxiedRepository1 = createRepository( "proxied1", "test://..." ); - proxiedRepositories.clear(); - ProxiedArtifactRepository proxiedArtifactRepository1 = createProxiedRepository( proxiedRepository1 ); - proxiedRepositories.add( proxiedArtifactRepository1 ); - - wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); - wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); - - wagonMockControl.replay(); - - try - { - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - fail( "Found file: " + file + "; but was expecting a failure" ); - } - catch ( ResourceDoesNotExistException e ) - { - // as expected - wagonMockControl.verify(); - - File tempFile = new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ); - assertFalse( "Check temporary file removed", tempFile.exists() ); - } - } - - public void testGetRemovesTemporaryChecksumFileOnSuccess() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File tempFile = new File( file.getParentFile(), file.getName() + ".sha1.tmp" ); - assertFalse( "Check temporary file removed", tempFile.exists() ); - } - - public void testGetRemovesTemporaryChecksumFileOnError() - throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, - AuthorizationException - { - String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); - - proxiedRepository1 = createRepository( "proxied1", "test://..." ); - proxiedRepositories.clear(); - ProxiedArtifactRepository proxiedArtifactRepository1 = createProxiedRepository( proxiedRepository1 ); - proxiedRepositories.add( proxiedArtifactRepository1 ); - - wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); - - mockFailedChecksums( path, expectedFile ); - - wagonMockControl.replay(); - - try - { - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - fail( "Found file: " + file + "; but was expecting a failure" ); - } - catch ( ResourceDoesNotExistException e ) - { - // as expected - wagonMockControl.verify(); - - File tempFile = new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ); - assertFalse( "Check temporary file removed", tempFile.exists() ); - - tempFile = new File( expectedFile.getParentFile(), expectedFile.getName() + ".sha1.tmp" ); - assertFalse( "Check temporary file removed", tempFile.exists() ); - } - } - - public void testGetChecksumBothCorrect() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - File checksumFile = getChecksumFile( file, "sha1" ); - assertTrue( "Check file created", checksumFile.exists() ); - assertEquals( "Check checksum", "066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-both-right-1.0.jar", - FileUtils.fileRead( checksumFile ).trim() ); - - assertFalse( "Check file not created", getChecksumFile( file, "md5" ).exists() ); - } - - public void testGetCorrectSha1NoMd5() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - File checksumFile = getChecksumFile( file, "sha1" ); - assertTrue( "Check file created", checksumFile.exists() ); - assertEquals( "Check checksum", "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", - FileUtils.fileRead( checksumFile ).trim() ); - - assertFalse( "Check file not created", getChecksumFile( file, "md5" ).exists() ); - } - - public void testGetCorrectSha1BadMd5() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - File checksumFile = getChecksumFile( file, "sha1" ); - assertTrue( "Check file created", checksumFile.exists() ); - assertEquals( "Check checksum", "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar", - FileUtils.fileRead( checksumFile ).trim() ); - - assertFalse( "Check file not created", getChecksumFile( file, "md5" ).exists() ); - } - - public void testGetCorrectMd5NoSha1() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - File checksumFile = getChecksumFile( file, "md5" ); - assertTrue( "Check file created", checksumFile.exists() ); - assertEquals( "Check checksum", "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar", - FileUtils.fileRead( checksumFile ).trim() ); - - assertFalse( "Check file not created", getChecksumFile( file, "sha1" ).exists() ); - } - - public void testGetCorrectMd5BadSha1() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - File checksumFile = getChecksumFile( file, "md5" ); - assertTrue( "Check file created", checksumFile.exists() ); - assertEquals( "Check checksum", "8a02aa67549d27b2a03cd4547439c6d3 *get-checksum-md5-bad-sha1-1.0.jar", - FileUtils.fileRead( checksumFile ).trim() ); - - assertFalse( "Check file not created", getChecksumFile( file, "sha1" ).exists() ); - } - - public void testGetWithNoChecksums() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - assertFalse( "Check file not created", getChecksumFile( file, "md5" ).exists() ); - assertFalse( "Check file not created", getChecksumFile( file, "sha1" ).exists() ); - } - - public void testGetBadMd5BadSha1() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); - - try - { - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - fail( "Found file: " + file + "; but was expecting a failure" ); - } - catch ( ResourceDoesNotExistException e ) - { - // expect a failure - assertFalse( "Check file not created", expectedFile.exists() ); - - assertFalse( "Check file not created", getChecksumFile( expectedFile, "md5" ).exists() ); - assertFalse( "Check file not created", getChecksumFile( expectedFile, "sha1" ).exists() ); - } - } - - public void testGetChecksumTransferFailed() - throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, - AuthorizationException - { - String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); - - proxiedRepository1 = createRepository( "proxied1", "test://..." ); - proxiedRepositories.clear(); - ProxiedArtifactRepository proxiedArtifactRepository1 = createProxiedRepository( proxiedRepository1 ); - proxiedRepositories.add( proxiedArtifactRepository1 ); - - wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); - - mockFailedChecksums( path, expectedFile ); - - wagonMockControl.replay(); - - try - { - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - fail( "Found file: " + file + "; but was expecting a failure" ); - } - catch ( ResourceDoesNotExistException e ) - { - // as expected - wagonMockControl.verify(); - - assertFalse( "Check file not created", expectedFile.exists() ); - - assertFalse( "Check file not created", getChecksumFile( expectedFile, "md5" ).exists() ); - assertFalse( "Check file not created", getChecksumFile( expectedFile, "sha1" ).exists() ); - } - } - - public void testGetAlwaysBadChecksumPresentLocallyAbsentRemote() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( expectedFile ); - - assertTrue( expectedFile.exists() ); - - File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - - assertFalse( "Check checksum removed", new File( file.getParentFile(), file.getName() + ".sha1" ).exists() ); - assertFalse( "Check checksum removed", new File( file.getParentFile(), file.getName() + ".md5" ).exists() ); - } - - public void testGetChecksumPresentInManagedRepo() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = - "org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( expectedFile ); - - assertTrue( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testGetAlwaysChecksumPresentInManagedRepo() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = - "org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( expectedFile ); - - assertTrue( expectedFile.exists() ); - - File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testGetChecksumNotPresentInManagedRepo() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar.sha1"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); - - try - { - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - fail( "Found file: " + file + "; but was expecting a failure" ); - } - catch ( ResourceDoesNotExistException e ) - { - // expected - - assertFalse( expectedFile.exists() ); - } - } - - public void testGetAlwaysChecksumNotPresentInManagedRepo() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar.sha1"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); - - try - { - File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); - fail( "Found file: " + file + "; but was expecting a failure" ); - } - catch ( ResourceDoesNotExistException e ) - { - // expected - - assertFalse( expectedFile.exists() ); - } - } - - public void testGetMetadataNotPresent() - throws ProxyException, IOException - { - String path = "org/apache/maven/test/dummy-artifact/1.0/maven-metadata.xml"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - assertFalse( expectedFile.exists() ); - - try - { - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - fail( "Found file: " + file + "; but was expecting a failure" ); - } - catch ( ResourceDoesNotExistException e ) - { - // expected - - assertFalse( expectedFile.exists() ); - } - } - - public void testGetMetadataProxied() - throws ProxyException, ResourceDoesNotExistException, IOException - { - String path = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - String expectedContents = getExpectedMetadata( "get-default-metadata", "1.0" ); - assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); - } - - public void testGetMetadataMergeRepos() - throws IOException, ResourceDoesNotExistException, ProxyException - { - String path = "org/apache/maven/test/get-merged-metadata/maven-metadata.xml"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - assertTrue( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - String expectedContents = getExpectedMetadata( "get-merged-metadata", getVersioning( - Arrays.asList( new String[]{"0.9", "1.0", "2.0", "3.0", "5.0", "4.0"} ) ) ); - - assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); - } - - public void testGetMetadataRemovedFromProxies() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-removed-metadata/1.0/maven-metadata.xml"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); - - assertTrue( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); - } - - public void testGetReleaseMetadataNotExpired() - throws IOException, ResourceDoesNotExistException, ProxyException, ParseException - { - String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); - - assertTrue( expectedFile.exists() ); - - new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() ); - - proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); - proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); - - String unexpectedContents = FileUtils.fileRead( new File( proxiedRepository1.getBasedir(), path ) ); - assertFalse( "Check content doesn't match proxy version", - unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testGetSnapshotMetadataNotExpired() - throws IOException, ResourceDoesNotExistException, ProxyException, ParseException - { - String path = "org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); - - assertTrue( expectedFile.exists() ); - - new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() ); - - proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); - proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); - - String unexpectedContents = FileUtils.fileRead( new File( proxiedRepository1.getBasedir(), path ) ); - assertFalse( "Check content doesn't match proxy version", - unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testGetReleaseMetadataExpired() - throws IOException, ResourceDoesNotExistException, ProxyException, ParseException - { - String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); - - assertTrue( expectedFile.exists() ); - - new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() ); - - proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); - proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - String expectedContents = - getExpectedMetadata( "get-updated-metadata", getVersioning( Arrays.asList( new String[]{"1.0", "2.0"} ) ) ); - - assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); - assertFalse( "Check content doesn't match proxy version", - unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testGetSnapshotMetadataExpired() - throws IOException, ResourceDoesNotExistException, ProxyException, ParseException - { - String path = "org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); - - assertTrue( expectedFile.exists() ); - - new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() ); - - proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); - proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - String expectedContents = - getExpectedMetadata( "get-updated-metadata", "1.0-SNAPSHOT", getVersioning( "20050831.111213", 2 ) ); - - assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); - assertFalse( "Check content doesn't match proxy version", - unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testGetMetadataNotUpdated() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); - - assertTrue( expectedFile.exists() ); - - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( proxiedFile.lastModified() ); - - proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); - - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertFalse( "Check content doesn't match proxy version", - unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testGetMetadataUpdated() - throws IOException, ResourceDoesNotExistException, ProxyException, ParseException - { - String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); - - assertTrue( expectedFile.exists() ); - - new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - String expectedContents = - getExpectedMetadata( "get-updated-metadata", getVersioning( Arrays.asList( new String[]{"1.0", "2.0"} ) ) ); - assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); - assertFalse( "Check content doesn't match old version", - unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testGetAlwaysMetadata() - throws IOException, ResourceDoesNotExistException, ProxyException - { - String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); - - assertTrue( expectedFile.exists() ); - - File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - String expectedContents = - getExpectedMetadata( "get-updated-metadata", getVersioning( Arrays.asList( new String[]{"1.0", "2.0"} ) ) ); - - assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); - assertFalse( "Check content doesn't match old version", - unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testSnapshotNonExistant() - throws ProxyException, IOException - { - String path = "org/apache/maven/test/does-not-exist/1.0-SNAPSHOT/does-not-exist-1.0-SNAPSHOT.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - assertFalse( expectedFile.exists() ); - - try - { - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - fail( "File returned was: " + file + "; should have got a not found exception" ); - } - catch ( ResourceDoesNotExistException e ) - { - // expected, but check file was not created - assertFalse( expectedFile.exists() ); - } - } - - public void testTimestampDrivenSnapshotNotPresentAlready() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = - "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - } - - public void testNewerTimestampDrivenSnapshotOnFirstRepo() - throws ResourceDoesNotExistException, ProxyException, IOException, ParseException - { - String path = - "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - assertTrue( expectedFile.exists() ); - - expectedFile.setLastModified( getPastDate().getTime() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - } - - public void testOlderTimestampDrivenSnapshotOnFirstRepo() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = - "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( expectedFile ); - - assertTrue( expectedFile.exists() ); - - expectedFile.setLastModified( getFutureDate().getTime() ); - - proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - -/* TODO: won't pass until Wagon preserves timestamp on download - public void testNewerTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready() - throws ResourceDoesNotExistException, ProxyException, IOException, ParseException - { - String path = - "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - assertFalse( expectedFile.exists() ); - - File repoLocation = getTestFile( "target/test-repository/proxied1" ); - FileUtils.deleteDirectory( repoLocation ); - copyDirectoryStructure( getTestFile( "src/test/repositories/proxied1" ), repoLocation ); - proxiedRepository1 = createRepository( "proxied1", repoLocation ); - - new File( proxiedRepository1.getBasedir(), path ).setLastModified( getPastDate().getTime() ); - - proxiedRepositories.clear(); - proxiedRepositories.add( createProxiedRepository( proxiedRepository1 ) ); - proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - File proxiedFile = new File( proxiedRepository2.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - - proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } -*/ - - public void testOlderTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready() - throws ParseException, ResourceDoesNotExistException, ProxyException, IOException - { - String path = - "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - File repoLocation = getTestFile( "target/test-repository/proxied2" ); - FileUtils.deleteDirectory( repoLocation ); - copyDirectoryStructure( getTestFile( "src/test/repositories/proxied2" ), repoLocation ); - proxiedRepository2 = createRepository( "proxied2", repoLocation ); - - new File( proxiedRepository2.getBasedir(), path ).setLastModified( getPastDate().getTime() ); - - proxiedRepositories.clear(); - proxiedRepositories.add( createProxiedRepository( proxiedRepository1 ) ); - proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - - proxiedFile = new File( proxiedRepository2.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testTimestampDrivenSnapshotNotExpired() - throws IOException, ResourceDoesNotExistException, ProxyException - { - String path = - "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - assertTrue( expectedFile.exists() ); - - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - proxiedFile.setLastModified( getFutureDate().getTime() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - String expectedContents = FileUtils.fileRead( expectedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testTimestampDrivenSnapshotNotUpdated() - throws IOException, ResourceDoesNotExistException, ProxyException - { - String path = - "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( expectedFile ); - - assertTrue( expectedFile.exists() ); - - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - expectedFile.setLastModified( proxiedFile.lastModified() ); - - proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testTimestampDrivenSnapshotNotPresentAlreadyExpiredCacheFailure() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = - "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - proxiedRepositories.clear(); - ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); - proxiedArtifactRepository.addFailure( path, ALWAYS_UPDATE_POLICY ); - proxiedRepositories.add( proxiedArtifactRepository ); - proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - - assertFalse( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); - } - - public void testMetadataDrivenSnapshotNotPresentAlready() - throws ResourceDoesNotExistException, ProxyException, IOException - { - String path = - "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - } - - public void testGetMetadataDrivenSnapshotRemoteUpdate() - throws ResourceDoesNotExistException, ProxyException, IOException, ParseException - { - // Metadata driven snapshots (using a full timestamp) are treated like a release. It is the timing of the - // updates to the metadata files that triggers which will be downloaded - - String path = - "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( expectedFile ); - - assertTrue( expectedFile.exists() ); - - expectedFile.setLastModified( getPastDate().getTime() ); - - File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - } - - public void testLegacyManagedRepoGetNotPresent() - throws IOException, ResourceDoesNotExistException, ProxyException - { - String path = "org.apache.maven.test/jars/get-default-layout-1.0.jar"; - File expectedFile = new File( legacyManagedRepository.getBasedir(), path ); - - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, legacyManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File proxiedFile = new File( proxiedRepository1.getBasedir(), - "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar" ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - // TODO: timestamp preservation requires support for that in wagon -// assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() ); - } - - public void testLegacyManagedRepoGetAlreadyPresent() - throws IOException, ResourceDoesNotExistException, ProxyException - { - String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar"; - File expectedFile = new File( legacyManagedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( expectedFile ); - long originalModificationTime = expectedFile.lastModified(); - - assertTrue( expectedFile.exists() ); - - File file = requestHandler.get( path, proxiedRepositories, legacyManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - File proxiedFile = new File( proxiedRepository1.getBasedir(), - "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar" ); - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() ); - assertEquals( "Check file timestamp is that of original managed file", originalModificationTime, - file.lastModified() ); - } - - public void testLegacyProxyRepoGetNotPresent() - throws IOException, ResourceDoesNotExistException, ProxyException - { - String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - - expectedFile.delete(); - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, legacyProxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File proxiedFile = - new File( legacyProxiedRepository.getBasedir(), "org.apache.maven.test/jars/get-default-layout-1.0.jar" ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - // TODO: timestamp preservation requires support for that in wagon -// assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() ); - } - - public void testLegacyProxyRepoGetAlreadyPresent() - throws IOException, ResourceDoesNotExistException, ProxyException - { - String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; - File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( expectedFile ); - long originalModificationTime = expectedFile.lastModified(); - - assertTrue( expectedFile.exists() ); - - File file = requestHandler.get( path, legacyProxiedRepositories, defaultManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - File proxiedFile = new File( legacyProxiedRepository.getBasedir(), - "org.apache.maven.test/jars/get-default-layout-present-1.0.jar" ); - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() ); - assertEquals( "Check file timestamp is that of original managed file", originalModificationTime, - file.lastModified() ); - } - - public void testLegacyManagedAndProxyRepoGetNotPresent() - throws IOException, ResourceDoesNotExistException, ProxyException - { - String path = "org.apache.maven.test/jars/get-default-layout-1.0.jar"; - File expectedFile = new File( legacyManagedRepository.getBasedir(), path ); - - assertFalse( expectedFile.exists() ); - - File file = requestHandler.get( path, legacyProxiedRepositories, legacyManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - File proxiedFile = new File( legacyProxiedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( proxiedFile ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - // TODO: timestamp preservation requires support for that in wagon -// assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() ); - } - - public void testLegacyManagedAndProxyRepoGetAlreadyPresent() - throws IOException, ResourceDoesNotExistException, ProxyException - { - String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar"; - File expectedFile = new File( legacyManagedRepository.getBasedir(), path ); - String expectedContents = FileUtils.fileRead( expectedFile ); - long originalModificationTime = expectedFile.lastModified(); - - assertTrue( expectedFile.exists() ); - - File file = requestHandler.get( path, legacyProxiedRepositories, legacyManagedRepository ); - - assertEquals( "Check file matches", expectedFile, file ); - assertTrue( "Check file created", file.exists() ); - assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); - File proxiedFile = new File( legacyProxiedRepository.getBasedir(), path ); - String unexpectedContents = FileUtils.fileRead( proxiedFile ); - assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); - assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() ); - assertEquals( "Check file timestamp is that of original managed file", originalModificationTime, - file.lastModified() ); - } - - private static Versioning getVersioning( List versions ) - { - Versioning versioning = new Versioning(); - for ( Iterator i = versions.iterator(); i.hasNext(); ) - { - String v = (String) i.next(); - versioning.addVersion( v ); - } - return versioning; - } - - private static String getExpectedMetadata( String artifactId, Versioning versioning ) - throws IOException - { - return getExpectedMetadata( artifactId, null, versioning ); - } - - private static String getExpectedMetadata( String artifactId, String version, Versioning versioning ) - throws IOException - { - StringWriter expectedContents = new StringWriter(); - - Metadata m = new Metadata(); - m.setGroupId( "org.apache.maven.test" ); - m.setArtifactId( artifactId ); - m.setVersion( version ); - m.setVersioning( versioning ); - m.setModelEncoding( null ); - - new MetadataXpp3Writer().write( expectedContents, m ); - return expectedContents.toString(); - } - - private static String getExpectedMetadata( String artifactId, String version ) - throws IOException - { - return getExpectedMetadata( artifactId, version, null ); - } - - private static Versioning getVersioning( String timestamp, int buildNumber ) - { - Versioning versioning = new Versioning(); - versioning.setSnapshot( new Snapshot() ); - versioning.getSnapshot().setTimestamp( timestamp ); - versioning.getSnapshot().setBuildNumber( buildNumber ); - return versioning; - } - - private static Date getPastDate() - throws ParseException - { - return new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).parse( "2000-01-01" ); - } - - private static Date getFutureDate() - { - Calendar cal = Calendar.getInstance(); - cal.add( Calendar.YEAR, 1 ); - return cal.getTime(); - } - - private void mockFailedChecksums( String path, File expectedFile ) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException - { - // must do it twice as it will re-attempt it - wagonMock.get( path + ".sha1", new File( expectedFile.getParentFile(), expectedFile.getName() + ".sha1.tmp" ) ); - wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); - - wagonMock.get( path + ".md5", new File( expectedFile.getParentFile(), expectedFile.getName() + ".md5.tmp" ) ); - wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); - - wagonMock.get( path + ".sha1", new File( expectedFile.getParentFile(), expectedFile.getName() + ".sha1.tmp" ) ); - wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); - - wagonMock.get( path + ".md5", new File( expectedFile.getParentFile(), expectedFile.getName() + ".md5.tmp" ) ); - wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); - } - - private File getChecksumFile( File file, String algorithm ) - { - return new File( file.getParentFile(), file.getName() + "." + algorithm ); - } - - /** - * A faster recursive copy that omits .svn directories. - * - * @param sourceDirectory the source directory to copy - * @param destDirectory the target location - * @throws java.io.IOException if there is a copying problem - * @todo get back into plexus-utils, share with converter module - */ - private static void copyDirectoryStructure( File sourceDirectory, File destDirectory ) - throws IOException - { - if ( !sourceDirectory.exists() ) - { - throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." ); - } - - File[] files = sourceDirectory.listFiles(); - - String sourcePath = sourceDirectory.getAbsolutePath(); - - for ( int i = 0; i < files.length; i++ ) - { - File file = files[i]; - - String dest = file.getAbsolutePath(); - - dest = dest.substring( sourcePath.length() + 1 ); - - File destination = new File( destDirectory, dest ); - - if ( file.isFile() ) - { - destination = destination.getParentFile(); - - FileUtils.copyFileToDirectory( file, destination ); - } - else if ( file.isDirectory() ) - { - if ( !".svn".equals( file.getName() ) ) - { - if ( !destination.exists() && !destination.mkdirs() ) - { - throw new IOException( - "Could not create destination directory '" + destination.getAbsolutePath() + "'." ); - } - - copyDirectoryStructure( file, destination ); - } - } - else - { - throw new IOException( "Unknown file type: " + file.getAbsolutePath() ); - } - } - } - - private static ProxiedArtifactRepository createProxiedRepository( ArtifactRepository repository ) - { - ProxiedArtifactRepository proxiedArtifactRepository = new ProxiedArtifactRepository( repository ); - proxiedArtifactRepository.setName( repository.getId() ); - proxiedArtifactRepository.setCacheFailures( true ); - return proxiedArtifactRepository; - } - - private static ProxiedArtifactRepository createHardFailProxiedRepository( ArtifactRepository repository ) - { - ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( repository ); - proxiedArtifactRepository.setHardFail( true ); - return proxiedArtifactRepository; - } - - private ArtifactRepository createRepository( String id, File repoLocation ) - throws MalformedURLException - { - return createRepository( id, repoLocation.toURI().toURL().toExternalForm() ); - } - - private ArtifactRepository createRepository( String id, File location, ArtifactRepositoryLayout layout ) - throws MalformedURLException - { - return createRepository( id, location.toURI().toURL().toExternalForm(), layout ); - } - - private ArtifactRepository createRepository( String id, String url ) - { - return createRepository( id, url, defaultLayout ); - } - - private ArtifactRepository createRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout ) - { - return factory.createArtifactRepository( id, url, repositoryLayout, null, null ); - } -} diff --git a/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/WagonDelegate.java b/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/WagonDelegate.java deleted file mode 100644 index 023195e4d..000000000 --- a/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/WagonDelegate.java +++ /dev/null @@ -1,198 +0,0 @@ -package org.apache.maven.repository.proxy; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.wagon.ConnectionException; -import org.apache.maven.wagon.ResourceDoesNotExistException; -import org.apache.maven.wagon.TransferFailedException; -import org.apache.maven.wagon.Wagon; -import org.apache.maven.wagon.authentication.AuthenticationException; -import org.apache.maven.wagon.authentication.AuthenticationInfo; -import org.apache.maven.wagon.authorization.AuthorizationException; -import org.apache.maven.wagon.events.SessionListener; -import org.apache.maven.wagon.events.TransferListener; -import org.apache.maven.wagon.proxy.ProxyInfo; -import org.apache.maven.wagon.repository.Repository; -import org.codehaus.plexus.util.FileUtils; - -import java.io.File; -import java.io.IOException; - -/** - * A dummy wagon implementation - * - * @author Brett Porter - */ -public class WagonDelegate - implements Wagon -{ - private Wagon delegate; - - private String contentToGet; - - public void get( String resourceName, File destination ) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException - { - delegate.get( resourceName, destination ); - create( destination ); - } - - public boolean getIfNewer( String resourceName, File destination, long timestamp ) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException - { - boolean result = delegate.getIfNewer( resourceName, destination, timestamp ); - createIfMissing( destination ); - return result; - } - - public void put( File source, String destination ) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException - { - delegate.put( source, destination ); - } - - public void putDirectory( File sourceDirectory, String destinationDirectory ) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException - { - delegate.putDirectory( sourceDirectory, destinationDirectory ); - } - - public boolean supportsDirectoryCopy() - { - return delegate.supportsDirectoryCopy(); - } - - public Repository getRepository() - { - return delegate.getRepository(); - } - - public void connect( Repository source ) - throws ConnectionException, AuthenticationException - { - delegate.connect( source ); - } - - public void connect( Repository source, ProxyInfo proxyInfo ) - throws ConnectionException, AuthenticationException - { - delegate.connect( source, proxyInfo ); - } - - public void connect( Repository source, AuthenticationInfo authenticationInfo ) - throws ConnectionException, AuthenticationException - { - delegate.connect( source, authenticationInfo ); - } - - public void connect( Repository source, AuthenticationInfo authenticationInfo, ProxyInfo proxyInfo ) - throws ConnectionException, AuthenticationException - { - delegate.connect( source, authenticationInfo, proxyInfo ); - } - - public void openConnection() - throws ConnectionException, AuthenticationException - { - delegate.openConnection(); - } - - public void disconnect() - throws ConnectionException - { - delegate.disconnect(); - } - - public void addSessionListener( SessionListener listener ) - { - delegate.addSessionListener( listener ); - } - - public void removeSessionListener( SessionListener listener ) - { - delegate.removeSessionListener( listener ); - } - - public boolean hasSessionListener( SessionListener listener ) - { - return delegate.hasSessionListener( listener ); - } - - public void addTransferListener( TransferListener listener ) - { - delegate.addTransferListener( listener ); - } - - public void removeTransferListener( TransferListener listener ) - { - delegate.removeTransferListener( listener ); - } - - public boolean hasTransferListener( TransferListener listener ) - { - return delegate.hasTransferListener( listener ); - } - - public boolean isInteractive() - { - return delegate.isInteractive(); - } - - public void setInteractive( boolean interactive ) - { - delegate.setInteractive( interactive ); - } - - public void setDelegate( Wagon delegate ) - { - this.delegate = delegate; - } - - void setContentToGet( String content ) - { - contentToGet = content; - } - - private void createIfMissing( File destination ) - { - // since the mock won't actually copy a file, create an empty one to simulate file existence - if ( !destination.exists() ) - { - create( destination ); - } - } - - private void create( File destination ) - { - try - { - destination.getParentFile().mkdirs(); - if ( contentToGet == null ) - { - destination.createNewFile(); - } - else - { - FileUtils.fileWrite( destination.getAbsolutePath(), contentToGet ); - } - } - catch ( IOException e ) - { - throw new RuntimeException( e.getMessage(), e ); - } - } -} diff --git a/maven-repository-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/get-default-layout-present-1.0.jar b/maven-repository-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/get-default-layout-present-1.0.jar deleted file mode 100644 index bf26f6b57..000000000 --- a/maven-repository-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/get-default-layout-present-1.0.jar +++ /dev/null @@ -1,2 +0,0 @@ -get-default-layout-present-1.0.jar -(managed) diff --git a/maven-repository-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-1.0.jar b/maven-repository-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-1.0.jar deleted file mode 100644 index 77dbb7858..000000000 --- a/maven-repository-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-1.0.jar +++ /dev/null @@ -1 +0,0 @@ -get-default-layout-1.0.jar diff --git a/maven-repository-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-present-1.0.jar b/maven-repository-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-present-1.0.jar deleted file mode 100644 index 9f4121a86..000000000 --- a/maven-repository-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-present-1.0.jar +++ /dev/null @@ -1,2 +0,0 @@ -get-default-layout-present-1.0.jar -(proxied) diff --git a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar b/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar deleted file mode 100644 index 62a1e1c71..000000000 --- a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar +++ /dev/null @@ -1,3 +0,0 @@ -get-bad-local-checksum-1.0.jar -(managed) - diff --git a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.md5 b/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.md5 deleted file mode 100644 index 5fd0ae2b7..000000000 --- a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.md5 +++ /dev/null @@ -1 +0,0 @@ -invalid checksum file \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.sha1 b/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.sha1 deleted file mode 100644 index 5fd0ae2b7..000000000 --- a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -invalid checksum file \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 b/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 deleted file mode 100644 index de9618d2f..000000000 --- a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-from-managed-repo-1.0.jar diff --git a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar b/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar deleted file mode 100644 index a3b38382c..000000000 --- a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar +++ /dev/null @@ -1,3 +0,0 @@ -get-default-layout-present-1.0.jar -(managed) - diff --git a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-merged-metadata/maven-metadata.xml b/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-merged-metadata/maven-metadata.xml deleted file mode 100644 index 8404eb8a9..000000000 --- a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-merged-metadata/maven-metadata.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - org.apache.maven.test - get-merged-metadata - - - 0.9 - - 1.0 - - 2.0 - - - - \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar b/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar deleted file mode 100644 index b71eb7b74..000000000 --- a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar +++ /dev/null @@ -1,2 +0,0 @@ -get-present-metadata-snapshot-1.0-20050831.101112-1.jar -(managed) \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar b/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar deleted file mode 100644 index 0c2d93e3c..000000000 --- a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar +++ /dev/null @@ -1,2 +0,0 @@ -get-present-timestamped-snapshot-1.0-SNAPSHOT.jar -(managed) \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-from-proxies/1.0/get-removed-from-proxies-1.0.jar b/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-from-proxies/1.0/get-removed-from-proxies-1.0.jar deleted file mode 100644 index 54dc5ee86..000000000 --- a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-from-proxies/1.0/get-removed-from-proxies-1.0.jar +++ /dev/null @@ -1,3 +0,0 @@ -get-removed-from-proxies-1.0.jar -(managed) - diff --git a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-metadata/1.0/maven-metadata.xml b/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-metadata/1.0/maven-metadata.xml deleted file mode 100644 index 7bd77c137..000000000 --- a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-metadata/1.0/maven-metadata.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/.metadata-proxied1 b/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/.metadata-proxied1 deleted file mode 100644 index 76b43d62a..000000000 --- a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/.metadata-proxied1 +++ /dev/null @@ -1,25 +0,0 @@ - - - - org.apache.maven.test - get-updated-metadata - - - 1.0 - - - diff --git a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/.metadata-proxied1 b/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/.metadata-proxied1 deleted file mode 100644 index 6354f21bc..000000000 --- a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/.metadata-proxied1 +++ /dev/null @@ -1,27 +0,0 @@ - - - - org.apache.maven.test - get-updated-metadata - 1.0-SNAPSHOT - - - 20050831.1011112 - 1 - - - \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml b/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml deleted file mode 100644 index cd7216a64..000000000 --- a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - org.apache.maven.test - get-updated-metadata - 1.0-SNAPSHOT - - - 20050831.1011112 - 1 - - - \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/maven-metadata.xml b/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/maven-metadata.xml deleted file mode 100644 index 5cd8af101..000000000 --- a/maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/maven-metadata.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - org.apache.maven.test - get-updated-metadata - - - 1.0 - - - \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar deleted file mode 100644 index b5d8045c9..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar +++ /dev/null @@ -1,3 +0,0 @@ -get-bad-local-checksum-1.0.jar -(proxied 1) - diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar deleted file mode 100644 index 98fae8093..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar +++ /dev/null @@ -1,2 +0,0 @@ -get-checksum-both-bad-1.0.jar - diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.md5 b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.md5 deleted file mode 100644 index 5fd0ae2b7..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.md5 +++ /dev/null @@ -1 +0,0 @@ -invalid checksum file \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.sha1 b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.sha1 deleted file mode 100644 index a2d3f29ea..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -invalid checksum file diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar deleted file mode 100644 index 7fa9ec4a0..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar +++ /dev/null @@ -1 +0,0 @@ -get-checksum-both-right-1.0.jar diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.md5 b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.md5 deleted file mode 100644 index 9b9e3374c..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.md5 +++ /dev/null @@ -1 +0,0 @@ -e58f30c6a150a2e843552438d18e15cb *get-checksum-both-right-1.0.jar \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.sha1 b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.sha1 deleted file mode 100644 index cdd9a336b..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-both-right-1.0.jar diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 deleted file mode 100644 index 8fc645ca3..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 +++ /dev/null @@ -1,2 +0,0 @@ -066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-from-managed-repo-1.0.jar -(proxied 1) diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar deleted file mode 100644 index 68e3480fc..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar +++ /dev/null @@ -1,2 +0,0 @@ -get-checksum-md5-bad-sha1-1.0.jar - diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.md5 b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.md5 deleted file mode 100644 index d785caa7f..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.md5 +++ /dev/null @@ -1 +0,0 @@ -8a02aa67549d27b2a03cd4547439c6d3 *get-checksum-md5-bad-sha1-1.0.jar \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.sha1 b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.sha1 deleted file mode 100644 index a2d3f29ea..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -invalid checksum file diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar deleted file mode 100644 index 915323d0e..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar +++ /dev/null @@ -1,2 +0,0 @@ -get-checksum-md5-only-1.0.jar - diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar.md5 b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar.md5 deleted file mode 100644 index f5ecac3db..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar.md5 +++ /dev/null @@ -1 +0,0 @@ -f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar deleted file mode 100644 index f02c91843..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar +++ /dev/null @@ -1,2 +0,0 @@ -get-checksum-sha1-bad-md5-1.0.jar - diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.md5 b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.md5 deleted file mode 100644 index a2d3f29ea..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.md5 +++ /dev/null @@ -1 +0,0 @@ -invalid checksum file diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.sha1 b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.sha1 deleted file mode 100644 index 425623525..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar deleted file mode 100644 index efd9ed015..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar +++ /dev/null @@ -1,2 +0,0 @@ -get-checksum-sha1-only-1.0.jar - diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar.sha1 b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar.sha1 deleted file mode 100644 index e64dccfd8..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar deleted file mode 100644 index 15fd36d5d..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar +++ /dev/null @@ -1,3 +0,0 @@ -get-default-layout-present-1.0.jar -(proxied 1) - diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar deleted file mode 100644 index a129891a7..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar +++ /dev/null @@ -1,2 +0,0 @@ -get-default-layout-1.0.jar - diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml deleted file mode 100644 index 7855530fb..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - org.apache.maven.test - get-default-metadata - 1.0 - \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar deleted file mode 100644 index 3cc35fa29..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar +++ /dev/null @@ -1,3 +0,0 @@ -get-in-both-proxies-1.0.jar -(proxied 1) - diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-merged-metadata/maven-metadata.xml b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-merged-metadata/maven-metadata.xml deleted file mode 100644 index f697f68a9..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-merged-metadata/maven-metadata.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - org.apache.maven.test - get-merged-metadata - - - 2.0 - - 3.0 - - 5.0 - - - - \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar deleted file mode 100644 index 139c17b97..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar +++ /dev/null @@ -1 +0,0 @@ -get-metadata-snapshot-1.0-SNAPSHOT.jar \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar deleted file mode 100644 index 8bbffa00f..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar +++ /dev/null @@ -1,2 +0,0 @@ -get-present-metadata-snapshot-1.0-20050831.101112-1.jar -(proxied 1) \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar deleted file mode 100644 index 0bf178413..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar +++ /dev/null @@ -1,2 +0,0 @@ -get-present-timestamped-snapshot-1.0-SNAPSHOT.jar -(proxied 1) \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar deleted file mode 100644 index dfacfaa15..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar +++ /dev/null @@ -1,2 +0,0 @@ -get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar -(proxied 1) \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar deleted file mode 100644 index af86df92f..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar +++ /dev/null @@ -1 +0,0 @@ -get-timestamped-snapshot-1.0-SNAPSHOT.jar \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml deleted file mode 100644 index 67a3c6206..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - org.apache.maven.test - get-updated-metadata - 1.0-SNAPSHOT - - - 20050831.111213 - 2 - - - \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/maven-metadata.xml b/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/maven-metadata.xml deleted file mode 100644 index 27c44b418..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/maven-metadata.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - org.apache.maven.test - get-updated-metadata - - - 1.0 - 2.0 - - - \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar b/maven-repository-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar deleted file mode 100644 index e46d60ac3..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar +++ /dev/null @@ -1,3 +0,0 @@ -get-in-both-proxies-1.0.jar -(proxied 2) - diff --git a/maven-repository-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar b/maven-repository-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar deleted file mode 100644 index 3460f656d..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar +++ /dev/null @@ -1,2 +0,0 @@ -get-in-second-proxy-1.0.jar - diff --git a/maven-repository-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-merged-metadata/maven-metadata.xml b/maven-repository-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-merged-metadata/maven-metadata.xml deleted file mode 100644 index 5a7a94818..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-merged-metadata/maven-metadata.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - org.apache.maven.test - get-merged-metadata - - - 1.0 - - 3.0 - - 4.0 - - - - \ No newline at end of file diff --git a/maven-repository-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar b/maven-repository-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar deleted file mode 100644 index 915b2b22c..000000000 --- a/maven-repository-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar +++ /dev/null @@ -1,2 +0,0 @@ -get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar -(proxied 2) \ No newline at end of file diff --git a/maven-repository-proxy/src/test/resources/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.xml b/maven-repository-proxy/src/test/resources/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.xml deleted file mode 100644 index a3a47dbbe..000000000 --- a/maven-repository-proxy/src/test/resources/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - org.apache.maven.wagon.Wagon - test - org.apache.maven.repository.proxy.WagonDelegate - - - org.codehaus.plexus.logging.LoggerManager - org.codehaus.plexus.logging.console.ConsoleLoggerManager - basic - - - ERROR - - - - diff --git a/maven-repository-reports-standard/pom.xml b/maven-repository-reports-standard/pom.xml deleted file mode 100755 index bbead04d7..000000000 --- a/maven-repository-reports-standard/pom.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - - - org.apache.maven.repository - maven-repository-manager - 1.0-SNAPSHOT - - 4.0.0 - maven-repository-reports-standard - Maven Repository Standard Reports - - - org.codehaus.plexus - plexus-utils - - - org.codehaus.plexus - plexus-container-default - - - org.apache.maven - maven-artifact - - - org.apache.maven - maven-artifact-manager - - - org.apache.maven - maven-model - - - org.apache.maven - maven-repository-metadata - - - org.apache.maven.wagon - wagon-provider-api - - - org.apache.maven - maven-artifact-manager - - - org.apache.maven.repository - maven-repository-utils - - - org.apache.maven.repository - maven-repository-indexer - - - diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java deleted file mode 100644 index 997597c77..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.Metadata; -import org.apache.maven.artifact.repository.metadata.Snapshot; -import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.util.List; - -/** - * - */ -public abstract class AbstractRepositoryQueryLayer - implements RepositoryQueryLayer -{ - protected ArtifactRepository repository; - - public boolean containsArtifact( Artifact artifact ) - { - File f = new File( repository.getBasedir(), repository.pathOf( artifact ) ); - return f.exists(); - } - - public boolean containsArtifact( Artifact artifact, Snapshot snapshot ) - { - String artifactPath = getSnapshotArtifactRepositoryPath( artifact, snapshot ); - File artifactFile = new File( artifactPath ); - return artifactFile.exists(); - } - - public List getVersions( Artifact artifact ) - throws RepositoryQueryLayerException - { - Metadata metadata = getMetadata( artifact ); - - return metadata.getVersioning().getVersions(); - } - - protected String getSnapshotArtifactRepositoryPath( Artifact artifact, Snapshot snapshot ) - { - File f = new File( repository.getBasedir(), repository.pathOf( artifact ) ); - String snapshotInfo = artifact.getVersion().replaceFirst( "SNAPSHOT", snapshot.getTimestamp() + "-" + - snapshot.getBuildNumber() + ".pom" ); - File snapshotFile = new File( f.getParentFile(), artifact.getArtifactId() + "-" + snapshotInfo ); - return snapshotFile.getAbsolutePath(); - } - - protected Metadata getMetadata( Artifact artifact ) - throws RepositoryQueryLayerException - { - Metadata metadata; - - ArtifactRepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact ); - String path = repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ); - File metadataFile = new File( repository.getBasedir(), path ); - if ( metadataFile.exists() ) - { - MetadataXpp3Reader reader = new MetadataXpp3Reader(); - try - { - metadata = reader.read( new FileReader( metadataFile ) ); - } - catch ( FileNotFoundException e ) - { - throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e ); - } - catch ( IOException e ) - { - throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e ); - } - catch ( XmlPullParserException e ) - { - throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e ); - } - } - else - { - throw new RepositoryQueryLayerException( "Metadata not found: " + metadataFile.getAbsolutePath() ); - } - - return metadata; - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java deleted file mode 100644 index 773b2c7f5..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Model; - -/** - * This interface will be called by the main system for each artifact as it is discovered. This is how each of the - * different types of reports are implemented. - */ -public interface ArtifactReportProcessor -{ - String ROLE = ArtifactReportProcessor.class.getName(); - - void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, ArtifactRepository repository ) - throws ReportProcessorException; - -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java deleted file mode 100644 index a48476491..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; - -import java.util.Iterator; - -/** - * This interface is used by the single artifact processor. - *

- * The initial implementation of this will just need to be a mock implementation in src/test/java, used to track the - * failures and successes for checking assertions. Later, implementations will be made to present reports on the - * web interface, send them via mail, and so on. - * - * @todo i18n - */ -public interface ArtifactReporter -{ - String ROLE = ArtifactReporter.class.getName(); - - String NULL_MODEL = "Provided model was null"; - - String NULL_ARTIFACT = "Provided artifact was null"; - - String EMPTY_GROUP_ID = "Group id was empty or null"; - - String EMPTY_ARTIFACT_ID = "Artifact id was empty or null"; - - String EMPTY_VERSION = "Version was empty or null"; - - String EMPTY_DEPENDENCY_GROUP_ID = "Group id was empty or null"; - - String EMPTY_DEPENDENCY_ARTIFACT_ID = "Artifact id was empty or null"; - - String EMPTY_DEPENDENCY_VERSION = "Version was empty or null"; - - String NO_DEPENDENCIES = "Artifact has no dependencies"; - - String ARTIFACT_NOT_FOUND = "Artifact does not exist in the repository"; - - String DEPENDENCY_NOT_FOUND = "Artifact's dependency does not exist in the repository"; - - void addFailure( Artifact artifact, String reason ); - - void addSuccess( Artifact artifact ); - - void addWarning( Artifact artifact, String message ); - - void addFailure( RepositoryMetadata metadata, String reason ); - - void addSuccess( RepositoryMetadata metadata ); - - void addWarning( RepositoryMetadata metadata, String message ); - - Iterator getArtifactFailureIterator(); - - Iterator getArtifactSuccessIterator(); - - Iterator getArtifactWarningIterator(); - - Iterator getRepositoryMetadataFailureIterator(); - - Iterator getRepositoryMetadataSuccessIterator(); - - Iterator getRepositoryMetadataWarningIterator(); - - int getFailures(); - - int getSuccesses(); - - int getWarnings(); -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java deleted file mode 100644 index 6c0aba900..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; - -/** - * A result of the report for a given artifact being processed. - * - * @author Brett Porter - * @version $Id$ - */ -public class ArtifactResult -{ - private final Artifact artifact; - - private final String reason; - - public ArtifactResult( Artifact artifact ) - { - this.artifact = artifact; - this.reason = null; - } - - public ArtifactResult( Artifact artifact, String reason ) - { - this.artifact = artifact; - this.reason = reason; - } - - public Artifact getArtifact() - { - return artifact; - } - - public String getReason() - { - return reason; - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java deleted file mode 100644 index fdba18d39..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java +++ /dev/null @@ -1,330 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.metadata.Plugin; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.Snapshot; -import org.apache.maven.artifact.repository.metadata.Versioning; -import org.codehaus.plexus.util.FileUtils; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** - * This class will report on bad metadata files. These include invalid version declarations and incomplete version - * information inside the metadata file. Plugin metadata will be checked for validity of the latest plugin artifacts. - * - * @plexus.component role="org.apache.maven.repository.reporting.MetadataReportProcessor" role-hint="bad-metadata" - */ -public class BadMetadataReportProcessor - implements MetadataReportProcessor -{ - /** - * @plexus.requirement - */ - private ArtifactFactory artifactFactory; - - /** - * @plexus.requirement - */ - private RepositoryQueryLayerFactory repositoryQueryLayerFactory; - - /** - * Process the metadata encountered in the repository and report all errors found, if any. - * - * @param metadata the metadata to be processed. - * @param repository the repository where the metadata was encountered - * @param reporter the ArtifactReporter to receive processing results - * @throws ReportProcessorException if an error was occurred while processing the metadata - */ - public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter ) - throws ReportProcessorException - { - boolean hasFailures = false; - - if ( metadata.storedInGroupDirectory() ) - { - try - { - hasFailures = checkPluginMetadata( metadata, repository, reporter ); - } - catch ( IOException e ) - { - throw new ReportProcessorException( "Error getting plugin artifact directories versions", e ); - } - } - else - { - String lastUpdated = metadata.getMetadata().getVersioning().getLastUpdated(); - if ( lastUpdated == null || lastUpdated.length() == 0 ) - { - reporter.addFailure( metadata, "Missing lastUpdated element inside the metadata." ); - hasFailures = true; - } - - if ( metadata.storedInArtifactVersionDirectory() ) - { - hasFailures |= checkSnapshotMetadata( metadata, repository, reporter ); - } - else - { - if ( !checkMetadataVersions( metadata, repository, reporter ) ) - { - hasFailures = true; - } - - try - { - if ( checkRepositoryVersions( metadata, repository, reporter ) ) - { - hasFailures = true; - } - } - catch ( IOException e ) - { - throw new ReportProcessorException( "Error getting versions", e ); - } - } - } - - if ( !hasFailures ) - { - reporter.addSuccess( metadata ); - } - } - - /** - * Method for processing a GroupRepositoryMetadata - * - * @param metadata the metadata to be processed. - * @param repository the repository where the metadata was encountered - * @param reporter the ArtifactReporter to receive processing results - */ - private boolean checkPluginMetadata( RepositoryMetadata metadata, ArtifactRepository repository, - ArtifactReporter reporter ) - throws IOException - { - boolean hasFailures = false; - - File metadataDir = - new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( metadata ) ).getParentFile(); - List pluginDirs = getArtifactIdFiles( metadataDir ); - - Map prefixes = new HashMap(); - for ( Iterator plugins = metadata.getMetadata().getPlugins().iterator(); plugins.hasNext(); ) - { - Plugin plugin = (Plugin) plugins.next(); - - String artifactId = plugin.getArtifactId(); - if ( artifactId == null || artifactId.length() == 0 ) - { - reporter.addFailure( metadata, "Missing or empty artifactId in group metadata." ); - hasFailures = true; - } - - String prefix = plugin.getPrefix(); - if ( prefix == null || prefix.length() == 0 ) - { - reporter.addFailure( metadata, "Missing or empty plugin prefix for artifactId " + artifactId + "." ); - hasFailures = true; - } - else - { - if ( prefixes.containsKey( prefix ) ) - { - reporter.addFailure( metadata, "Duplicate plugin prefix found: " + prefix + "." ); - hasFailures = true; - } - else - { - prefixes.put( prefix, plugin ); - } - } - - if ( artifactId != null && artifactId.length() > 0 ) - { - File pluginDir = new File( metadataDir, artifactId ); - if ( !pluginDirs.contains( pluginDir ) ) - { - reporter.addFailure( metadata, "Metadata plugin " + artifactId + " not found in the repository" ); - hasFailures = true; - } - else - { - pluginDirs.remove( pluginDir ); - } - } - } - - if ( pluginDirs.size() > 0 ) - { - for ( Iterator plugins = pluginDirs.iterator(); plugins.hasNext(); ) - { - File plugin = (File) plugins.next(); - reporter.addFailure( metadata, "Plugin " + plugin.getName() + " is present in the repository but " + - "missing in the metadata." ); - } - hasFailures = true; - } - - return hasFailures; - } - - /** - * Method for processing a SnapshotArtifactRepository - * - * @param metadata the metadata to be processed. - * @param repository the repository where the metadata was encountered - * @param reporter the ArtifactReporter to receive processing results - */ - private boolean checkSnapshotMetadata( RepositoryMetadata metadata, ArtifactRepository repository, - ArtifactReporter reporter ) - { - RepositoryQueryLayer repositoryQueryLayer = - repositoryQueryLayerFactory.createRepositoryQueryLayer( repository ); - - boolean hasFailures = false; - - Snapshot snapshot = metadata.getMetadata().getVersioning().getSnapshot(); - String timestamp = snapshot.getTimestamp(); - String buildNumber = String.valueOf( snapshot.getBuildNumber() ); - - Artifact artifact = createArtifact( metadata ); - if ( !repositoryQueryLayer.containsArtifact( artifact, snapshot ) ) - { - reporter.addFailure( metadata, "Snapshot artifact " + timestamp + "-" + buildNumber + " does not exist." ); - hasFailures = true; - } - - return hasFailures; - } - - /** - * Method for validating the versions declared inside an ArtifactRepositoryMetadata - * - * @param metadata the metadata to be processed. - * @param repository the repository where the metadata was encountered - * @param reporter the ArtifactReporter to receive processing results - */ - private boolean checkMetadataVersions( RepositoryMetadata metadata, ArtifactRepository repository, - ArtifactReporter reporter ) - { - RepositoryQueryLayer repositoryQueryLayer = - repositoryQueryLayerFactory.createRepositoryQueryLayer( repository ); - - boolean hasFailures = false; - Versioning versioning = metadata.getMetadata().getVersioning(); - for ( Iterator versions = versioning.getVersions().iterator(); versions.hasNext(); ) - { - String version = (String) versions.next(); - - Artifact artifact = createArtifact( metadata, version ); - - if ( !repositoryQueryLayer.containsArtifact( artifact ) ) - { - reporter.addFailure( metadata, "Artifact version " + version + " is present in metadata but " + - "missing in the repository." ); - hasFailures = true; - } - } - return hasFailures; - } - - /** - * Searches the artifact repository directory for all versions and verifies that all of them are listed in the - * ArtifactRepositoryMetadata - * - * @param metadata the metadata to be processed. - * @param repository the repository where the metadata was encountered - * @param reporter the ArtifactReporter to receive processing results - */ - private boolean checkRepositoryVersions( RepositoryMetadata metadata, ArtifactRepository repository, - ArtifactReporter reporter ) - throws IOException - { - boolean hasFailures = false; - Versioning versioning = metadata.getMetadata().getVersioning(); - File versionsDir = - new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( metadata ) ).getParentFile(); - List versions = FileUtils.getFileNames( versionsDir, "*/*.pom", null, false ); - for ( Iterator i = versions.iterator(); i.hasNext(); ) - { - File path = new File( (String) i.next() ); - String version = path.getParentFile().getName(); - if ( !versioning.getVersions().contains( version ) ) - { - reporter.addFailure( metadata, "Artifact version " + version + " found in the repository but " + - "missing in the metadata." ); - hasFailures = true; - } - } - return hasFailures; - } - - /** - * Used to create an artifact object from a metadata base version - */ - private Artifact createArtifact( RepositoryMetadata metadata ) - { - return artifactFactory.createBuildArtifact( metadata.getGroupId(), metadata.getArtifactId(), - metadata.getBaseVersion(), "pom" ); - } - - /** - * Used to create an artifact object with a specified version - */ - private Artifact createArtifact( RepositoryMetadata metadata, String version ) - { - return artifactFactory.createBuildArtifact( metadata.getGroupId(), metadata.getArtifactId(), version, "pom" ); - } - - /** - * Used to gather artifactIds from a groupId directory - */ - private List getArtifactIdFiles( File groupIdDir ) - throws IOException - { - List artifactIdFiles = new ArrayList(); - - List fileArray = new ArrayList( Arrays.asList( groupIdDir.listFiles() ) ); - for ( Iterator files = fileArray.iterator(); files.hasNext(); ) - { - File artifactDir = (File) files.next(); - - if ( artifactDir.isDirectory() ) - { - List versions = FileUtils.getFileNames( artifactDir, "*/*.pom", null, false ); - if ( versions.size() > 0 ) - { - artifactIdFiles.add( artifactDir ); - } - } - } - - return artifactIdFiles; - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java deleted file mode 100644 index 8f695f91d..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java +++ /dev/null @@ -1,221 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * Class to implement caching. - */ -public class Cache -{ - private final Map cache; - - private final double cacheHitRatio; - - private final int cacheMaxSize; - - private long cacheHits; - - private long cacheMiss; - - /** - * Caches all data and expires only the oldest data when the specified cache hit rate is reached. - */ - public Cache( double cacheHitRatio ) - { - this( cacheHitRatio, 0 ); - } - - /** - * Caches all data and expires only the oldest data when the maximum cache size is reached - */ - public Cache( int cacheMaxSize ) - { - this( (double) 1, cacheMaxSize ); - } - - /** - * Caches all data and expires only the oldest data when either the specified cache hit rate is reached - * or the maximum cache size is reached. - */ - public Cache( double cacheHitRatio, int cacheMaxSize ) - { - this.cacheHitRatio = cacheHitRatio; - this.cacheMaxSize = cacheMaxSize; - - if ( cacheMaxSize > 0 ) - { - cache = new LinkedHashMap( cacheMaxSize ); - } - else - { - cache = new LinkedHashMap(); - } - } - - /** - * Check if the specified key is already mapped to an object. - * - * @param key the key used to map the cached object - * @return true if the cache contains an object associated with the given key - */ - public boolean containsKey( Object key ) - { - boolean contains; - synchronized ( cache ) - { - contains = cache.containsKey( key ); - - if ( contains ) - { - cacheHits++; - } - else - { - cacheMiss++; - } - } - - return contains; - } - - /** - * Check for a cached object and return it if it exists. Returns null when the keyed object is not found - * - * @param key the key used to map the cached object - * @return the object mapped to the given key, or null if no cache object is mapped to the given key - */ - public Object get( Object key ) - { - Object retValue = null; - - synchronized ( cache ) - { - if ( cache.containsKey( key ) ) - { - // remove and put: this promotes it to the top since we use a linked hash map - retValue = cache.remove( key ); - - cache.put( key, retValue ); - - cacheHits++; - } - else - { - cacheMiss++; - } - } - - return retValue; - } - - /** - * Cache the given value and map it using the given key - * - * @param key the object to map the valued object - * @param value the object to cache - */ - public void put( Object key, Object value ) - { - // remove and put: this promotes it to the top since we use a linked hash map - synchronized ( cache ) - { - if ( cache.containsKey( key ) ) - { - cache.remove( key ); - } - - cache.put( key, value ); - } - - manageCache(); - } - - /** - * Compute for the efficiency of this cache. - * - * @return the ratio of cache hits to the cache misses to queries for cache objects - */ - public double getHitRate() - { - synchronized ( cache ) - { - return cacheHits == 0 && cacheMiss == 0 ? 0 : (double) cacheHits / (double) ( cacheHits + cacheMiss ); - } - } - - /** - * Get the total number of cache objects currently cached. - */ - public int size() - { - return cache.size(); - } - - /** - * Empty the cache and reset the cache hit rate - */ - public void clear() - { - synchronized ( cache ) - { - cacheHits = 0; - cacheMiss = 0; - cache.clear(); - } - } - - private void manageCache() - { - synchronized ( cache ) - { - Iterator iterator = cache.entrySet().iterator(); - if ( cacheMaxSize == 0 ) - { - //desired HitRatio is reached, we can trim the cache to conserve memory - if ( cacheHitRatio <= getHitRate() ) - { - iterator.next(); - iterator.remove(); - } - } - else if ( cache.size() > cacheMaxSize ) - { - // maximum cache size is reached - while ( cache.size() > cacheMaxSize ) - { - iterator.next(); - iterator.remove(); - } - } - else - { - //even though the max has not been reached, the desired HitRatio is already reached, - // so we can trim the cache to conserve memory - if ( cacheHitRatio <= getHitRate() ) - { - iterator.next(); - iterator.remove(); - } - } - } - } - -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java deleted file mode 100644 index b0c1eac27..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.metadata.Metadata; -import org.apache.maven.artifact.repository.metadata.Snapshot; - - -/** - * - */ -public class CachedRepositoryQueryLayer - extends AbstractRepositoryQueryLayer -{ - private Cache cache; - - public static final double CACHE_HIT_RATIO = 0.5; - - public CachedRepositoryQueryLayer( ArtifactRepository repository ) - { - this.repository = repository; - - cache = new Cache( CACHE_HIT_RATIO ); - } - - public double getCacheHitRate() - { - return cache.getHitRate(); - } - - public boolean containsArtifact( Artifact artifact ) - { - boolean artifactFound = true; - - String artifactPath = repository.getBasedir() + "/" + repository.pathOf( artifact ); - - if ( cache.get( artifactPath ) == null ) - { - artifactFound = super.containsArtifact( artifact ); - if ( artifactFound ) - { - cache.put( artifactPath, artifactPath ); - } - } - - return artifactFound; - } - - public boolean containsArtifact( Artifact artifact, Snapshot snapshot ) - { - boolean artifactFound = true; - - String path = getSnapshotArtifactRepositoryPath( artifact, snapshot ); - - if ( cache.get( path ) == null ) - { - artifactFound = super.containsArtifact( artifact, snapshot ); - if ( artifactFound ) - { - cache.put( path, path ); - } - } - - return artifactFound; - } - - /** - * Override method to utilize the cache - */ - protected Metadata getMetadata( Artifact artifact ) - throws RepositoryQueryLayerException - { - Metadata metadata = (Metadata) cache.get( artifact.getId() ); - - if ( metadata == null ) - { - metadata = super.getMetadata( artifact ); - cache.put( artifact.getId(), metadata ); - } - - return metadata; - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java deleted file mode 100644 index 51b4a8772..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Model; -import org.apache.maven.repository.digest.Digester; -import org.apache.maven.repository.digest.DigesterException; -import org.codehaus.plexus.util.FileUtils; - -import java.io.File; -import java.io.IOException; - -/** - * This class reports invalid and mismatched checksums of artifacts and metadata files. - * It validates MD5 and SHA-1 checksums. - * - * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="checksum" - */ -public class ChecksumArtifactReporter - implements ArtifactReportProcessor -{ - /** - * @plexus.requirement role-hint="sha1" - */ - private Digester sha1Digester; - - /** - * @plexus.requirement role-hint="md5" - */ - private Digester md5Digester; - - /** - * Validate the checksum of the specified artifact. - * - * @param model - * @param artifact - * @param reporter - * @param repository - */ - public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, - ArtifactRepository repository ) - { - if ( !"file".equals( repository.getProtocol() ) ) - { - // We can't check other types of URLs yet. Need to use Wagon, with an exists() method. - throw new UnsupportedOperationException( - "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" ); - } - - //check if checksum files exist - String path = repository.pathOf( artifact ); - File file = new File( repository.getBasedir(), path ); - - verifyChecksum( repository, path + ".md5", file, md5Digester, reporter, artifact ); - verifyChecksum( repository, path + ".sha1", file, sha1Digester, reporter, artifact ); - } - - private void verifyChecksum( ArtifactRepository repository, String path, File file, Digester digester, - ArtifactReporter reporter, Artifact artifact ) - { - File checksumFile = new File( repository.getBasedir(), path ); - if ( checksumFile.exists() ) - { - try - { - digester.verify( file, FileUtils.fileRead( checksumFile ) ); - - reporter.addSuccess( artifact ); - } - catch ( DigesterException e ) - { - reporter.addFailure( artifact, e.getMessage() ); - } - catch ( IOException e ) - { - reporter.addFailure( artifact, "Read file error: " + e.getMessage() ); - } - } - else - { - reporter.addFailure( artifact, digester.getAlgorithm() + " checksum file does not exist." ); - } - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumMetadataReporter.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumMetadataReporter.java deleted file mode 100644 index df732f656..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumMetadataReporter.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; -import org.apache.maven.repository.digest.Digester; -import org.apache.maven.repository.digest.DigesterException; -import org.codehaus.plexus.util.FileUtils; - -import java.io.File; -import java.io.IOException; - -/** - * This class reports invalid and mismatched checksums of artifacts and metadata files. - * It validates MD5 and SHA-1 checksums. - * - * @plexus.component role="org.apache.maven.repository.reporting.MetadataReportProcessor" role-hint="checksum-metadata" - */ -public class ChecksumMetadataReporter - implements MetadataReportProcessor -{ - /** - * @plexus.requirement role-hint="sha1" - */ - private Digester sha1Digester; - - /** - * @plexus.requirement role-hint="md5" - */ - private Digester md5Digester; - - /** - * Validate the checksums of the metadata. Get the metadata file from the - * repository then validate the checksum. - */ - public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter ) - { - if ( !"file".equals( repository.getProtocol() ) ) - { - // We can't check other types of URLs yet. Need to use Wagon, with an exists() method. - throw new UnsupportedOperationException( - "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" ); - } - - //check if checksum files exist - String path = repository.pathOfRemoteRepositoryMetadata( metadata ); - File file = new File( repository.getBasedir(), path ); - - verifyChecksum( repository, path + ".md5", file, md5Digester, reporter, metadata ); - verifyChecksum( repository, path + ".sha1", file, sha1Digester, reporter, metadata ); - - } - - private void verifyChecksum( ArtifactRepository repository, String path, File file, Digester digester, - ArtifactReporter reporter, RepositoryMetadata metadata ) - { - File checksumFile = new File( repository.getBasedir(), path ); - if ( checksumFile.exists() ) - { - try - { - digester.verify( file, FileUtils.fileRead( checksumFile ) ); - - reporter.addSuccess( metadata ); - } - catch ( DigesterException e ) - { - reporter.addFailure( metadata, e.getMessage() ); - } - catch ( IOException e ) - { - reporter.addFailure( metadata, "Read file error: " + e.getMessage() ); - } - } - else - { - reporter.addFailure( metadata, digester.getAlgorithm() + " checksum file does not exist." ); - } - } - -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java deleted file mode 100644 index b869e7e49..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java +++ /dev/null @@ -1,161 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Model; - -import java.util.Iterator; -import java.util.List; - -/** - * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="default" - */ -public class DefaultArtifactReportProcessor - implements ArtifactReportProcessor -{ - private static final String EMPTY_STRING = ""; - - // plexus components - private ArtifactFactory artifactFactory; - - private RepositoryQueryLayer repositoryQueryLayer; - - public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, - ArtifactRepository repository ) - { - if ( artifact == null ) - { - reporter.addFailure( artifact, ArtifactReporter.NULL_ARTIFACT ); - } - else - { - processArtifact( artifact, reporter ); - } - - if ( model == null ) - { - reporter.addFailure( artifact, ArtifactReporter.NULL_MODEL ); - } - else - { - List dependencies = model.getDependencies(); - processDependencies( dependencies, reporter ); - } - } - - private void processArtifact( Artifact artifact, ArtifactReporter reporter ) - { - boolean hasFailed = false; - if ( EMPTY_STRING.equals( artifact.getGroupId() ) || artifact.getGroupId() == null ) - { - reporter.addFailure( artifact, ArtifactReporter.EMPTY_GROUP_ID ); - hasFailed = true; - } - if ( EMPTY_STRING.equals( artifact.getArtifactId() ) || artifact.getArtifactId() == null ) - { - reporter.addFailure( artifact, ArtifactReporter.EMPTY_ARTIFACT_ID ); - hasFailed = true; - } - if ( EMPTY_STRING.equals( artifact.getVersion() ) || artifact.getVersion() == null ) - { - reporter.addFailure( artifact, ArtifactReporter.EMPTY_VERSION ); - hasFailed = true; - } - if ( !hasFailed ) - { - if ( repositoryQueryLayer.containsArtifact( artifact ) ) - { - reporter.addSuccess( artifact ); - } - else - { - reporter.addFailure( artifact, ArtifactReporter.ARTIFACT_NOT_FOUND ); - } - } - } - - private void processDependencies( List dependencies, ArtifactReporter reporter ) - { - if ( dependencies.size() > 0 ) - { - Iterator iterator = dependencies.iterator(); - while ( iterator.hasNext() ) - { - boolean hasFailed = false; - Dependency dependency = (Dependency) iterator.next(); - Artifact artifact = createArtifact( dependency ); - if ( EMPTY_STRING.equals( dependency.getGroupId() ) || dependency.getGroupId() == null ) - { - reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID ); - hasFailed = true; - } - if ( EMPTY_STRING.equals( dependency.getArtifactId() ) || dependency.getArtifactId() == null ) - { - reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID ); - hasFailed = true; - } - if ( EMPTY_STRING.equals( dependency.getVersion() ) || dependency.getVersion() == null ) - { - reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_VERSION ); - hasFailed = true; - } - if ( !hasFailed ) - { - if ( repositoryQueryLayer.containsArtifact( artifact ) ) - { - reporter.addSuccess( artifact ); - } - else - { - reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_NOT_FOUND ); - } - } - } - } - - } - - /** - * Only used for passing a mock object when unit testing - * - * @param repositoryQueryLayer - */ - protected void setRepositoryQueryLayer( RepositoryQueryLayer repositoryQueryLayer ) - { - this.repositoryQueryLayer = repositoryQueryLayer; - } - - /** - * Only used for passing a mock object when unit testing - * - * @param artifactFactory - */ - protected void setArtifactFactory( ArtifactFactory artifactFactory ) - { - this.artifactFactory = artifactFactory; - } - - private Artifact createArtifact( Dependency dependency ) - { - return artifactFactory.createBuildArtifact( dependency.getGroupId(), dependency.getArtifactId(), - dependency.getVersion(), "pom" ); - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java deleted file mode 100644 index 32b4cd755..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -/** - * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReporter" role-hint="default" - */ -public class DefaultArtifactReporter - implements ArtifactReporter -{ - private List artifactFailures = new ArrayList(); - - private List artifactSuccesses = new ArrayList(); - - private List artifactWarnings = new ArrayList(); - - private List metadataFailures = new ArrayList(); - - private List metadataSuccesses = new ArrayList(); - - private List metadataWarnings = new ArrayList(); - - public void addFailure( Artifact artifact, String reason ) - { - artifactFailures.add( new ArtifactResult( artifact, reason ) ); - } - - public void addSuccess( Artifact artifact ) - { - artifactSuccesses.add( new ArtifactResult( artifact ) ); - } - - public void addWarning( Artifact artifact, String message ) - { - artifactWarnings.add( new ArtifactResult( artifact, message ) ); - } - - public void addFailure( RepositoryMetadata metadata, String reason ) - { - metadataFailures.add( new RepositoryMetadataResult( metadata, reason ) ); - } - - public void addSuccess( RepositoryMetadata metadata ) - { - metadataSuccesses.add( new RepositoryMetadataResult( metadata ) ); - } - - public void addWarning( RepositoryMetadata metadata, String message ) - { - metadataWarnings.add( new RepositoryMetadataResult( metadata, message ) ); - } - - public Iterator getArtifactFailureIterator() - { - return artifactFailures.iterator(); - } - - public Iterator getArtifactSuccessIterator() - { - return artifactSuccesses.iterator(); - } - - public Iterator getArtifactWarningIterator() - { - return artifactWarnings.iterator(); - } - - public Iterator getRepositoryMetadataFailureIterator() - { - return metadataFailures.iterator(); - } - - public Iterator getRepositoryMetadataSuccessIterator() - { - return metadataSuccesses.iterator(); - } - - public Iterator getRepositoryMetadataWarningIterator() - { - return metadataWarnings.iterator(); - } - - public int getFailures() - { - return artifactFailures.size() + metadataFailures.size(); - } - - public int getSuccesses() - { - return artifactSuccesses.size() + metadataSuccesses.size(); - } - - public int getWarnings() - { - return artifactWarnings.size() + metadataWarnings.size(); - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java deleted file mode 100644 index 5570666dd..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.repository.ArtifactRepository; - -/** - * - */ -public class DefaultRepositoryQueryLayer - extends AbstractRepositoryQueryLayer -{ - public DefaultRepositoryQueryLayer( ArtifactRepository repository ) - { - this.repository = repository; - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java deleted file mode 100644 index 56f9826dc..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.repository.ArtifactRepository; - -/** - * Gets the default implementation of a repository query layer for the given repository. - * - * @author Brett Porter - * @version $Id$ - * @plexus.component role="org.apache.maven.repository.reporting.RepositoryQueryLayerFactory" - */ -public class DefaultRepositoryQueryLayerFactory - implements RepositoryQueryLayerFactory -{ - public RepositoryQueryLayer createRepositoryQueryLayer( ArtifactRepository repository ) - { - return new DefaultRepositoryQueryLayer( repository ); - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java deleted file mode 100644 index df8c81a85..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java +++ /dev/null @@ -1,124 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 java.io.File; -import java.util.Iterator; -import java.util.List; - -import org.apache.lucene.index.Term; -import org.apache.lucene.search.TermQuery; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Model; -import org.apache.maven.repository.digest.Digester; -import org.apache.maven.repository.digest.DigesterException; -import org.apache.maven.repository.indexing.RepositoryArtifactIndex; -import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; -import org.apache.maven.repository.indexing.RepositoryIndexSearchException; -import org.apache.maven.repository.indexing.lucene.LuceneQuery; -import org.apache.maven.repository.indexing.record.StandardArtifactIndexRecord; -import org.apache.maven.repository.indexing.record.StandardIndexRecordFields; - -/** - * Validates an artifact file for duplicates within the same groupId based from what's available in a repository index. - * - * @author Edwin Punzalan - * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="duplicate" - */ -public class DuplicateArtifactFileReportProcessor - implements ArtifactReportProcessor -{ - /** - * @plexus.requirement role-hint="md5" - */ - private Digester digester; - - /** - * @plexus.requirement - */ - private RepositoryArtifactIndexFactory indexFactory; - - /** - * @plexus.configuration - */ - private String indexDirectory; - - public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, - ArtifactRepository repository ) - throws ReportProcessorException - { - if ( artifact.getFile() != null ) - { - RepositoryArtifactIndex index = indexFactory.createStandardIndex( new File( indexDirectory ) ); - - String checksum; - try - { - checksum = digester.calc( artifact.getFile() ); - } - catch ( DigesterException e ) - { - throw new ReportProcessorException( "Failed to generate checksum", e ); - } - - try - { - List results = index.search( new LuceneQuery( - new TermQuery( new Term( StandardIndexRecordFields.MD5, checksum.toLowerCase() ) ) ) ); - - if ( results.isEmpty() ) - { - reporter.addSuccess( artifact ); - } - else - { - boolean hasDuplicates = false; - for ( Iterator i = results.iterator(); i.hasNext(); ) - { - StandardArtifactIndexRecord result = (StandardArtifactIndexRecord) i.next(); - - //make sure it is not the same artifact - if ( !result.getFilename().equals( repository.pathOf( artifact ) ) ) - { - //report only duplicates from the same groupId - String groupId = artifact.getGroupId(); - if ( groupId.equals( result.getGroupId() ) ) - { - hasDuplicates = true; - reporter.addFailure( artifact, "Found duplicate for " + artifact.getId() ); - } - } - } - - if ( !hasDuplicates ) - { - reporter.addSuccess( artifact ); - } - } - } - catch ( RepositoryIndexSearchException e ) - { - throw new ReportProcessorException( "Failed to search in index", e ); - } - } - else - { - reporter.addWarning( artifact, "Artifact file is null" ); - } - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java deleted file mode 100644 index a11f35754..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Model; -import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.Reader; - -/** - * This class validates well-formedness of pom xml file. - * - * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="invalid-pom" - */ -public class InvalidPomArtifactReportProcessor - implements ArtifactReportProcessor -{ - /** - * @param model - * @param artifact The pom xml file to be validated, passed as an artifact object. - * @param reporter The artifact reporter object. - * @param repository the repository where the artifact is located. - */ - public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, - ArtifactRepository repository ) - { - if ( !"file".equals( repository.getProtocol() ) ) - { - // We can't check other types of URLs yet. Need to use Wagon, with an exists() method. - throw new UnsupportedOperationException( - "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" ); - } - - if ( "pom".equals( artifact.getType().toLowerCase() ) ) - { - File f = new File( repository.getBasedir(), repository.pathOf( artifact ) ); - - if ( !f.exists() ) - { - reporter.addFailure( artifact, "Artifact not found." ); - } - else - { - Reader reader = null; - - MavenXpp3Reader pomReader = new MavenXpp3Reader(); - - try - { - reader = new FileReader( f ); - pomReader.read( reader ); - reporter.addSuccess( artifact ); - } - catch ( XmlPullParserException e ) - { - reporter.addFailure( artifact, "The pom xml file is not well-formed. Error while parsing: " + - e.getMessage() ); - } - catch ( FileNotFoundException e ) - { - reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() ); - } - catch ( IOException e ) - { - reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() ); - } - finally - { - IOUtil.close( reader ); - } - } - } - else - { - reporter.addWarning( artifact, "The artifact is not a pom xml file." ); - } - } - -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessor.java deleted file mode 100644 index 140425656..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessor.java +++ /dev/null @@ -1,196 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Model; -import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; - -/** - * Validate the location of the artifact based on the values indicated - * in its pom (both the pom packaged with the artifact & the pom in the - * file system). - * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="artifact-location" - */ -public class LocationArtifactReportProcessor - implements ArtifactReportProcessor -{ - /** @plexus.requirement */ - private ArtifactFactory artifactFactory; - - /** - * Check whether the artifact is in its proper location. The location of the artifact - * is validated first against the groupId, artifactId and versionId in the specified model - * object (pom in the file system). Then unpack the artifact (jar file) and get the model (pom) - * included in the package. If a model exists inside the package, then check if the artifact's - * location is valid based on the location specified in the pom. Check if the both the location - * specified in the file system pom and in the pom included in the package is the same. - * - * @param model Represents the pom in the file system. - * @param artifact - * @param reporter - * @param repository - */ - public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, - ArtifactRepository repository ) - throws ReportProcessorException - { - if ( !"file".equals( repository.getProtocol() ) ) - { - // We can't check other types of URLs yet. Need to use Wagon, with an exists() method. - throw new UnsupportedOperationException( - "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" ); - } - - //check if the artifact is located in its proper location based on the info - //specified in the model object/pom - Artifact modelArtifact = artifactFactory.createBuildArtifact( model.getGroupId(), model.getArtifactId(), - model.getVersion(), model.getPackaging() ); - - boolean failed = false; - String modelPath = repository.pathOf( modelArtifact ); - String artifactPath = repository.pathOf( artifact ); - if ( modelPath.equals( artifactPath ) ) - { - //get the location of the artifact itself - File file = new File( repository.getBasedir(), artifactPath ); - - if ( file.exists() ) - { - //unpack the artifact (using the groupId, artifactId & version specified in the artifact object itself - //check if the pom is included in the package - Model extractedModel = readArtifactModel( file, artifact.getGroupId(), artifact.getArtifactId() ); - - if ( extractedModel != null ) - { - Artifact extractedArtifact = artifactFactory.createBuildArtifact( extractedModel.getGroupId(), - extractedModel.getArtifactId(), - extractedModel.getVersion(), - extractedModel.getPackaging() ); - if ( !repository.pathOf( extractedArtifact ).equals( artifactPath ) ) - { - reporter.addFailure( artifact, - "The artifact is out of place. It does not match the specified location in the packaged pom." ); - failed = true; - } - } - } - else - { - reporter.addFailure( artifact, - "The artifact is out of place. It does not exist at the specified location in the repository pom." ); - failed = true; - } - } - else - { - reporter.addFailure( artifact, - "The artifact is out of place. It does not match the specified location in the repository pom." ); - failed = true; - } - - if ( !failed ) - { - reporter.addSuccess( artifact ); - } - } - - /** - * Extract the contents of the artifact/jar file. - * - * @param file - * @param groupId - * @param artifactId - */ - private Model readArtifactModel( File file, String groupId, String artifactId ) - throws ReportProcessorException - { - Model model = null; - - JarFile jar = null; - try - { - jar = new JarFile( file ); - - //Get the entry and its input stream. - JarEntry entry = jar.getJarEntry( "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml" ); - - // If the entry is not null, extract it. - if ( entry != null ) - { - model = readModel( jar.getInputStream( entry ) ); - } - } - catch ( IOException e ) - { - // TODO: should just warn and continue? - throw new ReportProcessorException( "Unable to read artifact to extract model", e ); - } - catch ( XmlPullParserException e ) - { - // TODO: should just warn and continue? - throw new ReportProcessorException( "Unable to read artifact to extract model", e ); - } - finally - { - if ( jar != null ) - { - //noinspection UnusedCatchParameter - try - { - jar.close(); - } - catch ( IOException e ) - { - // ignore - } - } - } - return model; - } - - private Model readModel( InputStream entryStream ) - throws IOException, XmlPullParserException - { - Reader isReader = new InputStreamReader( entryStream ); - - Model model; - try - { - MavenXpp3Reader pomReader = new MavenXpp3Reader(); - model = pomReader.read( isReader ); - } - finally - { - IOUtil.close( isReader ); - } - return model; - } - -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java deleted file mode 100644 index 0431a8adf..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; - -/** - * This interface is called by the main system for each piece of metadata as it is discovered. - */ -public interface MetadataReportProcessor -{ - String ROLE = MetadataReportProcessor.class.getName(); - - void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter ) - throws ReportProcessorException; -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java deleted file mode 100644 index 5f73dbdc0..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * Exception occurring during reporting. - * - * @author Brett Porter - * @version $Id$ - */ -public class ReportProcessorException - extends Exception -{ - public ReportProcessorException( String msg, Throwable cause ) - { - super( msg, cause ); - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java deleted file mode 100644 index 4c962986a..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.repository.metadata.RepositoryMetadata; - -/** - * A result of the report for a given artifact being processed. - * - * @author Brett Porter - * @version $Id$ - */ -public class RepositoryMetadataResult -{ - private final RepositoryMetadata metadata; - - private final String reason; - - public RepositoryMetadataResult( RepositoryMetadata metadata ) - { - this.metadata = metadata; - this.reason = null; - } - - public RepositoryMetadataResult( RepositoryMetadata metadata, String reason ) - { - this.metadata = metadata; - this.reason = reason; - } - - public RepositoryMetadata getMetadata() - { - return metadata; - } - - public String getReason() - { - return reason; - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java deleted file mode 100644 index 950f7a252..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.metadata.Snapshot; - -import java.util.List; - -/** - * The transitive and metadata validation reports will need to query the repository for artifacts. - */ -public interface RepositoryQueryLayer -{ - String ROLE = RepositoryQueryLayer.class.getName(); - - boolean containsArtifact( Artifact artifact ); - - /** @todo I believe we can remove this [BP] - artifact should contain all the necessary version info */ - boolean containsArtifact( Artifact artifact, Snapshot snapshot ); - - List getVersions( Artifact artifact ) - throws RepositoryQueryLayerException; -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerException.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerException.java deleted file mode 100644 index ae7f77947..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerException.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * - */ -public class RepositoryQueryLayerException - extends Exception -{ - public RepositoryQueryLayerException( String message, Throwable cause ) - { - super( message, cause ); - } - - public RepositoryQueryLayerException( String message ) - { - super( message ); - } -} diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java deleted file mode 100644 index 00f42b30d..000000000 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.repository.ArtifactRepository; - -/** - * Gets the preferred implementation of a repository query layer for the given repository. - * - * @author Brett Porter - * @version $Id$ - */ -public interface RepositoryQueryLayerFactory -{ - String ROLE = RepositoryQueryLayerFactory.class.getName(); - - /** - * Create or obtain a query interface. - * - * @param repository the repository to query - * @return the obtained query layer - */ - RepositoryQueryLayer createRepositoryQueryLayer( ArtifactRepository repository ); -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java deleted file mode 100644 index 93b9b2e6e..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java +++ /dev/null @@ -1,283 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.repository.digest.Digester; -import org.apache.maven.repository.digest.DigesterException; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.IOUtil; - -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.util.jar.JarEntry; -import java.util.jar.JarOutputStream; - -/** - * This class creates the artifact and metadata files used for testing the ChecksumArtifactReporter. - * It is extended by ChecksumArtifactReporterTest class. - */ -public abstract class AbstractChecksumArtifactReporterTestCase - extends AbstractRepositoryReportsTestCase -{ - private static final String[] validArtifactChecksumJars = {"validArtifact-1.0"}; - - private static final String[] invalidArtifactChecksumJars = {"invalidArtifact-1.0"}; - - private static final String metadataChecksumFilename = "maven-metadata"; - - private Digester sha1Digest; - - private Digester md5Digest; - - public void setUp() - throws Exception - { - super.setUp(); - - sha1Digest = (Digester) lookup( Digester.ROLE, "sha1" ); - md5Digest = (Digester) lookup( Digester.ROLE, "md5" ); - } - - /** - * Create checksum files. - * - * @param type The type of checksum file to be created. - */ - protected void createChecksumFile( String type ) - throws DigesterException, IOException - { - //loop through the valid artifact names.. - if ( "VALID".equals( type ) ) - { - for ( int i = 0; i < validArtifactChecksumJars.length; i++ ) - { - writeChecksumFile( "checksumTest/", validArtifactChecksumJars[i], "jar", true ); - } - } - else if ( "INVALID".equals( type ) ) - { - for ( int i = 0; i < invalidArtifactChecksumJars.length; i++ ) - { - writeChecksumFile( "checksumTest/", invalidArtifactChecksumJars[i], "jar", false ); - } - } - } - - /** - * Create checksum files for metadata. - * - * @param type The type of checksum to be created. (Valid or invalid) - */ - protected void createMetadataFile( String type ) - throws DigesterException, IOException - { - //loop through the valid artifact names.. - if ( "VALID".equals( type ) ) - { - writeMetadataFile( "checksumTest/validArtifact/1.0/", metadataChecksumFilename, "xml", true ); - writeMetadataFile( "checksumTest/validArtifact/", metadataChecksumFilename, "xml", true ); - writeMetadataFile( "checksumTest/", metadataChecksumFilename, "xml", true ); - } - else if ( "INVALID".equals( type ) ) - { - writeMetadataFile( "checksumTest/invalidArtifact/1.0/", metadataChecksumFilename, "xml", false ); - } - } - - /** - * Create artifact together with its checksums. - * - * @param relativePath The groupId - * @param filename The filename of the artifact to be created. - * @param type The file type (JAR) - * @param isValid Indicates whether the checksum to be created is valid or not. - */ - private void writeChecksumFile( String relativePath, String filename, String type, boolean isValid ) - throws IOException, DigesterException - { - //Initialize variables for creating jar files - String repoUrl = repository.getBasedir(); - - String dirs = filename.replace( '-', '/' ); - //create the group level directory of the artifact - File dirFiles = new File( repoUrl + relativePath + dirs ); - - if ( dirFiles.mkdirs() ) - { - // create a jar file - String path = repoUrl + relativePath + dirs + "/" + filename + "." + type; - FileOutputStream f = new FileOutputStream( path ); - JarOutputStream out = new JarOutputStream( new BufferedOutputStream( f ) ); - - // jar sample.txt - String filename1 = repoUrl + relativePath + dirs + "/sample.txt"; - createSampleFile( filename1 ); - - BufferedReader in = new BufferedReader( new FileReader( filename1 ) ); - out.putNextEntry( new JarEntry( filename1 ) ); - IOUtil.copy( in, out ); - in.close(); - out.close(); - - //Create md5 and sha-1 checksum files.. - - File file = new File( path + ".md5" ); - OutputStream os = new FileOutputStream( file ); - OutputStreamWriter osw = new OutputStreamWriter( os ); - String sum = md5Digest.calc( new File( path ) ); - if ( !isValid ) - { - osw.write( sum + "1" ); - } - else - { - osw.write( sum ); - } - osw.close(); - - file = new File( path + ".sha1" ); - os = new FileOutputStream( file ); - osw = new OutputStreamWriter( os ); - String sha1sum = sha1Digest.calc( new File( path ) ); - if ( !isValid ) - { - osw.write( sha1sum + "2" ); - } - else - { - osw.write( sha1sum ); - } - osw.close(); - } - } - - /** - * Create metadata file together with its checksums. - * - * @param relativePath The groupId - * @param filename The filename of the artifact to be created. - * @param type The file type (JAR) - * @param isValid Indicates whether the checksum to be created is valid or not. - */ - private void writeMetadataFile( String relativePath, String filename, String type, boolean isValid ) - throws IOException, DigesterException - { - //create checksum for the metadata file.. - String repoUrl = repository.getBasedir(); - String url = repository.getBasedir() + "/" + filename + "." + type; - - String path = repoUrl + relativePath + filename + "." + type; - FileUtils.copyFile( new File( url ), new File( path ) ); - - //Create md5 and sha-1 checksum files.. - File file = new File( path + ".md5" ); - OutputStream os = new FileOutputStream( file ); - OutputStreamWriter osw = new OutputStreamWriter( os ); - String md5sum = md5Digest.calc( new File( path ) ); - if ( !isValid ) - { - osw.write( md5sum + "1" ); - } - else - { - osw.write( md5sum ); - } - osw.close(); - - file = new File( path + ".sha1" ); - os = new FileOutputStream( file ); - osw = new OutputStreamWriter( os ); - String sha1sum = sha1Digest.calc( new File( path ) ); - if ( !isValid ) - { - osw.write( sha1sum + "2" ); - } - else - { - osw.write( sha1sum ); - } - osw.close(); - } - - /** - * Create the sample file that will be included in the jar. - * - * @param filename - */ - private void createSampleFile( String filename ) - throws IOException - { - File file = new File( filename ); - OutputStream os = new FileOutputStream( file ); - OutputStreamWriter osw = new OutputStreamWriter( os ); - osw.write( "This is the content of the sample file that will be included in the jar file." ); - osw.close(); - } - - /** - * Delete the test directory created in the repository. - * - * @param dir The directory to be deleted. - */ - protected void deleteTestDirectory( File dir ) - { - try - { - FileUtils.deleteDirectory( dir ); - } - catch ( IOException e ) - { - // ignore - } - } - - private void deleteFile( String filename ) - { - File f = new File( filename ); - f.delete(); - } - - protected void deleteChecksumFiles( String type ) - { - //delete valid checksum files of artifacts created - for ( int i = 0; i < validArtifactChecksumJars.length; i++ ) - { - deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) + - "/" + validArtifactChecksumJars[i] + "." + type + ".md5" ); - - deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) + - "/" + validArtifactChecksumJars[i] + "." + type + ".sha1" ); - } - - //delete valid checksum files of metadata file - for ( int i = 0; i < validArtifactChecksumJars.length; i++ ) - { - deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) + - "/" + metadataChecksumFilename + ".xml.md5" ); - - deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) + - "/" + metadataChecksumFilename + ".xml.sha1" ); - } - } - -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTestCase.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTestCase.java deleted file mode 100644 index 6de998c8f..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTestCase.java +++ /dev/null @@ -1,142 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.artifact.repository.metadata.Snapshot; -import org.codehaus.plexus.PlexusTestCase; - -import java.io.File; -import java.util.List; - -/** - * - */ -public abstract class AbstractRepositoryQueryLayerTestCase - extends PlexusTestCase -{ - private ArtifactFactory artifactFactory; - - protected ArtifactRepository repository; - - protected CachedRepositoryQueryLayer queryLayer; - - protected void setUp() - throws Exception - { - super.setUp(); - File repositoryDirectory = getTestFile( "src/test/repository" ); - - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - - repository = - factory.createArtifactRepository( "test", repositoryDirectory.toURL().toString(), layout, null, null ); - } - - public void testContainsArtifactTrue() - { - Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-alpha-1" ); - - assertTrue( "check artifact", queryLayer.containsArtifact( artifact ) ); - } - - public void testContainsArtifactFalse() - { - Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-beta-1" ); - - assertFalse( "check non-existent artifact", queryLayer.containsArtifact( artifact ) ); - } - - public void testContainsSnapshotArtifactTrue() - { - Snapshot snapshot = new Snapshot(); - snapshot.setTimestamp( "20050611.202024" ); - snapshot.setBuildNumber( 1 ); - - Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" ); - assertTrue( "check for snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) ); - } - - public void testContainsSnapshotArtifactFalse() - { - Snapshot snapshot = new Snapshot(); - snapshot.setTimestamp( "20050611.202024" ); - snapshot.setBuildNumber( 2 ); - - Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" ); - assertFalse( "check for non-existent snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) ); - } - - public void testArtifactVersionsTrue() - throws Exception - { - Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" ); - - List versions = queryLayer.getVersions( artifact ); - - assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) ); - assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) ); - assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) ); - } - - public void testArtifactVersionsFalse() - throws Exception - { - Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" ); - - List versions = queryLayer.getVersions( artifact ); - - assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) ); - assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) ); - assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) ); - } - - public void testArtifactVersionsError() - { - Artifact artifact = getArtifact( "groupId", "none", "ignored" ); - - try - { - queryLayer.getVersions( artifact ); - fail( "expected error not thrown" ); - } - catch ( RepositoryQueryLayerException e ) - { - //expected - } - } - - private Artifact getArtifact( String groupId, String artifactId, String version ) - { - return artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" ); - } - - protected void tearDown() - throws Exception - { - release( artifactFactory ); - super.tearDown(); - artifactFactory = null; - repository = null; - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java deleted file mode 100644 index 45f12964e..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.codehaus.plexus.PlexusTestCase; - -import java.io.File; - -/** - * - */ -public abstract class AbstractRepositoryReportsTestCase - extends PlexusTestCase -{ - /** - * This should only be used for the few that can't use the query layer. - */ - protected ArtifactRepository repository; - - protected static final String remoteRepoUrl = "http://public.planetmirror.com/pub/maven2/"; - - protected static final String remoteArtifactGroup = "HTTPClient"; - - protected static final String remoteArtifactId = "HTTPClient"; - - protected static final String remoteArtifactVersion = "0.3-3"; - - protected static final String remoteArtifactScope = "compile"; - - protected static final String remoteArtifactType = "jar"; - - protected static final String remoteRepoId = "remote-repo"; - - protected void setUp() - throws Exception - { - super.setUp(); - File repositoryDirectory = getTestFile( "src/test/repository" ); - - ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - - repository = factory.createArtifactRepository( "repository", repositoryDirectory.toURL().toString(), layout, - null, null ); - } - -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java deleted file mode 100644 index 4d6c697f3..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java +++ /dev/null @@ -1,463 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Model; - -import java.util.Iterator; - -/** - * - */ -public class ArtifactReportProcessorTest - extends AbstractRepositoryReportsTestCase -{ - private static final String EMPTY_STRING = ""; - - private static final String VALID = "temp"; - - private MockArtifactReporter reporter; - - private Artifact artifact; - - private Model model; - - private DefaultArtifactReportProcessor processor; - - private static final boolean ARTIFACT_FOUND = true; - - private static final boolean ARTIFACT_NOT_FOUND = false; - - protected void setUp() - throws Exception - { - super.setUp(); - reporter = new MockArtifactReporter(); - artifact = new MockArtifact(); - model = new Model(); - processor = new DefaultArtifactReportProcessor(); - } - - public void testNullArtifact() - { - processor.processArtifact( model, null, reporter, null ); - assertEquals( 0, reporter.getSuccesses() ); - assertEquals( 1, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.NULL_ARTIFACT, result.getReason() ); - } - - public void testNoProjectDescriptor() - { - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - processor.setRepositoryQueryLayer( queryLayer ); - setRequiredElements( artifact, VALID, VALID, VALID ); - processor.processArtifact( null, artifact, reporter, null ); - assertEquals( 1, reporter.getSuccesses() ); - assertEquals( 1, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.NULL_MODEL, result.getReason() ); - } - - public void testArtifactFoundButNoDirectDependencies() - { - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - processor.setRepositoryQueryLayer( queryLayer ); - setRequiredElements( artifact, VALID, VALID, VALID ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 1, reporter.getSuccesses() ); - assertEquals( 0, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - } - - public void testArtifactNotFound() - { - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_NOT_FOUND ); - processor.setRepositoryQueryLayer( queryLayer ); - setRequiredElements( artifact, VALID, VALID, VALID ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 0, reporter.getSuccesses() ); - assertEquals( 1, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.ARTIFACT_NOT_FOUND, result.getReason() ); - } - - public void testValidArtifactWithNullDependency() - { - MockArtifactFactory artifactFactory = new MockArtifactFactory(); - processor.setArtifactFactory( artifactFactory ); - - setRequiredElements( artifact, VALID, VALID, VALID ); - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - Dependency dependency = new Dependency(); - setRequiredElements( dependency, VALID, VALID, VALID ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - processor.setRepositoryQueryLayer( queryLayer ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 2, reporter.getSuccesses() ); - assertEquals( 0, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - } - - public void testValidArtifactWithValidSingleDependency() - { - MockArtifactFactory artifactFactory = new MockArtifactFactory(); - processor.setArtifactFactory( artifactFactory ); - - setRequiredElements( artifact, VALID, VALID, VALID ); - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - Dependency dependency = new Dependency(); - setRequiredElements( dependency, VALID, VALID, VALID ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - processor.setRepositoryQueryLayer( queryLayer ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 2, reporter.getSuccesses() ); - assertEquals( 0, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - } - - public void testValidArtifactWithValidMultipleDependencies() - { - MockArtifactFactory artifactFactory = new MockArtifactFactory(); - processor.setArtifactFactory( artifactFactory ); - - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - Dependency dependency = new Dependency(); - setRequiredElements( dependency, VALID, VALID, VALID ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - setRequiredElements( artifact, VALID, VALID, VALID ); - processor.setRepositoryQueryLayer( queryLayer ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 6, reporter.getSuccesses() ); - assertEquals( 0, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - } - - public void testValidArtifactWithAnInvalidDependency() - { - MockArtifactFactory artifactFactory = new MockArtifactFactory(); - processor.setArtifactFactory( artifactFactory ); - - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - Dependency dependency = new Dependency(); - setRequiredElements( dependency, VALID, VALID, VALID ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_NOT_FOUND ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - setRequiredElements( artifact, VALID, VALID, VALID ); - processor.setRepositoryQueryLayer( queryLayer ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 5, reporter.getSuccesses() ); - assertEquals( 1, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() ); - } - - public void testEmptyGroupId() - { - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - processor.setRepositoryQueryLayer( queryLayer ); - - setRequiredElements( artifact, EMPTY_STRING, VALID, VALID ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 0, reporter.getSuccesses() ); - assertEquals( 1, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() ); - } - - public void testEmptyArtifactId() - { - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - processor.setRepositoryQueryLayer( queryLayer ); - - setRequiredElements( artifact, VALID, EMPTY_STRING, VALID ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 0, reporter.getSuccesses() ); - assertEquals( 1, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() ); - } - - public void testEmptyVersion() - { - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - processor.setRepositoryQueryLayer( queryLayer ); - - setRequiredElements( artifact, VALID, VALID, EMPTY_STRING ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 0, reporter.getSuccesses() ); - assertEquals( 1, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() ); - } - - public void testNullGroupId() - { - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - processor.setRepositoryQueryLayer( queryLayer ); - - setRequiredElements( artifact, null, VALID, VALID ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 0, reporter.getSuccesses() ); - assertEquals( 1, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() ); - } - - public void testNullArtifactId() - { - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - processor.setRepositoryQueryLayer( queryLayer ); - - setRequiredElements( artifact, VALID, null, VALID ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 0, reporter.getSuccesses() ); - assertEquals( 1, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() ); - } - - public void testNullVersion() - { - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - processor.setRepositoryQueryLayer( queryLayer ); - - setRequiredElements( artifact, VALID, VALID, null ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 0, reporter.getSuccesses() ); - assertEquals( 1, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() ); - } - - public void testMultipleFailures() - { - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - processor.setRepositoryQueryLayer( queryLayer ); - - setRequiredElements( artifact, null, null, null ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 0, reporter.getSuccesses() ); - assertEquals( 3, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() ); - result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() ); - result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() ); - } - - public void testValidArtifactWithInvalidDependencyGroupId() - { - MockArtifactFactory artifactFactory = new MockArtifactFactory(); - processor.setArtifactFactory( artifactFactory ); - - setRequiredElements( artifact, VALID, VALID, VALID ); - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - Dependency dependency = new Dependency(); - setRequiredElements( dependency, null, VALID, VALID ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - processor.setRepositoryQueryLayer( queryLayer ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 1, reporter.getSuccesses() ); - assertEquals( 1, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID, result.getReason() ); - } - - public void testValidArtifactWithInvalidDependencyArtifactId() - { - MockArtifactFactory artifactFactory = new MockArtifactFactory(); - processor.setArtifactFactory( artifactFactory ); - - setRequiredElements( artifact, VALID, VALID, VALID ); - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - Dependency dependency = new Dependency(); - setRequiredElements( dependency, VALID, null, VALID ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - processor.setRepositoryQueryLayer( queryLayer ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 1, reporter.getSuccesses() ); - assertEquals( 1, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID, result.getReason() ); - } - - public void testValidArtifactWithInvalidDependencyVersion() - { - MockArtifactFactory artifactFactory = new MockArtifactFactory(); - processor.setArtifactFactory( artifactFactory ); - - setRequiredElements( artifact, VALID, VALID, VALID ); - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - Dependency dependency = new Dependency(); - setRequiredElements( dependency, VALID, VALID, null ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - processor.setRepositoryQueryLayer( queryLayer ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 1, reporter.getSuccesses() ); - assertEquals( 1, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_VERSION, result.getReason() ); - } - - public void testValidArtifactWithInvalidDependencyRequiredElements() - { - MockArtifactFactory artifactFactory = new MockArtifactFactory(); - processor.setArtifactFactory( artifactFactory ); - - setRequiredElements( artifact, VALID, VALID, VALID ); - MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer(); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - Dependency dependency = new Dependency(); - setRequiredElements( dependency, null, null, null ); - model.addDependency( dependency ); - queryLayer.addReturnValue( ARTIFACT_FOUND ); - - processor.setRepositoryQueryLayer( queryLayer ); - processor.processArtifact( model, artifact, reporter, null ); - assertEquals( 1, reporter.getSuccesses() ); - assertEquals( 3, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID, result.getReason() ); - result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID, result.getReason() ); - result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_VERSION, result.getReason() ); - } - - protected void tearDown() - throws Exception - { - model = null; - artifact = null; - reporter = null; - super.tearDown(); - } - - private void setRequiredElements( Artifact artifact, String groupId, String artifactId, String version ) - { - artifact.setGroupId( groupId ); - artifact.setArtifactId( artifactId ); - artifact.setVersion( version ); - } - - private void setRequiredElements( Dependency dependency, String groupId, String artifactId, String version ) - { - dependency.setGroupId( groupId ); - dependency.setArtifactId( artifactId ); - dependency.setVersion( version ); - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java deleted file mode 100644 index e3fc97f6b..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java +++ /dev/null @@ -1,187 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.metadata.Versioning; -import org.apache.maven.model.Model; - -import java.util.Iterator; - -/** - * - */ -public class ArtifactReporterTest - extends AbstractRepositoryReportsTestCase -{ - private ArtifactReporter reporter; - - private Artifact artifact; - - private MockArtifactReportProcessor processor; - - private Model model; - - protected void setUp() - throws Exception - { - super.setUp(); - reporter = new DefaultArtifactReporter(); - ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); - processor = new MockArtifactReportProcessor(); - Versioning versioning = new Versioning(); - versioning.addVersion( "1.0-alpha-1" ); - versioning.setLastUpdated( "20050611.202020" ); - model = new Model(); - } - - public void testArtifactReporterSingleSuccess() - { - processor.addReturnValue( ReportCondition.SUCCESS, artifact, "all is good" ); - processor.processArtifact( model, artifact, reporter, null ); - Iterator success = reporter.getArtifactSuccessIterator(); - assertTrue( success.hasNext() ); - assertEquals( 1, reporter.getSuccesses() ); - Artifact result = ( (ArtifactResult) success.next() ).getArtifact(); - assertEquals( "groupId", result.getGroupId() ); - assertEquals( "artifactId", result.getArtifactId() ); - assertEquals( "1.0-alpha-1", result.getVersion() ); - assertFalse( success.hasNext() ); - } - - public void testArtifactReporterMultipleSuccess() - { - processor.clearList(); - processor.addReturnValue( ReportCondition.SUCCESS, artifact, "one" ); - processor.addReturnValue( ReportCondition.SUCCESS, artifact, "two" ); - processor.addReturnValue( ReportCondition.SUCCESS, artifact, "three" ); - reporter = new DefaultArtifactReporter(); - processor.processArtifact( model, artifact, reporter, null ); - Iterator success = reporter.getArtifactSuccessIterator(); - assertTrue( success.hasNext() ); - int i; - for ( i = 0; success.hasNext(); i++ ) - { - success.next(); - } - assertEquals( 3, i ); - assertEquals( 3, reporter.getSuccesses() ); - assertEquals( 0, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - } - - public void testArtifactReporterSingleFailure() - { - processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" ); - processor.processArtifact( model, artifact, reporter, null ); - Iterator failure = reporter.getArtifactFailureIterator(); - assertTrue( failure.hasNext() ); - failure.next(); - assertFalse( failure.hasNext() ); - assertEquals( 0, reporter.getSuccesses() ); - assertEquals( 1, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - } - - public void testArtifactReporterMultipleFailure() - { - processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" ); - processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed twice" ); - processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed thrice" ); - processor.processArtifact( model, artifact, reporter, null ); - Iterator failure = reporter.getArtifactFailureIterator(); - assertTrue( failure.hasNext() ); - int i; - for ( i = 0; failure.hasNext(); i++ ) - { - failure.next(); - } - assertEquals( 3, i ); - assertEquals( 0, reporter.getSuccesses() ); - assertEquals( 3, reporter.getFailures() ); - assertEquals( 0, reporter.getWarnings() ); - } - - public void testFailureMessages() - { - processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" ); - processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed twice" ); - processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed thrice" ); - processor.processArtifact( model, artifact, reporter, null ); - Iterator failure = reporter.getArtifactFailureIterator(); - assertEquals( "failed once", ( (ArtifactResult) failure.next() ).getReason() ); - assertEquals( "failed twice", ( (ArtifactResult) failure.next() ).getReason() ); - assertEquals( "failed thrice", ( (ArtifactResult) failure.next() ).getReason() ); - } - - public void testArtifactReporterSingleWarning() - { - processor.addReturnValue( ReportCondition.WARNING, artifact, "you've been warned" ); - processor.processArtifact( model, artifact, reporter, null ); - Iterator warning = reporter.getArtifactWarningIterator(); - assertTrue( warning.hasNext() ); - warning.next(); - assertFalse( warning.hasNext() ); - assertEquals( 0, reporter.getSuccesses() ); - assertEquals( 0, reporter.getFailures() ); - assertEquals( 1, reporter.getWarnings() ); - } - - public void testArtifactReporterMultipleWarning() - { - processor.addReturnValue( ReportCondition.WARNING, artifact, "i'm warning you" ); - processor.addReturnValue( ReportCondition.WARNING, artifact, "you have to stop now" ); - processor.addReturnValue( ReportCondition.WARNING, artifact, "all right... that does it!" ); - processor.processArtifact( model, artifact, reporter, null ); - Iterator warning = reporter.getArtifactWarningIterator(); - assertTrue( warning.hasNext() ); - int i; - for ( i = 0; warning.hasNext(); i++ ) - { - warning.next(); - } - assertEquals( 3, i ); - assertEquals( 0, reporter.getSuccesses() ); - assertEquals( 0, reporter.getFailures() ); - assertEquals( 3, reporter.getWarnings() ); - } - - public void testWarningMessages() - { - processor.addReturnValue( ReportCondition.WARNING, artifact, "i'm warning you" ); - processor.addReturnValue( ReportCondition.WARNING, artifact, "you have to stop now" ); - processor.addReturnValue( ReportCondition.WARNING, artifact, "all right... that does it!" ); - processor.processArtifact( model, artifact, reporter, null ); - Iterator warning = reporter.getArtifactWarningIterator(); - assertEquals( "i'm warning you", ( (ArtifactResult) warning.next() ).getReason() ); - assertEquals( "you have to stop now", ( (ArtifactResult) warning.next() ).getReason() ); - assertEquals( "all right... that does it!", ( (ArtifactResult) warning.next() ).getReason() ); - } - - protected void tearDown() - throws Exception - { - model = null; - processor.clearList(); - processor = null; - reporter = null; - super.tearDown(); - } - -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java deleted file mode 100644 index 828b27274..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java +++ /dev/null @@ -1,358 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.Plugin; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.Snapshot; -import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.Versioning; - -import java.util.Iterator; - -/** - * @todo??? should use MetadataXpp3Reader instead ? - */ -public class BadMetadataReportProcessorTest - extends AbstractRepositoryReportsTestCase -{ - private ArtifactFactory artifactFactory; - - private MetadataReportProcessor badMetadataReportProcessor; - - protected void setUp() - throws Exception - { - super.setUp(); - - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - - badMetadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE ); - } - - public void testMetadataMissingLastUpdated() - throws ReportProcessorException - { - ArtifactReporter reporter = new MockArtifactReporter(); - - Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); - - Versioning versioning = new Versioning(); - versioning.addVersion( "1.0-alpha-1" ); - versioning.addVersion( "1.0-alpha-2" ); - - RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); - - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator failures = reporter.getRepositoryMetadataFailureIterator(); - assertTrue( "check there is a failure", failures.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); - assertEquals( "check metadata", metadata, result.getMetadata() ); - assertEquals( "check reason", "Missing lastUpdated element inside the metadata.", result.getReason() ); - assertFalse( "check no more failures", failures.hasNext() ); - } - - public void testMetadataValidVersions() - throws ReportProcessorException - { - ArtifactReporter reporter = new MockArtifactReporter(); - - Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); - - Versioning versioning = new Versioning(); - versioning.addVersion( "1.0-alpha-1" ); - versioning.addVersion( "1.0-alpha-2" ); - versioning.setLastUpdated( "20050611.202020" ); - - RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); - - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator failures = reporter.getRepositoryMetadataFailureIterator(); - assertFalse( "check there are no failures", failures.hasNext() ); - } - - public void testMetadataMissingADirectory() - throws ReportProcessorException - { - ArtifactReporter reporter = new MockArtifactReporter(); - - Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); - - Versioning versioning = new Versioning(); - versioning.addVersion( "1.0-alpha-1" ); - versioning.setLastUpdated( "20050611.202020" ); - - RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); - - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator failures = reporter.getRepositoryMetadataFailureIterator(); - assertTrue( "check there is a failure", failures.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); - assertEquals( "check metadata", metadata, result.getMetadata() ); - // TODO: should be more robust - assertEquals( "check reason", - "Artifact version 1.0-alpha-2 found in the repository but missing in the metadata.", - result.getReason() ); - assertFalse( "check no more failures", failures.hasNext() ); - } - - public void testMetadataInvalidArtifactVersion() - throws ReportProcessorException - { - ArtifactReporter reporter = new MockArtifactReporter(); - - Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); - - Versioning versioning = new Versioning(); - versioning.addVersion( "1.0-alpha-1" ); - versioning.addVersion( "1.0-alpha-2" ); - versioning.addVersion( "1.0-alpha-3" ); - versioning.setLastUpdated( "20050611.202020" ); - - RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); - - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator failures = reporter.getRepositoryMetadataFailureIterator(); - assertTrue( "check there is a failure", failures.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); - assertEquals( "check metadata", metadata, result.getMetadata() ); - // TODO: should be more robust - assertEquals( "check reason", - "Artifact version 1.0-alpha-3 is present in metadata but missing in the repository.", - result.getReason() ); - assertFalse( "check no more failures", failures.hasNext() ); - } - - public void testMoreThanOneMetadataVersionErrors() - throws ReportProcessorException - { - ArtifactReporter reporter = new MockArtifactReporter(); - - Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); - - Versioning versioning = new Versioning(); - versioning.addVersion( "1.0-alpha-1" ); - versioning.addVersion( "1.0-alpha-3" ); - versioning.setLastUpdated( "20050611.202020" ); - - RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); - - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator failures = reporter.getRepositoryMetadataFailureIterator(); - assertTrue( "check there is a failure", failures.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); - assertEquals( "check metadata", metadata, result.getMetadata() ); - // TODO: should be more robust - assertEquals( "check reason", - "Artifact version 1.0-alpha-3 is present in metadata but missing in the repository.", - result.getReason() ); - assertTrue( "check there is a 2nd failure", failures.hasNext() ); - result = (RepositoryMetadataResult) failures.next(); - // TODO: should be more robust - assertEquals( "check reason", - "Artifact version 1.0-alpha-2 found in the repository but missing in the metadata.", - result.getReason() ); - assertFalse( "check no more failures", failures.hasNext() ); - } - - public void testValidPluginMetadata() - throws ReportProcessorException - { - ArtifactReporter reporter = new MockArtifactReporter(); - - RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); - metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); - metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) ); - - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator failures = reporter.getRepositoryMetadataFailureIterator(); - assertFalse( "check there are no failures", failures.hasNext() ); - } - - public void testMissingMetadataPlugin() - throws ReportProcessorException - { - ArtifactReporter reporter = new MockArtifactReporter(); - - RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); - metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); - metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) ); - metadata.getMetadata().addPlugin( createMetadataPlugin( "missing-plugin", "default3" ) ); - - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator failures = reporter.getRepositoryMetadataFailureIterator(); - assertTrue( "check there is a failure", failures.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); - // TODO: should be more robust - assertEquals( "check reason", "Metadata plugin missing-plugin not found in the repository", - result.getReason() ); - assertFalse( "check no more failures", failures.hasNext() ); - } - - public void testIncompletePluginMetadata() - throws ReportProcessorException - { - ArtifactReporter reporter = new MockArtifactReporter(); - - RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); - metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); - - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator failures = reporter.getRepositoryMetadataFailureIterator(); - assertTrue( "check there is a failure", failures.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); - // TODO: should be more robust - assertEquals( "check reason", - "Plugin snapshot-artifact is present in the repository but " + "missing in the metadata.", - result.getReason() ); - assertFalse( "check no more failures", failures.hasNext() ); - } - - public void testInvalidPluginArtifactId() - throws ReportProcessorException - { - ArtifactReporter reporter = new MockArtifactReporter(); - - RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); - metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); - metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) ); - metadata.getMetadata().addPlugin( createMetadataPlugin( null, "default3" ) ); - metadata.getMetadata().addPlugin( createMetadataPlugin( "", "default4" ) ); - - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator failures = reporter.getRepositoryMetadataFailureIterator(); - assertTrue( "check there is a failure", failures.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); - // TODO: should be more robust - assertEquals( "check reason", "Missing or empty artifactId in group metadata.", result.getReason() ); - assertTrue( "check there is a 2nd failure", failures.hasNext() ); - result = (RepositoryMetadataResult) failures.next(); - // TODO: should be more robust - assertEquals( "check reason", "Missing or empty artifactId in group metadata.", result.getReason() ); - assertFalse( "check no more failures", failures.hasNext() ); - } - - public void testInvalidPluginPrefix() - throws ReportProcessorException - { - ArtifactReporter reporter = new MockArtifactReporter(); - - RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); - metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", null ) ); - metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "" ) ); - - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator failures = reporter.getRepositoryMetadataFailureIterator(); - assertTrue( "check there is a failure", failures.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); - // TODO: should be more robust - assertEquals( "check reason", "Missing or empty plugin prefix for artifactId artifactId.", result.getReason() ); - assertTrue( "check there is a 2nd failure", failures.hasNext() ); - result = (RepositoryMetadataResult) failures.next(); - // TODO: should be more robust - assertEquals( "check reason", "Missing or empty plugin prefix for artifactId snapshot-artifact.", - result.getReason() ); - assertFalse( "check no more failures", failures.hasNext() ); - } - - public void testDuplicatePluginPrefixes() - throws ReportProcessorException - { - ArtifactReporter reporter = new MockArtifactReporter(); - - RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); - metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); - metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default" ) ); - - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator failures = reporter.getRepositoryMetadataFailureIterator(); - assertTrue( "check there is a failure", failures.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); - // TODO: should be more robust - assertEquals( "check reason", "Duplicate plugin prefix found: default.", result.getReason() ); - assertFalse( "check no more failures", failures.hasNext() ); - } - - public void testValidSnapshotMetadata() - throws ReportProcessorException - { - ArtifactReporter reporter = new MockArtifactReporter(); - - Artifact artifact = - artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "type" ); - - Snapshot snapshot = new Snapshot(); - snapshot.setBuildNumber( 1 ); - snapshot.setTimestamp( "20050611.202024" ); - - RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot ); - - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator failures = reporter.getRepositoryMetadataFailureIterator(); - assertFalse( "check there are no failures", failures.hasNext() ); - } - - public void testInvalidSnapshotMetadata() - throws ReportProcessorException - { - ArtifactReporter reporter = new MockArtifactReporter(); - - Artifact artifact = - artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "type" ); - - Snapshot snapshot = new Snapshot(); - snapshot.setBuildNumber( 2 ); - snapshot.setTimestamp( "20050611.202024" ); - - RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot ); - - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator failures = reporter.getRepositoryMetadataFailureIterator(); - assertTrue( "check there is a failure", failures.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); - assertEquals( "check metadata", metadata, result.getMetadata() ); - // TODO: should be more robust - assertEquals( "check reason", "Snapshot artifact 20050611.202024-2 does not exist.", result.getReason() ); - assertFalse( "check no more failures", failures.hasNext() ); - } - - private Plugin createMetadataPlugin( String artifactId, String prefix ) - { - Plugin plugin = new Plugin(); - plugin.setArtifactId( artifactId ); - plugin.setName( artifactId ); - plugin.setPrefix( prefix ); - return plugin; - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java deleted file mode 100644 index cfc83b309..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 junit.framework.TestCase; - -/** - * - */ -public class CacheTest - extends TestCase -{ - private Cache cache; - - private static final double CACHE_HIT_RATIO = 0.5; - - private static final double CACHE_HIT_RATIO_THRESHOLD = 0.75; - - public void testCacheManagementBasedOnHitsRatio() - { - cache = new Cache( CACHE_HIT_RATIO ); - newCacheObjectTests(); - - String key = "key"; - String value = "value"; - for ( int ctr = 1; ctr < 10; ctr++ ) - { - cache.put( key + ctr, value + ctr ); - } - - while ( cache.getHitRate() < CACHE_HIT_RATIO_THRESHOLD ) - { - cache.get( "key2" ); - } - cache.put( "key10", "value10" ); - assertNull( "first key must be expired", cache.get( "key1" ) ); - } - - public void testCacheManagementBasedOnCacheSize() - { - cache = new Cache( 9 ); - newCacheObjectTests(); - - String key = "key"; - String value = "value"; - for ( int ctr = 1; ctr < 10; ctr++ ) - { - cache.put( key + ctr, value + ctr ); - } - - cache.put( "key10", "value10" ); - assertNull( "first key must be expired", cache.get( "key1" ) ); - assertEquals( "check cache size to be max size", 9, cache.size() ); - } - - public void testCacheManagementBasedOnCacheSizeAndHitRate() - { - cache = new Cache( CACHE_HIT_RATIO, 9 ); - newCacheObjectTests(); - - String key = "key"; - String value = "value"; - for ( int ctr = 1; ctr < 5; ctr++ ) - { - cache.put( key + ctr, value + ctr ); - } - - while ( cache.getHitRate() < CACHE_HIT_RATIO ) - { - cache.get( "key3" ); - } - - cache.put( "key10", "value10" ); - assertNull( "first key must be expired", cache.get( "key1" ) ); - - while ( cache.getHitRate() >= CACHE_HIT_RATIO ) - { - cache.get( "key11" ); - } - - for ( int ctr = 5; ctr < 10; ctr++ ) - { - cache.put( key + ctr, value + ctr ); - } - - cache.put( "key11", "value11" ); - assertNull( "second key must be expired", cache.get( "key2" ) ); - assertEquals( "check cache size to be max size", 9, cache.size() ); - } - - public void testCacheOnRedundantData() - { - cache = new Cache( CACHE_HIT_RATIO, 9 ); - newCacheObjectTests(); - - String key = "key"; - String value = "value"; - for ( int ctr = 1; ctr < 10; ctr++ ) - { - cache.put( key + ctr, value + ctr ); - } - - cache.put( "key1", "value1" ); - cache.put( "key10", "value10" ); - assertNull( "second key must be gone", cache.get( "key2" ) ); - assertEquals( "check cache size to be max size", 9, cache.size() ); - } - - private void newCacheObjectTests() - { - assertEquals( (double) 0, cache.getHitRate(), 0 ); - assertEquals( "check cache size", 0, cache.size() ); - - String value = "value"; - String key = "key"; - - cache.put( key, value ); - assertEquals( "check cache hit", value, cache.get( key ) ); - assertEquals( (double) 1, cache.getHitRate(), 0 ); - assertEquals( "check cache size", 1, cache.size() ); - assertNull( "check cache miss", cache.get( "none" ) ); - assertEquals( CACHE_HIT_RATIO, cache.getHitRate(), 0 ); - cache.clear(); - assertNull( "check flushed object", cache.get( "key" ) ); - assertEquals( (double) 0, cache.getHitRate(), 0 ); - assertEquals( "check flushed cache size", 0, cache.size() ); - cache.clear(); - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java deleted file mode 100644 index 11c0b8e95..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * - */ -public class CachedRepositoryQueryLayerTest - extends AbstractRepositoryQueryLayerTestCase -{ - - protected void setUp() - throws Exception - { - super.setUp(); - - queryLayer = new CachedRepositoryQueryLayer( repository ); - } - - public void testUseFileCache() - { - testContainsArtifactTrue(); - assertEquals( 0, queryLayer.getCacheHitRate(), 0 ); - testContainsArtifactTrue(); - assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 ); - } - - public void testUseMetadataCache() - throws Exception - { - testArtifactVersionsTrue(); - assertEquals( 0, queryLayer.getCacheHitRate(), 0 ); - testArtifactVersionsTrue(); - assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 ); - } - - public void testUseFileCacheOnSnapshot() - { - testContainsSnapshotArtifactTrue(); - assertEquals( 0, queryLayer.getCacheHitRate(), 0 ); - testContainsSnapshotArtifactTrue(); - assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 ); - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java deleted file mode 100644 index 64585c52d..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java +++ /dev/null @@ -1,220 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.artifact.handler.DefaultArtifactHandler; -import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.repository.digest.DigesterException; - -import java.io.File; -import java.io.IOException; -import java.util.Iterator; - -/** - * This class tests the ChecksumArtifactReporter. - * It extends the AbstractChecksumArtifactReporterTestCase class. - */ -public class ChecksumArtifactReporterTest - extends AbstractChecksumArtifactReporterTestCase -{ - private ArtifactReportProcessor artifactReportProcessor; - - private ArtifactReporter reporter = new MockArtifactReporter(); - - private MetadataReportProcessor metadataReportProcessor; - - public void setUp() - throws Exception - { - super.setUp(); - artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "checksum" ); - metadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE, "checksum-metadata" ); - } - - /** - * Test the ChecksumArtifactReporter when the checksum files are valid. - */ - public void testChecksumArtifactReporterSuccess() - throws ReportProcessorException, IOException, DigesterException - { - createChecksumFile( "VALID" ); - createChecksumFile( "INVALID" ); - - ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); - VersionRange version = VersionRange.createFromVersion( "1.0" ); - Artifact artifact = - new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler ); - - artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); - assertEquals( 2, reporter.getSuccesses() ); - } - - /** - * Test the ChecksumArtifactReporter when the checksum files are invalid. - */ - public void testChecksumArtifactReporterFailed() - throws ReportProcessorException - { - ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); - VersionRange version = VersionRange.createFromVersion( "1.0" ); - Artifact artifact = - new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler ); - - artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); - assertEquals( 2, reporter.getFailures() ); - } - - /** - * Test the valid checksum of a metadata file. - * The reporter should report 2 success validation. - */ - public void testChecksumMetadataReporterSuccess() - throws ReportProcessorException, DigesterException, IOException - { - createMetadataFile( "VALID" ); - createMetadataFile( "INVALID" ); - - ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); - VersionRange version = VersionRange.createFromVersion( "1.0" ); - Artifact artifact = - new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler ); - - //Version level metadata - RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); - metadataReportProcessor.processMetadata( metadata, repository, reporter ); - - //Artifact level metadata - metadata = new ArtifactRepositoryMetadata( artifact ); - metadataReportProcessor.processMetadata( metadata, repository, reporter ); - - //Group level metadata - metadata = new GroupRepositoryMetadata( "checksumTest" ); - metadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator iter = reporter.getRepositoryMetadataSuccessIterator(); - assertTrue( "check if there is a success", iter.hasNext() ); - } - - /** - * Test the corrupted checksum of a metadata file. - * The reporter must report 2 failures. - */ - public void testChecksumMetadataReporterFailure() - throws ReportProcessorException - { - ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); - VersionRange version = VersionRange.createFromVersion( "1.0" ); - Artifact artifact = - new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler ); - - RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); - metadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator iter = reporter.getRepositoryMetadataFailureIterator(); - assertTrue( "check if there is a failure", iter.hasNext() ); - } - - /** - * Test the checksum of an artifact located in a remote location. - */ - /* public void testChecksumArtifactRemote() - { - ArtifactHandler handler = new DefaultArtifactHandler( remoteArtifactType ); - VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion ); - Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version, remoteArtifactScope, - remoteArtifactType, "", handler ); - ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl, - new DefaultRepositoryLayout() ); - - artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); - if ( reporter.getFailures() == 2 ) - assertTrue( reporter.getFailures() == 2 ); - - if ( reporter.getSuccesses() == 2 ) - assertTrue( reporter.getSuccesses() == 2 ); - - } - */ - - /** - * Test the checksum of a metadata file located in a remote location. - */ - /* public void testChecksumMetadataRemote() - { - - try - { - ArtifactHandler handler = new DefaultArtifactHandler( remoteArtifactType ); - VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion ); - Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version, - remoteArtifactScope, remoteArtifactType, "", handler ); - ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl, - new DefaultRepositoryLayout() ); - - RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); - - metadataReportProcessor.processMetadata( metadata, repository, reporter ); - Iterator iter = reporter.getRepositoryMetadataFailureIterator(); - if ( iter.hasNext() ) - assertTrue( "check if there is a failure", iter.hasNext() ); - - iter = reporter.getRepositoryMetadataSuccessIterator(); - if ( iter.hasNext() ) - assertTrue( "check if there is a success", iter.hasNext() ); - - } - catch ( Exception e ) - { - e.printStackTrace(); - } - } - */ - - /** - * Test the conditional when the checksum files of the artifact & metadata do not exist. - */ - public void testChecksumFilesDoNotExist() - throws ReportProcessorException, DigesterException, IOException - { - createChecksumFile( "VALID" ); - createMetadataFile( "VALID" ); - deleteChecksumFiles( "jar" ); - - ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); - VersionRange version = VersionRange.createFromVersion( "1.0" ); - Artifact artifact = - new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler ); - - artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); - assertEquals( 2, reporter.getFailures() ); - - RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); - metadataReportProcessor.processMetadata( metadata, repository, reporter ); - - Iterator iter = reporter.getRepositoryMetadataFailureIterator(); - assertTrue( "check if there is a failure", iter.hasNext() ); - - deleteTestDirectory( new File( repository.getBasedir() + "checksumTest" ) ); - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java deleted file mode 100644 index ac19ab3e0..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java +++ /dev/null @@ -1,184 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.Versioning; - -import java.util.Iterator; - -/** - * - */ -public class DefaultArtifactReporterTest - extends AbstractRepositoryReportsTestCase -{ - private ArtifactReporter reporter; - - private Artifact artifact; - - private RepositoryMetadata metadata; - - public void testEmptyArtifactReporter() - { - assertEquals( "No failures", 0, reporter.getFailures() ); - assertEquals( "No warnings", 0, reporter.getWarnings() ); - assertEquals( "No successes", 0, reporter.getSuccesses() ); - assertFalse( "No artifact failures", reporter.getArtifactFailureIterator().hasNext() ); - assertFalse( "No artifact warnings", reporter.getArtifactWarningIterator().hasNext() ); - assertFalse( "No artifact successes", reporter.getArtifactSuccessIterator().hasNext() ); - assertFalse( "No metadata failures", reporter.getRepositoryMetadataFailureIterator().hasNext() ); - assertFalse( "No metadata warnings", reporter.getRepositoryMetadataWarningIterator().hasNext() ); - assertFalse( "No metadata successes", reporter.getRepositoryMetadataSuccessIterator().hasNext() ); - } - - public void testMetadataSingleFailure() - { - reporter.addFailure( metadata, "Single Failure Reason" ); - assertEquals( "failures count", 1, reporter.getFailures() ); - assertEquals( "warnings count", 0, reporter.getWarnings() ); - assertEquals( "successes count", 0, reporter.getSuccesses() ); - - Iterator results = reporter.getRepositoryMetadataFailureIterator(); - assertTrue( "must have failures", results.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) results.next(); - assertEquals( "check failure cause", metadata, result.getMetadata() ); - assertEquals( "check failure reason", "Single Failure Reason", result.getReason() ); - assertFalse( "no more failures", results.hasNext() ); - } - - public void testMetadataMultipleFailures() - { - reporter.addFailure( metadata, "First Failure Reason" ); - reporter.addFailure( metadata, "Second Failure Reason" ); - assertEquals( "failures count", 2, reporter.getFailures() ); - assertEquals( "warnings count", 0, reporter.getWarnings() ); - assertEquals( "successes count", 0, reporter.getSuccesses() ); - - Iterator results = reporter.getRepositoryMetadataFailureIterator(); - assertTrue( "must have failures", results.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) results.next(); - assertEquals( "check failure cause", metadata, result.getMetadata() ); - assertEquals( "check failure reason", "First Failure Reason", result.getReason() ); - assertTrue( "must have 2nd failure", results.hasNext() ); - result = (RepositoryMetadataResult) results.next(); - assertEquals( "check failure cause", metadata, result.getMetadata() ); - assertEquals( "check failure reason", "Second Failure Reason", result.getReason() ); - assertFalse( "no more failures", results.hasNext() ); - } - - public void testMetadataSingleWarning() - { - reporter.addWarning( metadata, "Single Warning Message" ); - assertEquals( "failures count", 0, reporter.getFailures() ); - assertEquals( "warnings count", 1, reporter.getWarnings() ); - assertEquals( "successes count", 0, reporter.getSuccesses() ); - - Iterator results = reporter.getRepositoryMetadataWarningIterator(); - assertTrue( "must have failures", results.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) results.next(); - assertEquals( "check failure cause", metadata, result.getMetadata() ); - assertEquals( "check failure reason", "Single Warning Message", result.getReason() ); - assertFalse( "no more failures", results.hasNext() ); - } - - public void testMetadataMultipleWarnings() - { - reporter.addWarning( metadata, "First Warning" ); - reporter.addWarning( metadata, "Second Warning" ); - assertEquals( "failures count", 0, reporter.getFailures() ); - assertEquals( "warnings count", 2, reporter.getWarnings() ); - assertEquals( "successes count", 0, reporter.getSuccesses() ); - - Iterator results = reporter.getRepositoryMetadataWarningIterator(); - assertTrue( "must have warnings", results.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) results.next(); - assertEquals( "check failure cause", metadata, result.getMetadata() ); - assertEquals( "check failure reason", "First Warning", result.getReason() ); - assertTrue( "must have 2nd warning", results.hasNext() ); - result = (RepositoryMetadataResult) results.next(); - assertEquals( "check failure cause", metadata, result.getMetadata() ); - assertEquals( "check failure reason", "Second Warning", result.getReason() ); - assertFalse( "no more failures", results.hasNext() ); - } - - public void testMetadataSingleSuccess() - { - reporter.addSuccess( metadata ); - assertEquals( "failures count", 0, reporter.getFailures() ); - assertEquals( "warnings count", 0, reporter.getWarnings() ); - assertEquals( "successes count", 1, reporter.getSuccesses() ); - - Iterator results = reporter.getRepositoryMetadataSuccessIterator(); - assertTrue( "must have successes", results.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) results.next(); - assertEquals( "check success metadata", metadata, result.getMetadata() ); - assertNull( "check no reason", result.getReason() ); - assertFalse( "no more failures", results.hasNext() ); - } - - public void testMetadataMultipleSuccesses() - { - Versioning versioning = new Versioning(); - versioning.addVersion( "1.0-beta-1" ); - versioning.addVersion( "1.0-beta-2" ); - RepositoryMetadata metadata2 = new ArtifactRepositoryMetadata( artifact, versioning ); - - reporter.addSuccess( metadata ); - reporter.addSuccess( metadata2 ); - assertEquals( "failures count", 0, reporter.getFailures() ); - assertEquals( "warnings count", 0, reporter.getWarnings() ); - assertEquals( "successes count", 2, reporter.getSuccesses() ); - - Iterator results = reporter.getRepositoryMetadataSuccessIterator(); - assertTrue( "must have successes", results.hasNext() ); - RepositoryMetadataResult result = (RepositoryMetadataResult) results.next(); - assertEquals( "check success metadata", metadata, result.getMetadata() ); - assertNull( "check no reason", result.getReason() ); - assertTrue( "must have 2nd success", results.hasNext() ); - result = (RepositoryMetadataResult) results.next(); - assertEquals( "check success metadata", metadata2, result.getMetadata() ); - assertNull( "check no reason", result.getReason() ); - assertFalse( "no more successes", results.hasNext() ); - } - - protected void setUp() - throws Exception - { - super.setUp(); - - reporter = new DefaultArtifactReporter(); - ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); - - Versioning versioning = new Versioning(); - versioning.addVersion( "1.0-alpha-1" ); - versioning.addVersion( "1.0-alpha-2" ); - } - - protected void tearDown() - throws Exception - { - super.tearDown(); - - reporter = null; - metadata = null; - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java deleted file mode 100644 index 31dec3015..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java +++ /dev/null @@ -1,149 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.model.Model; -import org.apache.maven.repository.indexing.RepositoryArtifactIndex; -import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; -import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory; -import org.codehaus.plexus.util.FileUtils; - -import java.io.File; -import java.util.Collections; - -/** - * @author Edwin Punzalan - */ -public class DuplicateArtifactFileReportProcessorTest - extends AbstractRepositoryReportsTestCase -{ - private Artifact artifact; - - private Model model; - - private ArtifactReportProcessor processor; - - private ArtifactFactory artifactFactory; - - File indexDirectory; - - protected void setUp() - throws Exception - { - super.setUp(); - - indexDirectory = getTestFile( "target/indexDirectory" ); - FileUtils.deleteDirectory( indexDirectory ); - - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "jar" ); - model = new Model(); - - RepositoryArtifactIndexFactory factory = - (RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" ); - - RepositoryArtifactIndex index = factory.createStandardIndex( indexDirectory ); - - RepositoryIndexRecordFactory recordFactory = - (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "standard" ); - - index.indexRecords( Collections.singletonList( recordFactory.createRecord( artifact ) ) ); - - processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "duplicate" ); - } - - public void testNullArtifactFile() - throws Exception - { - artifact.setFile( null ); - - MockArtifactReporter reporter = new MockArtifactReporter(); - - processor.processArtifact( model, artifact, reporter, repository ); - - assertEquals( "Check no successes", 0, reporter.getSuccesses() ); - assertEquals( "Check warnings", 1, reporter.getWarnings() ); - assertEquals( "Check no failures", 0, reporter.getFailures() ); - } - - public void testSuccessOnAlreadyIndexedArtifact() - throws Exception - { - MockArtifactReporter reporter = new MockArtifactReporter(); - - processor.processArtifact( model, artifact, reporter, repository ); - - assertEquals( "Check no successes", 1, reporter.getSuccesses() ); - assertEquals( "Check warnings", 0, reporter.getWarnings() ); - assertEquals( "Check no failures", 0, reporter.getFailures() ); - } - - public void testSuccessOnDifferentGroupId() - throws Exception - { - MockArtifactReporter reporter = new MockArtifactReporter(); - - artifact.setGroupId( "different.groupId" ); - processor.processArtifact( model, artifact, reporter, repository ); - - assertEquals( "Check no successes", 1, reporter.getSuccesses() ); - assertEquals( "Check warnings", 0, reporter.getWarnings() ); - assertEquals( "Check no failures", 0, reporter.getFailures() ); - } - - public void testSuccessOnNewArtifact() - throws Exception - { - Artifact newArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "pom" ); - - MockArtifactReporter reporter = new MockArtifactReporter(); - - processor.processArtifact( model, newArtifact, reporter, repository ); - - assertEquals( "Check no successes", 1, reporter.getSuccesses() ); - assertEquals( "Check warnings", 0, reporter.getWarnings() ); - assertEquals( "Check no failures", 0, reporter.getFailures() ); - } - - public void testFailure() - throws Exception - { - Artifact duplicate = createArtifact( artifact.getGroupId(), "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", - artifact.getVersion(), artifact.getType() ); - duplicate.setFile( artifact.getFile() ); - - MockArtifactReporter reporter = new MockArtifactReporter(); - - processor.processArtifact( model, duplicate, reporter, repository ); - - assertEquals( "Check no successes", 0, reporter.getSuccesses() ); - assertEquals( "Check warnings", 0, reporter.getWarnings() ); - assertEquals( "Check no failures", 1, reporter.getFailures() ); - } - - private Artifact createArtifact( String groupId, String artifactId, String baseVersion, String version, - String type ) - { - Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, type ); - artifact.setBaseVersion( baseVersion ); - artifact.setRepository( repository ); - artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); - return artifact; - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java deleted file mode 100644 index 7ab3de250..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Edwin Punzalan - */ -public class GenericMockObject - implements InvocationHandler -{ - private Map invocations = new HashMap(); - - public GenericMockObject() - { - //default constructor - } - - public GenericMockObject( Map returnMap ) - { - invocations = new HashMap( returnMap ); - } - - public void setExpectedReturns( Method method, List returnList ) - { - invocations.put( method, returnList ); - } - - public Object invoke( Object proxy, Method method, Object[] args ) - { - if ( !invocations.containsKey( method ) ) - { - throw new UnsupportedOperationException( "No expected return values defined." ); - } - - List returnList = (List) invocations.get( method ); - if ( returnList.size() < 1 ) - { - throw new UnsupportedOperationException( "Too few expected return values defined." ); - } - return returnList.remove( 0 ); - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessorTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessorTest.java deleted file mode 100644 index 71c53d8bd..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessorTest.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.artifact.handler.DefaultArtifactHandler; -import org.apache.maven.artifact.versioning.VersionRange; - -/** - * This class tests the InvalidPomArtifactReportProcessor class. - */ -public class InvalidPomArtifactReportProcessorTest - extends AbstractRepositoryReportsTestCase -{ - private ArtifactReportProcessor artifactReportProcessor; - - private ArtifactReporter reporter = new MockArtifactReporter(); - - public void setUp() - throws Exception - { - super.setUp(); - artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "invalid-pom" ); - } - - /** - * Test the InvalidPomArtifactReportProcessor when the artifact is an invalid pom. - */ - public void testInvalidPomArtifactReportProcessorFailure() - throws ReportProcessorException - { - ArtifactHandler handler = new DefaultArtifactHandler( "pom" ); - VersionRange version = VersionRange.createFromVersion( "1.0-alpha-3" ); - Artifact artifact = - new DefaultArtifact( "org.apache.maven", "artifactId", version, "compile", "pom", "", handler ); - - artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); - assertEquals( 1, reporter.getFailures() ); - } - - - /** - * Test the InvalidPomArtifactReportProcessor when the artifact is a valid pom. - */ - public void testInvalidPomArtifactReportProcessorSuccess() - throws ReportProcessorException - { - ArtifactHandler handler = new DefaultArtifactHandler( "pom" ); - VersionRange version = VersionRange.createFromVersion( "1.0-alpha-2" ); - Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "pom", "", handler ); - - artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); - assertEquals( 1, reporter.getSuccesses() ); - } - - - /** - * Test the InvalidPomArtifactReportProcessor when the artifact is not a pom. - */ - public void testNotAPomArtifactReportProcessorSuccess() - throws ReportProcessorException - { - ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); - VersionRange version = VersionRange.createFromVersion( "1.0-alpha-1" ); - Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler ); - - artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); - assertEquals( 1, reporter.getWarnings() ); - } - - /** - * Test the InvalidPomArtifactReportProcessor when the pom is located in - * a remote repository. - */ - /* public void testRemotePomArtifactReportProcessorSuccess(){ - try{ - ArtifactHandler handler = new DefaultArtifactHandler( "pom" ); - VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion ); - Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version, remoteArtifactScope, - "pom", "", handler ); - ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl, - new DefaultRepositoryLayout() ); - - artifactReportProcessor.processArtifact(null, artifact, reporter, repository); - if(reporter.getSuccesses() == 1) - assertTrue(reporter.getSuccesses() == 1); - - }catch(Exception e){ - - } - } - */ -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessorTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessorTest.java deleted file mode 100644 index d892dd3a6..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessorTest.java +++ /dev/null @@ -1,224 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.artifact.handler.DefaultArtifactHandler; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.model.Model; -import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.Reader; - -/** - * This class tests the LocationArtifactReportProcessor. - */ -public class LocationArtifactReportProcessorTest - extends AbstractRepositoryReportsTestCase -{ - private ArtifactReportProcessor artifactReportProcessor; - - private ArtifactReporter reporter = new MockArtifactReporter(); - - private MavenXpp3Reader pomReader; - - public void setUp() - throws Exception - { - super.setUp(); - artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "artifact-location" ); - pomReader = new MavenXpp3Reader(); - } - - public void tearDown() - throws Exception - { - super.tearDown(); - artifactReportProcessor = null; - pomReader = null; - } - - /** - * Test the LocationArtifactReporter when the artifact's physical location matches the location specified - * both in the file system pom and in the pom included in the package. - */ - public void testPackagedPomLocationArtifactReporterSuccess() - throws ReportProcessorException, IOException, XmlPullParserException - { - ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); - VersionRange version = VersionRange.createFromVersion( "2.0" ); - Artifact artifact = - new DefaultArtifact( "org.apache.maven", "maven-model", version, "compile", "jar", "", handler ); - - String path = "org/apache/maven/maven-model/2.0/maven-model-2.0.pom"; - Model model = readPom( path ); - - artifactReportProcessor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 1, reporter.getSuccesses() ); - } - - /** - * Test the LocationArtifactReporter when the artifact is in the location specified in the - * file system pom (but the jar file does not have a pom included in its package). - */ - public void testLocationArtifactReporterSuccess() - throws ReportProcessorException, IOException, XmlPullParserException - { - ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); - VersionRange version = VersionRange.createFromVersion( "1.0-alpha-1" ); - Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler ); - - String path = "groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom"; - Model model = readPom( path ); - - artifactReportProcessor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 1, reporter.getSuccesses() ); - } - - /** - * Test the LocationArtifactReporter when the artifact is not in the location specified - * in the file system pom. - */ - public void testLocationArtifactReporterFailure() - throws IOException, XmlPullParserException, ReportProcessorException - { - ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); - VersionRange version = VersionRange.createFromVersion( "1.0-alpha-2" ); - Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler ); - - String path = "groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom"; - Model model = readPom( path ); - - artifactReportProcessor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 1, reporter.getFailures() ); - } - - /** - * Test the LocationArtifactReporter when the artifact's physical location does not match the - * location in the file system pom but instead matches the specified location in the packaged pom. - */ - public void testFsPomArtifactMatchFailure() - throws IOException, ReportProcessorException, XmlPullParserException - { - ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); - VersionRange version = VersionRange.createFromVersion( "2.0" ); - Artifact artifact = - new DefaultArtifact( "org.apache.maven", "maven-archiver", version, "compile", "jar", "", handler ); - - String path = "org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom"; - Model model = readPom( path ); - - artifactReportProcessor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 1, reporter.getFailures() ); - } - - private Model readPom( String path ) - throws IOException, XmlPullParserException - { - Reader reader = new FileReader( new File( repository.getBasedir(), path ) ); - Model model = pomReader.read( reader ); - // hokey inheritence to avoid some errors right now - if ( model.getGroupId() == null ) - { - model.setGroupId( model.getParent().getGroupId() ); - } - if ( model.getVersion() == null ) - { - model.setVersion( model.getParent().getVersion() ); - } - return model; - } - - /** - * Test the LocationArtifactReporter when the artifact's physical location does not match the - * location specified in the packaged pom but matches the location specified in the file system pom. - */ - public void testPkgPomArtifactMatchFailure() - throws IOException, XmlPullParserException, ReportProcessorException - { - ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); - VersionRange version = VersionRange.createFromVersion( "2.1" ); - Artifact artifact = - new DefaultArtifact( "org.apache.maven", "maven-monitor", version, "compile", "jar", "", handler ); - - String path = "org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.pom"; - Model model = readPom( path ); - - artifactReportProcessor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 1, reporter.getFailures() ); - } - - /** - * Test the LocationArtifactReporter when the artifact's physical location does not match both the - * location specified in the packaged pom and the location specified in the file system pom. - */ - public void testBothPomArtifactMatchFailure() - throws IOException, XmlPullParserException, ReportProcessorException - { - ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); - VersionRange version = VersionRange.createFromVersion( "2.1" ); - Artifact artifact = - new DefaultArtifact( "org.apache.maven", "maven-project", version, "compile", "jar", "", handler ); - - String path = "org/apache/maven/maven-project/2.1/maven-project-2.1.pom"; - Model model = readPom( path ); - - artifactReportProcessor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 1, reporter.getFailures() ); - } - - /** - * Test the LocationArtifactReportProcessor when the artifact is located in the remote repository. - */ - /* public void testRemoteArtifactReportProcessorFailure() - { - - ArtifactHandler handler = new DefaultArtifactHandler( remoteArtifactType ); - VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion ); - Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version, remoteArtifactScope, - remoteArtifactType, "", handler ); - ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl, - new DefaultRepositoryLayout() ); - try - { - URL url = new URL( remoteRepoUrl + remoteArtifactGroup + "/" + remoteArtifactId + "/" - + remoteArtifactVersion + "/" + remoteArtifactId + "-" + remoteArtifactVersion + ".pom" ); - InputStream is = url.openStream(); - Reader reader = new InputStreamReader( is ); - Model model = pomReader.read( reader ); - - artifactReportProcessor.processArtifact( model, artifact, reporter, repository ); - if ( reporter.getFailures() > 0 ) - assertTrue( reporter.getFailures() == 1 ); - - if ( reporter.getSuccesses() > 0 ) - assertTrue( reporter.getSuccesses() == 1 ); - - } - catch ( Exception e ) - { - e.printStackTrace(); - } - } - */ -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifact.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifact.java deleted file mode 100644 index a9f3cd3f2..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifact.java +++ /dev/null @@ -1,258 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.artifact.metadata.ArtifactMetadata; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.apache.maven.artifact.versioning.OverConstrainedVersionException; -import org.apache.maven.artifact.versioning.VersionRange; - -import java.io.File; -import java.util.Collection; -import java.util.List; - -/** - * @noinspection ReturnOfNull - */ -public class MockArtifact - implements Artifact -{ - private String groupId; - - private String artifactId; - - private String version; - - public String getGroupId() - { - return groupId; - } - - public String getArtifactId() - { - return artifactId; - } - - public String getVersion() - { - return version; - } - - public void setVersion( String s ) - { - version = s; - } - - public String getScope() - { - return null; - } - - public String getType() - { - return null; - } - - public String getClassifier() - { - return null; - } - - public boolean hasClassifier() - { - return false; - } - - public File getFile() - { - return null; - } - - public void setFile( File file ) - { - } - - public String getBaseVersion() - { - return null; - } - - public void setBaseVersion( String s ) - { - } - - public String getId() - { - return null; - } - - public String getDependencyConflictId() - { - return null; - } - - public void addMetadata( ArtifactMetadata artifactMetadata ) - { - } - - public Collection getMetadataList() - { - return null; - } - - public void setRepository( ArtifactRepository artifactRepository ) - { - } - - public ArtifactRepository getRepository() - { - return null; - } - - public void updateVersion( String s, ArtifactRepository artifactRepository ) - { - } - - public String getDownloadUrl() - { - return null; - } - - public void setDownloadUrl( String s ) - { - } - - public ArtifactFilter getDependencyFilter() - { - return null; - } - - public void setDependencyFilter( ArtifactFilter artifactFilter ) - { - } - - public ArtifactHandler getArtifactHandler() - { - return null; - } - - public List getDependencyTrail() - { - return null; - } - - public void setDependencyTrail( List list ) - { - } - - public void setScope( String s ) - { - } - - public VersionRange getVersionRange() - { - return null; - } - - public void setVersionRange( VersionRange versionRange ) - { - } - - public void selectVersion( String s ) - { - } - - public void setGroupId( String s ) - { - groupId = s; - } - - public void setArtifactId( String s ) - { - artifactId = s; - } - - public boolean isSnapshot() - { - return false; - } - - public void setResolved( boolean b ) - { - } - - public boolean isResolved() - { - return false; - } - - public void setResolvedVersion( String s ) - { - } - - public void setArtifactHandler( ArtifactHandler artifactHandler ) - { - } - - public boolean isRelease() - { - return false; - } - - public void setRelease( boolean b ) - { - } - - public List getAvailableVersions() - { - return null; - } - - public void setAvailableVersions( List list ) - { - } - - public boolean isOptional() - { - return false; - } - - public ArtifactVersion getSelectedVersion() - throws OverConstrainedVersionException - { - return null; - } - - public boolean isSelectedVersionKnown() - throws OverConstrainedVersionException - { - return false; - } - - public int compareTo( Object o ) - { - return 0; - } - - public void setOptional( boolean b ) - { - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactFactory.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactFactory.java deleted file mode 100644 index 7bdc708a9..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactFactory.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.versioning.VersionRange; - -/** - * @noinspection ReturnOfNull - */ -public class MockArtifactFactory - implements ArtifactFactory -{ - public Artifact createArtifact( String s, String s1, String s2, String s3, String s4 ) - { - return null; - } - - public Artifact createArtifactWithClassifier( String s, String s1, String s2, String s3, String s4 ) - { - return null; - } - - public Artifact createDependencyArtifact( String s, String s1, VersionRange versionRange, String s2, String s3, - String s4 ) - { - return null; - } - - public Artifact createDependencyArtifact( String s, String s1, VersionRange versionRange, String s2, String s3, - String s4, String s5 ) - { - return null; - } - - public Artifact createDependencyArtifact( String s, String s1, VersionRange versionRange, String s2, String s3, - String s4, String s5, boolean b ) - { - return null; - } - - public Artifact createBuildArtifact( String s, String s1, String s2, String s3 ) - { - return null; - } - - public Artifact createProjectArtifact( String s, String s1, String s2 ) - { - return null; - } - - public Artifact createParentArtifact( String s, String s1, String s2 ) - { - return null; - } - - public Artifact createPluginArtifact( String s, String s1, VersionRange versionRange ) - { - return null; - } - - public Artifact createProjectArtifact( String s, String s1, String s2, String s3 ) - { - return null; - } - - public Artifact createExtensionArtifact( String s, String s1, VersionRange versionRange ) - { - return null; - } - - public Artifact createDependencyArtifact( String string, String string1, VersionRange versionRange, String string2, - String string3, String string4, boolean b ) - { - return null; - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java deleted file mode 100644 index 00bdc23ae..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Model; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -/** - * - */ -public class MockArtifactReportProcessor - implements ArtifactReportProcessor -{ - private List reportConditions; - - private Iterator iterator; - - public MockArtifactReportProcessor() - { - reportConditions = new ArrayList(); - } - - public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, - ArtifactRepository repository ) - { - if ( iterator == null || !iterator.hasNext() ) // not initialized or reached end of the list. start again - { - iterator = reportConditions.iterator(); - } - if ( !reportConditions.isEmpty() ) - { - while ( iterator.hasNext() ) - { - ReportCondition reportCondition = (ReportCondition) iterator.next(); - int i = reportCondition.getResult(); - if ( i == ReportCondition.SUCCESS ) - { - reporter.addSuccess( reportCondition.getArtifact() ); - } - else if ( i == ReportCondition.WARNING ) - { - reporter.addWarning( reportCondition.getArtifact(), reportCondition.getReason() ); - } - else if ( i == ReportCondition.FAILURE ) - { - reporter.addFailure( reportCondition.getArtifact(), reportCondition.getReason() ); - } - } - } - } - - public void addReturnValue( int result, Artifact artifact, String reason ) - { - reportConditions.add( new ReportCondition( result, artifact, reason ) ); - } - - public void clearList() - { - reportConditions.clear(); - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java deleted file mode 100755 index f13e660cf..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java +++ /dev/null @@ -1,121 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -/** - * Mock implementation of the artifact reporter. - * - * @author Brett Porter - * @version $Id$ - */ -public class MockArtifactReporter - implements ArtifactReporter -{ - private List artifactFailures = new ArrayList(); - - private List artifactSuccesses = new ArrayList(); - - private List artifactWarnings = new ArrayList(); - - private List metadataFailures = new ArrayList(); - - private List metadataSuccesses = new ArrayList(); - - private List metadataWarnings = new ArrayList(); - - public void addFailure( Artifact artifact, String reason ) - { - artifactFailures.add( new ArtifactResult( artifact, reason ) ); - } - - public void addSuccess( Artifact artifact ) - { - artifactSuccesses.add( new ArtifactResult( artifact ) ); - } - - public void addWarning( Artifact artifact, String message ) - { - artifactWarnings.add( new ArtifactResult( artifact, message ) ); - } - - public void addFailure( RepositoryMetadata metadata, String reason ) - { - metadataFailures.add( new RepositoryMetadataResult( metadata, reason ) ); - } - - public void addSuccess( RepositoryMetadata metadata ) - { - metadataSuccesses.add( new RepositoryMetadataResult( metadata ) ); - } - - public void addWarning( RepositoryMetadata metadata, String message ) - { - metadataWarnings.add( new RepositoryMetadataResult( metadata, message ) ); - } - - public Iterator getArtifactFailureIterator() - { - return artifactFailures.iterator(); - } - - public Iterator getArtifactSuccessIterator() - { - return artifactSuccesses.iterator(); - } - - public Iterator getArtifactWarningIterator() - { - return artifactWarnings.iterator(); - } - - public Iterator getRepositoryMetadataFailureIterator() - { - return metadataFailures.iterator(); - } - - public Iterator getRepositoryMetadataSuccessIterator() - { - return metadataSuccesses.iterator(); - } - - public Iterator getRepositoryMetadataWarningIterator() - { - return metadataWarnings.iterator(); - } - - public int getFailures() - { - return artifactFailures.size(); - } - - public int getSuccesses() - { - return artifactSuccesses.size(); - } - - public int getWarnings() - { - return artifactWarnings.size(); - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java deleted file mode 100644 index e6ec4eef3..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; -import org.apache.maven.artifact.repository.metadata.Snapshot; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -/** - * - */ -public class MockRepositoryQueryLayer - implements RepositoryQueryLayer -{ - private List queryConditions; - - private Iterator iterator; - - public MockRepositoryQueryLayer() - { - queryConditions = new ArrayList(); - } - - public boolean containsArtifact( Artifact artifact ) - { - if ( iterator == null || !iterator.hasNext() ) // not initialized or reached end of the list. start again - { - iterator = queryConditions.iterator(); - } - boolean b; - if ( queryConditions.isEmpty() ) - { - b = false; - } - else - { - b = ( (Boolean) iterator.next() ).booleanValue(); - } - return b; - } - - public void addReturnValue( boolean queryCondition ) - { - queryConditions.add( Boolean.valueOf( queryCondition ) ); - } - - public void clearList() - { - queryConditions.clear(); - } - - public boolean containsArtifact( Artifact artifact, Snapshot snapshot ) - { - return containsArtifact( artifact ); - } - - public List getVersions( Artifact artifact ) - { - return Collections.EMPTY_LIST; - } -} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java deleted file mode 100644 index 98df89646..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.apache.maven.repository.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.artifact.Artifact; - -/** - * - */ -public class ReportCondition -{ - public static final int SUCCESS = 0; - - public static final int FAILURE = -1; - - public static final int WARNING = 1; - - private int result; - - private Artifact artifact; - - private String reason; - - public ReportCondition( int result, Artifact artifact, String reason ) - { - this.result = result; - this.artifact = artifact; - this.reason = reason; - } - - public int getResult() - { - return result; - } - - public void setResult( int result ) - { - this.result = result; - } - - public Artifact getArtifact() - { - return artifact; - } - - public void setArtifact( Artifact artifact ) - { - this.artifact = artifact; - } - - public String getReason() - { - return reason; - } - - public void setReason( String reason ) - { - this.reason = reason; - } -} diff --git a/maven-repository-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.jar b/maven-repository-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.jar deleted file mode 100644 index c2ea777c1..000000000 Binary files a/maven-repository-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.jar and /dev/null differ diff --git a/maven-repository-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom b/maven-repository-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom deleted file mode 100644 index 24bca8028..000000000 --- a/maven-repository-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 4.0.0 - groupId - artifactId - 1.0-alpha-1 - diff --git a/maven-repository-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom b/maven-repository-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom deleted file mode 100644 index fd07c6f14..000000000 --- a/maven-repository-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom +++ /dev/null @@ -1,6 +0,0 @@ - - 4.0.0 - groupId - artifactId - 1.0-alpha-2 - diff --git a/maven-repository-reports-standard/src/test/repository/groupId/artifactId/maven-metadata.xml b/maven-repository-reports-standard/src/test/repository/groupId/artifactId/maven-metadata.xml deleted file mode 100644 index a8ea6e7e0..000000000 --- a/maven-repository-reports-standard/src/test/repository/groupId/artifactId/maven-metadata.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - groupId - artifactId - 1.0-alpha-1 - - - 1.0-alpha-1 - 1.0-alpha-2 - - - diff --git a/maven-repository-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-20050611.202024-1.pom b/maven-repository-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-20050611.202024-1.pom deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-SNAPSHOT.pom b/maven-repository-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-SNAPSHOT.pom deleted file mode 100644 index e69de29bb..000000000 diff --git a/maven-repository-reports-standard/src/test/repository/groupId/unexpectedfile.xml b/maven-repository-reports-standard/src/test/repository/groupId/unexpectedfile.xml deleted file mode 100644 index 44c9d51ff..000000000 --- a/maven-repository-reports-standard/src/test/repository/groupId/unexpectedfile.xml +++ /dev/null @@ -1,17 +0,0 @@ -This file is here to make sure that it will not be processed during unit - - test. \ No newline at end of file diff --git a/maven-repository-reports-standard/src/test/repository/maven-metadata.xml b/maven-repository-reports-standard/src/test/repository/maven-metadata.xml deleted file mode 100644 index 9efaee38c..000000000 --- a/maven-repository-reports-standard/src/test/repository/maven-metadata.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - checksumTest - invalidArtifact - 1.0 - diff --git a/maven-repository-reports-standard/src/test/repository/org/apache/maven/artifactId/1.0-alpha-3/artifactId-1.0-alpha-3.pom b/maven-repository-reports-standard/src/test/repository/org/apache/maven/artifactId/1.0-alpha-3/artifactId-1.0-alpha-3.pom deleted file mode 100644 index 31d626277..000000000 --- a/maven-repository-reports-standard/src/test/repository/org/apache/maven/artifactId/1.0-alpha-3/artifactId-1.0-alpha-3.pom +++ /dev/null @@ -1,9 +0,0 @@ - - 4.0.0 - org.apache.maven - artifactId - 1.0-alpha-3 - - - - diff --git a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.jar b/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.jar deleted file mode 100644 index 2acfe605d..000000000 Binary files a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.jar and /dev/null differ diff --git a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom b/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom deleted file mode 100644 index e5cbe38fd..000000000 --- a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom +++ /dev/null @@ -1,31 +0,0 @@ - - - maven - org.apache.maven - 2.1 - - 4.0.0 - maven-archiver - Maven Archiver - 2.1 - - - org.apache.maven - maven-project - 2.0 - - - org.codehaus.plexus - plexus-archiver - 1.0-alpha-3 - - - org.apache.maven - maven-artifact - 2.0 - - - - deployed - - diff --git a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/note.txt b/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/note.txt deleted file mode 100644 index bc218ba95..000000000 --- a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/note.txt +++ /dev/null @@ -1,4 +0,0 @@ -- The artifact location does not match the location specified in the file system, but - matches the location specified in the pom included in the package. -- The groupId, artifactId and version of the pom in the file system does not match - the groupId, artifactId and version of the pom included in the package. diff --git a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar b/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar deleted file mode 100644 index d6820d6fe..000000000 Binary files a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar and /dev/null differ diff --git a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom b/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom deleted file mode 100644 index 17bc67891..000000000 --- a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom +++ /dev/null @@ -1,86 +0,0 @@ - - - maven - org.apache.maven - 2.0 - - 4.0.0 - org.apache.maven - maven-model - Maven Model - 2.0 - Maven Model - - - - org.codehaus.modello - modello-maven-plugin - - - - xpp3-writer - java - xpp3-reader - xsd - - - - - 4.0.0 - maven.mdo - - - - - - - all-models - - - - org.codehaus.modello - modello-maven-plugin - - - v3 - - xpp3-writer - java - xpp3-reader - xsd - - - 3.0.0 - true - - - - - - maven-jar-plugin - - - package - - jar - - - all - - - - - - - - - - - org.codehaus.plexus - plexus-utils - - - - deployed - - diff --git a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/note.txt b/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/note.txt deleted file mode 100644 index 13b46ec93..000000000 --- a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/note.txt +++ /dev/null @@ -1,3 +0,0 @@ -- The artifact is located in the proper location. -- The groupId, artifactId and version of the pom in the file system matches - the groupId, artifactId and version of the pom included in the package. diff --git a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.jar b/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.jar deleted file mode 100644 index c499d94ff..000000000 Binary files a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.jar and /dev/null differ diff --git a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.pom b/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.pom deleted file mode 100644 index 44ba7ed4e..000000000 --- a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.pom +++ /dev/null @@ -1,15 +0,0 @@ - - - maven - org.apache.maven - 2.1 - - 4.0.0 - org.apache.maven - maven-monitor - Maven Monitor - 2.1 - - deployed - - diff --git a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/note.txt b/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/note.txt deleted file mode 100644 index 796d100b0..000000000 --- a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/note.txt +++ /dev/null @@ -1,4 +0,0 @@ -- The artifact location matches the location specified in the file system, but - does not match the location specified in the pom included in the package. -- The groupId, artifactId and version of the pom in the file system does not match - the groupId, artifactId and version of the pom included in the package. diff --git a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.jar b/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.jar deleted file mode 100644 index efeb8d456..000000000 Binary files a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.jar and /dev/null differ diff --git a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.pom b/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.pom deleted file mode 100644 index 8993ed385..000000000 --- a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.pom +++ /dev/null @@ -1,52 +0,0 @@ - - - maven - org.apache.maven - 2.0 - - 4.0.0 - maven-project - Maven Project Builder - 2.0 - This library is used to not only read Maven project object model files, but to assemble inheritence - and to retrieve remote models as required. - - - org.apache.maven - maven-artifact-test - 2.0 - test - - - org.apache.maven - maven-profile - 2.0 - - - org.apache.maven - maven-model - 2.0 - - - org.apache.maven - maven-artifact-manager - 2.0 - - - org.codehaus.plexus - plexus-utils - - - org.apache.maven - maven-artifact - 2.0 - - - org.codehaus.plexus - plexus-container-default - - - - deployed - - diff --git a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/note.txt b/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/note.txt deleted file mode 100644 index 38aefadac..000000000 --- a/maven-repository-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/note.txt +++ /dev/null @@ -1,4 +0,0 @@ -- The artifact location does not match both the location specified in the file system pom - and in the pom included in the package. -- The groupId, artifactId and version of the pom in the file system does not match - the groupId, artifactId and version of the pom included in the package. diff --git a/maven-repository-reports-standard/src/test/resources/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.xml b/maven-repository-reports-standard/src/test/resources/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.xml deleted file mode 100644 index d8b910c2e..000000000 --- a/maven-repository-reports-standard/src/test/resources/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - org.apache.maven.repository.reporting.ArtifactReportProcessor - duplicate - org.apache.maven.repository.reporting.DuplicateArtifactFileReportProcessor - - - org.apache.maven.repository.digest.Digester - md5 - - - org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory - - - - ${basedir}/target/indexDirectory - - - - \ No newline at end of file diff --git a/maven-repository-utils/pom.xml b/maven-repository-utils/pom.xml deleted file mode 100644 index 7c211a127..000000000 --- a/maven-repository-utils/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - org.apache.maven.repository - maven-repository-manager - 1.0-SNAPSHOT - - 4.0.0 - maven-repository-utils - Maven Repository Utilities - - - org.codehaus.plexus - plexus-container-default - test - - - org.codehaus.plexus - plexus-utils - - - org.apache.maven - maven-artifact - - - diff --git a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/AbstractDigester.java b/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/AbstractDigester.java deleted file mode 100644 index c4c8cc7b1..000000000 --- a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/AbstractDigester.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.apache.maven.repository.digest; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.util.IOUtil; -import org.codehaus.plexus.util.StringUtils; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.security.NoSuchAlgorithmException; - -/** - * Create a digest for a file. - * - * @author Brett Porter - */ -public abstract class AbstractDigester - implements Digester -{ - private final StreamingDigester streamingDigester; - - protected AbstractDigester( StreamingDigester streamingDigester ) - throws NoSuchAlgorithmException - { - this.streamingDigester = streamingDigester; - } - - public String getAlgorithm() - { - return streamingDigester.getAlgorithm(); - } - - public String calc( File file ) - throws DigesterException - { - FileInputStream fis = null; - try - { - fis = new FileInputStream( file ); - streamingDigester.reset(); - streamingDigester.update( fis ); - return streamingDigester.calc(); - } - catch ( IOException e ) - { - throw new DigesterException( "Unable to calculate the " + streamingDigester.getAlgorithm() + - " hashcode for " + file.getAbsolutePath() + ": " + e.getMessage(), e ); - } - finally - { - IOUtil.close( fis ); - } - } - - public void verify( File file, String checksum ) - throws DigesterException - { - String trimmedChecksum = - DigestUtils.cleanChecksum( checksum, streamingDigester.getAlgorithm(), file.getName() ); - - //Create checksum for jar file - String sum = calc( file ); - if ( !StringUtils.equalsIgnoreCase( trimmedChecksum, sum ) ) - { - throw new DigesterException( "Checksum failed" ); - } - } - - public String toString() - { - return "[Digester:" + streamingDigester.getAlgorithm() + "]"; - } -} diff --git a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/AbstractStreamingDigester.java b/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/AbstractStreamingDigester.java deleted file mode 100644 index 7d148f657..000000000 --- a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/AbstractStreamingDigester.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.apache.maven.repository.digest; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 java.io.IOException; -import java.io.InputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -/** - * Gradually create a digest for a stream. - * - * @author Brett Porter - */ -public abstract class AbstractStreamingDigester - implements StreamingDigester -{ - protected final MessageDigest md; - - private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray(); - - private static final int HI_MASK = 0xF0; - - private static final int LO_MASK = 0x0F; - - private static final int BUFFER_SIZE = 32768; - - protected AbstractStreamingDigester( String algorithm ) - throws NoSuchAlgorithmException - { - md = MessageDigest.getInstance( algorithm ); - } - - public String getAlgorithm() - { - return md.getAlgorithm(); - } - - public String calc() - throws DigesterException - { - return calc( this.md ); - } - - public void reset() - throws DigesterException - { - md.reset(); - } - - public void update( InputStream is ) - throws DigesterException - { - update( is, md ); - } - - protected static String calc( MessageDigest md ) - { - byte[] digest = md.digest(); - - char[] hash = new char[digest.length * 2]; - for ( int i = 0; i < digest.length; i++ ) - { - hash[i * 2] = HEX_CHARS[( digest[i] & HI_MASK ) >> 4]; - hash[i * 2 + 1] = HEX_CHARS[( digest[i] & LO_MASK )]; - } - return new String( hash ); - } - - protected static void update( InputStream is, MessageDigest digest ) - throws DigesterException - { - try - { - byte[] buffer = new byte[BUFFER_SIZE]; - int size = is.read( buffer, 0, BUFFER_SIZE ); - while ( size >= 0 ) - { - digest.update( buffer, 0, size ); - size = is.read( buffer, 0, BUFFER_SIZE ); - } - } - catch ( IOException e ) - { - throw new DigesterException( "Unable to update " + digest.getAlgorithm() + " hash: " + e.getMessage(), e ); - } - } -} diff --git a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/DigestUtils.java b/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/DigestUtils.java deleted file mode 100644 index 8bc76b8d2..000000000 --- a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/DigestUtils.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.apache.maven.repository.digest; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Parse files from checksum file formats. - * - * @author Brett Porter - */ -public class DigestUtils -{ - private DigestUtils() - { - // don't create this class - } - - public static String cleanChecksum( String checksum, String algorithm, String path ) - throws DigesterException - { - String trimmedChecksum = checksum.replace( '\n', ' ' ).trim(); - - // Free-BSD / openssl - String regex = algorithm.replaceAll( "-", "" ) + "\\s*\\((.*?)\\)\\s*=\\s*([a-fA-F0-9]+)"; - Matcher m = Pattern.compile( regex ).matcher( trimmedChecksum ); - if ( m.matches() ) - { - String filename = m.group( 1 ); - if ( !path.endsWith( filename ) ) - { - throw new DigesterException( "Supplied checksum does not match checksum pattern" ); - } - trimmedChecksum = m.group( 2 ); - } - else - { - // GNU tools - m = Pattern.compile( "([a-fA-F0-9]+)\\s\\*?(.+)" ).matcher( trimmedChecksum ); - if ( m.matches() ) - { - String filename = m.group( 2 ); - if ( !path.endsWith( filename ) ) - { - throw new DigesterException( "Supplied checksum does not match checksum pattern" ); - } - trimmedChecksum = m.group( 1 ); - } - } - return trimmedChecksum; - } -} diff --git a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/Digester.java b/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/Digester.java deleted file mode 100644 index 70fb8f6ee..000000000 --- a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/Digester.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.apache.maven.repository.digest; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 java.io.File; -import java.io.InputStream; - -/** - * Create a digest for a file. - * - * @author Brett Porter - */ -public interface Digester -{ - String ROLE = Digester.class.getName(); - - /** - * Get the algorithm used for the checksum. - * - * @return the algorithm - */ - String getAlgorithm(); - - /** - * Calculate a checksum for a file. - * - * @param file the file to calculate the checksum for - * @return the current checksum. - * @throws DigesterException if there was a problem computing the hashcode. - */ - String calc( File file ) - throws DigesterException; - - /** - * Verify that a checksum is correct. - * - * @param file the file to compute the checksum for - * @param checksum the checksum to compare to - * @throws DigesterException if there was a problem computing the hashcode. - */ - void verify( File file, String checksum ) - throws DigesterException; -} diff --git a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/DigesterException.java b/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/DigesterException.java deleted file mode 100644 index 789957b84..000000000 --- a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/DigesterException.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.maven.repository.digest; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -/** - * @author Edwin Punzalan - */ -public class DigesterException - extends Exception -{ - public DigesterException( String message ) - { - super( message ); - } - - public DigesterException( String message, Throwable cause ) - { - super( message, cause ); - } -} diff --git a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/Md5Digester.java b/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/Md5Digester.java deleted file mode 100644 index 3ac6a04b2..000000000 --- a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/Md5Digester.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.maven.repository.digest; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 java.security.NoSuchAlgorithmException; - -/** - * Digester that does MD5 Message Digesting Only. - * - * @plexus.component role="org.apache.maven.repository.digest.Digester" role-hint="md5" - */ -public class Md5Digester - extends AbstractDigester -{ - public Md5Digester() - throws NoSuchAlgorithmException - { - super( new StreamingMd5Digester() ); - } -} diff --git a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/Sha1Digester.java b/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/Sha1Digester.java deleted file mode 100644 index f0383a0c1..000000000 --- a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/Sha1Digester.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.maven.repository.digest; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 java.security.NoSuchAlgorithmException; - -/** - * Digester that does SHA1 Message Digesting Only. - * - * @plexus.component role="org.apache.maven.repository.digest.Digester" role-hint="sha1" - */ -public class Sha1Digester - extends AbstractDigester -{ - public Sha1Digester() - throws NoSuchAlgorithmException - { - super( new StreamingSha1Digester() ); - } -} diff --git a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/StreamingDigester.java b/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/StreamingDigester.java deleted file mode 100644 index ec0c5a4b7..000000000 --- a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/StreamingDigester.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.apache.maven.repository.digest; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 java.io.InputStream; - -/** - * Gradually create a digest for a stream. - * - * @author Brett Porter - */ -public interface StreamingDigester -{ - String ROLE = StreamingDigester.class.getName(); - - /** - * Get the algorithm used for the checksum. - * - * @return the algorithm - */ - String getAlgorithm(); - - /** - * Reset the hashcode calculation algorithm. - * Only useful when performing incremental hashcodes based on repeated use of {@link #update(InputStream)} - * - * @throws DigesterException if there was a problem with the internal message digest - */ - void reset() - throws DigesterException; - - /** - * Calculate the current checksum. - * - * @return the current checksum. - * @throws DigesterException if there was a problem computing the hashcode. - */ - String calc() - throws DigesterException; - - /** - * Update the checksum with the content of the input stream. - * - * @param is the input stream - * @throws DigesterException if there was a problem computing the hashcode. - */ - void update( InputStream is ) - throws DigesterException; - -} diff --git a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/StreamingMd5Digester.java b/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/StreamingMd5Digester.java deleted file mode 100644 index 2fc11e45c..000000000 --- a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/StreamingMd5Digester.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apache.maven.repository.digest; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 java.security.NoSuchAlgorithmException; - -/** - * An MD5 implementation of the streaming digester. - * - * @author Brett Porter - * @plexus.component role="org.apache.maven.repository.digest.StreamingDigester" role-hint="md5" - */ -public class StreamingMd5Digester - extends AbstractStreamingDigester -{ - public StreamingMd5Digester() - throws NoSuchAlgorithmException - { - super( "MD5" ); - } -} diff --git a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/StreamingSha1Digester.java b/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/StreamingSha1Digester.java deleted file mode 100644 index 845989eca..000000000 --- a/maven-repository-utils/src/main/java/org/apache/maven/repository/digest/StreamingSha1Digester.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apache.maven.repository.digest; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 java.security.NoSuchAlgorithmException; - -/** - * An SHA-1 implementation of the streaming digester. - * - * @author Brett Porter - * @plexus.component role="org.apache.maven.repository.digest.StreamingDigester" role-hint="sha1" - */ -public class StreamingSha1Digester - extends AbstractStreamingDigester -{ - public StreamingSha1Digester() - throws NoSuchAlgorithmException - { - super( "SHA-1" ); - } -} diff --git a/maven-repository-utils/src/test/java/org/apache/maven/repository/digest/DigesterTest.java b/maven-repository-utils/src/test/java/org/apache/maven/repository/digest/DigesterTest.java deleted file mode 100644 index 97477d142..000000000 --- a/maven-repository-utils/src/test/java/org/apache/maven/repository/digest/DigesterTest.java +++ /dev/null @@ -1,229 +0,0 @@ -package org.apache.maven.repository.digest; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.PlexusTestCase; - -import java.io.File; -import java.io.IOException; -import java.security.NoSuchAlgorithmException; - -/** - * Test the digester. - * - * @author Brett Porter - */ -public class DigesterTest - extends PlexusTestCase -{ - private static final String MD5 = "adbc688ce77fa2aece4bb72cad9f98ba"; - - private static final String SHA1 = "2a7b459938e12a2dc35d1bf6cff35e9c2b592fa9"; - - private static final String WRONG_SHA1 = "4d8703779816556cdb8be7f6bb5c954f4b5730e2"; - - private Digester sha1Digest; - - private Digester md5Digest; - - protected void setUp() - throws Exception - { - super.setUp(); - - sha1Digest = (Digester) lookup( Digester.ROLE, "sha1" ); - md5Digest = (Digester) lookup( Digester.ROLE, "md5" ); - } - - public void testAlgorithm() - { - assertEquals( "SHA-1", sha1Digest.getAlgorithm() ); - assertEquals( "MD5", md5Digest.getAlgorithm() ); - } - - public void testBareDigestFormat() - throws DigesterException, IOException - { - File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); - - try - { - md5Digest.verify( file, MD5 ); - } - catch ( DigesterException e ) - { - fail( "Bare format MD5 must not throw exception" ); - } - - try - { - sha1Digest.verify( file, SHA1 ); - } - catch ( DigesterException e ) - { - fail( "Bare format SHA1 must not throw exception" ); - } - - try - { - sha1Digest.verify( file, WRONG_SHA1 ); - fail( "wrong checksum must throw an exception" ); - } - catch ( DigesterException e ) - { - //expected - } - } - - public void testOpensslDigestFormat() - throws IOException, DigesterException - { - File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); - - try - { - md5Digest.verify( file, "MD5(test-file.txt)= " + MD5 ); - } - catch ( DigesterException e ) - { - fail( "OpenSSL MD5 format must not cause exception" ); - } - - try - { - md5Digest.verify( file, "MD5 (test-file.txt) = " + MD5 ); - } - catch ( DigesterException e ) - { - fail( "FreeBSD MD5 format must not cause exception" ); - } - - try - { - sha1Digest.verify( file, "SHA1(test-file.txt)= " + SHA1 ); - } - catch ( DigesterException e ) - { - fail( "OpenSSL SHA1 format must not cause exception" ); - } - - try - { - sha1Digest.verify( file, "SHA1 (test-file.txt) = " + SHA1 ); - } - catch ( DigesterException e ) - { - fail( "FreeBSD SHA1 format must not cause exception" ); - } - - try - { - sha1Digest.verify( file, "SHA1 (FOO) = " + SHA1 ); - fail( "Wrong filename should cause an exception" ); - } - catch ( DigesterException e ) - { - //expected - } - - try - { - sha1Digest.verify( file, "SHA1 (test-file.txt) = " + WRONG_SHA1 ); - fail( "Wrong sha1 should cause an exception" ); - } - catch ( DigesterException e ) - { - //expected - } - } - - public void testGnuDigestFormat() - throws NoSuchAlgorithmException, IOException, DigesterException - { - File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); - - try - { - md5Digest.verify( file, MD5 + " *test-file.txt" ); - } - catch ( DigesterException e ) - { - fail( "GNU format MD5 must not cause exception" ); - } - - try - { - md5Digest.verify( file, MD5 + " test-file.txt" ); - } - catch ( DigesterException e ) - { - fail( "GNU text format MD5 must not cause exception" ); - } - - try - { - sha1Digest.verify( file, SHA1 + " *test-file.txt" ); - } - catch ( DigesterException e ) - { - fail( "GNU format SHA1 must not cause exception" ); - } - - try - { - sha1Digest.verify( file, SHA1 + " test-file.txt" ); - } - catch ( DigesterException e ) - { - fail( "GNU text format SHA1 must not cause exception" ); - } - - try - { - sha1Digest.verify( file, SHA1 + " FOO" ); - fail( "Wrong filename cause an exception" ); - } - catch ( DigesterException e ) - { - //expected - } - - try - { - sha1Digest.verify( file, WRONG_SHA1 + " test-file.txt" ); - fail( "Wrong SHA1 cause an exception" ); - } - catch ( DigesterException e ) - { - //expected - } - } - - public void testUntrimmedContent() - throws NoSuchAlgorithmException, IOException - { - File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); - try - { - sha1Digest.verify( file, SHA1 + " *test-file.txt \n" ); - } - catch ( DigesterException e ) - { - fail( "GNU untrimmed SHA1 must not cause exception" ); - } - } -} diff --git a/maven-repository-utils/src/test/resources/test-file.txt b/maven-repository-utils/src/test/resources/test-file.txt deleted file mode 100644 index ece41df91..000000000 --- a/maven-repository-utils/src/test/resources/test-file.txt +++ /dev/null @@ -1 +0,0 @@ -the quick brown fox, and all that \ No newline at end of file diff --git a/maven-repository-webapp/pom.xml b/maven-repository-webapp/pom.xml deleted file mode 100644 index 1201eeb7b..000000000 --- a/maven-repository-webapp/pom.xml +++ /dev/null @@ -1,182 +0,0 @@ - - - - 4.0.0 - - org.apache.maven.repository - maven-repository-manager - 1.0-SNAPSHOT - - maven-repository-webapp - war - Maven Repository Manager Web Application - - - javax.servlet - servlet-api - 2.4 - provided - - - opensymphony - sitemesh - 2.2.1 - - - taglibs - standard - 1.1.2 - - - jstl - jstl - 1.1.2 - - - org.codehaus.plexus - plexus-xwork-integration - 1.0-alpha-2-SNAPSHOT - - - org.codehaus.plexus - plexus-log4j-logging - 1.1-alpha-2 - - - org.apache.maven.wagon - wagon-http-lightweight - 1.0-beta-1 - runtime - - - org.apache.maven.wagon - wagon-file - 1.0-beta-1 - runtime - - - org.codehaus.plexus - plexus-container-default - 1.0-alpha-10-SNAPSHOT - - - org.apache.maven.repository - maven-repository-indexer - - - org.apache.maven.repository - maven-repository-discovery - - - org.apache.maven.repository - maven-repository-configuration - - - org.apache.maven.repository - maven-repository-proxy - - - org.apache.maven.repository - maven-repository-core - - - org.apache.maven.repository - maven-repository-artifact-applet - - provided - - - org.apache.maven - maven-project - - - - maven-repository-webapp - - - org.mortbay.jetty - maven-jetty-plugin - - 10 - / - - - 9000 - 60000 - - - - - - org.codehaus.mojo - dependency-maven-plugin - - - copy - process-resources - - copy - - - - - ${project.groupId} - maven-repository-artifact-applet - ${project.version} - src/main/webapp - maven-repository-artifact-applet.jar - - - - - - - - org.codehaus.plexus - plexus-maven-plugin - - - - com.opensymphony.xwork.Action - per-lookup - - - - - - org.codehaus.mojo - cobertura-maven-plugin - - - - - **/** - - - - - - - - - - codehaus.snapshots - http://snapshots.repository.codehaus.org - - - diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java deleted file mode 100644 index ad7e9cbb5..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java +++ /dev/null @@ -1,353 +0,0 @@ -package org.apache.maven.repository.manager.web.action; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 com.opensymphony.xwork.ActionSupport; -import org.apache.lucene.index.Term; -import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.TermQuery; -import org.apache.maven.repository.configuration.Configuration; -import org.apache.maven.repository.configuration.ConfigurationStore; -import org.apache.maven.repository.configuration.ConfigurationStoreException; -import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; -import org.apache.maven.repository.indexing.RepositoryArtifactIndex; -import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; -import org.apache.maven.repository.indexing.RepositoryIndexException; -import org.apache.maven.repository.indexing.RepositoryIndexSearchException; -import org.apache.maven.repository.indexing.lucene.LuceneQuery; -import org.apache.maven.repository.indexing.record.StandardArtifactIndexRecord; -import org.apache.maven.repository.indexing.record.StandardIndexRecordFields; -import org.codehaus.plexus.util.StringUtils; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.TreeMap; -import java.util.TreeSet; - -/** - * Browse the repository. - * - * @todo the tree part probably belongs in a browsing component, and the indexer could optimize how it retrieves the terms rather than querying everything - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="browseAction" - */ -public class BrowseAction - extends ActionSupport -{ - /** - * @plexus.requirement - */ - private RepositoryArtifactIndexFactory factory; - - /** - * @plexus.requirement - */ - private ConfiguredRepositoryFactory repositoryFactory; - - /** - * @plexus.requirement - */ - private ConfigurationStore configurationStore; - - private List groups; - - private String groupId; - - private static final String GROUP_SEPARATOR = "."; - - private List artifactIds; - - private String artifactId; - - private List versions; - - public String browse() - throws ConfigurationStoreException, RepositoryIndexException, IOException, RepositoryIndexSearchException - { - RepositoryArtifactIndex index = getIndex(); - - if ( !index.exists() ) - { - addActionError( "The repository is not yet indexed. Please wait, and then try again." ); - return ERROR; - } - - GroupTreeNode rootNode = buildGroupTree( index ); - - this.groups = collateGroups( rootNode ); - - return SUCCESS; - } - - public String browseGroup() - throws ConfigurationStoreException, RepositoryIndexException, IOException, RepositoryIndexSearchException - { - RepositoryArtifactIndex index = getIndex(); - - if ( !index.exists() ) - { - addActionError( "The repository is not yet indexed. Please wait, and then try again." ); - return ERROR; - } - - GroupTreeNode rootNode = buildGroupTree( index ); - - if ( StringUtils.isEmpty( groupId ) ) - { - // TODO: i18n - addActionError( "You must specify a group ID to browse" ); - return ERROR; - } - - StringTokenizer tok = new StringTokenizer( groupId, GROUP_SEPARATOR ); - while ( tok.hasMoreTokens() ) - { - String part = tok.nextToken(); - - if ( !rootNode.getChildren().containsKey( part ) ) - { - // TODO: i18n - addActionError( "The group specified was not found" ); - return ERROR; - } - else - { - rootNode = (GroupTreeNode) rootNode.getChildren().get( part ); - } - } - - this.groups = collateGroups( rootNode ); - - List records = index.search( - new LuceneQuery( new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, groupId ) ) ) ); - - Set artifactIds = new HashSet(); - for ( Iterator i = records.iterator(); i.hasNext(); ) - { - StandardArtifactIndexRecord record = (StandardArtifactIndexRecord) i.next(); - artifactIds.add( record.getArtifactId() ); - } - this.artifactIds = new ArrayList( artifactIds ); - Collections.sort( this.artifactIds ); - - return SUCCESS; - } - - public String browseArtifact() - throws ConfigurationStoreException, RepositoryIndexException, IOException, RepositoryIndexSearchException - { - RepositoryArtifactIndex index = getIndex(); - - if ( StringUtils.isEmpty( groupId ) ) - { - // TODO: i18n - addActionError( "You must specify a group ID to browse" ); - return ERROR; - } - - if ( StringUtils.isEmpty( artifactId ) ) - { - // TODO: i18n - addActionError( "You must specify a artifact ID to browse" ); - return ERROR; - } - - BooleanQuery query = new BooleanQuery(); - query.add( new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, groupId ) ), - BooleanClause.Occur.MUST ); - query.add( new TermQuery( new Term( StandardIndexRecordFields.ARTIFACTID_EXACT, artifactId ) ), - BooleanClause.Occur.MUST ); - - List records = index.search( new LuceneQuery( query ) ); - - if ( records.isEmpty() ) - { - // TODO: i18n - addActionError( "Could not find any artifacts with the given group and artifact ID" ); - return ERROR; - } - - Set versions = new HashSet(); - for ( Iterator i = records.iterator(); i.hasNext(); ) - { - StandardArtifactIndexRecord record = (StandardArtifactIndexRecord) i.next(); - versions.add( record.getVersion() ); - } - - this.versions = new ArrayList( versions ); - Collections.sort( this.versions ); - - return SUCCESS; - } - - private GroupTreeNode buildGroupTree( RepositoryArtifactIndex index ) - throws IOException, RepositoryIndexSearchException - { - // TODO: give action message if indexing is in progress - - // TODO: this will be inefficient over a very large number of artifacts, should be cached - - List records = index.search( new LuceneQuery( new MatchAllDocsQuery() ) ); - - Set groups = new TreeSet(); - for ( Iterator i = records.iterator(); i.hasNext(); ) - { - StandardArtifactIndexRecord record = (StandardArtifactIndexRecord) i.next(); - groups.add( record.getGroupId() ); - } - - GroupTreeNode rootNode = new GroupTreeNode(); - - // build a tree structure - for ( Iterator i = groups.iterator(); i.hasNext(); ) - { - String groupId = (String) i.next(); - - StringTokenizer tok = new StringTokenizer( groupId, GROUP_SEPARATOR ); - - GroupTreeNode node = rootNode; - - while ( tok.hasMoreTokens() ) - { - String part = tok.nextToken(); - - if ( !node.getChildren().containsKey( part ) ) - { - GroupTreeNode newNode = new GroupTreeNode( part, node ); - node.addChild( newNode ); - node = newNode; - } - else - { - node = (GroupTreeNode) node.getChildren().get( part ); - } - } - } - return rootNode; - } - - private List collateGroups( GroupTreeNode rootNode ) - { - List groups = new ArrayList(); - for ( Iterator i = rootNode.getChildren().values().iterator(); i.hasNext(); ) - { - GroupTreeNode node = (GroupTreeNode) i.next(); - - while ( node.getChildren().size() == 1 ) - { - node = (GroupTreeNode) node.getChildren().values().iterator().next(); - } - - groups.add( node.getFullName() ); - } - return groups; - } - - private RepositoryArtifactIndex getIndex() - throws ConfigurationStoreException, RepositoryIndexException - { - Configuration configuration = configurationStore.getConfigurationFromStore(); - File indexPath = new File( configuration.getIndexPath() ); - - return factory.createStandardIndex( indexPath ); - } - - public List getGroups() - { - return groups; - } - - public List getArtifactIds() - { - return artifactIds; - } - - public String getGroupId() - { - return groupId; - } - - public void setGroupId( String groupId ) - { - this.groupId = groupId; - } - - public String getArtifactId() - { - return artifactId; - } - - public void setArtifactId( String artifactId ) - { - this.artifactId = artifactId; - } - - public List getVersions() - { - return versions; - } - - private static class GroupTreeNode - { - private final String name; - - private final String fullName; - - private final Map children = new TreeMap(); - - GroupTreeNode() - { - name = null; - fullName = null; - } - - GroupTreeNode( String name, GroupTreeNode parent ) - { - this.name = name; - this.fullName = parent.fullName != null ? parent.fullName + GROUP_SEPARATOR + name : name; - } - - public String getName() - { - return name; - } - - public String getFullName() - { - return fullName; - } - - public Map getChildren() - { - return children; - } - - public void addChild( GroupTreeNode newNode ) - { - children.put( newNode.name, newNode ); - } - } -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ProxyAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ProxyAction.java deleted file mode 100644 index 246463d5d..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ProxyAction.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.apache.maven.repository.manager.web.action; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 com.opensymphony.xwork.ActionSupport; -import org.apache.maven.repository.proxy.ProxyException; -import org.apache.maven.repository.proxy.ProxyManager; -import org.apache.maven.wagon.ResourceDoesNotExistException; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; - -/** - * Proxy functionality. - * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="proxyAction" - */ -public class ProxyAction - extends ActionSupport -{ - /** - * @plexus.requirement - */ - private ProxyManager proxyManager; - - private String path; - - private String filename; - - private String contentType; - - private static final String NOT_FOUND = "notFound"; - - private InputStream artifactStream; - - public String execute() - throws ProxyException - { - try - { - File file = proxyManager.get( path ); - - artifactStream = new FileInputStream( file ); - - // TODO: could be better - contentType = "application/octet-stream"; - - filename = file.getName(); - } - catch ( ResourceDoesNotExistException e ) - { - // TODO: set message? - return NOT_FOUND; - } - catch ( FileNotFoundException e ) - { - // TODO: set message? - return NOT_FOUND; - } - - return SUCCESS; - } - - public String getPath() - { - return path; - } - - public void setPath( String path ) - { - this.path = path; - } - - public String getFilename() - { - return filename; - } - - public String getContentType() - { - return contentType; - } - - public InputStream getArtifactStream() - { - return artifactStream; - } -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java deleted file mode 100644 index d17b19349..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java +++ /dev/null @@ -1,181 +0,0 @@ -package org.apache.maven.repository.manager.web.action; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 com.opensymphony.xwork.ActionSupport; -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.index.Term; -import org.apache.lucene.queryParser.MultiFieldQueryParser; -import org.apache.lucene.queryParser.ParseException; -import org.apache.lucene.search.TermQuery; -import org.apache.maven.repository.configuration.Configuration; -import org.apache.maven.repository.configuration.ConfigurationStore; -import org.apache.maven.repository.configuration.ConfigurationStoreException; -import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; -import org.apache.maven.repository.indexing.RepositoryArtifactIndex; -import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory; -import org.apache.maven.repository.indexing.RepositoryIndexException; -import org.apache.maven.repository.indexing.RepositoryIndexSearchException; -import org.apache.maven.repository.indexing.lucene.LuceneQuery; -import org.apache.maven.repository.indexing.record.StandardIndexRecordFields; - -import java.io.File; -import java.net.MalformedURLException; -import java.util.List; - -/** - * Search all indexed fields by the given criteria. - * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="searchAction" - */ -public class SearchAction - extends ActionSupport -{ - /** - * Query string. - */ - private String q; - - /** - * The MD5 to search by. - */ - private String md5; - - /** - * Search results. - */ - private List searchResults; - - /** - * @plexus.requirement - */ - private RepositoryArtifactIndexFactory factory; - - /** - * @plexus.requirement - */ - private ConfiguredRepositoryFactory repositoryFactory; - - /** - * @plexus.requirement - */ - private ConfigurationStore configurationStore; - - private static final String NO_RESULTS = "noResults"; - - private static final String RESULTS = "results"; - - private static final String ARTIFACT = "artifact"; - - public String quickSearch() - throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException, - ConfigurationStoreException, ParseException - { - // TODO: give action message if indexing is in progress - - assert q != null && q.length() != 0; - - RepositoryArtifactIndex index = getIndex(); - - if ( !index.exists() ) - { - addActionError( "The repository is not yet indexed. Please wait, and then try again." ); - return ERROR; - } - - // TODO! this is correct, but ugly - MultiFieldQueryParser parser = new MultiFieldQueryParser( new String[]{StandardIndexRecordFields.GROUPID, - StandardIndexRecordFields.ARTIFACTID, StandardIndexRecordFields.BASE_VERSION, - StandardIndexRecordFields.CLASSIFIER, StandardIndexRecordFields.CLASSES, StandardIndexRecordFields.FILES, - StandardIndexRecordFields.TYPE, StandardIndexRecordFields.PROJECT_NAME, - StandardIndexRecordFields.PROJECT_DESCRIPTION}, new StandardAnalyzer() ); - searchResults = index.search( new LuceneQuery( parser.parse( q ) ) ); - - return SUCCESS; - } - - public String findArtifact() - throws Exception - { - // TODO: give action message if indexing is in progress - - assert md5 != null && md5.length() != 0; - - RepositoryArtifactIndex index = getIndex(); - - if ( !index.exists() ) - { - addActionError( "The repository is not yet indexed. Please wait, and then try again." ); - return ERROR; - } - - searchResults = index.search( - new LuceneQuery( new TermQuery( new Term( StandardIndexRecordFields.MD5, md5.toLowerCase() ) ) ) ); - - if ( searchResults.isEmpty() ) - { - return NO_RESULTS; - } - if ( searchResults.size() == 1 ) - { - return ARTIFACT; - } - else - { - return RESULTS; - } - } - - private RepositoryArtifactIndex getIndex() - throws ConfigurationStoreException, RepositoryIndexException - { - Configuration configuration = configurationStore.getConfigurationFromStore(); - File indexPath = new File( configuration.getIndexPath() ); - - return factory.createStandardIndex( indexPath ); - } - - public String doInput() - { - return INPUT; - } - - public String getQ() - { - return q; - } - - public void setQ( String q ) - { - this.q = q; - } - - public String getMd5() - { - return md5; - } - - public void setMd5( String md5 ) - { - this.md5 = md5; - } - - public List getSearchResults() - { - return searchResults; - } -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ShowArtifactAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ShowArtifactAction.java deleted file mode 100644 index b739f6aa9..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ShowArtifactAction.java +++ /dev/null @@ -1,144 +0,0 @@ -package org.apache.maven.repository.manager.web.action; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 com.opensymphony.xwork.ActionSupport; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Model; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectBuilder; -import org.apache.maven.project.ProjectBuildingException; -import org.apache.maven.repository.configuration.Configuration; -import org.apache.maven.repository.configuration.ConfigurationStore; -import org.apache.maven.repository.configuration.ConfigurationStoreException; -import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.IOException; -import java.util.List; - -/** - * Browse the repository. - * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="showArtifactAction" - */ -public class ShowArtifactAction - extends ActionSupport -{ - /** - * @plexus.requirement - */ - private ArtifactFactory artifactFactory; - - /** - * @plexus.requirement - */ - private ConfiguredRepositoryFactory repositoryFactory; - - /** - * @plexus.requirement - */ - private MavenProjectBuilder projectBuilder; - - /** - * @plexus.requirement - */ - private ConfigurationStore configurationStore; - - private String groupId; - - private String artifactId; - - private String version; - - private Model model; - - public String execute() - throws ConfigurationStoreException, IOException, XmlPullParserException, ProjectBuildingException - { - if ( StringUtils.isEmpty( groupId ) ) - { - // TODO: i18n - addActionError( "You must specify a group ID to browse" ); - return ERROR; - } - - if ( StringUtils.isEmpty( artifactId ) ) - { - // TODO: i18n - addActionError( "You must specify a artifact ID to browse" ); - return ERROR; - } - - if ( StringUtils.isEmpty( version ) ) - { - // TODO: i18n - addActionError( "You must specify a version to browse" ); - return ERROR; - } - - Configuration configuration = configurationStore.getConfigurationFromStore(); - List repositories = repositoryFactory.createRepositories( configuration ); - - Artifact artifact = artifactFactory.createProjectArtifact( groupId, artifactId, version ); - // TODO: maybe we can decouple the assembly parts of the project builder from the repository handling to get rid of the temp repo - ArtifactRepository localRepository = repositoryFactory.createLocalRepository( configuration ); - MavenProject project = projectBuilder.buildFromRepository( artifact, repositories, localRepository ); - - model = project.getModel(); - - return SUCCESS; - } - - public Model getModel() - { - return model; - } - - public String getGroupId() - { - return groupId; - } - - public void setGroupId( String groupId ) - { - this.groupId = groupId; - } - - public String getArtifactId() - { - return artifactId; - } - - public void setArtifactId( String artifactId ) - { - this.artifactId = artifactId; - } - - public String getVersion() - { - return version; - } - - public void setVersion( String version ) - { - this.version = version; - } -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/AbstractConfigureRepositoryAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/AbstractConfigureRepositoryAction.java deleted file mode 100644 index 223136b74..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/AbstractConfigureRepositoryAction.java +++ /dev/null @@ -1,153 +0,0 @@ -package org.apache.maven.repository.manager.web.action.admin; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 com.opensymphony.xwork.ActionSupport; -import com.opensymphony.xwork.ModelDriven; -import com.opensymphony.xwork.Preparable; -import org.apache.maven.repository.configuration.AbstractRepositoryConfiguration; -import org.apache.maven.repository.configuration.Configuration; -import org.apache.maven.repository.configuration.ConfigurationChangeException; -import org.apache.maven.repository.configuration.ConfigurationStore; -import org.apache.maven.repository.configuration.ConfigurationStoreException; -import org.apache.maven.repository.configuration.InvalidConfigurationException; - -import java.io.IOException; - -/** - * Base action for repository configuration actions. - * - * @author Brett Porter - */ -public abstract class AbstractConfigureRepositoryAction - extends ActionSupport - implements ModelDriven, Preparable -{ - /** - * @plexus.requirement - */ - private ConfigurationStore configurationStore; - - /** - * The repository. - */ - private AbstractRepositoryConfiguration repository; - - /** - * The repository ID to lookup when editing a repository. - */ - private String repoId; - - /** - * The previously read configuration. - */ - protected Configuration configuration; - - public String add() - throws IOException, ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException - { - // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded - - AbstractRepositoryConfiguration existingRepository = getRepository( repository.getId() ); - if ( existingRepository != null ) - { - addFieldError( "id", "A repository with that id already exists" ); - return INPUT; - } - - return saveConfiguration(); - } - - public String edit() - throws IOException, ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException - { - // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded - - AbstractRepositoryConfiguration existingRepository = getRepository( repository.getId() ); - removeRepository( existingRepository ); - - return saveConfiguration(); - } - - protected abstract void removeRepository( AbstractRepositoryConfiguration existingRepository ); - - protected abstract AbstractRepositoryConfiguration getRepository( String id ); - - private String saveConfiguration() - throws IOException, ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException - { - addRepository(); - - configurationStore.storeConfiguration( configuration ); - - // TODO: do we need to check if indexing is needed? - - addActionMessage( "Successfully saved configuration" ); - - return SUCCESS; - } - - protected abstract void addRepository() - throws IOException; - - public String input() - { - return INPUT; - } - - public Object getModel() - { - return repository; - } - - protected abstract AbstractRepositoryConfiguration createRepository(); - - public void prepare() - throws ConfigurationStoreException - { - configuration = configurationStore.getConfigurationFromStore(); - - if ( repository == null ) - { - repository = getRepository( repoId ); - } - if ( repository == null ) - { - repository = createRepository(); - } - } - - public String getRepoId() - { - return repoId; - } - - public void setRepoId( String repoId ) - { - this.repoId = repoId; - } - - protected AbstractRepositoryConfiguration getRepository() - { - return repository; - } - - public Configuration getConfiguration() - { - return configuration; - } -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/AbstractDeleteRepositoryAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/AbstractDeleteRepositoryAction.java deleted file mode 100644 index 31244c227..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/AbstractDeleteRepositoryAction.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.apache.maven.repository.manager.web.action.admin; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.repository.configuration.AbstractRepositoryConfiguration; -import org.apache.maven.repository.configuration.Configuration; -import org.apache.maven.repository.configuration.ConfigurationChangeException; -import org.apache.maven.repository.configuration.ConfigurationStore; -import org.apache.maven.repository.configuration.ConfigurationStoreException; -import org.apache.maven.repository.configuration.InvalidConfigurationException; -import org.apache.maven.repository.configuration.RepositoryConfiguration; -import org.codehaus.plexus.xwork.action.PlexusActionSupport; - -import java.io.IOException; - -/** - * Base action for repository removal actions. - * - * @author Brett Porter - */ -public abstract class AbstractDeleteRepositoryAction - extends PlexusActionSupport -{ - /** - * @plexus.requirement - */ - private ConfigurationStore configurationStore; - - /** - * The repository ID to lookup when editing a repository. - */ - protected String repoId; - - /** - * Which operation to select. - */ - private String operation = "unmodified"; - - public String execute() - throws ConfigurationStoreException, IOException, InvalidConfigurationException, ConfigurationChangeException - { - // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded - - if ( "delete-entry".equals( operation ) || "delete-contents".equals( operation ) ) - { - Configuration configuration = configurationStore.getConfigurationFromStore(); - - AbstractRepositoryConfiguration existingRepository = getRepository( configuration ); - if ( existingRepository == null ) - { - addActionError( "A repository with that id does not exist" ); - return ERROR; - } - - // TODO: remove from index too! - - removeRepository( configuration, existingRepository ); - - configurationStore.storeConfiguration( configuration ); - - if ( "delete-contents".equals( operation ) ) - { - removeContents( existingRepository ); - } - } - - return SUCCESS; - } - - protected abstract void removeContents( AbstractRepositoryConfiguration existingRepository ) - throws IOException; - - protected abstract AbstractRepositoryConfiguration getRepository( Configuration configuration ); - - protected abstract void removeRepository( Configuration configuration, - AbstractRepositoryConfiguration existingRepository ); - - public String input() - { - return INPUT; - } - - public String getRepoId() - { - return repoId; - } - - public void setRepoId( String repoId ) - { - this.repoId = repoId; - } - - public String getOperation() - { - return operation; - } - - public void setOperation( String operation ) - { - this.operation = operation; - } -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureAction.java deleted file mode 100644 index 5077365bb..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureAction.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.apache.maven.repository.manager.web.action.admin; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 com.opensymphony.xwork.ActionSupport; -import com.opensymphony.xwork.ModelDriven; -import com.opensymphony.xwork.Preparable; -import org.apache.maven.repository.configuration.Configuration; -import org.apache.maven.repository.configuration.ConfigurationChangeException; -import org.apache.maven.repository.configuration.ConfigurationStore; -import org.apache.maven.repository.configuration.ConfigurationStoreException; -import org.apache.maven.repository.configuration.InvalidConfigurationException; -import org.apache.maven.repository.indexing.RepositoryIndexException; -import org.apache.maven.repository.indexing.RepositoryIndexSearchException; - -import java.io.File; -import java.io.IOException; - -/** - * Configures the application. - * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureAction" - */ -public class ConfigureAction - extends ActionSupport - implements ModelDriven, Preparable -{ - /** - * @plexus.requirement - */ - private ConfigurationStore configurationStore; - - /** - * The configuration. - */ - private Configuration configuration; - - public String execute() - throws IOException, RepositoryIndexException, RepositoryIndexSearchException, ConfigurationStoreException, - InvalidConfigurationException, ConfigurationChangeException - { - // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded - // TODO: if this is changed, do we move the index or recreate it? - - // Normalize the path - File file = new File( configuration.getIndexPath() ); - configuration.setIndexPath( file.getCanonicalPath() ); - if ( !file.exists() ) - { - file.mkdirs(); - // TODO: error handling when this fails, or is not a directory - } - - // Just double checking that our validation routines line up with what is expected in the configuration - assert configuration.isValid(); - - configurationStore.storeConfiguration( configuration ); - - // TODO: if the repository has changed, we need to check if indexing is needed - - addActionMessage( "Successfully saved configuration" ); - - return SUCCESS; - } - - public String input() - { - return INPUT; - } - - public Object getModel() - { - return configuration; - } - - public void prepare() - throws ConfigurationStoreException - { - configuration = configurationStore.getConfigurationFromStore(); - } -} \ No newline at end of file diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureProxiedRepositoryAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureProxiedRepositoryAction.java deleted file mode 100644 index 82607f814..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureProxiedRepositoryAction.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.apache.maven.repository.manager.web.action.admin; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.repository.configuration.AbstractRepositoryConfiguration; -import org.apache.maven.repository.configuration.ProxiedRepositoryConfiguration; - -import java.io.IOException; - -/** - * Configures the application repositories. - * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureProxiedRepositoryAction" - */ -public class ConfigureProxiedRepositoryAction - extends AbstractConfigureRepositoryAction -{ - protected void removeRepository( AbstractRepositoryConfiguration existingRepository ) - { - configuration.removeProxiedRepository( (ProxiedRepositoryConfiguration) existingRepository ); - } - - protected AbstractRepositoryConfiguration getRepository( String id ) - { - return configuration.getProxiedRepositoryById( id ); - } - - protected void addRepository() - throws IOException - { - ProxiedRepositoryConfiguration repository = (ProxiedRepositoryConfiguration) getRepository(); - - configuration.addProxiedRepository( repository ); - } - - protected AbstractRepositoryConfiguration createRepository() - { - return new ProxiedRepositoryConfiguration(); - } -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureRepositoryAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureRepositoryAction.java deleted file mode 100644 index 9c00b52a0..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureRepositoryAction.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.apache.maven.repository.manager.web.action.admin; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.repository.configuration.RepositoryConfiguration; -import org.apache.maven.repository.configuration.AbstractRepositoryConfiguration; - -import java.io.File; -import java.io.IOException; - -/** - * Configures the application repositories. - * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureRepositoryAction" - */ -public class ConfigureRepositoryAction - extends AbstractConfigureRepositoryAction -{ - protected void removeRepository( AbstractRepositoryConfiguration existingRepository ) - { - configuration.removeRepository( (RepositoryConfiguration) existingRepository ); - } - - protected AbstractRepositoryConfiguration getRepository( String id ) - { - return configuration.getRepositoryById( id ); - } - - protected void addRepository() - throws IOException - { - RepositoryConfiguration repository = (RepositoryConfiguration) getRepository(); - - // Normalize the path - File file = new File( repository.getDirectory() ); - repository.setDirectory( file.getCanonicalPath() ); - if ( !file.exists() ) - { - file.mkdirs(); - // TODO: error handling when this fails, or is not a directory - } - - configuration.addRepository( repository ); - } - - protected AbstractRepositoryConfiguration createRepository() - { - RepositoryConfiguration repository = new RepositoryConfiguration(); - repository.setIndexed( false ); - return repository; - } -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction.java deleted file mode 100644 index 7546238bc..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.apache.maven.repository.manager.web.action.admin; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.repository.configuration.AbstractRepositoryConfiguration; -import org.apache.maven.repository.configuration.SyncedRepositoryConfiguration; - -import java.io.IOException; - -/** - * Configures the application repositories. - * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureSyncedRepositoryAction" - */ -public class ConfigureSyncedRepositoryAction - extends AbstractConfigureRepositoryAction -{ - protected void removeRepository( AbstractRepositoryConfiguration existingRepository ) - { - configuration.removeSyncedRepository( (SyncedRepositoryConfiguration) existingRepository ); - } - - protected AbstractRepositoryConfiguration getRepository( String id ) - { - return configuration.getSyncedRepositoryById( id ); - } - - protected void addRepository() - throws IOException - { - SyncedRepositoryConfiguration repository = (SyncedRepositoryConfiguration) getRepository(); - - configuration.addSyncedRepository( repository ); - } - - protected AbstractRepositoryConfiguration createRepository() - { - return new SyncedRepositoryConfiguration(); - } -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteProxiedRepositoryAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteProxiedRepositoryAction.java deleted file mode 100644 index 69a7500fe..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteProxiedRepositoryAction.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.apache.maven.repository.manager.web.action.admin; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.repository.configuration.AbstractRepositoryConfiguration; -import org.apache.maven.repository.configuration.Configuration; -import org.apache.maven.repository.configuration.ProxiedRepositoryConfiguration; -import org.apache.maven.repository.configuration.RepositoryConfiguration; -import org.codehaus.plexus.util.FileUtils; - -import java.io.IOException; - -/** - * Configures the application repositories. - * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="deleteProxiedRepositoryAction" - */ -public class DeleteProxiedRepositoryAction - extends AbstractDeleteRepositoryAction -{ - protected AbstractRepositoryConfiguration getRepository( Configuration configuration ) - { - return configuration.getProxiedRepositoryById( repoId ); - } - - protected void removeRepository( Configuration configuration, AbstractRepositoryConfiguration existingRepository ) - { - configuration.removeProxiedRepository( (ProxiedRepositoryConfiguration) existingRepository ); - } - - protected void removeContents( AbstractRepositoryConfiguration existingRepository ) - throws IOException - { - // TODO! - } -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteRepositoryAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteRepositoryAction.java deleted file mode 100644 index 0823afc61..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteRepositoryAction.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.apache.maven.repository.manager.web.action.admin; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.repository.configuration.AbstractRepositoryConfiguration; -import org.apache.maven.repository.configuration.Configuration; -import org.apache.maven.repository.configuration.RepositoryConfiguration; -import org.codehaus.plexus.util.FileUtils; - -import java.io.IOException; - -/** - * Configures the application repositories. - * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="deleteRepositoryAction" - */ -public class DeleteRepositoryAction - extends AbstractDeleteRepositoryAction -{ - protected AbstractRepositoryConfiguration getRepository( Configuration configuration ) - { - return configuration.getRepositoryById( repoId ); - } - - protected void removeRepository( Configuration configuration, AbstractRepositoryConfiguration existingRepository ) - { - configuration.removeRepository( (RepositoryConfiguration) existingRepository ); - } - - protected void removeContents( AbstractRepositoryConfiguration existingRepository ) - throws IOException - { - RepositoryConfiguration repository = (RepositoryConfiguration) existingRepository; - getLogger().info( "Removing " + repository.getDirectory() ); - FileUtils.deleteDirectory( repository.getDirectory() ); - } -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteSyncedRepositoryAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteSyncedRepositoryAction.java deleted file mode 100644 index f12fe09e3..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/DeleteSyncedRepositoryAction.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.apache.maven.repository.manager.web.action.admin; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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.repository.configuration.AbstractRepositoryConfiguration; -import org.apache.maven.repository.configuration.SyncedRepositoryConfiguration; -import org.apache.maven.repository.configuration.Configuration; - -import java.io.IOException; - -/** - * Configures the application repositories. - * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="deleteSyncedRepositoryAction" - */ -public class DeleteSyncedRepositoryAction - extends AbstractDeleteRepositoryAction -{ - protected AbstractRepositoryConfiguration getRepository( Configuration configuration ) - { - return configuration.getSyncedRepositoryById( repoId ); - } - - protected void removeRepository( Configuration configuration, AbstractRepositoryConfiguration existingRepository ) - { - configuration.removeSyncedRepository( (SyncedRepositoryConfiguration) existingRepository ); - } - - protected void removeContents( AbstractRepositoryConfiguration existingRepository ) - throws IOException - { - // TODO! - } -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/RunIndexerAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/RunIndexerAction.java deleted file mode 100644 index 244346081..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/RunIndexerAction.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.apache.maven.repository.manager.web.action.admin; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 com.opensymphony.xwork.ActionSupport; -import org.apache.maven.repository.scheduler.RepositoryTaskScheduler; -import org.apache.maven.repository.scheduler.TaskExecutionException; - -/** - * Configures the application. - * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="runIndexerAction" - */ -public class RunIndexerAction - extends ActionSupport -{ - /** - * @plexus.requirement - */ - private RepositoryTaskScheduler taskScheduler; - - public String execute() - throws TaskExecutionException - { - taskScheduler.runIndexer(); - - return SUCCESS; - } -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/interceptor/ConfigurationInterceptor.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/interceptor/ConfigurationInterceptor.java deleted file mode 100644 index 388c7222a..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/interceptor/ConfigurationInterceptor.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.apache.maven.repository.manager.web.interceptor; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 com.opensymphony.xwork.ActionInvocation; -import com.opensymphony.xwork.interceptor.Interceptor; -import org.apache.maven.repository.configuration.Configuration; -import org.apache.maven.repository.configuration.ConfigurationStore; -import org.codehaus.plexus.logging.AbstractLogEnabled; - -/** - * An interceptor that makes the application configuration available - * - * @author Brett Porter - * @todo might be a generally useful thing in plexus-xwork-integration - * @plexus.component role="com.opensymphony.xwork.interceptor.Interceptor" role-hint="configurationInterceptor" - */ -public class ConfigurationInterceptor - extends AbstractLogEnabled - implements Interceptor -{ - /** - * @plexus.requirement - */ - private ConfigurationStore configurationStore; - - public String intercept( ActionInvocation actionInvocation ) - throws Exception - { - Configuration configuration = configurationStore.getConfigurationFromStore(); - - if ( !configuration.isValid() ) - { - if ( configuration.getRepositories().isEmpty() ) - { - getLogger().info( "No repositories were configured - forwarding to repository configuration page" ); - return "config-repository-needed"; - } - else - { - getLogger().info( "Configuration is incomplete - forwarding to configuration page" ); - return "config-needed"; - } - } - else - { - return actionInvocation.invoke(); - } - } - - public void destroy() - { - // This space left intentionally blank - } - - public void init() - { - // This space left intentionally blank - } -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java deleted file mode 100644 index ae89c3704..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.apache.maven.repository.manager.web.mapper; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 com.opensymphony.webwork.dispatcher.mapper.ActionMapping; -import com.opensymphony.webwork.dispatcher.mapper.DefaultActionMapper; - -import javax.servlet.http.HttpServletRequest; -import java.util.HashMap; -import java.util.Map; - -/** - * Map alternate URLs to specific actions. Used for the repository browser and the proxy. - * - * @author Brett Porter - */ -public class RepositoryActionMapper - extends DefaultActionMapper -{ - private static final String BROWSE_PREFIX = "/browse/"; - - private static final String PROXY_PREFIX = "/proxy/"; - - public String getUriFromActionMapping( ActionMapping actionMapping ) - { - Map params = actionMapping.getParams(); - if ( "browseGroup".equals( actionMapping.getName() ) ) - { - return BROWSE_PREFIX + params.remove( "groupId" ); - } - else if ( "browseArtifact".equals( actionMapping.getName() ) ) - { - return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ); - } - else if ( "showArtifact".equals( actionMapping.getName() ) ) - { - return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" + - params.remove( "version" ); - } - else if ( "proxy".equals( actionMapping.getName() ) ) - { - return PROXY_PREFIX + params.remove( "path" ); - } - - return super.getUriFromActionMapping( actionMapping ); - } - - public ActionMapping getMapping( HttpServletRequest httpServletRequest ) - { - String path = httpServletRequest.getServletPath(); - if ( path.startsWith( BROWSE_PREFIX ) ) - { - path = path.substring( BROWSE_PREFIX.length() ); - if ( path.length() == 0 ) - { - return new ActionMapping( "browse", "/", "", null ); - } - else - { - String[] parts = path.split( "/" ); - if ( parts.length == 1 ) - { - Map params = new HashMap(); - params.put( "groupId", parts[0] ); - return new ActionMapping( "browseGroup", "/", "", params ); - } - else if ( parts.length == 2 ) - { - Map params = new HashMap(); - params.put( "groupId", parts[0] ); - params.put( "artifactId", parts[1] ); - return new ActionMapping( "browseArtifact", "/", "", params ); - } - else if ( parts.length == 3 ) - { - Map params = new HashMap(); - params.put( "groupId", parts[0] ); - params.put( "artifactId", parts[1] ); - params.put( "version", parts[2] ); - return new ActionMapping( "showArtifact", "/", "", params ); - } - } - } - else if ( path.startsWith( PROXY_PREFIX ) ) - { - // retain the leading / - path = path.substring( PROXY_PREFIX.length() - 1 ); - - Map params = new HashMap(); - params.put( "path", path ); - return new ActionMapping( "proxy", "/", "", params ); - } - - return super.getMapping( httpServletRequest ); - } -} diff --git a/maven-repository-webapp/src/main/resources/META-INF/plexus/application.xml b/maven-repository-webapp/src/main/resources/META-INF/plexus/application.xml deleted file mode 100644 index 89bfd4b7e..000000000 --- a/maven-repository-webapp/src/main/resources/META-INF/plexus/application.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - - - - - org.codehaus.plexus.logging.LoggerManager - org.codehaus.plexus.logging.log4j.Log4JLoggerManager - basic - - - WARN - console - - - console - DEBUG - org.apache.log4j.ConsoleAppender - %d [%t] %-5p %-30c{1} - %m%n - - - - - org.codehaus.plexus.mailsender.MailSender - INFO - - - org.apache.jasper - INFO - - - com.opensymphony.xwork - INFO - - - com.opensymphony.webwork - INFO - - - org.apache.maven - DEBUG - - - - - - - - - webapp - - - webapp - Web Application Component Lifecycle Handler - - - - - - - - - - - - - - - - - - - - - - - - - - - org.apache.maven.repository.scheduler.RepositoryTaskScheduler - - - diff --git a/maven-repository-webapp/src/main/resources/maven-proxy-complete.conf b/maven-repository-webapp/src/main/resources/maven-proxy-complete.conf deleted file mode 100644 index cfa847144..000000000 --- a/maven-repository-webapp/src/main/resources/maven-proxy-complete.conf +++ /dev/null @@ -1,145 +0,0 @@ -################ GLOBAL SETTINGS -# This is where maven-proxy stores files it has downloaded -repo.local.store=/tmp/proxy-cache - -#The port to listen on - not used if loaded as a webapp -port=9999 - -#This is the base area that all files are loaded from. While it is possible to leave this blank, this behaviour -#is deprecated and will be disabled in version 2.0. There are too many namespace conflicts caused by not using -#a prefix. -#The repository will be shown at http://localhost:9999/repository/ -#for the .war loaded into a webapp server, the default prefix is "repository" (edit the web.xml to change) -# As maven doesn't like a trailing slash, this address shouldn't have one either. -prefix=repository - -#This is the simple date format used to display the last modified date while browsing the repository. -lastModifiedDateFormat=yyyy/MM/dd HH:mm:ss - -################ SNAPSHOT HANDLING -#If you want the proxy to look for newer snapshots, set to true -snapshot.update=true - -################ M2 METADATA HANDLING -#If you want the proxy to prevent looking for newer metadata, set to false (default is true) -#metadata.update=false - -################ M2 POM HANDLING -#If you want the proxy to look for newer POMs, set to true (default is false) -pom.update=true - -################ PROMOTION HANDLING -# ***** NOT CURRENTLY IMPLEMENTED ***** -#Promotion describes the process by which new artifacts are loaded to global maven-proxy repository. It -# is designed to be used by "higher security installations" that do not want to acquire artifacts from -# remote repositories without approval. -# -#If promotion handling is enabled, then the proxy will not download remote artifacts without permission -# (local repositories with copy=false are considered to be local) -# -#Permission to download is granted via the Promotion menu which will be enabled -# when promotion handling is enabled. -# -#If promotion is false, artifacts are sourced from any repository as per normal. -# -#Promotion and snapshots: If promotion is enabled, snapshots are not downloadable. The concept of using -# a snapshot in a production build (which is primarily what promotion is for) is counterintuitive. -## -promotion=false - -################ WEB INTERFACE -# This defines the absolute URL the server should use to identify itself. -# This can often be determined automatically, but we recommend you specify -# it explicitly to prevent problems during startup. -# The prefix will be added to this for the actual repository -# i.e. proxy available at http://localhost:9999/, repository at http://localhost:9999/repository -serverName=http://localhost:9999 - -#If true, the repository can be browsed -browsable=true - -#If true, the repository can be searched -searchable=true - -#Not currently implemented. Will allow webdav access to the repository at some point. -webdav=true - -#Stylesheet - if configured, will override the default stylesheet shipped with maven-proxy - absolute URLs only -#eg. /maven-proxy/style.css, http://www.example.com/style.css -stylesheet=/maven-proxy/style.css - -#bgColor / bgColorHighlight are replaced in the built in stylesheet to produce a simple color scheme. -#If a stylesheet is set, these are not used. -bgColor=#14B -bgColorHighlight=#94B - -#rowColor / rowColorHighlight are replaced in the built in stylesheet to produce a simple color scheme. -#If a stylesheet is set, these are not used. -rowColor=#CCF -rowColorHighlight=#DDF - - -################ PROXIES -#This is just a hack, it should auto discover them -#proxy.list=one,two,three -proxy.list= - -#Unauthenticated proxy -#proxy.one.host=proxy1.example.com -#proxy.one.port=3128 - -#Authenticated proxy -#proxy.two.host=proxy2.example.org -#proxy.two.port=80 -#proxy.two.username=username2 -#proxy.two.password=password2 - -#Authenticated proxy -#proxy.three.host=proxy3.example.net -#proxy.three.port=3129 -#proxy.three.username=username3 -#proxy.three.password=password3 - - -################# REPOSITORIES -#This is not just a hack, it specifies the order repositories should be checked -#Note that the proxy adds a "/" which is why the urls aren't suffixed with a "/" -repo.list=www-ibiblio-org - -#local-store -# The local store represents a location that local jars you host can be located. -# This could also be achieved by having a local http repository, but this is less cumbersome -repo.local-repo.url=file://target -repo.local-repo.description=Super Secret Custom Repository -#If copy is true, jars are copied from the store to the proxy-repo. Only configurable for file:/// repos -repo.local-repo.copy=false -#If hardfail is true, any unexpected errors from the repository will cause -#the client download to fail (typically with a 500 error) -repo.local-repo.hardfail=true -#Don't cache a file repository -repo.local-repo.cache.period=0 - - -#www.ibiblio.org -repo.www-ibiblio-org.url=http://www.ibiblio.org/maven2 -repo.www-ibiblio-org.description=www.ibiblio.org -repo.www-ibiblio-org.proxy= -repo.www-ibiblio-org.hardfail=true -#Cache this repository for 1 hour -repo.www-ibiblio-org.cache.period=3600 -repo.www-ibiblio-org.cache.failures=true - -#dist.codehaus.org -repo.dist-codehaus-org.url=http://dist.codehaus.org -repo.dist-codehaus-org.proxy=two -repo.dist-codehaus-org.hardfail=false -repo.dist-codehaus-org.cache.period=3600 -repo.dist-codehaus-org.cache.failures=true - -#private.example.com -repo.private-example-com.url=http://private.example.com/internal -repo.private-example-com.description=Commercial In Confidence Repository -repo.private-example-com.username=username1 -repo.private-example-com.password=password1 -repo.private-example-com.proxy=three -repo.private-example-com.cache.period=3600 diff --git a/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/SearchAction-checksumSearch-validation.xml b/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/SearchAction-checksumSearch-validation.xml deleted file mode 100644 index 771a8ab6b..000000000 --- a/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/SearchAction-checksumSearch-validation.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - You must select a file, or enter the checksum. If the file was given and you receive this message, - there may have been an error generating the checksum. - - - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/SearchAction-quickSearch-validation.xml b/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/SearchAction-quickSearch-validation.xml deleted file mode 100644 index 961cb7c8d..000000000 --- a/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/SearchAction-quickSearch-validation.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - You must enter some search terms. - - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureAction-validation.xml b/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureAction-validation.xml deleted file mode 100644 index 60b774bc7..000000000 --- a/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureAction-validation.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - You must enter the index directory. - - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureProxiedRepositoryAction-validation.xml b/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureProxiedRepositoryAction-validation.xml deleted file mode 100644 index ee58ed9f9..000000000 --- a/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureProxiedRepositoryAction-validation.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - You must enter the repository identifier. - - - - - You must enter the repository name. - - - - - You must enter the repository URL. - - - - - - - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureRepositoryAction-validation.xml b/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureRepositoryAction-validation.xml deleted file mode 100644 index 0a1bb779d..000000000 --- a/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureRepositoryAction-validation.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - You must enter the repository identifier. - - - - - You must enter the repository name. - - - - - You must enter the repository directory. - - - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction-addSelectedSyncedRepository-validation.xml b/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction-addSelectedSyncedRepository-validation.xml deleted file mode 100644 index 0a9f275f7..000000000 --- a/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction-addSelectedSyncedRepository-validation.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - You must enter the repository identifier. - - - - - You must enter the repository name. - - - - - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction-validation.xml b/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction-validation.xml deleted file mode 100644 index 154b28fb3..000000000 --- a/maven-repository-webapp/src/main/resources/org/apache/maven/repository/manager/web/action/admin/ConfigureSyncedRepositoryAction-validation.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - You must enter the synchronization method. - - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/resources/webwork.properties b/maven-repository-webapp/src/main/resources/webwork.properties deleted file mode 100644 index 6837803ce..000000000 --- a/maven-repository-webapp/src/main/resources/webwork.properties +++ /dev/null @@ -1,5 +0,0 @@ -# define our own action mapper here -webwork.mapper.class=org.apache.maven.repository.manager.web.mapper.RepositoryActionMapper -webwork.objectFactory = org.codehaus.plexus.xwork.PlexusObjectFactory - -# TODO: package up a theme and share with Continuum. Should contain everything from xhtml, and set templateDir to WEB-INF/themes \ No newline at end of file diff --git a/maven-repository-webapp/src/main/resources/xwork.xml b/maven-repository-webapp/src/main/resources/xwork.xml deleted file mode 100644 index db1d796a7..000000000 --- a/maven-repository-webapp/src/main/resources/xwork.xml +++ /dev/null @@ -1,212 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /admin - configure - - - /admin - - addRepository!input - - /WEB-INF/jsp/generalError.jsp - - - - - - - - - - - - - - - - - - /WEB-INF/jsp/quickSearch.jsp - - - - /WEB-INF/jsp/quickSearch.jsp - /WEB-INF/jsp/results.jsp - /WEB-INF/jsp/quickSearch.jsp - /WEB-INF/jsp/noResults.jsp - - - - - /WEB-INF/jsp/findArtifact.jsp - - - - /WEB-INF/jsp/findArtifact.jsp - /WEB-INF/jsp/results.jsp - /WEB-INF/jsp/findArtifact.jsp - /WEB-INF/jsp/noResults.jsp - - - /browse/${searchResults[0].groupId}/${searchResults[0].artifactId}/${searchResults[0].version} - - - - - /WEB-INF/jsp/browse.jsp - - - - /WEB-INF/jsp/browseGroup.jsp - - - - /WEB-INF/jsp/browseArtifact.jsp - - - - /WEB-INF/jsp/showArtifact.jsp - - - - - ${contentType} - filename="${filename}" - artifactStream - 1024 - - 404 - - - - - - - /WEB-INF/jsp/admin/index.jsp - - - - /WEB-INF/jsp/admin/addRepository.jsp - index - - - - - /WEB-INF/jsp/admin/editRepository.jsp - index - - - - - /WEB-INF/jsp/admin/deleteRepository.jsp - index - - - - /WEB-INF/jsp/admin/proxiedRepositories.jsp - - - - /WEB-INF/jsp/admin/addProxiedRepository.jsp - proxiedRepositories - - - - /WEB-INF/jsp/admin/editProxiedRepository.jsp - proxiedRepositories - - - - - /WEB-INF/jsp/admin/deleteProxiedRepository.jsp - proxiedRepositories - - - - /WEB-INF/jsp/admin/syncedRepositories.jsp - - - - /WEB-INF/jsp/admin/selectSyncedRepository.jsp - - addSelectedSyncedRepository - input - - - - - /WEB-INF/jsp/admin/addSyncedRepository.jsp - syncedRepositories - - - - /WEB-INF/jsp/admin/editSyncedRepository.jsp - syncedRepositories - - - - - /WEB-INF/jsp/admin/deleteSyncedRepository.jsp - syncedRepositories - - - - /WEB-INF/jsp/admin/configure.jsp - - - - - /WEB-INF/jsp/admin/configure.jsp - /WEB-INF/jsp/admin/index.jsp - - - - - index - - - - diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/decorators.xml b/maven-repository-webapp/src/main/webapp/WEB-INF/decorators.xml deleted file mode 100644 index 03131ae9f..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/decorators.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - /* - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/addProxiedRepository.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/addProxiedRepository.jsp deleted file mode 100644 index 6b70fda5b..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/addProxiedRepository.jsp +++ /dev/null @@ -1,43 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> - - - - Configuration - - - - - -

Configuration

- -
- -

Add Proxied Repository

- - - - - <%@ include file="/WEB-INF/jsp/admin/include/proxiedRepositoryForm.jspf" %> - - - -
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/addRepository.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/addRepository.jsp deleted file mode 100644 index 82c470120..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/addRepository.jsp +++ /dev/null @@ -1,43 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> - - - - Configuration - - - - - -

Configuration

- -
- -

Add Managed Repository

- - - - - <%@ include file="/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf" %> - - - -
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/addSyncedRepository.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/addSyncedRepository.jsp deleted file mode 100644 index 524164c81..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/addSyncedRepository.jsp +++ /dev/null @@ -1,44 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - Configuration - - - - - -

Configuration

- -
- -

Add Synced Repository

- - - - - <%@ include file="/WEB-INF/jsp/admin/include/syncedRepositoryForm.jspf" %> - - - -
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp deleted file mode 100644 index 725e4be7d..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp +++ /dev/null @@ -1,44 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> - - - - Configuration - - - - - -

Configuration

- -
- - - - - - - - - - - -
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteProxiedRepository.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteProxiedRepository.jsp deleted file mode 100644 index b064b5678..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteProxiedRepository.jsp +++ /dev/null @@ -1,48 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> - - - - Configuration - - - - - -

Configuration

- -
- -

Delete Proxied Repository

- -
- WARNING: This operation can not be undone. -
- - - - - - -
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRepository.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRepository.jsp deleted file mode 100644 index cb2245256..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRepository.jsp +++ /dev/null @@ -1,47 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> - - - - Configuration - - - - - -

Configuration

- -
- -

Delete Managed Repository

- -
- WARNING: This operation can not be undone. -
- - - - - - -
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteSyncedRepository.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteSyncedRepository.jsp deleted file mode 100644 index 7db55d5c7..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteSyncedRepository.jsp +++ /dev/null @@ -1,48 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> - - - - Configuration - - - - - -

Configuration

- -
- -

Delete Synced Repository

- -
- WARNING: This operation can not be undone. -
- - - - - - -
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/editProxiedRepository.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/editProxiedRepository.jsp deleted file mode 100644 index ee60cfe67..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/editProxiedRepository.jsp +++ /dev/null @@ -1,42 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> - - - - Configuration - - - - - -

Configuration

- -
- -

Edit Proxied Repository

- - - - - <%@ include file="/WEB-INF/jsp/admin/include/proxiedRepositoryForm.jspf" %> - - -
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/editRepository.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/editRepository.jsp deleted file mode 100644 index 9afd85681..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/editRepository.jsp +++ /dev/null @@ -1,43 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> - - - - Configuration - - - - - -

Configuration

- -
- -

Edit Managed Repository

- - - - - <%@ include file="/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf" %> - - - -
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/editSyncedRepository.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/editSyncedRepository.jsp deleted file mode 100644 index a39e2ac84..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/editSyncedRepository.jsp +++ /dev/null @@ -1,44 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - Configuration - - - - - -

Configuration

- -
- -

Edit Synced Repository

- - - - - <%@ include file="/WEB-INF/jsp/admin/include/syncedRepositoryForm.jspf" %> - - - -
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf deleted file mode 100644 index 2dcbce3be..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/include/managedRepositoryForm.jspf +++ /dev/null @@ -1,23 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> -<%@ taglib prefix="ww" uri="/webwork" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - - diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxiedRepositoryForm.jspf b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxiedRepositoryForm.jspf deleted file mode 100644 index 4b46713e8..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxiedRepositoryForm.jspf +++ /dev/null @@ -1,39 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> - - - - - - - - - - - diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/include/syncedRepositoryForm.jspf b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/include/syncedRepositoryForm.jspf deleted file mode 100644 index 91b2a1047..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/include/syncedRepositoryForm.jspf +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/index.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/index.jsp deleted file mode 100644 index 6f8a66e78..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/index.jsp +++ /dev/null @@ -1,135 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - Administration - - - - - -

Administration

- -
-

Configuration

- - - - - - - - - - - <%-- TODO: a "run now without timestamp checking" operation should be here too, to pick up any stragglers (in the event of a bug) --%> - <%-- TODO: a "delete index and run now" operation should be here too (really clean, remove deletions that didn't get picked up) --%> - - -
Index Directory - -
Indexing Schedule - - ">Run Now
- - - -

HTTP Proxy

- - - - - - - - - - - - - - -
Host${proxy.host}
Port${proxy.port}
Username${proxy.username}
-
- -

- ">Edit Configuration -

- -

Managed Repositories

- - - - There are no managed repositories configured yet. - - -
-
- <%-- TODO replace with icons --%> - ">Edit - Repository | ">Delete - Repository -
-

${repository.name}

- - - - - - - - - - - - - - - - - - - - - - -
Identifier - ${repository.id} -
Directory${repository.directory}
Type - - - Maven 2.x Repository - - - Maven 1.x Repository - - -
Snapshots Included
Indexed
-
-
- -

- ">Add Repository -

-
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/proxiedRepositories.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/proxiedRepositories.jsp deleted file mode 100644 index b0670d29c..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/proxiedRepositories.jsp +++ /dev/null @@ -1,148 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - Administration - - - - - -

Administration

- -
-

Proxied Repositories

- - - - There are no proxied repositories configured yet. - - -
-
- <%-- TODO replace with icons --%> - ">Edit - Repository | ">Delete - Repository -
-

${repository.name}

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Identifier - ${repository.id} -
URL${repository.url}
Type - - - Maven 2.x Repository - - - Maven 1.x Repository - - -
Snapshots - - - - Disabled - - - Updated every request - - - Updated hourly - - - Updated daily - - - Updated every ${repository.snapshotsInterval} minutes - - -
Releases - - - - Disabled - - - Updated every request - - - Updated hourly - - - Updated daily - - - Updated every ${repository.releasesInterval} minutes - - -
Proxied through - - ${repositoriesMap[repository.managedRepository].name} - (${repositoriesMap[repository.managedRepository].id}) -
Use HTTP Proxy
Cache Failures
Fail Whole Group
-
-
- -

- ">Add Repository -

-
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/selectSyncedRepository.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/selectSyncedRepository.jsp deleted file mode 100644 index 9cd8384d4..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/selectSyncedRepository.jsp +++ /dev/null @@ -1,46 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> - - - - Configuration - - - - - -

Configuration

- -
- -

Add Synced Repository

- - - - - - - -
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/syncedRepositories.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/syncedRepositories.jsp deleted file mode 100644 index 31ad29e64..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/syncedRepositories.jsp +++ /dev/null @@ -1,145 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - Administration - - - - - -

Administration

- -
-

Synced Repositories

- - - - There are no synced repositories configured yet. - - -
-
- <%-- TODO replace with icons --%> - ">Edit - Repository | ">Delete - Repository -
-

${repository.name}

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Identifier - ${repository.id} -
Method${repository.method}
CVS Root${repository.properties['cvsRoot']}
Subversion URL${repository.properties['svnUrl']}
Subversion Username${repository.properties['username']}
Rsync Host${repository.properties['rsyncHost']}
Rsync Directory${repository.properties['rsyncDirectory']}
Rsync Method - - - Anonymous - - - SSH - - -
Username${repository.properties['username']}
Directory${repository.properties['directory']}
Type - - - Maven 2.x Repository - - - Maven 1.x Repository - - -
Synced to - - ${repositoriesMap[repository.managedRepository].name} - (${repositoriesMap[repository.managedRepository].id}) -
Schedule${repository.cronExpression}
-
-
- -

- ">Add Repository -

-
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp deleted file mode 100644 index da6c69ecc..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp +++ /dev/null @@ -1,74 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - Browse Repository - - - - - -

Browse Repository

- -
-
-

Groups

- -
- - <%-- TODO: later, when supported in metadata -
-

Category

- - - - - - - -
- Java -
- Ruby -
-
- -

Labels

- -
-

- jdo - j2ee - maven -

-
- --%> -
- - - diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browseArtifact.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browseArtifact.jsp deleted file mode 100644 index f7ba822ee..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browseArtifact.jsp +++ /dev/null @@ -1,66 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - Browse Repository - - - - - -

Browse Repository

- -
-
-

- - - - - - - - - - - - - ${part} / - - ${artifactId} -

- -

Versions

- -
-
- - - diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browseGroup.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browseGroup.jsp deleted file mode 100644 index fb352b5ad..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browseGroup.jsp +++ /dev/null @@ -1,86 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - Browse Repository - - - - - -

Browse Repository

- -
-
-

- - - - - - - - - - - - ${part} - - - - - - ${part} / - - - -

- - - -

Group / Artifact

- -
- - - -

Artifacts

- -
-
-
- - - diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp deleted file mode 100644 index 76f7b3402..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp +++ /dev/null @@ -1,145 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %> -<%@ taglib uri="/webwork" prefix="ww" %> -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> -<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %> - - - Maven Repository Manager :: - <decorator:title default="Maven Repository Manager" /> - - - - - - - -" class="composite"> - - - - -
- - -
- -
-
- -
-
- -
-
-
- - - - diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/findArtifact.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/findArtifact.jsp deleted file mode 100644 index bfc1b0959..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/findArtifact.jsp +++ /dev/null @@ -1,86 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> - - - - Find Artifact - - - - - -

Find Artifact

- -
- -
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/form.jspf b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/form.jspf deleted file mode 100644 index 6049fe788..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/form.jspf +++ /dev/null @@ -1,53 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - - - -

Search by MD5 (select an artifact):

- -
- - - -
- -

- - -

- -

Search:

- -
- - -
- -

Search by Java Package:

- -
- - -
- - diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/generalError.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/generalError.jsp deleted file mode 100644 index bef5023c3..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/generalError.jsp +++ /dev/null @@ -1,33 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - Error Occurred - - - - - -

Error Occurred

- - - - - diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/include/quickSearchForm.jspf b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/include/quickSearchForm.jspf deleted file mode 100644 index b40dcd7be..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/include/quickSearchForm.jspf +++ /dev/null @@ -1,28 +0,0 @@ -<%@ taglib prefix="ww" uri="/webwork" %> -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/quickSearch.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/quickSearch.jsp deleted file mode 100644 index 82ed0351c..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/quickSearch.jsp +++ /dev/null @@ -1,33 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> - - - Quick Search - - - - - -

Search

- -
- <%@ include file="/WEB-INF/jsp/include/quickSearchForm.jspf" %> -
- - - \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp deleted file mode 100644 index 9ef4f69e3..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp +++ /dev/null @@ -1,92 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib uri="/webwork" prefix="ww" %> -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> - - - - Search Results - - - - - -

Search Results

- -
- -
- - diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp deleted file mode 100644 index ed843a634..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp +++ /dev/null @@ -1,266 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib prefix="ww" uri="/webwork" %> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - Browse Repository - - - - - -<%-- TODO: image by type -jar ---%> - -<%-- TODO: download link - ---%> - - -

- - - ${model.artifactId} - - - ${model.name} - - -

- -
-
-

- Info - <%-- TODO: perhaps using ajax? - Dependencies - Depended On - Mailing Lists - Developers - POM - --%> -

-
- -
-

- - - - - - - - - - - - - ${part} / - - - - - - ${model.artifactId} / - ${model.version} - - -

- -

${mode.description}

- - - - - - - - - - - - - - - - - - - <%-- TODO: derivatives - - - - - --%> - - - - - - - <%-- TODO: deployment timestamp - - - - - --%> - -
Group ID${model.groupId}
Artifact ID${model.artifactId}
Version${model.version}
Packaging${model.packaging}
Derivatives - Source - | - Javadoc -
Parent - ${model.parent.groupId} ${model.parent.artifactId} ${model.parent.version} - - - - - - (View) -
Deployment Date - 15 Jan 2006, 20:38:00 +1000 -
- - - -

Other Details

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
URL - ${model.url} -
Organisation - - - ${model.organization.name} - - - ${model.organization.name} - - -
License - - - ${license.name} - - - ${license.name} - - -
Issue Tracker - - - ${model.issueManagement.system} - - - ${model.issueManagement.system} - - -
Continuous Integration - - - ${model.ciManagement.system} - - - ${model.ciManagement.system} - - -
-
- - -

SCM

- - - - - - - - - - - - - - - - - - - -
Connection - ${model.scm.connection} -
Dev. Connection - ${model.scm.developerConnection} -
Viewer - ${model.scm.url} -
-
- -
-
- - - diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/tags/currentWWUrl.tag b/maven-repository-webapp/src/main/webapp/WEB-INF/tags/currentWWUrl.tag deleted file mode 100644 index 6febd7f06..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/tags/currentWWUrl.tag +++ /dev/null @@ -1,38 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%@ taglib uri="/webwork" prefix="ww" %> -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> -<%@ attribute name="action" required="true" %> -<%@ attribute name="namespace" required="true" %> - - - - - - - - - - - - - - - - - - diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/web.xml b/maven-repository-webapp/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 49da01f29..000000000 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - Maven Repository Manager - - - webwork-cleanup - com.opensymphony.webwork.dispatcher.ActionContextCleanUp - - - - sitemesh - com.opensymphony.module.sitemesh.filter.PageFilter - - - - webwork - com.opensymphony.webwork.dispatcher.FilterDispatcher - - - - - webwork-cleanup - /* - - - - sitemesh - /* - - - - webwork - /* - - - - org.codehaus.plexus.xwork.PlexusLifecycleListener - - diff --git a/maven-repository-webapp/src/main/webapp/css/maven-base.css b/maven-repository-webapp/src/main/webapp/css/maven-base.css deleted file mode 100644 index 9dc7da470..000000000 --- a/maven-repository-webapp/src/main/webapp/css/maven-base.css +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -body { - margin: 0px; - padding: 0px; -} - -img { - border: none; -} - -table { - padding: 0px; - width: 100%; - margin-left: -2px; - margin-right: -2px; -} - -acronym { - cursor: help; - border-bottom: 1px dotted #feb; -} - -table.bodyTable th, table.bodyTable td { - padding: 2px 4px 2px 4px; - vertical-align: top; -} - -div.clear { - clear: both; - visibility: hidden; -} - -div.clear hr { - display: none; -} - -#bannerLeft, #bannerRight { - font-size: xx-large; - font-weight: bold; -} - -#bannerLeft img, #bannerRight img { - margin: 0px; -} - -.xleft, #bannerLeft img { - float: left; - text-shadow: #7CFC00; -} - -.xright, #bannerRight img { - float: right; - text-shadow: #7CFC00; -} - -#banner { - padding: 0px; -} - -#banner img { - border: none; -} - -#breadcrumbs { - padding: 3px 10px 3px 10px; -} - -#leftColumn { - width: 170px; - float: left; - overflow: auto; -} - -#bodyColumn { - margin-right: 1.5em; - margin-left: 197px; -} - -#legend { - padding: 8px 0 8px 0; -} - -#navcolumn { - padding: 8px 4px 0 8px; -} - -#navcolumn h5 { - margin: 0; - padding: 0; - font-size: small; -} - -#navcolumn ul { - margin: 0; - padding: 0; - font-size: small; -} - -#navcolumn li { - list-style-type: none; - background-image: none; - background-repeat: no-repeat; - background-position: 0 0.4em; - padding-left: 16px; - list-style-position: outside; - line-height: 1.2em; - font-size: smaller; -} - -#navcolumn li.expanded { - background-image: url( ../images/expanded.gif ); -} - -#navcolumn li.collapsed { - background-image: url( ../images/collapsed.gif ); -} - -#poweredBy { - text-align: center; -} - -#navcolumn img { - margin-top: 10px; - margin-bottom: 3px; -} - -#poweredBy img { - display: block; - margin: 20px 0 20px 17px; - border: 1px solid black; - width: 90px; - height: 30px; -} - -#search img { - margin: 0px; - display: block; -} - -#search #q, #search #btnG { - border: 1px solid #999; - margin-bottom: 10px; -} - -#search form { - margin: 0px; -} - -#lastPublished { - font-size: x-small; -} - -.navSection { - margin-bottom: 2px; - padding: 8px; -} - -.navSectionHead { - font-weight: bold; - font-size: x-small; -} - -.section { - padding: 4px; -} - -#footer { - padding: 3px 10px 3px 10px; - font-size: x-small; -} - -#breadcrumbs { - font-size: x-small; - margin: 0pt; -} - -.source { - padding: 12px; - margin: 1em 7px 1em 7px; -} - -.source pre { - margin: 0px; - padding: 0px; -} diff --git a/maven-repository-webapp/src/main/webapp/css/maven-theme.css b/maven-repository-webapp/src/main/webapp/css/maven-theme.css deleted file mode 100644 index e035dce77..000000000 --- a/maven-repository-webapp/src/main/webapp/css/maven-theme.css +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -body { - padding: 0px 0px 10px 0px; -} - -body, td, select, input, li { - font-family: Verdana, Helvetica, Arial, sans-serif; - font-size: 13px; -} - -select, input { - font-size: x-small; -} - -table { - width: auto; -} - -code { - font-family: Courier, monospace; - font-size: 13px; -} - -a { - text-decoration: none; -} - -#legend li.externalLink { - background: url( ../images/external.png ) left top no-repeat; - padding-left: 18px; -} - -a.externalLink, a.externalLink:link, a.externalLink:visited, a.externalLink:active, a.externalLink:hover { - background: url( ../images/external.png ) right center no-repeat; - padding-right: 18px; -} - -#legend li.newWindow { - background: url( ../images/newwindow.png ) left top no-repeat; - padding-left: 18px; -} - -a.newWindow, a.newWindow:link, a.newWindow:visited, a.newWindow:active, a.newWindow:hover { - background: url( ../images/newwindow.png ) right center no-repeat; - padding-right: 18px; -} - -p { - line-height: 1.3em; - font-size: small; -} - -#breadcrumbs { - border-top: 1px solid #fff; - border-bottom: 1px solid #999; - background-color: #F3B455; - padding: 2px 8px; -} - -#navcolumn h5 { - color: gray; - font-weight: bold; - font-size: 11px; - padding: 10px 0px 1px 19px; -} - -table.bodyTable th { - color: white; - background-color: #bbb; - text-align: left; - font-weight: bold; -} - -table.bodyTable th, table.bodyTable td { - font-size: 1em; -} - -table.bodyTable tr.a { - background-color: #ddd; -} - -table.bodyTable tr.b { - background-color: #eee; -} - -.source { - border: 1px solid #999; -} - -dl { - padding: 4px 4px 4px 6px; - border: 1px solid #aaa; - background-color: #ffc; -} - -dt { - color: #900; -} - -#organizationLogo img, #projectLogo img, #projectLogo span { - margin: 8px; -} - -#banner { - border-bottom: 1px solid #fff; - padding: 8px; -} - -#breadcrumbs a:link { - text-decoration: none; -} - -#breadcrumbs a:visited { - text-decoration: none; - color: #333 -} - -#breadcrumbs a:hover { - text-decoration: none; - color: white -} - -a:link { - color: #333; -} - -.errormark, .warningmark, .donemark, .infomark { - background: url( ../images/icon_error_sml.gif ) no-repeat; -} - -.warningmark { - background-image: url( ../images/icon_warning_sml.gif ); -} - -.donemark { - background-image: url( ../images/icon_success_sml.gif ); -} - -.infomark { - background-image: url( ../images/icon_info_sml.gif ); -} - -#leftColumn { - padding: 4px 4px 4px 4px; - overflow: hidden; -} - -#navcolumn { - padding: 6px 0 0 2px; -} - -#navcolumn li { - font-size: 9px; - text-indent: 19px; - line-height: 24px; - height: 25px; - width: 161px; - background-image: url( ../images/super.gif ); - background-position: 0 0; - background-repeat: no-repeat; - display: block; - padding-left: 0; -} - -#navcolumn li li { - padding-left: 16px; - background: none; - display: block; -} - -#navcolumn li li a:hover { - color: black !important; - background: none; - display: block; -} - -#navcolumn li li a:active { - color: red !important; - background: none; - display: block; -} - -#navcolumn li.expanded { - background-image: url( ../images/super.gif ); - height: inherit; -} - -#navcolumn li a:link { - color: #666; - display: block; -} - -#navcolumn li a:hover { - color: #fff !important; - background: url( ../images/super_hl.gif ) 0 -25px no-repeat; - display: block; -} - -#navcolumn li a:active { - color: #fff !important; - background: url( ../images/super_hl.gif ) 0 -50px no-repeat; - display: block; -} - -#navcolumn li a:visited { - color: #666; - display: block; -} - -#footer { - background: url( ../images/footerborder.gif ) 0 5px repeat-x; - padding: 14px 4px 12px 4px; - margin-top: 2em; -} - diff --git a/maven-repository-webapp/src/main/webapp/css/print.css b/maven-repository-webapp/src/main/webapp/css/print.css deleted file mode 100644 index 9a6106d2d..000000000 --- a/maven-repository-webapp/src/main/webapp/css/print.css +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -#banner, #footer, #leftcol, #breadcrumbs, .docs #toc, .docs .courtesylinks, #leftColumn, #navColumn { - display: none !important; -} - -#bodyColumn, body.docs div.docs { - margin: 0 !important; - border: none !important -} diff --git a/maven-repository-webapp/src/main/webapp/css/site.css b/maven-repository-webapp/src/main/webapp/css/site.css deleted file mode 100644 index 98931b472..000000000 --- a/maven-repository-webapp/src/main/webapp/css/site.css +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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. - */ - -#sidebar { - float: right; - font-size: small; - margin: 10px; - padding: 10px; - border: 1px black solid; - width: 10em; -} - -#contentArea { - border: 1px solid black; - margin-right: 15em; - padding: 1em; -} - -#tabs strong { - border: 1px solid black; - padding-left: 1em; - padding-right: 1em; -} - -#tabs a { - border: 1px solid black; - padding-left: 1em; - padding-right: 1em; - text-decoration: none; -} - -#tabArea { - border: 1px solid black; - padding: 1em; -} - -#searchBox p { - font-size: x-small; - text-align: center; - color: gray; -} - -#searchTypes { - text-align: right; - font-size: xx-small; -} - -/* TODO: remove if they aren't used -#feed { - float: right; -} - -.downloadButton { - background-color: green; - border: double white; - float: right; - padding: 5px; -} - -.downloadButton a { - font-size: large; - color: white; - font-weight: bold; - text-decoration: none; -} - -#labels { - background-color: #f2f2f2; - padding: 0.5em 1em 0.5em 1em; -} - -.statusWarn { - color: orange; - font-weight: bold; -} -*/ - -.statusOk { - color: green; - font-weight: bold; -} - -.statusFailed { - color: red; - font-weight: bold; -} - -/* WebWork validation failures */ -.errorMessage { - color: red; - font-weight: bold; -} - -.actionMessage { - font-weight: bold; -} - -sWarn { - color: orange; - font-weight: bold; -} - -/* WebWork validation failures */ -.errorMessage { - color: red; - font-weight: bold; -} - -.actionMessage { - font-weight: bold; -} - - font-weight: bold; -} diff --git a/maven-repository-webapp/src/main/webapp/images/collapsed.gif b/maven-repository-webapp/src/main/webapp/images/collapsed.gif deleted file mode 100644 index 6e7108406..000000000 Binary files a/maven-repository-webapp/src/main/webapp/images/collapsed.gif and /dev/null differ diff --git a/maven-repository-webapp/src/main/webapp/images/expanded.gif b/maven-repository-webapp/src/main/webapp/images/expanded.gif deleted file mode 100644 index 0fef3d89e..000000000 Binary files a/maven-repository-webapp/src/main/webapp/images/expanded.gif and /dev/null differ diff --git a/maven-repository-webapp/src/main/webapp/images/external.png b/maven-repository-webapp/src/main/webapp/images/external.png deleted file mode 100644 index 3f999fc88..000000000 Binary files a/maven-repository-webapp/src/main/webapp/images/external.png and /dev/null differ diff --git a/maven-repository-webapp/src/main/webapp/images/footerborder.gif b/maven-repository-webapp/src/main/webapp/images/footerborder.gif deleted file mode 100644 index 958ce7ae3..000000000 Binary files a/maven-repository-webapp/src/main/webapp/images/footerborder.gif and /dev/null differ diff --git a/maven-repository-webapp/src/main/webapp/images/icon_error_sml.gif b/maven-repository-webapp/src/main/webapp/images/icon_error_sml.gif deleted file mode 100644 index 61132ef2b..000000000 Binary files a/maven-repository-webapp/src/main/webapp/images/icon_error_sml.gif and /dev/null differ diff --git a/maven-repository-webapp/src/main/webapp/images/icon_info_sml.gif b/maven-repository-webapp/src/main/webapp/images/icon_info_sml.gif deleted file mode 100644 index c6cb9ad7c..000000000 Binary files a/maven-repository-webapp/src/main/webapp/images/icon_info_sml.gif and /dev/null differ diff --git a/maven-repository-webapp/src/main/webapp/images/icon_success_sml.gif b/maven-repository-webapp/src/main/webapp/images/icon_success_sml.gif deleted file mode 100644 index 52e85a430..000000000 Binary files a/maven-repository-webapp/src/main/webapp/images/icon_success_sml.gif and /dev/null differ diff --git a/maven-repository-webapp/src/main/webapp/images/icon_warning_sml.gif b/maven-repository-webapp/src/main/webapp/images/icon_warning_sml.gif deleted file mode 100644 index 873bbb52c..000000000 Binary files a/maven-repository-webapp/src/main/webapp/images/icon_warning_sml.gif and /dev/null differ diff --git a/maven-repository-webapp/src/main/webapp/images/newwindow.png b/maven-repository-webapp/src/main/webapp/images/newwindow.png deleted file mode 100644 index 6287f72bd..000000000 Binary files a/maven-repository-webapp/src/main/webapp/images/newwindow.png and /dev/null differ diff --git a/maven-repository-webapp/src/main/webapp/images/super.gif b/maven-repository-webapp/src/main/webapp/images/super.gif deleted file mode 100644 index c8ee24344..000000000 Binary files a/maven-repository-webapp/src/main/webapp/images/super.gif and /dev/null differ diff --git a/maven-repository-webapp/src/main/webapp/images/super_hl.gif b/maven-repository-webapp/src/main/webapp/images/super_hl.gif deleted file mode 100644 index d90b8f0f8..000000000 Binary files a/maven-repository-webapp/src/main/webapp/images/super_hl.gif and /dev/null differ diff --git a/maven-repository-webapp/src/main/webapp/index.jsp b/maven-repository-webapp/src/main/webapp/index.jsp deleted file mode 100644 index 867a05e78..000000000 --- a/maven-repository-webapp/src/main/webapp/index.jsp +++ /dev/null @@ -1,17 +0,0 @@ -<%-- - ~ Copyright 2005-2006 The Apache Software Foundation. - ~ - ~ Licensed 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. - --%> - -<%response.sendRedirect( request.getContextPath() + "/index.action" );%> \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/template/repository-manager/radiomap.ftl b/maven-repository-webapp/src/main/webapp/template/repository-manager/radiomap.ftl deleted file mode 100644 index 89ef578d1..000000000 --- a/maven-repository-webapp/src/main/webapp/template/repository-manager/radiomap.ftl +++ /dev/null @@ -1,39 +0,0 @@ -<@ww.iterator value="parameters.list"> - <#if parameters.listKey?exists> - <#assign itemKey = stack.findValue(parameters.listKey)/> - <#else> - <#assign itemKey = stack.findValue('top')/> - - <#if parameters.listValue?exists> - <#assign itemValue = stack.findString(parameters.listValue)/> - <#else> - <#assign itemValue = stack.findString('top')/> - - -<#if tag.contains(parameters.nameValue, itemKey)> - checked="checked"<#rt/> - -<#if itemKey?exists> - value="${itemKey?html}"<#rt/> - -<#if parameters.disabled?default(false)> - disabled="disabled"<#rt/> - -<#if parameters.tabindex?exists> - tabindex="${parameters.tabindex?html}"<#rt/> - -<#if parameters.cssClass?exists> - class="${parameters.cssClass?html}"<#rt/> - -<#if parameters.cssStyle?exists> - style="${parameters.cssStyle?html}"<#rt/> - -<#if parameters.title?exists> - title="${parameters.title?html}"<#rt/> - -<#include "/${parameters.templateDir}/simple/scripting-events.ftl" /> -/><#rt/> -
- diff --git a/maven-repository-webapp/src/main/webapp/template/repository-manager/theme.properties b/maven-repository-webapp/src/main/webapp/template/repository-manager/theme.properties deleted file mode 100644 index b0dfbe775..000000000 --- a/maven-repository-webapp/src/main/webapp/template/repository-manager/theme.properties +++ /dev/null @@ -1,17 +0,0 @@ -# -# Copyright 2005-2006 The Apache Software Foundation. -# -# Licensed 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. -# - -parent = xhtml diff --git a/maven-repository-webapp/src/test/java/org/apache/maven/repository/proxy/web/action/test/stub/HttpServletRequestStub.java b/maven-repository-webapp/src/test/java/org/apache/maven/repository/proxy/web/action/test/stub/HttpServletRequestStub.java deleted file mode 100644 index 02c8fe5a7..000000000 --- a/maven-repository-webapp/src/test/java/org/apache/maven/repository/proxy/web/action/test/stub/HttpServletRequestStub.java +++ /dev/null @@ -1,154 +0,0 @@ -package org.apache.maven.repository.proxy.web.action.test.stub; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; -import java.security.Principal; -import java.util.Enumeration; - -public class HttpServletRequestStub - extends ServletRequestStub - implements HttpServletRequest -{ - - public String getAuthType() - { - return null; - } - - public String getContextPath() - { - return "/location1/location2/location3"; - } - - public Cookie[] getCookies() - { - return null; - } - - public long getDateHeader( String name ) - { - return -1; - } - - public String getHeader( String name ) - { - return null; - } - - public Enumeration getHeaderNames() - { - return null; - } - - public Enumeration getHeaders( String name ) - { - return null; - } - - public int getIntHeader( String name ) - { - return -1; - } - - public String getMethod() - { - return null; - } - - public String getPathInfo() - { - return null; - } - - public String getPathTranslated() - { - return null; - } - - public String getQueryString() - { - return null; - } - - public String getRemoteUser() - { - return null; - } - - public String getRequestedSessionId() - { - return null; - } - - public String getRequestURI() - { - return "/projectname/repository/org/sometest/artifact-0.0.jar"; - } - - public StringBuffer getRequestURL() - { - return null; - } - - public String getServletPath() - { - return "/repository/org/sometest/artifact-0.0.jar"; - } - - public HttpSession getSession() - { - return null; - } - - public HttpSession getSession( boolean create ) - { - return null; - } - - public Principal getUserPrincipal() - { - return null; - } - - public boolean isRequestedSessionIdFromCookie() - { - return false; - } - - public boolean isRequestedSessionIdFromUrl() - { - return false; - } - - public boolean isRequestedSessionIdFromURL() - { - return false; - } - - public boolean isRequestedSessionIdValid() - { - return false; - } - - public boolean isUserInRole( String role ) - { - return false; - } -} diff --git a/maven-repository-webapp/src/test/java/org/apache/maven/repository/proxy/web/action/test/stub/ServletRequestStub.java b/maven-repository-webapp/src/test/java/org/apache/maven/repository/proxy/web/action/test/stub/ServletRequestStub.java deleted file mode 100644 index e5919d19b..000000000 --- a/maven-repository-webapp/src/test/java/org/apache/maven/repository/proxy/web/action/test/stub/ServletRequestStub.java +++ /dev/null @@ -1,181 +0,0 @@ -package org.apache.maven.repository.proxy.web.action.test.stub; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed 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 javax.servlet.RequestDispatcher; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletRequest; -import java.io.BufferedReader; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -public class ServletRequestStub - implements ServletRequest -{ - - public Object getAttribute( String key ) - { - return null; - } - - public Enumeration getAttributeNames() - { - return null; - } - - public String getCharacterEncoding() - { - return null; - } - - public int getContentLength() - { - return -1; - } - - public int getRemotePort() - { - return -1; - } - - public int getLocalPort() - { - return -1; - } - - public String getLocalAddr() - { - return null; - } - - public String getLocalName() - { - return null; - } - - public String getContentType() - { - return null; - } - - public ServletInputStream getInputStream() - { - return null; - } - - public Locale getLocale() - { - return null; - } - - public Enumeration getLocales() - { - return null; - } - - public String getParameter( String name ) - { - return null; - } - - public Map getParameterMap() - { - HashMap parameterMap = new HashMap(); - - parameterMap.put( "key1", "value1" ); - parameterMap.put( "key2", "value2" ); - - return parameterMap; - } - - public Enumeration getParameterNames() - { - return null; - } - - public String[] getParameterValues( String name ) - { - return null; - } - - public String getProtocol() - { - return null; - } - - public BufferedReader getReader() - { - return null; - } - - public String getRealPath( String path ) - { - return null; - } - - public String getRemoteAddr() - { - return null; - } - - public String getRemoteHost() - { - return null; - } - - public RequestDispatcher getRequestDispatcher( String path ) - { - return null; - } - - public String getScheme() - { - return null; - } - - public String getServerName() - { - return null; - } - - public int getServerPort() - { - return -1; - } - - public boolean isSecure() - { - return false; - } - - public void removeAttribute( String name ) - { - - } - - public void setAttribute( String name, Object value ) - { - - } - - public void setCharacterEncoding( String env ) - { - - } -} diff --git a/maven-repository-webapp/src/test/resources/unit/proxy-test/maven-proxy-complete.conf b/maven-repository-webapp/src/test/resources/unit/proxy-test/maven-proxy-complete.conf deleted file mode 100644 index 95f01bb30..000000000 --- a/maven-repository-webapp/src/test/resources/unit/proxy-test/maven-proxy-complete.conf +++ /dev/null @@ -1,145 +0,0 @@ -################ GLOBAL SETTINGS -# This is where maven-proxy stores files it has downloaded -#repo.local.store=/tmp/proxy-cache - -#The port to listen on - not used if loaded as a webapp -port=9999 - -#This is the base area that all files are loaded from. While it is possible to leave this blank, this behaviour -#is deprecated and will be disabled in version 2.0. There are too many namespace conflicts caused by not using -#a prefix. -#The repository will be shown at http://localhost:9999/repository/ -#for the .war loaded into a webapp server, the default prefix is "repository" (edit the web.xml to change) -# As maven doesn't like a trailing slash, this address shouldn't have one either. -prefix=repository - -#This is the simple date format used to display the last modified date while browsing the repository. -lastModifiedDateFormat=yyyy/MM/dd HH:mm:ss - -################ SNAPSHOT HANDLING -#If you want the proxy to look for newer snapshots, set to true -snapshot.update=true - -################ M2 METADATA HANDLING -#If you want the proxy to prevent looking for newer metadata, set to false (default is true) -#metadata.update=false - -################ M2 POM HANDLING -#If you want the proxy to look for newer POMs, set to true (default is false) -pom.update=true - -################ PROMOTION HANDLING -# ***** NOT CURRENTLY IMPLEMENTED ***** -#Promotion describes the process by which new artifacts are loaded to global maven-proxy repository. It -# is designed to be used by "higher security installations" that do not want to acquire artifacts from -# remote repositories without approval. -# -#If promotion handling is enabled, then the proxy will not download remote artifacts without permission -# (local repositories with copy=false are considered to be local) -# -#Permission to download is granted via the Promotion menu which will be enabled -# when promotion handling is enabled. -# -#If promotion is false, artifacts are sourced from any repository as per normal. -# -#Promotion and snapshots: If promotion is enabled, snapshots are not downloadable. The concept of using -# a snapshot in a production build (which is primarily what promotion is for) is counterintuitive. -## -promotion=false - -################ WEB INTERFACE -# This defines the absolute URL the server should use to identify itself. -# This can often be determined automatically, but we recommend you specify -# it explicitly to prevent problems during startup. -# The prefix will be added to this for the actual repository -# i.e. proxy available at http://localhost:9999/, repository at http://localhost:9999/repository -serverName=http://localhost:9999 - -#If true, the repository can be browsed -browsable=true - -#If true, the repository can be searched -searchable=true - -#Not currently implemented. Will allow webdav access to the repository at some point. -webdav=true - -#Stylesheet - if configured, will override the default stylesheet shipped with maven-proxy - absolute URLs only -#eg. /maven-proxy/style.css, http://www.example.com/style.css -stylesheet=/maven-proxy/style.css - -#bgColor / bgColorHighlight are replaced in the built in stylesheet to produce a simple color scheme. -#If a stylesheet is set, these are not used. -bgColor=#14B -bgColorHighlight=#94B - -#rowColor / rowColorHighlight are replaced in the built in stylesheet to produce a simple color scheme. -#If a stylesheet is set, these are not used. -rowColor=#CCF -rowColorHighlight=#DDF - - -################ PROXIES -#This is just a hack, it should auto discover them -#proxy.list=one,two,three -proxy.list= - -#Unauthenticated proxy -#proxy.one.host=proxy1.example.com -#proxy.one.port=3128 - -#Authenticated proxy -#proxy.two.host=proxy2.example.org -#proxy.two.port=80 -#proxy.two.username=username2 -#proxy.two.password=password2 - -#Authenticated proxy -#proxy.three.host=proxy3.example.net -#proxy.three.port=3129 -#proxy.three.username=username3 -#proxy.three.password=password3 - - -################# REPOSITORIES -#This is not just a hack, it specifies the order repositories should be checked -#Note that the proxy adds a "/" which is why the urls aren't suffixed with a "/" -repo.list=www-ibiblio-org - -#local-store -# The local store represents a location that local jars you host can be located. -# This could also be achieved by having a local http repository, but this is less cumbersome -repo.local-repo.url=file://target -repo.local-repo.description=Super Secret Custom Repository -#If copy is true, jars are copied from the store to the proxy-repo. Only configurable for file:/// repos -repo.local-repo.copy=false -#If hardfail is true, any unexpected errors from the repository will cause -#the client download to fail (typically with a 500 error) -repo.local-repo.hardfail=true -#Don't cache a file repository -repo.local-repo.cache.period=0 - - -#www.ibiblio.org -repo.www-ibiblio-org.url=http://www.ibiblio.org/maven2 -repo.www-ibiblio-org.description=www.ibiblio.org -repo.www-ibiblio-org.proxy= -repo.www-ibiblio-org.hardfail=true -#Cache this repository for 1 hour -repo.www-ibiblio-org.cache.period=3600 -repo.www-ibiblio-org.cache.failures=true - -#dist.codehaus.org -repo.dist-codehaus-org.url=http://dist.codehaus.org -repo.dist-codehaus-org.proxy=two -repo.dist-codehaus-org.hardfail=false -repo.dist-codehaus-org.cache.period=3600 -repo.dist-codehaus-org.cache.failures=true - -#private.example.com -repo.private-example-com.url=http://private.example.com/internal -repo.private-example-com.description=Commercial In Confidence Repository -repo.private-example-com.username=username1 -repo.private-example-com.password=password1 -repo.private-example-com.proxy=three -repo.private-example-com.cache.period=3600 diff --git a/pom.xml b/pom.xml index 46c227b97..8e57c63a8 100644 --- a/pom.xml +++ b/pom.xml @@ -22,13 +22,13 @@ 1 ../pom/maven/pom.xml - org.apache.maven.repository - maven-repository-manager + org.apache.maven.archiva + archiva pom - Maven Repository Manager + Archiva 1.0-SNAPSHOT - The Maven Repository Manager is an application for managing one or more remote repositories, including + Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching. @@ -115,19 +115,17 @@ - - maven-repository-artifact-applet - maven-repository-converter - maven-repository-discovery - maven-repository-reports-standard - maven-repository-indexer - maven-repository-utils - maven-repository-webapp - maven-repository-proxy - maven-repository-core - maven-repository-configuration + archiva-applet + archiva-converter + archiva-discoverer + archiva-reports-standard + archiva-indexer + archiva-utils + archiva-webapp + archiva-proxy + archiva-core + archiva-configuration + maven-meeper @@ -200,48 +198,48 @@ 1.0-alpha-6 - org.apache.maven.repository - maven-repository-core + org.apache.maven.archiva + archiva-core ${pom.version} - org.apache.maven.repository - maven-repository-reports-standard + org.apache.maven.archiva + archiva-reports-standard ${pom.version} - org.apache.maven.repository - maven-repository-discovery + org.apache.maven.archiva + archiva-discoverer ${pom.version} - org.apache.maven.repository - maven-repository-indexer + org.apache.maven.archiva + archiva-indexer ${pom.version} - org.apache.maven.repository - maven-repository-proxy + org.apache.maven.archiva + archiva-proxy ${pom.version} - org.apache.maven.repository - maven-repository-utils + org.apache.maven.archiva + archiva-utils ${pom.version} - org.apache.maven.repository - maven-repository-artifact-applet + org.apache.maven.archiva + archiva-applet ${pom.version} - org.apache.maven.repository - maven-repository-configuration + org.apache.maven.archiva + archiva-configuration ${pom.version} - org.apache.maven.repository - maven-repository-converter + org.apache.maven.archiva + archiva-converter ${pom.version}