use of com.intellij.openapi.roots.RootProvider 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.RootProvider in project intellij-plugins by JetBrains.
the class FlexCompositeSdk method getRootProvider.
@NotNull
public RootProvider getRootProvider() {
return new RootProvider() {
@NotNull
public String[] getUrls(@NotNull final OrderRootType rootType) {
final Collection<String> result = new HashSet<>();
forAllSdks(sdk -> {
result.addAll(Arrays.asList(sdk.getRootProvider().getUrls(rootType)));
return true;
});
return ArrayUtil.toStringArray(result);
}
@NotNull
public VirtualFile[] getFiles(@NotNull final OrderRootType rootType) {
final Collection<VirtualFile> result = new HashSet<>();
forAllSdks(sdk -> {
result.addAll(Arrays.asList(sdk.getRootProvider().getFiles(rootType)));
return true;
});
return result.toArray(new VirtualFile[result.size()]);
}
public void addRootSetChangedListener(@NotNull final RootSetChangedListener listener) {
forAllSdks(sdk -> {
final RootProvider rootProvider = sdk.getRootProvider();
rootProvider.removeRootSetChangedListener(listener);
rootProvider.addRootSetChangedListener(listener);
return true;
});
}
public void addRootSetChangedListener(@NotNull final RootSetChangedListener listener, @NotNull final Disposable parentDisposable) {
forAllSdks(sdk -> {
sdk.getRootProvider().addRootSetChangedListener(listener, parentDisposable);
return true;
});
}
public void removeRootSetChangedListener(@NotNull final RootSetChangedListener listener) {
forAllSdks(sdk -> {
sdk.getRootProvider().removeRootSetChangedListener(listener);
return true;
});
}
};
}
Aggregations