text:
/*
 * $Id$
 */

/*

Copyright (c) 2000-2016 Board of Trustees of Leland Stanford Jr. University,
all rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
STANFORD UNIVERSITY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of Stanford University shall not
be used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from Stanford University.

*/

package org.lockss.plugin.peerj;

import java.net.URL;
import java.util.Properties;
import junit.framework.Test;

import org.lockss.config.Configuration;
import org.lockss.daemon.ConfigParamDescr;
import org.lockss.daemon.RangeCachedUrlSetSpec;
import org.lockss.plugin.ArchivalUnit;
import org.lockss.plugin.CachedUrlSet;
import org.lockss.plugin.PluginManager;
import org.lockss.plugin.base.BaseCachedUrlSet;
import org.lockss.plugin.definable.DefinableArchivalUnit;
import org.lockss.plugin.definable.DefinablePlugin;
import org.lockss.state.AuState;
import org.lockss.test.ConfigurationUtil;
import org.lockss.test.LockssTestCase;
import org.lockss.test.MockAuState;
import org.lockss.test.MockLockssDaemon;
import org.lockss.util.ListUtil;
import org.lockss.util.Logger;
import org.lockss.util.TimeBase;

/*
 * Tests archival unit for PeerJ Archival site
 */
public class TestPeerJArchivalUnit extends LockssTestCase {

  String variantPluginId;
  String variantPluginName;
  DefinableArchivalUnit variantPeerjAu;
  String variantPeerjSite;
  String variantBaseConstant;
  String tempDirPath;
  MockLockssDaemon daemon;
  PluginManager pluginMgr;

  private static final Logger log = Logger.getLogger(TestPeerJArchivalUnit.class);

  private static final String BASE_URL_KEY = ConfigParamDescr.BASE_URL.getKey();
  private static final String VOL_KEY = ConfigParamDescr.VOLUME_NAME.getKey();
  private static final String BASE_URL = "http://www.example.com/";
  private static final String VOLUME_NAME = "2013";

  public DefinableArchivalUnit createAu(URL url, String volume,
      String pluginId) throws Exception {
    Properties props = new Properties();
    props.setProperty(VOL_KEY, volume);
    if (url != null) {
      props.setProperty(BASE_URL_KEY, url.toString());
    }
    Configuration config = ConfigurationUtil.fromProps(props);
    DefinablePlugin peerjDefinablePlugin = new DefinablePlugin();
    peerjDefinablePlugin.initPlugin(getMockLockssDaemon(), pluginId);
    DefinableArchivalUnit au =
        (DefinableArchivalUnit)peerjDefinablePlugin.createAu(config);
    return au;
  }

  // Test the crawl rules for PeerJ Archives (main) site
  public void testShouldCacheProperPages(DefinableArchivalUnit au,
      String peerjSite, String baseConstant) throws Exception {
    daemon.getLockssRepository(au);
    daemon.getNodeManager(au);
    BaseCachedUrlSet cus = new BaseCachedUrlSet(au,
        new RangeCachedUrlSetSpec(BASE_URL));
    // permission page
    shouldCacheTest(BASE_URL + "lockss.txt", true, au, cus);
    // volume page - https://peerj.com/archives/?year=2013
    // volume page - https://peerj.com/archives-preprints/?year=2013
    shouldCacheTest(BASE_URL + peerjSite + "/?year=2013", true, au, cus);
    // issue toc - https://peerj.com/articles/index.html?month=2013-09
    shouldCacheTest(BASE_URL + baseConstant + "/index.html?month=2013-09",
                    true, au, cus);
    // article from Archives (main) site - https://peerj.com/articles/55/
    //   other files: .bib, .pdf, .ris, .xml, .rdf, .json, .unixref, /reviews
    // article from Preprints site - https://peerj.com/preprints/55/
    //   other files: .bib, .pdf, .ris, .xml, .rdf, .json
    shouldCacheTest(BASE_URL + baseConstant + "/55/", true, au, cus);
    shouldCacheTest(BASE_URL + baseConstant + "/55.bib", true, au, cus);
    shouldCacheTest(BASE_URL + baseConstant + "/55.pdf", true, au, cus);
    shouldCacheTest(BASE_URL + baseConstant + "/55.ris", true, au, cus);
    shouldCacheTest(BASE_URL + baseConstant + "/55.xml", true, au, cus);
    shouldCacheTest(BASE_URL + baseConstant + "/55.html", true, au, cus);
    shouldCacheTest(BASE_URL + baseConstant + "/55.rdf", true, au, cus);
    shouldCacheTest(BASE_URL + baseConstant + "/55.json", true, au, cus);
    // not exists on Preprints site
    if (baseConstant == "archives") {
      shouldCacheTest(BASE_URL + baseConstant + "/55.unixref", true, au, cus);
      shouldCacheTest(BASE_URL + baseConstant + "/55/reviews/", true, au, cus);
    }
    // images figures and tables can live here
    // https://dfzljdn9uc3pi.cloudfront.net/2013/55/1/fig-1-2x.jpg
    // https://dfzljdn9uc3pi.cloudfront.net/2013/55/1/fig-1-full.png
    // https://d3amtssd1tejdt.cloudfront.net/2013/21/1/figure1.png
    // https://d2pdyyx74uypu5.cloudfront.net/2013/22/2/figure2.jpg
    shouldCacheTest("https://dfzljdn9uc3pi.cloudfront.net"
    		    + "/2013/55/1/fig-1-2x.jpg", true, au, cus);
    shouldCacheTest("https://dfzljdn9uc3pi.cloudfront.net"
                    + "/2013/55/1/fig-1-full.png", true, au, cus);
    shouldCacheTest("https://d3amtssd1tejdt.cloudfront.net"
                    + "/2013/21/1/figure1.png", true, au, cus);
    shouldCacheTest("https://d2pdyyx74uypu5.cloudfront.net"
                   + "/2013/22/2/figure2.jpg", true, au, cus);
    // missing peerj site string - should not get crawled
    shouldCacheTest(BASE_URL + "?year=2012", false, au, cus);
    // LOCKSS
    shouldCacheTest("http://lockss.stanford.edu", false, au, cus);
  }

  private void shouldCacheTest(String url, boolean shouldCache,
      ArchivalUnit au, CachedUrlSet cus) {
    //log.info ("shouldCacheTest url: " + url);
    assertEquals(shouldCache, au.shouldBeCached(url));
  }

  public void testStartUrlConstruction(DefinableArchivalUnit au,
      String peerjSite) throws Exception {
    String expected = BASE_URL + peerjSite + "/?year=2013";
    assertEquals(ListUtil.list(expected), au.getStartUrls());
  }

  public void testShouldNotCachePageFromOtherSite(DefinableArchivalUnit au,
      String peerjSite) throws Exception {
    daemon.getLockssRepository(au);
    daemon.getNodeManager(au);
    assertFalse(au.shouldBeCached("http://shadow2.stanford.edu/" +
        peerjSite + "/?year=2013"));
  }

  public void testShouldDoNewContentCrawlTooEarly(DefinableArchivalUnit au)
      throws Exception {
    AuState aus = new MockAuState(null, TimeBase.nowMs(), -1, -1, null);
    assertFalse(au.shouldCrawlForNewContent(aus));
  }

  public void testShouldDoNewContentCrawlFor0(DefinableArchivalUnit au)
      throws Exception {
    AuState aus = new MockAuState(null, 0, -1, -1, null);
    assertTrue(au.shouldCrawlForNewContent(aus));
  }

  public void testConstructNullUrl(String volume, String pluginId)
      throws Exception {
    try {
      createAu(null, volume, pluginId);
      fail("Should have thrown ArchivalUnit.ConfigurationException");
    } catch (ArchivalUnit.ConfigurationException e) {
    }
  }

  public void testGetName(String url, String volume, String pluginId,
      String pluginName) throws Exception {
    DefinableArchivalUnit au = createAu(new URL(url), volume, pluginId);
    assertEquals(pluginName + ", Base URL " + url + ", Volume " +
        volume, au.getName());
  }

  public void setUp() throws Exception {
    super.setUp();
    tempDirPath = setUpDiskSpace();
    daemon = getMockLockssDaemon();
    pluginMgr = daemon.getPluginManager();
    pluginMgr.setLoadablePluginsReady(true);
    daemon.setDaemonInited(true);
    pluginMgr.startService();
    daemon.getAlertManager();
    daemon.getCrawlManager();
  }

  // Variant to test PeerJ Archives (main) site
  public static class TestArchives extends TestPeerJArchivalUnit {
    public void testArchivalUnit() throws Exception {
      variantPluginName = "PeerJ Plugin (retired plugin)";
      variantPluginId =  "org.lockss.plugin.peerj.PeerJPlugin";
      variantPeerjSite = "archives";
      variantBaseConstant = "articles";
      variantPeerjAu = createAu(new URL("http://www.example.com/"),
        VOLUME_NAME, variantPluginId);

      testGetName("http://www.example1.com/", "2010", variantPluginId,
          variantPluginName);
      testConstructNullUrl("2011", variantPluginId);
      testShouldDoNewContentCrawlFor0(variantPeerjAu);
      testShouldDoNewContentCrawlTooEarly(variantPeerjAu);
      testShouldNotCachePageFromOtherSite(variantPeerjAu, variantPeerjSite);
      testStartUrlConstruction(variantPeerjAu, variantPeerjSite);
      testShouldCacheProperPages(variantPeerjAu, variantPeerjSite,
          variantBaseConstant);
    }
  }

  public static Test suite() {
    return variantSuites(new Class[] {
        TestArchives.class,
        // Variant to test PeerJ Preprints site no longer exists
    });
  }

}


text:
import java.util.*;
class B {
    <T> String  foo(T t, St<caret>ring s){return null;}
}

redpajama_set_name: RedPajamaGithub


text:
<?xml version="1.0" encoding="UTF-8"?>

<!--L
   Copyright Ekagra Software Technologies

   Distributed under the OSI-approved BSD 3-Clause License.
   See http://ncip.github.com/common-logging-module/LICENSE.txt for details.
L-->

<?xml-stylesheet type="text/xsl"
                 href="http://gforge.nci.nih.gov/svnroot/commonlibrary/trunk/ivy-xsl/ivy.xsl"?>
<ivy-module version="1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">

  <info organisation="javax.servlet" module="servlet" revision="2.3.1" status="integration" publication="20120203210402"/>

  <configurations>
    <conf name="master"/>
    <conf name="compile"/>
    <conf name="runtime" extends="compile"/>
  </configurations>

  <publications>
    <artifact name="servlet" type="jar" conf="master, compile"/>
  </publications>

  <dependencies>
  </dependencies>

</ivy-module>


text:
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <errno.h>
#include <stdio.h>
#include <string.h>

#include <winpr/crypto.h>
#include <winpr/crt.h>
#include <winpr/file.h>
#include <winpr/path.h>

#include <openssl/pem.h>
#include <openssl/rsa.h>

static const char certificate_store_dir[] = "certs";
static const char certificate_server_dir[] = "server";
static const char certificate_known_hosts_file[] = "known_hosts2";
static const char certificate_legacy_hosts_file[] = "known_hosts";

#include <freerdp/log.h>
#include <freerdp/crypto/certificate.h>

#define TAG FREERDP_TAG("crypto")

static BOOL certificate_split_line(char* line, char** host, UINT16* port,
					 char**subject, char**issuer,
					 char** fingerprint);

BOOL certificate_store_init(rdpCertificateStore* certificate_store)
{
	char* server_path = NULL;
	rdpSettings* settings;

	settings = certificate_store->settings;

	if (!PathFileExistsA(settings->ConfigPath))
	{
		if (!PathMakePathA(settings->ConfigPath, 0))
		{
			WLog_ERR(TAG, "error creating directory '%s'", settings->ConfigPath);
			goto fail;
		}
		WLog_INFO(TAG, "creating directory %s", settings->ConfigPath);
	}

	if (!(certificate_store->path = GetCombinedPath(settings->ConfigPath, (char*) certificate_store_dir)))
		goto fail;

	if (!PathFileExistsA(certificate_store->path))
	{
		if (!PathMakePathA(certificate_store->path, 0))
		{
			WLog_ERR(TAG, "error creating directory [%s]", certificate_store->path);
			goto fail;
		}
		WLog_INFO(TAG, "creating directory [%s]", certificate_store->path);
	}

	if (!(server_path = GetCombinedPath(settings->ConfigPath, (char*) certificate_server_dir)))
		goto fail;

	if (!PathFileExistsA(server_path))
	{
		if (!PathMakePathA(server_path, 0))
		{
			WLog_ERR(TAG, "error creating directory [%s]", server_path);
			goto fail;
		}
		WLog_INFO(TAG, "created directory [%s]", server_path);
	}

	if (!(certificate_store->file = GetCombinedPath(settings->ConfigPath, (char*) certificate_known_hosts_file)))
		goto fail;

	if (!(certificate_store->legacy_file = GetCombinedPath(settings->ConfigPath,
								(char*) certificate_legacy_hosts_file)))
		goto fail;

	free(server_path);

	return TRUE;

fail:
	WLog_ERR(TAG, "certificate store initialization failed");
	free(server_path);
	free(certificate_store->path);
	free(certificate_store->file);
	certificate_store->path = NULL;
	certificate_store->file = NULL;
	return FALSE;
}

