List of usage examples for org.eclipse.jdt.internal.core JavaProject setProject
@Override public void setProject(IProject project)
From source file:com.motorola.studio.android.packaging.ui.export.PackageExportWizardArea.java
License:Apache License
/** * do the finish: Create the package for each selected descriptor */// w w w . ja v a 2 s . c o m public boolean performFinish() { final boolean[] finished = { false }; boolean destOK = false; final MultiStatus status = new MultiStatus(PackagingUIPlugin.PLUGIN_ID, IStatus.OK, "", null); //$NON-NLS-1$ ProgressMonitorDialog monitorDialog = null; String DESCRIPTION_TO_LOG = StudioLogger.DESCRIPTION_DEFAULT; try { destOK = checkDestination(); } catch (CoreException e) { status.add(e.getStatus()); } if (destOK) { monitorDialog = new ProgressMonitorDialog(parentComposite.getShell()); try { monitorDialog.run(false, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor aMonitor) throws InvocationTargetException, InterruptedException { int finishSize = getSelectedItems().size() * PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER; SubMonitor monitor = SubMonitor.convert(aMonitor); monitor.beginTask(Messages.PACKAGE_EXPORT_WIZARD_AREA_FINISH_ACTION_LABEL, finishSize); IPath exportDestinationFolder = new Path(destinationText.getText()); IPath exportDestinationFile = null; for (TreeItem item : getSelectedItems()) { // get the eclipse project as a java project to get // the project // destination IProject eclipseProject = (IProject) item.getData(); try { monitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4); JavaProject javaProject = new JavaProject(); javaProject.setProject(eclipseProject); // find all packages built by Android builder Map<String, String> apkConfigurations = SdkUtils .getAPKConfigurationsForProject(eclipseProject); Set<String> apkConfNames = new HashSet<String>(); if (apkConfigurations != null) { apkConfNames.addAll(apkConfigurations.keySet()); } apkConfNames.add(""); // the default package //$NON-NLS-1$ SubMonitor submonitor = monitor .newChild(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4); submonitor.beginTask(Messages.PACKAGE_EXPORT_WIZARD_AREA_EXPORTING_ACTION_LABEL, 3 * PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER * apkConfNames.size()); for (String apkConfName : apkConfNames) { String apkName = eclipseProject.getName() + (apkConfName.isEmpty() ? apkConfName : "-" //$NON-NLS-1$ //$NON-NLS-2$ + apkConfName); if (defaultDestination.getSelection()) { exportDestinationFolder = eclipseProject.getLocation() .append(CertificateManagerActivator.PACKAGE_PROJECT_DESTINATION); } exportDestinationFile = exportDestinationFolder.append(apkName) .addFileExtension(CertificateManagerActivator.PACKAGE_EXTENSION); File file = exportDestinationFile.toFile(); submonitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER); //always export unsigned package AdtUtils.exportUnsignedReleaseApk(javaProject.getProject(), file, submonitor); submonitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER); if (signCheckBox.getSelection()) { //sign the package if required IStatus signStatus = signPackage(eclipseProject, file); status.add(signStatus); } //zipalign the file and we are done exporting the package PackageFile.zipAlign(file); submonitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER); } submonitor.done(); } catch (CoreException e) { StudioLogger.error(PackageExportWizardArea.class, "Error while building project or getting project output folder" //$NON-NLS-1$ + eclipseProject.getName(), e); status.add(new Status(IStatus.ERROR, PackagingUIPlugin.PLUGIN_ID, Messages.PACKAGE_EXPORT_WIZARD_AREA_ERROR_PROJECT_BUILD + " " //$NON-NLS-1$ + eclipseProject.getName())); } finally { try { eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, monitor.newChild(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4)); } catch (CoreException e) { // do nothing } } monitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4); } finished[0] = true; } }); } catch (Exception e) { StudioLogger.warn("Error finishing package export."); } } if (!status.isOK()) { status.getMessage(); DESCRIPTION_TO_LOG = Messages.PACKAGE_EXPORT_WIZARD_AREA_READONLY_TITLE; ErrorDialog.openError(parentComposite.getShell(), Messages.PACKAGE_EXPORT_WIZARD_AREA_READONLY_TITLE, Messages.PACKAGE_EXPORT_WIZARD_AREA_READONLY_MESSAGE, status); } // Saving usage data try { StudioLogger.collectUsageData(StudioLogger.WHAT_APP_MANAGEMENT_PACKAGE, StudioLogger.KIND_APP_MANAGEMENT, DESCRIPTION_TO_LOG, PackagingUIPlugin.PLUGIN_ID, PackagingUIPlugin.getDefault().getBundle().getVersion().toString()); } catch (Throwable e) { // Do nothing, but error on the log should never prevent app from // working } return finished[0]; }
From source file:org.eclipse.acceleo.internal.ide.ui.builders.AcceleoMarkerUtils.java
License:Open Source License
/** * Computes if the java service described in the message is accessible from the given file. * //from w w w . j a v a 2 s . c o m * @param file * The file * @param message * The message describing the service * @param marker * The marker to use if the service is not accessible * @throws JavaModelException * In case of problem during the search of the service class. * @throws CoreException * In case of problem during the search of the service class. */ private static void computeAccessibleService(IFile file, String message, IMarker marker) throws JavaModelException, CoreException { boolean exported = false; boolean found = false; String projectName = ""; //$NON-NLS-1$ IProject project = file.getProject(); AcceleoProject acceleoProject = new AcceleoProject(project); List<IProject> recursivelyAccessibleProjects = acceleoProject.getRecursivelyAccessibleProjects(); for (IProject iProject : recursivelyAccessibleProjects) { if (iProject.isAccessible() && iProject.hasNature(JavaCore.NATURE_ID)) { JavaProject javaProject = new JavaProject(); javaProject.setProject(iProject); IType type = null; List<IType> types = new ArrayList<IType>(); IPackageFragment[] packageFragments = javaProject.getPackageFragments(); for (IPackageFragment iPackageFragment : packageFragments) { if (iPackageFragment.getKind() == IPackageFragmentRoot.K_SOURCE) { ICompilationUnit[] compilationUnits = iPackageFragment.getCompilationUnits(); for (ICompilationUnit iCompilationUnit : compilationUnits) { types.addAll(Arrays.asList(iCompilationUnit.getTypes())); } } } for (IType iType : types) { if (iType.getFullyQualifiedName() .equals(message.substring(AcceleoParserInfo.SERVICE_INVOCATION.length()))) { type = iType; } } BundleDescription bundleDescription = null; if (type != null && PluginRegistry.findModel(iProject) != null) { found = true; projectName = iProject.getName(); IPluginModelBase plugin = PluginRegistry.findModel(iProject); bundleDescription = plugin.getBundleDescription(); } if (type != null && PluginRegistry.findModel(iProject) != null && bundleDescription != null) { ExportPackageDescription[] exportPackages = bundleDescription.getExportPackages(); for (ExportPackageDescription exportPackageDescription : exportPackages) { if (exportPackageDescription.getName().equals(type.getPackageFragment().getElementName())) { exported = true; } } } } } if (found && !exported) { marker.setAttribute(IMarker.MESSAGE, AcceleoUIMessages.getString("AcceleoMarkerUtils.JavaServiceClassNotExported", message //$NON-NLS-1$ .substring(AcceleoParserInfo.SERVICE_INVOCATION.length()), projectName)); } else { marker.delete(); } }
From source file:org.eclipse.andmore.android.packaging.ui.export.PackageExportWizardArea.java
License:Apache License
/** * do the finish: Create the package for each selected descriptor *//* w w w . jav a2s . c o m*/ public boolean performFinish() { final boolean[] finished = { false }; boolean destOK = false; final MultiStatus status = new MultiStatus(PackagingUIPlugin.PLUGIN_ID, IStatus.OK, "", null); //$NON-NLS-1$ ProgressMonitorDialog monitorDialog = null; String DESCRIPTION_TO_LOG = UsageDataConstants.DESCRIPTION_DEFAULT; try { destOK = checkDestination(); } catch (CoreException e) { status.add(e.getStatus()); } if (destOK) { monitorDialog = new ProgressMonitorDialog(parentComposite.getShell()); try { monitorDialog.run(false, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor aMonitor) throws InvocationTargetException, InterruptedException { int finishSize = getSelectedItems().size() * PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER; SubMonitor monitor = SubMonitor.convert(aMonitor); monitor.beginTask(Messages.PACKAGE_EXPORT_WIZARD_AREA_FINISH_ACTION_LABEL, finishSize); IPath exportDestinationFolder = new Path(destinationText.getText()); IPath exportDestinationFile = null; for (TreeItem item : getSelectedItems()) { // get the eclipse project as a java project to get // the project // destination IProject eclipseProject = (IProject) item.getData(); try { monitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4); JavaProject javaProject = new JavaProject(); javaProject.setProject(eclipseProject); // find all packages built by Android builder Map<String, String> apkConfigurations = SdkUtils .getAPKConfigurationsForProject(eclipseProject); Set<String> apkConfNames = new HashSet<String>(); if (apkConfigurations != null) { apkConfNames.addAll(apkConfigurations.keySet()); } apkConfNames.add(""); // the default package //$NON-NLS-1$ SubMonitor submonitor = monitor .newChild(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4); submonitor.beginTask(Messages.PACKAGE_EXPORT_WIZARD_AREA_EXPORTING_ACTION_LABEL, 3 * PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER * apkConfNames.size()); for (String apkConfName : apkConfNames) { String apkName = eclipseProject.getName() + (apkConfName.isEmpty() ? apkConfName : "-" //$NON-NLS-1$ + apkConfName); if (defaultDestination.getSelection()) { exportDestinationFolder = eclipseProject.getLocation() .append(CertificateManagerActivator.PACKAGE_PROJECT_DESTINATION); } exportDestinationFile = exportDestinationFolder.append(apkName) .addFileExtension(CertificateManagerActivator.PACKAGE_EXTENSION); File file = exportDestinationFile.toFile(); submonitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER); // always export unsigned package AdtUtils.exportUnsignedReleaseApk(javaProject.getProject(), file, submonitor); submonitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER); if (signCheckBox.getSelection()) { // sign the package if required IStatus signStatus = signPackage(eclipseProject, file); status.add(signStatus); } // zipalign the file and we are done // exporting the package PackageFile.zipAlign(file); submonitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER); } submonitor.done(); } catch (CoreException e) { AndmoreLogger.error(PackageExportWizardArea.class, "Error while building project or getting project output folder" //$NON-NLS-1$ + eclipseProject.getName(), e); status.add(new Status(IStatus.ERROR, PackagingUIPlugin.PLUGIN_ID, Messages.PACKAGE_EXPORT_WIZARD_AREA_ERROR_PROJECT_BUILD + " " //$NON-NLS-1$ + eclipseProject.getName())); } finally { try { eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, monitor.newChild(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4)); } catch (CoreException e) { // do nothing } } monitor.worked(PackagingUIPlugin.PROGRESS_MONITOR_MULTIPLIER / 4); } finished[0] = true; } }); } catch (Exception e) { AndmoreLogger.warn("Error finishing package export."); } } if (!status.isOK()) { status.getMessage(); DESCRIPTION_TO_LOG = Messages.PACKAGE_EXPORT_WIZARD_AREA_READONLY_TITLE; ErrorDialog.openError(parentComposite.getShell(), Messages.PACKAGE_EXPORT_WIZARD_AREA_READONLY_TITLE, Messages.PACKAGE_EXPORT_WIZARD_AREA_READONLY_MESSAGE, status); } // Saving usage data try { AndmoreLogger.collectUsageData(UsageDataConstants.WHAT_APP_MANAGEMENT_PACKAGE, UsageDataConstants.KIND_APP_MANAGEMENT, DESCRIPTION_TO_LOG, PackagingUIPlugin.PLUGIN_ID, PackagingUIPlugin.getDefault().getBundle().getVersion().toString()); } catch (Throwable e) { // Do nothing, but error on the log should never prevent app from // working } return finished[0]; }