mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-116891 gradle import creates a lot of extra empty directories
This commit is contained in:
@@ -11,6 +11,7 @@ setting.type.location.explicit.correct={0} location is defined
|
||||
setting.type.location.explicit.incorrect={0} location is incorrect
|
||||
settings.label.select.project={0} project:
|
||||
settings.label.use.auto.import=Use auto-import
|
||||
settings.label.create.empty.content.root.directories=Create directories for known content roots automatically
|
||||
settings.title.linked.projects=Linked {0} projects
|
||||
settings.title.project.settings=Project-level settings
|
||||
settings.title.system.settings=Global {0} settings
|
||||
|
||||
+10
@@ -28,6 +28,7 @@ public abstract class ExternalProjectSettings implements Comparable<ExternalProj
|
||||
|
||||
private String myExternalProjectPath;
|
||||
private boolean myUseAutoImport;
|
||||
private boolean myCreateEmptyContentRootDirectories;
|
||||
|
||||
public String getExternalProjectPath() {
|
||||
return myExternalProjectPath;
|
||||
@@ -45,6 +46,14 @@ public abstract class ExternalProjectSettings implements Comparable<ExternalProj
|
||||
myUseAutoImport = useAutoImport;
|
||||
}
|
||||
|
||||
public boolean isCreateEmptyContentRootDirectories() {
|
||||
return myCreateEmptyContentRootDirectories;
|
||||
}
|
||||
|
||||
public void setCreateEmptyContentRootDirectories(boolean createEmptyContentRootDirectories) {
|
||||
myCreateEmptyContentRootDirectories = createEmptyContentRootDirectories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull ExternalProjectSettings that) {
|
||||
return Comparing.compare(myExternalProjectPath, that.myExternalProjectPath);
|
||||
@@ -76,5 +85,6 @@ public abstract class ExternalProjectSettings implements Comparable<ExternalProj
|
||||
protected void copyTo(@NotNull ExternalProjectSettings receiver) {
|
||||
receiver.myExternalProjectPath = myExternalProjectPath;
|
||||
receiver.myUseAutoImport = myUseAutoImport;
|
||||
receiver.myCreateEmptyContentRootDirectories = myCreateEmptyContentRootDirectories;
|
||||
}
|
||||
}
|
||||
|
||||
+32
-12
@@ -4,10 +4,13 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.externalSystem.model.DataNode;
|
||||
import com.intellij.openapi.externalSystem.model.Key;
|
||||
import com.intellij.openapi.externalSystem.model.ProjectKeys;
|
||||
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
|
||||
import com.intellij.openapi.externalSystem.model.project.ContentRootData;
|
||||
import com.intellij.openapi.externalSystem.model.project.ExternalSystemSourceType;
|
||||
import com.intellij.openapi.externalSystem.model.project.ModuleData;
|
||||
import com.intellij.openapi.externalSystem.service.project.ProjectStructureHelper;
|
||||
import com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings;
|
||||
import com.intellij.openapi.externalSystem.settings.ExternalProjectSettings;
|
||||
import com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange;
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemConstants;
|
||||
@@ -95,30 +98,45 @@ public class ContentRootDataService implements ProjectDataService<ContentRootDat
|
||||
for(ContentEntry contentEntry : contentEntries) {
|
||||
contentEntriesMap.put(contentEntry.getUrl(), contentEntry);
|
||||
}
|
||||
|
||||
boolean createEmptyContentRootDirectories = false;
|
||||
if (!datas.isEmpty()) {
|
||||
ProjectSystemId projectSystemId = datas.iterator().next().getData().getOwner();
|
||||
AbstractExternalSystemSettings externalSystemSettings =
|
||||
ExternalSystemApiUtil.getSettings(module.getProject(), projectSystemId);
|
||||
|
||||
String path = module.getOptionValue(ExternalSystemConstants.ROOT_PROJECT_PATH_KEY);
|
||||
if (path != null) {
|
||||
ExternalProjectSettings projectSettings = externalSystemSettings.getLinkedProjectSettings(path);
|
||||
createEmptyContentRootDirectories = projectSettings != null && projectSettings.isCreateEmptyContentRootDirectories();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
for (final DataNode<ContentRootData> data : datas) {
|
||||
final ContentRootData contentRoot = data.getData();
|
||||
|
||||
final ContentEntry contentEntry = findOrCreateContentRoot(model, contentRoot.getRootPath());
|
||||
contentEntry.clearExcludeFolders();
|
||||
contentEntry.clearSourceFolders();
|
||||
LOG.info(String.format("Importing content root '%s' for module '%s'", contentRoot.getRootPath(), module.getName()));
|
||||
for (String path : contentRoot.getPaths(ExternalSystemSourceType.SOURCE)) {
|
||||
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, false);
|
||||
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, false, createEmptyContentRootDirectories);
|
||||
}
|
||||
for (String path : contentRoot.getPaths(ExternalSystemSourceType.TEST)) {
|
||||
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, false);
|
||||
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, false, createEmptyContentRootDirectories);
|
||||
}
|
||||
for (String path : contentRoot.getPaths(ExternalSystemSourceType.RESOURCE)) {
|
||||
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.RESOURCE, false);
|
||||
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.RESOURCE, false, createEmptyContentRootDirectories);
|
||||
}
|
||||
for (String path : contentRoot.getPaths(ExternalSystemSourceType.TEST_RESOURCE)) {
|
||||
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.TEST_RESOURCE, false);
|
||||
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.TEST_RESOURCE, false, createEmptyContentRootDirectories);
|
||||
}
|
||||
for (String path : contentRoot.getPaths(ExternalSystemSourceType.SOURCE_GENERATED)) {
|
||||
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, true);
|
||||
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, true, createEmptyContentRootDirectories);
|
||||
}
|
||||
for (String path : contentRoot.getPaths(ExternalSystemSourceType.TEST_GENERATED)) {
|
||||
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, true);
|
||||
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, true, createEmptyContentRootDirectories);
|
||||
}
|
||||
for (String path : contentRoot.getPaths(ExternalSystemSourceType.EXCLUDED)) {
|
||||
createExcludedRootIfAbsent(contentEntry, path, module.getName());
|
||||
@@ -154,7 +172,7 @@ public class ContentRootDataService implements ProjectDataService<ContentRootDat
|
||||
|
||||
private static void createSourceRootIfAbsent(
|
||||
@NotNull ContentEntry entry, @NotNull String path, @NotNull String moduleName,
|
||||
@NotNull JpsModuleSourceRootType sourceRootType, boolean generated) {
|
||||
@NotNull JpsModuleSourceRootType sourceRootType, boolean generated, boolean createEmptyContentRootDirectories) {
|
||||
List<SourceFolder> folders = entry.getSourceFolders(sourceRootType);
|
||||
for (SourceFolder folder : folders) {
|
||||
VirtualFile file = folder.getFile();
|
||||
@@ -173,11 +191,13 @@ public class ContentRootDataService implements ProjectDataService<ContentRootDat
|
||||
properties.setForGeneratedSources(true);
|
||||
}
|
||||
}
|
||||
try {
|
||||
VfsUtil.createDirectoryIfMissing(path);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.warn(String.format("Unable to create directory for the path: %s", path), e);
|
||||
if(createEmptyContentRootDirectories) {
|
||||
try {
|
||||
VfsUtil.createDirectoryIfMissing(path);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.warn(String.format("Unable to create directory for the path: %s", path), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-1
@@ -37,6 +37,7 @@ public abstract class AbstractExternalProjectSettingsControl<S extends ExternalP
|
||||
@NotNull private S myInitialSettings;
|
||||
|
||||
private JBCheckBox myUseAutoImportBox;
|
||||
private JBCheckBox myCreateEmptyContentRootDirectoriesBox;
|
||||
private boolean myHideUseAutoImportBox;
|
||||
|
||||
protected AbstractExternalProjectSettingsControl(@NotNull S initialSettings) {
|
||||
@@ -57,13 +58,18 @@ public abstract class AbstractExternalProjectSettingsControl<S extends ExternalP
|
||||
myUseAutoImportBox = new JBCheckBox(ExternalSystemBundle.message("settings.label.use.auto.import"));
|
||||
myUseAutoImportBox.setVisible(!myHideUseAutoImportBox);
|
||||
canvas.add(myUseAutoImportBox, ExternalSystemUiUtil.getFillLineConstraints(indentLevel));
|
||||
myCreateEmptyContentRootDirectoriesBox =
|
||||
new JBCheckBox(ExternalSystemBundle.message("settings.label.create.empty.content.root.directories"));
|
||||
canvas.add(myCreateEmptyContentRootDirectoriesBox, ExternalSystemUiUtil.getFillLineConstraints(indentLevel));
|
||||
fillExtraControls(canvas, indentLevel);
|
||||
}
|
||||
|
||||
protected abstract void fillExtraControls(@NotNull PaintAwarePanel content, int indentLevel);
|
||||
|
||||
public boolean isModified() {
|
||||
return myUseAutoImportBox.isSelected() != getInitialSettings().isUseAutoImport() || isExtraSettingModified();
|
||||
return myUseAutoImportBox.isSelected() != getInitialSettings().isUseAutoImport()
|
||||
|| myCreateEmptyContentRootDirectoriesBox.isSelected() != getInitialSettings().isCreateEmptyContentRootDirectories()
|
||||
|| isExtraSettingModified();
|
||||
}
|
||||
|
||||
protected abstract boolean isExtraSettingModified();
|
||||
@@ -74,6 +80,7 @@ public abstract class AbstractExternalProjectSettingsControl<S extends ExternalP
|
||||
|
||||
public void reset(boolean isDefaultModuleCreation) {
|
||||
myUseAutoImportBox.setSelected(getInitialSettings().isUseAutoImport());
|
||||
myCreateEmptyContentRootDirectoriesBox.setSelected(getInitialSettings().isCreateEmptyContentRootDirectories());
|
||||
resetExtraSettings(isDefaultModuleCreation);
|
||||
}
|
||||
|
||||
@@ -83,6 +90,8 @@ public abstract class AbstractExternalProjectSettingsControl<S extends ExternalP
|
||||
public void apply(@NotNull S settings) {
|
||||
settings.setUseAutoImport(myUseAutoImportBox.isSelected());
|
||||
myInitialSettings.setUseAutoImport(myUseAutoImportBox.isSelected());
|
||||
settings.setCreateEmptyContentRootDirectories(myCreateEmptyContentRootDirectoriesBox.isSelected());
|
||||
myInitialSettings.setCreateEmptyContentRootDirectories(myCreateEmptyContentRootDirectoriesBox.isSelected());
|
||||
if (myInitialSettings.getExternalProjectPath() != null) {
|
||||
settings.setExternalProjectPath(myInitialSettings.getExternalProjectPath());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user