<commit_before>/*******************************************************************************
 * Copyright (c) 2003, 2006 Subclipse project and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Subclipse project committers - initial API and implementation
 ******************************************************************************/
package org.tigris.subversion.subclipse.core.resources;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.team.IMoveDeleteHook;
import org.eclipse.core.resources.team.IResourceTree;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.team.core.TeamException;
import org.tigris.subversion.subclipse.core.ISVNLocalFile;
import org.tigris.subversion.subclipse.core.ISVNLocalFolder;
import org.tigris.subversion.subclipse.core.ISVNLocalResource;
import org.tigris.subversion.subclipse.core.Policy;
import org.tigris.subversion.subclipse.core.SVNException;
import org.tigris.subversion.subclipse.core.SVNTeamProvider;
import org.tigris.subversion.subclipse.core.client.OperationManager;
import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
import org.tigris.subversion.svnclientadapter.ISVNProperty;
import org.tigris.subversion.svnclientadapter.SVNClientException;

public class SVNMoveDeleteHook implements IMoveDeleteHook {
	private static Set deletedFiles = new HashSet();

    public boolean deleteFile(IResourceTree tree, IFile file, int updateFlags,
            IProgressMonitor monitor) {

        if (SVNWorkspaceRoot.isLinkedResource(file))
            return false;

        ISVNLocalFile resource = new LocalFile(file);
        try {
            if (!resource.isManaged()) {
                return false;
            }

            if (getDeferFileDelete(file))
            	return false;
            
            monitor.beginTask(null, 1000);
            deletedFiles.add(file);
            resource.delete();
            tree.deletedFile(file);           

        } catch (SVNException e) {
            tree.failed(e.getStatus());
        } finally {
            monitor.done();
        }
        return true;

    }

    public static boolean isDeleted(IFile file) {
    	return deletedFiles.contains(file);
    }
    
    public static void removeFromDeletedFileList(IFile file) {
    	deletedFiles.remove(file);
    }
    
    public boolean deleteFolder(IResourceTree tree, IFolder folder,
            int updateFlags, IProgressMonitor monitor) {

        if (SVNWorkspaceRoot.isLinkedResource(folder))
            return false;

        ISVNLocalFolder resource = new LocalFolder(folder);
        try {

            if (!resource.isManaged()) {
                return false;
            }
            monitor.beginTask(null, 1000);
            resource.delete();
        } catch (SVNException e) {
            tree.failed(e.getStatus());
        } finally {
            monitor.done();
        }
        return true;

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.core.resources.team.IMoveDeleteHook#moveFile(org.eclipse.core.resources.team.IResourceTree,
     *      org.eclipse.core.resources.IFile, org.eclipse.core.resources.IFile,
     *      int, org.eclipse.core.runtime.IProgressMonitor)
     */
    public boolean moveFile(IResourceTree tree, IFile source,
            IFile destination, int updateFlags, IProgressMonitor monitor) {

        if (SVNWorkspaceRoot.isLinkedResource(source))
            return false;

        try {
        	
        	RepositoryProvider repositoryProvider = RepositoryProvider
            .getProvider(destination.getProject());
        	
            if (repositoryProvider == null || !(repositoryProvider instanceof SVNTeamProvider)) //target is not SVN project
                throw new SVNException(Policy.bind("SVNMoveHook.moveFileException"));
        	
            ISVNLocalFile resource = new LocalFile(source);

            if (!resource.isManaged())
                return false; // pass

            ISVNClientAdapter svnClient = resource.getRepository()
                    .getSVNClient();
            monitor.beginTask(null, 1000);

            try {
                OperationManager.getInstance().beginOperation(svnClient);

                // add destination directory to version control if necessary
                // see bug #15
                if (!SVNWorkspaceRoot.getSVNFolderFor(destination.getParent())
                        .isManaged()) {
                    SVNTeamProvider provider = (SVNTeamProvider) repositoryProvider;
                    provider.add(new IResource[] { destination.getParent() },
                            IResource.DEPTH_ZERO, new NullProgressMonitor());
                    ISVNLocalResource parent = SVNWorkspaceRoot.getSVNResourceFor(destination.getParent());
                    if (parent != null) parent.refreshStatus();
                }

                // force is set to true because when we rename (refactor) a
                // java class, the file is modified before being moved
                // A modified file cannot be moved without force

               svnClient.move(source.getLocation().toFile(), 
            		   destination.getLocation().toFile(), true);

                //movedFile must be done before endOperation because
                // destination file must not already exist in the workspace
                // resource tree.
                tree.movedFile(source, destination);
                destination.refreshLocal(IResource.DEPTH_ZERO, monitor);
            } catch (SVNClientException e) {
                throw SVNException.wrapException(e);
            } catch (TeamException e) {
                throw SVNException.wrapException(e);
            } catch (CoreException e) {
                throw SVNException.wrapException(e);
            } finally {
                OperationManager.getInstance().endOperation(false);
            }

        } catch (SVNException e) {
            tree.failed(e.getStatus());
        } finally {
            monitor.done();
        }
        return true;
    }

