Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b663026c721879648940a759b669361f00c80ca8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.releng.version.bucky;

import org.eclipse.emf.cdo.releng.version.BuildState;
import org.eclipse.emf.cdo.releng.version.Release;
import org.eclipse.emf.cdo.releng.version.VersionBuilder;
import org.eclipse.emf.cdo.releng.version.VersionValidator;

import org.eclipse.buckminster.cvspkg.internal.CVSSession;
import org.eclipse.buckminster.cvspkg.internal.RepositoryMetaData;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.team.internal.ccvs.core.CVSTag;
import org.eclipse.team.internal.ccvs.core.CVSTeamProvider;
import org.eclipse.team.internal.ccvs.core.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.ICVSResource;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;

import java.util.Date;

/**
 * @author Eike Stepper
 */
@SuppressWarnings("restriction")
public class BuckyValidator extends VersionValidator
{
  public BuckyValidator()
  {
  }

  @Override
  public void updateBuildState(BuildState buildState, String releasePath, Release release, IProject project,
      IResourceDelta delta, IProgressMonitor monitor) throws Exception
  {
    if (delta != null)
    {
      buildState.setChangedSinceRelease(true);
      return;
    }

    LocalModificationVisitor visitor = new LocalModificationVisitor(monitor);
    project.accept(visitor);
    if (visitor.isChanged())
    {
      buildState.setChangedSinceRelease(true);
      return;
    }

    CVSTeamProvider provider = (CVSTeamProvider)RepositoryProvider.getProvider(project);
    CVSWorkspaceRoot root = provider.getCVSWorkspaceRoot();
    String location = root.getRemoteLocation().getLocation(false);
    String module = root.getLocalRoot().getRepositoryRelativePath();
    String repositoryLocation = location + "," + module;

    VersionBuilder.trace("Bucky: Getting release timestamp...");
    CVSTag releaseTag = new CVSTag(release.getTag(), CVSTag.VERSION);
    Date releaseModification = getLastModification(repositoryLocation, releaseTag, monitor);

    ICVSFolder cvsProject = CVSWorkspaceRoot.getCVSFolderFor(project);
    FolderSyncInfo syncInfo = cvsProject.getFolderSyncInfo();
    CVSTag projectTag = syncInfo.getTag();
    if (projectTag == null)
    {
      projectTag = new CVSTag();
    }

    VersionBuilder.trace("Bucky: Getting project timestamp...");
    Date projectModification = getLastModification(repositoryLocation, projectTag, monitor);
    buildState.setChangedSinceRelease(!releaseModification.equals(projectModification));
  }

  private Date getLastModification(String repositoryLocation, CVSTag tag, IProgressMonitor monitor)
      throws CoreException
  {
    org.eclipse.buckminster.cvspkg.internal.CVSSession session = null;

    try
    {
      session = new CVSSession(repositoryLocation);
      RepositoryMetaData metaData = RepositoryMetaData.getMetaData(session, tag, monitor);
      return metaData.getLastModification();
    }
    finally
    {
      if (session != null)
      {
        session.close();
      }
    }
  }

  /**
   * @author Eike Stepper
   */
  private static final class LocalModificationVisitor implements IResourceVisitor
  {
    private IProgressMonitor monitor;

    private boolean changed;

    private LocalModificationVisitor(IProgressMonitor monitor)
    {
      this.monitor = monitor;
    }

    public boolean isChanged()
    {
      return changed;
    }

    public boolean visit(IResource resource) throws CoreException
    {
      ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
      if (cvsResource.isManaged())
      {
        VersionBuilder.trace("Bucky: " + resource.getFullPath());
        if (cvsResource.isModified(monitor))
        {
          changed = true;
          return false;
        }
      }

      return true;
    }
  }
}

Back to the top