[MRM-1282] sort the results for platform independance

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@911469 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2010-02-18 16:15:15 +00:00
parent 13f4b3cc1f
commit 13d0e893b2
1 changed files with 58 additions and 34 deletions

View File

@ -19,24 +19,6 @@ package org.apache.archiva.metadata.repository.file;
* under the License. * under the License.
*/ */
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.CiManagement; import org.apache.archiva.metadata.model.CiManagement;
import org.apache.archiva.metadata.model.Dependency; import org.apache.archiva.metadata.model.Dependency;
@ -57,6 +39,26 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
/** /**
* @plexus.component role="org.apache.archiva.metadata.repository.MetadataRepository" * @plexus.component role="org.apache.archiva.metadata.repository.MetadataRepository"
*/ */
@ -126,8 +128,8 @@ public class FileMetadataRepository
{ {
updateProject( repoId, namespace, projectId ); updateProject( repoId, namespace, projectId );
File directory = File directory = new File( getDirectory( repoId ),
new File( getDirectory( repoId ), namespace + "/" + projectId + "/" + versionMetadata.getId() ); namespace + "/" + projectId + "/" + versionMetadata.getId() );
Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY ); Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY );
// remove properties that are not references or artifacts // remove properties that are not references or artifacts
@ -288,8 +290,8 @@ public class FileMetadataRepository
Properties properties; Properties properties;
try try
{ {
properties = properties = readProperties( new File( getMetadataDirectory( repositoryId, facetId ), name ),
readProperties( new File( getMetadataDirectory( repositoryId, facetId ), name ), METADATA_KEY ); METADATA_KEY );
} }
catch ( FileNotFoundException e ) catch ( FileNotFoundException e )
{ {
@ -324,8 +326,8 @@ public class FileMetadataRepository
try try
{ {
File directory = File directory = new File( getMetadataDirectory( repositoryId, metadataFacet.getFacetId() ),
new File( getMetadataDirectory( repositoryId, metadataFacet.getFacetId() ), metadataFacet.getName() ); metadataFacet.getName() );
writeProperties( properties, directory, METADATA_KEY ); writeProperties( properties, directory, METADATA_KEY );
} }
catch ( IOException e ) catch ( IOException e )
@ -372,6 +374,7 @@ public class FileMetadataRepository
{ {
getArtifactsByDateRange( artifacts, repoId, ns, startTime, endTime ); getArtifactsByDateRange( artifacts, repoId, ns, startTime, endTime );
} }
Collections.sort( artifacts, new ArtifactComparator() );
return artifacts; return artifacts;
} }
@ -576,10 +579,10 @@ public class FileMetadataRepository
Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY ); Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY );
properties.setProperty( "artifact:updated:" + artifact.getId(), properties.setProperty( "artifact:updated:" + artifact.getId(), Long.toString(
Long.toString( artifact.getFileLastModified().getTime() ) ); artifact.getFileLastModified().getTime() ) );
properties.setProperty( "artifact:whenGathered:" + artifact.getId(), properties.setProperty( "artifact:whenGathered:" + artifact.getId(), Long.toString(
Long.toString( artifact.getWhenGathered().getTime() ) ); artifact.getWhenGathered().getTime() ) );
properties.setProperty( "artifact:size:" + artifact.getId(), Long.toString( artifact.getSize() ) ); properties.setProperty( "artifact:size:" + artifact.getId(), Long.toString( artifact.getSize() ) );
if ( artifact.getMd5() != null ) if ( artifact.getMd5() != null )
{ {
@ -738,8 +741,8 @@ public class FileMetadataRepository
MailingList mailingList = new MailingList(); MailingList mailingList = new MailingList();
mailingList.setName( mailingListName ); mailingList.setName( mailingListName );
mailingList.setMainArchiveUrl( properties.getProperty( "mailingList." + i + ".archive" ) ); mailingList.setMainArchiveUrl( properties.getProperty( "mailingList." + i + ".archive" ) );
mailingList.setOtherArchives( mailingList.setOtherArchives( Arrays.asList( properties.getProperty(
Arrays.asList( properties.getProperty( "mailingList." + i + ".otherArchives" ).split( "," ) ) ); "mailingList." + i + ".otherArchives" ).split( "," ) ) );
mailingList.setPostAddress( properties.getProperty( "mailingList." + i + ".post" ) ); mailingList.setPostAddress( properties.getProperty( "mailingList." + i + ".post" ) );
mailingList.setSubscribeAddress( properties.getProperty( "mailingList." + i + ".subscribe" ) ); mailingList.setSubscribeAddress( properties.getProperty( "mailingList." + i + ".subscribe" ) );
mailingList.setUnsubscribeAddress( properties.getProperty( "mailingList." + i + ".unsubscribe" ) ); mailingList.setUnsubscribeAddress( properties.getProperty( "mailingList." + i + ".unsubscribe" ) );
@ -763,8 +766,8 @@ public class FileMetadataRepository
dependency.setArtifactId( dependencyArtifactId ); dependency.setArtifactId( dependencyArtifactId );
dependency.setGroupId( properties.getProperty( "dependency." + i + ".groupId" ) ); dependency.setGroupId( properties.getProperty( "dependency." + i + ".groupId" ) );
dependency.setClassifier( properties.getProperty( "dependency." + i + ".classifier" ) ); dependency.setClassifier( properties.getProperty( "dependency." + i + ".classifier" ) );
dependency.setOptional( dependency.setOptional( Boolean.valueOf( properties.getProperty(
Boolean.valueOf( properties.getProperty( "dependency." + i + ".optional" ) ) ); "dependency." + i + ".optional" ) ) );
dependency.setScope( properties.getProperty( "dependency." + i + ".scope" ) ); dependency.setScope( properties.getProperty( "dependency." + i + ".scope" ) );
dependency.setSystemPath( properties.getProperty( "dependency." + i + ".systemPath" ) ); dependency.setSystemPath( properties.getProperty( "dependency." + i + ".systemPath" ) );
dependency.setType( properties.getProperty( "dependency." + i + ".type" ) ); dependency.setType( properties.getProperty( "dependency." + i + ".type" ) );
@ -848,8 +851,8 @@ public class FileMetadataRepository
reference.setProjectId( properties.getProperty( "ref:reference." + i + ".projectId" ) ); reference.setProjectId( properties.getProperty( "ref:reference." + i + ".projectId" ) );
reference.setNamespace( properties.getProperty( "ref:reference." + i + ".namespace" ) ); reference.setNamespace( properties.getProperty( "ref:reference." + i + ".namespace" ) );
reference.setProjectVersion( properties.getProperty( "ref:reference." + i + ".projectVersion" ) ); reference.setProjectVersion( properties.getProperty( "ref:reference." + i + ".projectVersion" ) );
reference.setReferenceType( ProjectVersionReference.ReferenceType.valueOf( reference.setReferenceType( ProjectVersionReference.ReferenceType.valueOf( properties.getProperty(
properties.getProperty( "ref:reference." + i + ".referenceType" ) ) ); "ref:reference." + i + ".referenceType" ) ) );
references.add( reference ); references.add( reference );
} }
return references; return references;
@ -956,4 +959,25 @@ public class FileMetadataRepository
{ {
this.configuration = configuration; this.configuration = configuration;
} }
private static class ArtifactComparator
implements Comparator<ArtifactMetadata>
{
public int compare( ArtifactMetadata artifact1, ArtifactMetadata artifact2 )
{
if ( artifact1.getWhenGathered() == artifact2.getWhenGathered() )
{
return 0;
}
if ( artifact1.getWhenGathered() == null )
{
return 1;
}
if ( artifact2.getWhenGathered() == null )
{
return -1;
}
return artifact1.getWhenGathered().compareTo( artifact2.getWhenGathered() );
}
}
} }