Skip to content

Commit

Permalink
Merge pull request apache#6872 from matthiasblaesing/followup_6602
Browse files Browse the repository at this point in the history
Wildfly Integration further cleanup after dca223a
  • Loading branch information
matthiasblaesing authored Jan 7, 2024
2 parents b2db3a6 + eef4194 commit 50812d5
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.enterprise.deploy.model.DeployableObject;
Expand Down Expand Up @@ -83,8 +83,8 @@ public class WildflyDeploymentManager implements DeploymentManager2 {
* server instance bcs instance properties are also removed along with
* instance.
*/
private static final ConcurrentMap<InstanceProperties, Boolean> PROPERTIES_TO_IS_RUNNING
= new ConcurrentHashMap(new WeakHashMap());
private static final Map<InstanceProperties, Boolean> PROPERTIES_TO_IS_RUNNING
= Collections.synchronizedMap(new WeakHashMap());

private final DeploymentFactory df;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class WildflyJ2eePlatformFactory extends J2eePlatformFactory {

static final String KODO_JPA_PROVIDER = "kodo.persistence.PersistenceProviderImpl";

private static final WeakHashMap<InstanceProperties, J2eePlatformImplImpl> instanceCache = new WeakHashMap<InstanceProperties, J2eePlatformImplImpl>();
private static final WeakHashMap<InstanceProperties, J2eePlatformImplImpl> instanceCache = new WeakHashMap<>();

@Override
public synchronized J2eePlatformImpl getJ2eePlatformImpl(DeploymentManager dm) {
Expand All @@ -91,7 +91,7 @@ public synchronized J2eePlatformImpl getJ2eePlatformImpl(DeploymentManager dm) {

public static class J2eePlatformImplImpl extends J2eePlatformImpl2 {

private static final Set<Type> MODULE_TYPES = new HashSet<Type>(8);
private static final Set<Type> MODULE_TYPES = new HashSet<>(8);

static {
MODULE_TYPES.add(Type.EAR);
Expand All @@ -101,7 +101,7 @@ public static class J2eePlatformImplImpl extends J2eePlatformImpl2 {
MODULE_TYPES.add(Type.CAR);
}

private static final Set<Profile> WILDFLY_PROFILES = new HashSet<Profile>(16);
private static final Set<Profile> WILDFLY_PROFILES = new HashSet<>(16);

static {
WILDFLY_PROFILES.add(Profile.JAVA_EE_6_WEB);
Expand All @@ -112,21 +112,21 @@ public static class J2eePlatformImplImpl extends J2eePlatformImpl2 {
WILDFLY_PROFILES.add(Profile.JAVA_EE_8_FULL);
WILDFLY_PROFILES.add(Profile.JAKARTA_EE_8_FULL);
}
private static final Set<Profile> JAKARTAEE_FULL_PROFILES = new HashSet<Profile>(8);
private static final Set<Profile> JAKARTAEE_FULL_PROFILES = new HashSet<>(8);

static {
JAKARTAEE_FULL_PROFILES.add(Profile.JAKARTA_EE_9_FULL);
JAKARTAEE_FULL_PROFILES.add(Profile.JAKARTA_EE_9_1_FULL);
JAKARTAEE_FULL_PROFILES.add(Profile.JAKARTA_EE_10_FULL);
}
private static final Set<Profile> EAP6_PROFILES = new HashSet<Profile>(4);
private static final Set<Profile> EAP6_PROFILES = new HashSet<>(4);

static {
EAP6_PROFILES.add(Profile.JAVA_EE_6_WEB);
EAP6_PROFILES.add(Profile.JAVA_EE_6_FULL);
}

private static final Set<Profile> WILDFLY_WEB_PROFILES = new HashSet<Profile>(16);
private static final Set<Profile> WILDFLY_WEB_PROFILES = new HashSet<>(16);

static {
WILDFLY_WEB_PROFILES.add(Profile.JAVA_EE_6_WEB);
Expand All @@ -138,7 +138,7 @@ public static class J2eePlatformImplImpl extends J2eePlatformImpl2 {
WILDFLY_WEB_PROFILES.add(Profile.JAKARTA_EE_10_WEB);
}

private static final Set<Profile> JAKARTAEE_WEB_PROFILES = new HashSet<Profile>(8);
private static final Set<Profile> JAKARTAEE_WEB_PROFILES = new HashSet<>(8);

static {
JAKARTAEE_WEB_PROFILES.add(Profile.JAKARTA_EE_9_WEB);
Expand Down Expand Up @@ -189,7 +189,7 @@ public Set<Type> getSupportedTypes() {

@Override
public Set<String> getSupportedJavaPlatformVersions() {
Set versions = new HashSet();
Set<String> versions = new HashSet<>();
versions.add("1.7"); // NOI18N
versions.add("1.8"); // NOI18N
versions.add("1.8"); // NOI18N
Expand Down Expand Up @@ -334,21 +334,13 @@ String getDefaultJpaProvider() {
}

private boolean containsJaxWsLibraries() {
File[] jaxWsAPILib = new File(properties.getModulePath("org/jboss/ws/api/main")).listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith("jbossws-api") && name.endsWith("jar");
}
}); // NOI18N
File[] jaxWsAPILib = new File(properties.getModulePath("org/jboss/ws/api/main")) // NOI18N
.listFiles((File dir, String name) -> name.startsWith("jbossws-api") && name.endsWith("jar")); // NOI18N
if (jaxWsAPILib != null && jaxWsAPILib.length == 1 && jaxWsAPILib[0].exists()) {
return true;
}
jaxWsAPILib = new File(properties.getModulePath("javax/xml/ws/api/main")).listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith("jboss-jaxws-api") && name.endsWith("jar");
}
}); // NOI18N
jaxWsAPILib = new File(properties.getModulePath("javax/xml/ws/api/main")) // NOI18N
.listFiles((File dir, String name) -> name.startsWith("jboss-jaxws-api") && name.endsWith("jar")); // NOI18N
if (jaxWsAPILib != null && jaxWsAPILib.length == 1 && jaxWsAPILib[0].exists()) {
return true;
}
Expand Down Expand Up @@ -385,6 +377,7 @@ private static boolean containsService(LibraryImplementation library, String ser
return false;
}

@SuppressWarnings("NestedAssignment")
private static boolean containsService(FileObject serviceFO, String serviceName, String serviceImplName) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(serviceFO.getInputStream()))) {
String line;
Expand Down Expand Up @@ -522,7 +515,7 @@ public Lookup getLookup() {
private class JaxRsStackSupportImpl implements JaxRsStackSupportImplementation {

private static final String JAX_RS_APPLICATION_CLASS = "javax.ws.rs.core.Application"; //NOI18N
private J2eePlatformImplImpl j2eePlatform;
private final J2eePlatformImplImpl j2eePlatform;

JaxRsStackSupportImpl(J2eePlatformImplImpl j2eePlatform) {
this.j2eePlatform = j2eePlatform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

import java.awt.Component;
import java.io.File;
import java.util.HashSet;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.swing.event.ChangeEvent;
Expand All @@ -44,25 +43,15 @@ public class AddServerLocationPanel implements WizardDescriptor.FinishablePanel,

private AddServerLocationVisualPanel component;
private WizardDescriptor wizard;
private final transient Set listeners = ConcurrentHashMap.newKeySet(2);
private final transient Set<ChangeListener> listeners = ConcurrentHashMap.newKeySet(2);

public AddServerLocationPanel(WildflyInstantiatingIterator instantiatingIterator) {
this.instantiatingIterator = instantiatingIterator;
}

@Override
public void stateChanged(ChangeEvent ev) {
fireChangeEvent(ev);
}

private void fireChangeEvent(ChangeEvent ev) {
Iterator it;
synchronized (listeners) {
it = new HashSet(listeners).iterator();
}
while (it.hasNext()) {
((ChangeListener) it.next()).stateChanged(ev);
}
new ArrayList<>(listeners).forEach(l -> l.stateChanged(ev));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
package org.netbeans.modules.javaee.wildfly.ide.ui;

import java.io.File;
import java.util.HashSet;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.swing.JFileChooser;
Expand All @@ -30,7 +29,9 @@
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.filechooser.FileFilter;

import static org.netbeans.modules.javaee.wildfly.ide.ui.WildflyPluginUtils.getDefaultConfigurationFile;

import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.util.NbBundle;
Expand All @@ -42,7 +43,7 @@
*/
public class AddServerLocationVisualPanel extends javax.swing.JPanel {

private final Set listeners = ConcurrentHashMap.newKeySet();
private final Set<ChangeListener> listeners = ConcurrentHashMap.newKeySet();

/**
* Creates new form AddServerLocationVisualPanel
Expand Down Expand Up @@ -101,14 +102,8 @@ public void removeChangeListener(ChangeListener l) {
}

private void fireChangeEvent() {
Iterator it;
synchronized (listeners) {
it = new HashSet(listeners).iterator();
}
ChangeEvent ev = new ChangeEvent(this);
while (it.hasNext()) {
((ChangeListener) it.next()).stateChanged(ev);
}
new ArrayList<>(listeners).forEach(l -> l.stateChanged(ev));
}

private void locationChanged() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

import java.awt.Component;
import java.io.File;
import java.util.HashSet;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.swing.event.ChangeEvent;
Expand Down Expand Up @@ -169,20 +168,10 @@ public Component getComponent() {

@Override
public void stateChanged(ChangeEvent ev) {
fireChangeEvent(ev);
new ArrayList<>(listeners).forEach(l -> l.stateChanged(ev));
}

private void fireChangeEvent(ChangeEvent ev) {
Iterator it;
synchronized (listeners) {
it = new HashSet(listeners).iterator();
}
while (it.hasNext()) {
((ChangeListener)it.next()).stateChanged(ev);
}
}

private final transient Set listeners = ConcurrentHashMap.newKeySet(2);
private final transient Set<ChangeListener> listeners = ConcurrentHashMap.newKeySet(2);
@Override
public void removeChangeListener(ChangeListener l) {
listeners.remove(l);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@

import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.util.HashSet;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
Expand All @@ -48,7 +45,7 @@
*/
public class AddServerPropertiesVisualPanel extends JPanel {

private final Set listeners = ConcurrentHashMap.newKeySet();
private final Set<ChangeListener> listeners = ConcurrentHashMap.newKeySet();

private javax.swing.JComboBox domainField; // Domain name (list of registered domains) can be edited
private javax.swing.JTextField domainPathField; //
Expand Down Expand Up @@ -90,14 +87,8 @@ private void somethingChanged() {
}

private void fireChangeEvent() {
Iterator it;
synchronized (listeners) {
it = new HashSet(listeners).iterator();
}
ChangeEvent ev = new ChangeEvent(this);
while (it.hasNext()) {
((ChangeListener)it.next()).stateChanged(ev);
}
new ArrayList<>(listeners).forEach(l -> l.stateChanged(ev));
}

public boolean isLocalServer(){
Expand Down Expand Up @@ -197,12 +188,7 @@ private void init(){
label1 = new JLabel(NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "TXT_PROPERTY_TEXT")); //NOI18N

serverType = new JComboBox(new String[]{"Local","Remote"});//NOI18N
serverType.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
serverTypeChanged();
}
});
serverType.addActionListener((ActionEvent e) -> serverTypeChanged());


domainPathLabel = new JLabel(NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_DomainPath"));//NOI18N
Expand All @@ -221,11 +207,7 @@ public void actionPerformed(ActionEvent e) {
domainField.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_Domain"));
domainField.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_Domain"));

domainField.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
domainChanged();
}
});
domainField.addActionListener((ActionEvent e) -> domainChanged());

domainLabel.setLabelFor(domainField);
org.openide.awt.Mnemonics.setLocalizedText(domainLabel, org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_Domain")); // NOI18N
Expand Down Expand Up @@ -465,7 +447,7 @@ public void actionPerformed(ActionEvent e) {
}


class SomeChangesListener implements KeyListener{
private class SomeChangesListener implements KeyListener{

@Override
public void keyTyped(KeyEvent e){}
Expand All @@ -478,54 +460,6 @@ public void keyPressed(KeyEvent e){}

}

private String browseDomainLocation(){
String insLocation = null;
JFileChooser chooser = getJFileChooser();
int returnValue = chooser.showDialog(this, NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_ChooseButton")); //NOI18N

if(returnValue == JFileChooser.APPROVE_OPTION){
insLocation = chooser.getSelectedFile().getAbsolutePath();
}
return insLocation;
}

private JFileChooser getJFileChooser(){
JFileChooser chooser = new JFileChooser();

chooser.setDialogTitle("LBL_Chooser_Name"); //NOI18N
chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);

chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); //NOI18N
chooser.setMultiSelectionEnabled(false);
chooser.addChoosableFileFilter(new dirFilter());
chooser.setAcceptAllFileFilterUsed(false);
chooser.setApproveButtonToolTipText("LBL_Chooser_Name"); //NOI18N

chooser.getAccessibleContext().setAccessibleName("LBL_Chooser_Name"); //NOI18N
chooser.getAccessibleContext().setAccessibleDescription("LBL_Chooser_Name"); //NOI18N

return chooser;
}

private static class dirFilter extends javax.swing.filechooser.FileFilter {

@Override
public boolean accept(File f) {
if(!f.exists() || !f.canRead() || !f.isDirectory() ) {
return false;
}else{
return true;
}
}

@Override
public String getDescription() {
return NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_DirType"); //NOI18N
}

}

}


Expand Down
Loading

0 comments on commit 50812d5

Please sign in to comment.