IDEA-116756 Gradle multi-module project with deep-nested modules - idea places iml file in the wrong directory

This commit is contained in:
Vladislav.Soroka
2013-11-28 11:44:43 +04:00
parent 9ecbdc65a3
commit 8e2ad06199
8 changed files with 91 additions and 16 deletions
@@ -15,14 +15,15 @@
*/
package com.intellij.openapi.externalSystem.model.project;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
/**
* @author Denis Zhdanov
* @since 5/18/13 10:51 PM
*/
* @author Denis Zhdanov
* @since 5/18/13 10:51 PM
*/
public class ExternalProjectPojo implements Comparable<ExternalProjectPojo> {
@NotNull private String myName;
@NotNull private String myPath;
@@ -38,10 +39,11 @@ public class ExternalProjectPojo implements Comparable<ExternalProjectPojo> {
}
@NotNull
public static <T extends Named & ExternalConfigPathAware> ExternalProjectPojo from(@NotNull T data) {
return new ExternalProjectPojo(data.getName(), data.getLinkedExternalProjectPath());
public static <T extends Named & ExternalConfigPathAware & Identifiable> ExternalProjectPojo from(@NotNull T data) {
String projectUniqueName = StringUtil.isEmpty(data.getId()) ? data.getName() : data.getId();
return new ExternalProjectPojo(projectUniqueName, data.getLinkedExternalProjectPath());
}
@NotNull
public String getName() {
return myName;
@@ -0,0 +1,28 @@
/*
* Copyright 2000-2013 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 com.intellij.openapi.externalSystem.model.project;
import org.jetbrains.annotations.NotNull;
/**
* @author Vladislav.Soroka
* @since 11/27/13
*/
public interface Identifiable {
@NotNull
String getId();
}
@@ -4,7 +4,6 @@ import com.intellij.ide.highlighter.ModuleFileType;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.ContainerUtilRt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -17,12 +16,13 @@ import java.util.Map;
* @author Denis Zhdanov
* @since 8/8/11 12:11 PM
*/
public class ModuleData extends AbstractNamedData implements Named, ExternalConfigPathAware {
public class ModuleData extends AbstractNamedData implements Named, ExternalConfigPathAware, Identifiable {
private static final long serialVersionUID = 1L;
@NotNull private final Map<ExternalSystemSourceType, String> myCompileOutputPaths = ContainerUtilRt.newHashMap();
@NotNull private final Map<ExternalSystemSourceType, String> myCompileOutputPaths = ContainerUtil.newHashMap();
@NotNull private final String myId;
@NotNull private final String myIdeModuleFileName;
@NotNull private final String myModuleTypeId;
@NotNull private final String myExternalConfigPath;
@NotNull private String myModuleFilePath;
@@ -32,18 +32,41 @@ public class ModuleData extends AbstractNamedData implements Named, ExternalConf
private boolean myInheritProjectCompileOutputPath = true;
@Deprecated
public ModuleData(@NotNull ProjectSystemId owner,
@NotNull String typeId,
@NotNull String name,
@NotNull String moduleFileDirectoryPath,
@NotNull String externalConfigPath) {
this("", owner, typeId, name, moduleFileDirectoryPath, externalConfigPath);
}
public ModuleData(@NotNull String id,
@NotNull ProjectSystemId owner,
@NotNull String typeId,
@NotNull String name,
@NotNull String moduleFileDirectoryPath,
@NotNull String externalConfigPath) {
super(owner, name);
myId = id;
myIdeModuleFileName = name.replaceAll("(/|\\\\)", "_");
myModuleTypeId = typeId;
myExternalConfigPath = externalConfigPath;
myArtifacts = Collections.emptyList();
setModuleFileDirectoryPath(moduleFileDirectoryPath);
}
@NotNull
@Override
public String getId() {
return myId;
}
@NotNull
public String getIdeModuleFileName() {
return myIdeModuleFileName;
}
@NotNull
public String getModuleTypeId() {
return myModuleTypeId;
@@ -61,7 +84,7 @@ public class ModuleData extends AbstractNamedData implements Named, ExternalConf
}
public void setModuleFileDirectoryPath(@NotNull String path) {
myModuleFilePath = ExternalSystemApiUtil.toCanonicalPath(path + "/" + getName() + ModuleFileType.DOT_DEFAULT_EXTENSION);
myModuleFilePath = ExternalSystemApiUtil.toCanonicalPath(path + "/" + myIdeModuleFileName + ModuleFileType.DOT_DEFAULT_EXTENSION);
}
public boolean isInheritProjectCompileOutputPath() {
@@ -3,6 +3,7 @@ package com.intellij.openapi.externalSystem.model.project;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Not thread-safe.
@@ -10,7 +11,7 @@ import org.jetbrains.annotations.NotNull;
* @author Denis Zhdanov
* @since 8/1/11 1:30 PM
*/
public class ProjectData extends AbstractNamedData implements ExternalConfigPathAware {
public class ProjectData extends AbstractNamedData implements ExternalConfigPathAware, Identifiable {
private static final long serialVersionUID = 1L;
@@ -65,4 +66,10 @@ public class ProjectData extends AbstractNamedData implements ExternalConfigPath
public String toString() {
return String.format("%s project '%s'", getOwner().toString().toLowerCase(), getName());
}
@NotNull
@Override
public String getId() {
return "";
}
}
@@ -9,6 +9,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -28,7 +29,7 @@ public class ProjectStructureHelper {
@Nullable
public Module findIdeModule(@NotNull ModuleData module, @NotNull Project ideProject) {
return findIdeModule(module.getName(), ideProject);
return findIdeModule(module.getIdeModuleFileName(), ideProject);
}
@Nullable
@@ -68,7 +68,8 @@ class ExternalProjectBuilder extends BuilderSupport {
ProjectSystemId projectSystemId = attributes.projectSystemId ?: TEST_EXTERNAL_SYSTEM_ID
String moduleFilePath = attributes.moduleFilePath ?: projectDir.path
String externalConfigPath = attributes.externalConfigPath ?: projectDir.path
ModuleData moduleData = new ModuleData(projectSystemId,
ModuleData moduleData = new ModuleData(attributes.name ?: name as String,
projectSystemId,
ModuleTypeId.JAVA_MODULE,
attributes.name ?: name as String,
moduleFilePath,
@@ -26,6 +26,7 @@ import com.intellij.openapi.externalSystem.model.ProjectKeys;
import com.intellij.openapi.externalSystem.model.project.*;
import com.intellij.openapi.externalSystem.model.task.TaskData;
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
import com.intellij.openapi.externalSystem.util.ExternalSystemDebugEnvironment;
import com.intellij.openapi.externalSystem.util.Order;
import com.intellij.openapi.module.EmptyModuleType;
import com.intellij.openapi.module.JavaModuleType;
@@ -128,7 +129,13 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver
}
final String moduleConfigPath = GradleUtil.getConfigPath(gradleModule.getGradleProject(), projectData.getLinkedExternalProjectPath());
ModuleData moduleData = new ModuleData(GradleConstants.SYSTEM_ID,
if(ExternalSystemDebugEnvironment.DEBUG_ORPHAN_MODULES_PROCESSING) {
LOG.info(String.format(
"Creating module data ('%s') with the external config path: '%s'", gradleModule.getGradleProject().getPath(), moduleConfigPath
));
}
ModuleData moduleData = new ModuleData(gradleModule.getGradleProject().getPath(),
GradleConstants.SYSTEM_ID,
StdModuleTypes.JAVA.getId(),
moduleName,
moduleConfigPath,
@@ -29,6 +29,7 @@ import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotifica
import com.intellij.openapi.externalSystem.model.task.TaskData;
import com.intellij.openapi.externalSystem.service.project.ExternalSystemProjectResolver;
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
import com.intellij.openapi.externalSystem.util.ExternalSystemDebugEnvironment;
import com.intellij.openapi.util.KeyValue;
import com.intellij.openapi.util.Pair;
import com.intellij.util.Function;
@@ -204,6 +205,11 @@ public class GradleProjectResolver implements ExternalSystemProjectResolver<Grad
if (gradleModule == null) {
continue;
}
if (ExternalSystemDebugEnvironment.DEBUG_ORPHAN_MODULES_PROCESSING) {
LOG.info(String.format("Importing module data: %s", gradleModule));
}
final String moduleName = gradleModule.getName();
if (moduleName == null) {
throw new IllegalStateException("Module with undefined name detected: " + gradleModule);