浏览代码

Changing time parameter

pull/51/head
Martin Stockhammer 4 年前
父节点
当前提交
379a72c3b7
共有 12 个文件被更改,包括 69 次插入50 次删除
  1. 4
    2
      archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java
  2. 3
    1
      archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java
  3. 3
    3
      archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java
  4. 3
    2
      archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java
  5. 9
    8
      archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java
  6. 14
    10
      archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java
  7. 4
    2
      archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/webtest/memory/TestMetadataRepository.java
  8. 5
    4
      archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java
  9. 8
    7
      archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java
  10. 6
    4
      archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java
  11. 6
    4
      archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
  12. 4
    3
      archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java

+ 4
- 2
archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java 查看文件

@@ -46,6 +46,8 @@ import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -69,7 +71,7 @@ public class ArchivaMetadataCreationConsumer
@Inject
private FileTypes filetypes;

private Date whenGathered;
private ZonedDateTime whenGathered;

private List<String> includes = new ArrayList<>( 0 );

@@ -120,7 +122,7 @@ public class ArchivaMetadataCreationConsumer
throws ConsumerException
{
repoId = repo.getId();
this.whenGathered = whenGathered;
this.whenGathered = ZonedDateTime.ofInstant(whenGathered.toInstant(), ZoneId.of("GMT"));
}

@Override

+ 3
- 1
archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java 查看文件

@@ -64,6 +64,8 @@ import java.io.Reader;
import java.nio.channels.Channels;
import java.nio.charset.Charset;
import java.nio.file.NoSuchFileException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@@ -740,7 +742,7 @@ public class Maven2RepositoryStorage
}

