Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Jakarta version switch to RWT launch configuration. #96

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bundles/org.eclipse.rap.tools.launch.rwt/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)",
org.eclipse.jdt.launching;bundle-version="[3.5.0,4.0.0)",
org.eclipse.jetty.ee10.servlet;bundle-version="[12.0.0,13.0.0)",
org.eclipse.jetty.ee10.webapp;bundle-version="[12.0.0,13.0.0)",
org.eclipse.jetty.ee8.server;bundle-version="[12.0.0,13.0.0)",
org.eclipse.jetty.ee8.servlet;bundle-version="[12.0.0,13.0.0)",
org.eclipse.jetty.ee8.webapp;bundle-version="[12.0.0,13.0.0)",
org.eclipse.jetty.http;bundle-version="[12.0.0,13.0.0)",
org.eclipse.jetty.io;bundle-version="[12.0.0,13.0.0)",
org.eclipse.jetty.security;bundle-version="[12.0.0,13.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public static enum LaunchTarget {
ENTRY_POINT,
WEB_XML,
}

public static enum JakartaVersion {
EE8,
EE10,
}

// Attribute names from JDT's Java Launcher
private static final String PROJECT_NAME
Expand All @@ -57,6 +62,7 @@ public static enum LaunchTarget {
private static final String OPEN_BROWSER = PREFIX + "openBrowser"; //$NON-NLS-1$
private static final String BROWSER_MODE = PREFIX + "browserMode"; //$NON-NLS-1$
private static final String DEVELOPMENT_MODE = PREFIX + "developmentMode"; //$NON-NLS-1$
public static final String JAKARTA_VERSION = PREFIX + "jakartaVersion"; //$NON-NLS-1$

// Default values for attributes
private static final LaunchTarget DEFAULT_LAUNCH_TARGET = LaunchTarget.ENTRY_POINT;
Expand All @@ -77,6 +83,7 @@ public static enum LaunchTarget {
private static final boolean DEFAULT_OPEN_BROWSER = true;
private static final String DEFAULT_BROWSER_MODE = BrowserMode.INTERNAL.toString();
private static final boolean DEFAULT_DEVELOPMENT_MODE = true;
public static final JakartaVersion DEFAULT_JAKARTA_VERSION = JakartaVersion.EE10;


public static ILaunchConfigurationType getType() {
Expand All @@ -102,6 +109,7 @@ public static void setDefaults( ILaunchConfigurationWorkingCopy config ) {
config.setAttribute( SESSION_TIMEOUT, DEFAULT_SESSION_TIMEOUT );
config.setAttribute( OPEN_BROWSER, DEFAULT_OPEN_BROWSER );
config.setAttribute( BROWSER_MODE, DEFAULT_BROWSER_MODE );
config.setAttribute( JAKARTA_VERSION, DEFAULT_JAKARTA_VERSION.toString() );
}

private final ILaunchConfiguration config;
Expand Down Expand Up @@ -291,6 +299,17 @@ public void setDevelopmentMode( boolean developmentMode ) {
checkWorkingCopy();
workingCopy.setAttribute( DEVELOPMENT_MODE, developmentMode );
}

public JakartaVersion getJakartaVersion() {
String attribute = getAttribute( JAKARTA_VERSION, DEFAULT_JAKARTA_VERSION.name() );
return Enum.valueOf( JakartaVersion.class, attribute );
}

public void setJakartaVersion( JakartaVersion jakartaVersion ) {
checkNotNull( jakartaVersion, "jakartaVersion" ); //$NON-NLS-1$
checkWorkingCopy();
workingCopy.setAttribute( JAKARTA_VERSION, jakartaVersion.name() );
}

private static void checkNotNull( Object argument, String argumentName ) {
if( argument == null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
import org.eclipse.rap.tools.launch.rwt.internal.config.RWTLaunchConfig;
import org.eclipse.rap.tools.launch.rwt.internal.util.BundleFileLocator;
import org.eclipse.rap.tools.launch.rwt.internal.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class RWTLaunchDelegate extends JavaLaunchDelegate {

private static final Logger LOG = LoggerFactory.getLogger( RWTLaunchDelegate.class );
private static final String VMARG_JETTY_HOME = " -Djetty.home="; //$NON-NLS-1$
private static final String VMARG_DEVELOPMENT_MODE
= " -Dorg.eclipse.rap.rwt.developmentMode="; //$NON-NLS-1$
Expand Down Expand Up @@ -72,6 +75,10 @@ public String[] getClasspath( ILaunchConfiguration configuration ) throws CoreEx
list.add( BundleFileLocator.locate( "jakarta.servlet-api" ) ); //$NON-NLS-1$
list.add( BundleFileLocator.locate( "org.eclipse.jetty.ee10.servlet" ) ); //$NON-NLS-1$
list.add( BundleFileLocator.locate( "org.eclipse.jetty.ee10.webapp" ) ); //$NON-NLS-1$
list.add( BundleFileLocator.locate( "org.eclipse.jetty.ee8.server" ) ); //$NON-NLS-1$
list.add( BundleFileLocator.locate( "org.eclipse.jetty.ee8.security" ) ); //$NON-NLS-1$
list.add( BundleFileLocator.locate( "org.eclipse.jetty.ee8.servlet" ) ); //$NON-NLS-1$
list.add( BundleFileLocator.locate( "org.eclipse.jetty.ee8.webapp" ) ); //$NON-NLS-1$
list.add( BundleFileLocator.locate( "org.eclipse.jetty.server" ) ); //$NON-NLS-1$
list.add( BundleFileLocator.locate( "org.eclipse.jetty.security" ) ); //$NON-NLS-1$
list.add( BundleFileLocator.locate( "org.eclipse.jetty.http" ) ); //$NON-NLS-1$
Expand All @@ -93,8 +100,15 @@ public String getProgramArguments( ILaunchConfiguration configuration ) {
String port = String.valueOf( launch.getPort() );
String contextPath = getContextPath();
String webAppDirectory = launch.getWebAppPath().getAbsolutePath();
Object[] arguments = new Object[] { port, contextPath, webAppDirectory };
return MessageFormat.format( "{0} {1} \"{2}\"", arguments ); //$NON-NLS-1$
String jakartaVersion = RWTLaunchConfig.DEFAULT_JAKARTA_VERSION.name();
try {
jakartaVersion = configuration.getAttribute( RWTLaunchConfig.JAKARTA_VERSION,
RWTLaunchConfig.DEFAULT_JAKARTA_VERSION.name() );
} catch( CoreException exception ) {
LOG.error( exception.getLocalizedMessage(), exception );
}
Object[] arguments = new Object[] { port, contextPath, webAppDirectory, jakartaVersion };
return MessageFormat.format( "{0} {1} \"{2}\" \"{3}\"", arguments ); //$NON-NLS-1$
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
******************************************************************************/
package org.eclipse.rap.tools.launch.rwt.internal.jetty;

import org.eclipse.jetty.ee10.webapp.WebAppContext;

import org.eclipse.jetty.server.Server;
import org.eclipse.rap.tools.launch.rwt.internal.config.RWTLaunchConfig.JakartaVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -23,10 +24,18 @@ public class JettyLauncher {
public static void main( String[] args ) {
try {
Server server = new Server( Integer.parseInt( args[ 0 ] ) );
WebAppContext webapp = new WebAppContext();
webapp.setContextPath( args[ 1 ] );
webapp.setWar( args[ 2 ] );
server.setHandler( webapp );
JakartaVersion jakartaVersion = Enum.valueOf( JakartaVersion.class, args[ 3 ] );
if( jakartaVersion == JakartaVersion.EE8 ) {
org.eclipse.jetty.ee8.webapp.WebAppContext webapp = new org.eclipse.jetty.ee8.webapp.WebAppContext();
webapp.setContextPath( args[ 1 ] );
webapp.setWar( args[ 2 ] );
server.setHandler( webapp );
} else {
org.eclipse.jetty.ee10.webapp.WebAppContext webapp = new org.eclipse.jetty.ee10.webapp.WebAppContext();
webapp.setContextPath( args[ 1 ] );
webapp.setWar( args[ 2 ] );
server.setHandler( webapp );
}
server.start();
server.join();
} catch( Exception exception ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.rap.tools.launch.rwt.internal.config.RWTLaunchConfig;
import org.eclipse.rap.tools.launch.rwt.internal.config.RWTLaunchConfig.JakartaVersion;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.GridData;
Expand All @@ -28,6 +29,8 @@ public class ServerSettingsSection extends RWTLaunchTab {
private Spinner spnSessionTimeout;
private Button cbContextPath;
private Text txtContextPath;
private Button rbEe8;
private Button rbEe10;

public String getName() {
return "Server Settings";
Expand Down Expand Up @@ -58,12 +61,28 @@ public void createControl( Composite parent ) {
cbContextPath.setText( "Context pat&h:" );
cbContextPath.addSelectionListener( new UpdateConfigSelectionListener() );
txtContextPath = new Text( group, SWT.BORDER | SWT.SINGLE );
GridDataFactory.fillDefaults().grab( true, false ).span( 3, 1 ).applyTo( txtContextPath );
GridDataFactory.fillDefaults().grab( true, false ).applyTo( txtContextPath );
txtContextPath.addModifyListener( new UpdateConfigModifyListener() );
Composite cJakartaVersion = createJakartaVersionPart( group );
GridDataFactory.fillDefaults().grab( true, false ).span( 2, 1 ).indent( 25, 0 ).applyTo( cJakartaVersion );
updateEnablement();
setControl( group );
HelpContextIds.assign( getControl(), HelpContextIds.MAIN_TAB );
}

private Composite createJakartaVersionPart( Composite parent ) {
Composite composite = new Composite( parent, SWT.NONE );
composite.setLayout( new GridLayout( 3, false ) );
Label lblServletPath = new Label( composite, SWT.NONE );
lblServletPath.setText( "Jakarta Version:" );
rbEe8 = new Button( composite, SWT.RADIO );
rbEe8.setText( JakartaVersion.EE8.name() );
rbEe8.addSelectionListener( new JakartaVersionSelectionListener() );
rbEe10 = new Button( composite, SWT.RADIO );
rbEe10.setText( JakartaVersion.EE10.name() );
rbEe10.addSelectionListener( new JakartaVersionSelectionListener() );
return composite;
}

public void initializeFrom( RWTLaunchConfig launchConfig ) {
cbManualPort.setSelection( launchConfig.getUseManualPort() );
Expand All @@ -72,6 +91,8 @@ public void initializeFrom( RWTLaunchConfig launchConfig ) {
spnSessionTimeout.setSelection( launchConfig.getSessionTimeout() );
cbContextPath.setSelection( launchConfig.getUseManualContextPath() );
txtContextPath.setText( launchConfig.getContextPath() );
rbEe8.setSelection( JakartaVersion.EE8.equals( launchConfig.getJakartaVersion() ) );
rbEe10.setSelection( JakartaVersion.EE10.equals( launchConfig.getJakartaVersion() ) );
updateEnablement();
}

Expand All @@ -82,6 +103,11 @@ public void performApply( RWTLaunchConfig launchConfig ) {
launchConfig.setSessionTimeout( spnSessionTimeout.getSelection() );
launchConfig.setUseManualContextPath( cbContextPath.getSelection() );
launchConfig.setContextPath( txtContextPath.getText().trim() );
if( rbEe8.getSelection() ) {
launchConfig.setJakartaVersion( JakartaVersion.EE8 );
} else if( rbEe10.getSelection() ) {
launchConfig.setJakartaVersion( JakartaVersion.EE10 );
}
}

private void updateEnablement() {
Expand All @@ -102,5 +128,11 @@ public void modifyText( ModifyEvent event ) {
updateLaunchConfigurationDialog();
}
}

private class JakartaVersionSelectionListener extends SelectionAdapter {
public void widgetSelected( SelectionEvent event ) {
updateLaunchConfigurationDialog();
}
}

}