📄 deployedjadwriter.java
字号:
/**
* Copyright (c) 2003-2007 Craig Setera
* All Rights Reserved.
* Licensed under the Eclipse Public License - v 1.0
* For more information see http://www.eclipse.org/legal/epl-v10.html
*/
package eclipseme.core.internal.packaging;
import java.io.File;
import java.io.IOException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import eclipseme.core.internal.signing.SignatureUtils;
import eclipseme.core.internal.utils.ColonDelimitedProperties;
import eclipseme.core.model.ApplicationDescriptor;
import eclipseme.core.model.IJADConstants;
import eclipseme.core.model.IJadSignature;
import eclipseme.core.model.IMidletSuiteProject;
/**
* A helper class that is used to create a JAD file representing the deployed
* JAR file.
* <p />
* Copyright (c) 2003-2007 Craig Setera<br>
* All Rights Reserved.<br>
* Licensed under the Eclipse Public License - v 1.0<p/>
* <br>
* $Revision$
* <br>
* $Date$
* <br>
* @author Craig Setera
*/
public class DeployedJADWriter {
private IMidletSuiteProject midletSuite;
private IFolder deploymentFolder;
private File deployedJarFile;
/**
* Construct a new JAD Writer to handle the specified deployment.
*/
public DeployedJADWriter(IMidletSuiteProject midletSuite, IFolder deploymentFolder, File deployedJar) {
super();
this.midletSuite = midletSuite;
this.deploymentFolder = deploymentFolder;
this.deployedJarFile = deployedJar;
}
/**
* Write out a deployed JAD file for the previously created JAR file.
*
* @param incrementalBuild
* @param monitor
* @throws IOException
* @throws CoreException
*/
public void writeDeployedJAD(boolean incrementalBuild, IProgressMonitor monitor)
throws IOException, CoreException
{
// Read the source jad file and update the jar file
// length property.
ApplicationDescriptor appDescriptor = midletSuite.getApplicationDescriptor();
ColonDelimitedProperties jadProperties = appDescriptor.getManifestProperties();
// Update the size of the jar file
jadProperties.setProperty(
IJADConstants.JAD_MIDLET_JAR_SIZE,
(new Long(deployedJarFile.length())).toString());
// If requested, we overwrite the JAD URL such that it is just the
// name of the jar file. This is for runtime handling.
if (incrementalBuild) {
jadProperties.setProperty(IJADConstants.JAD_MIDLET_JAR_URL, deployedJarFile.getName());
}
// write the JAD file in case signing blows up - at least we'll have
// something non-bogus.
writeJad(appDescriptor);
if (!incrementalBuild) {
// Retrieve the signature object for this project. This will be null
// if we're not supposed to sign this project.
IJadSignature signatureObject = SignatureUtils.getSignatureObject(midletSuite);
if (signatureObject != null)
{
signJad(signatureObject, deployedJarFile, jadProperties);
writeJad(appDescriptor);
}
}
}
/**
* Sign the JAR file associated with the project and add the signature
* properties to the JAD file.
*
* @param signatureObject IJadSignature object that will do the actual signing
* @param deployedJarFile File referencing the JAR file to be signed
* @param jadProperties Contents of the JAD file to be added to
*
* @throws CoreException
*/
private void signJad(IJadSignature signatureObject, File deployedJarFile, ColonDelimitedProperties jadProperties)
throws CoreException
{
signatureObject.computeSignature(deployedJarFile);
jadProperties.setProperty(IJADConstants.JAD_MIDLET_JAR_RSA_SHA1,
signatureObject.getJarSignatureString());
String[] certificates = signatureObject.getCertificateStrings();
for (int i = 1; i <= certificates.length; i++)
{
jadProperties.setProperty(IJADConstants.JAD_MIDLET_CERTIFICATE + i,
certificates[i-1]);
}
}
/**
* Write the application descriptor out to the deployed location.
*
* @param appDescriptor
* @throws IOException
*/
private void writeJad(ApplicationDescriptor appDescriptor)
throws IOException
{
IFile deployedJadFile = deploymentFolder.getFile(midletSuite.getJadFile().getName());
appDescriptor.store(deployedJadFile.getLocation().toFile());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -