├── .travis.yml
├── .tool-versions
├── gradle.properties
├── lib
├── maven
│ ├── maven.jar
│ ├── resources_en.jar
│ ├── maven-server-api.jar
│ ├── maven2-server-impl.jar
│ └── maven30-server-impl.jar
├── ant
│ ├── ant-jps-plugin.jar
│ ├── antIntegration.jar
│ └── resources_en.jar
├── properties
│ └── properties.jar
└── netty
│ └── netty-all-4.1.0.Beta3.jar
├── src
├── test
│ ├── resources
│ │ ├── noroottag.launch
│ │ ├── unknown.launch
│ │ ├── workbench.launch
│ │ ├── remote.launch
│ │ ├── arguments.launch
│ │ ├── arguments-withnewline.launch
│ │ ├── directory.launch
│ │ ├── tool.launch
│ │ ├── newline.launch
│ │ ├── workspace.launch
│ │ ├── env.launch
│ │ ├── ant-github.launch
│ │ ├── java.launch
│ │ ├── maven.launch
│ │ ├── resolve.launch
│ │ ├── maven-absolute.launch
│ │ ├── maven-project-loc.launch
│ │ ├── maven-relative.launch
│ │ ├── java-wd.launch
│ │ ├── xml
│ │ │ └── build.xml
│ │ ├── notypeattribute.launch
│ │ ├── ant.launch
│ │ ├── invalidroottag.launch
│ │ ├── valid.launch
│ │ └── junit.launch
│ └── java
│ │ └── com
│ │ └── kukido
│ │ └── eclipser
│ │ ├── configuration
│ │ ├── Maven2ConfigurationTest.java
│ │ ├── ConfigurationTypeTest.java
│ │ └── ConfigurationBuilderTest.java
│ │ ├── command
│ │ ├── AddExternalToolCommandTest.java
│ │ ├── AddAntTargetCommandTest.java
│ │ ├── AddMaven2ConfigurationCommandTest.java
│ │ ├── AddRemoteJavaApplicationCommandTest.java
│ │ └── AddApplicationConfigurationCommandTest.java
│ │ └── EclipserActionTest.java
└── main
│ ├── resources
│ ├── images
│ │ └── eclipser.gif
│ └── META-INF
│ │ └── plugin.xml
│ └── java
│ └── com
│ └── kukido
│ └── eclipser
│ ├── EclipserException.java
│ ├── command
│ ├── Command.java
│ ├── AddMaven2ConfigurationCommand.java
│ ├── AddRemoteJavaApplicationCommand.java
│ ├── AddApplicationConfigurationCommand.java
│ ├── AddAntTargetCommand.java
│ └── AddExternalToolCommand.java
│ ├── configuration
│ ├── Configuration.java
│ ├── AntTargetConfiguration.java
│ ├── ExternalToolConfiguration.java
│ ├── RemoteJavaApplicationConfiguration.java
│ ├── ConfigurationType.java
│ ├── JavaConfiguration.java
│ ├── Maven2Configuration.java
│ └── ConfigurationBuilder.java
│ ├── icons
│ └── EclipserIcons.java
│ ├── EclipserFileType.java
│ ├── EclipserXml.java
│ └── EclipserAction.java
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── README.md
├── gradlew.bat
├── gradlew
└── LICENSE
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 |
--------------------------------------------------------------------------------
/.tool-versions:
--------------------------------------------------------------------------------
1 | java temurin-17.0.3+7
2 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | kotlin.stdlib.default.dependency = false
2 |
--------------------------------------------------------------------------------
/lib/maven/maven.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kukido/eclipser/HEAD/lib/maven/maven.jar
--------------------------------------------------------------------------------
/src/test/resources/noroottag.launch:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lib/ant/ant-jps-plugin.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kukido/eclipser/HEAD/lib/ant/ant-jps-plugin.jar
--------------------------------------------------------------------------------
/lib/ant/antIntegration.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kukido/eclipser/HEAD/lib/ant/antIntegration.jar
--------------------------------------------------------------------------------
/lib/ant/resources_en.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kukido/eclipser/HEAD/lib/ant/resources_en.jar
--------------------------------------------------------------------------------
/lib/maven/resources_en.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kukido/eclipser/HEAD/lib/maven/resources_en.jar
--------------------------------------------------------------------------------
/lib/maven/maven-server-api.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kukido/eclipser/HEAD/lib/maven/maven-server-api.jar
--------------------------------------------------------------------------------
/lib/properties/properties.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kukido/eclipser/HEAD/lib/properties/properties.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | out
3 | .idea\/workspace.xml
4 | eclipser.jar
5 | .idea
6 | build/
7 | .gradle
8 | *.iml
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kukido/eclipser/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/lib/maven/maven2-server-impl.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kukido/eclipser/HEAD/lib/maven/maven2-server-impl.jar
--------------------------------------------------------------------------------
/lib/maven/maven30-server-impl.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kukido/eclipser/HEAD/lib/maven/maven30-server-impl.jar
--------------------------------------------------------------------------------
/lib/netty/netty-all-4.1.0.Beta3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kukido/eclipser/HEAD/lib/netty/netty-all-4.1.0.Beta3.jar
--------------------------------------------------------------------------------
/src/main/resources/images/eclipser.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kukido/eclipser/HEAD/src/main/resources/images/eclipser.gif
--------------------------------------------------------------------------------
/src/test/resources/unknown.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/EclipserException.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser;
2 |
3 | public class EclipserException extends Exception {
4 | public EclipserException(String s) {
5 | super(s);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/test/resources/workbench.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
4 | networkTimeout=10000
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/command/Command.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.command;
2 |
3 | import com.intellij.openapi.project.Project;
4 | import com.kukido.eclipser.EclipserException;
5 |
6 | public interface Command {
7 | public void execute(Project project) throws EclipserException;
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/configuration/Configuration.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.configuration;
2 |
3 | import com.kukido.eclipser.EclipserException;
4 | import com.kukido.eclipser.command.Command;
5 |
6 | public interface Configuration {
7 | public Command getCommand() throws EclipserException;
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/icons/EclipserIcons.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.icons;
2 |
3 | import com.intellij.openapi.util.IconLoader;
4 |
5 | import javax.swing.*;
6 |
7 | public class EclipserIcons {
8 |
9 | private static final String ECLIPSER_ICON_PATH = "/images/eclipser.gif";
10 |
11 | private static Icon load() {
12 | return IconLoader.getIcon(ECLIPSER_ICON_PATH, EclipserIcons.class);
13 | }
14 |
15 | public static final Icon Launch = load();
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/test/resources/remote.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/test/resources/arguments.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/test/java/com/kukido/eclipser/configuration/Maven2ConfigurationTest.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.configuration;
2 |
3 | import com.intellij.testFramework.LightIdeaTestCase;
4 | import com.kukido.eclipser.EclipserException;
5 |
6 | public class Maven2ConfigurationTest extends LightIdeaTestCase {
7 |
8 | public void testGetCommandWithMavenPluginDisabled() throws Exception {
9 | Maven2Configuration configuration = new Maven2Configuration(
10 | "kukido-test",
11 | true,
12 | new String[]{"local", "remote"},
13 | "clean compile",
14 | "/home/test/eclipser"
15 | );
16 |
17 | try {
18 | configuration.getCommand();
19 | } catch (EclipserException ee) {
20 | assertEquals("Maven plugin is installed, but not enabled. Please enable Maven plugin to continue.", ee.getMessage());
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/test/resources/arguments-withnewline.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/configuration/AntTargetConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.configuration;
2 |
3 | import com.kukido.eclipser.EclipserException;
4 | import com.kukido.eclipser.command.AddAntTargetCommand;
5 | import com.kukido.eclipser.command.Command;
6 | import org.jetbrains.annotations.NotNull;
7 |
8 | public class AntTargetConfiguration implements Configuration {
9 |
10 | private final String name;
11 | private final String location;
12 |
13 | public AntTargetConfiguration(@NotNull String name, @NotNull String location) {
14 | this.name = name;
15 | this.location = location;
16 | }
17 |
18 | public String getName() {
19 | return name;
20 | }
21 |
22 | public String getLocation() {
23 | return location;
24 | }
25 |
26 | @Override
27 | public Command getCommand() throws EclipserException {
28 | return new AddAntTargetCommand(this);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/resources/directory.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/test/resources/tool.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/test/resources/newline.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/test/resources/workspace.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/test/resources/env.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/test/resources/ant-github.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/test/resources/java.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/test/resources/maven.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/test/resources/resolve.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/test/resources/maven-absolute.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/test/resources/maven-project-loc.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/test/resources/maven-relative.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/test/resources/java-wd.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/test/resources/xml/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | simple example build file
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
19 |
20 |
21 |
22 |
23 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/configuration/ExternalToolConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.configuration;
2 |
3 | import com.kukido.eclipser.command.AddExternalToolCommand;
4 | import com.kukido.eclipser.command.Command;
5 | import org.jetbrains.annotations.NotNull;
6 |
7 | public class ExternalToolConfiguration implements Configuration {
8 |
9 | public static final String PROJECT_FILE_DIR = "$ProjectFileDir$";
10 |
11 | private final String name;
12 | private final String program;
13 | private final String parameters;
14 | private final String workingDirectory;
15 |
16 | public ExternalToolConfiguration(@NotNull String name, @NotNull String program, String parameters, String workingDirectory) {
17 | this.name = name;
18 | this.program = program;
19 | this.parameters = parameters;
20 | this.workingDirectory = workingDirectory;
21 | }
22 |
23 | public String getProgram() {
24 | return program;
25 | }
26 |
27 | public String getParameters() {
28 | return parameters;
29 | }
30 |
31 | public String getName() {
32 | return name;
33 | }
34 |
35 | public String getWorkingDirectory() {
36 | if (workingDirectory == null) return PROJECT_FILE_DIR;
37 | else return workingDirectory;
38 | }
39 |
40 | @Override
41 | public Command getCommand() {
42 | return new AddExternalToolCommand(this);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/com/kukido/eclipser/configuration/ConfigurationTypeTest.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.configuration;
2 |
3 | import com.intellij.openapi.util.io.FileUtil;
4 | import com.intellij.psi.PsiFile;
5 | import com.intellij.testFramework.LightIdeaTestCase;
6 | import org.jetbrains.annotations.NotNull;
7 |
8 | import java.io.File;
9 | import java.io.IOException;
10 |
11 | public class ConfigurationTypeTest extends LightIdeaTestCase {
12 |
13 | public void testSupportedConfigurationType() throws Exception {
14 | PsiFile file = getPsiFile("ant.launch");
15 | ConfigurationType type = ConfigurationType.configurationTypeForPsiFile(file);
16 | assertEquals(ConfigurationType.SUPPORTED, type);
17 | }
18 |
19 | public void testUnsupportedConfigurationType() throws Exception {
20 | PsiFile file = getPsiFile("workbench.launch");
21 | ConfigurationType type = ConfigurationType.configurationTypeForPsiFile(file);
22 | assertEquals(ConfigurationType.UNSUPPORTED, type);
23 | }
24 |
25 | public void testUnknownConfigurationType() throws Exception {
26 | PsiFile file = getPsiFile("unknown.launch");
27 | ConfigurationType type = ConfigurationType.configurationTypeForPsiFile(file);
28 | assertEquals(ConfigurationType.UNKNOWN, type);
29 | }
30 |
31 | @NotNull
32 | private PsiFile getPsiFile(String name) throws IOException {
33 | return createFile(name.replace(".launch", ".xml"), FileUtil.loadFile(new File(this.getClass().getClassLoader().getResource(name).getPath())));
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/test/resources/notypeattribute.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/EclipserFileType.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser;
2 |
3 | import com.intellij.ide.highlighter.DomSupportEnabled;
4 | import com.intellij.ide.highlighter.XmlLikeFileType;
5 | import com.intellij.lang.xml.XMLLanguage;
6 | import com.intellij.openapi.vfs.CharsetToolkit;
7 | import com.intellij.openapi.vfs.VirtualFile;
8 | import com.kukido.eclipser.icons.EclipserIcons;
9 | import org.jetbrains.annotations.NotNull;
10 | import org.jetbrains.annotations.Nullable;
11 |
12 | import javax.swing.*;
13 |
14 | class EclipserFileType extends XmlLikeFileType implements DomSupportEnabled {
15 |
16 | public static final EclipserFileType INSTANCE = new EclipserFileType();
17 |
18 | private EclipserFileType() {
19 | super(XMLLanguage.INSTANCE);
20 | }
21 |
22 | @NotNull
23 | @Override
24 | public String getName() {
25 | return "Eclipser";
26 | }
27 |
28 | @NotNull
29 | @Override
30 | public String getDescription() {
31 | return "Eclipse launch file";
32 | }
33 |
34 | @NotNull
35 | @Override
36 | public String getDefaultExtension() {
37 | return EclipserXml.LAUNCH_EXT;
38 | }
39 |
40 | @Nullable
41 | @Override
42 | public Icon getIcon() {
43 | return EclipserIcons.Launch;
44 | }
45 |
46 | @Override
47 | public boolean isReadOnly() {
48 | return false;
49 | }
50 |
51 | @Nullable
52 | @Override
53 | public String getCharset(@NotNull VirtualFile file, @NotNull byte[] content) {
54 | return CharsetToolkit.UTF8;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/test/resources/ant.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/test/resources/invalidroottag.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/test/resources/valid.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | ## Introduction:
3 | Eclipser will automatically convert Eclipse launch configurations into IntelliJ IDEA configurations:
4 |
5 | * local Java application Eclipse launcher into run configuration
6 | * remote Java application Eclipse launcher into remote run configuration
7 | * program launch Eclipse launcher into external tool in Tools menu
8 | * Maven launch configuration into Maven run configuration
9 | * Ant launch configuration into Ant target run configuration
10 |
11 | ## How to use:
12 | * Eclipser is available in Project and Commander views.
13 | * Context menu for supported launch files will contain "Convert with Eclipser" item.
14 |
15 | ## Functionality limitations:
16 | * Current support for one Eclipse macro only:
17 | - $workspace_loc
18 | * Eclipse UI launch configuration is not supported:
19 | - org.eclipse.pde.ui.RuntimeWorkbench
20 |
21 | ## Known issues:
22 | * None
23 |
24 | ## Disclaimer:
25 | * Plugin is currently in beta. Please report any errors and suggestions to the link below.
26 |
27 | ## Support:
28 | * Email: mclovin@kukido.com
29 | * Support tickets: [https://github.com/kukido/eclipser/issues](https://github.com/kukido/eclipser/issues)
30 |
31 | ## For developers:
32 | * The project has dependency on Maven, Properties and Ant plugins. They all included with the project.
33 | * If you are developing in IntelliJ Ultimate, you have to add Netty jar from lib/netty as project library.
34 | * You will have to redefine `IntelliJ Platform Plugin SDK` location once you open the project.
35 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/configuration/RemoteJavaApplicationConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.configuration;
2 |
3 | import com.kukido.eclipser.EclipserException;
4 | import com.kukido.eclipser.command.AddRemoteJavaApplicationCommand;
5 | import com.kukido.eclipser.command.Command;
6 |
7 | import java.util.Map;
8 |
9 | public class RemoteJavaApplicationConfiguration implements Configuration {
10 |
11 | public static final String HOST_NAME_KEY = "hostname";
12 | public static final String PORT_KEY = "port";
13 |
14 | private final String name;
15 | private final Map connectMap;
16 | private final String vmConnectorId;
17 | private final String moduleName;
18 |
19 | public RemoteJavaApplicationConfiguration(String name, Map connectMap, String vmConnectorId, String moduleName) {
20 | this.name = name;
21 | this.connectMap = connectMap;
22 | this.vmConnectorId = vmConnectorId;
23 | this.moduleName = moduleName;
24 | }
25 |
26 | public String getName() {
27 | return name;
28 | }
29 |
30 | public String getHostName() {
31 | return connectMap.get(HOST_NAME_KEY);
32 | }
33 |
34 | public String getPort() {
35 | return connectMap.get(PORT_KEY);
36 | }
37 |
38 | public String getVmConnectorId() {
39 | return vmConnectorId;
40 | }
41 |
42 | public String getModuleName() {
43 | return moduleName;
44 | }
45 |
46 | @Override
47 | public Command getCommand() throws EclipserException {
48 | return new AddRemoteJavaApplicationCommand(this);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/test/resources/junit.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/configuration/ConfigurationType.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.configuration;
2 |
3 | import com.intellij.psi.PsiFile;
4 | import com.intellij.psi.xml.XmlFile;
5 | import com.intellij.psi.xml.XmlTag;
6 | import com.kukido.eclipser.EclipserXml;
7 | import org.jetbrains.annotations.Contract;
8 |
9 | import java.util.Arrays;
10 | import java.util.List;
11 |
12 | public enum ConfigurationType {
13 |
14 | SUPPORTED,
15 | UNSUPPORTED,
16 | UNKNOWN;
17 |
18 | private static final List supportedConfigurationType = Arrays.asList(
19 | EclipserXml.CONFIGURATION_TYPE_ANT_LAUNCH,
20 | EclipserXml.CONFIGURATION_TYPE_LOCAL_JAVA_APPLICATION,
21 | EclipserXml.CONFIGURATION_TYPE_MAVEN2_LAUNCH,
22 | EclipserXml.CONFIGURATION_TYPE_PROGRAM_LAUNCH,
23 | EclipserXml.CONFIGURATION_TYPE_REMOTE_JAVA_APPLICATION
24 | );
25 |
26 | private static final List unsupportedConfigurationType = Arrays.asList(
27 | EclipserXml.CONFIGURATION_TYPE_GWT_WEB_APPLICATION,
28 | EclipserXml.CONFIGURATION_TYPE_JUNIT_LAUNCH,
29 | EclipserXml.CONFIGURATION_TYPE_RUNTIME_WORKBENCH
30 | );
31 |
32 | public static ConfigurationType configurationTypeForPsiFile(PsiFile psiFile) throws Exception {
33 | String type = getConfigurationType(psiFile);
34 | if (supportedConfigurationType.contains(type)) {
35 | return SUPPORTED;
36 | } else if (unsupportedConfigurationType.contains(type)) {
37 | return UNSUPPORTED;
38 | } else {
39 | return UNKNOWN;
40 | }
41 | }
42 |
43 | @Contract("null -> fail")
44 | private static String getConfigurationType(PsiFile psiFile) throws Exception {
45 | assert psiFile instanceof XmlFile;
46 |
47 | XmlFile input = (XmlFile) psiFile;
48 |
49 | XmlTag root = input.getRootTag();
50 |
51 | //noinspection ConstantConditions
52 | return root.getAttribute(EclipserXml.TYPE).getValue();
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/configuration/JavaConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.configuration;
2 |
3 | import com.kukido.eclipser.command.AddApplicationConfigurationCommand;
4 | import com.kukido.eclipser.command.Command;
5 | import org.jetbrains.annotations.NotNull;
6 |
7 | import java.util.LinkedHashMap;
8 | import java.util.Map;
9 |
10 | public class JavaConfiguration implements Configuration {
11 |
12 | public static final String MODULE_DIR_MACRO = "$MODULE_DIR$";
13 | private final String configurationName;
14 | private final String mainClassName;
15 | private final String moduleName;
16 | private final String vmParameters;
17 | private final String programParameters;
18 | private final String workingDirectory;
19 | private final Map environmentVariables = new LinkedHashMap();
20 |
21 | public JavaConfiguration(
22 | @NotNull String configurationName,
23 | @NotNull String mainClassName,
24 | @NotNull String moduleName,
25 | String vmParameters,
26 | String programParameters,
27 | Map environmentVariables,
28 | String workingDirectory) {
29 | this.configurationName = configurationName;
30 | this.mainClassName = mainClassName;
31 | this.moduleName = moduleName;
32 | this.vmParameters = vmParameters;
33 | this.programParameters = programParameters;
34 | this.workingDirectory = workingDirectory;
35 | if (environmentVariables != null) {
36 | this.environmentVariables.putAll(environmentVariables);
37 | }
38 | }
39 |
40 | public String getConfigurationName() {
41 | return configurationName;
42 | }
43 |
44 | public String getMainClassName() {
45 | return mainClassName;
46 | }
47 |
48 | public String getModuleName() {
49 | return moduleName;
50 | }
51 |
52 | public String getWorkingDirectory() {
53 | return workingDirectory == null ? MODULE_DIR_MACRO : workingDirectory;
54 | }
55 |
56 | public String getVmParameters() {
57 | return vmParameters;
58 | }
59 |
60 | public String getProgramParameters() {
61 | return programParameters;
62 | }
63 |
64 | public Map getEnvironmentVariables() {
65 | return environmentVariables;
66 | }
67 |
68 | @Override
69 | public Command getCommand() {
70 | return new AddApplicationConfigurationCommand(this);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/command/AddMaven2ConfigurationCommand.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.command;
2 |
3 | import com.intellij.execution.RunManager;
4 | import com.intellij.execution.RunnerAndConfigurationSettings;
5 | import com.intellij.execution.impl.RunManagerImpl;
6 | import com.intellij.openapi.project.Project;
7 | import com.kukido.eclipser.EclipserException;
8 | import com.kukido.eclipser.configuration.Maven2Configuration;
9 | import org.jetbrains.idea.maven.execution.MavenRunConfigurationType;
10 | import org.jetbrains.idea.maven.execution.MavenRunnerParameters;
11 |
12 | public class AddMaven2ConfigurationCommand implements Command {
13 |
14 | private final Maven2Configuration maven2Configuration;
15 |
16 | public AddMaven2ConfigurationCommand(Maven2Configuration conf) {
17 | this.maven2Configuration = conf;
18 | }
19 |
20 | @Override
21 | public void execute(Project project) throws EclipserException {
22 |
23 | RunManagerImpl runManager = (RunManagerImpl) RunManager.getInstance(project);
24 |
25 | RunnerAndConfigurationSettings runnerAndConfigurationSettings = findConfigurationByName(maven2Configuration.getConfigurationName(), runManager);
26 |
27 | if (runnerAndConfigurationSettings != null) {
28 | String message = "Runtime configuration with name '" + maven2Configuration.getConfigurationName() + "' already exists. You can either rename it or delete to be replaced.";
29 | throw new EclipserException(message);
30 | }
31 |
32 | MavenRunnerParameters parameters = new MavenRunnerParameters();
33 | parameters.setGoals(maven2Configuration.getGoals());
34 | parameters.setProfilesMap(maven2Configuration.getProfilesMap());
35 | parameters.setWorkingDirPath(maven2Configuration.getWorkingDirectory());
36 | parameters.setResolveToWorkspace(maven2Configuration.isResolveToWorkspace());
37 |
38 | RunnerAndConfigurationSettings settings = MavenRunConfigurationType.createRunnerAndConfigurationSettings(null, null, parameters, project);
39 | settings.setName(maven2Configuration.getConfigurationName());
40 |
41 | runManager.addConfiguration(settings);
42 | runManager.setSelectedConfiguration(settings);
43 | }
44 |
45 | private RunnerAndConfigurationSettings findConfigurationByName(String name, RunManagerImpl runManager) {
46 | for (RunnerAndConfigurationSettings settings : runManager.getAllSettings()) {
47 | if (settings.getName().equals(name))
48 | return settings;
49 | }
50 | return null;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/EclipserXml.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser;
2 |
3 | import org.jetbrains.annotations.NonNls;
4 |
5 | public interface EclipserXml {
6 |
7 | @NonNls String LAUNCH_EXT = "launch";
8 | @NonNls String TYPE = "type";
9 | @NonNls String KEY = "key";
10 | @NonNls String VALUE = "value";
11 | @NonNls String MAIN_TYPE_KEY = "org.eclipse.jdt.launching.MAIN_TYPE";
12 | @NonNls String PROJECT_ATTR_KEY = "org.eclipse.jdt.launching.PROJECT_ATTR";
13 | @NonNls String VM_ARGUMENTS_KEY = "org.eclipse.jdt.launching.VM_ARGUMENTS";
14 | @NonNls String PROGRAM_ARGUMENTS_KEY = "org.eclipse.jdt.launching.PROGRAM_ARGUMENTS";
15 | @NonNls String ATTR_LOCATION_KEY = "org.eclipse.ui.externaltools.ATTR_LOCATION";
16 | @NonNls String ATTR_TOOL_ARGUMENTS_KEY = "org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS";
17 | @NonNls String ATTR_WORKING_DIRECTORY_KEY = "org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY";
18 | @NonNls String M2_GOALS_KEY = "M2_GOALS";
19 | @NonNls String M2_PROFILES_KEY = "M2_PROFILES";
20 | @NonNls String M2_WORKSPACE_RESOLUTION = "M2_WORKSPACE_RESOLUTION";
21 | @NonNls String WORKING_DIRECTORY_KEY = "org.eclipse.jdt.launching.WORKING_DIRECTORY";
22 | @NonNls String ENVIRONMENT_VARIABLES_KEY = "org.eclipse.debug.core.environmentVariables";
23 | @NonNls String CONNECT_MAP_KEY = "org.eclipse.jdt.launching.CONNECT_MAP";
24 | @NonNls String VM_CONNECTOR_ID_KEY = "org.eclipse.jdt.launching.VM_CONNECTOR_ID";
25 |
26 | // attribute type
27 | @NonNls String BOOLEAN_ATTRIBUTE = "booleanAttribute";
28 | @SuppressWarnings("UnusedDeclaration")
29 | @NonNls String LIST_ATTRIBUTE = "listAttribute";
30 | @NonNls String MAP_ATTRIBUTE = "mapAttribute";
31 | @NonNls String STRING_ATTRIBUTE = "stringAttribute";
32 | @NonNls String MAP_ENTRY_ATTRIBUTE = "mapEntry";
33 |
34 | // configuration type
35 | @NonNls String CONFIGURATION_TYPE_ANT_LAUNCH = "org.eclipse.ant.AntLaunchConfigurationType";
36 | @NonNls String CONFIGURATION_TYPE_LOCAL_JAVA_APPLICATION = "org.eclipse.jdt.launching.localJavaApplication";
37 | @NonNls String CONFIGURATION_TYPE_MAVEN2_LAUNCH = "org.eclipse.m2e.Maven2LaunchConfigurationType";
38 | @NonNls String CONFIGURATION_TYPE_PROGRAM_LAUNCH = "org.eclipse.ui.externaltools.ProgramLaunchConfigurationType";
39 | @NonNls String CONFIGURATION_TYPE_REMOTE_JAVA_APPLICATION = "org.eclipse.jdt.launching.remoteJavaApplication";
40 | // unsupported
41 | @NonNls String CONFIGURATION_TYPE_GWT_WEB_APPLICATION = "com.google.gdt.eclipse.suite.webapp";
42 | @NonNls String CONFIGURATION_TYPE_JUNIT_LAUNCH = "org.eclipse.jdt.junit.launchconfig";
43 | @NonNls String CONFIGURATION_TYPE_RUNTIME_WORKBENCH = "org.eclipse.pde.ui.RuntimeWorkbench";
44 |
45 | // eclipse macros
46 | @NonNls String WORKSPACE_LOC = "workspace_loc";
47 | @NonNls String PROJECT_LOC = "project_loc";
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%"=="" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%"=="" set DIRNAME=.
29 | @rem This is normally unused
30 | set APP_BASE_NAME=%~n0
31 | set APP_HOME=%DIRNAME%
32 |
33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35 |
36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38 |
39 | @rem Find java.exe
40 | if defined JAVA_HOME goto findJavaFromJavaHome
41 |
42 | set JAVA_EXE=java.exe
43 | %JAVA_EXE% -version >NUL 2>&1
44 | if %ERRORLEVEL% equ 0 goto execute
45 |
46 | echo.
47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48 | echo.
49 | echo Please set the JAVA_HOME variable in your environment to match the
50 | echo location of your Java installation.
51 |
52 | goto fail
53 |
54 | :findJavaFromJavaHome
55 | set JAVA_HOME=%JAVA_HOME:"=%
56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57 |
58 | if exist "%JAVA_EXE%" goto execute
59 |
60 | echo.
61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62 | echo.
63 | echo Please set the JAVA_HOME variable in your environment to match the
64 | echo location of your Java installation.
65 |
66 | goto fail
67 |
68 | :execute
69 | @rem Setup the command line
70 |
71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72 |
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if %ERRORLEVEL% equ 0 goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | set EXIT_CODE=%ERRORLEVEL%
85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87 | exit /b %EXIT_CODE%
88 |
89 | :mainEnd
90 | if "%OS%"=="Windows_NT" endlocal
91 |
92 | :omega
93 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/configuration/Maven2Configuration.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.configuration;
2 |
3 | import com.intellij.ide.plugins.IdeaPluginDescriptor;
4 | import com.intellij.ide.plugins.PluginManagerCore;
5 | import com.intellij.openapi.extensions.PluginId;
6 | import com.kukido.eclipser.EclipserException;
7 | import com.kukido.eclipser.command.AddMaven2ConfigurationCommand;
8 | import com.kukido.eclipser.command.Command;
9 | import org.jetbrains.annotations.NotNull;
10 |
11 | import java.util.Arrays;
12 | import java.util.HashMap;
13 | import java.util.List;
14 | import java.util.Map;
15 |
16 | public class Maven2Configuration implements Configuration {
17 |
18 | private static final String MAVEN_PLUGIN_IDENTIFIER = "org.jetbrains.idea.maven";
19 |
20 | private final String configurationName;
21 |
22 | private final String commandLine;
23 | private final String[] profiles;
24 | private final boolean resolveToWorkspace;
25 | private final String workingDirectory;
26 |
27 | public Maven2Configuration(@NotNull String configurationName, boolean resolveToWorkspace, String[] profiles, String commandLine, String workingDirectory) {
28 | this.configurationName = configurationName;
29 | this.resolveToWorkspace = resolveToWorkspace;
30 | this.profiles = profiles;
31 | this.commandLine = commandLine;
32 | this.workingDirectory = workingDirectory;
33 | }
34 |
35 | public String getConfigurationName() {
36 | return configurationName;
37 | }
38 |
39 | public boolean isResolveToWorkspace() {
40 | return resolveToWorkspace;
41 | }
42 |
43 | public String[] getProfiles() {
44 | return profiles;
45 | }
46 |
47 | public String getCommandLine() {
48 | return commandLine;
49 | }
50 |
51 | public String getWorkingDirectory() {
52 | return workingDirectory;
53 | }
54 |
55 | public Map getProfilesMap() {
56 | Map profilesMap = new HashMap<>(profiles.length);
57 | for (String profile : profiles) {
58 | profilesMap.put(profile, Boolean.TRUE);
59 | }
60 | return profilesMap;
61 | }
62 |
63 | public List getGoals() {
64 | return Arrays.asList(commandLine.split(" "));
65 | }
66 |
67 | @Override
68 | public Command getCommand() throws EclipserException {
69 | checkMavenPluginStatus();
70 | return new AddMaven2ConfigurationCommand(this);
71 | }
72 |
73 | private void checkMavenPluginStatus() throws EclipserException {
74 | PluginId pluginId = PluginId.getId(MAVEN_PLUGIN_IDENTIFIER);
75 |
76 | boolean installed = PluginManagerCore.isPluginInstalled(pluginId);
77 | boolean enabled = false;
78 |
79 | if (installed) {
80 | IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(pluginId);
81 | assert descriptor != null;
82 | enabled = descriptor.isEnabled();
83 | }
84 |
85 | if (!installed)
86 | throw new EclipserException("Maven plugin is not installed. Please install Maven plugin to continue.");
87 | if (!enabled)
88 | throw new EclipserException("Maven plugin is installed, but not enabled. Please enable Maven plugin to continue.");
89 | }
90 | }
91 |
92 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/command/AddRemoteJavaApplicationCommand.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.command;
2 |
3 | import com.intellij.execution.RunManager;
4 | import com.intellij.execution.impl.RunManagerImpl;
5 | import com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl;
6 | import com.intellij.execution.remote.RemoteConfiguration;
7 | import com.intellij.execution.remote.RemoteConfigurationType;
8 | import com.intellij.openapi.module.Module;
9 | import com.intellij.openapi.module.ModuleManager;
10 | import com.intellij.openapi.project.Project;
11 | import com.kukido.eclipser.EclipserException;
12 | import com.kukido.eclipser.configuration.RemoteJavaApplicationConfiguration;
13 |
14 | public class AddRemoteJavaApplicationCommand implements Command {
15 |
16 | public static final String SOCKET_ATTACH_CONNECTOR = "org.eclipse.jdt.launching.socketAttachConnector";
17 | private static final String SOCKET_LISTEN_CONNECTOR = "org.eclipse.jdt.launching.socketListenConnector";
18 |
19 | private final RemoteJavaApplicationConfiguration configuration;
20 |
21 | public AddRemoteJavaApplicationCommand(RemoteJavaApplicationConfiguration configuration) {
22 | this.configuration = configuration;
23 | }
24 |
25 | @Override
26 | public void execute(Project project) throws EclipserException {
27 | RemoteConfiguration remoteConfiguration;
28 |
29 | Module module = null;
30 | if (!isNullOrEmpty(configuration.getModuleName())) {
31 | module = ModuleManager.getInstance(project).findModuleByName(configuration.getModuleName());
32 | if (module == null) {
33 | String message = "Could not find the module with name '" + configuration.getModuleName() + "'. You can either update Eclipse launch file with the correct name or create a new module.";
34 | throw new EclipserException(message);
35 | }
36 | }
37 |
38 | RunManagerImpl runManager = (RunManagerImpl) RunManager.getInstance(project);
39 |
40 | RunnerAndConfigurationSettingsImpl runnerAndConfigurationSettings = (RunnerAndConfigurationSettingsImpl) runManager.findConfigurationByName(configuration.getName());
41 |
42 | if (runnerAndConfigurationSettings != null) {
43 | String message = "Runtime configuration with name '" + configuration.getName() + "' already exists. You can either rename it or delete to be replaced.";
44 | throw new EclipserException(message);
45 | } else {
46 | RemoteConfigurationType remoteConfigurationType = RemoteConfigurationType.getInstance();
47 | runnerAndConfigurationSettings = (RunnerAndConfigurationSettingsImpl) runManager.createConfiguration(configuration.getName(), remoteConfigurationType.getConfigurationFactories()[0]);
48 | remoteConfiguration = (RemoteConfiguration) runnerAndConfigurationSettings.getConfiguration();
49 | runManager.addConfiguration(runnerAndConfigurationSettings);
50 | }
51 |
52 | remoteConfiguration.setModule(module);
53 | remoteConfiguration.HOST = configuration.getHostName();
54 | remoteConfiguration.PORT = configuration.getPort();
55 | remoteConfiguration.SERVER_MODE = configuration.getVmConnectorId().equalsIgnoreCase(SOCKET_LISTEN_CONNECTOR);
56 |
57 | runManager.setSelectedConfiguration(runnerAndConfigurationSettings);
58 | }
59 |
60 | private boolean isNullOrEmpty(String string) {
61 | return string == null || string.isEmpty();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/com/kukido/eclipser/command/AddExternalToolCommandTest.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.command;
2 |
3 | import com.intellij.testFramework.LightIdeaTestCase;
4 | import com.intellij.tools.Tool;
5 | import com.intellij.tools.ToolManager;
6 | import com.intellij.tools.ToolsGroup;
7 | import com.kukido.eclipser.configuration.ExternalToolConfiguration;
8 |
9 | import java.util.Collections;
10 | import java.util.List;
11 |
12 | public class AddExternalToolCommandTest extends LightIdeaTestCase {
13 |
14 | private AddExternalToolCommand command;
15 |
16 | public void testExecuteWithFullConfiguration() {
17 |
18 | ExternalToolConfiguration configuration = new ExternalToolConfiguration(
19 | "full-configuration",
20 | "foo.sh",
21 | "--port 11111",
22 | "/user/bar/foo"
23 | );
24 |
25 | command = new AddExternalToolCommand(configuration);
26 | command.execute(null);
27 |
28 | ToolManager toolManager = ToolManager.getInstance();
29 |
30 | List> toolsGroups = toolManager.getGroups();
31 |
32 | ToolsGroup toolsGroup = null;
33 |
34 | for (ToolsGroup tg : toolsGroups) {
35 | if (tg.getName().equals(AddExternalToolCommand.DEFAULT_GROUP_NAME)) {
36 | toolsGroup = tg;
37 | break;
38 | }
39 | }
40 |
41 | if (toolsGroup == null) fail("Eclipser group was not created");
42 |
43 | List tools = toolManager.getTools(AddExternalToolCommand.DEFAULT_GROUP_NAME);
44 | assertEquals(1, tools.size());
45 |
46 | Tool tool = tools.get(0);
47 |
48 | assertEquals(configuration.getName(), tool.getName());
49 | assertEquals(configuration.getProgram(), tool.getProgram());
50 | assertEquals(configuration.getParameters(), tool.getParameters());
51 | assertEquals(configuration.getWorkingDirectory(), tool.getWorkingDirectory());
52 | }
53 |
54 | public void testExecuteWithMinimalConfiguration() {
55 |
56 | ExternalToolConfiguration configuration = new ExternalToolConfiguration(
57 | "minimal-configuration",
58 | "foo.sh",
59 | null,
60 | null
61 | );
62 |
63 | command = new AddExternalToolCommand(configuration);
64 | command.execute(null);
65 |
66 | ToolManager toolManager = ToolManager.getInstance();
67 |
68 | List> toolsGroups = toolManager.getGroups();
69 |
70 | ToolsGroup toolsGroup = null;
71 |
72 | for (ToolsGroup tg : toolsGroups) {
73 | if (tg.getName().equals(AddExternalToolCommand.DEFAULT_GROUP_NAME)) {
74 | toolsGroup = tg;
75 | break;
76 | }
77 | }
78 |
79 | if (toolsGroup == null) fail("Eclipser group was not created");
80 |
81 | List tools = toolManager.getTools(AddExternalToolCommand.DEFAULT_GROUP_NAME);
82 | assertEquals(1, tools.size());
83 |
84 | Tool tool = tools.get(0);
85 |
86 | assertEquals(configuration.getName(), tool.getName());
87 | assertEquals(configuration.getProgram(), tool.getProgram());
88 | assertEquals(ExternalToolConfiguration.PROJECT_FILE_DIR, tool.getWorkingDirectory());
89 | }
90 |
91 | @Override
92 | protected void tearDown() throws Exception {
93 | ToolManager.getInstance().setTools(Collections.>emptyList());
94 | super.tearDown();
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/test/java/com/kukido/eclipser/command/AddAntTargetCommandTest.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.command;
2 |
3 | import com.intellij.execution.RunManager;
4 | import com.intellij.execution.configurations.RunConfiguration;
5 | import com.intellij.execution.impl.RunManagerImpl;
6 | import com.intellij.lang.ant.config.AntBuildFile;
7 | import com.intellij.lang.ant.config.AntConfiguration;
8 | import com.intellij.lang.ant.config.execution.AntRunConfiguration;
9 | import com.intellij.openapi.project.Project;
10 | import com.intellij.testFramework.LightIdeaTestCase;
11 | import com.kukido.eclipser.EclipserException;
12 | import com.kukido.eclipser.configuration.AntTargetConfiguration;
13 |
14 | import java.net.URL;
15 | import java.util.List;
16 |
17 | public class AddAntTargetCommandTest extends LightIdeaTestCase {
18 |
19 | private AddAntTargetCommand command;
20 |
21 | public void testExecute() throws Exception {
22 |
23 | URL resource = this.getClass().getClassLoader().getResource("xml/build.xml");
24 |
25 | @SuppressWarnings("ConstantConditions")
26 | AntTargetConfiguration configuration = new AntTargetConfiguration("test-execute", resource.getPath());
27 |
28 | command = (AddAntTargetCommand) configuration.getCommand();
29 |
30 | Project project = getProject();
31 |
32 | command.execute(project);
33 |
34 | AntConfiguration antConfiguration = AntConfiguration.getInstance(project);
35 | AntBuildFile[] antBuildFiles = antConfiguration.getBuildFiles();
36 | assertEquals(1, antBuildFiles.length);
37 |
38 | AntRunConfiguration antRunConfiguration = getAntRunConfiguration(configuration.getName());
39 | assertNotNull(antRunConfiguration);
40 | }
41 |
42 | public void testExecuteWithMissingBuildFile() throws Exception {
43 | Project project = getProject();
44 |
45 | AntTargetConfiguration conf = new AntTargetConfiguration("missing", project.getBasePath() + "/missing/build.xml");
46 | command = (AddAntTargetCommand) conf.getCommand();
47 | try {
48 | command.execute(project);
49 | fail("Execute should throw an exception on missing build file");
50 | } catch (EclipserException ignored) {
51 | }
52 | }
53 |
54 | private AntRunConfiguration getAntRunConfiguration(String name) {
55 | AntRunConfiguration antRunConfiguration = null;
56 | RunManagerImpl manager = (RunManagerImpl) RunManager.getInstance(getProject());
57 | List configurations = manager.getAllConfigurationsList();
58 | for (RunConfiguration runConfiguration : configurations) {
59 | if (runConfiguration.getName().equalsIgnoreCase(name)) {
60 | if (runConfiguration instanceof AntRunConfiguration) {
61 | antRunConfiguration = (AntRunConfiguration) runConfiguration;
62 | }
63 | }
64 | }
65 | return antRunConfiguration;
66 | }
67 |
68 | @Override
69 | protected void tearDown() throws Exception {
70 | RunManagerImpl manager = (RunManagerImpl) RunManager.getInstance(getProject());
71 | manager.clearAll();
72 | Project project = getProject();
73 | AntConfiguration antConfiguration = AntConfiguration.getInstance(project);
74 | AntBuildFile[] antBuildFiles = antConfiguration.getBuildFiles();
75 | for (AntBuildFile antBuildFile : antBuildFiles) {
76 | antConfiguration.removeBuildFile(antBuildFile);
77 | }
78 | super.tearDown();
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/command/AddApplicationConfigurationCommand.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.command;
2 |
3 | import com.intellij.execution.RunManager;
4 | import com.intellij.execution.RunnerAndConfigurationSettings;
5 | import com.intellij.execution.application.ApplicationConfiguration;
6 | import com.intellij.execution.application.ApplicationConfigurationType;
7 | import com.intellij.execution.impl.RunManagerImpl;
8 | import com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl;
9 | import com.intellij.openapi.module.Module;
10 | import com.intellij.openapi.module.ModuleManager;
11 | import com.intellij.openapi.project.Project;
12 | import com.kukido.eclipser.EclipserException;
13 | import com.kukido.eclipser.configuration.JavaConfiguration;
14 |
15 | public class AddApplicationConfigurationCommand implements Command {
16 |
17 | private final JavaConfiguration javaConfiguration;
18 |
19 | public AddApplicationConfigurationCommand(JavaConfiguration conf) {
20 | this.javaConfiguration = conf;
21 | }
22 |
23 | @Override
24 | public void execute(Project project) throws EclipserException {
25 | createConfiguration(project);
26 | }
27 |
28 | private void createConfiguration(Project project) throws EclipserException {
29 |
30 | String moduleNameOfRunner = javaConfiguration.getModuleName();
31 |
32 | Module module = ModuleManager.getInstance(project).findModuleByName(moduleNameOfRunner);
33 |
34 | if (module == null) {
35 | String message = "Could not find the module with name '" + moduleNameOfRunner + "'. You can either update Eclipse launch file with the correct name or create a new module.";
36 | throw new EclipserException(message);
37 | }
38 |
39 | ApplicationConfiguration applicationConfiguration;
40 |
41 | RunManagerImpl runManager = (RunManagerImpl) RunManager.getInstance(project);
42 |
43 | RunnerAndConfigurationSettingsImpl runnerAndConfigurationSettings = findConfigurationByName(javaConfiguration.getConfigurationName(), runManager);
44 |
45 | if (runnerAndConfigurationSettings != null) {
46 | String message = "Runtime configuration with name '" + javaConfiguration.getConfigurationName() + "' already exists. You can either rename it or delete to be replaced.";
47 | throw new EclipserException(message);
48 | } else {
49 | ApplicationConfigurationType type = ApplicationConfigurationType.getInstance();
50 | runnerAndConfigurationSettings = (RunnerAndConfigurationSettingsImpl) runManager.createConfiguration(javaConfiguration.getConfigurationName(), type.getConfigurationFactories()[0]);
51 | applicationConfiguration = (ApplicationConfiguration) runnerAndConfigurationSettings.getConfiguration();
52 | runManager.addConfiguration(runnerAndConfigurationSettings);
53 | }
54 |
55 | applicationConfiguration.setModule(module);
56 | applicationConfiguration.setMainClassName(javaConfiguration.getMainClassName());
57 | applicationConfiguration.setWorkingDirectory(javaConfiguration.getWorkingDirectory());
58 | applicationConfiguration.setVMParameters(javaConfiguration.getVmParameters());
59 | applicationConfiguration.setProgramParameters(javaConfiguration.getProgramParameters());
60 | applicationConfiguration.setEnvs(javaConfiguration.getEnvironmentVariables());
61 |
62 | runManager.setSelectedConfiguration(runnerAndConfigurationSettings);
63 | }
64 |
65 | private RunnerAndConfigurationSettingsImpl findConfigurationByName(String name, RunManagerImpl runManager) {
66 | for (RunnerAndConfigurationSettings settings : runManager.getAllSettings()) {
67 | if (settings.getName().equals(name))
68 | return (RunnerAndConfigurationSettingsImpl) settings;
69 | }
70 | return null;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/test/java/com/kukido/eclipser/EclipserActionTest.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser;
2 |
3 | import com.intellij.openapi.actionSystem.AnActionEvent;
4 | import com.intellij.openapi.actionSystem.DataContext;
5 | import com.intellij.openapi.actionSystem.LangDataKeys;
6 | import com.intellij.openapi.util.io.FileUtil;
7 | import com.intellij.psi.PsiElement;
8 | import com.intellij.psi.PsiFile;
9 | import com.intellij.testFramework.LightIdeaTestCase;
10 | import com.intellij.testFramework.TestActionEvent;
11 | import org.jetbrains.annotations.Nullable;
12 |
13 | import java.io.File;
14 | import java.io.IOException;
15 |
16 | public class EclipserActionTest extends LightIdeaTestCase {
17 |
18 | private EclipserAction action;
19 |
20 | public void testIsSupportedWithValidFile() throws IOException {
21 | action = new EclipserAction();
22 | PsiFile valid = getPsiFile("valid.launch");
23 | assertTrue(action.isSupported(valid));
24 | }
25 |
26 | public void testIsSupportedWithInvalidRootTag() throws IOException {
27 | action = new EclipserAction();
28 | PsiFile invalid = getPsiFile("invalidroottag.launch");
29 | assertFalse(action.isSupported(invalid));
30 | }
31 |
32 | public void testIsSupportedWithNoTypeAttribute() throws IOException {
33 | action = new EclipserAction();
34 | PsiFile invalid = getPsiFile("notypeattribute.launch");
35 | assertFalse(action.isSupported(invalid));
36 | }
37 |
38 | public void testIsSupportedWithNoRootTag() throws IOException {
39 | action = new EclipserAction();
40 | PsiFile invalid = getPsiFile("noroottag.launch");
41 | assertFalse(action.isSupported(invalid));
42 | }
43 |
44 | public void testGetPsiElementsWithNull() {
45 | action = new EclipserAction();
46 | DataContext context = new DataContext() {
47 | @Nullable
48 | @Override
49 | public Object getData(String key) {
50 | return null;
51 | }
52 | };
53 | AnActionEvent event = new TestActionEvent(context, action);
54 | PsiElement[] elements = action.getPsiElements(event);
55 | assertEmpty(elements);
56 | }
57 |
58 | public void testGetPsiElementsWithPsiElementArray() throws IOException {
59 | action = new EclipserAction();
60 | final PsiFile[] psiFiles = {getPsiFile("valid.launch")};
61 | DataContext context = new DataContext() {
62 | @Nullable
63 | @Override
64 | public Object getData(String key) {
65 | if (LangDataKeys.PSI_ELEMENT_ARRAY.is(key)) {
66 | return psiFiles;
67 | }
68 | return null;
69 | }
70 | };
71 | AnActionEvent event = new TestActionEvent(context, action);
72 | PsiElement[] elements = action.getPsiElements(event);
73 | assertEquals(1, elements.length);
74 | }
75 |
76 | public void testGetPsiElementsWithPsiFile() throws IOException {
77 | action = new EclipserAction();
78 | final PsiFile psiFile = getPsiFile("valid.launch");
79 | DataContext context = new DataContext() {
80 | @Nullable
81 | @Override
82 | public Object getData(String key) {
83 | if (LangDataKeys.PSI_FILE.is(key)) {
84 | return psiFile;
85 | }
86 | return null;
87 | }
88 | };
89 | AnActionEvent event = new TestActionEvent(context, action);
90 | PsiElement[] elements = action.getPsiElements(event);
91 | assertEquals(1, elements.length);
92 | }
93 |
94 | private PsiFile getPsiFile(String name) throws IOException {
95 | return createFile(name.replace(".launch", ".xml"), FileUtil.loadFile(new File(this.getClass().getClassLoader().getResource(name).getPath())));
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/test/java/com/kukido/eclipser/command/AddMaven2ConfigurationCommandTest.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.command;
2 |
3 | import com.intellij.execution.RunManager;
4 | import com.intellij.execution.configurations.RunConfiguration;
5 | import com.intellij.execution.impl.RunManagerImpl;
6 | import com.intellij.openapi.project.Project;
7 | import com.intellij.testFramework.LightIdeaTestCase;
8 | import com.kukido.eclipser.EclipserException;
9 | import com.kukido.eclipser.configuration.Maven2Configuration;
10 | import org.jetbrains.idea.maven.execution.MavenRunConfiguration;
11 | import org.jetbrains.idea.maven.execution.MavenRunnerParameters;
12 |
13 | import java.util.List;
14 |
15 | public class AddMaven2ConfigurationCommandTest extends LightIdeaTestCase {
16 |
17 | private AddMaven2ConfigurationCommand command;
18 |
19 | public void testExecuteWithFullConfiguration() throws Exception {
20 | Maven2Configuration configuration = new Maven2Configuration(
21 | "kukido-test",
22 | true,
23 | new String[]{"local", "remote"},
24 | "clean compile",
25 | "/home/eclipser"
26 | );
27 |
28 | configuration.getCommand();
29 |
30 | command = new AddMaven2ConfigurationCommand(configuration);
31 |
32 | Project project = getProject();
33 | command.execute(project);
34 |
35 | validateCreatedConfiguration(configuration);
36 | }
37 |
38 | public void testExecuteWithDuplicateName() throws Exception {
39 | Maven2Configuration configuration = new Maven2Configuration(
40 | "kukido-test",
41 | true,
42 | new String[]{"local", "remote"},
43 | "clean compile",
44 | "/home/eclipser"
45 | );
46 |
47 | configuration.getCommand();
48 |
49 | command = new AddMaven2ConfigurationCommand(configuration);
50 |
51 | Project project = getProject();
52 | command.execute(project);
53 |
54 | try {
55 | command.execute(getProject());
56 | fail("Execute should throw an exception on duplicate configuration");
57 | } catch (EclipserException ignored) {
58 | }
59 | }
60 |
61 | private void validateCreatedConfiguration(Maven2Configuration configuration) {
62 | MavenRunConfiguration mavenRunConfiguration = null;
63 | RunManager manager = RunManager.getInstance(getProject());
64 | List configurations = manager.getAllConfigurationsList();
65 | for (RunConfiguration runConfiguration : configurations) {
66 | if (runConfiguration.getName().equals(configuration.getConfigurationName())) {
67 | if (runConfiguration instanceof MavenRunConfiguration) {
68 | mavenRunConfiguration = (MavenRunConfiguration)runConfiguration;
69 | }
70 | }
71 | }
72 |
73 | if (mavenRunConfiguration == null) {
74 | fail("Maven run configuration was not created");
75 | } else {
76 | assertEquals(configuration.getConfigurationName(), mavenRunConfiguration.getName());
77 | MavenRunnerParameters parameters = mavenRunConfiguration.getRunnerParameters();
78 | assertEquals(configuration.isResolveToWorkspace(), parameters.isResolveToWorkspace());
79 | assertContainsOrdered(parameters.getGoals(), configuration.getGoals());
80 | assertContainsElements(parameters.getProfilesMap().entrySet(), configuration.getProfilesMap().entrySet());
81 | assertEquals(configuration.getWorkingDirectory(), parameters.getWorkingDirPath());
82 | }
83 | }
84 |
85 | @Override
86 | protected void tearDown() throws Exception {
87 | RunManagerImpl manager = (RunManagerImpl) RunManager.getInstance(getProject());
88 | manager.clearAll();
89 | super.tearDown();
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/command/AddAntTargetCommand.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.command;
2 |
3 | import com.intellij.execution.RunManager;
4 | import com.intellij.execution.impl.RunManagerImpl;
5 | import com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl;
6 | import com.intellij.lang.ant.config.AntBuildFile;
7 | import com.intellij.lang.ant.config.AntBuildListener;
8 | import com.intellij.lang.ant.config.AntBuildModel;
9 | import com.intellij.lang.ant.config.AntBuildTarget;
10 | import com.intellij.lang.ant.config.AntConfiguration;
11 | import com.intellij.lang.ant.config.AntNoFileException;
12 | import com.intellij.lang.ant.config.execution.AntRunConfiguration;
13 | import com.intellij.lang.ant.config.execution.AntRunConfigurationType;
14 | import com.intellij.openapi.actionSystem.DataContext;
15 | import com.intellij.openapi.project.Project;
16 | import com.intellij.openapi.vfs.VirtualFile;
17 | import com.intellij.openapi.vfs.VirtualFileManager;
18 | import com.kukido.eclipser.EclipserException;
19 | import com.kukido.eclipser.configuration.AntTargetConfiguration;
20 | import org.jetbrains.annotations.Nullable;
21 |
22 | import java.util.List;
23 |
24 | public class AddAntTargetCommand implements Command {
25 |
26 | private final AntTargetConfiguration configuration;
27 |
28 | public AddAntTargetCommand(AntTargetConfiguration configuration) {
29 | this.configuration = configuration;
30 | }
31 |
32 | @Override
33 | public void execute(Project project) throws EclipserException {
34 | AntConfiguration c = AntConfiguration.getInstance(project);
35 | String url = String.format("file://%s", configuration.getLocation());
36 | VirtualFile virtualFile = VirtualFileManager.getInstance().findFileByUrl(url);
37 |
38 | if (virtualFile == null) throw new EclipserException("Unable to locate Ant build file: " + url);
39 |
40 | AntBuildFile antBuildFile;
41 | try {
42 | antBuildFile = c.addBuildFile(virtualFile);
43 | } catch (AntNoFileException antNoFileException) {
44 | throw new EclipserException(antNoFileException.getMessage());
45 | }
46 |
47 | String target = antBuildFile.getModel().getDefaultTargetName();
48 | if (target == null) throw new EclipserException("Unable to add Ant Target configuration. Default target is not defined in Ant build file.");
49 |
50 | AntRunConfiguration antRunConfiguration;
51 |
52 | RunManagerImpl runManager = (RunManagerImpl) RunManager.getInstance(project);
53 |
54 | AntRunConfigurationType type = AntRunConfigurationType.getInstance();
55 | RunnerAndConfigurationSettingsImpl runnerAndConfigurationSettings = (RunnerAndConfigurationSettingsImpl) runManager.createConfiguration(configuration.getName(), type.getConfigurationFactories()[0]);
56 | antRunConfiguration = (AntRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
57 | runManager.addConfiguration(runnerAndConfigurationSettings);
58 | AntBuildTarget antBuildTarget = new BuildTarget(antBuildFile, target);
59 | antRunConfiguration.acceptSettings(antBuildTarget);
60 | runManager.setSelectedConfiguration(runnerAndConfigurationSettings);
61 | }
62 |
63 | private class BuildTarget implements AntBuildTarget {
64 |
65 | private final AntBuildFile file;
66 | private final String name;
67 |
68 | public BuildTarget(AntBuildFile file, String name) {
69 | this.file = file;
70 | this.name = name;
71 | }
72 |
73 | @Nullable
74 | @Override
75 | public String getName() {
76 | return name;
77 | }
78 |
79 | @Nullable
80 | @Override
81 | public String getDisplayName() {
82 | return null;
83 | }
84 |
85 | @Nullable
86 | @Override
87 | public String getNotEmptyDescription() {
88 | return null;
89 | }
90 |
91 | @Override
92 | public boolean isDefault() {
93 | return false;
94 | }
95 |
96 | @Override
97 | public void run(DataContext dataContext, List list, AntBuildListener antBuildListener) {
98 | }
99 |
100 | @Override
101 | public AntBuildModel getModel() {
102 | return file.getModel();
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/command/AddExternalToolCommand.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.command;
2 |
3 | import com.intellij.openapi.project.Project;
4 | import com.intellij.tools.Tool;
5 | import com.intellij.tools.ToolManager;
6 | import com.intellij.tools.ToolsGroup;
7 | import com.kukido.eclipser.configuration.ExternalToolConfiguration;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | public class AddExternalToolCommand implements Command {
13 |
14 | public static final String DEFAULT_GROUP_NAME = "Eclipser";
15 |
16 | private final ExternalToolConfiguration configuration;
17 |
18 | public AddExternalToolCommand(ExternalToolConfiguration configuration) {
19 | this.configuration = configuration;
20 | }
21 |
22 | @Override
23 | public void execute(Project project) {
24 | ToolManager manager = ToolManager.getInstance();
25 |
26 | ToolsGroup target = null;
27 |
28 | List> groups = new ArrayList>(manager.getGroups());
29 |
30 | for (ToolsGroup group : groups) {
31 | if (group.getName().equalsIgnoreCase(DEFAULT_GROUP_NAME)) {
32 | target = group;
33 | }
34 | }
35 |
36 | if (target == null) {
37 | target = new ToolsGroup(DEFAULT_GROUP_NAME);
38 | groups.add(target);
39 | }
40 |
41 | EclipserTool tool = new EclipserTool();
42 |
43 | tool.setName(configuration.getName());
44 | tool.setShownInMainMenu(true);
45 | tool.setEnabled(true);
46 | tool.setUseConsole(true);
47 | tool.setProgram(configuration.getProgram());
48 | tool.setParameters(configuration.getParameters());
49 | tool.setWorkingDirectory(configuration.getWorkingDirectory());
50 | tool.setGroupName(DEFAULT_GROUP_NAME);
51 |
52 | target.addElement(tool);
53 |
54 | manager.setTools(groups);
55 | }
56 |
57 | static class EclipserTool extends Tool {
58 |
59 | private String name;
60 | private boolean shownInMainMenu;
61 | private boolean enabled;
62 | private boolean useConsole;
63 |
64 | @Override
65 | public String getName() {
66 | return name;
67 | }
68 |
69 | public void setName(String name) {
70 | this.name = name;
71 | }
72 |
73 | @Override
74 | public boolean isShownInMainMenu() {
75 | return shownInMainMenu;
76 | }
77 |
78 | @SuppressWarnings("SameParameterValue")
79 | public void setShownInMainMenu(boolean shownInMainMenu) {
80 | this.shownInMainMenu = shownInMainMenu;
81 | }
82 |
83 | @Override
84 | public boolean isEnabled() {
85 | return enabled;
86 | }
87 |
88 | @Override
89 | public void setEnabled(boolean enabled) {
90 | this.enabled = enabled;
91 | }
92 |
93 | @Override
94 | public boolean isUseConsole() {
95 | return useConsole;
96 | }
97 |
98 | @SuppressWarnings("SameParameterValue")
99 | public void setUseConsole(boolean useConsole) {
100 | this.useConsole = useConsole;
101 | }
102 |
103 | @Override
104 | public String getActionId() {
105 |
106 | StringBuilder id = new StringBuilder(ACTION_ID_PREFIX);
107 |
108 | String group = getGroup();
109 |
110 | id.append(group);
111 | id.append('_');
112 |
113 | if (name != null) {
114 | id.append(name);
115 | }
116 | return id.toString();
117 | }
118 |
119 | @SuppressWarnings("RedundantIfStatement")
120 | @Override
121 | public boolean equals(Object o) {
122 | if (this == o) return true;
123 | if (o == null || getClass() != o.getClass()) return false;
124 | if (!super.equals(o)) return false;
125 |
126 | EclipserTool that = (EclipserTool) o;
127 |
128 | if (enabled != that.enabled) return false;
129 | if (shownInMainMenu != that.shownInMainMenu) return false;
130 | if (useConsole != that.useConsole) return false;
131 | if (name != null ? !name.equals(that.name) : that.name != null) return false;
132 |
133 | return true;
134 | }
135 |
136 | @Override
137 | public int hashCode() {
138 | int result = name != null ? name.hashCode() : 0;
139 | result = 31 * result + (shownInMainMenu ? 1 : 0);
140 | result = 31 * result + (enabled ? 1 : 0);
141 | result = 31 * result + (useConsole ? 1 : 0);
142 | return result;
143 | }
144 | }
145 | }
--------------------------------------------------------------------------------
/src/test/java/com/kukido/eclipser/command/AddRemoteJavaApplicationCommandTest.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.command;
2 |
3 | import com.intellij.execution.RunManager;
4 | import com.intellij.execution.configurations.RunConfiguration;
5 | import com.intellij.execution.impl.RunManagerImpl;
6 | import com.intellij.execution.remote.RemoteConfiguration;
7 | import com.intellij.openapi.project.Project;
8 | import com.intellij.testFramework.LightIdeaTestCase;
9 | import com.kukido.eclipser.EclipserException;
10 | import com.kukido.eclipser.configuration.RemoteJavaApplicationConfiguration;
11 |
12 | import java.util.HashMap;
13 | import java.util.List;
14 | import java.util.Map;
15 |
16 | public class AddRemoteJavaApplicationCommandTest extends LightIdeaTestCase {
17 |
18 | private static final String TEST_CASE_MODULE_NAME = "light_idea_test_case";
19 |
20 | private AddRemoteJavaApplicationCommand command;
21 |
22 | public void testExecute() throws Exception {
23 |
24 | Map connectMap = new HashMap(2);
25 | connectMap.put(RemoteJavaApplicationConfiguration.HOST_NAME_KEY, "hostname");
26 | connectMap.put(RemoteJavaApplicationConfiguration.PORT_KEY, "9000");
27 |
28 | @SuppressWarnings("ConstantConditions")
29 | RemoteJavaApplicationConfiguration configuration = new RemoteJavaApplicationConfiguration("test-execute", connectMap, AddRemoteJavaApplicationCommand.SOCKET_ATTACH_CONNECTOR, TEST_CASE_MODULE_NAME);
30 |
31 | command = (AddRemoteJavaApplicationCommand) configuration.getCommand();
32 |
33 | Project project = getProject();
34 |
35 | command.execute(project);
36 |
37 |
38 | RemoteConfiguration remoteConfiguration = null;
39 | RunManagerImpl manager = (RunManagerImpl) RunManager.getInstance(getProject());
40 |
41 | List configurations = manager.getAllConfigurationsList();
42 | for (RunConfiguration runConfiguration : configurations) {
43 | if (runConfiguration.getName().equals(configuration.getName())) {
44 | if (runConfiguration instanceof RemoteConfiguration) {
45 | remoteConfiguration = (RemoteConfiguration) runConfiguration;
46 | }
47 | }
48 | }
49 |
50 | if (remoteConfiguration == null) {
51 | fail("Remote Java application configuration was not created");
52 | }
53 |
54 | assertEquals(configuration.getName(), remoteConfiguration.getName());
55 | assertEquals(configuration.getHostName(), remoteConfiguration.HOST);
56 | assertEquals(configuration.getPort(), remoteConfiguration.PORT);
57 | assertFalse(remoteConfiguration.SERVER_MODE);
58 | assertEquals(TEST_CASE_MODULE_NAME, remoteConfiguration.getModules()[0].getName());
59 | }
60 |
61 | public void testWithUnknownModule() throws Exception {
62 | Map connectMap = new HashMap(2);
63 | connectMap.put(RemoteJavaApplicationConfiguration.HOST_NAME_KEY, "hostname");
64 | connectMap.put(RemoteJavaApplicationConfiguration.PORT_KEY, "9000");
65 |
66 | @SuppressWarnings("ConstantConditions")
67 | RemoteJavaApplicationConfiguration configuration = new RemoteJavaApplicationConfiguration("test-execute", connectMap, AddRemoteJavaApplicationCommand.SOCKET_ATTACH_CONNECTOR, "unknown");
68 |
69 | command = (AddRemoteJavaApplicationCommand) configuration.getCommand();
70 |
71 | Project project = getProject();
72 |
73 | try {
74 | command.execute(project);
75 | fail("The command should fail if the specified module does not exist");
76 | } catch (EclipserException ignored) {
77 | }
78 | }
79 |
80 | public void testWithDuplicateConfigurationName() throws Exception {
81 | Map connectMap = new HashMap(2);
82 | connectMap.put(RemoteJavaApplicationConfiguration.HOST_NAME_KEY, "hostname");
83 | connectMap.put(RemoteJavaApplicationConfiguration.PORT_KEY, "9000");
84 |
85 | @SuppressWarnings("ConstantConditions")
86 | RemoteJavaApplicationConfiguration configuration = new RemoteJavaApplicationConfiguration("test-execute", connectMap, AddRemoteJavaApplicationCommand.SOCKET_ATTACH_CONNECTOR, null);
87 |
88 | command = (AddRemoteJavaApplicationCommand) configuration.getCommand();
89 |
90 | Project project = getProject();
91 |
92 | command.execute(project);
93 |
94 | try {
95 | command.execute(project);
96 | fail("The command should fail when there's already a configuration with the same name");
97 | } catch (EclipserException ignored) {
98 | }
99 | }
100 |
101 | @Override
102 | protected void tearDown() throws Exception {
103 | RunManagerImpl manager = (RunManagerImpl) RunManager.getInstance(getProject());
104 | manager.clearAll();
105 | super.tearDown();
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/EclipserAction.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser;
2 |
3 | import com.intellij.openapi.actionSystem.AnAction;
4 | import com.intellij.openapi.actionSystem.AnActionEvent;
5 | import com.intellij.openapi.actionSystem.LangDataKeys;
6 | import com.intellij.openapi.actionSystem.PlatformDataKeys;
7 | import com.intellij.openapi.actionSystem.Presentation;
8 | import com.intellij.openapi.project.Project;
9 | import com.intellij.openapi.ui.Messages;
10 | import com.intellij.openapi.vfs.VirtualFile;
11 | import com.intellij.psi.PsiElement;
12 | import com.intellij.psi.PsiFile;
13 | import com.intellij.psi.PsiManager;
14 | import com.intellij.psi.xml.XmlAttribute;
15 | import com.intellij.psi.xml.XmlDocument;
16 | import com.intellij.psi.xml.XmlFile;
17 | import com.intellij.psi.xml.XmlTag;
18 | import com.kukido.eclipser.command.Command;
19 | import com.kukido.eclipser.configuration.Configuration;
20 | import com.kukido.eclipser.configuration.ConfigurationBuilder;
21 | import com.kukido.eclipser.configuration.ConfigurationType;
22 | import org.jetbrains.annotations.NotNull;
23 |
24 | class EclipserAction extends AnAction {
25 |
26 | private static final String DEFAULT_FAILURE_MESSAGE = "%s\nEclipser was unable to convert launch file. Please submit a ticket at eclipser/issues";
27 | private static final String MESSAGE_FOR_UNSUPPORTED_LAUNCH_CONFIGURATION = "%s\nThe launch configuration is currently not supported by Eclipser.";
28 | private static final String MESSAGE_FOR_UNKNOWN_LAUNCH_CONFIGURATION = "%s\nThis is an unknown launch configuration. If you would like Eclipser to support it, please submit a ticket at eclipser/issues";
29 |
30 | public void actionPerformed(@NotNull AnActionEvent e) {
31 |
32 | final Project project = e.getProject();
33 | final PsiElement[] elements = getPsiElements(e);
34 |
35 | for (PsiElement element : elements) {
36 | process(element, project);
37 | }
38 | }
39 |
40 | private void process(PsiElement psiElement, Project project) {
41 | PsiFile psiFile = (PsiFile) psiElement;
42 |
43 | String message = null;
44 |
45 | try {
46 | ConfigurationType type = ConfigurationType.configurationTypeForPsiFile(psiFile);
47 | switch (type) {
48 | case UNSUPPORTED:
49 | say(String.format(MESSAGE_FOR_UNSUPPORTED_LAUNCH_CONFIGURATION, psiFile.getName()));
50 | return;
51 | case UNKNOWN:
52 | say(String.format(MESSAGE_FOR_UNKNOWN_LAUNCH_CONFIGURATION, psiFile.getName()));
53 | return;
54 | case SUPPORTED:
55 | break;
56 | }
57 |
58 | ConfigurationBuilder builder = new ConfigurationBuilder(psiFile);
59 | Configuration configuration = builder.build();
60 | Command command = configuration.getCommand();
61 | command.execute(project);
62 | } catch (EclipserException ee) {
63 | message = ee.getMessage();
64 | } catch (Exception exc) {
65 | exc.printStackTrace();
66 | message = String.format(DEFAULT_FAILURE_MESSAGE, psiFile.getName());
67 | }
68 |
69 | if (message != null) say(message);
70 | }
71 |
72 | void say(String message) {
73 | Messages.showMessageDialog(message, "Info", Messages.getInformationIcon());
74 | }
75 |
76 | @Override
77 | public void update(@NotNull AnActionEvent e) {
78 |
79 | final Presentation presentation = e.getPresentation();
80 | final Project project = e.getProject();
81 |
82 | if (project == null) {
83 | disable(presentation);
84 | return;
85 | }
86 |
87 | final VirtualFile[] files = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
88 |
89 | if (files == null) {
90 | disable(presentation);
91 | return;
92 | }
93 |
94 | for (VirtualFile file : files) {
95 | final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
96 | if (!isSupported(psiFile)) {
97 | disable(presentation);
98 | return;
99 | }
100 | }
101 |
102 | enable(presentation);
103 | }
104 |
105 | boolean isSupported(PsiFile psiFile) {
106 |
107 | if (!(psiFile instanceof XmlFile)) {
108 | return false;
109 | }
110 |
111 | final XmlFile xmlFile = (XmlFile) psiFile;
112 | final XmlDocument document = xmlFile.getDocument();
113 | if (document == null) {
114 | return false;
115 | }
116 |
117 | final XmlTag rootTag = xmlFile.getRootTag();
118 | if (rootTag == null) {
119 | return false;
120 | }
121 |
122 | final XmlAttribute typeAttribute = rootTag.getAttribute(EclipserXml.TYPE);
123 | if (typeAttribute == null) {
124 | return false;
125 | }
126 |
127 | //noinspection RedundantIfStatement
128 | if (!"launchConfiguration".equalsIgnoreCase(rootTag.getName())) {
129 | return false;
130 | }
131 |
132 | return true;
133 | }
134 |
135 | PsiElement[] getPsiElements(AnActionEvent event) {
136 |
137 | PsiElement[] psiElements = event.getData(LangDataKeys.PSI_ELEMENT_ARRAY);
138 | PsiFile psiFile = event.getData(LangDataKeys.PSI_FILE);
139 |
140 | if (psiFile == null && psiElements == null)
141 | return PsiElement.EMPTY_ARRAY;
142 |
143 | if (psiFile == null) {
144 | return psiElements;
145 | } else {
146 | return new PsiElement[]{psiFile};
147 | }
148 | }
149 |
150 | private void disable(Presentation presentation) {
151 | presentation.setEnabledAndVisible(false);
152 | }
153 |
154 | private void enable(Presentation presentation) {
155 | presentation.setEnabledAndVisible(true);
156 | }
157 |
158 | }
159 |
--------------------------------------------------------------------------------
/src/test/java/com/kukido/eclipser/command/AddApplicationConfigurationCommandTest.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.command;
2 |
3 | import com.intellij.execution.RunManager;
4 | import com.intellij.execution.application.ApplicationConfiguration;
5 | import com.intellij.execution.configurations.RunConfiguration;
6 | import com.intellij.execution.impl.RunManagerImpl;
7 | import com.intellij.openapi.project.Project;
8 | import com.intellij.testFramework.LightIdeaTestCase;
9 | import com.kukido.eclipser.EclipserException;
10 | import com.kukido.eclipser.configuration.JavaConfiguration;
11 |
12 | import java.util.LinkedHashMap;
13 | import java.util.List;
14 | import java.util.Map;
15 |
16 | public class AddApplicationConfigurationCommandTest extends LightIdeaTestCase {
17 |
18 | private static final String TEST_CASE_MODULE_NAME = "light_idea_test_case";
19 |
20 | private AddApplicationConfigurationCommand command;
21 |
22 | public void testExecuteWithFullConfiguration() throws Exception {
23 | Map envs = new LinkedHashMap();
24 | envs.put("ENV", "test");
25 | JavaConfiguration configuration = new JavaConfiguration(
26 | "kukido-test",
27 | "com.kukido.example.MainClass",
28 | TEST_CASE_MODULE_NAME,
29 | "-ea -Xmx256M",
30 | "--port 8080",
31 | envs,
32 | null
33 | );
34 |
35 | command = new AddApplicationConfigurationCommand(configuration);
36 |
37 | Project project = getProject();
38 | command.execute(project);
39 |
40 | validateCreatedConfiguration(configuration);
41 | }
42 |
43 | public void testExecuteWithoutEnvironmentVariablesConfiguration() throws Exception {
44 | JavaConfiguration configuration = new JavaConfiguration(
45 | "kukido-test",
46 | "com.kukido.example.MainClass",
47 | TEST_CASE_MODULE_NAME,
48 | "-ea -Xmx256M",
49 | "--port 8080",
50 | null,
51 | null
52 | );
53 |
54 | command = new AddApplicationConfigurationCommand(configuration);
55 |
56 | Project project = getProject();
57 | command.execute(project);
58 |
59 | validateCreatedConfiguration(configuration);
60 | }
61 |
62 | public void testExecuteWithUnknownModule() throws Exception {
63 | JavaConfiguration configuration = new JavaConfiguration(
64 | "configuration",
65 | "Main",
66 | "undefined",
67 | null,
68 | null,
69 | null,
70 | null
71 | );
72 | command = new AddApplicationConfigurationCommand(configuration);
73 |
74 | try {
75 | command.execute(getProject());
76 | fail("Execute should throw an exception when module is not found");
77 | } catch (EclipserException ignored) {
78 | }
79 | }
80 |
81 | public void testExecuteWithMinimalConfiguration() throws Exception {
82 | JavaConfiguration configuration = new JavaConfiguration(
83 | "configuration",
84 | "Main",
85 | TEST_CASE_MODULE_NAME,
86 | null,
87 | null,
88 | null,
89 | null
90 | );
91 | command = new AddApplicationConfigurationCommand(configuration);
92 | command.execute(getProject());
93 |
94 | validateCreatedConfiguration(configuration);
95 | }
96 |
97 | public void testExecuteWithExistingConfiguration() throws Exception {
98 | JavaConfiguration configuration = new JavaConfiguration(
99 | "configuration",
100 | "Main",
101 | TEST_CASE_MODULE_NAME,
102 | null,
103 | null,
104 | null,
105 | null
106 | );
107 | command = new AddApplicationConfigurationCommand(configuration);
108 | command.execute(getProject());
109 | try {
110 | command.execute(getProject());
111 | fail("Execute should throw an exception on duplicate configuration");
112 | } catch (EclipserException ignored) {
113 | }
114 | }
115 |
116 | private void validateCreatedConfiguration(JavaConfiguration configuration) {
117 | ApplicationConfiguration applicationConfiguration = null;
118 | RunManager manager = RunManager.getInstance(getProject());
119 | List configurations = manager.getAllConfigurationsList();
120 | for (RunConfiguration runConfiguration : configurations) {
121 | if (runConfiguration.getName().equals(configuration.getConfigurationName())) {
122 | if (runConfiguration instanceof ApplicationConfiguration) {
123 | applicationConfiguration = (ApplicationConfiguration) runConfiguration;
124 | }
125 | }
126 | }
127 |
128 | if (applicationConfiguration == null) {
129 | fail("Application configuration was not created");
130 | } else {
131 | assertEquals(configuration.getConfigurationName(), applicationConfiguration.getName());
132 | assertEquals(configuration.getVmParameters(), applicationConfiguration.getVMParameters());
133 | assertEquals(configuration.getProgramParameters(), applicationConfiguration.getProgramParameters());
134 | assertEquals(configuration.getMainClassName(), applicationConfiguration.getRunClass());
135 | assertEquals(configuration.getModuleName(), applicationConfiguration.getConfigurationModule().getModuleName());
136 | assertEquals(configuration.getEnvironmentVariables(), applicationConfiguration.getEnvs());
137 | }
138 | }
139 |
140 | @Override
141 | protected void tearDown() throws Exception {
142 | RunManagerImpl manager = (RunManagerImpl) RunManager.getInstance(getProject());
143 | manager.clearAll();
144 | super.tearDown();
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | com.kukido.eclipser
4 | Eclipser
5 | 0.9.4
6 | Kukido
7 | org.jetbrains.idea.maven
8 | com.intellij.modules.java
9 | AntSupport
10 |
11 |
14 | Local Java application Eclipse launcher into Application run configuration
15 | Program launch Eclipse launcher into external tool in Tools menu
16 | Maven launch configuration into Maven run configuration
17 | Remote Java application Eclipse launcher into Remote run configuration
18 | Ant launch configuration into Ant target run configuration
19 |
20 | For limitations, known issues and support please refer to plugin wiki:
21 | https://github.com/kukido/eclipser/wiki
22 | ]]>
23 |
24 |
26 | 0.9.3
27 | - updated IntelliJ version
28 | 0.9.3
29 | - updated IntelliJ version
30 | - switched to Kotlin build script
31 | 0.9.2
32 | - updated IntelliJ version
33 | 0.9.1
34 | - updated IntelliJ version
35 | 0.9.0
36 | - updated IntelliJ version
37 | 0.8.9
38 | - updated IntelliJ version
39 | 0.8.8
40 | - updated IntelliJ version
41 | 0.8.7
42 | - maintenance release (ApplicationComponent removal)
43 | 0.8.6
44 | - maintenance release (FileTypeFactory deprecation)
45 | 0.8.5
46 | - maintenance release
47 | 0.8.4
48 | - compatibility release
49 | 0.8.3
50 | - even wider compatibility range
51 | 0.8.1
52 | - wider compatibility range
53 | 0.8.0
54 | - converted to gradle, contributed by https://github.com/deepy
55 | - fixed https://github.com/kukido/eclipser/issues/32, contributed by https://github.com/taizel
56 | 0.7.1
57 | - alternative messages for unsupported/unknown launch configurations
58 | - updated format for notification messages with a link to the project page
59 | 0.7.0
60 | - support for working directory for Java launch configuration
61 | - removed Android Studio support
62 | 0.6.3
63 | - hot key bug fix
64 | - added Eclipser action to editor context menu
65 | 0.6.2
66 | - improved plugin stability in certain corner cases
67 | 0.6.1
68 | - support for escaped characters (i.e. new lines in particular) with program arguments
69 | 0.6
70 | - support for Ant launch configuration [experimental]
71 | - support for Remote Java application configuration [experimental]
72 | - multi-selection support
73 | 0.5
74 | - improved support for environment variables [contributed by Piotr Wielgolaski]
75 | - improved support for Maven launch configuration
76 | 0.4.2
77 | - improved handling for environment variables [contributed by Piotr Wielgolaski]
78 | 0.4.1
79 | - support for Android Studio
80 | 0.4
81 | - support for Maven launch configuration[experimental]
82 | - added Eclipser context menu in Commander view
83 | - updated Eclipser to generate Application runtime configurations instead of Eclipser configurations
84 | - renamed configuration name to Eclipser
85 | 0.3
86 | - added warning for duplicate configuration
87 | - added conversion for control characters (newline and carriage return)
88 | - added conversion for workspace Eclipse macro in VM arguments
89 | - changed project home from bitbucket to github
90 | 0.2
91 | - updated unit tests
92 | - updated error dialogs
93 | - updates for 12.1 version of IDEA
94 | 0.1
95 | - initial release (beta)
96 |
97 | ]]>
98 |
99 |
100 |
101 |
102 |
103 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/src/main/java/com/kukido/eclipser/configuration/ConfigurationBuilder.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.configuration;
2 |
3 | import com.intellij.psi.PsiElement;
4 | import com.intellij.psi.PsiFile;
5 | import com.intellij.psi.impl.source.xml.XmlTagImpl;
6 | import com.intellij.psi.xml.XmlFile;
7 | import com.intellij.psi.xml.XmlTag;
8 | import com.kukido.eclipser.EclipserException;
9 | import com.kukido.eclipser.EclipserXml;
10 | import org.jetbrains.annotations.Contract;
11 | import org.jetbrains.annotations.NotNull;
12 |
13 | import java.util.LinkedHashMap;
14 | import java.util.Map;
15 | import java.util.regex.Matcher;
16 |
17 | public class ConfigurationBuilder {
18 |
19 | private final PsiFile psiFile;
20 | private String name;
21 | private String mainType;
22 | private String moduleName;
23 | private String vmParameters;
24 | private String parameters;
25 | private String location;
26 | private String programArguments;
27 | private String attrWorkingDirectory;
28 | private String workingDirectory;
29 | private boolean resolveToWorkspace;
30 | private String[] profiles;
31 | private String commandLine;
32 | private Map environmentVariables;
33 | private Map connectMap;
34 | private String vmConnectorId;
35 |
36 | public ConfigurationBuilder(PsiFile psiFile) {
37 | this.psiFile = psiFile;
38 | }
39 |
40 | public Configuration build() throws EclipserException {
41 |
42 | assert psiFile instanceof XmlFile;
43 |
44 | XmlFile input = (XmlFile) psiFile;
45 |
46 | XmlTag root = input.getRootTag();
47 |
48 | @SuppressWarnings("ConstantConditions")
49 | String configurationType = root.getAttribute(EclipserXml.TYPE).getValue();
50 |
51 | PsiElement[] children = root.getChildren();
52 |
53 | for (PsiElement child : children) {
54 | if (child instanceof XmlTagImpl) {
55 | XmlTagImpl tag = (XmlTagImpl) child;
56 | String key = tag.getAttributeValue(EclipserXml.KEY);
57 | String name = tag.getName();
58 | if (EclipserXml.STRING_ATTRIBUTE.equalsIgnoreCase(name)) {
59 | String value = tag.getAttributeValue(EclipserXml.VALUE);
60 | if (EclipserXml.MAIN_TYPE_KEY.equalsIgnoreCase(key)) {
61 | mainType = value;
62 | } else if (EclipserXml.VM_ARGUMENTS_KEY.equalsIgnoreCase(key)) {
63 | vmParameters = convertWorkspace(normalizeText(value));
64 | } else if (EclipserXml.PROJECT_ATTR_KEY.equalsIgnoreCase(key)) {
65 | moduleName = value;
66 | } else if (EclipserXml.ATTR_LOCATION_KEY.equalsIgnoreCase(key)) {
67 | location = value;
68 | } else if (EclipserXml.ATTR_TOOL_ARGUMENTS_KEY.equalsIgnoreCase(key)) {
69 | parameters = convertWorkspace(value);
70 | } else if (EclipserXml.PROGRAM_ARGUMENTS_KEY.equalsIgnoreCase(key)) {
71 | programArguments = normalizeText(value);
72 | } else if (EclipserXml.ATTR_WORKING_DIRECTORY_KEY.equalsIgnoreCase(key)) {
73 | attrWorkingDirectory = convertWorkspace(value);
74 | } else if (EclipserXml.M2_PROFILES_KEY.equalsIgnoreCase(key)) {
75 | profiles = convertProfiles(value);
76 | } else if (EclipserXml.M2_GOALS_KEY.equalsIgnoreCase(key)) {
77 | commandLine = value;
78 | } else if (EclipserXml.WORKING_DIRECTORY_KEY.equalsIgnoreCase(key)) {
79 | workingDirectory = value;
80 | } else if (EclipserXml.VM_CONNECTOR_ID_KEY.equalsIgnoreCase(key)) {
81 | vmConnectorId = value;
82 | }
83 | } else if (EclipserXml.BOOLEAN_ATTRIBUTE.equalsIgnoreCase(name)) {
84 | boolean value = Boolean.valueOf(tag.getAttributeValue(EclipserXml.VALUE));
85 | if (EclipserXml.M2_WORKSPACE_RESOLUTION.equalsIgnoreCase(key)) {
86 | resolveToWorkspace = value;
87 | }
88 | } else if (EclipserXml.MAP_ATTRIBUTE.equalsIgnoreCase(name)) {
89 | if (EclipserXml.ENVIRONMENT_VARIABLES_KEY.equalsIgnoreCase(key)) {
90 | environmentVariables = getMap(tag.getChildren());
91 | } else if (EclipserXml.CONNECT_MAP_KEY.equalsIgnoreCase(key)) {
92 | connectMap = getMap(tag.getChildren());
93 | }
94 | }
95 | }
96 | }
97 |
98 | if (useLaunchFileNameForConfigurationName(configurationType)) {
99 | name = psiFile.getVirtualFile().getNameWithoutExtension();
100 | }
101 |
102 | return createConfiguration(configurationType);
103 | }
104 |
105 | private Map getMap(PsiElement[] entries) {
106 | Map result = new LinkedHashMap();
107 | for (PsiElement entry : entries) {
108 | if (entry instanceof XmlTagImpl && EclipserXml.MAP_ENTRY_ATTRIBUTE.equalsIgnoreCase(((XmlTagImpl) entry).getName())) {
109 | XmlTagImpl tag = (XmlTagImpl) entry;
110 | result.put(tag.getAttributeValue(EclipserXml.KEY), tag.getAttributeValue(EclipserXml.VALUE));
111 | }
112 | }
113 | return result;
114 | }
115 |
116 | private Configuration createConfiguration(String configurationType) throws EclipserException {
117 | if (EclipserXml.CONFIGURATION_TYPE_LOCAL_JAVA_APPLICATION.equalsIgnoreCase(configurationType)) {
118 | return new JavaConfiguration(name, mainType, moduleName, vmParameters, programArguments, environmentVariables, resolveToProjectLocation(workingDirectory));
119 | } else if (EclipserXml.CONFIGURATION_TYPE_PROGRAM_LAUNCH.equalsIgnoreCase(configurationType)) {
120 | return new ExternalToolConfiguration(name, convertWorkspace(location), parameters, attrWorkingDirectory);
121 | } else if (EclipserXml.CONFIGURATION_TYPE_MAVEN2_LAUNCH.equalsIgnoreCase(configurationType)) {
122 | return new Maven2Configuration(name, resolveToWorkspace, profiles, commandLine, resolveToProjectLocation(workingDirectory));
123 | } else if (EclipserXml.CONFIGURATION_TYPE_ANT_LAUNCH.equalsIgnoreCase(configurationType)) {
124 | return new AntTargetConfiguration(name, resolveToProjectLocation(location));
125 | } else if (EclipserXml.CONFIGURATION_TYPE_REMOTE_JAVA_APPLICATION.equalsIgnoreCase(configurationType)) {
126 | return new RemoteJavaApplicationConfiguration(name, connectMap, vmConnectorId, moduleName);
127 | } else {
128 | throw new EclipserException("Unsupported configuration type: " + configurationType);
129 | }
130 | }
131 |
132 | private String normalizeText(String value) {
133 | return normalizeQuotes(normalizeControlCharacters(value));
134 | }
135 |
136 | private String normalizeQuotes(String value) {
137 | return value.replace(""", "\"");
138 | }
139 |
140 | private String normalizeControlCharacters(String value) {
141 | String lineSeparator = String.format("%n");
142 | return value
143 | .replace("
", lineSeparator)
144 | .replace("
", lineSeparator)
145 | .replace("
", lineSeparator);
146 | }
147 |
148 | @NotNull
149 | private String[] convertProfiles(String value) {
150 | return value.split(",");
151 | }
152 |
153 | private String convertWorkspace(String value) {
154 | return replaceWorkspaceLoc(value, ExternalToolConfiguration.PROJECT_FILE_DIR);
155 | }
156 |
157 | private String replaceWorkspaceLoc(String value, String basePath) {
158 | return value.replaceAll("\\$\\{workspace_loc:([^\\}]*)\\}", Matcher.quoteReplacement(basePath) + "$1");
159 | }
160 |
161 | @Contract("null -> null")
162 | private String resolveToProjectLocation(String value) {
163 | if (value == null) {
164 | return null;
165 | } else if (value.contains(EclipserXml.PROJECT_LOC)) {
166 | return value.replace("${project_loc}", psiFile.getProject().getBasePath());
167 | } else if (value.contains(EclipserXml.WORKSPACE_LOC)) {
168 | return replaceWorkspaceLoc(value, psiFile.getProject().getBasePath());
169 | } else {
170 | return value;
171 | }
172 | }
173 |
174 | private boolean useLaunchFileNameForConfigurationName(String configurationType) {
175 | return EclipserXml.CONFIGURATION_TYPE_LOCAL_JAVA_APPLICATION.equalsIgnoreCase(configurationType) ||
176 | EclipserXml.CONFIGURATION_TYPE_PROGRAM_LAUNCH.equalsIgnoreCase(configurationType) ||
177 | EclipserXml.CONFIGURATION_TYPE_MAVEN2_LAUNCH.equalsIgnoreCase(configurationType) ||
178 | EclipserXml.CONFIGURATION_TYPE_ANT_LAUNCH.equalsIgnoreCase(configurationType) ||
179 | EclipserXml.CONFIGURATION_TYPE_REMOTE_JAVA_APPLICATION.equalsIgnoreCase(configurationType);
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | #
21 | # Gradle start up script for POSIX generated by Gradle.
22 | #
23 | # Important for running:
24 | #
25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26 | # noncompliant, but you have some other compliant shell such as ksh or
27 | # bash, then to run this script, type that shell name before the whole
28 | # command line, like:
29 | #
30 | # ksh Gradle
31 | #
32 | # Busybox and similar reduced shells will NOT work, because this script
33 | # requires all of these POSIX shell features:
34 | # * functions;
35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37 | # * compound commands having a testable exit status, especially «case»;
38 | # * various built-in commands including «command», «set», and «ulimit».
39 | #
40 | # Important for patching:
41 | #
42 | # (2) This script targets any POSIX shell, so it avoids extensions provided
43 | # by Bash, Ksh, etc; in particular arrays are avoided.
44 | #
45 | # The "traditional" practice of packing multiple parameters into a
46 | # space-separated string is a well documented source of bugs and security
47 | # problems, so this is (mostly) avoided, by progressively accumulating
48 | # options in "$@", and eventually passing that to Java.
49 | #
50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52 | # see the in-line comments for details.
53 | #
54 | # There are tweaks for specific operating systems such as AIX, CygWin,
55 | # Darwin, MinGW, and NonStop.
56 | #
57 | # (3) This script is generated from the Groovy template
58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59 | # within the Gradle project.
60 | #
61 | # You can find Gradle at https://github.com/gradle/gradle/.
62 | #
63 | ##############################################################################
64 |
65 | # Attempt to set APP_HOME
66 |
67 | # Resolve links: $0 may be a link
68 | app_path=$0
69 |
70 | # Need this for daisy-chained symlinks.
71 | while
72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73 | [ -h "$app_path" ]
74 | do
75 | ls=$( ls -ld "$app_path" )
76 | link=${ls#*' -> '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | # This is normally unused
84 | # shellcheck disable=SC2034
85 | APP_BASE_NAME=${0##*/}
86 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
87 |
88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137 |
138 | Please set the JAVA_HOME variable in your environment to match the
139 | location of your Java installation."
140 | fi
141 |
142 | # Increase the maximum file descriptors if we can.
143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144 | case $MAX_FD in #(
145 | max*)
146 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147 | # shellcheck disable=SC3045
148 | MAX_FD=$( ulimit -H -n ) ||
149 | warn "Could not query maximum file descriptor limit"
150 | esac
151 | case $MAX_FD in #(
152 | '' | soft) :;; #(
153 | *)
154 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155 | # shellcheck disable=SC3045
156 | ulimit -n "$MAX_FD" ||
157 | warn "Could not set maximum file descriptor limit to $MAX_FD"
158 | esac
159 | fi
160 |
161 | # Collect all arguments for the java command, stacking in reverse order:
162 | # * args from the command line
163 | # * the main class name
164 | # * -classpath
165 | # * -D...appname settings
166 | # * --module-path (only if needed)
167 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
168 |
169 | # For Cygwin or MSYS, switch paths to Windows format before running java
170 | if "$cygwin" || "$msys" ; then
171 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
172 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
173 |
174 | JAVACMD=$( cygpath --unix "$JAVACMD" )
175 |
176 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
177 | for arg do
178 | if
179 | case $arg in #(
180 | -*) false ;; # don't mess with options #(
181 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
182 | [ -e "$t" ] ;; #(
183 | *) false ;;
184 | esac
185 | then
186 | arg=$( cygpath --path --ignore --mixed "$arg" )
187 | fi
188 | # Roll the args list around exactly as many times as the number of
189 | # args, so each arg winds up back in the position where it started, but
190 | # possibly modified.
191 | #
192 | # NB: a `for` loop captures its iteration list before it begins, so
193 | # changing the positional parameters here affects neither the number of
194 | # iterations, nor the values presented in `arg`.
195 | shift # remove old arg
196 | set -- "$@" "$arg" # push replacement arg
197 | done
198 | fi
199 |
200 | # Collect all arguments for the java command;
201 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
202 | # shell script including quotes and variable substitutions, so put them in
203 | # double quotes to make sure that they get re-expanded; and
204 | # * put everything else in single quotes, so that it's not re-expanded.
205 |
206 | set -- \
207 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
208 | -classpath "$CLASSPATH" \
209 | org.gradle.wrapper.GradleWrapperMain \
210 | "$@"
211 |
212 | # Stop when "xargs" is not available.
213 | if ! command -v xargs >/dev/null 2>&1
214 | then
215 | die "xargs is not available"
216 | fi
217 |
218 | # Use "xargs" to parse quoted args.
219 | #
220 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
221 | #
222 | # In Bash we could simply go:
223 | #
224 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
225 | # set -- "${ARGS[@]}" "$@"
226 | #
227 | # but POSIX shell has neither arrays nor command substitution, so instead we
228 | # post-process each arg (as a line of input to sed) to backslash-escape any
229 | # character that might be a shell metacharacter, then use eval to reverse
230 | # that process (while maintaining the separation between arguments), and wrap
231 | # the whole thing up as a single "set" statement.
232 | #
233 | # This will of course break if any of these variables contains a newline or
234 | # an unmatched quote.
235 | #
236 |
237 | eval "set -- $(
238 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
239 | xargs -n1 |
240 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
241 | tr '\n' ' '
242 | )" '"$@"'
243 |
244 | exec "$JAVACMD" "$@"
245 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
--------------------------------------------------------------------------------
/src/test/java/com/kukido/eclipser/configuration/ConfigurationBuilderTest.java:
--------------------------------------------------------------------------------
1 | package com.kukido.eclipser.configuration;
2 |
3 | import com.intellij.openapi.util.io.FileUtil;
4 | import com.intellij.psi.PsiFile;
5 | import com.intellij.testFramework.LightIdeaTestCase;
6 | import org.jetbrains.annotations.NotNull;
7 |
8 | import java.io.File;
9 | import java.io.IOException;
10 | import java.util.Collections;
11 | import java.util.LinkedHashMap;
12 | import java.util.Map;
13 |
14 | public class ConfigurationBuilderTest extends LightIdeaTestCase {
15 |
16 | private ConfigurationBuilder builder;
17 |
18 | public void testJavaConfiguration() throws Exception {
19 | PsiFile file = getPsiFile("java.launch");
20 | builder = new ConfigurationBuilder(file);
21 | Configuration conf = builder.build();
22 |
23 | assertInstanceOf(conf, JavaConfiguration.class);
24 |
25 | JavaConfiguration jc = (JavaConfiguration)conf;
26 |
27 | assertEquals("java", jc.getConfigurationName());
28 | assertEquals("com.example.jetty.JettyServer", jc.getMainClassName());
29 | assertEquals("developerPortal", jc.getModuleName());
30 | assertEquals(JavaConfiguration.MODULE_DIR_MACRO, jc.getWorkingDirectory());
31 | assertEquals("-ea -XX:MaxPermSize=128M -Xmx256M -DSHUTDOWN.PORT=\"28087\" -Djetty.port=\"8087\" -Dhibernate.config.file=\"../dbAccessLayer/resource/hibernate.cfg.xml\"", jc.getVmParameters());
32 | assertEquals(Collections.emptyMap(), jc.getEnvironmentVariables());
33 | }
34 |
35 | public void testEnvConfiguration() throws Exception {
36 | PsiFile file = getPsiFile("env.launch");
37 | builder = new ConfigurationBuilder(file);
38 | Configuration conf = builder.build();
39 |
40 | assertInstanceOf(conf, JavaConfiguration.class);
41 |
42 | JavaConfiguration jc = (JavaConfiguration)conf;
43 |
44 | assertEquals("env", jc.getConfigurationName());
45 | assertEquals("Main", jc.getMainClassName());
46 | assertEquals("simple", jc.getModuleName());
47 | assertEquals(JavaConfiguration.MODULE_DIR_MACRO, jc.getWorkingDirectory());
48 | assertEquals("-Duser=${USER}", jc.getVmParameters());
49 | Map expectedEnv = new LinkedHashMap();
50 | expectedEnv.put("ENV","TEST");
51 | assertEquals(expectedEnv, jc.getEnvironmentVariables());
52 | }
53 |
54 | public void testExternalToolConfiguration() throws Exception {
55 | PsiFile file = getPsiFile("tool.launch");
56 | builder = new ConfigurationBuilder(file);
57 | Configuration conf = builder.build();
58 |
59 | assertInstanceOf(conf, ExternalToolConfiguration.class);
60 |
61 | ExternalToolConfiguration etc = (ExternalToolConfiguration)conf;
62 |
63 | assertEquals("tool", etc.getName());
64 | assertEquals(ExternalToolConfiguration.PROJECT_FILE_DIR+"/kafka/kafka/config/zookeeper.properties", etc.getParameters());
65 | assertEquals(ExternalToolConfiguration.PROJECT_FILE_DIR+"/kafka/kafka/bin/zookeeper-server-start.sh", etc.getProgram());
66 | assertEquals(ExternalToolConfiguration.PROJECT_FILE_DIR, etc.getWorkingDirectory());
67 | }
68 |
69 | public void testExternalToolConfigurationWithWorkingDirectory() throws Exception {
70 | PsiFile file = getPsiFile("directory.launch");
71 | builder = new ConfigurationBuilder(file);
72 | Configuration conf = builder.build();
73 |
74 | assertInstanceOf(conf, ExternalToolConfiguration.class);
75 |
76 | ExternalToolConfiguration etc = (ExternalToolConfiguration)conf;
77 |
78 | assertEquals("directory", etc.getName());
79 | assertEquals(ExternalToolConfiguration.PROJECT_FILE_DIR+"/ms_api/hbase/bin/start-local-hbase.sh", etc.getProgram());
80 | assertEquals(ExternalToolConfiguration.PROJECT_FILE_DIR+"/ms_api/hbase", etc.getWorkingDirectory());
81 | }
82 |
83 | public void testJavaConfigurationWithArguments() throws Exception {
84 | PsiFile file = getPsiFile("arguments.launch");
85 | builder = new ConfigurationBuilder(file);
86 | Configuration conf = builder.build();
87 |
88 | assertInstanceOf(conf, JavaConfiguration.class);
89 |
90 | JavaConfiguration jc = (JavaConfiguration)conf;
91 |
92 | assertEquals("arguments", jc.getConfigurationName());
93 | assertEquals("com.thimbleware.jmemcached.Main", jc.getMainClassName());
94 | assertEquals("jmemcached-server", jc.getModuleName());
95 | assertEquals(JavaConfiguration.MODULE_DIR_MACRO, jc.getWorkingDirectory());
96 | assertEquals("--memory 10M --port 11111 --env ${ENV}", jc.getProgramParameters());
97 | }
98 |
99 | public void testJavaConfigurationWithArgumentsIncludingNewLine() throws Exception {
100 | PsiFile file = getPsiFile("arguments-withnewline.launch");
101 | builder = new ConfigurationBuilder(file);
102 | Configuration conf = builder.build();
103 |
104 | assertInstanceOf(conf, JavaConfiguration.class);
105 |
106 | JavaConfiguration jc = (JavaConfiguration)conf;
107 |
108 | assertEquals("arguments-withnewline", jc.getConfigurationName());
109 | assertEquals("com.thimbleware.jmemcached.Main", jc.getMainClassName());
110 | assertEquals("jmemcached-server", jc.getModuleName());
111 | assertEquals(JavaConfiguration.MODULE_DIR_MACRO, jc.getWorkingDirectory());
112 | assertEquals(String.format("--memory 10M%n--port 11111 --env ${ENV}"), jc.getProgramParameters());
113 | }
114 |
115 | public void testJavaConfigurationWithControlCharacters() throws Exception {
116 | PsiFile file = getPsiFile("newline.launch");
117 | builder = new ConfigurationBuilder(file);
118 | Configuration conf = builder.build();
119 |
120 | assertInstanceOf(conf, JavaConfiguration.class);
121 |
122 | JavaConfiguration jc = (JavaConfiguration) conf;
123 |
124 | assertEquals(String.format("-ea -Xmx512M%n-Dhbase.test=true"), jc.getVmParameters());
125 | }
126 |
127 | public void testJavaConfigurationWithWorkingDirectory() throws Exception {
128 | PsiFile file = getPsiFile("java-wd.launch");
129 | builder = new ConfigurationBuilder(file);
130 | Configuration conf = builder.build();
131 |
132 | assertInstanceOf(conf, JavaConfiguration.class);
133 |
134 | JavaConfiguration jc = (JavaConfiguration) conf;
135 |
136 | String workingDirectory = getProject().getBasePath() + "/";
137 |
138 | assertEquals(workingDirectory, jc.getWorkingDirectory());
139 | }
140 |
141 | public void testJavaConfigurationWithWorskspaceDefinedInVmParameters() throws Exception {
142 | PsiFile file = getPsiFile("workspace.launch");
143 | builder = new ConfigurationBuilder(file);
144 | Configuration conf = builder.build();
145 |
146 | assertInstanceOf(conf, JavaConfiguration.class);
147 |
148 | JavaConfiguration jc = (JavaConfiguration) conf;
149 |
150 | assertEquals("-Dhibernate.config.file=" + ExternalToolConfiguration.PROJECT_FILE_DIR + "/dbAccessLayer/resource/hibernate.cfg.xml", jc.getVmParameters());
151 | }
152 |
153 | public void testMavenConfiguration() throws Exception {
154 | PsiFile file = getPsiFile("maven.launch");
155 | builder = new ConfigurationBuilder(file);
156 | Configuration conf = builder.build();
157 |
158 | assertInstanceOf(conf, Maven2Configuration.class);
159 |
160 | Maven2Configuration mc = (Maven2Configuration)conf;
161 |
162 | assertEquals("maven", mc.getConfigurationName());
163 | assertEquals("clean install -DskipTests=true", mc.getCommandLine());
164 | String workingDirectory = getProject().getBasePath() + "/";
165 | assertEquals(workingDirectory, mc.getWorkingDirectory());
166 | }
167 |
168 | public void testMavenConfigurationWithProfiles() throws Exception {
169 | PsiFile file = getPsiFile("maven.launch");
170 | builder = new ConfigurationBuilder(file);
171 | Configuration conf = builder.build();
172 |
173 | assertInstanceOf(conf, Maven2Configuration.class);
174 |
175 | Maven2Configuration mc = (Maven2Configuration)conf;
176 |
177 | assertEquals(2, mc.getProfiles().length);
178 | assertEquals("localConfig", mc.getProfiles()[0]);
179 | assertEquals("dependencies", mc.getProfiles()[1]);
180 | }
181 |
182 | public void testMavenConfigurationWithResolveToWorkspace() throws Exception {
183 | PsiFile file = getPsiFile("resolve.launch");
184 | builder = new ConfigurationBuilder(file);
185 | Configuration conf = builder.build();
186 |
187 | assertInstanceOf(conf, Maven2Configuration.class);
188 |
189 | Maven2Configuration mc = (Maven2Configuration)conf;
190 |
191 | assertTrue(mc.isResolveToWorkspace());
192 | }
193 |
194 | public void testMavenConfigurationWithAbsolutePath() throws Exception {
195 | PsiFile file = getPsiFile("maven-absolute.launch");
196 | builder = new ConfigurationBuilder(file);
197 | Configuration conf = builder.build();
198 |
199 | Maven2Configuration mc = (Maven2Configuration)conf;
200 |
201 | assertEquals("/home/test/eclipser", mc.getWorkingDirectory());
202 | }
203 |
204 | public void testMavenConfigurationWithRelativePath() throws Exception {
205 | PsiFile file = getPsiFile("maven-relative.launch");
206 | builder = new ConfigurationBuilder(file);
207 | Configuration conf = builder.build();
208 |
209 | Maven2Configuration mc = (Maven2Configuration)conf;
210 |
211 | String expected = getProject().getBasePath() + "/foobar";
212 |
213 | assertEquals(expected, mc.getWorkingDirectory());
214 | }
215 |
216 | public void testMavenConfigurationWithProjectLocation() throws Exception {
217 | PsiFile file = getPsiFile("maven-project-loc.launch");
218 | builder = new ConfigurationBuilder(file);
219 | Configuration conf = builder.build();
220 |
221 | Maven2Configuration mc = (Maven2Configuration)conf;
222 |
223 | String expected = getProject().getBasePath() + "/foobar/";
224 |
225 | assertEquals(expected, mc.getWorkingDirectory());
226 | }
227 |
228 | public void testAntTargetConfiguration() throws Exception {
229 | PsiFile file = getPsiFile("ant.launch");
230 | builder = new ConfigurationBuilder(file);
231 | Configuration conf = builder.build();
232 |
233 | AntTargetConfiguration at = (AntTargetConfiguration) conf;
234 |
235 | String expected = getProject().getBasePath() + "/developerPortal/build.xml";
236 | assertEquals(expected, at.getLocation());
237 | assertEquals("ant", at.getName());
238 | }
239 |
240 | public void testAntTargetConfigurationWithAbsolutePath() throws Exception {
241 | PsiFile file = getPsiFile("ant-github.launch");
242 | builder = new ConfigurationBuilder(file);
243 | Configuration conf = builder.build();
244 |
245 | AntTargetConfiguration at = (AntTargetConfiguration) conf;
246 |
247 | String expected = "/home/kukido/workspace/build.xml";
248 | assertEquals(expected, at.getLocation());
249 | }
250 |
251 | public void testRemoteApplicationConfiguration() throws Exception {
252 | PsiFile file = getPsiFile("remote.launch");
253 | builder = new ConfigurationBuilder(file);
254 | Configuration configuration = builder.build();
255 |
256 | RemoteJavaApplicationConfiguration rlc = (RemoteJavaApplicationConfiguration)configuration;
257 | assertEquals("localhost", rlc.getHostName());
258 | assertEquals("8000", rlc.getPort());
259 | assertEquals("remote", rlc.getName());
260 | assertEquals("org.eclipse.jdt.launching.socketAttachConnector", rlc.getVmConnectorId());
261 | assertEquals("spacebook", rlc.getModuleName());
262 | }
263 |
264 | @NotNull
265 | private PsiFile getPsiFile(String name) throws IOException {
266 | return createFile(name.replace(".launch", ".xml"), FileUtil.loadFile(new File(this.getClass().getClassLoader().getResource(name).getPath())));
267 | }
268 | }
269 |
--------------------------------------------------------------------------------