IDEA-121819 $MODULE_DIR$ points to directory of the *.iml file

This commit is contained in:
Vassiliy.Kudryashov
2017-07-13 18:02:31 +03:00
parent d21d6e1dd1
commit 1cfc238ae0
8 changed files with 101 additions and 6 deletions
@@ -0,0 +1,30 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.externalSystem.service.project;
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.WorkingDirectoryProvider;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.SystemIndependent;
public class ExternalSystemWorkingDirectoryProvider implements WorkingDirectoryProvider {
@Nullable
@Override
public @SystemIndependent String getWorkingDirectoryPath(Module module) {
return ExternalSystemApiUtil.getExternalProjectPath(module);
}
}
@@ -18,6 +18,7 @@ package com.intellij.execution.ui;
import com.intellij.execution.CommonProgramRunConfigurationParameters;
import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.configuration.EnvironmentVariablesComponent;
import com.intellij.execution.util.ProgramParametersConfigurator;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.application.PathMacros;
@@ -38,6 +39,7 @@ import com.intellij.ui.components.JBList;
import com.intellij.util.ArrayUtil;
import com.intellij.util.PathUtil;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -125,16 +127,17 @@ public class CommonProgramParametersPanel extends JPanel implements PanelWithAnc
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<String> macros = new SmartList<>(PathMacros.getInstance().getUserMacroNames());
List<String> macros = new SmartList<>(ContainerUtil.map(PathMacros.getInstance().getUserMacroNames(), s -> "$" + s + "$"));
if (myModuleContext != null || myHasModuleMacro) {
macros.add(PathMacroUtil.MODULE_DIR_MACRO_NAME);
macros.add("$" + PathMacroUtil.MODULE_DIR_MACRO_NAME + "$");
macros.add(ProgramParametersConfigurator.MODULE_WORKING_DIR);
}
final JList list = new JBList(ArrayUtil.toStringArray(macros));
JBPopupFactory.getInstance().createListPopupBuilder(list).setItemChoosenCallback(() -> {
final Object value = list.getSelectedValue();
if (value instanceof String) {
textAccessor.setText('$' + ((String)value) + '$');
textAccessor.setText((String)value);
}
}).setMovable(false).setResizable(false).createPopup().showUnderneathOf(button);
}
@@ -20,14 +20,19 @@ import com.intellij.execution.configurations.ModuleBasedConfiguration;
import com.intellij.execution.configurations.RuntimeConfigurationWarning;
import com.intellij.execution.configurations.SimpleProgramParameters;
import com.intellij.openapi.components.PathMacroManager;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.WorkingDirectoryProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.EnvironmentUtil;
import com.intellij.util.PathUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.SystemIndependent;
import org.jetbrains.jps.model.serialization.PathMacroUtil;
import java.io.File;
@@ -35,6 +40,10 @@ import java.util.HashMap;
import java.util.Map;
public class ProgramParametersConfigurator {
private static final ExtensionPointName<WorkingDirectoryProvider> WORKING_DIRECTORY_PROVIDER_EP_NAME= ExtensionPointName
.create("com.intellij.module.workingDirectoryProvider");
public static final String MODULE_WORKING_DIR = "%MODULE_WORKING_DIR%";
public void configureConfiguration(SimpleProgramParameters parameters, CommonProgramRunConfigurationParameters configuration) {
Project project = configuration.getProject();
Module module = getModule(configuration);
@@ -68,6 +77,11 @@ public class ProgramParametersConfigurator {
if (("$" + PathMacroUtil.MODULE_DIR_MACRO_NAME + "$").equals(workingDirectory)) {
return defaultWorkingDir;
}
if (module != null && MODULE_WORKING_DIR.equals(workingDirectory)) {
String workingDir = getDefaultWorkingDir(module);
if (workingDir != null) return workingDir;
}
workingDirectory = defaultWorkingDir + "/" + workingDirectory;
}
return workingDirectory;
@@ -78,6 +92,19 @@ public class ProgramParametersConfigurator {
return PathUtil.getLocalPath(project.getBaseDir());
}
@Nullable
protected String getDefaultWorkingDir(@NotNull Module module) {
for (WorkingDirectoryProvider provider : WORKING_DIRECTORY_PROVIDER_EP_NAME.getExtensions()) {
@SystemIndependent String path = provider.getWorkingDirectoryPath(module);
if (path != null) return path;
}
VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
if (roots.length > 0) {
return PathUtil.getLocalPath(roots[0]);
}
return null;
}
public void checkWorkingDirectoryExist(CommonProgramRunConfigurationParameters configuration, Project project, Module module)
throws RuntimeConfigurationWarning {
final String workingDir = getWorkingDir(configuration, project, module);
@@ -0,0 +1,26 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.module;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.SystemIndependent;
public interface WorkingDirectoryProvider {
@Nullable @SystemIndependent
String getWorkingDirectoryPath(Module module);
}
@@ -18,6 +18,7 @@
<projectService serviceImplementation="com.intellij.openapi.externalSystem.service.notification.ExternalSystemNotificationManager"/>
<externalSystemNotificationExtension implementation="com.intellij.openapi.externalSystem.service.notification.ExternalSystemNotificationExtensionImpl" />
<module.workingDirectoryProvider implementation="com.intellij.openapi.externalSystem.service.project.ExternalSystemWorkingDirectoryProvider"/>
<!--Project structure management services-->
<applicationService serviceInterface="com.intellij.openapi.externalSystem.service.project.ProjectDataManager"
serviceImplementation="com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManagerImpl"/>
@@ -868,6 +868,8 @@
<extensionPoint name="moduleRendererFactory" interface="com.intellij.ide.util.ModuleRendererFactory"/>
<extensionPoint name="module.workingDirectoryProvider" interface="com.intellij.openapi.module.WorkingDirectoryProvider"/>
<extensionPoint name="projectStructure.sourceRootEditHandler"
interface="com.intellij.openapi.roots.ui.configuration.ModuleSourceRootEditHandler"/>
@@ -50,6 +50,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -77,7 +78,12 @@ public final class ExecutionHandler {
additionalProperties, antBuildListener, false);
if (result != null) {
try {
return result.get();
long l = System.currentTimeMillis();
try {
return result.get();
} finally {
new Throwable(EventQueue.isDispatchThread() + ": " + (System.currentTimeMillis() - l)).printStackTrace(System.out);
}
}
catch (InterruptedException | java.util.concurrent.ExecutionException e) {
LOG.warn(e);
+2 -2
View File
@@ -24,14 +24,14 @@
<option name="MAIN_CLASS_NAME" />
<option name="VM_PARAMETERS" value="-ea"/>
<option name="PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
<option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
</configuration>
<configuration name="&lt;template&gt;" type="TestNG" default="true" selected="false">
<option name="MAIN_CLASS_NAME"/>
<option name="VM_PARAMETERS" value="-ea"/>
<option name="PARAMETERS"/>
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$"/>
<option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%"/>
</configuration>
<configuration name="&lt;template&gt;" type="Remote" default="true" selected="false">