forked from eclipse-m2e/m2e-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
M2Eclipse gets stuck in endless update loop
Fix eclipse-m2e#123
- Loading branch information
Showing
3 changed files
with
145 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectProcessingTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Christoph Läubrich and others | ||
* 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: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.m2e.core.internal.project; | ||
|
||
import java.util.Iterator; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.eclipse.core.resources.IFile; | ||
|
||
|
||
/** | ||
* ProjectProcessingTracker keeps track of the progress in refreshing projects. | ||
* | ||
*/ | ||
public class ProjectProcessingTracker { | ||
|
||
static final Logger log = LoggerFactory.getLogger(ProjectProcessingTracker.class); | ||
|
||
private Set<IFile> processed = new LinkedHashSet<>(); | ||
|
||
private Set<IFile> changedWhileRunning = new LinkedHashSet<>(); | ||
|
||
private Set<IFile> seed; | ||
|
||
private DependencyResolutionContext context; | ||
|
||
/** | ||
* @param allProcessedPoms | ||
*/ | ||
public ProjectProcessingTracker(DependencyResolutionContext context) { | ||
this.context = context; | ||
this.seed = context.getCurrent(); | ||
} | ||
|
||
/** | ||
* @param context | ||
* @return | ||
*/ | ||
public boolean needsImprovement() { | ||
if(changedWhileRunning.isEmpty()) { | ||
log.debug("Nothing changed in this cycle."); | ||
return false; | ||
} | ||
if(seed.isEmpty()) { | ||
log.debug("Seed is empty."); | ||
return false; | ||
} | ||
log.debug("seed = {}", seed); | ||
log.debug("processed = {}", processed); | ||
log.debug("changed = {}", changedWhileRunning); | ||
boolean removed = false; | ||
for(Iterator<IFile> iterator = seed.iterator(); iterator.hasNext();) { | ||
IFile file = iterator.next(); | ||
if(changedWhileRunning.contains(file)) { | ||
//we need to keep this in the seed... | ||
continue; | ||
} | ||
log.debug("{} was improved!", file); | ||
iterator.remove(); | ||
removed = true; | ||
} | ||
if(removed) { | ||
//we have an improvement... | ||
context.forcePomFiles(changedWhileRunning); | ||
//add all possibly new ones to the seed... | ||
seed.addAll(changedWhileRunning); | ||
//clear everything for next iteration... | ||
changedWhileRunning.clear(); | ||
processed.clear(); | ||
return true; | ||
} | ||
log.debug("No new project was refreshed -> no improvement found!"); | ||
return false; | ||
} | ||
|
||
/** | ||
* @param pom | ||
* @return | ||
*/ | ||
public boolean shouldProcess(IFile pom) { | ||
if(processed.add(pom)) { | ||
return true; | ||
} | ||
changedWhileRunning.add(pom); | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters