@Test public void testCheckMetadataNotWhenUpdatePolicyIsNeverAndTimestampIsUnavailable() throws Exception { UpdateCheck<Metadata, MetadataTransferException> check = newMetadataCheck(); check.setPolicy( RepositoryPolicy.UPDATE_POLICY_NEVER ); session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( true, false ) ); manager.checkMetadata( session, check ); assertEquals( false, check.isRequired() ); }
public void checkMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check ) { if ( check.getLocalLastUpdated() != 0 && !isUpdatedRequired( session, check.getLocalLastUpdated(), check.getPolicy() ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote request for " + check.getItem() + ", locally installed metadata up-to-date." ); } check.setRequired( false ); return; } Metadata metadata = check.getItem(); RemoteRepository repository = check.getRepository(); File metadataFile = check.getFile(); if ( metadataFile == null ) { throw new IllegalArgumentException( String.format( "The metadata '%s' has no file attached", metadata ) ); } boolean fileExists = check.isFileValid() && metadataFile.exists(); File touchFile = getTouchFile( metadata, metadataFile ); Properties props = read( touchFile ); String updateKey = getUpdateKey( session, metadataFile, repository ); String dataKey = getDataKey( metadata, metadataFile, check.getAuthoritativeRepository() ); String error = getError( props, dataKey ); long lastUpdated; if ( error == null ) { if ( fileExists ) { lastUpdated = getLastUpdated( props, dataKey ); } else { lastUpdated = 0; } } else if ( error.length() <= 0 ) { lastUpdated = getLastUpdated( props, dataKey ); } else { String transferKey = getTransferKey( session, metadata, metadataFile, repository ); lastUpdated = getLastUpdated( props, transferKey ); } if ( lastUpdated == 0 ) { check.setRequired( true ); } else if ( isAlreadyUpdated( session, updateKey ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote request for " + check.getItem() + ", already updated during this session." ); } check.setRequired( false ); if ( error != null ) { check.setException( newException( error, metadata, repository ) ); } } else if ( isUpdatedRequired( session, lastUpdated, check.getPolicy() ) ) { check.setRequired( true ); } else if ( fileExists ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote request for " + check.getItem() + ", locally cached metadata up-to-date." ); } check.setRequired( false ); } else { int errorPolicy = Utils.getPolicy( session, metadata, repository ); int cacheFlag = getCacheFlag( error ); if ( ( errorPolicy & cacheFlag ) != 0 ) { check.setRequired( false ); check.setException( newException( error, metadata, repository ) ); } else { check.setRequired( true ); } } }
DefaultUpdateCheckManager implements UpdateCheckManager, Service { public void checkMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check ) { if ( check.getLocalLastUpdated() != 0 && !isUpdatedRequired( session, check.getLocalLastUpdated(), check.getPolicy() ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote request for " + check.getItem() + ", locally installed metadata up-to-date." ); } check.setRequired( false ); return; } Metadata metadata = check.getItem(); RemoteRepository repository = check.getRepository(); File metadataFile = check.getFile(); if ( metadataFile == null ) { throw new IllegalArgumentException( String.format( "The metadata '%s' has no file attached", metadata ) ); } boolean fileExists = check.isFileValid() && metadataFile.exists(); File touchFile = getTouchFile( metadata, metadataFile ); Properties props = read( touchFile ); String updateKey = getUpdateKey( session, metadataFile, repository ); String dataKey = getDataKey( metadata, metadataFile, check.getAuthoritativeRepository() ); String error = getError( props, dataKey ); long lastUpdated; if ( error == null ) { if ( fileExists ) { lastUpdated = getLastUpdated( props, dataKey ); } else { lastUpdated = 0; } } else if ( error.length() <= 0 ) { lastUpdated = getLastUpdated( props, dataKey ); } else { String transferKey = getTransferKey( session, metadata, metadataFile, repository ); lastUpdated = getLastUpdated( props, transferKey ); } if ( lastUpdated == 0 ) { check.setRequired( true ); } else if ( isAlreadyUpdated( session, updateKey ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote request for " + check.getItem() + ", already updated during this session." ); } check.setRequired( false ); if ( error != null ) { check.setException( newException( error, metadata, repository ) ); } } else if ( isUpdatedRequired( session, lastUpdated, check.getPolicy() ) ) { check.setRequired( true ); } else if ( fileExists ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote request for " + check.getItem() + ", locally cached metadata up-to-date." ); } check.setRequired( false ); } else { int errorPolicy = Utils.getPolicy( session, metadata, repository ); int cacheFlag = getCacheFlag( error ); if ( ( errorPolicy & cacheFlag ) != 0 ) { check.setRequired( false ); check.setException( newException( error, metadata, repository ) ); } else { check.setRequired( true ); } } } }
DefaultUpdateCheckManager implements UpdateCheckManager, Service { public void checkMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check ) { if ( check.getLocalLastUpdated() != 0 && !isUpdatedRequired( session, check.getLocalLastUpdated(), check.getPolicy() ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote request for " + check.getItem() + ", locally installed metadata up-to-date." ); } check.setRequired( false ); return; } Metadata metadata = check.getItem(); RemoteRepository repository = check.getRepository(); File metadataFile = check.getFile(); if ( metadataFile == null ) { throw new IllegalArgumentException( String.format( "The metadata '%s' has no file attached", metadata ) ); } boolean fileExists = check.isFileValid() && metadataFile.exists(); File touchFile = getTouchFile( metadata, metadataFile ); Properties props = read( touchFile ); String updateKey = getUpdateKey( session, metadataFile, repository ); String dataKey = getDataKey( metadata, metadataFile, check.getAuthoritativeRepository() ); String error = getError( props, dataKey ); long lastUpdated; if ( error == null ) { if ( fileExists ) { lastUpdated = getLastUpdated( props, dataKey ); } else { lastUpdated = 0; } } else if ( error.length() <= 0 ) { lastUpdated = getLastUpdated( props, dataKey ); } else { String transferKey = getTransferKey( session, metadata, metadataFile, repository ); lastUpdated = getLastUpdated( props, transferKey ); } if ( lastUpdated == 0 ) { check.setRequired( true ); } else if ( isAlreadyUpdated( session, updateKey ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote request for " + check.getItem() + ", already updated during this session." ); } check.setRequired( false ); if ( error != null ) { check.setException( newException( error, metadata, repository ) ); } } else if ( isUpdatedRequired( session, lastUpdated, check.getPolicy() ) ) { check.setRequired( true ); } else if ( fileExists ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote request for " + check.getItem() + ", locally cached metadata up-to-date." ); } check.setRequired( false ); } else { int errorPolicy = Utils.getPolicy( session, metadata, repository ); int cacheFlag = getCacheFlag( error ); if ( ( errorPolicy & cacheFlag ) != 0 ) { check.setRequired( false ); check.setException( newException( error, metadata, repository ) ); } else { check.setRequired( true ); } } } DefaultUpdateCheckManager(); @Inject  DefaultUpdateCheckManager( UpdatePolicyAnalyzer updatePolicyAnalyzer, LoggerFactory loggerFactory ); }
DefaultUpdateCheckManager implements UpdateCheckManager, Service { public void checkMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check ) { if ( check.getLocalLastUpdated() != 0 && !isUpdatedRequired( session, check.getLocalLastUpdated(), check.getPolicy() ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote request for " + check.getItem() + ", locally installed metadata up-to-date." ); } check.setRequired( false ); return; } Metadata metadata = check.getItem(); RemoteRepository repository = check.getRepository(); File metadataFile = check.getFile(); if ( metadataFile == null ) { throw new IllegalArgumentException( String.format( "The metadata '%s' has no file attached", metadata ) ); } boolean fileExists = check.isFileValid() && metadataFile.exists(); File touchFile = getTouchFile( metadata, metadataFile ); Properties props = read( touchFile ); String updateKey = getUpdateKey( session, metadataFile, repository ); String dataKey = getDataKey( metadata, metadataFile, check.getAuthoritativeRepository() ); String error = getError( props, dataKey ); long lastUpdated; if ( error == null ) { if ( fileExists ) { lastUpdated = getLastUpdated( props, dataKey ); } else { lastUpdated = 0; } } else if ( error.length() <= 0 ) { lastUpdated = getLastUpdated( props, dataKey ); } else { String transferKey = getTransferKey( session, metadata, metadataFile, repository ); lastUpdated = getLastUpdated( props, transferKey ); } if ( lastUpdated == 0 ) { check.setRequired( true ); } else if ( isAlreadyUpdated( session, updateKey ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote request for " + check.getItem() + ", already updated during this session." ); } check.setRequired( false ); if ( error != null ) { check.setException( newException( error, metadata, repository ) ); } } else if ( isUpdatedRequired( session, lastUpdated, check.getPolicy() ) ) { check.setRequired( true ); } else if ( fileExists ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote request for " + check.getItem() + ", locally cached metadata up-to-date." ); } check.setRequired( false ); } else { int errorPolicy = Utils.getPolicy( session, metadata, repository ); int cacheFlag = getCacheFlag( error ); if ( ( errorPolicy & cacheFlag ) != 0 ) { check.setRequired( false ); check.setException( newException( error, metadata, repository ) ); } else { check.setRequired( true ); } } } DefaultUpdateCheckManager(); @Inject  DefaultUpdateCheckManager( UpdatePolicyAnalyzer updatePolicyAnalyzer, LoggerFactory loggerFactory ); void initService( ServiceLocator locator ); DefaultUpdateCheckManager setLoggerFactory( LoggerFactory loggerFactory ); DefaultUpdateCheckManager setUpdatePolicyAnalyzer( UpdatePolicyAnalyzer updatePolicyAnalyzer ); void checkArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check ); void checkMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check ); void touchArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check ); void touchMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check ); }
DefaultUpdateCheckManager implements UpdateCheckManager, Service { public void checkMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check ) { if ( check.getLocalLastUpdated() != 0 && !isUpdatedRequired( session, check.getLocalLastUpdated(), check.getPolicy() ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote request for " + check.getItem() + ", locally installed metadata up-to-date." ); } check.setRequired( false ); return; } Metadata metadata = check.getItem(); RemoteRepository repository = check.getRepository(); File metadataFile = check.getFile(); if ( metadataFile == null ) { throw new IllegalArgumentException( String.format( "The metadata '%s' has no file attached", metadata ) ); } boolean fileExists = check.isFileValid() && metadataFile.exists(); File touchFile = getTouchFile( metadata, metadataFile ); Properties props = read( touchFile ); String updateKey = getUpdateKey( session, metadataFile, repository ); String dataKey = getDataKey( metadata, metadataFile, check.getAuthoritativeRepository() ); String error = getError( props, dataKey ); long lastUpdated; if ( error == null ) { if ( fileExists ) { lastUpdated = getLastUpdated( props, dataKey ); } else { lastUpdated = 0; } } else if ( error.length() <= 0 ) { lastUpdated = getLastUpdated( props, dataKey ); } else { String transferKey = getTransferKey( session, metadata, metadataFile, repository ); lastUpdated = getLastUpdated( props, transferKey ); } if ( lastUpdated == 0 ) { check.setRequired( true ); } else if ( isAlreadyUpdated( session, updateKey ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote request for " + check.getItem() + ", already updated during this session." ); } check.setRequired( false ); if ( error != null ) { check.setException( newException( error, metadata, repository ) ); } } else if ( isUpdatedRequired( session, lastUpdated, check.getPolicy() ) ) { check.setRequired( true ); } else if ( fileExists ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote request for " + check.getItem() + ", locally cached metadata up-to-date." ); } check.setRequired( false ); } else { int errorPolicy = Utils.getPolicy( session, metadata, repository ); int cacheFlag = getCacheFlag( error ); if ( ( errorPolicy & cacheFlag ) != 0 ) { check.setRequired( false ); check.setException( newException( error, metadata, repository ) ); } else { check.setRequired( true ); } } } DefaultUpdateCheckManager(); @Inject  DefaultUpdateCheckManager( UpdatePolicyAnalyzer updatePolicyAnalyzer, LoggerFactory loggerFactory ); void initService( ServiceLocator locator ); DefaultUpdateCheckManager setLoggerFactory( LoggerFactory loggerFactory ); DefaultUpdateCheckManager setUpdatePolicyAnalyzer( UpdatePolicyAnalyzer updatePolicyAnalyzer ); void checkArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check ); void checkMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check ); void touchArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check ); void touchMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check );  }