@Test public void testIsUpdateRequired_PolicyAlways() throws Exception { String policy = RepositoryPolicy.UPDATE_POLICY_ALWAYS; assertEquals( true, analyzer.isUpdatedRequired( session, Long.MIN_VALUE, policy ) ); assertEquals( true, analyzer.isUpdatedRequired( session, Long.MAX_VALUE, policy ) ); assertEquals( true, analyzer.isUpdatedRequired( session, 0, policy ) ); assertEquals( true, analyzer.isUpdatedRequired( session, 1, policy ) ); assertEquals( true, analyzer.isUpdatedRequired( session, now() - 1000, policy ) ); }
public boolean isUpdatedRequired( RepositorySystemSession session, long lastModified, String policy ) { boolean checkForUpdates; if ( policy == null ) { policy = ""; } if ( RepositoryPolicy.UPDATE_POLICY_ALWAYS.equals( policy ) ) { checkForUpdates = true; } else if ( RepositoryPolicy.UPDATE_POLICY_DAILY.equals( policy ) ) { Calendar cal = Calendar.getInstance(); cal.set( Calendar.HOUR_OF_DAY, 0 ); cal.set( Calendar.MINUTE, 0 ); cal.set( Calendar.SECOND, 0 ); cal.set( Calendar.MILLISECOND, 0 ); checkForUpdates = cal.getTimeInMillis() > lastModified; } else if ( policy.startsWith( RepositoryPolicy.UPDATE_POLICY_INTERVAL ) ) { int minutes = getMinutes( policy ); Calendar cal = Calendar.getInstance(); cal.add( Calendar.MINUTE, -minutes ); checkForUpdates = cal.getTimeInMillis() > lastModified; } else { checkForUpdates = false; if ( !RepositoryPolicy.UPDATE_POLICY_NEVER.equals( policy ) ) { logger.warn( "Unknown repository update policy '" + policy + "', assuming '" + RepositoryPolicy.UPDATE_POLICY_NEVER + "'" ); } } return checkForUpdates; }
DefaultUpdatePolicyAnalyzer implements UpdatePolicyAnalyzer, Service { public boolean isUpdatedRequired( RepositorySystemSession session, long lastModified, String policy ) { boolean checkForUpdates; if ( policy == null ) { policy = ""; } if ( RepositoryPolicy.UPDATE_POLICY_ALWAYS.equals( policy ) ) { checkForUpdates = true; } else if ( RepositoryPolicy.UPDATE_POLICY_DAILY.equals( policy ) ) { Calendar cal = Calendar.getInstance(); cal.set( Calendar.HOUR_OF_DAY, 0 ); cal.set( Calendar.MINUTE, 0 ); cal.set( Calendar.SECOND, 0 ); cal.set( Calendar.MILLISECOND, 0 ); checkForUpdates = cal.getTimeInMillis() > lastModified; } else if ( policy.startsWith( RepositoryPolicy.UPDATE_POLICY_INTERVAL ) ) { int minutes = getMinutes( policy ); Calendar cal = Calendar.getInstance(); cal.add( Calendar.MINUTE, -minutes ); checkForUpdates = cal.getTimeInMillis() > lastModified; } else { checkForUpdates = false; if ( !RepositoryPolicy.UPDATE_POLICY_NEVER.equals( policy ) ) { logger.warn( "Unknown repository update policy '" + policy + "', assuming '" + RepositoryPolicy.UPDATE_POLICY_NEVER + "'" ); } } return checkForUpdates; } }
DefaultUpdatePolicyAnalyzer implements UpdatePolicyAnalyzer, Service { public boolean isUpdatedRequired( RepositorySystemSession session, long lastModified, String policy ) { boolean checkForUpdates; if ( policy == null ) { policy = ""; } if ( RepositoryPolicy.UPDATE_POLICY_ALWAYS.equals( policy ) ) { checkForUpdates = true; } else if ( RepositoryPolicy.UPDATE_POLICY_DAILY.equals( policy ) ) { Calendar cal = Calendar.getInstance(); cal.set( Calendar.HOUR_OF_DAY, 0 ); cal.set( Calendar.MINUTE, 0 ); cal.set( Calendar.SECOND, 0 ); cal.set( Calendar.MILLISECOND, 0 ); checkForUpdates = cal.getTimeInMillis() > lastModified; } else if ( policy.startsWith( RepositoryPolicy.UPDATE_POLICY_INTERVAL ) ) { int minutes = getMinutes( policy ); Calendar cal = Calendar.getInstance(); cal.add( Calendar.MINUTE, -minutes ); checkForUpdates = cal.getTimeInMillis() > lastModified; } else { checkForUpdates = false; if ( !RepositoryPolicy.UPDATE_POLICY_NEVER.equals( policy ) ) { logger.warn( "Unknown repository update policy '" + policy + "', assuming '" + RepositoryPolicy.UPDATE_POLICY_NEVER + "'" ); } } return checkForUpdates; } DefaultUpdatePolicyAnalyzer(); @Inject  DefaultUpdatePolicyAnalyzer( LoggerFactory loggerFactory ); }
DefaultUpdatePolicyAnalyzer implements UpdatePolicyAnalyzer, Service { public boolean isUpdatedRequired( RepositorySystemSession session, long lastModified, String policy ) { boolean checkForUpdates; if ( policy == null ) { policy = ""; } if ( RepositoryPolicy.UPDATE_POLICY_ALWAYS.equals( policy ) ) { checkForUpdates = true; } else if ( RepositoryPolicy.UPDATE_POLICY_DAILY.equals( policy ) ) { Calendar cal = Calendar.getInstance(); cal.set( Calendar.HOUR_OF_DAY, 0 ); cal.set( Calendar.MINUTE, 0 ); cal.set( Calendar.SECOND, 0 ); cal.set( Calendar.MILLISECOND, 0 ); checkForUpdates = cal.getTimeInMillis() > lastModified; } else if ( policy.startsWith( RepositoryPolicy.UPDATE_POLICY_INTERVAL ) ) { int minutes = getMinutes( policy ); Calendar cal = Calendar.getInstance(); cal.add( Calendar.MINUTE, -minutes ); checkForUpdates = cal.getTimeInMillis() > lastModified; } else { checkForUpdates = false; if ( !RepositoryPolicy.UPDATE_POLICY_NEVER.equals( policy ) ) { logger.warn( "Unknown repository update policy '" + policy + "', assuming '" + RepositoryPolicy.UPDATE_POLICY_NEVER + "'" ); } } return checkForUpdates; } DefaultUpdatePolicyAnalyzer(); @Inject  DefaultUpdatePolicyAnalyzer( LoggerFactory loggerFactory ); void initService( ServiceLocator locator ); DefaultUpdatePolicyAnalyzer setLoggerFactory( LoggerFactory loggerFactory ); String getEffectiveUpdatePolicy( RepositorySystemSession session, String policy1, String policy2 ); boolean isUpdatedRequired( RepositorySystemSession session, long lastModified, String policy ); }
DefaultUpdatePolicyAnalyzer implements UpdatePolicyAnalyzer, Service { public boolean isUpdatedRequired( RepositorySystemSession session, long lastModified, String policy ) { boolean checkForUpdates; if ( policy == null ) { policy = ""; } if ( RepositoryPolicy.UPDATE_POLICY_ALWAYS.equals( policy ) ) { checkForUpdates = true; } else if ( RepositoryPolicy.UPDATE_POLICY_DAILY.equals( policy ) ) { Calendar cal = Calendar.getInstance(); cal.set( Calendar.HOUR_OF_DAY, 0 ); cal.set( Calendar.MINUTE, 0 ); cal.set( Calendar.SECOND, 0 ); cal.set( Calendar.MILLISECOND, 0 ); checkForUpdates = cal.getTimeInMillis() > lastModified; } else if ( policy.startsWith( RepositoryPolicy.UPDATE_POLICY_INTERVAL ) ) { int minutes = getMinutes( policy ); Calendar cal = Calendar.getInstance(); cal.add( Calendar.MINUTE, -minutes ); checkForUpdates = cal.getTimeInMillis() > lastModified; } else { checkForUpdates = false; if ( !RepositoryPolicy.UPDATE_POLICY_NEVER.equals( policy ) ) { logger.warn( "Unknown repository update policy '" + policy + "', assuming '" + RepositoryPolicy.UPDATE_POLICY_NEVER + "'" ); } } return checkForUpdates; } DefaultUpdatePolicyAnalyzer(); @Inject  DefaultUpdatePolicyAnalyzer( LoggerFactory loggerFactory ); void initService( ServiceLocator locator ); DefaultUpdatePolicyAnalyzer setLoggerFactory( LoggerFactory loggerFactory ); String getEffectiveUpdatePolicy( RepositorySystemSession session, String policy1, String policy2 ); boolean isUpdatedRequired( RepositorySystemSession session, long lastModified, String policy );  }