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


##########
enterprise/jakarta.transformer/src/org/netbeans/modules/fish/payara/jakarta/transformer/TransformerWizardIterator.java:
##########
@@ -0,0 +1,505 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.fish.payara.jakarta.transformer;
+
+import java.awt.Component;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.List;
+import javax.swing.JComponent;
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectManager;
+import org.netbeans.api.templates.TemplateRegistration;
+import org.netbeans.modules.maven.api.execute.RunUtils;
+import org.netbeans.modules.maven.execute.ModelRunConfig;
+import org.netbeans.modules.maven.execute.model.NetbeansActionMapping;
+import org.netbeans.spi.project.ui.support.ProjectChooser;
+import org.openide.DialogDisplayer;
+import org.openide.NotifyDescriptor;
+import org.openide.WizardDescriptor;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.ImageUtilities;
+import org.openide.util.Lookup;
+import org.openide.util.NbBundle;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.RequestProcessor;
+import org.netbeans.modules.maven.api.archetype.Archetype;
+import org.apache.maven.artifact.versioning.ComparableVersion;
+import org.netbeans.modules.maven.indexer.api.NBVersionInfo;
+import org.netbeans.modules.maven.indexer.api.RepositoryQueries;
+
+public final class TransformerWizardIterator implements 
WizardDescriptor.BackgroundInstantiatingIterator<WizardDescriptor> {
+
+    private int index;
+    private WizardDescriptor.Panel<WizardDescriptor>[] panels;
+    private WizardDescriptor wizardDescriptor;
+    
+    private static final RequestProcessor requestProcessor = 
+            new RequestProcessor(TransformerWizardIterator.class.getName());
+
+    static final Archetype TRANSFORMER_ARCHETYPE;
+    
+    static {
+        TRANSFORMER_ARCHETYPE = new Archetype();
+        
TRANSFORMER_ARCHETYPE.setGroupId(TransformerConstants.PAYARA_TRANSFORMER_GROUP_ID);
+        
TRANSFORMER_ARCHETYPE.setVersion(TransformerConstants.PAYARA_TRANSFORMER_VERSION);
+        
TRANSFORMER_ARCHETYPE.setArtifactId(TransformerConstants.PAYARA_TRANSFORMER_ARTIFACT_ID);
+    }
+
+    public TransformerWizardIterator() {
+    }
+
+    @TemplateRegistration(
+            folder = "Project/Maven2",
+            position=1010,
+            displayName = "#transformer_displayName",
+            description = "transformerDescription.html",
+            iconBase = 
"org/netbeans/modules/fish/payara/jakarta/transformer/JakartaEEIcon.png")
+    @Messages("transformer_displayName=Transform to Jakarta EE 10")
+    public static TransformerWizardIterator createWebAppIterator() {
+        return new TransformerWizardIterator();
+    }
+
+    @SuppressWarnings("rawtypes")
+    private WizardDescriptor.Panel<WizardDescriptor>[] createPanels() {
+        return new WizardDescriptor.Panel[] {new TransformerWizardPanel()};
+    }
+
+    private String[] createSteps() {
+        return new String[]{
+            NbBundle.getMessage(TransformerWizardIterator.class, 
"LBL_CreateProjectStep")
+        };
+    }
+    
+    @Override
+    public Set<FileObject> instantiate() throws IOException {      
+        Set<FileObject> resultSet = new LinkedHashSet<>();
+        //validate condition to identify if the case is to transform a folder 
to a new directory
+        String target = (String)wizardDescriptor.getProperty("targetSelected");
+        String source = (String)wizardDescriptor.getProperty("sourceSelected");
+        boolean override = (Boolean) wizardDescriptor.getProperty("override");
+        NotifyDescriptor notifyDescriptorTarget = new NotifyDescriptor
+                .Message(TransformerConstants.ERROR_MESSAGE_DIALOG_TARGET,
+                NotifyDescriptor.ERROR_MESSAGE);
+        NotifyDescriptor notifyDescriptorSource = new NotifyDescriptor
+                .Message(TransformerConstants.ERROR_MESSAGE_DIALOG_SOURCE,
+                NotifyDescriptor.ERROR_MESSAGE);
+        if(target != null && !target.isEmpty() && source != null && 
!source.isEmpty()) {
+            File targetFile = new File(target);
+            File sourceFile = new File(source);
+            
+            if(!sourceFile.exists()) {
+                DialogDisplayer.getDefault().notify(notifyDescriptorSource);
+            }
+            
+            if(sourceFile.exists() && sourceFile.isDirectory() && 
targetFile.isDirectory()){
+                //calling process to transform folder content to a new location
+                return transformFolderToNewDirectory(resultSet, target, 
source);
+            } else if(sourceFile.exists() && sourceFile.isDirectory() && 
!targetFile.exists()) {
+                DialogDisplayer.getDefault().notify(notifyDescriptorTarget);
+            }
+            
+            //validate condition to identify if the case is to transform a 
file to a new directory
+            if(sourceFile.exists() && sourceFile.isFile() && 
targetFile.isDirectory()) {
+                transformFileToNewDirectory(target, source);
+            } else if(sourceFile.exists() && sourceFile.isFile() && 
!targetFile.exists()) {
+                DialogDisplayer.getDefault().notify(notifyDescriptorTarget);
+            }
+            
+        }
+        
+        //override cases        
+        if(source != null && override) {
+            File sourceFile = new File(source);
+            
+            if(!sourceFile.exists()) {
+                DialogDisplayer.getDefault().notify(notifyDescriptorSource);
+            }
+            
+            //override folder on the same location
+            if(sourceFile.exists() && sourceFile.isDirectory()) {
+                return transformFolderOnSameLocation(resultSet, source);
+            } 
+            
+            //override file on the same location
+            if(sourceFile.exists() && sourceFile.isFile()) {
+                transformFileOnSameLocation(source);
+            }
+        }
+                               
+        return Collections.emptySet();
+    }
+    
+    public void transformFileOnSameLocation(String source) throws IOException {
+        File fileSource = new File(source);
+        File parentDirectory = new File(fileSource.getParent());
+        String pomFilePath = parentDirectory.getAbsolutePath()
+                + File.separator + TransformerConstants.POM_FILE_NAME;
+        File pomFile = new File(pomFilePath);
+        if (parentDirectory.exists() && parentDirectory.isDirectory()) {
+            FileObject directoryObject = 
FileUtil.toFileObject(parentDirectory);
+            if (!pomFile.exists()) {
+                copyTempPomFile(directoryObject);
+            }
+        }
+
+        FileObject p = FileUtil.toFileObject(parentDirectory);
+        if (p != null) {
+            Project project = ProjectManager.getDefault().findProject(p);      
      
+            requestProcessor.post(() -> {
+                NetbeansActionMapping mapping = new NetbeansActionMapping();
+                List<String> goals = new ArrayList<>();
+                
goals.add(getLastTransformerVersionOfPlugin(TRANSFORMER_ARCHETYPE));
+                mapping.setGoals(goals);
+                mapping.setActionName("Transform source");
+                
mapping.addProperty(TransformerConstants.SELECTED_SOURCE_PROPERTY_NAME,
+                        source);
+                
mapping.addProperty(TransformerConstants.SELECTED_TARGET_PROPERTY_NAME,
+                        source);
+                ModelRunConfig rc = new ModelRunConfig(project, mapping,
+                        mapping.getActionName(), null,
+                        Lookup.EMPTY, false);
+                RunUtils.run(rc);
+            });
+
+            requestProcessor.post(() -> {
+                if (pomFile.exists()) {
+                    pomFile.delete();
+                }
+                File folderToDelete = new 
File(parentDirectory.getAbsolutePath()
+                        + File.separator + 
TransformerConstants.TARGET_FOLDER_NAME);
+                deleteFileTree(folderToDelete);
+            }, 8000);

Review Comment:
   why is the second task separate? Can't the first task cleanup the files? 
Waiting a hardcoded amount of time before starting a cleanup is a bit of a red 
flag.
   
   (applies to the other methods too)
   
   The methods are very similar, would be good to make this more D.R.Y. if 
possible. Reuse code etc.



##########
php/php.editor/manifest.mf:
##########
@@ -1,5 +1,6 @@
 Manifest-Version: 1.0
-AutoUpdate-Show-In-Client: false
+AutoUpdate-Show-In-Client: true
+AutoUpdate-Essential-Module: true

Review Comment:
   reverted this since this sounds like a false positive 
https://github.com/apache/netbeans/pull/5847#issuecomment-1546394145



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

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

Reply via email to