Beispiel #1
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (!(obj instanceof TimeSeries)) return false;
   TimeSeries other = (TimeSeries) obj;
   return Util.nullSafeEquals(this.k, other.k) && Util.nullSafeEquals(this.v, other.v);
 }
Beispiel #2
0
    InMemorySourceRepository(@WillClose ZipInputStream in) throws IOException {
      try {
        while (true) {

          ZipEntry e = in.getNextEntry();
          if (e == null) break;
          if (!e.isDirectory()) {
            String name = e.getName();
            long size = e.getSize();

            if (size > Integer.MAX_VALUE)
              throw new IOException(name + " is too big at " + size + " bytes");
            ByteArrayOutputStream out;
            if (size <= 0) out = new ByteArrayOutputStream();
            else out = new ByteArrayOutputStream((int) size);
            GZIPOutputStream gOut = new GZIPOutputStream(out);
            IO.copy(in, gOut);
            gOut.close();
            byte data[] = out.toByteArray();
            contents.put(name, data);
            lastModified.put(name, e.getTime());
          }
          in.closeEntry();
        }
      } finally {
        Util.closeSilently(in);
      }
    }
Beispiel #3
0
  static {
    Class<Version> c = Version.class;
    URL u = c.getResource(c.getSimpleName() + ".class");
    boolean fromFile = "file".equals(u.getProtocol());
    InputStream in = null;
    String release = null;
    String date = null;
    String plugin_release_date = null;
    if (!fromFile) {
      try {
        Properties versionProperties = new Properties();
        in = Version.class.getResourceAsStream("version.properties");
        if (in != null) {
          versionProperties.load(in);
          release = (String) versionProperties.get("release.number");
          date = (String) versionProperties.get("release.date");
          plugin_release_date = (String) versionProperties.get("plugin.release.date");
        }
      } catch (Exception e) {
        assert true; // ignore
      } finally {
        Util.closeSilently(in);
      }
    }
    if (release == null) {
      release = COMPUTED_RELEASE;
    }
    if (date == null) {
      date = COMPUTED_DATE;
    }
    if (plugin_release_date == null) {
      plugin_release_date = COMPUTED_PLUGIN_RELEASE_DATE;
    }

    RELEASE = release;
    DATE = date;
    CORE_PLUGIN_RELEASE_DATE = plugin_release_date;
    Date parsedDate;
    try {
      SimpleDateFormat fmt =
          new SimpleDateFormat(UpdateChecker.PLUGIN_RELEASE_DATE_FMT, Locale.ENGLISH);

      parsedDate = fmt.parse(CORE_PLUGIN_RELEASE_DATE);
    } catch (ParseException e) {
      if (SystemProperties.ASSERTIONS_ENABLED) {
        e.printStackTrace();
      }
      parsedDate = null;
    }
    releaseDate = parsedDate;
  }
  /**
   * @param className
   * @param methodName
   * @param methodSignature
   * @param methodSourceSignature
   * @param isUnsupported
   * @param usesConcurrency TODO
   * @param isStub TODO
   * @param methodCallCount TODO
   * @param accessMethodFor TODO
   * @param isStatic
   */
  MethodInfo(
      @SlashedClassName String className,
      String methodName,
      String methodSignature,
      String methodSourceSignature,
      int accessFlags,
      boolean isUnconditionalThrower,
      boolean isUnsupported,
      boolean usesConcurrency,
      boolean hasBackBranch,
      boolean isStub,
      boolean isIdentity,
      int methodCallCount,
      @CheckForNull String[] exceptions,
      @CheckForNull MethodDescriptor accessMethodFor,
      Map<ClassDescriptor, AnnotationValue> methodAnnotations,
      Map<Integer, Map<ClassDescriptor, AnnotationValue>> methodParameterAnnotations) {
    super(className, methodName, methodSignature, (accessFlags & Constants.ACC_STATIC) != 0);
    this.accessFlags = accessFlags;
    this.exceptions = exceptions;
    if (exceptions != null)
      for (int i = 0; i < exceptions.length; i++)
        exceptions[i] = DescriptorFactory.canonicalizeString(exceptions[i]);
    this.methodSourceSignature = DescriptorFactory.canonicalizeString(methodSourceSignature);
    this.methodAnnotations = Util.immutableMap(methodAnnotations);
    this.methodParameterAnnotations = Util.immutableMap(methodParameterAnnotations);
    if (isUnconditionalThrower) unconditionalThrowers.put(this, null);
    if (isUnsupported) unsupportedMethods.put(this, null);
    if (accessMethodFor != null) MethodInfo.accessMethodFor.put(this, accessMethodFor);
    if (isIdentity) {
      MethodInfo.identifyMethods.put(this, null);
    }

    this.usesConcurrency = usesConcurrency;
    this.hasBackBranch = hasBackBranch;
    this.isStub = isStub;
    this.methodCallCount = methodCallCount;
  }
  private boolean checkAuthorized(URL response) throws IOException {
    HttpURLConnection connection = (HttpURLConnection) response.openConnection();

    int responseCode = connection.getResponseCode();
    if (responseCode == 200) {
      BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
      String status = in.readLine();
      sessionId = Long.parseLong(in.readLine());
      username = in.readLine();
      Util.closeSilently(in);
      if ("OK".equals(status)) {
        LOGGER.info("Authorized session " + sessionId);
        return true;
      }
    }
    connection.disconnect();
    return false;
  }
  /**
   * Get the "complementary" TypeQualifierValues for given exclusive type qualifier.
   *
   * @param tqv a type qualifier (which must be exclusive)
   * @return Collection of complementary exclusive type qualifiers
   */
  public static Collection<TypeQualifierValue> getComplementaryExclusiveTypeQualifierValue(
      TypeQualifierValue tqv) {
    assert tqv.isExclusiveQualifier();

    LinkedList<TypeQualifierValue> result = new LinkedList<TypeQualifierValue>();

    for (TypeQualifierValue t : instance.get().allKnownTypeQualifiers) {
      //
      // Any TypeQualifierValue with the same
      // annotation class but a different value is a complementary
      // type qualifier.
      //
      if (t.typeQualifier.equals(tqv.typeQualifier) && !Util.nullSafeEquals(t.value, tqv.value)) {
        result.add(t);
      }
    }

    return result;
  }
