Esempio n. 1
0
        private void addReferenceToProject(ref NPanday.Artifact.Artifact artifact, string text)
        {
            if (project.Object is VSProject)
            {
                IReferenceManager refMgr = new ReferenceManager();
                refMgr.Initialize((VSLangProj80.VSProject2)project.Object);
                artifact = refMgr.Add(new ReferenceInfo(artifact));

                if (!addVSProjectReference(artifact, text))
                {
                    return;
                }
            }
            else if (Connect.IsWebSite(project))
            {
                if (!addVSWebProjectReference(artifact, text))
                {
                    return;
                }
            }
            else
            {
                MessageBox.Show(this, "Cannot add artifact to none VS projects.", this.Text);
                return;
            }
        }
Esempio n. 2
0
 public Artifact CreateArtifact(String groupId, String artifactId, String version, String packaging)
 {
     Artifact artifact = new Artifact();
     artifact.ArtifactId = artifactId;
     artifact.GroupId = groupId;
     artifact.Version = version;
     artifact.Extension = GetExtensionFor(packaging);
     return artifact;
 }
Esempio n. 3
0
 public Artifact GetArtifact(NPanday.Model.Pom.Dependency dependency)
 {
     Artifact artifact = new Artifact();
     artifact.ArtifactId = dependency.artifactId;
     artifact.GroupId = dependency.groupId;
     artifact.Version = dependency.version;
     artifact.FileInfo = new FileInfo(GetLocalRepositoryPath(artifact, ".dll"));
     return artifact;
 }
Esempio n. 4
0
 public string pathOf(Artifact artifact)
 {
     StringBuilder sb = new StringBuilder();
     sb.Append(artifact.GroupId.Replace('.', '\\')).Append(@"\");
     sb.Append(artifact.ArtifactId).Append(@"\");
     sb.Append(artifact.Version).Append(@"\");
     sb.Append(artifact.ArtifactId).Append("-").Append(artifact.Version).Append(".").Append(artifact.Extension);
     return sb.ToString();
 }
Esempio n. 5
0
 public Artifact GetArtifactFor(NPanday.Model.Pom.Model model)
 {
     Artifact artifact = new Artifact();
     artifact.ArtifactId = model.artifactId;
     artifact.GroupId = model.groupId;
     artifact.Version = model.version;
     artifact.Extension = GetExtensionFor(model.packaging);
     return artifact;
 }
Esempio n. 6
0
        public static FileInfo GetPrivateApplicationBaseFileFor(Artifact artifact, DirectoryInfo localRepository, string currentDir)
        {
            FileInfo target = new FileInfo(currentDir + Path.PathSeparator + "target" + Path.PathSeparator+artifact.ArtifactId + artifact.Extension);

            FileInfo source = GetUserAssemblyCacheFileFor(artifact, localRepository);

            if(source.Exists)
            {
                   File.Copy( source.ToString(), target.ToString());
            }

            return target;
        }
Esempio n. 7
0
        public Artifact GetArtifact(DirectoryInfo uacDirectory, FileInfo artifactFile)
        {
            string[] tokens;
            try
            {
                tokens = PathUtil.GetRelativePathTokens(uacDirectory, artifactFile);
            }
            catch
            {
                List<string> tk = new List<string>(artifactFile.FullName.Split(@"\".ToCharArray()));
                tk.RemoveRange(0, tk.Count - 3);
                tokens = tk.ToArray();
            }

            //artifact for system path
            if (!artifactFile.FullName.Contains(".m2"))
            {
                return null;
            }

            string fileName = tokens[tokens.Length - 1];
            int index = fileName.LastIndexOf(".");

            string ext = fileName.Substring(index);
            string version = tokens[tokens.Length - 2];
            string artifactId = tokens[tokens.Length - 3];

            StringBuilder group = new StringBuilder();

            for (int i = 0; i < tokens.Length - 3; i++)
            {
                group.Append(tokens[i]).Append(".");
            }

            string groupId = group.ToString(0, group.Length - 1);

            Artifact artifact = new Artifact();
            artifact.ArtifactId = artifactId;
            artifact.Version = version;
            artifact.GroupId = groupId;
            artifact.FileInfo = new FileInfo(GetLocalRepositoryPath(artifact, ext));

            return artifact;
        }
Esempio n. 8
0
 public string GetRemoteRepositoryPath(Artifact artifact, string timeStampVersion, string url, string ext)
 {
     return string.Format("{0}/{1}/{2}/{3}/{2}-{4}{5}", url, artifact.GroupId.Replace('.', '/'), artifact.ArtifactId, artifact.Version, timeStampVersion, ext);
 }
Esempio n. 9
0
        // TODO: belongs in another utility classs
        public static bool downloadArtifactFromRemoteRepository(Artifact.Artifact artifact, string ext)
        {
            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);

                        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))
                    {
                        return true;
                    }
                }
                return false;
            }
            catch (Exception e)
            {
                log.Error("Cannot add reference of " + artifact.ArtifactId + ", an exception occurred trying to download it: " + e.Message);
                return false;
            }
        }
Esempio n. 10
0
 public string GetRemoteRepositoryPath(Artifact artifact, string timeStampVersion, string url, string ext)
 {
     return(string.Format("{0}/{1}/{2}/{3}/{2}-{4}{5}", url, artifact.GroupId.Replace('.', '/'), artifact.ArtifactId, artifact.Version, timeStampVersion, ext));
 }
Esempio n. 11
0
 public string GetLocalRepositoryPath(Artifact artifact, string ext)
 {
     return(string.Format(@"{0}\{1}\{2}\{3}\{2}-{3}{4}", localRepository.FullName, artifact.GroupId.Replace(@".", @"\"), artifact.ArtifactId, artifact.Version, ext));
 }
Esempio n. 12
0
 public static FileInfo GetUserAssemblyCacheFileFor(Artifact artifact, DirectoryInfo localRepository)
 {
     return new FileInfo( Path.Combine(localRepository.ToString(), string.Format(@"{0}\{1}\{2}\{1}-{2}.{3}", Tokenize(artifact.GroupId), artifact.ArtifactId, artifact.Version, artifact.Extension)));
 }
Esempio n. 13
0
        static bool downloadArtifact(Artifact.Artifact artifact)
        {
            WebClient client = new WebClient();
            bool dirCreated = false;

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

                log.InfoFormat("Download Start: {0} Downloading From {1}", DateTime.Now, artifact.RemotePath);

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

                log.InfoFormat("Download Finished: {0}", 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();
                }

                log.WarnFormat("Download Failed {0}", e.Message);

                return false;
            }

            finally
            {
                client.Dispose();
            }
        }
Esempio n. 14
0
 public static string GetLocalUacPath(Artifact.Artifact artifact, string ext)
 {
     return Path.Combine(SettingsUtil.GetLocalRepositoryPath(), string.Format(@"{0}\{1}\{1}{2}-{3}", Tokenize(artifact.GroupId), artifact.ArtifactId, artifact.Version, ext));
 }
Esempio n. 15
0
 public static FileInfo GetUserAssemblyCacheFileFor(Artifact artifact, DirectoryInfo localRepository)
 {
     return(new FileInfo(Path.Combine(localRepository.ToString(), string.Format(@"{0}\{1}\{2}\{1}-{2}.{3}", Tokenize(artifact.GroupId), artifact.ArtifactId, artifact.Version, artifact.Extension))));
 }
Esempio n. 16
0
 void addLocalArtifact(LocalArtifactItem item)
 {
     NPanday.Artifact.Artifact artifact = item.Artifact;
     addReferenceToProject(ref artifact, item.Text);
 }
Esempio n. 17
0
        public Artifact GetArtifactFor(String uri)
        {
            Artifact artifact = new Artifact();

            String[] tokens = uri.Split("/".ToCharArray(), Int32.MaxValue, StringSplitOptions.RemoveEmptyEntries);
            int size = tokens.Length;
            if (size < 3)
            {
                System.Reflection.Assembly a = System.Reflection.Assembly.LoadFile(uri);
                string[] info = a.FullName.Split(",".ToCharArray(), Int32.MaxValue, StringSplitOptions.RemoveEmptyEntries);
                artifact.ArtifactId = info[0];
                artifact.GroupId = info[0];
                artifact.Version = info[1].Split(new char[] { '=' })[1];
                artifact.Extension = tokens[0].Split(new char[] { '.' })[1];

                if (artifact.Version == null)
                {
                    artifact.Version = "1.0.0.0";
                }
            }

            else
            {
                artifact.ArtifactId = tokens[size - 3];
                StringBuilder buffer = new StringBuilder();
                for (int i = 0; i < size - 3; i++)
                {
                    buffer.Append(tokens[i]);
                    if (i != size - 4)
                    {
                        buffer.Append(".");
                    }
                }
                artifact.GroupId = buffer.ToString();
                artifact.Version = tokens[size - 2];
                String[] extToken = tokens[size - 1].Split(".".ToCharArray());
                artifact.Extension = extToken[extToken.Length - 1];
            }
            artifact.FileInfo = new FileInfo(localRepository.FullName + Path.DirectorySeparatorChar + Tokenize(artifact.GroupId) + Path.DirectorySeparatorChar + artifact.ArtifactId + Path.DirectorySeparatorChar
                + artifact.Version + Path.DirectorySeparatorChar + artifact.ArtifactId + "-" + artifact.Version + ".dll");
            return artifact;
        }
Esempio n. 18
0
        void addRemoteArtifact(RemoteArtifactNode node)
        {
            string uri = node.ArtifactUrl;
            string paths;
            string repoUrl = selectedRepoUrl;

            if (node.IsFileSystem)
            {
                //Uri repoUri = new Uri(repoUrl);
                //paths = uri.Substring(repoUri.LocalPath.Length).Replace(@"\",@"/");
                paths = uri;
            }
            else
            {
                paths = normalizePath(uri.Substring(repoUrl.Length));
            }

            NPanday.Artifact.Artifact artifact =
                artifactContext.GetArtifactRepository().GetArtifactFor(paths);

            //Download
            artifact.FileInfo.Directory.Create();
            if (node.IsFileSystem)
            {
                if (!File.Exists(artifact.FileInfo.FullName))
                {
                    File.Copy(node.ArtifactUrl, artifact.FileInfo.FullName);
                }
            }
            else
            {
                if (!File.Exists(artifact.FileInfo.FullName))
                {
                    byte[]     assembly = webClient.DownloadData(uri);
                    FileStream stream   = new FileStream(artifact.FileInfo.FullName, FileMode.Create);
                    stream.Write(assembly, 0, assembly.Length);
                    stream.Flush();
                    stream.Close();
                    stream.Dispose();
                    webClient.Dispose();
                }
                //make sure that file is properly closed before adding it to the reference
                System.Threading.Thread.Sleep(1000);
            }

            addReferenceToProject(ref artifact, artifact.ArtifactId);

            //if (project.Object is VSProject)
            //{
            //    if (!addVSProjectReference(artifact, artifact.ArtifactId))
            //        return;
            //}
            //else if (Connect.IsWebProject(project))
            //{
            //    if (!addVSWebProjectReference(artifact, artifact.ArtifactId))
            //        return;
            //}
            //else
            //{
            //    MessageBox.Show(this, "Cannot add artifact to none VS projects.", this.Text);
            //    return;
            //}
        }
Esempio n. 19
0
 public string GetLocalRepositoryPath(Artifact artifact, string ext)
 {
     return string.Format(@"{0}\{1}\{2}\{3}\{2}-{3}{4}", localRepository.FullName, artifact.GroupId.Replace(@".", @"\"), artifact.ArtifactId, artifact.Version, ext);
 }
Esempio n. 20
0
        private static string GetSnapshotVersion(NPanday.Artifact.Artifact artifact, string repo)
        {
            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)
                {
                    log.Warn("Timestamp was not specified in maven-metadata.xml - using default snapshot version");
                    return(null);
                }

                if (buildNumber == null)
                {
                    log.Warn("Build number was not specified in maven-metadata.xml - using default snapshot version");
                    return(null);
                }

                log.Info("Resolved SNAPSHOT: Timestamp = " + timeStamp + "; Build Number = " + buildNumber);
                timeStampVersion = timeStamp + "-" + buildNumber;
            }
            catch (Exception e)
            {
                return(null);
            }
            finally
            {
                client.Dispose();
            }

            return(timeStampVersion);
        }
Esempio n. 21
0
 public static bool DownloadArtifact(Artifact.Artifact artifact)
 {
     return downloadArtifactFromRemoteRepository(artifact, artifact.FileInfo.Extension);
 }