-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Drop legacy duplicated code #11501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
slawekjaranowski
wants to merge
1
commit into
apache:maven-3.9.x
from
slawekjaranowski:collapse-tracking-file-handling-3.x
Closed
Drop legacy duplicated code #11501
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -18,14 +18,13 @@ | |
| */ | ||
| package org.apache.maven.repository.legacy; | ||
|
|
||
| import javax.inject.Inject; | ||
| import javax.inject.Named; | ||
| import javax.inject.Singleton; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileInputStream; | ||
| import java.io.IOException; | ||
| import java.io.RandomAccessFile; | ||
| import java.nio.channels.Channels; | ||
| import java.nio.channels.FileChannel; | ||
| import java.nio.channels.FileLock; | ||
| import java.util.Date; | ||
| import java.util.HashMap; | ||
| import java.util.Properties; | ||
|
|
||
| import org.apache.maven.artifact.Artifact; | ||
|
|
@@ -37,19 +36,29 @@ | |
| import org.codehaus.plexus.component.annotations.Component; | ||
| import org.codehaus.plexus.logging.AbstractLogEnabled; | ||
| import org.codehaus.plexus.logging.Logger; | ||
| import org.eclipse.aether.internal.impl.TrackingFileManager; | ||
|
|
||
| /** | ||
| * DefaultUpdateCheckManager | ||
| */ | ||
| @Component(role = UpdateCheckManager.class) | ||
| @Named | ||
| @Singleton | ||
| public class DefaultUpdateCheckManager extends AbstractLogEnabled implements UpdateCheckManager { | ||
| private final TrackingFileManager trackingFileManager; | ||
|
|
||
| private static final String ERROR_KEY_SUFFIX = ".error"; | ||
|
|
||
| public DefaultUpdateCheckManager() {} | ||
| @Inject | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just make/leave this plain old plx component with field injection instead, and as said above, it will leave things less intrusive re UTs |
||
| public DefaultUpdateCheckManager(TrackingFileManager trackingFileManager) { | ||
| this.trackingFileManager = trackingFileManager; | ||
| } | ||
|
|
||
| public DefaultUpdateCheckManager(Logger logger) { | ||
| /** | ||
| * For testing purposes. | ||
| */ | ||
| public DefaultUpdateCheckManager(Logger logger, TrackingFileManager trackingFileManager) { | ||
| enableLogging(logger); | ||
| this.trackingFileManager = trackingFileManager; | ||
| } | ||
|
|
||
| public static final String LAST_UPDATE_TAG = ".lastUpdated"; | ||
|
|
@@ -148,7 +157,7 @@ public void touch(Artifact artifact, ArtifactRepository repository, String error | |
| File touchfile = getTouchfile(artifact); | ||
|
|
||
| if (file.exists()) { | ||
| touchfile.delete(); | ||
| trackingFileManager.delete(touchfile); | ||
| } else { | ||
| writeLastUpdated(touchfile, getRepositoryKey(repository), error); | ||
| } | ||
|
|
@@ -192,70 +201,10 @@ String getRepositoryKey(ArtifactRepository repository) { | |
| } | ||
|
|
||
| private void writeLastUpdated(File touchfile, String key, String error) { | ||
| synchronized (touchfile.getAbsolutePath().intern()) { | ||
| if (!touchfile.getParentFile().exists() | ||
| && !touchfile.getParentFile().mkdirs()) { | ||
| getLogger() | ||
| .debug("Failed to create directory: " + touchfile.getParent() | ||
| + " for tracking artifact metadata resolution."); | ||
| return; | ||
| } | ||
|
|
||
| FileChannel channel = null; | ||
| FileLock lock = null; | ||
| try { | ||
| Properties props = new Properties(); | ||
|
|
||
| channel = new RandomAccessFile(touchfile, "rw").getChannel(); | ||
| lock = channel.lock(); | ||
|
|
||
| if (touchfile.canRead()) { | ||
| getLogger().debug("Reading resolution-state from: " + touchfile); | ||
| props.load(Channels.newInputStream(channel)); | ||
| } | ||
|
|
||
| props.setProperty(key, Long.toString(System.currentTimeMillis())); | ||
|
|
||
| if (error != null) { | ||
| props.setProperty(key + ERROR_KEY_SUFFIX, error); | ||
| } else { | ||
| props.remove(key + ERROR_KEY_SUFFIX); | ||
| } | ||
|
|
||
| getLogger().debug("Writing resolution-state to: " + touchfile); | ||
| channel.truncate(0); | ||
| props.store(Channels.newOutputStream(channel), "Last modified on: " + new Date()); | ||
|
|
||
| lock.release(); | ||
| lock = null; | ||
|
|
||
| channel.close(); | ||
| channel = null; | ||
| } catch (IOException e) { | ||
| getLogger() | ||
| .debug( | ||
| "Failed to record lastUpdated information for resolution.\nFile: " | ||
| + touchfile.toString() + "; key: " + key, | ||
| e); | ||
| } finally { | ||
| if (lock != null) { | ||
| try { | ||
| lock.release(); | ||
| } catch (IOException e) { | ||
| getLogger() | ||
| .debug("Error releasing exclusive lock for resolution tracking file: " + touchfile, e); | ||
| } | ||
| } | ||
|
|
||
| if (channel != null) { | ||
| try { | ||
| channel.close(); | ||
| } catch (IOException e) { | ||
| getLogger().debug("Error closing FileChannel for resolution tracking file: " + touchfile, e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| HashMap<String, String> update = new HashMap<>(); | ||
| update.put(key, Long.toString(System.currentTimeMillis())); | ||
| update.put(key + ERROR_KEY_SUFFIX, error); // error==null => remove mapping | ||
| trackingFileManager.update(touchfile, update); | ||
| } | ||
|
|
||
| Date readLastUpdated(File touchfile, String key) { | ||
|
|
@@ -284,53 +233,7 @@ private String getError(File touchFile, String key) { | |
| } | ||
|
|
||
| private Properties read(File touchfile) { | ||
| if (!touchfile.canRead()) { | ||
| getLogger().debug("Skipped unreadable resolution tracking file " + touchfile); | ||
| return null; | ||
| } | ||
|
|
||
| synchronized (touchfile.getAbsolutePath().intern()) { | ||
| FileInputStream in = null; | ||
| FileLock lock = null; | ||
|
|
||
| try { | ||
| Properties props = new Properties(); | ||
|
|
||
| in = new FileInputStream(touchfile); | ||
| lock = in.getChannel().lock(0, Long.MAX_VALUE, true); | ||
|
|
||
| getLogger().debug("Reading resolution-state from: " + touchfile); | ||
| props.load(in); | ||
|
|
||
| lock.release(); | ||
| lock = null; | ||
|
|
||
| in.close(); | ||
| in = null; | ||
|
|
||
| return props; | ||
| } catch (IOException e) { | ||
| getLogger().debug("Failed to read resolution tracking file " + touchfile, e); | ||
|
|
||
| return null; | ||
| } finally { | ||
| if (lock != null) { | ||
| try { | ||
| lock.release(); | ||
| } catch (IOException e) { | ||
| getLogger().debug("Error releasing shared lock for resolution tracking file: " + touchfile, e); | ||
| } | ||
| } | ||
|
|
||
| if (in != null) { | ||
| try { | ||
| in.close(); | ||
| } catch (IOException e) { | ||
| getLogger().debug("Error closing FileChannel for resolution tracking file: " + touchfile, e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return trackingFileManager.read(touchfile); | ||
| } | ||
|
|
||
| File getTouchfile(Artifact artifact) { | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure would I migrate this from plx to sisu; moreover, undoing this change will make other UT changes unneeded (index scanning)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I afraid that I need add scaning to UT as implementation of
TrackingFileManageris sisiu