Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ object DartWebdev {
activated = true
return true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.*;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import com.jetbrains.lang.dart.sdk.DartSdk;
import com.jetbrains.lang.dart.util.PubspecYamlUtil;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.builtInWebServer.ConsoleManager;

import java.util.Collection;
import java.util.Map;

@Service(Service.Level.PROJECT)
public final class PubServerManager implements Disposable {
private static final Logger LOG = PluginLogger.INSTANCE.createLogger(PubServerManager.class);
Expand Down Expand Up @@ -130,39 +124,4 @@ public void stopAllPubServerProcesses() {
}
}
}

public @NotNull Collection<String> getAllAlivePubServerAuthorities() {
final Collection<String> result = new SmartList<>();
for (PubServerService service : myServedDirToPubService.asMap().values()) {
result.addAll(service.getAllPubServeAuthorities());
}
return result;
}

public @NotNull Collection<String> getAlivePubServerAuthoritiesForDartRoot(final @NotNull VirtualFile dartProjectRoot) {
final Collection<String> result = new SmartList<>();
for (VirtualFile subdir : dartProjectRoot.getChildren()) {
if (!subdir.isDirectory()) continue;
final PubServerService service = myServedDirToPubService.getIfPresent(subdir);
if (service == null) continue;
ContainerUtil.addIfNotNull(result, service.getPubServeAuthority(subdir));
}
return result;
}

public @Nullable VirtualFile getDartRootByAuthority(final @NotNull String authority) {
for (Map.Entry<VirtualFile, PubServerService> entry : myServedDirToPubService.asMap().entrySet()) {
if (entry.getValue().getAllPubServeAuthorities().contains(authority)) {
return entry.getKey();
}
}
return null;
}

public @Nullable String getPubServerAuthorityForServedDir(final @NotNull VirtualFile servedDir) {
LOG.assertTrue(servedDir.isDirectory() && servedDir.getParent().findChild(PubspecYamlUtil.PUBSPEC_YAML) != null,
"Bad argument: " + servedDir.getPath());
final PubServerService service = myServedDirToPubService.getIfPresent(servedDir);
return service != null ? service.getPubServeAuthority(servedDir) : null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.util.Consumer;
import com.intellij.util.SmartList;
import com.intellij.util.net.NetKt;
import com.jetbrains.lang.dart.DartBundle;
import com.jetbrains.lang.dart.ide.actions.DartPubActionBase;
Expand Down Expand Up @@ -98,7 +97,7 @@ private ClientInfo(@NotNull Channel channel, @NotNull HttpHeaders extraHeaders)
PubServerService(@NotNull Project project, @NotNull ConsoleManager consoleManager) {
super(project, consoleManager);

BuiltInServerManager.getInstance().createClientBootstrap().handler(new ChannelInitializer() {
BuiltInServerManager.getInstance().createClientBootstrap().handler(new ChannelInitializer<>() {
@Override
protected void initChannel(Channel channel) {
channel.pipeline().addLast(serverChannelRegistrar, new HttpClientCodec());
Expand Down Expand Up @@ -288,25 +287,6 @@ void sendToServer(final @NotNull VirtualFile servedDir,
Responses.send(response, clientChannel, clientRequest, extraHeaders);
}

@NotNull
Collection<String> getAllPubServeAuthorities() {
final Collection<String> result = new SmartList<>();
for (ServerInfo serverInfo : servedDirToSocketAddress.values()) {
if (serverInfo.address != null) {
result.add(serverInfo.address.getHostString() + ":" + serverInfo.address.getPort());
}
}
return result;
}


@Nullable
String getPubServeAuthority(final @NotNull VirtualFile dir) {
final ServerInfo serverInfo = servedDirToSocketAddress.get(dir);
final InetSocketAddress address = serverInfo == null ? null : serverInfo.address;
return address != null ? address.getHostString() + ":" + address.getPort() : null;
}

@ChannelHandler.Sharable
private class PubServeChannelHandler extends SimpleChannelInboundHandlerAdapter<HttpObject> {
PubServeChannelHandler() {
Expand Down
Loading