protected Artifact.Artifact GetArtifact(Reference reference) { //if (string.IsNullOrEmpty(reference.Name) || string.IsNullOrEmpty(reference.Version)) //{ // return null; //} //if (localArtifacts == null) //{ // return null; //} try { Artifact.Artifact artifact = GetArtifactFromRepoUsingEmbeddedAssemblyVersionNumber(reference); if (artifact == null) { artifact = GetArtifactFromRepoUsingHintPathVersionNumber(reference); } if (artifact == null) { artifact = artifactContext.GetArtifactRepository().GetArtifact(new FileInfo(reference.HintPath)); } return(artifact); } catch { return(null); } }
public ReferenceInfo(Artifact.Artifact artifact) { path = artifact.FileInfo.FullName; fileName = artifact.FileInfo.Name; version = artifact.Version; this.artifact = artifact; }
bool addVSProjectReference(Artifact.Artifact artifact, string name) { VSProject vsProject = (VSProject)project.Object; if (vsProject.References.Find(name) != null) { MessageBox.Show(this, "A version of artifact is already added to the project, please remove it first before adding this version.", this.Text); return(false); } try { Assembly a = Assembly.LoadFile(artifact.FileInfo.FullName); //if (a.ToString().Split(",".ToCharArray())[0].ToLower().StartsWith("interop.")) //{ // MessageBox.Show("Cannot add COM Interop reference from a Maven Artifact, just use Add Reference if you wish to add a COM reference.", "Add Maven Artifact", MessageBoxButtons.OK, MessageBoxIcon.Information); // return false; //} addArtifactToPom(artifact); vsProject.References.Add(artifact.FileInfo.FullName); return(true); } catch { MessageBox.Show("Cannot add COM reference from a Maven Artifact.", "Add Maven Artifact", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } }
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); }
protected Artifact.Artifact createArtifact(string name, string version) { Artifact.Artifact artifact = new Artifact.Artifact(); artifact.GroupId = name; artifact.ArtifactId = name; artifact.Version = version; artifact.Extension = "dll"; return(artifact); }
public Artifact.Artifact Add(IReferenceInfo reference) { EnsureInitialized(); string artifactFileName = CopyToReferenceFolder(reference.Artifact, referenceFolder); Artifact.Artifact a = reference.Artifact; a.FileInfo = new FileInfo(artifactFileName); return(a); }
public static string GetArtifactReferenceFilePath(Artifact.Artifact artifact, string referenceFolder) { string artifactReferenceFolder = GetArtifactReferenceFolder(artifact, referenceFolder); Directory.CreateDirectory(artifactReferenceFolder); string artifactReferenceFilePath = Path.Combine(artifactReferenceFolder, String.Concat(artifact.ArtifactId, artifact.FileInfo.Extension)); return(artifactReferenceFilePath); }
public static string GetArtifactReferenceFolder(Artifact.Artifact artifact, string referenceFolder) { //modified artifactFolder to match the .dll searched in NPanday.ProjectImporter.Digest.Model.Reference.cs string artifactFolder = Path.Combine( referenceFolder, string.Format("{0}\\{1}-{2}", artifact.GroupId, artifact.ArtifactId, artifact.Version)); return(artifactFolder); }
public void artifactSetUp() { ReferenceManager refMngr = new ReferenceManager(); Artifact.Artifact artifact = new Artifact.Artifact(); artifact.GroupId = "npanday.artifact"; artifact.Version = "1.1-SNAPSHOT"; artifact.ArtifactId = "NPanday.Artifact"; artifact.Extension = "dll"; refMngr.CopyArtifact(artifact); }
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(); } }
public void TestSetUp() { FileUtils.CopyDirectory(testProject, testProjectCopy); FileUtils.CopyDirectory(repo, repoCopy); refManager = new ReferenceManager(); refManager.ReferenceFolder = testProjectCopy.FullName + "\\TestProject\\.references"; testArtifact = new Artifact.Artifact(); testArtifact.GroupId = "npanday.test"; testArtifact.ArtifactId = "NPanday.Test"; testArtifact.Version = "1.0"; testArtifact.Extension = "dll"; }
void addArtifactToPom(Artifact.Artifact artifact) { try { if (pom != null) { PomHelperUtility pomUtil = new PomHelperUtility(pom); pomUtil.AddPomDependency(artifact.GroupId, artifact.ArtifactId, artifact.Version); } } catch (Exception err) { MessageBox.Show(this, err.Message, "NPanday Add Dependency Warning:", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }
public static DateTime GetArtifactTimestamp(Artifact.Artifact artifact) { // try maven-metadata-${repoId}.xml or maven-metadata-local.xml string localRepoArtifactFolder = artifact.FileInfo.Directory.FullName; string[] metadataFilePaths = Directory.GetFiles(localRepoArtifactFolder, "maven-metadata-*.xml"); DateTime metadataTimestamp; if (!TryGetArtifactTimestampFromMetadataFiles(metadataFilePaths, out metadataTimestamp)) { // if that fails, get the file's timestamp) metadataTimestamp = new FileInfo(artifact.FileInfo.FullName).LastWriteTimeUtc; } return(metadataTimestamp); }
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); } } } }
// 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); } }
private void CopyArtifactImpl( Artifact.Artifact artifact, ArtifactResyncSource artifactResyncSource) { EnsureInitialized(); bool isSnapshot = ArtifactUtils.IsSnapshot(artifact); bool resyncFromRemoteRepo = artifactResyncSource == ArtifactResyncSource.RemoteRepository; if (!ArtifactUtils.Exists(artifact) || (isSnapshot && resyncFromRemoteRepo)) { if (!ArtifactUtils.DownloadFromRemoteRepository(artifact)) { RaiseError("Unable to get the artifact {0} from any of your repositories.", artifact.ArtifactId); return; } } CopyToReferenceFolder(artifact, referenceFolder); }
bool addVSWebProjectReference(Artifact.Artifact artifact, string name) { try { VsWebSite.VSWebSite website = (VsWebSite.VSWebSite)project.Object; Assembly a = Assembly.LoadFile(artifact.FileInfo.FullName); if (a.ToString().Split(",".ToCharArray())[0].ToLower().StartsWith("interop.", true, CultureInfo.InvariantCulture)) { MessageBox.Show("Cannot add COM Interop reference from a Maven Artifact, just use Add Reference if you wish to add a COM reference.", "Add Maven Artifact", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } bool referenced = false; try { referenced = (website.References.Item(name) != null); } catch { referenced = false; } if (referenced) { MessageBox.Show(this, "A version of artifact is already added to the project, please remove it first before adding this version.", this.Text); return(false); } // not need to written in pom anymore //addArtifactToPom(artifact); website.References.AddFromFile(artifact.FileInfo.FullName); return(true); } catch { MessageBox.Show("Cannot add COM reference from a Maven Artifact.", "Add Maven Artifact", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } }
public static bool Exists(Artifact.Artifact artifact) { return(artifact.FileInfo.Exists); }
public static bool DownloadArtifact(Artifact.Artifact artifact) { return(downloadArtifactFromRemoteRepository(artifact, artifact.FileInfo.Extension)); }
// TODO: belongs in another utility class private static void SetReferenceFromFile(FileInfo dll, Reference reference) { string path = string.Empty; if (dll.Exists) { path = dll.FullName; } else { ArtifactContext artifactContext = new ArtifactContext(); Artifact.Artifact a = artifactContext.GetArtifactRepository().GetArtifact(dll); if (a != null) { if (!a.FileInfo.Exists) { if (!a.FileInfo.Directory.Exists) { a.FileInfo.Directory.Create(); } string localRepoPath = artifactContext.GetArtifactRepository().GetLocalRepositoryPath(a, dll.Extension); if (File.Exists(localRepoPath)) { File.Copy(localRepoPath, a.FileInfo.FullName); path = a.FileInfo.FullName; } else { if (Reference.downloadArtifactFromRemoteRepository(a, dll.Extension)) { path = a.FileInfo.FullName; } else { path = reference.getBinReference(dll.Name); if (!string.IsNullOrEmpty(path)) { File.Copy(path, a.FileInfo.FullName); } } //copy assembly to repo if not found. if (!string.IsNullOrEmpty(path) && !File.Exists(localRepoPath)) { if (!Directory.Exists(Path.GetDirectoryName(localRepoPath))) { Directory.CreateDirectory(Path.GetDirectoryName(localRepoPath)); } File.Copy(path, localRepoPath); } } } else { path = a.FileInfo.FullName; } } if (a == null || string.IsNullOrEmpty(path)) { log.Warn("Cannot find or download the artifact " + dll.Name + ", project may not build properly."); return; } } reference.SetAssemblyInfoValues(AssemblyName.GetAssemblyName(path).FullName); }
public static bool DownloadArtifact(Artifact.Artifact artifact, NPanday.Logging.Logger logger) { return(downloadArtifactFromRemoteRepository(artifact, artifact.FileInfo.Extension, logger)); }
protected Artifact.Artifact createArtifact(string name, string version) { Artifact.Artifact artifact = new Artifact.Artifact(); artifact.GroupId = name; artifact.ArtifactId = name; artifact.Version = version; artifact.Extension = "dll"; return artifact; }
public void CopyArtifact(Artifact.Artifact artifact, NPanday.Logging.Logger logger) { CopyArtifactImpl(artifact, logger, ArtifactResyncSource.RemoteRepository); }
// TODO: belongs in another utility class private static void SetReferenceFromFile(FileInfo dll, Reference reference) { Assembly asm = null; string path = string.Empty; //if (dll.Exists) if (dll.Exists) { //asm = Assembly.ReflectionOnlyLoadFrom(dll.FullName); path = dll.FullName; } else { ArtifactContext artifactContext = new ArtifactContext(); Artifact.Artifact a = artifactContext.GetArtifactRepository().GetArtifact(dll); if (a != null) { if (!a.FileInfo.Exists) { if (!a.FileInfo.Directory.Exists) { a.FileInfo.Directory.Create(); } string localRepoPath = artifactContext.GetArtifactRepository().GetLocalRepositoryPath(a, dll.Extension); if (File.Exists(localRepoPath)) { File.Copy(localRepoPath, a.FileInfo.FullName); //asm = Assembly.ReflectionOnlyLoadFrom(); path = a.FileInfo.FullName; } else { if (Reference.downloadArtifactFromRemoteRepository(a, dll.Extension, null)) { //asm = Assembly.ReflectionOnlyLoadFrom(a.FileInfo.FullName); path = a.FileInfo.FullName; } else { path = reference.getBinReference(dll.Name); if (!string.IsNullOrEmpty(path)) { File.Copy(path, a.FileInfo.FullName); } } //copy assembly to repo if not found. if (!string.IsNullOrEmpty(path) && !File.Exists(localRepoPath)) { if (!Directory.Exists(Path.GetDirectoryName(localRepoPath))) { Directory.CreateDirectory(Path.GetDirectoryName(localRepoPath)); } File.Copy(path, localRepoPath); } } } else { path = a.FileInfo.FullName; } } if (a == null || string.IsNullOrEmpty(path)) { Console.WriteLine("Cannot find or download the artifact " + dll.Name + ", project may not build properly."); return; } } bool asmNotLoaded = true; foreach (Assembly asmm in AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies()) { // compare the assembly name to the filename of the reference to determine if it is a match // as the location might not be set // TODO: why do we need to load the assembly? // added StringComparison.OrdinalIgnoreCase to assembly name compratison in order to avoid errors with // already loaded assemblies like nunit.framework and NUnit.Framework etc (note this can be reconsidered) if (asmm.GetName().Name.Equals(Path.GetFileNameWithoutExtension(path), StringComparison.OrdinalIgnoreCase)) { asm = asmm; asmNotLoaded = false; break; } } if (asmNotLoaded) { asm = Assembly.ReflectionOnlyLoadFrom(path); } reference.SetAssemblyInfoValues(asm.ToString()); //asm = null; }
protected Dependency ResolveDependency(Reference reference) { // resolve first from artifact Artifact.Artifact artifact = GetArtifact(reference); if (artifact != null) { Dependency dependency = new Dependency(); dependency.artifactId = artifact.ArtifactId; dependency.groupId = artifact.GroupId; dependency.version = artifact.Version; dependency.type = "dotnet-library"; return(dependency); } List <string> refs = GacUtility.GetInstance().GetAssemblyInfo(reference.Name, null, projectDigest.Platform); // resolve from GAC if (refs.Count > 0) { // Assembly is found at the gac //exclude ProcessArchitecture when loading assembly on a non-32 bit machine refs = GacUtility.GetInstance().GetAssemblyInfo(reference.Name, reference.Version, null); System.Reflection.Assembly a = System.Reflection.Assembly.ReflectionOnlyLoad(new System.Reflection.AssemblyName(refs[0]).FullName); Dependency refDependency = new Dependency(); refDependency.artifactId = reference.Name; refDependency.groupId = reference.Name; refDependency.type = GacUtility.GetNPandayGacType(a, reference.PublicKeyToken); refDependency.version = reference.Version ?? "1.0.0.0"; if (reference.PublicKeyToken != null) { refDependency.classifier = reference.PublicKeyToken; } else { int start = a.FullName.IndexOf("PublicKeyToken="); int length = (a.FullName.Length) - start; refDependency.classifier = a.FullName.Substring(start, length); refDependency.classifier = refDependency.classifier.Replace("PublicKeyToken=", ""); } return(refDependency); } bool isPathReference = false; // resolve using system path if (!string.IsNullOrEmpty(reference.HintFullPath) && new FileInfo(reference.HintFullPath).Exists) { // silent for re-import //commented out //if (projectDigest.ExistingPom != null) //{ // return null; //} //else { string prjRefPath = Path.Combine(projectDigest.FullDirectoryName, ".references"); //verbose for new-import if (!reference.HintFullPath.ToLower().StartsWith(prjRefPath.ToLower()) && !reference.Name.Contains("Interop")) { MessageBox.Show( string.Format("Warning: Build may not be portable if local references are used, Reference is not in Maven Repository or in GAC." + "\nReference: {0}" + "\nDeploying the reference to a Repository, will make the code portable to other machines", reference.HintFullPath ), "Add Reference", MessageBoxButtons.OK, MessageBoxIcon.Warning); isPathReference = true; } } // uncomment this if systemPath is supported Dependency refDependency = new Dependency(); if (!isPathReference) { refDependency.artifactId = reference.Name; //get version from the name above the last path string[] pathTokens = reference.HintFullPath.Split("\\\\".ToCharArray()); refDependency.groupId = pathTokens[pathTokens.Length - 3]; refDependency.version = pathTokens[pathTokens.Length - 2].Replace(reference.Name + "-", "") ?? "1.0.0.0"; //refDependency.version = reference.Version ?? "1.0.0.0"; refDependency.type = "dotnet-library"; //refDependency.scope = "system"; //refDependency.systemPath = reference.HintFullPath; } else { refDependency.artifactId = reference.Name; refDependency.groupId = reference.Name; refDependency.version = reference.Version ?? "1.0.0.0"; refDependency.type = "dotnet-library"; refDependency.scope = "system"; refDependency.systemPath = reference.HintFullPath; } return(refDependency); } return(null); }
public static bool IsSnapshot(Artifact.Artifact artifact) { return(artifact.Version.EndsWith("-SNAPSHOT")); }
public void CopyArtifact(Artifact.Artifact artifact) { CopyArtifactImpl(artifact, ArtifactResyncSource.RemoteRepository); }
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))); }
public static bool DownloadFromRemoteRepository(Artifact.Artifact artifact) { return(NPanday.ProjectImporter.Digest.Model.Reference.DownloadArtifact(artifact)); }