[bugzilla 384447] Improve RepositoryAdapter's SaveContexts Lifecycle
diff --git a/tests/org.eclipse.mylyn.docs.intent.test.server/.checkstyle b/tests/org.eclipse.mylyn.docs.intent.test.server/.checkstyle
new file mode 100644
index 0000000..14d1806
--- /dev/null
+++ b/tests/org.eclipse.mylyn.docs.intent.test.server/.checkstyle
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<fileset-config file-format-version="1.2.0" simple-config="true">
+    <fileset name="tous" enabled="true" check-config-name="Intent" local="false">
+        <file-match-pattern match-pattern="." include-pattern="true"/>
+    </fileset>
+</fileset-config>
diff --git a/tests/org.eclipse.mylyn.docs.intent.test.server/.classpath b/tests/org.eclipse.mylyn.docs.intent.test.server/.classpath
new file mode 100644
index 0000000..64c5e31
--- /dev/null
+++ b/tests/org.eclipse.mylyn.docs.intent.test.server/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tests/org.eclipse.mylyn.docs.intent.test.server/.project b/tests/org.eclipse.mylyn.docs.intent.test.server/.project
new file mode 100644
index 0000000..b344f29
--- /dev/null
+++ b/tests/org.eclipse.mylyn.docs.intent.test.server/.project
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.eclipse.mylyn.docs.intent.test.server</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.atlassw.tools.eclipse.checkstyle.CheckstyleBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
+		<nature>com.atlassw.tools.eclipse.checkstyle.CheckstyleNature</nature>
+	</natures>
+</projectDescription>
diff --git a/tests/org.eclipse.mylyn.docs.intent.test.server/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.mylyn.docs.intent.test.server/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..af0f20f
--- /dev/null
+++ b/tests/org.eclipse.mylyn.docs.intent.test.server/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/tests/org.eclipse.mylyn.docs.intent.test.server/META-INF/MANIFEST.MF b/tests/org.eclipse.mylyn.docs.intent.test.server/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..0172c83
--- /dev/null
+++ b/tests/org.eclipse.mylyn.docs.intent.test.server/META-INF/MANIFEST.MF
@@ -0,0 +1,19 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Server
+Bundle-SymbolicName: org.eclipse.mylyn.docs.intent.test.server
+Bundle-Version: 0.7.0.qualifier
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.emf.cdo.server.db,
+ org.eclipse.emf.cdo.server.net4j,
+ org.eclipse.net4j.db.h2,
+ org.eclipse.net4j.tcp,
+ org.eclipse.emf.cdo.net4j
+Import-Package: org.h2,
+ org.h2.api,
+ org.h2.jdbcx,
+ org.h2.tools,
+ org.h2.util
+Export-Package: org.eclipse.mylyn.docs.intent.test.server
diff --git a/tests/org.eclipse.mylyn.docs.intent.test.server/about.html b/tests/org.eclipse.mylyn.docs.intent.test.server/about.html
new file mode 100644
index 0000000..670d108
--- /dev/null
+++ b/tests/org.eclipse.mylyn.docs.intent.test.server/about.html
@@ -0,0 +1,106 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
+<html xmlns="http://www.w3.org/1999/xhtml"> 
+<head> 
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
+<title>Eclipse Foundation Software User Agreement</title> 
+</head> 
+ 
+<body lang="EN-US"> 
+<h2>Eclipse Foundation Software User Agreement</h2> 
+<p>April 14, 2010</p> 
+ 
+<h3>Usage Of Content</h3> 
+ 
+<p>THE ECLIPSE FOUNDATION MAKES AVAILABLE SOFTWARE, DOCUMENTATION, INFORMATION AND/OR OTHER MATERIALS FOR OPEN SOURCE PROJECTS
+   (COLLECTIVELY &quot;CONTENT&quot;).  USE OF THE CONTENT IS GOVERNED BY THE TERMS AND CONDITIONS OF THIS AGREEMENT AND/OR THE TERMS AND
+   CONDITIONS OF LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW.  BY USING THE CONTENT, YOU AGREE THAT YOUR USE
+   OF THE CONTENT IS GOVERNED BY THIS AGREEMENT AND/OR THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR
+   NOTICES INDICATED OR REFERENCED BELOW.  IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT AND THE TERMS AND
+   CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW, THEN YOU MAY NOT USE THE CONTENT.</p> 
+ 
+<h3>Applicable Licenses</h3> 
+ 
+<p>Unless otherwise indicated, all Content made available by the Eclipse Foundation is provided to you under the terms and conditions of the Eclipse Public License Version 1.0
+   (&quot;EPL&quot;).  A copy of the EPL is provided with this Content and is also available at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+   For purposes of the EPL, &quot;Program&quot; will mean the Content.</p> 
+ 
+<p>Content includes, but is not limited to, source code, object code, documentation and other files maintained in the Eclipse Foundation source code
+   repository (&quot;Repository&quot;) in software modules (&quot;Modules&quot;) and made available as downloadable archives (&quot;Downloads&quot;).</p> 
+ 
+<ul> 
+       <li>Content may be structured and packaged into modules to facilitate delivering, extending, and upgrading the Content.  Typical modules may include plug-ins (&quot;Plug-ins&quot;), plug-in fragments (&quot;Fragments&quot;), and features (&quot;Features&quot;).</li> 
+       <li>Each Plug-in or Fragment may be packaged as a sub-directory or JAR (Java&trade; ARchive) in a directory named &quot;plugins&quot;.</li> 
+       <li>A Feature is a bundle of one or more Plug-ins and/or Fragments and associated material.  Each Feature may be packaged as a sub-directory in a directory named &quot;features&quot;.  Within a Feature, files named &quot;feature.xml&quot; may contain a list of the names and version numbers of the Plug-ins
+      and/or Fragments associated with that Feature.</li> 
+       <li>Features may also include other Features (&quot;Included Features&quot;). Within a Feature, files named &quot;feature.xml&quot; may contain a list of the names and version numbers of Included Features.</li> 
+</ul> 
+ 
+<p>The terms and conditions governing Plug-ins and Fragments should be contained in files named &quot;about.html&quot; (&quot;Abouts&quot;). The terms and conditions governing Features and
+Included Features should be contained in files named &quot;license.html&quot; (&quot;Feature Licenses&quot;).  Abouts and Feature Licenses may be located in any directory of a Download or Module
+including, but not limited to the following locations:</p> 
+ 
+<ul> 
+       <li>The top-level (root) directory</li> 
+       <li>Plug-in and Fragment directories</li> 
+       <li>Inside Plug-ins and Fragments packaged as JARs</li> 
+       <li>Sub-directories of the directory named &quot;src&quot; of certain Plug-ins</li> 
+       <li>Feature directories</li> 
+</ul> 
+ 
+<p>Note: if a Feature made available by the Eclipse Foundation is installed using the Provisioning Technology (as defined below), you must agree to a license (&quot;Feature Update License&quot;) during the
+installation process.  If the Feature contains Included Features, the Feature Update License should either provide you with the terms and conditions governing the Included Features or
+inform you where you can locate them.  Feature Update Licenses may be found in the &quot;license&quot; property of files named &quot;feature.properties&quot; found within a Feature.
+Such Abouts, Feature Licenses, and Feature Update Licenses contain the terms and conditions (or references to such terms and conditions) that govern your use of the associated Content in
+that directory.</p> 
+ 
+<p>THE ABOUTS, FEATURE LICENSES, AND FEATURE UPDATE LICENSES MAY REFER TO THE EPL OR OTHER LICENSE AGREEMENTS, NOTICES OR TERMS AND CONDITIONS.  SOME OF THESE
+OTHER LICENSE AGREEMENTS MAY INCLUDE (BUT ARE NOT LIMITED TO):</p> 
+ 
+<ul> 
+       <li>Common Public License Version 1.0 (available at <a href="http://www.eclipse.org/legal/cpl-v10.html">http://www.eclipse.org/legal/cpl-v10.html</a>)</li> 
+       <li>Apache Software License 1.1 (available at <a href="http://www.apache.org/licenses/LICENSE">http://www.apache.org/licenses/LICENSE</a>)</li> 
+       <li>Apache Software License 2.0 (available at <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a>)</li> 
+       <li>Metro Link Public License 1.00 (available at <a href="http://www.opengroup.org/openmotif/supporters/metrolink/license.html">http://www.opengroup.org/openmotif/supporters/metrolink/license.html</a>)</li> 
+       <li>Mozilla Public License Version 1.1 (available at <a href="http://www.mozilla.org/MPL/MPL-1.1.html">http://www.mozilla.org/MPL/MPL-1.1.html</a>)</li> 
+</ul> 
+ 
+<p>IT IS YOUR OBLIGATION TO READ AND ACCEPT ALL SUCH TERMS AND CONDITIONS PRIOR TO USE OF THE CONTENT.  If no About, Feature License, or Feature Update License is provided, please
+contact the Eclipse Foundation to determine what terms and conditions govern that particular Content.</p> 
+ 
+ 
+<h3>Use of Provisioning Technology</h3> 
+ 
+<p>The Eclipse Foundation makes available provisioning software, examples of which include, but are not limited to, p2 and the Eclipse
+   Update Manager (&quot;Provisioning Technology&quot;) for the purpose of allowing users to install software, documentation, information and/or
+   other materials (collectively &quot;Installable Software&quot;). This capability is provided with the intent of allowing such users to
+   install, extend and update Eclipse-based products. Information about packaging Installable Software is available at <a 
+       href="http://eclipse.org/equinox/p2/repository_packaging.html">http://eclipse.org/equinox/p2/repository_packaging.html</a> 
+   (&quot;Specification&quot;).</p> 
+ 
+<p>You may use Provisioning Technology to allow other parties to install Installable Software. You shall be responsible for enabling the
+   applicable license agreements relating to the Installable Software to be presented to, and accepted by, the users of the Provisioning Technology
+   in accordance with the Specification. By using Provisioning Technology in such a manner and making it available in accordance with the
+   Specification, you further acknowledge your agreement to, and the acquisition of all necessary rights to permit the following:</p> 
+ 
+<ol> 
+       <li>A series of actions may occur (&quot;Provisioning Process&quot;) in which a user may execute the Provisioning Technology
+       on a machine (&quot;Target Machine&quot;) with the intent of installing, extending or updating the functionality of an Eclipse-based
+       product.</li> 
+       <li>During the Provisioning Process, the Provisioning Technology may cause third party Installable Software or a portion thereof to be
+       accessed and copied to the Target Machine.</li> 
+       <li>Pursuant to the Specification, you will provide to the user the terms and conditions that govern the use of the Installable
+       Software (&quot;Installable Software Agreement&quot;) and such Installable Software Agreement shall be accessed from the Target
+       Machine in accordance with the Specification. Such Installable Software Agreement must inform the user of the terms and conditions that govern
+       the Installable Software and must solicit acceptance by the end user in the manner prescribed in such Installable Software Agreement. Upon such
+       indication of agreement by the user, the provisioning Technology will complete installation of the Installable Software.</li> 
+</ol> 
+ 
+<h3>Cryptography</h3> 
+ 
+<p>Content may contain encryption software. The country in which you are currently may have restrictions on the import, possession, and use, and/or re-export to
+   another country, of encryption software. BEFORE using any encryption software, please check the country's laws, regulations and policies concerning the import,
+   possession, or use, and re-export of encryption software, to see if this is permitted.</p> 
+ 
+<p><small>Java and all Java-based trademarks are trademarks of Oracle Corporation in the United States, other countries, or both.</small></p> 
+</body> 
+</html> 
\ No newline at end of file
diff --git a/tests/org.eclipse.mylyn.docs.intent.test.server/build.properties b/tests/org.eclipse.mylyn.docs.intent.test.server/build.properties
new file mode 100644
index 0000000..aa1a008
--- /dev/null
+++ b/tests/org.eclipse.mylyn.docs.intent.test.server/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .,\
+               plugin.properties
diff --git a/tests/org.eclipse.mylyn.docs.intent.test.server/plugin.properties b/tests/org.eclipse.mylyn.docs.intent.test.server/plugin.properties
new file mode 100644
index 0000000..8eec0c5
--- /dev/null
+++ b/tests/org.eclipse.mylyn.docs.intent.test.server/plugin.properties
@@ -0,0 +1,12 @@
+#################################################################################
+# Copyright (c) 2010, 2011 Obeo.
+# 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:
+#     Obeo - initial API and implementation
+#################################################################################
+pluginName = Intent UI Test
+providerName = Eclipse Mylyn
\ No newline at end of file
diff --git a/tests/org.eclipse.mylyn.docs.intent.test.server/pom.xml b/tests/org.eclipse.mylyn.docs.intent.test.server/pom.xml
new file mode 100644
index 0000000..5c50db1
--- /dev/null
+++ b/tests/org.eclipse.mylyn.docs.intent.test.server/pom.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Copyright (C) 2011 Obeo
+
+   Cedric Brun <cedric.brun@obeo.fr>
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.eclipse.mylyn.docs.intent-group</groupId>
+    <artifactId>intent-parent</artifactId>
+    <version>0.7.0-SNAPSHOT</version>
+    <relativePath>../..</relativePath>
+  </parent>
+
+  <artifactId>org.eclipse.mylyn.docs.intent.test.server</artifactId>
+  <packaging>eclipse-test-plugin</packaging>
+
+ <build>   
+    <plugins>
+      <plugin>
+        <groupId>org.eclipse.tycho</groupId>
+        <artifactId>tycho-source-plugin</artifactId>
+      </plugin>      
+    </plugins>
+  </build>
+
+
+
+</project>
diff --git a/tests/org.eclipse.mylyn.docs.intent.test.server/src/org/eclipse/mylyn/docs/intent/test/server/IntentCDORepository.java b/tests/org.eclipse.mylyn.docs.intent.test.server/src/org/eclipse/mylyn/docs/intent/test/server/IntentCDORepository.java
new file mode 100644
index 0000000..9984818
--- /dev/null
+++ b/tests/org.eclipse.mylyn.docs.intent.test.server/src/org/eclipse/mylyn/docs/intent/test/server/IntentCDORepository.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 Obeo.
+ * 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:
+ *     Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.docs.intent.test.server;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.eclipse.emf.cdo.server.CDOServerUtil;
+import org.eclipse.emf.cdo.server.IRepository;
+import org.eclipse.emf.cdo.server.IStore;
+import org.eclipse.emf.cdo.server.db.CDODBUtil;
+import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
+import org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.AbstractHorizontalMappingStrategy;
+import org.eclipse.emf.cdo.server.net4j.CDONet4jServerUtil;
+import org.eclipse.net4j.acceptor.IAcceptor;
+import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBAdapter;
+import org.eclipse.net4j.db.IDBConnectionProvider;
+import org.eclipse.net4j.db.h2.H2Adapter;
+import org.eclipse.net4j.util.container.IPluginContainer;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.h2.jdbcx.JdbcDataSource;
+
+/**
+ * A CDO repository used to test Intent.
+ * 
+ * @author <a href="mailto:alex.lagarde@obeo.fr">Alex Lagarde</a>
+ */
+public final class IntentCDORepository {
+
+	private static IRepository repository;
+
+	private static IAcceptor acceptor;
+
+	private static final String SERVER_LOCATION = "localhost";
+
+	private static final String SERVER_PORT_NUMBER = "2036";
+
+	/**
+	 * Private constructor.
+	 */
+	private IntentCDORepository() {
+
+	}
+
+	/**
+	 * Starts the Intent test Server (if not already launched).
+	 * 
+	 * @param cleanStore
+	 *            true if the store must be clean (i.e. database should be dropped)
+	 * @param repositoryName
+	 *            the name of the repository to launch
+	 */
+	public static void start(boolean cleanStore, String repositoryName) {
+		if (acceptor == null) {
+			// Step 1 : setting up the db
+			// Step 1.1 : defining the datasource
+			JdbcDataSource dataSource = new JdbcDataSource();
+			dataSource.setURL("jdbc:h2:_database/" + repositoryName);
+
+			// Step 1.2 : defining the mapping strategy
+			IMappingStrategy mappingStrategy = CDODBUtil.createHorizontalMappingStrategy(true);
+			Map<String, String> mappingProperties = new LinkedHashMap<String, String>();
+			mappingProperties.put(AbstractHorizontalMappingStrategy.PROP_OBJECT_TYPE_CACHE_SIZE, "1000");
+			mappingProperties.put(AbstractHorizontalMappingStrategy.PROP_QUALIFIED_NAMES,
+					Boolean.TRUE.toString());
+			mappingStrategy.setProperties(mappingProperties);
+
+			// Step 1.3 : use a H2 database
+			IDBAdapter dbAdapter = new H2Adapter();
+			IDBConnectionProvider dbConnectionProvider = DBUtil.createConnectionProvider(dataSource);
+
+			// Clean the store if needed
+			if (cleanStore) {
+				DBUtil.dropAllTables(dbConnectionProvider.getConnection(), repositoryName);
+			}
+
+			// Step 1.4 : creating the IStore from the specified DB
+			IStore store = CDODBUtil.createStore(mappingStrategy, dbAdapter, dbConnectionProvider);
+
+			// Step 2 : creating the repository
+			Map<String, String> props = new HashMap<String, String>();
+			props.put(IRepository.Props.OVERRIDE_UUID, repositoryName);
+			props.put(IRepository.Props.SUPPORTING_AUDITS, "false");
+			props.put(IRepository.Props.SUPPORTING_BRANCHES, "false");
+			props.put(IRepository.Props.SUPPORTING_ECORE, "true");
+
+			repository = CDOServerUtil.createRepository(repositoryName, store, props);
+
+			CDOServerUtil.addRepository(IPluginContainer.INSTANCE, repository);
+			CDONet4jServerUtil.prepareContainer(IPluginContainer.INSTANCE);
+
+			// Step 3 : creating an acceptor on the server side
+			acceptor = (IAcceptor)IPluginContainer.INSTANCE.getElement("org.eclipse.net4j.acceptors", "tcp",
+					SERVER_LOCATION + ":" + SERVER_PORT_NUMBER);
+		}
+	}
+
+	/**
+	 * Stops the currently running Intent test server.
+	 */
+	public static void stop() {
+		if (acceptor != null) {
+			LifecycleUtil.deactivate(acceptor);
+			LifecycleUtil.deactivate(repository);
+			acceptor = null;
+			repository = null;
+		}
+	}
+}