|
Lines 40-46
import org.eclipse.ui.handlers.IHandlerService;
Link Here
|
| 40 |
* {@link #createTemplateSections()}. |
40 |
* {@link #createTemplateSections()}. |
| 41 |
* </p> |
41 |
* </p> |
| 42 |
* <p> |
42 |
* <p> |
| 43 |
* This class is responsible for modying the MANIFEST.MF after it has been |
43 |
* This class is responsible for modifying the MANIFEST.MF after it has been |
| 44 |
* created, in order to make it work for RAP. |
44 |
* created, in order to make it work for RAP. |
| 45 |
* </p> |
45 |
* </p> |
| 46 |
*/ |
46 |
*/ |
|
Lines 50-65
abstract class AbstractRAPWizard extends NewPluginTemplateWizard {
Link Here
|
| 50 |
private static final String CHARSET = "ISO-8859-1"; //$NON-NLS-1$ |
50 |
private static final String CHARSET = "ISO-8859-1"; //$NON-NLS-1$ |
| 51 |
private static final String PREFERENCE_INSTALL_TARGET = "installTarget"; //$NON-NLS-1$ |
51 |
private static final String PREFERENCE_INSTALL_TARGET = "installTarget"; //$NON-NLS-1$ |
| 52 |
|
52 |
|
|
|
53 |
private static final String TAG_PACKAGE_NAME = "${packageName}"; //$NON-NLS-1$ |
| 53 |
private static final String TAG_SERVLET_PATH = "${servletPath}"; //$NON-NLS-1$ |
54 |
private static final String TAG_SERVLET_PATH = "${servletPath}"; //$NON-NLS-1$ |
| 54 |
private static final String TAG_PLUGIN_ID = "${pluginId}"; //$NON-NLS-1$ |
55 |
private static final String TAG_PLUGIN_ID = "${pluginId}"; //$NON-NLS-1$ |
| 55 |
private static final String TAG_PROJECT_NAME = "${projectName}"; //$NON-NLS-1$ |
56 |
private static final String TAG_PROJECT_NAME = "${projectName}"; //$NON-NLS-1$ |
| 56 |
|
57 |
|
| 57 |
public boolean performFinish( final IProject project, |
58 |
public boolean performFinish( final IProject project, |
| 58 |
final IPluginModelBase model, |
59 |
final IPluginModelBase model, |
| 59 |
final IProgressMonitor monitor ) |
60 |
final IProgressMonitor monitor ) |
| 60 |
{ |
61 |
{ |
| 61 |
boolean result = super.performFinish( project, model, monitor ); |
62 |
boolean result = super.performFinish( project, model, monitor ); |
| 62 |
if( result ) { |
63 |
if( result ) { |
|
|
64 |
copyAppConfig( project, model ); |
| 63 |
copyLaunchConfig( project, model ); |
65 |
copyLaunchConfig( project, model ); |
| 64 |
IResourceChangeListener listener = new ManifestListener(); |
66 |
IResourceChangeListener listener = new ManifestListener(); |
| 65 |
ResourcesPlugin.getWorkspace().addResourceChangeListener( listener ); |
67 |
ResourcesPlugin.getWorkspace().addResourceChangeListener( listener ); |
|
Lines 67-72
abstract class AbstractRAPWizard extends NewPluginTemplateWizard {
Link Here
|
| 67 |
} |
69 |
} |
| 68 |
return result; |
70 |
return result; |
| 69 |
} |
71 |
} |
|
|
72 |
|
| 73 |
private void copyAppConfig( final IProject project, |
| 74 |
final IPluginModelBase model ) { |
| 75 |
IFile appConfig = project.getFile( "META-INF/appconfig.xml" ); |
| 76 |
if ( appConfig.exists() ) { |
| 77 |
try { |
| 78 |
String pluginId = model.getPluginBase().getId(); |
| 79 |
InputStream stream = readFile( appConfig.getContents(), project.getName(), pluginId ); |
| 80 |
appConfig.setContents( stream, true, false, null ); |
| 81 |
} catch( final CoreException ce ) { |
| 82 |
TemplateUtil.log( ce.getStatus() ); |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 70 |
|
86 |
|
| 71 |
private void copyLaunchConfig( final IProject project, |
87 |
private void copyLaunchConfig( final IProject project, |
| 72 |
final IPluginModelBase model ) |
88 |
final IPluginModelBase model ) |
|
Lines 75-81
abstract class AbstractRAPWizard extends NewPluginTemplateWizard {
Link Here
|
| 75 |
IFile launchConfig = project.getFile( name ); |
91 |
IFile launchConfig = project.getFile( name ); |
| 76 |
if( !launchConfig.exists() ) { |
92 |
if( !launchConfig.exists() ) { |
| 77 |
try { |
93 |
try { |
| 78 |
InputStream stream = readLaunchConfig( project, model ); |
94 |
InputStream template |
|
|
95 |
= AbstractRAPWizard.class.getResourceAsStream( LAUNCH_TEMPLATE ); |
| 96 |
String pluginId = model.getPluginBase().getId(); |
| 97 |
InputStream stream = readFile( template, project.getName(), pluginId ); |
| 79 |
launchConfig.create( stream, true, new NullProgressMonitor() ); |
98 |
launchConfig.create( stream, true, new NullProgressMonitor() ); |
| 80 |
} catch( final CoreException ce ) { |
99 |
} catch( final CoreException ce ) { |
| 81 |
TemplateUtil.log( ce.getStatus() ); |
100 |
TemplateUtil.log( ce.getStatus() ); |
|
Lines 83-97
abstract class AbstractRAPWizard extends NewPluginTemplateWizard {
Link Here
|
| 83 |
} |
102 |
} |
| 84 |
} |
103 |
} |
| 85 |
|
104 |
|
| 86 |
private InputStream readLaunchConfig( final IProject project, |
105 |
private InputStream readFile( final InputStream iStream, String projectName, String pluginId ) |
| 87 |
final IPluginModelBase model ) |
|
|
| 88 |
throws CoreException |
106 |
throws CoreException |
| 89 |
{ |
107 |
{ |
| 90 |
InputStream template |
|
|
| 91 |
= AbstractRAPWizard.class.getResourceAsStream( LAUNCH_TEMPLATE ); |
| 92 |
StringBuffer buffer = new StringBuffer(); |
108 |
StringBuffer buffer = new StringBuffer(); |
| 93 |
try { |
109 |
try { |
| 94 |
InputStreamReader reader = new InputStreamReader( template, CHARSET ); |
110 |
InputStreamReader reader = new InputStreamReader( iStream, CHARSET ); |
| 95 |
BufferedReader br = new BufferedReader( reader ); |
111 |
BufferedReader br = new BufferedReader( reader ); |
| 96 |
try { |
112 |
try { |
| 97 |
int character = br.read(); |
113 |
int character = br.read(); |
|
Lines 103-120
abstract class AbstractRAPWizard extends NewPluginTemplateWizard {
Link Here
|
| 103 |
br.close(); |
119 |
br.close(); |
| 104 |
} |
120 |
} |
| 105 |
} catch( final Exception ex ) { |
121 |
} catch( final Exception ex ) { |
| 106 |
String pluginId = TemplateUtil.PLUGIN_ID; |
|
|
| 107 |
String msg = "Could not read launch template"; //$NON-NLS-1$ |
122 |
String msg = "Could not read launch template"; //$NON-NLS-1$ |
| 108 |
throw new CoreException( new Status( IStatus.ERROR, pluginId, msg, ex ) ); |
123 |
throw new CoreException( new Status( IStatus.ERROR, TemplateUtil.PLUGIN_ID, msg, ex ) ); |
| 109 |
} |
124 |
} |
| 110 |
// Replace $-placeholder with actual values |
125 |
// Replace $-placeholder with actual values |
| 111 |
replacePlaceholder( buffer, TAG_PROJECT_NAME, project.getName() ); |
126 |
replacePlaceholder( buffer, TAG_PACKAGE_NAME, getPackageName() ); |
| 112 |
String pluginId = model.getPluginBase().getId(); |
127 |
replacePlaceholder( buffer, TAG_PROJECT_NAME, projectName ); |
| 113 |
replacePlaceholder( buffer, TAG_PLUGIN_ID, pluginId ); |
128 |
replacePlaceholder( buffer, TAG_PLUGIN_ID, pluginId ); |
| 114 |
replacePlaceholder( buffer, TAG_SERVLET_PATH, getServletPath() ); |
129 |
replacePlaceholder( buffer, TAG_SERVLET_PATH, getServletPath() ); |
| 115 |
return new ByteArrayInputStream( buffer.toString().getBytes() ); |
130 |
return new ByteArrayInputStream( buffer.toString().getBytes() ); |
| 116 |
} |
131 |
} |
| 117 |
|
132 |
|
|
|
133 |
protected abstract String getPackageName(); |
| 134 |
|
| 118 |
protected abstract String getServletPath(); |
135 |
protected abstract String getServletPath(); |
| 119 |
|
136 |
|
| 120 |
private static void replacePlaceholder( final StringBuffer buffer, |
137 |
private static void replacePlaceholder( final StringBuffer buffer, |
|
Lines 263-268
abstract class AbstractRAPWizard extends NewPluginTemplateWizard {
Link Here
|
| 263 |
} |
280 |
} |
| 264 |
writer.write( "Import-Package: javax.servlet;version=\"2.4.0\"," + NL ); //$NON-NLS-1$ |
281 |
writer.write( "Import-Package: javax.servlet;version=\"2.4.0\"," + NL ); //$NON-NLS-1$ |
| 265 |
writer.write( " javax.servlet.http;version=\"2.4.0\"" + NL ); //$NON-NLS-1$ |
282 |
writer.write( " javax.servlet.http;version=\"2.4.0\"" + NL ); //$NON-NLS-1$ |
|
|
283 |
IFile appconfigXml = file.getParent().getFile( new Path( "appconfig.xml" ) ); |
| 284 |
if ( appconfigXml.exists() ) { |
| 285 |
writer.write( "Service-Component: META-INF/appconfig.xml" + NL ); |
| 286 |
} |
| 266 |
} finally { |
287 |
} finally { |
| 267 |
writer.close(); |
288 |
writer.close(); |
| 268 |
} |
289 |
} |