Skip to content

Commit 92f566e

Browse files
committed
Add support for wildfly-jar maven plugin
Signed-off-by: Rob Stryker <[email protected]>
1 parent 850e0db commit 92f566e

File tree

8 files changed

+470
-3
lines changed

8 files changed

+470
-3
lines changed

as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ Require-Bundle: org.apache.ant;bundle-version="1.7.1",
3434
org.jboss.tools.foundation.core;bundle-version="1.1.0",
3535
org.jboss.tools.jmx.core;bundle-version="1.6.0";visibility:=reexport,
3636
org.eclipse.jdt.debug;bundle-version="3.8.100",
37-
org.jboss.tools.common.jdt.debug;bundle-version="3.10.2"
37+
org.jboss.tools.common.jdt.debug;bundle-version="3.10.2",
38+
org.eclipse.m2e.launching
3839
Bundle-ActivationPolicy: lazy
3940
Export-Package: org.jboss.ide.eclipse.as.core,
4041
org.jboss.ide.eclipse.as.core.extensions.descriptors,
@@ -59,7 +60,8 @@ Export-Package: org.jboss.ide.eclipse.as.core,
5960
org.jboss.tools.as.core.server.controllable.subsystems,
6061
org.jboss.tools.as.core.server.controllable.subsystems.internal;x-friends:="org.jboss.tools.as.test.core,org.jboss.ide.eclipse.as.ui",
6162
org.jboss.tools.as.core.server.controllable.systems,
62-
org.jboss.tools.as.core.server.controllable.util
63+
org.jboss.tools.as.core.server.controllable.util,
64+
org.jboss.tools.as.core.server.wildflyjar
6365
Bundle-ClassPath: dom4j-1.6.1.jar,
6466
jaxen-1.1-beta-6.jar,
6567
getopt.jar,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2021 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v1.0 which accompanies this distribution,
6+
* and is available at http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package org.jboss.tools.as.core.server.wildflyjar;
12+
13+
import org.eclipse.m2e.internal.launch.MavenLaunchDelegate;
14+
15+
public class WildflyJarLaunchConfigurationDelegate extends MavenLaunchDelegate {
16+
public static final String ID = "org.jboss.tools.as.core.server.wildflyjar.WildflyJarLaunchConfiguration";
17+
public static final String DEFAULT_GOAL = "wildfly-jar:dev-watch";
18+
}

as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,4 +3021,17 @@
30213021
</supported>
30223022
</extension>
30233023
<!-- AUTOGEN_SERVER_ADAPTER_CHUNK -->
3024+
3025+
3026+
<extension
3027+
point="org.eclipse.debug.core.launchConfigurationTypes">
3028+
<launchConfigurationType
3029+
delegate="org.jboss.tools.as.core.server.wildflyjar.WildflyJarLaunchConfigurationDelegate"
3030+
id="org.jboss.tools.as.core.server.wildflyjar.WildflyJarLaunchConfiguration"
3031+
sourceLocatorId="org.eclipse.m2e.launching.MavenSourceLocator"
3032+
sourcePathComputerId="org.eclipse.m2e.launching.MavenSourceComputer"
3033+
modes="run, debug"
3034+
name="WildFly Jar">
3035+
</launchConfigurationType>
3036+
</extension>
30243037
</plugin>