private static void populateArtifactMetadataFromFile(ArtifactMetadata metadata, StorageAsset file) throws IOException {
metadata.setWhenGathered(new Date());
metadata.setWhenGathered(ZonedDateTime.now(ZoneId.of("GMT")));
metadata.setFileLastModified(file.getModificationTime().toEpochMilli());
ChecksummedFile checksummedFile = new ChecksummedFile(file.getFilePath());
try {

+ 3
- 3
archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java 查看文件

@@ -97,7 +97,7 @@ public class NewArtifactsRssFeedProcessor
throws FeedException
{

ZonedDateTime greaterThanThisDate = ZonedDateTime.of(LocalDateTime.now(), GMT_TIME_ZONE.toZoneId()).minusDays(
ZonedDateTime greaterThanThisDate = ZonedDateTime.now(GMT_TIME_ZONE.toZoneId()).minusDays(
getNumberOfDaysBeforeNow()
).truncatedTo(ChronoUnit.SECONDS);
List<ArtifactMetadata> artifacts;
@@ -118,7 +118,7 @@ public class NewArtifactsRssFeedProcessor
int idx = 0;
for ( ArtifactMetadata artifact : artifacts )
{
long whenGathered = artifact.getWhenGathered().getTime();
long whenGathered = artifact.getWhenGathered().toInstant().toEpochMilli();

String id = artifact.getNamespace() + "/" + artifact.getProject() + "/" + artifact.getId();
if ( tmp != whenGathered )
@@ -133,7 +133,7 @@ public class NewArtifactsRssFeedProcessor
String repoId1 = artifact.getRepositoryId();
entry = new RssFeedEntry( this.getTitle() + "\'" + repoId1 + "\'" + " as of " + new Date(
whenGathered ) );
entry.setPublishedDate( artifact.getWhenGathered() );
entry.setPublishedDate( Date.from(artifact.getWhenGathered().toInstant()) );
description = this.getDescription() + "\'" + repoId1 + "\'" + ": \n" + id + " | ";
}
else

+ 3
- 2
archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java 查看文件

@@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@@ -116,7 +117,7 @@ public class NewVersionsOfArtifactRssFeedProcessor
int idx = 0;
for ( ArtifactMetadata artifact : artifacts )
{
long whenGathered = artifact.getWhenGathered().getTime();
long whenGathered = artifact.getWhenGathered().toInstant().toEpochMilli();

if ( tmp != whenGathered )
{
@@ -129,7 +130,7 @@ public class NewVersionsOfArtifactRssFeedProcessor

entry = new RssFeedEntry(
this.getTitle() + "\'" + groupId + ":" + artifactId + "\'" + " as of " + new Date( whenGathered ) );
entry.setPublishedDate( artifact.getWhenGathered() );
entry.setPublishedDate( Date.from(artifact.getWhenGathered().toInstant()) );
description =
this.getDescription() + "\'" + groupId + ":" + artifactId + "\'" + ": \n" + artifact.getId() +
" | ";

+ 9
- 8
archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java 查看文件

@@ -34,6 +34,8 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
@@ -95,7 +97,7 @@ public class NewArtifactsRssFeedProcessorTest
throws Exception
{
List<ArtifactMetadata> newArtifacts = new ArrayList<>();
Date whenGathered = Calendar.getInstance().getTime();
ZonedDateTime whenGathered = ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault());

newArtifacts.add( createArtifact( "artifact-one", "1.0", whenGathered ) );
newArtifacts.add( createArtifact( "artifact-one", "1.1", whenGathered ) );
@@ -115,9 +117,8 @@ public class NewArtifactsRssFeedProcessorTest
SyndFeed feed = newArtifactsProcessor.process( reqParams );

// check that the date used in the call is close to the one passed (5 seconds difference at most)
Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ) );
cal.add( Calendar.DATE, -30 );
assertTrue( metadataRepository.getFrom().minus(cal.getTimeInMillis(), ChronoUnit.MILLIS).toInstant().toEpochMilli() < 1000 * 5 );
ZonedDateTime cal = ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault()).minusDays(30);
assertTrue(ChronoUnit.SECONDS.between(cal.toInstant(), metadataRepository.getFrom().toInstant())<5);
assertEquals( null, metadataRepository.getTo() );
assertEquals( TEST_REPO, metadataRepository.getRepoId() );

@@ -125,16 +126,16 @@ public class NewArtifactsRssFeedProcessorTest
assertTrue(
feed.getDescription().equals( "New artifacts found in repository 'test-repo' during repository scan." ) );
assertTrue( feed.getLanguage().equals( "en-us" ) );
assertTrue( feed.getPublishedDate().equals( whenGathered ) );
assertTrue( feed.getPublishedDate().toInstant().equals( whenGathered.toInstant() ) );

List<SyndEntry> entries = feed.getEntries();
assertEquals( entries.size(), 1 );
assertTrue(
entries.get( 0 ).getTitle().equals( "New Artifacts in Repository 'test-repo' as of " + whenGathered ) );
assertTrue( entries.get( 0 ).getPublishedDate().equals( whenGathered ) );
entries.get( 0 ).getTitle().contains( "New Artifacts in Repository 'test-repo' as of " ));
assertTrue( entries.get( 0 ).getPublishedDate().toInstant().equals( whenGathered.toInstant() ) );
}

private ArtifactMetadata createArtifact( String artifactId, String version, Date whenGathered )
private ArtifactMetadata createArtifact( String artifactId, String version, ZonedDateTime whenGathered )
{
ArtifactMetadata artifact = new ArtifactMetadata();
artifact.setNamespace( "org.apache.archiva" );

+ 14
- 10
archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java 查看文件

@@ -40,6 +40,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;

import java.nio.file.Paths;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.TemporalAccessor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -119,12 +122,14 @@ public class NewVersionsOfArtifactRssFeedProcessorTest
public void testProcess()
throws Exception
{
Date whenGathered = new Date( 123456789 );
Date whenGatheredDate = new Date( 123456789 );
ZonedDateTime whenGathered = ZonedDateTime.ofInstant(whenGatheredDate.toInstant(), ZoneId.systemDefault());

ArtifactMetadata artifact1 = createArtifact( whenGathered, "1.0.1" );
ArtifactMetadata artifact2 = createArtifact( whenGathered, "1.0.2" );

Date whenGatheredNext = new Date( 345678912 );
Date whenGatheredNextDate = new Date( 345678912 );
ZonedDateTime whenGatheredNext = ZonedDateTime.ofInstant(whenGatheredNextDate.toInstant(), ZoneId.systemDefault());

ArtifactMetadata artifact3 = createArtifact( whenGatheredNext, "1.0.3-SNAPSHOT" );

@@ -148,24 +153,23 @@ public class NewVersionsOfArtifactRssFeedProcessorTest
assertEquals( "New versions of artifact 'org.apache.archiva:artifact-two' found during repository scan.",
feed.getDescription() );
assertEquals( "en-us", feed.getLanguage() );
assertEquals( whenGatheredNext, feed.getPublishedDate() );
assertEquals( whenGatheredNext.toInstant(), ZonedDateTime.ofInstant(feed.getPublishedDate().toInstant(), ZoneId.systemDefault()).toInstant() );

List<SyndEntry> entries = feed.getEntries();

assertEquals( 2, entries.size() );

assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGathered,
entries.get( 0 ).getTitle() );
assertEquals( whenGathered, entries.get( 0 ).getPublishedDate() );
assertTrue( entries.get(0).getTitle().contains("New Versions of Artifact 'org.apache.archiva:artifact-two' as of "));
assertEquals( whenGathered.toInstant(), entries.get( 0 ).getPublishedDate().toInstant() );

assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGatheredNext,
entries.get( 1 ).getTitle() );
assertEquals( whenGatheredNext, entries.get( 1 ).getPublishedDate() );
assertTrue(entries.get(1).getTitle().contains("New Versions of Artifact 'org.apache.archiva:artifact-two' as of "));
assertEquals( whenGatheredNext.toInstant(), entries.get( 1 ).getPublishedDate().toInstant() );

metadataRepositoryControl.verify();
}

