mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-71952 Generating a sub module (with parents) from intellij creates a module without relativePath in it
This commit is contained in:
+1
@@ -130,6 +130,7 @@ public class MavenModulePsiReference extends MavenPsiReference implements LocalQ
|
||||
modulePom,
|
||||
new MavenId(groupId, artifactId, version),
|
||||
myWithParent ? id : null,
|
||||
myPsiFile.getVirtualFile(),
|
||||
true);
|
||||
}
|
||||
catch (IOException e) {
|
||||
|
||||
@@ -285,10 +285,18 @@ public class MavenUtil {
|
||||
return "<img src=\"" + url + "\"> ";
|
||||
}
|
||||
|
||||
public static void runOrApplyMavenProjectFileTemplate(Project project,
|
||||
VirtualFile file,
|
||||
MavenId projectId,
|
||||
boolean interactive) throws IOException {
|
||||
runOrApplyMavenProjectFileTemplate(project, file, projectId, null, null, interactive);
|
||||
}
|
||||
|
||||
public static void runOrApplyMavenProjectFileTemplate(Project project,
|
||||
VirtualFile file,
|
||||
MavenId projectId,
|
||||
MavenId parentId,
|
||||
VirtualFile parentFile,
|
||||
boolean interactive) throws IOException {
|
||||
Properties properties = new Properties();
|
||||
Properties conditions = new Properties();
|
||||
@@ -300,6 +308,21 @@ public class MavenUtil {
|
||||
properties.setProperty("PARENT_GROUP_ID", parentId.getGroupId());
|
||||
properties.setProperty("PARENT_ARTIFACT_ID", parentId.getArtifactId());
|
||||
properties.setProperty("PARENT_VERSION", parentId.getVersion());
|
||||
|
||||
if (parentFile != null) {
|
||||
VirtualFile modulePath = file.getParent();
|
||||
VirtualFile parentModulePath = parentFile.getParent();
|
||||
|
||||
if (modulePath.getParent() != parentModulePath) {
|
||||
String relativePath = VfsUtil.getPath(file, parentModulePath, '/');
|
||||
if (relativePath != null) {
|
||||
if (relativePath.endsWith("/")) relativePath = relativePath.substring(0, relativePath.length() - 1);
|
||||
|
||||
conditions.setProperty("HAS_RELATIVE_PATH", "true");
|
||||
properties.setProperty("PARENT_RELATIVE_PATH", relativePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
runOrApplyFileTemplate(project, file, MavenFileTemplateGroupFactory.MAVEN_PROJECT_XML_TEMPLATE, properties, conditions, interactive);
|
||||
}
|
||||
|
||||
+1
-1
@@ -94,7 +94,7 @@ public class MavenModuleBuilderHelper {
|
||||
VirtualFile file;
|
||||
try {
|
||||
file = root.createChildData(this, MavenConstants.POM_XML);
|
||||
MavenUtil.runOrApplyMavenProjectFileTemplate(project, file, myProjectId, null, isInteractive);
|
||||
MavenUtil.runOrApplyMavenProjectFileTemplate(project, file, myProjectId, isInteractive);
|
||||
result.setResult(file);
|
||||
}
|
||||
catch (IOException e) {
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
<groupId>${PARENT_GROUP_ID}</groupId>
|
||||
<artifactId>${PARENT_ARTIFACT_ID}</artifactId>
|
||||
<version>${PARENT_VERSION}</version>
|
||||
#if (${HAS_RELATIVE_PATH})
|
||||
<relativePath>${PARENT_RELATIVE_PATH}</relativePath>
|
||||
#end
|
||||
</parent>
|
||||
|
||||
#end
|
||||
|
||||
@@ -303,7 +303,11 @@ public abstract class MavenDomTestCase extends MavenImportingTestCase {
|
||||
}
|
||||
|
||||
protected IntentionAction getIntentionAtCaret(String intentionName) throws IOException {
|
||||
configTest(myProjectPom);
|
||||
return getIntentionAtCaret(myProjectPom, intentionName);
|
||||
}
|
||||
|
||||
protected IntentionAction getIntentionAtCaret(VirtualFile pomFile, String intentionName) throws IOException {
|
||||
configTest(pomFile);
|
||||
try {
|
||||
List<IntentionAction> intentions = myFixture.getAvailableIntentions();
|
||||
|
||||
|
||||
+90
@@ -20,6 +20,7 @@ import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
public class MavenModuleCompletionAndResolutionTest extends MavenDomWithIndicesTestCase {
|
||||
@@ -467,6 +468,95 @@ public class MavenModuleCompletionAndResolutionTest extends MavenDomWithIndicesT
|
||||
"</project>");
|
||||
}
|
||||
|
||||
public void testCreateModuleWithParentQuickFix2() throws Throwable {
|
||||
createProjectPom("<groupId>test</groupId>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
"<version>1</version>" +
|
||||
"<packaging>pom</packaging>");
|
||||
importProject();
|
||||
|
||||
createProjectPom("<groupId>test</groupId>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
"<version>1</version>" +
|
||||
"<packaging>pom</packaging>" +
|
||||
|
||||
"<modules>" +
|
||||
" <module>ppp/new<caret>Module</module>" +
|
||||
"</modules>");
|
||||
|
||||
IntentionAction i = getIntentionAtCaret(CREATE_MODULE_WITH_PARENT_INTENTION);
|
||||
assertNotNull(i);
|
||||
myFixture.launchAction(i);
|
||||
|
||||
assertCreateModuleFixResult(
|
||||
"ppp/newModule/pom.xml",
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" +
|
||||
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
|
||||
" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" +
|
||||
" <modelVersion>4.0.0</modelVersion>\n" +
|
||||
"\n" +
|
||||
" <parent>\n" +
|
||||
" <groupId>test</groupId>\n" +
|
||||
" <artifactId>project</artifactId>\n" +
|
||||
" <version>1</version>\n" +
|
||||
" <relativePath>../..</relativePath>\n" +
|
||||
" </parent>\n" +
|
||||
"\n" +
|
||||
" <groupId>test</groupId>\n" +
|
||||
" <artifactId>newModule</artifactId>\n" +
|
||||
" <version>1</version>\n" +
|
||||
"\n" +
|
||||
" \n" +
|
||||
"</project>");
|
||||
}
|
||||
|
||||
public void testCreateModuleWithParentQuickFix3() throws Throwable {
|
||||
VirtualFile parentPom = createModulePom("parent",
|
||||
"<groupId>test</groupId>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
"<version>1</version>" +
|
||||
"<packaging>pom</packaging>");
|
||||
|
||||
importProject(parentPom);
|
||||
|
||||
VfsUtil.saveText(parentPom, createPomXml(
|
||||
"<groupId>test</groupId>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
"<version>1</version>" +
|
||||
"<packaging>pom</packaging>" +
|
||||
|
||||
"<modules>" +
|
||||
" <module>../ppp/new<caret>Module</module>" +
|
||||
"</modules>"));
|
||||
|
||||
IntentionAction i = getIntentionAtCaret(parentPom, CREATE_MODULE_WITH_PARENT_INTENTION);
|
||||
assertNotNull(i);
|
||||
myFixture.launchAction(i);
|
||||
|
||||
assertCreateModuleFixResult(
|
||||
"ppp/newModule/pom.xml",
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" +
|
||||
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
|
||||
" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" +
|
||||
" <modelVersion>4.0.0</modelVersion>\n" +
|
||||
"\n" +
|
||||
" <parent>\n" +
|
||||
" <groupId>test</groupId>\n" +
|
||||
" <artifactId>project</artifactId>\n" +
|
||||
" <version>1</version>\n" +
|
||||
" <relativePath>../../parent</relativePath>\n" +
|
||||
" </parent>\n" +
|
||||
"\n" +
|
||||
" <groupId>test</groupId>\n" +
|
||||
" <artifactId>newModule</artifactId>\n" +
|
||||
" <version>1</version>\n" +
|
||||
"\n" +
|
||||
" \n" +
|
||||
"</project>");
|
||||
}
|
||||
|
||||
public void testDoesNotShowCreatePomQuickFixForEmptyModuleTag() throws Throwable {
|
||||
createProjectPom("<groupId>test</groupId>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
|
||||
Reference in New Issue
Block a user