mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-114047: "Create Class" quickfix places new class in "target/generated-source" by default
This commit is contained in:
@@ -143,6 +143,10 @@ public interface ContentEntry extends Synthetic {
|
||||
<P extends JpsElement>
|
||||
SourceFolder addSourceFolder(@NotNull String url, @NotNull JpsModuleSourceRootType<P> type);
|
||||
|
||||
@NotNull
|
||||
<P extends JpsElement>
|
||||
SourceFolder addSourceFolder(@NotNull String url, @NotNull JpsModuleSourceRootType<P> type, @NotNull P properties);
|
||||
|
||||
/**
|
||||
* Removes a source or test source root from this content root.
|
||||
*
|
||||
|
||||
+9
-1
@@ -219,8 +219,16 @@ public class ContentEntryImpl extends RootModelComponentBase implements ContentE
|
||||
@NotNull
|
||||
@Override
|
||||
public <P extends JpsElement> SourceFolder addSourceFolder(@NotNull String url, @NotNull JpsModuleSourceRootType<P> type) {
|
||||
return addSourceFolder(url, type, type.createDefaultProperties());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <P extends JpsElement> SourceFolder addSourceFolder(@NotNull String url,
|
||||
@NotNull JpsModuleSourceRootType<P> type,
|
||||
@NotNull P properties) {
|
||||
assertFolderUnderMe(url);
|
||||
JpsModuleSourceRoot sourceRoot = JpsElementFactory.getInstance().createModuleSourceRoot(url, type, type.createDefaultProperties());
|
||||
JpsModuleSourceRoot sourceRoot = JpsElementFactory.getInstance().createModuleSourceRoot(url, type, properties);
|
||||
return addSourceFolder(new SourceFolderImpl(sourceRoot, this));
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -205,7 +205,8 @@ public class JpsContentEntry implements ContentEntry, Disposable {
|
||||
return addSourceFolder(url, type, type.createDefaultProperties());
|
||||
}
|
||||
|
||||
private <P extends JpsElement> SourceFolder addSourceFolder(final String url, JpsModuleSourceRootType<P> type, P properties) {
|
||||
@NotNull
|
||||
public <P extends JpsElement> SourceFolder addSourceFolder(@NotNull String url, @NotNull JpsModuleSourceRootType<P> type, @NotNull P properties) {
|
||||
final JpsModuleSourceRoot sourceRoot = myModule.addSourceRoot(url, type, properties);
|
||||
final JpsSourceFolder sourceFolder = new JpsSourceFolder(sourceRoot, this);
|
||||
mySourceFolders.add(sourceFolder);
|
||||
|
||||
+11
-11
@@ -181,8 +181,8 @@ public class MavenFoldersImporter {
|
||||
myModel.unregisterAll(targetDir.getPath(), true, false);
|
||||
|
||||
if (myImportingSettings.getGeneratedSourcesFolder() != MavenImportingSettings.GeneratedSourcesFolder.IGNORE) {
|
||||
myModel.addSourceFolder(myMavenProject.getAnnotationProcessorDirectory(true), JavaSourceRootType.TEST_SOURCE, true);
|
||||
myModel.addSourceFolder(myMavenProject.getAnnotationProcessorDirectory(false), JavaSourceRootType.SOURCE, true);
|
||||
myModel.addGeneratedJavaSourceFolder(myMavenProject.getAnnotationProcessorDirectory(true), JavaSourceRootType.TEST_SOURCE);
|
||||
myModel.addGeneratedJavaSourceFolder(myMavenProject.getAnnotationProcessorDirectory(false), JavaSourceRootType.SOURCE);
|
||||
}
|
||||
|
||||
File[] targetChildren = targetDir.listFiles();
|
||||
@@ -230,11 +230,11 @@ public class MavenFoldersImporter {
|
||||
private void configGeneratedSourceFolder(@NotNull File targetDir, final JavaSourceRootType rootType) {
|
||||
switch (myImportingSettings.getGeneratedSourcesFolder()) {
|
||||
case GENERATED_SOURCE_FOLDER:
|
||||
myModel.addSourceFolder(targetDir.getPath(), rootType, true);
|
||||
myModel.addGeneratedJavaSourceFolder(targetDir.getPath(), rootType);
|
||||
break;
|
||||
|
||||
case SUBFOLDER:
|
||||
addAllSubDirsAsSources(targetDir, rootType);
|
||||
addAllSubDirsAsGeneratedSources(targetDir, rootType);
|
||||
break;
|
||||
|
||||
case AUTODETECT:
|
||||
@@ -242,14 +242,14 @@ public class MavenFoldersImporter {
|
||||
|
||||
for (JavaModuleSourceRoot root : sourceRoots) {
|
||||
if (FileUtil.filesEqual(targetDir, root.getDirectory())) {
|
||||
myModel.addSourceFolder(targetDir.getPath(), rootType);
|
||||
myModel.addGeneratedJavaSourceFolder(targetDir.getPath(), rootType);
|
||||
return;
|
||||
}
|
||||
|
||||
addAsSourceFolder(root.getDirectory(), rootType);
|
||||
addAsGeneratedSourceFolder(root.getDirectory(), rootType);
|
||||
}
|
||||
|
||||
addAllSubDirsAsSources(targetDir, rootType);
|
||||
addAllSubDirsAsGeneratedSources(targetDir, rootType);
|
||||
break;
|
||||
|
||||
case IGNORE:
|
||||
@@ -257,16 +257,16 @@ public class MavenFoldersImporter {
|
||||
}
|
||||
}
|
||||
|
||||
private void addAsSourceFolder(@NotNull File dir, final JavaSourceRootType rootType) {
|
||||
private void addAsGeneratedSourceFolder(@NotNull File dir, final JavaSourceRootType rootType) {
|
||||
if (!myModel.hasRegisteredSourceSubfolder(dir)) {
|
||||
myModel.addSourceFolder(dir.getPath(), rootType, true);
|
||||
myModel.addGeneratedJavaSourceFolder(dir.getPath(), rootType);
|
||||
}
|
||||
}
|
||||
|
||||
private void addAllSubDirsAsSources(@NotNull File dir, final JavaSourceRootType rootType) {
|
||||
private void addAllSubDirsAsGeneratedSources(@NotNull File dir, final JavaSourceRootType rootType) {
|
||||
for (File f : getChildren(dir)) {
|
||||
if (f.isDirectory()) {
|
||||
addAsSourceFolder(f, rootType);
|
||||
addAsGeneratedSourceFolder(f, rootType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-4
@@ -39,6 +39,9 @@ import org.jetbrains.idea.maven.project.MavenProject;
|
||||
import org.jetbrains.idea.maven.project.MavenProjectsManager;
|
||||
import org.jetbrains.idea.maven.utils.Path;
|
||||
import org.jetbrains.idea.maven.utils.Url;
|
||||
import org.jetbrains.jps.model.JpsElement;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType;
|
||||
import org.jetbrains.jps.model.java.JpsJavaExtensionService;
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
|
||||
|
||||
import java.io.File;
|
||||
@@ -130,11 +133,16 @@ public class MavenRootModelAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
public void addSourceFolder(String path, final JpsModuleSourceRootType<?> rootType) {
|
||||
addSourceFolder(path, rootType, false);
|
||||
public <P extends JpsElement> void addSourceFolder(String path, final JpsModuleSourceRootType<P> rootType) {
|
||||
addSourceFolder(path, rootType, false, rootType.createDefaultProperties());
|
||||
}
|
||||
|
||||
public void addSourceFolder(String path, final JpsModuleSourceRootType<?> rootType, boolean ifNotEmpty) {
|
||||
public void addGeneratedJavaSourceFolder(String path, JavaSourceRootType rootType) {
|
||||
addSourceFolder(path, rootType, true, JpsJavaExtensionService.getInstance().createSourceRootProperties("", true));
|
||||
}
|
||||
|
||||
private <P extends JpsElement> void addSourceFolder(@NotNull String path, final @NotNull JpsModuleSourceRootType<P> rootType, boolean ifNotEmpty,
|
||||
final @NotNull P properties) {
|
||||
if (ifNotEmpty) {
|
||||
String[] childs = new File(toPath(path).getPath()).list();
|
||||
if (childs == null || childs.length == 0) return;
|
||||
@@ -148,7 +156,7 @@ public class MavenRootModelAdapter {
|
||||
if (e == null) return;
|
||||
unregisterAll(path, true, true);
|
||||
unregisterAll(path, false, true);
|
||||
e.addSourceFolder(url.getUrl(), rootType);
|
||||
e.addSourceFolder(url.getUrl(), rootType, properties);
|
||||
}
|
||||
|
||||
public boolean hasRegisteredSourceSubfolder(File f) {
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.intellij.openapi.progress.EmptyProgressIndicator;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.impl.SourceFolderImpl;
|
||||
import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
@@ -48,11 +49,12 @@ import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.concurrency.Semaphore;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.maven.execution.*;
|
||||
import org.jetbrains.idea.maven.model.MavenArtifact;
|
||||
import org.jetbrains.idea.maven.project.*;
|
||||
import org.jetbrains.jps.model.java.JavaResourceRootType;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootProperties;
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType;
|
||||
import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
|
||||
|
||||
@@ -123,6 +125,17 @@ public abstract class MavenImportingTestCase extends MavenTestCase {
|
||||
doAssertContentFolders(moduleName, JavaSourceRootType.SOURCE, expectedSources);
|
||||
}
|
||||
|
||||
protected void assertGeneratedSources(String moduleName, String... expectedSources) {
|
||||
ContentEntry contentRoot = getContentRoot(moduleName);
|
||||
List<ContentFolder> folders = new ArrayList<ContentFolder>();
|
||||
for (SourceFolder folder : contentRoot.getSourceFolders(JavaSourceRootType.SOURCE)) {
|
||||
if (((JavaSourceRootProperties)((SourceFolderImpl)folder).getJpsElement().getProperties()).isForGeneratedSources()) {
|
||||
folders.add(folder);
|
||||
}
|
||||
}
|
||||
doAssertContentFolders(contentRoot, folders, expectedSources);
|
||||
}
|
||||
|
||||
protected void assertResources(String moduleName, String... expectedSources) {
|
||||
doAssertContentFolders(moduleName, JavaResourceRootType.RESOURCE, expectedSources);
|
||||
}
|
||||
@@ -136,20 +149,23 @@ public abstract class MavenImportingTestCase extends MavenTestCase {
|
||||
}
|
||||
|
||||
protected void assertExcludes(String moduleName, String... expectedExcludes) {
|
||||
doAssertContentFolders(moduleName, null, expectedExcludes);
|
||||
ContentEntry contentRoot = getContentRoot(moduleName);
|
||||
doAssertContentFolders(contentRoot, Arrays.asList(contentRoot.getExcludeFolders()), expectedExcludes);
|
||||
}
|
||||
|
||||
protected void assertContentRootExcludes(String moduleName, String contentRoot, String... expectedExcudes) {
|
||||
doAssertContentFolders(getContentRoot(moduleName, contentRoot), null, expectedExcudes);
|
||||
ContentEntry root = getContentRoot(moduleName, contentRoot);
|
||||
doAssertContentFolders(root, Arrays.asList(root.getExcludeFolders()), expectedExcudes);
|
||||
}
|
||||
|
||||
private void doAssertContentFolders(String moduleName, @Nullable JpsModuleSourceRootType<?> rootType, String... expected) {
|
||||
doAssertContentFolders(getContentRoot(moduleName), rootType, expected);
|
||||
private void doAssertContentFolders(String moduleName, @NotNull JpsModuleSourceRootType<?> rootType, String... expected) {
|
||||
ContentEntry contentRoot = getContentRoot(moduleName);
|
||||
doAssertContentFolders(contentRoot, contentRoot.getSourceFolders(rootType), expected);
|
||||
}
|
||||
|
||||
private static void doAssertContentFolders(ContentEntry e, @Nullable JpsModuleSourceRootType<?> rootType, String... expected) {
|
||||
private static void doAssertContentFolders(ContentEntry e, final List<? extends ContentFolder> folders, String... expected) {
|
||||
List<String> actual = new ArrayList<String>();
|
||||
for (ContentFolder f : rootType != null ? e.getSourceFolders(rootType) : Arrays.asList(e.getExcludeFolders())) {
|
||||
for (ContentFolder f : folders) {
|
||||
String rootUrl = e.getUrl();
|
||||
String folderUrl = f.getUrl();
|
||||
|
||||
|
||||
+2
-2
@@ -79,10 +79,10 @@ public class MavenFoldersImporterTest extends MavenImportingTestCase {
|
||||
updateProjectFolders();
|
||||
|
||||
assertExcludes("m1", "target/foo");
|
||||
assertSources("m1", "target/generated-sources/xxx");
|
||||
assertGeneratedSources("m1", "target/generated-sources/xxx");
|
||||
|
||||
assertExcludes("m2", "target/bar");
|
||||
assertSources("m2", "target/generated-sources/yyy");
|
||||
assertGeneratedSources("m2", "target/generated-sources/yyy");
|
||||
}
|
||||
|
||||
public void testDoesNotTouchSourceFolders() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user