Configure Kotlin: do not show notification when apply directive contains double quotes
This commit is contained in:
@@ -81,7 +81,13 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
|
|
||||||
private boolean isFileConfigured(GroovyFile projectGradleFile) {
|
private boolean isFileConfigured(GroovyFile projectGradleFile) {
|
||||||
String fileText = projectGradleFile.getText();
|
String fileText = projectGradleFile.getText();
|
||||||
return fileText.contains(getApplyPluginDirective()) && fileText.contains(LIBRARY);
|
return containsDirective(fileText, getApplyPluginDirective()) && fileText.contains(LIBRARY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean containsDirective(@NotNull String fileText, @NotNull String directive) {
|
||||||
|
return fileText.contains(directive)
|
||||||
|
|| fileText.contains(directive.replace("\"", "'"))
|
||||||
|
|| fileText.contains(directive.replace("'", "\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -160,7 +166,8 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
|
|
||||||
String dependencyString = String.format(
|
String dependencyString = String.format(
|
||||||
"%s \"%s:%s:%s\"",
|
"%s \"%s:%s:%s\"",
|
||||||
groovyScope, libraryDescriptor.getLibraryGroupId(), libraryDescriptor.getLibraryArtifactId(), libraryDescriptor.getMaxVersion());
|
groovyScope, libraryDescriptor.getLibraryGroupId(), libraryDescriptor.getLibraryArtifactId(),
|
||||||
|
libraryDescriptor.getMaxVersion());
|
||||||
|
|
||||||
GrClosableBlock dependenciesBlock = getDependenciesBlock(gradleFile);
|
GrClosableBlock dependenciesBlock = getDependenciesBlock(gradleFile);
|
||||||
addLastExpressionInBlockIfNeeded(dependencyString, dependenciesBlock);
|
addLastExpressionInBlockIfNeeded(dependencyString, dependenciesBlock);
|
||||||
@@ -228,7 +235,7 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
|||||||
protected boolean addElementsToModuleFile(@NotNull GroovyFile file, @NotNull String version) {
|
protected boolean addElementsToModuleFile(@NotNull GroovyFile file, @NotNull String version) {
|
||||||
boolean wasModified = false;
|
boolean wasModified = false;
|
||||||
|
|
||||||
if (!file.getText().contains(getApplyPluginDirective())) {
|
if (!containsDirective(file.getText(), 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) {
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
apply plugin: "java"
|
||||||
|
apply plugin: "kotlin"
|
||||||
|
|
||||||
|
sourceCompatibility = 1.5
|
||||||
|
version = '1.0'
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
}
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
ext.kotlin_version = '$VERSION$'
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sourceSets {
|
||||||
|
main.java.srcDirs += 'src/main/kotlin'
|
||||||
|
}
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
apply plugin: "java"
|
||||||
|
apply plugin: "kotlin"
|
||||||
|
|
||||||
|
sourceCompatibility = 1.5
|
||||||
|
version = '1.0'
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||||
|
}
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sourceSets {
|
||||||
|
main.java.srcDirs += 'src/main/kotlin'
|
||||||
|
}
|
||||||
+6
@@ -48,6 +48,12 @@ public class ConfigureProjectByChangingFileTestGenerated extends AbstractConfigu
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/missedLibrary_before.gradle");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/missedLibrary_before.gradle");
|
||||||
doTestGradle(fileName);
|
doTestGradle(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("plugin_present_before.gradle")
|
||||||
|
public void testPlugin_present() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/configuration/gradle/plugin_present_before.gradle");
|
||||||
|
doTestGradle(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/configuration/maven")
|
@TestMetadata("idea/testData/configuration/maven")
|
||||||
|
|||||||
Reference in New Issue
Block a user