Update the JSON file.

@param JsonFile $jsonFile
@param array    $package
@param bool     $isPostInstall
8225
private function updateComposerJson(JsonFile $jsonFile, array $package, $isPostInstall)
    {
        $composerJson = $jsonFile->parse();

        $sortPackages = $this->getOptions()->sortPackages();
        $requireKey = $this->getOptions()->dev() ? 'require-dev' : 'require';
        $removeKey = $this->getOptions()->dev() ? 'require' : 'require-dev';
        $baseRequirements = array_key_exists($requireKey, $composerJson) ? $composerJson[$requireKey] : [];

        if (!$this->updateFileCleanly($jsonFile, $package, $requireKey, $removeKey, $sortPackages, $isPostInstall)) {
            foreach ($package as $name => $version) {
                $baseRequirements[$name] = $version;

                if (isset($composerJson[$removeKey][$name])) {
                    unset($composerJson[$removeKey][$name]);
                }
            }

            $composerJson[$requireKey] = $baseRequirements;
            $jsonFile->dump($composerJson);
        }
    }
2429
private void postPlugin(final boolean isPing) throws IOException {
        String serverVersion = getFullServerVersion();
        int playersOnline = getPlayersOnline();

        // END server software specific section -- all code below does not use any code outside of this class / Java

        // Construct the post data
        StringBuilder json = new StringBuilder(1024);
        json.append('{');

        // The plugin's description file containg all of the plugin data such as name, version, author, etc
        appendJSONPair(json, "guid", guid);
        appendJSONPair(json, "plugin_version", pluginVersion);
        appendJSONPair(json, "server_version", serverVersion);
        appendJSONPair(json, "players_online", Integer.toString(playersOnline));

        // New data as of R6
        String osname = System.getProperty("os.name");
        String osarch = System.getProperty("os.arch");
        String osversion = System.getProperty("os.version");
        String java_version = System.getProperty("java.version");
        int coreCount = Runtime.getRuntime().availableProcessors();

        // normalize os arch .. amd64 -> x86_64
        if (osarch.equals("amd64")) {
            osarch = "x86_64";
        }

        appendJSONPair(json, "osname", osname);
        appendJSONPair(json, "osarch", osarch);
        appendJSONPair(json, "osversion", osversion);
        appendJSONPair(json, "cores", Integer.toString(coreCount));
        // appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
        appendJSONPair(json, "java_version", java_version);

        // If we're pinging, append it
        if (isPing) {
            appendJSONPair(json, "ping", "1");
        }

        if (graphs.size() > 0) {
            synchronized (graphs) {
                json.append(',');
                json.append('"');
                json.append("graphs");
                json.append('"');
                json.append(':');
                json.append('{');

                boolean firstGraph = true;

                final Iterator<Graph> iter = graphs.iterator();

                while (iter.hasNext()) {
                    Graph graph = iter.next();

                    StringBuilder graphJson = new StringBuilder();
                    graphJson.append('{');

                    for (Plotter plotter : graph.getPlotters()) {
                        appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
                    }

                    graphJson.append('}');

                    if (!firstGraph) {
                        json.append(',');
                    }

                    json.append(escapeJSON(graph.getName()));
                    json.append(':');
                    json.append(graphJson);

                    firstGraph = false;
                }

                json.append('}');
            }
        }

        // close json
        json.append('}');

        // Create the url
        URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));

        // Connect to the website
        URLConnection connection;

        // Mineshafter creates a socks proxy, so we can safely bypass it
        // It does not reroute POST requests so we need to go around it
        if (isMineshafterPresent()) {
            connection = url.openConnection(Proxy.NO_PROXY);
        } else {
            connection = url.openConnection();
        }

        byte[] uncompressed = json.toString().getBytes();
        byte[] compressed = gzip(json.toString());

        // Headers
        connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
        connection.addRequestProperty("Content-Type", "application/json");
        connection.addRequestProperty("Content-Encoding", "gzip");
        connection.addRequestProperty("Content-Length", Integer.toString(compressed.length));
        connection.addRequestProperty("Accept", "application/json");
        connection.addRequestProperty("Connection", "close");

        connection.setDoOutput(true);

        if (debug) {
            System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
        }

        // Write the data
        OutputStream os = connection.getOutputStream();
        os.write(compressed);
        os.flush();

        // Now read the response
        final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String response = reader.readLine();

        // close resources
        os.close();
        reader.close();

        if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
            if (response == null) {
                response = "null";
            } else if (response.startsWith("7")) {
                response = response.substring(response.startsWith("7,") ? 2 : 1);
            }

            throw new IOException(response);
        } else {
            // Is this the first update this hour?
            if (response.equals("1") || response.contains("This is your first update this hour")) {
                synchronized (graphs) {
                    final Iterator<Graph> iter = graphs.iterator();

                    while (iter.hasNext()) {
                        final Graph graph = iter.next();

                        for (Plotter plotter : graph.getPlotters()) {
                            plotter.reset();
                        }
                    }
                }
            }
        }
    }