as/plugins/org.jboss.ide.eclipse.as.ui/META-INF/MANIFEST.MF

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ Require-Bundle: com.ibm.icu;bundle-version="4.2.1",
6565
org.jboss.tools.foundation.ui;bundle-version="1.1.0",
6666
org.jboss.tools.jmx.core;bundle-version="1.7.0",
6767
org.eclipse.jst.server.ui;bundle-version="1.1.100",
68-
org.eclipse.swt
68+
org.eclipse.swt,
69+
org.eclipse.m2e.core,
70+
org.eclipse.m2e.maven.runtime,
71+
org.eclipse.m2e.launching
6972
Bundle-ActivationPolicy: lazy
7073
Export-Package: org.jboss.ide.eclipse.as.ui,
7174
org.jboss.ide.eclipse.as.ui.actions,
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package org.jboss.ide.eclipse.as.ui.wildflyjar;
2+
3+
import java.util.ArrayList;
4+
5+
import org.eclipse.core.resources.IContainer;
6+
import org.eclipse.core.resources.IFile;
7+
import org.eclipse.core.resources.IFolder;
8+
import org.eclipse.core.resources.IProject;
9+
import org.eclipse.core.runtime.CoreException;
10+
import org.eclipse.core.runtime.IAdaptable;
11+
import org.eclipse.core.runtime.IPath;
12+
import org.eclipse.core.runtime.Path;
13+
import org.eclipse.debug.core.DebugPlugin;
14+
import org.eclipse.debug.core.ILaunchConfiguration;
15+
import org.eclipse.debug.core.ILaunchConfigurationType;
16+
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
17+
import org.eclipse.debug.core.ILaunchManager;
18+
import org.eclipse.debug.ui.DebugUITools;
19+
import org.eclipse.debug.ui.ILaunchGroup;
20+
import org.eclipse.debug.ui.ILaunchShortcut;
21+
import org.eclipse.jface.viewers.ISelection;
22+
import org.eclipse.jface.viewers.IStructuredSelection;
23+
import org.eclipse.m2e.actions.MavenLaunchConstants;
24+
import org.eclipse.m2e.internal.launch.LaunchingUtils;
25+
import org.eclipse.swt.widgets.Shell;
26+
import org.eclipse.ui.IEditorPart;
27+
import org.eclipse.ui.PlatformUI;
28+
import org.jboss.tools.as.core.server.wildflyjar.WildflyJarLaunchConfigurationDelegate;
29+
30+
public class RunAsWildflyJar implements ILaunchShortcut {
31+
public static final String ID_EXTERNAL_TOOLS_LAUNCH_GROUP = "org.eclipse.ui.externaltools.launchGroup"; //$NON-NLS-1$
32+
33+
@Override
34+
public void launch(IEditorPart editor, String mode) {
35+
// Do nothing
36+
}
37+
38+
@Override
39+
public void launch(ISelection selection, String mode) {
40+
IContainer basedir = getBaseDir(selection);
41+
if (basedir == null)
42+
return;
43+
44+
ILaunchConfiguration launchConfiguration = getLaunchConfiguration(basedir, mode);
45+
if (launchConfiguration == null) {
46+
return;
47+
}
48+
49+
ILaunchGroup group = DebugUITools.getLaunchGroup(launchConfiguration, mode);
50+
String groupId = group != null ? group.getIdentifier() : ID_EXTERNAL_TOOLS_LAUNCH_GROUP;
51+
DebugUITools.openLaunchConfigurationDialog(getShell(), launchConfiguration, groupId, null);
52+
}
53+
54+
private ILaunchConfiguration getLaunchConfiguration(IContainer basedir, String mode) {
55+
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
56+
ILaunchConfigurationType launchConfigurationType = launchManager
57+
.getLaunchConfigurationType(WildflyJarLaunchConfigurationDelegate.ID);
58+
59+
try {
60+
ArrayList<ILaunchConfiguration> match = findMatchingConfigs(launchManager, launchConfigurationType, basedir.getLocation());
61+
if( match != null && match.size() > 0 )
62+
return match.get(0);
63+
64+
String newName = launchManager.generateLaunchConfigurationName(basedir.getLocation().lastSegment());
65+
ILaunchConfigurationWorkingCopy workingCopy = launchConfigurationType.newInstance(null, newName);
66+
workingCopy.setAttribute(MavenLaunchConstants.ATTR_POM_DIR,
67+
LaunchingUtils.generateProjectLocationVariableExpression(basedir.getProject()));
68+
workingCopy.setAttribute(MavenLaunchConstants.ATTR_GOALS, WildflyJarLaunchConfigurationDelegate.DEFAULT_GOAL);
69+
return workingCopy.doSave();
70+
} catch (Exception ex) {
71+
}
72+
return null;
73+
}
74+
75+
private ArrayList<ILaunchConfiguration> findMatchingConfigs(ILaunchManager manager, ILaunchConfigurationType type,
76+
IPath basedirLocation) throws CoreException {
77+
ILaunchConfiguration[] launchConfigurations = manager.getLaunchConfigurations(type);
78+
ArrayList<ILaunchConfiguration> matchingConfigs = new ArrayList<ILaunchConfiguration>();
79+
for (ILaunchConfiguration configuration : launchConfigurations) {
80+
try {
81+
// substitute variables (may throw exceptions)
82+
String workDir = LaunchingUtils
83+
.substituteVar(configuration.getAttribute(MavenLaunchConstants.ATTR_POM_DIR, (String) null));
84+
if (workDir == null) {
85+
continue;
86+
}
87+
IPath workPath = new Path(workDir);
88+
if (basedirLocation.equals(workPath)) {
89+
matchingConfigs.add(configuration);
90+
}
91+
} catch (CoreException e) {
92+
}
93+
}
94+
return matchingConfigs;
95+
}
96+
97+
private Shell getShell() {
98+
return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
99+
}
100+
101+
protected IContainer getBaseDir(ISelection selection) {
102+
IContainer basedir = null;
103+
if (selection instanceof IStructuredSelection) {
104+
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
105+
Object object = structuredSelection.getFirstElement();
106+
107+
if (object instanceof IProject || object instanceof IFolder) {
108+
basedir = (IContainer) object;
109+
} else if (object instanceof IFile) {
110+
basedir = ((IFile) object).getParent();
111+
} else if (object instanceof IAdaptable) {
112+
IAdaptable adaptable = (IAdaptable) object;
113+
Object adapter = adaptable.getAdapter(IProject.class);
114+
if (adapter != null) {
115+
basedir = (IContainer) adapter;
116+
} else {
117+
adapter = adaptable.getAdapter(IFolder.class);
118+
if (adapter != null) {
119+
basedir = (IContainer) adapter;
120+
} else {
121+
adapter = adaptable.getAdapter(IFile.class);
122+
if (adapter != null) {
123+
basedir = ((IFile) object).getParent();
124+
}
125+
}
126+
}
127+
}
128+
}
129+
return basedir;
130+
}
131+
}

0 commit comments

Comments
 (0)