Permalink
Browse files

added AbstractWorkspaceCleaner (use by HEDL PRO and NatSpec) to clean

the workspace after installation
increased version number to force update
  • Loading branch information...
mirkoseifert committed Apr 5, 2013
1 parent c0edf58 commit 23541a7aac99e3001641dcafb048a27e84e31834
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2013
+ * DevBoost GmbH, Berlin, Amtsgericht Charlottenburg, HRB 140026
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * DevBoost GmbH - Berlin, Germany
+ * - initial API and implementation
+ ******************************************************************************/
+package de.devboost.eclipse.jdtutilities;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+
+/**
+ * The {@link AbstractWorkspaceCleaner} can be used to perform a clean build on
+ * the whole workspace.
+ */
+public abstract class AbstractWorkspaceCleaner {
+
+ public void performCleanBuildIfRequired() {
+ List<Job> jobs = createRefreshWorkspaceOnFirstStartupJobs();
+ for (Job job : jobs) {
+ job.schedule();
+ }
+ }
+
+ private List<Job> createRefreshWorkspaceOnFirstStartupJobs() {
+ List<Job> jobs = new ArrayList<Job>();
+ if (mustClean()) {
+ jobs.add(createCleanAllJob());
+ setCleaned();
+ }
+ return jobs;
+ }
+
+ protected abstract void setCleaned();
+
+ protected abstract boolean mustClean();
+
+ protected abstract void logException(CoreException ce);
+
+ private Job createCleanAllJob() {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IWorkspaceRoot root = workspace.getRoot();
+ final IProject[] projects = root.getProjects();
+ Job cleanAllJob = new Job("Clean workspace") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ for (IProject project : projects) {
+ try {
+ project.build(IncrementalProjectBuilder.CLEAN_BUILD, monitor);
+ } catch (CoreException ce) {
+ logException(ce);
+ }
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ cleanAllJob.setRule(root);
+ return cleanAllJob;
+ }
+}
@@ -2,7 +2,7 @@
<feature
id="de.devboost.eclipse.jdtutilities"
label="JDTUtilities"
- version="1.0.2"
+ version="1.0.3"
provider-name="DevBoost GmbH - Germany">
<description>JDTUtilities - A set of utility classes that ease working with the Eclipse JDT.</description>

0 comments on commit 23541a7

Please sign in to comment.