This is an automated email from the ASF dual-hosted git repository. jgauravgupta pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new 47f0466 Payara Micro Hot Deploy support in Apache NetBeans (#3248) 47f0466 is described below commit 47f0466f202eb2b0025520e9104f958d967146c2 Author: Gaurav Gupta <gaurav.gu...@payara.fish> AuthorDate: Wed Jan 26 23:25:55 2022 +0530 Payara Micro Hot Deploy support in Apache NetBeans (#3248) * Payara Micro Hot Deploy support in Apache NetBeans * Fixes selectedPayaraVersion NPE --- .../fish/payara/micro/plugin/Constants.java | 1 + .../fish/payara/micro/project/Bundle.properties | 2 + .../payara/micro/project/DeployOnSaveManager.java | 52 +++++++++----- .../payara/micro/project/MicroActionsProvider.java | 20 ++---- .../micro/project/MicroExecutionChecker.java | 3 +- .../payara/micro/project/MicroPropertiesPanel.form | 36 ++++++++-- .../payara/micro/project/MicroPropertiesPanel.java | 41 ++++++++--- .../fish/payara/micro/project/ReloadAction.java | 83 +++++++++++++++++----- 8 files changed, 172 insertions(+), 66 deletions(-) diff --git a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/plugin/Constants.java b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/plugin/Constants.java index c8d6642..7f8b78b 100644 --- a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/plugin/Constants.java +++ b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/plugin/Constants.java @@ -43,6 +43,7 @@ public interface Constants { String PROP_CONTEXT_ROOT = "contextRoot"; String VERSION = "version"; + String HOT_DEPLOY = "hotDeploy"; String WAR_PACKAGING = "war"; diff --git a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/Bundle.properties b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/Bundle.properties index 8f2e73f..aee40ac 100644 --- a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/Bundle.properties +++ b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/Bundle.properties @@ -23,3 +23,5 @@ MSG_IncrementalDeployFailed=Error during incremental deploy\: {0} TXT_Reload=Reload ({0}) ERR_Compile_On_Save_Not_Enabled=Reload Error ({0} : Compile on save not enabled) ERR_Payara_Micro_Plugin_Not_Found=Reload Error ({0} : Payara Micro plugin not found) +MicroPropertiesPanel.hotDeployLabel.text=Hot Deploy: +MicroPropertiesPanel.hotDeployCheckBox.text= diff --git a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/DeployOnSaveManager.java b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/DeployOnSaveManager.java index 53044d2..0bd7796 100644 --- a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/DeployOnSaveManager.java +++ b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/DeployOnSaveManager.java @@ -97,10 +97,9 @@ public final class DeployOnSaveManager { return t; }); - //private final ExecutorService EXECUTOR = Executors.newFixedThreadPool(1); /** <i>GuardedBy("this")</i> */ - private Map<J2eeModuleProvider, Set<Artifact>> toDeploy = new HashMap<>(); + private Map<J2eeModuleProvider, DeployArtifact> toDeploy = new HashMap<>(); /** <i>GuardedBy("this")</i> */ @@ -230,19 +229,16 @@ public final class DeployOnSaveManager { } } - public void submitChangedArtifacts(J2eeModuleProvider provider, Iterable<Artifact> artifacts) { + public void submitChangedArtifacts(Project project, J2eeModuleProvider provider, Iterable<Artifact> artifacts) { assert provider != null; assert artifacts != null; synchronized (this) { - Set<Artifact> preparedArtifacts = toDeploy.get(provider); + DeployArtifact preparedArtifacts = toDeploy.get(provider); if (preparedArtifacts == null) { - preparedArtifacts = new HashSet<>(); + preparedArtifacts = new DeployArtifact(project, artifacts); toDeploy.put(provider, preparedArtifacts); } - for (Artifact artifact : artifacts) { - preparedArtifacts.add(artifact); - } boolean delayed = true; if (current != null && !current.isDone()) { @@ -308,7 +304,7 @@ public final class DeployOnSaveManager { LOGGER.log(Level.FINE, "Delivered compile artifact: {0}", artifact); } } - DeployOnSaveManager.getDefault().submitChangedArtifacts(realProvider, realArtifacts); + DeployOnSaveManager.getDefault().submitChangedArtifacts(realProject, realProvider, realArtifacts); try { current.get(); @@ -354,7 +350,7 @@ public final class DeployOnSaveManager { LOGGER.log(Level.FINE, "Delivered copy artifact: {0}", artifact); } } - DeployOnSaveManager.getDefault().submitChangedArtifacts(realProvider, artifacts); + DeployOnSaveManager.getDefault().submitChangedArtifacts(realProject, realProvider, artifacts); try { current.get(); @@ -367,6 +363,26 @@ public final class DeployOnSaveManager { } } + class DeployArtifact { + + private final Project project; + private final Iterable<Artifact> artifacts; + + public DeployArtifact(Project project, Iterable<Artifact> artifacts) { + this.project = project; + this.artifacts = artifacts; + } + + public Project getProject() { + return project; + } + + public Iterable<Artifact> getArtifacts() { + return artifacts; + } + + } + private class DeployTask implements Runnable { private final boolean delayed; @@ -388,7 +404,7 @@ public final class DeployOnSaveManager { LOGGER.log(Level.FINE, "Performing pending deployments"); - Map<J2eeModuleProvider, Set<Artifact>> deployNow; + Map<J2eeModuleProvider, DeployArtifact> deployNow; Map<J2eeModuleProvider, List<DeployOnSaveListener>> listeners = new HashMap<>(); synchronized (DeployOnSaveManager.this) { if (toDeploy.isEmpty()) { @@ -407,8 +423,8 @@ public final class DeployOnSaveManager { } } - for (Map.Entry<J2eeModuleProvider, Set<Artifact>> entry : deployNow.entrySet()) { - if (entry.getValue().isEmpty()) { + for (Map.Entry<J2eeModuleProvider, DeployArtifact> entry : deployNow.entrySet()) { + if (!entry.getValue().getArtifacts().iterator().hasNext()) { continue; } try { @@ -419,7 +435,7 @@ public final class DeployOnSaveManager { List<DeployOnSaveListener> toFire = listeners.get(entry.getKey()); if (toFire != null) { - toFire.forEach(listener -> listener.deployed(entry.getValue())); + toFire.forEach(listener -> listener.deployed(entry.getValue().getArtifacts())); } } } catch (Throwable t) { @@ -429,10 +445,10 @@ public final class DeployOnSaveManager { } } - private boolean notifyServer(J2eeModuleProvider provider, Iterable<Artifact> artifacts) { + private boolean notifyServer(J2eeModuleProvider provider, DeployArtifact deployArtifact) { if (LOGGER.isLoggable(Level.FINEST)) { StringBuilder builder = new StringBuilder("Artifacts updated: ["); - for (Artifact artifact : artifacts) { + for (Artifact artifact : deployArtifact.getArtifacts()) { builder.append(artifact.getFile().getAbsolutePath()).append(","); } builder.setLength(builder.length() - 1); @@ -442,8 +458,8 @@ public final class DeployOnSaveManager { DeploymentState state; try { - distributeOnSave(FileUtil.toFile(provider.getJ2eeModule().getContentDirectory()), artifacts); - ReloadAction.reloadApplication(provider.getJ2eeModule().getContentDirectory().getPath()); + distributeOnSave(FileUtil.toFile(provider.getJ2eeModule().getContentDirectory()), deployArtifact.getArtifacts()); + ReloadAction.reloadApplication(provider.getJ2eeModule().getContentDirectory().getPath(), deployArtifact); state = DeploymentState.MODULE_UPDATED; } catch (IOException ex) { LOGGER.log(Level.INFO, null, ex); diff --git a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroActionsProvider.java b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroActionsProvider.java index 1846427..6741a8b 100644 --- a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroActionsProvider.java +++ b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroActionsProvider.java @@ -24,30 +24,16 @@ import static org.netbeans.modules.fish.payara.micro.plugin.Constants.PROFILE_SI import static org.netbeans.modules.fish.payara.micro.plugin.Constants.RUN_SINGLE_ACTION; import static org.netbeans.modules.fish.payara.micro.plugin.Constants.WAR_PACKAGING; import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; import java.util.Set; import java.util.prefs.Preferences; import org.netbeans.api.annotations.common.StaticResource; import org.netbeans.api.project.Project; import static org.netbeans.api.project.ProjectUtils.getPreferences; -import static org.netbeans.modules.fish.payara.micro.plugin.Constants.COMPILE_EXPLODE_ACTION; -import static org.netbeans.modules.fish.payara.micro.plugin.Constants.COMPILE_GOAL; -import static org.netbeans.modules.fish.payara.micro.plugin.Constants.DEBUG_ACTION; -import static org.netbeans.modules.fish.payara.micro.plugin.Constants.EXPLODED_GOAL; -import static org.netbeans.modules.fish.payara.micro.plugin.Constants.EXPLODE_ACTION; -import static org.netbeans.modules.fish.payara.micro.plugin.Constants.PROFILE_ACTION; -import static org.netbeans.modules.fish.payara.micro.plugin.Constants.RESOURCES_GOAL; -import static org.netbeans.modules.fish.payara.micro.plugin.Constants.RUN_ACTION; -import static org.netbeans.modules.fish.payara.micro.plugin.Constants.START_GOAL; -import static org.netbeans.modules.fish.payara.micro.plugin.Constants.STOP_ACTION; -import static org.netbeans.modules.fish.payara.micro.plugin.Constants.STOP_GOAL; +import static org.netbeans.modules.fish.payara.micro.plugin.Constants.HOT_DEPLOY; import static org.netbeans.modules.fish.payara.micro.plugin.Constants.VERSION; -import static org.netbeans.modules.fish.payara.micro.plugin.Constants.WAR_GOAL; import org.netbeans.modules.maven.api.NbMavenProject; import org.netbeans.modules.maven.api.execute.RunConfig; import org.netbeans.modules.maven.execute.model.NetbeansActionMapping; -import org.netbeans.modules.maven.j2ee.J2eeActionsProvider; import org.netbeans.modules.maven.spi.actions.AbstractMavenActionsProvider; import org.netbeans.modules.maven.spi.actions.MavenActionsProvider; import static org.netbeans.spi.project.ActionProvider.COMMAND_DEBUG; @@ -106,10 +92,14 @@ public class MicroActionsProvider implements MavenActionsProvider { if (microApplication != null) { Preferences pref = getPreferences(project, MicroApplication.class, true); String microVersionText = pref.get(VERSION, ""); + Boolean hotDeploy = pref.getBoolean(HOT_DEPLOY, false); RunConfig config = actionsProvider.createConfigForDefaultAction(actionName, project, lookup); if (!microVersionText.isEmpty()) { config.setProperty("version.payara", microVersionText); } + if(hotDeploy) { + config.setProperty("hotDeploy", Boolean.TRUE.toString()); + } return config; } return null; diff --git a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroExecutionChecker.java b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroExecutionChecker.java index 871775a..b207923 100644 --- a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroExecutionChecker.java +++ b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroExecutionChecker.java @@ -27,6 +27,7 @@ import static org.netbeans.modules.fish.payara.micro.plugin.Constants.PROFILE_SI import static org.netbeans.modules.fish.payara.micro.plugin.Constants.RUN_SINGLE_ACTION; import java.io.File; import static java.util.Arrays.asList; +import java.util.Collections; import java.util.HashSet; import java.util.Set; import org.netbeans.api.project.Project; @@ -118,7 +119,7 @@ public class MicroExecutionChecker extends ExecutionChecker { String buildPath = application.getMavenProject().getBuild().getDirectory() + File.separator + application.getMavenProject().getBuild().getFinalName(); - ReloadAction.reloadApplication(buildPath); + ReloadAction.reloadApplication(buildPath, null); } diff --git a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroPropertiesPanel.form b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroPropertiesPanel.form index 916c7ae..e92a749 100644 --- a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroPropertiesPanel.form +++ b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroPropertiesPanel.form @@ -37,11 +37,20 @@ <Layout> <DimensionLayout dim="0"> <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" alignment="0" attributes="0"> + <Group type="102" attributes="0"> <EmptySpace max="-2" attributes="0"/> - <Component id="microVersionLabel" min="-2" max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Component id="microVersionLabel" alignment="0" min="-2" max="-2" attributes="0"/> + <Component id="hotDeployLabel" alignment="0" min="-2" max="-2" attributes="0"/> + </Group> <EmptySpace max="-2" attributes="0"/> - <Component id="microVersionCombobox" pref="272" max="32767" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" attributes="0"> + <Component id="hotDeployCheckBox" min="-2" max="-2" attributes="0"/> + <EmptySpace min="0" pref="0" max="32767" attributes="0"/> + </Group> + <Component id="microVersionCombobox" pref="272" max="32767" attributes="0"/> + </Group> <EmptySpace max="-2" attributes="0"/> </Group> </Group> @@ -54,7 +63,12 @@ <Component id="microVersionCombobox" min="-2" max="-2" attributes="0"/> <Component id="microVersionLabel" min="-2" max="-2" attributes="0"/> </Group> - <EmptySpace pref="117" max="32767" attributes="0"/> + <EmptySpace type="unrelated" max="-2" attributes="0"/> + <Group type="103" groupAlignment="0" attributes="0"> + <Component id="hotDeployLabel" min="-2" max="-2" attributes="0"/> + <Component id="hotDeployCheckBox" alignment="0" min="-2" max="-2" attributes="0"/> + </Group> + <EmptySpace pref="85" max="32767" attributes="0"/> </Group> </Group> </DimensionLayout> @@ -74,5 +88,19 @@ </Property> </Properties> </Component> + <Component class="javax.swing.JLabel" name="hotDeployLabel"> + <Properties> + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> + <ResourceString bundle="org/netbeans/modules/fish/payara/micro/project/Bundle.properties" key="MicroPropertiesPanel.hotDeployLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + </Property> + </Properties> + </Component> + <Component class="javax.swing.JCheckBox" name="hotDeployCheckBox"> + <Properties> + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> + <ResourceString bundle="org/netbeans/modules/fish/payara/micro/project/Bundle.properties" key="MicroPropertiesPanel.hotDeployCheckBox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/> + </Property> + </Properties> + </Component> </SubComponents> </Form> diff --git a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroPropertiesPanel.java b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroPropertiesPanel.java index e86808c..9962c6c 100644 --- a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroPropertiesPanel.java +++ b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/MicroPropertiesPanel.java @@ -21,13 +21,13 @@ package org.netbeans.modules.fish.payara.micro.project; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Optional; import java.util.prefs.Preferences; import static java.util.stream.Collectors.toList; import javax.swing.DefaultComboBoxModel; import javax.swing.JPanel; import org.netbeans.api.project.Project; import static org.netbeans.api.project.ProjectUtils.getPreferences; +import static org.netbeans.modules.fish.payara.micro.plugin.Constants.HOT_DEPLOY; import static org.netbeans.modules.fish.payara.micro.plugin.Constants.VERSION; import org.netbeans.modules.maven.api.customizer.ModelHandle2; import org.netbeans.modules.maven.api.customizer.support.ComboBoxUpdater; @@ -41,17 +41,17 @@ import org.netbeans.modules.payara.tooling.data.PayaraPlatformVersionAPI; public class MicroPropertiesPanel extends JPanel { private final Preferences pref; - + private final ComboBoxUpdater<PayaraPlatformVersionAPI> microVersionComboBoxUpdater; - + private PayaraPlatformVersionAPI selectedPayaraVersion; - + public MicroPropertiesPanel(ModelHandle2 handle, Project project) { pref = getPreferences(project, MicroApplication.class, true); initComponents(); String microVersionText = pref.get(VERSION, ""); PayaraPlatformVersionAPI microVersion = PayaraPlatformVersion.toValue(microVersionText); - microVersionComboBoxUpdater = new ComboBoxUpdater<PayaraPlatformVersionAPI>(microVersionCombobox, microVersionLabel) { + microVersionComboBoxUpdater = new ComboBoxUpdater<PayaraPlatformVersionAPI>(microVersionCombobox, microVersionLabel) { @Override public PayaraPlatformVersionAPI getValue() { return microVersion != null ? microVersion : PayaraPlatformVersion.EMPTY; @@ -67,8 +67,9 @@ public class MicroPropertiesPanel extends JPanel { selectedPayaraVersion = microVersion; } }; + hotDeployCheckBox.setSelected(pref.getBoolean(HOT_DEPLOY, false)); } - + private PayaraPlatformVersionAPI[] getPayaraVersion() { List<PayaraPlatformVersionAPI> microVersions = new ArrayList<>(); microVersions.add(PayaraPlatformVersion.EMPTY); @@ -87,20 +88,32 @@ public class MicroPropertiesPanel extends JPanel { microVersionLabel = new javax.swing.JLabel(); microVersionCombobox = new javax.swing.JComboBox(); + hotDeployLabel = new javax.swing.JLabel(); + hotDeployCheckBox = new javax.swing.JCheckBox(); org.openide.awt.Mnemonics.setLocalizedText(microVersionLabel, org.openide.util.NbBundle.getMessage(MicroPropertiesPanel.class, "MicroPropertiesPanel.microVersionLabel.text")); // NOI18N microVersionCombobox.setModel(new DefaultComboBoxModel(getPayaraVersion())); + org.openide.awt.Mnemonics.setLocalizedText(hotDeployLabel, org.openide.util.NbBundle.getMessage(MicroPropertiesPanel.class, "MicroPropertiesPanel.hotDeployLabel.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(hotDeployCheckBox, org.openide.util.NbBundle.getMessage(MicroPropertiesPanel.class, "MicroPropertiesPanel.hotDeployCheckBox.text")); // NOI18N + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() - .addComponent(microVersionLabel) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(microVersionLabel) + .addComponent(hotDeployLabel)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(microVersionCombobox, 0, 272, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(hotDeployCheckBox) + .addGap(0, 0, Short.MAX_VALUE)) + .addComponent(microVersionCombobox, 0, 272, Short.MAX_VALUE)) .addContainerGap()) ); layout.setVerticalGroup( @@ -110,18 +123,24 @@ public class MicroPropertiesPanel extends JPanel { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(microVersionCombobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(microVersionLabel)) - .addContainerGap(117, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(hotDeployLabel) + .addComponent(hotDeployCheckBox)) + .addContainerGap(85, Short.MAX_VALUE)) ); }// </editor-fold>//GEN-END:initComponents - // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox hotDeployCheckBox; + private javax.swing.JLabel hotDeployLabel; private javax.swing.JComboBox microVersionCombobox; private javax.swing.JLabel microVersionLabel; // End of variables declaration//GEN-END:variables public void applyChanges() { - pref.put(VERSION, selectedPayaraVersion.toString()); + pref.put(VERSION, selectedPayaraVersion != null ? selectedPayaraVersion.toString() : ""); + pref.put(HOT_DEPLOY, Boolean.toString(hotDeployCheckBox.isSelected())); } } diff --git a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ReloadAction.java b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ReloadAction.java index 6d31472..7954e77 100644 --- a/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ReloadAction.java +++ b/enterprise/payara.micro/src/org/netbeans/modules/fish/payara/micro/project/ReloadAction.java @@ -20,14 +20,25 @@ package org.netbeans.modules.fish.payara.micro.project; import java.awt.event.ActionEvent; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.prefs.Preferences; import javax.swing.AbstractAction; import org.apache.maven.project.MavenProject; import org.netbeans.api.project.Project; +import static org.netbeans.api.project.ProjectUtils.getPreferences; import static org.netbeans.modules.fish.payara.micro.plugin.Constants.COMPILE_EXPLODE_ACTION; import static org.netbeans.modules.fish.payara.micro.plugin.Constants.EXPLODE_ACTION; +import static org.netbeans.modules.fish.payara.micro.plugin.Constants.HOT_DEPLOY; import static org.netbeans.modules.fish.payara.micro.plugin.Constants.RELOAD_FILE; import static org.netbeans.modules.fish.payara.micro.plugin.Constants.RELOAD_ICON; +import org.netbeans.modules.fish.payara.micro.project.DeployOnSaveManager.DeployArtifact; +import org.netbeans.modules.j2ee.deployment.devmodules.spi.ArtifactListener; import org.netbeans.modules.maven.api.NbMavenProject; import org.netbeans.modules.maven.api.execute.RunUtils; import static org.netbeans.modules.maven.api.execute.RunUtils.isCompileOnSaveEnabled; @@ -39,6 +50,8 @@ import org.openide.awt.ActionReference; import org.openide.awt.ActionReferences; import org.openide.awt.ActionRegistration; import org.openide.awt.StatusDisplayer; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.NbBundle.Messages; @@ -60,12 +73,9 @@ import org.openide.util.Utilities; lazy = true ) @ActionReferences({ - @ActionReference(path = "Menu/BuildProject", position = 55) - , - @ActionReference(path = "Toolbars/Build", position = 325) - , - @ActionReference(path = "Projects/org-netbeans-modules-maven/Actions", position = 1020) - , + @ActionReference(path = "Menu/BuildProject", position = 55), + @ActionReference(path = "Toolbars/Build", position = 325), + @ActionReference(path = "Projects/org-netbeans-modules-maven/Actions", position = 1020), @ActionReference(path = "Shortcuts", name = "DS-A") }) @Messages("CTL_ReloadAppAction=Reload") @@ -81,12 +91,12 @@ public class ReloadAction extends AbstractAction { public void actionPerformed(ActionEvent e) { Lookup context = Utilities.actionsGlobalContext(); Project project = context.lookup(Project.class); - if(project == null) { + if (project == null) { return; } NbMavenProject nbMavenProject = project.getLookup().lookup(NbMavenProject.class); MavenProject mavenProject = nbMavenProject.getMavenProject(); - + MicroApplication microApplication = MicroApplication.getInstance(project); if (microApplication == null) { StatusDisplayer.getDefault() @@ -105,16 +115,55 @@ public class ReloadAction extends AbstractAction { } } - public static void reloadApplication(String buildPath) { - File check = new File(buildPath, RELOAD_FILE); - if (check.exists()) { - check.setLastModified(System.currentTimeMillis()); - } else { - try { - check.createNewFile(); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); + public static void reloadApplication(String buildPath, DeployArtifact deployArtifact) { + try { + boolean metadataChanged = false; + List<String> sourcesChanged = new ArrayList<>(); + FileObject destRoot = FileUtil.createFolder(new File(buildPath)); + if (deployArtifact != null) { + for (ArtifactListener.Artifact artifact : deployArtifact.getArtifacts()) { + File altDistFile = artifact.getDistributionPath(); + FileObject checkFile = FileUtil.toFileObject(FileUtil.normalizeFile(altDistFile)); + String relative = FileUtil.getRelativePath(destRoot, checkFile); + sourcesChanged.add(relative); + if (checkFile.getExt().equals("xml") || checkFile.getExt().equals("properties")) { + metadataChanged = true; + } + } + } + + Preferences pref = getPreferences(deployArtifact.getProject(), MicroApplication.class, true); + Boolean hotDeploy = pref.getBoolean(HOT_DEPLOY, false); + File reloadFile = new File(buildPath, RELOAD_FILE); + if (hotDeploy) { + Properties props = new Properties(); + props.setProperty("hotdeploy", "true"); + if (metadataChanged) { + props.setProperty("metadatachanged", "true"); + } + if (!sourcesChanged.isEmpty()) { + props.setProperty("sourceschanged", String.join(",", sourcesChanged)); + } + try (FileOutputStream outputStrem = new FileOutputStream(reloadFile)) { + props.store(outputStrem, null); + } catch (Exception ex) { + throw new IllegalStateException("Unable to save .reload file " + ex.toString()); + } + } else if (reloadFile.exists()) { + try (PrintWriter pw = new PrintWriter(reloadFile)) { + } catch (FileNotFoundException ex) { + throw new IllegalStateException("Unable to find .reload file " + ex.toString()); + } + reloadFile.setLastModified(System.currentTimeMillis()); + } else { + try { + reloadFile.createNewFile(); + } catch (IOException ex) { + throw new IllegalStateException("Unable to create .reload file " + ex.toString()); + } } + } catch (Exception ex) { + Exceptions.printStackTrace(ex); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists