old java source root detection code removed

This commit is contained in:
nik
2011-10-25 17:37:04 +04:00
parent 5f8f9f4df2
commit b4a3d35a08
14 changed files with 110 additions and 255 deletions
@@ -17,35 +17,49 @@ package com.intellij.ide.util.importProject;
import com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot;
import com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.SmartList;
import java.io.File;
import java.io.IOException;
import java.util.*;
/**
* @author nik
*/
public class RootDetectionProcessor {
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.util.importProject.RootDetectionProcessor");
private final File myBaseDir;
private final ProjectStructureDetector[] myDetectors;
private final List<DetectedProjectRoot>[] myDetectedRoots;
private final FileTypeManager myTypeManager;
private final ProgressIndicator myProgressIndicator;
public RootDetectionProcessor(File baseDir) {
myBaseDir = baseDir;
myDetectors = ProjectStructureDetector.EP_NAME.getExtensions();
public RootDetectionProcessor(File baseDir, final ProjectStructureDetector[] detectors) {
myBaseDir = getCanonicalDir(baseDir);
myDetectors = detectors;
//noinspection unchecked
myDetectedRoots = new List[myDetectors.length];
myTypeManager = FileTypeManager.getInstance();
myProgressIndicator = ProgressManager.getInstance().getProgressIndicator();
}
private static File getCanonicalDir(File baseDir) {
try {
return new File(FileUtil.resolveShortWindowsName(baseDir.getAbsolutePath()));
}
catch (IOException e) {
LOG.info(e);
return baseDir;
}
}
public Map<ProjectStructureDetector, List<DetectedProjectRoot>> findRoots() {
if (!myBaseDir.isDirectory()) {
@@ -172,9 +172,10 @@ public class RootsDetectionStep extends AbstractStepWithProgress<List<DetectedRo
if (baseProjectPath == null) {
return Collections.emptyList();
}
final File baseProjectFile = new File(baseProjectPath);
Map<ProjectStructureDetector, List<DetectedProjectRoot>> roots = new RootDetectionProcessor(baseProjectFile).findRoots();
final File baseProjectFile = new File(baseProjectPath);
Map<ProjectStructureDetector, List<DetectedProjectRoot>> roots = new RootDetectionProcessor(baseProjectFile,
ProjectStructureDetector.EP_NAME.getExtensions()).findRoots();
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
if (progressIndicator != null) {
progressIndicator.setText2("Processing " + roots.values().size() + " project roots...");
@@ -1,43 +0,0 @@
/*
* Copyright 2000-2010 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.ide.util.newProjectWizard;
import com.intellij.ide.util.projectWizard.importSources.JavaSourceRootDetectionUtil;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.util.Pair;
import java.io.File;
import java.util.List;
/**
* @author Maxim.Medvedev
*/
public class JavaSourceRootFinder implements SourceRootFinder {
@Override
public List<Pair<File, String>> findRoots(File dir) {
return JavaSourceRootDetectionUtil.suggestRoots(dir, StdFileTypes.JAVA);
}
@Override
public String getDescription() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public String getName() {
return "Java";
}
}
@@ -21,6 +21,8 @@ import com.intellij.ide.util.BrowseFilesListener;
import com.intellij.ide.util.ElementsChooser;
import com.intellij.ide.util.projectWizard.AbstractStepWithProgress;
import com.intellij.ide.util.projectWizard.SourcePathsBuilder;
import com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot;
import com.intellij.ide.util.projectWizard.importSources.JavaSourceRootDetectionUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.diagnostic.Logger;
@@ -30,7 +32,6 @@ import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.MultiLineLabelUI;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Trinity;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
@@ -38,8 +39,6 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.FieldPanel;
import com.intellij.util.StringBuilderSpinAllocator;
import com.intellij.util.containers.MultiMap;
import com.intellij.util.containers.hash.HashMap;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -52,15 +51,16 @@ import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
* @author Eugene Zhuravlev
* Date: Jan 6, 2004
*/
public class SourcePathsStep extends AbstractStepWithProgress<List<Trinity<String, String, Collection<String>>>> {
public class SourcePathsStep extends AbstractStepWithProgress<List<JavaModuleSourceRoot>> {
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.util.newProjectWizard.SourcePathsStep");
@@ -68,11 +68,10 @@ public class SourcePathsStep extends AbstractStepWithProgress<List<Trinity<Strin
@NonNls private static final String CREATE_SOURCE_PANEL = "create_source";
@NonNls private static final String CHOOSE_SOURCE_PANEL = "choose_source";
private static final List<Trinity<String, String, Collection<String>>> EMPTY_STRING_STRING_ARRAY = Collections.emptyList();
private final SourcePathsBuilder myBuilder;
private final Icon myIcon;
private final String myHelpId;
private ElementsChooser<Trinity<String, String, Collection<String>>> mySourcePathsChooser;
private ElementsChooser<JavaModuleSourceRoot> mySourcePathsChooser;
private String myCurrentContentEntryPath = null;
private JRadioButton myRbCreateSource;
private JRadioButton myRbNoSource;
@@ -166,19 +165,16 @@ public class SourcePathsStep extends AbstractStepWithProgress<List<Trinity<Strin
private JComponent createComponentForChooseSources() {
final JPanel panel = new JPanel(new GridBagLayout());
mySourcePathsChooser = new ElementsChooser<Trinity<String, String, Collection<String>>>(true) {
public String getItemText(@NotNull Trinity<String, String, Collection<String>> pair) {
mySourcePathsChooser = new ElementsChooser<JavaModuleSourceRoot>(true) {
public String getItemText(@NotNull JavaModuleSourceRoot sourceRoot) {
StringBuilder builder = StringBuilderSpinAllocator.alloc();
try {
builder.append(pair.first);
if (!"".equals(pair.second)) {
builder.append(" (").append(pair.second).append(")");
builder.append(sourceRoot.getDirectory().getAbsolutePath());
final String packagePrefix = sourceRoot.getPackagePrefix();
if (!packagePrefix.isEmpty()) {
builder.append(" (").append(packagePrefix).append(")");
}
builder.append(" [");
for (String name : pair.third) {
builder.append(name).append(", ");
}
builder.replace(builder.length() - 2, builder.length(), "]");
builder.append(" [").append(sourceRoot.getRootTypeName()).append("]");
return builder.toString();
}
finally {
@@ -219,12 +215,12 @@ public class SourcePathsStep extends AbstractStepWithProgress<List<Trinity<Strin
public void updateDataModel() {
List<Pair<String,String>> paths = null;
if (CHOOSE_SOURCE_PANEL.equals(myCurrentMode)) {
final List<Trinity<String, String, Collection<String>>> selectedElements = mySourcePathsChooser.getMarkedElements();
final List<JavaModuleSourceRoot> selectedElements = mySourcePathsChooser.getMarkedElements();
if (selectedElements.size() > 0) {
paths = new ArrayList<Pair<String, String>>(selectedElements.size());
for (final Trinity<String, String, Collection<String>> path : selectedElements) {
paths.add(Pair.create(path.first.replace(File.separatorChar, '/'), path.second));
for (final JavaModuleSourceRoot root : selectedElements) {
paths.add(Pair.create(FileUtil.toSystemIndependentName(root.getDirectory().getAbsolutePath()), root.getPackagePrefix()));
}
}
}
@@ -294,7 +290,7 @@ public class SourcePathsStep extends AbstractStepWithProgress<List<Trinity<Strin
return isContentEntryChanged();
}
protected void onFinished(final List<Trinity<String, String, Collection<String>>> foundPaths, final boolean canceled) {
protected void onFinished(final List<JavaModuleSourceRoot> foundPaths, final boolean canceled) {
if (foundPaths.size() > 0) {
myCurrentMode = CHOOSE_SOURCE_PANEL;
mySourcePathsChooser.setElements(foundPaths, true);
@@ -323,50 +319,16 @@ public class SourcePathsStep extends AbstractStepWithProgress<List<Trinity<Strin
return myCurrentContentEntryPath == null? contentEntryPath != null : !myCurrentContentEntryPath.equals(contentEntryPath);
}
protected List<Trinity<String, String, Collection<String>>> calculate() {
return calculateSourceRoots(getContentRootPath());
protected List<JavaModuleSourceRoot> calculate() {
return new ArrayList<JavaModuleSourceRoot>(calculateSourceRoots(getContentRootPath()));
}
@NotNull
public static List<Trinity<String, String, Collection<String>>> calculateSourceRoots(final String contentRootPath) {
public static Collection<JavaModuleSourceRoot> calculateSourceRoots(final String contentRootPath) {
if (contentRootPath == null) {
return EMPTY_STRING_STRING_ARRAY;
return Collections.emptyList();
}
final File entryFile = new File(contentRootPath);
if (!entryFile.exists()) {
return EMPTY_STRING_STRING_ARRAY;
}
final File[] children = entryFile.listFiles();
if (children == null || children.length == 0) {
return EMPTY_STRING_STRING_ARRAY;
}
final Map<File, String> skippedPackages = new HashMap<File, String>();
final MultiMap<File, String> foundLanguages = new MultiMap<File, String>();
for (SourceRootFinder finder : SourceRootFinder.EP_NAME.getExtensions()) {
final List<Pair<File, String>> roots = finder.findRoots(entryFile);
final String name = finder.getName();
for (Pair<File, String> root : roots) {
if (!skippedPackages.containsKey(root.first)) {
skippedPackages.put(root.first, root.second);
}
foundLanguages.putValue(root.first, name);
}
}
final List<Trinity<String, String, Collection<String>>> paths = new ArrayList<Trinity<String, String, Collection<String>>>();
for (final File suggestedRoot : skippedPackages.keySet()) {
try {
if (FileUtil.isAncestor(entryFile, suggestedRoot, false)) {
final String path = FileUtil.resolveShortWindowsName(suggestedRoot.getPath());
paths.add(Trinity.create(path, skippedPackages.get(suggestedRoot), foundLanguages.get(suggestedRoot)));
}
}
catch (IOException e) {
LOG.info(e);
}
}
return paths;
return JavaSourceRootDetectionUtil.suggestRoots(new File(contentRootPath));
}
@Nullable
@@ -24,6 +24,11 @@ import java.util.List;
/**
* @author Maxim.Medvedev
*/
/**
* @deprecated use {@link com.intellij.ide.util.projectWizard.importSources.JavaSourceRootDetector} instead
*/
@Deprecated
public interface SourceRootFinder {
ExtensionPointName<SourceRootFinder> EP_NAME = ExtensionPointName.create("com.intellij.sourceRootFinder");
@@ -63,8 +63,13 @@ public class JavaModuleSourceRoot extends DetectedProjectRoot {
@Override
public DetectedProjectRoot combineWith(@NotNull DetectedProjectRoot root) {
if (root instanceof JavaModuleSourceRoot) {
return new JavaModuleSourceRoot(getDirectory(), myPackagePrefix, ContainerUtil.concat(myLanguages, ((JavaModuleSourceRoot)root).myLanguages));
return combineWith((JavaModuleSourceRoot)root);
}
return null;
}
@NotNull
public JavaModuleSourceRoot combineWith(@NotNull JavaModuleSourceRoot root) {
return new JavaModuleSourceRoot(getDirectory(), myPackagePrefix, ContainerUtil.concat(myLanguages, root.myLanguages));
}
}
@@ -15,13 +15,9 @@
*/
package com.intellij.ide.util.projectWizard.importSources;
import com.intellij.ide.util.importProject.RootDetectionProcessor;
import com.intellij.lexer.JavaLexer;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
@@ -32,13 +28,17 @@ import com.intellij.psi.impl.source.tree.ElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
import com.intellij.util.StringBuilderSpinAllocator;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.text.CharArrayCharSequence;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class JavaSourceRootDetectionUtil {
@@ -50,78 +50,29 @@ public class JavaSourceRootDetectionUtil {
private JavaSourceRootDetectionUtil() { }
public static List<Pair<File,String>> suggestRoots(File dir, LanguageFileType fileType) {
ArrayList<Pair<File,String>> foundDirectories = new ArrayList<Pair<File, String>>();
try{
suggestRootsImpl(dir, dir, foundDirectories, fileType);
}
catch(PathFoundException ignore){
}
return foundDirectories;
}
@NotNull
public static Collection<JavaModuleSourceRoot> suggestRoots(@NotNull File dir) {
final List<JavaSourceRootDetector> detectors = ContainerUtil.findAll(ProjectStructureDetector.EP_NAME.getExtensions(), JavaSourceRootDetector.class);
final RootDetectionProcessor processor = new RootDetectionProcessor(dir, detectors.toArray(new JavaSourceRootDetector[detectors.size()]));
final Map<ProjectStructureDetector,List<DetectedProjectRoot>> rootsMap = processor.findRoots();
private static class PathFoundException extends Exception {
public File myDirectory;
public PathFoundException(File directory) {
myDirectory = directory;
}
}
private static void suggestRootsImpl(File base,
File dir,
ArrayList<? super Pair<File, String>> foundDirectories,
LanguageFileType fileType) throws PathFoundException {
if (!dir.isDirectory()) {
return;
}
FileTypeManager typeManager = FileTypeManager.getInstance();
if (typeManager.isFileIgnored(dir.getName())) {
return;
}
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
if (progressIndicator != null) {
if (progressIndicator.isCanceled()) {
return;
}
progressIndicator.setText2(dir.getPath());
}
File[] list = dir.listFiles();
if (list == null || list.length == 0) {
return;
}
for (File child : list) {
if (child.isFile()) {
FileType type = typeManager.getFileTypeByFileName(child.getName());
if (fileType == type) {
if (progressIndicator != null && progressIndicator.isCanceled()) {
return;
}
Pair<File, String> root = suggestRootForJavaFile(child, base);
if (root != null) {
foundDirectories.add(root);
throw new PathFoundException(root.getFirst());
Map<File, JavaModuleSourceRoot> result = new HashMap<File, JavaModuleSourceRoot>();
for (List<DetectedProjectRoot> roots : rootsMap.values()) {
for (DetectedProjectRoot root : roots) {
if (root instanceof JavaModuleSourceRoot) {
final JavaModuleSourceRoot sourceRoot = (JavaModuleSourceRoot)root;
final File directory = sourceRoot.getDirectory();
final JavaModuleSourceRoot oldRoot = result.remove(directory);
if (oldRoot != null) {
result.put(directory, oldRoot.combineWith(sourceRoot));
}
else {
return;
}
}
}
}
for (File child : list) {
if (child.isDirectory()) {
try {
suggestRootsImpl(base, child, foundDirectories, fileType);
}
catch (PathFoundException found) {
if (!found.myDirectory.equals(child)) {
throw found;
result.put(directory, sourceRoot);
}
}
}
}
return result.values();
}
@@ -16,8 +16,8 @@
package com.intellij.openapi.roots.ui.configuration;
import com.intellij.Patches;
import com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot;
import com.intellij.ide.util.projectWizard.importSources.JavaSourceRootDetectionUtil;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
@@ -27,7 +27,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
@@ -36,6 +35,7 @@ import com.intellij.util.concurrency.SwingWorker;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -73,7 +73,7 @@ public class JavaContentEntriesEditor extends CommonContentEntriesEditor {
}
private static void addSourceRoots(final Project project, final ContentEntry[] contentEntries, final Runnable finishRunnable) {
final HashMap<ContentEntry, List<Pair<File, String>>> entryToRootMap = new HashMap<ContentEntry, List<Pair<File, String>>>();
final HashMap<ContentEntry, Collection<JavaModuleSourceRoot>> entryToRootMap = new HashMap<ContentEntry, Collection<JavaModuleSourceRoot>>();
final Map<File, ContentEntry> fileToEntryMap = new HashMap<File, ContentEntry>();
for (final ContentEntry contentEntry : contentEntries) {
final VirtualFile file = contentEntry.getFile();
@@ -94,7 +94,7 @@ public class JavaContentEntriesEditor extends CommonContentEntriesEditor {
public void run() {
for (final File file : fileToEntryMap.keySet()) {
progressIndicator.setText(ProjectBundle.message("module.paths.searching.source.roots.progress", file.getPath()));
final List<Pair<File, String>> roots = JavaSourceRootDetectionUtil.suggestRoots(file, StdFileTypes.JAVA);
final Collection<JavaModuleSourceRoot> roots = JavaSourceRootDetectionUtil.suggestRoots(file);
entryToRootMap.put(fileToEntryMap.get(file), roots);
}
}
@@ -107,13 +107,13 @@ public class JavaContentEntriesEditor extends CommonContentEntriesEditor {
final Runnable addSourcesRunnable = new Runnable() {
public void run() {
for (final ContentEntry contentEntry : contentEntries) {
final List<Pair<File, String>> suggestedRoots = entryToRootMap.get(contentEntry);
final Collection<JavaModuleSourceRoot> suggestedRoots = entryToRootMap.get(contentEntry);
if (suggestedRoots != null) {
for (final Pair<File, String> suggestedRoot : suggestedRoots) {
final VirtualFile sourceRoot = LocalFileSystem.getInstance().findFileByIoFile(suggestedRoot.first);
for (final JavaModuleSourceRoot suggestedRoot : suggestedRoots) {
final VirtualFile sourceRoot = LocalFileSystem.getInstance().findFileByIoFile(suggestedRoot.getDirectory());
final VirtualFile fileContent = contentEntry.getFile();
if (sourceRoot != null && fileContent != null && VfsUtil.isAncestor(fileContent, sourceRoot, false)) {
contentEntry.addSourceFolder(sourceRoot, false, suggestedRoot.getSecond());
contentEntry.addSourceFolder(sourceRoot, false, suggestedRoot.getPackagePrefix());
}
}
}
@@ -16,7 +16,7 @@
package com.intellij.ide.util;
import com.intellij.JavaTestUtil;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot;
import com.intellij.ide.util.projectWizard.importSources.JavaSourceRootDetectionUtil;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
@@ -58,7 +58,10 @@ public class JavaSourceRootDetectionTest extends PlatformTestCase {
final String dirPath = JavaTestUtil.getJavaTestDataPath() + FileUtil.toSystemDependentName("/ide/sourceRootDetection/" + getTestName(true));
final File dir = new File(dirPath);
assertTrue(dir.isDirectory());
final List<Pair<File,String>> actual = JavaSourceRootDetectionUtil.suggestRoots(dir, JavaFileType.INSTANCE);
final List<Pair<File, String>> actual = new ArrayList<Pair<File, String>>();
for (JavaModuleSourceRoot root : JavaSourceRootDetectionUtil.suggestRoots(dir)) {
actual.add(Pair.create(root.getDirectory(), root.getPackagePrefix()));
}
List<Pair<File, String>> expectedList = new ArrayList<Pair<File, String>>();
for (int i = 0; i < expected.length / 2; i++) {
expectedList.add(Pair.create(new File(dir, expected[2 * i]), expected[2 * i + 1]));
@@ -392,7 +392,6 @@
<xml.attributeDescriptorsProvider implementation="com.intellij.html.impl.Html5CustomAttributeDescriptorsProvider"/>
<sourceRootFinder implementation="com.intellij.ide.util.newProjectWizard.JavaSourceRootFinder"/>
<breadcrumbsPresentationProvider
implementation="com.intellij.codeInsight.daemon.impl.tagTreeHighlighting.XmlTagTreeBreadcrumbsPresentationProvider"/>
</extensions>
@@ -3,6 +3,7 @@ package org.jetbrains.android.importDependencies;
import com.intellij.CommonBundle;
import com.intellij.ide.highlighter.ModuleFileType;
import com.intellij.ide.util.newProjectWizard.SourcePathsStep;
import com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
@@ -17,7 +18,6 @@ import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Trinity;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
@@ -30,7 +30,10 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* @author Eugene.Kudelevsky
@@ -151,7 +154,7 @@ public class ImportDependenciesUtil {
}
if (createNewModuleTasks.size() > 0) {
final List<Trinity<String, String, Collection<String>>> sourceRoots = new ArrayList<Trinity<String, String, Collection<String>>>();
final List<JavaModuleSourceRoot> sourceRoots = new ArrayList<JavaModuleSourceRoot>();
for (CreateNewModuleTask task : createNewModuleTasks) {
final String contentRootPath = task.getContentRoot().getPath();
sourceRoots.addAll(SourcePathsStep.calculateSourceRoots(contentRootPath));
@@ -174,15 +177,15 @@ public class ImportDependenciesUtil {
}
}
private static void addSourceRoots(final Project project, final Collection<Trinity<String, String, Collection<String>>> sourceRoots) {
private static void addSourceRoots(final Project project, final List<JavaModuleSourceRoot> sourceRoots) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
for (Trinity<String, String, Collection<String>> sourceRootTrinity : sourceRoots) {
final VirtualFile sourceRoot = LocalFileSystem.getInstance()
.refreshAndFindFileByPath(FileUtil.toSystemIndependentName(sourceRootTrinity.first));
for (JavaModuleSourceRoot sourceRootTrinity : sourceRoots) {
final String path = sourceRootTrinity.getDirectory().getPath();
final VirtualFile sourceRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(path));
if (sourceRoot == null) {
LOG.debug(new Exception("Cannot find source root " + sourceRootTrinity.first));
LOG.debug(new Exception("Cannot find source root " + path));
continue;
}
@@ -195,7 +198,7 @@ public class ImportDependenciesUtil {
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
final ContentEntry[] entries = model.getContentEntries();
if (entries.length > 0) {
entries[0].addSourceFolder(sourceRoot, false, sourceRootTrinity.second);
entries[0].addSourceFolder(sourceRoot, false, sourceRootTrinity.getPackagePrefix());
}
else {
LOG.debug(new Exception("Module " + module.getName() + " has no content entries"));
@@ -1,34 +1,33 @@
package org.jetbrains.android.importDependencies;
import com.intellij.ide.util.ElementsChooser;
import com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.VerticalFlowLayout;
import com.intellij.openapi.util.Trinity;
import org.jetbrains.android.util.AndroidBundle;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.util.Collection;
import java.util.List;
/**
* @author Eugene.Kudelevsky
*/
class ImportSourceRootsDialog extends DialogWrapper {
private final ElementsChooser<Trinity<String, String, Collection<String>>> mySourcePathsChooser;
private final ElementsChooser<JavaModuleSourceRoot> mySourcePathsChooser;
public ImportSourceRootsDialog(@NotNull Project project, @NotNull List<Trinity<String, String, Collection<String>>> sourceRoots) {
public ImportSourceRootsDialog(@NotNull Project project, @NotNull List<JavaModuleSourceRoot> sourceRoots) {
super(project, false);
setTitle(AndroidBundle.message("android.import.dependencies.source.roots.dialog.title"));
mySourcePathsChooser = new ElementsChooser<Trinity<String, String, Collection<String>>>(true) {
public String getItemText(@NotNull Trinity<String, String, Collection<String>> sourceRootTrinity) {
return sourceRootTrinity.second.length() > 0
? sourceRootTrinity.first + " (" + sourceRootTrinity.second + ")"
: sourceRootTrinity.first;
mySourcePathsChooser = new ElementsChooser<JavaModuleSourceRoot>(true) {
public String getItemText(@NotNull JavaModuleSourceRoot sourceRoot) {
final String packagePrefix = sourceRoot.getPackagePrefix();
final String path = sourceRoot.getDirectory().getAbsolutePath();
return packagePrefix.length() > 0 ? path + " (" + packagePrefix + ")" : path;
}
};
mySourcePathsChooser.setElements(sourceRoots, true);
@@ -45,7 +44,7 @@ class ImportSourceRootsDialog extends DialogWrapper {
return panel;
}
public List<Trinity<String, String, Collection<String>>> getMarkedElements() {
public List<JavaModuleSourceRoot> getMarkedElements() {
return mySourcePathsChooser.getMarkedElements();
}
}
-1
View File
@@ -361,7 +361,6 @@
<stacktrace.fold substring="at org.codehaus.groovy.vmplugin.v5.PluginDefaultGroovyMethods." negate="true"/>
<stacktrace.fold substring="at org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport." negate="true"/>
<sourceRootFinder implementation="org.jetbrains.plugins.groovy.GroovySourceRootFinder"/>
<projectStructureDetector implementation="org.jetbrains.plugins.groovy.GroovySourceRootDetector"/>
<generation.topLevelFactory language="Groovy" implementationClass="org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFactoryProvider" />
@@ -1,43 +0,0 @@
/*
* Copyright 2000-2010 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.plugins.groovy;
import com.intellij.ide.util.projectWizard.importSources.JavaSourceRootDetectionUtil;
import com.intellij.ide.util.newProjectWizard.SourceRootFinder;
import com.intellij.openapi.util.Pair;
import java.io.File;
import java.util.List;
/**
* @author Maxim.Medvedev
*/
public class GroovySourceRootFinder implements SourceRootFinder {
@Override
public List<Pair<File, String>> findRoots(File dir) {
return JavaSourceRootDetectionUtil.suggestRoots(dir, GroovyFileType.GROOVY_FILE_TYPE);
}
@Override
public String getDescription() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public String getName() {
return "Groovy";
}
}