static int certificate_data_match_legacy(rdpCertificateStore* certificate_store,
					 rdpCertificateData* certificate_data)
{
	FILE* fp;
	int match = 1;
	char* data;
	char* mdata;
	char* pline;
	char* hostname;
	long size;
	size_t length;

	fp = fopen(certificate_store->legacy_file, "rb");
	if (!fp)
		return match;

	fseek(fp, 0, SEEK_END);
	size = ftell(fp);
	fseek(fp, 0, SEEK_SET);

	if (size < 1)
	{
		fclose(fp);
		return match;
	}

	mdata = (char*) malloc(size + 2);
	if (!mdata)
	{
		fclose(fp);
		return match;
	}

	data = mdata;
	if (fread(data, size, 1, fp) != 1)
	{
		free(data);
		fclose(fp);
		return match;
	}

	fclose(fp);

	data[size] = '\n';
	data[size + 1] = '\0';
	pline = StrSep(&data, "\r\n");

	while (pline != NULL)
	{
		length = strlen(pline);

		if (length > 0)
		{
			hostname = StrSep(&pline, " \t");
			if (!hostname || !pline)
				WLog_WARN(TAG, "Invalid %s entry %s %s!", certificate_legacy_hosts_file,
					hostname, pline);
			else if (strcmp(hostname, certificate_data->hostname) == 0)
			{
				match = strcmp(pline, certificate_data->fingerprint);
				break;
			}
		}

		pline = StrSep(&data, "\r\n");
	}
	free(mdata);

	/* Found a valid fingerprint in legacy file,
	 * copy to new file in new format. */
	if (0 == match)
	{
		rdpCertificateData* data = certificate_data_new(hostname,
						certificate_data->port,
								NULL, NULL,
								pline);
		if (data)
			match = certificate_data_print(certificate_store, data) ? 0 : 1;
		certificate_data_free(data);
	}

	return match;

}

static int certificate_data_match_raw(rdpCertificateStore* certificate_store,
							rdpCertificateData* certificate_data,
							char** psubject, char** pissuer,
							char** fprint)
{
	BOOL found = FALSE;
	FILE* fp;
	int length;
	char* data;
	char* mdata;
	char* pline;
	int match = 1;
	long int size;
	char* hostname = NULL;
	char* subject = NULL;
	char* issuer = NULL;
	char* fingerprint = NULL;
	unsigned short port = 0;

	fp = fopen(certificate_store->file, "rb");

	if (!fp)
		return match;

	fseek(fp, 0, SEEK_END);
	size = ftell(fp);
	fseek(fp, 0, SEEK_SET);

	if (size < 1)
	{
		fclose(fp);
		return match;
	}

	mdata = (char*) malloc(size + 2);
	if (!mdata)
	{
		fclose(fp);
		return match;
	}

	data = mdata;
	if (fread(data, size, 1, fp) != 1)
	{
		fclose(fp);
		free(data);
		return match;
	}
	fclose(fp);

	data[size] = '\n';
	data[size + 1] = '\0';
	pline = StrSep(&data, "\r\n");

	while (pline != NULL)
	{
		length = strlen(pline);

		if (length > 0)
		{
			if (!certificate_split_line(pline, &hostname, &port,
								&subject, &issuer, &fingerprint))
				WLog_WARN(TAG, "Invalid %s entry %s!",
						certificate_known_hosts_file, pline);
			else if (strcmp(pline, certificate_data->hostname) == 0)
			{
				int outLen;

				if (port == certificate_data->port)
				{
					found = TRUE;
					match = strcmp(certificate_data->fingerprint, fingerprint);
					if (fingerprint && fprint)
						*fprint = _strdup(fingerprint);
					if (subject && psubject)
						crypto_base64_decode(subject, strlen(subject), (BYTE**)psubject, &outLen);
					if (issuer && pissuer)
						crypto_base64_decode(issuer, strlen(issuer), (BYTE**)pissuer, &outLen);
					break;
				}
			}
		}

		pline = StrSep(&data, "\r\n");
	}
	free(mdata);

	if ((match != 0) && !found)
		match = certificate_data_match_legacy(certificate_store, certificate_data);

	return match;
}

BOOL certificate_get_stored_data(rdpCertificateStore* certificate_store,
				 rdpCertificateData* certificate_data,
				 char** subject, char** issuer,
				 char** fingerprint)
{
	int rc = certificate_data_match_raw(certificate_store, certificate_data,
							subject, issuer, fingerprint);

	if ((rc == 0) || (rc == -1))
		return TRUE;
	return FALSE;
}

int certificate_data_match(rdpCertificateStore* certificate_store,
				 rdpCertificateData* certificate_data)
{
	return certificate_data_match_raw(certificate_store, certificate_data,
						NULL, NULL, NULL);
}

BOOL certificate_data_replace(rdpCertificateStore* certificate_store,
						rdpCertificateData* certificate_data)
{
	FILE* fp;
	BOOL rc = FALSE;
	int length;
	char* data;
	char* sdata;
	char* pline;
	long int size;

	fp = fopen(certificate_store->file, "rb");

	if (!fp)
		return FALSE;
	/* Read the current contents of the file. */
	fseek(fp, 0, SEEK_END);
	size = ftell(fp);
	fseek(fp, 0, SEEK_SET);

	if (size < 1)
	{
		fclose(fp);
		return FALSE;
	}

	data = (char*) malloc(size + 2);
	if (!data)
	{
		fclose(fp);
		return FALSE;
	}

	if (fread(data, size, 1, fp) != 1)
	{
		fclose(fp);
		free(data);
		return FALSE;
	}

	fclose(fp);

	fp = fopen(certificate_store->file, "wb");

	if (!fp)
	{
		free(data);
		return FALSE;
	}

	/* Write the file back out, with appropriate fingerprint substitutions */
	data[size] = '\n';
	data[size + 1] = '\0';
	sdata = data;
	pline = StrSep(&sdata, "\r\n");

	while (pline != NULL)
	{
		length = strlen(pline);

		if (length > 0)
		{
			UINT16 port = 0;
			char* hostname = NULL;
			char* fingerprint = NULL;
			char* subject = NULL;
			char* issuer = NULL;

			if (!certificate_split_line(pline, &hostname, &port, &subject, &issuer, &fingerprint))
				WLog_WARN(TAG, "Skipping invalid %s entry %s!",
						certificate_known_hosts_file, pline);
			else
			{
				/* If this is the replaced hostname, use the updated fingerprint. */
				if ((strcmp(hostname, certificate_data->hostname) == 0) &&
						(port == certificate_data->port))
				{
					fingerprint = certificate_data->fingerprint;
					rc = TRUE;
				}
				fprintf(fp, "%s %hu %s %s %s\n", hostname, port, fingerprint, subject, issuer);
			}
		}

		pline = StrSep(&sdata, "\r\n");
	}

	fclose(fp);
	free(data);

	return rc;
}

BOOL certificate_split_line(char* line, char** host, UINT16* port, char** subject,
					char** issuer, char** fingerprint)
{
		char* cur;
		size_t length = strlen(line);

		if (length <= 0)
			return FALSE;

		cur = StrSep(&line, " \t");
		if (!cur)
			return FALSE;
		*host = cur;

		cur = StrSep(&line, " \t");
		if (!cur)
			return FALSE;

		if(sscanf(cur, "%hu", port) != 1)
			return FALSE;

		cur = StrSep(&line, " \t");
		if (!cur)
			return FALSE;

		*fingerprint = cur;

		cur = StrSep(&line, " \t");
		if (!cur)
			return FALSE;

		*subject = cur;

		cur = StrSep(&line, " \t");
		if (!cur)
			return FALSE;

		*issuer = cur;

		return TRUE;
}

BOOL certificate_data_print(rdpCertificateStore* certificate_store, rdpCertificateData* certificate_data)
{
	FILE* fp;

	/* reopen in append mode */
	fp = fopen(certificate_store->file, "ab");

	if (!fp)
		return FALSE;

	fprintf(fp, "%s %hu %s %s %s\n", certificate_data->hostname, certificate_data->port,
					 certificate_data->fingerprint, certificate_data->subject,
					 certificate_data->issuer);

	fclose(fp);

	return TRUE;
}

rdpCertificateData* certificate_data_new(char* hostname, UINT16 port, char* subject, char* issuer, char* fingerprint)
{
	rdpCertificateData* certdata;

	if (!hostname)
		return NULL;

	if (!fingerprint)
		return NULL;

	certdata = (rdpCertificateData *)calloc(1, sizeof(rdpCertificateData));
	if (!certdata)
		return NULL;

	certdata->port = port;
	certdata->hostname = _strdup(hostname);
	if (subject)
		certdata->subject = crypto_base64_encode((BYTE*)subject, strlen(subject));
	else
		certdata->subject = crypto_base64_encode((BYTE*)"", 0);
	if (issuer)
		certdata->issuer = crypto_base64_encode((BYTE*)issuer, strlen(subject));
	else
		certdata->issuer = crypto_base64_encode((BYTE*)"", 0);
	certdata->fingerprint = _strdup(fingerprint);

	if (!certdata->hostname || !certdata->subject ||
			!certdata->issuer || !certdata->fingerprint)
		goto fail;

	return certdata;

fail:
	free(certdata->hostname);
	free(certdata->subject);
	free(certdata->issuer);
	free(certdata->fingerprint);
	free(certdata);
	return NULL;
}

void certificate_data_free(rdpCertificateData* certificate_data)
{
	if (certificate_data != NULL)
	{
		free(certificate_data->hostname);
		free(certificate_data->subject);
		free(certificate_data->issuer);
		free(certificate_data->fingerprint);
		free(certificate_data);
	}
}

rdpCertificateStore* certificate_store_new(rdpSettings* settings)
{
	rdpCertificateStore* certificate_store;

	certificate_store = (rdpCertificateStore*) calloc(1, sizeof(rdpCertificateStore));

	if (!certificate_store)
		return NULL;

	certificate_store->settings = settings;

	if (!certificate_store_init(certificate_store))
	{
		free(certificate_store);
		return NULL;
	}

	return certificate_store;
}

void certificate_store_free(rdpCertificateStore* certstore)
{
	if (certstore != NULL)
	{
		free(certstore->path);
		free(certstore->file);
		free(certstore->legacy_file);
		free(certstore);
	}
}


text:
import os
import json
import datetime

dirpath = os.path.dirname(os.path.realpath(__file__))
config = json.loads(open(os.path.join(dirpath,'config.json'),'r').read())

def log(message):
	if config['debugging']:
		f = open(os.path.join(dirpath,'log.txt'), 'a+')
		f.write(str(datetime.datetime.now()) + ':\t' + message + '\n')
		f.close()


text:
package web

import (
	"log"
	"net/http"
	"regexp"
	"sort"
	"strings"
	"sync"
)

type method int

const (
	mCONNECT method = 1 << iota
	mDELETE
	mGET
	mHEAD
	mOPTIONS
	mPATCH
	mPOST
	mPUT
	mTRACE
	// We only natively support the methods above, but we pass through other
	// methods. This constant pretty much only exists for the sake of mALL.
	mIDK

	mALL method = mCONNECT | mDELETE | mGET | mHEAD | mOPTIONS | mPATCH |
		mPOST | mPUT | mTRACE | mIDK
)

// The key used to communicate to the NotFound handler what methods would have
// been allowed if they'd been provided.
const ValidMethodsKey = "goji.web.validMethods"

var validMethodsMap = map[string]method{
	"CONNECT": mCONNECT,
	"DELETE":  mDELETE,
	"GET":     mGET,
	"HEAD":    mHEAD,
	"OPTIONS": mOPTIONS,
	"PATCH":   mPATCH,
	"POST":    mPOST,
	"PUT":     mPUT,
	"TRACE":   mTRACE,
}

type route struct {
	// Theory: most real world routes have a string prefix which is both
	// cheap(-ish) to test against and pretty selective. And, conveniently,
	// both regexes and string patterns give us this out-of-box.
	prefix  string
	method  method
	pattern Pattern
	handler Handler
}

