mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
IDEA-76142: Gradle support - cannot update IDEA projects once one of build.gradle files changes
Added support for unnamed library dependencies
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.JDOMExternalizable;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
@@ -29,7 +30,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
public interface Library extends JDOMExternalizable, Disposable {
|
||||
Library[] EMPTY_ARRAY = new Library[0];
|
||||
|
||||
String getName();
|
||||
@Nullable String getName();
|
||||
|
||||
@NotNull String[] getUrls(@NotNull OrderRootType rootType);
|
||||
|
||||
|
||||
@@ -113,10 +113,7 @@ public class GradleDiffUtil {
|
||||
|
||||
@Override
|
||||
public void visit(@NotNull LibraryOrderEntry libraryDependency) {
|
||||
final String libraryName = libraryDependency.getLibraryName();
|
||||
if (libraryName != null) {
|
||||
context.register(new GradleLibraryDependencyPresenceChange(null, libraryDependency));
|
||||
}
|
||||
context.register(new GradleLibraryDependencyPresenceChange(null, libraryDependency));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -9,6 +9,7 @@ import org.jetbrains.plugins.gradle.diff.GradleChangesCalculationContext;
|
||||
import org.jetbrains.plugins.gradle.diff.GradleStructureChangesCalculator;
|
||||
import org.jetbrains.plugins.gradle.model.gradle.GradleLibrary;
|
||||
import org.jetbrains.plugins.gradle.model.gradle.LibraryPathType;
|
||||
import org.jetbrains.plugins.gradle.util.GradleUtil;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -47,7 +48,7 @@ public class GradleLibraryStructureChangesCalculator implements GradleStructureC
|
||||
@NotNull
|
||||
@Override
|
||||
public Object getIntellijKey(@NotNull Library entity) {
|
||||
return entity.getName();
|
||||
return GradleUtil.getLibraryName(entity);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+3
-6
@@ -6,6 +6,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.gradle.diff.GradleAbstractConflictingPropertyChange;
|
||||
import org.jetbrains.plugins.gradle.diff.GradleProjectStructureChangeVisitor;
|
||||
import org.jetbrains.plugins.gradle.util.GradleBundle;
|
||||
import org.jetbrains.plugins.gradle.util.GradleUtil;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -22,12 +23,8 @@ public class GradleMismatchedLibraryPathChange extends GradleAbstractConflicting
|
||||
@Nullable Set<String> intellijValue)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
super(GradleBundle.message("gradle.sync.change.library.path", entity.getName()), gradleValue, intellijValue);
|
||||
myLibraryName = entity.getName();
|
||||
if (myLibraryName == null) {
|
||||
throw new IllegalArgumentException(String.format("Can't create %s instance. Reason: given library has no name (%s)",
|
||||
getClass().getName(), entity));
|
||||
}
|
||||
super(GradleBundle.message("gradle.sync.change.library.path", GradleUtil.getLibraryName(entity)), gradleValue, intellijValue);
|
||||
myLibraryName = GradleUtil.getLibraryName(entity);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+13
-10
@@ -4,8 +4,8 @@ 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.libraries.Library;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.gradle.model.GradleEntityOwner;
|
||||
@@ -92,20 +92,23 @@ public class GradleEntityIdMapper {
|
||||
|
||||
@Override
|
||||
public void visit(@NotNull ModuleAwareContentRoot contentRoot) {
|
||||
final VirtualFile file = contentRoot.getFile();
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
result.set(new GradleContentRootId(GradleEntityOwner.INTELLIJ, contentRoot.getModule().getName(), file.getPath()));
|
||||
final String path = contentRoot.getFile().getPath();
|
||||
result.set(new GradleContentRootId(GradleEntityOwner.INTELLIJ, contentRoot.getModule().getName(), path));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(@NotNull LibraryOrderEntry libraryDependency) {
|
||||
final String libraryName = libraryDependency.getLibraryName();
|
||||
if (libraryName != null) {
|
||||
result
|
||||
.set(new GradleLibraryDependencyId(GradleEntityOwner.INTELLIJ, libraryDependency.getOwnerModule().getName(), libraryName));
|
||||
String libraryName = libraryDependency.getLibraryName();
|
||||
if (libraryName == null) {
|
||||
final Library library = libraryDependency.getLibrary();
|
||||
if (library != null) {
|
||||
libraryName = GradleUtil.getLibraryName(library);
|
||||
}
|
||||
}
|
||||
if (libraryName == null) {
|
||||
return;
|
||||
}
|
||||
result.set(new GradleLibraryDependencyId(GradleEntityOwner.INTELLIJ, libraryDependency.getOwnerModule().getName(), libraryName));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-4
@@ -10,7 +10,6 @@ import com.intellij.openapi.ui.popup.Balloon;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.ui.TreeSpeedSearch;
|
||||
import com.intellij.ui.TreeUIHelper;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.ui.treeStructure.Tree;
|
||||
import com.intellij.util.Alarm;
|
||||
@@ -50,8 +49,7 @@ public class GradleProjectStructureChangesPanel extends GradleToolWindowPanel {
|
||||
|
||||
private static final int TOOLTIP_DELAY_MILLIS = 500;
|
||||
private static final int COLLAPSE_STATE_PROCESSING_DELAY_MILLIS = 200;
|
||||
private static final String PATH_SEPARATOR = "/";
|
||||
|
||||
|
||||
private static final Comparator<TreePath> PATH_COMPARATOR = new Comparator<TreePath>() {
|
||||
@Override
|
||||
public int compare(TreePath o1, TreePath o2) {
|
||||
@@ -385,7 +383,7 @@ public class GradleProjectStructureChangesPanel extends GradleToolWindowPanel {
|
||||
private static String getPath(@NotNull TreePath path) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (TreePath current = path; current != null; current = current.getParentPath()) {
|
||||
buffer.append(current.getLastPathComponent().toString()).append(PATH_SEPARATOR);
|
||||
buffer.append(current.getLastPathComponent().toString()).append(GradleUtil.PATH_SEPARATOR);
|
||||
}
|
||||
buffer.setLength(buffer.length() - 1);
|
||||
return buffer.toString();
|
||||
|
||||
+3
-2
@@ -19,6 +19,7 @@ import org.jetbrains.plugins.gradle.model.id.GradleContentRootId;
|
||||
import org.jetbrains.plugins.gradle.model.id.GradleLibraryDependencyId;
|
||||
import org.jetbrains.plugins.gradle.model.id.GradleModuleDependencyId;
|
||||
import org.jetbrains.plugins.gradle.model.intellij.ModuleAwareContentRoot;
|
||||
import org.jetbrains.plugins.gradle.util.GradleUtil;
|
||||
|
||||
/**
|
||||
* Thread-safe.
|
||||
@@ -127,7 +128,7 @@ public class GradleProjectStructureHelper extends AbstractProjectComponent {
|
||||
}
|
||||
for (ModuleAwareContentRoot contentRoot : myFacade.getContentRoots(module)) {
|
||||
final VirtualFile file = contentRoot.getFile();
|
||||
if (file != null && id.getRootPath().equals(file.getPath())) {
|
||||
if (id.getRootPath().equals(file.getPath())) {
|
||||
return contentRoot;
|
||||
}
|
||||
}
|
||||
@@ -144,7 +145,7 @@ public class GradleProjectStructureHelper extends AbstractProjectComponent {
|
||||
final LibraryTable libraryTable = myFacade.getProjectLibraryTable(myProject);
|
||||
for (Library intellijLibrary : libraryTable.getLibraries()) {
|
||||
// TODO den consider 'merged libraries' at the registered project structure changes here.
|
||||
if (libraryName.equals(intellijLibrary.getName())) {
|
||||
if (libraryName.equals(GradleUtil.getLibraryName(intellijLibrary))) {
|
||||
return intellijLibrary;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ public class GradleLibraryConflictControlFactory {
|
||||
@NotNull
|
||||
public JComponent getControl(@NotNull Library library, @NotNull GradleMismatchedLibraryPathChange change) {
|
||||
GradleProjectStructureNode<GradleSyntheticId> root = new GradleProjectStructureNode<GradleSyntheticId>(
|
||||
GradleUtil.buildSyntheticDescriptor(library.getName(), GradleIcons.LIB_ICON)
|
||||
GradleUtil.buildSyntheticDescriptor(GradleUtil.getLibraryName(library), GradleIcons.LIB_ICON)
|
||||
);
|
||||
final Set<String> gradleLocalBinaryPaths = change.getGradleValue();
|
||||
if (gradleLocalBinaryPaths != null) {
|
||||
|
||||
@@ -12,6 +12,8 @@ import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.LibraryOrderEntry;
|
||||
import com.intellij.openapi.roots.ModuleOrderEntry;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.ui.MessageType;
|
||||
import com.intellij.openapi.ui.popup.Balloon;
|
||||
import com.intellij.openapi.ui.popup.BalloonBuilder;
|
||||
@@ -54,6 +56,8 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class GradleUtil {
|
||||
|
||||
public static final String PATH_SEPARATOR = "/";
|
||||
|
||||
private GradleUtil() {
|
||||
}
|
||||
|
||||
@@ -275,6 +279,37 @@ public class GradleUtil {
|
||||
}
|
||||
return new Point(bounds.x + xAdjustment, bounds.y + bounds.height);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getLibraryName(@NotNull Library library) {
|
||||
final String result = library.getName();
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
String[] endingsToStrip = { "/", "!", ".jar" };
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (OrderRootType type : OrderRootType.getAllTypes()) {
|
||||
for (String url : library.getUrls(type)) {
|
||||
buffer.setLength(0);
|
||||
buffer.append(url);
|
||||
for (String ending : endingsToStrip) {
|
||||
if (buffer.lastIndexOf(ending) == buffer.length() - ending.length()) {
|
||||
buffer.setLength(buffer.length() - ending.length());
|
||||
}
|
||||
}
|
||||
final int i = buffer.lastIndexOf(PATH_SEPARATOR);
|
||||
if (i < 0 || i >= buffer.length() - 1) {
|
||||
continue;
|
||||
}
|
||||
String candidate = buffer.substring(i + 1);
|
||||
if (!StringUtil.isEmpty(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert false;
|
||||
return "unknown-lib";
|
||||
}
|
||||
|
||||
private interface TaskUnderProgress {
|
||||
void execute(@NotNull ProgressIndicator indicator);
|
||||
|
||||
Reference in New Issue
Block a user