Skip to content

Commit

Permalink
Merge pull request #13 from unv-unv/unv/execution-refactoring
Browse files Browse the repository at this point in the history
Execution and navigator refactoring
  • Loading branch information
VISTALL authored Oct 5, 2024
2 parents de3d3bf + b8bc8e1 commit fb80c45
Show file tree
Hide file tree
Showing 51 changed files with 6,009 additions and 6,532 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,89 +15,92 @@
*/
package org.jetbrains.idea.maven.execution;

import consulo.ui.annotation.RequiredUIAccess;
import consulo.ui.ex.awt.DialogWrapper;
import consulo.util.lang.Pair;
import consulo.util.collection.ArrayUtil;
import consulo.util.lang.Couple;
import consulo.util.lang.Pair;

import javax.annotation.Nullable;

import javax.swing.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Arrays;
import java.util.Map;

public class EditMavenPropertyDialog extends DialogWrapper
{
private JPanel contentPane;
private JComboBox myNameBox;
private JTextField myValueField;
private final Map<String, String> myAvailableProperties;
public class EditMavenPropertyDialog extends DialogWrapper {
private JPanel contentPane;
private JComboBox myNameBox;
private JTextField myValueField;
private final Map<String, String> myAvailableProperties;

public EditMavenPropertyDialog(@Nullable Pair<String, String> value, Map<String, String> availableProperties) {
super(false);
setTitle(value == null ? "Add Maven Property" : "Edit Maven Property");
public EditMavenPropertyDialog(@Nullable Pair<String, String> value, Map<String, String> availableProperties) {
super(false);
setTitle(value == null ? "Add Maven Property" : "Edit Maven Property");

myAvailableProperties = availableProperties;
myAvailableProperties = availableProperties;

installFocusListeners();
fillAvailableProperties();
installFocusListeners();
fillAvailableProperties();

if (value != null) {
myNameBox.getEditor().setItem(value.getFirst());
myValueField.setText(value.getSecond());
}
if (value != null) {
myNameBox.getEditor().setItem(value.getFirst());
myValueField.setText(value.getSecond());
}

installPropertySelectionListener();
installPropertySelectionListener();

init();
}
init();
}

private void installFocusListeners() {
myNameBox.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
myNameBox.getEditor().selectAll();
}
});
myValueField.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
myValueField.selectAll();
}
});
}
private void installFocusListeners() {
myNameBox.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
myNameBox.getEditor().selectAll();
}
});
myValueField.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
myValueField.selectAll();
}
});
}

private void installPropertySelectionListener() {
myNameBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() != ItemEvent.SELECTED) return;
String key = (String)e.getItem();
String value = myAvailableProperties.get(key);
if (value != null) myValueField.setText(value);
}
});
}
private void installPropertySelectionListener() {
myNameBox.addItemListener(e -> {
if (e.getStateChange() != ItemEvent.SELECTED) {
return;
}
String key = (String)e.getItem();
String value = myAvailableProperties.get(key);
if (value != null) {
myValueField.setText(value);
}
});
}

private void fillAvailableProperties() {
String[] keys = ArrayUtil.toStringArray(myAvailableProperties.keySet());
Arrays.sort(keys);
myNameBox.setModel(new DefaultComboBoxModel(keys));
}
private void fillAvailableProperties() {
String[] keys = ArrayUtil.toStringArray(myAvailableProperties.keySet());
Arrays.sort(keys);
myNameBox.setModel(new DefaultComboBoxModel(keys));
}

@Nullable
protected JComponent createCenterPanel() {
return contentPane;
}
@Nullable
@Override
protected JComponent createCenterPanel() {
return contentPane;
}

@Override
public JComponent getPreferredFocusedComponent() {
return myNameBox;
}
@Override
@RequiredUIAccess
public JComponent getPreferredFocusedComponent() {
return myNameBox;
}