914695
public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        if (false === parent::isInstalled($repo, $package)) {
            return false;
        }

        $targetRoot = $this->getContaoRoot();

        foreach ($this->getSources($package) as $targetPath) {
            if (!file_exists($this->filesystem->normalizePath($targetRoot . '/' . $targetPath))) {
                return false;
            }
        }

        return true;
    }
168879
public function doDownload(PackageInterface $package, $path, $url)
    {
        GitUtil::cleanEnv();
        $path = $this->normalizePath($path);

        if (!$this->isRequiredRepository($path, $url)) {
            throw new FilesystemException('Unknown repository installed into ' . $path);
        }

        $ref = $package->getSourceReference();
        if ($this->io->isVerbose()) {
            $this->io->write('    Multi-repository path: ' . $path);
        }
        if (!$this->isRepositoryCloned($path)) {
            $this->io->write('    Multi-repository GIT directory not found. Cloning...');
            $this->cloneRepository($package, $path, $url);
        } else {
            $this->io->write('    Multi-repository GIT directory found. Fetching changes...');
            $this->fetchRepositoryUpdates($package, $path, $url);
        }

        if ($newRef = $this->updateToCommit($path, $ref, $package->getPrettyVersion(), $package->getReleaseDate())) {
            if ($package->getDistReference() === $package->getSourceReference()) {
                $package->setDistReference($newRef);
            }
            $package->setSourceReference($newRef);
        }

        //copy file into required directory
        $this->copyFilesToDefaultPath($path);
    }
761474
protected function installFromFile()
    {
        if (!file_exists($path = base_path('components.json'))) {
            $this->error("File 'components.json' does not exist in your project root.");

            return;
        }

        $components = Json::make($path);

        $dependencies = $components->get('require', []);

        foreach ($dependencies as $component) {
            $component = collect($component);

            $this->install(
                $component->get('name'),
                $component->get('version'),
                $component->get('type')
            );
        }
    }
1077187
public void updateFile(int fileId, FileUpdate update) {
		getResourceFactory().getApiResource("/file/" + fileId)
				.entity(update, MediaType.APPLICATION_JSON_TYPE).put();
	}
1289907
protected static function updatePackages($dev = true)
    {
        if (! file_exists(base_path('package.json'))) {
            return;
        }

        $configurationKey = $dev ? 'devDependencies' : 'dependencies';

        $packages = json_decode(file_get_contents(base_path('package.json')), true);

        $packages[$configurationKey] = static::updatePackageArray(
            array_key_exists($configurationKey, $packages) ? $packages[$configurationKey] : [],
            $configurationKey
        );

        ksort($packages[$configurationKey]);

        file_put_contents(
            base_path('package.json'),
            json_encode($packages, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT).PHP_EOL
        );
    }
12702
protected function setPatchedPackageData(PackageInterface $package, array $patchesAppliedData)
    {
        $extra = $package->getExtra();
        $extra['patches_applied'] = $patchesAppliedData;
        $package->setExtra($extra);
        $this->composer->getRepositoryManager()->getLocalRepository()->write();
    }
106094
function updateInstalledPackage(updatedPackage) {
   var packageIndex = installedPackages.findIndex(function(element) { 
      return (element.packageName === updatedPackage.packageName); 
   });

   if (packageIndex < 0) {
      packageIndex = installedPackages.length;
      installedPackages.push(updatedPackage);
   } else {
      installedPackages[packageIndex] = updatedPackage;
   }

   fs.writeFileSync(installedPackagesDataFileName, JSON.stringify(installedPackages));
}
922753
public function isPackageExtraneous(PackageInterface $package, $checkInstall = false)
    {
        if ($checkInstall && !$this->isPackageInstalled($package)) {
            return false;
        }

        try {
            $bower = $this->config->getBowerFileContent();
        } catch (RuntimeException $e) { // no bower.json file, package is extraneous
            return true;
        }
        if (!isset($bower['dependencies'])) {
            return true;
        }
        // package is a direct dependencies
        if (isset($bower['dependencies'][$package->getName()])) {
            return false;
        }
        // look for dependencies of dependencies
        foreach ($bower['dependencies'] as $name => $version) {
            $dotBowerJson = $this->filesystem->read($this->config->getInstallDir() . '/' . $name . '/.bower.json');
            $depBower = json_decode($dotBowerJson, true);
            if (isset($depBower['dependencies'][$package->getName()])) {
                return false;
            }
            // look for dependencies of dependencies of dependencies
            if (isset($depBower['dependencies'])) {
                foreach ($depBower['dependencies'] as $name1 => $version1) {
                    $dotBowerJson = $this->filesystem->read($this->config->getInstallDir() . '/' . $name1 . '/.bower.json');
                    $depDepBower = json_decode($dotBowerJson, true);
                    if (isset($depDepBower['dependencies'][$package->getName()])) {
                        return false;
                    }
                }
            }
        }

        return true;
    }
