Skip to content

Commit

Permalink
Add support for wildfly-jar maven plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <rob@oxbeef.net>
  • Loading branch information
robstryker committed Jun 16, 2021
1 parent d26dafd commit ec1f88e
Show file tree
Hide file tree
Showing 8 changed files with 470 additions and 3 deletions.
6 changes: 4 additions & 2 deletions as/plugins/org.jboss.ide.eclipse.as.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Require-Bundle: org.apache.ant;bundle-version="1.7.1",
org.jboss.tools.foundation.core;bundle-version="1.1.0",
org.jboss.tools.jmx.core;bundle-version="1.6.0";visibility:=reexport,
org.eclipse.jdt.debug;bundle-version="3.8.100",
org.jboss.tools.common.jdt.debug;bundle-version="3.10.2"
org.jboss.tools.common.jdt.debug;bundle-version="3.10.2",
org.eclipse.m2e.launching
Bundle-ActivationPolicy: lazy
Export-Package: org.jboss.ide.eclipse.as.core,
org.jboss.ide.eclipse.as.core.extensions.descriptors,
Expand All @@ -59,7 +60,8 @@ Export-Package: org.jboss.ide.eclipse.as.core,
org.jboss.tools.as.core.server.controllable.subsystems,
org.jboss.tools.as.core.server.controllable.subsystems.internal;x-friends:="org.jboss.tools.as.test.core,org.jboss.ide.eclipse.as.ui",
org.jboss.tools.as.core.server.controllable.systems,
org.jboss.tools.as.core.server.controllable.util
org.jboss.tools.as.core.server.controllable.util,
org.jboss.tools.as.core.server.wildflyjar
Bundle-ClassPath: dom4j-1.6.1.jar,
jaxen-1.1-beta-6.jar,
getopt.jar,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*******************************************************************************
* Copyright (c) 2021 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.as.core.server.wildflyjar;

import org.eclipse.m2e.internal.launch.MavenLaunchDelegate;

public class WildflyJarLaunchConfigurationDelegate extends MavenLaunchDelegate {
public static final String ID = "org.jboss.tools.as.core.server.wildflyjar.WildflyJarLaunchConfiguration";
public static final String DEFAULT_GOAL = "wildfly-jar:dev-watch";
}
13 changes: 13 additions & 0 deletions as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3021,4 +3021,17 @@
</supported>
</extension>
<!-- AUTOGEN_SERVER_ADAPTER_CHUNK -->


<extension
point="org.eclipse.debug.core.launchConfigurationTypes">
<launchConfigurationType
delegate="org.jboss.tools.as.core.server.wildflyjar.WildflyJarLaunchConfigurationDelegate"
id="org.jboss.tools.as.core.server.wildflyjar.WildflyJarLaunchConfiguration"
sourceLocatorId="org.eclipse.m2e.launching.MavenSourceLocator"
sourcePathComputerId="org.eclipse.m2e.launching.MavenSourceComputer"
modes="run, debug"
name="WildFly Jar">
</launchConfigurationType>
</extension>
</plugin>
5 changes: 4 additions & 1 deletion as/plugins/org.jboss.ide.eclipse.as.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ Require-Bundle: com.ibm.icu;bundle-version="4.2.1",
org.jboss.tools.foundation.ui;bundle-version="1.1.0",
org.jboss.tools.jmx.core;bundle-version="1.7.0",
org.eclipse.jst.server.ui;bundle-version="1.1.100",
org.eclipse.swt
org.eclipse.swt,
org.eclipse.m2e.core,
org.eclipse.m2e.maven.runtime,
org.eclipse.m2e.launching
Bundle-ActivationPolicy: lazy
Export-Package: org.jboss.ide.eclipse.as.ui,
org.jboss.ide.eclipse.as.ui.actions,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package org.jboss.ide.eclipse.as.ui.wildflyjar;

import java.util.ArrayList;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.ILaunchGroup;
import org.eclipse.debug.ui.ILaunchShortcut;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.m2e.actions.MavenLaunchConstants;
import org.eclipse.m2e.internal.launch.LaunchingUtils;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.jboss.tools.as.core.server.wildflyjar.WildflyJarLaunchConfigurationDelegate;

public class RunAsWildflyJar implements ILaunchShortcut {
public static final String ID_EXTERNAL_TOOLS_LAUNCH_GROUP = "org.eclipse.ui.externaltools.launchGroup"; //$NON-NLS-1$

@Override
public void launch(IEditorPart editor, String mode) {
// Do nothing
}

@Override
public void launch(ISelection selection, String mode) {
IContainer basedir = getBaseDir(selection);
if (basedir == null)
return;

ILaunchConfiguration launchConfiguration = getLaunchConfiguration(basedir, mode);
if (launchConfiguration == null) {
return;
}

ILaunchGroup group = DebugUITools.getLaunchGroup(launchConfiguration, mode);
String groupId = group != null ? group.getIdentifier() : ID_EXTERNAL_TOOLS_LAUNCH_GROUP;
DebugUITools.openLaunchConfigurationDialog(getShell(), launchConfiguration, groupId, null);
}

private ILaunchConfiguration getLaunchConfiguration(IContainer basedir, String mode) {
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType launchConfigurationType = launchManager
.getLaunchConfigurationType(WildflyJarLaunchConfigurationDelegate.ID);

try {
ArrayList<ILaunchConfiguration> match = findMatchingConfigs(launchManager, launchConfigurationType, basedir.getLocation());
if( match != null && match.size() > 0 )
return match.get(0);

String newName = launchManager.generateLaunchConfigurationName(basedir.getLocation().lastSegment());
ILaunchConfigurationWorkingCopy workingCopy = launchConfigurationType.newInstance(null, newName);
workingCopy.setAttribute(MavenLaunchConstants.ATTR_POM_DIR,
LaunchingUtils.generateProjectLocationVariableExpression(basedir.getProject()));
workingCopy.setAttribute(MavenLaunchConstants.ATTR_GOALS, WildflyJarLaunchConfigurationDelegate.DEFAULT_GOAL);
return workingCopy.doSave();
} catch (Exception ex) {
}
return null;
}

private ArrayList<ILaunchConfiguration> findMatchingConfigs(ILaunchManager manager, ILaunchConfigurationType type,
IPath basedirLocation) throws CoreException {
ILaunchConfiguration[] launchConfigurations = manager.getLaunchConfigurations(type);
ArrayList<ILaunchConfiguration> matchingConfigs = new ArrayList<ILaunchConfiguration>();
for (ILaunchConfiguration configuration : launchConfigurations) {
try {
// substitute variables (may throw exceptions)
String workDir = LaunchingUtils
.substituteVar(configuration.getAttribute(MavenLaunchConstants.ATTR_POM_DIR, (String) null));
if (workDir == null) {
continue;
}
IPath workPath = new Path(workDir);
if (basedirLocation.equals(workPath)) {
matchingConfigs.add(configuration);
}
} catch (CoreException e) {
}
}
return matchingConfigs;
}

private Shell getShell() {
return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
}

protected IContainer getBaseDir(ISelection selection) {
IContainer basedir = null;
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object object = structuredSelection.getFirstElement();

if (object instanceof IProject || object instanceof IFolder) {
basedir = (IContainer) object;
} else if (object instanceof IFile) {
basedir = ((IFile) object).getParent();
} else if (object instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) object;
Object adapter = adaptable.getAdapter(IProject.class);
if (adapter != null) {
basedir = (IContainer) adapter;
} else {
adapter = adaptable.getAdapter(IFolder.class);
if (adapter != null) {
basedir = (IContainer) adapter;
} else {
adapter = adaptable.getAdapter(IFile.class);
if (adapter != null) {
basedir = ((IFile) object).getParent();
}
}
}
}
}
return basedir;
}
}
Loading

0 comments on commit ec1f88e

Please sign in to comment.