[ 
https://issues.apache.org/jira/browse/NPANDAY-322?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13143094#comment-13143094
 ] 

Stoyan Damov edited comment on NPANDAY-322 at 11/3/11 1:11 PM:
---------------------------------------------------------------

h3. NPANDAY-322 fix

h4. Added {{ArtifactUtils}} helper class with the following methods:

{code}
bool IsSnapshot(Artifact.Artifact artifact)
{code}

Checks whether the artifact is a snapshot one, implementation checks whether 
artifact's version ends on {{-SNAPSHOT}}.

{code}
bool Exists(Artifact.Artifact artifact)
{code}

Checks whether the artifact exists in the local repository (impl. in terms of 
{{artifact.FileInfo.Exists}})

{code}
bool DownloadFromRemoteRepository(Artifact.Artifact artifact, 
NPanday.Logging.Logger logger)
{code}

Downloads the artifact from the remote repository. Same as 
{{NPanday.ProjectImporter.Digest.Model.Reference.DownloadArtifact(artifact, 
logger)}}.

{code}
string GetArtifactReferenceFolder(Artifact.Artifact artifact, string 
referenceFolder)
{code}

Returns the reference folder for the artifact, modified to match the .dll 
searched in {{NPanday.ProjectImporter.Digest.Model.Reference.cs}}. The format 
is {{referenceFolder\groupId\artifactId-version}}, e.g. 
{{SomeFolder\.references\com.company.something\artifact-1.0-SNAPSHOT}}

{code}
string GetArtifactReferenceFilePath(Artifact.Artifact artifact, string 
referenceFolder)
{code}

Returns path to the artifact's file in the local reference folder in the format 
{{GetArtifactReferenceFolder()\artifactId.extension}}, e.g. 
{{SomeFolder\.references\com.company.something\artifact-1.0-SNAPSHOT\artifact.dll}}.

{code}
DateTime GetArtifactTimestamp(Artifact.Artifact artifact)
{code}

Returs the artifact's timestamp in the local repository. Attempts to get the 
timestamp off {{maven-metadata-repoId.xml}} or {{maven-metadata-local.xml}}, 
falls back to file's {{LastWriteStampUtc}}.

{code}
bool IsEarlierArtifactTimestamp(DateTime value, DateTime comparand)
{code}

Compares two timestamps disregarding the milliseconds (timestamps in 
{{maven-metadata-*.xml}} do not have milliseconds).

{note}I should have added the above documentation in the class. Let me know if 
I should do it and then re-attach the diff.{note}

h4. The fix explained:

{{CopyArtifactImpl}} which is now called by the original {{CopyArtifact}} looks 
like this:

