Ejemplo n.º 1
0
        private void ResyncArtifactsImpl(
            NPanday.Logging.Logger logger,
            ArtifactResyncSource artifactResyncSource)
        {
            EnsureInitialized();

            GetReferencesFromPom(logger, artifactResyncSource);
        }
Ejemplo n.º 2
0
        static bool downloadArtifact(Artifact.Artifact artifact, NPanday.Logging.Logger logger)
        {
            WebClient client     = new WebClient();
            bool      dirCreated = false;

            try
            {
                if (!artifact.FileInfo.Directory.Exists)
                {
                    artifact.FileInfo.Directory.Create();
                    dirCreated = true;
                }


                logger.Log(NPanday.Logging.Level.INFO, string.Format("Download Start: {0} Downloading From {1}\n", DateTime.Now, artifact.RemotePath));

                client.DownloadFile(artifact.RemotePath, artifact.FileInfo.FullName);

                logger.Log(NPanday.Logging.Level.INFO, string.Format("Download Finished: {0}\n", DateTime.Now));

                string artifactDir = GetLocalUacPath(artifact, artifact.FileInfo.Extension);

                if (!Directory.Exists(Path.GetDirectoryName(artifactDir)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(artifactDir));
                }
                if (!File.Exists(artifactDir))
                {
                    File.Copy(artifact.FileInfo.FullName, artifactDir);
                }

                return(true);
            }

            catch (Exception e)
            {
                if (dirCreated)
                {
                    artifact.FileInfo.Directory.Delete();
                }

                logger.Log(NPanday.Logging.Level.WARNING, string.Format("Download Failed {0}\n", e.Message));

                return(false);
            }

            finally
            {
                client.Dispose();
            }
        }
Ejemplo n.º 3
0
        void GetReferencesFromPom(NPanday.Logging.Logger logger, ArtifactResyncSource artifactResyncSource)
        {
            Artifact.ArtifactRepository repository = new NPanday.Artifact.ArtifactContext().GetArtifactRepository();
            NPanday.Model.Pom.Model     m          = NPanday.Utils.PomHelperUtility.ReadPomAsModel(new FileInfo(pomFile));

            if (m.dependencies != null)
            {
                foreach (Dependency d in m.dependencies)
                {
                    // check if intra-project reference and copy artifacts
                    if (!IsIntraProject(m, d) && d.classifier == null)
                    {
                        Artifact.Artifact artifact = repository.GetArtifact(d);
                        CopyArtifactImpl(artifact, logger, artifactResyncSource);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 public void ResyncArtifactsFromLocalRepository(NPanday.Logging.Logger logger)
 {
     ResyncArtifactsImpl(logger, ArtifactResyncSource.LocalRepository);
 }
Ejemplo n.º 6
0
 public void ResyncArtifacts(NPanday.Logging.Logger logger)
 {
     ResyncArtifactsImpl(logger, ArtifactResyncSource.RemoteRepository);
 }
Ejemplo n.º 7
0
 public void CopyArtifact(Artifact.Artifact artifact, NPanday.Logging.Logger logger)
 {
     CopyArtifactImpl(artifact, logger, ArtifactResyncSource.RemoteRepository);
 }
Ejemplo n.º 8
0
 public static bool DownloadFromRemoteRepository(Artifact.Artifact artifact, NPanday.Logging.Logger logger)
 {
     return(NPanday.ProjectImporter.Digest.Model.Reference.DownloadArtifact(artifact, logger));
 }
Ejemplo n.º 9
0
        private static string GetSnapshotVersion(NPanday.Artifact.Artifact artifact, string repo, NPanday.Logging.Logger logger)
        {
            WebClient client           = new WebClient();
            string    timeStampVersion = null;
            string    metadataPath     = repo + "/" + artifact.GroupId.Replace('.', '/') + "/" + artifact.ArtifactId;
            string    snapshot         = "<snapshot>";
            string    metadata         = "/maven-metadata.xml";

            try
            {
                metadataPath = metadataPath + "/" + artifact.Version + metadata;

                string   content = client.DownloadString(metadataPath);
                string[] lines   = content.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

                string timeStamp   = null;
                string buildNumber = null;

                foreach (string line in lines)
                {
                    int startIndex;
                    int len;

                    if (line.Contains("<timestamp>"))
                    {
                        startIndex = line.IndexOf("<timestamp>") + "<timestamp>".Length;
                        len        = line.IndexOf("</timestamp>") - startIndex;

                        timeStamp = line.Substring(startIndex, len);
                    }

                    if (line.Contains("<buildNumber>"))
                    {
                        startIndex = line.IndexOf("<buildNumber>") + "<buildNumber>".Length;
                        len        = line.IndexOf("</buildNumber>") - startIndex;

                        buildNumber = line.Substring(startIndex, len);
                    }
                }

                if (timeStamp == null)
                {
                    logger.Log(NPanday.Logging.Level.WARNING, "Timestamp was not specified in maven-metadata.xml - using default snapshot version");
                    return(null);
                }

                if (buildNumber == null)
                {
                    logger.Log(NPanday.Logging.Level.WARNING, "Build number was not specified in maven-metadata.xml - using default snapshot version");
                    return(null);
                }

                logger.Log(NPanday.Logging.Level.INFO, "Resolved SNAPSHOT: Timestamp = " + timeStamp + "; Build Number = " + buildNumber);
                timeStampVersion = timeStamp + "-" + buildNumber;
            }
            catch (Exception e)
            {
                return(null);
            }
            finally
            {
                client.Dispose();
            }

            return(timeStampVersion);
        }
Ejemplo n.º 10
0
        // TODO: belongs in another utility classs
        public static bool downloadArtifactFromRemoteRepository(Artifact.Artifact artifact, string ext, NPanday.Logging.Logger logger)
        {
            try
            {
                Dictionary <string, string> repos = SettingsUtil.GetSettingsRepositories();
                foreach (string id in repos.Keys)
                {
                    string url = repos[id];

                    ArtifactContext artifactContext = new ArtifactContext();

                    if (artifact.Version.Contains("SNAPSHOT"))
                    {
                        string newVersion = GetSnapshotVersion(artifact, url, logger);

                        if (newVersion != null)
                        {
                            artifact.RemotePath = artifactContext.GetArtifactRepository().GetRemoteRepositoryPath(artifact, artifact.Version.Replace("SNAPSHOT", newVersion), url, ext);
                        }

                        else
                        {
                            artifact.RemotePath = artifactContext.GetArtifactRepository().GetRemoteRepositoryPath(artifact, url, ext);
                        }
                    }
                    else
                    {
                        artifact.RemotePath = artifactContext.GetArtifactRepository().GetRemoteRepositoryPath(artifact, url, ext);
                    }

                    if (downloadArtifact(artifact, logger))
                    {
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception e)
            {
                MessageBox.Show("Cannot add reference of " + artifact.ArtifactId + ", an exception occurred trying to download it: " + e.Message);
                return(false);
            }
        }
Ejemplo n.º 11
0
 public static bool DownloadArtifact(Artifact.Artifact artifact, NPanday.Logging.Logger logger)
 {
     return(downloadArtifactFromRemoteRepository(artifact, artifact.FileInfo.Extension, logger));
 }