LEFT | RIGHT |
1 /* | 1 /* |
2 Copyright 2013 Google Inc | 2 Copyright 2013 Google Inc |
3 | 3 |
4 Licensed under the Apache License, Version 2.0 (the "License"); | 4 Licensed under the Apache License, Version 2.0 (the "License"); |
5 you may not use this file except in compliance with the License. | 5 you may not use this file except in compliance with the License. |
6 You may obtain a copy of the License at | 6 You may obtain a copy of the License at |
7 | 7 |
8 http://www.apache.org/licenses/LICENSE-2.0 | 8 http://www.apache.org/licenses/LICENSE-2.0 |
9 | 9 |
10 Unless required by applicable law or agreed to in writing, software | 10 Unless required by applicable law or agreed to in writing, software |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 using NuGet; | 22 using NuGet; |
23 | 23 |
24 namespace Google.Apis.Utils | 24 namespace Google.Apis.Utils |
25 { | 25 { |
26 /// <summary> | 26 /// <summary> |
27 /// NuGet utilities class which support publishing to NuGet main repository,
creating a local NuGet package, etc. | 27 /// NuGet utilities class which support publishing to NuGet main repository,
creating a local NuGet package, etc. |
28 /// </summary> | 28 /// </summary> |
29 public static class NuGetUtilities | 29 public static class NuGetUtilities |
30 { | 30 { |
31 static readonly TraceSource TraceSource = new TraceSource("Google.Apis")
; | 31 private static readonly TraceSource TraceSource = new TraceSource("Googl
e.Apis"); |
32 | 32 |
33 /// <summary>The local NuGet folder which stores local NuGet packages.</
summary> | 33 /// <summary>The local NuGet folder which stores local NuGet packages.</
summary> |
34 public const string LocalNuGetPackageFolder = @"C:\LocalNuGetFeed"; | 34 public static readonly string LocalNuGetPackageFolder; |
35 | 35 |
36 /// <summary>The main NuGet repository. This is used to publish a new pa
ckage.</summary> | 36 /// <summary>The main NuGet repository. This is used to publish a new pa
ckage.</summary> |
37 private static readonly IPackageRepository MainNuGetRepository = | 37 private static readonly IPackageRepository MainNuGetRepository = |
38 new PackageRepositoryFactory().CreateRepository("https://nuget.org/a
pi/v2/"); | 38 new PackageRepositoryFactory().CreateRepository("https://nuget.org/a
pi/v2/"); |
39 | 39 |
40 private const int NuGetPushTimeoutMills = 10000; | 40 private const int NuGetPushTimeoutMills = 10000; |
41 | 41 |
42 static NuGetUtilities() | 42 static NuGetUtilities() |
43 { | 43 { |
| 44 LocalNuGetPackageFolder = Path.Combine(Path.DirectorySeparatorChar.T
oString(), "LocalNuGetFeed"); |
44 if (!Directory.Exists(LocalNuGetPackageFolder)) | 45 if (!Directory.Exists(LocalNuGetPackageFolder)) |
45 { | 46 { |
46 Directory.CreateDirectory(LocalNuGetPackageFolder); | 47 Directory.CreateDirectory(LocalNuGetPackageFolder); |
47 } | 48 } |
48 } | 49 } |
49 | 50 |
50 /// <summary> | 51 /// <summary> |
51 /// Creates a local nupkg file, and stores it in a local folder (<see cr
ef="LocalNuGetPackageFolder"/>). | 52 /// Creates a local nupkg file, and stores it in a local folder (<see cr
ef="LocalNuGetPackageFolder"/>). |
52 /// </summary> | 53 /// </summary> |
53 /// <returns>The path to the nupkg file</returns> | 54 /// <returns>The path to the nupkg file</returns> |
(...skipping 15 matching lines...) Expand all Loading... |
69 } | 70 } |
70 TraceSource.TraceEvent(TraceEventType.Information, "{0} was crea
ted", nupkg); | 71 TraceSource.TraceEvent(TraceEventType.Information, "{0} was crea
ted", nupkg); |
71 } | 72 } |
72 return nupkg; | 73 return nupkg; |
73 } | 74 } |
74 | 75 |
75 /// <summary>Publishes to the NuGet main repository.</summary> | 76 /// <summary>Publishes to the NuGet main repository.</summary> |
76 public static void PublishToNuget(string packagePath, string nugetApiKey
) | 77 public static void PublishToNuget(string packagePath, string nugetApiKey
) |
77 { | 78 { |
78 TraceSource.TraceEvent(TraceEventType.Verbose, "Pushing \"{0}\" to N
uGet repository", packagePath); | 79 TraceSource.TraceEvent(TraceEventType.Verbose, "Pushing \"{0}\" to N
uGet repository", packagePath); |
79 PackageServer ps = new PackageServer("https://nuget.org/", "Google.A
pis"); | 80 PackageServer packageServer = new PackageServer("https://nuget.org/"
, "Google.Apis"); |
80 try | 81 try |
81 { | 82 { |
82 ps.PushPackage(nugetApiKey, new ZipPackage(packagePath), NuGetPu
shTimeoutMills); | 83 packageServer.PushPackage(nugetApiKey, new ZipPackage(packagePat
h), NuGetPushTimeoutMills); |
83 TraceSource.TraceEvent(TraceEventType.Information, "\"{0}\" was
pushed successfully", packagePath); | 84 TraceSource.TraceEvent(TraceEventType.Information, "\"{0}\" was
pushed successfully", packagePath); |
84 } | 85 } |
85 catch (Exception ex) | 86 catch (Exception ex) |
86 { | 87 { |
87 TraceSource.TraceEvent(TraceEventType.Error, "Can't publish \"{0
}\" to NuGet repository. " + | 88 TraceSource.TraceEvent(TraceEventType.Error, "Can't publish \"{0
}\" to NuGet repository. " + |
88 "Exception is: {1}", packagePath, ex.Message); | 89 "Exception is: {1}", packagePath, ex.Message); |
89 } | 90 } |
90 } | 91 } |
91 | 92 |
92 /// <summary> | 93 /// <summary> |
93 /// Returns <c>true</c> if a NuGet package already exists in the main Nu
Get repository for the input name and· | 94 /// Returns <c>true</c> if a NuGet package already exists in the main Nu
Get repository for the input name and· |
94 /// version. | 95 /// version. |
95 /// </summary> | 96 /// </summary> |
96 public static bool DoesNugetPackageExist(string packageName, string vers
ion) | 97 public static bool DoesNugetPackageExist(string packageName, string vers
ion) |
97 { | 98 { |
98 IPackage package; | 99 IPackage package; |
99 return MainNuGetRepository.TryFindPackage(packageName, new SemanticV
ersion(version), out package); | 100 return MainNuGetRepository.TryFindPackage(packageName, new SemanticV
ersion(version), out package); |
100 } | 101 } |
101 } | 102 } |
102 } | 103 } |
LEFT | RIGHT |