use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class ImportProjectsUtilities method afterImportAs.
/**
* DOC smallet Comment method "afterImportAs".
*
* @param newName
* @param technicalName
* @throws InvocationTargetException
*/
private static Project afterImportAs(String newName, String technicalName) throws InvocationTargetException {
// Rename in ".project" and "talendProject" or "talend.project"
// TODO SML Optimize
final IWorkspace workspace = org.eclipse.core.resources.ResourcesPlugin.getWorkspace();
IContainer containers = (IProject) workspace.getRoot().findMember(new Path(technicalName));
IResource file2 = containers.findMember(IProjectDescription.DESCRIPTION_FILE_NAME);
try {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
replaceInFile("<name>.*</name>", file2.getLocation().toOSString(), "<name>" + technicalName + "</name>");
// TDI-19269
final IProject project = workspace.getRoot().getProject(technicalName);
XmiResourceManager xmiManager = new XmiResourceManager();
try {
final Project loadProject = xmiManager.loadProject(project);
loadProject.setTechnicalLabel(technicalName);
loadProject.setLabel(newName);
loadProject.setLocal(true);
loadProject.setId(0);
loadProject.setUrl(null);
loadProject.setCreationDate(null);
loadProject.setDescription("");
loadProject.setType(null);
// ADD xqliu 2012-03-12 TDQ-4771 clear the list of Folders
if (loadProject.getFolders() != null) {
loadProject.getFolders().clear();
}
// ~ TDQ-4771
xmiManager.saveResource(loadProject.eResource());
return loadProject;
} catch (PersistenceException e) {
//
}
} catch (IOException e) {
throw new InvocationTargetException(e);
}
return null;
}
use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class BuildJobHandler method build.
@Override
public void build(IProgressMonitor monitor) throws Exception {
final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
try {
buildDelegate(monitor);
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
};
try {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.run(runnable, workspace.getRoot(), IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class TalendWizardProjectsImportPage method createProjects.
@SuppressWarnings("restriction")
@Override
public boolean createProjects() {
// TDI-19269
final boolean created = super.createProjects();
//
final Object[] selected = getProjectsList().getCheckedElements();
XmiResourceManager xmiManager = new XmiResourceManager();
try {
for (Object element : selected) {
final ProjectRecord record = (ProjectRecord) element;
String projectName = record.getProjectName();
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProject project = workspace.getRoot().getProject(projectName);
try {
final Project loadProject = xmiManager.loadProject(project);
loadProject.setLocal(true);
loadProject.setId(0);
loadProject.setUrl(null);
loadProject.setCreationDate(null);
//loadProject.setDescription(""); //$NON-NLS-1$
loadProject.setType(null);
xmiManager.saveResource(loadProject.eResource());
// FIXME TDI-22786, migrate the project name.
if (ProjectManager.enableSpecialTechnicalProjectName()) {
ChangeProjectTechinicalNameMigrationTask migrationTask = new ChangeProjectTechinicalNameMigrationTask();
migrationTask.migrateTalendProject(project, loadProject, xmiManager);
}
} catch (PersistenceException e) {
//
}
}
} finally {
xmiManager.unloadResources();
}
return created;
//
}
use of org.eclipse.core.resources.IWorkspace in project tesb-studio-se by Talend.
the class OpenWSDLPage method finish.
public boolean finish() {
// changed by hqzhang for TDI-19527, label=displayName
final String label = item.getProperty().getDisplayName();
item.getProperty().setLabel(label);
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(final IProgressMonitor monitor) throws CoreException {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
try {
item.setConnection(ServicesFactory.eINSTANCE.createServiceConnection());
if (creation) {
item.getProperty().setId(factory.getNextId());
factory.create(item, getDestinationPath());
repositoryNode = new RepositoryNode(new RepositoryViewObject(item.getProperty()), repositoryNode.getParent(), ENodeType.REPOSITORY_ELEMENT);
}
((ServiceConnection) item.getConnection()).setWSDLPath(path);
((ServiceConnection) item.getConnection()).getServicePort().clear();
final IFile fileWsdl = WSDLUtils.getWsdlFile(item);
final InputStream is;
if (null == path) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// create new WSDL file from template
TemplateProcessor.processTemplate("DATA_SERVICE_WSDL", Collections.singletonMap("serviceName", (Object) label), baos, getClass().getResourceAsStream(TEMPLATE_SERVICE_WSDL));
is = new ByteArrayInputStream(baos.toByteArray());
} else {
//$NON-NLS-1$
String filenameTemplate = item.getProperty().getLabel() + '_' + item.getProperty().getVersion() + ".%d.wsdl";
Map<String, InputStream> wsdls = new WSDLLoader().load(path, filenameTemplate);
is = wsdls.remove(WSDLLoader.DEFAULT_FILENAME);
for (Map.Entry<String, InputStream> wsdl : wsdls.entrySet()) {
String filename = wsdl.getKey();
IFile importedWsdl = fileWsdl.getParent().getFile(new Path(filename));
if (!importedWsdl.exists()) {
importedWsdl.create(wsdl.getValue(), true, monitor);
} else {
importedWsdl.setContents(wsdl.getValue(), 0, monitor);
}
createReferenceResources(filename.substring(filename.lastIndexOf('.', filename.lastIndexOf('.') - 1) + 1));
}
}
// store WSDL in service
if (!fileWsdl.exists()) {
fileWsdl.create(is, true, monitor);
} else {
fileWsdl.setContents(is, 0, monitor);
}
// create reference to wsdl
//$NON-NLS-1$
createReferenceResources("wsdl");
// path
definition = WSDLUtils.getDefinition(fileWsdl);
populateModelFromWsdl(factory, definition, item, repositoryNode);
factory.save(item);
ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
} catch (Exception e) {
//delete the node if any exception during the creation
if (creation) {
try {
factory.save(item);
factory.deleteObjectPhysical(repositoryNode.getObject());
} catch (PersistenceException e1) {
throw getCoreException("WDSL creation failed", e1);
}
}
//throw the exception
if (e instanceof CoreException) {
throw (CoreException) e;
}
if (e instanceof InvocationTargetException) {
throw getCoreException("WDSL creation failed", e.getCause());
}
throw getCoreException("WDSL creation failed", e);
}
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
// we use the workspace scheduling rule to lock all
ISchedulingRule schedulingRule = workspace.getRoot();
// workspace modifications during the run.
// the update of the project files need to be done in the workspace runnable to avoid all notification
// of changes before the end of the modifications.
workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null);
} catch (CoreException e) {
MessageBoxExceptionHandler.process(e);
return false;
}
// open wsdl editor
OpenWSDLEditorAction action = new OpenWSDLEditorAction();
action.setServiceItem(item);
action.run();
// import schemas if required
if (checkImport.isVisible() && checkImport.getSelection() && null != definition) {
PublishMetadataRunnable publishMetadataRunnable = new PublishMetadataRunnable(definition, getShell());
try {
getContainer().run(true, true, publishMetadataRunnable);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
String message = (null != cause.getMessage()) ? cause.getMessage() : cause.getClass().getName();
setErrorMessage("Populate schema to repository: " + message);
return false;
} catch (InterruptedException e) {
return false;
}
}
return true;
}
use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class DemosImportTest method createTempDemoProject.
protected void createTempDemoProject(String demoName) throws CoreException, PersistenceException {
Project projectInfor = new Project();
projectInfor.setLabel(demoName);
projectInfor.setDescription("no desc");
projectInfor.setLanguage(ECodeLanguage.JAVA);
User user = PropertiesFactory.eINSTANCE.createUser();
user.setLogin("testauto@talend.com");
projectInfor.setAuthor(user);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
String technicalLabel = Project.createTechnicalName(projectInfor.getLabel());
IProject prj = root.getProject(technicalLabel);
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
IProjectDescription desc = null;
if (prj.exists()) {
// always delete to avoid conflicts between 2 tests
prj.delete(true, null);
}
desc = workspace.newProjectDescription(technicalLabel);
desc.setNatureIds(new String[] { TalendNature.ID });
desc.setComment(projectInfor.getDescription());
prj.create(desc, null);
prj.open(IResource.DEPTH_INFINITE, null);
prj.setDefaultCharset("UTF-8", null);
} catch (CoreException e) {
throw new PersistenceException(e);
}
tempDemoProject = new Project();
// Fill project object
tempDemoProject.setLabel(projectInfor.getLabel());
tempDemoProject.setDescription(projectInfor.getDescription());
tempDemoProject.setLanguage(projectInfor.getLanguage());
tempDemoProject.setAuthor(projectInfor.getAuthor());
tempDemoProject.setLocal(true);
tempDemoProject.setTechnicalLabel(technicalLabel);
XmiResourceManager xmiResourceManager = new XmiResourceManager();
Resource projectResource = xmiResourceManager.createProjectResource(prj);
projectResource.getContents().add(tempDemoProject.getEmfProject());
projectResource.getContents().add(tempDemoProject.getAuthor());
xmiResourceManager.saveResource(projectResource);
}
Aggregations