type router struct {
	lock     sync.Mutex
	routes   []route
	notFound Handler
	machine  *routeMachine
}

// A Pattern determines whether or not a given request matches some criteria.
// They are often used in routes, which are essentially (pattern, methodSet,
// handler) tuples. If the method and pattern match, the given handler is used.
//
// Built-in implementations of this interface are used to implement regular
// expression and string matching.
type Pattern interface {
	// In practice, most real-world routes have a string prefix that can be
	// used to quickly determine if a pattern is an eligible match. The
	// router uses the result of this function to optimize away calls to the
	// full Match function, which is likely much more expensive to compute.
	// If your Pattern does not support prefixes, this function should
	// return the empty string.
	Prefix() string
	// Returns true if the request satisfies the pattern. This function is
	// free to examine both the request and the context to make this
	// decision. Match should not modify either argument, and since it will
	// potentially be called several times over the course of matching a
	// request, it should be reasonably efficient.
	Match(r *http.Request, c *C) bool
	// Run the pattern on the request and context, modifying the context as
	// necessary to bind URL parameters or other parsed state.
	Run(r *http.Request, c *C)
}

func parsePattern(p interface{}) Pattern {
	switch p.(type) {
	case Pattern:
		return p.(Pattern)
	case *regexp.Regexp:
		return parseRegexpPattern(p.(*regexp.Regexp))
	case string:
		return parseStringPattern(p.(string))
	default:
		log.Fatalf("Unknown pattern type %v. Expected a web.Pattern, "+
			"regexp.Regexp, or a string.", p)
	}
	panic("log.Fatalf does not return")
}

type netHTTPWrap struct {
	http.Handler
}

func (h netHTTPWrap) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	h.Handler.ServeHTTP(w, r)
}
func (h netHTTPWrap) ServeHTTPC(c C, w http.ResponseWriter, r *http.Request) {
	h.Handler.ServeHTTP(w, r)
}

func parseHandler(h interface{}) Handler {
	switch h.(type) {
	case Handler:
		return h.(Handler)
	case http.Handler:
		return netHTTPWrap{h.(http.Handler)}
	case func(c C, w http.ResponseWriter, r *http.Request):
		f := h.(func(c C, w http.ResponseWriter, r *http.Request))
		return HandlerFunc(f)
	case func(w http.ResponseWriter, r *http.Request):
		f := h.(func(w http.ResponseWriter, r *http.Request))
		return netHTTPWrap{http.HandlerFunc(f)}
	default:
		log.Fatalf("Unknown handler type %v. Expected a web.Handler, "+
			"a http.Handler, or a function with signature func(C, "+
			"http.ResponseWriter, *http.Request) or "+
			"func(http.ResponseWriter, *http.Request)", h)
	}
	panic("log.Fatalf does not return")
}

func httpMethod(mname string) method {
	if method, ok := validMethodsMap[mname]; ok {
		return method
	}
	return mIDK
}

type routeMachine struct {
	sm     stateMachine
	routes []route
}

func matchRoute(route route, m method, ms *method, r *http.Request, c *C) bool {
	if !route.pattern.Match(r, c) {
		return false
	}
	*ms |= route.method

	if route.method&m != 0 {
		route.pattern.Run(r, c)
		return true
	}
	return false
}

func (rm routeMachine) route(c *C, w http.ResponseWriter, r *http.Request) (method, bool) {
	m := httpMethod(r.Method)
	var methods method
	p := r.URL.Path

	if len(rm.sm) == 0 {
		return methods, false
	}

	var i int
	for {
		sm := rm.sm[i].mode
		if sm&smSetCursor != 0 {
			si := rm.sm[i].i
			p = r.URL.Path[si:]
			i++
			continue
		}

		length := int(sm & smLengthMask)
		match := false
		if length <= len(p) {
			bs := rm.sm[i].bs
			switch length {
			case 3:
				if p[2] != bs[2] {
					break
				}
				fallthrough
			case 2:
				if p[1] != bs[1] {
					break
				}
				fallthrough
			case 1:
				if p[0] != bs[0] {
					break
				}
				fallthrough
			case 0:
				p = p[length:]
				match = true
			}
		}

		if match && sm&smRoute != 0 {
			si := rm.sm[i].i
			if matchRoute(rm.routes[si], m, &methods, r, c) {
				rm.routes[si].handler.ServeHTTPC(*c, w, r)
				return 0, true
			}
			i++
		} else if (match && sm&smJumpOnMatch != 0) ||
			(!match && sm&smJumpOnMatch == 0) {

			if sm&smFail != 0 {
				return methods, false
			}
			i = int(rm.sm[i].i)
		} else {
			i++
		}
	}

	return methods, false
}

// Compile the list of routes into bytecode. This only needs to be done once
// after all the routes have been added, and will be called automatically for
// you (at some performance cost on the first request) if you do not call it
// explicitly.
func (rt *router) Compile() *routeMachine {
	rt.lock.Lock()
	defer rt.lock.Unlock()
	sm := routeMachine{
		sm:     compile(rt.routes),
		routes: rt.routes,
	}
	rt.setMachine(&sm)
	return &sm
}

func (rt *router) route(c *C, w http.ResponseWriter, r *http.Request) {
	rm := rt.getMachine()
	if rm == nil {
		rm = rt.Compile()
	}

	methods, ok := rm.route(c, w, r)
	if ok {
		return
	}

	if methods == 0 {
		rt.notFound.ServeHTTPC(*c, w, r)
		return
	}

	var methodsList = make([]string, 0)
	for mname, meth := range validMethodsMap {
		if methods&meth != 0 {
			methodsList = append(methodsList, mname)
		}
	}
	sort.Strings(methodsList)

	if c.Env == nil {
		c.Env = map[string]interface{}{
			ValidMethodsKey: methodsList,
		}
	} else {
		c.Env[ValidMethodsKey] = methodsList
	}
	rt.notFound.ServeHTTPC(*c, w, r)
}

func (rt *router) handleUntyped(p interface{}, m method, h interface{}) {
	pat := parsePattern(p)
	rt.handle(pat, m, parseHandler(h))
}

func (rt *router) handle(p Pattern, m method, h Handler) {
	rt.lock.Lock()
	defer rt.lock.Unlock()

	// Calculate the sorted insertion point, because there's no reason to do
	// swapping hijinks if we're already making a copy. We need to use
	// bubble sort because we can only compare adjacent elements.
	pp := p.Prefix()
	var i int
	for i = len(rt.routes); i > 0; i-- {
		rip := rt.routes[i-1].prefix
		if rip <= pp || strings.HasPrefix(rip, pp) {
			break
		}
	}

	newRoutes := make([]route, len(rt.routes)+1)
	copy(newRoutes, rt.routes[:i])
	newRoutes[i] = route{
		prefix:  pp,
		method:  m,
		pattern: p,
		handler: h,
	}
	copy(newRoutes[i+1:], rt.routes[i:])

	rt.setMachine(nil)
	rt.routes = newRoutes
}

// This is a bit silly, but I've renamed the method receivers in the public
// functions here "m" instead of the standard "rt", since they will eventually
// be shown on the documentation for the Mux that they are included in.

/*
Dispatch to the given handler when the pattern matches, regardless of HTTP
method. See the documentation for type Mux for a description of what types are
accepted for pattern and handler.

This method is commonly used to implement sub-routing: an admin application, for
instance, can expose a single handler that is attached to the main Mux by
calling Handle("/admin*", adminHandler) or similar. Note that this function
doesn't strip this prefix from the path before forwarding it on (e.g., the
handler will see the full path, including the "/admin" part), but this
functionality can easily be performed by an extra middleware layer.
*/
func (rt *router) Handle(pattern interface{}, handler interface{}) {
	rt.handleUntyped(pattern, mALL, handler)
}

// Dispatch to the given handler when the pattern matches and the HTTP method is
// CONNECT. See the documentation for type Mux for a description of what types
// are accepted for pattern and handler.
func (rt *router) Connect(pattern interface{}, handler interface{}) {
	rt.handleUntyped(pattern, mCONNECT, handler)
}

// Dispatch to the given handler when the pattern matches and the HTTP method is
// DELETE. See the documentation for type Mux for a description of what types
// are accepted for pattern and handler.
func (rt *router) Delete(pattern interface{}, handler interface{}) {
	rt.handleUntyped(pattern, mDELETE, handler)
}

// Dispatch to the given handler when the pattern matches and the HTTP method is
// GET. See the documentation for type Mux for a description of what types are
// accepted for pattern and handler.
//
// All GET handlers also transparently serve HEAD requests, since net/http will
// take care of all the fiddly bits for you. If you wish to provide an alternate
// implementation of HEAD, you should add a handler explicitly and place it
// above your GET handler.
func (rt *router) Get(pattern interface{}, handler interface{}) {
	rt.handleUntyped(pattern, mGET|mHEAD, handler)
}

// Dispatch to the given handler when the pattern matches and the HTTP method is
// HEAD. See the documentation for type Mux for a description of what types are
// accepted for pattern and handler.
func (rt *router) Head(pattern interface{}, handler interface{}) {
	rt.handleUntyped(pattern, mHEAD, handler)
}

// Dispatch to the given handler when the pattern matches and the HTTP method is
// OPTIONS. See the documentation for type Mux for a description of what types
// are accepted for pattern and handler.
func (rt *router) Options(pattern interface{}, handler interface{}) {
	rt.handleUntyped(pattern, mOPTIONS, handler)
}

// Dispatch to the given handler when the pattern matches and the HTTP method is
// PATCH. See the documentation for type Mux for a description of what types are
// accepted for pattern and handler.
func (rt *router) Patch(pattern interface{}, handler interface{}) {
	rt.handleUntyped(pattern, mPATCH, handler)
}

// Dispatch to the given handler when the pattern matches and the HTTP method is
// POST. See the documentation for type Mux for a description of what types are
// accepted for pattern and handler.
func (rt *router) Post(pattern interface{}, handler interface{}) {
	rt.handleUntyped(pattern, mPOST, handler)
}

// Dispatch to the given handler when the pattern matches and the HTTP method is
// PUT. See the documentation for type Mux for a description of what types are
// accepted for pattern and handler.
func (rt *router) Put(pattern interface{}, handler interface{}) {
	rt.handleUntyped(pattern, mPUT, handler)
}

// Dispatch to the given handler when the pattern matches and the HTTP method is
// TRACE. See the documentation for type Mux for a description of what types are
// accepted for pattern and handler.
func (rt *router) Trace(pattern interface{}, handler interface{}) {
	rt.handleUntyped(pattern, mTRACE, handler)
}

// Set the fallback (i.e., 404) handler for this mux. See the documentation for
// type Mux for a description of what types are accepted for handler.
//
// As a convenience, the context environment variable "goji.web.validMethods"
// (also available as the constant ValidMethodsKey) will be set to the list of
// HTTP methods that could have been routed had they been provided on an
// otherwise identical request.
func (rt *router) NotFound(handler interface{}) {
	rt.notFound = parseHandler(handler)
}


text:
layout: post
title: "R-Ladies Ames Meetup: Webscraping with `tidyverse` Packages"
date: "2017-02-09 13:40:27 CDT"
categories: blog, rladies
---

Slides are [here](../static/presentations/RLadies/2017-02-09-WebscrapingTidyverse.html)


text:
Implemented in: **v0.9.0**

## Motivation

To have a more organized, readable, and aethetically-pleasing log output.

## Goals

- Consistency between Maven and Gradle
- Organize across levels of verbosity

## Proposed Design

### Categories

The log output will be organized into 4 categories:

#### Lifecycle

Messages that are part of the execution and will always show up.

#### Info

Messages that are extra information and do not need to be displayed by default. Note that for Maven, these will be at the same level as Debug.

#### Debug

Messages that are useful for debugging what went wrong, but not as useful (or convoluting) as user-facing information. These would be helpful to include in, for example, a bug report.

#### Warn/Error

These messages will be displayed by default, but as the warning/error format of the specific Maven/Gradle logger implementations. Jib should not explicitly log error messages, but rather throw those messages as part of exceptions.

### Information to include

The information to include, in the order in which they should appear are:

1. (info) Where inputs are inferred from, including
    1. The main class
1. (info) Files that went into each layer
    1. Classes, resources, dependencies
