private IStatus cleanCacheInternal(final IProgressMonitor monitor) { checkNotNull(monitor, "monitor"); final SubMonitor subMonitor = SubMonitor.convert(monitor, 1); try { subMonitor.setTaskName("Cleaning npm cache"); performGitPull(subMonitor.newChild(1, SubMonitor.SUPPRESS_ALL_LABELS)); final File targetInstallLocation = new File(locationProvider.getTargetPlatformInstallLocation()); return clean(targetInstallLocation); } finally { subMonitor.done(); } }
private static void configureResourceSet(ResourceSet rs, URI modelURI, HashMap<String, String> nsURIMapping, SubMonitor subMonitor) { subMonitor.subTask("Configuring ResourceSet"); subMonitor.newChild(1); final String fileExtension = modelURI.fileExtension(); // indicates which melange query should be added to the xml uri handler // for a given extension // use to resolve cross ref URI during XMI parsing final XMLURIHandler handler = new XMLURIHandler(modelURI.query(), fileExtension); handler.setResourceSet(rs); rs.getLoadOptions().put(XMLResource.OPTION_URI_HANDLER, handler); final MelangeURIConverter converter = new MelangeURIConverter(nsURIMapping); rs.setURIConverter(converter); // fix sirius to prevent non intentional model savings converter.getURIHandlers().add(0, new DebugURIHandler(converter.getURIHandlers())); }
@Override protected void clean(IProgressMonitor monitor) throws CoreException { SubMonitor localmonitor = SubMonitor.convert(monitor, "JPF Manifest validation", 1); try { // clean problem markers on the project cleanProblems(getProject(), IResource.DEPTH_ZERO); // clean the manifest directory (since errors can be created on // manifest files with incorrect casing) IFile manifestFile = JPFProject.getManifest(getProject()); cleanProblems(manifestFile.getParent(), IResource.DEPTH_ONE); localmonitor.worked(1); } finally { localmonitor.done(); } }
/** * The gw generated code contains a classname that might be different from the filename chosen in the wizard , which lead to a compile error. * We need to fix that by modifying the source code so that names are aligned. * @param monitor * @return */ private void rename(IProgressMonitor monitor) { SubMonitor subMonitor = SubMonitor.convert(monitor, 100); try { String newClassname = getConvertedFile().getName(); newClassname = newClassname.substring(0,newClassname.indexOf(".")); String oldClassname = context.getSelectedGraphFileName(); oldClassname = oldClassname.substring(0,oldClassname.indexOf(".")); subMonitor.split(10); convertedFile = JDTManager.renameClass(getConvertedFile(), oldClassname, newClassname,monitor); } catch (Exception e) { ResourceManager.logException(e); } finally { subMonitor.split(90); } }
public static void generateOffline(final IResource resource, IPackageFragment pkg, String classfile , BuildPolicy[] generators, int timeout, IWorkbenchWindow aww) { Job job = new Job("GW4E Offline Generation Source Job") { @Override public IStatus run(IProgressMonitor monitor) { try { if (resource instanceof IFile) { SubMonitor subMonitor = SubMonitor.convert(monitor, 120); IFile file = (IFile) resource; if (PreferenceManager.isGraphModelFile(file)) { AbstractPostConversion converter = getOfflineConversion(file,pkg,classfile,generators,timeout); ConversionRunnable runnable = converter.createConversionRunnable(aww); subMonitor.subTask("Processing converter "); SubMonitor child = subMonitor.split(1); runnable.run(child); } } } catch (Exception e) { e.printStackTrace(); ResourceManager.logException(e); } return Status.OK_STATUS; } }; job.setUser(true); job.schedule(); }
/** * Create a file in a folder with the specified name and content * * @param fullpath * @param filename * @param content * @throws CoreException * @throws InterruptedException */ public static IFile createFileDeleteIfExists(String fullpath, String filename, String content, IProgressMonitor monitor) throws CoreException, InterruptedException { SubMonitor subMonitor = SubMonitor.convert(monitor, 100); subMonitor.setTaskName("Create file delete if it exists " + fullpath); IFile newFile; try { IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot(); IContainer container = (IContainer) wroot.findMember(new Path(fullpath)); newFile = container.getFile(new Path(filename)); if (newFile.exists()) { JDTManager.rename(newFile, new NullProgressMonitor()); newFile.delete(true, new NullProgressMonitor()); } subMonitor.split(30); byte[] source = content.getBytes(Charset.forName("UTF-8")); newFile.create(new ByteArrayInputStream(source), true, new NullProgressMonitor()); subMonitor.split(70); } finally { subMonitor.done(); } return newFile; }
/** * @param jobname * @param tasks * @return */ public static Job createJob(String jobname, List<UITask.Task> tasks) { Job job = new Job(jobname) { @Override protected IStatus run(IProgressMonitor monitor) { SubMonitor subMonitor = SubMonitor.convert(monitor, tasks.size()); for (UITask.Task task : tasks) { try { subMonitor.setTaskName(task.getSummary()); workOnTask(task, subMonitor.split(1)); } catch (Exception e) { return Status.CANCEL_STATUS; } } return Status.OK_STATUS; } }; job.setUser(true); return job; }
private void performTest(DbSource source) throws IOException, InterruptedException, CoreException { assertFalse("DB source should not be loaded", source.isLoaded()); try{ source.getDbObject(); fail("Source is not loaded yet, exception expected"); }catch(IllegalStateException ex){ // do nothing: expected behavior } PgDatabase dbSource = source.get(SubMonitor.convert(null, "", 1)); assertTrue("DB source should be loaded", source.isLoaded()); assertEquals("Db loaded not equal to predefined db", dbPredefined, dbSource); }
@Override protected PgDatabase loadInternal(SubMonitor monitor) throws IOException, InterruptedException, CoreException { String charset = proj.getProjectCharset(); monitor.subTask(Messages.dbSource_loading_tree); IProject project = proj.getProject(); int filesCount = PgUIDumpLoader.countFiles(project); monitor.setWorkRemaining(filesCount); IEclipsePreferences pref = proj.getPrefs(); return PgUIDumpLoader.loadDatabaseSchemaFromIProject( project.getProject(), getPgDiffArgs(charset, pref.getBoolean(PROJ_PREF.FORCE_UNIX_NEWLINES, true)), monitor, null, errors); }
@Override protected PgDatabase loadInternal(SubMonitor monitor) throws InterruptedException, IOException { monitor.subTask(Messages.dbSource_loading_dump); try { int linesCount = countLines(filename); monitor.setWorkRemaining(linesCount > AVERAGE_STATEMENT_LENGTH ? linesCount/AVERAGE_STATEMENT_LENGTH : 1); } catch (IOException e) { Log.log(Log.LOG_INFO, "Error counting file lines. Setting 1000"); //$NON-NLS-1$ monitor.setWorkRemaining(1000); } List<AntlrError> errList = null; try (PgDumpLoader loader = new PgDumpLoader(filename, getPgDiffArgs(encoding, forceUnixNewlines), monitor, 2)) { errList = loader.getErrors(); return loader.load(); } finally { if (errList != null && !errList.isEmpty()) { errors.put(filename.getPath(), errList); } } }
@Override protected PgDatabase loadInternal(SubMonitor monitor) throws IOException, InterruptedException { SubMonitor pm = SubMonitor.convert(monitor, 2); try (TempFile tf = new TempFile("tmp_dump_", ".sql")) { //$NON-NLS-1$ //$NON-NLS-2$ File dump = tf.get().toFile(); pm.newChild(1).subTask(Messages.dbSource_executing_pg_dump); new PgDumper(exePgdump, customParams, host, port, user, pass, dbname, encoding, timezone, dump.getAbsolutePath()).pgDump(); pm.newChild(1).subTask(Messages.dbSource_loading_dump); try (PgDumpLoader loader = new PgDumpLoader(dump, getPgDiffArgs(encoding, forceUnixNewlines), monitor)) { return loader.load(); } } }
@Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { Log.log(Log.LOG_INFO, "Init project at " + proj.getPathToProject()); //$NON-NLS-1$ SubMonitor pm = SubMonitor.convert(monitor, Messages.initProjectFromSource_initializing_project, 75); initRepoFromSource(pm); monitor.done(); } catch (IOException | CoreException ex) { throw new InvocationTargetException(ex, MessageFormat.format( Messages.initProjectFromSource_ioexception_while_creating_project, ex.getLocalizedMessage())); } }
@Override protected IStatus run(IProgressMonitor monitor) { SubMonitor pm = SubMonitor.convert( monitor, Messages.commitPartDescr_commiting, 2); Log.log(Log.LOG_INFO, "Applying diff tree to db"); //$NON-NLS-1$ pm.newChild(1).subTask(Messages.commitPartDescr_modifying_db_model); // 1 pm.newChild(1).subTask(Messages.commitPartDescr_exporting_db_model); // 2 try { Collection<TreeElement> checked = new TreeFlattener() .onlySelected() .onlyEdits(dbProject.getDbObject(), dbRemote.getDbObject()) .flatten(tree); new ProjectUpdater(dbRemote.getDbObject(), dbProject.getDbObject(), checked, proj).updatePartial(); monitor.done(); } catch (IOException | CoreException e) { return new Status(Status.ERROR, PLUGIN_ID.THIS, Messages.ProjectEditorDiffer_commit_error, e); } if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
@Override protected IStatus run(IProgressMonitor monitor) { try { Log.log(Log.LOG_INFO, "Update DDL starting"); //$NON-NLS-1$ SubMonitor.convert(monitor).setTaskName(Messages.SqlEditor_update_ddl); scriptThread.start(); while(scriptThread.isAlive()) { Thread.sleep(20); if(monitor.isCanceled()) { ConsoleFactory.write(Messages.sqlScriptDialog_script_execution_interrupted); Log.log(Log.LOG_INFO, "Script execution interrupted by user"); //$NON-NLS-1$ scriptThread.interrupt(); return Status.CANCEL_STATUS; } } return Status.OK_STATUS; } catch (InterruptedException ex) { scriptThread.interrupt(); return Status.CANCEL_STATUS; } finally { monitor.done(); } }
@Override public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException { SubMonitor progress = SubMonitor.convert(monitor); if (!prefs.isCompilerEnabled()) { return; } final List<IResourceDescription.Delta> deltas = getRelevantDeltas(context); if (deltas.isEmpty()) { return; } if (progress.isCanceled()) { throw new OperationCanceledException(); } progress.beginTask("Compiling solidity...", deltas.size()); List<URI> uris = deltas.stream().map(delta -> delta.getUri()).collect(Collectors.toList()); compiler.compile(uris, progress); context.getBuiltProject().refreshLocal(IProject.DEPTH_INFINITE, progress); progress.done(); }
/** * Creates an appengine-web.xml file in the WEB-INF folder if it doesn't exist. */ @VisibleForTesting void createConfigFiles(IProject project, IProgressMonitor monitor) throws CoreException { SubMonitor progress = SubMonitor.convert(monitor, 10); IFile appEngineWebXml = WebProjectUtil.findInWebInf(project, new Path(APPENGINE_WEB_XML)); if (appEngineWebXml != null && appEngineWebXml.exists()) { return; } // Use the virtual component model decide where to create the appengine-web.xml appEngineWebXml = WebProjectUtil.createFileInWebInf(project, new Path(APPENGINE_WEB_XML), new ByteArrayInputStream(new byte[0]), progress.newChild(2)); String configFileLocation = appEngineWebXml.getLocation().toString(); Map<String, String> parameters = new HashMap<>(); parameters.put("runtime", "java8"); Templates.createFileContent(configFileLocation, Templates.APPENGINE_WEB_XML_TEMPLATE, parameters); progress.worked(4); appEngineWebXml.refreshLocal(IFile.DEPTH_ZERO, progress.newChild(1)); }
/** {@inheritDoc} */ @Override public void process(final Delta delta, final ResourceSet resourceSet, final IProgressMonitor monitor) { URI uri = delta.getUri(); ILanguageSpecificResourcePostProcessor postProcessor = getPostProcessor(uri); if (postProcessor != null) { try { traceSet.started(ResourcePostProcessingEvent.class, uri); SubMonitor subMonitor = SubMonitor.convert(monitor, 1); if (delta.getNew() != null) { if (resourceSet == null) { throw new IllegalArgumentException("resourceSet may not be null for changed resources."); //$NON-NLS-1$ } postProcessor.processChanged(uri, resourceSet.getResource(uri, true), resourceSet, subMonitor.newChild(1)); } else { postProcessor.processDeleted(uri, resourceSet, subMonitor.newChild(1)); } } finally { traceSet.ended(ResourcePostProcessingEvent.class); } } }
/** * Modifies the set of project facets in the configured project by performing the series of * configured facets actions. * * @param monitor a progress monitor, or null if progress reporting and cancellation are not desired * @throws CoreException if anything goes wrong while applying facet actions */ public void install(IProgressMonitor monitor) throws CoreException { SubMonitor subMonitor = SubMonitor.convert(monitor, 100); // Workaround deadlock bug described in Eclipse bug (https://bugs.eclipse.org/511793). // There are graph update jobs triggered by the completion of the CreateProjectOperation // above (from resource notifications) and from other resource changes from modifying the // project facets. So we force the dependency graph to defer updates try { IDependencyGraph.INSTANCE.preUpdate(); try { Job.getJobManager().join(DependencyGraphImpl.GRAPH_UPDATE_JOB_FAMILY, subMonitor.newChild(10)); } catch (OperationCanceledException | InterruptedException ex) { logger.log(Level.WARNING, "Exception waiting for WTP Graph Update job", ex); } facetedProject.modify(facetInstallSet, subMonitor.newChild(90)); } finally { IDependencyGraph.INSTANCE.postUpdate(); } }
private void createConfigFiles(IProject project, IProgressMonitor monitor) throws CoreException { SubMonitor subMonitor = SubMonitor.convert(monitor, 100); FlexDeployPreferences flexDeployPreferences = new FlexDeployPreferences(project); String appYamlPath = flexDeployPreferences.getAppYamlPath(); IFile appYaml = project.getFile(appYamlPath); if (appYaml.exists()) { return; } IContainer appYamlParentFolder = appYaml.getParent(); if (!appYamlParentFolder.exists()) { ResourceUtils.createFolders(appYamlParentFolder, subMonitor.newChild(5)); } appYaml.create(new ByteArrayInputStream(new byte[0]), true, subMonitor.newChild(10)); String configFileLocation = appYaml.getLocation().toString(); Templates.createFileContent( configFileLocation, Templates.APP_YAML_TEMPLATE, Collections.<String, String>emptyMap()); subMonitor.worked(55); appYaml.refreshLocal(IResource.DEPTH_ZERO, subMonitor.newChild(30)); }
/** {@inheritDoc} */ @Override protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { SubMonitor subMonitor = SubMonitor.convert(monitor, "create new Catalog:" + getProjectInfo().getCatalogName(), 2); IFolder outputFolder = (IFolder) getProjectInfo().getPackageFragment().getResource(); IProject project = outputFolder.getProject(); IPath path = project.getLocation().makeAbsolute(); try { generatorUtil.generateCheckFile(path, getProjectInfo()); generatorUtil.generateDefaultQuickfixProvider(path, getProjectInfo()); project.refreshLocal(IResource.DEPTH_INFINITE, monitor); } finally { setResult(outputFolder.getFile(getProjectInfo().getCatalogName() + '.' + CheckConstants.FILE_EXTENSION)); subMonitor.done(); } }
/** * Creates files for a sample App Engine project in the supplied Eclipse project. * * @param project the Eclipse project to be filled with templated code * @param config replacement values * @param isStandardProject true if project should be configured to have the App Engine Standard * configuration files and false if project should have the App Engine Flexible configuration * files. * @param monitor progress monitor * @return the most important file created that should be opened in an editor */ private static IFile materialize(IProject project, AppEngineProjectConfig config, boolean isStandardProject, IProgressMonitor monitor) throws CoreException { SubMonitor subMonitor = SubMonitor.convert(monitor, "Generating code", 45); IFile hello = createJavaSourceFiles(project, config, isStandardProject, subMonitor.newChild(15)); createAppEngineWebXmlOrAppYaml(project, config, isStandardProject, subMonitor.newChild(5)); createWebXml(project, config, isStandardProject, subMonitor.newChild(5)); createWebContents(project, subMonitor.newChild(15)); if (config.getUseMaven()) { createPomXml(project, config, isStandardProject, subMonitor.newChild(5)); } else { subMonitor.worked(5); } return hello; }
private static void enableMavenNature(IProject newProject, IProgressMonitor monitor) throws CoreException { SubMonitor subMonitor = SubMonitor.convert(monitor, 30); // Workaround deadlock bug described in Eclipse bug (https://bugs.eclipse.org/511793). try { IDependencyGraph.INSTANCE.preUpdate(); try { Job.getJobManager().join(DependencyGraphImpl.GRAPH_UPDATE_JOB_FAMILY, subMonitor.newChild(8)); } catch (OperationCanceledException | InterruptedException ex) { logger.log(Level.WARNING, "Exception waiting for WTP Graph Update job", ex); } ResolverConfiguration resolverConfiguration = new ResolverConfiguration(); MavenPlugin.getProjectConfigurationManager().enableMavenNature(newProject, resolverConfiguration, subMonitor.newChild(20)); } finally { IDependencyGraph.INSTANCE.postUpdate(); } // M2E will cleverly set "target/<artifact ID>-<version>/WEB-INF/classes" as a new Java output // folder; delete the default old folder. newProject.getFolder("build").delete(true /* force */, subMonitor.newChild(2)); }
@Override protected void addAdditionalDependencies(IProject newProject, AppEngineProjectConfig config, IProgressMonitor monitor) throws CoreException { super.addAdditionalDependencies(newProject, config, monitor); if (config.getUseMaven()) { return; } SubMonitor subMonitor = SubMonitor.convert(monitor, 100); // Create a lib folder IFolder libFolder = newProject.getFolder("lib"); //$NON-NLS-1$ if (!libFolder.exists()) { libFolder.create(true, true, subMonitor.newChild(10)); } // Download the dependencies from maven subMonitor.setWorkRemaining(SERVLET_DEPENDENCIES.size() + 10); for (MavenCoordinates dependency : SERVLET_DEPENDENCIES) { installArtifact(dependency, libFolder, subMonitor.newChild(1)); } addDependenciesToClasspath(newProject, libFolder, subMonitor.newChild(10)); }
public static void publishExploded(IProject project, IPath destination, IPath safeWorkDirectory, IProgressMonitor monitor) throws CoreException { Preconditions.checkNotNull(project, "project is null"); //$NON-NLS-1$ Preconditions.checkNotNull(destination, "destination is null"); //$NON-NLS-1$ Preconditions.checkArgument(!destination.isEmpty(), "destination is empty path"); //$NON-NLS-1$ Preconditions.checkNotNull(safeWorkDirectory, "safeWorkDirectory is null"); //$NON-NLS-1$ if (monitor.isCanceled()) { throw new OperationCanceledException(); } SubMonitor subMonitor = SubMonitor.convert(monitor, 100); subMonitor.setTaskName(Messages.getString("task.name.publish.war")); IModuleResource[] resources = flattenResources(project, safeWorkDirectory, subMonitor.newChild(10)); PublishUtil.publishFull(resources, destination, subMonitor.newChild(90)); }
public static void publishWar(IProject project, IPath destination, IPath safeWorkDirectory, IProgressMonitor monitor) throws CoreException { Preconditions.checkNotNull(project, "project is null"); //$NON-NLS-1$ Preconditions.checkNotNull(destination, "destination is null"); //$NON-NLS-1$ Preconditions.checkArgument(!destination.isEmpty(), "destination is empty path"); //$NON-NLS-1$ Preconditions.checkNotNull(safeWorkDirectory, "safeWorkDirectory is null"); //$NON-NLS-1$ if (monitor.isCanceled()) { throw new OperationCanceledException(); } SubMonitor subMonitor = SubMonitor.convert(monitor, 100); subMonitor.setTaskName(Messages.getString("task.name.publish.war")); IModuleResource[] resources = flattenResources(project, safeWorkDirectory, subMonitor.newChild(10)); PublishUtil.publishZip(resources, destination, subMonitor.newChild(90)); }
/** * @param explodedWarDirectory the input of the staging operation * @param stagingDirectory where the result of the staging operation will be written * @param cloudSdk executes the staging operation */ public static void stageStandard(IPath explodedWarDirectory, IPath stagingDirectory, CloudSdk cloudSdk, IProgressMonitor monitor) { if (monitor.isCanceled()) { throw new OperationCanceledException(); } SubMonitor progress = SubMonitor.convert(monitor, 1); progress.setTaskName(Messages.getString("task.name.stage.project")); //$NON-NLS-1$ DefaultStageStandardConfiguration stagingConfig = new DefaultStageStandardConfiguration(); stagingConfig.setSourceDirectory(explodedWarDirectory.toFile()); stagingConfig.setStagingDirectory(stagingDirectory.toFile()); stagingConfig.setEnableJarSplitting(true); stagingConfig.setDisableUpdateCheck(true); CloudSdkAppEngineStandardStaging staging = new CloudSdkAppEngineStandardStaging(cloudSdk); staging.stageStandard(stagingConfig); progress.worked(1); }
/** * @param appEngineDirectory directory containing {@code app.yaml} * @param deployArtifact project to be deploy (such as WAR or JAR) * @param stagingDirectory where the result of the staging operation will be written * @throws AppEngineException when staging fails * @throws OperationCanceledException when user cancels the operation */ public static void stageFlexible(IPath appEngineDirectory, IPath deployArtifact, IPath stagingDirectory, IProgressMonitor monitor) { if (monitor.isCanceled()) { throw new OperationCanceledException(); } SubMonitor progress = SubMonitor.convert(monitor, 1); progress.setTaskName(Messages.getString("task.name.stage.project")); //$NON-NLS-1$ DefaultStageFlexibleConfiguration stagingConfig = new DefaultStageFlexibleConfiguration(); stagingConfig.setAppEngineDirectory(appEngineDirectory.toFile()); stagingConfig.setArtifact(deployArtifact.toFile()); stagingConfig.setStagingDirectory(stagingDirectory.toFile()); CloudSdkAppEngineFlexibleStaging staging = new CloudSdkAppEngineFlexibleStaging(); staging.stageFlexible(stagingConfig); progress.worked(1); }
@Override public IStatus stage(IPath stagingDirectory, IPath safeWorkDirectory, MessageConsoleStream stdoutOutputStream, MessageConsoleStream stderrOutputStream, IProgressMonitor monitor) { SubMonitor subMonitor = SubMonitor.convert(monitor, 100); boolean result = stagingDirectory.toFile().mkdirs(); if (!result) { return StatusUtil.error(this, "Could not create staging directory " + stagingDirectory); } try { IPath deployArtifact = getDeployArtifact(safeWorkDirectory, subMonitor.newChild(40)); CloudSdkStagingHelper.stageFlexible(appEngineDirectory, deployArtifact, stagingDirectory, subMonitor.newChild(60)); return Status.OK_STATUS; } catch (AppEngineException | CoreException ex) { return StatusUtil.error(this, Messages.getString("deploy.job.staging.failed"), ex); } finally { subMonitor.done(); } }
@Override protected IPath getDeployArtifact(IPath safeWorkingDirectory, IProgressMonitor monitor) throws CoreException { SubMonitor subMonitor = SubMonitor.convert(monitor, 100); try { ILaunchConfiguration config = createMavenPackagingLaunchConfiguration(project); ILaunch launch = config.launch("run", subMonitor.newChild(10)); if (!waitUntilLaunchTerminates(launch, subMonitor.newChild(90))) { throw new OperationCanceledException(); } return getFinalArtifactPath(project); } catch (InterruptedException ex) { throw new OperationCanceledException(); } }
@Before public void setUp() { handler = new LaunchHelper() { @Override protected void launch(IServer server, String launchMode, SubMonitor progress) throws CoreException { // do nothing } @Override public Collection<IServer> findExistingServers(IModule[] modules, boolean exact, SubMonitor progress) { if (serverToReturn != null) { return Collections.singleton(serverToReturn); } return super.findExistingServers(modules, exact, progress); } }; }
@Override public void earlyStartup() { workbench = PlatformUI.getWorkbench(); workspace = ResourcesPlugin.getWorkspace(); Job projectUpdater = new WorkspaceJob(Messages.getString("updating.projects.jobname")) { //$NON-NLS-1$ @Override public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { SubMonitor progress = SubMonitor.convert(monitor, 40); progress.subTask(Messages.getString("searching.for.projects")); //$NON-NLS-1$ Collection<IProject> projects = findCandidates(progress.newChild(10)); if (projects.isEmpty()) { return Status.OK_STATUS; } projects = promptUser(projects, progress.newChild(5)); if (projects.isEmpty()) { return Status.OK_STATUS; } progress.subTask(Messages.getString("updating.projects")); //$NON-NLS-1$ return upgradeProjects(projects, progress.newChild(25)); } }; projectUpdater.setRule(workspace.getRoot()); projectUpdater.setUser(true); projectUpdater.schedule(500); }
/** * Prompt the user to select the projects to upgrade. */ private Collection<IProject> promptUser(final Collection<IProject> projects, SubMonitor progress) { Preconditions.checkArgument(!projects.isEmpty(), "no projects specified!"); // $NON-NLS-1$ //$NON-NLS-1$ progress.setBlocked(StatusUtil.info(this, Messages.getString("waiting.for.user"))); //$NON-NLS-1$ final boolean[] proceed = new boolean[1]; workbench.getDisplay().syncExec(new Runnable() { @Override public void run() { StringBuilder sb = new StringBuilder( Messages.getString("following.projects.must.be.updated")); //$NON-NLS-1$ sb.append("\n"); //$NON-NLS-1$ for (IProject project : projects) { sb.append("\n ").append(project.getName()); //$NON-NLS-1$ } sb.append("\n\n"); //$NON-NLS-1$ sb.append(Messages.getString("update.now")); //$NON-NLS-1$ proceed[0] = MessageDialog.openQuestion(getShell(), Messages.getString("cloud.tools.for.eclipse"), sb.toString()); //$NON-NLS-1$ } }); progress.clearBlocked(); return proceed[0] ? projects : Collections.<IProject>emptyList(); }
/** * Removes various GPE-related remnants: classpath entries, nature, runtime, and facets. Any error * during operation is logged but ignored. * * @return true if this was a GPE project * @throws CoreException if the project is unusable (e.g., not open, doesn't exist, out of sync) */ public static boolean removeObsoleteGpeRemnants( final IFacetedProject facetedProject, IProgressMonitor monitor) throws CoreException { SubMonitor subMonitor = SubMonitor.convert(monitor, 40); IProject project = facetedProject.getProject(); boolean wasGpeProject = false; wasGpeProject |= removeGpeClasspathEntries(project, subMonitor.newChild(10)); if (subMonitor.isCanceled()) { return wasGpeProject; } wasGpeProject |= removeGpeNature(project, subMonitor.newChild(10)); if (subMonitor.isCanceled()) { return wasGpeProject; } wasGpeProject |= removeGpeRuntimeAndFacets(facetedProject); subMonitor.worked(20); return wasGpeProject; }
public static void addNativeLibrary(IJavaProject javaProject, List<Library> libraries, IProgressMonitor monitor) throws CoreException { if (libraries.isEmpty()) { return; } AnalyticsLibraryPingHelper.sendLibrarySelectionPing(AnalyticsEvents.NATIVE_PROJECT, libraries); SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.getString("adding.app.engine.libraries"), //$NON-NLS-1$ 25); Library masterLibrary = collectLibraryFiles(javaProject, libraries, subMonitor.newChild(8)); IClasspathEntry masterEntry = computeEntry(javaProject, masterLibrary, subMonitor.newChild(8)); saveLibraryList(javaProject, libraries, subMonitor.newChild(1)); if (masterEntry != null) { ClasspathUtil.addClasspathEntry(javaProject.getProject(), masterEntry, subMonitor.newChild(8)); } runContainerResolverJob(javaProject); }
/** * Load the list of library dependencies saved for this project. */ public static List<Library> loadLibraryList(IJavaProject project, IProgressMonitor monitor) throws CoreException { SubMonitor progress = SubMonitor.convert(monitor, 10); LibraryClasspathContainerSerializer serializer = new LibraryClasspathContainerSerializer(); List<String> savedLibraryIds; try { savedLibraryIds = serializer.loadLibraryIds(project); progress.worked(3); } catch (IOException ex) { throw new CoreException( StatusUtil.error(BuildPath.class, "Error retrieving project library list", ex)); //$NON-NLS-1$ } List<Library> selectedLibraries = new ArrayList<>(); progress.setWorkRemaining(savedLibraryIds.size()); for (String libraryId : savedLibraryIds) { Library library = CloudLibraries.getLibrary(libraryId); if (library != null) { selectedLibraries.add(library); } progress.worked(1); } return selectedLibraries; }
/** * Save the list of library dependencies for this project. */ public static void saveLibraryList(IJavaProject project, List<Library> libraries, IProgressMonitor monitor) throws CoreException { SubMonitor progress = SubMonitor.convert(monitor, libraries.size() + 10); LibraryClasspathContainerSerializer serializer = new LibraryClasspathContainerSerializer(); List<String> libraryIds = new ArrayList<>(); for (Library library : libraries) { libraryIds.add(library.getId()); progress.worked(1); } try { serializer.saveLibraryIds(project, libraryIds); progress.worked(5); // in practice, we only ever use the master-container IPath containerPath = new Path(LibraryClasspathContainer.CONTAINER_PATH_PREFIX) .append(CloudLibraries.MASTER_CONTAINER_ID); serializer.resetContainer(project, containerPath); progress.worked(5); } catch (IOException ex) { throw new CoreException( StatusUtil.error(BuildPath.class, "Error saving project library list", ex)); //$NON-NLS-1$ } }
@Override public IStatus resolveAll(IJavaProject javaProject, IProgressMonitor monitor) { try { MultiStatus status = StatusUtil.multi(this, Messages.getString("TaskResolveLibrariesError")); //$NON-NLS-1$ IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.getString("TaskResolveLibraries"), //$NON-NLS-1$ getTotalWork(rawClasspath)); for (IClasspathEntry classpathEntry : rawClasspath) { if (classpathEntry.getPath().segment(0) .equals(LibraryClasspathContainer.CONTAINER_PATH_PREFIX)) { IStatus resolveContainerStatus = resolveContainer(javaProject, classpathEntry.getPath(), subMonitor.newChild(1)); status.add(resolveContainerStatus); } } // rewrite if OK as otherwise Progress View shows the resolving error message return StatusUtil.filter(status); } catch (CoreException ex) { return StatusUtil.error(this, Messages.getString("TaskResolveLibrariesError"), ex); //$NON-NLS-1$ } }
private LibraryClasspathContainer resolveLibraryFiles(IJavaProject javaProject, IPath containerPath, Library library, List<Job> sourceAttacherJobs, IProgressMonitor monitor) throws CoreException { List<LibraryFile> libraryFiles = library.getAllDependencies(); SubMonitor subMonitor = SubMonitor.convert(monitor, libraryFiles.size()); subMonitor.subTask(Messages.getString("TaskResolveArtifacts", getLibraryDescription(library))); SubMonitor child = subMonitor.newChild(libraryFiles.size()); List<IClasspathEntry> entries = new ArrayList<>(); for (LibraryFile libraryFile : libraryFiles) { IClasspathEntry newLibraryEntry = resolveLibraryFileAttachSourceAsync(javaProject, containerPath, libraryFile, sourceAttacherJobs, monitor); entries.add(newLibraryEntry); child.worked(1); } monitor.done(); LibraryClasspathContainer container = new LibraryClasspathContainer( containerPath, getLibraryDescription(library), entries, libraryFiles); return container; }
/** * @see org.eclipse.tools.templates.freemarker.FMProjectGenerator#generate(java.util.Map, * org.eclipse.core.runtime.IProgressMonitor) */ @Override public void generate(Map<String, Object> model, IProgressMonitor monitor) throws CoreException { model.put("statechartName", this.statechartName); //$NON-NLS-1$ model.put("srcFolder", this.srcFolderName); //$NON-NLS-1$ model.put("srcGenFolder", this.srcGenFolderName); //$NON-NLS-1$ model.put("timer", this.timer.getId()); //$NON-NLS-1$ model.put("cyclePeriod", Integer.toString(this.cyclePeriod)); //$NON-NLS-1$ final SubMonitor subMonitor = SubMonitor.convert(monitor, 100); super.generate(model, subMonitor.split(70)); final IProject project = getProject(); CoreModel.getDefault().create(project).setRawPathEntries( new IPathEntry[] { CoreModel.newSourceEntry(project.getFullPath()) }, subMonitor.split(10)); createDiagram(subMonitor.split(20)); }
/** * Builds all other registered (non-language specific) {@link IXtextBuilderParticipant}s. * * @param buildContext * the {@link IBuildContext}, must not be {@code null} * @param monitor * the {@link IProgressMonitor}, must not be {@code null} * @throws CoreException * caused by an {@link IXtextBuilderParticipant} */ protected void buildOtherParticipants(final IBuildContext buildContext, final IProgressMonitor monitor) throws CoreException { ImmutableList<IXtextBuilderParticipant> otherBuilderParticipants = getParticipants(); if (otherBuilderParticipants.isEmpty()) { return; } SubMonitor progress = SubMonitor.convert(monitor, otherBuilderParticipants.size()); progress.subTask(Messages.RegistryBuilderParticipant_InvokingBuildParticipants); for (final IXtextBuilderParticipant participant : otherBuilderParticipants) { if (progress.isCanceled()) { throw new OperationCanceledException(); } try { if (initializeParticipant(participant)) { participant.build(buildContext, progress.newChild(1)); } // CHECKSTYLE:CHECK-OFF IllegalCatchCheck we need to recover from any exception and continue the build } catch (Throwable throwable) { // CHECKSTYLE:CHECK-ON IllegalCatchCheck LOG.error("Error occurred during build of builder participant: " //$NON-NLS-1$ + participant.getClass().getName(), throwable); } } }