{code}
private void CopyArtifactImpl(
    Artifact.Artifact artifact, 
    NPanday.Logging.Logger logger, 
    ArtifactResyncSource artifactResyncSource)
{
    EnsureInitialized();

    bool isSnapshot = ArtifactUtils.IsSnapshot(artifact);
    bool resyncFromRemoteRepo = artifactResyncSource == 
ArtifactResyncSource.RemoteRepository;

    if (!ArtifactUtils.Exists(artifact) || (isSnapshot && resyncFromRemoteRepo))
    {
        if (!ArtifactUtils.DownloadFromRemoteRepository(artifact, logger))
        {
            RaiseError("Unable to get the artifact {0} from any of your 
repositories.", artifact.ArtifactId);
            return;
        }
    }

    CopyToReferenceFolder(artifact, referenceFolder);
}
{code}

The code above works towards implementing NPANDAY-476 (resync from local repo 
only) and then calls into {{CopyToReferenceFolder}} which now looks quite a bit 
different after the fix:

{code}
static string CopyToReferenceFolder(Artifact.Artifact artifact, string 
referenceFolder)
{
    string artifactReferenceFilePath = 
ArtifactUtils.GetArtifactReferenceFilePath(artifact, referenceFolder);

    bool overwriteReferenceFile;
    DateTime localRepoArtifactTimestamp = 
ArtifactUtils.GetArtifactTimestamp(artifact);
    if (File.Exists(artifactReferenceFilePath))
    {
        DateTime referenceFileTimestamp = new 
FileInfo(artifactReferenceFilePath).LastWriteTimeUtc;
        overwriteReferenceFile = ArtifactUtils.IsEarlierArtifactTimestamp(
            referenceFileTimestamp, 
            localRepoArtifactTimestamp);
    }
    else
    {
        overwriteReferenceFile = true;
    }

    if (overwriteReferenceFile)
    {
        File.Copy(artifact.FileInfo.FullName, artifactReferenceFilePath, true);
        // set the timestamp of the local repo's artifact
        new FileInfo(artifactReferenceFilePath).LastWriteTimeUtc = 
localRepoArtifactTimestamp;
    }

    return artifactReferenceFilePath;
}
{code}

The {{ArtifactUtils}} calls are explained at the top of this comment.


h3. Implemented NPANDAY-476

I know it's wrong to put that in this ticket, but this is a placeholder until I 
get myself to update the other ticket.

In {{Connect.cs}} refactored a bit so that methods dealing with resync 
solution/project references have appropriate names.
Extracted the resync logic into implementation methods and refactored button 
click event handlers to call these.
In the implementation methods added a boolean flag whether to resync from the 
remote or local repositories and then just delegated to the appropriate 
{{ReferenceManager.ResyncXxx}} call.

In {{ReferenceManager.cs}}'s {{IReferenceManager}} added 
{{ResyncArtifactsFromLocalRepository}} method.

Refactored {{ResyncArtifacts}} and {{ResyncArtifactsFromLocalRepository}} to 
call an implementation method, passing whether the resync should be done from 
the remote or local repository.

                
      was (Author: stoyan):
    h3. NPANDAY-322 fix

h4. Added {{ArtifactUtils}} helper class with the following methods:

{code}
bool IsSnapshot(Artifact.Artifact artifact)
{code}

Checks whether the artifact is a snapshot one, implementation checks whether 
artifact's version ends on {{-SNAPSHOT}}.

{code}
bool Exists(Artifact.Artifact artifact)
{code}

Checks whether the artifact exists in the local repository (impl. in terms of 
{{artifact.FileInfo.Exists}})

{code}
bool DownloadFromRemoteRepository(Artifact.Artifact artifact, 
NPanday.Logging.Logger logger)
{code}

Downloads the artifact from the remote repository. Same as 
{{NPanday.ProjectImporter.Digest.Model.Reference.DownloadArtifact(artifact, 
logger)}}.

{code}
string GetArtifactReferenceFolder(Artifact.Artifact artifact, string 
referenceFolder)
{code}

Returns the reference folder for the artifact, modified to match the .dll 
searched in {{NPanday.ProjectImporter.Digest.Model.Reference.cs}}. The format 
is {{referenceFolder\groupId\artifactId-version}}, e.g. 
{{SomeFolder\.references\com.company.something\artifact-1.0-SNAPSHOT}}

{code}
string GetArtifactReferenceFilePath(Artifact.Artifact artifact, string 
referenceFolder)
{code}

Returns path to the artifact's file in the local reference folder in the format 
{{GetArtifactReferenceFolder()\artifactId.extension}}, e.g. 
{{SomeFolder\.references\com.company.something\artifact-1.0-SNAPSHOT\artifact.dll}}.

{code}
DateTime GetArtifactTimestamp(Artifact.Artifact artifact)
{code}

Returs the artifact's timestamp in the local repository. Attempts to get the 
timestamp off {{maven-metadata-repoId.xml}} or {{maven-metadata-local.xml}}, 
falls back to file's {{LastWriteStampUtc}}.

{code}
bool IsEarlierArtifactTimestamp(DateTime value, DateTime comparand)
{code}

Compares two timestamps disregarding the milliseconds (timestamps in 
{{maven-metadata-*.xml}} do not have milliseconds).

{note}I should have added the above documentation in the class. Let me know if 
I should do it and then re-attach the diff.{note}

h4. *TODO:* Describe the fix.


h3. Implemented NPANDAY-476

I know it's wrong to put that in this ticket, but this is a placeholder until I 
get myself to update the other ticket.

In {{Connect.cs}} refactored a bit so that methods dealing with resync 
solution/project references have appropriate names.
Extracted the resync logic into implementation methods and refactored button 
click event handlers to call these.
In the implementation methods added a boolean flag whether to resync from the 
remote or local repositories and then just delegated to the appropriate 
{{ReferenceManager.ResyncXxx}} call.

In {{ReferenceManager.cs}}'s {{IReferenceManager}} added 
{{ResyncArtifactsFromLocalRepository}} method.

Refactored {{ResyncArtifacts}} and {{ResyncArtifactsFromLocalRepository}} to 
call an implementation method, passing whether the resync should be done from 
the remote or local repository.

                  
> Resync Reference doesn't update SNAPSHOT artifact from local repository that 
> already exist in .references folder
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: NPANDAY-322
>                 URL: https://issues.apache.org/jira/browse/NPANDAY-322
>             Project: NPanday
>          Issue Type: Bug
>          Components: Visual Studio Add-in
>    Affects Versions: 1.4-incubating
>            Reporter: Dmitry L
>            Assignee: Lars Corneliussen
>            Priority: Minor
>             Fix For: 1.2.1, 1.4.1-incubating
>
>         Attachments: ArtifactUtils.cs, Connect.cs, 
> NPANDAY-322_and_NPANDAY-476.diff, ReferenceManager.cs
>
>
> Steps:
> 1. Install Library1 into local maven repo
> 2. Add Library1 as dependency using Resync Reference to ProjectA (it will be 
> copied into .references folder)
> 3. Update and reinstall Library1 into local maven repo
> 4. Invoke Resync Reference for ProjectA
> 5. Error: Library1 won't be updated in .references folder
> Expected: newer version (in terms of file timestamp) of Library1 (if any) 
> should be copied into .references folder from local maven repo during Resync 
> Reference
> Issue exist in trunk r59731

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to