com.intellij.util.Urls Java Examples

The following examples show how to use com.intellij.util.Urls. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpRequestUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean parseAndCheckIsLocalHost(String uri, boolean onlyAnyOrLoopback, boolean hostsOnly) {
  if (uri == null || uri.equals("about:blank")) {
    return true;
  }

  try {
    Url parsedUri = Urls.parse(uri, false);
    if (parsedUri == null) {
      return false;
    }

    String host = getHost(parsedUri);

    return host != null && (isTrustedChromeExtension(parsedUri) || isLocalHost(host, onlyAnyOrLoopback, hostsOnly));
  }
  catch (Exception ignored) {
  }
  return false;
}
 
Example #2
Source File: QuarkusModelRegistry.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
public static void zip(String endpoint, String tool, String groupId, String artifactId, String version,
                       String className, String path, QuarkusModel model, File output) throws IOException {
    Url url = Urls.newFromEncoded(endpoint + "/api/download");
    Map<String, String> parameters = new HashMap<>();
    parameters.put(CODE_TOOL_PARAMETER_NAME, tool);
    parameters.put(CODE_GROUP_ID_PARAMETER_NAME, groupId);
    parameters.put(CODE_ARTIFACT_ID_PARAMETER_NAME, artifactId);
    parameters.put(CODE_VERSION_PARAMETER_NAME, version);
    parameters.put(CODE_CLASSNAME_PARAMETER_NAME, className);
    parameters.put(CODE_PATH_PARAMETER_NAME, path);
    parameters.put(CODE_EXTENSIONS_SHORT_PARAMETER_NAME, model.getCategories().stream().flatMap(category -> category.getExtensions().stream()).
            filter(extension -> extension.isSelected() || extension.isDefaultExtension()).
            map(extension -> extension.getShortId()).
            collect(Collectors.joining(".")));
    url = url.addParameters(parameters);
    RequestBuilder builder = HttpRequests.request(url.toString()).userAgent(QuarkusModelRegistry.USER_AGENT).tuner(connection -> {
        connection.setRequestProperty(CODE_QUARKUS_IO_CLIENT_NAME_HEADER_NAME, CODE_QUARKUS_IO_CLIENT_NAME_HEADER_VALUE);
        connection.setRequestProperty(CODE_QUARKUS_IO_CLIENT_CONTACT_EMAIL_HEADER_NAME, CODE_QUARKUS_IO_CLIENT_CONTACT_EMAIL_HEADER_VALUE);
    });
    try {
        if (ApplicationManager.getApplication().executeOnPooledThread(() -> builder.connect(request -> {
            ZipUtil.unpack(request.getInputStream(), output, name -> {
                int index = name.indexOf('/');
                return name.substring(index);
            });
            return true;
        })).get() == null) {
            throw new IOException();
        }
} catch (InterruptedException | ExecutionException e) {
        throw new IOException(e);
    }
}
 
Example #3
Source File: FlutterSdkUtil.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@VisibleForTesting
public static String parseFlutterSdkPath(String packagesFileContent) {
  for (String line : packagesFileContent.split("\n")) {
    // flutter:file:///Users/.../flutter/packages/flutter/lib/
    line = line.trim();

    if (line.isEmpty() || line.startsWith("#")) {
      continue;
    }

    final String flutterPrefix = "flutter:";
    if (line.startsWith(flutterPrefix)) {
      final String urlString = line.substring(flutterPrefix.length());

      if (urlString.startsWith("file:")) {
        final Url url = Urls.parseEncoded(urlString);
        if (url == null) {
          continue;
        }
        final String path = url.getPath();
        // go up three levels
        final File file = new File(url.getPath());
        return file.getParentFile().getParentFile().getParentFile().getPath();
      }
    }
  }

  return null;
}
 
Example #4
Source File: FlutterSdkUtil.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@VisibleForTesting
public static String parseFlutterSdkPath(String packagesFileContent) {
  for (String line : packagesFileContent.split("\n")) {
    // flutter:file:///Users/.../flutter/packages/flutter/lib/
    line = line.trim();

    if (line.isEmpty() || line.startsWith("#")) {
      continue;
    }

    final String flutterPrefix = "flutter:";
    if (line.startsWith(flutterPrefix)) {
      final String urlString = line.substring(flutterPrefix.length());

      if (urlString.startsWith("file:")) {
        final Url url = Urls.parseEncoded(urlString);
        if (url == null) {
          continue;
        }
        final String path = url.getPath();
        // go up three levels
        final File file = new File(url.getPath());
        return file.getParentFile().getParentFile().getParentFile().getPath();
      }
    }
  }

  return null;
}