diff options
author | Tomasz Zarna | 2008-05-07 13:52:29 +0000 |
---|---|---|
committer | Tomasz Zarna | 2008-05-07 13:52:29 +0000 |
commit | 8dc485b46793697cd72615e1909a7cbc8733e243 (patch) | |
tree | 4f96fea2ebad077bf7874bf92e0287050e108877 /tests/org.eclipse.team.tests.core/src/org/eclipse | |
parent | 9aee6c3979d030d789b270cac123b80cc4dee913 (diff) | |
download | eclipse.platform.team-8dc485b46793697cd72615e1909a7cbc8733e243.tar.gz eclipse.platform.team-8dc485b46793697cd72615e1909a7cbc8733e243.tar.xz eclipse.platform.team-8dc485b46793697cd72615e1909a7cbc8733e243.zip |
Diffstat (limited to 'tests/org.eclipse.team.tests.core/src/org/eclipse')
4 files changed, 200 insertions, 1 deletions
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamTests.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamTests.java index 5ff47c6fc..669a77d6b 100644 --- a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamTests.java +++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation 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 @@ -37,6 +37,7 @@ public class AllTeamTests extends ResourceTest { suite.addTest(RepositoryProviderTests.suite()); suite.addTest(StreamTests.suite()); suite.addTest(StorageMergerTests.suite()); + suite.addTest(org.eclipse.team.tests.core.regression.AllTests.suite()); return suite; } } diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/regression/AllTests.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/regression/AllTests.java new file mode 100644 index 000000000..b9ec67523 --- /dev/null +++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/regression/AllTests.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.tests.core.regression; + +import junit.framework.*; + +public class AllTests extends TestCase { + public AllTests() { + super(null); + } + + public AllTests(String name) { + super(name); + } + + public static Test suite() { + TestSuite suite = new TestSuite(AllTests.class.getName()); + suite.addTest(Bug_217673.suite()); + return suite; + } +} diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/regression/Bug_217673.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/regression/Bug_217673.java new file mode 100644 index 000000000..69bf485d2 --- /dev/null +++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/regression/Bug_217673.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.tests.core.regression; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourceAttributes; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.team.core.RepositoryProvider; +import org.eclipse.team.tests.core.TeamTest; + +public class Bug_217673 extends TeamTest { + + public void test() throws CoreException { + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + final IProject project = workspace.getRoot().getProject( + getUniqueString()); + project.create(null); + project.open(null); + IResource resource = project.getFile(".project"); + try { + RepositoryProvider.map(project, + PessimisticRepositoryProvider.NATURE_ID); + PessimisticRepositoryProvider.markWritableOnEdit = true; + setReadOnly(resource, true); + project.getFolder("test").createLink(getTempDir(), IResource.NONE, + null); + assertTrue(".project should no longer be read-only", + !isReadOnly(resource)); + } finally { + PessimisticRepositoryProvider.markWritableOnEdit = false; + RepositoryProvider.unmap(project); + } + } + + private boolean isReadOnly(IResource resource) { + ResourceAttributes resourceAttributes = resource + .getResourceAttributes(); + return resourceAttributes.isReadOnly(); + } + + public static Test suite() { + return new TestSuite(Bug_217673.class); + } + +} diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/regression/PessimisticRepositoryProvider.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/regression/PessimisticRepositoryProvider.java new file mode 100644 index 000000000..e65f5dab1 --- /dev/null +++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/regression/PessimisticRepositoryProvider.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.tests.core.regression; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFileModificationValidator; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourceAttributes; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.team.core.RepositoryProvider; + +/** + * Repository provider that can be configured to be pessimistic. + */ +public class PessimisticRepositoryProvider extends RepositoryProvider implements IFileModificationValidator { + private static PessimisticRepositoryProvider soleInstance; + + public static final String NATURE_ID = "org.eclipse.team.tests.core.regression.pessimistic-provider"; + + public static boolean markWritableOnEdit; + public static boolean markWritableOnSave; + + public PessimisticRepositoryProvider() { + soleInstance = this; + } + + public void configureProject() { + } + + public String getID() { + return NATURE_ID; + } + + public void deconfigure() { + } + public boolean canHandleLinkedResourceURI() { + return true; + } + /* + * @see IRepositoryProvider#getFileModificationValidator() + */ + public IFileModificationValidator getFileModificationValidator() { + return soleInstance; + } + + public IStatus validateEdit(final IFile[] files, Object context) { + if (markWritableOnEdit) { + try { + ResourcesPlugin.getWorkspace().run( + new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) { + for (int i = 0, length = files.length; i < length; i++) { + try { + setReadOnly(files[i], false); + } catch (CoreException e) { + e.printStackTrace(); + } + } + } + }, + null); + } catch (CoreException e) { + e.printStackTrace(); + return e.getStatus(); + } + } + return Status.OK_STATUS; + } + + public IStatus validateSave(IFile file) { + if (markWritableOnSave) { + try { + setReadOnly(file, false); + } catch (CoreException e) { + e.printStackTrace(); + return e.getStatus(); + } + } + return Status.OK_STATUS; + } + + public void setReadOnly(IResource resource, boolean readOnly) throws CoreException { + ResourceAttributes resourceAttributes = resource.getResourceAttributes(); + if (resourceAttributes != null) { + resourceAttributes.setReadOnly(readOnly); + resource.setResourceAttributes(resourceAttributes); + } + } + + public boolean isReadOnly(IResource resource) throws CoreException { + ResourceAttributes resourceAttributes = resource.getResourceAttributes(); + if (resourceAttributes != null) { + return resourceAttributes.isReadOnly(); + } + return false; + } +} |