-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract the delta handling from the resource API
Currently m2e is directly wired to the resource delta API, while this seems good in the context of eclipse for m2e this imposes to restrictive API as it is all noimplement/extend interfaces and offer much more than m2e actually using. This aims to implement a thin wrapper for further improvement of delta detection especially when it comes to resource see for example #1302 This will not fix anything but is an important first step to ensure things are still working as before.
- Loading branch information
Showing
6 changed files
with
222 additions
and
45 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
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
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
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
76 changes: 76 additions & 0 deletions
76
...e/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseResourceBuildDelta.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,76 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2008-2023 Sonatype, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Sonatype, Inc. - initial API and implementation | ||
* Christoph Läubrich - extracted and implement wrapper API | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.m2e.core.internal.builder.plexusbuildapi; | ||
|
||
import java.io.File; | ||
|
||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.resources.IResourceDelta; | ||
import org.eclipse.core.runtime.IAdaptable; | ||
import org.eclipse.core.runtime.IPath; | ||
import org.eclipse.core.runtime.Path; | ||
|
||
import org.eclipse.m2e.core.internal.builder.IIncrementalBuildFramework; | ||
|
||
|
||
public final class EclipseResourceBuildDelta implements IIncrementalBuildFramework.BuildDelta, IAdaptable { | ||
private final IResource resource; | ||
|
||
private final IResourceDelta delta; | ||
|
||
/** | ||
* @param resource | ||
* @param delta | ||
*/ | ||
public EclipseResourceBuildDelta(IResourceDelta delta) { | ||
this.resource = delta != null ? delta.getResource() : null; | ||
this.delta = delta; | ||
} | ||
|
||
@Override | ||
public boolean hasDelta(File file) { | ||
return hasDelta(getRelativePath(file)); | ||
} | ||
|
||
private boolean hasDelta(IPath path) { | ||
return path == null || this.delta.findMember(path) != null; | ||
} | ||
|
||
/** | ||
* Returns path relative to delta resource location. | ||
*/ | ||
private IPath getRelativePath(File file) { | ||
IPath basepath = this.resource.getLocation(); | ||
IPath path = Path.fromOSString(file.getAbsolutePath()); | ||
|
||
if(!basepath.isPrefixOf(path)) { | ||
return null; | ||
} | ||
|
||
return path.removeFirstSegments(basepath.segmentCount()); | ||
} | ||
|
||
@Override | ||
public <T> T getAdapter(Class<T> adapter) { | ||
if(adapter.isInstance(delta)) { | ||
return adapter.cast(delta); | ||
} | ||
if(adapter.isInstance(resource)) { | ||
return adapter.cast(resource); | ||
} | ||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.