Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6cd50ee6054fe52a4f194f652b76c494fdecc836 (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
/*******************************************************************************
 * Copyright (c) 2013 Boeing.
 * 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:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.ote.version.svn;

import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.ote.version.FileVersion;
import org.eclipse.osee.ote.version.FileVersionInformationProvider;
import org.eclipse.team.svn.core.connector.ISVNConnector;
import org.eclipse.team.svn.core.connector.SVNDepth;
import org.eclipse.team.svn.core.connector.SVNEntryInfo;
import org.eclipse.team.svn.core.connector.SVNEntryRevisionReference;
import org.eclipse.team.svn.core.extension.CoreExtensionsManager;
import org.eclipse.team.svn.core.operation.SVNNullProgressMonitor;
import org.eclipse.team.svn.core.utility.SVNUtility;

public class SvnVersionProvider implements FileVersionInformationProvider {

   protected boolean isSvn(File file) {
      File svn = new File(file, SVNUtility.getSVNFolderName());
      return svn.exists();
   }

   @Override
   public void getFileVersions(List<File> scriptFiles, Map<File, FileVersion> versions) {

      IProject[] workspaceProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
      ScriptToProject collection = new ScriptToProject(workspaceProjects);

      for (File scriptFile : scriptFiles) {
         collection.add(scriptFile);
      }

      ISVNConnector proxy = CoreExtensionsManager.instance().getSVNConnectorFactory().createConnector();
      for (String projectName : collection.getProjectsSet()) {
         try {
            SVNEntryInfo[] st =
               SVNUtility.info(proxy, new SVNEntryRevisionReference(projectName), SVNDepth.INFINITY,
                  new SVNNullProgressMonitor());
            for (SVNEntryInfo entry : st) {
               String svnEntryPath = entry.path;
               String itemToMatch = svnEntryPath.substring(svnEntryPath.lastIndexOf("/") + 1);
               File scriptFile = collection.getScriptFileMatch(projectName, itemToMatch);
               if (scriptFile != null) {
                  versions.put(scriptFile, new SvnFileVersion(entry));
               }
            }
         } catch (Exception ex) {
            OseeLog.logf(getClass(), Level.SEVERE, "SVNConnectorException while retrieving script SVN info ", ex);
         }
      }
   }
}

Back to the top