add KotlinJavascriptMavenConfigurator
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
<idea-plugin>
|
<idea-plugin>
|
||||||
<extensions defaultExtensionNs="org.jetbrains.kotlin">
|
<extensions defaultExtensionNs="org.jetbrains.kotlin">
|
||||||
<projectConfigurator implementation="org.jetbrains.jet.plugin.configuration.KotlinMavenConfigurator"/>
|
<projectConfigurator implementation="org.jetbrains.jet.plugin.configuration.KotlinJavaMavenConfigurator"/>
|
||||||
|
<projectConfigurator implementation="org.jetbrains.jet.plugin.configuration.KotlinJavascriptMavenConfigurator"/>
|
||||||
</extensions>
|
</extensions>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.plugin.configuration;
|
||||||
|
|
||||||
|
import com.intellij.openapi.module.Module;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.idea.maven.dom.model.*;
|
||||||
|
import org.jetbrains.jet.plugin.project.ProjectStructureUtil;
|
||||||
|
|
||||||
|
public class KotlinJavaMavenConfigurator extends KotlinMavenConfigurator {
|
||||||
|
public static final String NAME = "maven";
|
||||||
|
private static final String STD_LIB_ID = "kotlin-stdlib";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getLibraryId() {
|
||||||
|
return STD_LIB_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isKotlinModule(@NotNull Module module) {
|
||||||
|
return ProjectStructureUtil.isJavaKotlinModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void createExecutions(VirtualFile virtualFile, MavenDomPlugin kotlinPlugin, Module module) {
|
||||||
|
createExecution(virtualFile, kotlinPlugin, module, false);
|
||||||
|
createExecution(virtualFile, kotlinPlugin, module, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected String getGoal(boolean isTest) {
|
||||||
|
return isTest ? "test-compile" : "compile";
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getPresentableText() {
|
||||||
|
return "Maven";
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return NAME;
|
||||||
|
}
|
||||||
|
}
|
||||||
+61
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.plugin.configuration;
|
||||||
|
|
||||||
|
import com.intellij.openapi.module.Module;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.idea.maven.dom.model.MavenDomPlugin;
|
||||||
|
import org.jetbrains.jet.plugin.project.ProjectStructureUtil;
|
||||||
|
|
||||||
|
public class KotlinJavascriptMavenConfigurator extends KotlinMavenConfigurator {
|
||||||
|
public static final String NAME = "js maven";
|
||||||
|
private static final String STD_LIB_ID = "kotlin-js-library";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getLibraryId() {
|
||||||
|
return STD_LIB_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isKotlinModule(@NotNull Module module) {
|
||||||
|
return ProjectStructureUtil.isJsKotlinModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void createExecutions(VirtualFile virtualFile, MavenDomPlugin kotlinPlugin, Module module) {
|
||||||
|
createExecution(virtualFile, kotlinPlugin, module, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected String getGoal(boolean isTest) {
|
||||||
|
return "js";
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getPresentableText() {
|
||||||
|
return "JavaScript Maven";
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return NAME;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,28 +45,30 @@ import org.jetbrains.idea.maven.project.MavenProjectsManager;
|
|||||||
import org.jetbrains.jet.cli.common.KotlinVersion;
|
import org.jetbrains.jet.cli.common.KotlinVersion;
|
||||||
import org.jetbrains.jet.plugin.JetPluginUtil;
|
import org.jetbrains.jet.plugin.JetPluginUtil;
|
||||||
import org.jetbrains.jet.plugin.framework.ui.ConfigureDialogWithModulesAndVersion;
|
import org.jetbrains.jet.plugin.framework.ui.ConfigureDialogWithModulesAndVersion;
|
||||||
import org.jetbrains.jet.plugin.project.ProjectStructureUtil;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class KotlinMavenConfigurator implements KotlinProjectConfigurator {
|
public abstract class KotlinMavenConfigurator implements KotlinProjectConfigurator {
|
||||||
private static final String[] KOTLIN_VERSIONS = {KotlinVersion.VERSION};
|
private static final String[] KOTLIN_VERSIONS = {KotlinVersion.VERSION};
|
||||||
|
|
||||||
public static final String NAME = "maven";
|
public static final String NAME = "maven";
|
||||||
|
|
||||||
private static final String STD_LIB_ID = "kotlin-stdlib";
|
|
||||||
private static final String MAVEN_PLUGIN_ID = "kotlin-maven-plugin";
|
private static final String MAVEN_PLUGIN_ID = "kotlin-maven-plugin";
|
||||||
private static final String KOTLIN_VERSION_PROPERTY = "kotlin.version";
|
private static final String KOTLIN_VERSION_PROPERTY = "kotlin.version";
|
||||||
private static final String SNAPSHOT_REPOSITORY_ID = "sonatype.oss.snapshots";
|
private static final String SNAPSHOT_REPOSITORY_ID = "sonatype.oss.snapshots";
|
||||||
|
|
||||||
|
protected abstract String getLibraryId();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isApplicable(@NotNull Module module) {
|
public boolean isApplicable(@NotNull Module module) {
|
||||||
return JetPluginUtil.isMavenModule(module);
|
return JetPluginUtil.isMavenModule(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract boolean isKotlinModule(@NotNull Module module);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConfigured(@NotNull Module module) {
|
public boolean isConfigured(@NotNull Module module) {
|
||||||
if (ProjectStructureUtil.isJavaKotlinModule(module)) {
|
if (isKotlinModule(module)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +76,7 @@ public class KotlinMavenConfigurator implements KotlinProjectConfigurator {
|
|||||||
if (pomFile == null) return false;
|
if (pomFile == null) return false;
|
||||||
String text = pomFile.getText();
|
String text = pomFile.getText();
|
||||||
return text.contains("<artifactId>" + MAVEN_PLUGIN_ID + "</artifactId>") &&
|
return text.contains("<artifactId>" + MAVEN_PLUGIN_ID + "</artifactId>") &&
|
||||||
text.contains("<artifactId>" + STD_LIB_ID + "</artifactId>");
|
text.contains("<artifactId>" + getLibraryId() + "</artifactId>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -99,7 +101,7 @@ public class KotlinMavenConfigurator implements KotlinProjectConfigurator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void changePomFile(@NotNull final Module module, final @NotNull PsiFile file, @NotNull final String version) {
|
protected void changePomFile(@NotNull final Module module, final @NotNull PsiFile file, @NotNull final String version) {
|
||||||
final VirtualFile virtualFile = file.getVirtualFile();
|
final VirtualFile virtualFile = file.getVirtualFile();
|
||||||
assert virtualFile != null : "Virtual file should exists for psi file " + file.getName();
|
assert virtualFile != null : "Virtual file should exists for psi file " + file.getName();
|
||||||
final MavenDomProjectModel domModel = MavenDomUtil.getMavenDomProjectModel(module.getProject(), virtualFile);
|
final MavenDomProjectModel domModel = MavenDomUtil.getMavenDomProjectModel(module.getProject(), virtualFile);
|
||||||
@@ -147,20 +149,20 @@ public class KotlinMavenConfigurator implements KotlinProjectConfigurator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addLibraryDependencyIfNeeded(MavenDomProjectModel domModel) {
|
private void addLibraryDependencyIfNeeded(MavenDomProjectModel domModel) {
|
||||||
for (MavenDomDependency dependency : domModel.getDependencies().getDependencies()) {
|
for (MavenDomDependency dependency : domModel.getDependencies().getDependencies()) {
|
||||||
if (STD_LIB_ID.equals(dependency.getArtifactId().getStringValue())) {
|
if (getLibraryId().equals(dependency.getArtifactId().getStringValue())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MavenDomDependency dependency = MavenDomUtil.createDomDependency(domModel, null);
|
MavenDomDependency dependency = MavenDomUtil.createDomDependency(domModel, null);
|
||||||
dependency.getGroupId().setStringValue("org.jetbrains.kotlin");
|
dependency.getGroupId().setStringValue("org.jetbrains.kotlin");
|
||||||
dependency.getArtifactId().setStringValue(STD_LIB_ID);
|
dependency.getArtifactId().setStringValue(getLibraryId());
|
||||||
dependency.getVersion().setStringValue("${" + KOTLIN_VERSION_PROPERTY + "}");
|
dependency.getVersion().setStringValue("${" + KOTLIN_VERSION_PROPERTY + "}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addPluginIfNeeded(MavenDomProjectModel domModel, Module module, VirtualFile virtualFile) {
|
private void addPluginIfNeeded(MavenDomProjectModel domModel, Module module, VirtualFile virtualFile) {
|
||||||
MavenDomPlugins plugins = domModel.getBuild().getPlugins();
|
MavenDomPlugins plugins = domModel.getBuild().getPlugins();
|
||||||
for (MavenDomPlugin plugin : plugins.getPlugins()) {
|
for (MavenDomPlugin plugin : plugins.getPlugins()) {
|
||||||
if (MAVEN_PLUGIN_ID.equals(plugin.getArtifactId().getStringValue())) {
|
if (MAVEN_PLUGIN_ID.equals(plugin.getArtifactId().getStringValue())) {
|
||||||
@@ -171,10 +173,11 @@ public class KotlinMavenConfigurator implements KotlinProjectConfigurator {
|
|||||||
kotlinPlugin.getArtifactId().setStringValue("kotlin-maven-plugin");
|
kotlinPlugin.getArtifactId().setStringValue("kotlin-maven-plugin");
|
||||||
kotlinPlugin.getGroupId().setStringValue("org.jetbrains.kotlin");
|
kotlinPlugin.getGroupId().setStringValue("org.jetbrains.kotlin");
|
||||||
kotlinPlugin.getVersion().setStringValue("${" + KOTLIN_VERSION_PROPERTY + "}");
|
kotlinPlugin.getVersion().setStringValue("${" + KOTLIN_VERSION_PROPERTY + "}");
|
||||||
createExecution(virtualFile, kotlinPlugin, module, false);
|
createExecutions(virtualFile, kotlinPlugin, module);
|
||||||
createExecution(virtualFile, kotlinPlugin, module, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void createExecutions(VirtualFile virtualFile, MavenDomPlugin kotlinPlugin, Module module);
|
||||||
|
|
||||||
private static boolean isRepositoryConfigured(List<MavenDomRepository> pluginRepositories) {
|
private static boolean isRepositoryConfigured(List<MavenDomRepository> pluginRepositories) {
|
||||||
for (MavenDomRepository repository : pluginRepositories) {
|
for (MavenDomRepository repository : pluginRepositories) {
|
||||||
if (SNAPSHOT_REPOSITORY_ID.equals(repository.getId().getStringValue())) {
|
if (SNAPSHOT_REPOSITORY_ID.equals(repository.getId().getStringValue())) {
|
||||||
@@ -192,22 +195,33 @@ public class KotlinMavenConfigurator implements KotlinProjectConfigurator {
|
|||||||
createTagIfNeeded(repository.getSnapshots(), "enabled", "true");
|
createTagIfNeeded(repository.getSnapshots(), "enabled", "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createExecution(
|
@NotNull
|
||||||
|
protected static String getExecutionId(boolean isTest) {
|
||||||
|
return isTest ? "test-compile" : "compile";
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
protected static String getPhase(@NotNull Module module, boolean isTest) {
|
||||||
|
if (hasJavaFiles(module)) {
|
||||||
|
return isTest ? "process-test-sources" : "process-sources";
|
||||||
|
}
|
||||||
|
return isTest ? "test-compile" : "compile";
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
protected abstract String getGoal(boolean isTest);
|
||||||
|
|
||||||
|
protected void createExecution(
|
||||||
@NotNull VirtualFile virtualFile,
|
@NotNull VirtualFile virtualFile,
|
||||||
@NotNull MavenDomPlugin kotlinPlugin,
|
@NotNull MavenDomPlugin kotlinPlugin,
|
||||||
@NotNull Module module,
|
@NotNull Module module,
|
||||||
boolean isTest
|
boolean isTest
|
||||||
) {
|
) {
|
||||||
MavenDomPluginExecution execution = kotlinPlugin.getExecutions().addExecution();
|
MavenDomPluginExecution execution = kotlinPlugin.getExecutions().addExecution();
|
||||||
String tagValue = isTest ? "test-compile" : "compile";
|
String tagValue = getExecutionId(isTest);
|
||||||
execution.getId().setStringValue(tagValue);
|
execution.getId().setStringValue(tagValue);
|
||||||
if (hasJavaFiles(module)) {
|
execution.getPhase().setStringValue(getPhase(module, isTest));
|
||||||
execution.getPhase().setStringValue(isTest ? "process-test-sources" : "process-sources");
|
createTagIfNeeded(execution.getGoals(), "goal", getGoal(isTest));
|
||||||
}
|
|
||||||
else {
|
|
||||||
execution.getPhase().setStringValue(tagValue);
|
|
||||||
}
|
|
||||||
createTagIfNeeded(execution.getGoals(), "goal", tagValue);
|
|
||||||
|
|
||||||
XmlTag sourcesTag = createTagIfNeeded(execution.getConfiguration(), "sourceDirs", "");
|
XmlTag sourcesTag = createTagIfNeeded(execution.getConfiguration(), "sourceDirs", "");
|
||||||
|
|
||||||
@@ -231,7 +245,7 @@ public class KotlinMavenConfigurator implements KotlinProjectConfigurator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static PsiFile findModulePomFile(@NotNull Module module) {
|
protected static PsiFile findModulePomFile(@NotNull Module module) {
|
||||||
List<VirtualFile> files = MavenProjectsManager.getInstance(module.getProject()).getProjectsFiles();
|
List<VirtualFile> files = MavenProjectsManager.getInstance(module.getProject()).getProjectsFiles();
|
||||||
for (VirtualFile file : files) {
|
for (VirtualFile file : files) {
|
||||||
Module fileModule = ModuleUtilCore.findModuleForFile(file, module.getProject());
|
Module fileModule = ModuleUtilCore.findModuleForFile(file, module.getProject());
|
||||||
@@ -261,17 +275,13 @@ public class KotlinMavenConfigurator implements KotlinProjectConfigurator {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getPresentableText() {
|
public abstract String getPresentableText();
|
||||||
return "Maven";
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public abstract String getName();
|
||||||
return NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean canConfigureFile(@NotNull PsiFile file) {
|
protected static boolean canConfigureFile(@NotNull PsiFile file) {
|
||||||
return WritingAccessProvider.isPotentiallyWritable(file.getVirtualFile(), null);
|
return WritingAccessProvider.isPotentiallyWritable(file.getVirtualFile(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -30,7 +30,7 @@ public abstract class AbstractConfigureProjectByChangingFileTest extends LightCo
|
|||||||
|
|
||||||
public void doTestWithMaven(@NotNull String path) throws Exception {
|
public void doTestWithMaven(@NotNull String path) throws Exception {
|
||||||
String pathWithFile = path + "/" + MavenConstants.POM_XML;
|
String pathWithFile = path + "/" + MavenConstants.POM_XML;
|
||||||
doTest(pathWithFile, pathWithFile.replace("pom", "pom_after"), new KotlinMavenConfigurator());
|
doTest(pathWithFile, pathWithFile.replace("pom", "pom_after"), new KotlinJavaMavenConfigurator());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doTestAndroidGradle(@NotNull String path) throws Exception {
|
public void doTestAndroidGradle(@NotNull String path) throws Exception {
|
||||||
@@ -51,7 +51,7 @@ public abstract class AbstractConfigureProjectByChangingFileTest extends LightCo
|
|||||||
((KotlinWithGradleConfigurator) configurator).changeGradleFile((GroovyFile) getFile(), version);
|
((KotlinWithGradleConfigurator) configurator).changeGradleFile((GroovyFile) getFile(), version);
|
||||||
}
|
}
|
||||||
else if (configurator instanceof KotlinMavenConfigurator) {
|
else if (configurator instanceof KotlinMavenConfigurator) {
|
||||||
KotlinMavenConfigurator.changePomFile(getModule(), getFile(), version);
|
((KotlinMavenConfigurator) configurator).changePomFile(getModule(), getFile(), version);
|
||||||
}
|
}
|
||||||
|
|
||||||
JetTestUtils.assertEqualsToFile(new File(afterFile), getFile().getText().replace(version, "$VERSION$"));
|
JetTestUtils.assertEqualsToFile(new File(afterFile), getFile().getText().replace(version, "$VERSION$"));
|
||||||
|
|||||||
Reference in New Issue
Block a user