[Retro] Improving java retro : support of regular expressions to filter
the Java classes to synchronize inside a java project
diff --git a/examples/org.eclipse.mylyn.docs.intent.retro/src/org/eclipse/mylyn/docs/intent/retro/ProtocolFactory.java b/examples/org.eclipse.mylyn.docs.intent.retro/src/org/eclipse/mylyn/docs/intent/retro/ProtocolFactory.java
index 52e3129..8c41705 100644
--- a/examples/org.eclipse.mylyn.docs.intent.retro/src/org/eclipse/mylyn/docs/intent/retro/ProtocolFactory.java
+++ b/examples/org.eclipse.mylyn.docs.intent.retro/src/org/eclipse/mylyn/docs/intent/retro/ProtocolFactory.java
@@ -10,6 +10,8 @@
  *******************************************************************************/

 package org.eclipse.mylyn.docs.intent.retro;

 

+import java.util.regex.Pattern;

+

 import org.eclipse.core.resources.IProject;

 import org.eclipse.core.resources.IResource;

 import org.eclipse.core.resources.IResourceVisitor;

@@ -23,7 +25,8 @@
 public class ProtocolFactory implements Resource.Factory {

 

 	public Resource createResource(URI uri) {

-		String projectName = parse(uri);

+		String projectName = extractProjectName(uri);

+		String regExp = extractRegExp(uri);

 		if (projectName != null) {

 			IWorkspace wksps = ResourcesPlugin.getWorkspace();

 			if (wksps != null) {

@@ -33,7 +36,7 @@
 					Project rPrj = RetroFactory.eINSTANCE.createProject();

 					rPrj.setId(projectName);

 					try {

-						fillProjectWithTests(rPrj, prj);

+						fillProjectWithTests(rPrj, prj, regExp);

 					} catch (CoreException e) {

 						// TODO Auto-generated catch block

 						e.printStackTrace();

@@ -56,18 +59,24 @@
 

 	}

 

-	private void fillProjectWithTests(final Project rPrj, IProject prj) throws CoreException {

+	private void fillProjectWithTests(final Project rPrj, IProject prj, final String regExp)

+			throws CoreException {

+		final Pattern pattern = Pattern.compile(regExp, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);

 		prj.accept(new IResourceVisitor() {

 

 			public boolean visit(IResource resource) throws CoreException {

-				if ("java".equals(resource.getFileExtension())

-						&& resource.getFullPath().toString().contains("acceptance/comparedialog/patch")) {

-					// TODO really parse Java and retrieve U-tests

-					AcceptanceTest tst = RetroFactory.eINSTANCE.createAcceptanceTest();

-					tst.setSwtBotClassName(resource.getFullPath().lastSegment().replace(".java", ""));

-					tst.setPackage(resource.getFullPath().removeFirstSegments(2).removeFirstSegments(5)

-							.removeLastSegments(1).toString().replaceAll("/", "."));

-					rPrj.getAcceptanceTests().add(tst);

+				// We consider :

+				// java files

+				if ("java".equals(resource.getFileExtension())) {

+					String resourcePath = resource.getFullPath().removeFirstSegments(2)

+							.removeFirstSegments(5).removeLastSegments(1).toString().replaceAll("/", ".");

+					// that matches the given regExp

+					if (pattern.matcher(resourcePath).matches()) {

+						AcceptanceTest tst = RetroFactory.eINSTANCE.createAcceptanceTest();

+						tst.setSwtBotClassName(resource.getFullPath().lastSegment().replace(".java", ""));

+						tst.setPackage(resourcePath);

+						rPrj.getAcceptanceTests().add(tst);

+					}

 

 				}

 				return true;

@@ -77,16 +86,46 @@
 

 	}

 

-	private String parse(URI uri) {

-		// expected URIS are : retro:/myProject

-		if (uri.segmentCount() == 1) {

+	/**

+	 * Returns the project name for the given retro uri ("retro:/myProjectName[/myExpreg]").

+	 * 

+	 * @param uri

+	 *            the retro uri ("retro:/myProjectName[/myExpreg]")

+	 * @return the extracted project name or null if none found

+	 */

+	public static String extractProjectName(URI uri) {

+		// expected URIS are : retro:/myProject[/expreg]

+		if (uri.segmentCount() >= 1) {

 			return uri.segment(0);

 		}

 		return null;

 	}

 

-	class ParsedURI {

-

+	/**

+	 * Returns the regular expression for the given retro uri ("retro:/myProjectName[/myExpreg]").

+	 * 

+	 * @param uri

+	 *            the retro uri ("retro:/myProjectName[/myExpreg]")

+	 * @return the extracted regular expression or ".*" if none found

+	 */

+	public static String extractRegExp(URI uri) {

+		if (uri.segmentCount() > 1) {

+			// Getting the expreg

+			String regExp = "";

+			for (int i = 1; i < uri.segmentCount(); i++) {

+				if (i > 1) {

+					regExp += "/";

+				}

+				regExp += uri.segment(i);

+			}

+			// Replacing "." by literal characters

+			regExp = regExp.replace(".", "\\.");

+			// Replacing "*" by ".*" and "?" by "."

+			regExp = regExp.replace("*", ".*").replace("?", ".");

+			return regExp;

+		}

+		// If no expreg found, we return ".*"

+		return ".*";

 	}

 

 }

diff --git a/examples/org.eclipse.mylyn.docs.intent.retro/src/org/eclipse/mylyn/docs/intent/retro/RetroGeneratedElementListener.java b/examples/org.eclipse.mylyn.docs.intent.retro/src/org/eclipse/mylyn/docs/intent/retro/RetroGeneratedElementListener.java
index 00a2f42..7d9b9b6 100644
--- a/examples/org.eclipse.mylyn.docs.intent.retro/src/org/eclipse/mylyn/docs/intent/retro/RetroGeneratedElementListener.java
+++ b/examples/org.eclipse.mylyn.docs.intent.retro/src/org/eclipse/mylyn/docs/intent/retro/RetroGeneratedElementListener.java
@@ -72,10 +72,13 @@
 	 */

 	public void addListenedElements(SynchronizerRepositoryClient synchronizer, Set<URI> listenedElementsURIs) {

 		for (URI uri : listenedElementsURIs) {

-			if (!(uriToSynchronizers.containsKey(uri))) {

-				uriToSynchronizers.put(uri, Sets.<SynchronizerRepositoryClient> newLinkedHashSet());

+			// We only get the project uri

+			String projectName = ProtocolFactory.extractProjectName(uri);

+			URI simplifiedURI = URI.createURI("retro:/" + projectName);

+			if (!(uriToSynchronizers.containsKey(simplifiedURI))) {

+				uriToSynchronizers.put(simplifiedURI, Sets.<SynchronizerRepositoryClient> newLinkedHashSet());

 			}

-			uriToSynchronizers.get(uri).add(synchronizer);

+			uriToSynchronizers.get(simplifiedURI).add(synchronizer);

 		}

 	}

 

@@ -88,7 +91,10 @@
 	public void removeListenedElements(SynchronizerRepositoryClient synchronizer,

 			Set<URI> listenedElementsURIs) {

 		for (URI uri : listenedElementsURIs) {

-			uriToSynchronizers.remove(uri);

+			// We only get the project uri

+			String projectName = ProtocolFactory.extractProjectName(uri);

+			URI simplifiedURI = URI.createURI("retro:/" + projectName);

+			uriToSynchronizers.remove(simplifiedURI);

 		}

 	}

 

@@ -163,6 +169,8 @@
 			Set<SynchronizerRepositoryClient> listeningSynchronizers = uriToSynchronizers.get(uri);

 			if (listeningSynchronizers != null) {

 				synchronizersToNotify.addAll(listeningSynchronizers);

+			} else {

+				System.err.println("arg");

 			}

 		}

 		for (SynchronizerRepositoryClient listeningSynchronizer : synchronizersToNotify) {

diff --git a/plugins/org.eclipse.mylyn.docs.intent.client.compiler/src/org/eclipse/mylyn/docs/intent/client/compiler/saver/CompilerInformationsSaver.java b/plugins/org.eclipse.mylyn.docs.intent.client.compiler/src/org/eclipse/mylyn/docs/intent/client/compiler/saver/CompilerInformationsSaver.java
index 35b32e3..2fac2aa 100644
--- a/plugins/org.eclipse.mylyn.docs.intent.client.compiler/src/org/eclipse/mylyn/docs/intent/client/compiler/saver/CompilerInformationsSaver.java
+++ b/plugins/org.eclipse.mylyn.docs.intent.client.compiler/src/org/eclipse/mylyn/docs/intent/client/compiler/saver/CompilerInformationsSaver.java
@@ -280,6 +280,8 @@
 				resourcePath = resourcePath.substring(resourcePath.lastIndexOf('/') + 1);
 			}
 		}
+		// Removing invalid characters
+		resourcePath = resourcePath.replace("*", "").replace("?", "");
 		resourcePath = IntentLocations.GENERATED_RESOURCES_FOLDER_PATH + resourcePath;
 		return resourcePath;
 	}
diff --git a/plugins/org.eclipse.mylyn.docs.intent.collab.ide/src/org/eclipse/mylyn/docs/intent/collab/ide/repository/WorkspaceSession.java b/plugins/org.eclipse.mylyn.docs.intent.collab.ide/src/org/eclipse/mylyn/docs/intent/collab/ide/repository/WorkspaceSession.java
index 66ce330..5fc9691 100644
--- a/plugins/org.eclipse.mylyn.docs.intent.collab.ide/src/org/eclipse/mylyn/docs/intent/collab/ide/repository/WorkspaceSession.java
+++ b/plugins/org.eclipse.mylyn.docs.intent.collab.ide/src/org/eclipse/mylyn/docs/intent/collab/ide/repository/WorkspaceSession.java
@@ -11,6 +11,7 @@
 package org.eclipse.mylyn.docs.intent.collab.ide.repository;

 

 import com.google.common.collect.Iterables;

+import com.google.common.collect.Sets;

 

 import java.io.IOException;

 import java.util.ArrayList;

@@ -287,9 +288,9 @@
 		}

 

 		// Step 2 : notifying element listeners

-		for (EObject root : resource.getContents()) {

-			for (ElementListAdapter elementListAdapter : Iterables.filter(root.eAdapters(),

-					ElementListAdapter.class)) {

+		for (EObject root : Sets.newLinkedHashSet(resource.getContents())) {

+			for (ElementListAdapter elementListAdapter : Sets.newLinkedHashSet(Iterables.filter(

+					root.eAdapters(), ElementListAdapter.class))) {

 				elementListAdapter.notifyChangesOnElement(root);

 			}

 		}

diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/data/unit/demo/demo.zip b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/data/unit/demo/demo.zip
index b6f40b7..139a72e 100644
--- a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/data/unit/demo/demo.zip
+++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/data/unit/demo/demo.zip
Binary files differ
diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/synchronization/JavaTest.java b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/synchronization/JavaTest.java
index 5b93b37..f23bc0b 100644
--- a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/synchronization/JavaTest.java
+++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/synchronization/JavaTest.java
@@ -133,7 +133,8 @@
 

 		repositoryListener.startRecording();

 		editor72.doSave(new NullProgressMonitor());

-		waitForCompiler();

+		editor72.close(false);

+		waitForSynchronizer();

 

 		// Step 6.3 : check 7.1

 		assertFalse(TEST_SYNCHRONIZER_INVALID_WARNING_MSG, AnnotationUtils.hasIntentAnnotation(editor71,

@@ -142,6 +143,7 @@
 		// Step 7 : fix error in 3.7

 		document37.set(getFileContent(SECTION_37_V3_FILENAME));

 		editor37.doSave(new NullProgressMonitor());

+		editor37.close(false);

 		assertFalse(TEST_COMPILER_INVALID_ERROR_MSG, AnnotationUtils.hasIntentAnnotation(editor37,

 				IntentAnnotationMessageType.COMPILER_INFO,

 				"-The required feature 'isTestedBy' of 'patchingDifferences' must be set", true));