@Override
 protected RunnerAndConfigurationSettings findExistingByElement(
     Location location,
     @NotNull List<RunnerAndConfigurationSettings> existingConfigurations,
     ConfigurationContext context) {
   for (RunnerAndConfigurationSettings existingConfiguration : existingConfigurations) {
     final RunConfiguration configuration = existingConfiguration.getConfiguration();
     final GroovyScriptRunConfiguration existing = (GroovyScriptRunConfiguration) configuration;
     final String path = existing.getScriptPath();
     if (path != null) {
       final PsiFile file = location.getPsiElement().getContainingFile();
       if (file instanceof GroovyFile) {
         final VirtualFile vfile = file.getVirtualFile();
         if (vfile != null && FileUtil.toSystemIndependentName(path).equals(vfile.getPath())) {
           if (!((GroovyFile) file).isScript()
               || GroovyScriptTypeDetector.getScriptType((GroovyFile) file)
                   .isConfigurationByLocation(existing, location)) {
             return existingConfiguration;
           }
         }
       }
     }
   }
   return null;
 }
コード例 #2
0
 @Override
 public void tuneConfiguration(
     @NotNull GroovyFile file,
     @NotNull GroovyScriptRunConfiguration configuration,
     Location location) {
   List<String> tasks = getTasksTarget(location);
   if (tasks != null) {
     String s = StringUtil.join(tasks, " ");
     configuration.setScriptParameters(s);
     configuration.setName("gradle:" + s);
   }
   RunManagerEx.disableTasks(
       file.getProject(),
       configuration,
       CompileStepBeforeRun.ID,
       CompileStepBeforeRunNoErrorCheck.ID);
 }
コード例 #3
0
  @Override
  public boolean isConfigurationByLocation(
      @NotNull GroovyScriptRunConfiguration existing, @NotNull Location location) {
    final String params = existing.getScriptParameters();
    if (params == null) {
      return false;
    }

    final List<String> tasks = getTasksTarget(location);
    if (tasks == null) {
      return false;
    }

    String s = StringUtil.join(tasks, " ");
    return params.startsWith(s + " ") || params.equals(s);
  }
  @Nullable
  private RunnerAndConfigurationSettings createConfiguration(final PsiClass aClass) {
    final Project project = aClass.getProject();
    RunnerAndConfigurationSettings settings =
        RunManagerEx.getInstanceEx(project).createConfiguration("", getConfigurationFactory());
    final GroovyScriptRunConfiguration configuration =
        (GroovyScriptRunConfiguration) settings.getConfiguration();
    final PsiFile file = aClass.getContainingFile().getOriginalFile();
    final PsiDirectory dir = file.getContainingDirectory();
    if (dir == null) return null;
    configuration.setWorkDir(dir.getVirtualFile().getPath());
    final VirtualFile vFile = file.getVirtualFile();
    if (vFile == null) return null;
    configuration.setScriptPath(vFile.getPath());
    RunConfigurationModule module = configuration.getConfigurationModule();

    String name = getConfigurationName(aClass, module);
    configuration.setName(name);
    configuration.setModule(JavaExecutionUtil.findModule(aClass));
    return settings;
  }