Java源码示例:org.eclipse.jdt.ui.jarpackager.IJarExportRunnable
示例1
private IStatus export(JarPackageData[] jarPackages) {
Shell shell= getShell();
IJarExportRunnable op= jarPackages[0].createJarExportRunnable(jarPackages, shell);
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(false, true, op);
//PlatformUI.getWorkbench().getProgressService().run(false, true, op); // see bug 118152
} catch (InvocationTargetException ex) {
if (ex.getTargetException() != null) {
ExceptionHandler.handle(ex, shell, JarPackagerMessages.CreateJarActionDelegate_jarExportError_title, JarPackagerMessages.CreateJarActionDelegate_jarExportError_message);
return null;
}
} catch (InterruptedException e) {
// do nothing on cancel
return null;
}
return op.getStatus();
}
示例2
/**
* Exports the JAR package.
*
* @param op the op
* @return a boolean indicating success or failure
*/
protected boolean executeExportOperation(IJarExportRunnable op) {
try {
getContainer().run(true, true, op);
} catch (InterruptedException e) {
return false;
} catch (InvocationTargetException ex) {
if (ex.getTargetException() != null) {
ExceptionHandler.handle(ex, getShell(), JarPackagerMessages.JarPackageWizard_jarExportError_title, JarPackagerMessages.JarPackageWizard_jarExportError_message);
return false;
}
}
IStatus status= op.getStatus();
if (!status.isOK()) {
ErrorDialog.openError(getShell(), JarPackagerMessages.JarPackageWizard_jarExport_title, null, status);
return !(status.matches(IStatus.ERROR));
}
return true;
}
示例3
public void exportAsJar(final String absoluteTargetFilePath, final boolean includeSources)
throws InvocationTargetException, InterruptedException {
try {
checkWritePermission(new File(absoluteTargetFilePath));
} catch (final IOException e) {
throw new InvocationTargetException(e);
}
final JarPackageData jarPackakeData = createJarPackageData();
final IFile[] elements = Collections.singletonList(getResource()).toArray(new IFile[1]);
jarPackakeData.setJarLocation(new Path(absoluteTargetFilePath));
jarPackakeData.setBuildIfNeeded(true);
jarPackakeData.setElements(elements);
jarPackakeData.setExportWarnings(true);
jarPackakeData.setComment(SourceRepositoryStore.SIGNATURE_FILE_NAME);
jarPackakeData.setExportClassFiles(true);
jarPackakeData.setExportJavaFiles(includeSources);
jarPackakeData.setGenerateManifest(true);
jarPackakeData.setUsesManifest(true);
jarPackakeData.setOverwrite(true);
jarPackakeData.setUseSourceFolderHierarchy(includeSources);
final IJarExportRunnable runnable = jarPackakeData.createJarExportRunnable(null);
runnable.run(Repository.NULL_PROGRESS_MONITOR);
}
示例4
/**
* Creates a JAR file containing the given resource (Java class with
* main()) and all associated resources
*
* @param resource the resource
* @return a file designing the created package
*/
public void run(IProgressMonitor monitor) {
log.fine("Build jar");
JarPackageData jarrer = new JarPackageData();
jarrer.setExportJavaFiles(true);
jarrer.setExportClassFiles(true);
jarrer.setExportOutputFolders(true);
jarrer.setOverwrite(true);
try {
// IJavaProject project =
// (IJavaProject) resource.getProject().getNature(JavaCore.NATURE_ID);
// check this is the case before letting this method get called
Object element = resource.getAdapter(IJavaElement.class);
IType type = ((ICompilationUnit) element).findPrimaryType();
jarrer.setManifestMainClass(type);
// Create a temporary JAR file name
File baseDir = Activator.getDefault().getStateLocation().toFile();
String prefix =
String.format("%s_%s-", resource.getProject().getName(), resource
.getName());
File jarFile = File.createTempFile(prefix, ".jar", baseDir);
jarrer.setJarLocation(new Path(jarFile.getAbsolutePath()));
jarrer.setElements(resource.getProject().members(IResource.FILE));
IJarExportRunnable runnable =
jarrer.createJarExportRunnable(Display.getDefault()
.getActiveShell());
runnable.run(monitor);
this.jarFile = jarFile;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
示例5
/**
* Creates a JAR file containing the given resource (Java class with
* main()) and all associated resources
*
* @param resource the resource
* @return a file designing the created package
*/
public void run(IProgressMonitor monitor) {
log.fine("Build jar");
JarPackageData jarrer = new JarPackageData();
jarrer.setExportJavaFiles(true);
jarrer.setExportClassFiles(true);
jarrer.setExportOutputFolders(true);
jarrer.setOverwrite(true);
try {
// IJavaProject project =
// (IJavaProject) resource.getProject().getNature(JavaCore.NATURE_ID);
// check this is the case before letting this method get called
Object element = resource.getAdapter(IJavaElement.class);
IType type = ((ICompilationUnit) element).findPrimaryType();
jarrer.setManifestMainClass(type);
// Create a temporary JAR file name
File baseDir = Activator.getDefault().getStateLocation().toFile();
String prefix =
String.format("%s_%s-", resource.getProject().getName(), resource
.getName());
File jarFile = File.createTempFile(prefix, ".jar", baseDir);
jarrer.setJarLocation(new Path(jarFile.getAbsolutePath()));
jarrer.setElements(resource.getProject().members(IResource.FILE));
IJarExportRunnable runnable =
jarrer.createJarExportRunnable(Display.getDefault()
.getActiveShell());
runnable.run(monitor);
this.jarFile = jarFile;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}