Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2013-04-25 00:30:13 -0400
committerIgor Fedorenko2013-05-04 12:43:23 -0400
commitc92859e1225c14b9f94648b3d9c32d7b566d7c78 (patch)
tree5e85a2ffeff2728f9b6969f865c5c085f52a06be
parentc7cca17b29afc1f48b84d9baddb36eaccbad4ae7 (diff)
downloadm2e-core-c92859e1225c14b9f94648b3d9c32d7b566d7c78.tar.gz
m2e-core-c92859e1225c14b9f94648b3d9c32d7b566d7c78.tar.xz
m2e-core-c92859e1225c14b9f94648b3d9c32d7b566d7c78.zip
perf: optimized WorkspaceStateWriter
WorkspaceStateWriter was forcing loading of MavenProject for all workspace projects. Use IProject persistent property to avoid unnecessary loading of MavenProjects. Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceStateWriter.java50
1 files changed, 40 insertions, 10 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceStateWriter.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceStateWriter.java
index cc3c1c1e..feffab14 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceStateWriter.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceStateWriter.java
@@ -22,15 +22,18 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.QualifiedName;
-import org.apache.maven.artifact.Artifact;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.internal.project.registry.MavenProjectManager;
import org.eclipse.m2e.core.project.IMavenProjectChangedListener;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
@@ -41,6 +44,8 @@ import org.eclipse.m2e.core.project.MavenProjectChangedEvent;
* Maintains map file of maven artifacts present in workspace.
*/
public class WorkspaceStateWriter implements IMavenProjectChangedListener {
+ private static QualifiedName PPROP_EXTENSION = new QualifiedName(WorkspaceStateWriter.class.getName(), "extension"); //$NON-NLS-1$
+
private static final Logger log = LoggerFactory.getLogger(WorkspaceStateWriter.class);
private MavenProjectManager projectManager;
@@ -55,28 +60,47 @@ public class WorkspaceStateWriter implements IMavenProjectChangedListener {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
for(IMavenProjectFacade projectFacade : projectManager.getProjects()) {
- if(!projectFacade.getProject().isAccessible()) {
- log.debug("Project registry contains closed project {}", projectFacade.getProject());
+ IProject project = projectFacade.getProject();
+ if(!project.isAccessible()) {
+ log.debug("Project registry contains closed project {}", project);
// this is actually a bug somewhere in registry refresh logic, closed projects should not be there
continue;
}
try {
- Artifact artifact = projectFacade.getMavenProject(monitor).getArtifact();
+ ArtifactKey artifact = projectFacade.getArtifactKey();
IFile pomFile = projectFacade.getPom();
IPath location = pomFile.getLocation();
if(location != null) {
File pom = location.toFile();
if(pom.canRead()) {
- String key = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":pom:" + artifact.getBaseVersion(); //$NON-NLS-1$ //$NON-NLS-2$
+ String key = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":pom:" + artifact.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$
state.put(key, pom.getCanonicalPath());
}
}
IResource outputLocation = root.findMember(projectFacade.getOutputLocation());
- if(!"pom".equals(artifact.getType()) && outputLocation != null && outputLocation.exists()) { //$NON-NLS-1$
- String extension = artifact.getArtifactHandler().getExtension();
- String key = artifact.getGroupId()
- + ":" + artifact.getArtifactId() + ":" + extension + ":" + artifact.getBaseVersion(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- state.put(key, outputLocation.getLocation().toFile().getCanonicalPath());
+ if(!"pom".equals(projectFacade.getPackaging()) && outputLocation != null && outputLocation.exists()) { //$NON-NLS-1$
+ // three cases to consider
+ // 1. facade has cached MavenProject instance, i.e. it was refreshed during this eclipse session
+ // 2. project has persistent PPROP_EXTENSION
+ // 3. neither cached MavenProject instance nor PPROP_EXTENSION are present
+ String extension;
+ MavenProject mavenProject = projectFacade.getMavenProject();
+ if(mavenProject != null) {
+ extension = getAndPersistArtifactExtension(project, mavenProject);
+ } else {
+ extension = project.getPersistentProperty(PPROP_EXTENSION);
+ }
+ if(extension == null && mavenProject == null) {
+ // force loading of MavenProject
+ extension = getAndPersistArtifactExtension(project, projectFacade.getMavenProject(monitor));
+ }
+ if(extension != null) {
+ String key = artifact.getGroupId()
+ + ":" + artifact.getArtifactId() + ":" + extension + ":" + artifact.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ state.put(key, outputLocation.getLocation().toFile().getCanonicalPath());
+ } else {
+ log.warn("Could not determine project {} main artifact extension.", project);
+ }
}
} catch(CoreException ex) {
log.error("Error writing workspace state file", ex);
@@ -93,4 +117,10 @@ public class WorkspaceStateWriter implements IMavenProjectChangedListener {
log.error("Error writing workspace state file", ex);
}
}
+
+ private String getAndPersistArtifactExtension(IProject project, MavenProject mavenProject) throws CoreException {
+ String extension = mavenProject.getArtifact().getArtifactHandler().getExtension();
+ project.setPersistentProperty(PPROP_EXTENSION, extension);
+ return extension;
+ }
}

Back to the top