Author: adamw Date: 2006-05-04 12:52:14 -0400 (Thu, 04 May 2006) New Revision: 4093 Modified: labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/shotoku/web/admin/UpdateServlet.java labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnTools.java labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnRepository.java labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java Log: http://jira.jboss.com/jira/browse/JBSHOTOKU-31 Modified: labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/shotoku/web/admin/UpdateServlet.java =================================================================== --- labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/shotoku/web/admin/UpdateServlet.java 2006-05-04 16:52:03 UTC (rev 4092) +++ labs/shotoku/trunk/shotoku-admin/src/java/org/jboss/shotoku/web/admin/UpdateServlet.java 2006-05-04 16:52:14 UTC (rev 4093) @@ -18,6 +18,7 @@ HttpServletResponse response) throws ServletException, IOException { String data = request.getParameter("data"); + System.out.println("DATA: " + data); if (data == null) { return; } @@ -32,7 +33,7 @@ Set<String> toUpdate = new HashSet<String>(); String current = tokens[0]; - toUpdate.add(current); + /*toUpdate.add(current); for (String token : tokens) { if (!"".equals(token) && !token.startsWith(current)) { @@ -47,7 +48,7 @@ System.out.println("Rev: " + revision + ", id: " + id); - SvnTools.getService().addPathsToUpdate(id, revision, toUpdate); + //SvnTools.getService().addPathsToUpdate(id, revision, toUpdate); */ } catch (Exception e) { // In case of an exception, doing nothing. } Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java =================================================================== --- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java 2006-05-04 16:52:03 UTC (rev 4092) +++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java 2006-05-04 16:52:14 UTC (rev 4093) @@ -562,10 +562,10 @@ implClass.getConstructor(String.class, String.class, Configuration.class), conf)); - Set<String> implIds = implementationsIds.get(id); + Set<String> implIds = implementationsIds.get(implementation); if (implIds == null) { implIds = new HashSet<String>(); - implementationsIds.put(id, implIds); + implementationsIds.put(implementation, implIds); } implIds.add(id); Modified: labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnTools.java =================================================================== --- labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnTools.java 2006-05-04 16:52:03 UTC (rev 4092) +++ labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnTools.java 2006-05-04 16:52:14 UTC (rev 4093) @@ -58,6 +58,7 @@ public static final String PROPERTY_URL = "url"; public static final String PROPERTY_PASSWORD = "password"; public static final String PROPERTY_LOCALPATH = "localpath"; + public static final String PROPERTY_FULLUPDATE = "fullupdate"; /* * Names of internal shotoku properties. Modified: labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnRepository.java =================================================================== --- labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnRepository.java 2006-05-04 16:52:03 UTC (rev 4092) +++ labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnRepository.java 2006-05-04 16:52:14 UTC (rev 4093) @@ -65,6 +65,15 @@ private ConcurrentSet<String> frozenModifiedTrees; private ConcurrentSet<String> frozenDeletedResources; + /** + * Number of updates after which a full WC update is done. + */ + private int fullUpdate; + /** + * Number of updates since last full WC update. + */ + private int updateCounter; + private Set<Pair<Long, Set<String>>> toUpdate; /** @@ -78,25 +87,22 @@ private ContentManager cm; public SvnRepository(String id, String username, String password, - String url, String localpath) { + String url, String localpath, int fullUpdate) { log.info("Creating new Subversion Repository: id: "+id+ ", username: "+username+ ", passwd: "+password+ ", url: "+url+ ", localpath: "+localpath); ISVNOptions options = SVNWCUtil.createDefaultOptions(true); - log.info(" Creating new SVNClientManager..."); ourClientManager = SVNClientManager.newInstance(options, username, password); - log.info(" SVNClientManager created."); try { repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded( url)); - log.info(" SVNRepositoryFactory.create() call successful. Setting AuthenticationManager..."); + log.info(" SVNRepositoryFactory.create() call successful."); repository.setAuthenticationManager( SVNWCUtil.createDefaultAuthenticationManager(username, password)); - log.info(" AuthenticationManager set using given username and passwd."); } catch (SVNException e) { log.warn("Error while creating SVNRepository.", e); } @@ -106,6 +112,9 @@ this.url = url; this.id = id; + this.fullUpdate = fullUpdate; + updateCounter = 0; + wc = new File(localpath); modifiedTrees = new ConcurrentHashSet<String>(); @@ -151,9 +160,41 @@ * Updates the local working copy. */ public void update() { - update(false, true); + updateCounter++; + if (updateCounter == fullUpdate) { + // Everything will be updated anyway. + toUpdate.clear(); + update(false, true); + + updateCounter = 0; + } else { + // Only updating the "toUpdate" resources. + updateToUpdate(); + } } + private void updateToUpdate() { + SVNUpdateClient updateClient = ourClientManager.getUpdateClient(); + updateClient.setIgnoreExternals(false); + + for (Iterator<Pair<Long, Set<String>>> iter = toUpdate.iterator(); iter.hasNext();) { + Pair<Long, Set<String>> updateData = iter.next(); + // Only updating if the data is newer then the current one in the wc. + if (updateData.getFirst() > lastRevision) { + for (String path : updateData.getSecond()) { + File wcPath = new File(wc.getPath() + File.separator + path); + try { + updateClient.doUpdate(wcPath, SVNRevision.HEAD, true); + } catch (SVNException e) { + log.warn("Error updating a modified path: " + path + ".", e); + } + } + } + + iter.remove(); + } + } + /** * Updates the repository. If it fails, and <code>tryCheckout</code> is * set to true, a checkout is attempted; if it set to false, and @@ -200,8 +241,6 @@ // Doing the actual update. try { - SVNURL repositoryURL = SVNURL.parseURIEncoded(url); - SVNUpdateClient updateClient = ourClientManager.getUpdateClient(); updateClient.setIgnoreExternals(false); try { @@ -213,6 +252,8 @@ lastRevision = updateClient.doUpdate(wc, SVNRevision.HEAD, true); } catch (SVNException e) { + SVNURL repositoryURL = SVNURL.parseURIEncoded(url); + if (tryCheckout) { updateClient.doCheckout(repositoryURL, wc, SVNRevision.HEAD, SVNRevision.HEAD, true); Modified: labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java =================================================================== --- labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java 2006-05-04 16:52:03 UTC (rev 4092) +++ labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java 2006-05-04 16:52:14 UTC (rev 4093) @@ -175,7 +175,8 @@ conf.getString(SvnTools.PROPERTY_USERNAME), conf.getString(SvnTools.PROPERTY_PASSWORD), conf.getString(SvnTools.PROPERTY_URL), - conf.getString(SvnTools.PROPERTY_LOCALPATH)); + conf.getString(SvnTools.PROPERTY_LOCALPATH), + conf.getInt(SvnTools.PROPERTY_FULLUPDATE, 1)); repositories.put(id, repo); |