private ArtifactMetadata createArtifact( Date whenGathered, String version )
private ArtifactMetadata createArtifact(ZonedDateTime whenGathered, String version )
{
ArtifactMetadata artifact = new ArtifactMetadata();
artifact.setNamespace( GROUP_ID );

+ 4
- 2
archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/webtest/memory/TestMetadataRepository.java 查看文件

@@ -23,6 +23,7 @@ import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.repository.AbstractMetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySession;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collection;
@@ -43,7 +44,8 @@ public class TestMetadataRepository

public TestMetadataRepository()
{
Date whenGathered = new Date( 123456789 );
Date whenGatheredDate = new Date( 123456789 );
ZonedDateTime whenGathered = ZonedDateTime.ofInstant(whenGatheredDate.toInstant(), ZoneId.systemDefault());

addArtifact( "artifact-one", "1.0", whenGathered );
addArtifact( "artifact-one", "1.1", whenGathered );
@@ -55,7 +57,7 @@ public class TestMetadataRepository
addArtifact( "artifact-four", "1.1-beta-2", whenGathered );
}

private void addArtifact( String projectId, String projectVersion, Date whenGathered )
private void addArtifact( String projectId, String projectVersion, ZonedDateTime whenGathered )
{
ArtifactMetadata artifact = new ArtifactMetadata();
artifact.setFileLastModified( System.currentTimeMillis() );

+ 5
- 4
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java 查看文件

@@ -20,6 +20,7 @@ package org.apache.archiva.metadata.model;
*/

import javax.xml.bind.annotation.XmlRootElement;
import java.time.ZonedDateTime;
import java.util.Date;

/**
@@ -96,7 +97,7 @@ public class ArtifactMetadata
/**
* When the artifact was found in the repository storage and added to the metadata content repository.
*/
private Date whenGathered;
private ZonedDateTime whenGathered;

public String getId()
{
@@ -143,7 +144,7 @@ public class ArtifactMetadata
this.fileLastModified = new Date( fileLastModified );
}

public void setWhenGathered( Date whenGathered )
public void setWhenGathered( ZonedDateTime whenGathered )
{
this.whenGathered = whenGathered;
}
@@ -158,7 +159,7 @@ public class ArtifactMetadata
this.sha1 = sha1;
}

public Date getWhenGathered()
public ZonedDateTime getWhenGathered()
{
return whenGathered;
}
@@ -269,7 +270,7 @@ public class ArtifactMetadata
{
return false;
}
if ( whenGathered != null ? !whenGathered.equals( that.whenGathered ) : that.whenGathered != null )
if ( whenGathered != null ? !whenGathered.toInstant().equals( that.whenGathered.toInstant() ) : that.whenGathered != null )
{
return false;
}

+ 8
- 7
archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java 查看文件

@@ -35,6 +35,7 @@ import org.springframework.format.annotation.NumberFormat;
import org.springframework.test.context.ContextConfiguration;

import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.TemporalUnit;
import java.util.*;
@@ -1224,7 +1225,7 @@ public abstract class AbstractMetadataRepositoryTest
getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
session.save( );

ZonedDateTime date = ZonedDateTime.from(artifact.getWhenGathered().toInstant()).minusSeconds(10);
ZonedDateTime date = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).minusSeconds(10);