1. (lifecycle/info) Important build steps
    1. Show what's skipped?
    1. Asynchronous steps (the order may vary between runs)
        - [lifecycle] Retrieving credentials for \<base image>...
            - [info] Credentials for \<target image> found via (docker-credential-*/Docker config/Maven settings) in \<### ms>
        - [lifecycle] Retrieving credentials for \<target image>...
            - [info] Credentials for \<target image> found via (docker-credential-*/Docker config/Maven settings) in \<### ms>
        - [lifecycle] Getting base image \<base image>…
            - [info] Fetching manifest for \<base image>...
            - [info] Fetched manifest for \<base image> in \<### ms>
            - [info] Fetching layer \<digest> of \<base image>...
            - [info] Fetched layer \<digest> of \<base image> in \<### ms>
            - [info] Pulled base image in \<### ms>
        - [lifecycle] Building dependencies layer...
            - [info] Built and cached dependencies layer \<digest> in \<### ms>
            - [info] Pushing dependencies layer \<digest>...
            - [info] Pushed dependencies layer \<digest> in \<### ms>
        - [lifecycle] Building resources layer
            - Same as for dependencies
        - [lifecycle] Building classes layer
            - Same as for dependencies
        - [lifecycle] Finalizing…
            - [info] Pushing container configuration \<digest>...
            - [info] Pushed container configuration \<digest> in \<### ms>
            - [info] Pushing manifest...
            - [info] Pushed manifest in \<### ms>
        - [lifecycle] Build complete in \<### s>
1. Finalized information
    1. Container entrypoint set to \<entrypoint>
    1. Built and pushed image as \<target image>

### Example log

At lifecycle level:

```
[lifecycle] Containerizing application to gcr.io/my-gcp-project/my-app...
[lifecycle]
[lifecycle] Retrieving credentials for gcr.io/distroless/java…
[lifecycle] Retrieving credentials for gcr.io/my-gcp-project/my-app...
[lifecycle] Getting base image gcr.io/distroless/java…
[lifecycle] Building dependencies layer...
[lifecycle] Building resources layer...
[lifecycle] Building classes layer...
[lifecycle] Finalizing…
[lifecycle] Build complete in 2.1354s
[lifecycle]
[lifecycle] Container entrypoint set to [java, -cp, /app/libs/*:/app/resources/:/app/classes/, my.App]
[lifecycle]
[lifecycle] Built and pushed image as gcr.io/my-gcp-project/my-ap
```

At info level:

```
[lifecycle] Containerizing application to gcr.io/my-gcp-project/my-app...
[info] Using main class from maven-jar-plugin/: my.App
[info] Containerizing application with the following files:
[info]     Classes:
[info]         <the files>
[info]     Resources:
[info]         <the files>
[info]     Dependencies:
[info]         <the files>
[lifecycle]
[lifecycle] Retrieving credentials for gcr.io/distroless/java…
[info] Credentials for gcr.io/distroless/java found via docker-credential-gcr in 400ms
[lifecycle] Retrieving credentials for gcr.io/my-gcp-project/my-app...
[info] Credentials for gcr.io/my-gcp-project/my-app found via docker-credential-gcr in 300ms
[lifecycle] Getting base image gcr.io/distroless/java…
[info] Fetching manifest for gcr.io/distroless/java...
[info] Fetched manifest for gcr.io/distroless/java in 300ms
[info] Fetching layer sha256:fafafafa... of gcr.io/distroless/java…
[info] Fetching layer sha256:fafafafa... of gcr.io/distroless/java...
[info] Fetched layer sha256:fafafafa... of gcr.io/distroless/java in 200ms
[info] Fetched layer sha256:fafafafa... of gcr.io/distroless/java in 200ms
[info] Pulled base image in 550ms
[lifecycle] Building dependencies layer...
[info] Built and cached dependencies layer sha256:ababab... in 20ms
[info] Pushing dependencies layer sha256:ababab...
[info] Pushed dependencies layer sha256:ababab... in 200ms
[lifecycle] Building resources layer
[info] Built and cached resources layer sha256:bcbcbc... in 20ms
[info] Pushing resources layer sha256:bcbcbc...
[info] Pushed resources layer sha256:bcbcbc... in 250ms
[lifecycle] Building classes layer
[info] Built and cached classes layer sha256:cdcdcd... in 10ms
[info] Pushing classes layer sha256:cdcdcd...
[info] Pushed classes layer sha256:cdcdcd... in 10ms
[lifecycle] Finalizing…
[info] Pushing container configuration sha256:cdcdcd...
[info] Pushed container configuration sha256:cdcdcd... in 100ms
[info] Pushing manifest...
[info] Pushed manifest in 150ms
[lifecycle] Build complete in 2.1354s
[lifecycle]
[lifecycle] Container entrypoint set to [java, -cp, /app/libs/*:/app/resources/:/app/classes/, my.App]
[lifecycle]
[lifecycle] Built and pushed image as gcr.io/my-gcp-project/my-app
```

## Appendix: Current output

Example of current Maven output (`mvn compile jib:build`):

```
[INFO] --- jib-maven-plugin:0.1.7-SNAPSHOT:build (default-cli) @ hello-world ---
[INFO] Using main class from maven-jar-plugin: com.test.HelloWorld
[INFO]
[INFO] Containerizing application with the following files:
[INFO]
[INFO] 	Dependencies:
[INFO]
[INFO] 		/google/src/cloud/qingyangc/sandbox/google3/experimental/users/qingyangc/sandbox/helloproject/libs/dependency-1.0.0.jar
[INFO] 		/usr/local/google/home/qingyangc/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar
[INFO] 		/usr/local/google/home/qingyangc/.m2/repository/com/google/errorprone/error_prone_annotations/2.1.3/error_prone_annotations-2.1.3.jar
[INFO] 		/usr/local/google/home/qingyangc/.m2/repository/com/google/guava/guava/23.6-jre/guava-23.6-jre.jar
[INFO] 		/usr/local/google/home/qingyangc/.m2/repository/com/google/j2objc/j2objc-annotations/1.1/j2objc-annotations-1.1.jar
[INFO] 		/usr/local/google/home/qingyangc/.m2/repository/org/checkerframework/checker-compat-qual/2.0.0/checker-compat-qual-2.0.0.jar
[INFO] 		/usr/local/google/home/qingyangc/.m2/repository/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14.jar
[INFO] 	Resources:
[INFO]
[INFO] 		/google/src/cloud/qingyangc/sandbox/google3/experimental/users/qingyangc/sandbox/helloproject/target/classes/20m.2
[INFO] 		/google/src/cloud/qingyangc/sandbox/google3/experimental/users/qingyangc/sandbox/helloproject/target/classes/aklwejflkjawelkfjlkefjlkawejflaweflkwenfkneawklfewnlknaewlgjnlaewkgjklaewgnjlakewnglaekwnglaewngkwengnglkweangklawnglekangwklgnelkngwlknglekwnglkanglkwgnew
[INFO] 		/google/src/cloud/qingyangc/sandbox/google3/experimental/users/qingyangc/sandbox/helloproject/target/classes/world2
[INFO] 	Classes:
[INFO]
[INFO] 		/google/src/cloud/qingyangc/sandbox/google3/experimental/users/qingyangc/sandbox/helloproject/target/classes/com
[INFO]
[INFO]
[INFO] Pushing image as gcr.io/qingyangc-sandbox/jibtestimage:built-with-jib
[INFO]
[INFO] RUNNING	Building and pushing image
[INFO] RUNNING	Retrieving registry credentials for gcr.io
[INFO] RUNNING	Retrieving registry credentials for gcr.io
[INFO] Checking credentials from docker-credential-gcr
[INFO] Checking credentials from docker-credential-gcr
[INFO] RUNNING	Building application layers
[INFO] RUNNING	Building dependencies layer
[INFO] RUNNING	Building resources layer
[INFO] Building application layers : 0.931 ms
[INFO] RUNNING	Building classes layer
[INFO] RUNNING	Setting up to push layers
[INFO] Setting up to push layers : 1.083 ms
[INFO] Building dependencies layer : 2.82 ms
[INFO] Building resources layer : 2.879 ms
[INFO] Building classes layer : 10.285 ms
[INFO] Using docker-credential-gcr for gcr.io
[INFO] Using docker-credential-gcr for gcr.io
[INFO] Retrieving registry credentials for gcr.io : 325.95 ms
[INFO] Retrieving registry credentials for gcr.io : 325.974 ms
[INFO] RUNNING	Authenticating with push to gcr.io
[INFO] RUNNING	Authenticating pull from gcr.io
[INFO] Authenticating pull from gcr.io : 674.983 ms
[INFO] RUNNING	Pulling base image manifest
[INFO] Authenticating with push to gcr.io : 745.519 ms
[INFO] RUNNING	Pushing BLOB sha256:c63484398b097b7e9693ac373ac95630bb8d8ad8ff90a3277e7105bb77e8e986
[INFO] RUNNING	Pushing BLOB sha256:9a6afec7bf36218264ed61dc525d8fe6b585dd7a84b780a327c3663de4ef51b1
[INFO] RUNNING	Pushing BLOB sha256:3b6efb8e94b25098a394fa4d2e988cc12a6afd7a2b112a2c97cc9899d446ae18
[INFO] BLOB : sha256:9a6afec7bf36218264ed61dc525d8fe6b585dd7a84b780a327c3663de4ef51b1 already exists on registry
[INFO] Pushing BLOB sha256:9a6afec7bf36218264ed61dc525d8fe6b585dd7a84b780a327c3663de4ef51b1 : 176.432 ms
[INFO] BLOB : sha256:c63484398b097b7e9693ac373ac95630bb8d8ad8ff90a3277e7105bb77e8e986 already exists on registry
[INFO] Pushing BLOB sha256:c63484398b097b7e9693ac373ac95630bb8d8ad8ff90a3277e7105bb77e8e986 : 189.759 ms
[INFO] BLOB : sha256:3b6efb8e94b25098a394fa4d2e988cc12a6afd7a2b112a2c97cc9899d446ae18 already exists on registry
[INFO] Pushing BLOB sha256:3b6efb8e94b25098a394fa4d2e988cc12a6afd7a2b112a2c97cc9899d446ae18 : 281.987 ms
[INFO] Pulling base image manifest : 439.962 ms
[INFO] RUNNING	Setting up base image caching
[INFO] Setting up base image caching : 1.027 ms
[INFO] RUNNING	Pulling base image layer sha256:15705ab016593987662839b40f5a22fd1032996c90808d4a1371eb46974017d5
[INFO] RUNNING	Setting up to push layers
[INFO] RUNNING	Pulling base image layer sha256:ba7c544469e514f1a9a4dec59ab640540d50992b288adbb34a1a63c45bf19a24
[INFO] Pulling base image layer sha256:15705ab016593987662839b40f5a22fd1032996c90808d4a1371eb46974017d5 : 0.078 ms
[INFO] RUNNING	Pulling base image layer sha256:eb05f3dbdb543cc610527248690575bacbbcebabe6ecf665b189cf18b541e3ca
[INFO] RUNNING	Pushing BLOB sha256:15705ab016593987662839b40f5a22fd1032996c90808d4a1371eb46974017d5
[INFO] Pulling base image layer sha256:eb05f3dbdb543cc610527248690575bacbbcebabe6ecf665b189cf18b541e3ca : 0.167 ms
[INFO] Setting up to push layers : 0.1 ms
[INFO] RUNNING	Pushing BLOB sha256:eb05f3dbdb543cc610527248690575bacbbcebabe6ecf665b189cf18b541e3ca
[INFO] Pulling base image layer sha256:ba7c544469e514f1a9a4dec59ab640540d50992b288adbb34a1a63c45bf19a24 : 0.281 ms
[INFO] RUNNING	Pushing BLOB sha256:ba7c544469e514f1a9a4dec59ab640540d50992b288adbb34a1a63c45bf19a24
[INFO] RUNNING	Building container configuration
[INFO] Building container configuration : 15.243 ms
[INFO] BLOB : sha256:eb05f3dbdb543cc610527248690575bacbbcebabe6ecf665b189cf18b541e3ca already exists on registry
[INFO] Pushing BLOB sha256:eb05f3dbdb543cc610527248690575bacbbcebabe6ecf665b189cf18b541e3ca : 90.115 ms
[INFO] BLOB : sha256:15705ab016593987662839b40f5a22fd1032996c90808d4a1371eb46974017d5 already exists on registry
[INFO] Pushing BLOB sha256:15705ab016593987662839b40f5a22fd1032996c90808d4a1371eb46974017d5 : 123.695 ms
[INFO] Pushing container configuration sha256:71529d335fd983477a62eaf9e1cd37e488c48eb1d9477e09fbd63e37857b251c : 152.741 ms
[INFO] BLOB : sha256:ba7c544469e514f1a9a4dec59ab640540d50992b288adbb34a1a63c45bf19a24 already exists on registry
[INFO] Pushing BLOB sha256:ba7c544469e514f1a9a4dec59ab640540d50992b288adbb34a1a63c45bf19a24 : 304.932 ms
[INFO] RUNNING	Pushing new image
[INFO] Pushing new image : 1191.479 ms
[INFO] Building and pushing image : 3149.412 ms
[INFO]
[INFO] Container entrypoint set to [java, -cp, /app/libs/*:/app/resources/:/app/classes/, com.test.HelloWorld]
[INFO]
[INFO] Built and pushed image as gcr.io/qingyangc-sandbox/jibtestimage:built-with-jib
```

