use of com.intellij.openapi.roots.OrderRootType in project intellij-community by JetBrains.
the class LibraryImpl method readRoots.
private void readRoots(Element element) throws InvalidDataException {
for (OrderRootType rootType : getAllRootTypes()) {
final Element rootChild = element.getChild(rootType.name());
if (rootChild == null) {
continue;
}
VirtualFilePointerContainer roots = myRoots.get(rootType);
roots.readExternal(rootChild, ROOT_PATH_ELEMENT);
}
Element excludedRoot = element.getChild(EXCLUDED_ROOTS_TAG);
if (excludedRoot != null) {
getOrCreateExcludedRoots().readExternal(excludedRoot, ROOT_PATH_ELEMENT);
}
}
use of com.intellij.openapi.roots.OrderRootType in project intellij-community by JetBrains.
the class JarDirectoryWatcherImpl method updateWatchedRoots.
@Override
public void updateWatchedRoots() {
final LocalFileSystem fs = LocalFileSystem.getInstance();
if (!myJarDirectories.isEmpty()) {
final Set<String> recursiveRoots = new HashSet<>();
final Set<String> flatRoots = new HashSet<>();
final VirtualFileManager fm = VirtualFileManager.getInstance();
for (OrderRootType rootType : myJarDirectories.getRootTypes()) {
for (String url : myJarDirectories.getDirectories(rootType)) {
if (fm.getFileSystem(VirtualFileManager.extractProtocol(url)) instanceof LocalFileSystem) {
final boolean watchRecursively = myJarDirectories.isRecursive(rootType, url);
final String path = VirtualFileManager.extractPath(url);
(watchRecursively ? recursiveRoots : flatRoots).add(path);
}
}
}
myWatchRequests = fs.replaceWatchedRoots(myWatchRequests, recursiveRoots, flatRoots);
if (myBusConnection == null) {
myBusConnection = ApplicationManager.getApplication().getMessageBus().connect();
myBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
@Override
public void after(@NotNull final List<? extends VFileEvent> events) {
boolean changesDetected = false;
for (VFileEvent event : events) {
if (event instanceof VFileCopyEvent) {
final VFileCopyEvent copyEvent = (VFileCopyEvent) event;
final VirtualFile file = copyEvent.getFile();
if (isUnderJarDirectory(copyEvent.getNewParent() + "/" + copyEvent.getNewChildName()) || file != null && isUnderJarDirectory(file.getUrl())) {
changesDetected = true;
break;
}
} else if (event instanceof VFileMoveEvent) {
final VFileMoveEvent moveEvent = (VFileMoveEvent) event;
final VirtualFile file = moveEvent.getFile();
if (file != null && (isUnderJarDirectory(file.getUrl()) || isUnderJarDirectory(moveEvent.getOldParent().getUrl() + "/" + file.getName()))) {
changesDetected = true;
break;
}
} else if (event instanceof VFileDeleteEvent) {
final VFileDeleteEvent deleteEvent = (VFileDeleteEvent) event;
if (isUnderJarDirectory(deleteEvent.getFile().getUrl())) {
changesDetected = true;
break;
}
} else if (event instanceof VFileCreateEvent) {
final VFileCreateEvent createEvent = (VFileCreateEvent) event;
if (isUnderJarDirectory(createEvent.getParent().getUrl() + "/" + createEvent.getChildName())) {
changesDetected = true;
break;
}
}
}
if (changesDetected) {
fireRootSetChanged();
}
}
private boolean isUnderJarDirectory(String url) {
for (String rootUrl : myJarDirectories.getAllDirectories()) {
if (FileUtil.startsWith(url, rootUrl)) {
return true;
}
}
return false;
}
});
}
} else {
cleanup();
}
}
use of com.intellij.openapi.roots.OrderRootType in project intellij-community by JetBrains.
the class RootDetectionUtil method detectRoots.
@NotNull
public static List<OrderRoot> detectRoots(@NotNull final Collection<VirtualFile> rootCandidates, @Nullable Component parentComponent, @Nullable Project project, @NotNull final LibraryRootsDetector detector, @NotNull OrderRootType[] rootTypesAllowedToBeSelectedByUserIfNothingIsDetected) {
final List<OrderRoot> result = new ArrayList<>();
final List<SuggestedChildRootInfo> suggestedRoots = new ArrayList<>();
new Task.Modal(project, "Scanning for Roots", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
for (VirtualFile rootCandidate : rootCandidates) {
final Collection<DetectedLibraryRoot> roots = detector.detectRoots(rootCandidate, indicator);
if (!roots.isEmpty() && allRootsHaveOneTypeAndEqualToOrAreDirectParentOf(roots, rootCandidate)) {
for (DetectedLibraryRoot root : roots) {
final LibraryRootType libraryRootType = root.getTypes().get(0);
result.add(new OrderRoot(root.getFile(), libraryRootType.getType(), libraryRootType.isJarDirectory()));
}
} else {
for (DetectedLibraryRoot root : roots) {
final HashMap<LibraryRootType, String> names = new HashMap<>();
for (LibraryRootType type : root.getTypes()) {
final String typeName = detector.getRootTypeName(type);
LOG.assertTrue(typeName != null, "Unexpected root type " + type.getType().name() + (type.isJarDirectory() ? " (JAR directory)" : "") + ", detectors: " + detector);
names.put(type, typeName);
}
suggestedRoots.add(new SuggestedChildRootInfo(rootCandidate, root, names));
}
}
}
} catch (ProcessCanceledException ignored) {
}
}
}.queue();
if (!suggestedRoots.isEmpty()) {
final DetectedRootsChooserDialog dialog = parentComponent != null ? new DetectedRootsChooserDialog(parentComponent, suggestedRoots) : new DetectedRootsChooserDialog(project, suggestedRoots);
if (!dialog.showAndGet()) {
return Collections.emptyList();
}
for (SuggestedChildRootInfo rootInfo : dialog.getChosenRoots()) {
final LibraryRootType selectedRootType = rootInfo.getSelectedRootType();
result.add(new OrderRoot(rootInfo.getDetectedRoot().getFile(), selectedRootType.getType(), selectedRootType.isJarDirectory()));
}
}
if (result.isEmpty() && rootTypesAllowedToBeSelectedByUserIfNothingIsDetected.length > 0) {
Map<String, Pair<OrderRootType, Boolean>> types = new HashMap<>();
for (OrderRootType type : rootTypesAllowedToBeSelectedByUserIfNothingIsDetected) {
for (boolean isJarDirectory : new boolean[] { false, true }) {
final String typeName = detector.getRootTypeName(new LibraryRootType(type, isJarDirectory));
if (typeName != null) {
types.put(StringUtil.capitalizeWords(typeName, true), Pair.create(type, isJarDirectory));
}
}
}
LOG.assertTrue(!types.isEmpty(), "No allowed root types found for " + detector);
List<String> names = new ArrayList<>(types.keySet());
if (names.size() == 1) {
String title = "Attach Roots";
String typeName = names.get(0);
String message = ApplicationNamesInfo.getInstance().getProductName() + " cannot determine what kind of files the chosen items contain. " + "Do you want to attach them as '" + typeName + "'?";
int answer = parentComponent != null ? Messages.showYesNoDialog(parentComponent, message, title, null) : Messages.showYesNoDialog(project, message, title, null);
if (answer == Messages.YES) {
Pair<OrderRootType, Boolean> pair = types.get(typeName);
for (VirtualFile candidate : rootCandidates) {
result.add(new OrderRoot(candidate, pair.getFirst(), pair.getSecond()));
}
}
} else {
String title = "Choose Categories of Selected Files";
String description = XmlStringUtil.wrapInHtml(ApplicationNamesInfo.getInstance().getProductName() + " cannot determine what kind of files the chosen items contain.<br>" + "Choose the appropriate categories from the list.");
ChooseElementsDialog<String> dialog;
if (parentComponent != null) {
dialog = new ChooseRootTypeElementsDialog(parentComponent, names, title, description);
} else {
dialog = new ChooseRootTypeElementsDialog(project, names, title, description);
}
for (String rootType : dialog.showAndGetResult()) {
final Pair<OrderRootType, Boolean> pair = types.get(rootType);
for (VirtualFile candidate : rootCandidates) {
result.add(new OrderRoot(candidate, pair.getFirst(), pair.getSecond()));
}
}
}
}
return result;
}
use of com.intellij.openapi.roots.OrderRootType in project intellij-community by JetBrains.
the class RepositoryAttachHandler method createRoots.
public static List<OrderRoot> createRoots(@NotNull Collection<MavenArtifact> artifacts, @Nullable String copyTo) {
final List<OrderRoot> result = new ArrayList<>();
final VirtualFileManager manager = VirtualFileManager.getInstance();
for (MavenArtifact each : artifacts) {
try {
File repoFile = each.getFile();
File toFile = repoFile;
if (copyTo != null) {
toFile = new File(copyTo, repoFile.getName());
if (repoFile.exists()) {
FileUtil.copy(repoFile, toFile);
}
}
// search for jar file first otherwise lib root won't be found!
manager.refreshAndFindFileByUrl(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(toFile.getPath())));
final String url = VfsUtil.getUrlForLibraryRoot(toFile);
final VirtualFile file = manager.refreshAndFindFileByUrl(url);
if (file != null) {
OrderRootType rootType;
if (MavenExtraArtifactType.DOCS.getDefaultClassifier().equals(each.getClassifier())) {
rootType = JavadocOrderRootType.getInstance();
} else if (MavenExtraArtifactType.SOURCES.getDefaultClassifier().equals(each.getClassifier())) {
rootType = OrderRootType.SOURCES;
} else {
rootType = OrderRootType.CLASSES;
}
result.add(new OrderRoot(file, rootType));
}
} catch (IOException e) {
MavenLog.LOG.warn(e);
}
}
return result;
}
use of com.intellij.openapi.roots.OrderRootType in project android by JetBrains.
the class AndroidModuleConverter1 method process.
@Override
public void process(ModuleSettings moduleSettings) throws CannotConvertException {
Element confElement = AndroidConversionUtil.findAndroidFacetConfigurationElement(moduleSettings);
assert confElement != null;
Element platformNameElement = AndroidConversionUtil.getOptionElement(confElement, PLATFORM_NAME_ATTRIBUTE);
String platformName = platformNameElement != null ? platformNameElement.getAttributeValue(AndroidConversionUtil.OPTION_VALUE_ATTRIBUTE) : null;
if (platformName == null)
return;
removeOldDependencies(moduleSettings, platformName);
confElement.removeContent(platformNameElement);
Library androidLibrary = LibraryTablesRegistrar.getInstance().getLibraryTable().getLibraryByName(platformName);
if (androidLibrary != null) {
AndroidPlatform androidPlatform = AndroidPlatform.parse(androidLibrary, null, null);
if (androidPlatform != null) {
IAndroidTarget target = androidPlatform.getTarget();
Sdk androidSdk = AndroidSdkUtils.findAppropriateAndroidPlatform(target, androidPlatform.getSdkData(), false);
if (androidSdk == null) {
androidSdk = AndroidSdks.getInstance().create(target, androidPlatform.getSdkData().getLocation(), false);
if (androidSdk != null) {
final SdkModificator modificator = androidSdk.getSdkModificator();
for (OrderRootType type : OrderRootType.getAllTypes()) {
for (VirtualFile root : androidLibrary.getFiles(type)) {
modificator.addRoot(root, type);
}
}
modificator.commitChanges();
}
}
if (androidSdk != null) {
addNewDependency(moduleSettings, androidSdk.getName());
}
}
}
}
Aggregations