tryAssert( ( ) -> {
List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, date, null );
@@ -1243,7 +1244,7 @@ public abstract class AbstractMetadataRepositoryTest
ArtifactMetadata artifact = createArtifact( );
getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );

ZonedDateTime date = ZonedDateTime.from(artifact.getWhenGathered().toInstant()).plusSeconds(10);
ZonedDateTime date = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).plusSeconds(10);

tryAssert( ( ) -> {
List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, date, null );
@@ -1263,8 +1264,8 @@ public abstract class AbstractMetadataRepositoryTest
getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
session.save( );

ZonedDateTime lower = ZonedDateTime.from(artifact.getWhenGathered().toInstant()).minusSeconds(10);
ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant()).plusSeconds(10);
ZonedDateTime lower = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).minusSeconds(10);
ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).plusSeconds(10);

tryAssert( ( ) -> {
List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, lower, upper );
@@ -1284,7 +1285,7 @@ public abstract class AbstractMetadataRepositoryTest
getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
session.save( );

ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant()).plusSeconds(10);
ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).plusSeconds(10);

tryAssert( ( ) -> {
List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, upper );
@@ -1304,7 +1305,7 @@ public abstract class AbstractMetadataRepositoryTest
getRepository( ).updateArtifact( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
session.save( );

ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant()).minusSeconds(10);
ZonedDateTime upper = ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())).minusSeconds(10);

tryAssert( ( ) -> {
List<ArtifactMetadata> artifacts = getRepository( ).getArtifactsByDateRange( session, TEST_REPO_ID, null, upper );
@@ -2208,7 +2209,7 @@ public abstract class AbstractMetadataRepositoryTest
{
ArtifactMetadata artifact = new ArtifactMetadata( );
artifact.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type );
artifact.setWhenGathered( new Date( ) );
artifact.setWhenGathered( ZonedDateTime.now() );
artifact.setNamespace( TEST_NAMESPACE );
artifact.setProject( TEST_PROJECT );
artifact.setRepositoryId( TEST_REPO_ID );

+ 6
- 4
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java 查看文件

@@ -69,6 +69,8 @@ import org.modelmapper.ModelMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collection;
@@ -1335,7 +1337,7 @@ public class CassandraMetadataRepository
// updater
ColumnFamilyUpdater<String, String> updater = this.artifactMetadataTemplate.createUpdater( key );
updater.setLong( FILE_LAST_MODIFIED.toString(), artifactMeta.getFileLastModified().getTime() );
updater.setLong( WHEN_GATHERED.toString(), artifactMeta.getWhenGathered().getTime() );
updater.setLong( WHEN_GATHERED.toString(), artifactMeta.getWhenGathered().toInstant().toEpochMilli() );
updater.setLong( SIZE.toString(), artifactMeta.getSize() );
addUpdateStringValue( updater, MD5.toString(), artifactMeta.getMd5() );
addUpdateStringValue( updater, SHA1.toString(), artifactMeta.getSha1() );
@@ -1357,7 +1359,7 @@ public class CassandraMetadataRepository
.addInsertion( key, cf, column( SIZE.toString(), artifactMeta.getSize() ) ) //
.addInsertion( key, cf, column( MD5.toString(), artifactMeta.getMd5() ) ) //
.addInsertion( key, cf, column( SHA1.toString(), artifactMeta.getSha1() ) ) //
.addInsertion( key, cf, column( WHEN_GATHERED.toString(), artifactMeta.getWhenGathered().getTime() ) )//
.addInsertion( key, cf, column( WHEN_GATHERED.toString(), artifactMeta.getWhenGathered().toInstant().toEpochMilli() ) )//
.execute();
}

@@ -1807,7 +1809,7 @@ public class CassandraMetadataRepository
Long whenGathered = getLongValue( columnSlice, WHEN_GATHERED.toString() );
if ( whenGathered != null )
{
artifactMetadata.setWhenGathered( new Date( whenGathered ) );
artifactMetadata.setWhenGathered(ZonedDateTime.ofInstant(Instant.ofEpochMilli(whenGathered), ZoneId.of("GMT")));
}
return artifactMetadata;
}
@@ -1828,7 +1830,7 @@ public class CassandraMetadataRepository
Long whenGathered = getAsLongValue( columnSlice, WHEN_GATHERED.toString() );
if ( whenGathered != null )
{
artifactMetadata.setWhenGathered( new Date( whenGathered ) );
artifactMetadata.setWhenGathered(ZonedDateTime.ofInstant(Instant.ofEpochMilli(whenGathered), ZoneId.of("GMT")));
}
return artifactMetadata;
}

