|
Lines 1-7
Link Here
|
|
|
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2007 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Andrew Eberbach (aeberbac@us.ibm.com) |
| 10 |
* IBM Corporation - initial API and implementation |
| 11 |
*******************************************************************************/ |
| 1 |
package org.eclipse.tptp.wsdm.tooling.internal.projectizer; |
12 |
package org.eclipse.tptp.wsdm.tooling.internal.projectizer; |
| 2 |
|
13 |
|
|
|
14 |
import java.io.File; |
| 15 |
import java.io.FileNotFoundException; |
| 16 |
import java.io.InputStream; |
| 17 |
import java.net.URL; |
| 18 |
import java.util.Map; |
| 19 |
|
| 3 |
import org.apache.muse.tools.generator.projectizer.J2EEMiniProjectizer; |
20 |
import org.apache.muse.tools.generator.projectizer.J2EEMiniProjectizer; |
|
|
21 |
import org.apache.muse.tools.generator.util.ConfigurationData; |
| 22 |
import org.apache.muse.util.FileUtils; |
| 23 |
import org.apache.muse.ws.resource.metadata.MetadataDescriptor; |
| 24 |
import org.apache.muse.ws.wsdl.WsdlUtils; |
| 25 |
import org.eclipse.core.runtime.FileLocator; |
| 26 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 27 |
import org.eclipse.core.runtime.Platform; |
| 28 |
import org.eclipse.tptp.wsdm.tooling.codegen.mrt.provisional.EclipseConfigurationData; |
| 29 |
import org.eclipse.tptp.wsdm.tooling.internal.util.WebProjectHelper; |
| 30 |
import org.eclipse.tptp.wsdm.tooling.provisional.util.ProgressMonitorHelper; |
| 31 |
import org.eclipse.tptp.wsdm.tooling.provisional.util.ProjectHelper; |
| 32 |
import org.w3c.dom.Document; |
| 33 |
import org.w3c.dom.Element; |
| 4 |
|
34 |
|
| 5 |
public class EclipseJ2EEMiniProjectizer extends J2EEMiniProjectizer { |
35 |
public class EclipseJ2EEMiniProjectizer extends J2EEMiniProjectizer { |
|
|
36 |
private static final String[] LIB_BUNDLE_IDS = { |
| 37 |
"org.apache.muse.api", //$NON-NLS-1$ |
| 38 |
"org.apache.muse.impl", //$NON-NLS-1$ |
| 39 |
"org.apache.muse.core", //$NON-NLS-1$ |
| 40 |
"org.apache.muse.tools", //$NON-NLS-1$ |
| 41 |
"org.apache.muse.utils" //$NON-NLS-1$ |
| 42 |
}; |
| 43 |
|
| 44 |
private static final String CONTAINER_BUNDLE = "org.apache.muse.tools";//$NON-NLS-1$ |
| 45 |
private static final String CONTAINER_RESOURCE = "/containers/muse-platform-mini-2.2.0.jar";//$NON-NLS-1$ |
| 46 |
|
| 47 |
private String _projectName; |
| 48 |
private String _projectLocation; |
| 49 |
private File[] _additionalJars; |
| 50 |
private Object[][] _instances; |
| 51 |
private ProgressMonitorHelper _progressMonitorHelper; |
| 52 |
|
| 53 |
public void projectize(ConfigurationData configuration) throws Exception { |
| 54 |
ConfigurationData.checkConfiguration(this, configuration); |
| 55 |
loadParameters(configuration); |
| 56 |
ProgressMonitorHelper progressHelper = getProgressMonitor(); |
| 57 |
progressHelper.startProgressMonitor(6); |
| 58 |
|
| 59 |
try { |
| 60 |
WebProjectHelper helper = createProjectHelper(); |
| 61 |
|
| 62 |
helper.setSuspendValidation(true); |
| 63 |
|
| 64 |
createJavaSources(helper, progressHelper); |
| 65 |
createArtifacts(helper, progressHelper); |
| 66 |
createLibraries(helper, progressHelper); |
| 67 |
|
| 68 |
helper.refreshProject(); |
| 69 |
helper.setSuspendValidation(false); |
| 70 |
} finally { |
| 71 |
progressHelper.finishProgressMonitor(); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
protected void createLibraries(WebProjectHelper helper, ProgressMonitorHelper progressHelper) throws Exception { |
| 76 |
copyLibrariesFromBundles(helper, LIB_BUNDLE_IDS); |
| 77 |
progressHelper.recordProgress(); |
| 78 |
|
| 79 |
copyAdditionalJars(helper); |
| 80 |
progressHelper.recordProgress(); |
| 81 |
|
| 82 |
copyContainer(helper); |
| 83 |
progressHelper.recordProgress(); |
| 84 |
} |
| 85 |
|
| 86 |
protected void copyContainer(WebProjectHelper helper) throws Exception { |
| 87 |
File webInfLibDir = new File(helper.getProjectDirectory(), EclipseJ2EEMiniProjectizerConstants.WEBINFLIB_DIR); |
| 88 |
URL url = Platform.getBundle(CONTAINER_BUNDLE).getEntry(CONTAINER_RESOURCE); |
| 89 |
url = FileLocator.toFileURL(url); |
| 90 |
|
| 91 |
File libSource = ProjectHelper.toFile(url); |
| 92 |
FileUtils.copy(libSource, webInfLibDir); |
| 93 |
} |
| 94 |
|
| 95 |
protected void copyAdditionalJars(WebProjectHelper helper) throws Exception { |
| 96 |
File webInfLibDir = new File(helper.getProjectDirectory(), EclipseJ2EEMiniProjectizerConstants.WEBINFLIB_DIR); |
| 97 |
|
| 98 |
File[] additionalJars = getAdditionalJars(); |
| 99 |
|
| 100 |
if(additionalJars != null) { |
| 101 |
for (int i=0; i < additionalJars.length; i++) { |
| 102 |
if(!additionalJars[i].exists()) { |
| 103 |
throw new FileNotFoundException(additionalJars[i].getAbsolutePath()); |
| 104 |
} |
| 105 |
|
| 106 |
FileUtils.copyFile(additionalJars[i], webInfLibDir); |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
protected void copyLibrariesFromBundles(WebProjectHelper helper, String[] libBundleIds) throws Exception { |
| 112 |
URL url = null; |
| 113 |
File webInfDir = new File(helper.getProjectDirectory(), EclipseJ2EEMiniProjectizerConstants.WEBINF_DIR); |
| 114 |
|
| 115 |
for (int i=0; i < libBundleIds.length; i++) { |
| 116 |
url = Platform.getBundle(libBundleIds[i]).getEntry(EclipseJ2EEMiniProjectizerConstants.PROJECT_LIB_DIR_RESOURCE); |
| 117 |
url = FileLocator.toFileURL(url); |
| 118 |
|
| 119 |
File libSource = ProjectHelper.toFile(url); |
| 120 |
FileUtils.copyDirectory(libSource, webInfDir); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
protected WebProjectHelper createProjectHelper() throws Exception { |
| 125 |
return new WebProjectHelper( |
| 126 |
getProjectName(), |
| 127 |
getProjectLocation(), |
| 128 |
EclipseJ2EEMiniProjectizerConstants.JAVA_BIN_DIR, |
| 129 |
EclipseJ2EEMiniProjectizerConstants.JAVA_SRC_DIR); |
| 130 |
} |
| 131 |
|
| 132 |
protected void createJavaSources(WebProjectHelper helper, ProgressMonitorHelper progressHelper) throws Exception { |
| 133 |
File javaSourceDir = new File( |
| 134 |
helper.getProjectDirectory(), |
| 135 |
EclipseJ2EEMiniProjectizerConstants.JAVA_SRC_DIR); |
| 136 |
|
| 137 |
createJavaSources(javaSourceDir, getFilesMaps()); |
| 138 |
progressHelper.recordProgress(); |
| 139 |
} |
| 140 |
|
| 141 |
protected void createArtifacts(WebProjectHelper helper, ProgressMonitorHelper progressHelper) throws Exception { |
| 142 |
File descriptorFile = new File( |
| 143 |
helper.getProjectDirectory(), |
| 144 |
EclipseJ2EEMiniProjectizerConstants.DESCRIPTOR_FILE); |
| 145 |
|
| 146 |
File wsdldir = new File( |
| 147 |
helper.getProjectDirectory(), |
| 148 |
EclipseJ2EEMiniProjectizerConstants.WSDL_DIR); |
| 149 |
|
| 150 |
File routerEntriesDir = new File( |
| 151 |
helper.getProjectDirectory(), |
| 152 |
EclipseJ2EEMiniProjectizerConstants.ROUTER_ENTRIES_DIR); |
| 153 |
|
| 154 |
for(int i=0; i < getNumCapabilityMaps(); i++) { |
| 155 |
Map capabilities = getCapabilityMap(i); |
| 156 |
MetadataDescriptor rmd = getMetadata(i); |
| 157 |
Document wsdl = getWsdl(i); |
| 158 |
|
| 159 |
createDescriptor(getDescriptor(), |
| 160 |
wsdl, |
| 161 |
descriptorFile, |
| 162 |
capabilities, |
| 163 |
EclipseJ2EEMiniProjectizerConstants.WSDL_RELATIVE_PATH, |
| 164 |
i); |
| 165 |
|
| 166 |
createRMDFile(rmd, wsdl, wsdldir); |
| 167 |
createWSDLFile(wsdl, wsdldir); |
| 168 |
|
| 169 |
if(getInstances() == null) { |
| 170 |
createRouterEntries(routerEntriesDir, WsdlUtils.getServiceName(wsdl.getDocumentElement()), _capabilitiesList[i]); |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
progressHelper.recordProgress(); |
| 175 |
|
| 176 |
if(getInstances() != null) { |
| 177 |
createRouterEntries(routerEntriesDir, getInstances()); |
| 178 |
} |
| 179 |
|
| 180 |
createWebDescriptor(helper); |
| 181 |
createBuildFile(helper.getProjectDirectory(), |
| 182 |
EclipseJ2EEMiniProjectizerConstants.BUILD_FILE_RESOURCE, |
| 183 |
EclipseJ2EEMiniProjectizerConstants.BUILD_FILE); |
| 184 |
|
| 185 |
progressHelper.recordProgress(); |
| 186 |
} |
| 187 |
|
| 188 |
protected void createBuildFile(File baseTargetDir, String buildFileResource, String buildFile) throws Exception { |
| 189 |
InputStream buildTemplate = FileUtils.loadFromContext(this.getClass(),buildFileResource); |
| 190 |
File build = new File(baseTargetDir, buildFile); |
| 191 |
copyStreamCheck(buildTemplate, build); |
| 192 |
} |
| 193 |
|
| 194 |
protected void createWebDescriptor(WebProjectHelper helper) throws Exception { |
| 195 |
File webInfDir = new File(helper.getProjectDirectory(),EclipseJ2EEMiniProjectizerConstants.WEBINF_DIR); |
| 196 |
File descriptorFile = new File(webInfDir, EclipseJ2EEMiniProjectizerConstants.WEBXML_FILE); |
| 197 |
if(!descriptorFile.delete()) { |
| 198 |
throw new Exception(); |
| 199 |
} |
| 200 |
createFileFromResource(webInfDir, |
| 201 |
EclipseJ2EEMiniProjectizerConstants.WEBXML_RESOURCE, |
| 202 |
EclipseJ2EEMiniProjectizerConstants.WEBXML_FILE); |
| 203 |
} |
| 204 |
|
| 205 |
protected Map getCapabilityMap(int index) { |
| 206 |
return _capabilitiesList[index]; |
| 207 |
} |
| 208 |
|
| 209 |
protected void createRouterEntries(File routerEntriesDir,Object[][] instances) throws Exception { |
| 210 |
routerEntriesDir.mkdirs(); |
| 211 |
|
| 212 |
for (int i = 0; i < getInstances().length; i++) { |
| 213 |
Object[] instancePair = getInstances()[i]; |
| 214 |
|
| 215 |
// |
| 216 |
// This is really tacky, but it's the only real way to do this |
| 217 |
// since there are no pairs. The File use is to get the last element |
| 218 |
// of the path in a nice, non-hack way. |
| 219 |
// |
| 220 |
String path = (String) instancePair[0]; |
| 221 |
String resourcePathName = new File(path).getName(); |
| 222 |
|
| 223 |
Element instanceElement = (Element) instancePair[1]; |
| 224 |
|
| 225 |
File serviceDir = new File(routerEntriesDir, resourcePathName); |
| 226 |
File routerEntryFile = new File(serviceDir, getResourceFileName(i)); |
| 227 |
|
| 228 |
writeToFileCheck(instanceElement, routerEntryFile); |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
/** |
| 233 |
* Get the name of a resource-instance file with the appropriate counter. This is |
| 234 |
* really just a string-replace of the PLACE_HOLDER value with the given counter |
| 235 |
* |
| 236 |
* @param counter The number to use in the string replace |
| 237 |
* @return The string with PLACE_HOLDER replaced by the string value of counter |
| 238 |
*/ |
| 239 |
protected String getResourceFileName(int counter) { |
| 240 |
return EclipseJ2EEMiniProjectizerConstants.RESOURCE_FILE.replaceFirst(PLACE_HOLDER, String.valueOf(counter)); |
| 241 |
} |
| 242 |
|
| 243 |
protected void loadParameters(ConfigurationData data) { |
| 244 |
super.loadParameters(data); |
| 245 |
|
| 246 |
_additionalJars = (File[]) data.getParameter(EclipseConfigurationData.ADDITIONAL_JARS); |
| 247 |
_instances = (Object[][]) data.getParameter(EclipseConfigurationData.INSTANCES); |
| 248 |
_progressMonitorHelper = new ProgressMonitorHelper((IProgressMonitor) data.getParameter(EclipseConfigurationData.PROGRESS_MONITOR)); |
| 249 |
_projectName = (String) data.getParameter(EclipseConfigurationData.PROJECT_NAME); |
| 250 |
_projectLocation = (String) data.getParameter(EclipseConfigurationData.PROJECT_LOCATION); |
| 251 |
} |
| 252 |
|
| 253 |
protected File[] getAdditionalJars() { |
| 254 |
return _additionalJars; |
| 255 |
} |
| 256 |
|
| 257 |
protected Map[] getFilesMaps() { |
| 258 |
return _filesMaps; |
| 259 |
} |
| 260 |
|
| 261 |
protected String getProjectLocation() { |
| 262 |
return _projectLocation; |
| 263 |
} |
| 264 |
|
| 265 |
protected String getProjectName() { |
| 266 |
return _projectName; |
| 267 |
} |
| 268 |
|
| 269 |
protected ProgressMonitorHelper getProgressMonitor() { |
| 270 |
return _progressMonitorHelper; |
| 271 |
} |
| 272 |
|
| 273 |
protected Object[][] getInstances() { |
| 274 |
return _instances; |
| 275 |
} |
| 276 |
|
| 277 |
protected Document getDescriptor() { |
| 278 |
return _descriptor; |
| 279 |
} |
| 280 |
|
| 281 |
protected int getNumCapabilityMaps() { |
| 282 |
return _capabilitiesList.length; |
| 283 |
} |
| 284 |
|
| 285 |
protected Document getWsdl(int index) { |
| 286 |
return _wsdls[index]; |
| 287 |
} |
| 6 |
|
288 |
|
|
|
289 |
protected MetadataDescriptor getMetadata(int index) { |
| 290 |
return _metadatas[index]; |
| 291 |
} |
| 7 |
} |
292 |
} |