private void logAndUnmapGoneMappedResource(final RepositoryMapping m) { Activator.logError( MessageFormat.format(CoreText.GitProjectData_mappedResourceGone, m.toString()), new FileNotFoundException(m.getContainerPath().toString())); m.clear(); UnmapJob unmapJob = new UnmapJob(getProject()); unmapJob.schedule(); }
private void map(final RepositoryMapping m) { final IResource r; final File git; final IResource dotGit; IContainer c = null; m.clear(); r = getProject().findMember(m.getContainerPath()); if (r instanceof IContainer) { c = (IContainer) r; } else if (r != null) { c = Utils.getAdapter(r, IContainer.class); } if (c == null) { logAndUnmapGoneMappedResource(m); return; } m.setContainer(c); IPath absolutePath = m.getGitDirAbsolutePath(); if (absolutePath == null) { logAndUnmapGoneMappedResource(m); return; } git = absolutePath.toFile(); if (!git.isDirectory() || !new File(git, "config").isFile()) { // $NON-NLS-1$ logAndUnmapGoneMappedResource(m); return; } try { m.setRepository(Activator.getDefault().getRepositoryCache().lookupRepository(git)); } catch (IOException ioe) { logAndUnmapGoneMappedResource(m); return; } m.fireRepositoryChanged(); trace( "map " //$NON-NLS-1$ + c + " -> " //$NON-NLS-1$ + m.getRepository()); try { c.setSessionProperty(MAPPING_KEY, m); } catch (CoreException err) { Activator.logError(CoreText.GitProjectData_failedToCacheRepoMapping, err); } dotGit = c.findMember(Constants.DOT_GIT); if (dotGit != null && dotGit.getLocation().toFile().equals(git)) { protect(dotGit); } }
/** * Hide our private parts from the navigators other browsers. * * @throws CoreException */ public void markTeamPrivateResources() throws CoreException { for (final Object rmObj : mappings) { final RepositoryMapping rm = (RepositoryMapping) rmObj; final IContainer c = rm.getContainer(); if (c == null) continue; // Not fully mapped yet? final IResource dotGit = c.findMember(Constants.DOT_GIT); if (dotGit != null) { try { final Repository r = rm.getRepository(); final File dotGitDir = dotGit.getLocation().toFile().getCanonicalFile(); if (dotGitDir.equals(r.getDirectory())) { trace("teamPrivate " + dotGit); // $NON-NLS-1$ dotGit.setTeamPrivateMember(true); } } catch (IOException err) { throw new CoreException(Activator.error(CoreText.Error_CanonicalFile, err)); } } } }
/** * Store information about the repository connection in the workspace * * @throws CoreException */ public void store() throws CoreException { final File dat = propertyFile(); final File tmp; boolean ok = false; try { trace("save " + dat); // $NON-NLS-1$ tmp = File.createTempFile( "gpd_", //$NON-NLS-1$ ".prop", //$NON-NLS-1$ dat.getParentFile()); final FileOutputStream o = new FileOutputStream(tmp); try { final Properties p = new Properties(); for (final RepositoryMapping repoMapping : mappings) { repoMapping.store(p); } p.store(o, "GitProjectData"); // $NON-NLS-1$ ok = true; } finally { o.close(); if (!ok && tmp.exists()) { FileUtils.delete(tmp); } } if (dat.exists()) FileUtils.delete(dat); if (!tmp.renameTo(dat)) { if (tmp.exists()) FileUtils.delete(tmp); throw new CoreException( Activator.error(NLS.bind(CoreText.GitProjectData_saveFailed, dat), null)); } } catch (IOException ioe) { throw new CoreException( Activator.error(NLS.bind(CoreText.GitProjectData_saveFailed, dat), ioe)); } }
private GitProjectData load() throws IOException { final File dat = propertyFile(); trace("load " + dat); // $NON-NLS-1$ final FileInputStream o = new FileInputStream(dat); try { final Properties p = new Properties(); p.load(o); mappings.clear(); for (final Object keyObj : p.keySet()) { final String key = keyObj.toString(); if (RepositoryMapping.isInitialKey(key)) { mappings.add(new RepositoryMapping(p, key)); } } } finally { o.close(); } remapAll(); return this; }