diff --git a/plugins/gradle/resources/i18n/GradleBundle.properties b/plugins/gradle/resources/i18n/GradleBundle.properties
index e85e37d53385..2f5a36196e9f 100644
--- a/plugins/gradle/resources/i18n/GradleBundle.properties
+++ b/plugins/gradle/resources/i18n/GradleBundle.properties
@@ -55,6 +55,7 @@ gradle.sync.change.type.conflict=Settings conflict
gradle.sync.change.type.unchanged=Unchanged setting
gradle.sync.change.type.confirmed=Confirmed settings diff
gradle.sync.change.entity.type.module=module
+gradle.sync.change.entity.type.module.dependency=module dependency
gradle.sync.change.entity.type.library.dependency=library dependency
gradle.sync.change.library.path=library ''{0}'' binary path
gradle.sync.change.project.name.text=project name
diff --git a/plugins/gradle/src/META-INF/plugin.xml b/plugins/gradle/src/META-INF/plugin.xml
index 71c23dd96f02..50b6a4bbf64c 100644
--- a/plugins/gradle/src/META-INF/plugin.xml
+++ b/plugins/gradle/src/META-INF/plugin.xml
@@ -38,6 +38,7 @@
+
diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/GradleAbstractDependencyStructureChangesCalculator.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/GradleAbstractDependencyStructureChangesCalculator.java
new file mode 100644
index 000000000000..5c6977b2ae36
--- /dev/null
+++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/GradleAbstractDependencyStructureChangesCalculator.java
@@ -0,0 +1,25 @@
+package org.jetbrains.plugins.gradle.diff;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.gradle.model.gradle.GradleEntity;
+
+/**
+ * Manages common dependency properties like 'scope', 'exported'.
+ *
+ * Thread-safe.
+ *
+ * @author Denis Zhdanov
+ * @since 2/20/12 11:17 AM
+ */
+public abstract class GradleAbstractDependencyStructureChangesCalculator
+ implements GradleStructureChangesCalculator
+{
+ @Override
+ public void calculate(@NotNull G gradleEntity, @NotNull I intellijEntity, @NotNull GradleChangesCalculationContext context)
+ {
+ // TODO den process common dependency properties here.
+ doCalculate(gradleEntity, intellijEntity, context);
+ }
+
+ protected abstract void doCalculate(@NotNull G gradleEntity, @NotNull I intellijEntity, @NotNull GradleChangesCalculationContext context);
+}
diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/GradleChangesCalculationContext.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/GradleChangesCalculationContext.java
new file mode 100644
index 000000000000..7511561cb088
--- /dev/null
+++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/GradleChangesCalculationContext.java
@@ -0,0 +1,53 @@
+package org.jetbrains.plugins.gradle.diff;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * 'Parameter object' to use during project structure changes calculations.
+ *
+ * Thread-safe.
+ */
+public class GradleChangesCalculationContext {
+
+ @NotNull private final Set myKnownChanges = new HashSet();
+ @NotNull private final Set myCurrentChanges = new HashSet();
+
+ @NotNull private final PlatformFacade myPlatformFacade;
+
+ /**
+ * @param knownChanges changes between the gradle and intellij project structure that has been known up until now
+ * @param platformFacade platform facade to use during the calculations
+ */
+ public GradleChangesCalculationContext(@NotNull Set knownChanges,
+ @NotNull PlatformFacade platformFacade)
+ {
+ myKnownChanges.addAll(knownChanges);
+ myPlatformFacade = platformFacade;
+ }
+
+ @NotNull
+ public Set getKnownChanges() {
+ return myKnownChanges;
+ }
+
+ @NotNull
+ public Set getCurrentChanges() {
+ return myCurrentChanges;
+ }
+
+ public void register(@NotNull GradleProjectStructureChange change) {
+ myCurrentChanges.add(change);
+ }
+
+ public boolean hasNewChanges() {
+ return !myKnownChanges.equals(myCurrentChanges);
+ }
+
+ @NotNull
+ public PlatformFacade getPlatformFacade() {
+ return myPlatformFacade;
+ }
+}
diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/GradleDiffUtil.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/GradleDiffUtil.java
index 243003b92ff7..16ee64b7690f 100644
--- a/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/GradleDiffUtil.java
+++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/diff/GradleDiffUtil.java
@@ -1,11 +1,17 @@
package org.jetbrains.plugins.gradle.diff;
import com.intellij.openapi.module.Module;
+import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.LibraryOrderEntry;
+import com.intellij.openapi.roots.ModuleOrderEntry;
+import com.intellij.openapi.roots.OrderEntry;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.gradle.model.gradle.*;
+import org.jetbrains.plugins.gradle.model.intellij.IntellijEntityVisitor;
+import org.jetbrains.plugins.gradle.util.GradleUtil;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
/**
* Contains various utility methods for building changes between the gradle and intellij project structures.
@@ -25,10 +31,10 @@ public class GradleDiffUtil {
* Example: particular module has been added at the gradle side. We want to mark that module, its content root(s), dependencies etc
* as gradle-local changes.
*
- * @param entity target gradle-local entity
- * @param currentChanges holder for the changes built during the current call
+ * @param entity target gradle-local entity
+ * @param context changes calculation context to use
*/
- public static void buildLocalChanges(@NotNull GradleEntity entity, @NotNull final Set currentChanges) {
+ public static void buildLocalChanges(@NotNull GradleEntity entity, @NotNull final GradleChangesCalculationContext context) {
entity.invite(new GradleEntityVisitor() {
@Override
public void visit(@NotNull GradleProject project) {
@@ -37,7 +43,7 @@ public class GradleDiffUtil {
@Override
public void visit(@NotNull GradleModule module) {
- currentChanges.add(new GradleModulePresenceChange(module, null));
+ context.register(new GradleModulePresenceChange(module, null));
for (GradleDependency dependency : module.getDependencies()) {
dependency.invite(this);
}
@@ -55,59 +61,56 @@ public class GradleDiffUtil {
@Override
public void visit(@NotNull GradleModuleDependency dependency) {
- // TODO den implement
+ context.register(new GradleModuleDependencyPresenceChange(dependency, null));
}
@Override
public void visit(@NotNull GradleLibraryDependency dependency) {
- currentChanges.add(new GradleLibraryDependencyPresenceChange(dependency, null));
+ context.register(new GradleLibraryDependencyPresenceChange(dependency, null));
}
});
}
- /**
- * Analogues to {@link #buildLocalChanges} but targets intellij entity.
- *
- * @param module target intellij-local module that doesn't present at the gradle side
- * @param currentChanges holder for the changes built during the current call
- */
- public static void buildLocalChanges(@NotNull Module module,
- @NotNull Set currentChanges)
- {
- currentChanges.add(new GradleModulePresenceChange(null, module));
- // TODO den process module sub-entities here (content roots and dependencies).
- }
-
- /**
- * Analogues to {@link #buildLocalChanges} but targets intellij entity.
- *
- * @param libraryDependency target intellij-local library dependency that doesn't present at the gradle side
- * @param currentChanges holder for the changes built during the current call
- */
- public static void buildLocalChanges(@NotNull LibraryOrderEntry libraryDependency,
- @NotNull Set currentChanges)
- {
- final String libraryName = libraryDependency.getLibraryName();
- if (libraryName != null) {
- currentChanges.add(new GradleLibraryDependencyPresenceChange(null, libraryDependency));
- }
- }
-
/**
* Performs argument type-based dispatch and delegates to one of strongly typed 'buildLocalChanges()' methods.
*
- * @param entity target intellij-local entity that doesn't present at the gradle side
- * @param currentChanges holder for the changes built during the current call
+ * @param entity target intellij-local entity that doesn't present at the gradle side
+ * @param context changes calculation context to use
*/
- public static void buildLocalChanges(@NotNull Object entity, @NotNull Set currentChanges) {
+ public static void buildLocalChanges(@NotNull Object entity, @NotNull final GradleChangesCalculationContext context) {
if (entity instanceof GradleEntity) {
- buildLocalChanges((GradleEntity)entity, currentChanges);
+ buildLocalChanges((GradleEntity)entity, context);
}
- else if (entity instanceof Module) {
- buildLocalChanges((Module)entity, currentChanges);
- }
- else if (entity instanceof LibraryOrderEntry) {
- buildLocalChanges((LibraryOrderEntry)entity, currentChanges);
+ else {
+ GradleUtil.dispatch(entity, new IntellijEntityVisitor() {
+ @Override
+ public void visit(@NotNull Project project) {
+ }
+
+ @Override
+ public void visit(@NotNull Module module) {
+ context.register(new GradleModulePresenceChange(null, module));
+ for (OrderEntry entry : context.getPlatformFacade().getOrderEntries(module)) {
+ GradleUtil.dispatch(entry, this);
+ }
+ }
+
+ @Override
+ public void visit(@NotNull LibraryOrderEntry libraryDependency) {
+ final String libraryName = libraryDependency.getLibraryName();
+ if (libraryName != null) {
+ context.register(new GradleLibraryDependencyPresenceChange(null, libraryDependency));
+ }
+ }
+
+ @Override
+ public void visit(@NotNull ModuleOrderEntry moduleDependency) {
+ final Module module = moduleDependency.getModule();
+ if (module != null) {
+ context.register(new GradleModuleDependencyPresenceChange(null, moduleDependency));
+ }
+ }
+ });
}
}
@@ -120,8 +123,7 @@ public class GradleDiffUtil {
* @param calculator comparison strategy that works with the single entities (not collection of entities)
* @param gradleEntities entities available at the gradle side
* @param intellijEntities entities available at the intellij side
- * @param knownChanges collection that contains known changes about the entities
- * @param currentChanges holder for the changes discovered during the current call
+ * @param context changes calculation context
* @param target intellij entity type
* @param target gradle entity type
*/
@@ -129,8 +131,7 @@ public class GradleDiffUtil {
@NotNull GradleStructureChangesCalculator calculator,
@NotNull Iterable extends G> gradleEntities,
@NotNull Iterable extends I> intellijEntities,
- @NotNull Set knownChanges,
- @NotNull Set currentChanges)
+ @NotNull GradleChangesCalculationContext context)
{
Map