📄 abstractdevice.java
字号:
/**
* @return Returns the launchCommandTemplate.
*/
public String getLaunchCommandTemplate() {
return launchCommandTemplate;
}
/**
* @param launchCommandTemplate The launchCommandTemplate to set.
*/
public void setLaunchCommandTemplate(String launchCommandTemplate) {
this.launchCommandTemplate = launchCommandTemplate;
}
/**
* Add a value from the launch configuration to the execution
* properties map.
*
* @param executionProperties
* @param propertyName
* @param launchConfiguration
* @param launchConstant
* @throws CoreException
*/
protected void addLaunchConfigurationValue(
Map executionProperties,
String propertyName,
ILaunchConfiguration launchConfiguration,
String launchConstant)
throws CoreException
{
String configValue = launchConfiguration.getAttribute(launchConstant, (String) null);
if (configValue != null) {
executionProperties.put(propertyName, configValue);
}
}
/**
* Calculate the return the appropriate JAD file to use
* during launching.
*
* @param configuration
* @return
* @throws CoreException
*/
protected File calculateJADFile(
IMidletSuiteProject midletSuite,
ILaunchConfiguration configuration)
throws CoreException
{
File jadFile = getDeployedJadFile(midletSuite, configuration);
if (isPredeploymentRequired()) {
// Assume that we need to create a new single-class
// jad file and then copy the jar file alongside
// the jad file
jadFile = createSingleClassJadFile(midletSuite, configuration, jadFile);
}
return jadFile;
}
/**
* Return the JAD file represented by the launch configuration as it
* would be located in the project deployed directory.
*
* @param configuration
* @return
* @throws CoreException
*/
protected File getDeployedJadFile(
IMidletSuiteProject midletSuite,
ILaunchConfiguration configuration)
throws CoreException
{
IFolder tempFolder =
midletSuite.getProject().getFolder(IEclipseMECoreConstants.TEMP_FOLDER_NAME);
IFolder emulationFolder = tempFolder.getFolder(IEclipseMECoreConstants.EMULATION_FOLDER_NAME);
IFile jadFile = emulationFolder.getFile(midletSuite.getJadFile().getName());
return jadFile.getLocation().toFile();
}
/**
* Return the url specified by the user for direct launching
* or <code>null</code> if none was specified.
*
* @param launchConfiguration
* @return
* @throws CoreException
*/
protected String getSpecifiedJadURL(ILaunchConfiguration launchConfiguration)
throws CoreException
{
return launchConfiguration.getAttribute(
ILaunchConstants.SPECIFIED_JAD_URL,
(String) null);
}
/**
* Return a boolean indicating whether or not the emulation
* should just directly launch a specified JAD URL without
* the other things that normally happen during launching.
*
* @param configuration
* @return
* @throws CoreException
*/
protected boolean shouldDirectLaunchJAD(ILaunchConfiguration configuration)
throws CoreException
{
return configuration.getAttribute(
ILaunchConstants.DO_JAD_LAUNCH,
false);
}
/**
* Return a boolean indicating whether or not the emulation should
* be launched as OTA.
*
* @param configuration
* @return
* @throws CoreException
*/
protected boolean shouldDoOTA(ILaunchConfiguration configuration)
throws CoreException
{
return configuration.getAttribute(
ILaunchConstants.DO_OTA,
true);
}
/**
* Encode the specified information for a URL.
*
* @param value
* @return
*/
protected String urlEncoded(String value) {
String encoded = null;
try {
encoded = URLEncoder.encode(value, "UTF-8");
} catch (UnsupportedEncodingException e) {
// Should never happen
}
return encoded;
}
/**
* Create and return a new temporary JAD file using the
* specified JAD file with the selected class to be run
* as the single midlet listed in the temporary JAD file.
*
* @param configuration
* @param jadFile
* @return
* @throws CoreException
*/
private File createSingleClassJadFile(
IMidletSuiteProject midletSuite,
ILaunchConfiguration configuration,
File jadFile)
throws CoreException
{
File tempJadFile = null;
if (jadFile.exists()) {
try {
// Read the current JAD file contents...
ColonDelimitedProperties props = new ColonDelimitedProperties();
InputStream contents = new FileInputStream(jadFile);
props.load(contents);
contents.close();
// Convert the JAD properties to be a single class
getSingleClassJADProperties(configuration, props);
// Write out to a temp directory
File tempDirectory =
TemporaryFileManager.instance.createTempDirectory("launch_", ".j2me");
// Copy the predeployed jar file
IFolder deployedFolder = getDeployedFolder(midletSuite);
String jarName = midletSuite.getJarFilename();
IFile srcJar = deployedFolder.getFile(jarName);
File tgtJar = new File(tempDirectory, jarName);
File srcFile = srcJar.getLocation().toFile();
Utils.copyFile(srcFile, tgtJar, null);
props.setProperty("MIDlet-Jar-URL", jarName);
tempJadFile = new File(tempDirectory, jadFile.getName());
FileOutputStream fos = new FileOutputStream(tempJadFile);
props.store(fos, "Temporary manifest file");
fos.close();
} catch (IOException e) {
EclipseMECorePlugin.throwCoreException(
IStatus.ERROR,
-999,
e);
}
}
return tempJadFile;
}
/**
* Return the folder used for deployment.
*
* @param midletSuiteProject
* @return
*/
private IFolder getDeployedFolder(IMidletSuiteProject midletSuiteProject) {
String deployedDirectoryName = EclipseMECorePlugin.getDeploymentDirectoryName();
return midletSuiteProject.getProject().getFolder(deployedDirectoryName);
}
/**
* Get a JAD properties object set up for a single class.
*
* @param configuration
* @param props
* @throws CoreException
*/
private void getSingleClassJADProperties(
ILaunchConfiguration configuration,
ColonDelimitedProperties props)
throws CoreException
{
// Remove the midlets that are defined in the JAD file
for (int i = 0; i < 100; i++) {
String key = "MIDlet-" + i;
if (props.containsKey(key)) {
props.remove(key);
} else {
break;
}
}
// Add the midlet to the JAD
String midlet = configuration.getAttribute(ILaunchConstants.EMULATED_CLASS, "");
String propValue = midlet + ",," + midlet;
props.setProperty("MIDlet-1", propValue);
}
/**
* Look for the library with the specified type and return it.
* If it cannot be found, return <code>null</code>
*
* @param type
* @return
*/
private ILibrary getLibraryWithType(APIType type) {
ILibrary library = null;
Classpath classpath = getClasspath();
ILibrary[] libraries = classpath.getEntries();
for (int i = 0; i < libraries.length; i++) {
if (libraries[i].getAPI(type) != null) {
library = libraries[i];
break;
}
}
return library;
}
/**
* Return the Over the Air URL for accessing the JAD file
* via the built-in OTA HTTP server.
* @param launchConfig
* @return
* @throws CoreException
*/
protected String getOTAURL(
ILaunchConfiguration launchConfig,
IMidletSuiteProject midletSuite)
throws CoreException
{
// If we are doing OTA launching, make sure that the
// OTA server has been started
try {
OTAServer.instance.start();
} catch (MultiException e) {
EclipseMECorePlugin.log(IStatus.WARNING, "launch", e);
}
String projectName = midletSuite.getProject().getName();
String jadName = midletSuite.getJadFile().getName();
StringBuffer sb = new StringBuffer();
sb
.append("http://localhost:")
.append(OTAServer.getPort())
.append("/ota/")
.append(urlEncoded(projectName))
.append('/')
.append(urlEncoded(jadName));
return sb.toString();
}
/**
* Return the classpath string to be used when launching the specified
* project.
*
* @param midletSuite
* @return
* @throws CoreException
*/
protected String getProjectClasspathString(IMidletSuiteProject midletSuite, IProgressMonitor monitor)
throws CoreException
{
de.schlichtherle.io.File deployedJar = PreverificationBuilder.getRuntimeJar(midletSuite.getProject(), monitor);
return deployedJar.getAbsolutePath();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -