You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "mbien (via GitHub)" <gi...@apache.org> on 2024/07/18 20:11:49 UTC

Re: [PR] Support for Payara Server instance running on WSL [netbeans]

mbien commented on code in PR #5736:
URL: https://github.com/apache/netbeans/pull/5736#discussion_r1683416126


##########
enterprise/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/DeployOnSaveManager.java:
##########
@@ -592,7 +602,162 @@ private void runJPDAAppReloaded() {
                 Exceptions.printStackTrace(ex);
             }
         }
-        
+
+        private void distributeOnSave(File destDir, Iterable<Artifact> artifacts) throws IOException {
+
+            try {
+                FileObject destRoot = FileUtil.createFolder(destDir);
+
+                // create target FOs map keyed by relative paths
+                Enumeration<? extends FileObject> destFiles = destRoot.getChildren(true);
+                Map<String, FileObject> destMap = new HashMap<>();
+                int rootPathLen = destRoot.getPath().length();
+                for (; destFiles.hasMoreElements();) {
+                    FileObject destFO = (FileObject) destFiles.nextElement();
+                    destMap.put(destFO.getPath().substring(rootPathLen + 1), destFO);
+                }
+
+                FileObject contentDirectory = destRoot;
+                assert contentDirectory != null;
+
+                for (Artifact artifact : artifacts) {
+                    File fsFile = artifact.getFile();
+                    File altDistFile = artifact.getDistributionPath();
+                    if (altDistFile == null) {
+                        String classes = "target" + File.separator + "classes";
+                        String filePath = artifact.getFile().getPath();
+                        String altDistRelativePath = filePath.substring(filePath.indexOf(classes) + classes.length());
+                        altDistFile = new File(destRoot.getPath() + File.separator + "WEB-INF" + File.separator + "classes" + altDistRelativePath);
+                    }
+
+                    FileObject file = FileUtil.toFileObject(FileUtil.normalizeFile(fsFile));
+
+                    FileObject checkFile = FileUtil.toFileObject(FileUtil.normalizeFile(altDistFile));
+                    if (checkFile == null && file != null) { //#165045
+                        checkFile = FileUtil.createData(altDistFile);
+                    }
+
+                    if (checkFile != null && file != null) {
+                        String relative = FileUtil.getRelativePath(contentDirectory, checkFile);
+                        if (relative != null) {
+                            FileObject targetFO = destMap.get(relative);
+                            if (file.isFolder()) {
+                                destMap.remove(relative);
+                                //continue;
+                            }
+
+                            createOrReplace(file, targetFO, destRoot, relative, destMap, false);
+                        }
+                    } else if (checkFile != null && file == null) {
+                        checkFile.delete();
+                    }
+                }
+
+            } catch (Exception e) {
+                String msg = NbBundle.getMessage(DeployOnSaveManager.class, "MSG_IncrementalDeployFailed", e);
+                throw new RuntimeException(msg, e);
+            }
+        }
+
+        private void createOrReplace(
+                FileObject sourceFO,
+                FileObject targetFO,
+                FileObject destRoot,
+                String relativePath,
+                Map destMap, boolean checkTimeStamps) throws IOException {

Review Comment:
   this would be `Map<String, FileObject> destMap`, right? Please update if possible.



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

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


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

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