@Test public void testCheckArtifactWhenLocallyMissingEvenIfUpdatePolicyIsNever() throws Exception { UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck(); check.setPolicy( RepositoryPolicy.UPDATE_POLICY_NEVER ); session.setNotFoundCachingEnabled( true ); check.getFile().delete(); assertEquals( check.getFile().getAbsolutePath(), false, check.getFile().exists() ); manager.checkArtifact( session, check ); assertEquals( true, check.isRequired() ); }
public void checkArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check ) { if ( check.getLocalLastUpdated() != 0 && !isUpdatedRequired( session, check.getLocalLastUpdated(), check.getPolicy() ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote update check for " + check.getItem() + ", locally installed artifact up-to-date." ); } check.setRequired( false ); return; } Artifact artifact = check.getItem(); RemoteRepository repository = check.getRepository(); File artifactFile = check.getFile(); if ( artifactFile == null ) { throw new IllegalArgumentException( String.format( "The artifact '%s' has no file attached", artifact ) ); } boolean fileExists = check.isFileValid() && artifactFile.exists(); File touchFile = getTouchFile( artifact, artifactFile ); Properties props = read( touchFile ); String updateKey = getUpdateKey( artifactFile, repository ); String dataKey = getDataKey( artifact, artifactFile, repository ); String error = getError( props, dataKey ); long lastUpdated; if ( fileExists ) { lastUpdated = artifactFile.lastModified(); } else if ( error == null ) { lastUpdated = 0; } else if ( error.length() <= 0 ) { lastUpdated = getLastUpdated( props, dataKey ); } else { String transferKey = getTransferKey( artifact, artifactFile, repository ); lastUpdated = getLastUpdated( props, transferKey ); } if ( isAlreadyUpdated( session.getData(), updateKey ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote update check for " + check.getItem() + ", already updated during this session." ); } check.setRequired( false ); if ( error != null ) { check.setException( newException( error, artifact, repository ) ); } } else if ( lastUpdated == 0 ) { check.setRequired( true ); } else if ( isUpdatedRequired( session, lastUpdated, check.getPolicy() ) ) { check.setRequired( true ); } else if ( fileExists ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote update check for " + check.getItem() + ", locally cached artifact up-to-date." ); } check.setRequired( false ); } else { if ( error == null || error.length() <= 0 ) { if ( session.isNotFoundCachingEnabled() ) { check.setRequired( false ); check.setException( newException( error, artifact, repository ) ); } else { check.setRequired( true ); } } else { if ( session.isTransferErrorCachingEnabled() ) { check.setRequired( false ); check.setException( newException( error, artifact, repository ) ); } else { check.setRequired( true ); } } } }
DefaultUpdateCheckManager implements UpdateCheckManager, Service { public void checkArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check ) { if ( check.getLocalLastUpdated() != 0 && !isUpdatedRequired( session, check.getLocalLastUpdated(), check.getPolicy() ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote update check for " + check.getItem() + ", locally installed artifact up-to-date." ); } check.setRequired( false ); return; } Artifact artifact = check.getItem(); RemoteRepository repository = check.getRepository(); File artifactFile = check.getFile(); if ( artifactFile == null ) { throw new IllegalArgumentException( String.format( "The artifact '%s' has no file attached", artifact ) ); } boolean fileExists = check.isFileValid() && artifactFile.exists(); File touchFile = getTouchFile( artifact, artifactFile ); Properties props = read( touchFile ); String updateKey = getUpdateKey( artifactFile, repository ); String dataKey = getDataKey( artifact, artifactFile, repository ); String error = getError( props, dataKey ); long lastUpdated; if ( fileExists ) { lastUpdated = artifactFile.lastModified(); } else if ( error == null ) { lastUpdated = 0; } else if ( error.length() <= 0 ) { lastUpdated = getLastUpdated( props, dataKey ); } else { String transferKey = getTransferKey( artifact, artifactFile, repository ); lastUpdated = getLastUpdated( props, transferKey ); } if ( isAlreadyUpdated( session.getData(), updateKey ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote update check for " + check.getItem() + ", already updated during this session." ); } check.setRequired( false ); if ( error != null ) { check.setException( newException( error, artifact, repository ) ); } } else if ( lastUpdated == 0 ) { check.setRequired( true ); } else if ( isUpdatedRequired( session, lastUpdated, check.getPolicy() ) ) { check.setRequired( true ); } else if ( fileExists ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote update check for " + check.getItem() + ", locally cached artifact up-to-date." ); } check.setRequired( false ); } else { if ( error == null || error.length() <= 0 ) { if ( session.isNotFoundCachingEnabled() ) { check.setRequired( false ); check.setException( newException( error, artifact, repository ) ); } else { check.setRequired( true ); } } else { if ( session.isTransferErrorCachingEnabled() ) { check.setRequired( false ); check.setException( newException( error, artifact, repository ) ); } else { check.setRequired( true ); } } } } }
DefaultUpdateCheckManager implements UpdateCheckManager, Service { public void checkArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check ) { if ( check.getLocalLastUpdated() != 0 && !isUpdatedRequired( session, check.getLocalLastUpdated(), check.getPolicy() ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote update check for " + check.getItem() + ", locally installed artifact up-to-date." ); } check.setRequired( false ); return; } Artifact artifact = check.getItem(); RemoteRepository repository = check.getRepository(); File artifactFile = check.getFile(); if ( artifactFile == null ) { throw new IllegalArgumentException( String.format( "The artifact '%s' has no file attached", artifact ) ); } boolean fileExists = check.isFileValid() && artifactFile.exists(); File touchFile = getTouchFile( artifact, artifactFile ); Properties props = read( touchFile ); String updateKey = getUpdateKey( artifactFile, repository ); String dataKey = getDataKey( artifact, artifactFile, repository ); String error = getError( props, dataKey ); long lastUpdated; if ( fileExists ) { lastUpdated = artifactFile.lastModified(); } else if ( error == null ) { lastUpdated = 0; } else if ( error.length() <= 0 ) { lastUpdated = getLastUpdated( props, dataKey ); } else { String transferKey = getTransferKey( artifact, artifactFile, repository ); lastUpdated = getLastUpdated( props, transferKey ); } if ( isAlreadyUpdated( session.getData(), updateKey ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote update check for " + check.getItem() + ", already updated during this session." ); } check.setRequired( false ); if ( error != null ) { check.setException( newException( error, artifact, repository ) ); } } else if ( lastUpdated == 0 ) { check.setRequired( true ); } else if ( isUpdatedRequired( session, lastUpdated, check.getPolicy() ) ) { check.setRequired( true ); } else if ( fileExists ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote update check for " + check.getItem() + ", locally cached artifact up-to-date." ); } check.setRequired( false ); } else { if ( error == null || error.length() <= 0 ) { if ( session.isNotFoundCachingEnabled() ) { check.setRequired( false ); check.setException( newException( error, artifact, repository ) ); } else { check.setRequired( true ); } } else { if ( session.isTransferErrorCachingEnabled() ) { check.setRequired( false ); check.setException( newException( error, artifact, repository ) ); } else { check.setRequired( true ); } } } } DefaultUpdateCheckManager();  DefaultUpdateCheckManager( Logger logger ); }
DefaultUpdateCheckManager implements UpdateCheckManager, Service { public void checkArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check ) { if ( check.getLocalLastUpdated() != 0 && !isUpdatedRequired( session, check.getLocalLastUpdated(), check.getPolicy() ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote update check for " + check.getItem() + ", locally installed artifact up-to-date." ); } check.setRequired( false ); return; } Artifact artifact = check.getItem(); RemoteRepository repository = check.getRepository(); File artifactFile = check.getFile(); if ( artifactFile == null ) { throw new IllegalArgumentException( String.format( "The artifact '%s' has no file attached", artifact ) ); } boolean fileExists = check.isFileValid() && artifactFile.exists(); File touchFile = getTouchFile( artifact, artifactFile ); Properties props = read( touchFile ); String updateKey = getUpdateKey( artifactFile, repository ); String dataKey = getDataKey( artifact, artifactFile, repository ); String error = getError( props, dataKey ); long lastUpdated; if ( fileExists ) { lastUpdated = artifactFile.lastModified(); } else if ( error == null ) { lastUpdated = 0; } else if ( error.length() <= 0 ) { lastUpdated = getLastUpdated( props, dataKey ); } else { String transferKey = getTransferKey( artifact, artifactFile, repository ); lastUpdated = getLastUpdated( props, transferKey ); } if ( isAlreadyUpdated( session.getData(), updateKey ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote update check for " + check.getItem() + ", already updated during this session." ); } check.setRequired( false ); if ( error != null ) { check.setException( newException( error, artifact, repository ) ); } } else if ( lastUpdated == 0 ) { check.setRequired( true ); } else if ( isUpdatedRequired( session, lastUpdated, check.getPolicy() ) ) { check.setRequired( true ); } else if ( fileExists ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote update check for " + check.getItem() + ", locally cached artifact up-to-date." ); } check.setRequired( false ); } else { if ( error == null || error.length() <= 0 ) { if ( session.isNotFoundCachingEnabled() ) { check.setRequired( false ); check.setException( newException( error, artifact, repository ) ); } else { check.setRequired( true ); } } else { if ( session.isTransferErrorCachingEnabled() ) { check.setRequired( false ); check.setException( newException( error, artifact, repository ) ); } else { check.setRequired( true ); } } } } DefaultUpdateCheckManager();  DefaultUpdateCheckManager( Logger logger ); void initService( ServiceLocator locator ); DefaultUpdateCheckManager setLogger( Logger logger ); String getEffectiveUpdatePolicy( RepositorySystemSession session, String policy1, String policy2 ); void checkArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check ); void checkMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check ); boolean isUpdatedRequired( RepositorySystemSession session, long lastModified, String policy ); void touchArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check ); void touchMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check ); }
DefaultUpdateCheckManager implements UpdateCheckManager, Service { public void checkArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check ) { if ( check.getLocalLastUpdated() != 0 && !isUpdatedRequired( session, check.getLocalLastUpdated(), check.getPolicy() ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote update check for " + check.getItem() + ", locally installed artifact up-to-date." ); } check.setRequired( false ); return; } Artifact artifact = check.getItem(); RemoteRepository repository = check.getRepository(); File artifactFile = check.getFile(); if ( artifactFile == null ) { throw new IllegalArgumentException( String.format( "The artifact '%s' has no file attached", artifact ) ); } boolean fileExists = check.isFileValid() && artifactFile.exists(); File touchFile = getTouchFile( artifact, artifactFile ); Properties props = read( touchFile ); String updateKey = getUpdateKey( artifactFile, repository ); String dataKey = getDataKey( artifact, artifactFile, repository ); String error = getError( props, dataKey ); long lastUpdated; if ( fileExists ) { lastUpdated = artifactFile.lastModified(); } else if ( error == null ) { lastUpdated = 0; } else if ( error.length() <= 0 ) { lastUpdated = getLastUpdated( props, dataKey ); } else { String transferKey = getTransferKey( artifact, artifactFile, repository ); lastUpdated = getLastUpdated( props, transferKey ); } if ( isAlreadyUpdated( session.getData(), updateKey ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote update check for " + check.getItem() + ", already updated during this session." ); } check.setRequired( false ); if ( error != null ) { check.setException( newException( error, artifact, repository ) ); } } else if ( lastUpdated == 0 ) { check.setRequired( true ); } else if ( isUpdatedRequired( session, lastUpdated, check.getPolicy() ) ) { check.setRequired( true ); } else if ( fileExists ) { if ( logger.isDebugEnabled() ) { logger.debug( "Skipped remote update check for " + check.getItem() + ", locally cached artifact up-to-date." ); } check.setRequired( false ); } else { if ( error == null || error.length() <= 0 ) { if ( session.isNotFoundCachingEnabled() ) { check.setRequired( false ); check.setException( newException( error, artifact, repository ) ); } else { check.setRequired( true ); } } else { if ( session.isTransferErrorCachingEnabled() ) { check.setRequired( false ); check.setException( newException( error, artifact, repository ) ); } else { check.setRequired( true ); } } } } DefaultUpdateCheckManager();  DefaultUpdateCheckManager( Logger logger ); void initService( ServiceLocator locator ); DefaultUpdateCheckManager setLogger( Logger logger ); String getEffectiveUpdatePolicy( RepositorySystemSession session, String policy1, String policy2 ); void checkArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check ); void checkMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check ); boolean isUpdatedRequired( RepositorySystemSession session, long lastModified, String policy ); void touchArtifact( RepositorySystemSession session, UpdateCheck<Artifact, ArtifactTransferException> check ); void touchMetadata( RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check );  }