public static XModelObject getJarEntryObject(IProject p, String jarFile, String entry) { if (p == null) { IFile f = EclipseResourceUtil.getFile(jarFile); if (f == null) return null; p = f.getProject(); } if (p == null) return null; IModelNature n = EclipseResourceUtil.getModelNature(p); XModel model = null; if (n != null) { model = n.getModel(); } else { XModelObject o = EclipseResourceUtil.createObjectForResource(p); if (o != null) model = o.getModel(); } if (model == null) return null; XModelObject[] fs = FileSystemsHelper.getFileSystems(model).getChildren(); for (XModelObject s : fs) { String loc = Paths.expand(s.get(XModelObjectConstants.ATTR_NAME_LOCATION), model.getProperties()); if (new File(loc).equals(new File(jarFile))) { XModelObject result = s.getChildByPath(entry); if (result == null && entry != null) { int q = entry.indexOf('/'); int d = entry.indexOf('.'); if (q > d && d >= 0) { String entry1 = entry.substring(0, q).replace('.', '/') + entry.substring(q); result = s.getChildByPath(entry1); } } if (result != null) return result; } } return (n == null) ? null : n.getModel().getByPath("/" + entry); // $NON-NLS-1$ }
public void load(XModelObject object) { if (EclipseResourceUtil.isProjectFragment(object.getModel())) return; IAutoLoad auto = (IAutoLoad) object.getModel().getProperties().get(XModelConstants.AUTOLOAD); if (auto != null) { auto.load(object.getModel()); updateLibs(object); _updateSrcs(object); ((FileSystemsImpl) object).updateOverlapped(); return; } String f = getEclipseFileName(object, true); if (f == null) super.load(object); else util().load(new File(f), object); XModelObject[] os = object.getChildren(); for (int i = 0; i < os.length; i++) { String s = os[i].getAttributeValue(XModelObjectConstants.ATTR_NAME_LOCATION); if (s == null || !s.startsWith(XModelConstants.WORKSPACE_OLD_REF)) continue; s = XModelConstants.WORKSPACE_REF + s.substring(XModelConstants.WORKSPACE_OLD_REF.length()); os[i].setAttributeValue(XModelObjectConstants.ATTR_NAME_LOCATION, s); } removeMissingJarSystems(object); }
private static IEditorInput convertFileInput(IFileEditorInput input) { IFileEditorInput fi = (IFileEditorInput) input; IFile f = fi.getFile(); if (f != null && !f.isSynchronized(IResource.DEPTH_INFINITE)) { try { f.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { // ignore } } XModelObject o = EclipseResourceUtil.getObjectByResource(f); if (o == null) { o = EclipseResourceUtil.createObjectForResource(f); } return (o == null || o.getFileType() != XModelObject.FILE) ? input : new XModelObjectEditorInput(getMainObject(o)); }
/** * Returns true if XModelObject corresponding to the file is replaced. * * @return */ public boolean updateXModelObject() { IFile file = getFile(); XModelObject o = EclipseResourceUtil.createObjectForResource(file); if (o != null && o != object) { object = o; cache = new XModelObjectCache(object); return true; } return false; }
public Object getAdapter(Class adapter) { if (adapter == XModelObject.class) return getXModelObject(); Object result = null; if (IFile.class.isAssignableFrom(adapter)) { result = EclipseResourceUtil.getResource(object); if (result != null && !adapter.isAssignableFrom(result.getClass())) result = null; } else { result = super.getAdapter(adapter); } return result; }
private void updateLibs(XModelObject object) { if (WatcherLoader.isLocked(object.getModel())) { return; } IProject project = EclipseResourceUtil.getProject(object); if (project == null) return; XModelObject lib = validateLib(object); // if(lib == null) { // return; // } Libs libs = FileSystemsHelper.getLibs(object); if (libs != null) libs.update(); }
private static void _updateSrcs(XModelObject object) { IProject p = EclipseResourceUtil.getProject(object); if (p == null || !p.isAccessible()) return; String[] srcs = EclipseResourceUtil.getJavaProjectSrcLocations(p); Set<String> paths = new HashSet<String>(); for (int i = 0; i < srcs.length; i++) { String path = EclipseResourceUtil.getRelativeLocation(object.getModel(), srcs[i]); if (path == null) continue; paths.add(path); } XModelObject[] cs = object.getChildren(XModelObjectConstants.ENT_FILE_SYSTEM_FOLDER); for (int i = 0; i < cs.length; i++) { if (cs[i] .getAttributeValue(XModelObjectConstants.ATTR_NAME) .startsWith("src")) { // $NON-NLS-1$ String loc = cs[i].getAttributeValue(XModelObjectConstants.ATTR_NAME_LOCATION); if (!paths.contains(loc)) { object.removeChild(cs[i]); } else { paths.remove(loc); } } } for (String path : paths) { String n = getNextSrcName(object); Properties properties = new Properties(); properties.setProperty(XModelObjectConstants.ATTR_NAME_LOCATION, path); properties.setProperty(XModelObjectConstants.ATTR_NAME, n); FileSystemImpl s = (FileSystemImpl) object .getModel() .createModelObject(XModelObjectConstants.ENT_FILE_SYSTEM_FOLDER, properties); object.addChild(s); } }
private boolean saveEclipse(XModelObject object) { String f = getEclipseFileName(object, false); boolean b = f != null && util().save(new File(f), object); if (b) { IFile file = EclipseResourceUtil.getFile(f); if (file != null) { try { file.refreshLocal(0, null); } catch (CoreException e) { // ignore } } } return b; }
public static IEditorInput checkInput(IEditorInput input) { if (input instanceof IModelObjectEditorInput) return input; if (input instanceof ILocationProvider) return convertExternalInput((ILocationProvider) input); if (input instanceof IFileEditorInput) return convertFileInput((IFileEditorInput) input); if (input instanceof IStorageEditorInput) return convertStorageEditorInput((IStorageEditorInput) input); if (input instanceof IURIEditorInput) { URI uri = ((IURIEditorInput) input).getURI(); String f = uri.getPath(); XModelObject o = EclipseResourceUtil.createObjectForLocation(f); return (o == null || o.getFileType() != XModelObject.FILE) ? (IEditorInput) input : new ModelObjectLocationEditorInput(getMainObject(o), new Path(f)); } return input; }
private static IEditorInput convertExternalInput(ILocationProvider input) { XModelObject o = EclipseResourceUtil.createObjectForLocation(input.getPath(input).toString()); return (o == null || o.getFileType() != XModelObject.FILE) ? (IEditorInput) input : new ModelObjectLocationEditorInput(getMainObject(o), input.getPath(input)); }
private static IFile getFileByObject(XModelObject object) { return (IFile) EclipseResourceUtil.getResource(object); }
public String getToolTipText() { IFile f = (IFile) EclipseResourceUtil.getResource(object); if (f != null && f.exists()) return f.getLocation().toString(); return object.getPresentationString(); }