public Pair<String, String> getValue() {
return new Pair<String, String>((String)myNameBox.getEditor().getItem(), myValueField.getText());
}
public Pair<String, String> getValue() {
return Couple.of((String)myNameBox.getEditor().getItem(), myValueField.getText());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,101 +17,151 @@
*/
@SuppressWarnings("AccessStaticViaInstance")
public class MavenArgumentsCompletionProvider extends CommandLineCompletionProvider {
private static final Options ourOptions;

private static final Options ourOptions;
static {
// Copy pasted from org.apache.maven.cli.CLIManager.<init>()

static {
// Copy pasted from org.apache.maven.cli.CLIManager.<init>()
Options options = new Options();
options.addOption(OptionBuilder.withLongOpt("help").withDescription("Display help information").create('h'));
options.addOption(
OptionBuilder.withLongOpt("file")
.hasArg()
.withDescription("Force the use of an alternate POM file (or directory with pom.xml).")
.create('f')
);
options.addOption(OptionBuilder.withLongOpt("define").hasArg().withDescription("Define a system property").create('D'));
options.addOption(OptionBuilder.withLongOpt("offline").withDescription("Work offline").create('o'));
options.addOption(OptionBuilder.withLongOpt("version").withDescription("Display version information").create('v'));
options.addOption(OptionBuilder.withLongOpt("quiet").withDescription("Quiet output - only show errors").create('q'));
options.addOption(OptionBuilder.withLongOpt("debug").withDescription("Produce execution debug output").create('X'));
options.addOption(OptionBuilder.withLongOpt("errors").withDescription("Produce execution error messages").create('e'));
options.addOption(OptionBuilder.withLongOpt("non-recursive").withDescription("Do not recurse into sub-projects").create('N'));
options.addOption(
OptionBuilder.withLongOpt("update-snapshots")
.withDescription("Forces a check for updated releases and snapshots on remote repositories")
.create('U')
);
options.addOption(
OptionBuilder.withLongOpt("activate-profiles")
.withDescription("Comma-delimited list of profiles to activate")
.hasArg()
.create('P')
);
options.addOption(OptionBuilder.withLongOpt("batch-mode").withDescription("Run in non-interactive (batch) mode").create('B'));
options.addOption(OptionBuilder.withLongOpt("no-snapshot-updates").withDescription("Suppress SNAPSHOT updates").create("nsu"));
options.addOption(
OptionBuilder.withLongOpt("strict-checksums").withDescription("Fail the build if checksums don't match").create('C')
);
options.addOption(OptionBuilder.withLongOpt("lax-checksums").withDescription("Warn if checksums don't match").create('c'));
options.addOption(
OptionBuilder.withLongOpt("settings")
.withDescription("Alternate path for the user settings file")
.hasArg()
.create('s')
);
options.addOption(
OptionBuilder.withLongOpt("global-settings")
.withDescription("Alternate path for the global settings file")
.hasArg()
.create("gs")
);
options.addOption(
OptionBuilder.withLongOpt("toolchains")
.withDescription("Alternate path for the user toolchains file")
.hasArg()
.create('t')
);
options.addOption(
OptionBuilder.withLongOpt("fail-fast")
.withDescription("Stop at first failure in reactorized builds")
.create("ff")
);
options.addOption(
OptionBuilder.withLongOpt("fail-at-end")
.withDescription("Only fail the build afterwards; allow all non-impacted builds to continue")
.create("fae"));
options.addOption(
OptionBuilder.withLongOpt("fail-never")
.withDescription("NEVER fail the build, regardless of project result")
.create("fn")
);
options.addOption(
OptionBuilder.withLongOpt("resume-from")
.hasArg()
.withDescription("Resume reactor from specified project")
.create("rf")
);
options.addOption(
OptionBuilder.withLongOpt("projects")
.withDescription(
"Comma-delimited list of specified reactor projects to build instead of all projects. " +
"A project can be specified by [groupId]:artifactId or by its relative path."
)
.hasArg()
.create("pl")
);
options.addOption(
OptionBuilder.withLongOpt("also-make")
.withDescription("If project list is specified, also build projects required by the list")
.create("am")
);
options.addOption(
OptionBuilder.withLongOpt("also-make-dependents")
.withDescription("If project list is specified, also build projects that depend on projects on the list")
.create("amd")
);
options.addOption(
OptionBuilder.withLongOpt("log-file")
.hasArg()
.withDescription("Log file to where all build output will go.")
.create("l")
);
options.addOption(
OptionBuilder.withLongOpt("show-version")
.withDescription("Display version information WITHOUT stopping build")
.create('V')
);
options.addOption(
OptionBuilder.withLongOpt("encrypt-master-password")
.hasArg()
.withDescription("Encrypt master security password")
.create("emp")
);
options.addOption(
OptionBuilder.withLongOpt("encrypt-password")
.hasArg()
.withDescription("Encrypt server password")
.create("ep")
);
options.addOption(
OptionBuilder.withLongOpt("threads")
.hasArg()
.withDescription("Thread count, for instance 2.0C where C is core multiplied")
.create("T")
);

Options options = new Options();
options.addOption(OptionBuilder.withLongOpt("help").withDescription("Display help information").create('h'));
options.addOption(
OptionBuilder.withLongOpt("file").hasArg().withDescription("Force the use of an alternate POM file (or directory with pom.xml).")
.create(
'f'));
options.addOption(OptionBuilder.withLongOpt("define").hasArg().withDescription("Define a system property").create('D'));
options.addOption(OptionBuilder.withLongOpt("offline").withDescription("Work offline").create('o'));
options.addOption(OptionBuilder.withLongOpt("version").withDescription("Display version information").create('v'));
options.addOption(OptionBuilder.withLongOpt("quiet").withDescription("Quiet output - only show errors").create('q'));
options.addOption(OptionBuilder.withLongOpt("debug").withDescription("Produce execution debug output").create('X'));
options.addOption(OptionBuilder.withLongOpt("errors").withDescription("Produce execution error messages").create('e'));
options.addOption(OptionBuilder.withLongOpt("non-recursive").withDescription("Do not recurse into sub-projects").create('N'));
options.addOption(OptionBuilder.withLongOpt("update-snapshots")
.withDescription("Forces a check for updated releases and snapshots on remote repositories").create(
'U'));
options.addOption(
OptionBuilder.withLongOpt("activate-profiles").withDescription("Comma-delimited list of profiles to activate").hasArg().create(
'P'));
options.addOption(OptionBuilder.withLongOpt("batch-mode").withDescription("Run in non-interactive (batch) mode").create('B'));
options.addOption(OptionBuilder.withLongOpt("no-snapshot-updates").withDescription("Suppress SNAPSHOT updates").create("nsu"));
options.addOption(OptionBuilder.withLongOpt("strict-checksums").withDescription("Fail the build if checksums don't match").create(
'C'));
options.addOption(OptionBuilder.withLongOpt("lax-checksums").withDescription("Warn if checksums don't match").create('c'));
options.addOption(OptionBuilder.withLongOpt("settings").withDescription("Alternate path for the user settings file").hasArg().create(
's'));
options.addOption(
OptionBuilder.withLongOpt("global-settings").withDescription("Alternate path for the global settings file").hasArg().create(
"gs"));
options
.addOption(OptionBuilder.withLongOpt("toolchains").withDescription("Alternate path for the user toolchains file").hasArg().create(
't'));
options.addOption(OptionBuilder.withLongOpt("fail-fast").withDescription("Stop at first failure in reactorized builds").create(
"ff"));
options.addOption(
OptionBuilder.withLongOpt("fail-at-end").withDescription("Only fail the build afterwards; allow all non-impacted builds to continue")
.create(
"fae"));
options.addOption(OptionBuilder.withLongOpt("fail-never").withDescription("NEVER fail the build, regardless of project result").create(
"fn"));
options.addOption(OptionBuilder.withLongOpt("resume-from").hasArg().withDescription("Resume reactor from specified project").create(
"rf"));
options.addOption(OptionBuilder.withLongOpt("projects").withDescription(
"Comma-delimited list of specified reactor projects to build instead of all projects. A project can be specified by [groupId]:artifactId or by its relative path.")
.hasArg().create(
"pl"));
options.addOption(
OptionBuilder.withLongOpt("also-make").withDescription("If project list is specified, also build projects required by the list")
.create(
"am"));
options.addOption(OptionBuilder.withLongOpt("also-make-dependents")
.withDescription("If project list is specified, also build projects that depend on projects on the list").create(
"amd"));
options.addOption(OptionBuilder.withLongOpt("log-file").hasArg().withDescription("Log file to where all build output will go.").create(
"l"));
options
.addOption(OptionBuilder.withLongOpt("show-version").withDescription("Display version information WITHOUT stopping build").create(
'V'));
options
.addOption(OptionBuilder.withLongOpt("encrypt-master-password").hasArg().withDescription("Encrypt master security password").create(
"emp"));
options.addOption(OptionBuilder.withLongOpt("encrypt-password").hasArg().withDescription("Encrypt server password").create(
"ep"));
options.addOption(
OptionBuilder.withLongOpt("threads").hasArg().withDescription("Thread count, for instance 2.0C where C is core multiplied").create(
"T"));
ourOptions = options;
}

ourOptions = options;
}
private volatile List<LookupElement> myCachedElements;
private final Project myProject;

private volatile List<LookupElement> myCachedElements;
private final Project myProject;

public MavenArgumentsCompletionProvider(@Nonnull Project project) {
super(ourOptions);
myProject = project;
}

public MavenArgumentsCompletionProvider(@Nonnull Project project) {
super(ourOptions);
myProject = project;
}
@Override
protected void addArgumentVariants(@Nonnull CompletionResultSet result) {
List<LookupElement> cachedElements = myCachedElements;
if (cachedElements == null) {
cachedElements = MavenUtil.getPhaseVariants(MavenProjectsManager.getInstance(myProject));

@Override
protected void addArgumentVariants(@Nonnull CompletionResultSet result) {
List<LookupElement> cachedElements = myCachedElements;
if (cachedElements == null) {
cachedElements = MavenUtil.getPhaseVariants(MavenProjectsManager.getInstance(myProject));
myCachedElements = cachedElements;
}

myCachedElements = cachedElements;
result.addAllElements(cachedElements);
}

result.addAllElements(cachedElements);

}
}
Loading

0 comments on commit fb80c45

Please sign in to comment.