+ 6
- 4
archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java 查看文件

@@ -52,6 +52,8 @@ import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
@@ -537,9 +539,9 @@ public class FileMetadataRepository
{
for ( ArtifactMetadata artifact : getArtifacts( session, repoId, ns, project, version ) )
{
if ( startTime == null || startTime.isBefore( ZonedDateTime.from(artifact.getWhenGathered().toInstant()) ) )
if ( startTime == null || startTime.isBefore( ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())) ) )
{
if ( endTime == null || endTime.isAfter( ZonedDateTime.from(artifact.getWhenGathered().toInstant()) ) )
if ( endTime == null || endTime.isAfter( ZonedDateTime.from(artifact.getWhenGathered().toInstant().atZone(ZoneId.systemDefault())) ) )
{
artifacts.add( artifact );
}
@@ -600,7 +602,7 @@ public class FileMetadataRepository
}
else if ( "whenGathered".equals( field ) )
{
artifact.setWhenGathered( new Date( Long.parseLong( value ) ) );
artifact.setWhenGathered( ZonedDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong( value )), ZoneId.of("GMT") ) );
}
else if ( "version".equals( field ) )
{
@@ -951,7 +953,7 @@ public class FileMetadataRepository
properties.setProperty( "artifact:updated:" + id,
Long.toString( artifact.getFileLastModified().getTime() ) );
properties.setProperty( "artifact:whenGathered:" + id,
Long.toString( artifact.getWhenGathered().getTime() ) );
Long.toString( artifact.getWhenGathered().toInstant().toEpochMilli()) );
properties.setProperty( "artifact:size:" + id, Long.toString( artifact.getSize() ) );
if ( artifact.getMd5() != null )
{

+ 4
- 3
archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java 查看文件

@@ -72,6 +72,7 @@ import javax.jcr.query.RowIterator;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.Map.Entry;
@@ -206,8 +207,7 @@ public class JcrMetadataRepository
cal.setTime( artifactMeta.getFileLastModified() );
node.setProperty( JCR_LAST_MODIFIED, cal );

cal = Calendar.getInstance();
cal.setTime( artifactMeta.getWhenGathered() );
cal = GregorianCalendar.from(artifactMeta.getWhenGathered());
node.setProperty( "whenGathered", cal );

node.setProperty( "size", artifactMeta.getSize() );
@@ -1671,7 +1671,8 @@ public class JcrMetadataRepository

if ( artifactNode.hasProperty( "whenGathered" ) )
{
artifact.setWhenGathered( artifactNode.getProperty( "whenGathered" ).getDate().getTime() );
Calendar cal = artifactNode.getProperty("whenGathered").getDate();
artifact.setWhenGathered( ZonedDateTime.ofInstant(cal.toInstant(), cal.getTimeZone().toZoneId()));
}

if ( artifactNode.hasProperty( "size" ) )

正在加载...
取消
保存