jkovalsky commented on a change in pull request #31:
URL: https://github.com/apache/netbeans-tools/pull/31#discussion_r436715580



##########
File path: pp3/module/Application/src/Application/Pp/Catalog.php
##########
@@ -120,7 +205,89 @@ public function storeXml($destinationFolder, $xml) {
         $gz =gzopen($path.'.gz', 'w9');
         gzwrite($gz, $xml);
         gzclose($gz);
-        return true;       
+        return true;
     }
 
+    /**
+     * Update the info XML for the module
+     * 
+     * @param \Application\Entity\PluginVersion $pluginVersion
+     */
+    private function updateInfoXML($pluginVersion) {
+        $sha1Reference = false;
+        $sha256Reference = false;
+
+        foreach ($pluginVersion->getDigests() as $digest) {
+            if ($digest->getAlgorithm() == 'SHA-1') {
+                $sha1Reference = $digest->getValue();
+            } else if ($digest->getAlgorithm() == 'SHA-256') {
+                $sha256Reference = $digest->getValue();
+            }
+        }
+
+        // Skip update if:
+        // - info.xml is present (PP3 assumes immutable sources)
+        // - SHA-256 checksum is present
+        // - artifact size is present
+        if($pluginVersion->getInfoXml() != null && 
$pluginVersion->getArtifactSize() && $sha256Reference) {
+            return;
+        }
+        // Fetch NBM
+        $client = new Client($pluginVersion->getUrl(), array(
+            'maxredirects' => 0,
+            'timeout' => 30
+        ));
+        $response = $client->send();
+        if ($response->isSuccess()) {
+            // Store result to file to make it processible by ZipArchive
+            $archiveFile = tempnam(sys_get_temp_dir(), "mvn-download");
+            $fid = fopen($archiveFile, "w");
+            fwrite($fid, $response->getBody());
+            fclose($fid);
+            $response = null;
+
+            $filesize = filesize($archiveFile);
+            $sha1 = hash_file("sha1", $archiveFile);
+            $sha256 = hash_file("sha256", $archiveFile);
+
+            if(strtolower($sha1) != $sha1Reference) {
+                error_log(sprintf('PluginVersion(id: %d) SHA-1 message digest 
does not match artifact. Expected: %s, Got: %s', $pluginVersion->getId(), 
$sha1Reference, $sha1));
+                return;
+            }
+
+            if(! $sha256Reference) {
+                $pluginVersion->addDigest('SHA-256', $sha256);
+            }
+
+            if(substr(strtolower($pluginVersion->getUrl()), -4) == '.jar') {
+               $execution = self::OSGI_JAR_PARSER . " " . 
escapeshellarg($archiveFile);
+               $return_var = -1;
+               $output = [];
+               exec($execution, $output, $return_var);
+               $outputString = implode("\n", $output);
+               if(intval($return_var) != 0) {
+                   error_log(sprintf('PluginVersion(id: %d) Failed to extract 
info from JAR, Got: %s', $pluginVersion->getId(), $outputString));
+                   return;
+               }
+               $infoXML = $outputString;
+            } else {
+                // Extract Info/info.xml from archive
+                $archive = new ZipArchive();

Review comment:
       Yes, apologies. I am terribly behind with e-mails so I didn't know you 
have already fixed it over the weekend whereas that error was from Friday. 
Great job Matthias/Eric/Antonio!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to