Mercurial > hg > mercurial
diff mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java @ 106:8587a9c22d55
switch to new API
author | Pavel.Sher |
---|---|
date | Tue, 11 May 2010 00:05:11 +0400 |
parents | 1b80570ddadf |
children | 80eb7fdc4de0 e8125034f6a9 |
line wrap: on
line diff
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Wed Apr 14 19:18:53 2010 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Tue May 11 00:05:11 2010 +0400 @@ -15,9 +15,7 @@ */ package jetbrains.buildServer.buildTriggers.vcs.mercurial; -import jetbrains.buildServer.AgentSideCheckoutAbility; import jetbrains.buildServer.BuildAgent; -import jetbrains.buildServer.CollectChangesByIncludeRule; import jetbrains.buildServer.Used; import jetbrains.buildServer.buildTriggers.vcs.AbstractVcsPropertiesProcessor; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.*; @@ -55,7 +53,7 @@ * <p>Working copy of repository is created in the $TEAMCITY_DATA_PATH/system/caches/hg_<hash code> folder. * <p>Personal builds (remote runs) are not yet supported, they require corresponding functionality from the IDE. */ -public class MercurialVcsSupport extends VcsSupport implements CollectChangesByIncludeRule, LabelingSupport, AgentSideCheckoutAbility { +public class MercurialVcsSupport extends ServerVcsSupport implements LabelingSupport, VcsFileContentProvider { private ConcurrentMap<String, Lock> myWorkDirLocks= new ConcurrentHashMap<String, Lock>(); private static final int OLD_WORK_DIRS_CLEANUP_PERIOD = 600; private VcsManager myVcsManager; @@ -65,7 +63,6 @@ @NotNull ServerPaths paths, @NotNull final SBuildServer server, @NotNull EventDispatcher<BuildServerListener> dispatcher) { - vcsManager.registerVcsSupport(this); myVcsManager = vcsManager; server.getExecutor().scheduleAtFixedRate(new Runnable() { public void run() { @@ -95,67 +92,6 @@ }); } - public List<ModificationData> collectBuildChanges(final VcsRoot root, - @NotNull final String fromVersion, - @NotNull final String currentVersion, - final CheckoutRules checkoutRules) throws VcsException { - syncClonedRepository(root); - return VcsSupportUtil.collectBuildChanges(root, fromVersion, currentVersion, checkoutRules, this); - } - - public List<ModificationData> collectBuildChanges(final VcsRoot root, - final String fromVersion, - final String currentVersion, - final IncludeRule includeRule) throws VcsException { - // first obtain changes between specified versions - List<ModificationData> result = new ArrayList<ModificationData>(); - Settings settings = createSettings(root); - LogCommand lc = new LogCommand(settings); - String fromId = new ChangeSetRevision(fromVersion).getId(); - lc.setFromRevId(fromId); - lc.setToRevId(new ChangeSetRevision(currentVersion).getId()); - List<ChangeSet> changeSets = lc.execute(); - if (changeSets.isEmpty()) { - return result; - } - - // invoke status command for each changeset and determine what files were modified in these changesets - StatusCommand st = new StatusCommand(settings); - ChangeSet prev = new ChangeSet(fromVersion); - for (ChangeSet cur : changeSets) { - if (cur.getId().equals(fromId)) continue; // skip already reported changeset - - String prevId = prev.getId(); - List<ChangeSetRevision> curParents = cur.getParents(); - boolean merge = curParents != null && curParents.size() > 1; - if (curParents != null && !merge) { - prevId = curParents.get(0).getId(); - } - - List<ModifiedFile> modifiedFiles = new ArrayList<ModifiedFile>(); - if (merge) { - modifiedFiles.addAll(computeModifiedFilesForMergeCommit(settings, cur)); - } else { - st.setFromRevId(prevId); - st.setToRevId(cur.getId()); - modifiedFiles = st.execute(); - } - - // changeset full version will be set into VcsChange structure and - // stored in database (note that getContent method will be invoked with this version) - List<VcsChange> files = toVcsChanges(modifiedFiles, prev.getFullVersion(), cur.getFullVersion(), includeRule); - if (files.isEmpty() && !merge) continue; - ModificationData md = new ModificationData(cur.getTimestamp(), files, cur.getDescription(), cur.getUser(), root, cur.getFullVersion(), cur.getId()); - if (merge) { - md.setCanBeIgnored(false); - } - result.add(md); - prev = cur; - } - - return result; - } - private Collection<ModifiedFile> computeModifiedFilesForMergeCommit(final Settings settings, final ChangeSet cur) throws VcsException { if (!cur.containsFiles()) return Collections.emptyList(); @@ -169,13 +105,14 @@ for (ModifiedFile mf: modifiedFiles) { String normalizedPath = PathUtil.normalizeSeparator(mf.getPath()); if (!normalizedPath.startsWith(includeRule.getFrom())) continue; // skip files which do not match include rule + String relPath = StringUtil.removeLeadingSlash(normalizedPath.substring(includeRule.getFrom().length())); VcsChangeInfo.Type changeType = getChangeType(mf.getStatus()); if (changeType == null) { Loggers.VCS.warn("Unable to convert status: " + mf.getStatus() + " to VCS change type"); changeType = VcsChangeInfo.Type.NOT_CHANGED; } - files.add(new VcsChange(changeType, mf.getStatus().getName(), normalizedPath, normalizedPath, prevVer, curVer)); + files.add(new VcsChange(changeType, mf.getStatus().getName(), normalizedPath, relPath, prevVer, curVer)); } return files; } @@ -272,26 +209,30 @@ return result.get(settings.getBranchName()).getFullVersion(); } + public boolean sourcesUpdatePossibleIfChangesNotFound(@NotNull final VcsRoot root) { + return false; + } + @NotNull public String describeVcsRoot(final VcsRoot vcsRoot) { return "mercurial: " + vcsRoot.getProperty(Constants.REPOSITORY_PROP); } - public boolean isTestConnectionSupported() { - return true; - } - - @Nullable - public String testConnection(@NotNull final VcsRoot vcsRoot) throws VcsException { - Settings settings = createSettings(vcsRoot); - IdentifyCommand id = new IdentifyCommand(settings); - StringBuilder res = new StringBuilder(); - res.append(quoteIfNeeded(settings.getHgCommandPath())); - res.append(" identify "); - final String obfuscatedUrl = CommandUtil.removePrivateData(settings.getRepositoryUrl(), Collections.singleton(settings.getPassword())); - res.append(quoteIfNeeded(obfuscatedUrl)); - res.append('\n').append(id.execute()); - return res.toString(); + @Override + public TestConnectionSupport getTestConnectionSupport() { + return new TestConnectionSupport() { + public String testConnection(@NotNull final VcsRoot vcsRoot) throws VcsException { + Settings settings = createSettings(vcsRoot); + IdentifyCommand id = new IdentifyCommand(settings); + StringBuilder res = new StringBuilder(); + res.append(quoteIfNeeded(settings.getHgCommandPath())); + res.append(" identify "); + final String obfuscatedUrl = CommandUtil.removePrivateData(settings.getRepositoryUrl(), Collections.singleton(settings.getPassword())); + res.append(quoteIfNeeded(obfuscatedUrl)); + res.append('\n').append(id.execute()); + return res.toString(); + } + }; } private String quoteIfNeeded(@NotNull String str) { @@ -330,20 +271,6 @@ }; } - public void buildPatch(@NotNull final VcsRoot root, - @Nullable final String fromVersion, - @NotNull final String toVersion, - @NotNull final PatchBuilder builder, - @NotNull final CheckoutRules checkoutRules) throws IOException, VcsException { - syncClonedRepository(root); - Settings settings = createSettings(root); - if (fromVersion == null) { - buildFullPatch(settings, new ChangeSet(toVersion), builder, checkoutRules); - } else { - buildIncrementalPatch(settings, new ChangeSet(fromVersion), new ChangeSet(toVersion), builder, checkoutRules); - } - } - // builds patch from version to version private void buildIncrementalPatch(final Settings settings, @NotNull final ChangeSet fromVer, @NotNull final ChangeSet toVer, final PatchBuilder builder, final CheckoutRules checkoutRules) throws VcsException, IOException { @@ -474,6 +401,98 @@ return this; } + @NotNull + public VcsFileContentProvider getContentProvider() { + return this; + } + + @NotNull + public CollectChangesPolicy getCollectChangesPolicy() { + return new CollectChangesByIncludeRules() { + @NotNull + public IncludeRuleChangeCollector getChangeCollector(@NotNull final VcsRoot root, @NotNull final String fromVersion, @Nullable final String currentVersion) throws VcsException { + return new IncludeRuleChangeCollector() { + @NotNull + public List<ModificationData> collectChanges(@NotNull final IncludeRule includeRule) throws VcsException { + syncClonedRepository(root); + + // first obtain changes between specified versions + List<ModificationData> result = new ArrayList<ModificationData>(); + if (currentVersion == null) return result; + + Settings settings = createSettings(root); + LogCommand lc = new LogCommand(settings); + String fromId = new ChangeSetRevision(fromVersion).getId(); + lc.setFromRevId(fromId); + lc.setToRevId(new ChangeSetRevision(currentVersion).getId()); + List<ChangeSet> changeSets = lc.execute(); + if (changeSets.isEmpty()) { + return result; + } + + // invoke status command for each changeset and determine what files were modified in these changesets + StatusCommand st = new StatusCommand(settings); + ChangeSet prev = new ChangeSet(fromVersion); + for (ChangeSet cur : changeSets) { + if (cur.getId().equals(fromId)) continue; // skip already reported changeset + + String prevId = prev.getId(); + List<ChangeSetRevision> curParents = cur.getParents(); + boolean merge = curParents != null && curParents.size() > 1; + if (curParents != null && !merge) { + prevId = curParents.get(0).getId(); + } + + List<ModifiedFile> modifiedFiles = new ArrayList<ModifiedFile>(); + if (merge) { + modifiedFiles.addAll(computeModifiedFilesForMergeCommit(settings, cur)); + } else { + st.setFromRevId(prevId); + st.setToRevId(cur.getId()); + modifiedFiles = st.execute(); + } + + // changeset full version will be set into VcsChange structure and + // stored in database (note that getContent method will be invoked with this version) + List<VcsChange> files = toVcsChanges(modifiedFiles, prev.getFullVersion(), cur.getFullVersion(), includeRule); + if (files.isEmpty() && !merge) continue; + ModificationData md = new ModificationData(cur.getTimestamp(), files, cur.getDescription(), cur.getUser(), root, cur.getFullVersion(), cur.getId()); + if (merge) { + md.setCanBeIgnored(false); + } + result.add(md); + prev = cur; + } + + return result; + } + + public void dispose() throws VcsException { + } + }; + } + }; + } + + @NotNull + public BuildPatchPolicy getBuildPatchPolicy() { + return new BuildPatchByCheckoutRules() { + public void buildPatch(@NotNull final VcsRoot root, + @Nullable final String fromVersion, + @NotNull final String toVersion, + @NotNull final PatchBuilder builder, + @NotNull final CheckoutRules checkoutRules) throws IOException, VcsException { + syncClonedRepository(root); + Settings settings = createSettings(root); + if (fromVersion == null) { + buildFullPatch(settings, new ChangeSet(toVersion), builder, checkoutRules); + } else { + buildIncrementalPatch(settings, new ChangeSet(fromVersion), new ChangeSet(toVersion), builder, checkoutRules); + } + } + }; + } + private void lockWorkDir(@NotNull File workDir) { getWorkDirLock(workDir).lock(); } @@ -483,10 +502,10 @@ } @Override - public boolean ignoreServerCachesFor(@NotNull final VcsRoot root) { + public boolean allowSourceCaching() { // since a copy of repository for each VCS root is already stored on disk - // we do not need separate cache for our patches - return true; + // we do not need separate cache for our patches + return false; } private Lock getWorkDirLock(final File workDir) {