    public boolean moveFolder(IResourceTree tree, IFolder source,
            IFolder destination, int updateFlags, IProgressMonitor monitor) {

        if (SVNWorkspaceRoot.isLinkedResource(source))
            return false;

        try {
            ISVNLocalFolder resource = new LocalFolder(source);
            if (!resource.isManaged())
                return false;
            
        	RepositoryProvider repositoryProvider = RepositoryProvider
            .getProvider(destination.getProject());

        	if (repositoryProvider == null || !(repositoryProvider instanceof SVNTeamProvider)) //target is not SVN project
        		 throw new SVNException(Policy.bind("SVNMoveHook.moveFolderException"));

            monitor.beginTask(null, 1000);

            ISVNClientAdapter svnClient = resource.getRepository().getSVNClient();

            try {
                OperationManager.getInstance().beginOperation(svnClient);
                // add destination directory to version control if necessary
                // see bug #15
                if (!SVNWorkspaceRoot.getSVNFolderFor(destination.getParent())
                        .isManaged()) {
                    SVNTeamProvider provider = (SVNTeamProvider)repositoryProvider;
                    provider.add(new IResource[] { destination.getParent() },
                            IResource.DEPTH_ZERO, new NullProgressMonitor());
                    ISVNLocalResource parent = SVNWorkspaceRoot.getSVNResourceFor(destination.getParent());
                    if (parent != null) parent.refreshStatus();
               }

               svnClient.move(source.getLocation().toFile(), 
            		   destination.getLocation().toFile(), true);

                tree.movedFolderSubtree(source, destination);
                destination.refreshLocal(IResource.DEPTH_INFINITE, monitor);

            } catch (SVNClientException e) {
                throw SVNException.wrapException(e);

            } catch (CoreException e) {
                throw SVNException.wrapException(e);
            } finally {
                OperationManager.getInstance().endOperation();
            }

        } catch (SVNException e) {
            tree.failed(e.getStatus());
        } finally {
            monitor.done();
        }
        return true;
    }