Current Gradle output (`gradle build jib --info`):

```
:jib (Thread[Task worker for ':',5,main]) started.
RUNNING Retrieving registry credentials for gcr.io
Using jib extension for gcr.io
RUNNING Retrieving registry credentials for gcr.io
Retrieving registry credentials for gcr.io : 0.176 ms
RUNNING Building dependencies layer
Using jib extension for gcr.io
RUNNING Building resources layer
RUNNING Building classes layer
RUNNING Authenticating with push to gcr.io
Retrieving registry credentials for gcr.io : 0.342 ms
Building dependencies layer : 0.351 ms
Building resources layer : 0.43 ms
RUNNING Authenticating pull from gcr.io
Building classes layer : 0.958 ms
Authentication error: Unable to respond to any of these challenges: {bearer=WWW-Authenticate: Bearer realm="https://gcr.io/v2/token",service="gcr.io"}
Authentication error: Unable to respond to any of these challenges: {bearer=WWW-Authenticate: Bearer realm="https://gcr.io/v2/token",service="gcr.io"}
Authenticating pull from gcr.io : 196.848 ms
RUNNING Pulling base image manifest
Authenticating with push to gcr.io : 237.681 ms
RUNNING Pushing BLOB sha256:3b6efb8e94b25098a394fa4d2e988cc12a6afd7a2b112a2c97cc9899d446ae18
RUNNING Pushing BLOB sha256:c63484398b097b7e9693ac373ac95630bb8d8ad8ff90a3277e7105bb77e8e986
RUNNING Pushing BLOB sha256:9a6afec7bf36218264ed61dc525d8fe6b585dd7a84b780a327c3663de4ef51b1
BLOB : sha256:3b6efb8e94b25098a394fa4d2e988cc12a6afd7a2b112a2c97cc9899d446ae18 already exists on registry
Pushing BLOB sha256:3b6efb8e94b25098a394fa4d2e988cc12a6afd7a2b112a2c97cc9899d446ae18 : 101.4 ms
BLOB : sha256:9a6afec7bf36218264ed61dc525d8fe6b585dd7a84b780a327c3663de4ef51b1 already exists on registry
Pushing BLOB sha256:9a6afec7bf36218264ed61dc525d8fe6b585dd7a84b780a327c3663de4ef51b1 : 120.31 ms
BLOB : sha256:c63484398b097b7e9693ac373ac95630bb8d8ad8ff90a3277e7105bb77e8e986 already exists on registry
Pushing BLOB sha256:c63484398b097b7e9693ac373ac95630bb8d8ad8ff90a3277e7105bb77e8e986 : 137.118 ms
Pulling base image manifest : 361.452 ms
RUNNING Setting up base image caching
RUNNING Pulling base image layer sha256:eb05f3dbdb543cc610527248690575bacbbcebabe6ecf665b189cf18b541e3ca
Setting up base image caching : 0.224 ms
Pulling base image layer sha256:eb05f3dbdb543cc610527248690575bacbbcebabe6ecf665b189cf18b541e3ca : 0.086 ms
RUNNING Pulling base image layer sha256:15705ab016593987662839b40f5a22fd1032996c90808d4a1371eb46974017d5
RUNNING Pulling base image layer sha256:ba7c544469e514f1a9a4dec59ab640540d50992b288adbb34a1a63c45bf19a24
Pulling base image layer sha256:15705ab016593987662839b40f5a22fd1032996c90808d4a1371eb46974017d5 : 0.224 ms
RUNNING Setting up to push layers
Pulling base image layer sha256:ba7c544469e514f1a9a4dec59ab640540d50992b288adbb34a1a63c45bf19a24 : 0.334 ms
RUNNING Pushing BLOB sha256:eb05f3dbdb543cc610527248690575bacbbcebabe6ecf665b189cf18b541e3ca
RUNNING Building container configuration
Setting up to push layers : 0.365 ms
RUNNING Pushing BLOB sha256:ba7c544469e514f1a9a4dec59ab640540d50992b288adbb34a1a63c45bf19a24
RUNNING Pushing BLOB sha256:15705ab016593987662839b40f5a22fd1032996c90808d4a1371eb46974017d5
Building container configuration : 1.208 ms
BLOB : sha256:eb05f3dbdb543cc610527248690575bacbbcebabe6ecf665b189cf18b541e3ca already exists on registry
Pushing BLOB sha256:eb05f3dbdb543cc610527248690575bacbbcebabe6ecf665b189cf18b541e3ca : 89.462 ms
BLOB : sha256:15705ab016593987662839b40f5a22fd1032996c90808d4a1371eb46974017d5 already exists on registry
Pushing BLOB sha256:15705ab016593987662839b40f5a22fd1032996c90808d4a1371eb46974017d5 : 120.538 ms
Pushing container configuration sha256:71529d335fd983477a62eaf9e1cd37e488c48eb1d9477e09fbd63e37857b251c : 121.327 ms
BLOB : sha256:ba7c544469e514f1a9a4dec59ab640540d50992b288adbb34a1a63c45bf19a24 already exists on registry
Pushing BLOB sha256:ba7c544469e514f1a9a4dec59ab640540d50992b288adbb34a1a63c45bf19a24 : 149.226 ms
RUNNING Pushing new image
Pushing new image : 730.65 ms

> Task :jib
Task ':jib' is not up-to-date because:
  Task has not declared any outputs.

Containerizing application with the following files:

        Dependencies:

                /google/src/cloud/qingyangc/sandbox/google3/experimental/users/qingyangc/sandbox/helloproject/libs/dependency-1.0.0.jar
                /usr/local/google/home/qingyangc/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar
                /usr/local/google/home/qingyangc/.m2/repository/com/google/errorprone/error_prone_annotations/2.1.3/error_prone_annotations-2.1.3.jar
                /usr/local/google/home/qingyangc/.m2/repository/com/google/guava/guava/23.6-jre/guava-23.6-jre.jar
                /usr/local/google/home/qingyangc/.m2/repository/com/google/j2objc/j2objc-annotations/1.1/j2objc-annotations-1.1.jar
                /usr/local/google/home/qingyangc/.m2/repository/org/checkerframework/checker-compat-qual/2.0.0/checker-compat-qual-2.0.0.jar
                /usr/local/google/home/qingyangc/.m2/repository/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14.jar
        Resources:

                /google/src/cloud/qingyangc/sandbox/google3/experimental/users/qingyangc/sandbox/helloproject/build/resources/main/20m.2
                /google/src/cloud/qingyangc/sandbox/google3/experimental/users/qingyangc/sandbox/helloproject/build/resources/main/aklwejflkjawelkfjlkefjlkawejflaweflkwenfkneawklfewnlknaewlgjnlaewkgjklaewgnjlakewnglaekwnglaewngkwengnglkweangklawnglekangwklgnelkngwlknglekwnglkanglkwgnew
                /google/src/cloud/qingyangc/sandbox/google3/experimental/users/qingyangc/sandbox/helloproject/build/resources/main/world2
        Classes:

                /google/src/cloud/qingyangc/sandbox/google3/experimental/users/qingyangc/sandbox/helloproject/build/classes/java/main/com

Pushing image as gcr.io/qingyangc-sandbox/jibgradleimage:67923843946446

RUNNING Building and pushing image
RUNNING Building application layers
Building application layers : 0.382 ms
RUNNING Setting up to push layers
Setting up to push layers : 0.327 ms
Building and pushing image : 1446.819 ms

Container entrypoint set to [java, -cp, /app/libs/*:/app/resources/:/app/classes/, com.test.HelloWorld]

Built and pushed image as gcr.io/qingyangc-sandbox/jibgradleimage:67923843946446

:jib (Thread[Task worker for ':',5,main]) completed. Took 1.468 secs.
```


text:
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LaptopStore.App.App_Start
{
    public static class MapperConfig
    {
        public static void RegisterMappings()
        {
           // Mapper.CreateMap();
        }
    }
}


text:
import * as angular from "angular";
import {moduleName} from "../module-name";
import "pascalprecht.translate";
import {DateTimeUtils} from '../utils/DateTimeUtils';

angular.module(moduleName).directive("kyloTimer",
  ['$interval','$filter', ($interval, $filter) => {
     return {
            restrict: "EA",
            scope: {
                startTime: "=",
                refreshTime: "@",
                truncatedFormat: '=?',
                addAgoSuffix: '=?'
            },
            link: ($scope: any, element: any, attrs: any)=> {

                $scope.truncatedFormat = angular.isDefined($scope.truncatedFormat) ? $scope.truncatedFormat : false;
                $scope.addAgoSuffix = angular.isDefined($scope.addAgoSuffix) ? $scope.addAgoSuffix : false;

                $scope.time = $scope.startTime;
                $scope.previousDisplayStr = '';
                $scope.$watch('startTime', (newVal: any, oldVal: any)=> {
                    $scope.time = $scope.startTime;
                    format();
                })
                format();
                var seconds = 0;
                var minutes = 0;
                var hours = 0;
                var days = 0;
                var months = 0;
                var years = 0;
                if ($scope.refreshTime == undefined) {
                    $scope.refreshTime = 1000;
                }
                function update() {
                    $scope.time += $scope.refreshTime;
                    //format it
                    format();
                }

                function format() {
                    var ms = $scope.time;
                    var displayStr = new DateTimeUtils($filter('translate')).formatMillisAsText(ms,$scope.truncatedFormat,false);
                    if($scope.addAgoSuffix) {
                        displayStr += " ago";
                    }

                    if ($scope.previousDisplayStr == '' || $scope.previousDisplayStr != displayStr) {
                        element.html(displayStr);
                        element.attr('title', displayStr);
                    }
                    $scope.previousDisplayStr = displayStr;

                }

                var interval = $interval(update, $scope.refreshTime);

                var clearInterval = ()=> {
                    $interval.cancel(interval);
                    interval = null;
                }
                $scope.$on('$destroy', ()=> {
                    clearInterval()
                });
            }

        }
  }
  ]);


