Package tool.repository

Source Code of tool.repository.RepositorySync

package tool.repository;

import java.util.LinkedHashSet;
import java.util.Set;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;

import tool.ToolPlugin;
import tool.ToolProjectSupport;
import tool.builder.ToolBuilder;
import tool.model.ToolPlan;

public class RepositorySync implements IRunnableWithProgress {
  private IProject project;
 
  public RepositorySync(IProject project) {
    super();
    this.project = project;
  }

  @Override
  public void run(IProgressMonitor monitor) {
    Assert.isNotNull(this.project);
    RepositorySession session = RepositorySession.getRepositorySession(project);

    Set<ToolPlan> plans = ToolProjectSupport.getAllPlansForProject(this.project);
    monitor.beginTask("Repository Sync", plans.size()+ 1);
    Set<ToolPlan> importedPlans = new LinkedHashSet<ToolPlan>();
    monitor.subTask("Ordering plans for export");
    try {
      for (ToolPlan plan : plans){
        /*
         * build the supplierTo information
         */
        Set<String> suppliers = plan.getSupplierPlans();
        for (String name : suppliers){
          // skip over forte libraries
          if (ToolProjectSupport.forteLibrariesSet.contains(name))
            continue;
          ToolPlan supplierPlan = ToolPlan.fetch(project, name);
          if (supplierPlan == null){
            System.out.println("looking for:"+name+":got null");
            continue;
          }

          supplierPlan.addSupplierTo(plan.getToolName());
        }
        //Do the traversal
        if (!importedPlans.contains(plan))
          traverseAndImport(plan, importedPlans);
       
      }
      monitor.worked(1);
      for (ToolPlan plan : importedPlans){
        if (monitor.isCanceled())
          return;
        monitor.subTask(plan.getToolName());
        System.out.println("Exporting:" + plan.getToolName());
       
        try {
          Thread.sleep(30); //TODO replace this with connection to Repos
        } catch (InterruptedException e) {
          ToolPlugin.showError("Error synchronizing with Tool Respository", e);
        }
        monitor.worked(1);
      }

    } finally {
      monitor.done();
     
    }
  }
  private void traverseAndImport(ToolPlan plan, Set<ToolPlan> importedPlans){
    if (plan == null)
      return;
    Set<String> suppliers = plan.getSupplierPlans();
    for (String name : suppliers){
      // skip over forte libraries
      if (ToolProjectSupport.forteLibrariesSet.contains(name))
        continue;
      ToolPlan supplierPlan = ToolPlan.fetch(project, name);
      if (supplierPlan == null){
        continue;
      }
      if (!importedPlans.contains(supplierPlan)){
        traverseAndImport(supplierPlan, importedPlans);
      }
    }
    importedPlans.add(plan);
   
  }
}
TOP

Related Classes of tool.repository.RepositorySync

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.