517853
public function update(
        InstalledRepositoryInterface $repo,
        PackageInterface $initial,
        PackageInterface $target
    ) {
        $installPath = $this->getInstallPath($target);
        $junglist = new FileJunglist;
        $junglist->saveModifiedFiles($installPath);
        DebugPrinter::log('Updating package');
        parent::update($repo, $initial, $target);
        DebugPrinter::log('Post-update file rotate');
        $junglist->rotateInstalledFiles($installPath);
        $junglist->restoreModifiedFiles($installPath);
        DebugPrinter::log('Finished updating');
    }
466315
@Override
    public JSONObject post(String path, JSONObject content, Map<String, String> headers)
            throws ServiceException, JSONException {
        String[] segments = getSegments(path);
        if (segments.length == 2) {
            ServiceLocator.getAssetServices().createPackage(segments[1]);
            CacheRegistration.getInstance().refreshCache("PackageCache");
        }
        else if (segments.length == 3) {
            String asset = segments[1] + '/' + segments[2];
            if (segments[2].endsWith(".proc")) {
                try {
                    Query query = getQuery(path, headers);
                    if (query.getFilter("template") == null)
                        query.setFilter("template", "new");
                    ServiceLocator.getWorkflowServices().createProcess(asset, query);
                }
                catch (IOException ex) {
                    throw new ServiceException(ServiceException.INTERNAL_ERROR, ex.getMessage());
                }
            }
            else {
                ServiceLocator.getAssetServices().createAsset(asset);
            }
        }
        else {
            throw new ServiceException(ServiceException.BAD_REQUEST, "Invalid path: " + path);
        }
        return null;
    }
1132445
public function install( Structure $package, array $extra = array() )
    {
        $data = static::loadPackageData();

        if ( empty( $data['require'] ) )
        {
            return false;
        }

        if ( ! empty( $extra ) )
        {
            if ( ! static::mergeJsonData( static::EXTRA_FILE, $extra ) )
            {
                return false;
            }

            $data['extra']['patch-data-file'] = static::EXTRA_FILE;
        }

        $data['require'][$package->name] = '*';
        return static::savePackageData( $data );
    }
1295496
private function updateConfigFile(PackageInterface $package)
    {
        $defaultConfigFile = $this->projectPath . self::DS .
            'App' . self::DS . 'Resource' . self::DS . 'config' . self::DS . 'config.default.php';

        if (is_writeable($defaultConfigFile)) {
            $output = include $defaultConfigFile;
            $bundleConf = [
                'bundles' => [
                    $this->getPackageName($package) => []
                ]
            ];

            $data = array_merge($output, $bundleConf);

            if (false === file_put_contents($defaultConfigFile, '<?php return ' . var_export($data, true) . ';')) {
                throw new RuntimeException(sprintf('Cannot update config file "%s"', $defaultConfigFile));
            }
        }
    }
720370
def update_install_json():
        """"""
        if not os.path.isfile('install.json'):
            return

        with open('install.json', 'r') as f:
            install_json = json.load(f)

        if install_json.get('programMain'):
            install_json['programMain'] = 'run'

        # update features
        install_json['features'] = ['aotExecutionEnabled', 'appBuilderCompliant', 'secureParams']

        with open('install.json', 'w') as f:
            json.dump(install_json, f, indent=2, sort_keys=True)
1125350
public function update()
    {
        foreach ((array) $this->package as $package) {
            $_POST['plugin64'] = $package;
            ob_start();
            plugin_install();
            ob_end_clean();
        }
    }
1058341
function updateSidebar() {

    var sidebarJSONPath = path.resolve(rootDir, srcSidebar);
    const sidebarText = fs.readFileSync(sidebarJSONPath).toString();
    var sidebarJSON = JSON.parse(sidebarText);
    sidebarJSON.docs.Packages = [];

    sidebarEntries
        .map((entry) => sidebarJSON.docs.Packages.push(entry))

    if (dryRun) {
        console.log("In website/sidebars.json, this script updates...\n" +
            "...the Packages array with the filepath to each package's index file.");
    } else {
        fs.writeFile(sidebarJSONPath, JSON.stringify(sidebarJSON, null, 2), 'utf8', (err) => {
            if (err) throw err;
            console.log(chalk.green(`${srcSidebar} was succesfully updated!`));
        }); 
    }

}