mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-76142: Gradle support - cannot update IDEA projects once one of build.gradle files changes
1. Gradle node descriptor uses only entity id as a data value now; 2. Minor refactorings;
This commit is contained in:
+3
-1
@@ -18,6 +18,7 @@ import com.intellij.ui.treeStructure.Tree;
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.gradle.model.id.GradleSyntheticId;
|
||||
import org.jetbrains.plugins.gradle.ui.GradleIcons;
|
||||
import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNodeDescriptor;
|
||||
import org.jetbrains.plugins.gradle.util.GradleBundle;
|
||||
@@ -257,7 +258,8 @@ public class GradleColorAndFontPreviewPanel implements PreviewPanel {
|
||||
}
|
||||
|
||||
private DefaultMutableTreeNode createNode(@NotNull String text, @NotNull Icon icon, @Nullable TextAttributesKey textAttributesKey) {
|
||||
final GradleProjectStructureNodeDescriptor<String> descriptor = new GradleProjectStructureNodeDescriptor<String>(text, text, icon);
|
||||
final GradleProjectStructureNodeDescriptor<GradleSyntheticId> descriptor
|
||||
= new GradleProjectStructureNodeDescriptor<GradleSyntheticId>(new GradleSyntheticId(text), text, icon);
|
||||
DefaultMutableTreeNode result = new DefaultMutableTreeNode(descriptor);
|
||||
if (textAttributesKey != null) {
|
||||
final PresentationData presentation = descriptor.getPresentation();
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
@@ -41,12 +40,6 @@ public interface PlatformFacade {
|
||||
@NotNull
|
||||
Collection<OrderEntry> getOrderEntries(@NotNull Module module);
|
||||
|
||||
/**
|
||||
* @return icon that should be used for representation project root node at the tree UI controls used by the gradle integration
|
||||
*/
|
||||
@NotNull
|
||||
Icon getProjectIcon();
|
||||
|
||||
/**
|
||||
* Allows to derive from the given VFS file path that may be compared to the path used by the gradle api.
|
||||
* <p/>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.jetbrains.plugins.gradle.diff;
|
||||
|
||||
import com.intellij.openapi.application.ex.ApplicationInfoEx;
|
||||
import com.intellij.openapi.fileTypes.FileTypes;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
@@ -10,13 +9,11 @@ import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderEntry;
|
||||
import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -50,12 +47,6 @@ public class PlatformFacadeImpl implements PlatformFacade {
|
||||
return Arrays.asList(ModuleRootManager.getInstance(module).getOrderEntries());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Icon getProjectIcon() {
|
||||
return IconLoader.getIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getLocalFileSystemPath(@NotNull VirtualFile file) {
|
||||
|
||||
+10
-14
@@ -98,35 +98,31 @@ public class GradleLocalNodeImportHelper {
|
||||
// Collect up.
|
||||
for (GradleProjectStructureNode<?> n = node.getParent(); n != null; n = n.getParent()) {
|
||||
final GradleProjectStructureNodeDescriptor<?> descriptor = n.getDescriptor();
|
||||
if (n.getType() == GradleEntityType.SYNTHETIC) {
|
||||
if (n.getDescriptor().getElement().getType() == GradleEntityType.SYNTHETIC) {
|
||||
continue;
|
||||
}
|
||||
if (descriptor.getAttributes() != GradleTextAttributes.GRADLE_LOCAL_CHANGE) {
|
||||
break;
|
||||
}
|
||||
Object id = descriptor.getElement();
|
||||
if (id instanceof GradleEntityId) {
|
||||
final Object entity = myIdMapper.mapIdToEntity((GradleEntityId)id);
|
||||
if (entity instanceof GradleEntity) {
|
||||
((GradleEntity)entity).invite(context.visitor);
|
||||
}
|
||||
final Object entity = myIdMapper.mapIdToEntity((GradleEntityId)id);
|
||||
if (entity instanceof GradleEntity) {
|
||||
((GradleEntity)entity).invite(context.visitor);
|
||||
}
|
||||
}
|
||||
|
||||
// Collect down.
|
||||
final Stack<GradleEntity> toProcess = new Stack<GradleEntity>();
|
||||
final Object id = node.getDescriptor().getElement();
|
||||
if (id instanceof GradleEntityId) {
|
||||
final Object entity = myIdMapper.mapIdToEntity((GradleEntityId)id);
|
||||
if (entity instanceof GradleEntity) {
|
||||
toProcess.push((GradleEntity)entity);
|
||||
}
|
||||
final Object entity = myIdMapper.mapIdToEntity((GradleEntityId)id);
|
||||
if (entity instanceof GradleEntity) {
|
||||
toProcess.push((GradleEntity)entity);
|
||||
}
|
||||
|
||||
|
||||
context.recursive = true;
|
||||
while (!toProcess.isEmpty()) {
|
||||
final GradleEntity entity = toProcess.pop();
|
||||
entity.invite(context.visitor);
|
||||
final GradleEntity e = toProcess.pop();
|
||||
e.invite(context.visitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-13
@@ -8,9 +8,10 @@ import com.intellij.ui.treeStructure.Tree;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.gradle.importing.GradleProjectImportBuilder;
|
||||
import org.jetbrains.plugins.gradle.model.*;
|
||||
import org.jetbrains.plugins.gradle.importing.wizard.AbstractImportFromGradleWizardStep;
|
||||
import org.jetbrains.plugins.gradle.model.gradle.*;
|
||||
import org.jetbrains.plugins.gradle.model.id.GradleEntityId;
|
||||
import org.jetbrains.plugins.gradle.model.id.GradleSyntheticId;
|
||||
import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNode;
|
||||
import org.jetbrains.plugins.gradle.util.GradleBundle;
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants;
|
||||
@@ -18,7 +19,10 @@ import org.jetbrains.plugins.gradle.util.GradleConstants;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.*;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.MutableTreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
@@ -175,7 +179,7 @@ public class GradleAdjustImportSettingsStep extends AbstractImportFromGradleWiza
|
||||
Map<GradleEntity, Pair<String, Collection<GradleProjectStructureNode>>> entity2nodes
|
||||
= new HashMap<GradleEntity, Pair<String, Collection<GradleProjectStructureNode>>>();
|
||||
int counter = 0;
|
||||
GradleProjectStructureNode<GradleProject> root = buildNode(project, entity2nodes, counter++);
|
||||
GradleProjectStructureNode<GradleEntityId> root = buildNode(project, entity2nodes, counter++);
|
||||
|
||||
List<GradleModule> modules = new ArrayList<GradleModule>(project.getModules());
|
||||
Collections.sort(modules, Named.COMPARATOR);
|
||||
@@ -186,15 +190,15 @@ public class GradleAdjustImportSettingsStep extends AbstractImportFromGradleWiza
|
||||
for (GradleModule module : modules) {
|
||||
GradleModule moduleCopy = module.clone(cloneContext);
|
||||
moduleMappings.put(module, moduleCopy);
|
||||
GradleProjectStructureNode<GradleModule> moduleNode = buildNode(module, entity2nodes, counter++);
|
||||
GradleProjectStructureNode<GradleEntityId> moduleNode = buildNode(module, entity2nodes, counter++);
|
||||
moduleNodes.add(moduleNode);
|
||||
for (GradleContentRoot contentRoot : moduleCopy.getContentRoots()) {
|
||||
moduleNode.add(buildNode(contentRoot, entity2nodes, counter++));
|
||||
}
|
||||
Collection<GradleDependency> dependencies = module.getDependencies();
|
||||
if (!dependencies.isEmpty()) {
|
||||
GradleProjectStructureNode<String> dependenciesNode
|
||||
= new GradleProjectStructureNode<String>(GradleConstants.DEPENDENCIES_NODE_DESCRIPTOR, GradleEntityType.SYNTHETIC);
|
||||
GradleProjectStructureNode<GradleSyntheticId> dependenciesNode
|
||||
= new GradleProjectStructureNode<GradleSyntheticId>(GradleConstants.DEPENDENCIES_NODE_DESCRIPTOR);
|
||||
final List<GradleModuleDependency> moduleDependencies = new ArrayList<GradleModuleDependency>();
|
||||
final List<GradleLibraryDependency> libraryDependencies = new ArrayList<GradleLibraryDependency>();
|
||||
GradleEntityVisitor visitor = new GradleEntityVisitorAdapter() {
|
||||
@@ -234,8 +238,8 @@ public class GradleAdjustImportSettingsStep extends AbstractImportFromGradleWiza
|
||||
}
|
||||
else {
|
||||
// Insert intermediate 'modules' and 'libraries' nodes if the project has both libraries and nodes.
|
||||
GradleProjectStructureNode<String> modulesNode
|
||||
= new GradleProjectStructureNode<String>(GradleConstants.MODULES_NODE_DESCRIPTOR, GradleEntityType.SYNTHETIC);
|
||||
GradleProjectStructureNode<GradleSyntheticId> modulesNode
|
||||
= new GradleProjectStructureNode<GradleSyntheticId>(GradleConstants.MODULES_NODE_DESCRIPTOR);
|
||||
for (MutableTreeNode node : moduleNodes) {
|
||||
modulesNode.add(node);
|
||||
}
|
||||
@@ -243,8 +247,8 @@ public class GradleAdjustImportSettingsStep extends AbstractImportFromGradleWiza
|
||||
|
||||
List<GradleLibrary> sortedLibraries = new ArrayList<GradleLibrary>(libraries);
|
||||
Collections.sort(sortedLibraries, Named.COMPARATOR);
|
||||
GradleProjectStructureNode<String> librariesNode
|
||||
= new GradleProjectStructureNode<String>(GradleConstants.LIBRARIES_NODE_DESCRIPTOR, GradleEntityType.SYNTHETIC);
|
||||
GradleProjectStructureNode<GradleSyntheticId> librariesNode
|
||||
= new GradleProjectStructureNode<GradleSyntheticId>(GradleConstants.LIBRARIES_NODE_DESCRIPTOR);
|
||||
for (GradleLibrary library : sortedLibraries) {
|
||||
librariesNode.add(buildNode(library, entity2nodes, counter++));
|
||||
}
|
||||
@@ -258,13 +262,13 @@ public class GradleAdjustImportSettingsStep extends AbstractImportFromGradleWiza
|
||||
builder.setModuleMappings(moduleMappings);
|
||||
}
|
||||
|
||||
private <T extends GradleEntity> GradleProjectStructureNode<T> buildNode(
|
||||
@NotNull T entity, @NotNull Map<GradleEntity, Pair<String, Collection<GradleProjectStructureNode>>> processed, int counter)
|
||||
private GradleProjectStructureNode<GradleEntityId> buildNode(
|
||||
@NotNull GradleEntity entity, @NotNull Map<GradleEntity, Pair<String, Collection<GradleProjectStructureNode>>> processed, int counter)
|
||||
{
|
||||
// We build tree node, its settings control and map them altogether. The only trick here is that nodes can reuse the same
|
||||
// settings control (e.g. more than one node may have the same library as a dependency, so, library dependency node for
|
||||
// every control will use the same settings control).
|
||||
GradleProjectStructureNode<T> result = new GradleProjectStructureNode<T>(myFactory.buildDescriptor(entity), GradleEntityType.SYNTHETIC);
|
||||
GradleProjectStructureNode<GradleEntityId> result = new GradleProjectStructureNode<GradleEntityId>(myFactory.buildDescriptor(entity));
|
||||
Pair<String, Collection<GradleProjectStructureNode>> pair = processed.get(entity);
|
||||
if (pair == null) {
|
||||
String cardName = String.valueOf(counter);
|
||||
|
||||
+10
-15
@@ -1,14 +1,14 @@
|
||||
package org.jetbrains.plugins.gradle.importing.wizard.adjust;
|
||||
|
||||
import com.intellij.openapi.application.ex.ApplicationInfoEx;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.gradle.model.gradle.*;
|
||||
import org.jetbrains.plugins.gradle.ui.GradleIcons;
|
||||
import org.jetbrains.plugins.gradle.model.id.GradleEntityId;
|
||||
import org.jetbrains.plugins.gradle.model.id.GradleEntityIdMapper;
|
||||
import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNode;
|
||||
import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNodeDescriptor;
|
||||
import org.jetbrains.plugins.gradle.util.GradleBundle;
|
||||
import org.jetbrains.plugins.gradle.util.GradleUtil;
|
||||
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
@@ -32,32 +32,27 @@ public class GradleProjectStructureFactory {
|
||||
|
||||
@SuppressWarnings({"MethodMayBeStatic", "unchecked"})
|
||||
@NotNull
|
||||
public <T extends GradleEntity> GradleProjectStructureNodeDescriptor<T> buildDescriptor(@NotNull T entity) {
|
||||
final Ref<GradleProjectStructureNodeDescriptor<GradleEntity>> result = new Ref<GradleProjectStructureNodeDescriptor<GradleEntity>>();
|
||||
public <T extends GradleEntity> GradleProjectStructureNodeDescriptor<GradleEntityId> buildDescriptor(@NotNull T entity) {
|
||||
final Ref<String> text = new Ref<String>();
|
||||
entity.invite(new GradleEntityVisitor() {
|
||||
@Override
|
||||
public void visit(@NotNull GradleProject project) {
|
||||
result.set(new GradleProjectStructureNodeDescriptor<GradleEntity>(
|
||||
project, project.getName(), IconLoader.getIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl())
|
||||
));
|
||||
text.set(project.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(@NotNull GradleModule module) {
|
||||
result.set(new GradleProjectStructureNodeDescriptor<GradleEntity>(module, module.getName(), GradleIcons.MODULE_ICON));
|
||||
text.set(module.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(@NotNull GradleContentRoot contentRoot) {
|
||||
result.set(new GradleProjectStructureNodeDescriptor<GradleEntity>(
|
||||
contentRoot,
|
||||
GradleBundle.message("gradle.import.structure.tree.node.content.root"), GradleIcons.CONTENT_ROOT_ICON
|
||||
));
|
||||
text.set(GradleBundle.message("gradle.import.structure.tree.node.content.root"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(@NotNull GradleLibrary library) {
|
||||
result.set(new GradleProjectStructureNodeDescriptor<GradleEntity>(library, library.getName(), GradleIcons.LIB_ICON));
|
||||
text.set(library.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,7 +65,7 @@ public class GradleProjectStructureFactory {
|
||||
visit(dependency.getTarget());
|
||||
}
|
||||
});
|
||||
return (GradleProjectStructureNodeDescriptor<T>)result.get();
|
||||
return GradleUtil.buildDescriptor(GradleEntityIdMapper.mapEntityToId(entity), text.get());
|
||||
}
|
||||
|
||||
@SuppressWarnings("MethodMayBeStatic")
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.jetbrains.plugins.gradle.model;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.gradle.diff.PlatformFacade;
|
||||
import org.jetbrains.plugins.gradle.ui.GradleIcons;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -12,14 +10,8 @@ import javax.swing.*;
|
||||
* @since 2/7/12 11:18 AM
|
||||
*/
|
||||
public enum GradleEntityType {
|
||||
MODULE(GradleIcons.MODULE_ICON), MODULE_DEPENDENCY(GradleIcons.MODULE_ICON), LIBRARY_DEPENDENCY(GradleIcons.LIB_ICON), SYNTHETIC(null),
|
||||
PROJECT(null) {
|
||||
@Nullable
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return ServiceManager.getService(PlatformFacade.class).getProjectIcon();
|
||||
}
|
||||
};
|
||||
PROJECT(GradleIcons.PROJECT_ICON), MODULE(GradleIcons.MODULE_ICON), MODULE_DEPENDENCY(GradleIcons.MODULE_ICON),
|
||||
LIBRARY_DEPENDENCY(GradleIcons.LIB_ICON), CONTENT_ROOT(GradleIcons.CONTENT_ROOT_ICON), SYNTHETIC(null);
|
||||
|
||||
@Nullable private final Icon myIcon;
|
||||
|
||||
|
||||
+3
-3
@@ -12,12 +12,12 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
* @author Denis Zhdanov
|
||||
* @since 2/14/12 1:32 PM
|
||||
*/
|
||||
public abstract class AbstractGradleEntityId implements GradleEntityId {
|
||||
public abstract class GradleAbstractEntityId implements GradleEntityId {
|
||||
|
||||
@NotNull private final AtomicReference<GradleEntityOwner> myOwner = new AtomicReference<GradleEntityOwner>();
|
||||
@NotNull private final GradleEntityType myType;
|
||||
|
||||
public AbstractGradleEntityId(@NotNull GradleEntityType type, @NotNull GradleEntityOwner owner) {
|
||||
public GradleAbstractEntityId(@NotNull GradleEntityType type, @NotNull GradleEntityOwner owner) {
|
||||
myType = type;
|
||||
myOwner.set(owner);
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public abstract class AbstractGradleEntityId implements GradleEntityId {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
AbstractGradleEntityId that = (AbstractGradleEntityId)o;
|
||||
GradleAbstractEntityId that = (GradleAbstractEntityId)o;
|
||||
return myType.equals(that.myType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.jetbrains.plugins.gradle.model.id;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.gradle.model.GradleEntityOwner;
|
||||
import org.jetbrains.plugins.gradle.model.GradleEntityType;
|
||||
import org.jetbrains.plugins.gradle.model.gradle.GradleContentRoot;
|
||||
import org.jetbrains.plugins.gradle.model.gradle.GradleModule;
|
||||
|
||||
/**
|
||||
* @author Denis Zhdanov
|
||||
* @since 2/16/12 12:22 PM
|
||||
*/
|
||||
public class GradleContentRootId extends GradleAbstractEntityId {
|
||||
|
||||
@NotNull private final String myModuleName;
|
||||
@NotNull private final String myRootPath;
|
||||
|
||||
public GradleContentRootId(@NotNull GradleEntityOwner owner, @NotNull String moduleName, @NotNull String rootPath) {
|
||||
super(GradleEntityType.CONTENT_ROOT, owner);
|
||||
myModuleName = moduleName;
|
||||
myRootPath = rootPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object mapToEntity(@NotNull GradleEntityMappingContext context) {
|
||||
switch (getOwner()) {
|
||||
case GRADLE:
|
||||
final GradleModule module = context.getProjectStructureHelper().findGradleModule(myModuleName);
|
||||
if (module == null) {
|
||||
return null;
|
||||
}
|
||||
for (GradleContentRoot root : module.getContentRoots()) {
|
||||
if (myRootPath.equals(root.getRootPath())) {
|
||||
return root;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
case INTELLIJ: return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class GradleEntityIdMapper {
|
||||
|
||||
@Override
|
||||
public void visit(@NotNull GradleContentRoot contentRoot) {
|
||||
// TODO den implement
|
||||
result.set(new GradleContentRootId(GradleEntityOwner.GRADLE, contentRoot.getOwnerModule().getName(), contentRoot.getRootPath()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import org.jetbrains.plugins.gradle.model.GradleEntityType;
|
||||
* @author Denis Zhdanov
|
||||
* @since 2/14/12 1:59 PM
|
||||
*/
|
||||
public class GradleLibraryDependencyId extends AbstractGradleEntityId {
|
||||
public class GradleLibraryDependencyId extends GradleAbstractEntityId {
|
||||
|
||||
@NotNull private final String myModuleName;
|
||||
@NotNull private final String myLibraryName;
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import org.jetbrains.plugins.gradle.model.GradleEntityType;
|
||||
* @author Denis Zhdanov
|
||||
* @since 2/14/12 2:06 PM
|
||||
*/
|
||||
public class GradleModuleDependencyId extends AbstractGradleEntityId {
|
||||
public class GradleModuleDependencyId extends GradleAbstractEntityId {
|
||||
|
||||
@NotNull private final String myOwnerModuleName;
|
||||
@NotNull private final String myDependencyModuleName;
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.jetbrains.plugins.gradle.model.GradleEntityType;
|
||||
* @author Denis Zhdanov
|
||||
* @since 2/14/12 1:55 PM
|
||||
*/
|
||||
public class GradleModuleId extends AbstractGradleEntityId {
|
||||
public class GradleModuleId extends GradleAbstractEntityId {
|
||||
|
||||
@NotNull private final String myModuleName;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.jetbrains.plugins.gradle.model.GradleEntityType;
|
||||
* @author Denis Zhdanov
|
||||
* @since 2/14/12 1:34 PM
|
||||
*/
|
||||
public class GradleProjectId extends AbstractGradleEntityId {
|
||||
public class GradleProjectId extends GradleAbstractEntityId {
|
||||
|
||||
public GradleProjectId(@NotNull GradleEntityOwner owner) {
|
||||
super(GradleEntityType.PROJECT, owner);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.jetbrains.plugins.gradle.model.id;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.gradle.model.GradleEntityOwner;
|
||||
import org.jetbrains.plugins.gradle.model.GradleEntityType;
|
||||
|
||||
/**
|
||||
* Whole 'entity id' thing is necessary for mapping 'sync project structures' tree nodes to the domain entities. However, there are
|
||||
* special types of nodes that don't map to any entity - {@link GradleEntityType#SYNTHETIC synthetic nodes}.
|
||||
* <p/>
|
||||
* This class is designed to serve as a data object for such a nodes.
|
||||
* <p/>
|
||||
* Thread-safe.
|
||||
*
|
||||
* @author Denis Zhdanov
|
||||
* @since 2/16/12 11:40 AM
|
||||
*/
|
||||
public class GradleSyntheticId extends GradleAbstractEntityId {
|
||||
|
||||
@NotNull private final String myText;
|
||||
|
||||
public GradleSyntheticId(@NotNull String text) {
|
||||
super(GradleEntityType.SYNTHETIC, GradleEntityOwner.GRADLE/* no matter what owner is used */);
|
||||
myText = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return myText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object mapToEntity(@NotNull GradleEntityMappingContext context) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+14
-22
@@ -11,13 +11,12 @@ import com.intellij.util.containers.hash.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.gradle.config.GradleTextAttributes;
|
||||
import org.jetbrains.plugins.gradle.diff.*;
|
||||
import org.jetbrains.plugins.gradle.model.GradleEntityType;
|
||||
import org.jetbrains.plugins.gradle.model.id.*;
|
||||
import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNode;
|
||||
import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNodeDescriptor;
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants;
|
||||
import org.jetbrains.plugins.gradle.util.GradleUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import java.util.ArrayList;
|
||||
@@ -45,8 +44,8 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel {
|
||||
* |_dependency2
|
||||
* </pre>
|
||||
*/
|
||||
private final Map<String, GradleProjectStructureNode<String>> myModuleDependencies
|
||||
= new HashMap<String, GradleProjectStructureNode<String>>();
|
||||
private final Map<String, GradleProjectStructureNode<GradleSyntheticId>> myModuleDependencies
|
||||
= new HashMap<String, GradleProjectStructureNode<GradleSyntheticId>>();
|
||||
private final Map<String, GradleProjectStructureNode<GradleModuleId>> myModules
|
||||
= new HashMap<String, GradleProjectStructureNode<GradleModuleId>>();
|
||||
|
||||
@@ -109,7 +108,7 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel {
|
||||
if (dependencies.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
GradleProjectStructureNode<String> dependenciesNode = getDependenciesNode(moduleId);
|
||||
GradleProjectStructureNode<GradleSyntheticId> dependenciesNode = getDependenciesNode(moduleId);
|
||||
for (GradleProjectStructureNode<?> dependency : dependencies) {
|
||||
dependenciesNode.add(dependency);
|
||||
}
|
||||
@@ -123,28 +122,21 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel {
|
||||
public Project getProject() {
|
||||
return myProject;
|
||||
}
|
||||
|
||||
private static <T> GradleProjectStructureNodeDescriptor<T> buildDescriptor(@NotNull T entity, @NotNull String name, @NotNull Icon icon) {
|
||||
return new GradleProjectStructureNodeDescriptor<T>(entity, name, icon);
|
||||
}
|
||||
|
||||
private <T extends GradleEntityId> GradleProjectStructureNode<T> buildNode(@NotNull T entityId, @NotNull String name) {
|
||||
final Icon icon = entityId.getType().getIcon();
|
||||
assert icon != null;
|
||||
final GradleProjectStructureNode<T> result
|
||||
= new GradleProjectStructureNode<T>(buildDescriptor(entityId, name, icon), entityId.getType());
|
||||
private <T extends GradleEntityId> GradleProjectStructureNode<T> buildNode(@NotNull T id, @NotNull String name) {
|
||||
final GradleProjectStructureNode<T> result = GradleUtil.buildNode(id, name);
|
||||
result.addListener(myNodeListener);
|
||||
return result;
|
||||
}
|
||||
|
||||
private GradleProjectStructureNode<String> getDependenciesNode(@NotNull GradleModuleId id) {
|
||||
final GradleProjectStructureNode<String> cached = myModuleDependencies.get(id.getModuleName());
|
||||
private GradleProjectStructureNode<GradleSyntheticId> getDependenciesNode(@NotNull GradleModuleId id) {
|
||||
final GradleProjectStructureNode<GradleSyntheticId> cached = myModuleDependencies.get(id.getModuleName());
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
GradleProjectStructureNode<GradleModuleId> moduleNode = getModuleNode(id);
|
||||
GradleProjectStructureNode<String> result
|
||||
= new GradleProjectStructureNode<String>(GradleConstants.DEPENDENCIES_NODE_DESCRIPTOR, GradleEntityType.SYNTHETIC);
|
||||
GradleProjectStructureNode<GradleSyntheticId> result
|
||||
= new GradleProjectStructureNode<GradleSyntheticId>(GradleConstants.DEPENDENCIES_NODE_DESCRIPTOR);
|
||||
moduleNode.add(result);
|
||||
myModuleDependencies.put(id.getModuleName(), result);
|
||||
|
||||
@@ -201,7 +193,7 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel {
|
||||
}
|
||||
|
||||
private void processNewMismatchedLibraryPathChange(@NotNull GradleMismatchedLibraryPathChange change) {
|
||||
for (GradleProjectStructureNode<String> holder : myModuleDependencies.values()) {
|
||||
for (GradleProjectStructureNode<GradleSyntheticId> holder : myModuleDependencies.values()) {
|
||||
for (GradleProjectStructureNode<GradleLibraryDependencyId> dependencyNode : holder.getChildren(GradleLibraryDependencyId.class)) {
|
||||
final GradleLibraryDependencyId id = dependencyNode.getDescriptor().getElement();
|
||||
if (change.getLibraryName().equals(id.getLibraryName())) {
|
||||
@@ -220,7 +212,7 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel {
|
||||
attributes = GradleTextAttributes.INTELLIJ_LOCAL_CHANGE;
|
||||
}
|
||||
assert id != null;
|
||||
final GradleProjectStructureNode<String> dependenciesNode = getDependenciesNode(id.getModuleId());
|
||||
final GradleProjectStructureNode<GradleSyntheticId> dependenciesNode = getDependenciesNode(id.getModuleId());
|
||||
for (GradleProjectStructureNode<GradleLibraryDependencyId> node : dependenciesNode.getChildren(GradleLibraryDependencyId.class)) {
|
||||
GradleProjectStructureNodeDescriptor<GradleLibraryDependencyId> d = node.getDescriptor();
|
||||
if (id.equals(d.getElement())) {
|
||||
@@ -261,7 +253,7 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel {
|
||||
}
|
||||
|
||||
private void processObsoleteMismatchedLibraryPathChange(@NotNull GradleMismatchedLibraryPathChange change) {
|
||||
for (GradleProjectStructureNode<String> holder : myModuleDependencies.values()) {
|
||||
for (GradleProjectStructureNode<GradleSyntheticId> holder : myModuleDependencies.values()) {
|
||||
for (GradleProjectStructureNode<GradleLibraryDependencyId> node : holder.getChildren(GradleLibraryDependencyId.class)) {
|
||||
final GradleLibraryDependencyId id = node.getDescriptor().getElement();
|
||||
if (id.getLibraryName().equals(change.getLibraryName())) {
|
||||
@@ -285,7 +277,7 @@ public class GradleProjectStructureTreeModel extends DefaultTreeModel {
|
||||
else {
|
||||
removeNode = !myProjectStructureHelper.isGradleLibraryDependencyExist(id);
|
||||
}
|
||||
final GradleProjectStructureNode<String> holder = myModuleDependencies.get(id.getModuleName());
|
||||
final GradleProjectStructureNode<GradleSyntheticId> holder = myModuleDependencies.get(id.getModuleName());
|
||||
if (holder == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.jetbrains.plugins.gradle.ui;
|
||||
|
||||
import com.intellij.openapi.application.ex.ApplicationInfoEx;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@@ -14,7 +16,19 @@ public class GradleIcons {
|
||||
public static final Icon LIB_ICON = IconLoader.getIcon("/nodes/ppLib.png");
|
||||
public static final Icon MODULE_ICON = IconLoader.getIcon("/nodes/ModuleOpen.png");
|
||||
public static final Icon CONTENT_ROOT_ICON = IconLoader.getIcon("/modules/addContentEntry.png");
|
||||
public static final Icon PROJECT_ICON = getProjectIcon();
|
||||
|
||||
private GradleIcons() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Icon getProjectIcon() {
|
||||
try {
|
||||
return IconLoader.getIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl());
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Control flow may reach this place if we run tests and platform IoC has not been initialised.
|
||||
return IconLoader.getIcon("/nodes/ideProject.png");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.gradle.config.GradleTextAttributes;
|
||||
import org.jetbrains.plugins.gradle.diff.GradleProjectStructureChange;
|
||||
import org.jetbrains.plugins.gradle.model.GradleEntityType;
|
||||
import org.jetbrains.plugins.gradle.model.id.GradleEntityId;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.MutableTreeNode;
|
||||
@@ -18,7 +18,9 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
* @since 8/23/11 3:50 PM
|
||||
* @param <T> type of the target entity {@link GradleProjectStructureNodeDescriptor#getElement() associated} with the current node
|
||||
*/
|
||||
public class GradleProjectStructureNode<T> extends DefaultMutableTreeNode implements Iterable<GradleProjectStructureNode<?>> {
|
||||
public class GradleProjectStructureNode<T extends GradleEntityId> extends DefaultMutableTreeNode
|
||||
implements Iterable<GradleProjectStructureNode<?>>
|
||||
{
|
||||
|
||||
public static final Comparator<GradleProjectStructureNode<?>> NODE_COMPARATOR = new Comparator<GradleProjectStructureNode<?>>() {
|
||||
@Override
|
||||
@@ -42,12 +44,10 @@ public class GradleProjectStructureNode<T> extends DefaultMutableTreeNode implem
|
||||
private final List<Listener> myListeners = new CopyOnWriteArrayList<Listener>();
|
||||
|
||||
private final GradleProjectStructureNodeDescriptor<T> myDescriptor;
|
||||
private final GradleEntityType myType;
|
||||
|
||||
public GradleProjectStructureNode(@NotNull GradleProjectStructureNodeDescriptor<T> descriptor, @NotNull GradleEntityType type) {
|
||||
public GradleProjectStructureNode(@NotNull GradleProjectStructureNodeDescriptor<T> descriptor) {
|
||||
super(descriptor);
|
||||
myDescriptor = descriptor;
|
||||
myType = type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -55,11 +55,6 @@ public class GradleProjectStructureNode<T> extends DefaultMutableTreeNode implem
|
||||
return myDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GradleEntityType getType() {
|
||||
return myType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GradleProjectStructureNode<?> getChildAt(int index) {
|
||||
return (GradleProjectStructureNode)super.getChildAt(index);
|
||||
@@ -175,7 +170,7 @@ public class GradleProjectStructureNode<T> extends DefaultMutableTreeNode implem
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@NotNull
|
||||
public <C> Collection<GradleProjectStructureNode<C>> getChildren(@NotNull Class<C> clazz) {
|
||||
public <C extends GradleEntityId> Collection<GradleProjectStructureNode<C>> getChildren(@NotNull Class<C> clazz) {
|
||||
List<GradleProjectStructureNode<C>> result = null;
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
final GradleProjectStructureNode<?> child = getChildAt(i);
|
||||
|
||||
+12
-16
@@ -20,16 +20,16 @@ import javax.swing.*;
|
||||
* @since 8/12/11 2:47 PM
|
||||
* @param <T> target element type
|
||||
*/
|
||||
public class GradleProjectStructureNodeDescriptor<T> extends PresentableNodeDescriptor<T> {
|
||||
public class GradleProjectStructureNodeDescriptor<T extends GradleEntityId> extends PresentableNodeDescriptor<T> {
|
||||
|
||||
private TextAttributesKey myAttributes = GradleTextAttributes.GRADLE_NO_CHANGE;
|
||||
|
||||
private final T myData;
|
||||
private final T myId;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
public GradleProjectStructureNodeDescriptor(@NotNull T data, @NotNull String text, @Nullable Icon icon) {
|
||||
public GradleProjectStructureNodeDescriptor(@NotNull T id, @NotNull String text, @Nullable Icon icon) {
|
||||
super(null, null);
|
||||
myData = data;
|
||||
myId = id;
|
||||
myOpenIcon = myClosedIcon = icon;
|
||||
myName = text;
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class GradleProjectStructureNodeDescriptor<T> extends PresentableNodeDesc
|
||||
@NotNull
|
||||
@Override
|
||||
public T getElement() {
|
||||
return myData;
|
||||
return myId;
|
||||
}
|
||||
|
||||
public void setName(@NotNull String name) {
|
||||
@@ -59,18 +59,14 @@ public class GradleProjectStructureNodeDescriptor<T> extends PresentableNodeDesc
|
||||
|
||||
public void setAttributes(@NotNull TextAttributesKey attributes) {
|
||||
myAttributes = attributes;
|
||||
// TODO den remove the type check
|
||||
if (myData instanceof GradleEntityId) {
|
||||
final GradleEntityId id = (GradleEntityId)myData;
|
||||
GradleEntityOwner owner = id.getOwner();
|
||||
if (attributes == GradleTextAttributes.GRADLE_LOCAL_CHANGE) {
|
||||
owner = GradleEntityOwner.GRADLE;
|
||||
}
|
||||
else if (attributes == GradleTextAttributes.GRADLE_NO_CHANGE || attributes == GradleTextAttributes.INTELLIJ_LOCAL_CHANGE) {
|
||||
owner = GradleEntityOwner.INTELLIJ;
|
||||
}
|
||||
id.setOwner(owner);
|
||||
GradleEntityOwner owner = myId.getOwner();
|
||||
if (attributes == GradleTextAttributes.GRADLE_LOCAL_CHANGE) {
|
||||
owner = GradleEntityOwner.GRADLE;
|
||||
}
|
||||
else if (attributes == GradleTextAttributes.GRADLE_NO_CHANGE || attributes == GradleTextAttributes.INTELLIJ_LOCAL_CHANGE) {
|
||||
owner = GradleEntityOwner.INTELLIJ;
|
||||
}
|
||||
myId.setOwner(owner);
|
||||
update();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.jetbrains.plugins.gradle.util;
|
||||
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.gradle.model.id.GradleSyntheticId;
|
||||
import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNodeDescriptor;
|
||||
|
||||
/**
|
||||
@@ -20,27 +22,19 @@ public class GradleConstants {
|
||||
@NonNls public static final String ACTION_GROUP_SYNC_TREE = "Gradle.SyncTreeGroup";
|
||||
|
||||
|
||||
public static final GradleProjectStructureNodeDescriptor<String> DEPENDENCIES_NODE_DESCRIPTOR
|
||||
= new GradleProjectStructureNodeDescriptor<String>(
|
||||
GradleBundle.message("gradle.project.structure.tree.node.dependencies"),
|
||||
GradleBundle.message("gradle.project.structure.tree.node.dependencies"),
|
||||
null
|
||||
);
|
||||
public static final GradleProjectStructureNodeDescriptor<GradleSyntheticId> DEPENDENCIES_NODE_DESCRIPTOR
|
||||
= buildSyntheticDescriptor(GradleBundle.message("gradle.project.structure.tree.node.dependencies"));
|
||||
|
||||
public static final GradleProjectStructureNodeDescriptor<String> MODULES_NODE_DESCRIPTOR
|
||||
= new GradleProjectStructureNodeDescriptor<String>(
|
||||
GradleBundle.message("gradle.import.structure.tree.node.modules"),
|
||||
GradleBundle.message("gradle.import.structure.tree.node.modules"),
|
||||
null
|
||||
);
|
||||
public static final GradleProjectStructureNodeDescriptor<GradleSyntheticId> MODULES_NODE_DESCRIPTOR
|
||||
= buildSyntheticDescriptor(GradleBundle.message("gradle.import.structure.tree.node.modules"));
|
||||
|
||||
public static final GradleProjectStructureNodeDescriptor<String> LIBRARIES_NODE_DESCRIPTOR
|
||||
= new GradleProjectStructureNodeDescriptor<String>(
|
||||
GradleBundle.message("gradle.import.structure.tree.node.libraries"),
|
||||
GradleBundle.message("gradle.import.structure.tree.node.libraries"),
|
||||
null
|
||||
);
|
||||
public static final GradleProjectStructureNodeDescriptor<GradleSyntheticId> LIBRARIES_NODE_DESCRIPTOR
|
||||
= buildSyntheticDescriptor(GradleBundle.message("gradle.import.structure.tree.node.libraries"));
|
||||
|
||||
private GradleConstants() {
|
||||
}
|
||||
|
||||
private static GradleProjectStructureNodeDescriptor<GradleSyntheticId> buildSyntheticDescriptor(@NotNull String text) {
|
||||
return new GradleProjectStructureNodeDescriptor<GradleSyntheticId>(new GradleSyntheticId(text), text, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,13 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.gradle.config.GradleSettings;
|
||||
import org.jetbrains.plugins.gradle.model.gradle.GradleProject;
|
||||
import org.jetbrains.plugins.gradle.model.id.GradleEntityId;
|
||||
import org.jetbrains.plugins.gradle.model.intellij.IntellijEntityVisitor;
|
||||
import org.jetbrains.plugins.gradle.remote.GradleApiException;
|
||||
import org.jetbrains.plugins.gradle.task.GradleResolveProjectTask;
|
||||
import org.jetbrains.plugins.gradle.ui.GradleIcons;
|
||||
import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNode;
|
||||
import org.jetbrains.plugins.gradle.ui.GradleProjectStructureNodeDescriptor;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -219,6 +222,20 @@ public class GradleUtil {
|
||||
visitor.visit(((ModuleOrderEntry)entity));
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends GradleEntityId> GradleProjectStructureNodeDescriptor<T> buildDescriptor(@NotNull T id, @NotNull String name) {
|
||||
return new GradleProjectStructureNodeDescriptor<T>(id, name, id.getType().getIcon());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T extends GradleEntityId> GradleProjectStructureNode<T> buildNode(@NotNull T id) {
|
||||
return new GradleProjectStructureNode<T>(buildDescriptor(id, id.toString()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T extends GradleEntityId> GradleProjectStructureNode<T> buildNode(@NotNull T id, @NotNull String name) {
|
||||
return new GradleProjectStructureNode<T>(buildDescriptor(id, name));
|
||||
}
|
||||
|
||||
private interface TaskUnderProgress {
|
||||
void execute(@NotNull ProgressIndicator indicator);
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@ import static junit.framework.Assert.assertEquals
|
||||
import static junit.framework.Assert.fail
|
||||
import org.jetbrains.plugins.gradle.model.GradleEntityOwner
|
||||
import org.jetbrains.plugins.gradle.model.id.GradleEntityId
|
||||
import org.jetbrains.plugins.gradle.model.GradleEntityType
|
||||
|
||||
/**
|
||||
* @author Denis Zhdanov
|
||||
@@ -64,7 +65,7 @@ class ProjectStructureChecker {
|
||||
def expectedMarkup = COLORS[node.children().find {it instanceof CharSequence}]?: GradleTextAttributes.GRADLE_NO_CHANGE
|
||||
assertEquals("node '$descriptor'", expectedMarkup, descriptor.attributes)
|
||||
|
||||
if (descriptor.element instanceof GradleEntityId) {
|
||||
if (descriptor.element.type != GradleEntityType.SYNTHETIC) {
|
||||
def expectedOwner = expectedMarkup == GradleTextAttributes.GRADLE_LOCAL_CHANGE ? GradleEntityOwner.GRADLE : GradleEntityOwner.INTELLIJ
|
||||
assertEquals("node '$descriptor'", expectedOwner, descriptor.element.owner)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user