use of org.eclipse.core.resources.IProject in project che by eclipse.
the class DeltaProcessor method traverseDelta.
/*
* Converts an <code>IResourceDelta</code> and its children into
* the corresponding <code>IJavaElementDelta</code>s.
*/
private void traverseDelta(IResourceDelta delta, int elementType, RootInfo rootInfo, OutputsInfo outputsInfo) {
IResource res = delta.getResource();
// set stack of elements
if (this.currentElement == null && rootInfo != null) {
this.currentElement = rootInfo.project;
}
// process current delta
boolean processChildren = true;
if (res instanceof IProject) {
// reset source element parser cache
this.sourceElementParserCache = null;
processChildren = updateCurrentDeltaAndIndex(delta, elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT ? // case of prj=src
IJavaElement.JAVA_PROJECT : elementType, rootInfo);
} else if (rootInfo != null) {
processChildren = updateCurrentDeltaAndIndex(delta, elementType, rootInfo);
} else {
// not yet inside a package fragment root
processChildren = true;
}
// process children if needed
if (processChildren) {
IResourceDelta[] children = (IResourceDelta[]) delta.getAffectedChildren();
boolean oneChildOnClasspath = false;
int length = children.length;
IResourceDelta[] orphanChildren = null;
Openable parent = null;
boolean isValidParent = true;
for (int i = 0; i < length; i++) {
IResourceDelta child = children[i];
IResource childRes = child.getResource();
// check source attachment change
checkSourceAttachmentChange(child, childRes);
// find out whether the child is a package fragment root of the current project
IPath childPath = externalPath(childRes);
int childKind = child.getKind();
RootInfo childRootInfo = rootInfo(childPath, childKind);
RootInfo originalChildRootInfo = childRootInfo;
if (childRootInfo != null && !childRootInfo.isRootOfProject(childPath)) {
// package fragment root of another project (dealt with later)
childRootInfo = null;
}
// compute child type
int childType = elementType(childRes, childKind, elementType, rootInfo == null ? childRootInfo : rootInfo);
// is childRes in the output folder and is it filtered out ?
boolean isResFilteredFromOutput = isResFilteredFromOutput(rootInfo, outputsInfo, childRes, childType);
boolean isNestedRoot = rootInfo != null && childRootInfo != null;
if (!isResFilteredFromOutput && !isNestedRoot) {
// do not treat as non-java rsc if nested root
traverseDelta(child, childType, rootInfo == null ? childRootInfo : rootInfo, // traverse delta for child in the same project
outputsInfo);
if (childType == NON_JAVA_RESOURCE) {
if (rootInfo != null) {
// if inside a package fragment root
if (!isValidParent)
continue;
if (parent == null) {
// find the parent of the non-java resource to attach to
if (this.currentElement == null || !rootInfo.project.equals(this.currentElement.getJavaProject())) {
// note if currentElement is the
// IJavaModel, getJavaProject() is null
// force the currentProject to be used
this.currentElement = rootInfo.project;
}
if (elementType == IJavaElement.JAVA_PROJECT || (elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT && res instanceof IProject)) {
// NB: attach non-java resource to project (not to its package fragment root)
parent = rootInfo.project;
} else {
parent = createElement(res, elementType, rootInfo);
}
if (parent == null) {
isValidParent = false;
continue;
}
}
// add child as non java resource
try {
nonJavaResourcesChanged(parent, child);
} catch (JavaModelException e) {
// ignore
}
} else {
// the non-java resource (or its parent folder) will be attached to the java project
if (orphanChildren == null)
orphanChildren = new IResourceDelta[length];
orphanChildren[i] = child;
}
} else {
if (rootInfo == null && childRootInfo == null) {
// the non-java resource (or its parent folder) will be attached to the java project
if (orphanChildren == null)
orphanChildren = new IResourceDelta[length];
orphanChildren[i] = child;
}
}
} else {
// to avoid reporting child delta as non-java resource delta
oneChildOnClasspath = true;
}
// but it is a package fragment root of another project, traverse delta too
if (isNestedRoot || (childRootInfo == null && originalChildRootInfo != null)) {
traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, originalChildRootInfo, // binary output of childRootInfo.project cannot be this root
null);
}
// if the child is a package fragment root of one or several other projects
ArrayList rootList;
if ((rootList = otherRootsInfo(childPath, childKind)) != null) {
Iterator iterator = rootList.iterator();
while (iterator.hasNext()) {
originalChildRootInfo = (RootInfo) iterator.next();
this.currentElement = // ensure that 2 roots refering to the same resource don't share the current element (see
null;
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=210746 )
traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, originalChildRootInfo, // binary output of childRootInfo.project cannot be this root
null);
}
}
}
if (orphanChildren != null && (// orphan children are siblings of a package fragment root
oneChildOnClasspath || res instanceof IProject)) {
// non-java resource directly under a project
// // attach orphan children
// IProject rscProject = res.getProject();
// JavaProject adoptiveProject = (JavaProject)JavaCore.create(rscProject);
// if (adoptiveProject != null
// && JavaProject.hasJavaNature(rscProject)) { // delta iff Java project (18698)
// for (int i = 0; i < length; i++) {
// if (orphanChildren[i] != null) {
// try {
// nonJavaResourcesChanged(adoptiveProject, orphanChildren[i]);
// } catch (JavaModelException e) {
// // ignore
// }
// }
// }
// }
}
// else resource delta will be added by parent
}
// else resource delta will be added by parent
}
use of org.eclipse.core.resources.IProject in project che by eclipse.
the class DeleteResourcesProcessor method checkDirtyResources.
private void checkDirtyResources(final RefactoringStatus result) throws CoreException {
for (int i = 0; i < fResources.length; i++) {
IResource resource = fResources[i];
if (resource instanceof IProject && !((IProject) resource).isOpen())
continue;
resource.accept(new IResourceVisitor() {
public boolean visit(IResource visitedResource) throws CoreException {
if (visitedResource instanceof IFile) {
checkDirtyFile(result, (IFile) visitedResource);
}
return true;
}
}, IResource.DEPTH_INFINITE, false);
}
}
use of org.eclipse.core.resources.IProject in project tdi-studio-se by Talend.
the class AutoConversionTypesEditor method applyChange.
private void applyChange() {
try {
IProject project = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
IFolder prefsSettingFolder = ResourceUtils.getFolder(project, RepositoryConstants.SETTING_DIRECTORY, false);
AutoConvertTypesUtils.save(typeModel.getBeansList(), AutoConvertTypesUtils.getTypeFile());
prefsSettingFolder.refreshLocal(IResource.DEPTH_ONE, null);
} catch (CoreException e) {
ExceptionHandler.process(e);
} catch (PersistenceException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.eclipse.core.resources.IProject in project tdi-studio-se by Talend.
the class CustomComponentSettingPage method finish.
private void finish(IProgressMonitor... monitorWrap) {
IProgressMonitor monitor = null;
if (monitorWrap != null && monitorWrap.length == 1) {
monitor = monitorWrap[0];
}
final IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
if (PluginChecker.isSVNProviderPluginLoaded() && (!sharedAdded.isEmpty() || !backAdded.isEmpty())) {
RepositoryWorkUnit repositoryWorkUnit = new RepositoryWorkUnit("Update custom components") {
@Override
public void run() throws PersistenceException {
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor subMonitor) throws CoreException {
ISVNProviderService service = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
String projectLabel = pro.getTechnicalLabel();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
String targetRoot = eclipseProject.getLocation().toString() + "/" + ERepositoryObjectType.getFolderName(ERepositoryObjectType.COMPONENTS);
File componentFolder = new File(targetRoot);
URL url = null;
try {
if (!componentFolder.exists()) {
FilesUtils.createFoldersIfNotExists(targetRoot, false);
}
Bundle b = Platform.getBundle(IComponentsFactory.COMPONENTS_LOCATION);
url = FileLocator.toFileURL(FileLocator.find(b, new Path(""), null));
String sourceRoot = url.getFile();
// delete share
for (IComponent component : backAdded.keySet()) {
String componentFullPath = targetRoot + File.separator + component.getName();
if (service.isSVNProject(pro)) {
service.svnEclipseHandlerDelete(eclipseProject, pro, componentFullPath);
if (subMonitor != null) {
subMonitor.worked(10);
}
} else {
File file = new File(componentFullPath);
if (file != null && file.exists()) {
org.talend.utils.io.FilesUtils.deleteFolder(file, true);
}
}
}
if (!backAdded.isEmpty()) {
getCustomComponentSettings().removeAll(backAdded.values());
}
FileFilter ff = new FileFilter() {
@Override
public boolean accept(File pathname) {
if (FilesUtils.isSVNFolder(pathname)) {
return false;
}
return true;
}
};
// share
for (IComponent component : sharedAdded.keySet()) {
String sourcePath = sourceRoot + component.getPathSource() + File.separator + component.getName();
File sourceFile = new File(sourcePath);
String targetPath = targetRoot + File.separatorChar + component.getName();
File targetFile = new File(targetPath);
FilesUtils.copyFolder(sourceFile, targetFile, true, ff, null, true, false);
if (subMonitor != null) {
subMonitor.worked(10);
}
}
} catch (Exception e) {
resetCustomComponentSetting();
ExceptionHandler.process(e);
}
try {
prf.saveProject(pro);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
try {
eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, subMonitor);
} catch (CoreException e1) {
ExceptionHandler.process(e1);
}
}
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update 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(op, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
} catch (CoreException e) {
throw new PersistenceException(e.getCause());
}
}
};
repositoryWorkUnit.setRefreshRepository(false);
repositoryWorkUnit.setForceTransaction(true);
prf.executeRepositoryWorkUnit(repositoryWorkUnit);
try {
repositoryWorkUnit.throwPersistenceExceptionIfAny();
} catch (PersistenceException e) {
e.printStackTrace();
}
}
if (monitor != null) {
monitor.done();
}
// refresh again after the gui closed .
try {
String projectLabel = pro.getTechnicalLabel();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (CoreException e1) {
ExceptionHandler.process(e1);
}
}
use of org.eclipse.core.resources.IProject in project tdi-studio-se by Talend.
the class AddCopyBookXc2jFileMigrationTask method getReferenceXc2jFile.
public static IFile getReferenceXc2jFile(ConnectionItem connectionItem) {
IFile x2cjFile = null;
try {
IProject currentProject = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
String label = connectionItem.getProperty().getLabel();
String version = connectionItem.getProperty().getVersion();
String xc2jFileName = label + "_" + version + ".xc2j";
String folderPath = "";
String folder = "";
if (connectionItem.getState() != null) {
folderPath = connectionItem.getState().getPath();
}
if (!folderPath.equals("")) {
folder = "/" + folderPath;
}
x2cjFile = currentProject.getFolder("metadata/fileEBCDIC" + folder).getFile(xc2jFileName);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
return x2cjFile;
}
Aggregations