use of com.intellij.openapi.roots.OrderRootType in project intellij-community by JetBrains.
the class JavaSdkImpl method createMockJdk.
@NotNull
@TestOnly
public Sdk createMockJdk(@NotNull String jdkName, @NotNull String home, boolean isJre) {
String homePath = home.replace(File.separatorChar, '/');
File jdkHomeFile = new File(homePath);
ProjectRootContainerImpl rootContainer = new ProjectRootContainerImpl(true);
SdkModificator sdkModificator = new SdkModificator() {
@Override
public String getName() {
throw new UnsupportedOperationException();
}
@Override
public void setName(String name) {
throw new UnsupportedOperationException();
}
@Override
public String getHomePath() {
throw new UnsupportedOperationException();
}
@Override
public void setHomePath(String path) {
throw new UnsupportedOperationException();
}
@Override
public String getVersionString() {
throw new UnsupportedOperationException();
}
@Override
public void setVersionString(String versionString) {
throw new UnsupportedOperationException();
}
@Override
public SdkAdditionalData getSdkAdditionalData() {
throw new UnsupportedOperationException();
}
@Override
public void setSdkAdditionalData(SdkAdditionalData data) {
throw new UnsupportedOperationException();
}
@Override
public VirtualFile[] getRoots(OrderRootType rootType) {
throw new UnsupportedOperationException();
}
@Override
public void removeRoot(VirtualFile root, OrderRootType rootType) {
throw new UnsupportedOperationException();
}
@Override
public void removeRoots(OrderRootType rootType) {
throw new UnsupportedOperationException();
}
@Override
public void removeAllRoots() {
throw new UnsupportedOperationException();
}
@Override
public void commitChanges() {
throw new UnsupportedOperationException();
}
@Override
public boolean isWritable() {
throw new UnsupportedOperationException();
}
@Override
public void addRoot(VirtualFile root, OrderRootType rootType) {
rootContainer.addRoot(root, rootType);
}
};
rootContainer.startChange();
addClasses(jdkHomeFile, sdkModificator, isJre);
addSources(jdkHomeFile, sdkModificator);
rootContainer.finishChange();
ProjectJdkImpl jdk = new ProjectJdkImpl(jdkName, this, homePath, jdkName) {
@Override
public void setName(@NotNull String name) {
throwReadOnly();
}
@Override
public void readExternal(@NotNull Element element) {
throwReadOnly();
}
@Override
public void readExternal(@NotNull Element element, @Nullable ProjectJdkTable projectJdkTable) {
throwReadOnly();
}
@NotNull
@Override
public SdkModificator getSdkModificator() {
throwReadOnly();
return null;
}
@Override
public void setSdkAdditionalData(SdkAdditionalData data) {
throwReadOnly();
}
@Override
public void addRoot(VirtualFile root, OrderRootType rootType) {
throwReadOnly();
}
@Override
public void removeRoot(VirtualFile root, OrderRootType rootType) {
throwReadOnly();
}
@Override
public void removeRoots(OrderRootType rootType) {
throwReadOnly();
}
@Override
public void removeAllRoots() {
throwReadOnly();
}
@Override
public boolean isWritable() {
return false;
}
@Override
public void update() {
throwReadOnly();
}
@Override
public VirtualFile[] getRoots(OrderRootType rootType) {
return rootContainer.getRootFiles(rootType);
}
@NotNull
@Override
public RootProvider getRootProvider() {
return new RootProvider() {
@NotNull
@Override
public String[] getUrls(@NotNull OrderRootType rootType) {
return ContainerUtil.map2Array(getFiles(rootType), String.class, VirtualFile::getUrl);
}
@NotNull
@Override
public VirtualFile[] getFiles(@NotNull OrderRootType rootType) {
return getRoots(rootType);
}
@Override
public void addRootSetChangedListener(@NotNull RootSetChangedListener listener) {
}
@Override
public void addRootSetChangedListener(@NotNull RootSetChangedListener listener, @NotNull Disposable parentDisposable) {
}
@Override
public void removeRootSetChangedListener(@NotNull RootSetChangedListener listener) {
}
};
}
private void throwReadOnly() {
throw new IncorrectOperationException("Can't modify, MockJDK is read-only, consider calling .clone() first");
}
};
ProjectJdkImpl.copyRoots(rootContainer, jdk);
return jdk;
}
use of com.intellij.openapi.roots.OrderRootType in project intellij-community by JetBrains.
the class JavaSdkImpl method addDocs.
private void addDocs(File jdkHome, SdkModificator sdkModificator, @Nullable Sdk sdk) {
OrderRootType docRootType = JavadocOrderRootType.getInstance();
VirtualFile apiDocs = findDocs(jdkHome, "docs/api");
if (apiDocs != null) {
sdkModificator.addRoot(apiDocs, docRootType);
} else if (SystemInfo.isMac) {
VirtualFile commonDocs = findDocs(jdkHome, "docs");
if (commonDocs == null)
commonDocs = findInJar(new File(jdkHome, "docs.jar"), "doc/api");
if (commonDocs == null)
commonDocs = findInJar(new File(jdkHome, "docs.jar"), "docs/api");
if (commonDocs != null) {
sdkModificator.addRoot(commonDocs, docRootType);
}
VirtualFile appleDocs = findDocs(jdkHome, "appledocs");
if (appleDocs == null)
appleDocs = findInJar(new File(jdkHome, "appledocs.jar"), "appledoc/api");
if (appleDocs != null) {
sdkModificator.addRoot(appleDocs, docRootType);
}
}
if (sdk != null && sdkModificator.getRoots(docRootType).length == 0 && sdkModificator.getRoots(OrderRootType.SOURCES).length == 0) {
// registers external docs when both sources and local docs are missing
String docUrl = getDefaultDocumentationUrl(sdk);
if (docUrl != null) {
VirtualFile onlineDoc = VirtualFileManager.getInstance().findFileByUrl(docUrl);
if (onlineDoc != null) {
sdkModificator.addRoot(onlineDoc, docRootType);
}
}
if (getVersion(sdk) == JavaSdkVersion.JDK_1_7) {
VirtualFile fxDocUrl = VirtualFileManager.getInstance().findFileByUrl("http://docs.oracle.com/javafx/2/api/");
if (fxDocUrl != null) {
sdkModificator.addRoot(fxDocUrl, docRootType);
}
}
}
}
use of com.intellij.openapi.roots.OrderRootType in project intellij-community by JetBrains.
the class JavaSdkImpl method attachJdkAnnotations.
public static void attachJdkAnnotations(@NotNull SdkModificator modificator) {
LocalFileSystem lfs = LocalFileSystem.getInstance();
List<String> pathsChecked = new ArrayList<>();
// community idea under idea
String path = FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/java/jdkAnnotations";
VirtualFile root = lfs.findFileByPath(path);
pathsChecked.add(path);
if (root == null) {
// idea under idea
path = FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/community/java/jdkAnnotations";
root = lfs.findFileByPath(path);
pathsChecked.add(path);
}
if (root == null) {
// build
String url = "jar://" + FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/lib/jdkAnnotations.jar!/";
root = VirtualFileManager.getInstance().findFileByUrl(url);
pathsChecked.add(FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/lib/jdkAnnotations.jar");
}
if (root == null) {
String msg = "Paths checked:\n";
for (String p : pathsChecked) {
File file = new File(p);
msg += "Path: '" + p + "' " + (file.exists() ? "Found" : "Not found") + "; directory children: " + Arrays.toString(file.getParentFile().listFiles()) + "\n";
}
LOG.error("JDK annotations not found", msg);
return;
}
OrderRootType annoType = AnnotationOrderRootType.getInstance();
modificator.removeRoot(root, annoType);
modificator.addRoot(root, annoType);
}
use of com.intellij.openapi.roots.OrderRootType in project intellij-community by JetBrains.
the class SdkEditor method doSetHomePath.
private void doSetHomePath(final String homePath, final SdkType sdkType) {
if (homePath == null) {
return;
}
setHomePathValue(homePath.replace('/', File.separatorChar));
final String newSdkName = suggestSdkName(homePath);
((ProjectJdkImpl) mySdk).setName(newSdkName);
try {
final Sdk dummySdk = (Sdk) mySdk.clone();
SdkModificator sdkModificator = dummySdk.getSdkModificator();
sdkModificator.setHomePath(homePath);
sdkModificator.removeAllRoots();
sdkModificator.commitChanges();
sdkType.setupSdkPaths(dummySdk, mySdkModel);
clearAllPaths();
myVersionString = dummySdk.getVersionString();
if (myVersionString == null) {
Messages.showMessageDialog(ProjectBundle.message("sdk.java.corrupt.error", homePath), ProjectBundle.message("sdk.java.corrupt.title"), Messages.getErrorIcon());
}
sdkModificator = dummySdk.getSdkModificator();
for (OrderRootType type : myPathEditors.keySet()) {
SdkPathEditor pathEditor = myPathEditors.get(type);
pathEditor.setAddBaseDir(dummySdk.getHomeDirectory());
pathEditor.addPaths(sdkModificator.getRoots(type));
}
mySdkModel.getMulticaster().sdkHomeSelected(dummySdk, homePath);
} catch (CloneNotSupportedException e) {
// should not happen in normal program
LOG.error(e);
}
}
use of com.intellij.openapi.roots.OrderRootType in project intellij-community by JetBrains.
the class ProjectJdkImpl method copyRoots.
static void copyRoots(@NotNull ProjectRootContainerImpl rootContainer, @NotNull ProjectJdkImpl dest) {
dest.myRootContainer.startChange();
dest.myRootContainer.removeAllRoots();
for (OrderRootType rootType : OrderRootType.getAllTypes()) {
final ProjectRoot[] newRoots = rootContainer.getRoots(rootType);
for (ProjectRoot newRoot : newRoots) {
dest.myRootContainer.addRoot(newRoot, rootType);
}
}
dest.myRootContainer.finishChange();
}
Aggregations