Package tool.repository

Source Code of tool.repository.RepositoryExport

package tool.repository;

import java.util.List;

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

import tool.ToolPlugin;
import tool.ToolProjectSupport;
import tool.builder.PlanDetail;
/**
* this class exports a repository to the file system
* @author Peter
*
*/
public class RepositoryExport implements IRunnableWithProgress {
  private IProject project;
  public RepositoryExport(IProject project){
    super();
    this.project = project;
  }
  @Override
  public void run(IProgressMonitor monitor) {
    Assert.isNotNull(this.project);
    RepositorySession repos = RepositorySession.getRepositorySession(project);
    Assert.isNotNull(repos);
      IFolder projectsDir = ToolProjectSupport.getSourceFolders(project).get(0);
      List<PlanDetail> plans;
      try {
        repos.setJustRefreshed(true); //Kludge to prevent the build
        repos.openRepository();
        repos.openWorkspace();
       
        plans = repos.listPlanNamesWithDetails(
            false,//pIncludeSystem,
            true,//pIncludeLibraries,
            false,//Topo,
            false);//pIncludeInternal
        if (monitor != null)
          monitor.beginTask("Importing Plan", plans.size());
        for (PlanDetail plan : plans){
          if (monitor != null){
            if (monitor.isCanceled())
              break;
            monitor.subTask(plan.getName());
           
          }

          if (!plan.isLibrary()){
            IFolder planDir = projectsDir.getFolder(plan.getName());
            if (!planDir.exists()){
              planDir.create(false, true, null);

            }
            repos.exportPlanAndComponents(plan.getName(), planDir.getLocation().toOSString(), true);
            IResource planResource = planDir.findMember(plan.getName() + ".prx");
            planDir.setPersistentProperty(ToolProjectSupport.toolPlanNameQualifiedName, plan.getName());
          } else {
            if (!ToolProjectSupport.forteLibrariesSet.contains(plan.getName())){ //this skips over HTTP
              IFolder librariesDir = (IFolder)project.findMember(ToolProjectSupport.LIBRARY_FOLDER_NAME);
              repos.exportPlanAsPEX(plan.getName(),  librariesDir.getLocation().toPortableString());
            }
          }
          if (monitor != null)
            monitor.worked(1);
        }
        repos.closeWorkspace();
        repos.closeRepository();
        project.refreshLocal(IResource.DEPTH_INFINITE, null);

      } catch (NotConnectedException e) {
        ToolPlugin.showError("Error importing from Tool repository", e);
      } catch (CommandException e) {
        ToolPlugin.showError("Error importing from Tool repository", e);
      } catch (CoreException e) {
        ToolPlugin.showError("Error importing from Tool repository", e);
    } finally {
        if (monitor != null)
          monitor.done();
      }

  }

}
TOP

Related Classes of tool.repository.RepositoryExport

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.