mirror of https://github.com/apache/archiva.git
[MRM-125] separate the timestamp for the metadata and the artifacts to ensure both get resolved
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@425044 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a12af7203c
commit
7e0bf5be8d
|
@ -18,13 +18,16 @@ package org.apache.maven.repository.discovery;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
|
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for artifact discoverers.
|
* Base class for artifact discoverers.
|
||||||
|
@ -58,7 +61,8 @@ public abstract class AbstractArtifactDiscoverer
|
||||||
throw new UnsupportedOperationException( "Only filesystem repositories are supported" );
|
throw new UnsupportedOperationException( "Only filesystem repositories are supported" );
|
||||||
}
|
}
|
||||||
|
|
||||||
long comparisonTimestamp = readComparisonTimestamp( repository, operation );
|
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
|
// 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.
|
// mid-discovery and missed by the scanner will get checked next time.
|
||||||
|
@ -126,4 +130,20 @@ public abstract class AbstractArtifactDiscoverer
|
||||||
|
|
||||||
return artifact;
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -142,11 +141,8 @@ public abstract class AbstractDiscoverer
|
||||||
return excludedPaths.iterator();
|
return excludedPaths.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected long readComparisonTimestamp( ArtifactRepository repository, String operation )
|
protected long readComparisonTimestamp( ArtifactRepository repository, String operation, Xpp3Dom dom )
|
||||||
{
|
{
|
||||||
File file = new File( repository.getBasedir(), "maven-metadata.xml" );
|
|
||||||
Xpp3Dom dom = readDom( file );
|
|
||||||
dom = getLastDiscoveryDom( dom );
|
|
||||||
Xpp3Dom entry = dom.getChild( operation );
|
Xpp3Dom entry = dom.getChild( operation );
|
||||||
long comparisonTimestamp = 0;
|
long comparisonTimestamp = 0;
|
||||||
if ( entry != null )
|
if ( entry != null )
|
||||||
|
@ -194,13 +190,24 @@ public abstract class AbstractDiscoverer
|
||||||
return dom;
|
return dom;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Xpp3Dom getLastDiscoveryDom( Xpp3Dom dom )
|
protected Xpp3Dom getLastArtifactDiscoveryDom( Xpp3Dom dom )
|
||||||
{
|
{
|
||||||
Xpp3Dom lastDiscoveryDom = dom.getChild( "lastDiscovery" );
|
Xpp3Dom lastDiscoveryDom = dom.getChild( "lastArtifactDiscovery" );
|
||||||
if ( lastDiscoveryDom == null )
|
if ( lastDiscoveryDom == null )
|
||||||
{
|
{
|
||||||
dom.addChild( new Xpp3Dom( "lastDiscovery" ) );
|
dom.addChild( new Xpp3Dom( "lastArtifactDiscovery" ) );
|
||||||
lastDiscoveryDom = dom.getChild( "lastDiscovery" );
|
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;
|
return lastDiscoveryDom;
|
||||||
}
|
}
|
||||||
|
@ -218,8 +225,26 @@ public abstract class AbstractDiscoverer
|
||||||
|
|
||||||
Xpp3Dom dom = readDom( file );
|
Xpp3Dom dom = readDom( file );
|
||||||
|
|
||||||
Xpp3Dom lastDiscoveryDom = getLastDiscoveryDom( dom );
|
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;
|
boolean changed = false;
|
||||||
|
|
||||||
// do this in reverse so that removing doesn't affect counter
|
// do this in reverse so that removing doesn't affect counter
|
||||||
|
@ -232,14 +257,10 @@ public abstract class AbstractDiscoverer
|
||||||
lastDiscoveryDom.removeChild( i );
|
lastDiscoveryDom.removeChild( i );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return changed;
|
||||||
if ( changed )
|
|
||||||
{
|
|
||||||
saveDom( file, dom );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveDom( File file, Xpp3Dom dom )
|
protected void saveDom( File file, Xpp3Dom dom )
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
FileWriter writer = new FileWriter( file );
|
FileWriter writer = new FileWriter( file );
|
||||||
|
@ -255,25 +276,19 @@ public abstract class AbstractDiscoverer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastCheckedTime( ArtifactRepository repository, String operation, Date date )
|
protected void setEntry( Xpp3Dom lastDiscoveryDom, String operation, String dateString )
|
||||||
throws IOException
|
|
||||||
{
|
{
|
||||||
// see notes in resetLastCheckedTime
|
|
||||||
|
|
||||||
File file = new File( repository.getBasedir(), "maven-metadata.xml" );
|
|
||||||
|
|
||||||
Xpp3Dom dom = readDom( file );
|
|
||||||
|
|
||||||
Xpp3Dom lastDiscoveryDom = getLastDiscoveryDom( dom );
|
|
||||||
|
|
||||||
Xpp3Dom entry = lastDiscoveryDom.getChild( operation );
|
Xpp3Dom entry = lastDiscoveryDom.getChild( operation );
|
||||||
if ( entry == null )
|
if ( entry == null )
|
||||||
{
|
{
|
||||||
entry = new Xpp3Dom( operation );
|
entry = new Xpp3Dom( operation );
|
||||||
lastDiscoveryDom.addChild( entry );
|
lastDiscoveryDom.addChild( entry );
|
||||||
}
|
}
|
||||||
entry.setValue( new SimpleDateFormat( DATE_FMT, Locale.US ).format( date ) );
|
entry.setValue( dateString );
|
||||||
|
}
|
||||||
|
|
||||||
saveDom( file, dom );
|
protected Xpp3Dom readRepositoryMetadataDom( ArtifactRepository repository )
|
||||||
|
{
|
||||||
|
return readDom( new File( repository.getBasedir(), "maven-metadata.xml" ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
|
||||||
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
|
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
|
||||||
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -34,11 +35,13 @@ import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,7 +66,8 @@ public class DefaultMetadataDiscoverer
|
||||||
throw new UnsupportedOperationException( "Only filesystem repositories are supported" );
|
throw new UnsupportedOperationException( "Only filesystem repositories are supported" );
|
||||||
}
|
}
|
||||||
|
|
||||||
long comparisonTimestamp = readComparisonTimestamp( repository, operation );
|
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
|
// 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.
|
// mid-discovery and missed by the scanner will get checked next time.
|
||||||
|
@ -226,4 +230,20 @@ public class DefaultMetadataDiscoverer
|
||||||
|
|
||||||
return metadata;
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue