public static IProject unpackResourceProject(IProject project, Example.Resource resource) throws Exception { if (resource.getType() == Type.ENVIRONMENT) CloudScaleProjectSupport.addProjectNature(project); ZipFile file = new ZipFile(resource.getArchive().getFile()); ZipFileStructureProvider provider = new ZipFileStructureProvider(file); IPath containerPath = project.getFullPath(); Object source = provider.getRoot(); IOverwriteQuery query = new IOverwriteQuery() { @Override public String queryOverwrite(String path) { return IOverwriteQuery.ALL; }; }; ImportOperation operation = new ImportOperation(containerPath, source, provider, query); operation.run(null); return project; }
/** * extract zip file and import files into project * * @param srcZipFile * @param destPath * @param monitor * @param query * @throws CoreException */ private static void importFilesFromZip( ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor, IOverwriteQuery query ) throws CoreException { try { ZipFileStructureProvider structureProvider = new ZipFileStructureProvider( srcZipFile ); List list = prepareFileList( structureProvider, structureProvider .getRoot( ), null ); ImportOperation op = new ImportOperation( destPath, structureProvider.getRoot( ), structureProvider, query, list ); op.run( monitor ); } catch ( Exception e ) { String message = srcZipFile.getName( ) + ": " + e.getMessage( ); //$NON-NLS-1$ Logger.logException( e ); throw BirtCoreException.getException( message, e ); } }
private static IProject importProject(File probandsFolder, String projectName, boolean prepareDotProject) throws Exception { File projectSourceFolder = new File(probandsFolder, projectName); if (!projectSourceFolder.exists()) { throw new IllegalArgumentException("proband not found in " + projectSourceFolder); } if (prepareDotProject) { prepareDotProject(projectSourceFolder); } IProgressMonitor monitor = new NullProgressMonitor(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProjectDescription newProjectDescription = workspace.newProjectDescription(projectName); IProject project = workspace.getRoot().getProject(projectName); project.create(newProjectDescription, monitor); project.open(monitor); if (!project.getLocation().toFile().exists()) { throw new IllegalArgumentException("test project correctly created in " + project.getLocation()); } IOverwriteQuery overwriteQuery = new IOverwriteQuery() { @Override public String queryOverwrite(String file) { return ALL; } }; ImportOperation importOperation = new ImportOperation(project.getFullPath(), projectSourceFolder, FileSystemStructureProvider.INSTANCE, overwriteQuery); importOperation.setCreateContainerStructure(false); importOperation.run(monitor); return project; }
@Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { BundleImportStructureProvider bundleImportStructureProvider = new BundleImportStructureProvider(bundle); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject project = workspace.getRoot().getProject(projectName); IOverwriteQuery overwriteQuery = new IOverwriteQuery() { public String queryOverwrite(String file) { return ALL; } }; ImportOperation importOperation = new ImportOperation(project.getFullPath(), bundleProjectEntryPath, bundleImportStructureProvider, overwriteQuery); importOperation.setCreateContainerStructure(false); importOperation.run(monitor); }
public IProject createProject(URL location, String sourceFolder) throws CoreException { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(sourceFolder); try { project.create(new NullProgressMonitor()); project.open(new NullProgressMonitor()); } catch (CoreException ex) { MessageDialog.openError(null, Messages.Error, NLS.bind(Messages.CreateProjectErrorFmt, project.getName(), ex.getMessage())); return null; } try { File templateRoot = new File(location.getPath(), sourceFolder); RelativeFileSystemStructureProvider structureProvider = new RelativeFileSystemStructureProvider(templateRoot); ImportOperation operation = new ImportOperation(project.getFullPath(), templateRoot, structureProvider, new IOverwriteQuery() { @Override public String queryOverwrite(String pathString) { return ALL; } }, structureProvider.getChildren(templateRoot)); operation.setContext(Display.getDefault().getActiveShell()); operation.run(null); } catch (Exception e) { throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage())); } return project; }
public static void importFilesFromZip( ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException { ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(srcZipFile); try { ImportOperation op = new ImportOperation( destPath, structureProvider.getRoot(), structureProvider, new ImportOverwriteQuery()); op.run(monitor); } catch (InterruptedException e) { // should not happen } }
private IProject doCreateProject(ProjectCandidate pc, IProgressMonitor monitor) throws CoreException, InterruptedException { HybridProjectCreator projectCreator = new HybridProjectCreator(); Widget w = pc.getWidget(); String projectName = pc.getProjectName(); URI location = null; if(!copyFiles){ location = pc.wwwLocation.getParentFile().toURI(); } IProject project = projectCreator.createProject(projectName, location, w.getName(), w.getId(), null, monitor); if(copyFiles){ ImportOperation operation = new ImportOperation(project .getFullPath(), pc.wwwLocation.getParentFile(), FileSystemStructureProvider.INSTANCE , this); operation.setContext(getShell()); operation.setOverwriteResources(true); operation.setCreateContainerStructure(false); try { operation.run(monitor); } catch (InvocationTargetException e) { if(e.getCause() != null && e.getCause() instanceof CoreException){ CoreException corex = (CoreException) e.getCause(); throw corex; } } IStatus status = operation.getStatus(); if (!status.isOK()) throw new CoreException(status); } return project; }
public static IProject createExampleProject(IProject project, Example.Resource resource) { try { if (resource.getType() == Type.ENVIRONMENT) CloudScaleProjectSupport.addProjectNature(project); ZipFile file = new ZipFile(resource.getArchive().getFile()); ZipFileStructureProvider provider = new ZipFileStructureProvider(file); IPath containerPath = project.getFullPath(); Object source = provider.getRoot(); IOverwriteQuery query = new IOverwriteQuery() { @Override public String queryOverwrite(String path) { return IOverwriteQuery.ALL; }; }; ImportOperation operation = new ImportOperation(containerPath, source, provider, query); try { operation.run(null); } catch (Exception ex) { ex.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); project = null; } return project; }
public static void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException { ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(srcZipFile); try { ImportOperation op = new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, new ImportOverwriteQuery()); op.run(monitor); } catch (InterruptedException e) { // should not happen } }
@Override public void run(String[] params, ICheatSheetManager manager) { if (params == null || params[0] == null) { return; } IWorkspace workspace = ResourcesPlugin.getWorkspace(); String projectName = params[0]; String zipName = params[1]; IProjectDescription newProjectDescription = workspace.newProjectDescription(projectName); IProject newProject = workspace.getRoot().getProject(projectName); try { newProject.create(newProjectDescription, null); newProject.open(null); URL url = this.getClass().getClassLoader().getResource(zipName); File f = new File(FileLocator.toFileURL(url).getPath()); IOverwriteQuery overwriteQuery = new IOverwriteQuery() { public String queryOverwrite(String file) { System.out.println(file); return ALL; } }; FileSystemStructureProvider provider = FileSystemStructureProvider.INSTANCE; File root = createTempDirectory(); unzip(f.getAbsolutePath(), root.getAbsolutePath()); List<File> files = readFiles(root.getAbsolutePath()); ImportOperation importOperation = new ImportOperation(newProject.getFullPath(), root, provider, overwriteQuery, files); importOperation.setCreateContainerStructure(false); importOperation.run(new NullProgressMonitor()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Override public void importExample(ExampleData edata, IProgressMonitor monitor) { try { IProjectDescription original = ResourcesPlugin.getWorkspace() .loadProjectDescription(new Path(edata.getProjectDir().getAbsolutePath()).append("/.project")); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(edata.getProjectDir().getName()); IProjectDescription clone = ResourcesPlugin.getWorkspace() .newProjectDescription(original.getName()); clone.setBuildSpec(original.getBuildSpec()); clone.setComment(original.getComment()); clone.setDynamicReferences(original .getDynamicReferences()); clone.setNatureIds(original.getNatureIds()); clone.setReferencedProjects(original .getReferencedProjects()); if(project.exists()){ return; } project.create(clone, monitor); project.open(monitor); @SuppressWarnings("unchecked") List<IFile> filesToImport = FileSystemStructureProvider.INSTANCE.getChildren(edata.getProjectDir()); ImportOperation io = new ImportOperation(project.getFullPath(), edata.getProjectDir(), FileSystemStructureProvider.INSTANCE, new IOverwriteQuery() { @Override public String queryOverwrite(String pathString) { return IOverwriteQuery.ALL; } }, filesToImport); io.setOverwriteResources(true); io.setCreateContainerStructure(false); io.run(monitor); project.refreshLocal(IProject.DEPTH_INFINITE, monitor); } catch (Exception e) { e.printStackTrace(); } }