Beispiel #7
0
  SourceRepository makeInMemorySourceRepository(final String url) {
    final BlockingSourceRepository r = new BlockingSourceRepository();
    Util.runInDameonThread(
        new Runnable() {

          public void run() {
            InputStream in = null;
            try {

              URLConnection connection = new URL(url).openConnection();
              in = connection.getInputStream();
              if (getProject().isGuiAvaliable())
                in =
                    getProject()
                        .getGuiCallback()
                        .getProgressMonitorInputStream(
                            in,
                            connection.getContentLength(),
                            "Downloading project source code...");

              if (url.endsWith(".z0p.gz")) in = new GZIPInputStream(in);

              r.setBase(new InMemorySourceRepository(new ZipInputStream(in)));

            } catch (IOException e) {
              if (getProject().isGuiAvaliable()) {
                getProject()
                    .getGuiCallback()
                    .setErrorMessage("Unable to load " + url + "; " + e.getMessage());
              }
              AnalysisContext.logError("Unable to load " + url, e);
              Util.closeSilently(in);
            }
          }
        },
        "Source loading thread");
    return r;
  }
Beispiel #8
0
  SourceRepository makeJarURLConnectionSourceRepository(final String url)
      throws MalformedURLException, IOException {
    final File file = File.createTempFile("jar_cache", null);
    file.deleteOnExit();
    final BlockingSourceRepository r = new BlockingSourceRepository();
    Util.runInDameonThread(
        new Runnable() {

          public void run() {
            InputStream in = null;
            OutputStream out = null;
            try {
              URLConnection connection = new URL(url).openConnection();
              if (getProject().isGuiAvaliable()) {
                int size = connection.getContentLength();
                in =
                    getProject()
                        .getGuiCallback()
                        .getProgressMonitorInputStream(
                            connection.getInputStream(), size, "Loading source via url");
              } else {
                in = connection.getInputStream();
              }
              out = new FileOutputStream(file);
              IO.copy(in, out);
              r.setBase(new ZipSourceRepository(new ZipFile(file)));
            } catch (IOException e) {
              assert true;
            } finally {
              Util.closeSilently(in);
              Util.closeSilently(out);
            }
          }
        },
        "Source loading thread");
    return r;
  }
 @Override
 public boolean equals(Object o) {
   if (!(o instanceof TypeQualifierValue)) return false;
   TypeQualifierValue other = (TypeQualifierValue) o;
   return typeQualifier.equals(other.typeQualifier) && Util.nullSafeEquals(value, other.value);
 }