use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.
the class WSDL2JAVAController method syncRoutine.
/**
* DOC xtan there will be refactor for this method with JavaRoutineSynchronizer.syncRoutine().
*
* @param routineItem
* @param copyToTemp
* @return
* @throws SystemException
*/
private IFile syncRoutine(RoutineItem routineItem, boolean copyToTemp, String name) throws SystemException {
FileOutputStream fos = null;
try {
IRunProcessService service = DesignerPlugin.getDefault().getRunProcessService();
ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
if (talendProcessJavaProject == null) {
return null;
}
IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
IFile file = srcFolder.getFile(JavaUtils.JAVA_ROUTINES_DIRECTORY + '/' + routineItem.getProperty().getLabel() + JavaUtils.JAVA_EXTENSION);
if (copyToTemp) {
String routineContent = new String(routineItem.getContent().getInnerContent());
routineContent = chanageRoutinesPackage(routineContent, name);
String label = routineItem.getProperty().getLabel();
if (!label.equals(ITalendSynchronizer.TEMPLATE)) {
routineContent = routineContent.replaceAll(ITalendSynchronizer.TEMPLATE, label);
File f = file.getLocation().toFile();
fos = new FileOutputStream(f);
fos.write(routineContent.getBytes());
fos.close();
}
}
if (!file.exists()) {
file.refreshLocal(1, null);
}
return file;
} catch (CoreException e) {
throw new SystemException(e);
} catch (IOException e) {
throw new SystemException(e);
} finally {
try {
fos.close();
} catch (Exception e) {
// ignore me even if i'm null
ExceptionHandler.process(e);
}
}
}
use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.
the class RemoveBinFolderMigrationTask method execute.
@Override
public ExecutionResult execute(Project project) {
XmiResourceManager xmiResourceManager = new XmiResourceManager();
IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
for (ERepositoryObjectType type : getTypes()) {
IFolder folder = null;
if (type != null && type.hasFolder()) {
try {
IProject fsProject = ResourceUtils.getProject(project.getTechnicalLabel());
if (!fsProject.getFolder(ERepositoryObjectType.getFolderName(type)).exists()) {
continue;
}
folder = ResourceUtils.getFolder(fsProject, ERepositoryObjectType.getFolderName(type), true);
for (IResource current : ResourceUtils.getMembers(folder)) {
if ((current instanceof IFolder) && ((IFolder) current).getName().equals("bin")) {
for (IResource fileCurrent : ResourceUtils.getMembers((IFolder) current)) {
if (fileCurrent instanceof IFile) {
if (xmiResourceManager.isPropertyFile((IFile) fileCurrent)) {
Property property = null;
try {
property = xmiResourceManager.loadProperty(fileCurrent);
} catch (RuntimeException e) {
// property will be null
ExceptionHandler.process(e);
}
if (property != null) {
// restore folder if doesn't exist anymore.
Item propertyItem = property.getItem();
propertyItem.getState().setDeleted(true);
EmfHelper.saveResource(propertyItem.eResource());
String oldPath = propertyItem.getState().getPath();
IPath path = new Path(oldPath);
factory.createParentFoldersRecursively(project, type, path, true);
FolderItem folderItem = factory.getFolderItem(project, type, path);
propertyItem.setParent(folderItem);
String name = fileCurrent.getName().replace(".properties", "");
// take all the files starting by the same name
IFolder typeRootFolder = ResourceUtils.getFolder(fsProject, ERepositoryObjectType.getFolderName(type), true);
for (IResource filesToMove : ResourceUtils.getMembers((IFolder) current)) {
if (filesToMove.getName().startsWith(name)) {
IPath originalPath = filesToMove.getFullPath();
IPath finalPath = typeRootFolder.getFullPath().append(path).append(originalPath.lastSegment());
if (fsProject.getWorkspace().getRoot().getFile(finalPath).exists()) {
// if the file exists in both bin and target directory, delete
// the one from bin.
filesToMove.delete(true, new NullProgressMonitor());
} else {
ResourceUtils.moveResource(filesToMove, finalPath);
}
}
}
}
}
}
}
IResource[] binFolder = ResourceUtils.getMembers((IFolder) current);
if (binFolder.length == 0 || (binFolder.length == 1 && FilesUtils.isSVNFolder(binFolder[0]))) {
try {
((IFolder) current).delete(true, null);
} catch (CoreException e) {
// not catched, not important if can delete or not
}
}
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
} catch (CoreException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
// }
return ExecutionResult.SUCCESS_NO_ALERT;
}
use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.
the class RemoveProjectLibsFolder method execute.
/*
* (non-Javadoc)
*
* @see org.talend.migration.IProjectMigrationTask#execute(org.talend.core.model.general.Project)
*/
@Override
public ExecutionResult execute(Project project) {
String libsFolderName = "libs";
IFolder libsF = null;
try {
IProject fsProject = ResourceUtils.getProject(project.getTechnicalLabel());
libsF = fsProject.getFolder(libsFolderName);
if (!libsF.exists()) {
return ExecutionResult.NOTHING_TO_DO;
}
final IPath location = libsF.getLocation();
libsFolder = new File(location.toPortableString());
ShareProjectLibsMigration migration = new ShareProjectLibsMigration();
migration.shareLibs(null, new NullProgressMonitor());
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
try {
libsF.delete(true, new NullProgressMonitor());
} catch (CoreException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.
the class SelectDeleteProjectDialog method delProjectItem.
private void delProjectItem() {
try {
if (delItemList.size() != 0) {
for (Object obj : delItemList) {
if (obj instanceof IProject) {
IProject project = (IProject) obj;
// project.delete(true, null);
project.delete(!chkButton.getSelection(), true, null);
// IResourceChangeDescriptionFactory factory =
// ResourceChangeValidator.getValidator().createDeltaFactory();
// factory.delete(project);
} else if (obj instanceof IFolder) {
IFolder folder = (IFolder) obj;
folder.delete(false, null);
}
}
}
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.
the class ImportProjectAsAction method clearExternalLibraries.
/**
* DOC zwang Comment method "clearExternalLibraries".
*/
private void clearExternalLibraries() {
try {
IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
Project[] projects = repositoryFactory.readProject();
for (Project project : projects) {
IProject fsProject = ResourceUtils.getProject(project);
IFolder libJavaFolder = fsProject.getFolder(ImportProjectAsAction.LIB);
if (!libJavaFolder.exists()) {
continue;
}
libJavaFolder.delete(true, null);
}
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
Aggregations