text:
		Key Risk Indicator (KRI) Form

					<a target="_self" href="<?=$site_url?>/main">Home

					Key Risk Indicator Form

			<form id="input-form" role="form" class="form-horizontal">

						Risk ID

							<input type="text" class="form-control input-sm input-readview" readonly="true" name="risk_library_code" placeholder="" value="<?=$risk['risk_code']?>">

						Risk Event

						<input type="text" class="form-control input-sm input-readview" readonly="true" name="risk_event" placeholder="" value="<?=$risk['risk_event']?>">

						Risk Level

						<input type="text" class="form-control input-sm input-readview" readonly="true" name="risk_level" placeholder="" value="<?=$risk['risk_level_v']?>">

						Risk Treatment

							<input type="text" class="form-control input-sm input-readview" readonly="true" name="risk_treatment" placeholder="" value="<?=$risk['treatment_v']?>">

						Action Plan

									Action Plan
									Due Date
									Action Plan Owner

								<?php foreach ($risk['action_plan_list'] as $key => $value) { ?>

										<?=$value['action_plan']?>
										<?=$value['due_date_v']?>
										<?=$value['division_v']?>

								<?php } ?>

			</form>

			<form id="kri-form" role="form" class="form-horizontal">
			<input type="hidden" name="kri_id" id="kri-id" value="<?=$kri['id']?>"/>
			<input type="hidden" name="risk_id" id="kri-risk-id" value=""/>

					<input type="hidden" name="kri_library_id" value=""/>
					KRI ID

						<input type="text" class="form-control input-sm input-readview" readonly="true" name="kri_library_code" placeholder="" value="<?=$kri['kri_code']?>">

					Key Risk Indicator

					<input type="text" class="form-control input-sm input-readview" readonly="true" name="key_risk_indicator" placeholder="" value="<?=$kri['key_risk_indicator']?>">

					Deadline For Report

					<input type="text" class="form-control input-sm input-readview" readonly="true" name="timing_pelaporan" placeholder="" value="<?=$kri['timing_pelaporan_v']?>">

				<?php if (isset($verifyRac) && $verifyRac) { ?>

					Threshold Description

					<input type="text" class="form-control input-sm input-readview"  name="threshold_description" id="threshold_description" placeholder="" value="">

				<?php } ?>

				<?php if (isset($verifyRac) && $verifyRac) { ?>

					 Threshold

								Operator
								Value 1
								Value 2
								Type Value
								Result

							<?php foreach ($kri['treshold_list'] as $key => $value) { ?>

									<?=$value['operator']?>
									<?=$value['value_1']?>
									<?=$value['value_2']?>
									<?=$value['value_type']?>
									<?=$value['result']?>

							<?php } ?>

				<?php } ?>

				<?php if ($kri['treshold_type'] == 'SELECTION') { ?>

						Response

						<select class="form-control input-sm" id="owner_report" name="owner_report">
							<?php foreach ($kri['treshold_list'] as $key => $value) { ?>
							<option value="<?=$value['value_1']?>" <?=$value['value_1'] == $kri['owner_report'] ? 'SELECTED' : ''?>><?=$value['value_1']?></option>
							<?php } ?>
						</select>

				<?php } else { ?>

						Response

						<select class="form-control input-sm" id="owner_report" name="owner_report">

							<?php foreach ($kri['treshold_list'] as $key => $value) {

							if ($value['value_2'] != null){
								$strip = "-" ;
								}else{
									$strip = "" ;
									}
							if ($value['value_type'] == 'PERCENTAGE'){
								$persen = "%" ;
								}else{
									$persen = "" ;
									}
							if ($value['value_2'] != null && $value['value_type'] == 'PERCENTAGE') {
								$persen2 = "%" ;
								}else{
									$persen2 = "" ;
									}
							 ?>
									PERCENTAGE
							<option value="<?=$value['value_1']?>" <?=$value['value_1'] == $kri['owner_report'] ? 'SELECTED' : ''?>><?=$value['operator']?> <?=$value['value_1']?> <?php echo $persen2 ;?> <?php echo $strip ;?> <?=$value['value_2']?> <?php echo $persen ;?> </option>
							<?php } ?>
						</select>

				<?php } ?>

				Supporting Evidence

				<textarea class="form-control input-sm popovers"  data-container="body" data-placement="bottom" rows="3" name="support" id="support" > <?=$kri['supporting_evidence']?> </textarea>

				<?php if (isset($verifyRac) && $verifyRac) { ?>

				Validation

				<textarea class="form-control input-sm popovers"  data-container="body" data-placement="bottom" rows="3" name="validation" id="validation" ></textarea>

					KRI Warning

					<?php
					if ($kri['kri_warning'] == 'RED'){
					?>

						<img id="warning_img" src="<?=$base_url?>assets/images/legend/kri_<?=strtolower($kri['kri_warning'])?>.gif"/>

					<?php
					}else{
					?>

						<img id="warning_img" src="<?=$base_url?>assets/images/legend/kri_<?=strtolower($kri['kri_warning'])?>.png"/>

					<?php
					}
					?>

				<?php } ?>

				<?php if (isset($verifyRac) && $verifyRac) { ?>
				<button id="kri-button-verify" type="button" class="btn blue"> Verify</button>
				<button type="button" class="btn yellow" id="kri-button-cancel"> Cancel</button>
				<?php } else { ?>
						<?php
							if ($role == 2){
						?>
			<button id="kri-button-verify" type="button" class="btn blue"> Submit</button>
						<?php
							}else{
						?>
				<button id="kri-button-verify" type="button" class="btn blue"> Submit</button>
				<button type="button" class="btn yellow" id="kri-button-cancel"> Cancel</button>
						<?php } ?>

				<?php } ?>

			</form>

<?php if (isset($verifyRac) && $verifyRac) { ?>

<?php } ?>

		<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>

Risk Level

	<?php
	$this->load->database();
	$sql2 = "select * from t_risk where risk_id = (select risk_id from t_kri where id = '$kri_id')";
	$sql2_run = $this->db->query($sql2)->row();
	?>

	Based on validation performed
 Do you consider any changes on current risk level ?

	current impact level = <?php echo $sql2_run->risk_impact_level; ?>

	current likelihood = <?php echo $sql2_run->risk_likelihood_key; ?>

	current risk level = <?php echo $sql2_run->risk_level; ?>

			<form id="modal-category-form" role="form" class="form-horizontal">
				<input type="hidden" name="mode" value="add" />
				<input type="hidden" name="cat_id" value="" />
				<input type="hidden" name="cat_parent" value="0" />

						Impact Level *

								 <input type="hidden" name="risk_impact_level_id" id = "risk_impact_level_id" value=""/>
								<input type="text" class="form-control input-sm" readonly="true" name="risk_impact_level_after_kri" id = "risk_impact_level_after_mitigation" placeholder="">

								<button class="btn btn-primary btn-sm" type="button" id="btn_impact_list"></button>

						Likelihood *

								 <input type="hidden" name="risk_likelihood_id" id = "risk_likelihood_id" value=""/>
								<input type="text" class="form-control input-sm" readonly="true" name="risk_likelihood_key_after_kri" id = "risk_likelihood_key_after_mitigation" placeholder="">

								<button class="btn btn-primary btn-sm" type="button" data-toggle="modal" href="#modal-likelihood"></button>

					    <input type="hidden" name="risk_level_id" id = "risk_level_id" value=""/>
						Risk Level

						<input type="text" class="form-control input-sm" readonly="true" name="risk_level_after_kri" id = "risk_level_after_mitigation" placeholder="">

			</form>

		<button type="button" data-dismiss="modal" class="btn btn-default">Close</button>
		<button id="modal-impactlevel-form-submit" type="button"
			class="btn blue ladda-button"
			 data-style="expand-right"
			>Save</button>

		<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>

Evaluation on Risk Impact

		* Dapat diisi lebih dari satu(1) kategori, namun dalam Satu(1)
		Kategori hanya boleh diisi satu(1) parameter

		<form id="form-impact">

				Category
				Parameter

			<?php $cnt = 0;
				foreach($impact_list['impact'] as $k=>$v) { ?>

					<?=$v?>

							<input type="radio" name="impactlevel_<?=$k?>" value="NA" checked> N/A
							<?php foreach($impact_list['impact_list'][$k] as $key=>$row) { ?>

							<input type="radio" name="impactlevel_<?=$k?>" value="<?=$key?>"> <?=$row?>
							<?php } ?>

			<?php $cnt++; } ?>

		</form>

		<button id="input-form-impact-button" type="button"
			class="btn blue ladda-button"
			 data-style="expand-right"
			>Save</button>

		<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>

Evaluation on Risk Likelihood

		* Pilih Salah Satu

		<form id="form-likelihood">

				Kemungkinan terjadinya resiko
				Deskripsi

			<?php $cnt = 0;
				foreach($likelihood as $row) { ?>

					<input type="radio" name="risk_likelihood" id="likelihood_<?=$row['l_id']?>" value="<?=$row['l_key']?>|<?=$row['l_title']?>" <?=$cnt == 0 ? 'checked' : ''?>>
					<?=$row['l_title']?>
					<?=$row['l_desc']?>

			<?php $cnt++; } ?>

		</form>

		<button id="input-form-likelihood-button" type="button"
			class="btn blue ladda-button"
			 data-style="expand-right"
			>Save</button>


text:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_7_2.xsd"
           version="7.1">

    <context-root>kisoonlineapp</context-root>
    <security-domain>kisoonlineSecurity</security-domain>
<!--    <resource-ref>
        <res-ref-name>jsf/ProjectStage</res-ref-name>
        <res-type>java.lang.String</res-type>
        <jndi-name>java:/env/jsf/ProjectStage</jndi-name>
    </resource-ref>-->
</jboss-web>


text:
package org.apache.hadoop.yarn.server.nodemanager.webapp.dao.gpu;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

/**
 * Temperature of GPU
 */
@InterfaceAudience.Private
@InterfaceStability.Unstable
@XmlRootElement(name = "temperature")
public class PerGpuTemperature {
  private float currentGpuTemp = Float.MIN_VALUE;
  private float maxGpuTemp = Float.MIN_VALUE;
  private float slowThresholdGpuTemp = Float.MIN_VALUE;

  /**
   * Get current celsius GPU temperature
   * @return temperature
   */
  @XmlJavaTypeAdapter(PerGpuDeviceInformation.StrToFloatBeforeSpaceAdapter.class)
  @XmlElement(name = "gpu_temp")
  public Float getCurrentGpuTemp() {
    return currentGpuTemp;
  }

  public void setCurrentGpuTemp(Float currentGpuTemp) {
    this.currentGpuTemp = currentGpuTemp;
  }

  /**
   * Get max possible celsius GPU temperature
   * @return temperature
   */
  @XmlJavaTypeAdapter(PerGpuDeviceInformation.StrToFloatBeforeSpaceAdapter.class)
  @XmlElement(name = "gpu_temp_max_threshold")
  public Float getMaxGpuTemp() {
    return maxGpuTemp;
  }

  public void setMaxGpuTemp(Float maxGpuTemp) {
    this.maxGpuTemp = maxGpuTemp;
  }

  /**
   * Get celsius GPU temperature which could make GPU runs slower
   * @return temperature
   */
  @XmlJavaTypeAdapter(PerGpuDeviceInformation.StrToFloatBeforeSpaceAdapter.class)
  @XmlElement(name = "gpu_temp_slow_threshold")
  public Float getSlowThresholdGpuTemp() {
    return slowThresholdGpuTemp;
  }

  public void setSlowThresholdGpuTemp(Float slowThresholdGpuTemp) {
    this.slowThresholdGpuTemp = slowThresholdGpuTemp;
  }
}


text:
/* tslint:disable:no-unused-variable */
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';
import { AppModule } from '../../../app.module';
import { SidebarComponent } from './sidebar.component';