    /* (non-Javadoc)
     * @see org.eclipse.core.resources.team.IMoveDeleteHook#deleteProject(org.eclipse.core.resources.team.IResourceTree, org.eclipse.core.resources.IProject, int, org.eclipse.core.runtime.IProgressMonitor)
     */
    public boolean deleteProject(IResourceTree tree, IProject project, int updateFlags, IProgressMonitor monitor) {
        return false;<commit_msg>Fix another SVNMoveDeleteHook schedule rule violation scenario. Issue #: 1236<commit_after>/*******************************************************************************
 * Copyright (c) 2003, 2006 Subclipse project and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Subclipse project committers - initial API and implementation
 ******************************************************************************/
package org.tigris.subversion.subclipse.core.resources;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.team.IMoveDeleteHook;
import org.eclipse.core.resources.team.IResourceTree;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.team.core.TeamException;
import org.tigris.subversion.subclipse.core.ISVNLocalFile;
import org.tigris.subversion.subclipse.core.ISVNLocalFolder;
import org.tigris.subversion.subclipse.core.ISVNLocalResource;
import org.tigris.subversion.subclipse.core.Policy;
import org.tigris.subversion.subclipse.core.SVNException;
import org.tigris.subversion.subclipse.core.SVNTeamProvider;
import org.tigris.subversion.subclipse.core.client.OperationManager;
import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
import org.tigris.subversion.svnclientadapter.ISVNProperty;
import org.tigris.subversion.svnclientadapter.SVNClientException;

public class SVNMoveDeleteHook implements IMoveDeleteHook {
	private static Set deletedFiles = new HashSet();

    public boolean deleteFile(IResourceTree tree, IFile file, int updateFlags,
            IProgressMonitor monitor) {

        if (SVNWorkspaceRoot.isLinkedResource(file))
            return false;

        ISVNLocalFile resource = new LocalFile(file);
        try {
            if (!resource.isManaged()) {
                return false;
            }

            if (getDeferFileDelete(file))
            	return false;
            
            monitor.beginTask(null, 1000);
            deletedFiles.add(file);
            resource.delete();
            tree.deletedFile(file);           

        } catch (SVNException e) {
            tree.failed(e.getStatus());
        } finally {
            monitor.done();
        }
        return true;

    }

    public static boolean isDeleted(IFile file) {
    	return deletedFiles.contains(file);
    }
    
    public static void removeFromDeletedFileList(IFile file) {
    	deletedFiles.remove(file);
    }
    
    public boolean deleteFolder(IResourceTree tree, IFolder folder,
            int updateFlags, IProgressMonitor monitor) {

        if (SVNWorkspaceRoot.isLinkedResource(folder))
            return false;

        ISVNLocalFolder resource = new LocalFolder(folder);
        try {

            if (!resource.isManaged()) {
                return false;
            }
            monitor.beginTask(null, 1000);
            resource.delete();
        } catch (SVNException e) {
            tree.failed(e.getStatus());
        } finally {
            monitor.done();
        }
        return true;

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.core.resources.team.IMoveDeleteHook#moveFile(org.eclipse.core.resources.team.IResourceTree,
     *      org.eclipse.core.resources.IFile, org.eclipse.core.resources.IFile,
     *      int, org.eclipse.core.runtime.IProgressMonitor)
     */
    public boolean moveFile(IResourceTree tree, IFile source,
            IFile destination, int updateFlags, IProgressMonitor monitor) {

        if (SVNWorkspaceRoot.isLinkedResource(source))
            return false;

        try {
        	
        	RepositoryProvider repositoryProvider = RepositoryProvider
            .getProvider(destination.getProject());
        	
            if (repositoryProvider == null || !(repositoryProvider instanceof SVNTeamProvider)) //target is not SVN project
                throw new SVNException(Policy.bind("SVNMoveHook.moveFileException"));
        	
            ISVNLocalFile resource = new LocalFile(source);

            if (!resource.isManaged())
                return false; // pass

            ISVNClientAdapter svnClient = resource.getRepository()
                    .getSVNClient();
            monitor.beginTask(null, 1000);

            try {
                OperationManager.getInstance().beginOperation(svnClient);

                // add destination directory to version control if necessary
                // see bug #15
                if (!SVNWorkspaceRoot.getSVNFolderFor(destination.getParent())
                        .isManaged()) {
                    SVNTeamProvider provider = (SVNTeamProvider) repositoryProvider;
                    provider.add(new IResource[] { destination.getParent() },
                            IResource.DEPTH_ZERO, new NullProgressMonitor());
                    ISVNLocalResource parent = SVNWorkspaceRoot.getSVNResourceFor(destination.getParent());
                    if (parent != null) parent.refreshStatus();
                }

                // force is set to true because when we rename (refactor) a
                // java class, the file is modified before being moved
                // A modified file cannot be moved without force

               svnClient.move(source.getLocation().toFile(), 
            		   destination.getLocation().toFile(), true);

                //movedFile must be done before endOperation because
                // destination file must not already exist in the workspace
                // resource tree.
                tree.movedFile(source, destination);
                destination.refreshLocal(IResource.DEPTH_ZERO, monitor);
            } catch (SVNClientException e) {
                throw SVNException.wrapException(e);
            } catch (TeamException e) {
                throw SVNException.wrapException(e);
            } catch (CoreException e) {
                throw SVNException.wrapException(e);
            } finally {
                OperationManager.getInstance().endOperation(false);
            }

        } catch (SVNException e) {
            tree.failed(e.getStatus());
        } finally {
            monitor.done();
        }
        return true;
    }

    public boolean moveFolder(IResourceTree tree, IFolder source,
            IFolder destination, int updateFlags, IProgressMonitor monitor) {

        if (SVNWorkspaceRoot.isLinkedResource(source))
            return false;

        try {
            ISVNLocalFolder resource = new LocalFolder(source);
            if (!resource.isManaged())
                return false;
            
        	RepositoryProvider repositoryProvider = RepositoryProvider
            .getProvider(destination.getProject());

        	if (repositoryProvider == null || !(repositoryProvider instanceof SVNTeamProvider)) //target is not SVN project
        		 throw new SVNException(Policy.bind("SVNMoveHook.moveFolderException"));

            monitor.beginTask(null, 1000);

            ISVNClientAdapter svnClient = resource.getRepository().getSVNClient();

            try {
                OperationManager.getInstance().beginOperation(svnClient);
                // add destination directory to version control if necessary
                // see bug #15
                if (!SVNWorkspaceRoot.getSVNFolderFor(destination.getParent())
                        .isManaged()) {
                    SVNTeamProvider provider = (SVNTeamProvider)repositoryProvider;
                    provider.add(new IResource[] { destination.getParent() },
                            IResource.DEPTH_ZERO, new NullProgressMonitor());
                    ISVNLocalResource parent = SVNWorkspaceRoot.getSVNResourceFor(destination.getParent());
                    if (parent != null) parent.refreshStatus();
               }

               svnClient.move(source.getLocation().toFile(), 
            		   destination.getLocation().toFile(), true);

                tree.movedFolderSubtree(source, destination);
                destination.refreshLocal(IResource.DEPTH_INFINITE, monitor);

            } catch (SVNClientException e) {
                throw SVNException.wrapException(e);

            } catch (CoreException e) {
                throw SVNException.wrapException(e);
            } finally {
                OperationManager.getInstance().endOperation(false);
            }

        } catch (SVNException e) {
            tree.failed(e.getStatus());
        } finally {
            monitor.done();
        }
        return true;
    }

    /* (non-Javadoc)
     * @see org.eclipse.core.resources.team.IMoveDeleteHook#deleteProject(org.eclipse.core.resources.team.IResourceTree, org.eclipse.core.resources.IProject, int, org.eclipse.core.runtime.IProgressMonitor)
     */
    public boolean deleteProject(IResourceTree tree, IProject project, int updateFlags, IProgressMonitor monitor) {
        return false;
{'fraction_non_alphanumeric': 0.10436493168164176, 'fraction_numerical': 0.00361529055239513, 'mean_word_length': 2.290187161098478, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6966999', 'n_tokens_mistral': 4840, 'n_tokens_neox': 4597, 'n_words': 985}