use of com.intellij.openapi.projectRoots.JavaSdk in project intellij-community by JetBrains.
the class JavaProjectDataService method importData.
@Override
public void importData(@NotNull final Collection<DataNode<JavaProjectData>> toImport, @Nullable final ProjectData projectData, @NotNull final Project project, @NotNull final IdeModifiableModelsProvider modelsProvider) {
if (toImport.isEmpty() || projectData == null) {
return;
}
if (toImport.size() != 1) {
throw new IllegalArgumentException(String.format("Expected to get a single project but got %d: %s", toImport.size(), toImport));
}
final DataNode<JavaProjectData> javaProjectDataNode = toImport.iterator().next();
final DataNode<ProjectData> projectDataNode = ExternalSystemApiUtil.findParent(javaProjectDataNode, ProjectKeys.PROJECT);
assert projectDataNode != null;
if (!ExternalSystemApiUtil.isOneToOneMapping(project, projectDataNode.getData())) {
return;
}
JavaProjectData javaProjectData = javaProjectDataNode.getData();
// JDK.
JavaSdkVersion version = javaProjectData.getJdkVersion();
JavaSdk javaSdk = JavaSdk.getInstance();
ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
Sdk sdk = rootManager.getProjectSdk();
if (sdk != null) {
JavaSdkVersion currentVersion = javaSdk.getVersion(sdk);
if (currentVersion == null || !currentVersion.isAtLeast(version)) {
updateSdk(project, version);
}
} else {
updateSdk(project, version);
}
// Language level.
setLanguageLevel(javaProjectData.getLanguageLevel(), project);
}
use of com.intellij.openapi.projectRoots.JavaSdk in project android by JetBrains.
the class AndroidTreeStructureProvider method modify.
@Override
@NotNull
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
Project project = parent.getProject();
if (project != null && AndroidProjectInfo.getInstance(project).requiresAndroidModel()) {
if (parent instanceof NamedLibraryElementNode) {
NamedLibraryElement value = ((NamedLibraryElementNode) parent).getValue();
LibraryOrSdkOrderEntry orderEntry = value.getOrderEntry();
if (orderEntry instanceof JdkOrderEntry) {
Sdk sdk = ((JdkOrderEntry) orderEntry).getJdk();
if (sdk.getSdkType() instanceof JavaSdk) {
List<AbstractTreeNode> newChildren = Lists.newArrayList();
for (AbstractTreeNode child : children) {
if (isRtJar(child)) {
newChildren.add(child);
}
}
if (!newChildren.isEmpty()) {
myEventDispatcher.getMulticaster().nodeChanged(parent, newChildren);
return newChildren;
}
}
}
} else if (isRtJar(parent)) {
List<AbstractTreeNode> newChildren = Lists.newArrayList();
for (AbstractTreeNode child : children) {
if (child instanceof PsiDirectoryNode) {
VirtualFile file = ((PsiDirectoryNode) child).getVirtualFile();
if (file != null && ("java".equals(file.getName()) || "javax".equals(file.getName()))) {
newChildren.add(child);
}
}
}
if (!newChildren.isEmpty()) {
myEventDispatcher.getMulticaster().nodeChanged(parent, newChildren);
return newChildren;
}
}
}
return children;
}
use of com.intellij.openapi.projectRoots.JavaSdk in project android by JetBrains.
the class RenderErrorContributor method isBuiltByJdk7OrHigher.
static boolean isBuiltByJdk7OrHigher(@NotNull Module module) {
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
if (sdk == null) {
return false;
}
AndroidSdks androidSdks = AndroidSdks.getInstance();
if (androidSdks.isAndroidSdk(sdk)) {
AndroidSdkAdditionalData data = androidSdks.getAndroidSdkAdditionalData(sdk);
if (data != null) {
Sdk jdk = data.getJavaSdk();
if (jdk != null) {
sdk = jdk;
}
}
}
return sdk.getSdkType() instanceof JavaSdk && JavaSdk.getInstance().isOfVersionOrHigher(sdk, JavaSdkVersion.JDK_1_7);
}
use of com.intellij.openapi.projectRoots.JavaSdk in project android by JetBrains.
the class NewModuleWizardTest method collectAllowedRoots.
@Override
protected void collectAllowedRoots(final List<String> roots) throws IOException {
JavaSdk javaSdk = JavaSdk.getInstance();
final List<String> jdkPaths = Lists.newArrayList(javaSdk.suggestHomePaths());
jdkPaths.add(SystemProperties.getJavaHome());
roots.addAll(jdkPaths);
for (final String jdkPath : jdkPaths) {
FileUtil.processFilesRecursively(new File(jdkPath), file -> {
try {
String path = file.getCanonicalPath();
if (!FileUtil.isAncestor(jdkPath, path, false)) {
roots.add(path);
}
} catch (IOException ignore) {
}
return true;
});
}
}
Aggregations