describe('SidebarComponent', () => {
  let component: SidebarComponent;
  let fixture: ComponentFixture<SidebarComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [ AppModule ],
      providers: [{provide: APP_BASE_HREF, useValue: '/'}]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(SidebarComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});


text:
namespace device {
namespace mojom {
class SerialPortInfo;
}  // namespace mojom
}  // namespace device

class PrefRegistrySimple;
class PrefService;

// This class is used to maintain and interpret the SerialAllowForUrls and
// SerialAllowUsbDevicesForUrls policies.
//
// A PrefChangeRegistrar is used to observe changes to the preference values so
// that the policy can be updated in real-time.
class SerialPolicyAllowedPorts {
 public:
  explicit SerialPolicyAllowedPorts(PrefService* pref_service);
  SerialPolicyAllowedPorts(SerialPolicyAllowedPorts& other) = delete;
  SerialPolicyAllowedPorts& operator=(SerialPolicyAllowedPorts& other) = delete;
  ~SerialPolicyAllowedPorts();

  static void RegisterPrefs(PrefRegistrySimple* registry);

  // Checks if |origin| is allowed to use the port with |port_info|.
  bool HasPortPermission(const url::Origin& origin,
                         const device::mojom::SerialPortInfo& port_info);

  const std::map<std::pair<int, int>, std::set<url::Origin>>&
  usb_device_policy() const {
    return usb_device_policy_;
  }
  const std::map<int, std::set<url::Origin>>& usb_vendor_policy() const {
    return usb_vendor_policy_;
  }
  const std::set<url::Origin>& all_ports_policy() const {
    return all_ports_policy_;
  }

 private:
  void LoadAllowAllPortsForUrlsPolicy();
  void LoadAllowUsbDevicesForUrlsPolicy();

  PrefChangeRegistrar pref_change_registrar_;

  // Stores the current policy configuration for specific USB devices
  // identified by vendor and product IDs (usb_device_policy_), all USB
  // devices from a particular vendor ID (usb_vendor_policy_) and origins
  // which are allowed to access all ports.
  std::map<std::pair<int, int>, std::set<url::Origin>> usb_device_policy_;
  std::map<int, std::set<url::Origin>> usb_vendor_policy_;
  std::set<url::Origin> all_ports_policy_;
};

#endif  // CHROME_BROWSER_SERIAL_SERIAL_POLICY_ALLOWED_PORTS_H_


text:
package com.github.df.restypass.test.service;

import com.github.df.restypass.annotation.RestyMethod;
import com.github.df.restypass.annotation.RestyService;
import com.github.df.restypass.test.entity.Response;
import com.github.df.restypass.test.entity.User;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@RestyService(serviceName = "resty",
        fallbackClass = ProxyServiceImpl.class,
        retry = 1,
        forceBreakEnabled = false
)
@RequestMapping(value = "/resty")
public interface ProxyService extends ApplicationService {

    @RestyMethod
    @RequestMapping(value = "/get_nothing", method = RequestMethod.GET, headers = "Client=RestyProxy", params = "Param1=val1")
    void getNothing();

    @RestyMethod
    @RequestMapping(value = "/get_string", method = RequestMethod.GET)
    String getString();

    @RestyMethod
    @RequestMapping(value = "/get_user", method = RequestMethod.GET)
    User getUser();

    @RestyMethod()
    @RequestMapping(value = "/list")
    List<User> getList();

    @RestyMethod()
    @RequestMapping(value = "/get_age", method = RequestMethod.GET)
    Response<String> getAge(@RequestParam("id") Long id, String code, @PathVariable(value = "name") String name);

    int getHeight(Long id);

    @RestyMethod
    @RequestMapping(value = "/update/{name}", method = RequestMethod.POST)
    String update(@RequestParam("id") Long id, @PathVariable(value = "name") String name, User user);

}


text:
"""
Fractals
--------
Fractals module which groups all the fractals functions and classes.

TODO
----

"""

import numpy as np
from pythonUtils.parallel_tools import distribute_tasks, reshape_limits
from plotting import image_building

class FractalBuilder:
    """Object wihch is able to build a fractal from a iteration in the complex
    plane.

    Example
    -------
    >>> import numpy as np
    >>> from ChaosFunctions.fractals import FractalBuilder, mandelbrot_iter,\
    >>>     p0_mandelbrot
    >>> ns = 1000, 1000
    >>> itermax = 100
    >>> limits = np.array([[-2, .5], [-1.25, 1.25]])
    >>> fb = FractalBuilder(mandelbrot_iter, p0_mandelbrot)
    >>> img = fb.build_fractal(ns, limits, itermax)
    >>> fig = fb.export_fractal(img, 'prueba')

    """

    def __init__(self, iteration, p0_init):
        """Instatiation of the fractal builder.

        Parameters
        ----------
        iteration: function
            the function which iterates from ones state to the next.
        p0_init: function
            the function which creates the initial state.

        """
        self.iter, self.p0_init = iteration, p0_init

    def build_fractal(self, ns, limits, itermax, memlim=None):
        """Main function to build the fractal.

        Parameters
        ----------
        ns: tuple
            ths size of the image.
        limits: np.ndarray
            the matrix of the limits.
        itermax: int
            the maximum number of iterations.
        memlim: int (default=None)
            the information about the limits of memory. It splits the
            computation task in parts in order to save RAM memory.

        Returns
        -------
        img: np.ndarray
            the final 2d state image.

        """
        img = iterator2d(self.iter, self.p0_init, ns, limits, itermax,
                         memlim=None)
        return img

    def export_fractal(self, img, namefile):
        """Export the fractal to a image file.

        Parameters
        ----------
        img: np.ndarray
            the final 2d state image.
        namefile: str
            the name of the file we want to export the image of the fractal.

        Returns
        -------
        fig: matplotlib.pyplot.figure
            the figure object which contains the plot.

        """
        fig = image_building(img, namefile)
        return fig

    def example_mandelbrot(self, ns=None, limits=None, itermax=100,
                           memlim=None):
        """Specific example of the mandelbrot iteration.

        Parameters
        ----------
        ns: tuple (default=None)
            ths size of the image.
        limits: np.ndarray (default=None)
            the matrix of the limits.
        itermax: int (default=100)
            the maximum number of iterations.
        memlim: int (default=None)
            the information about the limits of memory. It splits the
            computation task in parts in order to save RAM memory.

        Returns
        -------
        img: np.ndarray
            the final 2d state image.

        """
        ## 0. Set initial variables
        ns = (1000, 1000) if ns is None else ns
        if limits is None:
            limits = np.array([[-2, .5], [-1.25, 1.25]])
        itermax = 100 if itermax is None else itermax
        ## 1. Build fractal
        img = iterator2d(mandelbrot_iter, p0_mandelbrot, ns, limits,
                         itermax, 1)
        return img

def iterator2d(f, p0_init, ns, limits, itermax, memlim=None):
    """Function to iterate function f in the space determined by limits and ns.
    The maximum number of iterations it is bounded with itermax.

    Parameters
    ----------
    f: function
        the iteration function. 2 parameters, the state and a parameter.
    p0_init: function
        generator of the initial state from which we start the iteration.
    ns: tuple
        ths size of the image.
    limits: np.ndarray
        the matrix of the limits.
    itermax: int
        the maximum number of iterations.
    memlim: int (default=None)
        the information about the limits of memory. It splits the computation
        task in parts in order to save RAM memory.

    Returns
    -------
    img: np.ndarray
        the final 2d state image.

    """
    ## 00. Fragmentation of computation
    if memlim is not None:
        lims = distribute_tasks(ns[0], memlim)
        new_limits = reshape_limits(lims, [limits[0, 0], limits[0, 1]])
        img = np.zeros(ns)
        for i in xrange(len(lims)):
            n_limits = np.array([[new_limits[i][0], new_limits[i][1]],
                                [limits[1, 0], limits[1, 1]]])
            ms = lims[i][1]-lims[i][0]
            img[lims[i][0]:lims[i][1], :] = iterator2d(f, (ms, ns[1]),
                                                       n_limits, itermax)
        return img

    ## 0. Creation of the c complex number vectors
    c, z, ix, iy = p0_init(ns, limits)
    ## 1. Computation of the image
    img = np.zeros(ns, dtype=int)
    for i in xrange(itermax):
        if not len(z):
            break
        z, rem = f(z, c)
        # Add one for the points which have escaped
        img[ix[rem], iy[rem]] = i+1
        # Only use the points which haven't escaped
        rem = -rem
        z = z[rem]
        ix, iy = ix[rem], iy[rem]
        c = c[rem]
    return img

def mandelbrot_iter(z, c):
    """Mandelbrot iteration.

    Parameters
    ----------
    z: np.ndarray
        the state of the system to iterate.
    c: np.ndarray
        the possible complex numbers.

    Returns
    -------
    z: np.ndarray
        the iterated state of the system.
    rem: boolean np.ndarray
        the indices of the escaped points.

    """
    np.multiply(z, z, z)
    np.add(z, c, z)
    # these are the points that have escaped
    rem = np.abs(z) > 2.0
    return z, rem

def julia_iter(z, c):
    """Julia iteration.

    Parameters
    ----------
    z: np.ndarray
        the state of the system to iterate.
    c: np.ndarray
        the possible complex numbers.

    Returns
    -------
    z: np.ndarray
        the iterated state of the system.
    rem: boolean np.ndarray
        the indices of the escaped points.

    """
    z = (z*z) + c
    rem = np.abs(z) > 4.0
    return z, rem

def p0_mandelbrot(ns, limits):
    """Creation of the initial state for the mandelbrot set.

    Parameters
    ----------
    ns: tuple
        ths size of the image.
    limits: np.ndarray
        the matrix of the limits.

    Returns
    -------
    c: np.ndarray
        the possible complex numbers.
    z: np.ndarray
        the state of the system to iterate.
    ix: np.ndarray
        the possible x complex elements.
    iy: np.ndarray
        the possible y complex elements.

    """
    n, m = ns
    xmin, xmax = limits[0, 0], limits[0, 1]
    ymin, ymax = limits[1, 0], limits[1, 1]
    ix, iy = np.mgrid[0:n, 0:m]
    x = np.linspace(xmin, xmax, n)[ix]
    y = np.linspace(ymin, ymax, m)[iy]
    c = x+complex(0, 1)*y
    del x, y
    ix.shape = n*m
    iy.shape = n*m
    c.shape = n*m
    z = np.copy(c)
    return c, z, ix, iy

def p0_julia(ns, limits, parameter=0):
    """Creation of the initial state for the julia set.

    Parameters
    ----------
    ns: tuple
        ths size of the image.
    limits: np.ndarray
        the matrix of the limits.

    Returns
    -------
    c: np.ndarray
        the possible complex numbers.
    z: np.ndarray
        the state of the system to iterate.
    ix: np.ndarray
        the possible x complex elements.
    iy: np.ndarray
        the possible y complex elements.

    """
    n, m = ns
    xmin, xmax = limits[0, 0], limits[0, 1]
    ymin, ymax = limits[1, 0], limits[1, 1]
    ix, iy = np.mgrid[0:n, 0:m]
    x = np.linspace(xmin, xmax, n)[ix]
    y = np.linspace(ymin, ymax, m)[iy]
    z = x+complex(0, 1)*y
    del x, y
    ix.shape = n*m
    iy.shape = n*m
    z.shape = n*m
    c = np.ones(n*m) * parameter
    return c, z, ix, iy


text:
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
// To set up environmental variables, see http://twil.io/secure
$sid = getenv('TWILIO_ACCOUNT_SID');
$token = getenv('TWILIO_AUTH_TOKEN');
$client = new Client($sid, $token);

$members = $client
    ->queues("QU5ef8732a3c49700934481addd5ce1659")
    ->members
    ->read();

// Loop over the list of members and echo a property for each one
foreach ($members as $member) {
    echo $member->position;
}


text:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.PythonTools.Interpreter;
using Microsoft.PythonTools.Repl;

namespace Microsoft.PythonTools.Options {
    public partial class PythonDebugInteractiveOptionsControl : UserControl {

        public PythonDebugInteractiveOptionsControl() {
            InitializeComponent();

            AddToolTips();

#if DEV14_OR_LATER
            _inlinePrompts.Visible = false;
#endif
        }

        internal void EnableUserDefinedPrompts(bool enable) {
            _priPromptLabel.Enabled = _secPromptLabel.Enabled = _secPrompt.Enabled = _priPrompt.Enabled = _useUserDefinedPrompts.Checked = enable;
        }

        internal ReplIntellisenseMode ReplIntellisenseMode {
            get {
                if (_evalNever.Checked) {
                    return ReplIntellisenseMode.NeverEvaluate;
                } else if (_evalNoCalls.Checked) {
                    return ReplIntellisenseMode.DontEvaluateCalls;
                } else if (_evalAlways.Checked) {
                    return ReplIntellisenseMode.AlwaysEvaluate;
                } else {
                    return ReplIntellisenseMode.NeverEvaluate;
                }
            }
            set {
                switch (value) {
                    case ReplIntellisenseMode.AlwaysEvaluate: _evalAlways.Checked = true; break;
                    case ReplIntellisenseMode.DontEvaluateCalls: _evalNoCalls.Checked = true; break;
                    case ReplIntellisenseMode.NeverEvaluate: _evalNever.Checked = true; break;
                }
            }
        }

        private void AddToolTips() {
            const string inlinePromptsToolTip = "When checked the prompts are in the editor buffer.  When unchecked the prompts are on the side in a separate margin.";
            const string useInterpreterPromptsToolTip = "When checked the prompts are the ones configured here.  When unchecked the prompt strings are defined by sys.ps1 and sys.ps2.";
            const string smartReplHistoryToolTip = "Causes the up/down arrow keys to navigate history when the cursor is at the end of an input.";
            const string liveCompletionsToolTip = @"When offering completions don't use values that have come from analysis of the REPL buffer.  Instead, only use values from live objects.";

            _tooltips.SetToolTip(_inlinePrompts, inlinePromptsToolTip);
            _tooltips.SetToolTip(_useUserDefinedPrompts, useInterpreterPromptsToolTip);
            _tooltips.SetToolTip(_smartReplHistory, smartReplHistoryToolTip);
            _tooltips.SetToolTip(_liveCompletionsOnly, liveCompletionsToolTip);
        }

        /// <summary>
        /// Disable/Enable other buttons related to interpreter prompts.
        /// </summary>
        private void _useInterpreterPrompts_CheckedChanged(object sender, EventArgs e) {
            _priPromptLabel.Enabled = _secPromptLabel.Enabled = _secPrompt.Enabled = _priPrompt.Enabled = _useUserDefinedPrompts.Checked;
        }

        internal void SyncControlWithPageSettings(PythonToolsService pyService) {
            _smartReplHistory.Checked = pyService.DebugInteractiveOptions.ReplSmartHistory;
            ReplIntellisenseMode = pyService.DebugInteractiveOptions.ReplIntellisenseMode;
            _inlinePrompts.Checked = pyService.DebugInteractiveOptions.InlinePrompts;
            _priPrompt.Text = pyService.DebugInteractiveOptions.PrimaryPrompt;
            _secPrompt.Text = pyService.DebugInteractiveOptions.SecondaryPrompt;
            EnableUserDefinedPrompts(!pyService.DebugInteractiveOptions.UseInterpreterPrompts);
            _liveCompletionsOnly.Checked = pyService.DebugInteractiveOptions.LiveCompletionsOnly;
        }

        internal void SyncPageWithControlSettings(PythonToolsService pyService) {
            pyService.DebugInteractiveOptions.ReplSmartHistory = _smartReplHistory.Checked;
            pyService.DebugInteractiveOptions.InlinePrompts = _inlinePrompts.Checked;
            pyService.DebugInteractiveOptions.PrimaryPrompt = _priPrompt.Text;
            pyService.DebugInteractiveOptions.SecondaryPrompt = _secPrompt.Text;
            pyService.DebugInteractiveOptions.LiveCompletionsOnly = _liveCompletionsOnly.Checked;
            pyService.DebugInteractiveOptions.UseInterpreterPrompts = !_useUserDefinedPrompts.Checked;
        }
    }
}


text:
<!DOCTYPE html>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Modern Business - Start Bootstrap Template</title>

    <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <link href="css/modern-business.css" rel="stylesheet">

        Start Bootstrap
        <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">

        </button>

                    About

                    Services

                    Contact

                            Portfolio

                        1 Column Portfolio
                        2 Column Portfolio
                        3 Column Portfolio
                        4 Column Portfolio
                        Single Portfolio Item

                            Blog

                        Blog Home 1
                        Blog Home 2
                        Blog Post

                            Other Pages

                        Full Width Page
                        Sidebar Page
                        FAQ
                        404
                        Pricing Table

Pricing Subheading

                Home

Pricing

Basic

$19.99

per month

Cras justo odio

Dapibus ac facilisis in

Vestibulum at eros

Sign Up!

Plus

$39.99

per month

Cras justo odio

Dapibus ac facilisis in

Vestibulum at eros

Sign Up!

Ultra

$159.99

per month

Cras justo odio

Dapibus ac facilisis in

Vestibulum at eros

Sign Up!

Copyright © Your Website 2017


text:
Pattern: Use of modified variable in pipeline subshell

Issue: -

## Description

Variables set in subshells are not available outside the subshell. This is a wide topic, and better described on the [Wooledge Bash Wiki](http://mywiki.wooledge.org/BashFAQ/024).

## Further Reading

* [ShellCheck - SC2030](https://github.com/koalaman/shellcheck/wiki/SC2030)
* [ShellCheck - SC2031](https://github.com/koalaman/shellcheck/wiki/SC2031)


text:
@interface NSDictionary_MergeTests : SenTestCase
@end

@implementation NSDictionary_MergeTests

- (void)testExample {
    NSDictionary *d = @{
                        @"a": @"a",
                        @"b": @"b",
                        };

    NSDictionary *r = [d dictionaryByMergingDictionary:@{
                                                         @"b": @"B",
                                                         @"c": @"c"
                                                         }];

    STAssertTrue([r[@"a"] isEqualToString:@"a"], nil);
    STAssertTrue([r[@"b"] isEqualToString:@"b"], nil);
    STAssertTrue([r[@"c"] isEqualToString:@"c"], nil);
}

@end


text:
package com.intellij.openapi.util.io;

import com.intellij.openapi.util.NlsSafe;
import com.intellij.openapi.util.NotNullLazyValue;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.util.text.Strings;
import com.intellij.util.EnvironmentUtil;
import org.jetbrains.annotations.NotNull;

import java.io.File;

public final class PathExecLazyValue {
  private PathExecLazyValue() {
  }

  public static @NotNull NotNullLazyValue<Boolean> create(@NlsSafe @NotNull String name) {
    if (Strings.containsAnyChar(name, "/\\")) {
      throw new IllegalArgumentException(name);
    }

    return NotNullLazyValue.atomicLazy(() -> {
      String path = EnvironmentUtil.getValue("PATH");
      if (path != null) {
        for (String dir : StringUtil.tokenize(path, File.pathSeparator)) {
          if (new File(dir, name).canExecute()) {
            return true;
          }
        }
      }

      return false;
    });
  }
}


text:
package group.idealworld.dew.test;

import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.testcontainers.containers.DockerComposeContainer;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

public class RocketMQExtension implements BeforeAllCallback {

    private static final Logger LOGGER = LoggerFactory.getLogger(RocketMQExtension.class);

    private static final String DOCKER_COMPOSE = "version: '2'\n" +
            "services:\n" +
            "  namesrv:\n" +
            "    image: apache/rocketmq:4.9.2\n" +
            "    command: sh mqnamesrv\n" +
            "  broker:\n" +
            "    image: apache/rocketmq:4.9.2\n" +
            "    ports:\n" +
            "      - 10909:10909\n" +
            "      - 10911:10911\n" +
            "      - 10912:10912\n" +
            "    command: sh -c 'echo \"brokerIP1 = 127.0.0.1\" > ../conf/broker.conf && ./mqbroker -n namesrv:9876 -c ../conf/broker" +
            ".conf'\n" +
            "    depends_on:\n" +
            "      - namesrv";

    private static final Path TEMP_FILE;

    static {
        try {
            TEMP_FILE = Files.createTempFile(null, null);
            Files.write(TEMP_FILE, DOCKER_COMPOSE.getBytes(StandardCharsets.UTF_8));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * Initializer.
     */
    public static DockerComposeContainer rocketmqContainer =
            new DockerComposeContainer(TEMP_FILE.toFile())
                    .withExposedService("namesrv_1", 9876);

    @Override
    public void beforeAll(ExtensionContext extensionContext) {
        rocketmqContainer.start();
        String nameSrvUrl = rocketmqContainer.getServiceHost("namesrv_1", 9876)
                + ":" +
                rocketmqContainer.getServicePort("namesrv_1", 9876);
        LOGGER.info("Test RocketMQ name server url: " + nameSrvUrl);
    }

    /**
     * Initializer.
     */
    public static class Initializer
            implements ApplicationContextInitializer<ConfigurableApplicationContext> {
        /**
         * Initialize.
         *
         * @param configurableApplicationContext the application context
         */
        public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
            TestPropertyValues.of(
                    "rocketmq.name-server=" + rocketmqContainer.getServiceHost("namesrv_1", 9876)
                            + ":" +
                            rocketmqContainer.getServicePort("namesrv_1", 9876),
                    "rocketmq.producer.group=rocketmq-producer-group",
                    "rocketmq.consumer.group=rocketmq-consumer-group"
            ).applyTo(configurableApplicationContext.getEnvironment());
        }
    }

}


text:
import org.scalatest._

class TestSuite extends FunSuite with Matchers {

  test("hello") {
    Request(
      "GET",
      "http://localhost:8080/hello/James",
      Map.empty,
      None
    ) shouldBe
      Response(
        status = 200,
        Map("Content-Type" -> "text/plain;charset=utf-8"),
        "Hello, James."
      )
  }
}


text:
Chrome Extension [![Build Status](https://travis-ci.org/dnotez/chrome-extension.svg?branch=master)](https://travis-ci.org/dnotez/chrome-extension)
================

Development
========
run

```
gulp
```

test

```
phantomjs test/extension/run.js
```

Release
=======


text:
jest.unmock('../App');

import App from '../App';
import React from 'react';
import { shallow } from 'enzyme';

describe('App', () => {
  it('renders children correctly', () => {
    const wrapper = shallow(
      <App context={{ insertCss: () => {} }}>

      </App>
    );
    expect(wrapper.contains(
)).toBe(true);
  });
});


text:
package androidx.webkit;

import android.os.Handler;
import android.webkit.WebMessagePort;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RequiresFeature;
import androidx.annotation.RestrictTo;

import java.lang.reflect.InvocationHandler;

/**
 *
The Java representation of the
 *
 * HTML5 message ports.
 *
 *
A Message port represents one endpoint of a Message Channel. In Android
 * webview, there is no separate Message Channel object. When a message channel
 * is created, both ports are tangled to each other and started, and then
 * returned in a MessagePort array, see {@link WebViewCompat#createWebMessageChannel}
 * for creating a message channel.
 *
 *
When a message port is first created or received via transfer, it does not
 * have a WebMessageCallback to receive web messages. The messages are queued until
 * a WebMessageCallback is set.
 *
 *
A message port should be closed when it is not used by the embedder application
 * anymore. A closed port cannot be transferred or cannot be reopened to send
 * messages. Close can be called multiple times.
 *
 *
When a port is transferred to JS, it cannot be used to send or receive messages
 * at the Java side anymore. Different from HTML5 Spec, a port cannot be transferred
 * if one of these has ever happened: i. a message callback was set, ii. a message was
 * posted on it. A transferred port cannot be closed by the application, since
 * the ownership is also transferred.
 *
 *
It is possible to transfer both ports of a channel to JS, for example for
 * communication between subframes.
 */
public abstract class WebMessagePortCompat {
    /**
     * The listener for handling MessagePort events. The message callback
     * methods are called on the main thread. If the embedder application
     * wants to receive the messages on a different thread, it can do this
     * by passing a Handler in
     *  {@link WebMessagePortCompat#setWebMessageCallback(Handler, WebMessageCallbackCompat)}.
     * In the latter case, the application should be extra careful for thread safety
     * since WebMessagePort methods should be called on main thread.
     */
    public abstract static class WebMessageCallbackCompat {
        /**
         * Message callback for receiving onMessage events.
         *
         *
This method is called only if {@link WebViewFeature#WEB_MESSAGE_CALLBACK_ON_MESSAGE}
         * is supported. You can check whether that flag is supported using
         * {@link WebViewFeature#isFeatureSupported(String)}.
         *
         * @param port  the WebMessagePort that the message is destined for
         * @param message  the message from the entangled port.
         */
        public void onMessage(@NonNull WebMessagePortCompat port,
                @Nullable WebMessageCompat message) { }
    }

    /**
     * @hide disallow app devs to extend this class.
     */
    @RestrictTo(RestrictTo.Scope.LIBRARY)
    public WebMessagePortCompat() { }

    /**
     * Post a WebMessage to the entangled port.
     *
     *

     * This method should only be called if
     * {@link WebViewFeature#isFeatureSupported(String)}
     * returns true for {@link WebViewFeature#WEB_MESSAGE_PORT_POST_MESSAGE}.
     *
     * @param message  the message from Java to JS.
     *
     * @throws IllegalStateException If message port is already transferred or closed.
     */
    @RequiresFeature(name = WebViewFeature.WEB_MESSAGE_PORT_POST_MESSAGE,
            enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
    public abstract void postMessage(@NonNull WebMessageCompat message);

    /**
     * Close the message port and free any resources associated with it.
     *
     *

     * This method should only be called if
     * {@link WebViewFeature#isFeatureSupported(String)}
     * returns true for {@link WebViewFeature#WEB_MESSAGE_PORT_CLOSE}.
     */
    @RequiresFeature(name = WebViewFeature.WEB_MESSAGE_PORT_CLOSE,
            enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
    public abstract void close();

    /**
     * Sets a callback to receive message events on the main thread.
     *
     *

     * This method should only be called if
     * {@link WebViewFeature#isFeatureSupported(String)}
     * returns true for {@link WebViewFeature#WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK}.
     *
     * @param callback  the message callback.
     */
    @RequiresFeature(name = WebViewFeature.WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK,
            enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
    public abstract void setWebMessageCallback(@NonNull WebMessageCallbackCompat callback);

    /**
     * Sets a callback to receive message events on the handler that is provided
     * by the application. If the handler is null the message events are received on the main
     * thread.
     *
     *

     * This method should only be called if
     * {@link WebViewFeature#isFeatureSupported(String)}
     * returns true for {@link WebViewFeature#WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK}.
     *
     * @param handler   the handler to receive the message events.
     * @param callback  the message callback.
     */
    @RequiresFeature(name = WebViewFeature.WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK,
            enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
    public abstract void setWebMessageCallback(@Nullable Handler handler,
            @NonNull WebMessageCallbackCompat callback);

    /**
     * Internal getter returning the private {@link WebMessagePort} implementing this class. This is
     * only available on devices with an Android versions supporting WebMessagePorts.
     * @hide
     */
    @RequiresApi(23)
    @RestrictTo(RestrictTo.Scope.LIBRARY)
    @NonNull
    public abstract WebMessagePort getFrameworkPort();

    /**
     * Internal getter returning the private {@link java.lang.reflect.InvocationHandler}
     * implementing this class. This is only available on devices where the support library glue in
     * the WebView APK supports {@link WebMessagePortCompat}.
     * @hide
     */
    @NonNull
    @RestrictTo(RestrictTo.Scope.LIBRARY)
    public abstract InvocationHandler getInvocationHandler();

}


text:
This package provides the React shallowCompare add-on.

See <https://facebook.github.io/react/docs/shallow-compare.html> for more information.