Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source/javadoc attacher must report download actions as enabled. #3029

Merged
merged 2 commits into from Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -244,23 +244,28 @@ static String taskName(Project project, String action, Lookup lkp) {

private static void invokeProjectAction(final Project project, final ActionMapping mapping, Lookup context, boolean showUI) {
GradleExecConfiguration execCfg = ProjectConfigurationSupport.getEffectiveConfiguration(project, context);
ProjectConfigurationSupport.executeWithConfiguration(project, execCfg, () ->
invokeProjectAction2(project, mapping, execCfg, context, showUI));
ProjectConfigurationSupport.executeWithConfiguration(project, execCfg, () -> {
if (!invokeProjectAction2(project, mapping, execCfg, context, showUI)) {
// the caller may wait on the action not knowing that it's not going to be executed at all. Report a failure.
ActionProgress prg = ActionProgress.start(context);
prg.finished(false);
}
});
}

private static void invokeProjectAction2(final Project project, final ActionMapping mapping, final GradleExecConfiguration execCfg, Lookup context, boolean showUI) {
private static boolean invokeProjectAction2(final Project project, final ActionMapping mapping, final GradleExecConfiguration execCfg, Lookup context, boolean showUI) {
final String action = mapping.getName();
if (ActionMapping.isDisabled(mapping)) {
LOG.log(Level.FINE, "Attempt to run a config-disabled action: {0}", action);
return;
return false;
}
if (!ActionToTaskUtils.isActionEnabled(action, project, context)) {
LOG.log(Level.FINE, "Attempt to run action that is not enabled: {0}", action);
return;
return false;
}
String argLine = askInputArgs(mapping.getDisplayName(), mapping.getArgs());
if (argLine == null) {
return;
return false;
}
final StringWriter writer = new StringWriter();
PrintWriter out = new PrintWriter(writer);
Expand All @@ -281,7 +286,7 @@ private static void invokeProjectAction2(final Project project, final ActionMapp
pnl.rememberAs();
cfg = cfg.withCommandLine(pnl.getCommandLine());
} else {
return;
return false;
}
}

Expand Down Expand Up @@ -351,6 +356,7 @@ private static void invokeProjectAction2(final Project project, final ActionMapp
});
});
}
return true;
}

public static Action createCustomGradleAction(Project project, String name, ActionMapping mapping, Lookup context, boolean showUI) {
Expand Down
Expand Up @@ -54,6 +54,17 @@ public class JavaActionProvider extends DefaultGradleActionsProvider {
private static final String GATLING_PLUGIN = "com.github.lkishalmi.gatling"; //NOI18N
private static final String SIMULATION_POSTFIX = "Simulation.scala"; //NOI18N

/**
* Name of the 'download.sources' standard action
*/
public static final String COMMAND_DL_SOURCES = "download.sources"; //NOI18N

/**
* Name of the 'download.javadoc' standard action
*/
public static final String COMMAND_DL_JAVADOC = "download.javadoc"; //NOI18N


private static final String[] SUPPORTED = new String[]{
COMMAND_BUILD,
COMMAND_CLEAN,
Expand All @@ -71,6 +82,9 @@ public class JavaActionProvider extends DefaultGradleActionsProvider {
COMMAND_DEBUG_SINGLE,
COMMAND_COMPILE_SINGLE,
COMMAND_DELETE,

COMMAND_DL_JAVADOC,
COMMAND_DL_SOURCES
};

public JavaActionProvider() {
Expand Down
Expand Up @@ -39,13 +39,15 @@
import org.netbeans.modules.gradle.api.GradleDependency.ModuleDependency;
import org.netbeans.modules.gradle.api.GradleProjects;
import org.netbeans.modules.gradle.api.execute.RunUtils;
import org.netbeans.modules.gradle.java.JavaActionProvider;
import org.netbeans.spi.java.queries.SourceJavadocAttacherImplementation;
import org.netbeans.spi.project.ActionProgress;
import org.netbeans.spi.project.ActionProvider;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.filesystems.URLMapper;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.lookup.Lookups;
import org.openide.util.lookup.ServiceProvider;
Expand All @@ -68,12 +70,12 @@ public class GradleSourceAttacherImpl implements SourceJavadocAttacherImplementa
/**
* Name of the 'download.sources' standard action
*/
private static final String COMMAND_DL_SOURCES = "download.sources"; //NOI18N
private static final String COMMAND_DL_SOURCES = JavaActionProvider.COMMAND_DL_SOURCES;

/**
* Name of the 'download.javadoc' standard action
*/
private static final String COMMAND_DL_JAVADOC = "download.javadoc"; //NOI18N
private static final String COMMAND_DL_JAVADOC = JavaActionProvider.COMMAND_DL_JAVADOC;

/**
* Caches last queried URL. The workflow is to filter Definers that work with the given URL
Expand Down Expand Up @@ -297,11 +299,15 @@ boolean invokeWaitDownloadAction(ActionProvider ap, String command, ModuleDepend
}
// assume the action is invoked asynchronously.
try {
ap.invokeAction(command,
Lookups.fixed(
Lookup ctx = Lookups.fixed(
this,
RunUtils.simpleReplaceTokenProvider(REQUESTED_COMPONENT, dep.getId())
));
);
if (ap.isActionEnabled(command, ctx)) {
// disabled action will not even report action end through the Listener.
return false;
}
ap.invokeAction(command, ctx);
} catch (IllegalArgumentException ex) {
// since we cannot test whether action exists / is enabled, catch the exception
// if the action is really unsupported
Expand Down