Show only changed files in notification "Kotlin not configured"
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
## 1.1
|
## 1.1
|
||||||
|
|
||||||
## 1.0.2
|
## 1.0.2
|
||||||
|
- Show only changed files in notification "Kotlin not configured"
|
||||||
|
|
||||||
### JVM
|
### JVM
|
||||||
- Remove the compiler option "Xmultifile-facades-open"
|
- Remove the compiler option "Xmultifile-facades-open"
|
||||||
|
|||||||
+4
-5
@@ -59,20 +59,19 @@ public class KotlinAndroidGradleModuleConfigurator extends KotlinWithGradleConfi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addSourceSetsBlock(@NotNull GroovyFile file) {
|
protected boolean addSourceSetsBlock(@NotNull GroovyFile file) {
|
||||||
GrClosableBlock androidBlock = getAndroidBlock(file);
|
GrClosableBlock androidBlock = getAndroidBlock(file);
|
||||||
addLastExpressionInBlockIfNeeded(SOURCE_SET, getSourceSetsBlock(androidBlock));
|
return addLastExpressionInBlockIfNeeded(SOURCE_SET, getSourceSetsBlock(androidBlock));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean addElementsToFile(@NotNull GroovyFile groovyFile, boolean isTopLevelProjectFile, @NotNull String version) {
|
protected boolean addElementsToFile(@NotNull GroovyFile groovyFile, boolean isTopLevelProjectFile, @NotNull String version) {
|
||||||
if (isTopLevelProjectFile) {
|
if (isTopLevelProjectFile) {
|
||||||
addElementsToProjectFile(groovyFile, version);
|
return addElementsToProjectFile(groovyFile, version);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
addElementsToModuleFile(groovyFile, version);
|
return addElementsToModuleFile(groovyFile, version);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+5
-5
@@ -59,17 +59,17 @@ public class KotlinGradleModuleConfigurator extends KotlinWithGradleConfigurator
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addSourceSetsBlock(@NotNull GroovyFile file) {
|
protected boolean addSourceSetsBlock(@NotNull GroovyFile file) {
|
||||||
GrClosableBlock sourceSetBlock = getSourceSetsBlock(file);
|
GrClosableBlock sourceSetBlock = getSourceSetsBlock(file);
|
||||||
addLastExpressionInBlockIfNeeded(SOURCE_SET, sourceSetBlock);
|
return addLastExpressionInBlockIfNeeded(SOURCE_SET, sourceSetBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean addElementsToFile(@NotNull GroovyFile groovyFile, boolean isTopLevelProjectFile, @NotNull String version) {
|
protected boolean addElementsToFile(@NotNull GroovyFile groovyFile, boolean isTopLevelProjectFile, @NotNull String version) {
|
||||||
if (!isTopLevelProjectFile) {
|
if (!isTopLevelProjectFile) {
|
||||||
addElementsToProjectFile(groovyFile, version);
|
boolean wasModified = addElementsToProjectFile(groovyFile, version);
|
||||||
addElementsToModuleFile(groovyFile, version);
|
wasModified |= addElementsToModuleFile(groovyFile, version);
|
||||||
return true;
|
return wasModified;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-18
@@ -24,6 +24,7 @@ import com.intellij.openapi.module.Module;
|
|||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.roots.DependencyScope;
|
import com.intellij.openapi.roots.DependencyScope;
|
||||||
import com.intellij.openapi.roots.ExternalLibraryDescriptor;
|
import com.intellij.openapi.roots.ExternalLibraryDescriptor;
|
||||||
|
import com.intellij.openapi.roots.FileIndexFacade;
|
||||||
import com.intellij.openapi.ui.Messages;
|
import com.intellij.openapi.ui.Messages;
|
||||||
import com.intellij.openapi.vfs.VfsUtil;
|
import com.intellij.openapi.vfs.VfsUtil;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
@@ -198,33 +199,41 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void addElementsToProjectFile(@NotNull GroovyFile file, @NotNull String version) {
|
protected static boolean addElementsToProjectFile(@NotNull GroovyFile file, @NotNull String version) {
|
||||||
|
boolean wasModified;
|
||||||
|
|
||||||
GrClosableBlock buildScriptBlock = getBuildScriptBlock(file);
|
GrClosableBlock buildScriptBlock = getBuildScriptBlock(file);
|
||||||
addFirstExpressionInBlockIfNeeded(VERSION.replace(VERSION_TEMPLATE, version), buildScriptBlock);
|
wasModified = addFirstExpressionInBlockIfNeeded(VERSION.replace(VERSION_TEMPLATE, version), buildScriptBlock);
|
||||||
|
|
||||||
GrClosableBlock buildScriptRepositoriesBlock = getBuildScriptRepositoriesBlock(file);
|
GrClosableBlock buildScriptRepositoriesBlock = getBuildScriptRepositoriesBlock(file);
|
||||||
if (isSnapshot(version)) {
|
if (isSnapshot(version)) {
|
||||||
addLastExpressionInBlockIfNeeded(SNAPSHOT_REPOSITORY, buildScriptRepositoriesBlock);
|
wasModified |= addLastExpressionInBlockIfNeeded(SNAPSHOT_REPOSITORY, buildScriptRepositoriesBlock);
|
||||||
}
|
}
|
||||||
else if (!isRepositoryConfigured(buildScriptRepositoriesBlock)) {
|
else if (!isRepositoryConfigured(buildScriptRepositoriesBlock)) {
|
||||||
addLastExpressionInBlockIfNeeded(MAVEN_CENTRAL, buildScriptRepositoriesBlock);
|
wasModified |= addLastExpressionInBlockIfNeeded(MAVEN_CENTRAL, buildScriptRepositoriesBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
GrClosableBlock buildScriptDependenciesBlock = getBuildScriptDependenciesBlock(file);
|
GrClosableBlock buildScriptDependenciesBlock = getBuildScriptDependenciesBlock(file);
|
||||||
addLastExpressionInBlockIfNeeded(CLASSPATH, buildScriptDependenciesBlock);
|
wasModified |= addLastExpressionInBlockIfNeeded(CLASSPATH, buildScriptDependenciesBlock);
|
||||||
|
|
||||||
|
return wasModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addElementsToModuleFile(@NotNull GroovyFile file, @NotNull String version) {
|
protected boolean addElementsToModuleFile(@NotNull GroovyFile file, @NotNull String version) {
|
||||||
|
boolean wasModified = false;
|
||||||
|
|
||||||
if (!file.getText().contains(getApplyPluginDirective())) {
|
if (!file.getText().contains(getApplyPluginDirective())) {
|
||||||
GrExpression apply = GroovyPsiElementFactory.getInstance(file.getProject()).createExpressionFromText(getApplyPluginDirective());
|
GrExpression apply = GroovyPsiElementFactory.getInstance(file.getProject()).createExpressionFromText(getApplyPluginDirective());
|
||||||
GrApplicationStatement applyStatement = getApplyStatement(file);
|
GrApplicationStatement applyStatement = getApplyStatement(file);
|
||||||
if (applyStatement != null) {
|
if (applyStatement != null) {
|
||||||
file.addAfter(apply, applyStatement);
|
file.addAfter(apply, applyStatement);
|
||||||
|
wasModified = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
GrClosableBlock buildScript = getBlockByName(file, "buildscript");
|
GrClosableBlock buildScript = getBlockByName(file, "buildscript");
|
||||||
if (buildScript != null) {
|
if (buildScript != null) {
|
||||||
file.addAfter(apply, buildScript.getParent());
|
file.addAfter(apply, buildScript.getParent());
|
||||||
|
wasModified = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
GrStatement[] statements = file.getStatements();
|
GrStatement[] statements = file.getStatements();
|
||||||
@@ -234,22 +243,26 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
else {
|
else {
|
||||||
file.addAfter(apply, file.getFirstChild());
|
file.addAfter(apply, file.getFirstChild());
|
||||||
}
|
}
|
||||||
|
wasModified = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GrClosableBlock repositoriesBlock = getRepositoriesBlock(file);
|
GrClosableBlock repositoriesBlock = getRepositoriesBlock(file);
|
||||||
if (isSnapshot(version)) {
|
if (isSnapshot(version)) {
|
||||||
addLastExpressionInBlockIfNeeded(SNAPSHOT_REPOSITORY, repositoriesBlock);
|
wasModified |= addLastExpressionInBlockIfNeeded(SNAPSHOT_REPOSITORY, repositoriesBlock);
|
||||||
}
|
}
|
||||||
else if (!isRepositoryConfigured(repositoriesBlock)) {
|
else if (!isRepositoryConfigured(repositoriesBlock)) {
|
||||||
addLastExpressionInBlockIfNeeded(MAVEN_CENTRAL, repositoriesBlock);
|
wasModified |= addLastExpressionInBlockIfNeeded(MAVEN_CENTRAL, repositoriesBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
GrClosableBlock dependenciesBlock = getDependenciesBlock(file);
|
GrClosableBlock dependenciesBlock = getDependenciesBlock(file);
|
||||||
addLastExpressionInBlockIfNeeded(LIBRARY, dependenciesBlock);
|
Module module = FileIndexFacade.getInstance(file.getProject()).getModuleForFile(file.getVirtualFile());
|
||||||
|
wasModified |= addExpressionInBlockIfNeeded(LIBRARY, dependenciesBlock, false, !ConfigureKotlinInProjectUtilsKt.hasKotlinRuntimeInScope(module));
|
||||||
|
|
||||||
addSourceSetsBlock(file);
|
wasModified |= addSourceSetsBlock(file);
|
||||||
|
|
||||||
|
return wasModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isRepositoryConfigured(GrClosableBlock repositoriesBlock) {
|
private static boolean isRepositoryConfigured(GrClosableBlock repositoriesBlock) {
|
||||||
@@ -258,7 +271,7 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
|
|
||||||
protected abstract String getApplyPluginDirective();
|
protected abstract String getApplyPluginDirective();
|
||||||
|
|
||||||
protected abstract void addSourceSetsBlock(@NotNull GroovyFile file);
|
protected abstract boolean addSourceSetsBlock(@NotNull GroovyFile file);
|
||||||
|
|
||||||
protected abstract boolean addElementsToFile(
|
protected abstract boolean addElementsToFile(
|
||||||
@NotNull GroovyFile groovyFile,
|
@NotNull GroovyFile groovyFile,
|
||||||
@@ -312,7 +325,7 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
}.execute();
|
}.execute();
|
||||||
|
|
||||||
VirtualFile virtualFile = groovyFile.getVirtualFile();
|
VirtualFile virtualFile = groovyFile.getVirtualFile();
|
||||||
if (virtualFile != null) {
|
if (virtualFile != null && isModified[0]) {
|
||||||
collector.addMessage(virtualFile.getPath() + " was modified");
|
collector.addMessage(virtualFile.getPath() + " was modified");
|
||||||
}
|
}
|
||||||
return isModified[0];
|
return isModified[0];
|
||||||
@@ -369,12 +382,12 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void addLastExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block) {
|
protected static boolean addLastExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block) {
|
||||||
addExpressionInBlockIfNeeded(text, block, false);
|
return addExpressionInBlockIfNeeded(text, block, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addFirstExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block) {
|
private static boolean addFirstExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block) {
|
||||||
addExpressionInBlockIfNeeded(text, block, true);
|
return addExpressionInBlockIfNeeded(text, block, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -392,8 +405,8 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block, boolean isFirst) {
|
private static boolean addExpressionInBlockIfNeeded(@NotNull String text, @NotNull GrClosableBlock block, boolean isFirst, boolean forceInsert) {
|
||||||
if (block.getText().contains(text)) return;
|
if (!forceInsert && block.getText().contains(text)) return false;
|
||||||
GrExpression newStatement = GroovyPsiElementFactory.getInstance(block.getProject()).createExpressionFromText(text);
|
GrExpression newStatement = GroovyPsiElementFactory.getInstance(block.getProject()).createExpressionFromText(text);
|
||||||
CodeStyleManager.getInstance(block.getProject()).reformat(newStatement);
|
CodeStyleManager.getInstance(block.getProject()).reformat(newStatement);
|
||||||
GrStatement[] statements = block.getStatements();
|
GrStatement[] statements = block.getStatements();
|
||||||
@@ -409,6 +422,7 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
block.addAfter(newStatement, firstChild);
|
block.addAfter(newStatement, firstChild);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
Reference in New Issue
Block a user